コード例 #1
0
        public async Task <ReciboDto> GeneraReciboDto(long recibo)
        {
            ReciboDto                    result                     = new ReciboDto();
            CobGeneralCobranza           cobGeneralCobranza         = new CobGeneralCobranza();
            List <CobGrabacionCobranzas> listaCobGrabacionCobranzas = new List <CobGrabacionCobranzas>();

            try
            {
                //Crea Objeto General cobranzas
                cobGeneralCobranza = await GetGeneralCobranzaPorDocumento(recibo);

                CobGeneralCobranzaDto generalCobranzasDtos = _mapper.Map <CobGeneralCobranzaDto>(cobGeneralCobranza);

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

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

                generalCobranzasDtos.NombreCliente          = cliente.NoRegTribut + " " + cliente.Nombre.Trim();
                generalCobranzasDtos.IdCliente              = generalCobranzasDtos.IdCliente.Trim();
                generalCobranzasDtos.FechaTransaccionString = generalCobranzasDtos.FechaTransaccion.ToShortDateString();
                generalCobranzasDtos.NombreVendedor         = vendedor.Nombre;
                generalCobranzasDtos.vendedor         = vendedor.Codigo;
                generalCobranzasDtos.CorreoVendedor   = vendedor.EMail;
                generalCobranzasDtos.TelefonoVendedor = vendedor.TlfCelular;



                decimal decimalValue = generalCobranzasDtos.MontoTransaccion;
                generalCobranzasDtos.MontoTransaccionString = string.Format("{0:N}", decimalValue); // 1,234,567.00


                //creamos el objeto
                Moneda oMoneda = new Moneda();

                //primer parametro es la cantidad en string
                //segundo parametro es si queremos que sea mayuscula
                //tercer parametro la moneda


                MtrTipoMoneda tipoMoneda = await _mtrTipoMonedaService.GetById((long)cobGeneralCobranza.IdMtrTipoMoneda);

                string MonedaString = tipoMoneda.Descripcion;



                string resultado = oMoneda.Convertir(generalCobranzasDtos.MontoTransaccion.ToString(), true, MonedaString);
                generalCobranzasDtos.MontoLetras = resultado;


                decimal?detalleValue = generalCobranzasDtos.TotalDetalleCobrado;
                generalCobranzasDtos.TotalDetalleCobradoString = string.Format("{0:N}", detalleValue);
                generalCobranzasDtos.Status = EstatusRecibo(cobGeneralCobranza);

                MtrBancos banco = await _mtrBancosService.GetByCodigo(generalCobranzasDtos.IdBanco);

                generalCobranzasDtos.NombreBanco = banco.Nombre;

                CobTipoTransaccion tipoTransaccion = await _cobTipoTransaccionService.GetById(generalCobranzasDtos.IdTipoTransaccion);

                generalCobranzasDtos.NombreTipoTransaccion = tipoTransaccion.NombreTipoTransaccion;
                generalCobranzasDtos.FlagImpuesto          = tipoTransaccion.FlagImpuesto;


                MtrTipoMoneda mtrTipoMoneda = await _mtrTipoMonedaService.GetById((long)generalCobranzasDtos.IdMtrTipoMoneda);

                generalCobranzasDtos.NombreTipoMoneda = mtrTipoMoneda.Descripcion;



                listaCobGrabacionCobranzas = _unitOfWork.CobGrabacionCobranzasRepository.GetByDocumento(recibo);
                listaCobGrabacionCobranzas = listaCobGrabacionCobranzas.Where(x => x.DocumentoSap == "").ToList();

                List <CobGrabacionCobranzaDto> listaCobGrabacionCobranzasDto = _mapper.Map <List <CobGrabacionCobranzaDto> >(listaCobGrabacionCobranzas);

                foreach (CobGrabacionCobranzaDto item in listaCobGrabacionCobranzasDto)
                {
                    item.CuentaBancaria = banco.CodContable;
                    item.Moneda         = mtrTipoMoneda.Descripcion;
                    if (item.Transaccion == "RU")
                    {
                        item.DocAfectaMostrar = item.Cotizacion;
                    }
                    else
                    {
                        item.DocAfectaMostrar = item.DocAfectaSap;
                    }

                    decimalValue      = (decimal)item.Monto;
                    item.MontoMostrar = string.Format("{0:N}", decimalValue); // 1,234,567.00

                    CobEstadoDeCuenta cobEstadoDeCuenta = await _cobEstadoCuentaService.GetEstadoCuentaById(item.DocAfecta);

                    if (cobEstadoDeCuenta != null)
                    {
                        decimalValue              = (decimal)cobEstadoDeCuenta.BaseImponible;
                        item.BaseImponible        = (decimal)cobEstadoDeCuenta.BaseImponible;
                        item.BaseImponibleMostrar = string.Format("{0:N}", decimalValue); // 1,234,567.00
                        decimalValue              = (decimal)cobEstadoDeCuenta.Iva;
                        item.Iva        = (decimal)cobEstadoDeCuenta.Iva;
                        item.IvaMostrar = string.Format("{0:N}", decimalValue); // 1,234,567.00
                        decimalValue    = (decimal)cobEstadoDeCuenta.MontoOriginal;

                        item.MontoOriginalMostrar = string.Format("{0:N}", decimalValue); // 1,234,567.00
                        item.FechaDocumento       = cobEstadoDeCuenta.FechaDocumento;
                        DateTime fechaDocumento = (DateTime)cobEstadoDeCuenta.FechaDocumento;
                        item.FechaDocumentoString = fechaDocumento.ToShortDateString();
                    }

                    //List<CobPagosRetencionesDto> listCobPagosRetencionesDto = new List<CobPagosRetencionesDto>();
                    List <CobPagosRetenciones> listCobPagosRetenciones = _unitOfWork.CobPagosRetencionesRepository.GetByIdCobranzas(item.Id);

                    List <CobPagosRetencionesDto> listCobPagosRetencionesDto = _mapper.Map <List <CobPagosRetencionesDto> >(listCobPagosRetenciones);

                    if (listCobPagosRetencionesDto != null && listCobPagosRetencionesDto.Count > 0)
                    {
                        foreach (CobPagosRetencionesDto itemRet in listCobPagosRetencionesDto)
                        {
                            decimalValue        = itemRet.Monto;
                            itemRet.MontoString = string.Format("{0:N}", decimalValue); // 1,234,567.00

                            CobTransacciones transaccion = await _cobTransaccionesService.GetById(itemRet.IdTransaccion);

                            if (transaccion != null)
                            {
                                itemRet.NombreTransaccion = transaccion.NombreTransaccion;
                                itemRet.TxOrigen          = transaccion.TipoSap;
                            }
                            itemRet.FechaComprobanteString = itemRet.FechaComprobante.ToShortDateString();
                        }
                    }


                    item.CobPagosRetencionesDto = listCobPagosRetencionesDto;
                }



                result.CobGeneralCobranzaDto   = generalCobranzasDtos;
                result.CobGrabacionCobranzaDto = listaCobGrabacionCobranzasDto;

                return(result);
            }
            catch (Exception e)
            {
                string message = e.Message;
                throw;
            }
        }
