Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public SummaryDocumentsLineType[] getSummaryDocumentsLine()
        {
            SummaryDocumentsLineType HILT = new SummaryDocumentsLineType();

            SummaryDocumentsLineType[] MILT = new SummaryDocumentsLineType[RBD.Count];

            for (int i = 0; i < RBD.Count; ++i)
            {
                MILT[i] = new SummaryDocumentsLineType();

                LineIDType LIT = new LineIDType();
                LIT.Value      = (i + 1).ToString();
                MILT[i].LineID = LIT;

                DocumentTypeCodeType DTCT = new DocumentTypeCodeType();
                DTCT.Value = RBD[i].TPO_CPE;
                MILT[i].DocumentTypeCode = DTCT;

                IdentifierType IT = new IdentifierType();
                IT.Value = RBD[i].DOC_SER;
                MILT[i].DocumentSerialID = IT;

                IT       = null; IT = new IdentifierType();
                IT.Value = RBD[i].NUM_INI.ToString();
                MILT[i].StartDocumentNumberID = IT;

                IT       = null; IT = new IdentifierType();
                IT.Value = RBD[i].NUM_FIN.ToString();
                MILT[i].EndDocumentNumberID = IT;

                AmountType1 AT1 = new AmountType1();
                AT1.Value           = RBD[i].MTO_TOT;
                AT1.currencyID      = CurrencyCodeContentType.PEN;
                MILT[i].TotalAmount = AT1;


                // START - IMPORTES
                PaymentType[]  PT = { null, null, null };
                PaidAmountType PAT; InstructionIDType IIT;



                // IMPORTES - GRAVADOS
                var ImpGravados = Convert.ToDecimal(RBD[i].MTO_GRA, CultureInfo.CreateSpecificCulture("es-PE"));
                if (ImpGravados > 0)
                {
                    PAT                 = new PaidAmountType();
                    IIT                 = new InstructionIDType();
                    PT[0]               = new PaymentType();
                    PAT.Value           = Convert.ToDecimal(RBD[i].MTO_GRA, CultureInfo.CreateSpecificCulture("es-PE"));
                    PAT.currencyID      = CurrencyCodeContentType.PEN;
                    IIT.Value           = "01";
                    PT[0].PaidAmount    = PAT;
                    PT[0].InstructionID = IIT;
                    PAT                 = null; IIT = null;
                }

                // IMPORTES - EXONERADOS
                var ImpExonerado = Convert.ToDecimal(RBD[i].MTO_EXO, CultureInfo.CreateSpecificCulture("es-PE"));
                if (ImpExonerado > 0)
                {
                    PAT                 = new PaidAmountType();
                    IIT                 = new InstructionIDType();
                    PT[1]               = new PaymentType();
                    PAT.Value           = Convert.ToDecimal(RBD[i].MTO_EXO, CultureInfo.CreateSpecificCulture("es-PE"));
                    PAT.currencyID      = CurrencyCodeContentType.PEN;
                    IIT.Value           = "02";
                    PT[1].PaidAmount    = PAT;
                    PT[1].InstructionID = IIT;
                    PAT                 = null; IIT = null;
                }


                // IMPORTES - INAFECTO
                var ImpInafecto = Convert.ToDecimal(RBD[i].MTO_INA, CultureInfo.CreateSpecificCulture("es-PE"));
                if (ImpInafecto > 0)
                {
                    PAT                    = new PaidAmountType();
                    IIT                    = new InstructionIDType();
                    PT[2]                  = new PaymentType();
                    PAT.Value              = Convert.ToDecimal(RBD[i].MTO_INA, CultureInfo.CreateSpecificCulture("es-PE"));
                    PAT.currencyID         = CurrencyCodeContentType.PEN;
                    IIT.Value              = "03";
                    PT[2].PaidAmount       = PAT;
                    PT[2].InstructionID    = IIT;
                    PAT                    = null; IIT = null;
                    MILT[i].BillingPayment = PT;
                }

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

                    ChargeIndicatorType CIT = new ChargeIndicatorType();
                    CIT.Value = true;
                    ACT[0].ChargeIndicator = CIT;

                    AT1                     = null; AT1 = new AmountType1();
                    AT1.Value               = Convert.ToDecimal(RBD[i].MTO_OCA, CultureInfo.CreateSpecificCulture("es-PE"));
                    AT1.currencyID          = CurrencyCodeContentType.PEN;
                    ACT[0].Amount           = AT1;
                    MILT[i].AllowanceCharge = ACT;
                }
                // END - IMPORTES

                // START - TAXTOTAL
                TaxTotalType[]    TTP  = { null, null, null };
                TaxAmountType     TAT  = null;
                TaxSubtotalType[] TST  = { null };
                TaxSubtotalType[] TST2 = { null };
                TaxSubtotalType[] TST3 = { null };
                TaxCategoryType   TCT  = null;
                TaxSchemeType     THT  = null;
                IDType            IDT  = null;
                NameType1         TNT1 = null;
                TaxTypeCodeType   TTCT = null;


                // TOTAL IGV
                IDT        = new IDType();
                IDT.Value  = "1000";
                TNT1       = new NameType1();
                TNT1.Value = "IGV";
                TTCT       = new TaxTypeCodeType();
                TTCT.Value = "VAT";

                THT             = new TaxSchemeType();
                THT.ID          = IDT;
                THT.Name        = TNT1;
                THT.TaxTypeCode = TTCT;

                TCT           = new TaxCategoryType();
                TCT.TaxScheme = THT;

                TAT            = new TaxAmountType();
                TAT.currencyID = CurrencyCodeContentType.PEN;
                TAT.Value      = Convert.ToDecimal(RBD[i].IMP_IGV, CultureInfo.CreateSpecificCulture("es-PE"));

                TST[0]             = new TaxSubtotalType();
                TST[0].TaxAmount   = TAT;
                TST[0].TaxCategory = TCT;

                TTP[0]             = new TaxTotalType();
                TTP[0].TaxAmount   = TAT;
                TTP[0].TaxSubtotal = TST;

                TAT = null; TST = null; TCT = null; THT = null; IDT = null; TNT1 = null; TTCT = null;

                // TOTAL ISC
                IDT        = new IDType();
                IDT.Value  = "2000";
                TNT1       = new NameType1();
                TNT1.Value = "ISC";
                TTCT       = new TaxTypeCodeType();
                TTCT.Value = "EXC";

                THT             = new TaxSchemeType();
                THT.ID          = IDT;
                THT.Name        = TNT1;
                THT.TaxTypeCode = TTCT;

                TCT           = new TaxCategoryType();
                TCT.TaxScheme = THT;

                TAT            = new TaxAmountType();
                TAT.currencyID = CurrencyCodeContentType.PEN;
                TAT.Value      = Convert.ToDecimal(RBD[i].IMP_ISC, CultureInfo.CreateSpecificCulture("es-PE"));

                TST2[0]             = new TaxSubtotalType();
                TST2[0].TaxAmount   = TAT;
                TST2[0].TaxCategory = TCT;

                TTP[1]             = new TaxTotalType();
                TTP[1].TaxAmount   = TAT;
                TTP[1].TaxSubtotal = TST2;

                TAT = null; TST = null; TCT = null; THT = null; IDT = null; TNT1 = null; TTCT = null;

                // TOTAL OTH
                IDT        = new IDType();
                IDT.Value  = "9999";
                TNT1       = new NameType1();
                TNT1.Value = "OTROS";
                TTCT       = new TaxTypeCodeType();
                TTCT.Value = "OTH";

                THT             = new TaxSchemeType();
                THT.ID          = IDT;
                THT.Name        = TNT1;
                THT.TaxTypeCode = TTCT;

                TCT           = new TaxCategoryType();
                TCT.TaxScheme = THT;

                TAT            = new TaxAmountType();
                TAT.currencyID = CurrencyCodeContentType.PEN;
                TAT.Value      = Convert.ToDecimal(RBD[i].IMP_OTH, CultureInfo.CreateSpecificCulture("es-PE"));

                TST3[0]             = new TaxSubtotalType();
                TST3[0].TaxAmount   = TAT;
                TST3[0].TaxCategory = TCT;

                TTP[2]             = new TaxTotalType();
                TTP[2].TaxAmount   = TAT;
                TTP[2].TaxSubtotal = TST3;

                TAT = null; TST = null; TCT = null; THT = null; IDT = null; TNT1 = null; TTCT = null;

                MILT[i].TaxTotal = TTP;
                // END - TAXTOTAL
            }
            return(MILT);
        }
        public void SaveImplicitCreatedNorwegianInvoice()
        {
            Func <decimal, AmountType> newAmountType = v => new AmountType {
                Value = v, currencyID = "NOK"
            };
            var taxVAT = new TaxSchemeType {
                ID = "VAT"
            };
            // Create an invoice using global defaults set above
            InvoiceType doc = new InvoiceType
            {
                CustomizationID = "urn:www.cenbii.eu:transaction:biicoretrdm010:ver1.0",
                ProfileID       = "urn:www.cenbii.eu:profile:bii05:ver1.0",
                ID                   = "123456",
                IssueDate            = new DateTime(2009, 11, 12),
                DocumentCurrencyCode = "NOK",
                OrderReference       = new OrderReferenceType {
                    ID = "Prosjekt 13"
                },
                ContractDocumentReference = new DocumentReferenceType[] { new DocumentReferenceType {
                                                                              ID = "K987654321"
                                                                          } },
                AccountingSupplierParty = new SupplierPartyType
                {
                    Party = new PartyType
                    {
                        PartyName = new PartyNameType[] { new PartyNameType {
                                                              Name = "Leverandør"
                                                          } },
                        PostalAddress = new AddressType
                        {
                            Postbox        = "Postboks 123",
                            StreetName     = "Oslogate",
                            BuildingNumber = "1",
                            CityName       = "Oslo",
                            PostalZone     = "0612",
                            Country        = new CountryType {
                                IdentificationCode = "NO"
                            },
                        },
                        PartyTaxScheme = new PartyTaxSchemeType[]
                        {
                            new PartyTaxSchemeType
                            {
                                CompanyID = "NO999999999MVA",
                                TaxScheme = new TaxSchemeType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5153",
                                        schemeAgencyID = "6",
                                        Value          = "VAT"
                                    }
                                }
                            }
                        },
                        PartyLegalEntity = new PartyLegalEntityType[]
                        {
                            new PartyLegalEntityType {
                                CompanyID = "999999999"
                            }
                        },
                        Contact = new ContactType {
                            ID = "O Hansen"
                        },
                    }
                },
                AccountingCustomerParty = new CustomerPartyType
                {
                    Party = new PartyType
                    {
                        PartyIdentification = new [] { new PartyIdentificationType {
                                                           ID = "456789"
                                                       } },
                        PartyName = new [] { new PartyNameType {
                                                 Name = "Kjøper"
                                             } },
                        PostalAddress = new AddressType
                        {
                            StreetName     = "Testveien",
                            BuildingNumber = "1",
                            CityName       = "Frogner",
                            PostalZone     = "2012",
                            Country        = new CountryType {
                                IdentificationCode = "NO"
                            }
                        },
                        PartyLegalEntity = new PartyLegalEntityType[]
                        {
                            new PartyLegalEntityType {
                                CompanyID = "NO888888888MVA"
                            }
                        },
                        Contact = new ContactType {
                            ID = "Arne Bjarne Baluba"
                        }
                    }
                },
                Delivery = new DeliveryType[]
                {
                    new DeliveryType
                    {
                        ActualDeliveryDate = new DateTime(2009, 11, 25),
                        DeliveryLocation   = new LocationType
                        {
                            Address = new AddressType
                            {
                                StreetName     = "Testgata",
                                BuildingNumber = "1",
                                CityName       = "Oslo",
                                PostalZone     = "0112",
                                Country        = new CountryType {
                                    IdentificationCode = "NO"
                                }
                            }
                        }
                    }
                },
                PaymentMeans = new PaymentMeansType[]
                {
                    new PaymentMeansType
                    {
                        PaymentMeansCode      = "31",
                        PaymentDueDate        = new DateTime(2009, 11, 27),
                        PaymentID             = new Ubl2.Udt.IdentifierType[] { "1234561" },
                        PayeeFinancialAccount = new FinancialAccountType
                        {
                            ID = "NO9386011117947",
                            FinancialInstitutionBranch = new BranchType
                            {
                                ID = new IdentifierType {
                                    schemeID = "BIC", Value = "DNBANOKK"
                                },
                            }
                        }
                    }
                },
                TaxTotal = new TaxTotalType[]
                {
                    new TaxTotalType
                    {
                        TaxAmount   = newAmountType(962.0M),
                        TaxSubtotal = new TaxSubtotalType[]
                        {
                            new TaxSubtotalType
                            {
                                TaxableAmount = newAmountType(3400.0M),
                                TaxAmount     = newAmountType(850.0M),
                                TaxCategory   = new TaxCategoryType
                                {
                                    ID        = "S",
                                    Percent   = 25.0M,
                                    TaxScheme = taxVAT
                                }
                            },
                            new TaxSubtotalType
                            {
                                TaxableAmount = newAmountType(800.0M),
                                TaxAmount     = newAmountType(112.0M),
                                TaxCategory   = new TaxCategoryType
                                {
                                    ID        = "AA",
                                    Percent   = 8.0M,
                                    TaxScheme = taxVAT
                                }
                            }
                        }
                    }
                },
                LegalMonetaryTotal = new MonetaryTotalType
                {
                    LineExtensionAmount = newAmountType(4200.0M),
                    TaxExclusiveAmount  = newAmountType(4200.0M),
                    TaxInclusiveAmount  = newAmountType(5162.0M),
                    PayableAmount       = newAmountType(5162.0M)
                },
                InvoiceLine = new InvoiceLineType[]
                {
                    new InvoiceLineType
                    {
                        ID = "1",
                        InvoicedQuantity = new  Ubl2.Udt.QuantityType {
                            unitCode = "NMP", Value = 2
                        },
                        LineExtensionAmount = newAmountType(400.0M),
                        AccountingCost      = "200500600",
                        OrderLineReference  = new OrderLineReferenceType[]
                        {
                            new OrderLineReferenceType {
                                LineID = "5"
                            }
                        },
                        TaxTotal = new TaxTotalType[]
                        {
                            new TaxTotalType {
                                TaxAmount = newAmountType(100.0M)
                            }
                        },
                        Item = new ItemType
                        {
                            Name = "Testprodukt 1",
                            SellersItemIdentification = new ItemIdentificationType {
                                ID = "12345670"
                            },
                            ClassifiedTaxCategory = new TaxCategoryType[]
                            {
                                new TaxCategoryType
                                {
                                    ID        = "S",
                                    Percent   = 25.0M,
                                    TaxScheme = taxVAT
                                }
                            }
                        },
                        Price = new PriceType {
                            PriceAmount = newAmountType(200.0M)
                        }
                    },
                    new InvoiceLineType
                    {
                        ID = "2",
                        InvoicedQuantity = new QuantityType {
                            unitCode = "NAR", Value = 20
                        },
                        LineExtensionAmount = newAmountType(3000.0M),
                        AccountingCost      = "200900600",
                        OrderLineReference  = new OrderLineReferenceType[]
                        {
                            new OrderLineReferenceType {
                                LineID = "7"
                            }
                        },
                        TaxTotal = new TaxTotalType[]
                        {
                            new TaxTotalType {
                                TaxAmount = newAmountType(750.0M)
                            }
                        },
                        Item = new ItemType
                        {
                            Name = "Testprodukt 2",
                            SellersItemIdentification = new ItemIdentificationType {
                                ID = "24683432"
                            },
                            ClassifiedTaxCategory = new TaxCategoryType[]
                            {
                                new TaxCategoryType
                                {
                                    ID        = "S",
                                    Percent   = 25.0M,
                                    TaxScheme = taxVAT
                                }
                            }
                        },
                        Price = new PriceType {
                            PriceAmount = newAmountType(150.0M)
                        }
                    },
                    new InvoiceLineType
                    {
                        ID = "3",
                        InvoicedQuantity = new QuantityType {
                            unitCode = "KGM", Value = 8
                        },
                        LineExtensionAmount = newAmountType(800.0M),
                        AccountingCost      = "200600700",
                        OrderLineReference  = new OrderLineReferenceType[]
                        {
                            new OrderLineReferenceType {
                                LineID = "8"
                            }
                        },
                        TaxTotal = new TaxTotalType[]
                        {
                            new TaxTotalType {
                                TaxAmount = newAmountType(112.0M)
                            }
                        },
                        Item = new ItemType
                        {
                            Name = "Matprodukt 1",
                            SellersItemIdentification = new ItemIdentificationType {
                                ID = "23456785"
                            },
                            ClassifiedTaxCategory = new TaxCategoryType[]
                            {
                                new TaxCategoryType
                                {
                                    ID        = "AA",
                                    Percent   = 8.0M,
                                    TaxScheme = taxVAT
                                }
                            }
                        },
                        Price = new PriceType {
                            PriceAmount = newAmountType(100.0M)
                        }
                    }
                }
            };

            string filename = "SampleImplicitInvoice.xml";

            UblDoc <InvoiceType> .Save(filename, doc);

            // Use schema validation
            string       xmlSchemaFilename = @"..\..\..\UBL-2.1\xsd\maindoc\UBL-Invoice-2.1.xsd";
            string       preloadToAvoidExceptionFilename = @"..\..\..\UBL-2.1\xsd\common\UBL-xmldsig-core-schema-2.1.xsd";
            XmlSchemaSet invoiceSchemaSet = new XmlSchemaSet();

            // invoiceSchemaSet.Add(null, preloadToAvoidExceptionFilename); // bombs out!
            using (XmlTextReader tr = new XmlTextReader(preloadToAvoidExceptionFilename))
            {
                invoiceSchemaSet.Add(XmlSchema.Read(tr, null));
            }
            invoiceSchemaSet.Add(null, xmlSchemaFilename);
            invoiceSchemaSet.Compile();

            XDocument xDoc = XDocument.Load(filename);

            // throw if invalid
            System.Xml.Schema.Extensions.Validate(xDoc, invoiceSchemaSet, null);
        }