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