angular.module('focaCrearRemito') .controller('remitoController', [ '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', function( $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, remitoBusinessService, $rootScope, focaBotoneraLateralService) { config(); function config() { $scope.botonera = crearRemitoService.getBotonera(); $scope.isNumber = angular.isNumber; $scope.datepickerAbierto = false; $scope.show = false; $scope.cargando = true; $scope.now = new Date(); $scope.puntoVenta = rellenar(0, 4); $scope.comprobante = rellenar(0, 8); $scope.dateOptions = { maxDate: new Date(), minDate: new Date(2010, 0, 1) }; var monedaPorDefecto; //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { monedaPorDefecto = res.data[0]; $scope.remito.moneda = monedaPorDefecto; $scope.inicial.remito.moneda = $scope.remito.moneda; $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0]; $scope.inicial.remito.cotizacion = $scope.remito.cotizacion; }); //SETEO BOTONERA LATERAL $timeout(function() { focaBotoneraLateralService.showSalir(false); focaBotoneraLateralService.showPausar(true); focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); focaBotoneraLateralService.addCustomButton('Salir', salir); }); init(); } function init() { $scope.$broadcast('cleanCabecera'); $scope.remito = { id: 0, estado: 0, vendedor: {}, cliente: {}, proveedor: {}, domicilio: {dom: ''}, moneda: {}, cotizacion: {} }; $scope.notaPedido = { id: 0 }; $scope.articulosTabla = []; $scope.idLista = undefined; crearRemitoService.getNumeroRemito().then( function(res) { $scope.puntoVenta = rellenar(res.data.sucursal, 4); $scope.comprobante = rellenar(res.data.numeroRemito, 8); }, function(err) { focaModalService.alert('La terminal no esta configurada correctamente'); console.info(err); } ); $scope.inicial = { remito: angular.copy($scope.remito), notaPedido: angular.copy($scope.notaPedido), articulosTabla: angular.copy($scope.articulosTabla), idLista: angular.copy($scope.idLista) }; } $scope.seleccionarNotaPedido = 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; } } } ); modalInstance.result.then( function(notaPedido) { //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: $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: 'Precio condicion:', valor: valorPrecioCondicion() + ' ' + remitoBusinessService .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); } for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) { notaPedido.articulosNotaPedido[i].id = 0; } $scope.articulosTabla = notaPedido.articulosNotaPedido; remitoBusinessService.calcularArticulos($scope.articulosTabla, notaPedido.cotizacion.VENDEDOR); if(notaPedido.idPrecioCondicion > 0) { $scope.idLista = notaPedido.precioCondicion.idListaPrecio; }else { $scope.idLista = -1; } delete notaPedido.id; $scope.remito = notaPedido; $scope.remito.id = 0; $scope.remito.moneda = notaPedido.cotizacion.moneda; $scope.plazosPagos = notaPedido.notaPedidoPlazo; enableObservaciones(notaPedido.observaciones ? true : false); addArrayCabecera(cabeceras); }, function() { // funcion ejecutada cuando se cancela el modal } ); } }; $scope.seleccionarRemito = function() { var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Remito', templateUrl: 'foca-modal-remito.html', controller: 'focaModalRemitoController', size: 'lg', resolve: {usadoPor: function() {return 'remito';}} } ); modalInstance.result.then( function(remito) { //añado cabeceras $scope.$broadcast('removeCabecera', 'Moneda:'); $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); $scope.$broadcast('removeCabecera', 'Cotizacion:'); var cabeceras = [ { label: 'Moneda:', valor: remito.cotizacion.moneda.DETALLE }, { label: 'Fecha cotizacion:', valor: $filter('date')(remito.cotizacion.FECHA, 'dd/MM/yyyy') }, { label: 'Cotizacion:', valor: $filter('number')(remito.cotizacion.VENDEDOR, '2') }, { label: 'Cliente:', valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + remito.cliente.NOM }, { label: 'Domicilio:', valor: remito.domicilioStamp }, { label: 'Vendedor:', valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + ' - ' + remito.vendedor.NOM }, { label: 'Proveedor:', valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + ' - ' + remito.proveedor.NOM }, { label: 'Flete:', valor: remito.fob === 1 ? 'FOB' : ( remito.flete === 1 ? 'Si' : 'No') }, { label: 'Precio condicion:', valor: valorPrecioCondicion() + ' ' + remitoBusinessService.plazoToString(remito.remitoPlazo) } ]; function valorPrecioCondicion() { if(remito.idPrecioCondicion > 0) { return remito.precioCondicion.nombre; }else { return 'Ingreso Manual'; } } if(remito.flete === 1) { var cabeceraBomba = { label: 'Bomba', valor: remito.bomba === 1 ? 'Si' : 'No' }; if(remito.kilometros) { var cabeceraKilometros = { label: 'Kilometros', valor: remito.kilometros }; cabeceras.push(cabeceraKilometros); } cabeceras.push(cabeceraBomba); } $scope.articulosTabla = remito.articulosRemito; remitoBusinessService.calcularArticulos($scope.articulosTabla, remito.cotizacion.VENDEDOR); if(remito.idPrecioCondicion > 0) { $scope.idLista = remito.precioCondicion.idListaPrecio; }else { $scope.idLista = -1; } $scope.puntoVenta = rellenar(remito.sucursal, 4); $scope.comprobante = rellenar(remito.numeroRemito, 8); $scope.remito = remito; $scope.remito.moneda = remito.cotizacion.moneda; $scope.plazosPagos = remito.remitoPlazo; addArrayCabecera(cabeceras); }, function() { // funcion ejecutada cuando se cancela el modal } ); }; //validacion por domicilio y por plazo pago $scope.crearRemito = function() { if(!$scope.remito.vendedor) { focaModalService.alert('Ingrese Vendedor'); return; }else if(!$scope.remito.cliente) { focaModalService.alert('Ingrese Cliente'); return; }else if(!$scope.remito.proveedor) { focaModalService.alert('Ingrese Proveedor'); return; }else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) { focaModalService.alert('Ingrese Moneda'); return; }else if(!$scope.remito.cotizacion.ID) { focaModalService.alert('Ingrese Cotización'); return; }else if( $scope.remito.flete === undefined || $scope.remito.flete === null) { focaModalService.alert('Ingrese Flete'); return; }else if($scope.articulosTabla.length === 0) { focaModalService.alert('Debe cargar al menos un articulo'); return; } focaBotoneraLateralService.startGuardar(); $scope.saveLoading = true; var save = { remito: { id: $scope.remito.id, fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), idCliente: $scope.remito.cliente.COD, nombreCliente: $scope.remito.cliente.NOM, cuitCliente: $scope.remito.cliente.CUIT, responsabilidadIvaCliente: 0,//TODO, descuento: 0,//TODO, importeNeto: 0,//TODO importeExento: 0,//TODO importeIva: 0,//TODO importeIvaServicios: 0,//TODO importeImpuestoInterno: 0,//TODO importeImpuestoInterno1: 0,//TODO importeImpuestoInterno2: 0,//TODO percepcion: 0,//TODO percepcionIva: 0,//TODO redondeo: 0,//TODO total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, numeroNotaPedido: $scope.remito.numeroNotaPedido, anulado: false, planilla: 0,//TODO lugar: 0,//TODO cuentaMadre: 0,// cuentaContable: 0,//TODO asiento: 0,//TODO e_hd: '',//TODO c_hd: '', numeroLiquidoProducto: 0,//TODO idVendedor: $scope.remito.idVendedor, idProveedor: $scope.remito.idProveedor, idDomicilio: $scope.remito.idDomicilio, idCotizacion: $scope.remito.cotizacion.ID, idPrecioCondicion: $scope.remito.idPrecioCondicion, flete: $scope.remito.flete, fob: $scope.remito.fob, bomba: $scope.remito.bomba, kilometros: $scope.remito.kilometros, domicilioStamp: $scope.remito.domicilioStamp, estado: 0,//TODO destinoVenta: 0,//TODO operacionTipo: 0//TODO }, notaPedido: $scope.notaPedido }; crearRemitoService.crearRemito(save).then( function(data) { remitoBusinessService.addArticulos($scope.articulosTabla, data.data.id, $scope.remito.cotizacion.VENDEDOR); focaBotoneraLateralService.endGuardar(true); $scope.saveLoading = false; //TODO: updatear plazos if($scope.remito.id === 0) { $scope.remito.id = data.data.id; var plazos = $scope.plazosPagos; for(var j = 0; j < plazos.length; j++) { var json = { idRemito: $scope.remito.id, dias: plazos[j].dias }; crearRemitoService.crearPlazosParaRemito(json); } } $uibModal.open({ templateUrl: 'remito-comprobante.html', controller: 'focaRemitoComprobanteController', resolve: { parametros: { idRemito: data.data.id } } }); init(); }, function(error) { focaModalService.alert('Hubo un error al crear el remito'); focaBotoneraLateralService.endGuardar(); $scope.saveLoading = false; console.info(error); } ); }; $scope.seleccionarProductos = function() { if($scope.idLista === undefined) { focaModalService.alert( 'Primero seleccione una lista de precio y condicion'); return; } var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Productos', templateUrl: 'modal-busqueda-productos.html', controller: 'modalBusquedaProductosCtrl', resolve: { parametroProducto: { idLista: $scope.idLista, cotizacion: $scope.remito.cotizacion.COTIZACION, simbolo: $scope.remito.moneda.simbolo } }, size: 'lg' } ); modalInstance.result.then( function(producto) { var newArt = { id: 0, codigo: producto.codigo, sector: producto.sector, sectorCodigo: producto.sector + '-' + producto.codigo, descripcion: producto.descripcion, item: $scope.articulosTabla.length + 1, nombre: producto.descripcion, precio: parseFloat(producto.precio.toFixed(4)), costoUnitario: producto.costo, editCantidad: false, editPrecio: false, rubro: producto.CodRub, exentoUnitario: producto.precio, ivaUnitario: producto.IMPIVA, impuestoInternoUnitario: producto.ImpInt, impuestoInterno1Unitario: producto.ImpInt2, impuestoInterno2Unitario: producto.ImpInt3, precioLista: producto.precio, combustible: 1, facturado: 0 }; $scope.articuloACargar = newArt; $scope.cargando = false; }, function() { // funcion ejecutada cuando se cancela el modal } ); }; $scope.seleccionarPuntosDeDescarga = function() { if(!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { focaModalService.alert('Primero seleccione un cliente y un domicilio'); return; }else { var modalInstance = $uibModal.open( { ariaLabelledBy: 'Búsqueda de Puntos de descarga', templateUrl: 'modal-punto-descarga.html', controller: 'focaModalPuntoDescargaController', size: 'lg', resolve: { filters: { idDomicilio: $scope.remito.domicilio.id, idCliente: $scope.remito.cliente.COD, articulos: $scope.articulosTabla, puntosDescarga: $scope.remito.domicilio.puntosDescarga } } } ); modalInstance.result.then( function(puntosDescarga) { $scope.remito.puntosDescarga = puntosDescarga; //AGREGO PUNTOS DE DESCARGA A CABECERA var puntosStamp = ''; puntosDescarga.forEach(function(punto, idx, arr) { puntosStamp += punto.descripcion; if((idx + 1) !== arr.length) puntosStamp += ', '; }); $scope.$broadcast('addCabecera', { label: 'Puntos de descarga:', valor: puntosStamp }); }, function() { $scope.abrirModalDomicilios($scope.cliente); } ); } }; $scope.seleccionarVendedor = function() { if(varlidarRemitoFacturado()) { var parametrosModal = { titulo: 'Búsqueda vendedores', query: '/vendedor', columnas: [ { propiedad: 'NUM', nombre: 'Código', filtro: { nombre: 'rellenarDigitos', parametro: 3 } }, { propiedad: 'NOM', nombre: 'Nombre' } ], size: 'md' }; focaModalService.modal(parametrosModal).then( function(vendedor) { $scope.$broadcast('addCabecera',{ label: 'Vendedor:', valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + vendedor.NOM }); $scope.remito.idVendedor = vendedor.id; $scope.vendedor = vendedor; }, function() { } ); } }; $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' } ], tipo: 'POST', json: {razonCuitCod: ''} }; focaModalService.modal(parametrosModal).then( function(proveedor) { $scope.remito.idProveedor = proveedor.COD; $scope.$broadcast('addCabecera',{ label: 'Proveedor:', valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + proveedor.NOM }); }, function() { } ); } }; $scope.seleccionarCliente = function() { if(!$scope.vendedor) { focaModalService.alert('Primero seleccione un vendedor'); return; } if(varlidarRemitoFacturado()) { var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Cliente', templateUrl: 'foca-busqueda-cliente-modal.html', controller: 'focaBusquedaClienteModalController', resolve: { vendedor: function() { return $scope.vendedor; } }, size: 'lg' } ); modalInstance.result.then( function(cliente) { $scope.abrirModalDomicilios(cliente); $scope.cliente = cliente; }, function() { } ); } }; $scope.abrirModalDomicilios = function(cliente) { var modalInstanceDomicilio = $uibModal.open( { ariaLabelledBy: 'Busqueda de Domicilios', templateUrl: 'modal-domicilio.html', controller: 'focaModalDomicilioController', size: 'lg', resolve: { idCliente: function() { return cliente.cod; }, esNuevo: function() { return cliente.esNuevo; } } } ); modalInstanceDomicilio.result.then( function(domicilio) { $scope.remito.domicilio = domicilio; $scope.remito.cliente = { COD: cliente.cod, CUIT: cliente.cuit, NOM: cliente.nom, MAIL: cliente.mail }; var domicilioStamp = domicilio.Calle + ' ' + domicilio.Numero + ', ' + domicilio.Localidad + ', ' + domicilio.Provincia; $scope.remito.domicilioStamp = domicilioStamp; $scope.$broadcast('addCabecera',{ label: 'Cliente:', valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom }); $scope.$broadcast('addCabecera',{ label: 'Domicilio:', valor: domicilioStamp }); if(domicilio.verPuntos) { delete $scope.remito.domicilio.verPuntos; $scope.seleccionarPuntosDeDescarga(); }else { crearRemitoService .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) .then(function(res) { if(res.data.length) $scope.seleccionarPuntosDeDescarga(); }); } }, function() { $scope.seleccionarCliente(); return; } ); }; $scope.mostrarFichaCliente = function() { $uibModal.open( { ariaLabelledBy: 'Datos del Cliente', templateUrl: 'foca-crear-remito-ficha-cliente.html', controller: 'focaCrearRemitoFichaClienteController', size: 'lg' } ); }; $scope.getTotal = function() { var total = 0; var arrayTempArticulos = $scope.articulosTabla; for(var i = 0; i < arrayTempArticulos.length; i++) { total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; } return parseFloat(total.toFixed(2)); }; $scope.getSubTotal = function() { if($scope.articuloACargar) { return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; } }; $scope.seleccionarPreciosYCondiciones = function() { if(varlidarRemitoFacturado()) { var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Precio Condición', templateUrl: 'modal-precio-condicion.html', controller: 'focaModalPrecioCondicionController', size: 'lg' } ); modalInstance.result.then( function(precioCondicion) { var cabecera = ''; var plazosConcat = ''; if(!Array.isArray(precioCondicion)) { $scope.remito.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 + ' '; } cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); }else { //Cuando se ingresan los plazos manualmente $scope.remito.idPrecioCondicion = 0; //-1, el modal productos busca todos los productos $scope.idLista = -1; $scope.plazosPagos = precioCondicion; for(var j = 0; j < precioCondicion.length; j++) { plazosConcat += precioCondicion[j].dias + ' '; } cabecera = 'Ingreso manual ' + plazosConcat.trim(); } $scope.articulosTabla = []; $scope.$broadcast('addCabecera',{ label: 'Precios y condiciones:', valor: cabecera }); }, function() { } ); } }; $scope.seleccionarFlete = function() { 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 }; } } } ); modalInstance.result.then( function(datos) { $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: '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.fob = false; $scope.remito.bomba = false; $scope.remito.kilometros = null; } }, function() { } ); } }; $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) { $scope.abrirModalCotizacion(moneda); }, function() { } ); } }; $scope.seleccionarObservaciones = function() { focaModalService .prompt('Ingrese observaciones', $scope.remito.observaciones, true, true) .then(function(observaciones) { $scope.remito.observaciones = observaciones; }); }; $scope.abrirModalCotizacion = function(moneda) { var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Cotización', templateUrl: 'modal-cotizacion.html', controller: 'focaModalCotizacionController', size: 'lg', resolve: {idMoneda: function() {return moneda.ID;}} } ); modalInstance.result.then( function(cotizacion) { var articulosTablaTemp = $scope.articulosTabla; for(var i = 0; i < articulosTablaTemp.length; i++) { articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * $scope.remito.cotizacion.COTIZACION; articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / cotizacion.COTIZACION; } $scope.articulosTabla = articulosTablaTemp; $scope.remito.moneda = moneda; $scope.remito.cotizacion = cotizacion; if(moneda.DETALLE === 'PESOS ARGENTINOS') { $scope.$broadcast('removeCabecera', 'Moneda:'); $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); $scope.$broadcast('removeCabecera', 'Cotizacion:'); }else { $scope.$broadcast('addCabecera',{ label: 'Moneda:', valor: moneda.DETALLE }); $scope.$broadcast('addCabecera',{ label: 'Fecha cotizacion:', valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') }); $scope.$broadcast('addCabecera',{ label: 'Cotizacion:', valor: $filter('number')(cotizacion.COTIZACION, '2') }); } }, function() { } ); }; $scope.agregarATabla = function(key) { if(key === 13) { if($scope.articuloACargar.cantidad === undefined || $scope.articuloACargar.cantidad === 0 || $scope.articuloACargar.cantidad === null ) { focaModalService.alert('El valor debe ser al menos 1'); return; } delete $scope.articuloACargar.sectorCodigo; $scope.articulosTabla.push($scope.articuloACargar); $scope.cargando = true; } }; $scope.quitarArticulo = function(key) { $scope.articulosTabla.splice(key, 1); }; $scope.editarArticulo = function(key, articulo) { if(key === 13) { if(articulo.cantidad === null || articulo.cantidad === 0 || articulo.cantidad === undefined) { focaModalService.alert('El valor debe ser al menos 1'); return; } articulo.editCantidad = false; articulo.editPrecio = false; } }; $scope.cambioEdit = function(articulo, propiedad) { if(propiedad === 'cantidad') { articulo.editCantidad = true; }else if(propiedad === 'precio') { articulo.editPrecio = true; } }; $scope.limpiarFlete = function() { $scope.remito.fleteNombre = ''; $scope.remito.chofer = ''; $scope.remito.vehiculo = ''; $scope.remito.kilometros = ''; $scope.remito.costoUnitarioKmFlete = ''; $scope.choferes = ''; $scope.vehiculos = ''; }; $scope.limpiarPantalla = function() { $scope.limpiarFlete(); $scope.remito.flete = '0'; $scope.remito.bomba = '0'; $scope.remito.precioCondicion = ''; $scope.articulosTabla = []; $scope.remito.vendedor.nombre = ''; $scope.remito.cliente = {nombre: ''}; $scope.remito.domicilio = {dom: ''}; $scope.domiciliosCliente = []; }; $scope.resetFilter = function() { $scope.articuloACargar = {}; $scope.cargando = true; }; //Recibe aviso si el teclado está en uso $rootScope.$on('usarTeclado', function(event, data) { if(data) { $scope.mostrarTeclado = true; return; } $scope.mostrarTeclado = false; }); $scope.selectFocus = function($event) { // Si el teclado esta en uso no selecciona el valor if($scope.mostrarTeclado) { return; } $event.target.select(); }; function addArrayCabecera(array) { for(var i = 0; i < array.length; i++) { $scope.$broadcast('addCabecera',{ label: array[i].label, valor: array[i].valor }); } } function rellenar(relleno, longitud) { relleno = '' + relleno; while (relleno.length < longitud) { relleno = '0' + relleno; } return relleno; } function varlidarRemitoFacturado() { if($scope.remito.estado !== 5) { return true; }else { focaModalService.alert('No se puede editar un remito facturado'); return false(); } } function salir() { var confirmacion = false; angular.forEach($scope.inicial, function(valor, key) { if (!angular.equals($scope[key], $scope.inicial[key])) { confirmacion = true; } }); if (confirmacion) { focaModalService.confirm( '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' ).then(function(data) { if (data) { $location.path('/'); } }); } else { $location.path('/'); } } function enableObservaciones(val) { var boton = $scope.botonera.filter(function(botonObs) { return botonObs.label === 'Observaciones'; }); boton[0].disable = !val; } } ]);