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