コード例 #2
0
        public async Task <IActionResult> Insert(CobGrabacionCobranzaDto cobGrabacionCobranzaDto)
        {
            CobGrabacionCobranzaDto resultDto = new CobGrabacionCobranzaDto();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };
            ApiResponse <CobGrabacionCobranzaDto> response = new ApiResponse <CobGrabacionCobranzaDto>(resultDto);

            try
            {
                CobGeneralCobranza generalCobranza = await _generalCobranzaService.GetGeneralCobranzaPorDocumento((long)cobGrabacionCobranzaDto.Documento);

                if (cobGrabacionCobranzaDto.Transaccion == "RU" && generalCobranza.FlagPagoMas != true)
                {
                    OfdCotizacion cotizacion = new OfdCotizacion();


                    cotizacion = await _ofdCotizacionService.GetCotizacion(cobGrabacionCobranzaDto.Cotizacion);

                    if (cotizacion != null)
                    {
                        if (cotizacion.IdCliente == generalCobranza.IdCliente)
                        {
                            metadata.IsValid = true;
                            metadata.Message = "";
                        }
                        else
                        {
                            metadata.IsValid = false;
                            metadata.Message = "Cotizacion no pertenece a este cliente!!! " + generalCobranza.IdCliente;
                            response.Meta    = metadata;
                            response.Data    = resultDto;
                            return(Ok(response));
                        }
                    }
                    else
                    {
                        metadata.IsValid = false;
                        metadata.Message = "Cotizacion no existe!!!";
                        response.Meta    = metadata;
                        response.Data    = resultDto;

                        return(Ok(response));
                    }
                }



                CobGrabacionCobranzas cobGrabacionCobranza = _mapper.Map <CobGrabacionCobranzas>(cobGrabacionCobranzaDto);


                MtrTipoMoneda tipomoneda = await _mtrTipoMonedaService.GetById((long)generalCobranza.IdMtrTipoMoneda);

                bool dividirPagoImpuesto       = false;
                CobEstadoDeCuenta estadoCuenta = await _cobEstadoCuentaService.GetEstadoCuentaById(cobGrabacionCobranzaDto.DocAfecta);

                if (estadoCuenta != null)
                {
                    if (cobGrabacionCobranzaDto.Transaccion != "RU")
                    {
                        if (generalCobranza.IdTipoTransaccion != "RET")
                        {
                            bool existeMonedaDocumentoMonedaPago = await _cobMatrixMonedaValidaPagoService.ExisteMonedaDocumentoMonedaPago(estadoCuenta.Moneda, tipomoneda.Descripcion);

                            if (!existeMonedaDocumentoMonedaPago)
                            {
                                metadata.IsValid = false;

                                metadata.Message = "Esta intentando grabar cobro en moneda no valida a el Recibo";

                                response.Meta = metadata;
                                return(Ok(response));
                            }

                            decimal totalAfectadoDocumento = _cobGrabacionCobranzasService.TotalAfectadoDocumento((long)cobGrabacionCobranzaDto.Documento, cobGrabacionCobranzaDto.DocAfecta);
                            if (totalAfectadoDocumento + (decimal)cobGrabacionCobranzaDto.Monto > (decimal)estadoCuenta.Rpaap)
                            {
                                metadata.IsValid = false;

                                metadata.Message = "Esta intentando grabar monto superior al saldo del documento:" + "Total registrado en recibo: " + totalAfectadoDocumento.ToString() + "Saldo documento: " + estadoCuenta.Rpaap.ToString();
                                return(Ok(response));
                            }
                        }
                    }


                    if (cobGrabacionCobranzaDto.Monto > estadoCuenta.BaseImponible && cobGrabacionCobranzaDto.Transaccion != "RE" && tipomoneda.Descripcion == estadoCuenta.Moneda)
                    {
                        dividirPagoImpuesto = true;
                    }
                }

                if (!dividirPagoImpuesto)
                {
                    cobGrabacionCobranza.PagoCorrespondeIva = false;
                    CobGrabacionCobranzas cobranza = await _cobGrabacionCobranzasService.Insert(cobGrabacionCobranza);

                    if (cobranza != null)
                    {
                        resultDto        = _mapper.Map <CobGrabacionCobranzaDto>(cobranza);
                        metadata.IsValid = true;
                        metadata.Message = "Creado Satisfactoriamente";
                    }
                    else
                    {
                        metadata.IsValid = false;

                        metadata.Message = "Registro No actualizado";
                    }
                }
                else
                {
                    CobGrabacionCobranzas cobGrabacionCobranzaImpuesto = _mapper.Map <CobGrabacionCobranzas>(cobGrabacionCobranzaDto);


                    decimal?montoGrabado = cobGrabacionCobranza.Monto;
                    cobGrabacionCobranza.Monto = estadoCuenta.BaseImponible;


                    cobGrabacionCobranza.PagoCorrespondeIva = false;
                    CobGrabacionCobranzas cobranza = await _cobGrabacionCobranzasService.Insert(cobGrabacionCobranza);


                    cobGrabacionCobranzaImpuesto.Monto = montoGrabado - estadoCuenta.BaseImponible;
                    cobGrabacionCobranzaImpuesto.PagoCorrespondeIva = true;
                    CobGrabacionCobranzas cobranzaImpuesto = await _cobGrabacionCobranzasService.Insert(cobGrabacionCobranzaImpuesto);

                    if (cobranza != null)
                    {
                        resultDto        = _mapper.Map <CobGrabacionCobranzaDto>(cobranza);
                        metadata.IsValid = true;
                        metadata.Message = "Creado Satisfactoriamente";
                    }
                    else
                    {
                        metadata.IsValid = false;

                        metadata.Message = "Registro No actualizado";
                    }
                }

                //ApiResponse<CobGrabacionCobranzaDto> response = new ApiResponse<CobGrabacionCobranzaDto>(resultDto)
                //{
                //    Meta = metadata,
                //};
                response.Meta = metadata;
                response.Data = resultDto;

                return(Ok(response));
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;

                metadata.Message = ex.InnerException.Message;

                response.Meta = metadata;
                response.Data = resultDto;
                //ApiResponse<CobGrabacionCobranzaDto> response = new ApiResponse<CobGrabacionCobranzaDto>(resultDto)
                //{
                //    Meta = metadata,
                //};
                return(Ok(response));
            }
        }
