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