/// <summary>
        /// Genera un documento XML para Resumen Diario.
        /// </summary>
        /// <param name="summaryHeaderEntity">Entidad de Resumen</param>
        /// <param name="version2">version 2</param>
        /// <returns>Retorna el XML generado.</returns>
        public XmlFileResult GenerarDocumentoSummary(SummaryHeader summaryHeaderEntity, bool version2 = false)
        {
            try
            {
                #region Filename
                var id          = $"RC-{DateTime.Today:yyyyMMdd}-{summaryHeaderEntity.CorrelativoArchivo}";
                var xmlFilename = summaryHeaderEntity.RucEmisor + "-" + id;
                #endregion

                #region Gen Summary
                AmountType.TlsDefaultCurrencyID = summaryHeaderEntity.CodigoMoneda;
                var summaryDoc = new SummaryDocumentsType
                {
                    ID = id,
                    CustomizationID = version2 ? "1.1" : "1.0", // 2018 = 1.1
                    ReferenceDate   = summaryHeaderEntity.FechaEmision,
                    IssueDate       = DateTime.Today.Date,
                    UBLExtensions   = new[]
                    {
                        new UBLExtensionType
                        {
                            ExtensionContent = new AdditionalsInformationType()
                        },
                    },
                    Signature = UtilsXmlDoc.GetSignature(summaryHeaderEntity),
                    AccountingSupplierParty = UtilsXmlDoc.GetInfoEmisor(summaryHeaderEntity),
                    SummaryDocumentsLine    = UtilsXmlDoc.GetSummaryLines(summaryHeaderEntity.DetallesDocumento, version2)
                };
                #endregion

                return(FromDocument(summaryDoc, xmlFilename));
            }
            catch (Exception ex)
            {
                return(FromException(ex));
            }
        }
Example #2
0
        public bool GenerateXML()
        {
            bool isGenerated = false;

            InsertaTC();
            RBD = ordenaResumen();
            if (RBD.Count == 0)
            {
                MS.GeneraLog.IngresoBD01($"No se obtuvieron boletas y/o documentos asociados de la fecha {MS.SummaryDate}");
                return(false);
            }
            else
            {
                if (!DBConnection.ExchangueRateExists && DBConnection.DocumentDolarExists)
                {
                    MS.GeneraLog.IngresoBD01($"No se ha configurado el tipo de cambio para el día {MS.SummaryDate}");
                    return(false);
                }
            }

            getDocumentName();
            MS.getFileNames();

            try
            {
                MS.GeneraLog.GeneracionXML("-----  Inicio de Generación de Archivo: " + MS.XMLIFileLocation);
                XmlSerializer           mySerializer = new XmlSerializer(typeof(SummaryDocumentsType));
                XmlSerializerNamespaces ns           = getNamespaces();
                XmlWriterSettings       setting      = getSettings();

                SummaryDocumentsType sum = new SummaryDocumentsType();

                sum.AccountingSupplierParty = getSupplierPartyType();
                sum.Signature       = getSignatureType();
                sum.UBLVersionID    = getUBLVersionID();
                sum.CustomizationID = getCustomizationID();
                sum.ID                   = getID();
                sum.IssueDate            = getIssueDate();
                sum.ReferenceDate        = getReferenceDate();
                sum.Note                 = getNote();
                sum.SummaryDocumentsLine = getSummaryDocumentsLine();
                sum.UBLExtensions        = getUBLExtensions();

                StringWriterWithEncoding iso88591StringWriter = new StringWriterWithEncoding(ISO_8859_1);
                XmlSerializer            serializer           = new XmlSerializer(typeof(SummaryDocumentsType));
                XmlWriter writerx = XmlWriter.Create(iso88591StringWriter, setting);
                serializer.Serialize(writerx, sum, ns);

                XMLI = iso88591StringWriter.ToString();

                XMLI = XMLI.Replace("&lt;", "<");
                XMLI = XMLI.Replace("&gt;", ">");
                XMLI = XMLI.Replace("&amp;", "&");

                using (StreamWriter sw = new StreamWriter(MS.XMLIFileLocation, false, ISO_8859_1))
                {
                    sw.Write(XMLI);
                }

                SXMLI = GenerateStreamFromString(XMLI);

                isGenerated = true;
            }
            catch (Exception ex)
            {
                MS.GeneraLog.GeneracionXML("Ocurrió un error al momento de generar el XML Inicial");
                MS.GeneraLog.GeneracionXML("Error: " + ex.Message);
            }
            return(isGenerated);
        }
