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