コード例 #3
0
        public async Task <ApiResponse <List <AppIngredientsGetDto> > > GetAllFilter(AppIngredientsQueryFilter filter)
        {
            filter.PageNumber = filter.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filter.PageNumber;
            filter.PageSize   = filter.PageSize == 0 ? _paginationOptions.DefaultPageSize : filter.PageSize;

            List <AppIngredientsGetDto> resultDto = new List <AppIngredientsGetDto>();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };
            ApiResponse <List <AppIngredientsGetDto> > response = new ApiResponse <List <AppIngredientsGetDto> >(resultDto);

            try
            {
                List <AppIngredients> appIngredients = await _unitOfWork.AppIngredientsRepository.GetAllFilter(filter);


                if (appIngredients != null)
                {
                    List <AppIngredientsGetDto> appIngredientsDto = _mapper.Map <List <AppIngredientsGetDto> >(appIngredients);
                    foreach (AppIngredientsGetDto item in appIngredientsDto)
                    {
                        AppUnits AppUnitsFind = await _appUnitsService.GetById(item.AppUnitId);

                        if (AppUnitsFind != null)
                        {
                            AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                            item.AppUnitsGetDto = appUnitsGetDto;
                        }
                        MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.PrymaryMtrMonedaId);

                        if (MtrTipoMonedaFind != null)
                        {
                            MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                            item.PrymaryMtrMonedaDto = mtrTipoMonedaDto;
                        }

                        MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.SecundaryMtrMonedaId);

                        if (MtrTipoMonedaFind != null)
                        {
                            MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                            item.SecundaryMtrMonedaDto = mtrTipoMonedaDto;
                        }
                    }



                    response.Data = appIngredientsDto;
                    response.Meta = metadata;
                    return(response);
                }
                else
                {
                    metadata.IsValid = true;
                    metadata.Message = "No Data....";
                    response.Data    = null;
                    response.Meta    = metadata;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;
                metadata.Message = ex.InnerException.Message;
                response.Data    = null;
                response.Meta    = metadata;
                return(response);
            }
        }