Example #3
0
        //public bool GenerateXML()
        public Extras.Common.Method.ListUtilClass GenerateXML(string TypeRC)
        {
            //ListDocs.ListBoletas = new List<RBoletasDetalle>();
            ListDocs = new Extras.Common.Method.ListUtilClass();
            bool isGenerated = false;

            //InsertaTC(); exchange rate
            RBD = ordenaResumen(TypeRC);
            var temp = new List <RBoletasDetalle>();

            var temp_XGN = new List <RBoletasDetalle>();
            var temp_NCD = new List <RBoletasDetalle>();
            var temp_ANS = new List <RBoletasDetalle>();

            foreach (var doc in RBD)
            {
                if (doc.SYSTEM_STATUS == "XGN")
                {
                    if (doc.SUMMARY == 0)
                    {
                        temp_XGN.Add(doc);
                    }
                }
                else if (doc.SYSTEM_STATUS == "ANS")
                {
                    if (doc.VOIDED == 0)
                    {
                        temp_ANS.Add(doc);
                    }

                    if (doc.SUMMARY == 0)
                    {
                        temp_XGN.Add(doc);
                    }
                }

                if (doc.TPO_CPE.Contains("07") || doc.TPO_CPE.Contains("08"))
                {
                    temp_NCD.Add(doc);
                }
            }

            if (TypeRC == "ANS")
            {
                //temp = temp_ANS;

                foreach (var ans in temp_ANS)
                {
                    if (ans.STATUS_RC_DOC != 3)
                    {
                        temp.Add(ans);
                    }
                }
            }
            else if (TypeRC == "XGN")
            {
                foreach (var d in temp_XGN)
                {
                    if (!d.TPO_CPE.Contains("07") && !d.TPO_CPE.Contains("08") && d.STATUS_RC_DOC < 1)
                    {
                        temp.Add(d);
                    }
                }

                if (temp_NCD.Count > 0)
                {
                    ListDocs.ListNotesDoc = temp_NCD;
                }

                //if(temp_ANS.Count > 0)
                //{
                //    ListDocs.ListBoletasLow = temp_ANS;
                //}
                //ListDocs.ListBoletasLow = temp_ANS;
                ListDocs.ListBoletasLow.Add(new RBoletasDetalle()
                {
                    NUM_CPE = ""
                });
            }
            else
            {
                foreach (var ncd in temp_NCD)
                {
                    if (ncd.STATUS_RC_DOC <= 1)
                    {
                        temp.Add(ncd);
                    }
                }

                //temp = temp_NCD;

                //if (temp_ANS.Count > 0)
                //{
                //    ListDocs.ListBoletasLow = temp_ANS;
                //}
                //ListDocs.ListBoletasLow = temp_ANS;
                ListDocs.ListBoletasLow.Add(new RBoletasDetalle()
                {
                    NUM_CPE = ""
                });
            }

            #region old
            ////if (TypeRC == "ANS")
            ////{
            ////    foreach (var b in RBD)
            ////    {
            ////        if (b.SYSTEM_STATUS.Contains(TypeRC) && b.VOIDED == 0) { temp.Add(b); }
            ////    }
            ////}
            ////else if (TypeRC == "NCD")
            ////{
            ////    foreach (var b in RBD)
            ////    {
            ////        if (b.SYSTEM_STATUS.ToUpper().Contains("ANS"))
            ////        {
            ////            ListDocs.ListBoletasLow.Add(b);
            ////        }

            ////        if (!b.TPO_CPE.Contains("03") && (b.SUMMARY <= 0))
            ////        {
            ////            temp.Add(b);
            ////        }
            ////    }
            ////}
            ////else
            ////{
            ////    foreach (var b in RBD)
            ////    {
            ////        if (b.SYSTEM_STATUS.ToUpper().Contains("ANS"))
            ////        {
            ////            ListDocs.ListBoletasLow.Add(b);
            ////        }

            ////        if (b.TPO_CPE == "07" || b.TPO_CPE == "08")
            ////        {
            ////            ListDocs.ListNotesDoc.Add(b);
            ////        }

            ////        if (b.SUMMARY == 0 && !b.TPO_CPE.Contains("07") && !b.TPO_CPE.Contains("08"))
            ////        {
            ////            temp.Add(b);
            ////        }
            ////    }
            ////}
            //if (TypeRC == "ANS")
            //{
            //    foreach (var b in RBD)
            //    {
            //        if (b.SYSTEM_STATUS.Contains(TypeRC) && b.VOIDED == 0)
            //        {
            //            temp.Add(b);
            //        }
            //    }
            //}
            //else
            //{
            //    foreach (var b in RBD)
            //    {
            //        if (b.SYSTEM_STATUS.ToUpper().Contains("ANS"))
            //        {
            //            ListDocs.ListBoletasLow.Add(b);
            //        }

            //        if (b.SUMMARY == 0)
            //        {
            //            temp.Add(b);
            //        }

            //        if (b.TPO_CPE == "07" || b.TPO_CPE == "08")
            //        {
            //            ListDocs.ListNotesDoc.Add(b);
            //        }
            //    }
            //}

            //foreach (var b in RBD)
            //{
            //if (b.SYSTEM_STATUS.ToUpper().Contains("ANS"))
            //{
            //    ListDocs.ListBoletasLow.Add(b);
            //}
            //if (b.SYSTEM_STATUS.ToUpper().Contains(TypeRC))
            //{
            //    temp.Add(b);
            //}
            //}
            #endregion

            #region old cant
            //if (temp.Count > 1000)
            //{
            //    var tmp = new List<RBoletasDetalle>();
            //    for (int i = 0; i < 1000; i++)
            //    {
            //        tmp.Add(temp[i]);
            //    }
            //    RBD = tmp;
            //    ListDocs.CantDocs = temp.Count - 1000;
            //}
            //else
            //{
            //    RBD = temp;
            //}
            #endregion

            if (temp.Count > 500)
            {
                var tmp = new List <RBoletasDetalle>();
                for (int i = 0; i < 500; i++)
                {
                    tmp.Add(temp[i]);
                }
                RBD = tmp;
                ListDocs.CantDocs = temp.Count - 500;
            }
            else
            {
                RBD = temp;
            }


            if (RBD.Count == 0)
            {
                MS.GeneraLog.IngresoBD01($"No se obtuvieron boletas y/o documentos asociados de la fecha {MS.SummaryDate}");
                //return false;
                return(ListDocs);
            }
            else
            {
                if (!DBConnection.ExchangueRateExists && DBConnection.DocumentDolarExists)
                {
                    MS.GeneraLog.IngresoBD01($"No se ha configurado el tipo de cambio para el día {MS.SummaryDate}");
                    //return false;
                    return(ListDocs);
                }
            }

            getDocumentName();
            MS.getFileNames();

            try
            {
                MS.GeneraLog.GeneracionXML("-----  Inicio de Generación de Archivo: " + MS.XMLIFileLocation);
                XmlSerializer           mySerializer = new XmlSerializer(typeof(SummaryDocumentsType));
                XmlSerializerNamespaces ns           = getNamespaces();
                XmlWriterSettings       setting      = getSettings();

                SummaryDocumentsType sum = new SummaryDocumentsType();

                sum.AccountingSupplierParty = getSupplierPartyType();
                sum.Signature       = getSignatureType();
                sum.UBLVersionID    = getUBLVersionID();
                sum.CustomizationID = getCustomizationID();
                sum.ID                   = getID();
                sum.IssueDate            = getIssueDate();
                sum.ReferenceDate        = getReferenceDate();
                sum.Note                 = getNote();
                sum.SummaryDocumentsLine = getSummaryDocumentsLine(1, "", TypeRC);
                sum.UBLExtensions        = getUBLExtensions();

                StringWriterWithEncoding iso88591StringWriter = new StringWriterWithEncoding(ISO_8859_1);
                XmlSerializer            serializer           = new XmlSerializer(typeof(SummaryDocumentsType));
                XmlWriter writerx = XmlWriter.Create(iso88591StringWriter, setting);
                serializer.Serialize(writerx, sum, ns);

                XMLI = iso88591StringWriter.ToString();

                XMLI = XMLI.Replace("&lt;", "<");
                XMLI = XMLI.Replace("&gt;", ">");
                XMLI = XMLI.Replace("&amp;", "&");

                using (StreamWriter sw = new StreamWriter(MS.XMLIFileLocation, false, ISO_8859_1))
                {
                    sw.Write(XMLI);
                }

                SXMLI = GenerateStreamFromString(XMLI);

                isGenerated = true;
            }
            catch (Exception ex)
            {
                MS.GeneraLog.GeneracionXML("Ocurrió un error al momento de generar el XML Inicial");
                MS.GeneraLog.GeneracionXML("Error: " + ex.Message);
            }
            //return isGenerated;
            return(ListDocs);
        }
