Beispiel #1
0
        public async Task <IActionResult> ValidarCotizacionCliente(OfdCotizacionQueryFilter filters)
        {
            Metadata metadata = new Metadata
            {
                IsValid = false,
                Message = "",
            };


            OfdCotizacion    cotizacion    = new OfdCotizacion();
            OfdCotizacionDto cotizacionDto = new OfdCotizacionDto();

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

            if (cotizacion != null)
            {
                if (cotizacion.IdCliente == filters.IdCliente)
                {
                    metadata.IsValid = true;
                    metadata.Message = "";
                    cotizacionDto    = _mapper.Map <OfdCotizacionDto>(cotizacion);
                }
                else
                {
                    metadata.IsValid = false;
                    metadata.Message = "Cotizacion no pertenece a este cliente!!! " + filters.IdCliente;
                }
            }
            else
            {
                metadata.IsValid = false;
                metadata.Message = "Cotizacion no existe!!!";
            }


            ApiResponse <OfdCotizacionDto> response = new ApiResponse <OfdCotizacionDto>(cotizacionDto)
            {
                Meta = metadata
            };


            return(Ok(response));
        }
Beispiel #2
0
        public async Task Delete(string id)
        {
            OfdCotizacion entity = await GetByCotizacion(id);

            _context.OfdCotizacion.Remove(entity);
        }
Beispiel #3
0
 public void Update(OfdCotizacion entity)
 {
     _context.OfdCotizacion.Update(entity);
 }
Beispiel #4
0
 public async Task Add(OfdCotizacion entity)
 {
     await _context.OfdCotizacion.AddAsync(entity);
 }
Beispiel #5
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));
            }
        }