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