diff --git a/src/js/controller-productividad.js b/src/js/controller-productividad.js new file mode 100644 index 0000000..6645f0c --- /dev/null +++ b/src/js/controller-productividad.js @@ -0,0 +1,175 @@ +angular.module('focaModalInforme') + .controller('focaModalInformeProductividadController', + [ + '$filter', + '$scope', + '$uibModalInstance', + 'focaModalInformeProductividadService', + 'i18nService', + 'focaModalService', + function($filter, $scope, $uibModalInstance, + focaModalInformeProductividadService, i18nService, focaModalService + ) { + i18nService.setCurrentLang('es'); + var fecha = new Date(); + $scope.generando = false; + $scope.buscar = true; + $scope.informe = {}; + $scope.params = { + fechaHasta: new Date(), + fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)), + sector: undefined, + diferenciarProductos: false, + diferenciarMeses: false + }; + $scope.gridOptions = { + enableGridMenu: true, + exporterMenuCsv: false, + exporterPdfPageSize: 'A4', + exporterPdfFooter: function (currentPage, pageCount) { + return { + columns: [ + {text: $filter('date')(new Date(), 'dd/MM/yyyy'), + margin: [40, 0]}, + {text: currentPage + ' de ' + pageCount, + margin: [28, 0], alignment: 'right'} + ] + }; + }, + columnDefs: [ + { + field: 'cliente', + enableSorting: false, + cellClass: function(grid, row, col) { + var value = grid.getCellValue(row,col); + + if (value.indexOf('Vendedores') !== -1 || + value.indexOf('Cobradores') !== -1 || + value.indexOf('Transportistas') !== -1) + return 'yellow w-100'; + if (value.indexOf('Vendedor:') !== -1 || + value.indexOf('Cobrador:') !== -1 || + value.indexOf('Transportista:') !== -1) + return 'red w-100'; + if (value.indexOf('Fecha:') !== -1) + return 'green w-100'; + } + }, + { + field: 'fecha', + enableSorting: false, + cellClass: function(grid, row, col) { + if (!grid.getCellValue(row,col)) + return 'd-none'; + } + }, + { + field: 'kmRecorridos', + enableSorting: false, + cellClass: function(grid, row, col) { + if (!grid.getCellValue(row,col)) + return 'd-none'; + } + }, + { + field: 'geolocalizacion', + enableSorting: false, + cellClass: function(grid, row, col) { + if (!grid.getCellValue(row,col)) + return 'd-none'; + } + } + ] + }; + $scope.generarInforme = function() { + //$scope.generando = true; + focaModalInformeProductividadService + .getInformeData($scope.params) + .then(function(res) { + var result = []; + console.log(res); + if (true) { + result.push({ + cliente: 'Vendedores' + }); + res.data.vendedores.forEach(function(vendedor) { + result.push({ + cliente: 'Vendedor: ' + vendedor.NOM + }); + vendedor.notasPedido.forEach(function(notaPedido) { + var seguimiento = notaPedido.seguimiento; + result.push({ + cliente: notaPedido.cliente.NOM, + fecha: seguimiento ? $filter('date')(seguimiento.fecha) : $filter('date')(notaPedido.fechaCarga), + kmRecorridos: seguimiento ? $filter('number')(seguimiento.kmRecorridos || 0, 2) : $filter('number')(0, 2), + geolocalizacion: seguimiento ? seguimiento.latitud + ', ' + seguimiento.longitud : '' + }); + }); + }); + } + if (true) { + result.push({ + cliente: 'Cobradores' + }); + res.data.cobradores.forEach(function(cobrador) { + result.push({ + cliente: 'Cobrador: ' + cobrador.NOM + }); + cobrador.cobranzas.forEach(function(cobranza) { + var seguimiento = cobranza.seguimiento; + result.push({ + cliente: cobranza.cliente.NOM, + fecha: seguimiento ? $filter('date')(seguimiento.fecha, 'dd/MM/yyyy') : $filter('date')(cobranza.FEC), + kmRecorridos: seguimiento ? $filter('number')(seguimiento.kmRecorridos || 0, 2) : $filter('number')(0, 2), + geolocalizacion: seguimiento ? seguimiento.latitud + ', ' + seguimiento.longitud : '' + }); + }); + }); + } + if (true) { + result.push({ + cliente: 'Transportistas' + }); + res.data.transportistas.forEach(function(transportista) { + result.push({ + cliente: 'Transportista: ' + transportista.NOM + }); + transportista.remitos.forEach(function(remito) { + var kms = 0, + geolocalizacion; + remito.hojaRutaMovimiento.forEach(function(movimiento) { + kms += movimiento.seguimiento.kmRecorridos || 0; + geolocalizacion = geolocalizacion || + movimiento.seguimiento.latitud + ', ' + + movimiento.seguimiento.longitud; + }); + result.push({ + cliente: remito.cliente.NOM, + fecha: $filter('date')(remito.fechaRemito, 'dd/MM/yyyy'), + kmRecorridos: $filter('number')(kms, 2), + geolocalizacion: geolocalizacion + }); + }); + }); + } + $scope.gridOptions.data = result; + $scope.generando = false; + $scope.buscar = false; + }); + }; + + + $scope.volver = function() { + $scope.buscar = true; + }; + $scope.cancel = function() { + $uibModalInstance.dismiss('Cancelar'); + }; + $scope.clearSector = function() { + $scope.params.sector = undefined; + }; + + + } + ] + ); diff --git a/src/js/service.js b/src/js/service.js index 8de1dbd..95e2955 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -76,4 +76,16 @@ angular.module('focaModalInforme') } }; } + ]) + .factory('focaModalInformeProductividadService', [ + '$http', + 'API_ENDPOINT', + function($http, API_ENDPOINT) { + return { + getInformeData: function(params) { + return $http.post(API_ENDPOINT.URL + '/informe/productividad', + {params: params}); + } + }; + } ]); diff --git a/src/views/informe-productividad.html b/src/views/informe-productividad.html new file mode 100644 index 0000000..21dc676 --- /dev/null +++ b/src/views/informe-productividad.html @@ -0,0 +1,114 @@ +