diff --git a/src/js/controller.js b/src/js/controller.js index 1a70f2f..c5f65f4 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -7,17 +7,22 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', notaPedidoBusinessService, $rootScope ) { $scope.botonera = [ - {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, - {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, - {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, - {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, - { - texto: 'Precios y condiciones', - accion: function() {$scope.abrirModalListaPrecio();}}, - {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, + {texto: 'Vendedor', accion: function() { + validarNotaRemitada($scope.seleccionarVendedor);}}, + {texto: 'Cliente', accion: function() { + validarNotaRemitada($scope.seleccionarCliente);}}, + {texto: 'Proveedor', accion: function() { + validarNotaRemitada($scope.seleccionarProveedor);}}, + {texto: 'Moneda', accion: function() { + validarNotaRemitada($scope.abrirModalMoneda);}}, + {texto: 'Precios y condiciones', accion: function() { + validarNotaRemitada($scope.abrirModalListaPrecio);}}, + {texto: 'Flete', accion: function() { + validarNotaRemitada($scope.abrirModalFlete);}}, {texto: '', accion: function() {}}, {texto: '', accion: function() {}} ]; + $scope.datepickerAbierto = false; $scope.show = false; @@ -28,6 +33,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', }; $scope.notaPedido = { + id: 0, vendedor: {}, cliente: {}, proveedor: {}, @@ -120,16 +126,16 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', // }; $scope.crearNotaPedido = function() { - if(!$scope.notaPedido.vendedor.codigo) { + if(!$scope.notaPedido.vendedor.CodVen) { focaModalService.alert('Ingrese Vendedor'); return; - } else if(!$scope.notaPedido.cliente.cod) { + } else if(!$scope.notaPedido.cliente.COD) { focaModalService.alert('Ingrese Cliente'); return; - } else if(!$scope.notaPedido.proveedor.codigo) { + } else if(!$scope.notaPedido.proveedor.COD) { focaModalService.alert('Ingrese Proveedor'); return; - } else if(!$scope.notaPedido.moneda.id) { + } else if(!$scope.notaPedido.moneda.ID) { focaModalService.alert('Ingrese Moneda'); return; } else if(!$scope.notaPedido.cotizacion.ID) { @@ -143,7 +149,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', { focaModalService.alert('Ingrese Flete'); return; - } else if(!$scope.notaPedido.domicilio.id) { + } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto focaModalService.alert('Ingrese Domicilio'); return; } else if($scope.articulosTabla.length === 0) { @@ -152,14 +158,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } var date = new Date(); var notaPedido = { - id: 0, + id: $scope.notaPedido.id, fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) .toISOString().slice(0, 19).replace('T', ' '), - idVendedor: $scope.notaPedido.vendedor.codigo, - idCliente: $scope.notaPedido.cliente.cod, - nombreCliente: $scope.notaPedido.cliente.nom, - cuitCliente: $scope.notaPedido.cliente.cuit, - idProveedor: $scope.notaPedido.proveedor.codigo, + idVendedor: $scope.notaPedido.vendedor.CodVen, + 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, idCotizacion: $scope.notaPedido.cotizacion.ID, idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, @@ -212,7 +218,111 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', } ); }; + + $scope.seleccionarNotaPedido = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Nota de Pedido', + templateUrl: 'foca-modal-nota-pedido.html', + controller: 'focaModalNotaPedidoController', + size: 'lg' + } + ); + modalInstance.result.then( + function(notaPedido) { + //añado cabeceras + $scope.notaPedido.id = notaPedido.id; + removeCabecera('Moneda:'); + removeCabecera('Fecha cotizacion:'); + removeCabecera('Cotizacion:'); + var cabeceras = [ + { + label: 'Moneda', + valor: notaPedido.cotizacion[0].moneda[0].DETALLE + }, + { + label: 'Fecha cotizacion', + valor: $filter('date')(notaPedido.cotizacion[0].FECHA, + 'dd/MM/yyyy') + }, + { + label: 'Cotizacion', + valor: notaPedido.cotizacion[0].VENDEDOR + }, + { + label: 'Cliente:', + valor: notaPedido.cliente[0].NOM + }, + { + label: 'Domicilio:', + valor: notaPedido.domicilioStamp + }, + { + label: 'Vendedor:', + valor: notaPedido.vendedor[0].NomVen + }, + { + label: 'Proveedor:', + valor: notaPedido.proveedor[0].NOM + }, + { + label: 'Flete:', + valor: notaPedido.flete === 1 ? 'Si' : 'No' + }, + { + label: 'FOB:', + valor: notaPedido.fob === 1 ? 'Si' : 'No' + }, + { + label: 'Precio condicion:', + valor: valorPrecioCondicion() + } + ]; + //TODO MOSTRAR PLAZOS + function valorPrecioCondicion() { + if(notaPedido.idPrecioCondicion > 0) { + return notaPedido.precioCondicion[0].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; + if(notaPedido.precioCondicion.length > 0) { + $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; + } else { + $scope.idLista = -1; + } + $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); + $scope.notaPedido = notaPedido; + $scope.notaPedido.vendedor = notaPedido.vendedor[0]; + $scope.notaPedido.cliente = notaPedido.cliente[0]; + $scope.notaPedido.proveedor = notaPedido.proveedor[0]; + $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0]; + $scope.notaPedido.cotizacion = notaPedido.cotizacion[0]; + $scope.plazosPagos = notaPedido.plazoPago; + addArrayCabecera(cabeceras); + + }, function() { + // funcion ejecutada cuando se cancela el modal + } + ); + } + $scope.seleccionarArticulo = function() { if ($scope.idLista === undefined) { focaModalService.alert( @@ -279,7 +389,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', modalInstance.result.then( function(vendedor) { addCabecera('Vendedor:', vendedor.NomVen); - $scope.notaPedido.vendedor.codigo = vendedor.CodVen; + $scope.notaPedido.vendedor = vendedor; }, function() { } @@ -302,7 +412,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', ); modalInstance.result.then( function(proveedor) { - $scope.notaPedido.proveedor.codigo = proveedor.COD; + $scope.notaPedido.proveedor = proveedor; addCabecera('Proveedor:', proveedor.NOM); }, function() { @@ -341,8 +451,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', ); modalInstanceDomicilio.result.then( function(domicilio) { - $scope.notaPedido.domicilio.id = domicilio.id; - $scope.notaPedido.cliente = cliente; + $scope.notaPedido.domicilio = domicilio; + $scope.notaPedido.cliente = { + COD: cliente.cod, + CUIT: cliente.cuit, + NOM: cliente.nom + }; addCabecera('Cliente:', cliente.nom); var domicilioStamp = domicilio.Calle + ' ' + domicilio.Numero + ', ' + @@ -505,11 +619,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', cotizacion.VENDEDOR; } $scope.articulosTabla = articulosTablaTemp; - $scope.notaPedido.moneda = { - id: moneda.ID, - detalle: moneda.DETALLE, - simbolo: moneda.SIMBOLO - }; + $scope.notaPedido.moneda = moneda; $scope.notaPedido.cotizacion = cotizacion; addCabecera('Moneda:', moneda.DETALLE); addCabecera( @@ -612,6 +722,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', articulo.cantidad = parseFloat(articulo.cantidad); articulo.precio = parseFloat(articulo.precio); }; + + function addArrayCabecera(array) { + for(var i = 0; i < array.length; i++) { + addCabecera(array[i].label, array[i].valor); + } + } function addCabecera(label, valor) { var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); @@ -637,6 +753,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', return relleno; } + + function validarNotaRemitada(funcion) { + if($scope.notaPedido.idRemito) { + focaModalService.alert('No se puede editar una nota de pedido remitada'); + } + else { + funcion(); + } + } } ] ) diff --git a/src/views/nota-pedido.html b/src/views/nota-pedido.html index 10c246e..aa31107 100644 --- a/src/views/nota-pedido.html +++ b/src/views/nota-pedido.html @@ -10,6 +10,13 @@