diff --git a/src/js/controller.js b/src/js/controller.js index 130c78f..7c5e41b 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -105,148 +105,148 @@ angular.module('focaCrearRemito').controller('remitoController', }; $scope.getNotaPedidoModal = function () { - if (varlidarRemitoFacturado()) { - var modalInstance = $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Nota de Pedido', - templateUrl: 'foca-modal-nota-pedido.html', - controller: 'focaModalNotaPedidoController', - size: 'lg', - resolve: { - usadoPor: function () { return 'remito'; }, - idVendedor: function () { return null; } - } + if (!varlidarRemitoFacturado()) return; + if (!varlidarRemitoAbierto()) return; + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Nota de Pedido', + templateUrl: 'foca-modal-nota-pedido.html', + controller: 'focaModalNotaPedidoController', + size: 'lg', + resolve: { + usadoPor: function () { return 'remito'; }, + idVendedor: function () { return null; } } - ); - modalInstance.result.then( - function (notaPedido) { - //añado cabeceras - $scope.remitoIsDirty = true; - $scope.notaPedido = notaPedido; - $scope.remito.cliente = notaPedido.cliente; - $scope.$broadcast('removeCabecera', 'Bomba:'); - $scope.$broadcast('removeCabecera', 'Kilometros:'); - var puntosDescarga = []; - notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedido) { - puntosDescarga.push(notaPedido.puntoDescarga); - }); - $scope.cabeceras = [ - { - label: 'Cliente:', - valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + - ' - ' + 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: 'Flete:', - valor: notaPedido.fob === 1 ? 'FOB' : ( - notaPedido.flete === 1 ? 'Si' : 'No') - }, - { - label: 'Puntos de descarga: ', - valor: $filter('rellenarDigitos')( - getCabeceraPuntoDescarga(puntosDescarga)) - } - ]; - actualizarCabeceraMoneda(notaPedido.cotizacion); - valorPrecioCondicion(); - // Seteo checked en cabeceras - $filter('filter')($scope.botonera, - { label: 'Cliente' })[0].checked = true; - $filter('filter')($scope.botonera, - { label: 'Proveedor' })[0].checked = true; - $filter('filter')($scope.botonera, - { label: 'Moneda' })[0].checked = true; - $filter('filter')($scope.botonera, - { label: 'Nota pedido' })[0].checked = true; - $filter('filter')($scope.botonera, - { label: 'Precios y condiciones' })[0].checked = true; - $filter('filter')($scope.botonera, - { label: 'Domicilio de Entrega' })[0].checked = true; + } + ); + modalInstance.result.then( + function (notaPedido) { + //añado cabeceras + $scope.remitoIsDirty = true; + $scope.notaPedido = notaPedido; + $scope.remito.cliente = notaPedido.cliente; + $scope.$broadcast('removeCabecera', 'Bomba:'); + $scope.$broadcast('removeCabecera', 'Kilometros:'); + var puntosDescarga = []; + notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedido) { + puntosDescarga.push(notaPedido.puntoDescarga); + }); + $scope.cabeceras = [ + { + label: 'Cliente:', + valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + + ' - ' + notaPedido.cliente.NOM + }, + { + label: 'Domicilio:', + valor: notaPedido.domicilioStamp + }, + { + label: 'Vendedor:', + valor: $filter('rellenarDigitos')( + notaPedido.vendedor.NUM, 3 + ) + ' - ' + notaPedido.vendedor.NOM + }, - if (notaPedido.observaciones) { - $filter('filter')($scope.botonera, - { label: 'Observaciones' })[0].checked = true; + { + label: 'Proveedor:', + valor: $filter('rellenarDigitos') + (notaPedido.proveedor.COD, 5) + ' - ' + + notaPedido.proveedor.NOM + }, + + { + label: 'Flete:', + valor: notaPedido.fob === 1 ? 'FOB' : ( + notaPedido.flete === 1 ? 'Si' : 'No') + }, + { + label: 'Puntos de descarga: ', + valor: $filter('rellenarDigitos')( + getCabeceraPuntoDescarga(puntosDescarga)) } + ]; + actualizarCabeceraMoneda(notaPedido.cotizacion); + valorPrecioCondicion(); + // Seteo checked en cabeceras + $filter('filter')($scope.botonera, + { label: 'Cliente' })[0].checked = true; + $filter('filter')($scope.botonera, + { label: 'Proveedor' })[0].checked = true; + $filter('filter')($scope.botonera, + { label: 'Moneda' })[0].checked = true; + $filter('filter')($scope.botonera, + { label: 'Nota pedido' })[0].checked = true; + $filter('filter')($scope.botonera, + { label: 'Precios y condiciones' })[0].checked = true; + $filter('filter')($scope.botonera, + { label: 'Domicilio de Entrega' })[0].checked = true; + + if (notaPedido.observaciones) { + $filter('filter')($scope.botonera, + { label: 'Observaciones' })[0].checked = true; + } - function valorPrecioCondicion() { - if (parseInt(notaPedido.idListaPrecio) > 0) { - crearRemitoService - .getListaPrecioById(parseInt(notaPedido.idListaPrecio)) - .then(function (res) { - $scope.cabeceras.push({ - label: 'Precios y Condiciones:', - valor: - parseInt(res.data[0].ID) + ' - ' + - res.data[0].DES + ' ' + - remitoBusinessService - .plazoToString(notaPedido.notaPedidoPlazo) - }); - addArrayCabecera($scope.cabeceras); + function valorPrecioCondicion() { + if (parseInt(notaPedido.idListaPrecio) > 0) { + crearRemitoService + .getListaPrecioById(parseInt(notaPedido.idListaPrecio)) + .then(function (res) { + $scope.cabeceras.push({ + label: 'Precios y Condiciones:', + valor: + parseInt(res.data[0].ID) + ' - ' + + res.data[0].DES + ' ' + + remitoBusinessService + .plazoToString(notaPedido.notaPedidoPlazo) }); - } + addArrayCabecera($scope.cabeceras); + }); } + } - if (notaPedido.flete === 1) { - var cabeceraBomba = { - label: 'Bomba:', - valor: notaPedido.bomba === 1 ? 'Si' : 'No' + if (notaPedido.flete === 1) { + var cabeceraBomba = { + label: 'Bomba:', + valor: notaPedido.bomba === 1 ? 'Si' : 'No' + }; + if (notaPedido.kilometros) { + var cabeceraKilometros = { + label: 'Kilometros:', + valor: notaPedido.kilometros }; - if (notaPedido.kilometros) { - var cabeceraKilometros = { - label: 'Kilometros:', - valor: notaPedido.kilometros - }; - $scope.cabeceras.push(cabeceraKilometros); - } - $scope.cabeceras.push(cabeceraBomba); + $scope.cabeceras.push(cabeceraKilometros); } + $scope.cabeceras.push(cabeceraBomba); + } - $scope.remito = angular.copy(notaPedido); - $scope.remito.id = 0; - $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; - $scope.remito.remitoPuntoDescarga = notaPedido.notaPedidoPuntoDescarga; + $scope.remito = angular.copy(notaPedido); + $scope.remito.id = 0; + $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; + $scope.remito.remitoPuntoDescarga = notaPedido.notaPedidoPuntoDescarga; - notaPedido.articulosNotaPedido.forEach(function (articulo) { - articulo.id = 0; - articulo.idRemito = 0; - articulo.precio = - (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); - }); + notaPedido.articulosNotaPedido.forEach(function (articulo) { + articulo.id = 0; + articulo.idRemito = 0; + articulo.precio = + (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); + }); - $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; + $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; - if (notaPedido.idPrecioCondicion > 0) { - $scope.idLista = notaPedido.precioCondicion.idListaPrecio; - } else { - $scope.idLista = -1; - } + if (notaPedido.idPrecioCondicion > 0) { + $scope.idLista = notaPedido.precioCondicion.idListaPrecio; + } else { + $scope.idLista = -1; + } - enableObservaciones(notaPedido.observaciones ? true : false); - addArrayCabecera($scope.cabeceras); + enableObservaciones(notaPedido.observaciones ? true : false); + addArrayCabecera($scope.cabeceras); - }, function () { - // funcion ejecutada cuando se cancela el modal - } - ); - } + }, function () { + // funcion ejecutada cuando se cancela el modal + } + ); }; $scope.seleccionarRemito = function () { @@ -285,7 +285,6 @@ angular.module('focaCrearRemito').controller('remitoController', }; //validacion por domicilio y por plazo pago $scope.crearRemito = function () { - varlidarRemitoFacturado(); if (!$scope.remito.vendedor.NUM) { focaModalService.alert('Ingrese Vendedor'); return; @@ -416,6 +415,7 @@ angular.module('focaCrearRemito').controller('remitoController', $scope.seleccionarProductos = function () { if (!varlidarRemitoFacturado()) return; + if (!varlidarRemitoAbierto()) return; if ($scope.notaPedido.id !== 0) { $scope.idLista = parseInt($scope.notaPedido.idListaPrecio); } @@ -523,27 +523,27 @@ angular.module('focaCrearRemito').controller('remitoController', }; $scope.seleccionarCliente = function () { - if (varlidarRemitoFacturado()) { - 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.cliente = cliente; - $scope.abrirModalDomicilios(cliente); - }, function () { - } - ); - } + if (!varlidarRemitoFacturado()) return; + if (!varlidarRemitoAbierto()) return; + 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.cliente = cliente; + $scope.abrirModalDomicilios(cliente); + }, function () { + } + ); }; $scope.seleccionarEliminarRemito = function () { @@ -565,41 +565,42 @@ angular.module('focaCrearRemito').controller('remitoController', }; $scope.seleccionarProveedor = function () { - if (varlidarRemitoFacturado()) { - 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' + if (!varlidarRemitoFacturado()) return; + if (!varlidarRemitoAbierto()) return; + var parametrosModal = { + titulo: 'Búsqueda de Proveedor', + query: '/proveedor', + columnas: [ + { + nombre: 'Código', + propiedad: 'COD', + filtro: { + nombre: 'rellenarDigitos', + parametro: 5 } - ], - tipo: 'POST', - json: { razonCuitCod: '' } - }; - focaModalService.modal(parametrosModal).then( - function (proveedor) { - $scope.seleccionarFlete(proveedor); - }, function () { } - ); - } + }, + { + nombre: 'Nombre', + propiedad: 'NOM' + }, + { + nombre: 'CUIT', + propiedad: 'CUIT' + } + ], + tipo: 'POST', + json: { razonCuitCod: '' } + }; + focaModalService.modal(parametrosModal).then( + function (proveedor) { + $scope.seleccionarFlete(proveedor); + }, function () { } + ); }; $scope.seleccionarDomicilioDeEntrega = function () { if (!varlidarRemitoFacturado()) return; + if (!varlidarRemitoAbierto()) return; if (!$scope.remito.cliente.COD && !$scope.cliente) { focaModalService.alert('Seleccione un Cliente'); return; @@ -715,7 +716,7 @@ angular.module('focaCrearRemito').controller('remitoController', return; } if ($scope.remito.articulosRemito.length !== 0) { - if (varlidarRemitoFacturado()) { + if (varlidarRemitoFacturado() && varlidarRemitoAbierto()) { abrirModal(); } } else { @@ -793,115 +794,115 @@ angular.module('focaCrearRemito').controller('remitoController', }; $scope.seleccionarFlete = function (proveedor) { - if (varlidarRemitoFacturado()) { - var modalInstance = $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Flete', - templateUrl: 'modal-flete.html', - controller: 'focaModalFleteController', - size: 'lg', - resolve: { - parametrosFlete: - function () { - return { - flete: $scope.remito.flete ? '1' : - ($scope.remito.fob ? 'FOB' : - ($scope.remito.flete === undefined ? - null : '0')), - bomba: $scope.remito.bomba ? '1' : - ($scope.remito.bomba === undefined ? - null : '0'), - kilometros: $scope.remito.kilometros - }; - } - } + if (!varlidarRemitoFacturado()) return; + if (!varlidarRemitoAbierto()) return; + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Flete', + templateUrl: 'modal-flete.html', + controller: 'focaModalFleteController', + size: 'lg', + resolve: { + parametrosFlete: + function () { + return { + flete: $scope.remito.flete ? '1' : + ($scope.remito.fob ? 'FOB' : + ($scope.remito.flete === undefined ? + null : '0')), + bomba: $scope.remito.bomba ? '1' : + ($scope.remito.bomba === undefined ? + null : '0'), + kilometros: $scope.remito.kilometros + }; + } } - ); - modalInstance.result.then( - function (datos) { - $scope.remitoIsDirty = true; - $scope.remito.proveedor = proveedor; - $scope.remito.idProveedor = proveedor.COD; - $scope.$broadcast('addCabecera', { - label: 'Proveedor:', - valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + - proveedor.NOM - }); + } + ); + modalInstance.result.then( + function (datos) { + $scope.remitoIsDirty = true; + $scope.remito.proveedor = proveedor; + $scope.remito.idProveedor = proveedor.COD; + $scope.$broadcast('addCabecera', { + label: 'Proveedor:', + valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + + proveedor.NOM + }); - $scope.remito.flete = datos.flete; - $scope.remito.fob = datos.FOB; - $scope.remito.bomba = datos.bomba; - $scope.remito.kilometros = datos.kilometros; + $scope.remito.flete = datos.flete; + $scope.remito.fob = datos.FOB; + $scope.remito.bomba = datos.bomba; + $scope.remito.kilometros = datos.kilometros; + $scope.$broadcast('addCabecera', { + label: 'Flete:', + valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') + }); + if (datos.flete) { $scope.$broadcast('addCabecera', { - label: 'Flete:', - valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') + label: 'Bomba:', + valor: datos.bomba ? 'Si' : 'No' }); - if (datos.flete) { - $scope.$broadcast('addCabecera', { - label: 'Bomba:', - valor: datos.bomba ? 'Si' : 'No' - }); - $scope.$broadcast('addCabecera', { - label: 'Kilometros:', - valor: datos.kilometros - }); - } else { - $scope.$broadcast('removeCabecera', 'Bomba:'); - $scope.$broadcast('removeCabecera', 'Kilometros:'); - $scope.remito.bomba = false; - $scope.remito.kilometros = null; - } - - $filter('filter')($scope.botonera, - { label: 'Proveedor' })[0].checked = true; - }, function () { - $scope.seleccionarTransportista(); + $scope.$broadcast('addCabecera', { + label: 'Kilometros:', + valor: datos.kilometros + }); + } else { + $scope.$broadcast('removeCabecera', 'Bomba:'); + $scope.$broadcast('removeCabecera', 'Kilometros:'); + $scope.remito.bomba = false; + $scope.remito.kilometros = null; } - ); - } + + $filter('filter')($scope.botonera, + { label: 'Proveedor' })[0].checked = true; + }, function () { + $scope.seleccionarTransportista(); + } + ); }; $scope.seleccionarMoneda = function () { - if (varlidarRemitoFacturado()) { - var parametrosModal = { - titulo: 'Búsqueda de monedas', - query: '/moneda', - columnas: [ - { - propiedad: 'DETALLE', - nombre: 'Nombre' - }, - { - propiedad: 'SIMBOLO', - nombre: 'Símbolo' - } - ], - size: 'md' - }; - focaModalService.modal(parametrosModal).then( - function (moneda) { + if (!varlidarRemitoFacturado()) return; + if (!varlidarRemitoAbierto()) return; + var parametrosModal = { + titulo: 'Búsqueda de monedas', + query: '/moneda', + columnas: [ + { + propiedad: 'DETALLE', + nombre: 'Nombre' + }, + { + propiedad: 'SIMBOLO', + nombre: 'Símbolo' + } + ], + size: 'md' + }; + focaModalService.modal(parametrosModal).then( + function (moneda) { - if (moneda.ID !== 1) { - $scope.abrirModalCotizacion(moneda); - return; - } + if (moneda.ID !== 1) { + $scope.abrirModalCotizacion(moneda); + return; + } - crearRemitoService.getCotizacionByIdMoneda(1) - .then(function (res) { + crearRemitoService.getCotizacionByIdMoneda(1) + .then(function (res) { - cotizacionPArgentino = res.data[0].cotizaciones[0]; - cotizacionPArgentino.moneda = moneda; + cotizacionPArgentino = res.data[0].cotizaciones[0]; + cotizacionPArgentino.moneda = moneda; - actualizarCabeceraMoneda(cotizacionPArgentino); + actualizarCabeceraMoneda(cotizacionPArgentino); - $scope.remito.cotizacion = cotizacionPArgentino; - }); - }, function () { + $scope.remito.cotizacion = cotizacionPArgentino; + }); + }, function () { - } - ); - } + } + ); }; $scope.seleccionarObservaciones = function () { @@ -1076,6 +1077,16 @@ angular.module('focaCrearRemito').controller('remitoController', } } + function varlidarRemitoAbierto() { + if (!$scope.remito.hojaRuta) return true; + if ($scope.remito.hojaRuta.abierta !== '1') { + return true; + } else { + focaModalService.alert('No se puede editar un remito abierto'); + return false; + } + } + function salir() { var confirmacion = false; @@ -1105,7 +1116,10 @@ angular.module('focaCrearRemito').controller('remitoController', function setearRemito(remito) { //añado cabeceras - if (remito.estado !== 5 && remito.id) { + console.log(remito); + var esAbierto = remito.hojaRuta ? + (remito.hojaRuta.abierta === '1') : false; + if (remito.estado !== 5 && remito.id && !esAbierto) { $scope.botonera.forEach(function (boton) {