Commit b824425a6b85424a515177cfb2a7c255cb99f848
1 parent
fc27ef770c
Exists in
master
and in
1 other branch
Cambios en seleccionar fechas pasadas
Showing
2 changed files
with
28 additions
and
24 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 | 68 | ||
69 | $scope.inicial = angular.copy($scope.hojaRuta); | 69 | $scope.inicial = angular.copy($scope.hojaRuta); |
70 | } | 70 | } |
71 | 71 | ||
72 | $scope.$watch('hojaRuta', function(newValue, oldValue) { | 72 | $scope.$watch('hojaRuta', function(newValue, oldValue) { |
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 | var modalInstance = $uibModal.open( | 217 | var modalInstance = $uibModal.open( |
218 | { | 218 | { |
219 | ariaLabelledBy: 'Busqueda de Tarifario', | 219 | ariaLabelledBy: 'Busqueda de Tarifario', |
220 | templateUrl: 'modal-tarifa-flete.html', | 220 | templateUrl: 'modal-tarifa-flete.html', |
221 | controller: 'focaModalTarifaFleteController', | 221 | controller: 'focaModalTarifaFleteController', |
222 | size: 'lg', | 222 | size: 'lg', |
223 | resolve: { | 223 | resolve: { |
224 | parametrosTarifaFlete: function() { | 224 | parametrosTarifaFlete: function() { |
225 | return $scope.hojaRuta.tarifario.costo; | 225 | return $scope.hojaRuta.tarifario.costo; |
226 | } | 226 | } |
227 | } | 227 | } |
228 | } | 228 | } |
229 | ); | 229 | ); |
230 | 230 | ||
231 | modalInstance.result.then( | 231 | modalInstance.result.then( |
232 | function(tarifario) { | 232 | function(tarifario) { |
233 | $scope.hojaRuta.tarifario = tarifario; | 233 | $scope.hojaRuta.tarifario = tarifario; |
234 | $scope.$broadcast('addCabecera', { | 234 | $scope.$broadcast('addCabecera', { |
235 | label: 'Tarifario:', | 235 | label: 'Tarifario:', |
236 | valor: tarifario.costo | 236 | valor: tarifario.costo |
237 | }); | 237 | }); |
238 | }, function() { | 238 | }, function() { |
239 | // funcion ejecutada cuando se cancela el modal | 239 | // funcion ejecutada cuando se cancela el modal |
240 | } | 240 | } |
241 | ); | 241 | ); |
242 | }; | 242 | }; |
243 | 243 | ||
244 | $scope.seleccionarRemitos = function() { | 244 | $scope.seleccionarRemitos = function() { |
245 | if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; | 245 | if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; |
246 | var modalInstance = $uibModal.open( | 246 | var modalInstance = $uibModal.open( |
247 | { | 247 | { |
248 | ariaLabelledBy: 'Busqueda de Remito', | 248 | ariaLabelledBy: 'Busqueda de Remito', |
249 | templateUrl: 'foca-modal-remito.html', | 249 | templateUrl: 'foca-modal-remito.html', |
250 | controller: 'focaModalRemitoController', | 250 | controller: 'focaModalRemitoController', |
251 | size: 'lg', | 251 | size: 'lg', |
252 | resolve: {usadoPor: function() {return 'hojaRuta';}} | 252 | resolve: {usadoPor: function() {return 'hojaRuta';}} |
253 | } | 253 | } |
254 | ); | 254 | ); |
255 | modalInstance.result.then( | 255 | modalInstance.result.then( |
256 | function(remito) { | 256 | function(remito) { |
257 | // TODO: borrar cuando no se use definitivamente | 257 | // TODO: borrar cuando no se use definitivamente |
258 | // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { | 258 | // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { |
259 | // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { | 259 | // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { |
260 | // focaModalService.alert('Remito ya incluido'); | 260 | // focaModalService.alert('Remito ya incluido'); |
261 | // return; | 261 | // return; |
262 | // } | 262 | // } |
263 | // } | 263 | // } |
264 | 264 | ||
265 | // var litros = 0; | 265 | // var litros = 0; |
266 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { | 266 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { |
267 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); | 267 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); |
268 | // } | 268 | // } |
269 | 269 | ||
270 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { | 270 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { |
271 | // focaModalService.alert( | 271 | // focaModalService.alert( |
272 | // 'Debe ingresar toda la información para el transporte' | 272 | // 'Debe ingresar toda la información para el transporte' |
273 | // ); | 273 | // ); |
274 | // return; | 274 | // return; |
275 | // } | 275 | // } |
276 | 276 | ||
277 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) | 277 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) |
278 | // { | 278 | // { |
279 | // var litrostotales = litros; | 279 | // var litrostotales = litros; |
280 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; | 280 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; |
281 | // focaModalService.alert( | 281 | // focaModalService.alert( |
282 | // 'La carga excede la capacidad disponible del vehiculo. ' + | 282 | // 'La carga excede la capacidad disponible del vehiculo. ' + |
283 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' | 283 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' |
284 | // ); | 284 | // ); |
285 | // } | 285 | // } |
286 | 286 | ||
287 | // remito.litros = litros; | 287 | // remito.litros = litros; |
288 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; | 288 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; |
289 | $scope.cargarCisterna(remito.id).then(function() { | 289 | $scope.cargarCisterna(remito.id).then(function() { |
290 | $scope.hojaRuta.remitosTabla.push(remito); | 290 | $scope.hojaRuta.remitosTabla.push(remito); |
291 | $scope.seleccionarRemitos(); | 291 | $scope.seleccionarRemitos(); |
292 | }, function() { | 292 | }, function() { |
293 | $scope.seleccionarRemitos(); | 293 | $scope.seleccionarRemitos(); |
294 | }); | 294 | }); |
295 | }, function() { | 295 | }, function() { |
296 | // funcion ejecutada cuando se cancela el modal | 296 | // funcion ejecutada cuando se cancela el modal |
297 | } | 297 | } |
298 | ); | 298 | ); |
299 | }; | 299 | }; |
300 | 300 | ||
301 | $scope.seleccionarVehiculosPrecargados = function() { | 301 | $scope.seleccionarVehiculosPrecargados = function() { |
302 | if(!eligioFecha()) return; | 302 | if (!eligioFecha()) return; |
303 | modalVehiculos(true); | 303 | modalVehiculos(true); |
304 | }; | 304 | }; |
305 | 305 | ||
306 | $scope.cargarCisterna = function(idRemito) { | 306 | $scope.cargarCisterna = function(idRemito) { |
307 | if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; | 307 | if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; |
308 | var modalInstance = $uibModal.open( | 308 | var modalInstance = $uibModal.open( |
309 | { | 309 | { |
310 | ariaLabelledBy: 'Busqueda de Vehiculo', | 310 | ariaLabelledBy: 'Busqueda de Vehiculo', |
311 | templateUrl: 'foca-detalle-vehiculo.html', | 311 | templateUrl: 'foca-detalle-vehiculo.html', |
312 | controller: 'focaDetalleVehiculo', | 312 | controller: 'focaDetalleVehiculo', |
313 | size: 'lg', | 313 | size: 'lg', |
314 | resolve: { | 314 | resolve: { |
315 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, | 315 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, |
316 | idRemito: function() {return idRemito;}, | 316 | idRemito: function() {return idRemito;}, |
317 | fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} | 317 | fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} |
318 | } | 318 | } |
319 | } | 319 | } |
320 | ); | 320 | ); |
321 | return modalInstance.result; | 321 | return modalInstance.result; |
322 | }; | 322 | }; |
323 | 323 | ||
324 | $scope.seleccionarFechaEntrega = function() { | 324 | $scope.seleccionarFechaEntrega = function() { |
325 | if (!$scope.hojaRuta.fechaReparto) { | 325 | if (!$scope.hojaRuta.fechaReparto) { |
326 | elegirFecha(); | 326 | elegirFecha(); |
327 | return; | 327 | return; |
328 | } | 328 | } |
329 | focaModalService | 329 | focaModalService |
330 | .confirm('Si cambia la fecha se perderán los datos actuales') | 330 | .confirm('Si cambia la fecha se perderán los datos actuales') |
331 | .then(function() { | 331 | .then(function() { |
332 | elegirFecha(); | 332 | elegirFecha(); |
333 | }, function() { | 333 | }, function() { |
334 | return ; | 334 | return ; |
335 | }); | 335 | }); |
336 | }; | 336 | }; |
337 | 337 | ||
338 | $scope.seleccionarDatosExtra = function() { | 338 | $scope.seleccionarDatosExtra = function() { |
339 | var datosHojaRuta = $scope.hojaRuta.datosExtra; | 339 | var datosHojaRuta = $scope.hojaRuta.datosExtra; |
340 | var modalInstance = $uibModal.open( | 340 | var modalInstance = $uibModal.open( |
341 | { | 341 | { |
342 | templateUrl: 'foca-modal-datos-hoja-ruta.html', | 342 | templateUrl: 'foca-modal-datos-hoja-ruta.html', |
343 | controller: 'focaModalDatosHojaRutaCtrl', | 343 | controller: 'focaModalDatosHojaRutaCtrl', |
344 | size: 'lg', | 344 | size: 'lg', |
345 | resolve: { | 345 | resolve: { |
346 | parametrosDatos: function() { | 346 | parametrosDatos: function() { |
347 | return { | 347 | return { |
348 | datosHojaRuta: datosHojaRuta | 348 | datosHojaRuta: datosHojaRuta |
349 | }; | 349 | }; |
350 | } | 350 | } |
351 | } | 351 | } |
352 | } | 352 | } |
353 | ); | 353 | ); |
354 | return modalInstance.result.then(function(datosExtra) { | 354 | return modalInstance.result.then(function(datosExtra) { |
355 | $scope.hojaRuta.datosExtra = datosExtra; | 355 | $scope.hojaRuta.datosExtra = datosExtra; |
356 | }, function() { | 356 | }, function() { |
357 | //se ejecuta cuando se cancela el modal | 357 | //se ejecuta cuando se cancela el modal |
358 | }); | 358 | }); |
359 | }; | 359 | }; |
360 | 360 | ||
361 | $scope.desasociarRemito = function(key, idRemito) { | 361 | $scope.desasociarRemito = function(key, idRemito) { |
362 | var idsRemito = [idRemito]; | 362 | var idsRemito = [idRemito]; |
363 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + | 363 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + |
364 | ' vehículo?').then(function() { | 364 | ' vehículo?').then(function() { |
365 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, | 365 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, |
366 | $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1).then( | 366 | $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1).then( |
367 | function() { | 367 | function() { |
368 | $scope.hojaRuta.remitosTabla.splice(key, 1); | 368 | $scope.hojaRuta.remitosTabla.splice(key, 1); |
369 | focaModalService.alert('Remito desasociado con éxito'); | 369 | focaModalService.alert('Remito desasociado con éxito'); |
370 | } | 370 | } |
371 | ); | 371 | ); |
372 | }); | 372 | }); |
373 | }; | 373 | }; |
374 | 374 | ||
375 | function elegirFecha() { | 375 | function elegirFecha() { |
376 | focaModalService.modalFecha('Fecha de entrega').then(function(fecha) { | 376 | var fechaEntrega = { |
377 | titulo: 'Fecha de entrega', | ||
378 | minDate: new Date() | ||
379 | }; | ||
380 | focaModalService.modalFecha(fechaEntrega).then(function(fecha) { | ||
377 | $scope.$broadcast('addCabecera', { | 381 | $scope.$broadcast('addCabecera', { |
378 | label: 'Fecha de entrega:', | 382 | label: 'Fecha de entrega: ', |
379 | valor: fecha.toLocaleDateString() | 383 | valor: fecha.toLocaleDateString() |
380 | }); | 384 | }); |
381 | $scope.hojaRuta.fechaReparto = fecha; | 385 | $scope.hojaRuta.fechaReparto = fecha; |
382 | }); | 386 | }); |
383 | } | 387 | } |
384 | 388 | ||
385 | function eligioPreConfirmado() { | 389 | function eligioPreConfirmado() { |
386 | if($scope.eligioPreConfirmado) { | 390 | if ($scope.eligioPreConfirmado) { |
387 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); | 391 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); |
388 | return true; | 392 | return true; |
389 | } | 393 | } |
390 | return false; | 394 | return false; |
391 | } | 395 | } |
392 | 396 | ||
393 | function eligioFecha() { | 397 | function eligioFecha() { |
394 | if(!$scope.hojaRuta.fechaReparto) { | 398 | if (!$scope.hojaRuta.fechaReparto) { |
395 | focaModalService.alert('Primero seleccione fecha de reparto'); | 399 | focaModalService.alert('Primero seleccione fecha de reparto'); |
396 | return false; | 400 | return false; |
397 | } | 401 | } |
398 | return true; | 402 | return true; |
399 | } | 403 | } |
400 | 404 | ||
401 | function eligioVehiculo() { | 405 | function eligioVehiculo() { |
402 | if(!$scope.hojaRuta.vehiculo.id) { | 406 | if (!$scope.hojaRuta.vehiculo.id) { |
403 | focaModalService.alert('Primero seleccione vehiculo'); | 407 | focaModalService.alert('Primero seleccione vehiculo'); |
404 | return false; | 408 | return false; |
405 | } | 409 | } |
406 | return true; | 410 | return true; |
407 | } | 411 | } |
408 | 412 | ||
409 | function modalVehiculos(preCargados) { | 413 | function modalVehiculos(preCargados) { |
410 | var parametrosModal = {}; | 414 | var parametrosModal = {}; |
411 | if(preCargados) { | 415 | if (preCargados) { |
412 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + | 416 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + |
413 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); | 417 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); |
414 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; | 418 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; |
415 | }else { | 419 | } else { |
416 | parametrosModal.query = '/vehiculo'; | 420 | parametrosModal.query = '/vehiculo'; |
417 | parametrosModal.titulo = 'Búsqueda de vehículos'; | 421 | parametrosModal.titulo = 'Búsqueda de vehículos'; |
418 | } | 422 | } |
419 | parametrosModal.columnas = [ | 423 | parametrosModal.columnas = [ |
420 | { | 424 | { |
421 | propiedad: 'codigo', | 425 | propiedad: 'codigo', |
422 | nombre: 'Código' | 426 | nombre: 'Código' |
423 | }, | 427 | }, |
424 | { | 428 | { |
425 | propiedad: 'tractor', | 429 | propiedad: 'tractor', |
426 | nombre: 'tractor' | 430 | nombre: 'tractor' |
427 | }, | 431 | }, |
428 | { | 432 | { |
429 | propiedad: 'semi', | 433 | propiedad: 'semi', |
430 | nombre: 'Semi' | 434 | nombre: 'Semi' |
431 | } | 435 | } |
432 | ]; | 436 | ]; |
433 | focaModalService.modal(parametrosModal).then(function(vehiculo) { | 437 | focaModalService.modal(parametrosModal).then(function(vehiculo) { |
434 | if(!preCargados && vehiculoEnUso(vehiculo)) return; | 438 | if (!preCargados && vehiculoEnUso(vehiculo)) return; |
435 | $scope.hojaRuta.vehiculo = vehiculo; | 439 | $scope.hojaRuta.vehiculo = vehiculo; |
436 | $scope.hojaRuta.transportista = vehiculo.transportista; | 440 | $scope.hojaRuta.transportista = vehiculo.transportista; |
437 | if(preCargados) { | 441 | if (preCargados) { |
438 | $scope.eligioPreConfirmado = true; | 442 | $scope.eligioPreConfirmado = true; |
439 | $scope.hojaRuta.vehiculo = vehiculo; | 443 | $scope.hojaRuta.vehiculo = vehiculo; |
440 | $scope.$broadcast('addCabecera', { | 444 | $scope.$broadcast('addCabecera', { |
441 | label: 'Transportista:', | 445 | label: 'Transportista:', |
442 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + | 446 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + |
443 | ' - ' + vehiculo.transportista.NOM | 447 | ' - ' + vehiculo.transportista.NOM |
444 | }); | 448 | }); |
445 | focaCrearHojaRutaService | 449 | focaCrearHojaRutaService |
446 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) | 450 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) |
447 | .then(function(res) { | 451 | .then(function(res) { |
448 | $scope.hojaRuta.remitosTabla = res.data; | 452 | $scope.hojaRuta.remitosTabla = res.data; |
449 | }); | 453 | }); |
450 | }else { | 454 | } else { |
451 | focaCrearHojaRutaService | 455 | focaCrearHojaRutaService |
452 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) | 456 | .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) |
453 | .then(function(res) { | 457 | .then(function(res) { |
454 | $scope.hojaRuta.remitosTabla = res.data; | 458 | $scope.hojaRuta.remitosTabla = res.data; |
455 | }); | 459 | }); |
456 | } | 460 | } |
457 | $scope.$broadcast('addCabecera', { | 461 | $scope.$broadcast('addCabecera', { |
458 | label: 'Tractor:', | 462 | label: 'Tractor:', |
459 | valor: vehiculo.tractor | 463 | valor: vehiculo.tractor |
460 | }); | 464 | }); |
461 | $scope.$broadcast('addCabecera', { | 465 | $scope.$broadcast('addCabecera', { |
462 | label: 'Semi:', | 466 | label: 'Semi:', |
463 | valor: vehiculo.semi | 467 | valor: vehiculo.semi |
464 | }); | 468 | }); |
465 | $scope.$broadcast('addCabecera', { | 469 | $scope.$broadcast('addCabecera', { |
466 | label: 'Capacidad:', | 470 | label: 'Capacidad:', |
467 | valor: vehiculo.capacidad | 471 | valor: vehiculo.capacidad |
468 | }); | 472 | }); |
469 | }); | 473 | }); |
470 | } | 474 | } |
471 | 475 | ||
472 | function vehiculoEnUso(vehiculo) { | 476 | function vehiculoEnUso(vehiculo) { |
473 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; | 477 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; |
474 | for (var i = 0; i < vehiculo.cisternas.length; i++) { | 478 | for (var i = 0; i < vehiculo.cisternas.length; i++) { |
475 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { | 479 | for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { |
476 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; | 480 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; |
477 | if (cisternaCarga.fechaReparto.substring(0, 10) === | 481 | if (cisternaCarga.fechaReparto.substring(0, 10) === |
478 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && | 482 | new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && |
479 | cisternaCarga.idUsuarioProceso && | 483 | cisternaCarga.idUsuarioProceso && |
480 | cisternaCarga.idUsuarioProceso !== idUsuario) | 484 | cisternaCarga.idUsuarioProceso !== idUsuario) |
481 | { | 485 | { |
482 | focaModalService.alert('El vehículo está siendo usado por otro' + | 486 | focaModalService.alert('El vehículo está siendo usado por otro' + |
483 | ' usuario'); | 487 | ' usuario'); |
484 | return true; | 488 | return true; |
485 | } | 489 | } |
486 | } | 490 | } |
487 | } | 491 | } |
488 | return false; | 492 | return false; |
489 | } | 493 | } |
490 | 494 | ||
491 | function salir() { | 495 | function salir() { |
492 | var confirmacion = false; | 496 | var confirmacion = false; |
493 | 497 | ||
494 | if (!angular.equals($scope.hojaRuta, $scope.inicial)) { | 498 | if (!angular.equals($scope.hojaRuta, $scope.inicial)) { |
495 | confirmacion = true; | 499 | confirmacion = true; |
496 | } | 500 | } |
497 | 501 | ||
498 | if (confirmacion) { | 502 | if (confirmacion) { |
499 | focaModalService.confirm( | 503 | focaModalService.confirm( |
500 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 504 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
501 | ).then(function(data) { | 505 | ).then(function(data) { |
502 | if (data) { | 506 | if (data) { |
503 | $location.path('/'); | 507 | $location.path('/'); |
504 | } | 508 | } |
505 | }); | 509 | }); |
506 | } else { | 510 | } else { |
507 | $location.path('/'); | 511 | $location.path('/'); |
508 | } | 512 | } |
509 | } | 513 | } |
510 | 514 | ||
511 | function setearHojaRuta(hojaRuta) { | 515 | function setearHojaRuta(hojaRuta) { |
512 | $scope.$broadcast('cleanCabecera'); | 516 | $scope.$broadcast('cleanCabecera'); |
513 | 517 | ||
514 | var cabeceras = []; | 518 | var cabeceras = []; |
515 | if (hojaRuta.fechaReparto) { | 519 | if (hojaRuta.fechaReparto) { |
516 | cabeceras.push({ | 520 | cabeceras.push({ |
517 | label: 'Fecha de entrega:', | 521 | label: 'Fecha de entrega:', |
518 | valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') | 522 | valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') |
519 | }); | 523 | }); |
520 | } | 524 | } |
521 | if (hojaRuta.transportista.COD) { | 525 | if (hojaRuta.transportista.COD) { |
522 | cabeceras.push({ | 526 | cabeceras.push({ |
523 | label: 'Transportista:', | 527 | label: 'Transportista:', |
524 | valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + | 528 | valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + |
525 | hojaRuta.transportista.NOM | 529 | hojaRuta.transportista.NOM |
526 | }); | 530 | }); |
527 | } | 531 | } |
528 | if (hojaRuta.chofer.id) { | 532 | if (hojaRuta.chofer.id) { |
529 | cabeceras.push({ | 533 | cabeceras.push({ |
530 | label: 'Chofer:', | 534 | label: 'Chofer:', |
531 | valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + | 535 | valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + |
532 | ' - ' + hojaRuta.chofer.nombre | 536 | ' - ' + hojaRuta.chofer.nombre |
533 | }); | 537 | }); |
534 | } | 538 | } |
535 | if (hojaRuta.vehiculo.id) { | 539 | if (hojaRuta.vehiculo.id) { |
536 | cabeceras.push({ | 540 | cabeceras.push({ |
537 | label: 'Tractor:', | 541 | label: 'Tractor:', |
538 | valor: hojaRuta.vehiculo.tractor | 542 | valor: hojaRuta.vehiculo.tractor |
539 | }); | 543 | }); |
540 | cabeceras.push({ | 544 | cabeceras.push({ |
541 | label: 'Semi:', | 545 | label: 'Semi:', |
542 | valor: hojaRuta.vehiculo.semi | 546 | valor: hojaRuta.vehiculo.semi |
543 | }); | 547 | }); |
544 | cabeceras.push({ | 548 | cabeceras.push({ |
545 | label: 'Capacidad:', | 549 | label: 'Capacidad:', |
546 | valor: hojaRuta.vehiculo.capacidad | 550 | valor: hojaRuta.vehiculo.capacidad |
547 | }); | 551 | }); |
548 | } | 552 | } |
549 | if (hojaRuta.tarifario.costo) { | 553 | if (hojaRuta.tarifario.costo) { |
550 | cabeceras.push({ | 554 | cabeceras.push({ |
551 | label: 'Tarifario:', | 555 | label: 'Tarifario:', |
552 | valor: hojaRuta.tarifario.costo | 556 | valor: hojaRuta.tarifario.costo |
553 | }); | 557 | }); |
554 | } | 558 | } |
555 | 559 | ||
556 | addArrayCabecera(cabeceras); | 560 | addArrayCabecera(cabeceras); |
557 | $scope.hojaRuta = hojaRuta; | 561 | $scope.hojaRuta = hojaRuta; |
558 | } | 562 | } |
559 | 563 | ||
560 | function getLSHojaRuta() { | 564 | function getLSHojaRuta() { |
561 | var hojaRuta = JSON.parse($localStorage.hojaRuta || null); | 565 | var hojaRuta = JSON.parse($localStorage.hojaRuta || null); |
562 | if (hojaRuta) { | 566 | if (hojaRuta) { |
563 | setearHojaRuta(hojaRuta); | 567 | setearHojaRuta(hojaRuta); |
564 | delete $localStorage.hojaRuta; | 568 | delete $localStorage.hojaRuta; |
565 | } | 569 | } |
566 | } | 570 | } |
567 | function addArrayCabecera(array) { | 571 | function addArrayCabecera(array) { |
568 | for(var i = 0; i < array.length; i++) { | 572 | for(var i = 0; i < array.length; i++) { |
569 | $scope.$broadcast('addCabecera', { | 573 | $scope.$broadcast('addCabecera', { |
570 | label: array[i].label, | 574 | label: array[i].label, |
571 | valor: array[i].valor | 575 | valor: array[i].valor |
572 | }); | 576 | }); |
573 | } | 577 | } |
574 | } | 578 | } |
575 | } | 579 | } |
576 | ]); | 580 | ]); |
577 | 581 |
src/js/controllerDatosHojaRuta.js
1 | angular.module('focaCrearHojaRuta') | 1 | angular.module('focaCrearHojaRuta') |
2 | .controller('focaModalDatosHojaRutaCtrl', | 2 | .controller('focaModalDatosHojaRutaCtrl', |
3 | [ | 3 | [ |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'focaModalService', | 7 | 'focaModalService', |
8 | 'parametrosDatos', | 8 | 'parametrosDatos', |
9 | function($filter, $scope, $uibModalInstance, focaModalService, parametrosDatos) { | 9 | function($filter, $scope, $uibModalInstance, focaModalService, parametrosDatos) { |
10 | $scope.datosHojaRuta = parametrosDatos.datosHojaRuta; | 10 | $scope.datosHojaRuta = parametrosDatos.datosHojaRuta; |
11 | $scope.focused = 0; | 11 | $scope.focused = 0; |
12 | 12 | ||
13 | $scope.aceptar = function(key) { | 13 | $scope.aceptar = function(key) { |
14 | if(key === 13) { | 14 | if (key === 13) { |
15 | if(!$scope.formDatosHojaRuta.$valid) { | 15 | if (!$scope.formDatosHojaRuta.$valid) { |
16 | focaModalService.alert('Formulario inválido'); | 16 | focaModalService.alert('Formulario inválido'); |
17 | return; | 17 | return; |
18 | } | 18 | } |
19 | $uibModalInstance.close($scope.datosHojaRuta); | 19 | $uibModalInstance.close($scope.datosHojaRuta); |
20 | } | 20 | } |
21 | }; | 21 | }; |
22 | 22 | ||
23 | $scope.next = function(key) { | 23 | $scope.next = function(key) { |
24 | if(key === 13) $scope.focused++; | 24 | if (key === 13) $scope.focused++; |
25 | }; | 25 | }; |
26 | 26 | ||
27 | $scope.cancel = function() { | 27 | $scope.cancel = function() { |
28 | $uibModalInstance.dismiss('cancel'); | 28 | $uibModalInstance.dismiss('cancel'); |
29 | }; | 29 | }; |
30 | } | 30 | } |
31 | ] | 31 | ] |
32 | ); | 32 | ); |
33 | 33 |