Esempio n. 1
0
        public List <RBoletasDetalle> ordenaResumen(string TypeRC)
        {
            List <ResumenB> DBList = new List <ResumenB>();

            DBList = DBConnection.SP_ObtieneResumenBoletas_2_1(TypeRC);

            string sa = "", ta = "";
            int    na = 0, sl = 0;

            RBoletasDetalle RBL = null;

            RBC = new RBoletasCabecera();

            RBC.TOT_DOC = DBList.Count;
            RBD         = new List <RBoletasDetalle>();

            for (int i = 0; i < DBList.Count; i++)
            {
                RBC.DOC_UPD_LIST.Add($"{MS.RucNumber}-{DBList[i].TPODOC}-{DBList[i].SERIE}-{DBList[i].NUMERO.ToString().PadLeft(8, '0')}");

                RBL = new RBoletasDetalle();

                sa = DBList[i].SERIE;
                na = DBList[i].NUMERO - 1;
                ta = DBList[i].TPODOC;

                RBC.FEC_INI = DateTime.Parse(MS.SummaryDate);
                RBC.FEC_FIN = DateTime.Parse(MS.SummaryDate);


                RBL.MONEDA = DBList[i].MONEDA;

                RBL.TPO_CPE = DBList[i].TPODOC;

                RBL.FEC_EMIS = DBList[i].DESDE;

                RBL.LineID           = i + 1;
                RBL.DocumentTypeCode = DBList[i].TPODOC;
                RBL.ID = DBList[i].SERIE + "-" + DBList[i].NUMERO;

                RBL.CustomerAssignedAccountID = DBList[i].RE_NUMDOC;
                RBL.AdditionalAccountID       = DBList[i].RE_TPODOC;
                RBL.ConditionCode             = DBList[i].STATUS_RC_DOC;

                RBL.TPO_DOC_AFEC  = DBList[i].TPO_DOC_AFEC;
                RBL.NRO_DOC_AFEC  = DBList[i].NRO_DOC_AFEC;
                RBL.SYSTEM_STATUS = DBList[i].SYSTEM_STATUS;
                RBL.NUM_CPE       = DBList[i].NUM_CPE;

                RBL.STATUS_RC_DOC = DBList[i].STATUS_RC_DOC;

                // IMPORTES
                RBL.MTO_GRA  = DBList[i].GRAVADO;
                RBL.MTO_EXO  = DBList[i].EXONERADO;
                RBL.MTO_INA  = DBList[i].INAFECTO;
                RBL.MTO_OCA  = DBList[i].OCARGOS;
                RBL.MTO_GRAT = DBList[i].GRATUITO;

                // IMPUESTOS
                RBL.IMP_IGV = DBList[i].IGV;
                RBL.IMP_ISC = DBList[i].ISC;
                RBL.IMP_OTH = DBList[i].OTH;

                // TOTAL
                RBL.MTO_TOT = DBList[i].TOTAL;

                //SUMMARY
                RBL.SUMMARY = DBList[i].SUMMARY;
                RBL.VOIDED  = DBList[i].VOIDED;

                RBC.MTO_GRA  = DBList[i].GRAVADO;
                RBC.MTO_EXO  = DBList[i].EXONERADO;
                RBC.MTO_INA  = DBList[i].INAFECTO;
                RBC.MTO_OCA  = DBList[i].OCARGOS;
                RBC.MTO_GRAT = DBList[i].GRATUITO;

                RBC.IMP_IGV = DBList[i].IGV;
                RBC.IMP_ISC = DBList[i].ISC;
                RBC.IMP_OTH = DBList[i].OTH;

                sl++; na = DBList[i].NUMERO;
                RBD.Add(RBL);
            }
            return(RBD);
        }
