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