pagamentiSCTEsteriCtrl.js 16 KB

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