Esempio n. 2
0
        public List <RBoletasDetalle> ordenaResumen()
        {
            List <ResumenB> DBList = new List <ResumenB>();

            DBList = DBConnection.SP_ObtieneResumenBoletas();
            string sa = "", ta = "";
            int    na = 0, sl = 0;

            RBoletasDetalle RBL = null;

            RBC = new RBoletasCabecera();

            RBC.TOT_DOC = DBList.Count;
            RBD         = new List <RBoletasDetalle>();
            for (int i = 0; i < DBList.Count; ++i)
            {
                RBC.DOC_UPD_LIST.Add($"{MS.RucNumber}-{DBList[i].TPODOC}-{DBList[i].SERIE}-{DBList[i].NUMERO.ToString().PadLeft(8,'0')}");
                if (i == 0 || RBL == null)
                {
                    if (RBL == null)
                    {
                        RBL = new RBoletasDetalle();
                    }
                    sa = DBList[i].SERIE;
                    na = DBList[i].NUMERO - 1;
                    ta = DBList[i].TPODOC;

                    // NUEVO MÉTODO
                    RBL.TPO_CPE = DBList[i].TPODOC;
                    RBL.NUM_INI = DBList[i].NUMERO;
                    RBL.NUM_FIN = DBList[i].NUMERO;

                    RBC.FEC_INI = DateTime.Parse(MS.SummaryDate);
                    RBC.FEC_FIN = DateTime.Parse(MS.SummaryDate);
                }
                if (sa == DBList[i].SERIE && (na + 1) == DBList[i].NUMERO && ta == DBList[i].TPODOC)
                {
                    /*
                     * NUEVO MÉTODO
                     */
                    RBL.NRO_LIN = RBD.Count + 1;
                    RBL.TPO_CPE = DBList[i].TPODOC;
                    RBL.DOC_SER = DBList[i].SERIE;
                    RBL.NUM_FIN = DBList[i].NUMERO;

                    // IMPORTES

                    RBL.MTO_GRA = RBL.MTO_GRA + DBList[i].GRAVADO;
                    RBL.MTO_EXO = RBL.MTO_EXO + DBList[i].EXONERADO;
                    RBL.MTO_INA = RBL.MTO_INA + DBList[i].INAFECTO;
                    RBL.MTO_OCA = RBL.MTO_OCA + DBList[i].OCARGOS;


                    // IMPUESTOS
                    RBL.IMP_IGV = RBL.IMP_IGV + DBList[i].IGV;
                    RBL.IMP_ISC = RBL.IMP_ISC + DBList[i].ISC;
                    RBL.IMP_OTH = RBL.IMP_OTH + DBList[i].OTH;

                    // TOTAL
                    RBL.MTO_TOT = RBL.MTO_TOT + DBList[i].TOTAL;

                    RBC.MTO_GRA = RBC.MTO_GRA + DBList[i].GRAVADO;
                    RBC.MTO_EXO = RBC.MTO_EXO + DBList[i].EXONERADO;
                    RBC.MTO_INA = RBC.MTO_INA + DBList[i].INAFECTO;
                    RBC.MTO_OCA = RBC.MTO_OCA + DBList[i].OCARGOS;

                    RBC.IMP_IGV = RBC.IMP_IGV + DBList[i].IGV;
                    RBC.IMP_ISC = RBC.IMP_ISC + DBList[i].ISC;
                    RBC.IMP_OTH = RBC.IMP_OTH + DBList[i].OTH;

                    RBC.MTO_TOT = RBC.MTO_TOT + DBList[i].TOTAL;

                    sl++; na = DBList[i].NUMERO;
                }
                else
                {
                    /*
                     * NUEVO MÉTODO
                     */
                    RBD.Add(RBL);
                    RBL = null;
                    RBL = new RBoletasDetalle();

                    RBL.NRO_LIN = RBD.Count + 1;
                    RBL.TPO_CPE = DBList[i].TPODOC;
                    RBL.DOC_SER = DBList[i].SERIE;
                    RBL.NUM_INI = DBList[i].NUMERO;
                    RBL.NUM_FIN = DBList[i].NUMERO;

                    // IMPORTES

                    RBL.MTO_GRA = RBL.MTO_GRA + DBList[i].GRAVADO;
                    RBL.MTO_EXO = RBL.MTO_EXO + DBList[i].EXONERADO;
                    RBL.MTO_INA = RBL.MTO_INA + DBList[i].INAFECTO;
                    RBL.MTO_OCA = RBL.MTO_OCA + DBList[i].OCARGOS;

                    // IMPUESTOS
                    RBL.IMP_IGV = RBL.IMP_IGV + DBList[i].IGV;
                    RBL.IMP_ISC = RBL.IMP_ISC + DBList[i].ISC;
                    RBL.IMP_OTH = RBL.IMP_OTH + DBList[i].OTH;

                    // TOTAL
                    RBL.MTO_TOT = RBL.MTO_TOT + DBList[i].TOTAL;

                    RBC.MTO_GRA = RBC.MTO_GRA + DBList[i].GRAVADO;
                    RBC.MTO_EXO = RBC.MTO_EXO + DBList[i].EXONERADO;
                    RBC.MTO_INA = RBC.MTO_INA + DBList[i].INAFECTO;
                    RBC.MTO_OCA = RBC.MTO_OCA + DBList[i].OCARGOS;

                    RBC.IMP_IGV = RBC.IMP_IGV + DBList[i].IGV;
                    RBC.IMP_ISC = RBC.IMP_ISC + DBList[i].ISC;
                    RBC.IMP_OTH = RBC.IMP_OTH + DBList[i].OTH;

                    RBC.MTO_TOT = RBC.MTO_TOT + DBList[i].TOTAL;

                    sl++;
                    sa = DBList[i].SERIE;
                    na = DBList[i].NUMERO;
                    ta = DBList[i].TPODOC;
                }
                if (i + 1 == DBList.Count)
                {
                    RBD.Add(RBL); RBL = null;
                }
            }
            return(RBD);
        }
