Commit 65e7ac5fe53fda95fd89f8f0bf1b67f14a7aaae4
1 parent
ad8946fa4c
Exists in
master
and in
1 other branch
formateo codigo
Showing
1 changed file
with
14 additions
and
20 deletions
Show diff stats
src/js/controller-general-unidad.js
| 1 | angular.module('focaModalInforme') | 1 | angular.module('focaModalInforme') |
| 2 | .controller('focaModalInformeGeneralUnidadController', | 2 | .controller('focaModalInformeGeneralUnidadController', |
| 3 | [ | 3 | [ |
| 4 | '$filter', | 4 | '$filter', |
| 5 | '$scope', | 5 | '$scope', |
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
| 7 | 'focaModalInformeGeneralUnidadService', | 7 | 'focaModalInformeGeneralUnidadService', |
| 8 | 'i18nService', | 8 | 'i18nService', |
| 9 | 'focaModalService', | 9 | 'focaModalService', |
| 10 | function($filter, $scope, $uibModalInstance, | 10 | function($filter, $scope, $uibModalInstance, |
| 11 | focaModalInformeGeneralUnidadService, i18nService, focaModalService | 11 | focaModalInformeGeneralUnidadService, i18nService, focaModalService |
| 12 | ) { | 12 | ) { |
| 13 | i18nService.setCurrentLang('es'); | 13 | i18nService.setCurrentLang('es'); |
| 14 | var fecha = new Date(); | 14 | var fecha = new Date(); |
| 15 | $scope.generando = false; | 15 | $scope.generando = false; |
| 16 | $scope.buscar = true; | 16 | $scope.buscar = true; |
| 17 | $scope.informe = {}; | 17 | $scope.informe = {}; |
| 18 | $scope.params = { | 18 | $scope.params = { |
| 19 | fechaHasta: new Date(), | 19 | fechaHasta: new Date(), |
| 20 | fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)), | 20 | fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)), |
| 21 | sector: undefined, | 21 | sector: undefined, |
| 22 | diferenciarProductos: false, | 22 | diferenciarProductos: false, |
| 23 | detallarPorMes: false | 23 | detallarPorMes: false |
| 24 | }; | 24 | }; |
| 25 | $scope.gridOptions = { | 25 | $scope.gridOptions = { |
| 26 | enableGridMenu: true, | 26 | enableGridMenu: true, |
| 27 | exporterMenuCsv: false, | 27 | exporterMenuCsv: false, |
| 28 | exporterPdfPageSize: 'A4', | 28 | exporterPdfPageSize: 'A4', |
| 29 | exporterPdfFooter: function (currentPage, pageCount) { | 29 | exporterPdfFooter: function (currentPage, pageCount) { |
| 30 | return { | 30 | return { |
| 31 | columns: [ | 31 | columns: [ |
| 32 | {text: $filter('date')(new Date(), 'dd/MM/yyyy'), | 32 | {text: $filter('date')(new Date(), 'dd/MM/yyyy'), |
| 33 | margin: [40, 0]}, | 33 | margin: [40, 0]}, |
| 34 | {text: currentPage + ' de ' + pageCount, | 34 | {text: currentPage + ' de ' + pageCount, |
| 35 | margin: [28, 0], alignment: 'right'} | 35 | margin: [28, 0], alignment: 'right'} |
| 36 | ] | 36 | ] |
| 37 | }; | 37 | }; |
| 38 | }, | 38 | }, |
| 39 | columnDefs: [ | 39 | columnDefs: [ |
| 40 | { | 40 | { |
| 41 | field: 'vehiculo', | 41 | field: 'vehiculo', |
| 42 | enableSorting: false, | 42 | enableSorting: false, |
| 43 | cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { | 43 | cellClass: function(grid, row, col) { |
| 44 | if (grid.getCellValue(row,col).indexOf('Sector:') !== -1) | 44 | if (grid.getCellValue(row,col).indexOf('Sector:') !== -1) |
| 45 | return 'yellow w-100'; | 45 | return 'yellow w-100'; |
| 46 | if (grid.getCellValue(row,col).indexOf('Producto:') !== -1) | 46 | if (grid.getCellValue(row,col).indexOf('Producto:') !== -1) |
| 47 | return 'red w-100'; | 47 | return 'red w-100'; |
| 48 | if (grid.getCellValue(row,col).indexOf('Mes:') !== -1) | 48 | if (grid.getCellValue(row,col).indexOf('Mes:') !== -1) |
| 49 | return 'green w-100'; | 49 | return 'green w-100'; |
| 50 | } | 50 | } |
| 51 | }, | 51 | }, |
| 52 | { | 52 | { |
| 53 | field: 'kmRecorridos', | 53 | field: 'kmRecorridos', |
| 54 | enableSorting: false, | 54 | enableSorting: false, |
| 55 | cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { | 55 | cellClass: function(grid, row, col) { |
| 56 | if (!grid.getCellValue(row,col)) | 56 | if (!grid.getCellValue(row,col)) |
| 57 | return 'd-none'; | 57 | return 'd-none'; |
| 58 | } | 58 | } |
| 59 | }, | 59 | }, |
| 60 | { | 60 | { |
| 61 | field: 'litrosRepartidos', | 61 | field: 'litrosRepartidos', |
| 62 | enableSorting: false, | 62 | enableSorting: false, |
| 63 | cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { | 63 | cellClass: function(grid, row, col) { |
| 64 | if (!grid.getCellValue(row,col)) | 64 | if (!grid.getCellValue(row,col)) |
| 65 | return 'd-none'; | 65 | return 'd-none'; |
| 66 | } | 66 | } |
| 67 | }, | 67 | }, |
| 68 | { | 68 | { |
| 69 | field: 'viajes', | 69 | field: 'viajes', |
| 70 | enableSorting: false, | 70 | enableSorting: false, |
| 71 | cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { | 71 | cellClass: function(grid, row, col) { |
| 72 | if (!grid.getCellValue(row,col)) | 72 | if (!grid.getCellValue(row,col)) |
| 73 | return 'd-none'; | 73 | return 'd-none'; |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | ] | 76 | ] |
| 77 | }; | 77 | }; |
| 78 | $scope.generarInforme = function() { | 78 | $scope.generarInforme = function() { |
| 79 | $scope.generando = true; | 79 | $scope.generando = true; |
| 80 | focaModalInformeGeneralUnidadService | 80 | focaModalInformeGeneralUnidadService |
| 81 | .getInformeData($scope.params) | 81 | .getInformeData($scope.params) |
| 82 | .then(function(res) { | 82 | .then(function(res) { |
| 83 | console.log(res); | ||
| 84 | var result = []; | 83 | var result = []; |
| 85 | 84 | ||
| 86 | res.data.forEach(function(sector) { | 85 | res.data.forEach(function(sector) { |
| 87 | if (!$scope.params.sector || | 86 | if (!$scope.params.sector || |
| 88 | $scope.params.sector.ID === sector.idSector) { | 87 | $scope.params.sector.ID === sector.idSector) { |
| 88 | //AGREGO SECTORES | ||
| 89 | result.push({ | 89 | result.push({ |
| 90 | vehiculo: 'Sector: ' + | 90 | vehiculo: 'Sector: ' + |
| 91 | $filter('rellenarDigitos')(sector.idSector, 2, '0') + | 91 | $filter('rellenarDigitos')(sector.idSector, 2, '0') + |
| 92 | ' - ' + sector.sector.trim() | 92 | ' - ' + sector.sector.trim() |
| 93 | }); | 93 | }); |
| 94 | sector.productos.forEach(function(producto) { | 94 | sector.productos.forEach(function(producto) { |
| 95 | //AGREGO PRODUCTOS | ||
| 95 | result.push({ | 96 | result.push({ |
| 96 | vehiculo: 'Producto: ' + | 97 | vehiculo: 'Producto: ' + |
| 97 | producto.idProducto + | 98 | producto.idProducto + |
| 98 | ' - ' + producto.producto | 99 | ' - ' + producto.producto |
| 99 | }); | 100 | }); |
| 100 | producto.fechas.forEach(function(fecha) { | 101 | producto.fechas.forEach(function(fecha) { |
| 102 | //AGREGO FECHAS | ||
| 101 | result.push({ | 103 | result.push({ |
| 102 | vehiculo: 'Mes: ' + fecha.fecha | 104 | vehiculo: 'Mes: ' + fecha.fecha |
| 103 | }); | 105 | }); |
| 104 | fecha.vehiculos.forEach(function(vehiculo) { | 106 | fecha.vehiculos.forEach(function(vehiculo) { |
| 107 | //AGREGO VEHICULOS | ||
| 105 | result.push({ | 108 | result.push({ |
| 106 | vehiculo: vehiculo.vehiculo, | 109 | vehiculo: vehiculo.vehiculo, |
| 107 | kmRecorridos: $filter('number')(vehiculo.data.kms, 2), | 110 | kmRecorridos: |
| 108 | litrosRepartidos: $filter('number')(vehiculo.data.lts, 2), | 111 | $filter('number')(vehiculo.data.kms, 2), |
| 109 | viajes: $filter('number')(vehiculo.data.viajes, 0) | 112 | litrosRepartidos: |
| 113 | $filter('number')(vehiculo.data.lts, 2), | ||
| 114 | viajes: | ||
| 115 | $filter('number')(vehiculo.data.viajes, 0) | ||
| 110 | }); | 116 | }); |
| 111 | }); | 117 | }); |
| 112 | }); | 118 | }); |
| 113 | }); | 119 | }); |
| 114 | } | 120 | } |
| 115 | }); | 121 | }); |
| 116 | 122 | ||
| 117 | |||
| 118 | $scope.gridOptions.data = result; | 123 | $scope.gridOptions.data = result; |
| 119 | $scope.generando = false; | 124 | $scope.generando = false; |
| 120 | $scope.buscar = false; | 125 | $scope.buscar = false; |
| 121 | }); | 126 | }); |
| 122 | }; | 127 | }; |
| 123 | 128 | ||
| 124 | $scope.seleccionarSector = function(key) { | 129 | $scope.seleccionarSector = function(key) { |
| 125 | if (key === 13) { | 130 | if (key === 13) { |
| 126 | var parametrosModal = { | 131 | var parametrosModal = { |
| 127 | titulo: 'Búsqueda de Sector', | 132 | titulo: 'Búsqueda de Sector', |
| 128 | query: '/sector', | 133 | query: '/sector', |
| 129 | columnas: [ | 134 | columnas: [ |
| 130 | { | 135 | { |
| 131 | nombre: 'Código', | 136 | nombre: 'Código', |
| 132 | propiedad: 'ID' | 137 | propiedad: 'ID' |
| 133 | }, | 138 | }, |
| 134 | { | 139 | { |
| 135 | nombre: 'Nombre', | 140 | nombre: 'Nombre', |
| 136 | propiedad: 'NOMBRE' | 141 | propiedad: 'NOMBRE' |
| 137 | } | 142 | } |
| 138 | ], | 143 | ], |
| 139 | size: 'md' | 144 | size: 'md' |
| 140 | }; | 145 | }; |
| 141 | focaModalService.modal(parametrosModal).then( | 146 | focaModalService.modal(parametrosModal).then( |
| 142 | function(sector) { | 147 | function(sector) { |
| 143 | $scope.params.sector = sector; | 148 | $scope.params.sector = sector; |
| 144 | }, function() {} | 149 | }, function() {} |
| 145 | ); | 150 | ); |
| 146 | } | 151 | } |
| 147 | }; | 152 | }; |
| 148 | $scope.volver = function() { | 153 | $scope.volver = function() { |
| 149 | $scope.buscar = true; | 154 | $scope.buscar = true; |
| 150 | }; | 155 | }; |
| 151 | $scope.cancel = function() { | 156 | $scope.cancel = function() { |
| 152 | $uibModalInstance.dismiss('Cancelar'); | 157 | $uibModalInstance.dismiss('Cancelar'); |
| 153 | }; | 158 | }; |
| 154 | |||
| 155 | function agruparProductos(productos) { | ||
| 156 | console.log('productos', productos); | ||
| 157 | var result = { | ||
| 158 | vehiculos: [] | ||
| 159 | }; | ||
| 160 | productos.forEach(function(producto) { | ||
| 161 | result.vehiculos = result.vehiculos.concat(); |