delegheSedaCtrl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. app.controller('delegheSedaCtrl',
  2. function ($scope,$mdDialog, $window, $q,$location, $cookies, $mdBottomSheet, uiGridGroupingConstants, utilsSvc, DelegheSepa, Deleghe, Banche,
  3. DisposizioniRid, DisposizioniAea, DisposizioniBonifici, userService, locals) {
  4. $scope.disposizione = locals.disposizione;
  5. $scope.tipo = locals.tipo;
  6. $scope.maxItems = 0;
  7. $scope.itemsPerPage = 1000;
  8. $scope.selectedIndex=-1;
  9. $scope.records=[];
  10. $scope.vistaAggregatoAbi = false;
  11. $scope.lastAbi = '';
  12. $scope.ricercaInCorso = false;
  13. $scope.fromDisposizioni = false;
  14. $scope.topPosition = 0;
  15. $scope.lastIndexToRetrieve = 0;
  16. $scope.getListHeight = function() {
  17. containerHeight = ($window.innerHeight - $('#container').position().top - $('#view').position().top-85);
  18. return {'height': containerHeight + 'px'};
  19. };
  20. $scope.getGridItemHeight = function() {
  21. return utilsSvc.getGridHeight();
  22. }
  23. $window.addEventListener('resize', onResize);
  24. function onResize() {
  25. $scope.$digest();
  26. }
  27. $scope.$on('$destroy', function() {
  28. $window.removeEventListener('resize', onResize);
  29. });
  30. $scope.filterChiamante = userService.getFiltroIncassiSDD();
  31. $scope.disabilitaFiltri = function() {
  32. return $scope.filterChiamante.tipoChiamata != "Destinatari";
  33. }
  34. $scope.filteredView = false;
  35. $scope.delegheSepa = [];
  36. $scope.filter = {
  37. tipo:'0',
  38. statoDelega: '-1',
  39. cbDaDataApertura: false,
  40. daDataApertura: null,
  41. cbADataApertura: false,
  42. aDataApertura: null,
  43. cbDaDataChiusura: false,
  44. daDataChiusura: null,
  45. cbDaDataChiusura: false,
  46. aDataChiusura: null,
  47. codiceDelega: '',
  48. aggregazioneABI: false,
  49. codiceAbi: '',
  50. codiceClienteDebitore: '',
  51. idOrdinante: -1
  52. }
  53. $scope.defaultFilter = {
  54. tipo:'0',
  55. statoDelega: '-1',
  56. cbDaDataApertura: false,
  57. daDataApertura: null,
  58. cbADataApertura: false,
  59. aDataApertura: null,
  60. cbDaDataChiusura: false,
  61. daDataChiusura: null,
  62. cbDaDataChiusura: false,
  63. aDataChiusura: null,
  64. codiceDelega: '',
  65. aggregazioneABI: false,
  66. codiceAbi: '',
  67. codiceClienteDebitore: '',
  68. idOrdinante: -1
  69. }
  70. if ($scope.tipo!='')
  71. $scope.filter.tipo='0';
  72. if ($scope.tipo=="RID") {
  73. $scope.filter.codiceClienteDebitore = $scope.disposizione.codiceClienteDebitore;
  74. $scope.fromDisposizioni = true;
  75. $scope.filteredView = true;
  76. } else if ($scope.tipo=='SCT') {
  77. $scope.filter.codiceDestinatario = $scope.disposizione.codiceClienteDebitore;
  78. $scope.fromDisposizioni = true;
  79. $scope.filteredView = true;
  80. } else if ($scope.tipo=='SEDA') {
  81. $scope.filter.codiceClienteDebitore = $scope.disposizione.codiceClienteDebitore;
  82. $scope.fromDisposizioni = true;
  83. $scope.filteredView = true;
  84. }
  85. $scope.gridOptions = {
  86. enableSorting: true,
  87. columnDefs: [
  88. { name:'Abi', field: 'abi', grouping: { groupPriority: 0 } },
  89. { name:'Banca', field: 'banca'},
  90. { name:'Numero mandati', field: 'numeroMandati'},
  91. { name:'Stato', field: 'statoAllineamento'}
  92. ],
  93. data : $scope.records,
  94. enableFiltering: true,
  95. treeRowHeaderAlwaysVisible: false,
  96. onRegisterApi: function( gridApi ) {
  97. $scope.gridApi = gridApi;
  98. }
  99. };
  100. $scope.reportTotali = function(ev) {
  101. utilsSvc.showForever('Generazione in corso...');
  102. DelegheSepa.Print({},$scope.filter).$promise.then(function(data){
  103. utilsSvc.downloadFile('application/pdf',data.response,'AggregazioneDelegheSeda.pdf');
  104. utilsSvc.cancelMessage();
  105. }, function(err){
  106. utilsSvc.cancelMessage();
  107. if (error.status == 404)
  108. utilsSvc.showForever('Messuna delega estratta');
  109. else
  110. utilsSvc.handleHttpError(err);
  111. }).catch(function(err){
  112. if (err.status==404) {
  113. utilsSvc.cancelMessage();
  114. utilsSvc.showMessage('Nessuna delega estratta');
  115. } else
  116. utilsSvc.handleHttpError(err);
  117. });
  118. }
  119. $scope.exportXLS= function(ev) {
  120. utilsSvc.showForever('Generazione in corso...');
  121. DelegheSepa.Export({},$scope.filter).$promise.then(function(data){
  122. utilsSvc.downloadFile('attachment/csv',data.response,'ReportTotali.csv');
  123. utilsSvc.cancelMessage();
  124. }, function(err){
  125. utilsSvc.cancelMessage();
  126. if (error.status == 404)
  127. utilsSvc.showForever('Messuna delega estratta');
  128. else
  129. utilsSvc.handleHttpError(err);
  130. });
  131. }
  132. $scope.showCommands = function(index,$event) {
  133. $scope.selectedIndex = index;
  134. $mdBottomSheet.show({
  135. templateUrl: 'templates/bottom-sheet-template.html',
  136. controller: 'comandiDelegheSepaCtrl',
  137. idx: index,
  138. appVariables: $scope.appVariables,
  139. fromDisposizioni: $scope.fromDisposizioni,
  140. targetEvent: $event,
  141. parent:document.getElementById('dialogSeda')
  142. }).then(function(selectedCommand) {
  143. $scope.executeCommand(selectedCommand.cmdIndex, selectedCommand.recordIdx, $event);
  144. },
  145. function(){}
  146. );
  147. }
  148. $scope.executeCommand = function(cmdIndex, ndx, event) {
  149. if (cmdIndex==0)
  150. $scope.delegheSdd(ndx, event);
  151. else if (cmdIndex==1)
  152. $scope.delegheSeda(ndx, event);
  153. else if (cmdIndex==2)
  154. $scope.denominazioneBanca(ndx, event);
  155. }
  156. $scope.eseguiRicerca = function() {
  157. $scope.topPosition = 0;
  158. $scope.lastAbi = '';
  159. $scope.records = [];
  160. // $scope.filteredView = !$scope.filteredView;
  161. if (!$scope.filteredView) {
  162. $scope.filter.aggregazioneABI=false;
  163. $scope.filter=$scope.defaultFilter;
  164. }
  165. $scope.getDeleghe();
  166. }
  167. $scope.denominazioneBanca = function(ndx,ev) {
  168. Banche.GetByAbi({abi:$scope.records[ndx].abi.trim()}).$promise.then(function(data){
  169. var descrizioneBanca = data.descri;
  170. $mdDialog.show({
  171. targetEvent: ev,
  172. templateUrl: 'templates/ricercaFiliali.html',
  173. controller: 'ricercaFilialiCtrl',
  174. locals: {abi: data.abi, istituto: descrizioneBanca},
  175. multiple: true
  176. }).then(function(filiale){
  177. // non cambiare le info
  178. })
  179. });
  180. }
  181. $scope.getDeleghe = function() {
  182. if ($scope.ricercaInCorso)
  183. return;
  184. $scope.ricercaInCorso = true;
  185. utilsSvc.showForever('Ricerca in corso...');
  186. DelegheSepa.Count({}, ($scope.filteredView? $scope.filter: $scope.defaultFilter))
  187. .$promise.then(function(data){
  188. $scope.vistaAggregatoAbi = $scope.filter.aggregazioneABI;
  189. $scope.records=[];
  190. $scope.maxItems = data.value;
  191. $scope.infiniteItems.numLoaded_ = 0;
  192. $scope.infiniteItems.toLoad_ = 0;
  193. $scope.lastIndexToRetrieve = 0;
  194. if ($scope.filter.aggregazioneABI) {
  195. var listPromise = DelegheSepa.List({start: $scope.records.length,size:999999},
  196. ($scope.filteredView? $scope.filter: $scope.defaultFilter)).$promise;
  197. listPromise.then(
  198. function(data){
  199. $scope.ricercaInCorso = false;
  200. utilsSvc.cancelMessage();
  201. $scope.vistaAggregatoAbi = $scope.filter.aggregazioneABI;
  202. $scope.records = $scope.records.concat(data);
  203. $scope.gridOptions.data = data;
  204. // $scope.gridApi.grouping.clearGrouping();
  205. // $scope.gridApi.grouping.groupColumn('Abi');
  206. // $scope.gridApi.grouping.aggregateColumn('Banca', uiGridGroupingConstants.aggregation.COUNT);
  207. // $scope.gridApi.treeBase.expandAllRows();
  208. },
  209. function(error) {
  210. $scope.ricercaInCorso = false;
  211. utilsSvc.cancelMessage();
  212. utilsSvc.handleHttpError(error);
  213. }
  214. )
  215. } else {
  216. $scope.ricercaInCorso = false;
  217. if (data.value==0) {
  218. utilsSvc.cancelMessage();
  219. utilsSvc.show('Nessuna disposizione collegata alla delega');
  220. // if ($scope.filteredView)
  221. // window.close();
  222. }
  223. }
  224. });
  225. }
  226. $scope.getDeleghe();
  227. $scope.cancelDialog = function() {
  228. $mdDialog.cancel();
  229. }
  230. $scope.isEndAbiBlock=function(abi) {
  231. if ($scope.lastAbi!=abi) {
  232. $scope.lastAbi = abi;
  233. return true;
  234. }
  235. return false;
  236. }
  237. $scope.delegheSdd = function(ndx, ev){
  238. var filtro = userService.newFilter();
  239. filtro.codiceClienteDebitore = $scope.records[ndx].codiceDestinatario;
  240. filtro.tipoChiamata = 'FiltroDisposizioniReadOnly';
  241. DisposizioniRid.Count(filtro,
  242. function(data){
  243. if (data.value>0) {
  244. localStorage.setItem("filter", JSON.stringify(filtro));
  245. $window.open('#/incassiSDD','_blank');
  246. }
  247. else
  248. utilsSvc.showMessage('Nessuna disposizione collegata alla delega');
  249. }
  250. );
  251. }
  252. $scope.delegheSeda = function(ndx, ev){
  253. var filtro = userService.newFilter();
  254. filtro.codiceClienteDebitore = $scope.records[ndx].codiceDestinatario;
  255. filtro.tipoChiamata = 'FiltroDisposizioniReadOnly';
  256. DisposizioniAea.Count(filtro,
  257. function(data){
  258. if (data.value>0) {
  259. localStorage.setItem("filter", JSON.stringify(filtro));
  260. $window.open('#/allineamentoSEDA','_blank');
  261. }
  262. else
  263. utilsSvc.showMessage('Nessuna disposizione collegata alla delega');
  264. }
  265. );
  266. }
  267. $scope.decodeTipoDestinatario = function(tipoDestinatario){
  268. var res ="";
  269. switch (tipoDestinatario) {
  270. case "1":
  271. return "Utenza";
  272. case "2":
  273. return "Matricola";
  274. case "3":
  275. return "Codice fiscale";
  276. case "4":
  277. return "Codice cliente";
  278. case "5":
  279. return "Codice fornitore";
  280. case "6":
  281. return "Portafoglio commerciale"
  282. case "9":
  283. return "Altri";
  284. default:
  285. return "Altri";
  286. }
  287. }
  288. $scope.decodeStato = function(stato) {
  289. switch (stato) {
  290. case "0":
  291. return "In attesa di esito";
  292. case "1":
  293. return "Attiva";
  294. case "2":
  295. return "Non attiva";
  296. case "6":
  297. return "Attivata SDD";
  298. }
  299. }
  300. $scope.infiniteItems = {
  301. numLoaded_: 0,
  302. toLoad_: 0,
  303. loading_:false,
  304. listPromise:null,
  305. canceler: $q.defer(),
  306. // Required.
  307. getItemAtIndex: function(index) {
  308. if ($scope.maxItems==0 || index>$scope.maxItems)
  309. return null;
  310. if (!$scope.infiniteItems.loading_)
  311. if (index > $scope.records.length) {
  312. this.fetchMoreItems_(index);
  313. return null;
  314. }
  315. return $scope.records [index];
  316. },
  317. // Required.
  318. // For infinite scroll behavior, we always return a slightly
  319. // higher
  320. // number than the previously loaded items.
  321. getLength: function() {
  322. return $scope.maxItems;
  323. },
  324. fetchMoreItems_: function(index) {
  325. if (this.toLoad_ < index) {
  326. this.toLoad_ += $scope.itemsPerPage;
  327. $scope.infiniteItems.loading_ = true;
  328. //this.listPromise = DelegheSepa.List({start: index,size:$scope.itemsPerPage},
  329. this.listPromise = DelegheSepa.List({start: $scope.records.length,size:$scope.itemsPerPage}, //Math.max($scope.records.length+index,$scope.itemsPerPage)},
  330. ($scope.filteredView? $scope.filter: $scope.defaultFilter)).$promise;
  331. var mod=this;
  332. this.listPromise.then(
  333. function(data){
  334. $scope.infiniteItems.loading_ = false;
  335. utilsSvc.cancelMessage();
  336. $scope.vistaAggregatoAbi = $scope.filter.aggregazioneABI;
  337. $scope.records = $scope.records.concat(data);
  338. mod.numLoaded_ = $scope.records.length;
  339. },
  340. function(error) {
  341. $scope.infiniteItems.loading_ = false;
  342. utilsSvc.cancelMessage();
  343. utilsSvc.handleHttpError(error);
  344. }
  345. )
  346. }
  347. }
  348. }
  349. })
  350. .controller('comandiDelegheSepaCtrl', function($scope, $mdBottomSheet, idx, appVariables, fromDisposizioni) {
  351. $scope.title = 'Comandi';
  352. $scope.items = [
  353. { id:0, name: "SDD", icon: 'fa-folder-open', visible: true },
  354. { id:1, name: "Seda", icon: 'fa-folder-open',visible: true },
  355. { id:2, name: "Denom. Banca", icon: 'fa-bank',visible: true }
  356. ];
  357. if (fromDisposizioni) {
  358. $scope.items[0].visible = false;
  359. $scope.items[1].visible = false;
  360. }
  361. $scope.listItemClick = function($index, $event) {
  362. var clickedItem = $scope.items[$index];
  363. var result = {cmdIndex: $index, recordIdx: idx, event:$event}
  364. $mdBottomSheet.hide(result);
  365. };
  366. $scope.dismissBottomSheet = function() {
  367. $mdBottomSheet.cancel();
  368. }
  369. })