From 399786fc5794960f029393f7924a2e3d68c47483 Mon Sep 17 00:00:00 2001 From: Jose Pinto Date: Wed, 2 Jan 2019 17:30:12 -0300 Subject: [PATCH] crea nota de pedido, correccion guardar precios y condiciones --- src/js/businessService.js | 16 ++++++++++++++++ src/js/controller.js | 30 +++++++++++++++++++++--------- src/js/service.js | 6 +++++- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/js/businessService.js b/src/js/businessService.js index 8c024a4..b044e04 100644 --- a/src/js/businessService.js +++ b/src/js/businessService.js @@ -23,6 +23,22 @@ angular.module('focaCrearNotaPedido') }; crearNotaPedidoService.crearEstadoParaNotaPedido(estado); }, + addPuntosDescarga: function(idNotaPedido, puntosDescarga) { + var puntos = []; + + puntosDescarga.forEach(function(punto) { + punto.articulosAgregados.forEach(function(articulo) { + puntos.push({ + idPuntoDescarga: punto.id, + idNotaPedido: idNotaPedido, + idProducto: articulo.id, + cantidad: articulo.cantidad + }); + }); + }); + + return crearNotaPedidoService.crearPuntosDescarga(puntos); + }, calcularArticulos: function(articulos, cotizacion) { for(var i = 0; i < articulos.length; i++) { articulos[i].precio = articulos[i].precio / cotizacion; diff --git a/src/js/controller.js b/src/js/controller.js index 0f33476..234e005 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -147,15 +147,22 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', ); notaPedidoBusinessService.addArticulos($scope.articulosTabla, data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); - var plazos = $scope.plazosPagos; - for(var j = 0; j < plazos.length; j++) { - var json = { - idPedido: data.data.id, - dias: plazos[j].dias - }; - crearNotaPedidoService.crearPlazosParaNotaPedido(json); + if($scope.notaPedido.puntosDescarga) { + notaPedidoBusinessService.addPuntosDescarga(data.data.id, + $scope.notaPedido.puntosDescarga); } + + var plazos = $scope.plazosPagos; + var plazosACrear = []; + plazos.forEach(function(plazo) { + plazosACrear.push({ + idNotaPedido: data.data.id, + dias: plazo.dias + }); + }); + crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); + notaPedidoBusinessService.addEstado(data.data.id, $scope.notaPedido.vendedor.CodVen); @@ -256,7 +263,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', valor: notaPedido.proveedor.NOM }, { - label: 'Precio condicion:', + label: 'Precios y condiciones:', valor: valorPrecioCondicion() + ' ' + notaPedidoBusinessService .plazoToString(notaPedido.notaPedidoPlazo) @@ -446,7 +453,10 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', controller: 'focaModalDomicilioController', resolve: { idCliente: function() { return cliente.cod; }, - esNuevo: function() { return cliente.esNuevo; } + esNuevo: function() { return cliente.esNuevo; }, + articulos: function() { + return $scope.articulosTabla; + } }, size: 'lg', } @@ -464,6 +474,8 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', domicilio.Localidad + ', ' + domicilio.Provincia; $scope.notaPedido.domicilioStamp = domicilioStamp; + $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; + $scope.$broadcast('addCabecera', { label: 'Cliente:', valor: cliente.nom diff --git a/src/js/service.js b/src/js/service.js index 74b47af..3bce2cb 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -44,7 +44,7 @@ angular.module('focaCrearNotaPedido') return $http.post(route + '/flete', {flete : flete}); }, crearPlazosParaNotaPedido: function(plazos) { - return $http.post(route + '/plazo-pago/nota-pedido', plazos); + return $http.post(route + '/plazo-pago/nota-pedido', {plazos: plazos}); }, getCotizacionByIdMoneda: function(id) { return $http.get(route + '/moneda/' + id); @@ -58,6 +58,10 @@ angular.module('focaCrearNotaPedido') getBotonera: function() { return ['Vendedor', 'Cliente', 'Proveedor', 'Moneda', 'Precios y condiciones', 'Flete', 'Productos']; + }, + crearPuntosDescarga: function(puntosDescarga) { + return $http.post(route + '/puntos-descarga/nota-pedido', + {puntosDescarga: puntosDescarga}); } }; }]); -- 1.9.1