Exemplo n.º 1
0
        private static List <TotalImpuestosType> GetImpuestosGlobal(ventaDto objVenta)
        {
            var result = new List <TotalImpuestosType>();

            if (IsValueNotNullorZero(objVenta.d_IGV))
            {
                result.Add(new TotalImpuestosType
                {
                    TipoTributo = TipoTributo.IGV_VAT,
                    Monto       = objVenta.d_IGV ?? 0M
                });
            }
            if (IsValueNotNullorZero(objVenta.d_total_isc))
            {
                result.Add(new TotalImpuestosType
                {
                    TipoTributo = TipoTributo.ISC_EXC,
                    Monto       = objVenta.d_total_isc ?? 0M
                });
            }
            if (IsValueNotNullorZero(objVenta.d_total_otrostributos))
            {
                result.Add(new TotalImpuestosType
                {
                    TipoTributo = TipoTributo.OTROS_OTH,
                    Monto       = objVenta.d_total_otrostributos ?? 0M
                });
            }
            return(result);
        }
Exemplo n.º 2
0
        private Dictionary <OtrosConceptosTributarios, decimal> LoadDetail(List <InvoiceDetail> details, ventaDto obj, decimal igv)
        {
            var helper = new HelperScripts();
            var ventas = helper.GetVentaDetalles(obj.v_IdVenta, _config.i_GroupUndInter ?? 148);

            if (ventas == null)
            {
                return(null);
            }

            var sum = new Dictionary <OtrosConceptosTributarios, decimal>
            {
                { OtrosConceptosTributarios.TotalVentaOperacionesGravadas, 0 },
                { OtrosConceptosTributarios.TotalVentaOperacionesExoneradas, 0 },
                { OtrosConceptosTributarios.TotalVentaOperacionesInafectas, 0 },
                { OtrosConceptosTributarios.TotalVentaOperacionesGratuitas, 0 }
            };

            foreach (var detalle in ventas)
            {
                var item = detalle.Item1;
                var tipoAfectacionIgv = (TipoAfectacionIgv)Enum.ToObject(typeof(TipoAfectacionIgv), detalle.Item3);
                var precioUnit        = (tipoAfectacionIgv == TipoAfectacionIgv.GravadoOperacionOnerosa && obj.i_PreciosIncluyenIgv == 1
                                 ? item.d_Precio / (1M + igv) : item.d_Precio) ?? 0M;
                var            precioItem = precioUnit;
                productoiscDto isc        = null;
                if (IsValueNotNullorZero(item.d_isc))
                {
                    isc = helper.GetIscFromDetail(item.v_IdProductoDetalle, obj.v_Periodo);
                    switch (isc.i_IdSistemaIsc)
                    {
                    case 1:
                        precioItem *= 1M + isc.d_Porcentaje ?? 0;
                        break;

                    case 2:
                        precioItem += isc.d_Monto ?? 0;
                        break;

                    case 3:
                        precioItem += isc.d_Porcentaje * isc.d_Monto ?? 0;
                        break;
                    }
                }
                if (tipoAfectacionIgv == TipoAfectacionIgv.GravadoOperacionOnerosa)
                {
                    precioItem *= (1M + igv);
                }
                var isGratuito = (int)tipoAfectacionIgv % 10 != 0;
                var detail     = new InvoiceDetail
                {
                    CodigoProducto      = item.v_IdProductoDetalle,
                    Cantidad            = item.d_Cantidad ?? 0M,
                    DescripcionProducto = item.v_DescripcionProducto,
                    PrecioUnitario      = isGratuito ? 0 : precioUnit,
                    PrecioAlternativos  = new List <PrecioItemType>
                    {
                        new PrecioItemType
                        {
                            TipoDePrecio = TipoPrecioVenta.PrecioUnitario,
                            Monto        = isGratuito ? 0 : precioItem
                        }         // Precio con ISC e IGV
                    },
                    UnidadMedida = detalle.Item2,
                    ValorVenta   = item.d_ValorVenta ?? 0M,
                    Impuesto     = GetImpuestosLine(item, tipoAfectacionIgv)
                };
                if (isGratuito)
                {
                    detail.PrecioAlternativos.Add(new PrecioItemType
                    {
                        TipoDePrecio = TipoPrecioVenta.ValorReferencial,
                        Monto        = precioItem
                    });
                }

                if (isc != null)
                {
                    detail.Impuesto.Add(new TotalImpuestosType
                    {
                        TipoIsc     = (TipoSistemaIsc)Enum.ToObject(typeof(TipoSistemaIsc), isc.i_IdSistemaIsc ?? 1),
                        TipoTributo = TipoTributo.ISC_EXC,
                        Monto       = item.d_isc ?? 0
                    });
                }
                SetSuma(ref sum, tipoAfectacionIgv, isGratuito ? item.d_Cantidad * precioUnit ?? 0 : detail.ValorVenta);
                details.Add(detail);
            }
            return(sum);
        }
