Example #1
0
        public async Task <CobGeneralCobranza> InsertGeneralCobranza(CobGeneralCobranza generalCobranza)
        {
            SegUsuario user = await _unitOfWork.SegUsuarioRepository.GetUser(generalCobranza.UsuarioRegistro);

            if (user == null)
            {
                throw new Exception("usuario no existe");
            }

            CobGeneralCobranza existenDocumentosPendientes = await _unitOfWork.GeneralCobranzaRepository.ExisteCobranzaPendienteEnviar(generalCobranza);

            if (existenDocumentosPendientes != null)
            {
                throw new BusinessException("Este cliente ya tiene un RC abierto pendiente por enviar N° " + existenDocumentosPendientes.Documento.ToString() + ".Agregue la cobranza a este RC.Si es necesario grabar otro RC a este cliente, envíe el que está pendiente a la administradora.");
            }
            MtrCliente cliente = await _mtrClienteService.GetByIdAsync(generalCobranza.IdCliente);

            MtrVendedor vendedor = await _mtrVendedorService.GetByIdAsync(cliente.Vendedor1);

            string vIn  = cliente.OficinaVenta;
            short  vOut = Convert.ToInt16(vIn);

            MtrOficina mtrOficina = await _mtrOficinaService.GetOficina(vOut);

            generalCobranza.SearchText   = generalCobranza.IdCliente + "-" + cliente.Nombre + "-" + vendedor.Nombre + "-" + generalCobranza.Documento.ToString() + "-" + mtrOficina.NomOficina.Trim();
            generalCobranza.OficinaVenta = cliente.OficinaVenta;
            await _unitOfWork.GeneralCobranzaRepository.Add(generalCobranza);

            await _unitOfWork.SaveChangesAsync();


            CobGeneralCobranza result = await UpdateGeneralCobranza(generalCobranza);

            return(result);
        }
Example #2
0
        public async Task <CobGeneralCobranza> UpdateGeneralCobranza(CobGeneralCobranza generalCobranza)
        {
            CobGeneralCobranza cobranza = await GetGeneralCobranzaPorDocumento(generalCobranza.Documento);

            if (cobranza == null)
            {
                throw new Exception("Documento No existe");
            }

            MtrCliente cliente = await _mtrClienteService.GetByIdAsync(generalCobranza.IdCliente);

            MtrVendedor vendedor = await _mtrVendedorService.GetByIdAsync(cliente.Vendedor1);

            string vIn  = cliente.OficinaVenta;
            short  vOut = Convert.ToInt16(vIn);

            MtrOficina mtrOficina = await _mtrOficinaService.GetOficina(vOut);

            string statusString = EstatusRecibo(generalCobranza);

            if (vendedor != null)
            {
                cobranza.SearchText = cobranza.IdCliente + "-" + cliente.Nombre.Trim() + "-" + vendedor.Nombre.Trim() + "-" + cobranza.Documento.ToString() + "-" + statusString + "-Ofic " + mtrOficina.NomOficina.Trim();
            }
            else
            {
                cobranza.SearchText = cobranza.IdCliente + "-" + cliente.Nombre.Trim() + "-" + cobranza.Documento.ToString() + "-" + statusString + "-Ofic " + mtrOficina.NomOficina.Trim();
            }

            cobranza.IdCliente         = generalCobranza.IdCliente;
            cobranza.IdMtrTipoMoneda   = generalCobranza.IdMtrTipoMoneda;
            cobranza.MontoTransaccion  = generalCobranza.MontoTransaccion;
            cobranza.IdTipoTransaccion = generalCobranza.IdTipoTransaccion;
            cobranza.IdBanco           = generalCobranza.IdBanco;
            cobranza.FechaTransaccion  = generalCobranza.FechaTransaccion;
            cobranza.NumReferencia     = generalCobranza.NumReferencia;
            cobranza.EmailCliente      = generalCobranza.EmailCliente;
            cobranza.FechaRegistro     = generalCobranza.FechaRegistro;
            cobranza.UsuarioRegistro   = generalCobranza.UsuarioRegistro;
            cobranza.OficinaVenta      = cliente.OficinaVenta;

            cobranza.TotalDetalleCobrado = cobranza.MontoTransaccion - _cobGrabacionCobranzasService.TotalDetalleRecibo(cobranza.Documento);



            await _unitOfWork.GeneralCobranzaRepository.Update(cobranza);

            await _unitOfWork.SaveChangesAsync();

            return(await GetGeneralCobranzaPorDocumento(generalCobranza.Documento));
        }