Example #4
0
        private static SummaryDocumentsType PopulateInvoiceWithSampleData()
        {
            // Default that shpould be set when you load the library. Don't need to set it for each document.
            UblBaseDocumentType.GlbCustomizationID =
                "urn:oasis:names:specification:ubl:xpath:Invoice-2.0:sbs-1.0-draft";
            UblBaseDocumentType.GlbProfileID =
                "bpid:urn:oasis:names:draft:bpss:ubl-2-sbs-invoice-notification-draft";

            // Default value assinged to all amounts in this thread
            AmountType.TlsDefaultCurrencyID = "PEN";


            // This initialization will only work with C# 3.0 and above
            var res = new SummaryDocumentsType
            {
                // UBLVersionID = "2.0", Don't need to set this one. hardcoded in the library
                ID            = "A00095678",
                IssueDate     = new DateTime(2005, 6, 21),
                Note          = new TextType[] { "sample" },
                UBLExtensions = new[]
                {
                    new UBLExtensionType
                    {
                    }
                },
                AccountingSupplierParty = new SupplierPartyType
                {
                    CustomerAssignedAccountID = "CO001",
                    Party = new PartyType
                    {
                        PartyName     = new PartyNameType[] { "Consortial" },
                        PostalAddress = new AddressType
                        {
                            StreetName       = "Lima jejejeje",
                            BuildingName     = "Thereabouts",
                            BuildingNumber   = "56A",
                            CityName         = "Farthing",
                            PostalZone       = "AA99 1BB",
                            CountrySubentity = "Heremouthshire",
                            AddressLine      = new AddressLineType[] { "The Roundabout" },
                            Country          = new CountryType {
                                IdentificationCode = "GB"
                            }
                        },
                        PartyTaxScheme = new PartyTaxSchemeType[]
                        {
                            new PartyTaxSchemeType
                            {
                                RegistrationName = "Eduardo Quiroz Cosme",
                                CompanyID        = "45810953",
                                ExemptionReason  = "N/A",
                                TaxScheme        = new TaxSchemeType
                                {
                                    ID          = "VAT",
                                    TaxTypeCode = "VAT"
                                }
                            }
                        },
                        Contact = new ContactType
                        {
                            Name           = "Mrs Bouquet",
                            Telephone      = "0158 1233714",
                            Telefax        = "0158 1233856",
                            ElectronicMail = "*****@*****.**",
                        }
                    }
                },
                SummaryDocumentsLine = new []
                {
                    new SummaryDocumentsLineType
                    {
                        LineID           = "1",
                        DocumentTypeCode = "03",
                        ID = "B001-1",
                        SUNATPerceptionSummaryDocumentReference = new SUNATPerceptionSummaryDocumentReferenceType
                        {
                            SUNATPerceptionSystemCode = "01",
                            SUNATPerceptionPercent    = 2.00M,
                            TotalInvoiceAmount        = 10.00M,
                            SUNATTotalCashed          = 110.00M,
                            TaxableAmount             = 100.00M
                        },
                        Status = new StatusType
                        {
                            ConditionCode = "1"
                        },
                        BillingPayment = new []
                        {
                            new PaymentType
                            {
                                PaidAmount    = 100,
                                InstructionID = "1001"
                            }
                        },
                        TaxTotal = new TaxTotalType[]
                        {
                            new TaxTotalType
                            {
                                TaxAmount            = 17.50M,
                                TaxEvidenceIndicator = true,
                                TaxSubtotal          = new TaxSubtotalType[]
                                {
                                    new TaxSubtotalType
                                    {
                                        TaxableAmount = 100.00M,
                                        TaxAmount     = 17.50M,
                                        TaxCategory   = new TaxCategoryType
                                        {
                                            ID        = "A",
                                            Percent   = 17.5M,
                                            TaxScheme = new TaxSchemeType {
                                                ID = "UK VAT", TaxTypeCode = "VAT"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            return(res);
        }