Commit 7c42b1852e17a8ea941eb70e8e5a719e9b6097a0
1 parent
16f1bb1958
Exists in
master
and in
2 other branches
mejorar inicializacion y salir
Showing
1 changed file
with
70 additions
and
50 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', | 1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', | 3 | '$scope', |
| 4 | '$uibModal', | 4 | '$uibModal', |
| 5 | '$location', | 5 | '$location', |
| 6 | '$filter', | 6 | '$filter', |
| 7 | '$timeout', | 7 | '$timeout', |
| 8 | 'focaCrearHojaRutaService', | 8 | 'focaCrearHojaRutaService', |
| 9 | 'focaModalService', | 9 | 'focaModalService', |
| 10 | 'focaBotoneraLateralService', | 10 | 'focaBotoneraLateralService', |
| 11 | 'focaLoginService', | 11 | 'focaLoginService', |
| 12 | function($scope, $uibModal, $location, $filter, $timeout, | 12 | function($scope, $uibModal, $location, $filter, $timeout, |
| 13 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, | 13 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, |
| 14 | focaLoginSrv) | 14 | focaLoginSrv) |
| 15 | { | 15 | { |
| 16 | config(); | ||
| 16 | 17 | ||
| 17 | $scope.botonera = focaCrearHojaRutaService.getBotonera(); | 18 | function config() { |
| 18 | $scope.datepickerAbierto = false; | 19 | $scope.botonera = focaCrearHojaRutaService.getBotonera(); |
| 20 | $scope.datepickerAbierto = false; | ||
| 21 | $scope.show = false; | ||
| 22 | $scope.cargando = true; | ||
| 23 | $scope.now = new Date(); | ||
| 24 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | ||
| 25 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | ||
| 26 | |||
| 27 | //SETEO BOTONERA LATERAL | ||
| 28 | $timeout(function() { | ||
| 29 | focaBotoneraLateralService.showSalir(false); | ||
| 30 | focaBotoneraLateralService.showPausar(true); | ||
| 31 | focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); | ||
| 32 | focaBotoneraLateralService.addCustomButton('Salir', salir); | ||
| 33 | }); | ||
| 34 | |||
| 35 | init(); | ||
| 36 | } | ||
| 19 | 37 | ||
| 20 | $scope.show = false; | 38 | function init() { |
| 21 | $scope.cargando = true; | 39 | $scope.$broadcast('cleanCabecera'); |
| 22 | 40 | ||
| 23 | function nuevaHojaRuta() { | ||
| 24 | $scope.hojaRuta = { | 41 | $scope.hojaRuta = { |
| 25 | fecha: new Date(), | 42 | fecha: new Date(), |
| 26 | litros: 0, | 43 | litros: 0, |
| 27 | chofer: {}, | 44 | chofer: {}, |
| 28 | vehiculo: { | 45 | vehiculo: { |
| 29 | capacidad: 0 | 46 | capacidad: 0 |
| 30 | }, | 47 | }, |
| 31 | transportista: {}, | 48 | transportista: {}, |
| 32 | tarifario: { | 49 | tarifario: { |
| 33 | costo: null | 50 | costo: null |
| 34 | } | 51 | } |
| 35 | }; | 52 | }; |
| 53 | |||
| 54 | $scope.remitosTabla = []; | ||
| 55 | $scope.idLista = undefined; | ||
| 56 | |||
| 57 | focaCrearHojaRutaService.getNumeroHojaRuta().then( | ||
| 58 | function(res) { | ||
| 59 | $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); | ||
| 60 | $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); | ||
| 61 | }, | ||
| 62 | function(err) { | ||
| 63 | focaModalService.alert('La terminal no esta configurada correctamente'); | ||
| 64 | console.info(err); | ||
| 65 | } | ||
| 66 | ); | ||
| 67 | |||
| 68 | $scope.inicial = { | ||
| 69 | hojaRuta: angular.copy($scope.hojaRuta), | ||
| 70 | remitosTabla: angular.copy($scope.remitosTabla), | ||
| 71 | idLista: angular.copy($scope.idLista) | ||
| 72 | }; | ||
| 36 | } | 73 | } |
| 37 | nuevaHojaRuta(); | 74 | |
| 38 | $scope.showCabecera = true; | ||
| 39 | |||
| 40 | $scope.now = new Date(); | ||
| 41 | $scope.puntoVenta = '0000'; | ||
| 42 | $scope.comprobante = '00000000'; | ||
| 43 | $scope.remitosTabla = []; | ||
| 44 | $scope.idLista = undefined; | ||
| 45 | |||
| 46 | //SETEO BOTONERA LATERAL | ||
| 47 | $timeout(function() { | ||
| 48 | focaBotoneraLateralService.showSalir(true); | ||
| 49 | focaBotoneraLateralService.showPausar(true); | ||
| 50 | focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); | ||
| 51 | }); | ||
| 52 | |||
| 53 | focaCrearHojaRutaService.getNumeroHojaRuta().then( | ||
| 54 | function(res) { | ||
| 55 | $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); | ||
| 56 | $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); | ||
| 57 | }, | ||
| 58 | function(err) { | ||
| 59 | focaModalService.alert('La terminal no esta configurada correctamente'); | ||
| 60 | console.info(err); | ||
| 61 | } | ||
| 62 | ); | ||
| 63 | $scope.crearHojaRuta = function() { | 75 | $scope.crearHojaRuta = function() { |
| 64 | if(!$scope.remitosTabla.length) { | 76 | if(!$scope.remitosTabla.length) { |
| 65 | focaModalService.alert('Ingrese Remitos'); | 77 | focaModalService.alert('Ingrese Remitos'); |
| 66 | return; | 78 | return; |
| 67 | } | 79 | } |
| 68 | if(!$scope.hojaRuta.chofer.id) { | 80 | if(!$scope.hojaRuta.chofer.id) { |
| 69 | focaModalService.alert('Ingrese Chofer'); | 81 | focaModalService.alert('Ingrese Chofer'); |
| 70 | return; | 82 | return; |
| 71 | } | 83 | } |
| 72 | if(!$scope.hojaRuta.vehiculo.id) { | 84 | if(!$scope.hojaRuta.vehiculo.id) { |
| 73 | focaModalService.alert('Ingrese Vehiculo'); | 85 | focaModalService.alert('Ingrese Vehiculo'); |
| 74 | return; | 86 | return; |
| 75 | } | 87 | } |
| 76 | if(!$scope.hojaRuta.transportista.COD) { | 88 | if(!$scope.hojaRuta.transportista.COD) { |
| 77 | focaModalService.alert('Ingrese Transportista'); | 89 | focaModalService.alert('Ingrese Transportista'); |
| 78 | return; | 90 | return; |
| 79 | } | 91 | } |
| 80 | if(!$scope.hojaRuta.tarifario.costo) { | 92 | if(!$scope.hojaRuta.tarifario.costo) { |
| 81 | focaModalService.alert('Ingrese Tarifario'); | 93 | focaModalService.alert('Ingrese Tarifario'); |
| 82 | return; | 94 | return; |
| 83 | } | 95 | } |
| 84 | if(!$scope.hojaRuta.datosExtra) { | 96 | if(!$scope.hojaRuta.datosExtra) { |
| 85 | focaModalService.alert('Ingrese Datos extra'); | 97 | focaModalService.alert('Ingrese Datos extra'); |
| 86 | return; | 98 | return; |
| 87 | } | 99 | } |
| 88 | var date = new Date(); | 100 | var date = new Date(); |
| 89 | var save = { | 101 | var save = { |
| 90 | hojaRuta: { | 102 | hojaRuta: { |
| 91 | id: 0, | 103 | id: 0, |
| 92 | fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) | 104 | fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) |
| 93 | .replace('T', ' '), | 105 | .replace('T', ' '), |
| 94 | idTransportista: $scope.hojaRuta.transportista.COD, | 106 | idTransportista: $scope.hojaRuta.transportista.COD, |
| 95 | idChofer: $scope.hojaRuta.chofer.id, | 107 | idChofer: $scope.hojaRuta.chofer.id, |
| 96 | idVehiculo: $scope.hojaRuta.vehiculo.id, | 108 | idVehiculo: $scope.hojaRuta.vehiculo.id, |
| 97 | tarifaFlete: $scope.hojaRuta.tarifario.costo, | 109 | tarifaFlete: $scope.hojaRuta.tarifario.costo, |
| 98 | fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10), | 110 | fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10), |
| 99 | estado: 0 | 111 | estado: 0 |
| 100 | }, | 112 | }, |
| 101 | remitos: $scope.remitosTabla | 113 | remitos: $scope.remitosTabla |
| 102 | }; | 114 | }; |
| 103 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); | 115 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); |
| 104 | focaCrearHojaRutaService.crearHojaRuta(save).then( | 116 | focaCrearHojaRutaService.crearHojaRuta(save).then( |
| 105 | function(data) { | 117 | function(data) { |
| 106 | focaModalService.alert( | 118 | focaModalService.alert( |
| 107 | 'Hoja ruta creada Nº: ' + | 119 | 'Hoja ruta creada Nº: ' + |
| 108 | $scope.rellenar(data.data.sucursal, 4) + | 120 | $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + |
| 109 | '-' + | 121 | $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) |
| 110 | $scope.rellenar(data.data.numeroHojaRuta, 8) | ||
| 111 | ); | 122 | ); |
| 112 | nuevaHojaRuta(); | 123 | |
| 113 | $scope.remitosTabla = []; | 124 | init(); |
| 114 | $scope.$broadcast('cleanCabecera'); | ||
| 115 | |||
| 116 | focaCrearHojaRutaService.getNumeroHojaRuta().then(function(res) { | ||
| 117 | $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); | ||
| 118 | }); | ||
| 119 | }, | 125 | }, |
| 120 | function(error) { | 126 | function(error) { |
| 121 | focaModalService.alert('Hubo un error al crear la hoja de ruta'); | 127 | focaModalService.alert('Hubo un error al crear la hoja de ruta'); |
| 122 | console.info(error); | 128 | console.info(error); |
| 123 | } | 129 | } |
| 124 | ); | 130 | ); |
| 125 | }; | 131 | }; |
| 126 | 132 | ||
| 127 | $scope.seleccionarTransportista = function() { | 133 | $scope.seleccionarTransportista = function() { |
| 128 | if(eligioPreConfirmado()) return; | 134 | if(eligioPreConfirmado()) return; |
| 129 | var parametrosModal = { | 135 | var parametrosModal = { |
| 130 | titulo: 'Búsqueda de transportista', | 136 | titulo: 'Búsqueda de transportista', |
| 131 | query: '/transportista', | 137 | query: '/transportista', |
| 132 | columnas: [ | 138 | columnas: [ |
| 133 | { | 139 | { |
| 134 | nombre: 'Código', | 140 | nombre: 'Código', |
| 135 | propiedad: 'COD' | 141 | propiedad: 'COD' |
| 136 | }, | 142 | }, |
| 137 | { | 143 | { |
| 138 | nombre: 'Nombre', | 144 | nombre: 'Nombre', |
| 139 | propiedad: 'NOM' | 145 | propiedad: 'NOM' |
| 140 | }, | 146 | }, |
| 141 | { | 147 | { |
| 142 | nombre: 'CUIT', | 148 | nombre: 'CUIT', |
| 143 | propiedad: 'CUIT' | 149 | propiedad: 'CUIT' |
| 144 | } | 150 | } |
| 145 | ] | 151 | ] |
| 146 | }; | 152 | }; |
| 147 | focaModalService.modal(parametrosModal).then( | 153 | focaModalService.modal(parametrosModal).then( |
| 148 | function(proveedor) { | 154 | function(proveedor) { |
| 149 | $scope.hojaRuta.transportista = proveedor; | 155 | $scope.hojaRuta.transportista = proveedor; |
| 150 | $scope.$broadcast('addCabecera', { | 156 | $scope.$broadcast('addCabecera', { |
| 151 | label: 'Transportista:', | 157 | label: 'Transportista:', |
| 152 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 158 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 153 | proveedor.NOM | 159 | proveedor.NOM |
| 154 | }); | 160 | }); |
| 155 | }, function() { | 161 | }, function() { |
| 156 | 162 | ||
| 157 | } | 163 | } |
| 158 | ); | 164 | ); |
| 159 | }; | 165 | }; |
| 160 | 166 | ||
| 161 | $scope.seleccionarChofer = function() { | 167 | $scope.seleccionarChofer = function() { |
| 162 | var parametrosModal = { | 168 | var parametrosModal = { |
| 163 | titulo: 'Búsqueda de Chofer', | 169 | titulo: 'Búsqueda de Chofer', |
| 164 | query: '/chofer', | 170 | query: '/chofer', |
| 165 | columnas: [ | 171 | columnas: [ |
| 166 | { | 172 | { |
| 167 | propiedad: 'id', | 173 | propiedad: 'id', |
| 168 | nombre: 'Código', | 174 | nombre: 'Código', |
| 169 | filtro: { | 175 | filtro: { |
| 170 | nombre: 'rellenarDigitos', | 176 | nombre: 'rellenarDigitos', |
| 171 | parametro: 3 | 177 | parametro: 3 |
| 172 | } | 178 | } |
| 173 | }, | 179 | }, |
| 174 | { | 180 | { |
| 175 | propiedad: 'nombre', | 181 | propiedad: 'nombre', |
| 176 | nombre: 'Nombre' | 182 | nombre: 'Nombre' |
| 177 | }, | 183 | }, |
| 178 | { | 184 | { |
| 179 | propiedad: 'dni', | 185 | propiedad: 'dni', |
| 180 | nombre: 'DNI' | 186 | nombre: 'DNI' |
| 181 | }, | 187 | }, |
| 182 | { | 188 | { |
| 183 | propiedad: 'telefono', | 189 | propiedad: 'telefono', |
| 184 | nombre: 'Teléfono' | 190 | nombre: 'Teléfono' |
| 185 | } | 191 | } |
| 186 | ] | 192 | ] |
| 187 | }; | 193 | }; |
| 188 | focaModalService.modal(parametrosModal).then( | 194 | focaModalService.modal(parametrosModal).then( |
| 189 | function(chofer) { | 195 | function(chofer) { |
| 190 | $scope.hojaRuta.chofer = chofer; | 196 | $scope.hojaRuta.chofer = chofer; |
| 191 | $scope.$broadcast('addCabecera', { | 197 | $scope.$broadcast('addCabecera', { |
| 192 | label: 'Chofer:', | 198 | label: 'Chofer:', |
| 193 | valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre | 199 | valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre |
| 194 | }); | 200 | }); |
| 195 | }, function() { | 201 | }, function() { |
| 196 | // funcion ejecutada cuando se cancela el modal | 202 | // funcion ejecutada cuando se cancela el modal |
| 197 | } | 203 | } |
| 198 | ); | 204 | ); |
| 199 | }; | 205 | }; |
| 200 | 206 | ||
| 201 | $scope.seleccionarVehiculo = function() { | 207 | $scope.seleccionarVehiculo = function() { |
| 202 | if(!eligioFecha() || eligioPreConfirmado()) return; | 208 | if(!eligioFecha() || eligioPreConfirmado()) return; |
| 203 | modalVehiculos(); | 209 | modalVehiculos(); |
| 204 | }; | 210 | }; |
| 205 | 211 | ||
| 206 | $scope.seleccionarTarifario = function() { | 212 | $scope.seleccionarTarifario = function() { |
| 207 | var modalInstance = $uibModal.open( | 213 | var modalInstance = $uibModal.open( |
| 208 | { | 214 | { |
| 209 | ariaLabelledBy: 'Busqueda de Tarifario', | 215 | ariaLabelledBy: 'Busqueda de Tarifario', |
| 210 | templateUrl: 'modal-tarifa-flete.html', | 216 | templateUrl: 'modal-tarifa-flete.html', |
| 211 | controller: 'focaModalTarifaFleteController', | 217 | controller: 'focaModalTarifaFleteController', |
| 212 | size: 'lg', | 218 | size: 'lg', |
| 213 | resolve: { | 219 | resolve: { |
| 214 | parametrosTarifaFlete: function() { | 220 | parametrosTarifaFlete: function() { |
| 215 | return $scope.hojaRuta.tarifario.costo; | 221 | return $scope.hojaRuta.tarifario.costo; |
| 216 | } | 222 | } |
| 217 | } | 223 | } |
| 218 | } | 224 | } |
| 219 | ); | 225 | ); |
| 220 | 226 | ||
| 221 | modalInstance.result.then( | 227 | modalInstance.result.then( |
| 222 | function(tarifario) { | 228 | function(tarifario) { |
| 223 | $scope.hojaRuta.tarifario = tarifario; | 229 | $scope.hojaRuta.tarifario = tarifario; |
| 224 | $scope.$broadcast('addCabecera', { | 230 | $scope.$broadcast('addCabecera', { |
| 225 | label: 'Tarifario:', | 231 | label: 'Tarifario:', |
| 226 | valor: tarifario.costo | 232 | valor: tarifario.costo |
| 227 | }); | 233 | }); |
| 228 | }, function() { | 234 | }, function() { |
| 229 | // funcion ejecutada cuando se cancela el modal | 235 | // funcion ejecutada cuando se cancela el modal |
| 230 | } | 236 | } |
| 231 | ); | 237 | ); |
| 232 | }; | 238 | }; |
| 233 | 239 | ||
| 234 | $scope.seleccionarRemitos = function() { | 240 | $scope.seleccionarRemitos = function() { |
| 235 | if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; | 241 | if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; |
| 236 | var modalInstance = $uibModal.open( | 242 | var modalInstance = $uibModal.open( |
| 237 | { | 243 | { |
| 238 | ariaLabelledBy: 'Busqueda de Remito', | 244 | ariaLabelledBy: 'Busqueda de Remito', |
| 239 | templateUrl: 'foca-modal-remito.html', | 245 | templateUrl: 'foca-modal-remito.html', |
| 240 | controller: 'focaModalRemitoController', | 246 | controller: 'focaModalRemitoController', |
| 241 | size: 'lg', | 247 | size: 'lg', |
| 242 | resolve: {usadoPor: function() {return 'hojaRuta';}} | 248 | resolve: {usadoPor: function() {return 'hojaRuta';}} |
| 243 | } | 249 | } |
| 244 | ); | 250 | ); |
| 245 | modalInstance.result.then( | 251 | modalInstance.result.then( |
| 246 | function(remito) { | 252 | function(remito) { |
| 247 | // TODO: borrar cuando no se use definitivamente | 253 | // TODO: borrar cuando no se use definitivamente |
| 248 | // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { | 254 | // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { |
| 249 | // if ($scope.remitosTabla[i].id === remito.id) { | 255 | // if ($scope.remitosTabla[i].id === remito.id) { |
| 250 | // focaModalService.alert('Remito ya incluido'); | 256 | // focaModalService.alert('Remito ya incluido'); |
| 251 | // return; | 257 | // return; |
| 252 | // } | 258 | // } |
| 253 | // } | 259 | // } |
| 254 | 260 | ||
| 255 | // var litros = 0; | 261 | // var litros = 0; |
| 256 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { | 262 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { |
| 257 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); | 263 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); |
| 258 | // } | 264 | // } |
| 259 | 265 | ||
| 260 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { | 266 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { |
| 261 | // focaModalService.alert( | 267 | // focaModalService.alert( |
| 262 | // 'Debe ingresar toda la información para el transporte' | 268 | // 'Debe ingresar toda la información para el transporte' |
| 263 | // ); | 269 | // ); |
| 264 | // return; | 270 | // return; |
| 265 | // } | 271 | // } |
| 266 | 272 | ||
| 267 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) | 273 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) |
| 268 | // { | 274 | // { |
| 269 | // var litrostotales = litros; | 275 | // var litrostotales = litros; |
| 270 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; | 276 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; |
| 271 | // focaModalService.alert( | 277 | // focaModalService.alert( |
| 272 | // 'La carga excede la capacidad disponible del vehiculo. ' + | 278 | // 'La carga excede la capacidad disponible del vehiculo. ' + |
| 273 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' | 279 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' |
| 274 | // ); | 280 | // ); |
| 275 | // } | 281 | // } |
| 276 | 282 | ||
| 277 | // remito.litros = litros; | 283 | // remito.litros = litros; |
| 278 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; | 284 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; |
| 279 | $scope.cargarCisterna(remito.id).then(function() { | 285 | $scope.cargarCisterna(remito.id).then(function() { |
| 280 | $scope.remitosTabla.push(remito); | 286 | $scope.remitosTabla.push(remito); |
| 281 | $scope.seleccionarRemitos(); | 287 | $scope.seleccionarRemitos(); |
| 282 | }, function() { | 288 | }, function() { |
| 283 | $scope.seleccionarRemitos(); | 289 | $scope.seleccionarRemitos(); |
| 284 | }); | 290 | }); |
| 285 | }, function() { | 291 | }, function() { |
| 286 | // funcion ejecutada cuando se cancela el modal | 292 | // funcion ejecutada cuando se cancela el modal |
| 287 | } | 293 | } |
| 288 | ); | 294 | ); |
| 289 | }; | 295 | }; |
| 290 | 296 | ||
| 291 | $scope.seleccionarVehiculosPrecargados = function() { | 297 | $scope.seleccionarVehiculosPrecargados = function() { |
| 292 | if(!eligioFecha()) return; | 298 | if(!eligioFecha()) return; |
| 293 | modalVehiculos(true); | 299 | modalVehiculos(true); |
| 294 | }; | 300 | }; |
| 295 | 301 | ||
| 296 | $scope.cargarCisterna = function(idRemito) { | 302 | $scope.cargarCisterna = function(idRemito) { |
| 297 | if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; | 303 | if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; |
| 298 | var modalInstance = $uibModal.open( | 304 | var modalInstance = $uibModal.open( |
| 299 | { | 305 | { |
| 300 | ariaLabelledBy: 'Busqueda de Vehiculo', | 306 | ariaLabelledBy: 'Busqueda de Vehiculo', |
| 301 | templateUrl: 'foca-detalle-vehiculo.html', | 307 | templateUrl: 'foca-detalle-vehiculo.html', |
| 302 | controller: 'focaDetalleVehiculo', | 308 | controller: 'focaDetalleVehiculo', |
| 303 | size: 'lg', | 309 | size: 'lg', |
| 304 | resolve: { | 310 | resolve: { |
| 305 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, | 311 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, |
| 306 | idRemito: function() {return idRemito;}, | 312 | idRemito: function() {return idRemito;}, |
| 307 | fechaReparto: function() {return $scope.fechaReparto;} | 313 | fechaReparto: function() {return $scope.fechaReparto;} |
| 308 | } | 314 | } |
| 309 | } | 315 | } |
| 310 | ); | 316 | ); |
| 311 | return modalInstance.result; | 317 | return modalInstance.result; |
| 312 | }; | 318 | }; |
| 313 | 319 | ||
| 314 | $scope.seleccionarFechaEntrega = function() { | 320 | $scope.seleccionarFechaEntrega = function() { |
| 315 | if(!$scope.fechaReparto) { | 321 | if(!$scope.fechaReparto) { |
| 316 | elegirFecha(); | 322 | elegirFecha(); |
| 317 | return; | 323 | return; |
| 318 | } | 324 | } |
| 319 | focaModalService | 325 | focaModalService |
| 320 | .confirm('Si cambia la fecha se perderán los datos actuales') | 326 | .confirm('Si cambia la fecha se perderán los datos actuales') |
| 321 | .then(function() { | 327 | .then(function() { |
| 322 | elegirFecha(); | 328 | elegirFecha(); |
| 323 | }, function() { | 329 | }, function() { |
| 324 | return ; | 330 | return ; |
| 325 | }); | 331 | }); |
| 326 | }; | 332 | }; |
| 327 | 333 | ||
| 328 | $scope.seleccionarDatosExtra = function() { | 334 | $scope.seleccionarDatosExtra = function() { |
| 329 | var datosHojaRuta = $scope.hojaRuta.datosExtra; | 335 | var datosHojaRuta = $scope.hojaRuta.datosExtra; |
| 330 | var modalInstance = $uibModal.open( | 336 | var modalInstance = $uibModal.open( |
| 331 | { | 337 | { |
| 332 | templateUrl: 'foca-modal-datos-hoja-ruta.html', | 338 | templateUrl: 'foca-modal-datos-hoja-ruta.html', |
| 333 | controller: 'focaModalDatosHojaRutaCtrl', | 339 | controller: 'focaModalDatosHojaRutaCtrl', |
| 334 | size: 'lg', | 340 | size: 'lg', |
| 335 | resolve: { | 341 | resolve: { |
| 336 | parametrosDatos: function() { | 342 | parametrosDatos: function() { |
| 337 | return { | 343 | return { |
| 338 | datosHojaRuta: datosHojaRuta | 344 | datosHojaRuta: datosHojaRuta |
| 339 | }; | 345 | }; |
| 340 | } | 346 | } |
| 341 | } | 347 | } |
| 342 | } | 348 | } |
| 343 | ); | 349 | ); |
| 344 | return modalInstance.result.then(function(datosExtra) { | 350 | return modalInstance.result.then(function(datosExtra) { |
| 345 | $scope.hojaRuta.datosExtra = datosExtra; | 351 | $scope.hojaRuta.datosExtra = datosExtra; |
| 346 | }, function() { | 352 | }, function() { |
| 347 | //se ejecuta cuando se cancela el modal | 353 | //se ejecuta cuando se cancela el modal |
| 348 | }); | 354 | }); |
| 349 | }; | 355 | }; |
| 350 | 356 | ||
| 351 | $scope.desasociarRemito = function(key, idRemito) { | 357 | $scope.desasociarRemito = function(key, idRemito) { |
| 352 | var idsRemito = [idRemito]; | 358 | var idsRemito = [idRemito]; |
| 353 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + | 359 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + |
| 354 | ' vehículo?').then(function() { | 360 | ' vehículo?').then(function() { |
| 355 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, | 361 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, |
| 356 | $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( | 362 | $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( |
| 357 | function() { | 363 | function() { |
| 358 | $scope.remitosTabla.splice(key, 1); | 364 | $scope.remitosTabla.splice(key, 1); |
| 359 | focaModalService.alert('Remito desasociado con éxito'); | 365 | focaModalService.alert('Remito desasociado con éxito'); |
| 360 | } | 366 | } |
| 361 | ); | 367 | ); |
| 362 | }); | 368 | }); |
| 363 | }; | 369 | }; |
| 364 | 370 | ||
| 365 | function elegirFecha() { | 371 | function elegirFecha() { |
| 366 | focaModalService.modalFecha('Fecha de entrega').then(function(fecha) { | 372 | focaModalService.modalFecha('Fecha de entrega').then(function(fecha) { |
| 367 | $scope.$broadcast('addCabecera', { | 373 | $scope.$broadcast('addCabecera', { |
| 368 | label: 'Fecha de entrega:', | 374 | label: 'Fecha de entrega:', |
| 369 | valor: fecha.toLocaleDateString() | 375 | valor: fecha.toLocaleDateString() |
| 370 | }); | 376 | }); |
| 371 | $scope.fechaReparto = fecha; | 377 | $scope.fechaReparto = fecha; |
| 372 | nuevaHojaRuta(); | ||
| 373 | }); | 378 | }); |
| 374 | } | 379 | } |
| 375 | 380 | ||
| 376 | $scope.rellenar = function(relleno, longitud) { | ||
| 377 | relleno = '' + relleno; | ||
| 378 | while (relleno.length < longitud) { | ||
| 379 | relleno = '0' + relleno; | ||
| 380 | } | ||
| 381 | return relleno; | ||
| 382 | }; | ||
| 383 | |||
| 384 | function eligioPreConfirmado() { | 381 | function eligioPreConfirmado() { |
| 385 | if($scope.eligioPreConfirmado) { | 382 | if($scope.eligioPreConfirmado) { |
| 386 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); | 383 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); |
| 387 | return true; | 384 | return true; |
| 388 | } | 385 | } |
| 389 | return false; | 386 | return false; |
| 390 | } | 387 | } |
| 391 | 388 | ||
| 392 | function eligioFecha() { | 389 | function eligioFecha() { |
| 393 | if(!$scope.fechaReparto) { | 390 | if(!$scope.fechaReparto) { |
| 394 | focaModalService.alert('Primero seleccione fecha de reparto'); | 391 | focaModalService.alert('Primero seleccione fecha de reparto'); |
| 395 | return false; | 392 | return false; |
| 396 | } | 393 | } |
| 397 | return true; | 394 | return true; |
| 398 | } | 395 | } |
| 399 | 396 | ||
| 400 | function eligioVehiculo() { | 397 | function eligioVehiculo() { |
| 401 | if(!$scope.hojaRuta.vehiculo.id) { | 398 | if(!$scope.hojaRuta.vehiculo.id) { |
| 402 | focaModalService.alert('Primero seleccione vehiculo'); | 399 | focaModalService.alert('Primero seleccione vehiculo'); |
| 403 | return false; | 400 | return false; |
| 404 | } | 401 | } |
| 405 | return true; | 402 | return true; |
| 406 | } | 403 | } |
| 407 | 404 | ||
| 408 | function modalVehiculos(preCargados) { | 405 | function modalVehiculos(preCargados) { |
| 409 | var parametrosModal = {}; | 406 | var parametrosModal = {}; |
| 410 | if(preCargados) { | 407 | if(preCargados) { |
| 411 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + | 408 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + |
| 412 | $scope.fechaReparto.toISOString().substring(0, 10); | 409 | $scope.fechaReparto.toISOString().substring(0, 10); |
| 413 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; | 410 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; |
| 414 | }else { | 411 | }else { |
| 415 | parametrosModal.query = '/vehiculo'; | 412 | parametrosModal.query = '/vehiculo'; |
| 416 | parametrosModal.titulo = 'Búsqueda de vehículos'; | 413 | parametrosModal.titulo = 'Búsqueda de vehículos'; |
| 417 | } | 414 | } |
| 418 | parametrosModal.columnas = [ | 415 | parametrosModal.columnas = [ |
| 419 | { | 416 | { |
| 420 | propiedad: 'codigo', | 417 | propiedad: 'codigo', |
| 421 | nombre: 'Código' | 418 | nombre: 'Código' |
| 422 | }, | 419 | }, |
| 423 | { | 420 | { |
| 424 | propiedad: 'tractor', | 421 | propiedad: 'tractor', |
| 425 | nombre: 'tractor' | 422 | nombre: 'tractor' |
| 426 | }, | 423 | }, |
| 427 | { | 424 | { |
| 428 | propiedad: 'semi', | 425 | propiedad: 'semi', |
| 429 | nombre: 'Semi' | 426 | nombre: 'Semi' |
| 430 | } | 427 | } |
| 431 | ]; | 428 | ]; |
| 432 | focaModalService.modal(parametrosModal).then(function(vehiculo) { | 429 | focaModalService.modal(parametrosModal).then(function(vehiculo) { |
| 433 | if(!preCargados && vehiculoEnUso(vehiculo)) return; | 430 | if(!preCargados && vehiculoEnUso(vehiculo)) return; |
| 434 | $scope.hojaRuta.vehiculo = vehiculo; | 431 | $scope.hojaRuta.vehiculo = vehiculo; |
| 435 | $scope.hojaRuta.transportista = vehiculo.transportista; | 432 | $scope.hojaRuta.transportista = vehiculo.transportista; |
| 436 | if(preCargados) { | 433 | if(preCargados) { |
| 437 | $scope.eligioPreConfirmado = true; | 434 | $scope.eligioPreConfirmado = true; |
| 438 | $scope.hojaRuta.vehiculo = vehiculo; | 435 | $scope.hojaRuta.vehiculo = vehiculo; |
| 439 | $scope.$broadcast('addCabecera', { | 436 | $scope.$broadcast('addCabecera', { |
| 440 | label: 'Transportista:', | 437 | label: 'Transportista:', |
| 441 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + | 438 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + |
| 442 | ' - ' + vehiculo.transportista.NOM | 439 | ' - ' + vehiculo.transportista.NOM |
| 443 | }); | 440 | }); |
| 444 | focaCrearHojaRutaService | 441 | focaCrearHojaRutaService |
| 445 | .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) | 442 | .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) |
| 446 | .then(function(res) { | 443 | .then(function(res) { |
| 447 | $scope.remitosTabla = res.data; | 444 | $scope.remitosTabla = res.data; |
| 448 | }); | 445 | }); |
| 449 | }else { | 446 | }else { |
| 450 | focaCrearHojaRutaService | 447 | focaCrearHojaRutaService |
| 451 | .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true) | 448 | .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true) |
| 452 | .then(function(res) { | 449 | .then(function(res) { |
| 453 | $scope.remitosTabla = res.data; | 450 | $scope.remitosTabla = res.data; |
| 454 | }); | 451 | }); |
| 455 | } | 452 | } |
| 456 | $scope.$broadcast('addCabecera', { | 453 | $scope.$broadcast('addCabecera', { |
| 457 | label: 'Tractor:', | 454 | label: 'Tractor:', |
| 458 | valor: vehiculo.tractor | 455 | valor: vehiculo.tractor |
| 459 | }); | 456 | }); |
| 460 | $scope.$broadcast('addCabecera', { | 457 | $scope.$broadcast('addCabecera', { |
| 461 | label: 'Semi:', | 458 | label: 'Semi:', |
| 462 | valor: vehiculo.semi | 459 | valor: vehiculo.semi |
| 463 | }); | 460 | }); |
| 464 | $scope.$broadcast('addCabecera', { | 461 | $scope.$broadcast('addCabecera', { |
| 465 | label: 'Capacidad:', | 462 | label: 'Capacidad:', |
| 466 | valor: vehiculo.capacidad | 463 | valor: vehiculo.capacidad |
| 467 | }); | 464 | }); |
| 468 | }); | 465 | }); |
| 469 | } | 466 | } |
| 470 | 467 | ||
| 471 | function vehiculoEnUso(vehiculo) { | 468 | function vehiculoEnUso(vehiculo) { |
| 472 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; | 469 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; |