pagamentiSCTCtrl.js 16 KB

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