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