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