private List <InvoiceItemInfo> GetInvoiceItems() { var a = GlobalObjInvoiceItemInfo; var ListObjInvoiceItemInfo = new List <InvoiceItemInfo>(); DataTable dt = new DataTable(); dt = idDgvInvoice.DataSource as DataTable; for (var i = 0; i < dt.Rows.Count; i++) { var tempList = new InvoiceItemInfo(); if (GlobalObjInvoiceItemInfo != null) { if (i < GlobalObjInvoiceItemInfo.Count) { tempList.InvoiceId = GlobalObjInvoiceItemInfo[i].Id; } } tempList.Item = dt.Rows[i]["Item"].ToString(); tempList.HSN = dt.Rows[i]["HSN"].ToString(); tempList.Quantity = dt.Rows[i]["Quantity"].ToString(); tempList.UOM = dt.Rows[i]["UOM"].ToString(); tempList.TaxableAmount = dt.Rows[i]["TaxableAmount"].ToString(); tempList.SGST = dt.Rows[i]["SGST(Rs)"].ToString(); tempList.CGST = dt.Rows[i]["CGST(Rs)"].ToString(); tempList.IGST = dt.Rows[i]["IGST(Rs)"].ToString(); tempList.TotalAmount = dt.Rows[i]["TotalAmount"].ToString(); ListObjInvoiceItemInfo.Add(tempList); } return(ListObjInvoiceItemInfo); }
/// <summary> /// This routine adds the dynamic data to the invoice: /// </summary> protected void FillContent() { // Fill address in address text frame // XPathNavigator item = SelectItem("/invoice/to"); Paragraph paragraph = _addressFrame.AddParagraph(); paragraph.AddText(@"name/singleName"); paragraph.AddLineBreak(); paragraph.AddText(@"address/line1"); paragraph.AddLineBreak(); paragraph.AddText("address/postalCode address/city"); // Iterate the invoice items double totalExtendedPrice = 0; //XPathNodeIterator iter = this.navigator.Select("/invoice/items/*"); var iter = _invoiceList.GetEnumerator(); while (iter.MoveNext()) { InvoiceItemInfo item = (InvoiceItemInfo)iter.Current; // Each item fills two rows Row row1 = _table.AddRow(); Row row2 = _table.AddRow(); row1.TopPadding = 1.5; row1.Cells[0].Shading.Color = TABLE_GRAY_COLOR; row1.Cells[0].VerticalAlignment = VerticalAlignment.Center; row1.Cells[0].MergeDown = 1; row1.Cells[1].Format.Alignment = ParagraphAlignment.Left; row1.Cells[1].MergeRight = 3; row1.Cells[5].Shading.Color = TABLE_GRAY_COLOR; row1.Cells[5].MergeDown = 1; row1.Cells[0].AddParagraph(item.itemNumber.ToString()); // itemNumber paragraph = row1.Cells[1].AddParagraph(); paragraph.AddFormattedText(item.title); // title paragraph.AddFormattedText(" by ", TextFormat.Italic); paragraph.AddText(item.author); // author row2.Cells[1].AddParagraph(item.quantity.ToString()); // quantity row2.Cells[2].AddParagraph(item.price.ToString("0.00") + " €"); // price row2.Cells[3].AddParagraph(item.discount.ToString("0.0")); // discount row2.Cells[4].AddParagraph(); //row2.Cells[5].AddParagraph(item.price.ToString("0.00")); // price double extendedPrice = item.quantity * item.price; extendedPrice = extendedPrice * (100 - item.discount) / 100; row1.Cells[5].AddParagraph(extendedPrice.ToString("0.00") + " €"); // Extended Price row1.Cells[5].VerticalAlignment = VerticalAlignment.Bottom; totalExtendedPrice += extendedPrice; _table.SetEdge(0, _table.Rows.Count - 2, 6, 2, Edge.Box, BorderStyle.Single, 0.75); } // Add an invisible row as a space line to the table Row row = _table.AddRow(); row.Borders.Visible = false; // Add the total price row row = _table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Total Price"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = 4; row.Cells[5].AddParagraph(totalExtendedPrice.ToString("0.00") + " €"); // Add the VAT row row = _table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("VAT (19%)"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = 4; row.Cells[5].AddParagraph((0.19 * totalExtendedPrice).ToString("0.00") + " €"); // Add the additional fee row row = _table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Shipping and Handling"); row.Cells[5].AddParagraph(0.ToString("0.00") + " €"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = 4; // Add the total due row row = _table.AddRow(); row.Cells[0].AddParagraph("Total Due"); row.Cells[0].Borders.Visible = false; row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = 4; totalExtendedPrice += 0.19 * totalExtendedPrice; row.Cells[5].AddParagraph(totalExtendedPrice.ToString("0.00") + " €"); // Set the borders of the specified cell range _table.SetEdge(5, _table.Rows.Count - 4, 1, 4, Edge.Box, BorderStyle.Single, 0.75); // Add the notes paragraph paragraph = _document.LastSection.AddParagraph(); paragraph.Format.SpaceBefore = "1cm"; paragraph.Format.Borders.Width = 0.75; paragraph.Format.Borders.Distance = 3; paragraph.Format.Borders.Color = TABLE_BLUE_COLOR; paragraph.Format.Shading.Color = TABLE_GRAY_COLOR; paragraph.AddText(@"This is a sample invoice created with MigraDoc. The PDF document is rendered with PDFsharp."); }