allineamentoSEDACtrl.js 14 KB

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