app.controller( 'pagamentiDOMCtrl', function($scope, $http, $cookies, $window, $location, $timeout, $mdDialog, $q, $routeParams, $mdMedia, utilsSvc, userService, ComboManager, DisposizioniBonifici, DistinteBanca, UserManager) { var vm = this; vm.nomeFunzione = 'Bonifici Postali Domiciliati'; vm.filteredView = (typeof $routeParams.filter != "undefined"); $location.search('filter', null).replace(); vm.maxItems = 0; vm.itemsPerPage = 100; vm.records = []; vm.esitiRid = []; vm.selectedIndex = -1; vm.topIndex = 0; vm.filter = userService.getFiltroIncassiSDD(); vm.abilitaFirma = false; vm.appVariables = {}; vm.allSelected=false; vm.initFilter = function() { return; if (vm.filter.tipoChiamata != "DistinteBanca") { vm.filter.idDistintaBanca = 0; vm.filter.idDistintaFlusso = 0; vm.filter.codiceClienteDebitore = ''; userService.setFiltroIncassiSDD(vm.filter); } } vm.toggleSelectAll=function(){ vm.allSelected=!vm.allSelected; vm.records.forEach(function(item) { item.selected = vm.allSelected }); } vm.getSelectedIds = function(){ var res = []; if (vm.allSelected) res.push(-1); else vm.records.forEach(function(item){ if (item.selected) res.push(item.id) }); return res; } vm.cancellaDisposizioni = function(ev){ utilsSvc.showConfirm('Attenzione','Confermi la cancellazione delle disposizioni selezionate?',ev).then(function(){ utilsSvc.showForever('Cancellazione in corso...'); ids=vm.getSelectedIds(); let filter = new Object(); filter = vm.filter; filter.selectedIds=ids; DisposizioniBonifici.MassDelete({},filter).$promise.then(function(data){ utilsSvc.cancelMessage(); if (data.value) utilsSvc.showMessage('Cancellazione effettuata'); else utilsSvc.showMessage('Cancellazione effettuata. Alcune distinte non erano in uno stato da permetterne la cancellazione'); vm.getDisposizioni(); }).catch(function(err){ utilsSvc.cancelMessage(); utilsSvc.showMessage('Si è verificato un errore durante la cancellazione'); }) }); } vm.initFilter(); if (utilsSvc.largeScreen()) vm.columnWidths = [ 70, // 0 90, // 1 80, // 2 100, // 3 90, // 4 90, // 5 130, // 6 250, // 7 90, // 8 90, // 9 120, // 10 180, // 11 180, // 12 120, // 13 240, // 14 200 ]; else vm.columnWidths = [ 70, // 0 90, // 1 80, // 2 100, // 3 90, // 4 90, // 5 130, // 6 250, // 7 90, // 8 90, // 9 120, // 10 180, // 11 180, // 12 120, // 13 240, // 14 200 ]; vm.largeScreen =function(){ return utilsSvc.largeScreen(); } vm.getListHeight = function() { containerHeight = ($window.innerHeight - $('#container').position().top - $('#view') .position().top); return { 'height' : containerHeight + 'px' }; }; vm.getGridItemHeight = function() { return utilsSvc.getGridHeight(); } $window.addEventListener('resize', onResize); function onResize() { $scope.$digest(); } $scope.$on('$destroy', function() { $window.removeEventListener('resize', onResize); }); $timeout(function() { var evt = $window.document.createEvent('UIEvents'); evt.initUIEvent('resize', true, false, $window, 0); $window.dispatchEvent(evt); },100); vm.largeScreen = function() { return utilsSvc.largeScreen(); } vm.openMenu = function($mdMenu, ev) { originatorEv = ev; $mdMenu.open(ev); }; vm.getColumnWidth = // } // this.lastStartIdx = index; function(idx) { return { 'width' : vm.columnWidths[idx] + 'px', 'min-width' : vm.columnWidths[idx] + 'px', // 'padding-left':'6px', // 'padding-right':'6px', 'margin-left' : '8px', 'margin-right' : '8px' }; } vm.getMaxListWidth = function() { var res = 0; for (var i = 0; i < vm.columnWidths.length; i++) res += vm.columnWidths[i] + 6 + 8 + 10; $('#container').css('width', ($('#header').width() + 10) + 'px'); return { 'width' : res + 'px!important;' } } vm.getEsitoColor = function(esito) { var color; if (esito == 2) color = 'red'; else if (esito == 1) color = 'green'; return { 'color' : color }; } vm.setOrderField = function(field) { if (vm.filter.orderField != field) vm.filter.orderField = field; else vm.filter.orderField = "-" + field; vm.getDisposizioni(); } vm.cercaErrori = function(event) { vm.getDisposizioni(); } vm.stampaDisposizioni = function() { utilsSvc.showForever('Generazione in corso...'); ids=vm.getSelectedIds(); let filter = new Object(); if (vm.filteredView) filter = userService.getFilter(); else filter = vm.filter; filter.selectedIds=ids; if (vm.filteredView) DisposizioniBonifici.PrintFiltered({}, filter).$promise.then(function(data) { utilsSvc.downloadFile('application/pdf', data.response, 'DisposizioniBonifici.pdf'); utilsSvc.cancelMessage(); }).catch(function(err){ if (err.status==404) { utilsSvc.cancelMessage(); utilsSvc.showMessage('Nessuna disposizione estratta'); } else utilsSvc.handleHttpError(err); }); else DisposizioniBonifici.Print({}, filter).$promise .then(function(data) { utilsSvc.downloadFile( 'application/pdf', data.response, 'DisposizioniBonifici.pdf'); utilsSvc.cancelMessage(); }).catch(function(err){ if (err.status==404) { utilsSvc.cancelMessage(); utilsSvc.showMessage('Nessuna disposizione estratta'); } else utilsSvc.handleHttpError(err); }); } vm.firmaDistinta = function() { if (userService.getFiltroIncassiSDD().importoDistinta < vm.appVariables.importoLimiteFirma && (userService.getFiltroIncassiSDD().userIdFirmatario1 == '' || userService.getFiltroIncassiSDD().userIdFirmatario1 == null)) { utilsSvc.showConfirm("Conferma","Confermi la firma della distinta e l'emissione del flusso di pagamento?") .then(function(res) { vm.eseguiFirma(1,1,userService.getFiltroIncassiSDD().idDistintaBanca); }); } else if (userService.getFiltroIncassiSDD().importoDistinta >= vm.appVariables.importoLimiteFirma&& (userService.getFiltroIncassiSDD().userIdFirmatario1 == '' || userService .getFiltroIncassiSDD().userIdFirmatario1 == null)) { utilsSvc.showConfirm("Conferma","Confermi la firma della distinta e l'emissione del flusso di pagamento?
Per l'emissione del flusso di pagamento sarà richiesto il secondo firmatario") .then(function(res) { vm.eseguiFirma(1,0,userService.getFiltroIncassiSDD().idDistintaBanca); }); } else if (userService.getFiltroIncassiSDD().userIdFirmatario1 != '') { utilsSvc.showConfirm("Conferma","Confermi la firma della distinta e l'emissione del flusso di pagamento?") .then(function(res) { vm.eseguiFirma(2,1,userService.getFiltroIncassiSDD().idDistintaBanca); }); } } vm.eseguiFirma = function(tipoFirma, generaFlusso, idDistintaBanca) { DistinteBanca.FirmaDistinta({ tipoFirma : tipoFirma, generaFlusso : generaFlusso, idDistintaBanca : idDistintaBanca }).$promise .then(function(res) { if (res[0] == "0") utilsSvc .show("Firma distinta effettuata"); else if (res[0] == "4") utilsSvc .show("Firma distinta non effettuata: Errore : ErrorConflict"); else if (res[0] == "5") utilsSvc .show("Firma distinta non effettuata: Errore : ErrorConflictRecordDeleted"); else if (res[0] == "6") utilsSvc .show("Firma distinta non effettuata, tutte le disposizioni sono state eliminate"); else utilsSvc .show("Firma distinta non effettuata: Errore : " + res); $location.path('/distinteBanca'); }) } vm.exportExcel = function() { ids=vm.getSelectedIds(); let filter = new Object(); if (vm.filteredView) filter = userService.getFilter(); else filter = vm.filter; filter.selectedIds=ids; if (vm.filteredView) { utilsSvc.showForever('Generazione in corso...'); DisposizioniBonifici.ExportFiltered({}, filter).$promise.then(function(data) { utilsSvc.downloadFile('attachment/csv', data.response, 'export.csv'); utilsSvc.cancelMessage(); }).catch(function(err){ if (err.status==404) { utilsSvc.cancelMessage(); utilsSvc.showMessage('Nessuna disposizione estratta'); } else utilsSvc.handleHttpError(err); }); } else { utilsSvc.showForever('Generazione in corso...'); DisposizioniBonifici.Export({}, filter).$promise .then(function(data) { utilsSvc.downloadFile('attachment/csv', data.response, 'export.csv'); utilsSvc.cancelMessage(); }).catch(function(err){ if (err.status==404) { utilsSvc.cancelMessage(); utilsSvc.showMessage('Nessuna disposizione estratta'); } else utilsSvc.handleHttpError(err); }); } } vm.infiniteItems = { numLoaded_ : 0, toLoad_ : 0, loading_ : false, lastStartIdx : -1, listPromise : null, canceler : $q.defer(), // Required. getItemAtIndex : function(index) { if (vm.maxItems == 0 || index>vm.maxItems) return null; if (!vm.infiniteItems.loading_) if (index > vm.records.length) { this.fetchMoreItems_(index); return null; } return vm.records[index]; }, // Required. // For infinite scroll behavior, we always return a // slightly // higher // number than the previously loaded items. getLength : function() { return vm.maxItems; }, fetchMoreItems_ : function(index) { if (vm.infiniteItems.toLoad_ < index) { vm.infiniteItems.toLoad_ += vm.itemsPerPage; utilsSvc.showWaitMessage('Ricerca in corso...'); vm.infiniteItems.loading_ = true; if ((vm.records.length + vm.itemsPerPage) < vm.selectedIndex) vm.itemsPerPage = vm.selectedIndex - vm.records.length; if (vm.filteredView) { var args = { filtroRicerca : userService.getFilter(), filtro : vm.filter }; this.listPromise = DisposizioniBonifici .Filter( { start : vm.records.length, size : Math .max( vm.records.length + index, vm.itemsPerPage), orderField : vm.filter.orderField }, args).$promise; } else this.listPromise = DisposizioniBonifici .List({ start : vm.records.length, size : Math.max( vm.records.length + index, vm.itemsPerPage) }, vm.filter).$promise; var mod = this; this.listPromise.then(function(data) { vm.infiniteItems.loading_ = false; vm.infiniteItems.toLoad_=0; utilsSvc.cancelWaitMessage(); vm.records = vm.records.concat(data); mod.numLoaded_ = vm.records.length; mod.lastStartIdx = vm.records.length; vm.topIndex = vm.selectedIndex; }, function(error) { vm.infiniteItems.loading_ = false; vm.infiniteItems.toLoad_=0; utilsSvc.handleHttpError(error); }) } } } vm.getDisposizioni = function() { utilsSvc.showWaitMessage('Ricerca in corso...'); vm.filter.selectedIds=[]; if (vm.filteredView) { var args = { filtroRicerca : userService.getFilter(), filtro : vm.filter }; DisposizioniBonifici.CountFiltered({}, args, function(data) { vm.records = []; vm.maxItems = data.value; vm.infiniteItems.numLoaded_ = 0; vm.infiniteItems.toLoad_ = 0; utilsSvc.cancelWaitMessage(); if (data.value==0 && vm.filteredView) { utilsSvc.showMessage('Nessuna disposizione estratta'); $window.history.back(); } }, function(error) { utilsSvc.cancelWaitMessage(); utilsSvc.handleHttpError(error); }); } else DisposizioniBonifici.Count(vm.filter, function(data) { vm.records = []; vm.maxItems = data.value; vm.infiniteItems.numLoaded_ = 0; vm.infiniteItems.toLoad_ = 0; utilsSvc.cancelWaitMessage(); }, function(error) { utilsSvc.cancelWaitMessage(); utilsSvc.handleHttpError(error); }); } vm.getEsitoIcon = function(esito) { if (esito === '1') return "fa-clear"; else if (esito === '2') return 'fa-times'; } vm.ricercaDisposizioni = function(ev) { $mdDialog.show({ templateUrl : 'templates/filtroDisposizioni.html', controller : 'filtroDisposizioniCtrl', targetEvent : ev, locals : { filter : vm.filter } }).then(function(args) { vm.filteredView = false; // dialog confirmed vm.filter = args; vm.getDisposizioni(); }, function() { }); } vm.mostraDisposizione = function(idx, ev) { if (typeof vm.records == "undefined" || typeof vm.records[idx] == "undefined") return vm.selectedIndex = idx; // disposizione.importo = // parseFloat(disposizione.importo.replace(",",".")); DisposizioniBonifici.Get({ id : vm.records[idx].id }).$promise .then( function(res) { var disposizione = res; $mdDialog .show( { templateUrl : 'templates/dettaglioDisposizioneSCT.html', controller : 'dettaglioDisposizioneSctCtrl', targetEvent : ev, locals : { label: (utilsSvc.largeScreen()?'Dettaglio disposizione DOM': 'DOM'), disposizione : angular.copy(disposizione), appVariables : vm.appVariables } }) .then(function(args) { vm.initFilter(); vm.getDisposizioni(); }, function() { }); }, function(err) { utilsSvc.handleHttpError(err); }); } vm.key = function($event) { console.log($event.keyCode); if ($event.keyCode == 38) if (vm.selectedIndex > 0) vm.selectedIndex--; else if ($event.keyCode == 40) if (vm.selectedIndex < vm.maxItems) vm.selectedIndex++; } vm.init = function() { UserManager.AppVariables().$promise .then(function(data) { vm.appVariables = data; if (vm.filter.tipoChiamata == 'FiltroDisposizioni' || vm.filter.tipoChiamata == 'FiltroDisposizioniReadOnly' || vm.filter.tipoChiamata == 'DistinteBanca') { vm.abilitaFirma = vm.appVariables.profiloLocale == "DF"; } }); vm.getDisposizioni(); } vm.init(); });