Commit a8e9947cb735b1bf8960f174123c8a43472754f3
1 parent
75f00ec889
Exists in
master
parametros
Showing
2 changed files
with
92 additions
and
11 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 | '$localStorage', | 12 | '$localStorage', |
| 13 | function($scope, $uibModal, $location, $filter, $timeout, | 13 | function($scope, $uibModal, $location, $filter, $timeout, |
| 14 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, | 14 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, |
| 15 | focaLoginSrv, $localStorage) | 15 | focaLoginSrv, $localStorage) |
| 16 | { | 16 | { |
| 17 | config(); | 17 | config(); |
| 18 | 18 | ||
| 19 | function config() { | 19 | function config() { |
| 20 | $scope.botonera = focaCrearHojaRutaService.getBotonera(); | 20 | $scope.botonera = focaCrearHojaRutaService.getBotonera(); |
| 21 | $scope.datepickerAbierto = false; | 21 | $scope.datepickerAbierto = false; |
| 22 | $scope.show = false; | 22 | $scope.show = false; |
| 23 | $scope.cargando = true; | 23 | $scope.cargando = true; |
| 24 | $scope.now = new Date(); | 24 | $scope.now = new Date(); |
| 25 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 25 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
| 26 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 26 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
| 27 | 27 | ||
| 28 | //SETEO BOTONERA LATERAL | 28 | //SETEO BOTONERA LATERAL |
| 29 | $timeout(function() { | 29 | $timeout(function() { |
| 30 | focaBotoneraLateralService.showSalir(false); | 30 | focaBotoneraLateralService.showSalir(false); |
| 31 | focaBotoneraLateralService.showPausar(true); | 31 | focaBotoneraLateralService.showPausar(true); |
| 32 | focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); | 32 | focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); |
| 33 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 33 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 34 | }); | 34 | }); |
| 35 | 35 | ||
| 36 | focaCrearHojaRutaService.getParametros().then(function(res) { | ||
| 37 | |||
| 38 | var parametros = JSON.parse(res.data[0].jsonText); | ||
| 39 | |||
| 40 | if ($localStorage.hojaRuta) { | ||
| 41 | $timeout(function() {getLSHojaRuta();}); | ||
| 42 | } else { | ||
| 43 | |||
| 44 | for(var property in parametros) { | ||
| 45 | $scope.hojaRuta[property] = parametros[property]; | ||
| 46 | } | ||
| 47 | |||
| 48 | setearHojaRuta($scope.hojaRuta); | ||
| 49 | } | ||
| 50 | }); | ||
| 36 | init(); | 51 | init(); |
| 37 | $timeout(function() {getLSHojaRuta();}); | ||
| 38 | } | 52 | } |
| 39 | 53 | ||
| 40 | function init() { | 54 | function init() { |
| 41 | $scope.$broadcast('cleanCabecera'); | 55 | $scope.$broadcast('cleanCabecera'); |
| 42 | 56 | ||
| 43 | $scope.hojaRuta = { | 57 | $scope.hojaRuta = { |
| 44 | fecha: new Date(), | 58 | fecha: new Date(), |
| 45 | litros: 0, | 59 | litros: 0, |
| 46 | chofer: {}, | 60 | chofer: {}, |
| 47 | vehiculo: { | 61 | vehiculo: { |
| 48 | capacidad: 0 | 62 | capacidad: 0 |
| 49 | }, | 63 | }, |
| 50 | transportista: {}, | 64 | transportista: {}, |
| 51 | tarifario: { | ||
| 52 | costo: null | ||
| 53 | }, | ||
| 54 | remitosTabla: [] | 65 | remitosTabla: [] |
| 55 | }; | 66 | }; |
| 56 | $scope.idLista = undefined; | 67 | $scope.idLista = undefined; |
| 57 | 68 | ||
| 58 | focaCrearHojaRutaService.getNumeroHojaRuta().then( | 69 | focaCrearHojaRutaService.getNumeroHojaRuta().then( |
| 59 | function(res) { | 70 | function(res) { |
| 60 | $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); | 71 | $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); |
| 61 | $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); | 72 | $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); |
| 62 | }, | 73 | }, |
| 63 | function(err) { | 74 | function(err) { |
| 64 | focaModalService.alert('La terminal no esta configurada correctamente'); | 75 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 65 | console.info(err); | 76 | console.info(err); |
| 66 | } | 77 | } |
| 67 | ); | 78 | ); |
| 68 | setearFecha(new Date()); | 79 | setearFecha(new Date()); |
| 69 | $scope.inicial = angular.copy($scope.hojaRuta); | 80 | $scope.inicial = angular.copy($scope.hojaRuta); |
| 70 | } | 81 | } |
| 71 | 82 | ||
| 72 | $scope.$watch('hojaRuta', function(newValue) { | 83 | $scope.$watch('hojaRuta', function(newValue) { |
| 84 | |||
| 85 | // Seteo checked en remitos | ||
| 86 | if ($scope.hojaRuta.remitosTabla.length) { | ||
| 87 | |||
| 88 | $filter('filter')($scope.botonera, { | ||
| 89 | label: 'Remitos', | ||
| 90 | })[0].checked = true; | ||
| 91 | } else { | ||
| 92 | $filter('filter')($scope.botonera, { | ||
| 93 | label: 'Remitos', | ||
| 94 | })[0].checked = false; | ||
| 95 | } | ||
| 96 | |||
| 73 | focaBotoneraLateralService.setPausarData({ | 97 | focaBotoneraLateralService.setPausarData({ |
| 74 | label: 'hojaRuta', | 98 | label: 'hojaRuta', |
| 75 | val: newValue | 99 | val: newValue |
| 76 | }); | 100 | }); |
| 77 | }, true); | 101 | }, true); |
| 78 | 102 | ||
| 79 | $scope.crearHojaRuta = function() { | 103 | $scope.crearHojaRuta = function() { |
| 80 | if (!$scope.hojaRuta.remitosTabla.length) { | 104 | if (!$scope.hojaRuta.remitosTabla.length) { |
| 81 | focaModalService.alert('Ingrese Remitos'); | 105 | focaModalService.alert('Ingrese Remitos'); |
| 82 | return; | 106 | return; |
| 83 | } | 107 | } |
| 84 | if (!$scope.hojaRuta.chofer.id) { | 108 | if (!$scope.hojaRuta.chofer.id) { |
| 85 | focaModalService.alert('Ingrese Chofer'); | 109 | focaModalService.alert('Ingrese Chofer'); |
| 86 | return; | 110 | return; |
| 87 | } | 111 | } |
| 88 | if (!$scope.hojaRuta.vehiculo.id) { | 112 | if (!$scope.hojaRuta.vehiculo.id) { |
| 89 | focaModalService.alert('Ingrese Vehiculo'); | 113 | focaModalService.alert('Ingrese Vehiculo'); |
| 90 | return; | 114 | return; |
| 91 | } | 115 | } |
| 92 | if (!$scope.hojaRuta.transportista.COD) { | 116 | if (!$scope.hojaRuta.transportista.COD) { |
| 93 | focaModalService.alert('Ingrese Transportista'); | 117 | focaModalService.alert('Ingrese Transportista'); |
| 94 | return; | 118 | return; |
| 95 | } | 119 | } |
| 96 | if (!$scope.hojaRuta.tarifario.costo) { | 120 | if (!$scope.hojaRuta.tarifario) { |
| 97 | focaModalService.alert('Ingrese Tarifario'); | 121 | focaModalService.alert('Ingrese Tarifario'); |
| 98 | return; | 122 | return; |
| 99 | } | 123 | } |
| 100 | if (!$scope.hojaRuta.datosExtra) { | 124 | if (!$scope.hojaRuta.datosExtra) { |
| 101 | focaModalService.alert('Ingrese Datos extra'); | 125 | focaModalService.alert('Ingrese Datos extra'); |
| 102 | return; | 126 | return; |
| 103 | } | 127 | } |
| 104 | var date = new Date(); | 128 | var date = new Date(); |
| 105 | var save = { | 129 | var save = { |
| 106 | hojaRuta: { | 130 | hojaRuta: { |
| 107 | id: 0, | 131 | id: 0, |
| 108 | fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) | 132 | fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) |
| 109 | .replace('T', ' '), | 133 | .replace('T', ' '), |
| 110 | idTransportista: $scope.hojaRuta.transportista.COD, | 134 | idTransportista: $scope.hojaRuta.transportista.COD, |
| 111 | idChofer: $scope.hojaRuta.chofer.id, | 135 | idChofer: $scope.hojaRuta.chofer.id, |
| 112 | idVehiculo: $scope.hojaRuta.vehiculo.id, | 136 | idVehiculo: $scope.hojaRuta.vehiculo.id, |
| 113 | tarifaFlete: $scope.hojaRuta.tarifario.costo, | 137 | tarifaFlete: $scope.hojaRuta.tarifario, |
| 114 | fechaReparto: | 138 | fechaReparto: |
| 115 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), | 139 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), |
| 116 | estado: 0 | 140 | estado: 0 |
| 117 | }, | 141 | }, |
| 118 | remitos: $scope.hojaRuta.remitosTabla | 142 | remitos: $scope.hojaRuta.remitosTabla |
| 119 | }; | 143 | }; |
| 120 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); | 144 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); |
| 121 | focaCrearHojaRutaService.crearHojaRuta(save).then( | 145 | focaCrearHojaRutaService.crearHojaRuta(save).then( |
| 122 | function(data) { | 146 | function(data) { |
| 123 | focaModalService.alert( | 147 | focaModalService.alert( |
| 124 | 'Hoja ruta creada Nº: ' + | 148 | 'Hoja ruta creada Nº: ' + |
| 125 | $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + | 149 | $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + |
| 126 | $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) | 150 | $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) |
| 127 | ); | 151 | ); |
| 128 | 152 | ||
| 129 | init(); | 153 | config(); |
| 130 | }, | 154 | }, |
| 131 | function(error) { | 155 | function(error) { |
| 132 | focaModalService.alert('Hubo un error al crear la hoja de ruta'); | 156 | focaModalService.alert('Hubo un error al crear la hoja de ruta'); |
| 133 | console.info(error); | 157 | console.info(error); |
| 134 | } | 158 | } |
| 135 | ); | 159 | ); |
| 136 | }; | 160 | }; |
| 137 | 161 | ||
| 138 | $scope.seleccionarTransportista = function() { | 162 | $scope.seleccionarTransportista = function() { |
| 139 | if (eligioPreConfirmado()) return; | 163 | if (eligioPreConfirmado()) return; |
| 140 | var parametrosModal = { | 164 | var parametrosModal = { |
| 141 | titulo: 'Búsqueda de transportista', | 165 | titulo: 'Búsqueda de transportista', |
| 142 | query: '/transportista', | 166 | query: '/transportista', |
| 143 | columnas: [ | 167 | columnas: [ |
| 144 | { | 168 | { |
| 145 | nombre: 'Código', | 169 | nombre: 'Código', |
| 146 | propiedad: 'COD' | 170 | propiedad: 'COD' |
| 147 | }, | 171 | }, |
| 148 | { | 172 | { |
| 149 | nombre: 'Nombre', | 173 | nombre: 'Nombre', |
| 150 | propiedad: 'NOM' | 174 | propiedad: 'NOM' |
| 151 | }, | 175 | }, |
| 152 | { | 176 | { |
| 153 | nombre: 'CUIT', | 177 | nombre: 'CUIT', |
| 154 | propiedad: 'CUIT' | 178 | propiedad: 'CUIT' |
| 155 | } | 179 | } |
| 156 | ] | 180 | ] |
| 157 | }; | 181 | }; |
| 158 | focaModalService.modal(parametrosModal).then( | 182 | focaModalService.modal(parametrosModal).then( |
| 159 | function(proveedor) { | 183 | function(proveedor) { |
| 160 | $scope.hojaRuta.transportista = proveedor; | 184 | $scope.hojaRuta.transportista = proveedor; |
| 161 | $scope.$broadcast('addCabecera', { | 185 | $scope.$broadcast('addCabecera', { |
| 162 | label: 'Transportista:', | 186 | label: 'Transportista:', |
| 163 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 187 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 164 | proveedor.NOM | 188 | proveedor.NOM |
| 165 | }); | 189 | }); |
| 190 | |||
| 191 | $filter('filter')($scope.botonera, { | ||
| 192 | label: 'Transportista', | ||
| 193 | })[0].checked = true; | ||
| 166 | }, function() { | 194 | }, function() { |
| 167 | 195 | ||
| 168 | } | 196 | } |
| 169 | ); | 197 | ); |
| 170 | }; | 198 | }; |
| 171 | 199 | ||
| 172 | $scope.seleccionarChofer = function() { | 200 | $scope.seleccionarChofer = function() { |
| 173 | var parametrosModal = { | 201 | var parametrosModal = { |
| 174 | titulo: 'Búsqueda de Chofer', | 202 | titulo: 'Búsqueda de Chofer', |
| 175 | query: '/chofer', | 203 | query: '/chofer', |
| 176 | columnas: [ | 204 | columnas: [ |
| 177 | { | 205 | { |
| 178 | propiedad: 'id', | 206 | propiedad: 'id', |
| 179 | nombre: 'Código', | 207 | nombre: 'Código', |
| 180 | filtro: { | 208 | filtro: { |
| 181 | nombre: 'rellenarDigitos', | 209 | nombre: 'rellenarDigitos', |
| 182 | parametro: 3 | 210 | parametro: 3 |
| 183 | } | 211 | } |
| 184 | }, | 212 | }, |
| 185 | { | 213 | { |
| 186 | propiedad: 'nombre', | 214 | propiedad: 'nombre', |
| 187 | nombre: 'Nombre' | 215 | nombre: 'Nombre' |
| 188 | }, | 216 | }, |
| 189 | { | 217 | { |
| 190 | propiedad: 'dni', | 218 | propiedad: 'dni', |
| 191 | nombre: 'DNI' | 219 | nombre: 'DNI' |
| 192 | }, | 220 | }, |
| 193 | { | 221 | { |
| 194 | propiedad: 'telefono', | 222 | propiedad: 'telefono', |
| 195 | nombre: 'Teléfono' | 223 | nombre: 'Teléfono' |
| 196 | } | 224 | } |
| 197 | ] | 225 | ] |
| 198 | }; | 226 | }; |
| 199 | focaModalService.modal(parametrosModal).then( | 227 | focaModalService.modal(parametrosModal).then( |
| 200 | function(chofer) { | 228 | function(chofer) { |
| 201 | $scope.hojaRuta.chofer = chofer; | 229 | $scope.hojaRuta.chofer = chofer; |
| 202 | $scope.$broadcast('addCabecera', { | 230 | $scope.$broadcast('addCabecera', { |
| 203 | label: 'Chofer:', | 231 | label: 'Chofer:', |
| 204 | valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre | 232 | valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre |
| 205 | }); | 233 | }); |
| 234 | |||
| 235 | $filter('filter')($scope.botonera, { | ||
| 236 | label: 'Chofer', | ||
| 237 | })[0].checked = true; | ||
| 206 | }, function() { | 238 | }, function() { |
| 207 | // funcion ejecutada cuando se cancela el modal | 239 | // funcion ejecutada cuando se cancela el modal |
| 208 | } | 240 | } |
| 209 | ); | 241 | ); |
| 210 | }; | 242 | }; |
| 211 | 243 | ||
| 212 | $scope.seleccionarVehiculo = function() { | 244 | $scope.seleccionarVehiculo = function() { |
| 213 | if (!eligioFecha() || eligioPreConfirmado()) return; | 245 | if (!eligioFecha() || eligioPreConfirmado()) return; |
| 214 | modalVehiculos(); | 246 | modalVehiculos(); |
| 215 | }; | 247 | }; |
| 216 | 248 | ||
| 217 | $scope.seleccionarTarifario = function() { | 249 | $scope.seleccionarTarifario = function() { |
| 218 | focaModalService | 250 | focaModalService |
| 219 | .prompt({ | 251 | .prompt({ |
| 220 | titulo: 'Tarifa flete', | 252 | titulo: 'Tarifa flete', |
| 221 | value: $scope.hojaRuta.tarifario.costo | 253 | value: $scope.hojaRuta.tarifario |
| 222 | }) | 254 | }) |
| 223 | .then(function(costo) { | 255 | .then(function(costo) { |
| 224 | if (isNaN(costo)) { | 256 | if (isNaN(costo)) { |
| 225 | focaModalService | 257 | focaModalService |
| 226 | .alert('Ingrese un valor válido') | 258 | .alert('Ingrese un valor válido') |
| 227 | .then(function() { | 259 | .then(function() { |
| 228 | $scope.seleccionarTarifario(); | 260 | $scope.seleccionarTarifario(); |
| 229 | }); | 261 | }); |
| 230 | 262 | ||
| 231 | return; | 263 | return; |
| 232 | } | 264 | } |
| 233 | 265 | ||
| 234 | $scope.hojaRuta.tarifario.costo = costo; | 266 | $scope.hojaRuta.tarifario = costo; |
| 235 | $scope.$broadcast('addCabecera', { | 267 | $scope.$broadcast('addCabecera', { |
| 236 | label: 'Tarifario:', | 268 | label: 'Tarifario:', |
| 237 | valor: costo | 269 | valor: costo |
| 238 | }); | 270 | }); |
| 271 | |||
| 272 | $filter('filter')($scope.botonera, { | ||
| 273 | label: 'Tarifario', | ||
| 274 | })[0].checked = true; | ||
| 239 | }); | 275 | }); |
| 240 | }; | 276 | }; |
| 241 | 277 | ||
| 242 | $scope.seleccionarRemitos = function() { | 278 | $scope.seleccionarRemitos = function() { |
| 243 | if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; | 279 | if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; |
| 244 | var modalInstance = $uibModal.open( | 280 | var modalInstance = $uibModal.open( |
| 245 | { | 281 | { |
| 246 | ariaLabelledBy: 'Busqueda de Remito', | 282 | ariaLabelledBy: 'Busqueda de Remito', |
| 247 | templateUrl: 'foca-modal-remito.html', | 283 | templateUrl: 'foca-modal-remito.html', |
| 248 | controller: 'focaModalRemitoController', | 284 | controller: 'focaModalRemitoController', |
| 249 | size: 'lg', | 285 | size: 'lg', |
| 250 | resolve: {usadoPor: function() {return 'hojaRuta';}} | 286 | resolve: {usadoPor: function() {return 'hojaRuta';}} |
| 251 | } | 287 | } |
| 252 | ); | 288 | ); |
| 253 | modalInstance.result.then( | 289 | modalInstance.result.then( |
| 254 | function(remito) { | 290 | function(remito) { |
| 255 | // TODO: borrar cuando no se use definitivamente | 291 | // TODO: borrar cuando no se use definitivamente |
| 256 | // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { | 292 | // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { |
| 257 | // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { | 293 | // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { |
| 258 | // focaModalService.alert('Remito ya incluido'); | 294 | // focaModalService.alert('Remito ya incluido'); |
| 259 | // return; | 295 | // return; |
| 260 | // } | 296 | // } |
| 261 | // } | 297 | // } |
| 262 | 298 | ||
| 263 | // var litros = 0; | 299 | // var litros = 0; |
| 264 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { | 300 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { |
| 265 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); | 301 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); |
| 266 | // } | 302 | // } |
| 267 | 303 | ||
| 268 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { | 304 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { |
| 269 | // focaModalService.alert( | 305 | // focaModalService.alert( |
| 270 | // 'Debe ingresar toda la información para el transporte' | 306 | // 'Debe ingresar toda la información para el transporte' |
| 271 | // ); | 307 | // ); |
| 272 | // return; | 308 | // return; |
| 273 | // } | 309 | // } |
| 274 | 310 | ||
| 275 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) | 311 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) |
| 276 | // { | 312 | // { |
| 277 | // var litrostotales = litros; | 313 | // var litrostotales = litros; |
| 278 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; | 314 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; |
| 279 | // focaModalService.alert( | 315 | // focaModalService.alert( |
| 280 | // 'La carga excede la capacidad disponible del vehiculo. ' + | 316 | // 'La carga excede la capacidad disponible del vehiculo. ' + |
| 281 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' | 317 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' |
| 282 | // ); | 318 | // ); |
| 283 | // } | 319 | // } |
| 284 | 320 | ||
| 285 | // remito.litros = litros; | 321 | // remito.litros = litros; |
| 286 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; | 322 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; |
| 287 | $scope.cargarCisterna(remito.id).then(function() { | 323 | $scope.cargarCisterna(remito.id).then(function() { |
| 288 | $scope.hojaRuta.remitosTabla.push(remito); | 324 | $scope.hojaRuta.remitosTabla.push(remito); |
| 289 | }, function(error) { | 325 | }, function(error) { |
| 290 | 326 | ||
| 291 | if (error && error !== 'backdrop click') { | 327 | if (error && error !== 'backdrop click') { |
| 292 | 328 | ||
| 293 | focaModalService | 329 | focaModalService |
| 294 | .alert(error || 'Ha ocurrido un error') | 330 | .alert(error || 'Ha ocurrido un error') |
| 295 | .then(function() { | 331 | .then(function() { |
| 296 | $scope.seleccionarRemitos(); | 332 | $scope.seleccionarRemitos(); |
| 297 | }); | 333 | }); |
| 298 | 334 | ||
| 299 | } else { | 335 | } else { |
| 300 | 336 | ||
| 301 | $scope.seleccionarRemitos(); | 337 | $scope.seleccionarRemitos(); |
| 302 | 338 | ||
| 303 | } | 339 | } |
| 304 | }); | 340 | }); |
| 305 | }, function() { | 341 | }, function() { |
| 306 | // funcion ejecutada cuando se cancela el modal | 342 | // funcion ejecutada cuando se cancela el modal |
| 307 | } | 343 | } |
| 308 | ); | 344 | ); |
| 309 | }; | 345 | }; |
| 310 | 346 | ||
| 311 | $scope.seleccionarVehiculosPrecargados = function() { | 347 | $scope.seleccionarVehiculosPrecargados = function() { |
| 312 | if (!eligioFecha()) return; | 348 | if (!eligioFecha()) return; |
| 313 | modalVehiculos(true); | 349 | modalVehiculos(true); |
| 314 | }; | 350 | }; |
| 315 | 351 | ||
| 316 | $scope.cargarCisterna = function(idRemito) { | 352 | $scope.cargarCisterna = function(idRemito) { |
| 317 | if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; | 353 | if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; |
| 318 | var modalInstance = $uibModal.open( | 354 | var modalInstance = $uibModal.open( |
| 319 | { | 355 | { |
| 320 | ariaLabelledBy: 'Busqueda de Vehiculo', | 356 | ariaLabelledBy: 'Busqueda de Vehiculo', |
| 321 | templateUrl: 'foca-detalle-vehiculo.html', | 357 | templateUrl: 'foca-detalle-vehiculo.html', |
| 322 | controller: 'focaDetalleVehiculo', | 358 | controller: 'focaDetalleVehiculo', |
| 323 | size: 'lg', | 359 | size: 'lg', |
| 324 | resolve: { | 360 | resolve: { |
| 325 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, | 361 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, |
| 326 | idRemito: function() {return idRemito;}, | 362 | idRemito: function() {return idRemito;}, |
| 327 | fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} | 363 | fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} |
| 328 | } | 364 | } |
| 329 | } | 365 | } |
| 330 | ); | 366 | ); |
| 331 | return modalInstance.result; | 367 | return modalInstance.result; |
| 332 | }; | 368 | }; |
| 333 | 369 | ||
| 334 | $scope.seleccionarFechaEntrega = function() { | 370 | $scope.seleccionarFechaEntrega = function() { |
| 335 | if (!$scope.hojaRuta.fechaReparto) { | 371 | if (!$scope.hojaRuta.fechaReparto) { |
| 336 | elegirFecha(); | 372 | elegirFecha(); |
| 337 | return; | 373 | return; |
| 338 | } | 374 | } |
| 339 | focaModalService | 375 | focaModalService |
| 340 | .confirm('Si cambia la fecha se perderán los datos actuales') | 376 | .confirm('Si cambia la fecha se perderán los datos actuales') |
| 341 | .then(function() { | 377 | .then(function() { |
| 342 | elegirFecha(); | 378 | elegirFecha(); |
| 343 | }, function() { | 379 | }, function() { |
| 344 | return ; | 380 | return ; |
| 345 | }); | 381 | }); |
| 346 | }; | 382 | }; |
| 347 | 383 | ||
| 348 | function setearFecha(fecha) { | 384 | function setearFecha(fecha) { |
| 349 | $timeout(function() { | 385 | $timeout(function() { |
| 350 | $scope.$broadcast('addCabecera', { | 386 | $scope.$broadcast('addCabecera', { |
| 351 | label: 'Fecha de entrega: ', | 387 | label: 'Fecha de entrega: ', |
| 352 | valor: fecha.toLocaleDateString() | 388 | valor: fecha.toLocaleDateString() |
| 353 | }); | 389 | }); |
| 354 | $scope.hojaRuta.fechaReparto = fecha; | 390 | $scope.hojaRuta.fechaReparto = fecha; |
| 355 | }); | 391 | }); |
| 356 | } | 392 | } |
| 357 | 393 | ||
| 358 | $scope.seleccionarDatosExtra = function() { | 394 | $scope.seleccionarDatosExtra = function() { |
| 359 | var datosHojaRuta = $scope.hojaRuta.datosExtra; | 395 | var datosHojaRuta = $scope.hojaRuta.datosExtra; |
| 360 | var modalInstance = $uibModal.open( | 396 | var modalInstance = $uibModal.open( |
| 361 | { | 397 | { |
| 362 | templateUrl: 'foca-modal-datos-hoja-ruta.html', | 398 | templateUrl: 'foca-modal-datos-hoja-ruta.html', |
| 363 | controller: 'focaModalDatosHojaRutaCtrl', | 399 | controller: 'focaModalDatosHojaRutaCtrl', |
| 364 | size: 'lg', | 400 | size: 'lg', |
| 365 | resolve: { | 401 | resolve: { |
| 366 | parametrosDatos: function() { | 402 | parametrosDatos: function() { |
| 367 | return { | 403 | return { |
| 368 | datosHojaRuta: datosHojaRuta | 404 | datosHojaRuta: datosHojaRuta |
| 369 | }; | 405 | }; |
| 370 | } | 406 | } |
| 371 | } | 407 | } |
| 372 | } | 408 | } |
| 373 | ); | 409 | ); |
| 374 | return modalInstance.result.then(function(datosExtra) { | 410 | return modalInstance.result.then(function(datosExtra) { |
| 411 | |||
| 412 | $filter('filter')($scope.botonera, { | ||
| 413 | label: 'Datos extra', | ||
| 414 | })[0].checked = true; | ||
| 415 | |||
| 375 | $scope.hojaRuta.datosExtra = datosExtra; | 416 | $scope.hojaRuta.datosExtra = datosExtra; |
| 376 | }, function() { | 417 | }, function() { |
| 377 | //se ejecuta cuando se cancela el modal | 418 | //se ejecuta cuando se cancela el modal |
| 378 | }); | 419 | }); |
| 379 | }; | 420 | }; |
| 380 | 421 | ||
| 381 | $scope.desasociarRemito = function(key, idRemito) { | 422 | $scope.desasociarRemito = function(key, idRemito) { |
| 382 | var idsRemito = [idRemito]; | 423 | var idsRemito = [idRemito]; |
| 383 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + | 424 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + |
| 384 | ' vehículo?').then(function() { | 425 | ' vehículo?').then(function() { |
| 385 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, | 426 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, |
| 386 | $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) | 427 | $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) |
| 387 | .then(function() { | 428 | .then(function() { |
| 388 | $scope.hojaRuta.remitosTabla.splice(key, 1); | 429 | $scope.hojaRuta.remitosTabla.splice(key, 1); |
| 389 | focaModalService.alert('Remito desasociado con éxito'); | 430 | focaModalService.alert('Remito desasociado con éxito'); |
| 390 | }); | 431 | }); |
| 391 | }); | 432 | }); |
| 392 | }; | 433 | }; |
| 393 | 434 | ||
| 394 | $scope.verProductosRemito = function(idRemito) { | 435 | $scope.verProductosRemito = function(idRemito) { |
| 395 | var parametrosModal = { | 436 | var parametrosModal = { |
| 396 | titulo: 'Articulos remito', | 437 | titulo: 'Articulos remito', |
| 397 | query: '/articulos/remito/' + idRemito, | 438 | query: '/articulos/remito/' + idRemito, |
| 398 | soloMostrar: true, | 439 | soloMostrar: true, |
| 399 | columnas: [ | 440 | columnas: [ |
| 400 | { | 441 | { |
| 401 | nombre: 'Código', | 442 | nombre: 'Código', |
| 402 | propiedad: 'codigo' | 443 | propiedad: 'codigo' |
| 403 | }, | 444 | }, |
| 404 | { | 445 | { |
| 405 | nombre: 'Descripción', | 446 | nombre: 'Descripción', |
| 406 | propiedad: 'descripcion' | 447 | propiedad: 'descripcion' |
| 407 | }, | 448 | }, |
| 408 | { | 449 | { |
| 409 | nombre: 'Cantidad', | 450 | nombre: 'Cantidad', |
| 410 | propiedad: 'cantidad' | 451 | propiedad: 'cantidad' |
| 411 | } | 452 | } |
| 412 | ] | 453 | ] |
| 413 | }; | 454 | }; |
| 414 | focaModalService.modal(parametrosModal).then(); | 455 | focaModalService.modal(parametrosModal).then(); |
| 415 | }; | 456 | }; |
| 416 | 457 | ||
| 417 | function elegirFecha() { | 458 | function elegirFecha() { |
| 418 | var fechaEntrega = { | 459 | var fechaEntrega = { |
| 419 | titulo: 'Fecha de entrega', | 460 | titulo: 'Fecha de entrega', |
| 420 | minDate: new Date() | 461 | minDate: new Date() |
| 421 | }; | 462 | }; |
| 422 | focaModalService.modalFecha(fechaEntrega).then(function(fecha) { | 463 | focaModalService.modalFecha(fechaEntrega).then(function(fecha) { |
| 464 | |||
| 423 | $scope.$broadcast('addCabecera', { | 465 | $scope.$broadcast('addCabecera', { |
| 424 | label: 'Fecha de entrega: ', | 466 | label: 'Fecha de entrega: ', |
| 425 | valor: fecha.toLocaleDateString() | 467 | valor: fecha.toLocaleDateString() |
| 426 | }); | 468 | }); |
| 469 | |||
| 470 | $filter('filter')($scope.botonera, { | ||
| 471 | label: 'Fecha Entrega', | ||
| 472 | })[0].checked = true; | ||
| 473 | |||
| 427 | $scope.hojaRuta.fechaReparto = fecha; | 474 | $scope.hojaRuta.fechaReparto = fecha; |
| 428 | }); | 475 | }); |
| 429 | } | 476 | } |
| 430 | 477 | ||
| 431 | function eligioPreConfirmado() { | 478 | function eligioPreConfirmado() { |
| 432 | if ($scope.eligioPreConfirmado) { | 479 | if ($scope.eligioPreConfirmado) { |
| 433 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); | 480 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); |
| 434 | return true; | 481 | return true; |
| 435 | } | 482 | } |
| 436 | return false; | 483 | return false; |
| 437 | } | 484 | } |
| 438 | 485 | ||
| 439 | function eligioFecha() { | 486 | function eligioFecha() { |
| 440 | if (!$scope.hojaRuta.fechaReparto) { | 487 | if (!$scope.hojaRuta.fechaReparto) { |
| 441 | focaModalService.alert('Primero seleccione fecha de reparto'); | 488 | focaModalService.alert('Primero seleccione fecha de reparto'); |
| 442 | return false; | 489 | return false; |
| 443 | } | 490 | } |
| 444 | return true; | 491 | return true; |
| 445 | } | 492 | } |
| 446 | 493 | ||
| 447 | function eligioVehiculo() { | 494 | function eligioVehiculo() { |
| 448 | if (!$scope.hojaRuta.vehiculo.id) { | 495 | if (!$scope.hojaRuta.vehiculo.id) { |
| 449 | focaModalService.alert('Primero seleccione vehiculo'); | 496 | focaModalService.alert('Primero seleccione vehiculo'); |
| 450 | return false; | 497 | return false; |
| 451 | } | 498 | } |
| 452 | return true; | 499 | return true; |
| 453 | } | 500 | } |
| 454 | 501 | ||
| 455 | function modalVehiculos(preCargados) { | 502 | function modalVehiculos(preCargados) { |
| 456 | var parametrosModal = {}; | 503 | var parametrosModal = {}; |
| 457 | if (preCargados) { | 504 | if (preCargados) { |
| 458 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + | 505 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + |
| 459 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); | 506 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); |
| 460 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; | 507 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; |
| 461 | } else { | 508 | } else { |
| 462 | parametrosModal.query = '/vehiculo'; | 509 | parametrosModal.query = '/vehiculo'; |
| 463 | parametrosModal.titulo = 'Búsqueda de vehículos'; | 510 | parametrosModal.titulo = 'Búsqueda de vehículos'; |
| 464 | } | 511 | } |
| 465 | parametrosModal.columnas = [ | 512 | parametrosModal.columnas = [ |
| 466 | { | 513 | { |
| 467 | propiedad: 'codigo', | 514 | propiedad: 'codigo', |
| 468 | nombre: 'Código' | 515 | nombre: 'Código' |
| 469 | }, | 516 | }, |
| 470 | { | 517 | { |
| 471 | propiedad: 'tractor', | 518 | propiedad: 'tractor', |
| 472 | nombre: 'tractor' | 519 | nombre: 'tractor' |
| 473 | }, | 520 | }, |
| 474 | { | 521 | { |
| 475 | propiedad: 'semi', | 522 | propiedad: 'semi', |
| 476 | nombre: 'Semi' | 523 | nombre: 'Semi' |
| 477 | } | 524 | } |
| 478 | ]; | 525 | ]; |
| 479 | focaModalService.modal(parametrosModal).then(function(vehiculo) { | 526 | focaModalService.modal(parametrosModal).then(function(vehiculo) { |
| 480 | if (!preCargados && vehiculoEnUso(vehiculo)) return; | 527 | if (!preCargados && vehiculoEnUso(vehiculo)) return; |
| 481 | $scope.hojaRuta.vehiculo = vehiculo; | 528 | $scope.hojaRuta.vehiculo = vehiculo; |
| 482 | $scope.hojaRuta.transportista = vehiculo.transportista; | 529 | $scope.hojaRuta.transportista = vehiculo.transportista; |
| 483 | if (preCargados) { | 530 | if (preCargados) { |
| 484 | $scope.eligioPreConfirmado = true; | 531 | $scope.eligioPreConfirmado = true; |
| 485 | $scope.hojaRuta.vehiculo = vehiculo; | 532 | $scope.hojaRuta.vehiculo = vehiculo; |
| 486 | $scope.$broadcast('addCabecera', { | 533 | $scope.$broadcast('addCabecera', { |
| 487 | label: 'Transportista:', | 534 | label: 'Transportista:', |
| 488 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + | 535 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + |
| 489 | ' - ' + vehiculo.transportista.NOM | 536 | ' - ' + vehiculo.transportista.NOM |
| 490 | }); | 537 | }); |
| 491 | focaCrearHojaRutaService | 538 | focaCrearHojaRutaService |
| 492 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) | 539 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) |
| 493 | .then(function(res) { | 540 | .then(function(res) { |
| 541 | |||
| 542 | $filter('filter')($scope.botonera, { | ||
| 543 | label: 'Vehiculos precargados', | ||
| 544 | })[0].checked = true; | ||
| 545 | |||
| 494 | $scope.hojaRuta.remitosTabla = res.data; | 546 | $scope.hojaRuta.remitosTabla = res.data; |
| 495 | }); | 547 | }); |
| 496 | } else { | 548 | } else { |
| 497 | focaCrearHojaRutaService | 549 | focaCrearHojaRutaService |
| 498 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) | 550 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) |
| 499 | .then(function(res) { | 551 | .then(function(res) { |
| 552 | |||
| 553 | $filter('filter')($scope.botonera, { | ||
| 554 | label: 'Vehiculo', | ||
| 555 | })[0].checked = true; | ||
| 556 | |||
| 500 | $scope.hojaRuta.remitosTabla = res.data; | 557 | $scope.hojaRuta.remitosTabla = res.data; |
| 501 | }); | 558 | }); |
| 502 | } | 559 | } |
| 503 | $scope.$broadcast('addCabecera', { | 560 | $scope.$broadcast('addCabecera', { |
| 504 | label: 'Tractor:', | 561 | label: 'Tractor:', |
| 505 | valor: vehiculo.tractor | 562 | valor: vehiculo.tractor |
| 506 | }); | 563 | }); |
| 507 | $scope.$broadcast('addCabecera', { | 564 | $scope.$broadcast('addCabecera', { |
| 508 | label: 'Semi:', | 565 | label: 'Semi:', |
| 509 | valor: vehiculo.semi | 566 | valor: vehiculo.semi |
| 510 | }); | 567 | }); |
| 511 | $scope.$broadcast('addCabecera', { | 568 | $scope.$broadcast('addCabecera', { |
| 512 | label: 'Capacidad:', | 569 | label: 'Capacidad:', |
| 513 | valor: vehiculo.capacidad | 570 | valor: vehiculo.capacidad |
| 514 | }); | 571 | }); |
| 572 | |||
| 515 | }); | 573 | }); |
| 516 | } | 574 | } |
| 517 | 575 | ||
| 518 | function vehiculoEnUso(vehiculo) { | 576 | function vehiculoEnUso(vehiculo) { |
| 519 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; | 577 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; |
| 520 | for (var i = 0; i < vehiculo.cisternas.length; i++) { | 578 | for (var i = 0; i < vehiculo.cisternas.length; i++) { |
| 521 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { | 579 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { |
| 522 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; | 580 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; |
| 523 | if (cisternaCarga.fechaReparto.substring(0, 10) === | 581 | if (cisternaCarga.fechaReparto.substring(0, 10) === |
| 524 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && | 582 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && |
| 525 | cisternaCarga.idUsuarioProceso && | 583 | cisternaCarga.idUsuarioProceso && |
| 526 | cisternaCarga.idUsuarioProceso !== idUsuario) | 584 | cisternaCarga.idUsuarioProceso !== idUsuario) |
| 527 | { | 585 | { |
| 528 | focaModalService.alert('El vehículo está siendo usado por otro' + | 586 | focaModalService.alert('El vehículo está siendo usado por otro' + |
| 529 | ' usuario'); | 587 | ' usuario'); |
| 530 | return true; | 588 | return true; |
| 531 | } | 589 | } |
| 532 | } | 590 | } |
| 533 | } | 591 | } |
| 534 | return false; | 592 | return false; |
| 535 | } | 593 | } |
| 536 | 594 | ||
| 537 | function salir() { | 595 | function salir() { |
| 538 | var confirmacion = false; | 596 | var confirmacion = false; |
| 539 | 597 | ||
| 540 | if (!angular.equals($scope.hojaRuta, $scope.inicial)) { | 598 | if (!angular.equals($scope.hojaRuta, $scope.inicial)) { |
| 541 | confirmacion = true; | 599 | confirmacion = true; |
| 542 | } | 600 | } |
| 543 | 601 | ||
| 544 | if (confirmacion) { | 602 | if (confirmacion) { |
| 545 | focaModalService.confirm( | 603 | focaModalService.confirm( |
| 546 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 604 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 547 | ).then(function(data) { | 605 | ).then(function(data) { |
| 548 | if (data) { | 606 | if (data) { |
| 549 | $location.path('/'); | 607 | $location.path('/'); |
| 550 | } | 608 | } |
| 551 | }); | 609 | }); |
| 552 | } else { | 610 | } else { |
| 553 | $location.path('/'); | 611 | $location.path('/'); |
| 554 | } | 612 | } |
| 555 | } | 613 | } |
| 556 | 614 | ||
| 557 | function setearHojaRuta(hojaRuta) { | 615 | function setearHojaRuta(hojaRuta) { |
| 558 | $scope.$broadcast('cleanCabecera'); | 616 | $scope.$broadcast('cleanCabecera'); |
| 559 | 617 | ||
| 560 | var cabeceras = []; | 618 | var cabeceras = []; |
| 561 | if (hojaRuta.fechaReparto) { | 619 | if (hojaRuta.fechaReparto) { |
| 562 | cabeceras.push({ | 620 | cabeceras.push({ |
| 563 | label: 'Fecha de entrega:', | 621 | label: 'Fecha de entrega:', |
| 564 | valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') | 622 | valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') |
| 565 | }); | 623 | }); |
| 624 | |||
| 625 | $filter('filter')( $scope.botonera, { | ||
| 626 | label: 'Fecha Entrega' | ||
| 627 | })[0].checked = true; | ||
| 566 | } | 628 | } |
| 567 | if (hojaRuta.transportista.COD) { | 629 | if (hojaRuta.transportista.COD) { |
| 568 | cabeceras.push({ | 630 | cabeceras.push({ |
| 569 | label: 'Transportista:', | 631 | label: 'Transportista:', |
| 570 | valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + | 632 | valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + |
| 571 | hojaRuta.transportista.NOM | 633 | hojaRuta.transportista.NOM |
| 572 | }); | 634 | }); |
| 635 | |||
| 636 | $filter('filter')( $scope.botonera, { | ||
| 637 | label: 'Transportista' | ||
| 638 | })[0].checked = true; | ||
| 573 | } | 639 | } |
| 574 | if (hojaRuta.chofer.id) { | 640 | if (hojaRuta.chofer.id) { |
| 575 | cabeceras.push({ | 641 | cabeceras.push({ |
| 576 | label: 'Chofer:', | 642 | label: 'Chofer:', |
| 577 | valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + | 643 | valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + |
| 578 | ' - ' + hojaRuta.chofer.nombre | 644 | ' - ' + hojaRuta.chofer.nombre |
| 579 | }); | 645 | }); |
| 646 | |||
| 647 | $filter('filter')( $scope.botonera, { | ||
| 648 | label: 'Chofer' | ||
| 649 | })[0].checked = true; | ||
| 580 | } | 650 | } |
| 581 | if (hojaRuta.vehiculo.id) { | 651 | if (hojaRuta.vehiculo.id) { |
| 582 | cabeceras.push({ | 652 | cabeceras.push({ |
| 583 | label: 'Tractor:', | 653 | label: 'Tractor:', |
| 584 | valor: hojaRuta.vehiculo.tractor | 654 | valor: hojaRuta.vehiculo.tractor |
| 585 | }); | 655 | }); |
| 586 | cabeceras.push({ | 656 | cabeceras.push({ |
| 587 | label: 'Semi:', | 657 | label: 'Semi:', |
| 588 | valor: hojaRuta.vehiculo.semi | 658 | valor: hojaRuta.vehiculo.semi |
| 589 | }); | 659 | }); |
| 590 | cabeceras.push({ | 660 | cabeceras.push({ |
| 591 | label: 'Capacidad:', | 661 | label: 'Capacidad:', |
| 592 | valor: hojaRuta.vehiculo.capacidad | 662 | valor: hojaRuta.vehiculo.capacidad |
| 593 | }); | 663 | }); |
| 664 | |||
| 665 | $filter('filter')( $scope.botonera, { | ||
| 666 | label: 'Vehiculo' | ||
| 667 | })[0].checked = true; | ||
| 594 | } | 668 | } |
| 595 | if (hojaRuta.tarifario.costo) { | 669 | if (hojaRuta.tarifario) { |
| 596 | cabeceras.push({ | 670 | cabeceras.push({ |
| 597 | label: 'Tarifario:', | 671 | label: 'Tarifario:', |
| 598 | valor: hojaRuta.tarifario.costo | 672 | valor: hojaRuta.tarifario |
| 599 | }); | 673 | }); |
| 674 | |||
| 675 | $filter('filter')( $scope.botonera, { | ||
| 676 | label: 'Tarifario' | ||
| 677 | })[0].checked = true; | ||
| 600 | } | 678 | } |
| 601 | 679 | ||
| 602 | addArrayCabecera(cabeceras); | 680 | addArrayCabecera(cabeceras); |
| 603 | $scope.hojaRuta = hojaRuta; | 681 | $scope.hojaRuta = hojaRuta; |
| 604 | } | 682 | } |
| 605 | 683 | ||
| 606 | function getLSHojaRuta() { | 684 | function getLSHojaRuta() { |
| 607 | var hojaRuta = JSON.parse($localStorage.hojaRuta || null); | 685 | var hojaRuta = JSON.parse($localStorage.hojaRuta || null); |
| 608 | if (hojaRuta) { | 686 | if (hojaRuta) { |
| 609 | setearHojaRuta(hojaRuta); | 687 | setearHojaRuta(hojaRuta); |
| 610 | delete $localStorage.hojaRuta; | 688 | delete $localStorage.hojaRuta; |
| 611 | } | 689 | } |
| 612 | } | 690 | } |
| 613 | function addArrayCabecera(array) { | 691 | function addArrayCabecera(array) { |
| 614 | for(var i = 0; i < array.length; i++) { | 692 | for(var i = 0; i < array.length; i++) { |
| 615 | $scope.$broadcast('addCabecera', { | 693 | $scope.$broadcast('addCabecera', { |
| 616 | label: array[i].label, | 694 | label: array[i].label, |
| 617 | valor: array[i].valor | 695 | valor: array[i].valor |
| 618 | }); | 696 | }); |
| 619 | } | 697 | } |
src/js/service.js
| 1 | angular.module('focaCrearHojaRuta') | 1 | angular.module('focaCrearHojaRuta') |
| 2 | .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', | 2 | .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', |
| 3 | function($http, API_ENDPOINT) { | 3 | function($http, API_ENDPOINT) { |
| 4 | var route = API_ENDPOINT.URL; | 4 | var route = API_ENDPOINT.URL; |
| 5 | return { | 5 | return { |
| 6 | crearHojaRuta: function(hojaRuta) { | 6 | crearHojaRuta: function(hojaRuta) { |
| 7 | return $http.post(route + '/hoja-ruta', hojaRuta); | 7 | return $http.post(route + '/hoja-ruta', hojaRuta); |
| 8 | }, | 8 | }, |
| 9 | obtenerHojaRuta: function() { | 9 | obtenerHojaRuta: function() { |
| 10 | return $http.get(route +'/hoja-ruta'); | 10 | return $http.get(route +'/hoja-ruta'); |
| 11 | }, | 11 | }, |
| 12 | setHojaRuta: function(hojaRuta) { | 12 | setHojaRuta: function(hojaRuta) { |
| 13 | this.hojaRuta = hojaRuta; | 13 | this.hojaRuta = hojaRuta; |
| 14 | }, | 14 | }, |
| 15 | clearHojaRuta: function() { | 15 | clearHojaRuta: function() { |
| 16 | this.hojaRuta = undefined; | 16 | this.hojaRuta = undefined; |
| 17 | }, | 17 | }, |
| 18 | getHojaRuta: function() { | 18 | getHojaRuta: function() { |
| 19 | return this.hojaRuta; | 19 | return this.hojaRuta; |
| 20 | }, | 20 | }, |
| 21 | getArticulosByIdHojaRuta: function(id) { | 21 | getArticulosByIdHojaRuta: function(id) { |
| 22 | return $http.get(route+'/articulos/hoja-ruta/'+id); | 22 | return $http.get(route+'/articulos/hoja-ruta/'+id); |
| 23 | }, | 23 | }, |
| 24 | crearArticulosParaHojaRuta: function(articuloHojaRuta) { | 24 | crearArticulosParaHojaRuta: function(articuloHojaRuta) { |
| 25 | return $http.post(route + '/articulos/hoja-ruta', | 25 | return $http.post(route + '/articulos/hoja-ruta', |
| 26 | {articuloHojaRuta: articuloHojaRuta}); | 26 | {articuloHojaRuta: articuloHojaRuta}); |
| 27 | }, | 27 | }, |
| 28 | getDomiciliosByIdHojaRuta: function(id) { | 28 | getDomiciliosByIdHojaRuta: function(id) { |
| 29 | return $http.get(route +'/hoja-ruta/' + id + '/domicilios'); | 29 | return $http.get(route +'/hoja-ruta/' + id + '/domicilios'); |
| 30 | }, | 30 | }, |
| 31 | getDomiciliosByIdCliente: function(id) { | 31 | getDomiciliosByIdCliente: function(id) { |
| 32 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) | 32 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) |
| 33 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); | 33 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); |
| 34 | }, | 34 | }, |
| 35 | getPrecioCondicion: function() { | 35 | getPrecioCondicion: function() { |
| 36 | return $http.get(route + '/precio-condicion'); | 36 | return $http.get(route + '/precio-condicion'); |
| 37 | }, | 37 | }, |
| 38 | getPrecioCondicionById: function(id) { | 38 | getPrecioCondicionById: function(id) { |
| 39 | return $http.get(route + '/precio-condicion/' + id); | 39 | return $http.get(route + '/precio-condicion/' + id); |
| 40 | }, | 40 | }, |
| 41 | getPlazoPagoByPrecioCondicion: function(id) { | 41 | getPlazoPagoByPrecioCondicion: function(id) { |
| 42 | return $http.get(route + '/plazo-pago/precio-condicion/' + id); | 42 | return $http.get(route + '/plazo-pago/precio-condicion/' + id); |
| 43 | }, | 43 | }, |
| 44 | crearFlete: function(flete) { | 44 | crearFlete: function(flete) { |
| 45 | return $http.post(route + '/flete', {flete : flete}); | 45 | return $http.post(route + '/flete', {flete : flete}); |
| 46 | }, | 46 | }, |
| 47 | crearPlazosParaHojaRuta: function(plazos) { | 47 | crearPlazosParaHojaRuta: function(plazos) { |
| 48 | return $http.post(route + '/plazo-pago/hoja-ruta', plazos); | 48 | return $http.post(route + '/plazo-pago/hoja-ruta', plazos); |
| 49 | }, | 49 | }, |
| 50 | getCotizacionByIdMoneda: function(id) { | 50 | getCotizacionByIdMoneda: function(id) { |
| 51 | return $http.get(route + '/moneda/' + id); | 51 | return $http.get(route + '/moneda/' + id); |
| 52 | }, | 52 | }, |
| 53 | crearEstadoParaHojaRuta: function(estado) { | 53 | crearEstadoParaHojaRuta: function(estado) { |
| 54 | return $http.post(route + '/estado', {estado: estado}); | 54 | return $http.post(route + '/estado', {estado: estado}); |
| 55 | }, | 55 | }, |
| 56 | getNumeroHojaRuta: function() { | 56 | getNumeroHojaRuta: function() { |
| 57 | return $http.get(route + '/hoja-ruta/numero-siguiente'); | 57 | return $http.get(route + '/hoja-ruta/numero-siguiente'); |
| 58 | }, | 58 | }, |
| 59 | getRemitosByIdVehiculo: function(idVehiculo, fechaReparto, sinConfirmar) { | 59 | getRemitosByIdVehiculo: function(idVehiculo, fechaReparto, sinConfirmar) { |
| 60 | var noCofirmados = sinConfirmar ? '/sinConfirmar' : ''; | 60 | var noCofirmados = sinConfirmar ? '/sinConfirmar' : ''; |
| 61 | return $http.get(route + '/vehiculo/obtener/remitos/' + | 61 | return $http.get(route + '/vehiculo/obtener/remitos/' + |
| 62 | idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10) + noCofirmados); | 62 | idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10) + noCofirmados); |
| 63 | }, | 63 | }, |
| 64 | desasociarRemitos: function(idsRemitos, idVehiculo, sinRemitos) { | 64 | desasociarRemitos: function(idsRemitos, idVehiculo, sinRemitos) { |
| 65 | return $http.post(route + '/vehiculo/desasociar-remitos', | 65 | return $http.post(route + '/vehiculo/desasociar-remitos', |
| 66 | { | 66 | { |
| 67 | idsRemitos: idsRemitos, | 67 | idsRemitos: idsRemitos, |
| 68 | idVehiculo: idVehiculo, | 68 | idVehiculo: idVehiculo, |
| 69 | vehiculoSinRemitos: sinRemitos | 69 | vehiculoSinRemitos: sinRemitos |
| 70 | }); | 70 | }); |
| 71 | }, | 71 | }, |
| 72 | getParametros: function() { | ||
| 73 | return $http.get(API_ENDPOINT.URL + '/parametros/hojaRuta'); | ||
| 74 | }, | ||
| 72 | getBotonera: function() { | 75 | getBotonera: function() { |
| 73 | return [ | 76 | return [ |
| 74 | { | 77 | { |
| 75 | label: 'Fecha Entrega', | 78 | label: 'Fecha Entrega', |
| 76 | image: 'fechaDeReparto.png' | 79 | image: 'fechaDeReparto.png' |
| 77 | }, | 80 | }, |
| 78 | { | 81 | { |
| 79 | label: 'Transportista', | 82 | label: 'Transportista', |
| 80 | image: 'transportista.png' | 83 | image: 'transportista.png' |
| 81 | }, | 84 | }, |
| 82 | { | 85 | { |
| 83 | label: 'Chofer', | 86 | label: 'Chofer', |
| 84 | image: 'chofer.png' | 87 | image: 'chofer.png' |
| 85 | }, | 88 | }, |
| 86 | { | 89 | { |
| 87 | label: 'Vehiculo', | 90 | label: 'Vehiculo', |
| 88 | image: 'vehiculos.png' | 91 | image: 'vehiculos.png' |
| 89 | }, | 92 | }, |
| 90 | { | 93 | { |
| 91 | label: 'Tarifario', | 94 | label: 'Tarifario', |
| 92 | image: 'tarifario.png' | 95 | image: 'tarifario.png' |
| 93 | }, | 96 | }, |
| 94 | { | 97 | { |
| 95 | label: 'Remitos', | 98 | label: 'Remitos', |
| 96 | image: 'remito.png' | 99 | image: 'remito.png' |
| 97 | }, | 100 | }, |
| 98 | { | 101 | { |
| 99 | label: 'Vehiculos precargados', | 102 | label: 'Vehiculos precargados', |
| 100 | image: 'vehiculos.png' | 103 | image: 'vehiculos.png' |
| 101 | }, | 104 | }, |
| 102 | { | 105 | { |
| 103 | label: 'Datos extra', | 106 | label: 'Datos extra', |
| 104 | image: 'tarifario.png' | 107 | image: 'tarifario.png' |
| 105 | } | 108 | } |
| 106 | ]; | 109 | ]; |
| 107 | } | 110 | } |
| 108 | }; | 111 | }; |
| 109 | }]); | 112 | }]); |
| 110 | 113 |