From e2b3485e5414185a87d8a4de92580bb4d79ae515 Mon Sep 17 00:00:00 2001 From: Luigi Date: Tue, 11 Jun 2019 20:24:29 -0300 Subject: [PATCH] Crear Hoja de ruta RA --- src/js/businessService.js | 9 +- src/js/controller.js | 725 ++++++++++++++++++++++++++++++------- src/js/controllerDetalles.js | 157 ++++++++ src/js/service.js | 141 +++++++- src/views/hoja-ruta.html | 260 +++++++++---- src/views/modal-detalle-carga.html | 75 ++++ 6 files changed, 1159 insertions(+), 208 deletions(-) create mode 100644 src/js/controllerDetalles.js create mode 100644 src/views/modal-detalle-carga.html diff --git a/src/js/businessService.js b/src/js/businessService.js index b5632da..6c1202b 100644 --- a/src/js/businessService.js +++ b/src/js/businessService.js @@ -1,13 +1,14 @@ angular.module('focaCrearHojaRuta') .factory('hojaRutaBusinessService', [ - 'crearHojaRutaService', + 'focaCrearHojaRutaService', function(crearHojaRutaService) { return { - addArticulos: function(articulosHojaRuta, idHojaRuta, cotizacion) { + addArticulos: function(articulosHojaRuta, idRemito, cotizacion) { for(var i = 0; i < articulosHojaRuta.length; i++) { delete articulosHojaRuta[i].editCantidad; delete articulosHojaRuta[i].editPrecio; - articulosHojaRuta[i].idHojaRuta = idHojaRuta; + delete articulosHojaRuta[i].sectorCodigo; + articulosHojaRuta[i].idRemito = idRemito; articulosHojaRuta[i].precio = articulosHojaRuta[i].precio * cotizacion; crearHojaRutaService.crearArticulosParaHojaRuta(articulosHojaRuta[i]); } @@ -22,6 +23,6 @@ angular.module('focaCrearHojaRuta') idVendedor: idVendedor }; crearHojaRutaService.crearEstadoParaHojaRuta(estado); - } + }, }; }]); diff --git a/src/js/controller.js b/src/js/controller.js index 9f7500a..38e1406 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,4 +1,4 @@ -angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', +angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl', [ '$scope', '$uibModal', @@ -10,48 +10,59 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', 'focaBotoneraLateralService', 'focaLoginService', '$localStorage', - function($scope, $uibModal, $location, $filter, $timeout, + 'hojaRutaBusinessService', + '$cookies', + function ($scope, $uibModal, $location, $filter, $timeout, focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, - focaLoginSrv, $localStorage) - { + focaLoginSrv, $localStorage, hojaRutaBusinessService, $cookies) { config(); function config() { - $scope.botonera = focaCrearHojaRutaService.getBotonera(); + + $scope.botoneraPrincipal = focaCrearHojaRutaService.getBotones(); + $scope.botonera = []; + $scope.datepickerAbierto = false; $scope.show = false; + $scope.precargado = false; + $scope.cargaRemito = false; + $scope.remitoAbierto = false; + $scope.cisternaCargas = []; $scope.cargando = true; + $scope.articulos = []; + $scope.remito = { + id: '', + numeroRemito: '' + }; $scope.now = new Date(); $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); $scope.comprobante = $filter('rellenarDigitos')(0, 8); //SETEO BOTONERA LATERAL - $timeout(function() { + $timeout(function () { focaBotoneraLateralService.showSalir(false); focaBotoneraLateralService.showPausar(true); focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); focaBotoneraLateralService.addCustomButton('Salir', salir); }); - focaCrearHojaRutaService.getParametros().then(function(res) { + focaCrearHojaRutaService.getParametros().then(function (res) { var parametros = JSON.parse(res.data[0].jsonText); if ($localStorage.hojaRuta) { - $timeout(function() {getLSHojaRuta();}); + $timeout(function () { getLSHojaRuta(); }); } else { - - for(var property in parametros) { + for (var property in parametros) { $scope.hojaRuta[property] = parametros[property]; $scope.inicial[property] = parametros[property]; } - - setearHojaRuta($scope.hojaRuta); + //Setear Hoja de Ruta + //setearHojaRuta($scope.hojaRuta); } }); init(); } - function init() { $scope.$broadcast('cleanCabecera'); @@ -68,11 +79,11 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', $scope.idLista = undefined; focaCrearHojaRutaService.getNumeroHojaRuta().then( - function(res) { + function (res) { $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); }, - function(err) { + function (err) { focaModalService.alert('La terminal no esta configurada correctamente'); console.info(err); } @@ -81,49 +92,426 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', $scope.inicial = angular.copy($scope.hojaRuta); } - $scope.$watch('hojaRuta', function(newValue) { - - // Seteo checked en remitos - if ($scope.hojaRuta.remitosTabla.length) { + // $scope.$watch('hojaRuta', function(newValue) { + + // // Seteo checked en remitos + // if ($scope.hojaRuta.remitosTabla.length) { + // $filter('filter')($scope.botonera, { + // label: 'Remitos', + // })[0].checked = true; + // } else { + // $filter('filter')($scope.botonera, { + // label: 'Remitos', + // })[0].checked = false; + // } + + // focaBotoneraLateralService.setPausarData({ + // label: 'hojaRuta', + // val: newValue + // }); + // }, true); + + $scope.seleccionarRemitoAbierto = function () { + $scope.remitoAbierto = true; + $scope.cargaRemito = false; + $scope.botoneraPrincipal.forEach(function (boton) { + boton.checked = false; + }); + $filter('filter')($scope.botoneraPrincipal, { + label: 'Remito Abierto', + })[0].checked = false; + + $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); + }; - $filter('filter')($scope.botonera, { - label: 'Remitos', - })[0].checked = true; + $scope.seleccionarCargarRemitos = function () { + $scope.cargaRemito = true; + + var isBotoneraDirty = $scope.botonera.find(function (boton) { + return boton.checked; + }); + + if (isBotoneraDirty) { + focaModalService.confirm('Se perderan los cambios') + .then(function () { + limpiarBotonera($scope.botonera); + $scope.preCargados = false; + $filter('filter')($scope.botoneraPrincipal, { + label: 'Cargar Remitos', + })[0].checked = true; + $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); + }); } else { - $filter('filter')($scope.botonera, { - label: 'Remitos', - })[0].checked = false; + $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); } + $scope.precargado = false; + }; + + $scope.seleccionarPrecargados = function () { + $scope.precargado = true; + $filter('filter')($scope.botoneraPrincipal, { + label: '', + })[0].checked = true; + $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); + }; - focaBotoneraLateralService.setPausarData({ - label: 'hojaRuta', - val: newValue + $scope.quitarArticulo = function (articulo) { + $scope.articulosSeleccionados.forEach( function () { }); - }, true); + articulo = -1; + }; - $scope.crearHojaRuta = function() { - if (!$scope.hojaRuta.remitosTabla.length) { - focaModalService.alert('Ingrese Remitos'); - return; - } - if (!$scope.hojaRuta.chofer.id) { - focaModalService.alert('Ingrese Chofer'); - return; + function validarHojaRuta() { + if ($scope.precargado) { + if (!$scope.hojaRuta.chofer.id) { + focaModalService.alert('Ingrese Chofer'); + return false; + } + if (!$scope.hojaRuta.vehiculo.id) { + focaModalService.alert('Ingrese Vehiculo'); + return false; + } + if (!$scope.hojaRuta.transportista.COD) { + focaModalService.alert('Ingrese Transportista'); + return false; + } + if (!$scope.hojaRuta.datosExtra) { + focaModalService.alert('Ingrese Datos extra'); + return false; + } + } else if ($scope.cargaRemito) { + if (!$scope.hojaRuta.remitosTabla.length) { + focaModalService.alert('Ingrese Remitos'); + return false; + } else if (!$scope.hojaRuta.chofer.id) { + focaModalService.alert('Ingrese Chofer'); + return false; + } + if (!$scope.hojaRuta.vehiculo.id) { + focaModalService.alert('Ingrese Vehiculo'); + return false; + } + if (!$scope.hojaRuta.transportista.COD) { + focaModalService.alert('Ingrese Transportista'); + return false; + } + if (!$scope.hojaRuta.datosExtra) { + focaModalService.alert('Ingrese Datos extra'); + return false; + } + } else if ($scope.remitoAbierto) { + if (!$scope.hojaRuta.transportista.COD) { + focaModalService.alert('Ingrese Transportista'); + return false; + } else if (!$scope.hojaRuta.vehiculo.id) { + focaModalService.alert('Ingrese Vehiculo'); + return false; + } else if (!$scope.hojaRuta.chofer.id) { + focaModalService.alert('Ingrese Chofer'); + return false; + } else if (!$scope.hojaRuta.proveedor.COD) { + focaModalService.alert('Ingrese Proveedor'); + return false; + } else if (!$scope.hojaRuta.cliente.COD) { + focaModalService.alert('Ingrese un Cliente'); + return; + } } - if (!$scope.hojaRuta.vehiculo.id) { - focaModalService.alert('Ingrese Vehiculo'); + return true; + + } + + function getImporte(propiedad) { + var importe = 0; + + $scope.articulos.forEach(function (articulo) { + + if (articulo[propiedad]) { + importe += articulo[propiedad] * articulo.cantidad; + } return; + + }); + + return importe; + } + + function guardarRemitoAbierto() { + //guardar nuevo objeto (?) + var date = new Date(); + if ($scope.hojaRuta !== null) { + focaBotoneraLateralService.startGuardar(); + var save = { + remito: { + id: 0, + fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), + idCliente: $scope.hojaRuta.cliente.COD, + nombreCliente: $scope.hojaRuta.cliente.NOM, + cuitCliente: $scope.hojaRuta.cliente.CUIT, + idVendedor: $cookies.get('vendedorCobrador'), + idProveedor: $scope.hojaRuta.proveedor.COD, + idDomicilio: $scope.hojaRuta.idDomicilio || $scope.hojaRuta.domicilio.id, + idCotizacion: $scope.hojaRuta.cotizacion.ID, + domicilioStamp: $scope.hojaRuta.domicilioStamp, + observaciones: $scope.hojaRuta.observaciones, + idListaPrecio: $scope.hojaRuta.cliente.MOD.trim(), + total: getImporte('total') || 0, + descuento: 0,//TODO, + importeNeto: getImporte('netoUnitario') || 0, //TODO: arreglar, + importeExento: getImporte('exentoUnitario'), + importeIva: getImporte('ivaUnitario') || 0, //TODO: arreglar + importeIvaServicios: 0,//TODO + importeImpuestoInterno: getImporte('impuestoInternoUnitario'), + importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), + importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), + percepcion: 0,//TODO + percepcionIva: 0,//TODO + redondeo: 0,//TODO + anulado: false, + planilla: $filter('date')($scope.now, 'ddMMyyyy'), + lugar: parseInt($scope.puntoVenta), + cuentaMadre: 0,//TODO + cuentaContable: 0,//TODO + asiento: 0,//TODO + e_hd: '',//TODO + c_hd: '', + numeroLiquidoProducto: 0,//TODO + estado: 0, + destinoVenta: 0,//TODO + operacionTipo: 0, //TODO + }, + notaPedido: { + id: 0 + } + }; + focaCrearHojaRutaService.crearRemito(save).then( + function (data) { + focaBotoneraLateralService.endGuardar(true); + $scope.saveLoading = false; + + $scope.remito.id = data.data.id; + + focaCrearHojaRutaService.guardarCisternas({ + cisternaCargas: $scope.cisternaCargas, + cisternaMovimientos: $scope.cisternaMovimientos, + fechaReparto: $scope.hojaRuta.fechaReparto, + idVehiculo: $scope.hojaRuta.vehiculo.id + }, data.data.id); + $scope.remito.numeroRemito = data.data.numero; + + // if ($scope.remito.remitoPuntoDescarga.length > 0) { + // remitoBusinessService.addPuntosDescarga(data.data.id, + // $scope.remito.remitoPuntoDescarga); + // } + + hojaRutaBusinessService.addArticulos($scope.articulosRecibidos, + data.data.id, $scope.hojaRuta.cotizacion.VENDEDOR); + + guardarHojaRuta(data.data.id); + + }, function (error) { + focaModalService.alert(error.data || 'Hubo un error al crear el remito'); + focaBotoneraLateralService.endGuardar(); + $scope.saveLoading = false; + console.info(error); + } + ); + + function guardarHojaRuta(idRemito) { + + + var save2 = { + hojaRuta: { + id: 0, + fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) + .replace('T', ' '), + idTransportista: $scope.hojaRuta.transportista.COD, + idChofer: $scope.hojaRuta.chofer.id, + idVehiculo: $scope.hojaRuta.vehiculo.id, + proveedor: $scope.hojaRuta.proveedor.id, + fechaReparto: + new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), + estado: 0, + abierta: 1 + }, + remitos: [{id: idRemito}] + } + save2.hojaRuta = angular.extend({}, save2.hojaRuta, $scope.hojaRuta.datosExtra); + focaCrearHojaRutaService.crearHojaRuta(save2).then( + function (data) { + focaModalService.alert( + 'Hoja ruta creada Nº: ' + + $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + + $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + ); + + config(); + }, + function (error) { + focaModalService.alert('Hubo un error al crear la hoja de ruta'); + console.info(error); + } + ); + } } - if (!$scope.hojaRuta.transportista.COD) { - focaModalService.alert('Ingrese Transportista'); + } + + $scope.seleccionarCliente = function () { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cliente', + templateUrl: 'foca-busqueda-cliente-modal.html', + controller: 'focaBusquedaClienteModalController', + resolve: { + vendedor: function () { return null; }, + cobrador: function () { return null; } + }, + size: 'lg' + } + ); + modalInstance.result.then( + function (cliente) { + $scope.abrirModalDomicilios(cliente); + $scope.cliente = cliente; + }, function () { + } + ); + }; + + $scope.abrirModalDomicilios = function (cliente) { + var modalInstanceDomicilio = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Domicilios', + templateUrl: 'modal-domicilio.html', + controller: 'focaModalDomicilioController', + size: 'lg', + resolve: { + idCliente: function () { return cliente.cod; }, + esNuevo: function () { return cliente.esNuevo; } + } + } + ); + modalInstanceDomicilio.result.then( + function (domicilio) { + $scope.hojaRuta.domicilio = domicilio; + $scope.hojaRuta.cliente = { + COD: cliente.cod, + CUIT: cliente.cuit, + NOM: cliente.nom, + MAIL: cliente.mail, + MOD: cliente.mod, + IVA: cliente.iva, + VEN: cliente.ven + }; + focaCrearHojaRutaService.getVendedorById($scope.hojaRuta.cliente.VEN) + .then(function (res) { + if (res.data !== '') { + $scope.hojaRuta.vendedor = res.data; + $scope.$broadcast('addCabecera', { + label: 'Vendedor:', + valor: $filter('rellenarDigitos')($scope.hojaRuta.vendedor + .NUM, 3) +' - ' + $scope.hojaRuta.vendedor.NOM + }); + } + var domicilioStamp = + domicilio.Calle + ' ' + domicilio.Numero + ', ' + + domicilio.Localidad + ', ' + domicilio.Provincia; + $scope.hojaRuta.domicilioStamp = domicilioStamp; + $scope.$broadcast('addCabecera', { + label: 'Cliente:', + valor: $filter('rellenarDigitos')(cliente.cod, 3) + + ' - ' + cliente.nom + }); + $scope.$broadcast('addCabecera', { + label: 'Domicilio:', + valor: domicilioStamp + }); + + if (domicilio.verPuntos) { + delete $scope.hojaRuta.domicilio.verPuntos; + $scope.seleccionarPuntosDeDescarga(); + } else { + focaCrearHojaRutaService + .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) + .then(function (res) { + if (res.data.length) { + $scope.seleccionarPuntosDeDescarga(); + } + }); + } + + $filter('filter')($scope.botonera, { + label: 'Cliente', + })[0].checked = true; + }) + .catch(function (e) { console.log(e); }); + }, function () { + $scope.seleccionarCliente(true); + return; + } + ); + }; + + $scope.seleccionarPuntosDeDescarga = function () { + if (!$scope.hojaRuta.cliente.COD || !$scope.hojaRuta.domicilio.id) { + focaModalService.alert('Primero seleccione un cliente y un domicilio'); return; + } else { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Búsqueda de Puntos de descarga', + templateUrl: 'modal-punto-descarga.html', + controller: 'focaModalPuntoDescargaController', + size: 'lg', + resolve: { + filters: { + idDomicilio: $scope.remito.domicilio.id, + idCliente: $scope.remito.cliente.COD, + articulos: $scope.remito.articulosRemito, + puntosDescarga: $scope.remito.remitoPuntoDescarga, + domicilio: $scope.remito.domicilio + } + } + } + ); + modalInstance.result.then( + function(puntosDescarga) { + + puntosDescarga.forEach(function(punto) { + $scope.hojaRuta.remitoPuntoDescarga.push( + { + puntoDescarga: punto + } + ); + }); + + $scope.$broadcast('addCabecera', { + label: 'Puntos de descarga:', + valor: getCabeceraPuntoDescarga(puntosDescarga) + }); + }, function () { + $scope.abrirModalDomicilios($scope.cliente); + } + ); } - if (!$scope.hojaRuta.tarifario) { - focaModalService.alert('Ingrese Tarifario'); + }; + + function getCabeceraPuntoDescarga(puntosDescarga) { + var puntosStamp = ''; + puntosDescarga.forEach(function (punto, idx, arr) { + puntosStamp += punto.descripcion; + if ((idx + 1) !== arr.length) puntosStamp += ', '; + }); + return puntosStamp; + } + + $scope.crearHojaRuta = function () { + + var continuar = validarHojaRuta(); + if (!continuar) { return; - } - if (!$scope.hojaRuta.datosExtra) { - focaModalService.alert('Ingrese Datos extra'); + } else if ($scope.remitoAbierto) { + guardarRemitoAbierto(); return; } var date = new Date(); @@ -142,9 +530,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }, remitos: $scope.hojaRuta.remitosTabla }; + save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); focaCrearHojaRutaService.crearHojaRuta(save).then( - function(data) { + function (data) { focaModalService.alert( 'Hoja ruta creada Nº: ' + $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + @@ -153,14 +542,54 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', config(); }, - function(error) { + function (error) { focaModalService.alert('Hubo un error al crear la hoja de ruta'); console.info(error); } ); }; - $scope.seleccionarTransportista = function() { + $scope.seleccionarProveedor = function () { + var parametrosModal = { + titulo: 'Búsqueda de Proveedor', + query: '/proveedor', + columnas: [ + { + nombre: 'Código', + propiedad: 'COD', + filtro: { + nombre: 'rellenarDigitos', + parametro: 5 + } + }, + { + nombre: 'Nombre', + propiedad: 'NOM' + }, + { + nombre: 'CUIT', + propiedad: 'CUIT' + } + ], + tipo: 'POST', + json: { razonCuitCod: '' } + }; + focaModalService.modal(parametrosModal).then( + function (proveedor) { + $filter('filter')($scope.botonera, { + label: 'Proveedor', + })[0].checked = true; + + $scope.$broadcast('addCabecera', { + label: 'Proveedor:', + valor: proveedor.COD + ' - ' + proveedor.NOM + }); + $scope.hojaRuta.proveedor = proveedor; + }, function () { } + ); + }; + + $scope.seleccionarTransportista = function () { if (eligioPreConfirmado()) return; var parametrosModal = { titulo: 'Búsqueda de transportista', @@ -181,7 +610,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', ] }; focaModalService.modal(parametrosModal).then( - function(proveedor) { + function (proveedor) { $scope.hojaRuta.transportista = proveedor; $scope.$broadcast('addCabecera', { label: 'Transportista:', @@ -192,13 +621,13 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', $filter('filter')($scope.botonera, { label: 'Transportista', })[0].checked = true; - }, function() { + }, function () { } ); }; - $scope.seleccionarChofer = function() { + $scope.seleccionarChofer = function () { var parametrosModal = { titulo: 'Búsqueda de Chofer', query: '/chofer', @@ -226,41 +655,43 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', ] }; focaModalService.modal(parametrosModal).then( - function(chofer) { + function (chofer) { $scope.hojaRuta.chofer = chofer; $scope.$broadcast('addCabecera', { label: 'Chofer:', - valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre + valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' + chofer.nombre }); $filter('filter')($scope.botonera, { label: 'Chofer', })[0].checked = true; - }, function() { + $scope.mostrarDetalle($scope.hojaRuta); + + }, function () { // funcion ejecutada cuando se cancela el modal } ); }; - $scope.seleccionarVehiculo = function() { + $scope.seleccionarVehiculo = function () { if (!eligioFecha() || eligioPreConfirmado()) return; modalVehiculos(); }; - $scope.seleccionarTarifario = function() { + $scope.seleccionarTarifario = function () { focaModalService .prompt({ titulo: 'Tarifa flete', value: $scope.hojaRuta.tarifario }) - .then(function(costo) { + .then(function (costo) { if (isNaN(costo)) { focaModalService .alert('Ingrese un valor válido') - .then(function() { + .then(function () { $scope.seleccionarTarifario(); }); - + return; } @@ -276,7 +707,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }); }; - $scope.seleccionarRemitos = function() { + $scope.seleccionarRemitos = function () { if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; var modalInstance = $uibModal.open( { @@ -284,11 +715,11 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', templateUrl: 'foca-modal-remito.html', controller: 'focaModalRemitoController', size: 'lg', - resolve: {usadoPor: function() {return 'hojaRuta';}} + resolve: { usadoPor: function () { return 'hojaRuta'; } } } ); modalInstance.result.then( - function(remito) { + function (remito) { // TODO: borrar cuando no se use definitivamente // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { @@ -321,36 +752,36 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', // remito.litros = litros; // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; - $scope.cargarCisterna(remito.id).then(function() { + $scope.cargarCisterna(remito.id).then(function () { $scope.hojaRuta.remitosTabla.push(remito); - }, function(error) { + $filter('filter')($scope.botonera, { + label: 'Remitos', + })[0].checked = true; + }, function (error) { if (error && error !== 'backdrop click') { - focaModalService .alert(error || 'Ha ocurrido un error') - .then(function() { + .then(function () { $scope.seleccionarRemitos(); }); } else { - $scope.seleccionarRemitos(); - } }); - }, function() { + }, function () { // funcion ejecutada cuando se cancela el modal } ); }; - $scope.seleccionarVehiculosPrecargados = function() { + $scope.seleccionarVehiculosPrecargados = function () { if (!eligioFecha()) return; modalVehiculos(true); }; - $scope.cargarCisterna = function(idRemito) { + $scope.cargarCisterna = function (idRemito) { if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; var modalInstance = $uibModal.open( { @@ -359,41 +790,41 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', controller: 'focaDetalleVehiculo', size: 'lg', resolve: { - idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, - idRemito: function() {return idRemito;}, - fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} + idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; }, + idRemito: function () { return idRemito; }, + fechaReparto: function () { return $scope.hojaRuta.fechaReparto; } } } ); return modalInstance.result; }; - $scope.seleccionarFechaEntrega = function() { + $scope.seleccionarFechaEntrega = function () { var confirmacion = false; var hasVehiculoId = $scope.hojaRuta.vehiculo.id !== undefined; var hasTarifario = $scope.hojaRuta.tarifario !== null; var hasTransportista = Object.keys($scope.hojaRuta.transportista).length > 0; - var hasChofer = Object.keys($scope.hojaRuta.chofer).length > 0; + var hasChofer = Object.keys($scope.hojaRuta.chofer).length > 0; var hasDatosExtra = $scope.hojaRuta.datosExtra !== undefined; - + if (hasVehiculoId || hasTarifario || hasTransportista || - hasChofer || hasDatosExtra) { + hasChofer || hasDatosExtra) { confirmacion = true; if (confirmacion) { focaModalService - .confirm('Si cambia la fecha se perderán los datos actuales') - .then(function(data) { - if(data) { - $scope.hojaRuta.vehiculo.id = undefined; - $scope.hojaRuta.tarifario = null; - $scope.hojaRuta.transportista = {}; - $scope.hojaRuta.chofer = {}; - $scope.hojaRuta.datosExtra = undefined; - elegirFecha(); - } - }, function() { - return ; - }); + .confirm('Si cambia la fecha se perderán los datos actuales') + .then(function (data) { + if (data) { + $scope.hojaRuta.vehiculo.id = undefined; + $scope.hojaRuta.tarifario = null; + $scope.hojaRuta.transportista = {}; + $scope.hojaRuta.chofer = {}; + $scope.hojaRuta.datosExtra = undefined; + elegirFecha(); + } + }, function () { + return; + }); } } else { elegirFecha(); @@ -401,7 +832,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }; function setearFecha(fecha) { - $timeout(function() { + $timeout(function () { $scope.$broadcast('addCabecera', { label: 'Fecha de entrega: ', valor: fecha.toLocaleDateString() @@ -411,7 +842,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }); } - $scope.seleccionarDatosExtra = function() { + $scope.seleccionarDatosExtra = function () { var datosHojaRuta = $scope.hojaRuta.datosExtra; var modalInstance = $uibModal.open( { @@ -419,7 +850,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', controller: 'focaModalDatosHojaRutaCtrl', size: 'lg', resolve: { - parametrosDatos: function() { + parametrosDatos: function () { return { datosHojaRuta: datosHojaRuta }; @@ -427,32 +858,32 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', } } ); - return modalInstance.result.then(function(datosExtra) { + return modalInstance.result.then(function (datosExtra) { $filter('filter')($scope.botonera, { label: 'Datos extra', })[0].checked = true; $scope.hojaRuta.datosExtra = datosExtra; - }, function() { + }, function () { //se ejecuta cuando se cancela el modal }); }; - $scope.desasociarRemito = function(key, idRemito) { + $scope.desasociarRemito = function (key, idRemito) { var idsRemito = [idRemito]; focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + - ' vehículo?').then(function() { + ' vehículo?').then(function () { focaCrearHojaRutaService.desasociarRemitos(idsRemito, $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) - .then(function() { - $scope.hojaRuta.remitosTabla.splice(key, 1); - focaModalService.alert('Remito desasociado con éxito'); - }); + .then(function () { + $scope.hojaRuta.remitosTabla.splice(key, 1); + focaModalService.alert('Remito desasociado con éxito'); + }); }); }; - $scope.verProductosRemito = function(idRemito) { + $scope.verProductosRemito = function (idRemito) { var parametrosModal = { titulo: 'Articulos remito', query: '/articulos/remito/' + idRemito, @@ -475,12 +906,36 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', focaModalService.modal(parametrosModal).then(); }; + $scope.mostrarDetalle = function (hojasRutas) { + var modalInstance =$uibModal.open( + { + ariaLabelledBy: '', + templateUrl: 'modal-detalle-carga.html', + controller: 'focaModalDetalleController', + resolve: { + hojasRutas: function () { return hojasRutas; } + }, + size: 'lg', + } + ); + return modalInstance.result.then(function (res) { + res.cisternas.forEach( function (cisterna) { + $scope.cisternaCargas.push(cisterna.cisternaCarga); + }); + $scope.cisternaMovimientos = res.movimientos; + $scope.articulosRecibidos = res.articulos; + $scope.articulos = res.articulos; + }, function () { + //se ejecuta cuando se cancela el modal + }); + }; + function elegirFecha() { - var fechaEntrega = { + var fechaEntrega = { titulo: 'Fecha de entrega', minDate: new Date() }; - focaModalService.modalFecha(fechaEntrega).then(function(fecha) { + focaModalService.modalFecha(fechaEntrega).then(function (fecha) { $scope.hojaRuta.fechaReparto = fecha; @@ -488,6 +943,22 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', label: 'Fecha de entrega: ', valor: fecha.toLocaleDateString() }); + //habilitar los otros botones + var temp = []; + if ($scope.botonera.length > 1) { + limpiarBotonera($scope.botonera); + } else if ($scope.precargado) { + temp = focaCrearHojaRutaService.getBotoneraPrecargado(); + modalVehiculos(true); + } else if ($scope.cargaRemito && $scope.precargado === false) { + temp = focaCrearHojaRutaService.getBotoneraCargarRemito(); + } else { + temp = focaCrearHojaRutaService.getBotoneraCargarRemito(); + modalVehiculos(true); + } + temp.forEach(function (e) { + $scope.botonera.push(e); + }); $filter('filter')($scope.botonera, { label: 'Fecha Entrega', @@ -498,7 +969,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', function eligioPreConfirmado() { if ($scope.eligioPreConfirmado) { focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); - return true; + return true; } return false; } @@ -524,7 +995,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', if (preCargados) { parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); - parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; + parametrosModal.titulo = 'Búsqueda de vehiculos precargados'; } else { parametrosModal.query = '/vehiculo'; parametrosModal.titulo = 'Búsqueda de vehículos'; @@ -543,10 +1014,11 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', nombre: 'Semi' } ]; - focaModalService.modal(parametrosModal).then(function(vehiculo) { + focaModalService.modal(parametrosModal).then(function (vehiculo) { if (!preCargados && vehiculoEnUso(vehiculo)) return; $scope.hojaRuta.vehiculo = vehiculo; $scope.hojaRuta.transportista = vehiculo.transportista; + // mostrarDetalle(vehiculo); if (preCargados) { $scope.eligioPreConfirmado = true; $scope.hojaRuta.vehiculo = vehiculo; @@ -557,10 +1029,13 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }); focaCrearHojaRutaService .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) - .then(function(res) { - + .then(function (res) { $filter('filter')($scope.botonera, { - label: 'Vehiculos precargados', + label: 'Transportista', + })[0].checked = true; + + $filter('filter')($scope.botonera, { + label: 'Vehiculo', })[0].checked = true; $scope.hojaRuta.remitosTabla = res.data; @@ -568,7 +1043,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', } else { focaCrearHojaRutaService .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) - .then(function(res) { + .then(function (res) { $filter('filter')($scope.botonera, { label: 'Vehiculo', @@ -598,11 +1073,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', for (var i = 0; i < vehiculo.cisternas.length; i++) { for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; - if (cisternaCarga.fechaReparto.substring(0, 10) === + if (cisternaCarga.fechaReparto.substring(0, 10) === new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && - cisternaCarga.idUsuarioProceso !== idUsuario) - { + cisternaCarga.idUsuarioProceso !== idUsuario) { focaModalService.alert('El vehículo está siendo usado por otro' + ' usuario'); return true; @@ -622,7 +1096,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', if (confirmacion) { focaModalService.confirm( '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' - ).then(function(data) { + ).then(function (data) { if (data) { $location.path('/'); } @@ -632,6 +1106,11 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', } } + function limpiarBotonera(botonera) { + botonera.forEach(function (boton) { + boton.checked = false; + }); + } function setearHojaRuta(hojaRuta) { $scope.$broadcast('cleanCabecera'); @@ -642,7 +1121,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') }); - $filter('filter')( $scope.botonera, { + $filter('filter')($scope.botonera, { label: 'Fecha Entrega' })[0].checked = true; } @@ -653,7 +1132,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', hojaRuta.transportista.NOM }); - $filter('filter')( $scope.botonera, { + $filter('filter')($scope.botonera, { label: 'Transportista' })[0].checked = true; } @@ -664,7 +1143,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', ' - ' + hojaRuta.chofer.nombre }); - $filter('filter')( $scope.botonera, { + $filter('filter')($scope.botonera, { label: 'Chofer' })[0].checked = true; } @@ -682,7 +1161,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', valor: hojaRuta.vehiculo.capacidad }); - $filter('filter')( $scope.botonera, { + $filter('filter')($scope.botonera, { label: 'Vehiculo' })[0].checked = true; } @@ -692,7 +1171,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', valor: hojaRuta.tarifario }); - $filter('filter')( $scope.botonera, { + $filter('filter')($scope.botonera, { label: 'Tarifario' })[0].checked = true; } @@ -709,7 +1188,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', } } function addArrayCabecera(array) { - for(var i = 0; i < array.length; i++) { + for (var i = 0; i < array.length; i++) { $scope.$broadcast('addCabecera', { label: array[i].label, valor: array[i].valor diff --git a/src/js/controllerDetalles.js b/src/js/controllerDetalles.js new file mode 100644 index 0000000..afa0dea --- /dev/null +++ b/src/js/controllerDetalles.js @@ -0,0 +1,157 @@ +angular.module('focaCrearHojaRuta') + .controller('focaModalDetalleController', [ + '$scope', '$timeout', '$uibModalInstance', 'focaModalService', + 'focaCrearHojaRutaService', 'hojasRutas', '$uibModal', '$filter', + function ($scope, $timeout, $uibModalInstance, focaModalService, + focaCrearHojaRutaService, hojasRutas, $uibModal, $filter) { + + $scope.mostrar = false; + $scope.articulos = []; + $scope.cisternaMovimientos = []; + + init(); + function init() { + $scope.hojasRutas = hojasRutas; + + $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter( + function (cisterna) { + return !cisterna.desactivado; + } + ); + focaCrearHojaRutaService.getArticulos() + .then(function (articulos) { + $scope.articulos = articulos.data; + }); + } + + $scope.validarCisternaDisponible = function (cisterna) { + if (parseInt(cisterna.disponible) > cisterna.capacidad) { + focaModalService.alert('No se puede ingresar una capacidad disponible ' + + 'superior a la ' + 'capacidad del vehiculo '); + cisterna.disponible = cisterna.capacidad; + return; + } + }; + + $scope.seleccionarProductos = function (cisterna) { + focaModalService.modal({ + titulo: 'Productos', + data: $scope.articulos, + size: 'md', + columnas: [ + { + propiedad: 'CodRub', + nombre: 'Codigo' + }, + { + propiedad: 'descripcion', + nombre: 'Nombre' + }, + ], + }).then(function (res) { + console.log('Res: ', res); + + var newArt = + { + id: 0, + idRemito: 0, + codigo: res.codigo, + sector: res.sector, + sectorCodigo: res.sector + '-' + res.codigo, + descripcion: res.descripcion, + item: 1, + nombre: res.descripcion, + precio: parseFloat(res.precio.toFixed(4)), + costoUnitario: res.costo, + editCantidad: false, + editPrecio: false, + rubro: res.CodRub, + ivaUnitario: res.IMPIVA, + impuestoInternoUnitario: res.ImpInt, + impuestoInterno1Unitario: res.ImpInt2, + impuestoInterno2Unitario: res.ImpInt3, + precioLista: res.precio, + combustible: 1, + facturado: 0, + idArticulo: res.id, + tasaIva: res.tasaIVA + }; + + newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; + newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; + + cisterna.articuloSeleccionado = newArt; + cisterna.nombreArticulo = res.descripcion; + }).catch(function (e) { + console.log(e); + }); + }; + + $scope.guardar = function () { + + var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas.filter(function (cisterna) { + return parseInt(cisterna.disponible) > 0; + }); + + var articulos = []; + + cisternasFilter.forEach(function (cisterna) { + + var fechaReparto = $scope.hojasRutas.fechaReparto; + + var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { + return carga.fechaReparto === fechaReparto; + }); + + if (filtroCisternaCarga.length) { + cisterna.cisternaCarga = filtroCisternaCarga[0]; + } else { + cisterna.cisternaCarga = { + confirmado: null, + fechaReparto: fechaReparto, + idCisterna: cisterna.id, + }; + } + + if (!cisterna.articuloSeleccionado) { + focaModalService.alert('Seleccione Articulo'); + + return; + } + + //cargar + if (cisterna.cisternaCarga.cantidad) { + cisterna.cisternaCarga.cantidad += cisterna.disponible; + } else { + cisterna.cisternaCarga.cantidad = cisterna.disponible; + cisterna.cisternaCarga.idProducto = + cisterna.articuloSeleccionado.idArticulo; + } + + //Guardar + var now = new Date(); + var cisternaMovimiento = { + fecha: now.toISOString().slice(0, 19).replace('T', ' '), + cantidad: cisterna.disponible, + metodo: 'carga', + idCisternaCarga: cisterna.cisternaCarga.id, + }; + + cisterna.cisternaCarga.fechaReparto = fechaReparto; + cisterna.articuloSeleccionado.cantidad = cisterna.disponible; + articulos.push(cisterna.articuloSeleccionado); + $scope.cisternaMovimientos.push(cisternaMovimiento); + }); + + $uibModalInstance.close({ + cisternas: cisternasFilter, + movimientos: $scope.cisternaMovimientos, + articulos: articulos + }); + }; + + $scope.cancel = function () { + $uibModalInstance.close(null); + }; + } + ]); diff --git a/src/js/service.js b/src/js/service.js index 48475be..9acf0b1 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -1,11 +1,17 @@ angular.module('focaCrearHojaRuta') - .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', - function($http, API_ENDPOINT) { + .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', '$cookies', + function($http, API_ENDPOINT, $cookies) { var route = API_ENDPOINT.URL; return { + idUsuario: $cookies.get('vendedorCobrador'), crearHojaRuta: function(hojaRuta) { return $http.post(route + '/hoja-ruta', hojaRuta); }, + crearRemito: function(remito) { + console.log('Crear remito-----: ', remito); + // TODO: Cambiar para usar el servicio /remito + return $http.post(route + '/remito', remito); + }, obtenerHojaRuta: function() { return $http.get(route +'/hoja-ruta'); }, @@ -22,8 +28,8 @@ angular.module('focaCrearHojaRuta') return $http.get(route+'/articulos/hoja-ruta/'+id); }, crearArticulosParaHojaRuta: function(articuloHojaRuta) { - return $http.post(route + '/articulos/hoja-ruta', - {articuloHojaRuta: articuloHojaRuta}); + return $http.post(route + '/articulos/remito', + {articuloRemito: articuloHojaRuta}); }, getDomiciliosByIdHojaRuta: function(id) { return $http.get(route +'/hoja-ruta/' + id + '/domicilios'); @@ -107,6 +113,133 @@ angular.module('focaCrearHojaRuta') image: 'tarifario.png' } ]; + }, + getBotones: function () { + return [ + { + label: 'Precargados', + image: 'vehiculos.png' + }, + { + label: 'Cargar Remitos', + image: 'remito.png' + }, + { + label: 'Remito Abierto', + image: 'remitoabierto.png' + } + ]; + }, + getRemitoAbierto: function () { + return [ + { + label: 'Fecha Entrega', + image: 'FechaEntrega.png' + }, + { + label: 'Transportista', + image: 'transportista.png' + }, + { + label: 'Vehiculo', + image: 'vehiculos.png' + }, + { + label: 'Chofer', + image: 'chofer.png' + }, + { + label: 'Proveedor', + image: 'proveedor.png' + }, + { + label: 'Tarifario', + image: 'tarifario.png' + }, + { + label: 'Cliente', + image: 'cliente.png' + } + ]; + }, + getArticulos : function () { + return $http.get(API_ENDPOINT.URL + '/articulos'); + }, + getVendedorById : function (idVendedor) { + return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + idVendedor); + }, + getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { + return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + + idDomicilio + '/' + idCliente); + }, + getBotonFecha : function () { + return [ + { + label: 'Fecha Entrega', + image: 'FechaEntrega.png' + }, + ]; + }, + getBotoneraPrecargado: function () { + return [ + + { + label: 'Transportista', + image: 'transportista.png' + }, + { + label: 'Chofer', + image: 'chofer.png' + }, + { + label: 'Vehiculo', + image: 'vehiculos.png' + }, + { + label: 'Tarifario', + image: 'tarifario.png' + }, + { + label: 'Datos extra', + image: 'tarifario.png' + } + ]; + }, + getBotoneraCargarRemito: function () { + return [ + { + label: 'Transportista', + image: 'transportista.png' + }, + { + label: 'Chofer', + image: 'chofer.png' + }, + { + label: 'Vehiculo', + image: 'flete.png' + }, + { + label: 'Remitos', + image: 'remito.png' + }, + { + label: 'Tarifario', + image: 'tarifario.png' + }, + { + label: 'Datos extra', + image: 'tarifario.png' + } + ]; + }, + guardarCisternas: function(cisterna, idRemito) { + return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar/' + + this.idUsuario + '/' + idRemito, cisterna); + }, + crearArticulosParaRemito: function(articuloRemito) { + return $http.post(route + '/articulos/remito', + {articuloRemito: articuloRemito}); } }; }]); diff --git a/src/views/hoja-ruta.html b/src/views/hoja-ruta.html index 62de7d7..bbdcc6a 100644 --- a/src/views/hoja-ruta.html +++ b/src/views/hoja-ruta.html @@ -9,86 +9,192 @@
-
- +
+
- -
- - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + +
#RemitoClienteDirección - -
{{remito.sucursal | rellenarDigitos: 4}}-{{remito.numeroRemito | rellenarDigitos: 8}} - - - + + + + + + + + + +
+ + + + + + + + + + +
+ Items: + + +

Total:

+
+

{{getTotal() | currency: hojaRuta.cotizacion.moneda.SIMBOLO}}

+
+ +
+
+
diff --git a/src/views/modal-detalle-carga.html b/src/views/modal-detalle-carga.html new file mode 100644 index 0000000..3024e5d --- /dev/null +++ b/src/views/modal-detalle-carga.html @@ -0,0 +1,75 @@ + +
+
+ + Transportista {{hojasRutas.idTransportista}} {{hojasRutas.transportista.NOM}} + Unidad {{hojasRutas.vehiculo.codigo}} Tractor {{hojasRutas.vehiculo.tractor}} + + +
+
+
+
+ Fecha {{hojasRutas.fecha | date:'yyyy-MM-dd':'-0300'}} +
+
+ + + \ No newline at end of file -- 1.9.1