reportPagamentiCtrl.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. app.controller('reportPagamentiCtrl',
  2. function($scope, $http, $cookies, $window, $location, $timeout,
  3. $mdDialog, $q, $routeParams, $mdMedia, utilsSvc,
  4. userService, ReportPagamenti, UserManager,
  5. Upload) {
  6. var vm = this;
  7. vm.maxItems = 0;
  8. vm.itemsPerPage = 100;
  9. vm.records = [];
  10. vm.selectedIndex = -1;
  11. vm.topIndex = 0;
  12. vm.appVariables = {};
  13. vm.showDetails=function(record){
  14. $mdDialog.show({
  15. templateUrl: 'templates/dettaglioReportPagamenti.html',
  16. controller: 'dettaglioRecordPagamentiCtrl',
  17. targetEvent: event,
  18. locals: {report:record},
  19. multiple: true
  20. })
  21. }
  22. vm.columnWidths = [
  23. "140px", // 0
  24. "350px", // 1
  25. "350px", // 2
  26. "250px", // 3
  27. "150px", // 4
  28. "140px", // 5
  29. "140px", // 6
  30. ];
  31. vm.getColumnWidth = // }
  32. // this.lastStartIdx = index;
  33. function(idx) {
  34. return {
  35. 'width' : vm.columnWidths[idx] + 'px',
  36. 'min-width' : vm.columnWidths[idx] + 'px',
  37. // 'padding-left':'6px',
  38. // 'padding-right':'6px',
  39. 'margin-left' : '8px',
  40. 'margin-right' : '8px'
  41. };
  42. }
  43. vm.getListHeight = function() {
  44. containerHeight = ($window.innerHeight
  45. - $('#container').position().top - $('#view')
  46. .position().top);
  47. return {
  48. 'height' : containerHeight + 'px'
  49. };
  50. };
  51. vm.getGridItemHeight = function() {
  52. return utilsSvc.getGridHeight();
  53. }
  54. vm.trimData=function(str){
  55. if (str==null)
  56. return "";
  57. return str.substring(0,500);
  58. }
  59. $window.addEventListener('resize', onResize);
  60. function onResize() {
  61. $scope.$digest();
  62. }
  63. $scope.$on('$destroy', function() {
  64. $window.removeEventListener('resize', onResize);
  65. });
  66. $timeout(function() {
  67. var evt = $window.document.createEvent('UIEvents');
  68. evt.initUIEvent('resize', true, false, $window, 0);
  69. $window.dispatchEvent(evt);
  70. },100);
  71. vm.largeScreen = function() {
  72. return utilsSvc.largeScreen();
  73. }
  74. vm.uploadFile = function(file, errFiles) {
  75. $scope.f = file;
  76. $scope.errFile = errFiles && errFiles[0];
  77. if (file) {
  78. file.upload = Upload.upload({
  79. url: 'rest/reportPagamenti/uploadFile',
  80. data: {file: file}
  81. });
  82. file.upload.then(function (response) {
  83. file.result = response.data;
  84. vm.getDisposizioni();
  85. }, function (response) {
  86. if (response.status > 0)
  87. vm.errorMsg = response.status + ': ' + response.data;
  88. utilsSvc.showMessage('Si è verificato un errore durante il caricamento: '+ response.status + ': ' + response.data);
  89. }, function (evt) {
  90. file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
  91. });
  92. }
  93. }
  94. vm.getColumnWidth = function(idx) {
  95. return {
  96. 'width' : vm.columnWidths[idx] ,
  97. 'min-width' : vm.columnWidths[idx],
  98. // 'padding-left':'6px',
  99. // 'padding-right':'6px',
  100. 'margin-left' : '8px',
  101. 'margin-right' : '8px'
  102. };
  103. }
  104. vm.getMaxListWidth = function() {
  105. // var res = 0;
  106. // for (var i = 0; i < vm.columnWidths.length; i++)
  107. // res += vm.columnWidths[i] + 6 + 8 + 10;
  108. //
  109. // $('#container').css('width',
  110. // ($('#header').width() + 10) + 'px');
  111. // return {
  112. // 'width' : res + 'px!important;'
  113. // }
  114. }
  115. vm.setOrderField = function(field) {
  116. if (vm.filter.orderField != field)
  117. vm.filter.orderField = field;
  118. else
  119. vm.filter.orderField = "-" + field;
  120. vm.getDisposizioni();
  121. }
  122. vm.downloadFile = function(serviceUI) {
  123. utilsSvc.showForever('Generazione in corso...');
  124. ReportPagamenti.Download({id:serviceUI.idServiceUI}).$promise.then(function(data){
  125. utilsSvc.downloadFile('file/text',data.response,serviceUI.filenameOut);
  126. utilsSvc.cancelMessage();
  127. }).catch(function(err){
  128. if (err.status==404) {
  129. utilsSvc.cancelMessage();
  130. utilsSvc.showMessage('Nessun file estratto');
  131. }
  132. });
  133. }
  134. vm.exportExcel = function() {
  135. if (vm.filteredView) {
  136. utilsSvc.showForever('Generazione in corso...');
  137. DisposizioniBonifici.ExportFiltered({}, userService
  138. .getFilter()).$promise.then(function(data) {
  139. utilsSvc.downloadFile('attachment/csv',
  140. data.response, 'export.csv');
  141. utilsSvc.cancelMessage();
  142. }).catch(function(err){
  143. if (err.status==404) {
  144. utilsSvc.cancelMessage();
  145. utilsSvc.showMessage('Nessuna distinta estratta');
  146. }
  147. })
  148. } else {
  149. utilsSvc.showForever('Generazione in corso...');
  150. DisposizioniBonifici.Export({}, vm.filter).$promise
  151. .then(function(data) {
  152. utilsSvc.downloadFile('attachment/csv',
  153. data.response, 'export.csv');
  154. utilsSvc.cancelMessage();
  155. }).catch(function(err){
  156. if (err.status==404) {
  157. utilsSvc.cancelMessage();
  158. utilsSvc.showMessage('Nessuna distinta estratta');
  159. }
  160. })
  161. }
  162. }
  163. vm.infiniteItems = {
  164. numLoaded_ : 0,
  165. toLoad_ : 0,
  166. loading_ : false,
  167. lastStartIdx : -1,
  168. listPromise : null,
  169. canceler : $q.defer(),
  170. // Required.
  171. getItemAtIndex : function(index) {
  172. if (vm.maxItems == 0 || index>vm.maxItems)
  173. return null;
  174. if (!vm.infiniteItems.loading_)
  175. if (index > vm.records.length) {
  176. vm.infiniteItems.fetchMoreItems_(index);
  177. return null;
  178. }
  179. return vm.records[index];
  180. },
  181. // Required.
  182. // For infinite scroll behavior, we always return a
  183. // slightly
  184. // higher
  185. // number than the previously loaded items.
  186. getLength : function() {
  187. return vm.maxItems;
  188. },
  189. fetchMoreItems_ : function(index) {
  190. if (this.toLoad_ < index) {
  191. this.toLoad_ += vm.itemsPerPage;
  192. utilsSvc.showWaitMessage('Ricerca in corso...');
  193. vm.infiniteItems.loading_ = true;
  194. if ((vm.records.length + vm.itemsPerPage) < vm.selectedIndex)
  195. vm.itemsPerPage = vm.selectedIndex - vm.records.length;
  196. this.listPromise = ReportPagamenti.List({start : vm.records.length,size : Math.max(vm.records.length+ index,vm.itemsPerPage)}, vm.filter).$promise;
  197. var mod = this;
  198. this.listPromise.then(function(data) {
  199. vm.infiniteItems.loading_ = false;
  200. vm.infiniteItems.toLoad_=0;
  201. utilsSvc.cancelWaitMessage();
  202. vm.records = vm.records.concat(data);
  203. mod.numLoaded_ = vm.records.length;
  204. mod.lastStartIdx = vm.records.length;
  205. vm.topIndex = vm.selectedIndex;
  206. }, function(error) {
  207. vm.infiniteItems.loading_ = false;
  208. vm.infiniteItems.toLoad_=0;
  209. utilsSvc.handleHttpError(error);
  210. })
  211. }
  212. }
  213. }
  214. vm.getDisposizioni = function() {
  215. utilsSvc.showWaitMessage('Ricerca in corso...');
  216. ReportPagamenti.Count({},
  217. function(data) {
  218. vm.records = [];
  219. vm.maxItems = data.value;
  220. vm.infiniteItems.numLoaded_ = 0;
  221. vm.infiniteItems.toLoad_ = 0;
  222. utilsSvc.cancelWaitMessage();
  223. }, function(error) {
  224. utilsSvc.cancelWaitMessage();
  225. utilsSvc.handleHttpError(error);
  226. });
  227. }
  228. vm.getEsitoIcon = function(esito) {
  229. if (esito === '1')
  230. return "fa-clear";
  231. else if (esito === '2')
  232. return 'fa-times';
  233. }
  234. vm.init = function() {
  235. UserManager.AppVariables().$promise
  236. .then(function(data) {
  237. vm.appVariables = data;
  238. });
  239. vm.getDisposizioni();
  240. }
  241. vm.init();
  242. });
  243. app.controller('dettaglioRecordPagamentiCtrl',
  244. function ($scope,$mdDialog,utilsSvc, locals) {
  245. $scope.report = locals.report;
  246. $scope.confirmDialog = function() {
  247. $mdDialog.hide($scope.disposizione);
  248. }
  249. $scope.cancelDialog = function() {
  250. $mdDialog.cancel();
  251. }
  252. $scope.largeScreen = function() {
  253. return utilsSvc.largeScreen();
  254. }
  255. $scope.formattaReport=function(report){
  256. return report.replace(/(?:\r\n|\r|\n)/g, '<br>');
  257. }
  258. });