pagamentiSCTInpsCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. app.controller('pagamentiSCTInpsCtrl',
  2. function($scope, $http, $cookies, $window, $location, $timeout,
  3. $mdDialog, $q, $routeParams, $mdMedia, utilsSvc,
  4. userService, ComboManager, DisposizioniBonifici,
  5. DistinteBanca, UserManager) {
  6. var vm = this;
  7. vm.nomeFunzione = 'SCT INPS';
  8. vm.filteredView = (typeof $routeParams.filter != "undefined");
  9. $location.search('filter', null).replace();
  10. vm.maxItems = 0;
  11. vm.itemsPerPage = 100;
  12. vm.records = [];
  13. vm.esitiRid = [];
  14. vm.selectedIndex = -1;
  15. vm.topIndex = 0;
  16. vm.filter = userService.getFiltroIncassiSDD();
  17. vm.abilitaFirma = false;
  18. vm.appVariables = {};
  19. vm.initFilter = function() {
  20. return;
  21. if (vm.filter.tipoChiamata != "DistinteBanca") {
  22. vm.filter.idDistintaBanca = 0;
  23. vm.filter.idDistintaFlusso = 0;
  24. vm.filter.codiceClienteDebitore = '';
  25. userService.setFiltroIncassiSDD(vm.filter);
  26. }
  27. }
  28. vm.initFilter();
  29. if (utilsSvc.largeScreen())
  30. vm.columnWidths = [
  31. 70, // 0
  32. 90, // 1
  33. 80, // 2
  34. 100, // 3
  35. 90, // 4
  36. 90, // 5
  37. 130, // 6
  38. 250, // 7
  39. 90, // 8
  40. 90, // 9
  41. 120, // 10
  42. 180, // 11
  43. 180, // 12
  44. 120, // 13
  45. 240, // 14
  46. 200
  47. ];
  48. else
  49. vm.columnWidths = [
  50. 70, // 0
  51. 90, // 1
  52. 70, // 2
  53. 70, // 3
  54. 90, // 4
  55. 80, // 5
  56. 130, // 6
  57. 250, // 7
  58. 90, // 8
  59. 90, // 9
  60. 120, // 10
  61. 180, // 11
  62. 180, // 12
  63. 120, // 13
  64. 240, // 14
  65. 200
  66. ];
  67. vm.getListHeight = function() {
  68. containerHeight = ($window.innerHeight
  69. - $('#container').position().top - $('#view')
  70. .position().top);
  71. return {
  72. 'height' : containerHeight + 'px'
  73. };
  74. };
  75. vm.getGridItemHeight = function() {
  76. return utilsSvc.getGridHeight();
  77. }
  78. $window.addEventListener('resize', onResize);
  79. function onResize() {
  80. $scope.$digest();
  81. }
  82. $scope.$on('$destroy', function() {
  83. $window.removeEventListener('resize', onResize);
  84. });
  85. $timeout(function() {
  86. var evt = $window.document.createEvent('UIEvents');
  87. evt.initUIEvent('resize', true, false, $window, 0);
  88. $window.dispatchEvent(evt);
  89. },100);
  90. vm.largeScreen = function() {
  91. return utilsSvc.largeScreen();
  92. }
  93. vm.openMenu = function($mdMenu, ev) {
  94. originatorEv = ev;
  95. $mdMenu.open(ev);
  96. };
  97. vm.getColumnWidth = // }
  98. // this.lastStartIdx = index;
  99. function(idx) {
  100. return {
  101. 'width' : vm.columnWidths[idx] + 'px',
  102. 'min-width' : vm.columnWidths[idx] + 'px',
  103. // 'padding-left':'6px',
  104. // 'padding-right':'6px',
  105. 'margin-left' : '8px',
  106. 'margin-right' : '8px'
  107. };
  108. }
  109. vm.getMaxListWidth = function() {
  110. var res = 0;
  111. for (var i = 0; i < vm.columnWidths.length; i++)
  112. res += vm.columnWidths[i] + 6 + 8 + 10;
  113. $('#container').css('width',
  114. ($('#header').width() + 10) + 'px');
  115. return {
  116. 'width' : res + 'px!important;'
  117. }
  118. }
  119. vm.getEsitoColor = function(esito) {
  120. var color;
  121. if (esito == 2)
  122. color = 'red';
  123. else if (esito == 1)
  124. color = 'green';
  125. return {
  126. 'color' : color
  127. };
  128. }
  129. vm.setOrderField = function(field) {
  130. if (vm.filter.orderField != field)
  131. vm.filter.orderField = field;
  132. else
  133. vm.filter.orderField = "-" + field;
  134. vm.getDisposizioni();
  135. }
  136. vm.cercaErrori = function(event) {
  137. vm.getDisposizioni();
  138. }
  139. vm.stampaDisposizioni = function() {
  140. utilsSvc.showForever('Generazione in corso...');
  141. if (vm.filteredView)
  142. DisposizioniBonifici.PrintFiltered({}, userService
  143. .getFilter()).$promise.then(function(data) {
  144. utilsSvc.downloadFile('application/pdf',
  145. data.response,
  146. 'DisposizioniBonifici.pdf');
  147. utilsSvc.cancelMessage();
  148. }).catch(function(err){
  149. if (err.status==404) {
  150. utilsSvc.cancelMessage();
  151. utilsSvc.showMessage('Nessuna disposizione estratta');
  152. } else
  153. utilsSvc.handleHttpError(err);
  154. });
  155. else
  156. DisposizioniBonifici.Print({}, vm.filter).$promise
  157. .then(function(data) {
  158. utilsSvc.downloadFile(
  159. 'application/pdf',
  160. data.response,
  161. 'DisposizioniBonifici.pdf');
  162. utilsSvc.cancelMessage();
  163. }).catch(function(err){
  164. if (err.status==404) {
  165. utilsSvc.cancelMessage();
  166. utilsSvc.showMessage('Nessuna disposizione estratta');
  167. } else
  168. utilsSvc.handleHttpError(err);
  169. });
  170. }
  171. vm.firmaDistinta = function() {
  172. if (userService.getFiltroIncassiSDD().importoDistinta < vm.appVariables.importoLimiteFirma
  173. && (userService.getFiltroIncassiSDD().userIdFirmatario1 == '' || userService
  174. .getFiltroIncassiSDD().userIdFirmatario1 == null)) {
  175. utilsSvc
  176. .showConfirm("Conferma",
  177. "Confermi la firma della distinta e l'emissione del flusso di pagamento?")
  178. .then(
  179. function(res) {
  180. vm
  181. .eseguiFirma(
  182. 1,
  183. 1,
  184. userService
  185. .getFiltroIncassiSDD().idDistintaBanca);
  186. });
  187. } else if (userService.getFiltroIncassiSDD().importoDistinta >= vm.appVariables.importoLimiteFirma
  188. && (userService.getFiltroIncassiSDD().userIdFirmatario1 == '' || userService
  189. .getFiltroIncassiSDD().userIdFirmatario1 == null)) {
  190. utilsSvc
  191. .showConfirm(
  192. "Conferma",
  193. "Confermi la firma della distinta e l'emissione del flusso di pagamento?<br>Per l'emissione del flusso di pagamento sarà richiesto il secondo firmatario")
  194. .then(
  195. function(res) {
  196. vm
  197. .eseguiFirma(
  198. 1,
  199. 0,
  200. userService
  201. .getFiltroIncassiSDD().idDistintaBanca);
  202. });
  203. } else if (userService.getFiltroIncassiSDD().userIdFirmatario1 != '') {
  204. utilsSvc
  205. .showConfirm("Conferma",
  206. "Confermi la firma della distinta e l'emissione del flusso di pagamento?")
  207. .then(
  208. function(res) {
  209. vm
  210. .eseguiFirma(
  211. 2,
  212. 1,
  213. userService
  214. .getFiltroIncassiSDD().idDistintaBanca);
  215. });
  216. }
  217. }
  218. vm.eseguiFirma = function(tipoFirma, generaFlusso,
  219. idDistintaBanca) {
  220. DistinteBanca.FirmaDistinta({
  221. tipoFirma : tipoFirma,
  222. generaFlusso : generaFlusso,
  223. idDistintaBanca : idDistintaBanca
  224. }).$promise
  225. .then(function(res) {
  226. if (res[0] == "0")
  227. utilsSvc
  228. .show("Firma distinta effettuata");
  229. else if (res[0] == "4")
  230. utilsSvc
  231. .show("Firma distinta non effettuata: Errore : ErrorConflict");
  232. else if (res[0] == "5")
  233. utilsSvc
  234. .show("Firma distinta non effettuata: Errore : ErrorConflictRecordDeleted");
  235. else if (res[0] == "6")
  236. utilsSvc
  237. .show("Firma distinta non effettuata, tutte le disposizioni sono state eliminate");
  238. else
  239. utilsSvc
  240. .show("Firma distinta non effettuata: Errore : "
  241. + res);
  242. $location.path('/distinteBanca');
  243. })
  244. }
  245. vm.exportExcel = function() {
  246. if (vm.filteredView) {
  247. utilsSvc.showForever('Generazione in corso...');
  248. DisposizioniBonifici.ExportFiltered({}, userService
  249. .getFilter()).$promise.then(function(data) {
  250. utilsSvc.downloadFile('attachment/csv',
  251. data.response, 'export.csv');
  252. utilsSvc.cancelMessage();
  253. }).catch(function(err){
  254. if (err.status==404) {
  255. utilsSvc.cancelMessage();
  256. utilsSvc.showMessage('Nessuna distinta estratta');
  257. }
  258. })
  259. } else {
  260. utilsSvc.showForever('Generazione in corso...');
  261. DisposizioniBonifici.Export({}, vm.filter).$promise
  262. .then(function(data) {
  263. utilsSvc.downloadFile('attachment/csv',
  264. data.response, 'export.csv');
  265. utilsSvc.cancelMessage();
  266. }).catch(function(err){
  267. if (err.status==404) {
  268. utilsSvc.cancelMessage();
  269. utilsSvc.showMessage('Nessuna distinta estratta');
  270. }
  271. })
  272. }
  273. }
  274. vm.infiniteItems = {
  275. numLoaded_ : 0,
  276. toLoad_ : 0,
  277. loading_ : false,
  278. lastStartIdx : -1,
  279. listPromise : null,
  280. canceler : $q.defer(),
  281. // Required.
  282. getItemAtIndex : function(index) {
  283. if (vm.maxItems == 0 || index>vm.maxItems)
  284. return null;
  285. if (!vm.infiniteItems.loading_)
  286. if (index > vm.records.length) {
  287. vm.infiniteItems.fetchMoreItems_(index);
  288. return null;
  289. }
  290. return vm.records[index];
  291. },
  292. // Required.
  293. // For infinite scroll behavior, we always return a
  294. // slightly
  295. // higher
  296. // number than the previously loaded items.
  297. getLength : function() {
  298. return vm.maxItems;
  299. },
  300. fetchMoreItems_ : function(index) {
  301. if (this.toLoad_ < index) {
  302. this.toLoad_ += vm.itemsPerPage;
  303. utilsSvc.showWaitMessage('Ricerca in corso...');
  304. vm.infiniteItems.loading_ = true;
  305. if ((vm.records.length + vm.itemsPerPage) < vm.selectedIndex)
  306. vm.itemsPerPage = vm.selectedIndex - vm.records.length;
  307. if (vm.filteredView) {
  308. var args = {filtroRicerca : userService.getFilter(),filtro : vm.filter};
  309. this.listPromise = DisposizioniBonifici.Filter({start : vm.records.length,size : Math.max(vm.records.length + index,vm.itemsPerPage),orderField : vm.filter.orderField}, args).$promise;
  310. } else
  311. this.listPromise = DisposizioniBonifici.List({start : vm.records.length,size : Math.max(vm.records.length+ index,vm.itemsPerPage)}, vm.filter).$promise;
  312. var mod = this;
  313. this.listPromise.then(function(data) {
  314. vm.infiniteItems.loading_ = false;
  315. vm.infiniteItems.toLoad_=0;
  316. utilsSvc.cancelWaitMessage();
  317. vm.records = vm.records.concat(data);
  318. mod.numLoaded_ = vm.records.length;
  319. mod.lastStartIdx = vm.records.length;
  320. vm.topIndex = vm.selectedIndex;
  321. }, function(error) {
  322. vm.infiniteItems.loading_ = false;
  323. vm.infiniteItems.toLoad_=0;
  324. utilsSvc.handleHttpError(error);
  325. })
  326. }
  327. }
  328. }
  329. vm.getDisposizioni = function() {
  330. utilsSvc.showWaitMessage('Ricerca in corso...');
  331. if (vm.filteredView) {
  332. var args = {
  333. filtroRicerca : userService.getFilter(),
  334. filtro : vm.filter
  335. };
  336. DisposizioniBonifici.CountFiltered({}, args,
  337. function(data) {
  338. vm.records = [];
  339. vm.maxItems = data.value;
  340. vm.infiniteItems.numLoaded_ = 0;
  341. vm.infiniteItems.toLoad_ = 0;
  342. utilsSvc.cancelWaitMessage();
  343. if (data.value==0 && vm.filteredView) {
  344. utilsSvc.showMessage('Nessuna disposizione estratta');
  345. $window.history.back();
  346. }
  347. }, function(error) {
  348. utilsSvc.cancelWaitMessage();
  349. utilsSvc.handleHttpError(error);
  350. });
  351. } else
  352. DisposizioniBonifici.Count(vm.filter,
  353. function(data) {
  354. vm.records = [];
  355. vm.maxItems = data.value;
  356. vm.infiniteItems.numLoaded_ = 0;
  357. vm.infiniteItems.toLoad_ = 0;
  358. utilsSvc.cancelWaitMessage();
  359. }, function(error) {
  360. utilsSvc.cancelWaitMessage();
  361. utilsSvc.handleHttpError(error);
  362. });
  363. }
  364. vm.getEsitoIcon = function(esito) {
  365. if (esito === '1')
  366. return "fa-clear";
  367. else if (esito === '2')
  368. return 'fa-times';
  369. }
  370. vm.ricercaDisposizioni = function(ev) {
  371. $mdDialog.show({
  372. templateUrl : 'templates/filtroDisposizioni.html',
  373. controller : 'filtroDisposizioniCtrl',
  374. targetEvent : ev,
  375. locals : {
  376. filter : vm.filter
  377. }
  378. }).then(function(args) {
  379. vm.filteredView = false;
  380. // dialog confirmed
  381. vm.filter = args;
  382. vm.getDisposizioni();
  383. }, function() {
  384. });
  385. }
  386. vm.mostraDisposizione = function(idx, ev) {
  387. if (typeof vm.records == "undefined"
  388. || typeof vm.records[idx] == "undefined")
  389. return
  390. vm.selectedIndex = idx;
  391. // disposizione.importo =
  392. // parseFloat(disposizione.importo.replace(",","."));
  393. DisposizioniBonifici.Get({
  394. id : vm.records[idx].id
  395. }).$promise
  396. .then(
  397. function(res) {
  398. var disposizione = res;
  399. $mdDialog
  400. .show(
  401. {
  402. templateUrl : 'templates/dettaglioDisposizioneSCT.html',
  403. controller : 'dettaglioDisposizioneSctCtrl',
  404. targetEvent : ev,
  405. locals : {
  406. label: (utilsSvc.largeScreen()?'Dettaglio disposizione SCT': 'SCT'),
  407. disposizione : angular
  408. .copy(disposizione),
  409. appVariables : vm.appVariables
  410. }
  411. })
  412. .then(function(args) {
  413. vm.initFilter();
  414. vm.getDisposizioni();
  415. }, function() {
  416. });
  417. }, function(err) {
  418. utilsSvc.handleHttpError(err);
  419. });
  420. }
  421. vm.key = function($event) {
  422. console.log($event.keyCode);
  423. if ($event.keyCode == 38)
  424. if (vm.selectedIndex > 0)
  425. vm.selectedIndex--;
  426. else if ($event.keyCode == 40)
  427. if (vm.selectedIndex < vm.maxItems)
  428. vm.selectedIndex++;
  429. }
  430. vm.init = function() {
  431. UserManager.AppVariables().$promise
  432. .then(function(data) {
  433. vm.appVariables = data;
  434. if (vm.filter.tipoChiamata == 'FiltroDisposizioni'
  435. || vm.filter.tipoChiamata == 'FiltroDisposizioniReadOnly'
  436. || vm.filter.tipoChiamata == 'DistinteBanca') {
  437. vm.abilitaFirma = vm.appVariables.profiloLocale == "DF";
  438. }
  439. });
  440. vm.getDisposizioni();
  441. }
  442. vm.init();
  443. });