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