pagamentiDOMCtrl.js 17 KB

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