ordinantiCtrl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. app.controller('ordinantiCtrl',
  2. function ($scope,$http,$cookies,$window, $location,$timeout, $mdDialog, $q, $routeParams, $mdBottomSheet, $mdMedia, userService, utilsSvc, Ordinanti, UserManager) {
  3. var vm=this;
  4. vm.idOrdinante = $routeParams.idOrdinante;
  5. vm.maxItems = 0;
  6. vm.maxContiItems = 0;
  7. vm.itemsPerPage = 100;
  8. vm.selectedIndex=-1;
  9. vm.records=[];
  10. vm.filter={
  11. orderField:null
  12. };
  13. vm.appVariables = {};
  14. vm.setSelected=function(idx) {
  15. vm.selectedIndex = idx;
  16. }
  17. vm.columnWidths=[
  18. 250, //0
  19. 115,
  20. 115,
  21. 190,
  22. 250,
  23. 80,
  24. 150,
  25. 80
  26. ];
  27. UserManager.AppVariables().$promise.then(function(data) {
  28. vm.appVariables = data;
  29. });
  30. vm.getGridItemHeight = function() {
  31. return utilsSvc.getGridHeight();
  32. }
  33. vm.stampaOrdinanti = function() {
  34. utilsSvc.showForever('Generazione in corso...');
  35. Ordinanti.Print({},$scope.filter).$promise.then(function(data){
  36. utilsSvc.downloadFile('application/pdf',data.response,'Ordinanti.pdf');
  37. utilsSvc.cancelMessage();
  38. }).catch(function(err){
  39. if (err.status==404) {
  40. utilsSvc.cancelMessage();
  41. utilsSvc.showMessage('Nessun ordinante estratto');
  42. } else
  43. utilsSvc.handleHttpError(err);
  44. }); ;
  45. }
  46. vm.showCommands = function(distinta,index,$event) {
  47. vm.selectedIndex = index;
  48. $mdBottomSheet.show({
  49. templateUrl: 'templates/bottom-sheet-template.html',
  50. controller: 'comandiOrdinantiCtrl',
  51. locals:{idx: index, appVariables: vm.appVariables},
  52. targetEvent: $event
  53. }).then(function(selectedCommand) {
  54. vm.executeCommand(selectedCommand.cmdIndex, selectedCommand.recordIdx, $event);
  55. },
  56. function(){}
  57. );
  58. }
  59. vm.executeCommand = function(id,idx, $event) {
  60. $scope.filterChiamante = userService.getFiltroIncassiSDD();
  61. $scope.filterChiamante.tipoChiamata = "Destinatari";
  62. userService.setFiltroIncassiSDD($scope.filterChiamante);
  63. switch(id) {
  64. case 0: vm.editDestinatario(vm.records[idx], $event); break;
  65. case 1: vm.apriDestinatari(vm.records[idx], $event); break;
  66. case 2: vm.apriDelegheSeda(vm.records[idx], $event); break;
  67. }
  68. }
  69. vm.nuovoOrdinante = function(ev){
  70. Ordinanti.New().$promise.then(function(res){
  71. vm.records.push(res);
  72. vm.editDestinatario(vm.records[vm.records.length-1], event);
  73. });
  74. }
  75. vm.editDestinatario=function(ordinante, event) {
  76. $mdDialog.show({
  77. templateUrl: 'templates/ordinante.html',
  78. controller: 'ordinanteCtrl',
  79. targetEvent: event,
  80. locals: ordinante,
  81. multiple: true
  82. }).then(function(ordinante){
  83. Ordinanti.save({}, ordinante).$promise.then(function(res){
  84. utilsSvc.showMessage('Salvataggio modifiche effettuato');
  85. vm.getOrdinanti();
  86. },
  87. function(){
  88. vm.getOrdinanti();
  89. })
  90. })
  91. }
  92. vm.apriDestinatari=function(ordinante, event) {
  93. $mdDialog.show({
  94. templateUrl: 'templates/destinatari.html',
  95. controller: 'destinatariCtrl',
  96. locals: {ordinante:ordinante, ordinanti: vm.records},
  97. multiple: true
  98. });
  99. }
  100. vm.apriDelegheSeda=function(ordinante, event) {
  101. $mdDialog.show({
  102. templateUrl: 'templates/delegheSeda.html',
  103. controller: 'delegheSedaCtrl',
  104. targetEvent: event,
  105. locals: {idOrdinante:ordinante.idordinante, tipo: ''},
  106. multiple: true
  107. })
  108. }
  109. vm.getListHeight = function() {
  110. containerHeight = ($window.innerHeight - $('#container').position().top - $('#view').position().top);
  111. return {'height': containerHeight + 'px'};
  112. };
  113. $window.addEventListener('resize', onResize);
  114. function onResize() {
  115. $scope.$digest();
  116. }
  117. $scope.$on('$destroy', function() {
  118. $window.removeEventListener('resize', onResize);
  119. });
  120. vm.getColumnWidth = // }
  121. // this.lastStartIdx = index;
  122. function(idx) {
  123. return {
  124. 'width': vm.columnWidths[idx] + 'px',
  125. 'min-width':vm.columnWidths[idx] + 'px',
  126. 'max-width':vm.columnWidths[idx] + 'px',
  127. 'margin-left':'8px',
  128. 'margin-right':'8px',
  129. 'text-overflow': 'ellipsis',
  130. 'overflow': 'hidden',
  131. 'white-space':'nowrap'
  132. };
  133. }
  134. vm.getMaxListWidth = function() {
  135. var res=0;
  136. for (var i=0;i<vm.columnWidths.length;i++)
  137. res += vm.columnWidths[i]+6+8+10;
  138. $('#container').css('width',($('#header').width()+10)+'px');
  139. return {'width': res+ 'px!important;'}
  140. }
  141. vm.setOrderField = function(field) {
  142. if (vm.filter.orderField!=field)
  143. vm.filter.orderField = field;
  144. else
  145. vm.filter.orderField = "-" +field;
  146. vm.getOrdinanti();
  147. }
  148. vm.infiniteItems = {
  149. numLoaded_: 0,
  150. toLoad_: 0,
  151. loading_:false,
  152. lastStartIdx:-1,
  153. listPromise:null,
  154. canceler: $q.defer(),
  155. // Required.
  156. getItemAtIndex: function(index) {
  157. if (vm.maxItems==0 || index>vm.maxItems)
  158. return null;
  159. if (!vm.infiniteItems.loading_)
  160. if (index > vm.records.length) {
  161. this.fetchMoreItems_(index);
  162. return null;
  163. }
  164. return vm.records [index];
  165. },
  166. // Required.
  167. // For infinite scroll behavior, we always return a slightly
  168. // higher
  169. // number than the previously loaded items.
  170. getLength: function() {
  171. return vm.maxItems;
  172. },
  173. fetchMoreItems_: function(index) {
  174. if (this.toLoad_ < index) {
  175. this.toLoad_ += vm.itemsPerPage;
  176. utilsSvc.showWaitMessage('Ricerca in corso...');
  177. vm.infiniteItems.loading_ = true;
  178. this.listPromise = Ordinanti.List({idOrdinante: vm.idOrdinante, filter:vm.filter.filterText, start: vm.records.length,size:Math.max(vm.records.length+index,vm.itemsPerPage),orderBy:vm.filter.orderField}).$promise;
  179. var mod=this;
  180. this.listPromise.then(
  181. function(data){
  182. vm.infiniteItems.loading_ = false;
  183. vm.infiniteItems.toLoad_=0;
  184. utilsSvc.cancelWaitMessage();
  185. vm.records = vm.records.concat(data);
  186. mod.numLoaded_ = vm.records.length;
  187. mod.lastStartIdx = vm.records.length;
  188. },
  189. function(error) {
  190. vm.infiniteItems.loading_ = false;
  191. vm.infiniteItems.toLoad_=0;
  192. utilsSvc.handleHttpError(error);
  193. }
  194. )
  195. }
  196. }
  197. }
  198. vm.contiInfiniteItems = {
  199. numLoaded_: 0,
  200. toLoad_: 0,
  201. loading_:false,
  202. lastStartIdx:-1,
  203. listPromise:null,
  204. canceler: $q.defer(),
  205. // Required.
  206. getItemAtIndex: function(index) {
  207. if (vm.maxContiItems==0 || index>vm.maxContiItems)
  208. return null;
  209. if (!vm.contiInfiniteItems.loading_)
  210. if (index > vm.recordsConti.length) {
  211. this.fetchMoreItems_(index);
  212. return null;
  213. }
  214. return vm.recordsConti [index];
  215. },
  216. // Required.
  217. // For infinite scroll behavior, we always return a slightly
  218. // higher
  219. // number than the previously loaded items.
  220. getLength: function() {
  221. return vm.maxContiItems;
  222. },
  223. fetchMoreItems_: function(index) {
  224. if (this.toLoad_ < index) {
  225. this.toLoad_ += vm.itemsPerPage;
  226. utilsSvc.showWaitMessage('Ricerca in corso...');
  227. vm.contiInfiniteItems.loading_ = true;
  228. this.listPromise = ContiDestinatario.List({start: vm.recordsConti.length,size:Math.max(vm.recordsConti.length+index,vm.itemsPerPage),orderBy:vm.filter.orderField}).$promise;
  229. var mod=this;
  230. this.listPromise.then(
  231. function(data){
  232. vm.contiInfiniteItems.loading_ = false;
  233. vm.contiInfiniteItems.toLoad_=0;
  234. utilsSvc.cancelWaitMessage();
  235. vm.records = vm.recordsConti.concat(data);
  236. mod.numLoaded_ = vm.recordsConti.length;
  237. mod.lastStartIdx = vm.recordsConti.length;
  238. },
  239. function(error) {
  240. vm.contiInfiniteItems.loading_ = false;
  241. vm.contiInfiniteItems.toLoad_=0;
  242. utilsSvc.handleHttpError(error);
  243. }
  244. )
  245. }
  246. }
  247. }
  248. vm.eliminaOrdinante = function(ndx, event) {
  249. utilsSvc.showConfirm("Confermi la cancellazione dell'ordinante?", "Conferma", event)
  250. .then(function(res){
  251. Ordinanti.Delete({id: vm.records[ndx].idordinante}).$promise.then(function(data){
  252. utilsSvc.showMessage("Eliminazione effettuata");
  253. vm.getOrdinanti();
  254. },
  255. function(error) {
  256. utilsSvc.handleHttpError(error);
  257. });
  258. });
  259. }
  260. vm.getOrdinanti = function(){
  261. Ordinanti.Count({idOrdinante: vm.idOrdinante, filter:vm.filter.filterText}).$promise.then(
  262. function(data){
  263. vm.records=[];
  264. vm.maxItems = data.value;
  265. vm.infiniteItems.numLoaded_ = 0;
  266. vm.infiniteItems.toLoad_ = 0;
  267. }
  268. );
  269. }
  270. vm.getContiDestinaraio = function(idDestinatario){
  271. Ordinanti.Count({idDestintario: idDestinatario}).$promise.then(
  272. function(data){
  273. vm.records=[];
  274. vm.maxContiItems = data.value;
  275. vm.contiInfiniteItems.numLoaded_ = 0;
  276. vm.contiInfiniteItems.toLoad_ = 0;
  277. }
  278. );
  279. }
  280. vm.init = function() {
  281. vm.getOrdinanti();
  282. }
  283. vm.init();
  284. }
  285. )
  286. .controller('comandiOrdinantiCtrl', function($scope, $mdBottomSheet, locals) {
  287. $scope.title = 'Comandi';
  288. $scope.items = [
  289. { id:0, name: "Modifica", icon: 'fa-pencil',visible: true },
  290. { id:1, name: "Destinatari", icon: 'fa-users',visible: true },
  291. { id:2, name: "Deleghe SEDA", icon: 'fa-refresh', visible: true }
  292. ];
  293. if (locals.appVariables.profiloLocale=="TR" && !locals.appVariables.abilitaAccessoAnagrafica)
  294. $scope.items[1].visible = false;
  295. $scope.listItemClick = function($index, $event) {
  296. var clickedItem = $scope.items[$index];
  297. var result = {cmdIndex: $index, recordIdx: locals.idx, event:$event}
  298. $mdBottomSheet.hide(result);
  299. };
  300. $scope.dismissBottomSheet = function() {
  301. $mdBottomSheet.cancel();
  302. }
  303. })
  304. .controller('ordinanteCtrl', function($scope,$mdDialog,utilsSvc,locals) {
  305. $scope.ordinante = angular.copy(locals);
  306. $scope.controllaCF=function(){
  307. if (!utilsSvc.controllaCFoPiva($scope.ordinante.codiceFiscale))
  308. utilsSvc.showMessage("Codice fiscale / partita IVA non valido");
  309. }
  310. $scope.confirmDialog = function() {
  311. if ($scope.checkDati()) {
  312. if ($scope.ordinante.conto!=null)
  313. $scope.ordinante.conto = $scope.ordinante.conto.toUpperCase();
  314. $mdDialog.hide($scope.ordinante);
  315. }
  316. }
  317. $scope.cancelDialog = function() {
  318. $mdDialog.cancel();
  319. }
  320. $scope.checkDigit=function(event, len){
  321. if (event.key=="Backspace" || event.key=="ArrowLeft" || event.key=="ArrowRight" || event.key=="Tab")
  322. return;
  323. if ("0123456789".indexOf(event.key)==-1 || event.target.value.length>=len)
  324. event.preventDefault();
  325. }
  326. $scope.checkDati = function() {
  327. if ($scope.ordinante.ordinante==null || $scope.ordinante.ordinante=='' ){
  328. utilsSvc.showMessage("Inserire la denominazione dell'ordinante");
  329. return false;
  330. }
  331. if ($scope.ordinante.codiceFiscale==null || $scope.ordinante.codiceFiscale=='' ){
  332. utilsSvc.showMessage("Inserire il codice fiscale / partita IVA dell'ordinante");
  333. return false;
  334. }
  335. if ($scope.ordinante.codiceSia==null || $scope.ordinante.codiceSia=='' ){
  336. utilsSvc.showMessage("Inserire il codice SIA dell'ordinante");
  337. return false;
  338. }
  339. return true;
  340. }
  341. }
  342. )
  343. ;