Commit 6d022c98daf1581d05c0c8d19c8ab7cca57a52cc

Authored by Nicolás Guarnieri
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !10
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 'crearHojaRutaService', 8 'focaCrearHojaRutaService',
9 'focaModalService', 9 'focaModalService',
10 'focaBotoneraLateralService', 10 'focaBotoneraLateralService',
11 function($scope, $uibModal, $location, $filter, $timeout, 11 function($scope, $uibModal, $location, $filter, $timeout,
12 crearHojaRutaService, focaModalService, focaBotoneraLateralService) { 12 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService) {
13 13
14 $scope.botonera = crearHojaRutaService.getBotonera(); 14 $scope.botonera = focaCrearHojaRutaService.getBotonera();
15 $scope.datepickerAbierto = false; 15 $scope.datepickerAbierto = false;
16 16
17 $scope.show = false; 17 $scope.show = false;
18 $scope.cargando = true; 18 $scope.cargando = true;
19 $scope.dateOptions = {
20 maxDate: new Date(),
21 minDate: new Date(2010, 0, 1)
22 };
23
24 $scope.hojaRuta = {
25 fecha: new Date(),
26 litros: 0,
27 chofer: {},
28 vehiculo: {
29 capacidad: 0
30 },
31 transportista: {},
32 tarifario: {
33 costo: null
34 }
35 };
36 19
20 function nuevaHojaRuta() {
21 $scope.hojaRuta = {
22 fecha: new Date(),
23 litros: 0,
24 chofer: {},
25 vehiculo: {
26 capacidad: 0
27 },
28 transportista: {},
29 tarifario: {
30 costo: null
31 }
32 };
33 }
34 nuevaHojaRuta();
37 $scope.showCabecera = true; 35 $scope.showCabecera = true;
38 36
39 $scope.now = new Date(); 37 $scope.now = new Date();
40 $scope.puntoVenta = '0000'; 38 $scope.puntoVenta = '0000';
41 $scope.comprobante = '00000000'; 39 $scope.comprobante = '00000000';
42 $scope.remitosTabla = []; 40 $scope.remitosTabla = [];
43 $scope.idLista = undefined; 41 $scope.idLista = undefined;
44 //La pantalla solo se usa para cargar pedidos
45 //var hojaRutaTemp = crearHojaRutaService.getHojaRuta();
46 42
47 //SETEO BOTONERA LATERAL 43 //SETEO BOTONERA LATERAL
48 $timeout(function() { 44 $timeout(function() {
49 focaBotoneraLateralService.showSalir(true); 45 focaBotoneraLateralService.showSalir(true);
50 focaBotoneraLateralService.showPausar(true); 46 focaBotoneraLateralService.showPausar(true);
51 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); 47 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta);
52 }); 48 });
53 49
54 crearHojaRutaService.getNumeroHojaRuta().then( 50 focaCrearHojaRutaService.getNumeroHojaRuta().then(
55 function(res) { 51 function(res) {
56 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); 52 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4);
57 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); 53 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8);
58 }, 54 },
59 function(err) { 55 function(err) {
60 focaModalService.alert('La terminal no esta configurada correctamente'); 56 focaModalService.alert('La terminal no esta configurada correctamente');
61 console.info(err); 57 console.info(err);
62 } 58 }
63 ); 59 );
64 //La pantalla solo se usa para cargar pedidos
65 // if (hojaRutaTemp !== undefined) {
66 // hojaRutaTemp.fechaCarga = new Date(hojaRutaTemp.fechaCarga);
67 // $scope.hojaRuta = hojaRutaTemp;
68 // $scope.hojaRuta.flete = ($scope.hojaRuta.flete).toString();
69 // $scope.hojaRuta.bomba = ($scope.hojaRuta.bomba).toString();
70 // $scope.idLista = $scope.hojaRuta.precioCondicion;
71 // crearHojaRutaService
72 // .getArticulosByIdHojaRuta($scope.hojaRuta.id).then(
73 // function(res) {
74 // $scope.remitosTabla = res.data;
75 // }
76 // );
77 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO
78 //(NO REQUERIDO EN ESTA VERSION)
79 // crearHojaRutaService.getDomiciliosByIdHojaRuta($scope.hojaRuta.id).then(
80 // function(res) {
81 // $scope.hojaRuta.domicilio = res.data;
82 // }
83 // );
84 // } else {
85 // $scope.hojaRuta.fechaCarga = new Date();
86 // $scope.hojaRuta.bomba = '0';
87 // $scope.hojaRuta.flete = '0';
88 // $scope.idLista = undefined;
89 // }
90 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
91 // $scope.addNewDom = function() {
92 // $scope.hojaRuta.domicilio.push({ 'id': 0 });
93 // };
94 // $scope.removeNewChoice = function(choice) {
95 // if ($scope.hojaRuta.domicilio.length > 1) {
96 // $scope.hojaRuta.domicilio.splice($scope.hojaRuta.domicilio.findIndex(
97 // function(c) {
98 // return c.$$hashKey === choice.$$hashKey;
99 // }
100 // ), 1);
101 // }
102 // };
103
104 $scope.crearHojaRuta = function() { 60 $scope.crearHojaRuta = function() {
105 if($scope.hojaRuta.litros <= 0) { 61 if(!$scope.remitosTabla.length) {
106 focaModalService.alert('Ingrese Remitos'); 62 focaModalService.alert('Ingrese Remitos');
107 return; 63 return;
108 } 64 }
109
110 if(!$scope.hojaRuta.chofer.id) { 65 if(!$scope.hojaRuta.chofer.id) {
111 focaModalService.alert('Ingrese Chofer'); 66 focaModalService.alert('Ingrese Chofer');
112 return; 67 return;
113 } 68 }
114
115 if(!$scope.hojaRuta.vehiculo.id) { 69 if(!$scope.hojaRuta.vehiculo.id) {
116 focaModalService.alert('Ingrese Vehiculo'); 70 focaModalService.alert('Ingrese Vehiculo');
117 return; 71 return;
118 } 72 }
119 73 if(!$scope.hojaRuta.transportista.COD) {
120 if(!$scope.hojaRuta.transportista.codigo) {
121 focaModalService.alert('Ingrese Transportista'); 74 focaModalService.alert('Ingrese Transportista');
122 return; 75 return;
123 } 76 }
124
125 if($scope.hojaRuta.vehiculo.capacidad < $scope.hojaRuta.litros) {
126 focaModalService.alert(
127 'La capacidad del Vehiculo es menor a lo ingresado en Remitos'
128 );
129 return;
130 }
131
132 if(!$scope.hojaRuta.tarifario.costo) { 77 if(!$scope.hojaRuta.tarifario.costo) {
133 focaModalService.alert('Ingrese Tarifario'); 78 focaModalService.alert('Ingrese Tarifario');
134 return; 79 return;
135 } 80 }
136
137 var date = new Date(); 81 var date = new Date();
138 var save = { 82 var save = {
139 hojaRuta: { 83 hojaRuta: {
140 id: 0, 84 id: 0,
141 fechaCreacion: 85 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
142 new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 86 .replace('T', ' '),
143 .toISOString().slice(0, 19) .replace('T', ' '), 87 idTransportista: $scope.hojaRuta.transportista.COD,
144 idTransportista: $scope.hojaRuta.transportista.codigo,
145 idChofer: $scope.hojaRuta.chofer.id, 88 idChofer: $scope.hojaRuta.chofer.id,
146 idVehiculo: $scope.hojaRuta.vehiculo.id, 89 idVehiculo: $scope.hojaRuta.vehiculo.id,
147 tarifaFlete: $scope.hojaRuta.tarifario.costo 90 tarifaFlete: $scope.hojaRuta.tarifario.costo,
91 fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10),
92 estado: 0
148 }, 93 },
149 remitos: $scope.remitosTabla 94 remitos: $scope.remitosTabla
150 }; 95 };
151 96
152 crearHojaRutaService.crearHojaRuta(save).then( 97 focaCrearHojaRutaService.crearHojaRuta(save).then(
153 function(data) { 98 function(data) {
154 focaModalService.alert( 99 focaModalService.alert(
155 'Hoja ruta creada Nº: ' + 100 'Hoja ruta creada Nº: ' +
156 $scope.rellenar(data.data.sucursal, 4) + 101 $scope.rellenar(data.data.sucursal, 4) +
157 '-' + 102 '-' +
158 $scope.rellenar(data.data.numeroHojaRuta, 8) 103 $scope.rellenar(data.data.numeroHojaRuta, 8)
159 ); 104 );
160 $scope.hojaRuta = { 105 nuevaHojaRuta();
161 fecha: new Date(),
162 litros: 0,
163 chofer: {},
164 vehiculo: {
165 capacidad: 0
166 },
167 transportista: {},
168 tarifario: {
169 costo: null
170 }
171 };
172
173 $scope.remitosTabla = []; 106 $scope.remitosTabla = [];
174 $scope.$broadcast('cleanCabecera'); 107 $scope.$broadcast('cleanCabecera');
175 108
176 crearHojaRutaService.getNumeroHojaRuta().then(function(res) { 109 focaCrearHojaRutaService.getNumeroHojaRuta().then(function(res) {
177 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); 110 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8);
178 }); 111 });
179 }, 112 },
180 function(error) { 113 function(error) {
181 focaModalService.alert('Hubo un error al crear la nota de pedido'); 114 focaModalService.alert('Hubo un error al crear la hoja de ruta');
182 console.info(error); 115 console.info(error);
183 } 116 }
184 ); 117 );
185 }; 118 };
186 119
187 $scope.seleccionarTransportista = function() { 120 $scope.seleccionarTransportista = function() {
121 if(eligioPreConfirmado()) return;
188 var modalInstance = $uibModal.open( 122 var modalInstance = $uibModal.open(
189 { 123 {
190 ariaLabelledBy: 'Busqueda de Transportista', 124 ariaLabelledBy: 'Busqueda de Transportista',
191 templateUrl: 'modal-proveedor.html', 125 templateUrl: 'modal-proveedor.html',
192 controller: 'focaModalProveedorCtrl', 126 controller: 'focaModalProveedorCtrl',
193 size: 'lg', 127 size: 'lg',
194 resolve: { 128 resolve: {
195 transportista: function() { 129 transportista: function() {
196 return true; 130 return true;
197 } 131 }
198 } 132 }
199 } 133 }
200 ); 134 );
201 modalInstance.result.then( 135 modalInstance.result.then(
202 function(proveedor) { 136 function(proveedor) {
203 console.info($scope.hojaRuta); 137 $scope.hojaRuta.transportista = proveedor;
204 $scope.hojaRuta.transportista.codigo = proveedor.COD;
205 $scope.$broadcast('addCabecera', { 138 $scope.$broadcast('addCabecera', {
206 label: 'Transportista:', 139 label: 'Transportista:',
207 valor: proveedor.NOM 140 valor: proveedor.NOM
208 }); 141 });
209 }, function() { 142 }, function() {
210 143
211 } 144 }
212 ); 145 );
213 }; 146 };
214 147
215 $scope.seleccionarChofer = function() { 148 $scope.seleccionarChofer = function() {
216 var modalInstance = $uibModal.open( 149 var modalInstance = $uibModal.open(
217 { 150 {
218 ariaLabelledBy: 'Busqueda de Chofer', 151 ariaLabelledBy: 'Busqueda de Chofer',
219 templateUrl: 'modal-chofer.html', 152 templateUrl: 'modal-chofer.html',
220 controller: 'focaModalChoferController', 153 controller: 'focaModalChoferController',
221 size: 'lg' 154 size: 'lg'
222 } 155 }
223 ); 156 );
224 157
225 modalInstance.result.then( 158 modalInstance.result.then(
226 function(chofer) { 159 function(chofer) {
227 $scope.hojaRuta.chofer = chofer; 160 $scope.hojaRuta.chofer = chofer;
228 $scope.$broadcast('addCabecera', { 161 $scope.$broadcast('addCabecera', {
229 label: 'Chofer:', 162 label: 'Chofer:',
230 valor: chofer.nombre 163 valor: chofer.nombre
231 }); 164 });
232 }, function() { 165 }, function() {
233 // funcion ejecutada cuando se cancela el modal 166 // funcion ejecutada cuando se cancela el modal
234 } 167 }
235 ); 168 );
236 }; 169 };
237 170
238 $scope.seleccionarVehiculo = function() { 171 $scope.seleccionarVehiculo = function() {
239 var modalInstance = $uibModal.open( 172 if(eligioPreConfirmado()) return;
240 { 173 modalVehiculos();
241 ariaLabelledBy: 'Busqueda de Vehiculo',
242 templateUrl: 'modal-vehiculo.html',
243 controller: 'focaModalVehiculoController',
244 size: 'lg',
245 resolve: {
246 idTransportista: $scope.hojaRuta.transportista.codigo
247 }
248 }
249 );
250
251 modalInstance.result.then(
252 function(vehiculo) {
253 $scope.hojaRuta.vehiculo = vehiculo;
254 $scope.$broadcast('addCabecera', {
255 label: 'Tractor:',
256 valor: vehiculo.tractor
257 });
258 $scope.$broadcast('addCabecera', {
259 label: 'Semi:',
260 valor: vehiculo.semi
261 });
262 $scope.$broadcast('addCabecera', {
263 label: 'Capacidad:',
264 valor: vehiculo.capacidad
265 });
266 }, function() {
267 // funcion ejecutada cuando se cancela el modal
268 }
269 );
270 }; 174 };
271 175
272 $scope.seleccionarTarifario = function() { 176 $scope.seleccionarTarifario = function() {
273 var modalInstance = $uibModal.open( 177 var modalInstance = $uibModal.open(
274 { 178 {
275 ariaLabelledBy: 'Busqueda de Tarifario', 179 ariaLabelledBy: 'Busqueda de Tarifario',
276 templateUrl: 'modal-tarifa-flete.html', 180 templateUrl: 'modal-tarifa-flete.html',
277 controller: 'focaModalTarifaFleteController', 181 controller: 'focaModalTarifaFleteController',
278 size: 'lg', 182 size: 'lg',
279 resolve: { 183 resolve: {
280 parametrosTarifaFlete: function() { 184 parametrosTarifaFlete: function() {
281 return $scope.hojaRuta.tarifario.costo; 185 return $scope.hojaRuta.tarifario.costo;
282 } 186 }
283 } 187 }
284 } 188 }
285 ); 189 );
286 190
287 modalInstance.result.then( 191 modalInstance.result.then(
288 function(tarifario) { 192 function(tarifario) {
289 $scope.hojaRuta.tarifario = tarifario; 193 $scope.hojaRuta.tarifario = tarifario;
290 $scope.$broadcast('addCabecera', { 194 $scope.$broadcast('addCabecera', {
291 label: 'Tarifario:', 195 label: 'Tarifario:',
292 valor: tarifario.costo 196 valor: tarifario.costo
293 }); 197 });
294 }, function() { 198 }, function() {
295 // funcion ejecutada cuando se cancela el modal 199 // funcion ejecutada cuando se cancela el modal
296 } 200 }
297 ); 201 );
298 }; 202 };
299 203
300 $scope.seleccionarRemitos = function() { 204 $scope.seleccionarRemitos = function() {
205 if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
301 var modalInstance = $uibModal.open( 206 var modalInstance = $uibModal.open(
302 { 207 {
303 ariaLabelledBy: 'Busqueda de Remito', 208 ariaLabelledBy: 'Busqueda de Remito',
304 templateUrl: 'foca-modal-remito.html', 209 templateUrl: 'foca-modal-remito.html',
305 controller: 'focaModalRemitoController', 210 controller: 'focaModalRemitoController',
306 size: 'lg', 211 size: 'lg',
307 resolve: {usadoPor: function() {return 'hojaRuta';}} 212 resolve: {usadoPor: function() {return 'hojaRuta';}}
308 } 213 }
309 ); 214 );
310 modalInstance.result.then( 215 modalInstance.result.then(
311 function(remito) { 216 function(remito) {
312 for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { 217 // TODO: borrar cuando no se use definitivamente
313 if ($scope.remitosTabla[i].id === remito.id) { 218 // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) {
314 focaModalService.alert('Remito ya incluido'); 219 // if ($scope.remitosTabla[i].id === remito.id) {
315 return; 220 // focaModalService.alert('Remito ya incluido');
316 } 221 // return;
317 } 222 // }
223 // }
318 224
319 var litros = 0; 225 // var litros = 0;
320 for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 226 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
321 litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 227 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
322 } 228 // }
323 229
324 if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 230 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
325 focaModalService.alert( 231 // focaModalService.alert(
326 'Debe ingresar toda la información para el transporte' 232 // 'Debe ingresar toda la información para el transporte'
327 ); 233 // );
328 return; 234 // return;
329 } 235 // }
330 236
331 if ($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 237 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
332 { 238 // {
333 var litrostotales = litros; 239 // var litrostotales = litros;
334 litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 240 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
335 focaModalService.alert( 241 // focaModalService.alert(
336 'La carga excede la capacidad disponible del vehiculo. ' + 242 // 'La carga excede la capacidad disponible del vehiculo. ' +
337 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 243 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
338 ); 244 // );
339 } 245 // }
340 246
341 remito.litros = litros; 247 // remito.litros = litros;
342 $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 248 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
343 $scope.remitosTabla.push(remito); 249 $scope.cargarCisterna(remito.id).then(function() {
250 $scope.remitosTabla.push(remito);
251 }, function() {
252 // funcion ejecutada cuando se cancela el modal
253 });
344 }, function() { 254 }, function() {
345 // funcion ejecutada cuando se cancela el modal 255 // funcion ejecutada cuando se cancela el modal
346 } 256 }
347 ); 257 );
348 }; 258 };
349 259
350 $scope.getTotal = function() { 260 $scope.seleccionarVehiculosPrecargados = function() {
351 var total = 0; 261 if(!eligioFecha()) return;
352 var arrayTempArticulos = $scope.remitosTabla; 262 modalVehiculos(true);
353 for (var i = 0; i < arrayTempArticulos.length; i++) {
354 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
355 }
356 return parseFloat(total.toFixed(2));
357 }; 263 };
358 264
359 $scope.getSubTotal = function() { 265 $scope.cargarCisterna = function(idRemito) {
360 if($scope.articuloACargar) { 266 if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
361 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 267 var modalInstance = $uibModal.open(
362 } 268 {
363 }; 269 ariaLabelledBy: 'Busqueda de Vehiculo',
364 270 templateUrl: 'foca-detalle-vehiculo.html',
365 $scope.limpiarPantalla = function() { 271 controller: 'focaDetalleVehiculo',
366 $scope.limpiarFlete(); 272 size: 'lg',
367 $scope.hojaRuta.flete = '0'; 273 resolve: {
368 $scope.hojaRuta.bomba = '0'; 274 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;},
369 $scope.hojaRuta.precioCondicion = ''; 275 idRemito: function() {return idRemito;},
370 $scope.remitosTabla = []; 276 fechaReparto: function() {return $scope.fechaReparto;}
371 $scope.hojaRuta.vendedor.nombre = ''; 277 }
372 $scope.hojaRuta.cliente = {nombre: ''}; 278 }
373 $scope.hojaRuta.domicilio = {dom: ''}; 279 );
374 $scope.hojaRuta.litros = 0; 280 return modalInstance.result;
375 $scope.domiciliosCliente = [];
376 };
377 //Recibe aviso si el teclado está en uso
378 // $rootScope.$on('usarTeclado', function(event, data) {
379 // if(data) {
380 // $scope.mostrarTeclado = true;
381 // return;
382 // }
383 // $scope.mostrarTeclado = false;
384 // })
385 $scope.selectFocus = function($event) {
386 //Si el teclado esta en uso no selecciona el valor
387 // if($scope.mostrarTeclado) {
388 // return;
389 // }
390 $event.target.select();
391 }; 281 };
392 282
393 $scope.salir = function() { 283 $scope.seleccionarFechaEntrega = function() {
394 $location.path('/'); 284 if(!$scope.fechaReparto) {
285 elegirFecha();
286 return;
287 }
288 focaModalService
289 .confirm('Si cambia la fecha se perderán los datos actuales')
290 .then(function() {
291 elegirFecha();
292 }, function() {
293 return ;
294 });
395 }; 295 };
396 296
397 $scope.parsearATexto = function(articulo) { 297 function elegirFecha() {
398 articulo.cantidad = parseFloat(articulo.cantidad); 298 focaModalService.modalFecha('Fecha de entrega').then(function(fecha) {
399 articulo.precio = parseFloat(articulo.precio); 299 $scope.$broadcast('addCabecera', {
400 }; 300 label: 'Fecha de entrega:',
301 valor: fecha.toLocaleDateString()
302 });
303 $scope.fechaReparto = fecha;
304 nuevaHojaRuta();
305 });
306 }
401 307
402 $scope.rellenar = function(relleno, longitud) { 308 $scope.rellenar = function(relleno, longitud) {
403 relleno = '' + relleno; 309 relleno = '' + relleno;
404 while (relleno.length < longitud) { 310 while (relleno.length < longitud) {
405 relleno = '0' + relleno; 311 relleno = '0' + relleno;
406 } 312 }
407
408 return relleno; 313 return relleno;
409 }; 314 };
410 315
411 $scope.quitarArticulo = function(key) { 316 function eligioPreConfirmado() {
412 $scope.remitosTabla.splice(key, 1); 317 if($scope.eligioPreConfirmado) {
413 var litros = 0; 318 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado');
414 319 return true;
415 for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) {
416 litros += parseFloat($scope.remitosTabla[i].litros);
417 } 320 }
321 return false;
322 }
418 323
419 $scope.hojaRuta.litros = litros; 324 function eligioFecha() {
1 angular.module('focaCrearHojaRuta') 1 angular.module('focaCrearHojaRuta')
2 .service('crearHojaRutaService', ['$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) {
59 return $http.get(route + '/vehiculo/obtener/remitos/' +
60 idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10));
61 },
58 getBotonera: function() { 62 getBotonera: function() {
59 return [ 63 return [
60 { 64 {
65 label: 'Fecha Entrega',
66 image: 'fechaDeReparto.png'
67 },
68 {
61 label: 'Transportista', 69 label: 'Transportista',
62 image: 'transportista.png' 70 image: 'transportista.png'
63 }, 71 },
64 { 72 {
65 label: 'Chofer', 73 label: 'Chofer',
66 image: 'chofer.png' 74 image: 'chofer.png'
67 }, 75 },
68 { 76 {
69 label: 'Vehiculo', 77 label: 'Vehiculo',
70 image: 'vehiculos.png' 78 image: 'vehiculos.png'
71 }, 79 },
72 { 80 {
73 label: 'Tarifario', 81 label: 'Tarifario',
74 image: 'tarifario.png' 82 image: 'tarifario.png'
75 }, 83 },
76 { 84 {
77 label: 'Remitos', 85 label: 'Remitos',
78 image: 'remito.png' 86 image: 'remito.png'
87 },
88 {
89 label: 'Vehiculos precargados',
90 image: 'vehiculos.png'
79 } 91 }
80 ]; 92 ];
81 } 93 }
82 }; 94 };
83 }]); 95 }]);
84 96
src/views/hoja-ruta.html
1 <div class="crear-hoja-ruta foca-crear row"> 1 <div class="crear-hoja-ruta foca-crear row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Hoja de ruta'" 3 titulo="'Hoja de ruta'"
4 numero="puntoVenta + '-' + comprobante" 4 numero="puntoVenta + '-' + comprobante"
5 fecha="now" 5 fecha="now"
6 class="mb-0 col-lg-12" 6 class="mb-0 col-lg-12"
7 ></foca-cabecera-facturador> 7 ></foca-cabecera-facturador>
8 <div class="col-lg-12"> 8 <div class="col-lg-12">
9 <div class="row mt-4"> 9 <div class="row mt-4">
10 <div class="col-12 col-md-10 border border-light rounded"> 10 <div class="col-12 col-md-10 border border-light rounded">
11 <div class="row px-5 py-2 botonera-secundaria"> 11 <div class="row px-5 py-2 botonera-secundaria">
12 <div class="col-12"> 12 <div class="col-12">
13 <foca-botonera-facturador botones="botonera" extra="7" class="row"></foca-botonera-facturador> 13 <foca-botonera-facturador botones="botonera" extra="5" class="row"></foca-botonera-facturador>
14 </div> 14 </div>
15 </div> 15 </div>
16 <!-- PC --> 16 <!-- PC -->
17 <div class="row grilla-articulo align-items-end d-none d-sm-flex"> 17 <div class="row grilla-articulo align-items-end d-none d-sm-flex">
18 <table class="table tabla-articulo table-striped table-sm mb-0 rounded-bottom"> 18 <table class="table tabla-articulo table-striped table-sm mb-0 rounded-bottom">
19 <thead> 19 <thead>
20 <tr class="d-flex"> 20 <tr class="d-flex">
21 <th class="col-auto">#</th> 21 <th class="col-auto">#</th>
22 <th class="col-2">Remito</th> 22 <th class="col-2">Remito</th>
23 <th class="col">Cliente</th> 23 <th class="col">Cliente</th>
24 <th class="col">Dirección</th> 24 <th class="col">Dirección</th>
25 <th class="text-right" style="width: 80px">Cantidad</th>
26 <th class="col-auto"> 25 <th class="col-auto">
27 <button 26 <button
28 class="btn btn-outline-light selectable" 27 class="btn btn-outline-light selectable"
29 ng-click="show = !show; masMenos()" 28 ng-click="show = !show; masMenos()"
30 > 29 >
31 <i 30 <i
32 class="fa fa-chevron-down" 31 class="fa fa-chevron-down"
33 ng-show="show" 32 ng-show="show"
34 aria-hidden="true" 33 aria-hidden="true"
35 > 34 >
36 </i> 35 </i>
37 <i 36 <i
38 class="fa fa-chevron-up" 37 class="fa fa-chevron-up"
39 ng-hide="show" 38 ng-hide="show"
40 aria-hidden="true"> 39 aria-hidden="true">
41 </i> 40 </i>
42 </button> 41 </button>
43 </th> 42 </th>
44 </th> 43 </th>
45 </tr> 44 </tr>
46 </thead> 45 </thead>
47 <tbody class="tabla-articulo-body"> 46 <tbody class="tabla-articulo-body">
48 <tr 47 <tr
49 ng-repeat="(key, remito) in remitosTabla" 48 ng-repeat="(key, remito) in remitosTabla"
50 class="d-flex" 49 class="d-flex"
51 ng-show="show || key == remitosTabla.length - 1" 50 ng-show="show || key == remitosTabla.length - 1"
52 > 51 >
53 <td ng-bind="key + 1" class="col-auto"></td> 52 <td ng-bind="key + 1" class="col-auto"></td>
54 <td 53 <td
55 class="col-2" 54 class="col-2"
56 ng-bind="rellenar(remito.sucursal, 4) + '-' + rellenar(remito.numeroRemito, 8)" 55 ng-bind="rellenar(remito.sucursal, 4) + '-' + rellenar(remito.numeroRemito, 8)"
57 ></td> 56 ></td>
58 <th class="col" ng-bind="remito.cliente[0].NOM"></th> 57 <th class="col" ng-bind="remito.nombreCliente"></th>
59 <th class="col" ng-bind="remito.domicilioStamp"></th> 58 <th class="col" ng-bind="remito.domicilioStamp"></th>
60 <th class="text-right" ng-bind="remito.litros" style="width: 80px"></th>
61 <td class="text-center col-auto"> 59 <td class="text-center col-auto">
62 <button 60 <button
63 class="btn btn-outline-light" 61 class="btn btn-outline-light"
64 ng-click="quitarArticulo(key)" 62 ng-click="quitarArticulo(key)"
65 > 63 >
66 <i class="fa fa-trash"></i> 64 <i class="fa fa-trash"></i>
67 </button> 65 </button>
68 </td> 66 </td>
69 </tr> 67 </tr>
70 </tbody> 68 </tbody>
71 <tfoot> 69 <tfoot>
72 <tr class="d-flex"> 70 <tr class="d-flex">
73 <td class="col-auto px-1"> 71 <td class="col-auto px-1">
74 <strong>Remitos:</strong> 72 <strong>Remitos:</strong>
75 <a ng-bind="remitosTabla.length"></a> 73 <a ng-bind="remitosTabla.length"></a>
76 </td> 74 </td>
77 <td class="col"></td> 75 <td class="col"></td>
78 <td class="col-auto px-1"> 76 <td class="col-auto px-1">
79 <strong>Cantidad:</strong> 77 <strong>Cantidad:</strong>
80 <a ng-bind="hojaRuta.litros"></a> 78 <a ng-bind="hojaRuta.litros"></a>
81 </td> 79 </td>
82 </tr> 80 </tr>
83 </tfoot> 81 </tfoot>
84 </table> 82 </table>
85 </div> 83 </div>
86 84
87 <!-- MOBILE --> 85 <!-- MOBILE -->
88 <div class="row d-sm-none"> 86 <div class="row d-sm-none">
89 <table class="table table-sm table-striped tabla-articulo margin-bottom-mobile"> 87 <table class="table table-sm table-striped tabla-articulo margin-bottom-mobile">
90 <thead> 88 <thead>
91 <tr class="d-flex"> 89 <tr class="d-flex">
92 <th class="">#</th> 90 <th class="">#</th>
93 <th class="col px-0"> 91 <th class="col px-0">
94 <div class="d-flex"> 92 <div class="d-flex">
95 <div class="col-4 px-1">Código</div> 93 <div class="col-4 px-1">Código</div>
96 <div class="col-8 px-1">Descripción</div> 94 <div class="col-8 px-1">Descripción</div>
97 </div> 95 </div>
98 <div class="d-flex"> 96 <div class="d-flex">
99 <div class="col-3 px-1">Cantidad</div> 97 <div class="col-3 px-1">Cantidad</div>
100 <div class="col px-1 text-right">P. Uni.</div> 98 <div class="col px-1 text-right">P. Uni.</div>
101 <div class="col px-1 text-right">Subtotal</div> 99 <div class="col px-1 text-right">Subtotal</div>
102 </div> 100 </div>
103 </th> 101 </th>
104 <th class="text-center tamaño-boton"> 102 <th class="text-center tamaño-boton">
105 &nbsp; 103 &nbsp;
106 </th> 104 </th>
107 </tr> 105 </tr>
108 </thead> 106 </thead>
109 <tbody> 107 <tbody>
110 <tr 108 <tr
111 ng-repeat="(key, articulo) in remitosTabla" 109 ng-repeat="(key, articulo) in remitosTabla"
112 ng-show="show || key == remitosTabla.length - 1" 110 ng-show="show || key == remitosTabla.length - 1"
113 > 111 >
114 <td class="w-100 align-middle d-flex p-0"> 112 <td class="w-100 align-middle d-flex p-0">
115 <div class="align-middle p-1"> 113 <div class="align-middle p-1">
116 <span ng-bind="key+1" class="align-middle"></span> 114 <span ng-bind="key+1" class="align-middle"></span>
117 </div> 115 </div>
118 <div class="col px-0"> 116 <div class="col px-0">
119 <div class="d-flex"> 117 <div class="d-flex">
120 <div class="col-4 px-1"> 118 <div class="col-4 px-1">
121 <span 119 <span
122 ng-bind="articulo.sector + '-' + articulo.codigo" 120 ng-bind="articulo.sector + '-' + articulo.codigo"
123 ></span> 121 ></span>
124 </div> 122 </div>
125 <div class="col-8 px-1"> 123 <div class="col-8 px-1">
126 <span ng-bind="articulo.descripcion"></span> 124 <span ng-bind="articulo.descripcion"></span>
127 </div> 125 </div>
128 </div> 126 </div>
129 <div class="d-flex"> 127 <div class="d-flex">
130 <div class="col-3 px-1"> 128 <div class="col-3 px-1">
131 <span ng-bind="'x' + articulo.cantidad"></span> 129 <span ng-bind="'x' + articulo.cantidad"></span>
132 </div> 130 </div>
133 <div class="col-3 px-1 text-right"> 131 <div class="col-3 px-1 text-right">
134 <span ng-bind="articulo.precio | currency: hojaRuta.moneda.simbolo : 4"></span> 132 <span ng-bind="articulo.precio | currency: hojaRuta.moneda.simbolo : 4"></span>
135 </div> 133 </div>
136 <div class="col px-1 text-right"> 134 <div class="col px-1 text-right">
137 <span 135 <span
138 ng-bind="(articulo.precio * articulo.cantidad) | currency: hojaRuta.moneda.simbolo" 136 ng-bind="(articulo.precio * articulo.cantidad) | currency: hojaRuta.moneda.simbolo"
139 > 137 >
140 </span> 138 </span>
141 </div> 139 </div>
142 </div> 140 </div>
143 </div> 141 </div>
144 <div class="align-middle p-1"> 142 <div class="align-middle p-1">
145 <button 143 <button
146 class="btn btn-outline-light" 144 class="btn btn-outline-light"
147 ng-click="quitarArticulo(key)" 145 ng-click="quitarArticulo(key)"
148 > 146 >
149 <i class="fa fa-trash"></i> 147 <i class="fa fa-trash"></i>
150 </button> 148 </button>
151 </div> 149 </div>
152 </td> 150 </td>
153 </tr> 151 </tr>
154 </tbody> 152 </tbody>
155 <tfoot> 153 <tfoot>
156 <!-- CARGANDO ITEM --> 154 <!-- CARGANDO ITEM -->
157 <tr ng-show="!cargando" class="d-flex"> 155 <tr ng-show="!cargando" class="d-flex">
158 <td 156 <td
159 class="align-middle p-1" 157 class="align-middle p-1"
160 ng-bind="remitosTabla.length + 1" 158 ng-bind="remitosTabla.length + 1"
161 ></td> 159 ></td>
162 <td class="col p-0"> 160 <td class="col p-0">
163 <div class="d-flex"> 161 <div class="d-flex">
164 <div class="col-4 px-1"> 162 <div class="col-4 px-1">
165 <span 163 <span
166 ng-bind="articuloACargar.sectorCodigo" 164 ng-bind="articuloACargar.sectorCodigo"
167 ></span> 165 ></span>
168 </div> 166 </div>
169 <div class="col-8 px-1"> 167 <div class="col-8 px-1">
170 <span ng-bind="articuloACargar.descripcion"></span> 168 <span ng-bind="articuloACargar.descripcion"></span>
171 </div> 169 </div>
172 </div> 170 </div>
173 <div class="d-flex"> 171 <div class="d-flex">
174 <div class="col-3 px-1 m-1"> 172 <div class="col-3 px-1 m-1">
175 <input 173 <input
176 class="form-control p-1" 174 class="form-control p-1"
177 type="number" 175 type="number"
178 min="1" 176 min="1"
179 ng-model="articuloACargar.cantidad" 177 ng-model="articuloACargar.cantidad"
180 foca-focus="!cargando" 178 foca-focus="!cargando"
181 ng-keypress="agregarATabla($event.keyCode)" 179 ng-keypress="agregarATabla($event.keyCode)"
182 style="height: auto; line-height: 1.1em" 180 style="height: auto; line-height: 1.1em"
183 > 181 >
184 </div> 182 </div>
185 <div class="col-3 px-1 text-right"> 183 <div class="col-3 px-1 text-right">
186 <span ng-bind="articuloACargar.precio | currency: hojaRuta.moneda.simbolo : 4"></span> 184 <span ng-bind="articuloACargar.precio | currency: hojaRuta.moneda.simbolo : 4"></span>
187 </div> 185 </div>
188 <div class="col px-1 text-right"> 186 <div class="col px-1 text-right">
189 <span 187 <span
190 ng-bind="getSubTotal() | currency: hojaRuta.moneda.simbolo" 188 ng-bind="getSubTotal() | currency: hojaRuta.moneda.simbolo"
191 > 189 >
192 </span> 190 </span>
193 </div> 191 </div>
194 </div> 192 </div>
195 </td> 193 </td>
196 <td class="text-center align-middle"> 194 <td class="text-center align-middle">
197 <button 195 <button
198 class="btn btn-outline-light" 196 class="btn btn-outline-light"
199 ng-click="agregarATabla(13)" 197 ng-click="agregarATabla(13)"
200 > 198 >
201 <i class="fa fa-save"></i> 199 <i class="fa fa-save"></i>
202 </button> 200 </button>
203 </td> 201 </td>
204 </tr> 202 </tr>
205 <!-- SELECCIONAR PRODUCTO --> 203 <!-- SELECCIONAR PRODUCTO -->
206 <tr ng-show="cargando" class="d-flex"> 204 <tr ng-show="cargando" class="d-flex">
207 <td class="col-12"> 205 <td class="col-12">
208 <input 206 <input
209 placeholder="Seleccione Articulo" 207 placeholder="Seleccione Articulo"
210 class="form-control form-control-sm" 208 class="form-control form-control-sm"
211 readonly 209 readonly
212 ng-click="seleccionarArticulo()" 210 ng-click="seleccionarArticulo()"
213 /> 211 />
214 </td> 212 </td>
215 </tr> 213 </tr>
216 <!-- TOOGLE EXPANDIR --> 214 <!-- TOOGLE EXPANDIR -->
217 <tr> 215 <tr>
218 <td class="col"> 216 <td class="col">
219 <button 217 <button
220 class="btn btn-outline-light selectable w-100" 218 class="btn btn-outline-light selectable w-100"
221 ng-click="show = !show; masMenos()" 219 ng-click="show = !show; masMenos()"
222 ng-show="remitosTabla.length > 0" 220 ng-show="remitosTabla.length > 0"
223 > 221 >
224 <i 222 <i
225 class="fa fa-chevron-down" 223 class="fa fa-chevron-down"
226 ng-hide="show" 224 ng-hide="show"
227 aria-hidden="true" 225 aria-hidden="true"
228 > 226 >
229 </i> 227 </i>
230 <i 228 <i
231 class="fa fa-chevron-up" 229 class="fa fa-chevron-up"
232 ng-show="show" 230 ng-show="show"
233 aria-hidden="true"> 231 aria-hidden="true">
234 </i> 232 </i>
235 </button> 233 </button>
236 </td> 234 </td>
237 </tr> 235 </tr>
238 <!-- FOOTER --> 236 <!-- FOOTER -->
239 <tr class="d-flex"> 237 <tr class="d-flex">
240 <td class="align-middle no-border-top" colspan="2"> 238 <td class="align-middle no-border-top" colspan="2">
241 <strong>Cantidad Items:</strong> 239 <strong>Cantidad Items:</strong>
242 <a ng-bind="remitosTabla.length"></a> 240 <a ng-bind="remitosTabla.length"></a>
243 </td> 241 </td>
244 <td class="text-right ml-auto table-celda-total no-border-top"> 242 <td class="text-right ml-auto table-celda-total no-border-top">
245 <h3>Total:</h3> 243 <h3>Total:</h3>
246 </td> 244 </td>
247 <td class="table-celda-total text-right no-border-top"> 245 <td class="table-celda-total text-right no-border-top">
248 <h3>{{getTotal() | currency: hojaRuta.moneda.simbolo}}</h3> 246 <h3>{{getTotal() | currency: hojaRuta.moneda.simbolo}}</h3>
249 </td> 247 </td>
250 </tr> 248 </tr>
251 </tfoot> 249 </tfoot>
252 </table> 250 </table>
253 </div> 251 </div>
254 </div> 252 </div>
255 </div> 253 </div>
256 </div> 254 </div>
257 <div class="row d-md-none fixed-bottom"> 255 <div class="row d-md-none fixed-bottom">
258 <div class="w-100 bg-dark d-flex px-3 acciones-mobile"> 256 <div class="w-100 bg-dark d-flex px-3 acciones-mobile">
259 <span class="ml-3 text-muted" ng-click="salir()">Salir</span> 257 <span class="ml-3 text-muted" ng-click="salir()">Salir</span>
260 <span class="mr-3 ml-auto" ng-click="crearHojaRuta()">Guardar</span> 258 <span class="mr-3 ml-auto" ng-click="crearHojaRuta()">Guardar</span>
261 </div> 259 </div>
262 </div> 260 </div>
263 </div> 261 </div>
264 262