Commit 841b92ce6c4ffec76ec168dad3751aac10b85b21
Exists in
master
and in
2 other branches
Merge branch 'master' into 'develop'
Master(mpuebla) See merge request !24
Showing
2 changed files
Show diff stats
src/js/controller.js
| 1 | angular.module('focaHojaRuta') | 1 | angular.module('focaHojaRuta') |
| 2 | .controller('listaHojaRutaCtrl', | 2 | .controller('listaHojaRutaCtrl', |
| 3 | [ | 3 | [ |
| 4 | '$scope', '$location', '$filter', '$uibModal', 'hojaRutaService', | 4 | '$scope', '$location', '$filter', '$uibModal', 'hojaRutaService', |
| 5 | 'focaLoginService', 'focaModalService', '$rootScope', '$localStorage', | 5 | 'focaLoginService', 'focaModalService', '$rootScope', '$localStorage', |
| 6 | function ($scope, $location, $filter, $uibModal, hojaRutaService, | 6 | function ($scope, $location, $filter, $uibModal, hojaRutaService, |
| 7 | focaLoginService, focaModalService, $rootScope, $localStorage) { | 7 | focaLoginService, focaModalService, $rootScope, $localStorage) { |
| 8 | 8 | ||
| 9 | var loginData = focaLoginService.getLoginData(); | 9 | var loginData = focaLoginService.getLoginData(); |
| 10 | config(); | 10 | config(); |
| 11 | init(); | 11 | init(); |
| 12 | function config() { | 12 | function config() { |
| 13 | $scope.cabecera = []; | 13 | $scope.cabecera = []; |
| 14 | $scope.showCabecera = true; | 14 | $scope.showCabecera = true; |
| 15 | $scope.now = new Date(); | 15 | $scope.now = new Date(); |
| 16 | $scope.puntoVenta = '0000'; | 16 | $scope.puntoVenta = '0000'; |
| 17 | $scope.comprobante = '00000000'; | 17 | $scope.comprobante = '00000000'; |
| 18 | } | 18 | } |
| 19 | function init() { | 19 | function init() { |
| 20 | hojaRutaService.getHojaRuta(loginData.chofer) | 20 | hojaRutaService.getHojaRuta(loginData.chofer) |
| 21 | .then(function (res) { | 21 | .then(function (res) { |
| 22 | if (res.data) { | 22 | console.log(res.data); |
| 23 | var hojaRuta = res.data; | 23 | abrilModalHojasDeRuta(res.data); |
| 24 | }); | ||
| 25 | } | ||
| 26 | function abrilModalHojasDeRuta(hojasDeRuta) { | ||
| 27 | hojasDeRuta.forEach(function (hojaRuta) { | ||
| 28 | hojaRuta.comprobante = (hojaRuta.abierta ? 'RA ' : '') + | ||
| 29 | $filter('comprobante') | ||
| 30 | ([hojaRuta.sucursal, hojaRuta.numeroHojaRuta]); | ||
| 31 | }); | ||
| 32 | focaModalService.modal(parametrosModalHojasDeRuta(hojasDeRuta)) | ||
| 33 | .then(function (hojaRuta) { | ||
| 34 | if (hojaRuta) { | ||
| 24 | $scope.hojaRuta = hojaRuta; | 35 | $scope.hojaRuta = hojaRuta; |
| 25 | $scope.puntoVenta = hojaRuta.sucursal; | 36 | $scope.puntoVenta = hojaRuta.sucursal; |
| 26 | $scope.comprobante = hojaRuta.numeroHojaRuta; | 37 | $scope.comprobante = hojaRuta.numeroHojaRuta; |
| 27 | addCabecera('Transportista:', hojaRuta.transportista.NOM); | 38 | addCabecera('Transportista:', hojaRuta.transportista.NOM); |
| 28 | addCabecera('Chofer:', hojaRuta.chofer.nombre); | 39 | addCabecera('Chofer:', hojaRuta.chofer.nombre); |
| 29 | addCabecera('Vehículo:', hojaRuta.vehiculo.tractor); | 40 | addCabecera('Vehículo:', hojaRuta.vehiculo.tractor); |
| 41 | $localStorage.hojaRuta = JSON.stringify($scope.hojaRuta); | ||
| 30 | } else { | 42 | } else { |
| 31 | focaModalService.alert('Sin hoja de ruta asignada'); | 43 | focaModalService.alert('Sin hoja de ruta asignada'); |
| 32 | $location.path('/'); | 44 | $location.path('/'); |
| 33 | } | 45 | } |
| 34 | watch(); | 46 | // if (!$scope.estadoRed) { |
| 35 | if (!$scope.estadoRed) { | 47 | // getLSHojaRuta(); |
| 36 | getLSHojaRuta(); | 48 | // } |
| 37 | } | 49 | }) |
| 50 | .catch(function (e) { | ||
| 51 | console.info(e); | ||
| 52 | $location.path('/'); | ||
| 38 | }); | 53 | }); |
| 39 | } | 54 | } |
| 40 | function watch() { | 55 | $scope.$watch('hojaRuta', function (nuevoValor) { |
| 41 | $scope.$watch('hojaRuta', function (nuevoValor) { | 56 | $localStorage.hojaRuta = JSON.stringify(nuevoValor); |
| 42 | $localStorage.hojaRuta = JSON.stringify(nuevoValor); | 57 | }, true); |
| 43 | }, true); | ||
| 44 | } | ||
| 45 | $scope.verDetalle = function (remito) { | 58 | $scope.verDetalle = function (remito) { |
| 46 | var modalInstance = $uibModal.open( | 59 | var modalInstance = $uibModal.open( |
| 47 | { | 60 | { |
| 48 | ariaLabelledBy: 'Detalle hoja ruta', | 61 | ariaLabelledBy: 'Detalle hoja ruta', |
| 49 | templateUrl: 'modal-detalle-hoja-ruta.html', | 62 | templateUrl: 'modal-detalle-hoja-ruta.html', |
| 50 | controller: 'focaModalDetalleHojaRutaController', | 63 | controller: 'focaModalDetalleHojaRutaController', |
| 51 | resolve: { | 64 | resolve: { |
| 52 | parametros: { | 65 | parametros: { |
| 53 | remito: remito, | 66 | remito: remito, |
| 54 | } | 67 | } |
| 55 | }, | 68 | }, |
| 56 | size: 'lg' | 69 | size: 'lg' |
| 57 | } | 70 | } |
| 58 | ); | 71 | ); |
| 59 | modalInstance.result | 72 | modalInstance.result |
| 60 | .then(function (data) { | 73 | .then(function (data) { console.log(data); }) |
| 61 | //funcion se ejecuta cuando se carga pantalla | ||
| 62 | console.log(data); | ||
| 63 | }) | ||
| 64 | .catch(function (e) { console.info(e); }); | 74 | .catch(function (e) { console.info(e); }); |
| 65 | }; | 75 | }; |
| 66 | $scope.rellenar = function (relleno, longitud) { | ||
| 67 | relleno = '' + relleno; | ||
| 68 | while (relleno.length < longitud) { | ||
| 69 | relleno = '0' + relleno; | ||
| 70 | } | ||
| 71 | |||
| 72 | return relleno; | ||
| 73 | }; | ||
| 74 | $scope.salir = function () { | 76 | $scope.salir = function () { |
| 75 | $location.path('/'); | 77 | $location.path('/'); |
| 76 | }; | 78 | }; |
| 77 | $scope.terminarHojaRuta = function () { | 79 | $scope.terminarHojaRuta = function () { |
| 78 | focaModalService | 80 | focaModalService |
| 79 | .confirm('¿Desea terminar la hoja de ruta? No podra realizar ninguna ' + | 81 | .confirm('¿Desea terminar la hoja de ruta? No podra realizar ninguna ' + |
| 80 | 'otra descarga ni modificación') | 82 | 'otra descarga ni modificación') |
| 81 | .then(function () { $scope.datosExtraCierre(terminar); }); | 83 | .then(function () { $scope.datosExtraCierre(terminar); }) |
| 84 | .catch(function (e) { console.info('Modal ', e); }); | ||
| 82 | function terminar(datosExtraCierre) { | 85 | function terminar(datosExtraCierre) { |
| 83 | $scope.hojaRuta = angular.extend({}, $scope.hojaRuta, datosExtraCierre); | 86 | $scope.hojaRuta = angular.extend({}, $scope.hojaRuta, datosExtraCierre); |
| 84 | //limpio objeto para guardar | 87 | //limpio objeto para guardar |
| 85 | delete $scope.hojaRuta.chofer; | 88 | delete $scope.hojaRuta.chofer; |
| 86 | delete $scope.hojaRuta.remitos; | 89 | delete $scope.hojaRuta.remitos; |
| 87 | delete $scope.hojaRuta.transportista; | 90 | delete $scope.hojaRuta.transportista; |
| 88 | delete $scope.hojaRuta.vehiculo; | 91 | delete $scope.hojaRuta.vehiculo; |
| 89 | 92 | ||
| 90 | $scope.hojaRuta.fechaCreacion = | 93 | $scope.hojaRuta.fechaCreacion = |
| 91 | $scope.hojaRuta.fechaCreacion.slice(0, 19).replace('T', ' '); | 94 | $scope.hojaRuta.fechaCreacion.slice(0, 19).replace('T', ' '); |
| 92 | $scope.hojaRuta.fechaReparto = | 95 | $scope.hojaRuta.fechaReparto = |
| 93 | $scope.hojaRuta.fechaReparto.slice(0, 19).replace('T', ' '); | 96 | $scope.hojaRuta.fechaReparto.slice(0, 19).replace('T', ' '); |
| 94 | $scope.hojaRuta.estado = 2; | 97 | $scope.hojaRuta.estado = 2; |
| 95 | hojaRutaService.terminarHojaRuta($scope.hojaRuta).then( | 98 | hojaRutaService.terminarHojaRuta($scope.hojaRuta).then( |
| 96 | function () { | 99 | function () { |
| 97 | focaModalService.alert( | 100 | focaModalService.alert( |
| 98 | 'Hoja de ruta ' + | 101 | 'Hoja de ruta ' + |
| 99 | $filter('comprobante')([$scope.puntoVenta, | 102 | $filter('comprobante')([$scope.puntoVenta, |
| 100 | $scope.comprobante]) + ' cerrada con éxito'); | 103 | $scope.comprobante]) + ' cerrada con éxito'); |
| 101 | $location.path('/'); | 104 | $location.path('/'); |
| 102 | } | 105 | } |
| 103 | ); | 106 | ); |
| 104 | } | 107 | } |
| 105 | }; | 108 | }; |
| 106 | $scope.datosExtraCierre = function (terminar) { | 109 | $scope.datosExtraCierre = function (terminar) { |
| 107 | var modalInstance = $uibModal.open( | 110 | var modalInstance = $uibModal.open( |
| 108 | { | 111 | { |
| 109 | templateUrl: 'focaDatosExtra.html', | 112 | templateUrl: 'focaDatosExtra.html', |
| 110 | controller: 'focaModalDatosExtraCierre', | 113 | controller: 'focaModalDatosExtraCierre', |
| 111 | } | 114 | } |
| 112 | ); | 115 | ); |
| 113 | modalInstance.result.then(terminar); | 116 | modalInstance.result.then(terminar); |
| 114 | }; | 117 | }; |
| 115 | $scope.modalDescargas = function () { | 118 | $scope.modalDescargas = function () { |
| 116 | delete $scope.hojaRuta.remitos[0].cliente; | 119 | delete $scope.hojaRuta.remitos[0].cliente; |
| 117 | var remito = $scope.hojaRuta.remitos[0]; | 120 | var remito = $scope.hojaRuta.remitos[0]; |
| 118 | var msg = ''; | 121 | var msg = ''; |
| 119 | var mostrarMensaje = true; | 122 | var mostrarMensaje = true; |
| 120 | for (var i = 0; i < remito.cisternas.length; i++) { | 123 | for (var i = 0; i < remito.cisternas.length; i++) { |
| 121 | if (remito.cisternas[i].cisternaCarga.cantidad <= 0) | 124 | if (remito.cisternas[i].cisternaCarga.cantidad <= 0) |
| 122 | msg += 'Cisterna ' + remito.cisternas[i].cisternaCarga.articulo.DetArt + | 125 | msg += 'Cisterna ' + remito.cisternas[i].cisternaCarga.articulo.DetArt + |
| 123 | ' esta vacía.\n'; | 126 | ' esta vacía.\n'; |
| 124 | else | 127 | else |
| 125 | mostrarMensaje = false; | 128 | mostrarMensaje = false; |
| 126 | } | 129 | } |
| 127 | if (mostrarMensaje === true) { | 130 | if (mostrarMensaje === true) { |
| 128 | focaModalService.alert(msg); | 131 | focaModalService.alert(msg); |
| 129 | return; | 132 | return; |
| 130 | } | 133 | } |
| 131 | var modalInstance = $uibModal.open( | 134 | var modalInstance = $uibModal.open( |
| 132 | { | 135 | { |
| 133 | templateUrl: 'foca-modal-descarga.html', | 136 | templateUrl: 'foca-modal-descarga.html', |
| 134 | controller: 'focaModalDescargaCtrl', | 137 | controller: 'focaModalDescargaCtrl', |
| 135 | resolve: { | 138 | resolve: { |
| 136 | remito: function () { return remito; } | 139 | remito: function () { return remito; } |
| 137 | }, | 140 | }, |
| 138 | } | 141 | } |
| 139 | ); | 142 | ); |
| 140 | modalInstance.result.then(function (data) { | 143 | modalInstance.result.then(function (data) { |
| 141 | console.log(data); | 144 | console.log(data); |
| 142 | }); | 145 | }); |
| 143 | }; | 146 | }; |
| 144 | $scope.articulosDescargados = function (articulosRemito) { | 147 | $scope.articulosDescargados = function (articulosRemito) { |
| 145 | for (var i = 0; i < articulosRemito.length; i++) { | 148 | for (var i = 0; i < articulosRemito.length; i++) { |
| 146 | if (articulosRemito[i].cantidadDescargada > 0) continue; | 149 | if (articulosRemito[i].cantidadDescargada > 0) continue; |
| 147 | else return false; | 150 | else return false; |
| 148 | } | 151 | } |
| 149 | return true; | 152 | return true; |
| 150 | }; | 153 | }; |
| 151 | $scope.estaPendiente = function () { | 154 | $scope.estaPendiente = function () { |
| 155 | if ($scope.hojaRuta.abierta) { | ||
| 156 | $scope.terminarHojaRuta(); | ||
| 157 | return; | ||
| 158 | } | ||
| 152 | var pendiente = false; | 159 | var pendiente = false; |
| 153 | $scope.hojaRuta.remitos.forEach(function (remito) { | 160 | $scope.hojaRuta.remitos.forEach(function (remito) { |
| 154 | if (pendiente === false) { | 161 | if (pendiente === false) { |
| 155 | var aDescargado = false; | 162 | var aDescargado = false; |
| 156 | for (var i = 0; i < remito.articulosRemito.length; i++) { | 163 | for (var i = 0; i < remito.articulosRemito.length; i++) { |
| 157 | if (remito.articulosRemito[i].cantidadDescargada > 0) | 164 | if (remito.articulosRemito[i].cantidadDescargada > 0) |
| 158 | aDescargado = true; | 165 | aDescargado = true; |
| 159 | } | 166 | } |
| 160 | pendiente = (!aDescargado && remito.rechazado == null) ? true : false; | 167 | pendiente = (!aDescargado && remito.rechazado == null) ? true : false; |
| 161 | } | 168 | } |
| 162 | }); | 169 | }); |
| 163 | if (pendiente) { | 170 | if (pendiente) { |
| 164 | focaModalService.alert('Todavia hay remitos pendientes'); | 171 | focaModalService.alert('Todavia hay remitos pendientes'); |
| 165 | return; | 172 | return; |
| 166 | } | 173 | } |
| 167 | $scope.terminarHojaRuta(); | 174 | $scope.terminarHojaRuta(); |
| 168 | }; | 175 | }; |
| 169 | $rootScope.$on('estadoRed', function (event, value) { | 176 | $rootScope.$on('estadoRed', function (event, value) { |
| 170 | $scope.estadoRed = value; | 177 | $scope.estadoRed = value; |
| 171 | }); | 178 | }); |
| 172 | function addCabecera(label, valor) { | 179 | function addCabecera(label, valor) { |
| 173 | var propiedad = $filter('filter')($scope.cabecera, { label: label }, true); | 180 | var propiedad = $filter('filter')($scope.cabecera, { label: label }, true); |
| 174 | if (propiedad.length === 1) { | 181 | if (propiedad.length === 1) propiedad[0].valor = valor; |
| 175 | propiedad[0].valor = valor; | 182 | else $scope.cabecera.push({ label: label, valor: valor }); |
| 176 | } else { | ||
| 177 | $scope.cabecera.push({ label: label, valor: valor }); | ||
| 178 | } | ||
| 179 | } | 183 | } |
| 180 | function getLSHojaRuta() { | 184 | // function getLSHojaRuta() { |
| 181 | 185 | // var hojaRuta = JSON.parse($localStorage.hojaRuta || null); | |
| 182 | var hojaRuta = JSON.parse($localStorage.hojaRuta || null); | 186 | // if (hojaRuta) { |
| 183 | 187 | // $scope.hojaRuta = hojaRuta; | |
| 184 | if (hojaRuta) { | 188 | // delete $localStorage.hojaRuta; |
| 185 | console.log('getLSHojaRuta() => ', hojaRuta); | 189 | // } |
| 186 | $scope.hojaRuta = hojaRuta; | 190 | // } |
| 187 | delete $localStorage.hojaRuta; | 191 | function parametrosModalHojasDeRuta(datos) { |
| 188 | } | 192 | var parametrosModal = { |
| 193 | data: datos, | ||
| 194 | columnas: [ | ||
| 195 | { | ||
| 196 | propiedad: 'comprobante', | ||
| 197 | nombre: 'Número' | ||
| 198 | }, | ||
| 199 | { | ||
| 200 | propiedad: 'fechaReparto', |
src/js/service.js
| 1 | angular.module('focaHojaRuta') | 1 | angular.module('focaHojaRuta') |
| 2 | .factory('hojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .factory('hojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
| 3 | var route = API_ENDPOINT.URL; | 3 | var route = API_ENDPOINT.URL; |
| 4 | return { | 4 | return { |
| 5 | getHojaRuta: function(chofer) { | 5 | getHojaRuta: function(id) { |
| 6 | return $http.get(route + '/hoja-ruta/chofer/' + chofer); | 6 | return $http.get(route + '/hoja-ruta/chofer/' + id); |
| 7 | }, | 7 | }, |
| 8 | terminarHojaRuta: function(hojaRuta) { | 8 | terminarHojaRuta: function(hojaRuta) { |
| 9 | return $http.post(route + '/hoja-ruta/terminar', {hojaRuta: hojaRuta}); | 9 | return $http.post(route + '/hoja-ruta/terminar', {hojaRuta: hojaRuta}); |
| 10 | } | 10 | } |
| 11 | }; | 11 | }; |
| 12 | }]); | 12 | }]); |
| 13 | 13 |