コード例 #4
0
        public async Task <ApiResponse <List <AppProductsGetDto> > > GetAll(AppProdutsQueryFilter filters)
        {
            filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber;
            filters.PageSize   = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize;

            List <AppProductsGetDto> resultDto = new List <AppProductsGetDto>();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };
            ApiResponse <List <AppProductsGetDto> > response = new ApiResponse <List <AppProductsGetDto> >(resultDto);

            try
            {
                var appProducts = await _unitOfWork.AppProductsRepository.GetAllFilter(filters);

                if (appProducts != null)
                {
                    List <AppProductsGetDto> appProductsDto = _mapper.Map <List <AppProductsGetDto> >(appProducts);
                    foreach (var item in appProductsDto)
                    {
                        if (item.UrlImage == "" || item.UrlImage == null)
                        {
                            item.Link = _paginationOptions.UrlGetFiles + "NoImage.png";
                        }
                        else
                        {
                            item.Link = _paginationOptions.UrlGetFiles + item.UrlImage;
                        }

                        AppUnits AppUnitsFind = await _appUnitsService.GetById((int)item.AppUnitsId);

                        if (AppUnitsFind != null)
                        {
                            AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                            item.AppUnitsGetDto = appUnitsGetDto;
                        }

                        AppUnitsFind = await _appUnitsService.GetById((int)item.ProductionUnitId);

                        if (AppUnitsFind != null)
                        {
                            AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                            item.ProductionUnitGetDto = appUnitsGetDto;
                        }


                        MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.PrymaryMtrMonedaId);

                        if (MtrTipoMonedaFind != null)
                        {
                            MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                            item.PrymaryMtrMonedaGetDto = mtrTipoMonedaDto;
                        }

                        MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.SecundaryMtrMonedaId);

                        if (MtrTipoMonedaFind != null)
                        {
                            MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                            item.SecundaryMtrMonedaGetDto = mtrTipoMonedaDto;
                        }

                        AppSubCategory AppSubCategoryFind = await _appSubCategoryService.GetById((int)item.AppSubCategoryId);

                        if (AppSubCategoryFind != null)
                        {
                            AppSubCategoryGetDto appSubCategoryGetDto = _mapper.Map <AppSubCategoryGetDto>(AppSubCategoryFind);
                            item.AppSubCategoryGetDto = appSubCategoryGetDto;
                        }
                    }



                    response.Data = appProductsDto;
                    response.Meta = metadata;
                    return(response);
                }
                else
                {
                    metadata.IsValid = true;
                    metadata.Message = "No Data....";
                    response.Data    = null;
                    response.Meta    = metadata;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;
                metadata.Message = ex.InnerException.Message;
                response.Data    = null;
                response.Meta    = metadata;
                return(response);
            }
        }