Gammern / ubllarsen

.NET C# xml serialization of ubl documents
The Unlicense
13 stars 8 forks source link

Dynamic InvoiceLineType using foreach loop #11

Open Jawed34 opened 2 years ago

Jawed34 commented 2 years ago

I am generating invoice using UblLarsen.Ubl2.InvoiceType() and I need to generate multiple Line Items which comes from database. So I need to iterate the InvoiceLinetype using foreach loop. So how to use foreach loop inside InvoiceLine = new UblLarsen.Ubl2.Cac.InvoiceLineType[] { } block

yasirmadcodres commented 1 year ago

any idea for Dynamic InvoiceLineType using foreach loop I have also experienced this problem any idea pleas talk

Jawed34 commented 1 year ago

// //Read Items Values From Database String SqlStr = String.Format("Select ID,Name,Unit,Currency,Qty,Price,Amount,VAT,Total From UblItems"); DataSet ds = DBConnection.executeQuery(SqlStr, "UblItems"); //Generate Invoice Line Items Invoice.InvoiceLine = new InvoiceLineType[ds.Tables[0].Rows.Count]; foreach (DataRow dr in ds.Tables[0].Rows) { Invoice.InvoiceLine[Convert.ToInt32(ds.Tables[0].Rows.IndexOf(dr))] = new InvoiceLineType() { ID = dr["ID"].ToString(), InvoicedQuantity = new QuantityType() { unitCode = dr["Unit"].ToString(), Value = Convert.ToDecimal(dr["Qty"]) }, LineExtensionAmount = new AmountType() { currencyID = dr["Currency"].ToString(), Value = Convert.ToDecimal(dr["Amount"]) }, TaxTotal = new TaxTotalType[] { new TaxTotalType() { TaxAmount = new AmountType() { currencyID =dr["Currency"].ToString(), Value = Convert.ToDecimal(dr["VAT"]) }, RoundingAmount = new AmountType() { currencyID =dr["Currency"].ToString(), Value =Convert.ToDecimal(dr["Total"]) } } }, Item = new ItemType() { Name = dr["Name"].ToString(), ClassifiedTaxCategory = new TaxCategoryType[] { new TaxCategoryType() { ID = "S", Percent = 15, TaxScheme = new TaxSchemeType() { ID ="VAT" } } } }, Price = new PriceType() { PriceAmount = new AmountType() { currencyID = dr["Currency"].ToString(), Value = Convert.ToDecimal(dr["Price"]) } } }; }

yasirmadcodres commented 1 year ago

Thank so much sir

On Thu, Oct 27, 2022 at 7:49 PM Jawed Iqbal @.***> wrote:

// //Read Items Values From Database String SqlStr = String.Format("Select ID,Name,Unit,Currency,Qty,Price,Amount,VAT,Total From UblItems"); DataSet ds = DBConnection.executeQuery(SqlStr, "UblItems"); //Generate Invoice Line Items Invoice.InvoiceLine = new InvoiceLineType[ds.Tables[0].Rows.Count]; foreach (DataRow dr in ds.Tables[0].Rows) { Invoice.InvoiceLine[Convert.ToInt32(ds.Tables[0].Rows.IndexOf(dr))] = new InvoiceLineType() { ID = dr["ID"].ToString(), InvoicedQuantity = new QuantityType() { unitCode = dr["Unit"].ToString(), Value = Convert.ToDecimal(dr["Qty"]) }, LineExtensionAmount = new AmountType() { currencyID = dr["Currency"].ToString(), Value = Convert.ToDecimal(dr["Amount"]) }, TaxTotal = new TaxTotalType[] { new TaxTotalType() { TaxAmount = new AmountType() { currencyID =dr["Currency"].ToString(), Value = Convert.ToDecimal(dr["VAT"]) }, RoundingAmount = new AmountType() { currencyID =dr["Currency"].ToString(), Value =Convert.ToDecimal(dr["Total"]) } } }, Item = new ItemType() { Name = dr["Name"].ToString(), ClassifiedTaxCategory = new TaxCategoryType[] { new TaxCategoryType() { ID = "S", Percent = 15, TaxScheme = new TaxSchemeType() { ID ="VAT" } } } }, Price = new PriceType() { PriceAmount = new AmountType() { currencyID = dr["Currency"].ToString(), Value = Convert.ToDecimal(dr["Price"]) } } }; }

— Reply to this email directly, view it on GitHub https://github.com/Gammern/ubllarsen/issues/11#issuecomment-1293597209, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXC26GKFQVUTZW4YQCC5JDWFKFO3ANCNFSM5POPFTWA . You are receiving this because you commented.Message ID: @.***>