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