From 9b31d344c5d541d397679374b3fa511dda49382a Mon Sep 17 00:00:00 2001 From: Jose Pinto Date: Thu, 28 Feb 2019 10:50:01 -0300 Subject: [PATCH] Auto stash before merge of "master" and "upstream/master" --- src/js/controller.js | 339 +++++++++++++++++++++++---------------------- src/views/nota-pedido.html | 20 +-- 2 files changed, 187 insertions(+), 172 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index e2def0d..4237a28 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -13,11 +13,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', 'focaSeguimientoService', 'APP', 'focaLoginService', + '$localStorage', function( $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, - $rootScope, focaSeguimientoService, APP, focaLoginService) - { + $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) + { config(); function config() { @@ -26,7 +27,6 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', $scope.datepickerAbierto = false; $scope.show = false; $scope.cargando = true; - $scope.now = new Date(); $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); $scope.comprobante = $filter('rellenarDigitos')(0, 8); $scope.dateOptions = { @@ -49,14 +49,21 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } else { $scope.botonera = crearNotaPedidoService.getBotonera(); } - + //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' + var monedaPorDefecto; crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { - $scope.monedaDefecto = res.data[0]; - $scope.cotizacionDefecto = $scope.monedaDefecto.cotizaciones[0]; + monedaPorDefecto = res.data[0]; - init(); + $scope.notaPedido.cotizacion = Object.assign( + {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] + ); + $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; }); + + init(); + $timeout(function() {getLSNotaPedido();}); + } function init() { @@ -68,11 +75,11 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', proveedor: {}, domicilio: {dom: ''}, vendedor: {}, - moneda: $scope.monedaDefecto, - cotizacion: $scope.cotizacionDefecto + fechaCarga: new Date(), + cotizacion: {} }; - - $scope.articulosTabla = []; + + $scope.notaPedido.articulosNotaPedido = []; $scope.idLista = undefined; crearNotaPedidoService.getNumeroNotaPedido().then( @@ -107,13 +114,16 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', ); } - $scope.inicial = { - notaPedido: angular.copy($scope.notaPedido), - articulosTabla: angular.copy($scope.articulosTabla), - idLista: angular.copy($scope.idLista) - }; + $scope.inicial = angular.copy($scope.notaPedido); } + $scope.$watch('notaPedido', function(newValue, oldValue) { + focaBotoneraLateralService.setPausarData({ + label: 'notaPedido', + val: newValue + }); + }, true); + $scope.crearNotaPedido = function() { if(!$scope.notaPedido.vendedor.id) { focaModalService.alert('Ingrese Vendedor'); @@ -124,13 +134,13 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } else if(!$scope.notaPedido.proveedor.COD) { focaModalService.alert('Ingrese Proveedor'); return; - } else if(!$scope.notaPedido.moneda.ID) { + } else if(!$scope.notaPedido.cotizacion.moneda.ID) { focaModalService.alert('Ingrese Moneda'); return; } else if(!$scope.notaPedido.cotizacion.ID) { focaModalService.alert('Ingrese Cotización'); return; - } else if(!$scope.plazosPagos) { + } else if(!$scope.notaPedido.notaPedidoPlazo) { focaModalService.alert('Ingrese Precios y Condiciones'); return; } else if( @@ -141,7 +151,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto focaModalService.alert('Ingrese Domicilio'); return; - } else if($scope.articulosTabla.length === 0) { + } else if($scope.notaPedido.articulosNotaPedido.length === 0) { focaModalService.alert('Debe cargar al menos un articulo'); return; } @@ -149,13 +159,13 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', $scope.saveLoading = true; var notaPedido = { id: $scope.notaPedido.id, - fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), + fechaCarga: new Date($scope.notaPedido.fechaCarga).toISOString().slice(0, 19).replace('T', ' '), idVendedor: $scope.notaPedido.vendedor.id, idCliente: $scope.notaPedido.cliente.COD, nombreCliente: $scope.notaPedido.cliente.NOM, cuitCliente: $scope.notaPedido.cliente.CUIT, idProveedor: $scope.notaPedido.proveedor.COD, - idDomicilio: $scope.notaPedido.domicilio.id, + idDomicilio: $scope.notaPedido.idDomicilio || $scope.notaPedido.domicilio.id, idCotizacion: $scope.notaPedido.cotizacion.ID, idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, @@ -178,15 +188,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', data.data.id, '' ); - notaPedidoBusinessService.addArticulos($scope.articulosTabla, + notaPedidoBusinessService.addArticulos($scope.notaPedido.articulosNotaPedido, data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); - if($scope.notaPedido.puntosDescarga) { + if($scope.notaPedido.notaPedidoPuntoDescarga) { notaPedidoBusinessService.addPuntosDescarga(data.data.id, - $scope.notaPedido.puntosDescarga); + $scope.notaPedido.notaPedidoPuntoDescarga); } - var plazos = $scope.plazosPagos; + var plazos = $scope.notaPedido.notaPedidoPlazo; var plazosACrear = []; plazos.forEach(function(plazo) { plazosACrear.push({ @@ -233,111 +243,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } } ); - modalInstance.result.then( - function(notaPedido) { - $scope.now = new Date(notaPedido.fechaCarga); - //añado cabeceras - $scope.notaPedido.id = notaPedido.id; - $scope.$broadcast('removeCabecera', 'Bomba:'); - $scope.$broadcast('removeCabecera', 'Kilometros:'); - var cabeceras = [ - { - label: 'Moneda:', - valor: notaPedido.cotizacion.moneda.DETALLE - }, - { - label: 'Fecha cotizacion:', - valor: $filter('date')(notaPedido.cotizacion.FECHA, - 'dd/MM/yyyy') - }, - { - label: 'Cotizacion:', - valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, - '2') - }, - { - label: 'Cliente:', - valor: notaPedido.cliente.NOM - }, - { - label: 'Domicilio:', - valor: notaPedido.domicilioStamp - }, - { - label: 'Vendedor:', - valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + - ' - ' + notaPedido.vendedor.NOM - }, - { - label: 'Proveedor:', - valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + - ' - ' + notaPedido.proveedor.NOM - }, - { - label: 'Precios y condiciones:', - valor: valorPrecioCondicion() + ' ' + - notaPedidoBusinessService - .plazoToString(notaPedido.notaPedidoPlazo) - }, - { - label: 'Flete:', - valor: notaPedido.fob === 1 ? 'FOB' : ( - notaPedido.flete === 1 ? 'Si' : 'No') - } - ]; - - function valorPrecioCondicion() { - if(notaPedido.idPrecioCondicion > 0) { - return notaPedido.precioCondicion.nombre; - } else { - return 'Ingreso Manual'; - } - } - - if(notaPedido.flete === 1) { - var cabeceraBomba = { - label: 'Bomba:', - valor: notaPedido.bomba === 1 ? 'Si' : 'No' - }; - if(notaPedido.kilometros) { - var cabeceraKilometros = { - label: 'Kilometros:', - valor: notaPedido.kilometros - }; - cabeceras.push(cabeceraKilometros); - } - cabeceras.push(cabeceraBomba); - } - - $scope.articulosTabla = notaPedido.articulosNotaPedido; - notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, - notaPedido.cotizacion.VENDEDOR); - - if(notaPedido.idPrecioCondicion > 0) { - $scope.idLista = notaPedido.precioCondicion.idListaPrecio; - } else { - $scope.idLista = -1; - } - - $scope.puntoVenta = $filter('rellenarDigitos')( - notaPedido.sucursal, 4 - ); - - $scope.comprobante = $filter('rellenarDigitos')( - notaPedido.numeroNotaPedido, 8 - ); - - $scope.notaPedido = notaPedido; - $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; - $scope.plazosPagos = notaPedido.notaPedidoPlazo; - $scope.notaPedido.puntosDescarga = - formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); - addArrayCabecera(cabeceras); - - }, function() { - // funcion ejecutada cuando se cancela el modal - } - ); + modalInstance.result.then(setearNotaPedido); }; $scope.seleccionarProductos = function() { @@ -355,7 +261,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', parametroProducto: { idLista: $scope.idLista, cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, - simbolo: $scope.notaPedido.moneda.SIMBOLO + simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO } }, size: 'lg' @@ -370,7 +276,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', sector: producto.sector, sectorCodigo: producto.sector + '-' + producto.codigo, descripcion: producto.descripcion, - item: $scope.articulosTabla.length + 1, + item: $scope.notaPedido.articulosNotaPedido.length + 1, nombre: producto.descripcion, precio: parseFloat(producto.precio.toFixed(4)), costoUnitario: producto.costo, @@ -410,15 +316,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', filters: { idDomicilio: $scope.notaPedido.domicilio.id, idCliente: $scope.notaPedido.cliente.COD, - articulos: $scope.articulosTabla, - puntosDescarga: $scope.notaPedido.puntosDescarga + articulos: $scope.notaPedido.articulosNotaPedido, + puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga } } } ); modalInstance.result.then( function(puntosDescarga) { - $scope.notaPedido.puntosDescarga = puntosDescarga; + $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga; //AGREGO PUNTOS DE DESCARGA A CABECERA var puntosStamp = ''; @@ -567,7 +473,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', domicilio.Localidad + ', ' + domicilio.Provincia; $scope.notaPedido.domicilioStamp = domicilioStamp; - $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; + $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga; $scope.$broadcast('addCabecera', { label: 'Cliente:', @@ -596,12 +502,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', $scope.getTotal = function() { var total = 0; - - if ($scope.articulosTabla) { - var arrayTempArticulos = $scope.articulosTabla; - for (var i = 0; i < arrayTempArticulos.length; i++) { - total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; - } + var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; + for (var i = 0; i < arrayTempArticulos.length; i++) { + total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; } return parseFloat(total.toFixed(2)); @@ -628,8 +531,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', var cabecera = ''; var plazosConcat = ''; if(!Array.isArray(precioCondicion)) { + $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; + $scope.notaPedido.precioCondicion = precioCondicion; $scope.notaPedido.idPrecioCondicion = precioCondicion.id; - $scope.plazosPagos = precioCondicion.plazoPago; $scope.idLista = precioCondicion.idListaPrecio; for(var i = 0; i < precioCondicion.plazoPago.length; i++) { plazosConcat += precioCondicion.plazoPago[i].dias + ' '; @@ -640,13 +544,13 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', $scope.notaPedido.idPrecioCondicion = 0; //-1, el modal productos busca todos los productos $scope.idLista = -1; - $scope.plazosPagos = precioCondicion; + $scope.notaPedido.notaPedidoPlazo = precioCondicion; for(var j = 0; j < precioCondicion.length; j++) { plazosConcat += precioCondicion[j].dias + ' '; } cabecera = 'Ingreso manual ' + plazosConcat.trim(); } - $scope.articulosTabla = []; + $scope.notaPedido.articulosNotaPedido = []; $scope.$broadcast('addCabecera', { label: 'Precios y condiciones:', valor: cabecera @@ -766,21 +670,16 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', ); modalInstance.result.then( function(cotizacion) { - var articulosTablaTemp = $scope.articulosTabla; - + var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido; for(var i = 0; i < articulosTablaTemp.length; i++) { articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * $scope.notaPedido.cotizacion.VENDEDOR; articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / cotizacion.VENDEDOR; } - - $scope.articulosTabla = articulosTablaTemp; - $scope.notaPedido.moneda = moneda; - $scope.monedaDefecto = moneda; - $scope.cotizacionDefecto = cotizacion; + $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; $scope.notaPedido.cotizacion = cotizacion; - + $scope.notaPedido.cotizacion.moneda = moneda; if(moneda.DETALLE === 'PESOS ARGENTINOS') { $scope.$broadcast('removeCabecera', 'Moneda:'); $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); @@ -814,13 +713,13 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', return; } delete $scope.articuloACargar.sectorCodigo; - $scope.articulosTabla.push($scope.articuloACargar); + $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); $scope.cargando = true; } }; $scope.quitarArticulo = function(key) { - $scope.articulosTabla.splice(key, 1); + $scope.notaPedido.articulosNotaPedido.splice(key, 1); }; $scope.editarArticulo = function(key, articulo) { @@ -873,6 +772,116 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', articulo.precio = parseFloat(articulo.precio); }; + function setearNotaPedido(notaPedido) { + //añado cabeceras + $scope.notaPedido = notaPedido; + $scope.$broadcast('removeCabecera', 'Bomba:'); + $scope.$broadcast('removeCabecera', 'Kilometros:'); + + var cabeceras = []; + + if (notaPedido.cotizacion) { + cabeceras.push({ + label: 'Moneda:', + valor: notaPedido.cotizacion.moneda.DETALLE + }); + cabeceras.push({ + label: 'Fecha cotizacion:', + valor: $filter('date')(notaPedido.cotizacion.FECHA, + 'dd/MM/yyyy') + }); + cabeceras.push({ + label: 'Cotizacion:', + valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, + '2') + }); + } + if (notaPedido.cliente.COD) { + cabeceras.push({ + label: 'Cliente:', + valor: notaPedido.cliente.NOM + }); + cabeceras.push({ + label: 'Domicilio:', + valor: notaPedido.domicilioStamp + }); + } + if (notaPedido.vendedor.NUM) { + cabeceras.push({ + label: 'Vendedor:', + valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + + ' - ' + notaPedido.vendedor.NOM + }); + } + if (notaPedido.proveedor.COD) { + cabeceras.push({ + label: 'Proveedor:', + valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + + ' - ' + notaPedido.proveedor.NOM + }); + } + if (notaPedido.notaPedidoPlazo) { + cabeceras.push({ + label: 'Precios y condiciones:', + valor: valorPrecioCondicion() + ' ' + + notaPedidoBusinessService + .plazoToString(notaPedido.notaPedidoPlazo) + }); + } + if (notaPedido.flete !== undefined) { + cabeceras.push({ + label: 'Flete:', + valor: notaPedido.fob === 1 ? 'FOB' : ( + notaPedido.flete === 1 ? 'Si' : 'No') + }); + } + + + function valorPrecioCondicion() { + if(notaPedido.idPrecioCondicion > 0) { + return notaPedido.precioCondicion.nombre; + } else { + return 'Ingreso Manual'; + } + } + + if(notaPedido.flete === 1) { + var cabeceraBomba = { + label: 'Bomba:', + valor: notaPedido.bomba === 1 ? 'Si' : 'No' + }; + if(notaPedido.kilometros) { + var cabeceraKilometros = { + label: 'Kilometros:', + valor: notaPedido.kilometros + }; + cabeceras.push(cabeceraKilometros); + } + cabeceras.push(cabeceraBomba); + } + + notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido, + notaPedido.cotizacion.VENDEDOR); + + if(notaPedido.idPrecioCondicion > 0) { + $scope.idLista = notaPedido.precioCondicion.idListaPrecio; + } else { + $scope.idLista = -1; + } + + $scope.puntoVenta = $filter('rellenarDigitos')( + notaPedido.sucursal, 4 + ); + + $scope.comprobante = $filter('rellenarDigitos')( + notaPedido.numeroNotaPedido, 8 + ); + + $scope.notaPedido.notaPedidoPuntoDescarga = + formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []); + addArrayCabecera(cabeceras); + } + function addArrayCabecera(array) { for(var i = 0; i < array.length; i++) { $scope.$broadcast('addCabecera', { @@ -899,13 +908,13 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', return resultPunto.id === el.idPuntoDescarga; }); - if(puntoDescarga.length) { + if (puntoDescarga.length) { puntoDescarga[0].articulosAgregados.push({ cantidad: el.cantidad, descripcion: el.producto.descripcion, id: el.producto.id }); - }else { + } else { result.push({ id: el.puntoDescarga.id, id_cliente: el.puntoDescarga.id_cliente, @@ -929,11 +938,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', function salir() { var confirmacion = false; - angular.forEach($scope.inicial, function(valor, key) { - if (!angular.equals($scope[key], $scope.inicial[key])) { - confirmacion = true; - } - }); + if (!angular.equals($scope.notaPedido, $scope.inicial)) { + confirmacion = true; + } if (confirmacion) { focaModalService.confirm( @@ -947,5 +954,13 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', $location.path('/'); } } + + function getLSNotaPedido() { + var notaPedido = JSON.parse($localStorage.notaPedido || null); + if (notaPedido) { + setearNotaPedido(notaPedido); + delete $localStorage.notaPedido; + } + } } ]); diff --git a/src/views/nota-pedido.html b/src/views/nota-pedido.html index 72500e1..92c737d 100644 --- a/src/views/nota-pedido.html +++ b/src/views/nota-pedido.html @@ -2,7 +2,7 @@ @@ -47,8 +47,8 @@ @@ -127,7 +127,7 @@ Items: - +

Total:

@@ -237,8 +237,8 @@
@@ -309,7 +309,7 @@
@@ -363,7 +363,7 @@