Esempio n. 3
0
        private SummaryDocumentsLineType GetLineRC(RBoletasDetalle det, int i, string typerc)
        {
            detOk  = false;
            HILT_s = new SummaryDocumentsLineType();

            try
            {
                #region alter js

                LineIDType LIT = new LineIDType();
                LIT.Value = (i + 1).ToString();

                HILT_s.LineID = LIT;

                //tipo de documento (03, 07, 08)
                DocumentTypeCodeType DTCT = new DocumentTypeCodeType();
                DTCT.Value = RBD[i].TPO_CPE;
                HILT_s.DocumentTypeCode = DTCT;

                #region condition code

                StatusType        StatusTP  = new StatusType();
                ConditionCodeType Condition = new ConditionCodeType();
                RBD[i].ConditionCode = 0;

                if (RBD[i].ConditionCode == 0)
                {
                    if (typerc != "ANS")
                    {
                        Condition.Value = "1";
                    }
                    else
                    {
                        Condition.Value = "3";
                        #region other
                        //switch (RBD[i].SYSTEM_STATUS)
                        //{
                        //    case "XGN":
                        //        {
                        //            //Condition.Value = "1";
                        //            break;
                        //        }
                        //    case "ANS":
                        //        {
                        //            Condition.Value = "3";
                        //            //var res = ADE.Extras.Common.Method.Methods.Instance.DateCompare(DateTime.Now.ToString("yyyy-MM-dd"), RBD[i].FEC_EMIS.ToString("yyyy-MM-dd"));
                        //            //if (res == 1)
                        //            //{ Condition.Value = "3"; }
                        //            //else
                        //            ////{ Condition.Value = "4"; }
                        //            //{ Condition.Value = "3"; }
                        //            break;
                        //        }
                        //}
                        #endregion
                    }
                    ListDocs.Add(new Extras.Common.Method.UtilClass()
                    {
                        NUM_CE = RBD[i].NUM_CPE, STATUS_RC_DOC = int.Parse(Condition.Value)
                    });
                }


                StatusTP.ConditionCode = Condition;
                HILT_s.Status          = new StatusType();
                HILT_s.Status          = StatusTP;
                #endregion

                //ID (xxxx-xxxxxxxx)
                IDType IdDocumentType = new IDType();
                IdDocumentType.Value = RBD[i].ID;
                HILT_s.ID            = new IDType();
                HILT_s.ID            = IdDocumentType;

                //added js
                AmountType1 TotAmount = new AmountType1();
                TotAmount.Value      = RBD[i].MTO_TOT;
                TotAmount.currencyID = CurrencyCodeContentType.PEN;
                TotAmount.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;
                HILT_s.TotalAmount   = TotAmount;//total documento

                CustomerPartyType CPT = new CustomerPartyType();
                CPT.CustomerAssignedAccountID       = new CustomerAssignedAccountIDType();
                CPT.CustomerAssignedAccountID.Value = RBD[i].CustomerAssignedAccountID;

                AdditionalAccountIDType   AAID  = new AdditionalAccountIDType();
                AdditionalAccountIDType[] AAIDs = new AdditionalAccountIDType[1];

                AAID.Value = RBD[i].AdditionalAccountID;
                AAIDs[0]   = AAID;

                CPT.AdditionalAccountID = AAIDs;

                HILT_s.AccountingCustomerParty = CPT;

                PaymentType[] billingPayment = new PaymentType[4];

                PaymentType       bp_item        = new PaymentType();
                InstructionIDType idInsType      = new InstructionIDType();
                PaidAmountType    paidAmountType = new PaidAmountType();

                #region START - IMPORTES

                // IMPORTES - GRAVADO
                var ImpGravado = Convert.ToDecimal(RBD[i].MTO_GRA, CultureInfo.CreateSpecificCulture("es-PE"));
                if (ImpGravado > 0)
                {
                    bp_item        = new PaymentType();
                    idInsType      = new InstructionIDType();
                    paidAmountType = new PaidAmountType();

                    idInsType.Value      = "01";
                    paidAmountType.Value = Convert.ToDecimal(RBD[i].MTO_GRA, CultureInfo.CreateSpecificCulture("es-PE"));
                    //paidAmountType.currencyID = CurrencyCodeContentType.PEN;
                    paidAmountType.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;

                    bp_item.PaidAmount    = paidAmountType;
                    bp_item.InstructionID = idInsType;

                    billingPayment[0] = bp_item;
                }

                // IMPORTES - EXONERADOS
                var ImpExonerado = Convert.ToDecimal(RBD[i].MTO_EXO, CultureInfo.CreateSpecificCulture("es-PE"));
                if (ImpExonerado > 0)
                {
                    bp_item        = new PaymentType();
                    idInsType      = new InstructionIDType();
                    paidAmountType = new PaidAmountType();

                    idInsType.Value      = "02";
                    paidAmountType.Value = Convert.ToDecimal(RBD[i].MTO_EXO, CultureInfo.CreateSpecificCulture("es-PE"));
                    //paidAmountType.currencyID = CurrencyCodeContentType.PEN;
                    paidAmountType.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;

                    bp_item.PaidAmount    = paidAmountType;
                    bp_item.InstructionID = idInsType;

                    billingPayment[1] = bp_item;
                }

                // IMPORTES - INAFECTO
                var ImpInafecto = Convert.ToDecimal(RBD[i].MTO_INA, CultureInfo.CreateSpecificCulture("es-PE"));
                if (ImpInafecto > 0)
                {
                    bp_item        = new PaymentType();
                    idInsType      = new InstructionIDType();
                    paidAmountType = new PaidAmountType();

                    idInsType.Value      = "03";
                    paidAmountType.Value = Convert.ToDecimal(RBD[i].MTO_INA, CultureInfo.CreateSpecificCulture("es-PE"));
                    //paidAmountType.currencyID = CurrencyCodeContentType.PEN;
                    paidAmountType.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;

                    bp_item.PaidAmount    = paidAmountType;
                    bp_item.InstructionID = idInsType;

                    billingPayment[2] = bp_item;
                }

                // IMPORTES - GRATUITAS
                var ImpGratuitas = Convert.ToDecimal(RBD[i].MON_GRAT, CultureInfo.CreateSpecificCulture("es-PE"));
                if (ImpGratuitas > 0)
                {
                    bp_item        = new PaymentType();
                    idInsType      = new InstructionIDType();
                    paidAmountType = new PaidAmountType();

                    idInsType.Value      = "05";
                    paidAmountType.Value = Convert.ToDecimal(RBD[i].MON_GRAT, CultureInfo.CreateSpecificCulture("es-PE"));
                    //paidAmountType.currencyID = CurrencyCodeContentType.PEN;
                    paidAmountType.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;

                    bp_item.PaidAmount    = paidAmountType;
                    bp_item.InstructionID = idInsType;

                    billingPayment[3] = bp_item;
                }

                HILT_s.BillingPayment = billingPayment;

                // IMPORTES - OTROS CARGOS
                var ImpOtroCargos = Convert.ToDecimal(RBD[i].MTO_OCA, CultureInfo.CreateSpecificCulture("es-PE"));
                if (ImpOtroCargos > 0)
                {
                    AllowanceChargeType[] allowCharge = new AllowanceChargeType[1];
                    AmountType1           AT1         = new AmountType1();

                    ChargeIndicatorType CIT = new ChargeIndicatorType();
                    CIT.Value = true;


                    allowCharge[0] = new AllowanceChargeType();
                    allowCharge[0].ChargeIndicator = new ChargeIndicatorType();

                    allowCharge[0].ChargeIndicator = CIT;

                    AT1       = null; AT1 = new AmountType1();
                    AT1.Value = Convert.ToDecimal(RBD[i].MTO_OCA, CultureInfo.CreateSpecificCulture("es-PE"));
                    //AT1.currencyID = CurrencyCodeContentType.PEN;
                    AT1.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;

                    allowCharge[0].Amount = AT1;

                    HILT_s.AllowanceCharge    = new AllowanceChargeType[1];
                    HILT_s.AllowanceCharge[0] = new AllowanceChargeType();

                    HILT_s.AllowanceCharge[0] = allowCharge[0];
                }

                #endregion END IMPORTES

                #region START IMPUESTOS
                TaxTotalType[] TOTs;// = new TaxTotalType[3];
                TOTs = new TaxTotalType[3];

                TaxTotalType    TOT   = new TaxTotalType();
                TaxAmountType   TAT   = new TaxAmountType();
                TaxSubtotalType TST   = new TaxSubtotalType();
                TaxCategoryType TCT   = new TaxCategoryType();
                TaxSchemeType   TSchT = new TaxSchemeType();

                TaxSubtotalType[] TsTi;// = new TaxSubtotalType[3];


                IDType          IDsch    = new IDType();
                NameType1       nameType = new NameType1();
                TaxTypeCodeType tTCt     = new TaxTypeCodeType();


                //IMP IGV
                //var imp_igv = Convert.ToDecimal(RBD[i].IMP_IGV, CultureInfo.CreateSpecificCulture("es-PE"));
                //if (imp_igv > 0)
                //{
                TOT   = new TaxTotalType();
                TAT   = new TaxAmountType();
                TST   = new TaxSubtotalType();
                TCT   = new TaxCategoryType();
                TSchT = new TaxSchemeType();
                TsTi  = new TaxSubtotalType[1];

                //IDType IDsch = new IDType();
                //NameType1 nameType = new NameType1();
                //TaxTypeCodeType tTCt = new TaxTypeCodeType();

                IDsch    = new IDType();
                nameType = new NameType1();
                tTCt     = new TaxTypeCodeType();

                TAT.Value = Convert.ToDecimal(RBD[i].IMP_IGV, CultureInfo.CreateSpecificCulture("es-PE"));
                //TAT.currencyID = CurrencyCodeContentType.PEN;
                TAT.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;

                IDsch.Value    = "1000";
                nameType.Value = "IGV";
                tTCt.Value     = "VAT";

                TSchT.ID          = IDsch;
                TSchT.Name        = nameType;
                TSchT.TaxTypeCode = tTCt;
                TCT.TaxScheme     = TSchT;
                TST.TaxAmount     = TAT;
                TST.TaxCategory   = TCT;
                TOT.TaxAmount     = TAT;
                TsTi[0]           = TST;

                TOT.TaxSubtotal = TsTi;
                TOTs[0]         = TOT;

                //}

                //IMP ISC
                //var imp_isc = Convert.ToDecimal(RBD[i].IMP_ISC, CultureInfo.CreateSpecificCulture("es-PE"));
                //if (imp_isc > 0)
                //{
                TOT   = new TaxTotalType();
                TAT   = new TaxAmountType();
                TST   = new TaxSubtotalType();
                TCT   = new TaxCategoryType();
                TSchT = new TaxSchemeType();
                TsTi  = new TaxSubtotalType[1];

                //IDType IDsch = new IDType();
                //NameType1 nameType = new NameType1();
                //TaxTypeCodeType tTCt = new TaxTypeCodeType();

                IDsch    = new IDType();
                nameType = new NameType1();
                tTCt     = new TaxTypeCodeType();

                TAT.Value = Convert.ToDecimal(RBD[i].IMP_ISC, CultureInfo.CreateSpecificCulture("es-PE"));
                //TAT.currencyID = CurrencyCodeContentType.PEN;
                TAT.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;

                IDsch.Value    = "2000";
                nameType.Value = "ISC";
                tTCt.Value     = "EXC";

                TSchT.ID          = IDsch;
                TSchT.Name        = nameType;
                TSchT.TaxTypeCode = tTCt;
                TCT.TaxScheme     = TSchT;
                TST.TaxAmount     = TAT;
                TST.TaxCategory   = TCT;
                TOT.TaxAmount     = TAT;
                TsTi[0]           = TST;

                TOT.TaxSubtotal = TsTi;
                TOTs[1]         = TOT;

                //}

                //IMP OTH
                var imp_oth = Convert.ToDecimal(RBD[i].IMP_OTH, CultureInfo.CreateSpecificCulture("es-PE"));
                if (imp_oth > 0)
                {
                    TOT   = new TaxTotalType();
                    TAT   = new TaxAmountType();
                    TST   = new TaxSubtotalType();
                    TCT   = new TaxCategoryType();
                    TSchT = new TaxSchemeType();
                    TsTi  = new TaxSubtotalType[1];

                    //IDType IDsch = new IDType();
                    //NameType1 nameType = new NameType1();
                    //TaxTypeCodeType tTCt = new TaxTypeCodeType();

                    IDsch    = new IDType();
                    nameType = new NameType1();
                    tTCt     = new TaxTypeCodeType();

                    TAT.Value = Convert.ToDecimal(RBD[i].IMP_OTH, CultureInfo.CreateSpecificCulture("es-PE"));
                    //TAT.currencyID = CurrencyCodeContentType.PEN;
                    TAT.currencyID = RBD[i].MONEDA.ToUpper() == "USD" ? CurrencyCodeContentType.USD : CurrencyCodeContentType.PEN;

                    IDsch.Value    = "9999";
                    nameType.Value = "OTROS";
                    tTCt.Value     = "OTH";

                    TSchT.ID          = IDsch;
                    TSchT.Name        = nameType;
                    TSchT.TaxTypeCode = tTCt;
                    TCT.TaxScheme     = TSchT;
                    TST.TaxAmount     = TAT;
                    TST.TaxCategory   = TCT;
                    TOT.TaxAmount     = TAT;
                    TsTi[0]           = TST;

                    TOT.TaxSubtotal = TsTi;
                    TOTs[2]         = TOT;
                }

                HILT_s.TaxTotal = TOTs;

                #endregion END IMPUESTOS

                #region IF NOTE CREDI OR NOTE DEBIT
                if (RBD[i].TPO_CPE.Contains("07") || RBD[i].TPO_CPE.Contains("08"))
                {
                    string[] array_tpodoc_afec = RBD[i].TPO_DOC_AFEC.Split(',');
                    string[] array_nrodoc_afec = RBD[i].NRO_DOC_AFEC.Split(',');
                    if (array_tpodoc_afec.Length == array_nrodoc_afec.Length)
                    {
                        BillingReferenceType[] BRs    = new BillingReferenceType[array_nrodoc_afec.Length];
                        BillingReferenceType   BR     = new BillingReferenceType();
                        DocumentReferenceType  docRef = new DocumentReferenceType();
                        for (int af = 0; af < array_tpodoc_afec.Length; af++)
                        {
                            BR     = new BillingReferenceType();
                            docRef = new DocumentReferenceType();

                            IDType idref = new IDType();
                            idref.Value = array_nrodoc_afec[af];

                            DocumentTypeCodeType doctyperef = new DocumentTypeCodeType();
                            doctyperef.Value = array_tpodoc_afec[af];

                            docRef.ID = idref;
                            docRef.DocumentTypeCode = doctyperef;

                            BR.InvoiceDocumentReference = docRef;
                            BRs[af] = BR;
                        }
                        HILT_s.BillingReference = BRs;
                    }
                }
                #endregion

                //MILT[i] = HILT;


                #endregion
                detOk = true;
            }
            catch (Exception ex)
            {
                detOk = false;
            }
            return(HILT_s);
        }