diff --git a/src/js/controller.js b/src/js/controller.js index a62eac8..cc5da7b 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -50,37 +50,18 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', if (APP === 'distribuidor') { $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; } - //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' - //Trabajo con el proveedor YPF, por eso uso siempre la primera - var promiseMoneda = crearNotaPedidoService.getCotizacionByIdMoneda(1); - var promiseProveedor = crearNotaPedidoService.getProveedorById(98); - - //TODO refactor después de demo - Promise.all([promiseMoneda, promiseProveedor]).then(function(res) { - - var monedaPorDefecto = res[0].data[0]; - - $scope.notaPedido.cotizacion = Object.assign( - {moneda: monedaPorDefecto}, - monedaPorDefecto.cotizaciones[0] - ); - $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; - - var proveedorPorDefecto = res[1].data[0]; - - $scope.notaPedido.proveedor = proveedorPorDefecto; - $scope.inicial.proveedor = $scope.notaPedido.proveedor; - - $scope.notaPedido.flete = false; - $scope.notaPedido.fob = false; - $scope.notaPedido.bomba = false; - - $scope.inicial.flete = false; - $scope.inicial.fob = false; - $scope.inicial.bomba = false; - - $timeout(function() { getLSNotaPedido();} ); + crearNotaPedidoService.getParametros().then(function(res) { + var parametros = JSON.parse(res.data[0].jsonText); + if ($localStorage.notaPedido) { + $timeout(function() { getLSNotaPedido();} ); + } else { + for (property in parametros) { + $scope.notaPedido[property] = parametros[property]; + $scope.inicial[property] = parametros[property]; + } + setearNotaPedido($scope.notaPedido); + } }); init(); @@ -100,9 +81,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', cotizacion: {}, articulosNotaPedido: [], notaPedidoPlazo: [], - notaPedidoPuntoDescarga: { - puntoDescarga: {} - } + notaPedidoPuntoDescarga: [] }; $scope.idLista = undefined; @@ -956,7 +935,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', notaPedido.numeroNotaPedido, 8 ); - if (notaPedido.notaPedidoPuntoDescarga) { + if (notaPedido.notaPedidoPuntoDescarga.length) { var puntos = []; notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) { puntos.push(notaPedidoPuntoDescarga);