Exemplo n.º 3
0
        private NotasBase <InvoiceDetail> GetBaseNota(ventaDto pobjVenta, clienteDto pobjCliente, decimal igv)
        {
            var baseNote = new NotasBase <InvoiceDetail>
            {
                SerieDocumento                = pobjVenta.v_SerieDocumento,
                CorrelativoDocumento          = pobjVenta.v_CorrelativoDocumento,
                DocumentoRef                  = (pobjVenta.v_SerieDocumentoRef + "-" + pobjVenta.v_CorrelativoDocumentoRef).Trim(),
                TipoDocRef                    = (TipoDocumentoElectronico)Enum.ToObject(typeof(TipoDocumentoElectronico), pobjVenta.i_IdTipoDocumentoRef ?? 1),
                FechaEmision                  = pobjVenta.t_FechaRegistro ?? DateTime.Now,
                NombreRazonSocialCliente      = System.Text.RegularExpressions.Regex.Replace(string.Join(" ", pobjCliente.v_ApePaterno, pobjCliente.v_ApeMaterno, pobjCliente.v_PrimerNombre, pobjCliente.v_SegundoNombre, pobjCliente.v_RazonSocial), @"[^\w\.-]", " ").Trim(),
                TipoDocumentoIdentidadCliente = (TipoDocumentoIdentidad)Enum.ToObject(typeof(TipoDocumentoIdentidad), pobjCliente.i_IdTipoIdentificacion ?? 6),
                NroDocCliente                 = pobjCliente.v_NroDocIdentificacion,
                RucEmisor                    = _config.v_Ruc,
                NombreComercialEmisor        = _config.v_NombreComercial,
                NombreRazonSocialEmisor      = _config.v_RazonSocial,
                TipoDocumentoIdentidadEmisor = TipoDocumentoIdentidad.RegistroUnicoContribuyentes,
                CodigoMoneda                 = pobjVenta.i_IdMoneda == 1 ? "PEN" : "USD",
                Motivo          = pobjVenta.v_Concepto,
                Total           = pobjVenta.d_ValorVenta ?? 0M,
                TotalCargos     = 0,
                DireccionEmisor = new DireccionType
                {
                    CodigoPais    = "PE",
                    CodigoUbigueo = _config.v_Ubigueo,
                    Departamento  = _config.v_Departamento,
                    Provincia     = _config.v_Provincia,
                    Distrito      = _config.v_Distrito,
                    Zona          = _config.v_Urbanizacion,
                    Direccion     = _config.v_Domicilio
                },
                Impuesto          = GetImpuestosGlobal(pobjVenta),
                DetallesDocumento = new List <InvoiceDetail>()
            };

            //if (!string.IsNullOrWhiteSpace(pobjVenta.v_SerieDocumentoRef))
            //{
            //    baseNote.DocumentoReferenciaNumero = pobjVenta.v_SerieDocumentoRef + "-" + pobjVenta.v_CorrelativoDocumentoRef;
            //    baseNote.DocumentoReferenciaTipoDocumento = (TipoDocumentoElectronico)Enum.ToObject(typeof(TipoDocumentoElectronico), pobjVenta.i_IdTipoDocumentoRef);
            //}
            if (!string.IsNullOrWhiteSpace(pobjVenta.v_NroGuiaRemisionSerie))
            {
                baseNote.GuiaRemisionReferencia = new List <GuiaRemisionType>
                {
                    new GuiaRemisionType {
                        IdTipoGuiaRemision = "09", // Tipo Guia Remision
                        NumeroGuiaRemision = pobjVenta.v_NroGuiaRemisionSerie + "-" + pobjVenta.v_NroGuiaRemisionCorrelativo
                    }
                };
            }
            //Descuento Global
            var factDesc = 1M;
            //if (IsValueNotNullorZero(pobjVenta.d_PorcDescuento))
            //{
            //    factDesc = 1 - (pobjVenta.d_PorcDescuento ?? 0) / 100;
            //    var valTotal = pobjVenta.d_Total / factDesc;
            //    baseNote.DescuentoGlobal = valTotal - pobjVenta.d_Total ?? 0;
            //}
            var sumTotals = LoadDetail(baseNote.DetallesDocumento, pobjVenta, igv);

            baseNote.TotalTributosAdicionales = GetTributosAddicionales(sumTotals, factDesc);
            if (IsValueNotNullorZero(pobjVenta.d_Descuento)) //Si Tiene Descuentos
            {
                baseNote.TotalTributosAdicionales.Add(new TotalTributosType
                {
                    Id           = OtrosConceptosTributarios.TotalDescuentos,
                    MontoPagable = pobjVenta.d_Descuento ?? 0m
                });
            }
            return(baseNote);
        }