示例#1
0
        IEstructuraXml IDocumentoXml.Generar(IDocumentoElectronico request)
        {
            var documento = (ResumenDiario)request;
            var summary   = new SummaryDocuments
            {
                Id              = documento.IdDocumento,
                IssueDate       = Convert.ToDateTime(documento.FechaEmision),
                ReferenceDate   = Convert.ToDateTime(documento.FechaReferencia),
                CustomizationId = "1.0",
                UblVersionId    = "2.0",
                Signature       = new SignatureCac
                {
                    Id             = documento.IdDocumento,
                    SignatoryParty = new SignatoryParty
                    {
                        PartyIdentification = new PartyIdentification
                        {
                            Id = new PartyIdentificationId
                            {
                                Value = documento.Emisor.NroDocumento
                            }
                        },
                        PartyName = new PartyName
                        {
                            Name = documento.Emisor.NombreLegal
                        }
                    },
                    DigitalSignatureAttachment = new DigitalSignatureAttachment
                    {
                        ExternalReference = new ExternalReference
                        {
                            Uri = $"{documento.Emisor.NroDocumento}-{documento.IdDocumento}"
                        }
                    }
                },
                AccountingSupplierParty = new AccountingSupplierParty
                {
                    CustomerAssignedAccountId = documento.Emisor.NroDocumento,
                    AdditionalAccountId       = documento.Emisor.TipoDocumento,
                    Party = new Party
                    {
                        PartyLegalEntity = new PartyLegalEntity
                        {
                            RegistrationName = documento.Emisor.NombreLegal
                        }
                    }
                }
            };

            foreach (var grupo in documento.Resumenes)
            {
                var linea = new VoidedDocumentsLine
                {
                    LineId                = grupo.Id,
                    DocumentTypeCode      = grupo.TipoDocumento,
                    DocumentSerialId      = grupo.Serie,
                    StartDocumentNumberId = grupo.CorrelativoInicio,
                    EndDocumentNumberId   = grupo.CorrelativoFin,
                    TotalAmount           = new PayableAmount
                    {
                        CurrencyId = grupo.Moneda,
                        Value      = grupo.TotalVenta
                    },
                    //jcf Sólo agregar este nodo si el monto > 0
                    //BillingPayments = new List<BillingPayment>()
                    //{
                    //  new BillingPayment
                    //  {
                    //      PaidAmount = new PayableAmount
                    //      {
                    //          CurrencyId = grupo.Moneda,
                    //          Value = grupo.Gravadas
                    //      },
                    //      InstructionId = "01"
                    //  },
                    //  new BillingPayment
                    //  {
                    //      PaidAmount = new PayableAmount
                    //      {
                    //          CurrencyId = grupo.Moneda,
                    //          Value = grupo.Exoneradas
                    //      },
                    //      InstructionId = "02"
                    //  },
                    //  new BillingPayment
                    //  {
                    //      PaidAmount = new PayableAmount
                    //      {
                    //          CurrencyId = grupo.Moneda,
                    //          Value = grupo.Inafectas
                    //      },
                    //      InstructionId = "03"
                    //  },
                    //},
                    //AllowanceCharge = new AllowanceCharge
                    //{
                    //    ChargeIndicator = true,
                    //    Amount = new PayableAmount
                    //    {
                    //        CurrencyId = grupo.Moneda,
                    //        Value = grupo.TotalDescuentos
                    //    }
                    //},
                    TaxTotals = new List <TaxTotal>()
                    {
                        new TaxTotal
                        {
                            TaxAmount = new PayableAmount
                            {
                                CurrencyId = grupo.Moneda,
                                Value      = grupo.TotalIsc
                            },
                            TaxSubtotal = new TaxSubtotal
                            {
                                TaxAmount = new PayableAmount
                                {
                                    CurrencyId = grupo.Moneda,
                                    Value      = grupo.TotalIsc
                                },
                                TaxCategory = new TaxCategory
                                {
                                    TaxScheme = new TaxScheme
                                    {
                                        Id          = "2000",
                                        Name        = "ISC",
                                        TaxTypeCode = "EXC"
                                    }
                                }
                            }
                        },
                        new TaxTotal
                        {
                            TaxAmount = new PayableAmount
                            {
                                CurrencyId = grupo.Moneda,
                                Value      = grupo.TotalIgv
                            },
                            TaxSubtotal = new TaxSubtotal
                            {
                                TaxAmount = new PayableAmount
                                {
                                    CurrencyId = grupo.Moneda,
                                    Value      = grupo.TotalIgv
                                },
                                TaxCategory = new TaxCategory
                                {
                                    TaxScheme = new TaxScheme
                                    {
                                        Id          = "1000",
                                        Name        = "IGV",
                                        TaxTypeCode = "VAT"
                                    }
                                }
                            }
                        },
                        new TaxTotal
                        {
                            TaxAmount = new PayableAmount
                            {
                                CurrencyId = grupo.Moneda,
                                Value      = grupo.TotalOtrosImpuestos
                            },
                            TaxSubtotal = new TaxSubtotal
                            {
                                TaxAmount = new PayableAmount
                                {
                                    CurrencyId = grupo.Moneda,
                                    Value      = grupo.TotalOtrosImpuestos
                                },
                                TaxCategory = new TaxCategory
                                {
                                    TaxScheme = new TaxScheme
                                    {
                                        Id          = "9999",
                                        Name        = "OTROS",
                                        TaxTypeCode = "OTH"
                                    }
                                }
                            }
                        },
                    }
                };

                //jcf Sólo agregar este nodo si el monto > 0
                if (grupo.Gravadas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Gravadas
                        },
                        InstructionId = "01"
                    });
                }
                if (grupo.Exoneradas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Exoneradas
                        },
                        InstructionId = "02"
                    });
                }
                if (grupo.Inafectas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Inafectas
                        },
                        InstructionId = "03"
                    });
                }

                if (grupo.TotalDescuentos > 0)
                {
                    linea.AllowanceCharge = new AllowanceCharge
                    {
                        ChargeIndicator = true,
                        Amount          = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.TotalDescuentos
                        }
                    };
                }
                //Fin modificación ////////////////
                if (grupo.Exportacion > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Exportacion
                        },
                        InstructionId = "04"
                    });
                }
                if (grupo.Gratuitas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Gratuitas
                        },
                        InstructionId = "05"
                    });
                }
                summary.SummaryDocumentsLines.Add(linea);
            }

            return(summary);
        }
        IEstructuraXml IDocumentoXml.Generar(IDocumentoElectronico request)
        {
            var documento = (ResumenDiarioNuevo)request;
            var summary   = new SummaryDocuments
            {
                Id              = documento.IdDocumento,
                IssueDate       = Convert.ToDateTime(documento.FechaEmision),
                ReferenceDate   = Convert.ToDateTime(documento.FechaReferencia),
                CustomizationId = "1.1",
                UblVersionId    = "2.0",
                Signature       = new SignatureCac
                {
                    Id             = documento.IdDocumento,
                    SignatoryParty = new SignatoryParty
                    {
                        PartyIdentification = new PartyIdentification
                        {
                            Id = new PartyIdentificationId
                            {
                                Value = documento.Emisor.NroDocumento
                            }
                        },
                        PartyName = new PartyName
                        {
                            Name = documento.Emisor.NombreLegal
                        }
                    },
                    DigitalSignatureAttachment = new DigitalSignatureAttachment
                    {
                        ExternalReference = new ExternalReference
                        {
                            Uri = $"{documento.Emisor.NroDocumento}-{documento.IdDocumento}"
                        }
                    }
                },
                AccountingSupplierParty = new AccountingSupplierParty
                {
                    CustomerAssignedAccountId = documento.Emisor.NroDocumento,
                    AdditionalAccountId       = documento.Emisor.TipoDocumento,
                    Party = new Party
                    {
                        PartyLegalEntity = new PartyLegalEntity
                        {
                            RegistrationName = documento.Emisor.NombreLegal
                        }
                    }
                }
            };

            foreach (var grupo in documento.Resumenes)
            {
                var linea = new VoidedDocumentsLine
                {
                    LineId           = grupo.Id,
                    DocumentTypeCode = grupo.TipoDocumento,
                    Id = grupo.IdDocumento,
                    AccountingCustomerParty = new AccountingSupplierParty
                    {
                        AdditionalAccountId       = grupo.TipoDocumentoReceptor,
                        CustomerAssignedAccountId = grupo.NroDocumentoReceptor
                    },
                    BillingReference = new BillingReference
                    {
                        InvoiceDocumentReference = new InvoiceDocumentReference
                        {
                            Id = grupo.DocumentoRelacionado,
                            DocumentTypeCode = grupo.TipoDocumentoRelacionado
                        }
                    },
                    ConditionCode = grupo.CodigoEstadoItem,
                    TotalAmount   = new PayableAmount
                    {
                        CurrencyId = grupo.Moneda,
                        Value      = grupo.TotalVenta
                    },
                    BillingPayments = new List <BillingPayment>()
                    {
                        new BillingPayment
                        {
                            PaidAmount = new PayableAmount
                            {
                                CurrencyId = grupo.Moneda,
                                Value      = grupo.Gravadas
                            },
                            InstructionId = "01"
                        }
                    }
                    ,
                    AllowanceCharge = new AllowanceCharge
                    {
                        ChargeIndicator = true,
                        Amount          = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.TotalDescuentos
                        }
                    }
                };

                if (grupo.Exoneradas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Exoneradas
                        },
                        InstructionId = "02"
                    });
                }

                if (grupo.Inafectas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Inafectas
                        },
                        InstructionId = "03"
                    });
                }
                if (grupo.Exportacion > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Exportacion
                        },
                        InstructionId = "04"
                    });
                }
                if (grupo.Gratuitas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.Gratuitas
                        },
                        InstructionId = "05"
                    });
                }

                if (grupo.TotalIsc > 0)
                {
                    linea.TaxTotals.Add(new TaxTotal
                    {
                        TaxAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.TotalIsc
                        },
                        TaxSubtotal = new TaxSubtotal
                        {
                            TaxAmount = new PayableAmount
                            {
                                CurrencyId = grupo.Moneda,
                                Value      = grupo.TotalIsc
                            },
                            TaxCategory = new TaxCategory
                            {
                                TaxScheme = new TaxScheme
                                {
                                    Id          = "2000",
                                    Name        = "ISC",
                                    TaxTypeCode = "EXC"
                                }
                            }
                        }
                    });
                }
                if (grupo.TotalIgv > 0)
                {
                    linea.TaxTotals.Add(new TaxTotal
                    {
                        TaxAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.TotalIgv
                        },
                        TaxSubtotal = new TaxSubtotal
                        {
                            TaxAmount = new PayableAmount
                            {
                                CurrencyId = grupo.Moneda,
                                Value      = grupo.TotalIgv
                            },
                            TaxCategory = new TaxCategory
                            {
                                TaxScheme = new TaxScheme
                                {
                                    Id          = "1000",
                                    Name        = "IGV",
                                    TaxTypeCode = "VAT"
                                }
                            }
                        }
                    });
                }
                if (grupo.TotalOtrosImpuestos > 0)
                {
                    linea.TaxTotals.Add(new TaxTotal
                    {
                        TaxAmount = new PayableAmount
                        {
                            CurrencyId = grupo.Moneda,
                            Value      = grupo.TotalOtrosImpuestos
                        },
                        TaxSubtotal = new TaxSubtotal
                        {
                            TaxAmount = new PayableAmount
                            {
                                CurrencyId = grupo.Moneda,
                                Value      = grupo.TotalOtrosImpuestos
                            },
                            TaxCategory = new TaxCategory
                            {
                                TaxScheme = new TaxScheme
                                {
                                    Id          = "9999",
                                    Name        = "OTROS",
                                    TaxTypeCode = "OTH"
                                }
                            }
                        }
                    });
                }

                summary.SummaryDocumentsLines.Add(linea);
            }

            return(summary);
        }
        IEstructuraXml IDocumentoXml.Generar(IDocumentoElectronico request)
        {
            var documento = (ResumenDiario)request;
            var summary   = new SummaryDocuments
            {
                Id              = documento.IdDocumento,
                IssueDate       = Convert.ToDateTime(documento.FechaEmision),
                ReferenceDate   = Convert.ToDateTime(documento.FechaReferencia),
                CustomizationId = "1.1",
                UblVersionId    = "2.0",
                Signature       = new Signature
                {
                    Id             = documento.IdDocumento,
                    SignatoryParty = new SignatoryParty
                    {
                        PartyIdentification = new PartyIdentification
                        {
                            Id = new PartyIdentificationId {
                                Value = documento.Emisor.NroDocumento
                            }
                        },
                        PartyName = new PartyName {
                            Name = documento.Emisor.NombreLegal
                        }
                    },
                    DigitalSignatureAttachment = new DigitalSignatureAttachment
                    {
                        ExternalReference = new ExternalReference
                        {
                            Uri = $"{documento.Emisor.NroDocumento}-{documento.IdDocumento}"
                        }
                    }
                },
                AccountingSupplierParty = new AccountingContributorParty
                {
                    CustomerAssignedAccountId = documento.Emisor.NroDocumento,
                    AdditionalAccountId       = documento.Emisor.TipoDocumento,
                    Party = new Party
                    {
                        PartyLegalEntity = new PartyLegalEntity {
                            RegistrationName = documento.Emisor.NombreLegal
                        }
                    }
                }
            };

            foreach (var resumen in documento.Resumenes)
            {
                var linea = new VoidedDocumentsLine
                {
                    LineId           = resumen.Id,
                    DocumentTypeCode = resumen.TipoDocumento,
                    Id = resumen.Serie,                       // Serie correlativo
                    AccountingCustomerParty = new AccountingContributorParty
                    {
                        AdditionalAccountId       = resumen.Receptor.TipoDocumento,
                        CustomerAssignedAccountId = resumen.Receptor.NroDocumento
                    },
                    BillingReference = new BillingReference
                    {
                        InvoiceDocumentReference = new InvoiceDocumentReference
                        {
                            Id = resumen.DocumentoRelacionado,
                            DocumentTypeCode = new DocumentTypeCode()
                            {
                                Value = resumen.TipoDocumentoRelacionado
                            }
                        }
                    },
                    ConditionCode = resumen.CodigoEstadoItem,
                    TotalAmount   = new PayableAmount
                    {
                        CurrencyId = resumen.Moneda,
                        Value      = resumen.TotalVenta
                    },
                    BillingPayments = new List <BillingPayment>()
                    {
                        new BillingPayment
                        {
                            PaidAmount = new PayableAmount
                            {
                                CurrencyId = resumen.Moneda,
                                Value      = resumen.Gravadas
                            },
                            InstructionId = "01"
                        }
                    },
                    AllowanceCharge = new AllowanceCharge
                    {
                        ChargeIndicator = true,
                        Amount          = new PayableAmount
                        {
                            CurrencyId = resumen.Moneda,
                            Value      = resumen.TotalDescuentos
                        }
                    },
                };

                #region TaxTotal
                if (resumen.TotalImpuestos.Count > 0)
                {         // Monto total de impuestos del ítem
                    foreach (var totalImpuesto in resumen.TotalImpuestos)
                    {     // Total de impuestos para cada ítem
                        var lineaTotalImpuestos = new TaxTotal
                        { // Monto total de impuestos por línea
                            TaxAmount = new PayableAmount()
                            {
                                CurrencyId = totalImpuesto.TipoMonedaTotal, Value = totalImpuesto.MontoTotal
                            }
                        };

                        foreach (var subTotalImpuestos in totalImpuesto.SubTotalesImpuestos)
                        {   // Afectación al IGV por la línea | Afectación IVAP por la línea
                            lineaTotalImpuestos.TaxSubtotals.Add(new TaxSubtotal
                            {
                                TaxAmount = new PayableAmount
                                {                                                   // Monto de IGV/IVAP de la línea | Monto total de impuestos por linea
                                    CurrencyId = subTotalImpuestos.TipoMonedaTotal, // Código de tipo de moneda del monto total del impuesto
                                    Value      = subTotalImpuestos.MontoTotal       // Monto total del impuesto
                                },
                                TaxCategory = new TaxCategory
                                {   // Tasa del IGV o  Tasa del IVAP
                                    TaxCategoryId = new TaxCategoryId {
                                        Value = subTotalImpuestos.CategoriaImpuestos
                                    },                                                          // Categoría de impuestos
                                    Percent = subTotalImpuestos.PorcentajeImp,                  // Tasa del IGV o  Tasa del IVAP | Tasa del tributo
                                    TaxExemptionReasonCode = new TaxExemptionReasonCode()
                                    {
                                        Value = subTotalImpuestos.TipoAfectacion
                                    },                                                                                                   // Afectación al IGV o IVAP cuando corresponda
                                    TierRange = subTotalImpuestos.TipoSistemaISC,
                                    TaxScheme = new TaxScheme
                                    {
                                        TaxSchemeId = new TaxSchemeId {
                                            Value = subTotalImpuestos.CodigoTributo
                                        },                                                  // Código de tributo por línea | Catálogo No. 05
                                        Name        = subTotalImpuestos.NombreTributo,      // NombreTributo de tributo
                                        TaxTypeCode = subTotalImpuestos.CodigoInternacional // Código internacional tributo
                                    }
                                }
                            });
                        }
                        linea.TaxTotals.Add(lineaTotalImpuestos); // Realizar debug
                    }
                }
                #endregion TaxTotal

                if (resumen.Exoneradas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = resumen.Moneda,
                            Value      = resumen.Exoneradas
                        },
                        InstructionId = "02"
                    });
                }

                if (resumen.Inafectas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = resumen.Moneda,
                            Value      = resumen.Inafectas
                        },
                        InstructionId = "03"
                    });
                }
                if (resumen.Exportaciones > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = resumen.Moneda,
                            Value      = resumen.Exportaciones
                        },
                        InstructionId = "04"
                    });
                }
                if (resumen.Gratuitas > 0)
                {
                    linea.BillingPayments.Add(new BillingPayment
                    {
                        PaidAmount = new PayableAmount
                        {
                            CurrencyId = resumen.Moneda,
                            Value      = resumen.Gratuitas
                        },
                        InstructionId = "05"
                    });
                }

                summary.SummaryDocumentsLines.Add(linea);
            }

            return(summary);
        }