public void terbilang_With_Belasan_Return_Success() { var result = NumberToTextIDN.terbilang(16); Assert.NotEmpty(result); Assert.Equal("Enam belas", result); }
public void terbilangKoma_Return_Success() { var result = NumberToTextIDN.terbilangKoma(1000); Assert.NotEmpty(result); Assert.Equal("koma Satu Nol Nol Nol", result); }
public void terbilang_With_Ribuan_Return_Success() { var result = NumberToTextIDN.terbilang(1000); Assert.NotEmpty(result); Assert.Equal("Seribu", result); }
public void terbilang_With_Puluhan_Return_Success() { var result = NumberToTextIDN.terbilang(9); Assert.NotEmpty(result); Assert.Equal("Sembilan", result); }
public void TerbilangKoma_MoreThan_4_Decimal() { float number = 10.00069f; var terbilangKoma = NumberToTextIDN.terbilangKoma(number); Assert.Equal("koma Nol Nol Nol Tujuh", terbilangKoma); }
private string Nom(decimal total, string symbol, string description) { string TotalPaidString; string CurrencySay; if (symbol == "Rp" || symbol.ToUpper() == "IDR") { TotalPaidString = NumberToTextIDN.terbilang((double)total); CurrencySay = "Rupiah"; } else { TotalPaidString = NumberToTextIDN.terbilang((double)total); CurrencySay = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(description.ToLower()); } return(TotalPaidString + " " + CurrencySay); }
public MemoryStream GeneratePdfTemplate(SalesInvoiceViewModel viewModel, int clientTimeZoneOffset) { const int MARGIN = 15; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font Title_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Document document = new Document(PageSize.A4, MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region customViewModel double result = 0; double totalTax = 0; double totalPay = 0; var currencyLocal = ""; if (viewModel.Currency.Symbol == "Rp") { currencyLocal = "Rupiah"; } else if (viewModel.Currency.Symbol == "$") { currencyLocal = "Dollar"; } else { currencyLocal = viewModel.Currency.Symbol; } #endregion #region Header PdfPTable headerTable = new PdfPTable(2); PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(1); PdfPTable headerTable3 = new PdfPTable(2); PdfPTable headerTable4 = new PdfPTable(2); headerTable.SetWidths(new float[] { 10f, 10f }); headerTable.WidthPercentage = 100; headerTable3.SetWidths(new float[] { 20f, 40f }); headerTable3.WidthPercentage = 80; headerTable4.SetWidths(new float[] { 10f, 40f }); headerTable4.WidthPercentage = 100; PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader4 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderCS2 = new PdfPCell() { Border = Rectangle.NO_BORDER, Colspan = 2, HorizontalAlignment = Element.ALIGN_CENTER }; cellHeaderBody.Phrase = new Phrase("PT. DAN LIRIS", Title_bold_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Head Office : Jl. Merapi No. 23 Banaran, Grogol", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Sukoharjo, 57552 Central Java, Indonesia", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Telp :(+62 271) 740888, 714400", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Fax :(+62 271) 740777, 735222", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("PO BOX 116 Solo, 57100", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Web: www.danliris.com", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeader1.AddElement(headerTable1); headerTable.AddCell(cellHeader1); cellHeaderBody2.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody2.Phrase = new Phrase("FM-PJ-00-03-007", bold_font); headerTable2.AddCell(cellHeaderBody2); cellHeaderBody2.Phrase = new Phrase("Sukoharjo, " + viewModel.SalesInvoiceDate?.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); headerTable2.AddCell(cellHeaderBody2); cellHeaderBody2.Phrase = new Phrase("" + viewModel.Buyer.Name, normal_font); headerTable2.AddCell(cellHeaderBody2); cellHeaderBody2.Phrase = new Phrase("" + viewModel.Buyer.Address, normal_font); headerTable2.AddCell(cellHeaderBody2); cellHeader2.AddElement(headerTable2); headerTable.AddCell(cellHeader2); cellHeaderCS2.Phrase = new Phrase("FAKTUR PENJUALAN", header_font); headerTable.AddCell(cellHeaderCS2); cellHeaderCS2.Phrase = new Phrase($"No. {viewModel.SalesInvoiceType}{viewModel.AutoIncreament.ToString().PadLeft(6, '0')}", bold_font); headerTable.AddCell(cellHeaderCS2); cellHeaderCS2.Phrase = new Phrase("", normal_font); headerTable.AddCell(cellHeaderCS2); cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody.Phrase = new Phrase("NPWP ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": 01.139.907.8.532.000", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("NPPKP ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": 01.139.907.8.532.000", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("No Index Debitur ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.Buyer.Code, normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeader3.AddElement(headerTable3); headerTable.AddCell(cellHeader3); cellHeaderBody.Phrase = new Phrase("NIK", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.Buyer.NIK, normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("NPWP Buyer", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.Buyer.NPWP, normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeader4.AddElement(headerTable4); headerTable.AddCell(cellHeader4); cellHeaderCS2.Phrase = new Phrase("", normal_font); headerTable.AddCell(cellHeaderCS2); document.Add(headerTable); #endregion Header #region Body PdfPTable bodyTable = new PdfPTable(7); PdfPCell bodyCell = new PdfPCell(); float[] widthsBody = new float[] { 6f, 22f, 6f, 6f, 10f, 8f, 10f }; bodyTable.SetWidths(widthsBody); bodyTable.WidthPercentage = 100; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase("Kode", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Nama Barang", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Banyak", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Jumlah", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Satuan", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Harga", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("QuantityItem", bold_font); bodyTable.AddCell(bodyCell); foreach (var detail in viewModel.SalesInvoiceDetails) { foreach (var item in detail.SalesInvoiceItems) { bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.ProductCode, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.ProductName, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.QuantityPacking + " " + item.PackingUom, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.QuantityItem.GetValueOrDefault().ToString("N2"), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.ItemUom, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.Price.GetValueOrDefault().ToString("N2"), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.Amount.GetValueOrDefault().ToString("N2"), normal_font); bodyTable.AddCell(bodyCell); } } foreach (var item in viewModel.SalesInvoiceDetails) { foreach (var amount in item.SalesInvoiceItems) { result += amount.Amount.GetValueOrDefault(); } } totalTax = result * 0.1; totalPay = totalTax + result; document.Add(bodyTable); #endregion Body #region Footer var dueDate = viewModel.DueDate.Value.Date; var salesInvoiceDate = viewModel.SalesInvoiceDate.Value.Date; var tempo = (dueDate - salesInvoiceDate).ToString("dd"); CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; string TotalPayWithVat = textInfo.ToTitleCase(NumberToTextIDN.terbilang(totalPay)); string TotalPayWithoutVat = textInfo.ToTitleCase(NumberToTextIDN.terbilang(result)); //string TotalPayWithVat = NumberToTextIDN.terbilang(totalPay); //string TotalPayWithoutVat = NumberToTextIDN.terbilang(result); PdfPTable footerTable = new PdfPTable(2); PdfPTable footerTable1 = new PdfPTable(1); PdfPTable footerTable2 = new PdfPTable(2); PdfPTable footerTable3 = new PdfPTable(2); footerTable.SetWidths(new float[] { 10f, 10f }); footerTable.WidthPercentage = 100; footerTable1.WidthPercentage = 100; footerTable2.SetWidths(new float[] { 10f, 50f }); footerTable2.WidthPercentage = 100; footerTable3.SetWidths(new float[] { 30f, 50f }); footerTable3.WidthPercentage = 100; PdfPCell cellFooterLeft1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterLeft2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterLeft3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderFooter = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderFooter.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Tempo", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + tempo + " Hari", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Jth. Tempo", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.DueDate?.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("SJ No.", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.DeliveryOrderNo, normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellFooterLeft2.AddElement(footerTable2); footerTable.AddCell(cellFooterLeft2); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Dasar pengenaan pajak", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + result.ToString("N2"), normal_font); footerTable3.AddCell(cellHeaderFooter); if (viewModel.VatType.Equals("PPN Umum")) { cellHeaderFooter.Phrase = new Phrase("PPN 10%", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + totalTax.ToString("N2"), normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Jumlah", bold_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + totalPay.ToString("N2"), bold_font); footerTable3.AddCell(cellHeaderFooter); } else if (viewModel.VatType.Equals("PPN Kawasan Berikat")) { cellHeaderFooter.Phrase = new Phrase("PPN", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": Tarif PPN 0% (Berfasilitas)", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Jumlah", bold_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + totalPay.ToString("N2"), bold_font); footerTable3.AddCell(cellHeaderFooter); } else if (viewModel.VatType.Equals("PPN BUMN")) { cellHeaderFooter.Phrase = new Phrase("PPN 10%", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + totalTax.ToString("N2") + " (Dibayar terpisah)", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Jumlah", bold_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + result.ToString("N2"), bold_font); footerTable3.AddCell(cellHeaderFooter); } else if (viewModel.VatType.Equals("PPN Retail")) { cellHeaderFooter.Phrase = new Phrase("PPN 10%", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + totalTax.ToString("N2"), normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Jumlah", bold_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + totalPay.ToString("N2"), bold_font); footerTable3.AddCell(cellHeaderFooter); } else { cellHeaderFooter.Phrase = new Phrase("Jumlah", bold_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.Currency.Symbol + " " + result.ToString("N2"), bold_font); footerTable3.AddCell(cellHeaderFooter); } cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable3.AddCell(cellHeaderFooter); cellFooterLeft3.AddElement(footerTable3); footerTable.AddCell(cellFooterLeft3); document.Add(footerTable); cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); if (viewModel.VatType.Equals("PPN Umum")) { cellFooterLeft1.Phrase = new Phrase("Terbilang : " + TotalPayWithVat + " " + currencyLocal, normal_font); footerTable1.AddCell(cellFooterLeft1); } else if (viewModel.VatType.Equals("PPN Kawasan Berikat")) { cellFooterLeft1.Phrase = new Phrase("Terbilang : " + TotalPayWithVat + " " + currencyLocal, normal_font); footerTable1.AddCell(cellFooterLeft1); } else if (viewModel.VatType.Equals("PPN BUMN")) { cellFooterLeft1.Phrase = new Phrase("Terbilang : " + TotalPayWithoutVat + " " + currencyLocal, normal_font); footerTable1.AddCell(cellFooterLeft1); } else if (viewModel.VatType.Equals("PPN Retail")) { cellFooterLeft1.Phrase = new Phrase("Terbilang : " + TotalPayWithVat + " " + currencyLocal, normal_font); footerTable1.AddCell(cellFooterLeft1); } //else //{ // cellFooterLeft1.Phrase = new Phrase("Terbilang : " + TotalPayWithoutVat + " " + currencyLocal, normal_font); // footerTable1.AddCell(cellFooterLeft1); //} cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); cellFooterLeft1.Phrase = new Phrase("Catatan : " + viewModel.Remark, bold_font); footerTable1.AddCell(cellFooterLeft1); cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); PdfPTable signatureTable = new PdfPTable(4); PdfPCell signatureCell = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER }; float[] widthsSignature = new float[] { 6f, 6f, 6f, 6f }; signatureTable.SetWidths(widthsSignature); signatureTable.WidthPercentage = 30; signatureCell.Phrase = new Phrase("Tanda terima :", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Phrase = new Phrase("Dibuat oleh :", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Phrase = new Phrase("Diperiksa oleh :", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Phrase = new Phrase("Disetujui oleh :", normal_font); signatureTable.AddCell(signatureCell); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); footerTable1.AddCell(new PdfPCell(signatureTable)); cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); document.Add(footerTable1); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingLocalPriceCuttingNoteViewModel viewModel, Buyer buyer, int timeoffset) { const int MARGIN = 20; Font header_font_bold_big = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font header_font_bold = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE); Font header_font = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font normal_font = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font normal_font_underlined = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8, Font.UNDERLINE); Font normal_font_bold = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A5.Rotate(), MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region header PdfPTable tableHeader = new PdfPTable(2); tableHeader.WidthPercentage = 100; tableHeader.SetWidths(new float[] { 3f, 2f }); PdfPCell cellHeaderContent1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderContent2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderContent1.AddElement(new Phrase("\n", normal_font)); cellHeaderContent1.AddElement(new Phrase("PT. DAN LIRIS", header_font_bold)); cellHeaderContent1.AddElement(new Phrase("Jl. Merapi No. 23, Kel. Banaran Kec.Grogol Kab. Sukoharjo", normal_font)); cellHeaderContent1.AddElement(new Phrase("Telp : 0271-714400, Fax. 0271-717178", normal_font)); cellHeaderContent1.AddElement(new Phrase("PO. Box. 166 Solo-57100 Indonesia", normal_font)); tableHeader.AddCell(cellHeaderContent1); cellHeaderContent2.AddElement(new Phrase("Sukoharjo, " + viewModel.date.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID")), normal_font)); cellHeaderContent2.AddElement(new Phrase("\n", normal_font)); cellHeaderContent2.AddElement(new Phrase(viewModel.buyer.Name, normal_font)); cellHeaderContent2.AddElement(new Phrase(buyer.Address, normal_font)); tableHeader.AddCell(cellHeaderContent2); document.Add(tableHeader); #endregion #region title Paragraph title = new Paragraph("NOTA POTONGAN", header_font_bold); title.Alignment = Element.ALIGN_CENTER; document.Add(title); Paragraph no = new Paragraph(viewModel.cuttingPriceNoteNo, header_font_bold); no.Alignment = Element.ALIGN_CENTER; document.Add(no); Paragraph location = new Paragraph("SUKOHARJO - JATENG", normal_font_underlined); location.Alignment = Element.ALIGN_RIGHT; document.Add(location); #endregion #region bodyTable PdfPTable tableBody = new PdfPTable(2); tableBody.WidthPercentage = 100; tableBody.SetWidths(new float[] { 5f, 2f }); PdfPCell cellBodyLeft = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellBodyLeftNoBorder = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellBodyRight = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellBodyRightNoBorder = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellBodyCenter = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodyCenter.Phrase = new Phrase("Description", normal_font); tableBody.AddCell(cellBodyCenter); cellBodyCenter.Phrase = new Phrase("Jumlah", normal_font); cellBodyCenter.Colspan = 1; tableBody.AddCell(cellBodyCenter); double totalPrice = 0; foreach (var item in viewModel.items) { cellBodyLeft.Phrase = new Phrase(item.salesNoteNo, normal_font); tableBody.AddCell(cellBodyLeft); cellBodyRight.Phrase = new Phrase(string.Format("{0:n2}", item.cuttingAmount), normal_font); tableBody.AddCell(cellBodyRight); totalPrice += item.includeVat ? item.cuttingAmount * 100 / 110 : item.cuttingAmount; } double ppn = 0; if (viewModel.useVat) { ppn = totalPrice * 0.1; } double finalPrice = totalPrice + ppn; cellBodyRight.Phrase = new Phrase("Dasar Pengenaan Pajak...............Rp.", normal_font); cellBodyRight.Border = Rectangle.NO_BORDER; tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", totalPrice), normal_font); cellBodyRightNoBorder.Border = Rectangle.NO_BORDER; tableBody.AddCell(cellBodyRightNoBorder); cellBodyRight.Phrase = new Phrase("PPN = 10% X Dasar Pengenaan Pajak...Rp.", normal_font); tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", ppn), normal_font); cellBodyRightNoBorder.Border = Rectangle.BOTTOM_BORDER; tableBody.AddCell(cellBodyRightNoBorder); cellBodyRight.Phrase = new Phrase("Jumlah..............................Rp.", normal_font); tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", finalPrice), normal_font); cellBodyRightNoBorder.Border = Rectangle.NO_BORDER; tableBody.AddCell(cellBodyRightNoBorder); tableBody.SpacingAfter = 10; tableBody.SpacingBefore = 5; document.Add(tableBody); #endregion #region footer PdfPTable tableFooter = new PdfPTable(2); tableFooter.WidthPercentage = 100; tableFooter.SetWidths(new float[] { 1.5f, 9f }); PdfPCell cellFooterContent1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterContent2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; string terbilang = NumberToTextIDN.terbilang(Math.Round(finalPrice, 2)); cellFooterContent1.Phrase = (new Phrase("Terbilang :", normal_font)); tableFooter.AddCell(cellFooterContent1); cellFooterContent2.Phrase = (new Phrase(terbilang + " rupiah", normal_font)); tableFooter.AddCell(cellFooterContent2); cellFooterContent1.Phrase = (new Phrase("Catatan :", normal_font)); tableFooter.AddCell(cellFooterContent1); cellFooterContent2.Phrase = (new Phrase(viewModel.remark, normal_font)); tableFooter.AddCell(cellFooterContent2); tableFooter.SpacingAfter = 10; document.Add(tableFooter); #endregion #region sign PdfPTable tableSign = new PdfPTable(5); tableSign.WidthPercentage = 80; tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f }); PdfPCell cellBodySign = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodySign.Phrase = new Phrase("Diterima Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySign.Phrase = new Phrase("Dibuat Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("Diperiksa Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("Disetujui Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySignNoBorder.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(PurchasingDispositionViewModel viewModel, int clientTimeZoneOffset) { Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font small_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font smaller_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font2 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font3 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font bold_font4 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellCenterTopNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellJustifyNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED }; PdfPCell cellJustifyAllNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL }; PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRightMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellLeftMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; Document document = new Document(PageSize.A4, 30, 30, 30, 30); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); //writer.PageEvent = new TextEvents(viewModel.DispositionNo); document.Open(); string fmString = "FM-PB-00-06-011"; Paragraph fm = new Paragraph(fmString, bold_font4) { Alignment = Element.ALIGN_RIGHT }; string titleString = "DISPOSISI PEMBAYARAN"; Paragraph title = new Paragraph(titleString, bold_font4) { Alignment = Element.ALIGN_CENTER }; document.Add(title); bold_font.SetStyle(Font.NORMAL); string NoString = "NO : " + viewModel.DispositionNo; Paragraph dispoNumber = new Paragraph(NoString, bold_font4) { Alignment = Element.ALIGN_CENTER }; dispoNumber.SpacingAfter = 20f; document.Add(dispoNumber); #region Identity PdfPTable tableIdentity = new PdfPTable(5); tableIdentity.SetWidths(new float[] { 5f, 0.5f, 2f, 7f, 4f }); double dpp = 0; foreach (var item in viewModel.Items) { foreach (var detail in item.Details) { dpp += detail.PaidPrice; } } double ppn = (dpp * 0.1); string pph = ""; double pphRate = 0; foreach (var item in viewModel.Items) { if (!item.UseVat) { ppn = 0; } if (item.UseIncomeTax) { pph = item.IncomeTax.name; pphRate = dpp * (Convert.ToDouble(item.IncomeTax.rate) / 100); } break; } //Jumlah dibayar ke Supplier double paidToSupp = dpp + ppn - pphRate; if (viewModel.IncomeTaxBy == "Dan Liris") { paidToSupp = dpp + ppn; } double amount = dpp + ppn; if (viewModel.IncomeTaxBy == "Dan Liris") { amount = dpp + ppn + pphRate; } var payingDisposition = Math.Round((paidToSupp + viewModel.PaymentCorrection + pphRate), 2, MidpointRounding.AwayFromZero); cellLeftNoBorder.SetLeading(13f, 0f); cellLeftNoBorder.Phrase = new Phrase("Mohon Disposisi Pembayaran", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.PaymentMethod + " " + viewModel.Currency.code + " " + $"{payingDisposition.ToString("N", new CultureInfo("id-ID"))}", normal_font); cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase( viewModel.Currency.code + " " + $"{(paidToSupp + viewModel.PaymentCorrection + pphRate).ToString("N", new CultureInfo("id-ID")) }", normal_font); //tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 0; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Terbilang", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{ NumberToTextIDN.terbilang(payingDisposition) }" + " " + viewModel.Currency.description.ToLower(), normal_font); cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Perhitungan :", bold_font3); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Biaya", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code + " " + $"{viewModel.DPP.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("(PPn)", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code + " " + $"{ppn.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Total", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code + " " + $"{(dpp + ppn).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); var pphDanliris = pphRate; if (viewModel.IncomeTaxBy == "Dan Liris") { pphDanliris = 0; } cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("PPh pasal " + pph, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code + " " + $"{pphDanliris.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Jumlah dibayar ke Supplier ", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 2; cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code + " " + $"{(paidToSupp).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Koreksi Bayar", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code + " " + $"{viewModel.PaymentCorrection.ToString("N", new CultureInfo("id-ID"))}", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellSuppLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellSuppMid = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellSuppRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; cellSuppLeft.Phrase = new Phrase("Total dibayar ke Supplier", normal_font); tableIdentity.AddCell(cellSuppLeft); cellSuppMid.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellSuppMid); cellSuppRight.Colspan = 2; cellSuppRight.Phrase = new Phrase(viewModel.Currency.code + " " + $"{(paidToSupp + viewModel.PaymentCorrection).ToString("N", new CultureInfo("id-ID"))}", normal_font); tableIdentity.AddCell(cellSuppRight); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Pembayaran ditransfer ke", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Bank, normal_font); cellLeftNoBorder.Colspan = 3; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Dibayar ke Kas Negara", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code + " " + $"{(pphRate).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellIdentity = new PdfPCell(tableIdentity); tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 15f; document.Add(tableIdentity); #endregion #region Content PdfPTable tableContent = new PdfPTable(8); tableContent.SetWidths(new float[] { 6f, 5f, 4f, 3f, 3f, 2.5f, 2f, 3.5f }); cellCenter.Phrase = new Phrase("Nama Barang", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PR", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PO Eksternal", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Unit", bold_font); tableContent.AddCell(cellCenter); //cellCenter.Phrase = new Phrase("Kategori", bold_font); //tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Quantity", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Satuan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga Satuan", bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); //cellCenter.Phrase = new Phrase("Harga yang dibayar", bold_font); //cellCenter.Colspan = 2; //tableContent.AddCell(cellCenter); double total = 0; double totalPurchase = 0; foreach (PurchasingDispositionItemViewModel item in viewModel.Items) { for (int indexItem = 0; indexItem < item.Details.Count; indexItem++) { PurchasingDispositionDetailViewModel detail = item.Details[indexItem]; //var unitName = detail.Unit._id == "50" ? "WEAVING" : detail.Unit.name; var unitName = ""; var unitId = detail.Unit._id; if (unitId == "50") { unitName = "WEAVING"; } else if (unitId == "35") { unitName = "SPINNING 1"; } else { unitName = detail.Unit.name; } cellLeft.Colspan = 0; cellLeft.Phrase = new Phrase($"{detail.Product.name}", smaller_font); tableContent.AddCell(cellLeft); cellCenter.Colspan = 0; cellCenter.Phrase = new Phrase($"{detail.PRNo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{item.EPONo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{unitName}", smaller_font); tableContent.AddCell(cellCenter); //cellCenter.Phrase = new Phrase($"{detail.Category.name}", smaller_font); //tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase(string.Format("{0:n2}", detail.PaidQuantity), smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.DealUom.unit}", smaller_font); tableContent.AddCell(cellCenter); cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase($"{detail.PricePerDealUnit.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); double subtotalPrice = detail.PaidPrice * detail.PaidQuantity; //cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); //tableContent.AddCell(cellLeftMerge); //cellRightMerge.Phrase = new Phrase($"{detail.PaidPrice.ToString("N", new CultureInfo("id-ID"))}", smaller_font); //tableContent.AddCell(cellRightMerge); total += detail.PaidPrice; totalPurchase += (detail.PricePerDealUnit * detail.DealQuantity); } } //cellRight.Colspan = 8; //cellRight.Phrase = new Phrase("Total Amount", bold_font); //tableContent.AddCell(cellRight); //cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); //tableContent.AddCell(cellLeftMerge); //cellRightMerge.Phrase = new Phrase($"{total.ToString("N", new CultureInfo("id-ID"))}", smaller_font); //tableContent.AddCell(cellRightMerge); PdfPCell cellContent = new PdfPCell(tableContent); // dont remove tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 20f; document.Add(tableContent); #endregion #region note PdfPTable tableNote = new PdfPTable(3); tableNote.SetWidths(new float[] { 4f, 0.5f, 11f }); cellLeftNoBorder.Phrase = new Phrase("Note :", bold_font3); cellLeftNoBorder.Colspan = 4; tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Kategori", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Category.name, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Supplier / Agent", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Supplier.name, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Order Confirmation", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ConfirmationOrderNo, normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase("No Invoice", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(":", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(viewModel.InvoiceNo, normal_font); //tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Proforma", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ProformaNo, normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase("Investasi", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(":", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(viewModel.Investation, normal_font); //tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Mohon dibayar Tanggal", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.PaymentDueDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Perhitungan", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Calculation, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Keterangan", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Remark, normal_font); tableNote.AddCell(cellLeftNoBorder); var ppnPurchase = viewModel.VatValue > 0 ? (totalPurchase * 10 / 100) : 0; cellLeftNoBorder.Phrase = new Phrase("Total Pembelian", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{viewModel.Currency.code}" + " " + $"{(totalPurchase + ppnPurchase).ToString("N", new CultureInfo("id-ID"))}", normal_font); tableNote.AddCell(cellLeftNoBorder); PdfPCell cellNote = new PdfPCell(tableNote); // dont remove tableNote.ExtendLastRow = false; tableNote.SpacingAfter = 20f; document.Add(tableNote); #endregion #region signature PdfPTable tableSignature = new PdfPTable(4); tableSignature.SetWidths(new float[] { 4f, 4f, 4f, 4.1f }); PdfPCell cellSignatureContent = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellSignatureContent.Phrase = new Phrase("", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("", bold_font3); cellSignatureContent.Colspan = 2; tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 0; cellSignatureContent.Phrase = new Phrase("Sukoharjo, " + viewModel.CreatedUtc.ToString("dd MMMM yyyy", new CultureInfo("id-ID")), bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("Menyetujui,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("Mengetahui,", bold_font3); cellSignatureContent.Colspan = 2; tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 0; cellSignatureContent.Phrase = new Phrase("Hormat Kami,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove tableSignature.ExtendLastRow = false; tableSignature.SpacingBefore = 20f; tableSignature.SpacingAfter = 20f; document.Add(tableSignature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public static MemoryStream GeneratePdfTemplate(FormInsert model, int clientTimeZoneOffset) { const int MARGIN = 20; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Document document = new Document(PageSize.A4, MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region Header PdfPTable headerTable = new PdfPTable(2); headerTable.SetWidths(new float[] { 10f, 10f }); headerTable.WidthPercentage = 100; PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(2); headerTable2.SetWidths(new float[] { 15f, 40f }); headerTable2.WidthPercentage = 100; PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderCS2 = new PdfPCell() { Border = Rectangle.NO_BORDER, Colspan = 2 }; cellHeaderCS2.Phrase = new Phrase("BUKTI PENGELUARAN BANK PPH", bold_font); cellHeaderCS2.HorizontalAlignment = Element.ALIGN_CENTER; headerTable.AddCell(cellHeaderCS2); cellHeaderBody.Phrase = new Phrase("PT. DANLIRIS", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Kel. Banaran, Kec. Grogol", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Sukoharjo - 57100", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeader1.AddElement(headerTable1); headerTable.AddCell(cellHeader1); cellHeaderCS2.Phrase = new Phrase("", bold_font); headerTable2.AddCell(cellHeaderCS2); cellHeaderBody.Phrase = new Phrase("Tanggal", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + DateTimeOffset.UtcNow.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy"), normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("NO", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + model.PphBankInvoiceNo, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Pasal PPH", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + model.IncomeTax.Name, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Bank", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + model.Bank.BankName + " " + model.Bank.Currency.Code + " - A/C : " + model.Bank.AccountName + " " + model.Bank.AccountNumber, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeader2.AddElement(headerTable2); headerTable.AddCell(cellHeader2); document.Add(headerTable); document.Add(new Paragraph("\n")); #endregion Header #region Body PdfPTable bodyTable = new PdfPTable(7); PdfPCell bodyCell = new PdfPCell(); float[] widthsBody = new float[] { 5f, 12f, 10f, 5f, 5f, 15f, 15f }; bodyTable.SetWidths(widthsBody); bodyTable.WidthPercentage = 100; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Colspan = 1; bodyCell.Rowspan = 2; bodyCell.Phrase = new Phrase("No.", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 4; bodyCell.Rowspan = 1; bodyCell.Phrase = new Phrase("Uraian", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.Rowspan = 2; bodyCell.Phrase = new Phrase("PPH (" + model.IncomeTax.Rate + "%)", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("DPP", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.Rowspan = 1; bodyCell.Phrase = new Phrase("No. NI", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Supplier", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Unit", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Mata Uang", normal_font); bodyTable.AddCell(bodyCell); int index = 1; double totalDPP = model.PPHBankExpenditureNoteItems.SelectMany(s => s.Items).Sum(s => s.TotalAmount.GetValueOrDefault()); double totalPPH = model.PPHBankExpenditureNoteItems.SelectMany(s => s.Items).Sum(s => s.TotalIncomeTax); Dictionary <string, double> units = new Dictionary <string, double>(); model.PPHBankExpenditureNoteItems = model.PPHBankExpenditureNoteItems.OrderBy(p => p.SupplierName).ToList(); foreach (FormAdd item in model.PPHBankExpenditureNoteItems) { //var pdeItems = item.Items // .GroupBy(m => new { m.UnitCode, m.UnitName }) // .Select(s => new // { // UnitCode = s.First().UnitCode, // UnitName = s.First().UnitName, // TotalDPP = s.Sum(d => d.Price), // TotalPPH = (s.Sum(d => d.Price) * model.IncomeTaxRate) / 100 // }); //foreach (var pdeItem in pdeItems) //{ bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.VerticalAlignment = Element.ALIGN_TOP; bodyCell.Phrase = new Phrase((index++).ToString(), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.INNo, normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase(item.SupplierName, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(string.Join(',', item.Items.SelectMany(s => s.Details).Select(s => s.UnitCode).Distinct()), normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase(item.CurrencyCode, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", item.Items.FirstOrDefault().TotalIncomeTax), normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase(string.Format("{0:n4}", item.Items.FirstOrDefault().TotalAmount), normal_font); bodyTable.AddCell(bodyCell); //if (units.ContainsKey(pdeItem.UnitCode)) //{ // units[pdeItem.UnitCode] += pdeItem.TotalPPH; //} //else //{ // units.Add(pdeItem.UnitCode, pdeItem.TotalPPH); //} //totalPPH += pdeItem.TotalPPH; //totalDPP += pdeItem.TotalDPP; //} } bodyCell.Colspan = 3; bodyCell.Border = Rectangle.NO_BORDER; bodyCell.Phrase = new Phrase("", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.Border = Rectangle.RECTANGLE; bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase("Total", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(model.Bank.Currency.Code, bold_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", totalPPH), bold_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", totalDPP), bold_font); bodyTable.AddCell(bodyCell); document.Add(bodyTable); document.Add(new Paragraph("\n")); #endregion Body #region BodyFooter PdfPTable bodyFooterTable = new PdfPTable(6); bodyFooterTable.SetWidths(new float[] { 3f, 8f, 2f, 6f, 10f, 10f }); bodyFooterTable.WidthPercentage = 100; PdfPCell bodyFooterCell = new PdfPCell() { Border = Rectangle.NO_BORDER }; bodyFooterCell.Colspan = 1; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 5; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase("Rincian PPH per bagian:", normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.HorizontalAlignment = Element.ALIGN_RIGHT; foreach (var unit in units) { bodyFooterCell.Colspan = 1; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(unit.Key, normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(model.Bank.Currency.Code, normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(string.Format("{0:n4}", unit.Value), normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 2; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); } bodyFooterCell.Colspan = 1; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase("Terbilang", normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyFooterCell.Phrase = new Phrase(": " + model.Bank.Currency.Code, normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 3; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase(NumberToTextIDN.terbilang(totalPPH), normal_font); bodyFooterTable.AddCell(bodyFooterCell); document.Add(bodyFooterTable); document.Add(new Paragraph("\n")); #endregion BodyFooter #region Footer PdfPTable footerTable = new PdfPTable(2); PdfPCell cellFooter = new PdfPCell() { Border = Rectangle.NO_BORDER }; float[] widthsFooter = new float[] { 10f, 5f }; footerTable.SetWidths(widthsFooter); footerTable.WidthPercentage = 100; cellFooter.Phrase = new Phrase("Dikeluarkan dengan cek/BG No. : " + "", normal_font); footerTable.AddCell(cellFooter); cellFooter.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooter); PdfPTable signatureTable = new PdfPTable(3); PdfPCell signatureCell = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER }; signatureCell.Phrase = new Phrase("Bag. Keuangan", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Colspan = 2; signatureCell.HorizontalAlignment = Element.ALIGN_CENTER; signatureCell.Phrase = new Phrase("Direksi", normal_font); signatureTable.AddCell(signatureCell); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, Border = Rectangle.NO_BORDER, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, Border = Rectangle.NO_BORDER, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); footerTable.AddCell(new PdfPCell(signatureTable)); cellFooter.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooter); document.Add(footerTable); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(BankExpenditureNoteModel model, int clientTimeZoneOffset) { const int MARGIN = 15; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A5.Rotate(), MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); Dictionary <string, double> units = new Dictionary <string, double>(); model.Details = model.Details.OrderBy(o => o.SupplierName).ToList(); #region Header PdfPTable headerTable = new PdfPTable(2); headerTable.SetWidths(new float[] { 10f, 10f }); headerTable.WidthPercentage = 100; PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(2); headerTable2.SetWidths(new float[] { 15f, 40f }); headerTable2.WidthPercentage = 100; PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderCS2 = new PdfPCell() { Border = Rectangle.NO_BORDER, Colspan = 2 }; cellHeaderCS2.Phrase = new Phrase("BUKTI PENGELUARAN BANK", bold_font); cellHeaderCS2.HorizontalAlignment = Element.ALIGN_CENTER; headerTable.AddCell(cellHeaderCS2); cellHeaderBody.Phrase = new Phrase("PT. DANLIRIS", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Kel. Banaran, Kec. Grogol", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Sukoharjo - 57100", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeader1.AddElement(headerTable1); headerTable.AddCell(cellHeader1); cellHeaderCS2.Phrase = new Phrase("", bold_font); headerTable2.AddCell(cellHeaderCS2); cellHeaderBody.Phrase = new Phrase("Tanggal", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + DateTimeOffset.UtcNow.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy"), normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("NO", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + model.DocumentNo, normal_font); headerTable2.AddCell(cellHeaderBody); List <string> supplier = model.Details.Select(m => m.SupplierName).Distinct().ToList(); cellHeaderBody.Phrase = new Phrase("Dibayarkan ke", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + (supplier.Count > 0 ? supplier[0] : "-"), normal_font); headerTable2.AddCell(cellHeaderBody); for (int i = 1; i < supplier.Count; i++) { cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + supplier[i], normal_font); headerTable2.AddCell(cellHeaderBody); } cellHeaderBody.Phrase = new Phrase("Bank", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + model.BankAccountName + " - A/C : " + model.BankAccountNumber, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeader2.AddElement(headerTable2); headerTable.AddCell(cellHeader2); cellHeaderCS2.Phrase = new Phrase("", normal_font); headerTable.AddCell(cellHeaderCS2); document.Add(headerTable); #endregion Header #region Body PdfPTable bodyTable = new PdfPTable(7); PdfPCell bodyCell = new PdfPCell(); float[] widthsBody = new float[] { 5f, 10f, 10f, 10f, 8f, 7f, 15f }; bodyTable.SetWidths(widthsBody); bodyTable.WidthPercentage = 100; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase("No.", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("No. SPB", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Kategori Barang", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Divisi", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Unit", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Mata Uang", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Jumlah", bold_font); bodyTable.AddCell(bodyCell); int index = 1; double total = 0; foreach (BankExpenditureNoteDetailModel detail in model.Details) { var items = detail.Items .GroupBy(m => new { m.UnitCode, m.UnitName }) .Select(s => new { s.First().UnitCode, s.First().UnitName, Total = s.Sum(d => detail.Vat == 0 ? d.Price : d.Price * 1.1) }); foreach (var item in items) { bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.VerticalAlignment = Element.ALIGN_TOP; bodyCell.Phrase = new Phrase((index++).ToString(), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(detail.UnitPaymentOrderNo, normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase(detail.CategoryName, normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase(detail.DivisionName, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.UnitCode, normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase(detail.Currency, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", item.Total), normal_font); bodyTable.AddCell(bodyCell); if (units.ContainsKey(item.UnitCode)) { units[item.UnitCode] += item.Total; } else { units.Add(item.UnitCode, item.Total); } total += item.Total; } } bodyCell.Colspan = 4; bodyCell.Border = Rectangle.NO_BORDER; bodyCell.Phrase = new Phrase("", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.Border = Rectangle.BOX; bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase("Total", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(model.BankCurrencyCode, bold_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", total), bold_font); bodyTable.AddCell(bodyCell); document.Add(bodyTable); #endregion Body #region BodyFooter PdfPTable bodyFooterTable = new PdfPTable(6); bodyFooterTable.SetWidths(new float[] { 3f, 6f, 2f, 6f, 10f, 10f }); bodyFooterTable.WidthPercentage = 100; PdfPCell bodyFooterCell = new PdfPCell() { Border = Rectangle.NO_BORDER }; bodyFooterCell.Colspan = 1; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 1; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase("Rincian per bagian:", normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 4; bodyFooterCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); foreach (var unit in units) { bodyFooterCell.Colspan = 1; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(unit.Key, normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(model.BankCurrencyCode, normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(string.Format("{0:n4}", unit.Value), normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 2; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); } bodyFooterCell.Colspan = 1; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase("Terbilang", normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyFooterCell.Phrase = new Phrase(": " + model.BankCurrencyCode, normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 3; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase(NumberToTextIDN.terbilang(total), normal_font); bodyFooterTable.AddCell(bodyFooterCell); document.Add(bodyFooterTable); document.Add(new Paragraph("\n")); #endregion BodyFooter #region Footer PdfPTable footerTable = new PdfPTable(2); PdfPCell cellFooter = new PdfPCell() { Border = Rectangle.NO_BORDER }; float[] widthsFooter = new float[] { 10f, 5f }; footerTable.SetWidths(widthsFooter); footerTable.WidthPercentage = 100; cellFooter.Phrase = new Phrase("Dikeluarkan dengan cek/BG No. : " + model.BGCheckNumber, normal_font); footerTable.AddCell(cellFooter); cellFooter.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooter); PdfPTable signatureTable = new PdfPTable(3); PdfPCell signatureCell = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER }; signatureCell.Phrase = new Phrase("Bag. Keuangan", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Colspan = 2; signatureCell.HorizontalAlignment = Element.ALIGN_CENTER; signatureCell.Phrase = new Phrase("Direksi", normal_font); signatureTable.AddCell(signatureCell); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, Border = Rectangle.NO_BORDER, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, Border = Rectangle.NO_BORDER, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); footerTable.AddCell(new PdfPCell(signatureTable)); cellFooter.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooter); document.Add(footerTable); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public void Should_Success_TerbilangKoma_MoreThan_4_DecimalPlace() { var terbilangKoma = NumberToTextIDN.terbilangKoma(00123); Assert.NotNull(terbilangKoma); }
public void Should_Success_Terbilang_IsNegative_Decimal() { var terbilang = NumberToTextIDN.terbilang(-1.2); Assert.NotNull(terbilang); }
public MemoryStream GeneratePdfTemplate(PaymentDispositionRecapViewModel viewModel, int timeoffset) { const int MARGIN = 20; Font header_font_bold_big = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font header_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9, Font.UNDERLINE); Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8, Font.UNDERLINE); Font normal_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font small_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 6); Font small_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Document document = new Document(PageSize.A4.Rotate(), MARGIN, MARGIN, 40, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new GarmentPaymentDispositionRecapPDFTemplatePageEvent(viewModel.recapNo); document.Open(); #region header Paragraph title = new Paragraph("LAMPIRAN DISPOSISI PEMBAYARAN REKAP EMKL\n\n", header_font_bold); Paragraph title1 = new Paragraph("Kepada : Yth. Bp. Wakid. -Keuangan\n" + "Mohon dibayarkan kepada " + viewModel.emkl.Name + ", " + viewModel.emkl.address + " NPWP " + viewModel.emkl.npwp + "\n\nBiaya kirim sbb:\n\n", normal_font); Paragraph no = new Paragraph(viewModel.recapNo, normal_font_bold); document.Add(title); document.Add(title1); document.Add(no); #endregion #region table PdfPTable tableBody = new PdfPTable(19); tableBody.WidthPercentage = 100; tableBody.SetWidths(new float[] { 0.4f, 1.1f, 0.8f, 1.1f, 1.1f, 1f, 1.8f, 0.6f, 0.5f, 1f, 0.8f, 0.8f, 0.3f, 1f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f }); PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellRightNoLeftBorder = new PdfPCell() { Border = Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellLeftNoRightBorder = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; cellCenter.Phrase = new Phrase("No.", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No. Disposisi", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Tgl Inv/Tagihan", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No Inv/Tagihan", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nomor Faktur Pajak", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Invoice", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Buyer", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Volume", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Unit", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Amount", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Jasa", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("PPH", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Terbayar", small_font); cellCenter.Colspan = 2; tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("1A", small_font); cellCenter.Colspan = 1; tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("1B", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("2A", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("2B", small_font); tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("2C", small_font); tableBody.AddCell(cellCenter); var idx = 0; double total1A = 0; double total1B = 0; double total2A = 0; double total2B = 0; double total2C = 0; foreach (var item in viewModel.items) { total1A += item.paymentDisposition.amountPerUnit.ContainsKey("C1A") ? item.paymentDisposition.amountPerUnit["C1A"] : 0; total1B += item.paymentDisposition.amountPerUnit.ContainsKey("C1B") ? item.paymentDisposition.amountPerUnit["C1B"] : 0; total2A += item.paymentDisposition.amountPerUnit.ContainsKey("C2A") ? item.paymentDisposition.amountPerUnit["C2A"] : 0; total2B += item.paymentDisposition.amountPerUnit.ContainsKey("C2B") ? item.paymentDisposition.amountPerUnit["C2B"] : 0; total2C += item.paymentDisposition.amountPerUnit.ContainsKey("C2C") ? item.paymentDisposition.amountPerUnit["C2C"] : 0; idx++; string invNo = ""; foreach (var detail in item.paymentDisposition.invoiceDetails) { if (invNo != item.paymentDisposition.dispositionNo) { cellCenter.Phrase = new Phrase(idx.ToString(), small_font); tableBody.AddCell(cellCenter); cellLeft.Phrase = new Phrase(item.paymentDisposition.dispositionNo, small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.paymentDisposition.invoiceDate.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMM yy", new System.Globalization.CultureInfo("id-ID")), small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.paymentDisposition.invoiceNumber, small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.paymentDisposition.invoiceTaxNumber, small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(detail.invoiceNo, small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(detail.invoice.BuyerAgent.Name, small_font); tableBody.AddCell(cellLeft); cellRight.Phrase = new Phrase(string.Format("{0:n2}", detail.packingList.totalCBM), small_font); tableBody.AddCell(cellRight); cellLeft.Phrase = new Phrase(string.Join(", ", detail.invoice.items.Select(s => s.unit).Distinct()), small_font); tableBody.AddCell(cellLeft); cellRight.Phrase = new Phrase(item.paymentDisposition.amount.ToString("N0"), small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase(item.service.ToString("N0"), small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase(item.paymentDisposition.incomeTaxValue.ToString("N0"), small_font); tableBody.AddCell(cellRight); cellLeftNoRightBorder.Phrase = new Phrase("Rp ", small_font); tableBody.AddCell(cellLeftNoRightBorder); cellRightNoLeftBorder.Phrase = new Phrase(item.paymentDisposition.paid.ToString("N0"), small_font); tableBody.AddCell(cellRightNoLeftBorder); cellRight.Phrase = new Phrase(item.paymentDisposition.amountPerUnit.ContainsKey("C1A") ? item.paymentDisposition.amountPerUnit["C1A"].ToString("N0") : "", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase(item.paymentDisposition.amountPerUnit.ContainsKey("C1B") ? item.paymentDisposition.amountPerUnit["C1B"].ToString("N0") : "", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase(item.paymentDisposition.amountPerUnit.ContainsKey("C2A") ? item.paymentDisposition.amountPerUnit["C2A"].ToString("N0") : "", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase(item.paymentDisposition.amountPerUnit.ContainsKey("C2B") ? item.paymentDisposition.amountPerUnit["C2B"].ToString("N0") : "", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase(item.paymentDisposition.amountPerUnit.ContainsKey("C2C") ? item.paymentDisposition.amountPerUnit["C2C"].ToString("N0") : "", small_font); tableBody.AddCell(cellRight); } else { cellCenter.Phrase = new Phrase("", small_font); tableBody.AddCell(cellCenter); cellLeft.Phrase = new Phrase("", small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase("", small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase("", small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase("", small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(detail.invoiceNo, small_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(detail.invoice.BuyerAgent.Name, small_font); tableBody.AddCell(cellLeft); cellRight.Phrase = new Phrase(string.Format("{0:n2}", detail.packingList.totalCBM), small_font); tableBody.AddCell(cellRight); cellLeft.Phrase = new Phrase(string.Join(", ", detail.invoice.items.Select(s => s.unit).Distinct()), small_font); tableBody.AddCell(cellLeft); cellRight.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRight); cellLeftNoRightBorder.Phrase = new Phrase("", small_font); tableBody.AddCell(cellLeftNoRightBorder); cellRightNoLeftBorder.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRightNoLeftBorder); cellRight.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase("", small_font); tableBody.AddCell(cellRight); } invNo = item.paymentDisposition.dispositionNo; } } double totalPaid = (double)viewModel.items.Sum(s => s.paymentDisposition.paid); var terbilang = NumberToTextIDN.terbilang(totalPaid) + " rupiah"; decimal totalAmount = viewModel.items.Sum(s => s.paymentDisposition.amount); double totalService = viewModel.items.Sum(s => s.service); decimal totalIncomeTax = viewModel.items.Sum(s => s.paymentDisposition.incomeTaxValue); cellRight.Phrase = new Phrase(totalAmount.ToString("N0"), small_font); cellRight.Colspan = 10; tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase(totalService.ToString("N0"), small_font); cellRight.Colspan = 1; tableBody.AddCell(cellRight); cellRight.Phrase = new Phrase(totalIncomeTax.ToString("N0"), small_font); cellRight.Colspan = 1; tableBody.AddCell(cellRight); cellLeftNoRightBorder.Phrase = new Phrase("Rp", small_font); tableBody.AddCell(cellLeftNoRightBorder); cellRightNoLeftBorder.Phrase = new Phrase(totalPaid.ToString("N0"), small_font); tableBody.AddCell(cellRightNoLeftBorder); cellRight.Phrase = new Phrase("", small_font); cellRight.Colspan = 5; tableBody.AddCell(cellRight); cellLeft.Phrase = new Phrase("Terbilang : " + terbilang, small_font_bold); cellLeft.Colspan = 19; tableBody.AddCell(cellLeft); tableBody.HeaderRows = 1; tableBody.SpacingBefore = 10; document.Add(tableBody); #endregion #region unit PdfPTable tableUnit = new PdfPTable(3); tableUnit.WidthPercentage = 30; tableUnit.SetWidths(new float[] { 1f, 0.2f, 1f }); cellCenter.Phrase = new Phrase("BEBAN UNIT", normal_font_bold); cellCenter.Colspan = 3; tableUnit.AddCell(cellCenter); cellLeft.Phrase = new Phrase("1A", small_font); cellLeft.Colspan = 1; tableUnit.AddCell(cellLeft); cellLeftNoRightBorder.Phrase = new Phrase("Rp", small_font); tableUnit.AddCell(cellLeftNoRightBorder); cellRightNoLeftBorder.Phrase = new Phrase(total1A.ToString("N0"), small_font); tableUnit.AddCell(cellRightNoLeftBorder); cellLeft.Phrase = new Phrase("1B", small_font); tableUnit.AddCell(cellLeft); cellLeftNoRightBorder.Phrase = new Phrase("Rp", small_font); tableUnit.AddCell(cellLeftNoRightBorder); cellRightNoLeftBorder.Phrase = new Phrase(total1B.ToString("N0"), small_font); tableUnit.AddCell(cellRightNoLeftBorder); cellLeft.Phrase = new Phrase("2A", small_font); tableUnit.AddCell(cellLeft); cellLeftNoRightBorder.Phrase = new Phrase("Rp", small_font); tableUnit.AddCell(cellLeftNoRightBorder); cellRightNoLeftBorder.Phrase = new Phrase(total2A.ToString("N0"), small_font); tableUnit.AddCell(cellRightNoLeftBorder); cellLeft.Phrase = new Phrase("2B", small_font); tableUnit.AddCell(cellLeft); cellLeftNoRightBorder.Phrase = new Phrase("Rp", small_font); tableUnit.AddCell(cellLeftNoRightBorder); cellRightNoLeftBorder.Phrase = new Phrase(total2B.ToString("N0"), small_font); tableUnit.AddCell(cellRightNoLeftBorder); cellLeft.Phrase = new Phrase("2C", small_font); tableUnit.AddCell(cellLeft); cellLeftNoRightBorder.Phrase = new Phrase("Rp", small_font); tableUnit.AddCell(cellLeftNoRightBorder); cellRightNoLeftBorder.Phrase = new Phrase(total2C.ToString("N0"), small_font); tableUnit.AddCell(cellRightNoLeftBorder); tableUnit.SpacingAfter = 10; tableUnit.SpacingBefore = 5; tableUnit.HorizontalAlignment = Element.ALIGN_RIGHT; document.Add(tableUnit); #endregion #region sign PdfPTable tableSign = new PdfPTable(4); tableSign.WidthPercentage = 100; tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f }); PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodySignNoBorder.Phrase = new Phrase($"Solo, {DateTimeOffset.Now.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Hormat,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Mengetahui,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Dicek,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Kasir,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(SalesInvoiceViewModel viewModel, int clientTimeZoneOffset) { const int MARGIN = 15; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A4, MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region customViewModel double result = 0; double totalTax = 0; double totalPay = 0; var currencyLocal = ""; if (viewModel.CurrencySymbol == "Rp") { currencyLocal = "Rupiah"; } else if (viewModel.CurrencySymbol == "$") { currencyLocal = "Dollar"; } else { currencyLocal = viewModel.CurrencySymbol; } #endregion #region Header PdfPTable headerTable = new PdfPTable(2); PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(1); PdfPTable headerTable3 = new PdfPTable(2); PdfPTable headerTable4 = new PdfPTable(2); headerTable.SetWidths(new float[] { 10f, 10f }); headerTable.WidthPercentage = 100; headerTable3.SetWidths(new float[] { 20f, 40f }); headerTable3.WidthPercentage = 80; headerTable4.SetWidths(new float[] { 10f, 40f }); headerTable4.WidthPercentage = 100; PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader4 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderCS2 = new PdfPCell() { Border = Rectangle.NO_BORDER, Colspan = 2, HorizontalAlignment = Element.ALIGN_CENTER }; cellHeaderBody.Phrase = new Phrase("PT. DANLIRIS", bold_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Kel. Banaran (Sel. Lawehan), Telp. (0271) -740888, 714400", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Sukoharjo - Indonesia", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeader1.AddElement(headerTable1); headerTable.AddCell(cellHeader1); cellHeaderBody2.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody2.Phrase = new Phrase("FM-PJ-00-03-007", bold_font); headerTable2.AddCell(cellHeaderBody2); cellHeaderBody2.Phrase = new Phrase("Sukoharjo, " + viewModel.SalesInvoiceDate?.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); headerTable2.AddCell(cellHeaderBody2); cellHeaderBody2.Phrase = new Phrase("" + viewModel.BuyerName, normal_font); headerTable2.AddCell(cellHeaderBody2); cellHeaderBody2.Phrase = new Phrase("" + viewModel.BuyerAddress, normal_font); headerTable2.AddCell(cellHeaderBody2); cellHeader2.AddElement(headerTable2); headerTable.AddCell(cellHeader2); cellHeaderCS2.Phrase = new Phrase("FAKTUR PENJUALAN", header_font); headerTable.AddCell(cellHeaderCS2); cellHeaderCS2.Phrase = new Phrase("No. " + viewModel.SalesInvoiceNo, bold_font); headerTable.AddCell(cellHeaderCS2); cellHeaderCS2.Phrase = new Phrase("", normal_font); headerTable.AddCell(cellHeaderCS2); cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody.Phrase = new Phrase("NPWP ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": 01.139.907.8.532.000", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("NPPKP ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": 01.139.907.8.532.000", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("No Index Debitur ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.DebtorIndexNo, normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeader3.AddElement(headerTable3); headerTable.AddCell(cellHeader3); cellHeaderBody.Phrase = new Phrase("NIK", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.IDNo, normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("NPWP Buyer", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.BuyerNPWP, normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable4.AddCell(cellHeaderBody); cellHeader4.AddElement(headerTable4); headerTable.AddCell(cellHeader4); cellHeaderCS2.Phrase = new Phrase("", normal_font); headerTable.AddCell(cellHeaderCS2); document.Add(headerTable); #endregion Header #region Body PdfPTable bodyTable = new PdfPTable(7); PdfPCell bodyCell = new PdfPCell(); float[] widthsBody = new float[] { 5f, 12f, 7f, 7f, 5f, 10f, 10f }; bodyTable.SetWidths(widthsBody); bodyTable.WidthPercentage = 100; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase("Kode", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Nama Barang", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Banyak", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Jumlah", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Sat", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Harga Satuan", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Total", bold_font); bodyTable.AddCell(bodyCell); foreach (SalesInvoiceDetailViewModel item in viewModel.SalesInvoiceDetails) { bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.UnitCode, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.UnitName, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.Quantity + " " + item.UomUnit, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.Total.GetValueOrDefault().ToString("N2"), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase("Yard(s)", normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.UnitPrice.GetValueOrDefault().ToString("N2"), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(item.Amount.ToString("N2"), normal_font); bodyTable.AddCell(bodyCell); } foreach (var amount in viewModel.SalesInvoiceDetails) { result += amount.Amount; } totalTax = result * 0.1; totalPay = totalTax + result; document.Add(bodyTable); #endregion Body #region Footer var dueDate = viewModel.DueDate.Value.Date; var salesInvoiceDate = viewModel.SalesInvoiceDate.Value.Date; var tempo = (dueDate - salesInvoiceDate).ToString("dd"); string TotalPayWithVat = NumberToTextIDN.terbilang(totalPay); string TotalPayWithoutVat = NumberToTextIDN.terbilang(result); PdfPTable footerTable = new PdfPTable(2); PdfPTable footerTable1 = new PdfPTable(1); PdfPTable footerTable2 = new PdfPTable(2); PdfPTable footerTable3 = new PdfPTable(2); footerTable.SetWidths(new float[] { 10f, 10f }); footerTable.WidthPercentage = 100; footerTable1.WidthPercentage = 100; footerTable2.SetWidths(new float[] { 10f, 50f }); footerTable2.WidthPercentage = 100; footerTable3.SetWidths(new float[] { 30f, 50f }); footerTable3.WidthPercentage = 100; PdfPCell cellFooterLeft1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterLeft2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterLeft3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderFooter = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderFooter.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Tempo", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + tempo + " Hari", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Jth. Tempo", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.DueDate?.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("SJ No.", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.DeliveryOrderNo, normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellFooterLeft2.AddElement(footerTable2); footerTable.AddCell(cellFooterLeft2); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Dasar pengenaan pajak", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.CurrencySymbol + " " + result.ToString("N2"), normal_font); footerTable3.AddCell(cellHeaderFooter); if (viewModel.UseVat.Equals(true)) { cellHeaderFooter.Phrase = new Phrase("PPN 10%", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.CurrencySymbol + " " + totalTax.ToString("N2"), normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Jumlah", bold_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.CurrencySymbol + " " + totalPay.ToString("N2"), bold_font); footerTable3.AddCell(cellHeaderFooter); } else { cellHeaderFooter.Phrase = new Phrase("Jumlah", bold_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase(": " + viewModel.CurrencySymbol + " " + result.ToString("N2"), bold_font); footerTable3.AddCell(cellHeaderFooter); } cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable3.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable3.AddCell(cellHeaderFooter); cellFooterLeft3.AddElement(footerTable3); footerTable.AddCell(cellFooterLeft3); document.Add(footerTable); cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); if (viewModel.UseVat.Equals(true)) { cellFooterLeft1.Phrase = new Phrase("Terbilang : " + TotalPayWithVat + " " + currencyLocal, bold_font); footerTable1.AddCell(cellFooterLeft1); } else { cellFooterLeft1.Phrase = new Phrase("Terbilang : " + TotalPayWithoutVat + " " + currencyLocal, bold_font); footerTable1.AddCell(cellFooterLeft1); } cellFooterLeft1.Phrase = new Phrase("Catatan : " + viewModel.Remark, bold_font); footerTable1.AddCell(cellFooterLeft1); cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); PdfPTable signatureTable = new PdfPTable(4); PdfPCell signatureCell = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER }; signatureCell.Phrase = new Phrase("Tanda terima :", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Phrase = new Phrase("Dibuat oleh :", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Phrase = new Phrase("Diperiksa oleh :", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Phrase = new Phrase("Disetujui oleh :", normal_font); signatureTable.AddCell(signatureCell); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); footerTable1.AddCell(new PdfPCell(signatureTable)); cellFooterLeft1.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellFooterLeft1); document.Add(footerTable1); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream Generate(UnitPaymentOrder model, IUnitPaymentOrderFacade facade, int clientTimeZoneOffset = 7, string userName = null) { Font header_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Document document = new Document(PageSize.A5.Rotate(), 15, 15, 15, 15); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellCenterTopNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellJustifyNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED }; PdfPCell cellJustifyAllNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL }; PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRightMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellLeftMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; #region Header PdfPTable tableHeader = new PdfPTable(3); tableHeader.SetWidths(new float[] { 1f, 1f, 1f }); PdfPCell cellHeaderContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderContentLeft.AddElement(new Phrase("PT. MULTIYASA ABADI SENTOSA", header_font)); cellHeaderContentLeft.AddElement(new Phrase("BANARAN, GROGOL, SUKOHARJO", normal_font)); tableHeader.AddCell(cellHeaderContentLeft); PdfPCell cellHeaderContentCenter = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderContentCenter.AddElement(new Paragraph("NOTA KREDIT", header_font) { Alignment = Element.ALIGN_CENTER }); cellHeaderContentCenter.AddElement(new Paragraph(model.PaymentMethod.ToUpper().Trim().Equals("KREDIT") ? "" : model.PaymentMethod, normal_font) { Alignment = Element.ALIGN_CENTER }); tableHeader.AddCell(cellHeaderContentCenter); PdfPCell cellHeaderContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER }; //cellHeaderContentRight.AddElement(new Phrase("FM-PB-00-06-014/R1", normal_font)); cellHeaderContentRight.AddElement(new Phrase($"SUKOHARJO, {model.Date.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font)); cellHeaderContentRight.AddElement(new Phrase($"( {model.SupplierCode} ) {model.SupplierName}", normal_font)); cellHeaderContentRight.AddElement(new Phrase(model.SupplierAddress, normal_font)); tableHeader.AddCell(cellHeaderContentRight); PdfPCell cellHeader = new PdfPCell(tableHeader); tableHeader.ExtendLastRow = false; tableHeader.SpacingAfter = 15f; document.Add(tableHeader); #endregion #region Identity PdfPTable tableIdentity = new PdfPTable(3); tableIdentity.SetWidths(new float[] { 1.5f, 4.5f, 3f }); cellLeftNoBorder.Phrase = new Phrase("Nota Pembelian", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.CategoryName}", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"Nomor {model.UPONo}", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Untuk", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.DivisionName}", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellIdentity = new PdfPCell(tableIdentity); tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 15f; document.Add(tableIdentity); #endregion #region TableContent PdfPTable tableContent = new PdfPTable(10); tableContent.SetWidths(new float[] { 1.3f, 5f, 3f, 1.5f, 3.5f, 1.5f, 3.5f, 4f, 4f, 3f }); cellCenter.Phrase = new Phrase("No.", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nama Barang", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Jumlah", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga Satuan", bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga Total", bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nomor Order", bold_font); cellCenter.Colspan = 0; tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nomor Bon Unit", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Unit", bold_font); tableContent.AddCell(cellCenter); int no = 0; double jumlah = 0; List <DateTimeOffset> DueDates = new List <DateTimeOffset>() { model.DueDate }; List <DateTimeOffset> UnitReceiptNoteDates = new List <DateTimeOffset>() { DateTimeOffset.MinValue }; //foreach (var f in new float[15]) foreach (var item in model.Items) { var unitReceiptNote = facade.GetUnitReceiptNote(item.URNId); var unitReceiptNoteDate = unitReceiptNote.ReceiptDate; UnitReceiptNoteDates.Add(unitReceiptNoteDate); var UnitName = unitReceiptNote.UnitName; foreach (var detail in item.Details) { var PaymentDueDays = facade.GetExternalPurchaseOrder(detail.EPONo).PaymentDueDays; DueDates.Add(unitReceiptNoteDate.AddDays(Double.Parse(PaymentDueDays ?? "0"))); cellCenter.Phrase = new Phrase($"{++no}", normal_font); tableContent.AddCell(cellCenter); cellLeft.Phrase = new Phrase(detail.ProductName, normal_font); tableContent.AddCell(cellLeft); cellCenter.Phrase = new Phrase(string.Format("{0:n2}", detail.ReceiptQuantity) + $" {detail.UomUnit}", normal_font); tableContent.AddCell(cellCenter); cellLeftMerge.Phrase = new Phrase($"{model.CurrencyCode}", normal_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase(string.Format("{0:n4}", detail.PricePerDealUnit), normal_font); tableContent.AddCell(cellRightMerge); cellLeftMerge.Phrase = new Phrase($"{model.CurrencyCode}", normal_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase(string.Format("{0:n2}", detail.PriceTotal), normal_font); tableContent.AddCell(cellRightMerge); cellCenter.Phrase = new Phrase($"{detail.PRNo}", normal_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{item.URNNo}", normal_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{UnitName}", normal_font); tableContent.AddCell(cellCenter); jumlah += detail.PriceTotal; } } PdfPCell cellContent = new PdfPCell(tableContent); tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 10f; document.Add(tableContent); #endregion #region Tax PdfPTable tableTax = new PdfPTable(3); tableTax.SetWidths(new float[] { 1f, 0.3f, 1f }); var ppn = jumlah / 10; var total = jumlah + (model.UseVat ? ppn : 0); var pph = jumlah * model.IncomeTaxRate / 100; var totalWithPph = total - pph; var withoutIncomeTax = true; if (model.UseIncomeTax && model.IncomeTaxBy == "Supplier") { withoutIncomeTax = false; } if (withoutIncomeTax) { tableTax.AddCell(new PdfPCell() { Border = Rectangle.NO_BORDER }); } else { PdfPTable tableIncomeTax = new PdfPTable(3); tableIncomeTax.SetWidths(new float[] { 5f, 2f, 3f }); tableIncomeTax.AddCell(new PdfPCell(new Phrase(" ", normal_font)) { Border = Rectangle.NO_BORDER, Colspan = 3 }); cellLeftNoBorder.Phrase = new Phrase($"PPh {model.IncomeTaxName} {model.IncomeTaxRate} %", normal_font); tableIncomeTax.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.CurrencyCode}", normal_font); tableIncomeTax.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase($"{pph.ToString("n", new CultureInfo("id-ID"))}", normal_font); tableIncomeTax.AddCell(cellRightNoBorder); cellLeftNoBorder.Phrase = new Phrase("Jumlah dibayar Ke Supplier", normal_font); tableIncomeTax.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($": {model.CurrencyCode}", normal_font); tableIncomeTax.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase($"{totalWithPph.ToString("n", new CultureInfo("id-ID"))}", normal_font); tableIncomeTax.AddCell(cellRightNoBorder); tableTax.AddCell(new PdfPCell(tableIncomeTax) { Border = Rectangle.NO_BORDER }); } tableTax.AddCell(new PdfPCell() { Border = Rectangle.NO_BORDER }); PdfPTable tableVat = new PdfPTable(2); cellJustifyAllNoBorder.Phrase = new Phrase($"Jumlah . . . . . . . . . . . . . . . {model.CurrencyCode}", normal_font); tableVat.AddCell(cellJustifyAllNoBorder); cellRightNoBorder.Phrase = new Phrase($"{jumlah.ToString("n", new CultureInfo("id-ID"))}", normal_font); tableVat.AddCell(cellRightNoBorder); if (model.UseVat) { cellJustifyAllNoBorder.Phrase = new Phrase($"PPn 10 % . . . . . . . . . . . . . . {model.CurrencyCode}", normal_font); tableVat.AddCell(cellJustifyAllNoBorder); } else { cellLeftNoBorder.Phrase = new Phrase(string.Concat("PPn 10 %"), normal_font); tableVat.AddCell(cellLeftNoBorder); } cellRightNoBorder.Phrase = new Phrase(model.UseVat ? $"{ppn.ToString("n", new CultureInfo("id-ID"))}" : "-", normal_font); tableVat.AddCell(cellRightNoBorder); cellJustifyAllNoBorder.Phrase = new Phrase($"T O T A L. . . . . . . . . . . . . . {model.CurrencyCode}", normal_font); tableVat.AddCell(cellJustifyAllNoBorder); cellRightNoBorder.Phrase = new Phrase($"{total.ToString("n", new CultureInfo("id-ID"))}", normal_font); tableVat.AddCell(cellRightNoBorder); tableTax.AddCell(new PdfPCell(tableVat) { Border = Rectangle.NO_BORDER }); PdfPCell taxCell = new PdfPCell(tableTax); tableTax.ExtendLastRow = false; tableTax.SpacingAfter = 15f; document.Add(tableTax); #endregion Paragraph paragraphTerbilang = new Paragraph($"Terbilang : {NumberToTextIDN.terbilang(!withoutIncomeTax ? totalWithPph : total)} {model.CurrencyDescription.ToLower()}", bold_font) { SpacingAfter = 15f }; document.Add(paragraphTerbilang); #region Footer PdfPTable tableFooter = new PdfPTable(3); tableFooter.SetWidths(new float[] { 1f, 0.3f, 1f }); PdfPTable tableFooterLeft = new PdfPTable(3); tableFooterLeft.SetWidths(new float[] { 5f, 0.4f, 4.6f }); cellLeftNoBorder.Phrase = new Phrase("Perjanjian Pembayaran", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{DueDates.Max().ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Invoice", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{model.InvoiceNo ?? "-"}, {model.InvoiceDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No PIB", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{model.PibNo ?? "-"}", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Ket.", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{model.Remark ?? "-"}", normal_font); tableFooterLeft.AddCell(cellLeftNoBorder); tableFooter.AddCell(new PdfPCell(tableFooterLeft) { Border = Rectangle.NO_BORDER }); tableFooter.AddCell(new PdfPCell() { Border = Rectangle.NO_BORDER }); PdfPTable tableFooterRight = new PdfPTable(3); tableFooterRight.SetWidths(new float[] { 5f, 0.5f, 6.8f }); cellLeftNoBorder.Phrase = new Phrase("Barang Datang", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); var maxUnitReceiptNoteDate = UnitReceiptNoteDates.Max(); cellLeftNoBorder.Phrase = new Phrase($"{maxUnitReceiptNoteDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Nomor Faktur Pajak PPN", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{model.VatNo ?? "-"}", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Pembayaran", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{model.PaymentMethod ?? "-"}", normal_font); tableFooterRight.AddCell(cellLeftNoBorder); tableFooter.AddCell(new PdfPCell(tableFooterRight) { Border = Rectangle.NO_BORDER }); PdfPCell taxFooter = new PdfPCell(tableFooter); tableFooter.ExtendLastRow = false; tableFooter.SpacingAfter = 30f; document.Add(tableFooter); #endregion #region TableSignature PdfPTable tableSignature = new PdfPTable(4); cellCenterTopNoBorder.Phrase = new Paragraph("Diperiksa,\nVerifkasi\n\n\n\n\n\n\n\n( )", normal_font); tableSignature.AddCell(cellCenterTopNoBorder); cellCenterTopNoBorder.Phrase = new Paragraph("Mengetahui,\nPimpinan Bagian\n\n\n\n\n\n\n\n( )", normal_font); tableSignature.AddCell(cellCenterTopNoBorder); cellCenterTopNoBorder.Phrase = new Paragraph("Tanda Terima,\nBagian Pembelian\n\n\n\n\n\n\n\n( )", normal_font); tableSignature.AddCell(cellCenterTopNoBorder); cellCenterTopNoBorder.Phrase = new Paragraph($"Dibuat Oleh,\n\n\n\n\n\n\n\n\n( {userName ?? " "} )", normal_font); tableSignature.AddCell(cellCenterTopNoBorder); PdfPCell cellSignature = new PdfPCell(tableSignature); tableSignature.ExtendLastRow = false; document.Add(tableSignature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingInsuranceDispositionViewModel viewModel, Insurance insurance, int timeoffset) { const int MARGIN = 20; Font header_font_bold_big = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font header_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12, Font.UNDERLINE); Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE); Font normal_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 120, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region header Paragraph title = new Paragraph("DISPOSISI PEMBAYARAN", header_font_bold_underlined); title.Alignment = Element.ALIGN_CENTER; decimal totalPremi = viewModel.items.Sum(a => a.amount * viewModel.rate / 100); Phrase intro = new Phrase(); intro.Add(new Chunk("Mohon dibayarkan uang sebesar ", normal_font)); intro.Add(new Chunk("USD " + string.Format("{0:n2}", totalPremi), normal_font_bold)); var terbilang = NumberToTextIDN.terbilangDollar((double)totalPremi).Contains("us dolar") ? NumberToTextIDN.terbilangDollar((double)totalPremi) : NumberToTextIDN.terbilangDollar((double)totalPremi) + " us dolar"; intro.Add(new Chunk($" (terbilang : {terbilang}) untuk pembayaran polis asuransi proteksi piutang" + $"dagang ke {viewModel.insurance.Name}.\n", normal_font)); intro.Add(new Chunk("Disposisi no : " + viewModel.dispositionNo, normal_font)); document.Add(title); document.Add(new Paragraph("\n", normal_font)); document.Add(intro); #endregion #region bodyTable PdfPTable tableBody = new PdfPTable(8); tableBody.WidthPercentage = 100; tableBody.SetWidths(new float[] { 3.5f, 2.5f, 3.5f, 2f, 0.2f, 2f, 0.2f, 2f }); PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellCurrency = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellAmount = new PdfPCell() { Border = Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; cellLeft.Phrase = new Phrase("Nomor Polis & Certificate", normal_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase("Tgl Polis", normal_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase("Buyer", normal_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase("Invoice", normal_font); tableBody.AddCell(cellLeft); cellCenter.Phrase = new Phrase("Amount", normal_font); cellCenter.Colspan = 2; tableBody.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Premi", normal_font); tableBody.AddCell(cellCenter); foreach (var item in viewModel.items) { cellLeft.Phrase = new Phrase(item.policyNo, normal_font); cellLeft.Colspan = 1; tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.policyDate.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID")), normal_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.BuyerAgent.Name, normal_font); tableBody.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.invoiceNo, normal_font); tableBody.AddCell(cellLeft); cellCurrency.Phrase = new Phrase("$", normal_font); tableBody.AddCell(cellCurrency); cellAmount.Phrase = new Phrase(string.Format("{0:n2}", item.amount), normal_font); tableBody.AddCell(cellAmount); cellCurrency.Phrase = new Phrase("$", normal_font); tableBody.AddCell(cellCurrency); cellAmount.Phrase = new Phrase(string.Format("{0:n2}", item.amount * viewModel.rate), normal_font); tableBody.AddCell(cellAmount); } cellRight.Phrase = new Phrase("Total Premi", normal_font); cellRight.Colspan = 4; tableBody.AddCell(cellRight); cellCurrency.Phrase = new Phrase("$", normal_font_bold); tableBody.AddCell(cellCurrency); decimal totalAmount = viewModel.items.Sum(a => a.amount); cellAmount.Phrase = new Phrase(string.Format("{0:n2}", totalAmount), normal_font_bold); cellAmount.Colspan = 1; tableBody.AddCell(cellAmount); cellCurrency.Phrase = new Phrase("$", normal_font_bold); tableBody.AddCell(cellCurrency); cellAmount.Phrase = new Phrase(string.Format("{0:n2}", totalPremi), normal_font_bold); tableBody.AddCell(cellAmount); tableBody.SpacingAfter = 10; tableBody.SpacingBefore = 5; document.Add(tableBody); #endregion #region bank Paragraph bank = new Paragraph("Mohon ditransfer ke rekening bank sbb :\n\n", normal_font); document.Add(bank); PdfPTable tableBank = new PdfPTable(3); tableBank.WidthPercentage = 80; tableBank.SetWidths(new float[] { 3f, 0.5f, 14f }); cellLeft.Phrase = new Phrase("AccountName", normal_font); cellLeft.Border = Rectangle.NO_BORDER; tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase(viewModel.insurance.Name, normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase("Bank name", normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase(viewModel.bankName, normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase("Account no.", normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase(insurance.AccountNumber, normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase("Swift code", normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); tableBank.AddCell(cellLeft); cellLeft.Phrase = new Phrase(insurance.SwiftCode, normal_font); tableBank.AddCell(cellLeft); tableBank.SpacingAfter = 10; tableBank.HorizontalAlignment = Element.ALIGN_LEFT; document.Add(tableBank); Paragraph closing = new Paragraph("Demikian permohonan kami, terima kasih.\n\n", normal_font); document.Add(closing); #endregion #region sign Paragraph date = new Paragraph($"Sukoharjo, {DateTimeOffset.Now.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font); document.Add(date); PdfPTable tableSign = new PdfPTable(4); tableSign.WidthPercentage = 100; tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f }); PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodySignNoBorder.Phrase = new Phrase("Hormat kami,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Mengetahui,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Dicek,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Diterima,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("STAFF SHIPPING", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("KABAG/KASIE SHIPPING", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("BAGIAN VERIFIKASI", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("BAGIAN KASIR", normal_font); tableSign.AddCell(cellBodySignNoBorder); document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public void Should_Success_TerbilangKoma_LessThanEqual_4_DecimalPlace() { var terbilangKoma = NumberToTextIDN.terbilangKoma(1004); Assert.NotNull(terbilangKoma); }
public MemoryStream GeneratePdfTemplate(UnitPaymentCorrectionNoteViewModel viewModel, UnitPaymentOrderViewModel viewModelSpb, string username, int clientTimeZoneOffset, DateTimeOffset?receiptDate) { Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 14); Font small_normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 14); Font middle_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font terbilang_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font small_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); double totalPPn = 0; double totalPPh = 0; double totalDibayar = 0; double total = 0; string currencyCodePPn = ""; string currencyCodeTotal = ""; string currencyDesc = ""; //DateTime receiptDate = new DateTime(); Document document = new Document(PageSize.A5.Rotate(), 18, 18, 17, 10); //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()) MemoryStream stream = new MemoryStream(); try { PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region Header //string titleString = "NOTA KOREKSI"; //Paragraph title = new Paragraph(titleString, bold_font) { Alignment = Element.ALIGN_CENTER }; //document.Add(title); //string companyNameString = "PT DAN LIRIS"; //Paragraph companyName = new Paragraph(companyNameString, header_font) { Alignment = Element.ALIGN_LEFT }; //document.Add(companyName); PdfPTable tableHeader = new PdfPTable(3); tableHeader.SetWidths(new float[] { 4f, 5f, 4f }); PdfPCell cellHeaderContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellHeaderContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellHeaderContentCenter = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellHeaderContentLeft.Phrase = new Phrase("PT DAN LIRIS", bold_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentCenter.Phrase = new Phrase("NOTA KOREKSI", bold_font); tableHeader.AddCell(cellHeaderContentCenter); cellHeaderContentRight.Phrase = new Phrase(""); tableHeader.AddCell(cellHeaderContentRight); cellHeaderContentLeft.Phrase = new Phrase("BANARAN, GROGOL, SUKOHARJO", small_normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentCenter.Phrase = new Phrase(viewModel.correctionType, small_normal_font); tableHeader.AddCell(cellHeaderContentCenter); cellHeaderContentLeft.Phrase = new Phrase("FM-PB-00-06-015/R3", terbilang_bold_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(""); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentCenter.Phrase = new Phrase(""); tableHeader.AddCell(cellHeaderContentCenter); cellHeaderContentLeft.Phrase = new Phrase($"SUKOHARJO, {viewModel.correctionDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(""); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentCenter.Phrase = new Phrase(""); tableHeader.AddCell(cellHeaderContentCenter); cellHeaderContentLeft.Phrase = new Phrase("(" + viewModel.supplier.code + ") " + viewModel.supplier.name + "\n" + viewModel.supplier.address, normal_font); tableHeader.AddCell(cellHeaderContentLeft); PdfPCell cellHeader = new PdfPCell(tableHeader); tableHeader.ExtendLastRow = false; tableHeader.SpacingAfter = 1f; document.Add(tableHeader); #endregion #region Identity PdfPTable tableIdentity = new PdfPTable(4); tableIdentity.SetWidths(new float[] { 3f, 7f, 1.3f, 5f }); PdfPCell cellIdentityContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellIdentityContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; cellIdentityContentLeft.Phrase = new Phrase("Retur/Potongan", normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.category.name, normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentRight.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellIdentityContentRight); cellIdentityContentLeft.Phrase = new Phrase($"Nomor : {viewModel.uPCNo}", middle_bold_font); cellIdentityContentLeft.Rowspan = 2; tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase("Untuk", normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.division.name, normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellIdentityContentLeft); //cellIdentityContentLeft.Phrase = new Phrase("No.", normal_font); //tableIdentity.AddCell(cellIdentityContentLeft); //cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.no, normal_font); //tableIdentity.AddCell(cellIdentityContentLeft); PdfPCell cellIdentity = new PdfPCell(tableIdentity); tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 10f; tableIdentity.SpacingBefore = 3f; document.Add(tableIdentity); #endregion #region TableContent PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellRightMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellLeftMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; if (viewModel.correctionType == "Harga Satuan") { PdfPTable tableContent = new PdfPTable(8); tableContent.SetWidths(new float[] { 1f, 6f, 2f, 1.5f, 2f, 1.5f, 2f, 3f }); cellCenter.Phrase = new Phrase("No", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nama Barang", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Jumlah", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga Satuan SPB", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga Baru", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga Koreksi", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nilai Koreksi", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nomor Order", small_bold_font); tableContent.AddCell(cellCenter); //for (int a = 0; a < 20; a++) // coba kalau banyak baris ^_^ for (int indexItem = 0; indexItem < viewModel.items.Count; indexItem++) { UnitPaymentCorrectionNoteItemViewModel item = viewModel.items[indexItem]; var upoDetail = viewModelSpb.items.SelectMany(upoItem => upoItem.unitReceiptNote.items).FirstOrDefault(upoItem => upoItem.Id == item.uPODetailId); if (upoDetail == null) { upoDetail = new UnitPaymentOrderDetailViewModel(); } cellCenter.Phrase = new Phrase((indexItem + 1).ToString(), normal_font); cellCenter.Colspan = 0; tableContent.AddCell(cellCenter); cellLeft.Phrase = new Phrase($"{item.product.code} - {item.product.name}", normal_font); tableContent.AddCell(cellLeft); cellRight.Phrase = new Phrase(string.Format("{0:n2}", item.quantity) + $" {item.uom.unit}", normal_font); tableContent.AddCell(cellRight); cellRight.Phrase = new Phrase($"{item.currency.code} {upoDetail.pricePerDealUnit.ToString("N03", _cultureInfo)}", normal_font); tableContent.AddCell(cellRight); double priceCorrectionUnit = item.pricePerDealUnitAfter; if (viewModel.correctionType == "Harga Satuan") { priceCorrectionUnit = item.pricePerDealUnitAfter - item.pricePerDealUnitBefore; } cellRight.Phrase = new Phrase($"{item.currency.code} {item.pricePerDealUnitAfter.ToString("N03", _cultureInfo)}", normal_font); tableContent.AddCell(cellRight); double priceCorrectionTotal = item.priceTotalAfter; //if (viewModel.correctionType == "Harga Total") //{ // priceCorrectionTotal = item.priceTotalAfter - item.priceTotalBefore; //} //else if (viewModel.correctionType == "Harga Satuan") //{ priceCorrectionTotal = priceCorrectionUnit * item.quantity; //} cellRight.Phrase = new Phrase($"{item.currency.code} {priceCorrectionUnit.ToString("N03", _cultureInfo)}", normal_font); tableContent.AddCell(cellRight); cellRight.Phrase = new Phrase($"{item.currency.code} {priceCorrectionTotal.ToString("N03", _cultureInfo)}", normal_font); tableContent.AddCell(cellRight); cellLeft.Phrase = new Phrase(item.pRNo, normal_font); tableContent.AddCell(cellLeft); currencyCodePPn = item.currency.code; currencyDesc = viewModelSpb.currency.description; currencyCodeTotal = item.currency.code; total += priceCorrectionTotal; } totalPPn = (0.1 * total); double pph = double.Parse(viewModelSpb.incomeTax.rate); totalPPh = (pph * total) / 100; totalDibayar = total - totalPPh; PdfPCell cellContent = new PdfPCell(tableContent); tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 5f; document.Add(tableContent); } else { PdfPTable tableContent = new PdfPTable(7); tableContent.SetWidths(new float[] { 1f, 6f, 0.6f, 2f, 0.6f, 1.5f, 2f }); cellCenter.Phrase = new Phrase("No", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nama Barang", small_bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Total SPB", small_bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nilai Koreksi", small_bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Nomor Order", small_bold_font); tableContent.AddCell(cellCenter); //for (int a = 0; a < 20; a++) // coba kalau banyak baris ^_^ for (int indexItem = 0; indexItem < viewModel.items.Count; indexItem++) { UnitPaymentCorrectionNoteItemViewModel item = viewModel.items[indexItem]; cellCenter.Phrase = new Phrase((indexItem + 1).ToString(), normal_font); cellCenter.Colspan = 0; tableContent.AddCell(cellCenter); cellLeft.Phrase = new Phrase($"{item.product.code} - {item.product.name}", normal_font); tableContent.AddCell(cellLeft); cellLeftMerge.Phrase = new Phrase($"{item.currency.code}", normal_font); tableContent.AddCell(cellLeftMerge); double priceCorrectionUnit = item.pricePerDealUnitAfter; //if (viewModel.correctionType == "Harga Satuan") //{ // priceCorrectionUnit = item.pricePerDealUnitAfter - item.pricePerDealUnitBefore; //} cellRightMerge.Phrase = new Phrase(string.Format("{0:n4}", item.priceTotalBefore), normal_font); tableContent.AddCell(cellRightMerge); cellLeftMerge.Phrase = new Phrase($"{item.currency.code}", normal_font); tableContent.AddCell(cellLeftMerge); double priceCorrectionTotal = item.priceTotalAfter; if (viewModel.correctionType == "Harga Total") { priceCorrectionTotal = item.priceTotalAfter - item.priceTotalBefore; } //else if (viewModel.correctionType == "Harga Satuan") //{ // priceCorrectionTotal = priceCorrectionUnit * item.quantity; //} cellRightMerge.Phrase = new Phrase($"{priceCorrectionTotal.ToString("N", CultureInfo.InvariantCulture)}", normal_font); tableContent.AddCell(cellRightMerge); cellLeft.Phrase = new Phrase(item.pRNo, normal_font); tableContent.AddCell(cellLeft); currencyCodePPn = item.currency.code; currencyDesc = viewModelSpb.currency.description; currencyCodeTotal = item.currency.code; total += priceCorrectionTotal; } totalPPn = (0.1 * total); double pph = double.Parse(viewModelSpb.incomeTax.rate); totalPPh = (pph * total) / 100; totalDibayar = total - totalPPh; PdfPCell cellContent = new PdfPCell(tableContent); tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 5f; document.Add(tableContent); } #endregion #region TableTotal PdfPTable tableTotal = new PdfPTable(7); tableTotal.SetWidths(new float[] { 6f, 2f, 4f, 2f, 3f, 2f, 4f }); PdfPCell cellIdentityTotalContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellIdentityTotalContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellIdentityTotalContentCenter = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase("Jumlah", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase($"{currencyCodePPn}", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentRight.Phrase = new Phrase(total.ToString("N", CultureInfo.InvariantCulture), normal_font); tableTotal.AddCell(cellIdentityTotalContentRight); if (viewModel.useIncomeTax == false) { totalPPh = 0; cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); } else { cellIdentityTotalContentLeft.Phrase = new Phrase($"PPh {viewModelSpb.incomeTax.name} {viewModelSpb.incomeTax.rate} %", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase($"{currencyCodePPn}", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentRight.Phrase = new Phrase(totalPPh.ToString("N", CultureInfo.InvariantCulture), normal_font); tableTotal.AddCell(cellIdentityTotalContentRight); } cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); if (viewModel.useVat == false) { totalPPn = 0; cellIdentityTotalContentLeft.Phrase = new Phrase("PPn 10%", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentRight.Phrase = new Phrase(" - "); tableTotal.AddCell(cellIdentityTotalContentRight); } else { cellIdentityTotalContentLeft.Phrase = new Phrase("PPn 10%", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase($"{currencyCodePPn}", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentRight.Phrase = new Phrase(totalPPn.ToString("N", CultureInfo.InvariantCulture), normal_font); tableTotal.AddCell(cellIdentityTotalContentRight); } if (viewModel.useIncomeTax == false) { cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); } else { cellIdentityTotalContentLeft.Phrase = new Phrase($"Jumlah dibayar Ke Supplier", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase($"{currencyCodePPn}", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentRight.Phrase = new Phrase((total + totalPPn - totalPPh).ToString("N", CultureInfo.InvariantCulture), normal_font); tableTotal.AddCell(cellIdentityTotalContentRight); } cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase("Total", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase($"{currencyCodeTotal}", normal_font); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentRight.Phrase = new Phrase((total + totalPPn).ToString("N", CultureInfo.InvariantCulture), normal_font); tableTotal.AddCell(cellIdentityTotalContentRight); cellIdentityTotalContentLeft.Phrase = new Phrase($"Terbilang : { NumberToTextIDN.terbilang(total + totalPPn - totalPPh)} {currencyDesc.ToLower()}", terbilang_bold_font); if (viewModel.useIncomeTax == false) { cellIdentityTotalContentLeft.Phrase = new Phrase($"Terbilang : { NumberToTextIDN.terbilang(total + totalPPn)} {currencyDesc.ToLower()}", terbilang_bold_font); } cellIdentityTotalContentLeft.Colspan = 3; tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); cellIdentityTotalContentLeft.Phrase = new Phrase(" "); tableTotal.AddCell(cellIdentityTotalContentLeft); //cellIdentityContentLeft.Phrase = new Phrase("No.", normal_font); //tableIdentity.AddCell(cellIdentityContentLeft); //cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.no, normal_font); //tableIdentity.AddCell(cellIdentityContentLeft); PdfPCell cellIdentityTotal = new PdfPCell(tableTotal); tableTotal.ExtendLastRow = false; //tableTotal.SpacingAfter = 1f; tableTotal.SpacingBefore = 2f; document.Add(tableTotal); #endregion #region TableKeterangan PdfPTable tableKeterangan = new PdfPTable(4); tableKeterangan.SetWidths(new float[] { 3f, 4f, 3f, 4f }); PdfPCell cellIdentityKeteranganContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellIdentityKeteranganContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; cellIdentityKeteranganContentLeft.Phrase = new Phrase("Perjanjian Pembayaran ", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase($" : {viewModel.dueDate.GetValueOrDefault().ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase("Barang Datang ", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); DateTimeOffset date = receiptDate != null ? (DateTimeOffset)receiptDate : new DateTime(); cellIdentityKeteranganContentLeft.Phrase = new Phrase($" : {(date.ToString("dd MMMM yyyy", new CultureInfo("id-ID")))} ", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase("Nota ", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase($" : {viewModel.uPONo}", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase("Nomor Nota Retur ", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase($" : {viewModel.returNoteNo}", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase("Keterangan ", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase($" : {viewModel.remark}", small_bold_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase(" ", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase(" ", small_bold_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); cellIdentityKeteranganContentLeft.Phrase = new Phrase("", normal_font); tableKeterangan.AddCell(cellIdentityKeteranganContentLeft); //cellIdentityContentLeft.Phrase = new Phrase("No.", normal_font); //tableIdentity.AddCell(cellIdentityContentLeft); //cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.no, normal_font); //tableIdentity.AddCell(cellIdentityContentLeft); PdfPCell cellIdentityKeterangan = new PdfPCell(tableKeterangan); tableKeterangan.ExtendLastRow = false; tableKeterangan.SpacingAfter = 12f; //tableKeterangan.SpacingBefore = 2f; document.Add(tableKeterangan); #endregion //Paragraph date = new Paragraph($"Sukoharjo, {viewModel.correctionDate.ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font) { Alignment = Element.ALIGN_RIGHT }; //document.Add(date); #region TableSignature PdfPTable tableSignature = new PdfPTable(4); PdfPCell cellSignatureContent = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellSignatureContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; cellSignatureContent.Phrase = new Phrase("Diperiksa,\nVerifikasi\n\n\n\n\n( )", normal_font); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("Mengetahui,\nPimpinan Bagian\n\n\n\n\n( )", normal_font); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("Tanda Terima,\nBagian Pembelian\n\n\n\n\n( )", normal_font); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase($"Dibuat Oleh,\n\n\n\n\n\n( {viewModel.CreatedBy} )", normal_font); tableSignature.AddCell(cellSignatureContent); cellSignatureContentLeft.Phrase = new Phrase($"\n\nDicetak Oleh {username}", normal_font); tableSignature.AddCell(cellSignatureContentLeft); cellSignatureContent.Phrase = new Phrase(" ", normal_font); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase(" ", normal_font); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase(" ", normal_font); tableSignature.AddCell(cellSignatureContent); PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove tableSignature.ExtendLastRow = false; //tableSignature.SpacingBefore = 20f; tableSignature.SpacingAfter = 20f; document.Add(tableSignature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; } catch (Exception e) { throw new Exception(e.Message); } return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingPaymentDispositionViewModel viewModel, int timeoffset) { const int MARGIN = 20; Font header_font_bold_big = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font header_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12, Font.UNDERLINE); Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE); Font normal_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 40, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region header Paragraph title = new Paragraph("LAMPIRAN DISPOSISI PEMBAYARAN COURIER\n\n\n", header_font_bold); title.Alignment = Element.ALIGN_CENTER; Paragraph title1 = new Paragraph("DISPOSISI BIAYA SHIPMENT", normal_font_underlined); Paragraph no = new Paragraph(viewModel.dispositionNo, normal_font); Paragraph title2 = new Paragraph("Kepada : \nBp./Ibu Kasir Exp Garment PT Danliris", normal_font); Paragraph words = new Paragraph($"\nHarap dibayarkan kepada {viewModel.courier.Name} {viewModel.address} " + $"NPWP {viewModel.npwp} untuk tagihan Invoice No. {viewModel.invoiceNumber} Tgl. " + $"{viewModel.invoiceDate.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}" + $" Faktur Pajak No.{viewModel.invoiceTaxNumber} dengan rincian sbb : ", normal_font); document.Add(title); document.Add(title1); document.Add(no); document.Add(title2); document.Add(words); #endregion #region bodyTable PdfPTable tableBody = new PdfPTable(5); tableBody.WidthPercentage = 70; tableBody.SetWidths(new float[] { 3f, 0.5f, 1f, 2.8f, 1f }); PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellLeftNoBorder1 = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellLeftTopBorder = new PdfPCell() { Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRightTopBorder = new PdfPCell() { Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; var last = viewModel.billDetails.Last(); foreach (var bill in viewModel.billDetails) { cellLeftNoBorder.Phrase = new Phrase("- " + bill.billDescription, normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("RP", normal_font); tableBody.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", bill.amount), normal_font); tableBody.AddCell(cellRightNoBorder); if (bill == last) { cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font); tableBody.AddCell(cellLeftNoBorder); } else { cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); } } cellLeftNoBorder.Phrase = new Phrase("- Total Amount", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("RP", normal_font); tableBody.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue), normal_font); tableBody.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"- PPH {viewModel.incomeTax.name} ({viewModel.incomeTax.rate}%)", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font_bold); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("RP", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.IncomeTaxValue), normal_font_bold); tableBody.AddCell(cellRightNoBorder); cellLeftNoBorder.Phrase = new Phrase("(-)", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("RP", normal_font); tableBody.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue - viewModel.IncomeTaxValue), normal_font); tableBody.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("- PPN", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("RP", normal_font); tableBody.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.vatValue), normal_font); tableBody.AddCell(cellRightNoBorder); cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("- Total Bayar", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font_bold); tableBody.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("RP", normal_font_bold); tableBody.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.totalBill), normal_font_bold); tableBody.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); tableBody.SpacingAfter = 10; tableBody.SpacingBefore = 5; tableBody.HorizontalAlignment = Element.ALIGN_LEFT; document.Add(tableBody); var terbilang = NumberToTextIDN.terbilang((double)viewModel.totalBill) + " rupiah"; Paragraph trbilang = new Paragraph($"[ Terbilang : {terbilang} ]\n", normal_font); document.Add(trbilang); #endregion #region bank Paragraph units = new Paragraph("\nBeban Per Unit", normal_font_bold); document.Add(units); PdfPTable tableUnit = new PdfPTable(2); tableUnit.WidthPercentage = 50; tableUnit.SetWidths(new float[] { 1f, 1f }); PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; cellCenter.Phrase = new Phrase("Unit", normal_font_bold); tableUnit.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Amount", normal_font_bold); tableUnit.AddCell(cellCenter); foreach (var unitItem in viewModel.unitCharges) { cellLeft.Phrase = new Phrase(unitItem.unit.Code, normal_font); tableUnit.AddCell(cellLeft); cellRight.Phrase = new Phrase(string.Format("{0:n2}", unitItem.billAmount), normal_font); tableUnit.AddCell(cellRight); } tableUnit.SpacingAfter = 10; tableUnit.SpacingBefore = 5; tableUnit.HorizontalAlignment = Element.ALIGN_LEFT; document.Add(tableUnit); Paragraph closing = new Paragraph("Demikian permohonan kami, terima kasih.\n\n", normal_font); document.Add(closing); #endregion #region sign PdfPTable tableSign = new PdfPTable(4); tableSign.WidthPercentage = 100; tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f }); PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; cellBodySignNoBorder.Phrase = new Phrase($"Terima kasih, \nSolo, {DateTimeOffset.Now.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Hormat kami,\n\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Mengetahui,\n\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Menyetujui,\n\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Dicek oleh,\n\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( Etty / Andrei )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( Adriyana / Amumpuni )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( Hendro Suseno )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( L i a )", normal_font); tableSign.AddCell(cellBodySignNoBorder); document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(SalesReceiptViewModel viewModel, SalesReceiptDetailViewModel detailViewModel, int clientTimeZoneOffset) { const int MARGIN = 20; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font note_font = FontFactory.GetFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_italic_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Document document = new Document(PageSize.A5.Rotate(), MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region CustomModel double convertCurrency = 0; if (detailViewModel.Currency.Symbol == "Rp") { convertCurrency = viewModel.TotalPaid; } else { convertCurrency = (Math.Round((double)viewModel.TotalPaid * (double)detailViewModel.Currency.Rate)); } string TotalPaidString = NumberToTextIDN.terbilang(convertCurrency); #endregion CustomModel #region Header PdfPTable headerTable_A = new PdfPTable(2); PdfPTable headerTable_B = new PdfPTable(1); PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(1); PdfPTable headerTable3 = new PdfPTable(3); PdfPTable headerTable4 = new PdfPTable(2); headerTable_A.SetWidths(new float[] { 10f, 10f }); headerTable_A.WidthPercentage = 100; headerTable3.SetWidths(new float[] { 40f, 4f, 100f }); headerTable3.WidthPercentage = 100; headerTable4.SetWidths(new float[] { 10f, 40f }); headerTable4.WidthPercentage = 100; PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader4 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderBody.Phrase = new Phrase("PT. DANLIRIS", bold_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("INDUSTRIAL & TRADING CO.LTD.", bold_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Kel. Banaran (Selatan Lawehan)", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Telp. 714400, 719113", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("SOLO - INDONESIA 57100", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeader1.AddElement(headerTable1); headerTable_A.AddCell(cellHeader1); cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody.Phrase = new Phrase("", header_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", header_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("KUITANSI", header_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", header_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("No. " + viewModel.SalesReceiptNo, bold_font); headerTable2.AddCell(cellHeaderBody); cellHeader2.AddElement(headerTable2); headerTable_A.AddCell(cellHeader2); document.Add(headerTable_A); cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody.Phrase = new Phrase("Bank ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(viewModel.Bank.BankName + " " + viewModel.Bank.AccountNumber + " (" + detailViewModel.Currency.Code + ")", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Telah terima dari ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(viewModel.Buyer.Name, normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(viewModel.Buyer.Address, normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Banyaknya uang ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("" + TotalPaidString + " Rupiah", bold_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Untuk pembayaran ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); foreach (SalesReceiptDetailViewModel item in viewModel.SalesReceiptDetails) { cellHeaderBody.Phrase = new Phrase(item.SalesInvoiceNo + " ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(" ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(" ", normal_font); headerTable3.AddCell(cellHeaderBody); } cellHeaderBody.Phrase = new Phrase(" ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Terbilang", bold_italic_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", bold_italic_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Rp. " + convertCurrency.ToString("#,##0.00", new CultureInfo("id-ID")), bold_italic_font); headerTable3.AddCell(cellHeaderBody); cellHeader3.AddElement(headerTable3); headerTable_B.AddCell(cellHeader3); cellHeader4.AddElement(headerTable4); headerTable_B.AddCell(cellHeader4); document.Add(headerTable_B); #endregion Header #region Footer PdfPTable footerTable = new PdfPTable(2); PdfPTable footerTable1 = new PdfPTable(1); PdfPTable footerTable2 = new PdfPTable(2); footerTable.SetWidths(new float[] { 10f, 10f }); footerTable.WidthPercentage = 100; footerTable1.WidthPercentage = 80; footerTable2.SetWidths(new float[] { 30f, 50f }); footerTable2.WidthPercentage = 100; PdfPCell cellFooterLeft1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterLeft2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderFooter = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderFooter.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("Solo, " + viewModel.SalesReceiptDate?.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("( )", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable1.AddCell(cellHeaderFooter); foreach (SalesReceiptDetailViewModel item in viewModel.SalesReceiptDetails) { if (item.VatType == "PPN BUMN") { cellHeaderFooter.Phrase = new Phrase("Note : PPN dibayarkan oleh buyer secara terpisah", note_font); } } footerTable1.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", note_font); footerTable1.AddCell(cellHeaderFooter); cellFooterLeft1.AddElement(footerTable1); footerTable.AddCell(cellFooterLeft1); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellHeaderFooter.Phrase = new Phrase("", normal_font); footerTable2.AddCell(cellHeaderFooter); cellFooterLeft2.AddElement(footerTable2); footerTable.AddCell(cellFooterLeft2); document.Add(footerTable); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(PurchasingDispositionViewModel viewModel, int clientTimeZoneOffset) { Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font small_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font smaller_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font2 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font3 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font bold_font4 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellCenterTopNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellJustifyNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED }; PdfPCell cellJustifyAllNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL }; PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRightMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellLeftMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; Document document = new Document(PageSize.A4, 30, 30, 30, 30); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); string titleString = "DISPOSISI PEMBAYARAN"; Paragraph title = new Paragraph(titleString, bold_font4) { Alignment = Element.ALIGN_CENTER }; document.Add(title); bold_font.SetStyle(Font.NORMAL); string NoString = "NO : " + viewModel.DispositionNo; Paragraph dispoNumber = new Paragraph(NoString, bold_font4) { Alignment = Element.ALIGN_CENTER }; dispoNumber.SpacingAfter = 20f; document.Add(dispoNumber); #region Identity PdfPTable tableIdentity = new PdfPTable(5); tableIdentity.SetWidths(new float[] { 5f, 0.5f, 1f, 4f, 7f }); double ppn = (viewModel.Amount * 0.1); string pph = ""; double pphRate = 0; foreach (var item in viewModel.Items) { if (!item.UseVat) { ppn = 0; } if (item.UseIncomeTax) { pph = item.IncomeTax.name; pphRate = viewModel.Amount * (Convert.ToDouble(item.IncomeTax.rate) / 100); } break; } double amount = viewModel.Amount + ppn; cellLeftNoBorder.Phrase = new Phrase("Mohon Disposisi Pembelian", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{amount.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Terbilang", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{ NumberToTextIDN.terbilang(amount) }", normal_font); cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Perhitungan :", bold_font3); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Biaya", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{viewModel.Amount.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("(PPn)", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{ppn.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Total", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{amount.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("PPh pasal " + pph, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{pphRate.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Jumlah dibayar ke Supplier ", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{(amount-pphRate).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Pembayaran ditransfer ke", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Bank, normal_font); cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Dibayar ke Kas Negara", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{(pphRate).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellIdentity = new PdfPCell(tableIdentity); tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 15f; document.Add(tableIdentity); #endregion #region Content PdfPTable tableContent = new PdfPTable(11); tableContent.SetWidths(new float[] { 6f, 5f, 4f, 3.5f, 3f, 3f, 2f, 2f, 3.5f, 2f, 4f }); cellCenter.Phrase = new Phrase("Nama Barang", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PR", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PO Eksternal", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Unit", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Kategori", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Jumlah", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Satuan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga", bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Total Harga", bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); double total = 0; foreach (PurchasingDispositionItemViewModel item in viewModel.Items) { for (int indexItem = 0; indexItem < item.Details.Count; indexItem++) { PurchasingDispositionDetailViewModel detail = item.Details[indexItem]; cellCenter.Colspan = 0; cellCenter.Phrase = new Phrase($"{detail.Product.name}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.PRNo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{item.EPONo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.Unit.name}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.Category.name}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase(string.Format("{0:n2}", detail.PaidQuantity), smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.DealUom.unit}", smaller_font); tableContent.AddCell(cellCenter); cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase($"{detail.PaidPrice.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); double subtotalPrice = detail.PaidPrice * detail.PaidQuantity; cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase($"{subtotalPrice.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); total += subtotalPrice; } } cellRight.Colspan = 9; cellRight.Phrase = new Phrase("Total Amount", bold_font); tableContent.AddCell(cellRight); cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase($"{total.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); PdfPCell cellContent = new PdfPCell(tableContent); // dont remove tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 20f; document.Add(tableContent); #endregion #region note PdfPTable tableNote = new PdfPTable(3); tableNote.SetWidths(new float[] { 4f, 0.5f, 11f }); cellLeftNoBorder.Phrase = new Phrase("Note :", bold_font3); cellLeftNoBorder.Colspan = 4; tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Supplier / Agent", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Supplier.name, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Order Confirmation", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ConfirmationOrderNo, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Invoice", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.InvoiceNo, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Proforma", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ProformaNo, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Investasi", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Investation, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Mohon dibayar Tanggal", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.PaymentDueDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Perhitungan", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Calculation, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Keterangan", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Remark, normal_font); tableNote.AddCell(cellLeftNoBorder); PdfPCell cellNote = new PdfPCell(tableNote); // dont remove tableNote.ExtendLastRow = false; tableNote.SpacingAfter = 20f; document.Add(tableNote); #endregion #region signature PdfPTable tableSignature = new PdfPTable(4); PdfPCell cellSignatureContent = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellSignatureContent.Phrase = new Phrase("Menyetujui,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("Mengetahui,", bold_font3); cellSignatureContent.Colspan = 2; tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 0; cellSignatureContent.Phrase = new Phrase("Hormat Kami,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove tableSignature.ExtendLastRow = false; tableSignature.SpacingBefore = 20f; tableSignature.SpacingAfter = 20f; document.Add(tableSignature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(ShinFinishingPrintingSalesContractViewModel viewModel, int timeoffset) { Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Document document = new Document(PageSize.A4, 40, 40, 140, 40); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region customViewModel string jumlahTerbilang = NumberToTextIDN.terbilang(viewModel.PreSalesContract.OrderQuantity); List <string> details = new List <string>(); var uomLocal = ""; if (viewModel.UOM.Unit.ToLower() == "yds") { uomLocal = "YARD"; } else if (viewModel.UOM.Unit.ToLower() == "mtr") { uomLocal = "METER"; } else { uomLocal = viewModel.UOM.Unit; } foreach (var i in viewModel.Details) { var ppn = ""; if (viewModel.UseIncomeTax.GetValueOrDefault()) { if (i.UseIncomeTax) { ppn = "INCLUDING PPN 10%"; } else { ppn = "EXCLUDING PPN"; } } else { ppn = "TANPA PPN"; } var nominal = string.Format("{0:n2}", i.Price); if (i.Currency.Code.ToLower() == "usd") { nominal = string.Format("{0:n2}", i.Price); } details.Add(i.Currency.Symbol + " " + nominal + " / " + uomLocal + " " + ppn + " " + "( " + i.Color + " )"); } //var motive = !String.IsNullOrEmpty(viewModel.DesignMotive.Name) ? viewModel.DesignMotive.Name : ""; var appxLocal = ""; var date = (viewModel.DeliverySchedule.Value.Day); if (date >= 1 && date <= 10) { appxLocal = "AWAL"; } else if (date >= 11 && date <= 20) { appxLocal = "PERTENGAHAN"; } else if (date >= 21 && date <= 31) { appxLocal = "AKHIR"; } #endregion #region Header string codeNoString = "FM-PJ-00-03-003"; Paragraph codeNo = new Paragraph(codeNoString, bold_font) { Alignment = Element.ALIGN_RIGHT }; document.Add(codeNo); string titleString = "SALES CONTRACT"; Paragraph title = new Paragraph(titleString, bold_font) { Alignment = Element.ALIGN_CENTER }; title.SpacingAfter = 10f; document.Add(title); bold_font.SetStyle(Font.NORMAL); #endregion #region Identity PdfPTable tableIdentity = new PdfPTable(3); tableIdentity.SetWidths(new float[] { 0.5f, 4.5f, 2.5f }); PdfPCell cellIdentityContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellIdentityContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; cellIdentityContentLeft.Phrase = new Phrase("No", normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(": " + viewModel.SalesContractNo, normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase($"Sukoharjo, {viewModel.CreatedUtc.AddHours(timeoffset).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase("Hal", normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(": " + "KONFIRMASI PESANAN PRINTING", normal_font); tableIdentity.AddCell(cellIdentityContentLeft); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentity.AddCell(cellIdentityContentRight); PdfPCell cellIdentity = new PdfPCell(tableIdentity); // dont remove tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 10f; document.Add(tableIdentity); PdfPTable tableIdentityOpeningLetter = new PdfPTable(3); tableIdentity.SetWidths(new float[] { 2f, 4.5f, 2.5f }); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentityOpeningLetter.AddCell(cellIdentityContentRight); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentityOpeningLetter.AddCell(cellIdentityContentRight); cellIdentityContentLeft.Phrase = new Phrase("Kepada Yth :", normal_font); tableIdentityOpeningLetter.AddCell(cellIdentityContentLeft); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentityOpeningLetter.AddCell(cellIdentityContentRight); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentityOpeningLetter.AddCell(cellIdentityContentRight); cellIdentityContentLeft.Phrase = new Phrase(viewModel.PreSalesContract.Buyer.Name, normal_font); tableIdentityOpeningLetter.AddCell(cellIdentityContentLeft); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentityOpeningLetter.AddCell(cellIdentityContentRight); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentityOpeningLetter.AddCell(cellIdentityContentRight); cellIdentityContentLeft.Phrase = new Phrase(viewModel.PreSalesContract.Buyer.Address, normal_font); tableIdentityOpeningLetter.AddCell(cellIdentityContentLeft); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentityOpeningLetter.AddCell(cellIdentityContentRight); cellIdentityContentRight.Phrase = new Phrase(""); tableIdentityOpeningLetter.AddCell(cellIdentityContentRight); cellIdentityContentLeft.Phrase = new Phrase(viewModel.PreSalesContract.Buyer.City, normal_font); tableIdentityOpeningLetter.AddCell(cellIdentityContentLeft); PdfPCell cellIdentityOpeningLetter = new PdfPCell(tableIdentityOpeningLetter); // dont remove tableIdentityOpeningLetter.ExtendLastRow = false; tableIdentityOpeningLetter.SpacingAfter = 10f; document.Add(tableIdentityOpeningLetter); #endregion string HeaderParagraphString = "Dengan Hormat,"; Paragraph HeaderParagraph = new Paragraph(HeaderParagraphString, normal_font) { Alignment = Element.ALIGN_LEFT }; document.Add(HeaderParagraph); string firstParagraphString = "Sesuai dengan pesanan / order Bapak / Ibu kepada kami, maka bersama ini kami kirimkan surat persetujuan pesanan dengan ketentuan dan syarat - syarat di bawah ini: "; Paragraph firstParagraph = new Paragraph(firstParagraphString, normal_font) { Alignment = Element.ALIGN_JUSTIFIED }; firstParagraph.SpacingAfter = 10f; document.Add(firstParagraph); #region body PdfPTable tableBody = new PdfPTable(2); tableBody.SetWidths(new float[] { 0.75f, 2f }); PdfPCell bodyContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell bodyContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; bodyContentLeft.Phrase = new Phrase("Jenis", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.Commodity.Name, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("Material", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.Material.Name, normal_font); tableBody.AddCell(bodyContentLeft); if (!string.IsNullOrEmpty(viewModel.YarnMaterial.Name) && !string.IsNullOrWhiteSpace(viewModel.YarnMaterial.Name)) { bodyContentLeft.Phrase = new Phrase(" ", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(" " + viewModel.YarnMaterial.Name, normal_font); tableBody.AddCell(bodyContentLeft); } if (!string.IsNullOrEmpty(viewModel.CommodityDescription) && !string.IsNullOrWhiteSpace(viewModel.CommodityDescription)) { bodyContentLeft.Phrase = new Phrase(" ", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(" " + viewModel.CommodityDescription, normal_font); tableBody.AddCell(bodyContentLeft); } bodyContentLeft.Phrase = new Phrase("Jumlah", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.PreSalesContract.OrderQuantity.ToString("N2") + " (" + jumlahTerbilang + ") " + uomLocal, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("Kualitas", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.Quality.Name, normal_font); tableBody.AddCell(bodyContentLeft); //bodyContentLeft.Phrase = new Phrase("Motif", normal_font); //tableBody.AddCell(bodyContentLeft); //bodyContentLeft.Phrase = new Phrase(": " + motive, normal_font); //tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("Harga", normal_font); tableBody.AddCell(bodyContentLeft); int index = 0; foreach (var detail in details) { index++; if (index == 1) { bodyContentLeft.Phrase = new Phrase(": " + detail, normal_font); tableBody.AddCell(bodyContentLeft); } else { bodyContentLeft.Phrase = new Phrase(" ", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(" " + detail, normal_font); tableBody.AddCell(bodyContentLeft); } } bodyContentLeft.Phrase = new Phrase("Syarat Pembayaran", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.TermOfPayment.Name, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("Pembayaran Ke Alamat", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.AccountBank.BankName, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(" " + viewModel.AccountBank.BankAddress, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(" A/C. " + viewModel.AccountBank.AccountNumber, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(" A/N. " + viewModel.AccountBank.AccountName, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("Ongkos Angkut", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.TransportFee, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("Dikirim Ke", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.DeliveredTo, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("Jadwal Pengiriman", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + appxLocal + " " + (viewModel.DeliverySchedule.Value.AddHours(timeoffset).ToString("MMMM yyyy", new CultureInfo("id-ID")))?.ToUpper(), normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("Packing", normal_font); tableBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(": " + viewModel.Packing, normal_font); tableBody.AddCell(bodyContentLeft); bodyContentRight.Phrase = new Phrase(""); tableBody.AddCell(bodyContentRight); PdfPCell cellBody = new PdfPCell(tableBody); // dont remove tableBody.ExtendLastRow = false; document.Add(tableBody); PdfPTable conditionListBody = new PdfPTable(3); conditionListBody.SetWidths(new float[] { 0.4f, 0.025f, 1f }); bodyContentLeft.Phrase = new Phrase("Kondisi", normal_font); conditionListBody.AddCell(bodyContentLeft); cellIdentityContentLeft.Phrase = new Phrase("-", normal_font); conditionListBody.AddCell(cellIdentityContentLeft); bodyContentLeft.Phrase = new Phrase("Pesanan tidak dapat dibatalkan kecuali disetujui oleh kedua belah pihak.", normal_font); conditionListBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase("", normal_font); conditionListBody.AddCell(bodyContentLeft); cellIdentityContentLeft.Phrase = new Phrase("-", normal_font); conditionListBody.AddCell(cellIdentityContentLeft); bodyContentLeft.Phrase = new Phrase("Kelebihan / kekurangan pengiriman maksimal 10% dari jumlah pesanan.", normal_font); conditionListBody.AddCell(bodyContentLeft); bodyContentLeft.Phrase = new Phrase(" ", normal_font); conditionListBody.AddCell(bodyContentLeft); cellIdentityContentLeft.Phrase = new Phrase("- ", normal_font); conditionListBody.AddCell(cellIdentityContentLeft); bodyContentLeft.Phrase = new Phrase(viewModel.Condition, normal_font); conditionListBody.AddCell(bodyContentLeft); bodyContentRight.Phrase = new Phrase(""); conditionListBody.AddCell(bodyContentRight); PdfPCell cellConditionList = new PdfPCell(conditionListBody); // dont remove conditionListBody.ExtendLastRow = false; conditionListBody.SpacingAfter = 10f; document.Add(conditionListBody); #endregion string ClosingParagraphString = "Demikian konfirmasi order ini kami sampaikan untuk diketahui dan dipergunakan seperlunya. Tembusan surat ini mohon dikirim kembali setelah ditanda tangani dan dibubuhi cap perusahaan."; Paragraph ClosingParagraph = new Paragraph(ClosingParagraphString, normal_font) { Alignment = Element.ALIGN_JUSTIFIED }; ClosingParagraph.SpacingBefore = 10f; ClosingParagraph.SpacingAfter = 10f; document.Add(ClosingParagraph); #region signature PdfPTable signature = new PdfPTable(2); signature.SetWidths(new float[] { 1f, 1f }); PdfPCell cell_signature = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; signature.SetWidths(new float[] { 1f, 1f }); cell_signature.Phrase = new Phrase("Pembeli,", normal_font); signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Hormat Kami, ", normal_font); signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); signature.AddCell(cell_signature); string signatureArea = string.Empty; for (int i = 0; i < 5; i++) { signatureArea += Environment.NewLine; } cell_signature.Phrase = new Phrase(signatureArea, normal_font); signature.AddCell(cell_signature); signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("(...........................)", normal_font); signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("( ROBBY SAPUTRO )", normal_font); signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Penjualan Tekstil", normal_font); signature.AddCell(cell_signature); cellIdentityContentRight.Phrase = new Phrase(""); signature.AddCell(cellIdentityContentRight); PdfPCell signatureCell = new PdfPCell(signature); // dont remove signature.ExtendLastRow = false; signature.SpacingAfter = 10f; document.Add(signature); #endregion #region ConditionPage document.NewPage(); string ConditionString = "Kondisi"; Paragraph ConditionName = new Paragraph(ConditionString, header_font) { Alignment = Element.ALIGN_LEFT }; document.Add(ConditionName); string bulletListSymbol = "\u2022"; PdfPCell bodyContentJustify = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED }; PdfPTable conditionList = new PdfPTable(2); conditionList.SetWidths(new float[] { 0.01f, 1f }); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(bulletListSymbol, normal_font); conditionList.AddCell(cellIdentityContentLeft); bodyContentJustify.Phrase = new Phrase("Keterlambatan pembayaran dikenakan denda 3.00 % per bulan.", normal_font); conditionList.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(bulletListSymbol, normal_font); conditionList.AddCell(cellIdentityContentLeft); bodyContentJustify.Phrase = new Phrase("Pembayaran maju mendapat potongan 00.00 % per bulan, potongan pembayaran maju tersebut dapat berubah sewaktu - waktu baik dengan atau tanpa pemberitahuan terlebih dahulu dari pihak PT.DANLIRIS.", normal_font); conditionList.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(bulletListSymbol, normal_font); conditionList.AddCell(cellIdentityContentLeft); bodyContentJustify.Phrase = new Phrase("Bila terjadi kebijaksanaan pemerintah dalam bidang moneter, untuk barang yang belum terkirim harga akan dibicarakan lagi.", normal_font); conditionList.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(bulletListSymbol, normal_font); conditionList.AddCell(cellIdentityContentLeft); bodyContentJustify.Phrase = new Phrase("Kain/Benang yang telah diproses/dipotong tidak dapat dikembalikan kecuali ada persetujuan tertulis dari kedua belah pihak sebelumnya.", normal_font); conditionList.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(bulletListSymbol, normal_font); conditionList.AddCell(cellIdentityContentLeft); bodyContentJustify.Phrase = new Phrase("Semua klaim atas cacat Kain / Benang harus diinformasikan kepada penjual secara tertulis, berikut contoh atau bukti yang menunjang(memadai), maksimum 2 minggu setelah tanggal penerimaan barang.", normal_font); conditionList.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(bulletListSymbol, normal_font); conditionList.AddCell(cellIdentityContentLeft); bodyContentJustify.Phrase = new Phrase("Klaim yang diajukan akan diselesaikan secara terpisah dan tidak dapat dihubungkan atau dikompensasikan dengan pembayaran Kain Grey / Benang.", normal_font); conditionList.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(bulletListSymbol, normal_font); conditionList.AddCell(cellIdentityContentLeft); bodyContentJustify.Phrase = new Phrase("Penjual mempunyai hak dengan pemberitahuan sebelumnya untuk membatalkan Konfrmasi ini seluruhnya atau sebagian bilamana:", normal_font); conditionList.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionList.AddCell(cellIdentityContentLeft); PdfPCell conditionListData = new PdfPCell(conditionList); // dont remove conditionList.ExtendLastRow = false; document.Add(conditionList); PdfPTable conditionListChild = new PdfPTable(2); conditionListChild.SetWidths(new float[] { 0.04f, 1f }); cellIdentityContentRight.Phrase = new Phrase("1. ", normal_font); conditionListChild.AddCell(cellIdentityContentRight); bodyContentJustify.Phrase = new Phrase("Pembeli tidak dapat memenuhi / menyelesaikan jadwal pengiriman/pengambilan barang yang telah ditetapkan dan disetujui kedua belah pihak.", normal_font); conditionListChild.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionListChild.AddCell(cellIdentityContentLeft); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionListChild.AddCell(cellIdentityContentLeft); cellIdentityContentRight.Phrase = new Phrase("2. ", normal_font); conditionListChild.AddCell(cellIdentityContentRight); bodyContentJustify.Phrase = new Phrase("Pembeli belum / tidak dapat menyelesaikan pembayaran yang sudah jatuh tempo dari pengambilan / order yang telah terkirim sebelumnya.", normal_font); conditionListChild.AddCell(bodyContentJustify); cellIdentityContentLeft.Phrase = new Phrase(" ", normal_font); conditionListChild.AddCell(cellIdentityContentLeft); PdfPCell conditionListChildData = new PdfPCell(conditionListChild); // dont remove conditionListChild.ExtendLastRow = false; document.Add(conditionListChild); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingPaymentDispositionViewModel viewModel, List <GarmentShippingInvoiceViewModel> invoices, List <GarmentPackingListViewModel> packingLists, int timeoffset) { const int MARGIN = 20; Font header_font_bold_big = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font header_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12, Font.UNDERLINE); Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE); Font normal_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 40, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region header Paragraph title = new Paragraph("LAMPIRAN DISPOSISI PEMBAYARAN FORWARDER\n\n\n", header_font_bold); title.Alignment = Element.ALIGN_CENTER; Paragraph title1 = new Paragraph("DISPOSISI BIAYA SHIPMENT", normal_font_underlined); Paragraph no = new Paragraph(viewModel.dispositionNo, normal_font); document.Add(title); document.Add(title1); document.Add(no); document.Add(new Paragraph("\n", normal_font)); #endregion #region bodyTable List <string> inv = new List <string>(); List <string> como = new List <string>(); foreach (var i in invoices) { var dupInv = como.Find(a => a == i.InvoiceNo); if (string.IsNullOrEmpty(dupInv)) { inv.Add(i.InvoiceNo); } foreach (var item in i.Items) { var dupComo = como.Find(a => a == item.Comodity.Name); if (string.IsNullOrEmpty(dupComo)) { como.Add(item.Comodity.Name); } } } decimal invTotalQty = viewModel.invoiceDetails.Sum(a => a.quantity); decimal totalCtns = viewModel.invoiceDetails.Sum(a => a.totalCarton); double totalcbm = packingLists.Sum(a => a.Measurements.Sum(m => m.Length * m.Width * m.Height * m.CartonsQuantity / 1000000)); PdfPTable tableBody = new PdfPTable(7); tableBody.WidthPercentage = 80; tableBody.SetWidths(new float[] { 3f, 0.5f, 5f, 0.5f, 1f, 4f, 1f }); PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellLeftNoBorder1 = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellLeftTopBorder = new PdfPCell() { Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRightTopBorder = new PdfPCell() { Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; cellLeftNoBorder.Phrase = new Phrase("Subject", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.invoiceNumber, normal_font); cellLeftNoBorder1.Colspan = 5; tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Dikirim per", normal_font); cellLeftNoBorder.Colspan = 1; tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.sendBy, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Forwarder", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.forwarder.name, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Material", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(string.Join(", ", como), normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Pembeli", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.buyerAgent.Name, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("LCNo", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.paymentTerm, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Invoice", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(string.Join(", ", inv), normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Party", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase($"{string.Format("{0:n2}", invTotalQty)} pcs / {string.Format("{0:n2}", totalCtns)} ctns = {string.Format("{0:n2}", totalcbm)} cbm", normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Biaya", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder1); var last = viewModel.billDetails.Last(); foreach (var bill in viewModel.billDetails) { cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(bill.billDescription, normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("RP", normal_font); tableBody.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", bill.amount), normal_font); tableBody.AddCell(cellRightNoBorder); if (bill == last) { cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font); tableBody.AddCell(cellLeftNoBorder); } else { cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); } } cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("RP", normal_font); tableBody.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue), normal_font); tableBody.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"PPH {viewModel.incomeTax.name} ({viewModel.incomeTax.rate}%)", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font_bold); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("RP", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.IncomeTaxValue), normal_font_bold); tableBody.AddCell(cellRightNoBorder); cellLeftNoBorder.Phrase = new Phrase("(-)", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("RP", normal_font); tableBody.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue - viewModel.IncomeTaxValue), normal_font); tableBody.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("PPN", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("RP", normal_font); tableBody.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.vatValue), normal_font); tableBody.AddCell(cellRightNoBorder); cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("RP", normal_font_bold); tableBody.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.totalBill), normal_font_bold); tableBody.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBody.AddCell(cellLeftNoBorder); tableBody.SpacingAfter = 10; tableBody.SpacingBefore = 5; tableBody.HorizontalAlignment = Element.ALIGN_LEFT; document.Add(tableBody); var terbilang = NumberToTextIDN.terbilang((double)viewModel.totalBill) + " rupiah"; Paragraph trbilang = new Paragraph($"[ Terbilang : {terbilang} ]\n\n", normal_font); document.Add(trbilang); #endregion #region unit Paragraph units = new Paragraph("Beban Per Unit", normal_font_bold); document.Add(units); PdfPTable tableUnit = new PdfPTable(2); tableUnit.WidthPercentage = 50; tableUnit.SetWidths(new float[] { 1f, 1f }); PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; cellCenter.Phrase = new Phrase("Unit", normal_font_bold); tableUnit.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Amount", normal_font_bold); tableUnit.AddCell(cellCenter); foreach (var unitItem in viewModel.unitCharges) { cellLeft.Phrase = new Phrase(unitItem.unit.Code, normal_font); tableUnit.AddCell(cellLeft); cellRight.Phrase = new Phrase(string.Format("{0:n2}", unitItem.billAmount), normal_font); tableUnit.AddCell(cellRight); } tableUnit.SpacingAfter = 10; tableUnit.SpacingBefore = 5; tableUnit.HorizontalAlignment = Element.ALIGN_LEFT; document.Add(tableUnit); #endregion #region sign PdfPTable tableSign = new PdfPTable(3); tableSign.WidthPercentage = 100; tableSign.SetWidths(new float[] { 1f, 1f, 1f }); PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodySignNoBorder.Phrase = new Phrase($"Solo, {DateTimeOffset.Now.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Bag. Exp garment,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Mengetahui,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Diterima,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingLocalSalesNoteViewModel viewModel, GarmentLocalCoverLetterViewModel cl, Buyer buyer, int timeoffset) { const int MARGIN = 20; Font header_font_bold_big = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font header_font_bold = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE); Font header_font = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font normal_font = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font normal_font_underlined = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8, Font.UNDERLINE); Font normal_font_bold = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A5.Rotate(), MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region header PdfPTable tableHeader = new PdfPTable(2); tableHeader.WidthPercentage = 100; tableHeader.SetWidths(new float[] { 3f, 2f }); PdfPCell cellHeaderContent1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderContent2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderContent1.AddElement(new Phrase("\n", normal_font)); cellHeaderContent1.AddElement(new Phrase("PT. DAN LIRIS", header_font_bold)); cellHeaderContent1.AddElement(new Phrase("Jl. Merapi No. 23, Kel. Banaran Kec.Grogol Kab. Sukoharjo", normal_font)); cellHeaderContent1.AddElement(new Phrase("Telp : 0271-714400, Fax. 0271-717178", normal_font)); cellHeaderContent1.AddElement(new Phrase("PO. Box. 166 Solo-57100 Indonesia", normal_font)); //cellHeaderContent1.AddElement(new Phrase("\n", normal_font)); tableHeader.AddCell(cellHeaderContent1); cellHeaderContent2.AddElement(new Phrase("Sukoharjo, " + viewModel.date.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID")), normal_font)); cellHeaderContent2.AddElement(new Phrase("\n", normal_font)); //cellHeaderContent2.AddElement(new Phrase("\n", normal_font)); cellHeaderContent2.AddElement(new Phrase(viewModel.buyer.Code + " - " + viewModel.buyer.Name + " - " + viewModel.buyer.KaberType, normal_font)); cellHeaderContent2.AddElement(new Phrase(buyer.Address, normal_font)); tableHeader.AddCell(cellHeaderContent2); document.Add(tableHeader); #endregion #region title Paragraph title = new Paragraph("NOTA PENJUALAN GARMENT", header_font_bold); title.Alignment = Element.ALIGN_CENTER; document.Add(title); Paragraph no = new Paragraph(viewModel.noteNo, header_font_bold); no.Alignment = Element.ALIGN_CENTER; document.Add(no); if (viewModel.buyer.KaberType == "KABER") { Paragraph location = new Paragraph("PPN BERFASILITAS", normal_font_bold); location.Alignment = Element.ALIGN_RIGHT; document.Add(location); } PdfPTable tableTitle = new PdfPTable(3); tableTitle.WidthPercentage = 40; tableTitle.SetWidths(new float[] { 3f, 0.5f, 4f }); PdfPCell cellTitle1 = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; cellTitle1.Phrase = new Phrase("NPWP Penjual", normal_font); tableTitle.AddCell(cellTitle1); cellTitle1.Phrase = new Phrase(":", normal_font); tableTitle.AddCell(cellTitle1); cellTitle1.Phrase = new Phrase("01.139.907.8-532.000", normal_font); tableTitle.AddCell(cellTitle1); cellTitle1.Phrase = new Phrase("NPWP Pembeli", normal_font); tableTitle.AddCell(cellTitle1); cellTitle1.Phrase = new Phrase(":", normal_font); tableTitle.AddCell(cellTitle1); cellTitle1.Phrase = new Phrase(buyer.npwp, normal_font); tableTitle.AddCell(cellTitle1); cellTitle1.Phrase = new Phrase("NIK Pembeli", normal_font); tableTitle.AddCell(cellTitle1); cellTitle1.Phrase = new Phrase(":", normal_font); tableTitle.AddCell(cellTitle1); cellTitle1.Phrase = new Phrase(buyer.NIK, normal_font); tableTitle.AddCell(cellTitle1); tableTitle.SpacingAfter = 5; tableTitle.HorizontalAlignment = Element.ALIGN_LEFT; document.Add(tableTitle); #endregion #region bodyTable PdfPTable tableBody = new PdfPTable(7); tableBody.WidthPercentage = 100; tableBody.SetWidths(new float[] { 1.2f, 1f, 5f, 2f, 1f, 2f, 2f }); PdfPCell cellBodyLeft = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellBodyLeftNoBorder = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellBodyRight = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellBodyRightNoBorder = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellBodyCenter = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodyCenter.Phrase = new Phrase("Banyak", normal_font); tableBody.AddCell(cellBodyCenter); cellBodyCenter.Phrase = new Phrase("Satuan", normal_font); tableBody.AddCell(cellBodyCenter); cellBodyCenter.Phrase = new Phrase("Nama Barang", normal_font); tableBody.AddCell(cellBodyCenter); cellBodyCenter.Phrase = new Phrase("Quantity", normal_font); cellBodyCenter.Colspan = 2; tableBody.AddCell(cellBodyCenter); cellBodyCenter.Phrase = new Phrase("Harga Sat.", normal_font); cellBodyCenter.Colspan = 1; tableBody.AddCell(cellBodyCenter); cellBodyCenter.Phrase = new Phrase("Jumlah", normal_font); cellBodyCenter.Colspan = 1; tableBody.AddCell(cellBodyCenter); foreach (var item in viewModel.items) { cellBodyRight.Phrase = new Phrase(string.Format("{0:n2}", item.packageQuantity), normal_font); tableBody.AddCell(cellBodyRight); cellBodyLeft.Phrase = new Phrase(item.packageUom.Unit, normal_font); tableBody.AddCell(cellBodyLeft); cellBodyLeft.Phrase = new Phrase(item.product.code + " - " + item.product.name, normal_font); tableBody.AddCell(cellBodyLeft); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", item.quantity), normal_font); tableBody.AddCell(cellBodyRightNoBorder); cellBodyLeftNoBorder.Phrase = new Phrase(item.uom.Unit, normal_font); tableBody.AddCell(cellBodyLeftNoBorder); cellBodyRight.Phrase = new Phrase(string.Format("{0:n2}", item.price), normal_font); tableBody.AddCell(cellBodyRight); cellBodyRight.Phrase = new Phrase(string.Format("{0:n2}", item.price * item.quantity), normal_font); tableBody.AddCell(cellBodyRight); } double totalPrice = viewModel.items.Sum(a => a.quantity * a.price); double ppn = 0; if (viewModel.useVat) { ppn = totalPrice * 0.1; } double finalPrice = totalPrice + ppn; cellBodyRight.Phrase = new Phrase("Dasar Pengenaan Pajak...............Rp.", normal_font); cellBodyRight.Border = Rectangle.NO_BORDER; cellBodyRight.Colspan = 6; tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", totalPrice), normal_font); cellBodyRightNoBorder.Border = Rectangle.NO_BORDER; tableBody.AddCell(cellBodyRightNoBorder); cellBodyRight.Phrase = new Phrase("PPN = 10% X Dasar Pengenaan Pajak...Rp.", normal_font); tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", ppn), normal_font); cellBodyRightNoBorder.Border = Rectangle.BOTTOM_BORDER; tableBody.AddCell(cellBodyRightNoBorder); cellBodyRight.Phrase = new Phrase("Jumlah..............................Rp.", normal_font); tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", finalPrice), normal_font); cellBodyRightNoBorder.Border = Rectangle.NO_BORDER; tableBody.AddCell(cellBodyRightNoBorder); tableBody.SpacingAfter = 10; document.Add(tableBody); #endregion #region footer PdfPTable tableFooter = new PdfPTable(4); tableFooter.WidthPercentage = 100; tableFooter.SetWidths(new float[] { 2f, 3f, 2f, 3f }); PdfPCell cellFooterContent1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterContent2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterContent3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterContent4 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellFooterContent1.Phrase = new Phrase("No Sales Contract :", normal_font); tableFooter.AddCell(cellFooterContent1); cellFooterContent2.Phrase = new Phrase(viewModel.salesContractNo, normal_font); tableFooter.AddCell(cellFooterContent2); cellFooterContent3.Phrase = new Phrase("No Bon Keluar :", normal_font); tableFooter.AddCell(cellFooterContent3); cellFooterContent4.Phrase = new Phrase(viewModel.expenditureNo, normal_font); tableFooter.AddCell(cellFooterContent4); cellFooterContent1.Phrase = new Phrase("No Disposisi :", normal_font); tableFooter.AddCell(cellFooterContent1); cellFooterContent2.Phrase = new Phrase(string.IsNullOrWhiteSpace(viewModel.dispositionNo) ? "-" : viewModel.dispositionNo, normal_font); tableFooter.AddCell(cellFooterContent2); cellFooterContent3.Phrase = new Phrase("No Bea Cukai :", normal_font); tableFooter.AddCell(cellFooterContent3); cellFooterContent4.Phrase = new Phrase(cl == null ? "-" : cl.bcNo, normal_font); tableFooter.AddCell(cellFooterContent4); cellFooterContent1.Phrase = new Phrase("Tempo Pembayaran :", normal_font); tableFooter.AddCell(cellFooterContent1); cellFooterContent2.Phrase = new Phrase(viewModel.tempo + " Hari", normal_font); tableFooter.AddCell(cellFooterContent2); cellFooterContent3.Phrase = (new Phrase("Tanggal J/T :", normal_font)); tableFooter.AddCell(cellFooterContent3); cellFooterContent4.Phrase = (new Phrase(viewModel.date.GetValueOrDefault().AddDays(viewModel.tempo).ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID")), normal_font)); tableFooter.AddCell(cellFooterContent4); document.Add(tableFooter); #endregion #region footer1 PdfPTable tableFooter1 = new PdfPTable(2); tableFooter1.WidthPercentage = 100; tableFooter1.SetWidths(new float[] { 1.5f, 9f }); PdfPCell cellFooterContent11 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterContent21 = new PdfPCell() { Border = Rectangle.NO_BORDER }; string terbilang = NumberToTextIDN.terbilang(Math.Round(finalPrice, 2)); cellFooterContent11.Phrase = (new Phrase("Terbilang :", normal_font)); tableFooter1.AddCell(cellFooterContent11); cellFooterContent21.Phrase = (new Phrase(terbilang + " rupiah", normal_font)); tableFooter1.AddCell(cellFooterContent21); cellFooterContent11.Phrase = (new Phrase("Catatan :", normal_font)); tableFooter1.AddCell(cellFooterContent11); cellFooterContent21.Phrase = (new Phrase(viewModel.remark, normal_font)); tableFooter1.AddCell(cellFooterContent21); tableFooter1.SpacingAfter = 4; document.Add(tableFooter1); #endregion document.Add(new Paragraph("HARAP TRANSFER PEMBAYARAN DIATAS KEPADA BANK KORESPONDEN KAMI SEBAGAI BERIKUT :", normal_font)); document.Add(new Paragraph("MAYBANK INDONESIA - CABANG SLAMET RIYADI", normal_font)); document.Add(new Paragraph("ACC NO. : 2105010887 A/N : PT. DAN LIRIS", normal_font)); document.Add(new Paragraph(" ", normal_font)); #region sign PdfPTable tableSign = new PdfPTable(5); tableSign.WidthPercentage = 80; tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f }); PdfPCell cellBodySign = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodySign.Phrase = new Phrase("Diterima Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySign.Phrase = new Phrase("Dibuat Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("Diperiksa Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("Disetujui Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySignNoBorder.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); document.Add(tableSign); #endregion //document.Add(new Phrase("Model DL1",normal_font)); document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(VbWithPORequestViewModel viewModel, int clientTimeZoneOffset) { const int MARGIN = 20; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font note_font = FontFactory.GetFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_italic_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font Title_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 13); Document document = new Document(PageSize.A5.Rotate(), MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region Header PdfPTable headerTable_A = new PdfPTable(2); PdfPTable headerTable_B = new PdfPTable(1); PdfPTable headerTable_C = new PdfPTable(1); PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(1); PdfPTable headerTable3 = new PdfPTable(3); PdfPTable headerTable3a = new PdfPTable(10); PdfPTable headerTable4 = new PdfPTable(2); headerTable_A.SetWidths(new float[] { 10f, 10f }); headerTable_A.WidthPercentage = 100; headerTable3.SetWidths(new float[] { 40f, 4f, 100f }); headerTable3.WidthPercentage = 100; headerTable3a.SetWidths(new float[] { 3f, 10f, 3f, 10f, 3f, 10f, 3f, 10f, 3f, 10f }); headerTable3a.WidthPercentage = 100; headerTable4.SetWidths(new float[] { 10f, 40f }); headerTable4.WidthPercentage = 100; PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader4 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader3a = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderBody.Phrase = new Phrase("Kepada Yth.......", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Kasir PT. Danliris", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Di tempat", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeader1.AddElement(headerTable1); headerTable_A.AddCell(cellHeader1); cellHeader2.AddElement(headerTable2); headerTable_A.AddCell(cellHeader2); document.Add(headerTable_A); cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody2.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody3.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeaderBody2.Colspan = 3; cellHeaderBody2.Phrase = new Phrase("PERMOHONAN VB DENGAN PO", bold_font); headerTable3.AddCell(cellHeaderBody2); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); cellHeaderBody3.Colspan = 3; cellHeaderBody3.Phrase = new Phrase($"No : {viewModel.VBNo}", normal_font); headerTable3.AddCell(cellHeaderBody3); cellHeaderBody3.Colspan = 3; cellHeaderBody3.Phrase = new Phrase($"Tanggal : {viewModel.Date?.AddHours(clientTimeZoneOffset).ToString("dd/MM/yyyy")}", normal_font); headerTable3.AddCell(cellHeaderBody3); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("VB Uang", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); decimal convertCurrency = 0; string Usage = ""; string PoNumber = ""; foreach (var itm1 in viewModel.Items) { PoNumber += itm1.no + ", "; foreach (var itm2 in itm1.Details) { var price = itm2.priceBeforeTax * itm2.dealQuantity; if (itm2.useVat && !itm2.includePpn) { price += price * (decimal)0.1; } convertCurrency += price; Usage += itm2.product.name + ", "; } } Usage = Usage.Remove(Usage.Length - 2); PoNumber = PoNumber.Remove(PoNumber.Length - 2); cellHeaderBody.Phrase = new Phrase($"{viewModel.Currency.Code} " + viewModel.VBMoney.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Terbilang", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); string TotalPaidString; string CurrencySay; if (viewModel.Currency.Code == "IDR") { TotalPaidString = NumberToTextIDN.terbilang((double)viewModel.VBMoney); CurrencySay = "Rupiah"; } else { TotalPaidString = NumberToTextIDN.terbilang((double)viewModel.VBMoney); CurrencySay = viewModel.Currency.Description; CurrencySay = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(CurrencySay.ToLower()); } cellHeaderBody.Phrase = new Phrase(TotalPaidString + " " + CurrencySay, normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("No PO", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(PoNumber, normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Total Harga PO", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase($"{viewModel.Currency.Code} " + convertCurrency.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Kegunaan", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(":", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(viewModel.Usage, normal_font); headerTable3.AddCell(cellHeaderBody); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); //cellHeaderBody.Phrase = new Phrase(" ", normal_font); //headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Beban Unit :", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(" ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(" ", normal_font); headerTable3.AddCell(cellHeaderBody); cellHeader3.AddElement(headerTable3); headerTable_B.AddCell(cellHeader3); cellHeader4.AddElement(headerTable4); headerTable_B.AddCell(cellHeader4); document.Add(headerTable_B); //writer.AddAnnotation(_checkGroup); #endregion Header #region CheckBox string unit = ""; foreach (var itm in viewModel.Items) { unit += itm.unit.Name + ","; } unit = unit.Remove(unit.Length - 1); var items = unit.Split(","); string lastitem = items[items.Length - 1]; lastitem = lastitem.Trim(); cellHeaderBody.Phrase = new Phrase("", normal_font); //Create_Box(writer,headerTable3a); PdfPCell cellform = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG; PdfFormField _radioField1; Rectangle kotak = new Rectangle(100, 100); _radioG = new RadioCheckField(writer, kotak, "abc", "Yes"); _radioG.CheckType = RadioCheckField.TYPE_CHECK; _radioG.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG.BorderColor = BaseColor.Black; _radioG.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("SPINNING 1")) { _radioG.Checked = true; } else { _radioG.Checked = false; } _radioG.Rotation = 90; _radioG.Options = TextField.READ_ONLY; _radioField1 = _radioG.CheckField; cellform.CellEvent = new BebanUnitEvent(_checkGroup, _radioField1, 1); headerTable3a.AddCell(cellform); cellHeaderBody.Phrase = new Phrase("Spinning 1", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform1.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup1 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG1; PdfFormField _radioField11; Rectangle kotak1 = new Rectangle(100, 100); _radioG1 = new RadioCheckField(writer, kotak1, "abc", "Yes"); _radioG1.CheckType = RadioCheckField.TYPE_CHECK; _radioG1.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG1.BorderColor = BaseColor.Black; _radioG1.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("WEAVING 1")) { _radioG1.Checked = true; } else { _radioG1.Checked = false; } _radioG1.Rotation = 90; _radioG1.Options = TextField.READ_ONLY; _radioField11 = _radioG1.CheckField; cellform1.CellEvent = new BebanUnitEvent(_checkGroup1, _radioField11, 1); headerTable3a.AddCell(cellform1); cellHeaderBody.Phrase = new Phrase("Weaving 1", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform2.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup2 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG2; PdfFormField _radioField12; Rectangle kotak2 = new Rectangle(100, 100); _radioG2 = new RadioCheckField(writer, kotak2, "abc", "Yes"); _radioG2.CheckType = RadioCheckField.TYPE_CHECK; _radioG2.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG2.BorderColor = BaseColor.Black; _radioG2.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("FINISHING")) { _radioG2.Checked = true; } else { _radioG2.Checked = false; } _radioG2.Rotation = 90; _radioG2.Options = TextField.READ_ONLY; _radioField12 = _radioG2.CheckField; cellform2.CellEvent = new BebanUnitEvent(_checkGroup2, _radioField12, 1); headerTable3a.AddCell(cellform2); cellHeaderBody.Phrase = new Phrase("Finishing", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform3.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup3 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG3; PdfFormField _radioField13; Rectangle kotak3 = new Rectangle(100, 100); _radioG3 = new RadioCheckField(writer, kotak3, "abc", "Yes"); _radioG3.CheckType = RadioCheckField.TYPE_CHECK; _radioG3.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG3.BorderColor = BaseColor.Black; _radioG3.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("KONFEKSI 2A")) { _radioG3.Checked = true; } else { _radioG3.Checked = false; } _radioG3.Rotation = 90; _radioG3.Options = TextField.READ_ONLY; _radioField13 = _radioG3.CheckField; cellform3.CellEvent = new BebanUnitEvent(_checkGroup3, _radioField13, 1); headerTable3a.AddCell(cellform3); cellHeaderBody.Phrase = new Phrase("Konfeksi 2 A", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform4 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform4.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup4 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG4; PdfFormField _radioField14; Rectangle kotak4 = new Rectangle(100, 100); _radioG4 = new RadioCheckField(writer, kotak4, "abc", "Yes"); _radioG4.CheckType = RadioCheckField.TYPE_CHECK; _radioG4.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG4.BorderColor = BaseColor.Black; _radioG4.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("UMUM")) { _radioG4.Checked = true; } else { _radioG4.Checked = false; } _radioG4.Rotation = 90; _radioG4.Options = TextField.READ_ONLY; _radioField14 = _radioG4.CheckField; cellform4.CellEvent = new BebanUnitEvent(_checkGroup4, _radioField14, 1); headerTable3a.AddCell(cellform4); cellHeaderBody.Phrase = new Phrase("Umum", normal_font); headerTable3a.AddCell(cellHeaderBody); //================================================ cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform5 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform5.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup5 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG5; PdfFormField _radioField15; Rectangle kotak5 = new Rectangle(100, 100); _radioG5 = new RadioCheckField(writer, kotak5, "abc", "Yes"); _radioG5.CheckType = RadioCheckField.TYPE_CHECK; _radioG5.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG5.BorderColor = BaseColor.Black; _radioG5.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("SPINNING 2")) { _radioG5.Checked = true; } else { _radioG5.Checked = false; } _radioG5.Rotation = 90; _radioG5.Options = TextField.READ_ONLY; _radioField15 = _radioG5.CheckField; cellform5.CellEvent = new BebanUnitEvent(_checkGroup5, _radioField15, 1); headerTable3a.AddCell(cellform5); cellHeaderBody.Phrase = new Phrase("Spinning 2", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform6 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform6.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup6 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG6; PdfFormField _radioField16; Rectangle kotak6 = new Rectangle(100, 100); _radioG6 = new RadioCheckField(writer, kotak6, "abc", "Yes"); _radioG6.CheckType = RadioCheckField.TYPE_CHECK; _radioG6.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG6.BorderColor = BaseColor.Black; _radioG6.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("WEAVING 2")) { _radioG6.Checked = true; } else { _radioG6.Checked = false; } _radioG6.Rotation = 90; _radioG6.Options = TextField.READ_ONLY; _radioField16 = _radioG6.CheckField; cellform6.CellEvent = new BebanUnitEvent(_checkGroup6, _radioField16, 1); headerTable3a.AddCell(cellform6); cellHeaderBody.Phrase = new Phrase("Weaving 2", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform7 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform7.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup7 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG7; PdfFormField _radioField17; Rectangle kotak7 = new Rectangle(100, 100); _radioG7 = new RadioCheckField(writer, kotak7, "abc", "Yes"); _radioG7.CheckType = RadioCheckField.TYPE_CHECK; _radioG7.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG7.BorderColor = BaseColor.Black; _radioG7.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("KONFEKSI 1A")) { _radioG7.Checked = true; } else { _radioG7.Checked = false; } _radioG7.Rotation = 90; _radioG7.Options = TextField.READ_ONLY; _radioField17 = _radioG7.CheckField; cellform7.CellEvent = new BebanUnitEvent(_checkGroup7, _radioField17, 1); headerTable3a.AddCell(cellform7); cellHeaderBody.Phrase = new Phrase("Konfeksi 1A", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform8 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform8.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup8 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG8; PdfFormField _radioField18; Rectangle kotak8 = new Rectangle(100, 100); _radioG8 = new RadioCheckField(writer, kotak8, "abc", "Yes"); _radioG8.CheckType = RadioCheckField.TYPE_CHECK; _radioG8.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG8.BorderColor = BaseColor.Black; _radioG8.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("KONFEKSI 2B")) { _radioG8.Checked = true; } else { _radioG8.Checked = false; } _radioG8.Rotation = 90; _radioG8.Options = TextField.READ_ONLY; _radioField18 = _radioG8.CheckField; cellform8.CellEvent = new BebanUnitEvent(_checkGroup8, _radioField18, 1); headerTable3a.AddCell(cellform8); cellHeaderBody.Phrase = new Phrase("Konfeksi 2 B", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform9 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform9.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup9 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG9; PdfFormField _radioField19; Rectangle kotak9 = new Rectangle(100, 100); _radioG9 = new RadioCheckField(writer, kotak9, "abc", "Yes"); _radioG9.CheckType = RadioCheckField.TYPE_CHECK; _radioG9.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG9.BorderColor = BaseColor.Black; _radioG9.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; string res; if (lastitem.ToUpper() == "SPINNING 1" || lastitem.ToUpper() == "SPINNING 2" || lastitem.ToUpper() == "SPINNING 3" || lastitem.ToUpper() == "WEAVING 1" || lastitem.ToUpper() == "WEAVING 2" || lastitem.ToUpper() == "PRINTING" || lastitem.ToUpper() == "FINISHING" || lastitem.ToUpper() == "KONFEKSI 1A" || lastitem.ToUpper() == "KONFEKSI 1B" || lastitem.ToUpper() == "KONFEKSI 2A" || lastitem.ToUpper() == "KONFEKSI 2B" || lastitem.ToUpper() == "KONFEKSI 2C" || lastitem.ToUpper() == "UMUM") { _radioG9.Checked = false; res = "......."; } else { _radioG9.Checked = true; res = lastitem; } _radioG9.Rotation = 90; _radioG9.Options = TextField.READ_ONLY; _radioField19 = _radioG9.CheckField; cellform9.CellEvent = new BebanUnitEvent(_checkGroup9, _radioField19, 1); headerTable3a.AddCell(cellform9); cellHeaderBody.Phrase = new Phrase(res, normal_font); headerTable3a.AddCell(cellHeaderBody); //================================================ cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform10 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform10.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup10 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG10; PdfFormField _radioField110; Rectangle kotak10 = new Rectangle(100, 100); _radioG10 = new RadioCheckField(writer, kotak10, "abc", "Yes"); _radioG10.CheckType = RadioCheckField.TYPE_CHECK; _radioG10.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG10.BorderColor = BaseColor.Black; _radioG10.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("SPINNING 3")) { _radioG10.Checked = true; } else { _radioG10.Checked = false; } _radioG10.Rotation = 90; _radioG10.Options = TextField.READ_ONLY; _radioField110 = _radioG10.CheckField; cellform10.CellEvent = new BebanUnitEvent(_checkGroup10, _radioField110, 1); headerTable3a.AddCell(cellform10); cellHeaderBody.Phrase = new Phrase("Spinning 3", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform11 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform11.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup11 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG11; PdfFormField _radioField111; Rectangle kotak11 = new Rectangle(100, 100); _radioG11 = new RadioCheckField(writer, kotak11, "abc", "Yes"); _radioG11.CheckType = RadioCheckField.TYPE_CHECK; _radioG11.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG11.BorderColor = BaseColor.Black; _radioG11.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("PRINTING")) { _radioG11.Checked = true; } else { _radioG11.Checked = false; } _radioG11.Rotation = 90; _radioG11.Options = TextField.READ_ONLY; _radioField111 = _radioG11.CheckField; cellform11.CellEvent = new BebanUnitEvent(_checkGroup11, _radioField111, 1); headerTable3a.AddCell(cellform11); cellHeaderBody.Phrase = new Phrase("Printing", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform12 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform12.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup12 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG12; PdfFormField _radioField112; Rectangle kotak12 = new Rectangle(100, 100); _radioG12 = new RadioCheckField(writer, kotak12, "abc", "Yes"); _radioG12.CheckType = RadioCheckField.TYPE_CHECK; _radioG12.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG12.BorderColor = BaseColor.Black; _radioG12.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("KONFEKSI 1B")) { _radioG12.Checked = true; } else { _radioG12.Checked = false; } _radioG12.Rotation = 90; _radioG12.Options = TextField.READ_ONLY; _radioField112 = _radioG12.CheckField; cellform12.CellEvent = new BebanUnitEvent(_checkGroup12, _radioField112, 1); headerTable3a.AddCell(cellform12); cellHeaderBody.Phrase = new Phrase("Konfeksi 1B", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); PdfPCell cellform13 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform13.FixedHeight = 5f; //initiate form checkbox PdfFormField _checkGroup13 = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG13; PdfFormField _radioField113; Rectangle kotak13 = new Rectangle(100, 100); _radioG13 = new RadioCheckField(writer, kotak13, "abc", "Yes"); _radioG13.CheckType = RadioCheckField.TYPE_CHECK; _radioG13.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG13.BorderColor = BaseColor.Black; _radioG13.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; if (unit.ToUpper().Contains("KONFEKSI 2C")) { _radioG13.Checked = true; } else { _radioG13.Checked = false; } _radioG13.Rotation = 90; _radioG13.Options = TextField.READ_ONLY; _radioField113 = _radioG13.CheckField; cellform13.CellEvent = new BebanUnitEvent(_checkGroup13, _radioField113, 1); headerTable3a.AddCell(cellform13); cellHeaderBody.Phrase = new Phrase("Konfeksi 2C", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(" ", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(" ", normal_font); headerTable3a.AddCell(cellHeaderBody); cellHeader3a.AddElement(headerTable3a); headerTable_C.AddCell(cellHeader3a); document.Add(headerTable_C); writer.AddAnnotation(_checkGroup); writer.AddAnnotation(_checkGroup1); writer.AddAnnotation(_checkGroup2); writer.AddAnnotation(_checkGroup3); writer.AddAnnotation(_checkGroup4); writer.AddAnnotation(_checkGroup5); writer.AddAnnotation(_checkGroup6); writer.AddAnnotation(_checkGroup7); writer.AddAnnotation(_checkGroup8); writer.AddAnnotation(_checkGroup9); writer.AddAnnotation(_checkGroup10); writer.AddAnnotation(_checkGroup11); writer.AddAnnotation(_checkGroup12); writer.AddAnnotation(_checkGroup13); #endregion #region Footer PdfPTable table = new PdfPTable(4) { WidthPercentage = 100 }; float[] widths = new float[] { 1f, 1f, 1f, 1f }; table.SetWidths(widths); PdfPCell cell = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, }; PdfPCell cellLeft = new PdfPCell() { HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, }; PdfPCell cellColspan = new PdfPCell() { Colspan = 4, Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, }; cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("Menyetujui,", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("Mengetahui,", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("Diminta Oleh,", normal_font); table.AddCell(cell); for (var i = 0; i < 11; i++) { cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); } cell.Phrase = new Phrase("(..................)", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("(..................)", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("(..................)", normal_font); table.AddCell(cell); cell.Phrase = new Phrase($"({viewModel.CreatedBy})", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("Kasir", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("Anggaran", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("..................", normal_font); table.AddCell(cell); cell.Phrase = new Phrase($"Bag. {viewModel.Unit.Name}", normal_font); table.AddCell(cell); document.Add(table); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingCreditNoteViewModel viewModel, int timeoffset) { Font normal_font = FontFactory.GetFont(BaseFont.COURIER, 10, Font.NORMAL); Font underlined_font = FontFactory.GetFont(BaseFont.COURIER, 10, Font.UNDERLINE); Font big_font = FontFactory.GetFont(BaseFont.COURIER, 16, Font.BOLD); Document document = new Document(PageSize.A4, 20, 20, 20, 20); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); var chunkHeader = new Chunk("PT. DAN LIRIS", big_font); chunkHeader.SetHorizontalScaling(1.5f); document.Add(new Paragraph(chunkHeader)); PdfPTable tableHeadOffice = new PdfPTable(2); tableHeadOffice.SetWidths(new float[] { 1.5f, 6.5f }); PdfPCell cellHeadOffice = new PdfPCell { Border = Rectangle.NO_BORDER }; cellHeadOffice.Phrase = new Phrase("Head Office : ", normal_font); tableHeadOffice.AddCell(cellHeadOffice); cellHeadOffice.Phrase = new Phrase("Jl. Merapi No. 23, Kel. Banaran Kec. Grogol Kab. Sukoharjo\nTelp.(0271)714400, Fax.(0271)735222\ne-Mail:", normal_font); cellHeadOffice.Phrase.Add(new Chunk("*****@*****.**", underlined_font)); tableHeadOffice.AddCell(cellHeadOffice); Chunk chunkAddress = new Chunk("MESSRS :\n" + viewModel.buyer.Name + "\n" + viewModel.buyer.Address, normal_font); chunkAddress.SetHorizontalScaling(0.8f); Phrase phraseBuyerHeader = new Phrase(chunkAddress); //phraseBuyerHeader.Add(new Chunk(new VerticalPositionMark())); //phraseBuyerHeader.Add(new Chunk("CREDIT NOTE", normal_font)); phraseBuyerHeader.Add(new Chunk(new VerticalPositionMark())); phraseBuyerHeader.Add(new Chunk("DATE : " + viewModel.date.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font)); tableHeadOffice.AddCell(new PdfPCell { Border = Rectangle.NO_BORDER, Colspan = 2, PaddingLeft = 10f, Phrase = phraseBuyerHeader }); new PdfPCell(tableHeadOffice); tableHeadOffice.ExtendLastRow = false; tableHeadOffice.SpacingAfter = 5f; document.Add(tableHeadOffice); document.Add(new Paragraph("CREDIT NOTE", big_font) { Alignment = Element.ALIGN_CENTER, SpacingAfter = 5f }); document.Add(new Paragraph(viewModel.noteNo, big_font) { Alignment = Element.ALIGN_RIGHT, SpacingAfter = 5f }); PdfPTable tableItems = new PdfPTable(2); tableItems.SetWidths(new float[] { 3f, 1f }); tableItems.AddCell(new PdfPCell { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, Phrase = new Phrase("D e s c r i p t i o n", normal_font) }); tableItems.AddCell(new PdfPCell { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, Phrase = new Phrase("Amount", normal_font) }); PdfPTable tableItemsContent = new PdfPTable(2); tableItemsContent.SetWidths(new float[] { 3f, 1f }); tableItemsContent.AddCell(new PdfPCell { Border = Rectangle.NO_BORDER, Phrase = new Phrase(viewModel.description, normal_font) }); tableItemsContent.AddCell(new PdfPCell { Border = Rectangle.LEFT_BORDER, Phrase = new Phrase(" ", normal_font) }); foreach (var item in viewModel.items) { tableItemsContent.AddCell(new PdfPCell { Border = Rectangle.NO_BORDER, Phrase = new Phrase(item.description, normal_font) }); Phrase phraseAmount = new Phrase(); phraseAmount.Add(new Chunk(item.currency.Code, normal_font)); phraseAmount.Add(new Chunk(new VerticalPositionMark())); phraseAmount.Add(new Chunk(item.amount.ToString("n"), normal_font)); tableItemsContent.AddCell(new PdfPCell { Border = Rectangle.LEFT_BORDER, Phrase = phraseAmount }); } PdfPCell pdfPCellItemsContent = new PdfPCell { Colspan = 2, Padding = 0, Border = Rectangle.NO_BORDER, MinimumHeight = 400 }; new PdfPCell(tableItemsContent); pdfPCellItemsContent.AddElement(tableItemsContent); tableItems.AddCell(pdfPCellItemsContent); tableItems.AddCell(new PdfPCell { Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, PaddingRight = 10, Phrase = new Phrase("TOTAL", normal_font) }); Phrase phraseTotalAmount = new Phrase(); phraseTotalAmount.Add(new Chunk(viewModel.items.FirstOrDefault().currency.Code, normal_font)); phraseTotalAmount.Add(new Chunk(new VerticalPositionMark())); phraseTotalAmount.Add(new Chunk(viewModel.totalAmount.ToString("n"), normal_font)); tableItems.AddCell(new PdfPCell { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, Phrase = phraseTotalAmount }); //tableItems.AddCell(new PdfPCell //{ // Colspan = 2, // PaddingBottom = 10f, // Border = Rectangle.NO_BORDER, // Phrase = new Phrase("KETERANGAN : " + viewModel.description, normal_font) //}); string amountToText = ""; amountToText = CurrencyToText.ToWords(Convert.ToDecimal(viewModel.totalAmount)); if (viewModel.items.FirstOrDefault().currency.Code == "USD") { tableItems.AddCell(new PdfPCell { Colspan = 2, PaddingBottom = 10f, Border = Rectangle.NO_BORDER, Phrase = new Phrase("SAY : US DOLLARS " + amountToText.ToUpper() + " ONLY ///", normal_font) //Phrase = new Phrase("SAY : US DOLLARS " + NumberToTextEN.toWords(viewModel.totalAmount).Trim().ToUpper() + " ONLY ///", normal_font) }); } else { tableItems.AddCell(new PdfPCell { Colspan = 2, PaddingBottom = 10f, Border = Rectangle.NO_BORDER, Phrase = new Phrase("TERBILANG : " + NumberToTextIDN.terbilang(viewModel.totalAmount).Trim().ToUpper() + " RUPIAH ///", normal_font) }); } tableItems.AddCell(new PdfPCell { Border = Rectangle.NO_BORDER, PaddingRight = 10f, Phrase = new Phrase(" ", normal_font) }); Phrase phraseSign = new Phrase(); phraseSign.Add(new Chunk("S.E. & O\n" + viewModel.date.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")) + "\n\n\n\n", normal_font)); Chunk chunkSignName = new Chunk("WAHYU PAMUNGKAS", normal_font); chunkSignName.SetUnderline(1, -1); phraseSign.Add(chunkSignName); phraseSign.Add(new Chunk("\nAUTHORIZED SIGNATURE", normal_font)); tableItems.AddCell(new PdfPCell { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, Phrase = phraseSign }); new PdfPCell(tableItems); tableItems.ExtendLastRow = false; tableItems.SpacingAfter = 5f; document.Add(tableItems); document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(PaymentDispositionNoteViewModel viewModel, int clientTimeZoneOffset) { const int MARGIN = 15; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A4, MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region Header PdfPTable headerTable = new PdfPTable(2); headerTable.SetWidths(new float[] { 10f, 10f }); headerTable.WidthPercentage = 100; PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(2); headerTable2.SetWidths(new float[] { 15f, 40f }); headerTable2.WidthPercentage = 100; PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderCS2 = new PdfPCell() { Border = Rectangle.NO_BORDER, Colspan = 2 }; cellHeaderCS2.Phrase = new Phrase("BUKTI PENGELUARAN BANK - DISPOSISI", bold_font); cellHeaderCS2.HorizontalAlignment = Element.ALIGN_CENTER; headerTable.AddCell(cellHeaderCS2); cellHeaderCS2.Phrase = new Phrase("", bold_font); cellHeaderCS2.HorizontalAlignment = Element.ALIGN_CENTER; headerTable.AddCell(cellHeaderCS2); cellHeaderBody.Phrase = new Phrase("PT. DANLIRIS", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Kel. Banaran, Kec. Grogol", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Sukoharjo - 57100", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeader1.AddElement(headerTable1); headerTable.AddCell(cellHeader1); cellHeaderCS2.Phrase = new Phrase("", bold_font); headerTable2.AddCell(cellHeaderCS2); cellHeaderBody.Phrase = new Phrase("Tanggal", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.PaymentDate.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("NO", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.PaymentDispositionNo, normal_font); headerTable2.AddCell(cellHeaderBody); //List<string> supplier = model.Details.Select(m => m.SupplierName).Distinct().ToList(); cellHeaderBody.Phrase = new Phrase("Dibayarkan ke", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.Supplier.Name, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Bank", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase(": " + viewModel.AccountBank.BankName + " - A/C : " + viewModel.AccountBank.AccountNumber, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeader2.AddElement(headerTable2); headerTable.AddCell(cellHeader2); cellHeaderCS2.Phrase = new Phrase("", normal_font); headerTable.AddCell(cellHeaderCS2); document.Add(headerTable); #endregion Header Dictionary <string, double> units = new Dictionary <string, double>(); Dictionary <string, double> percentageUnits = new Dictionary <string, double>(); int index = 1; double total = 0; double totalPay = 0; if (viewModel.AccountBank.Currency.Code != "IDR" || viewModel.CurrencyCode == "IDR") { #region BodyNonIDR PdfPTable bodyNonIDRTable = new PdfPTable(6); PdfPCell bodyNonIDRCell = new PdfPCell(); float[] widthsBodyNonIDR = new float[] { 5f, 10f, 10f, 10f, 7f, 15f }; bodyNonIDRTable.SetWidths(widthsBodyNonIDR); bodyNonIDRTable.WidthPercentage = 100; bodyNonIDRCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyNonIDRCell.Phrase = new Phrase("No.", bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Phrase = new Phrase("No. Disposisi", bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Phrase = new Phrase("Kategori Barang", bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Phrase = new Phrase("Divisi", bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Phrase = new Phrase("Mata Uang", bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Phrase = new Phrase("Jumlah", bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); foreach (PaymentDispositionNoteItemViewModel item in viewModel.Items) { var details = item.Details .GroupBy(m => new { m.unit.code, m.unit.name }) .Select(s => new { s.First().unit.code, s.First().unit.name, Total = s.Sum(d => d.price) }); bodyNonIDRCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyNonIDRCell.VerticalAlignment = Element.ALIGN_TOP; bodyNonIDRCell.Phrase = new Phrase((index++).ToString(), normal_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyNonIDRCell.Phrase = new Phrase(item.dispositionNo, normal_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Phrase = new Phrase(item.category.name, normal_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Phrase = new Phrase(item.division.name, normal_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyNonIDRCell.Phrase = new Phrase(viewModel.AccountBank.Currency.Code, normal_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyNonIDRCell.Phrase = new Phrase(string.Format("{0:n4}", item.payToSupplier), normal_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); total += item.payToSupplier; foreach (var detail in details) { if (units.ContainsKey(detail.code)) { units[detail.code] += detail.Total; } else { units.Add(detail.code, detail.Total); } totalPay += detail.Total; } } foreach (var un in units) { percentageUnits[un.Key] = un.Value * 100 / totalPay; } bodyNonIDRCell.Colspan = 3; bodyNonIDRCell.Border = Rectangle.NO_BORDER; bodyNonIDRCell.Phrase = new Phrase("", normal_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Colspan = 1; bodyNonIDRCell.Border = Rectangle.BOX; bodyNonIDRCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyNonIDRCell.Phrase = new Phrase("Total", bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.Colspan = 1; bodyNonIDRCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyNonIDRCell.Phrase = new Phrase(viewModel.AccountBank.Currency.Code, bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); bodyNonIDRCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyNonIDRCell.Phrase = new Phrase(string.Format("{0:n4}", total), bold_font); bodyNonIDRTable.AddCell(bodyNonIDRCell); document.Add(bodyNonIDRTable); #endregion BodyNonIDR } else { #region Body PdfPTable bodyTable = new PdfPTable(7); PdfPCell bodyCell = new PdfPCell(); float[] widthsBody = new float[] { 5f, 10f, 10f, 10f, 7f, 10f, 10f }; bodyTable.SetWidths(widthsBody); bodyTable.WidthPercentage = 100; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase("No.", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("No. Disposisi", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Kategori Barang", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Divisi", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Mata Uang", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Jumlah", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Jumlah (IDR)", bold_font); bodyTable.AddCell(bodyCell); foreach (PaymentDispositionNoteItemViewModel item in viewModel.Items) { var details = item.Details .GroupBy(m => new { m.unit.code, m.unit.name }) .Select(s => new { s.First().unit.code, s.First().unit.name, Total = s.Sum(d => d.price) }); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.VerticalAlignment = Element.ALIGN_TOP; bodyCell.Phrase = new Phrase((index++).ToString(), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.dispositionNo, normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase(item.category.name, normal_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase(item.division.name, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(viewModel.CurrencyCode, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", item.payToSupplier), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", (item.payToSupplier * viewModel.CurrencyRate)), normal_font); bodyTable.AddCell(bodyCell); total += item.payToSupplier; foreach (var detail in details) { if (units.ContainsKey(detail.code)) { units[detail.code] += detail.Total; } else { units.Add(detail.code, detail.Total); } totalPay += detail.Total; } } foreach (var un in units) { percentageUnits[un.Key] = (un.Value * viewModel.CurrencyRate) * 100 / (totalPay * viewModel.CurrencyRate); } bodyCell.Colspan = 3; bodyCell.Border = Rectangle.NO_BORDER; bodyCell.Phrase = new Phrase("", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.Border = Rectangle.BOX; bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase("Total", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(viewModel.AccountBank.Currency.Code, bold_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", total), bold_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n4}", total * viewModel.CurrencyRate), bold_font); bodyTable.AddCell(bodyCell); document.Add(bodyTable); #endregion Body } #region BodyFooter PdfPTable bodyFooterTable = new PdfPTable(6); bodyFooterTable.SetWidths(new float[] { 3f, 6f, 2f, 6f, 10f, 10f }); bodyFooterTable.WidthPercentage = 100; PdfPCell bodyFooterCell = new PdfPCell() { Border = Rectangle.NO_BORDER }; bodyFooterCell.Colspan = 1; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 1; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase("Rincian per bagian:", normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 4; bodyFooterCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); total = viewModel.CurrencyId > 0 ? total * viewModel.CurrencyRate : total; foreach (var unit in percentageUnits) { bodyFooterCell.Colspan = 1; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(unit.Key, normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(viewModel.AccountBank.Currency.Code, normal_font); bodyFooterTable.AddCell(bodyFooterCell); //bodyFooterCell.Phrase = new Phrase(string.Format("{0:n4}", unit.Value), normal_font); //bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase(string.Format("{0:n4}", unit.Value * total / 100), normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 2; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); } bodyFooterCell.Colspan = 6; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 1; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase(""); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Phrase = new Phrase("Terbilang", normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyFooterCell.Phrase = new Phrase(": " + viewModel.AccountBank.Currency.Code, normal_font); bodyFooterTable.AddCell(bodyFooterCell); bodyFooterCell.Colspan = 3; bodyFooterCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyFooterCell.Phrase = new Phrase(NumberToTextIDN.terbilang(total), normal_font); bodyFooterTable.AddCell(bodyFooterCell); document.Add(bodyFooterTable); document.Add(new Paragraph("\n")); #endregion BodyFooter #region Footer PdfPTable footerTable = new PdfPTable(2); PdfPCell cellFooter = new PdfPCell() { Border = Rectangle.NO_BORDER }; float[] widthsFooter = new float[] { 10f, 5f }; footerTable.SetWidths(widthsFooter); footerTable.WidthPercentage = 100; cellFooter.Phrase = new Phrase("Dikeluarkan dengan cek/BG No. : " + viewModel.BGCheckNumber, normal_font); footerTable.AddCell(cellFooter); cellFooter.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooter); PdfPTable signatureTable = new PdfPTable(3); PdfPCell signatureCell = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER }; signatureCell.Phrase = new Phrase("Bag. Keuangan", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Colspan = 2; signatureCell.HorizontalAlignment = Element.ALIGN_CENTER; signatureCell.Phrase = new Phrase("Direksi", normal_font); signatureTable.AddCell(signatureCell); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, Border = Rectangle.NO_BORDER, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("---------------------------", normal_font), FixedHeight = 40, Border = Rectangle.NO_BORDER, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); footerTable.AddCell(new PdfPCell(signatureTable)); cellFooter.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooter); document.Add(footerTable); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(FormDto viewModel, int clientTimeZoneOffset, string userName) { Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font small_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font smaller_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font2 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font3 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font bold_font4 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellCenterTopNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellJustifyNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED }; PdfPCell cellJustifyAllNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL }; PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRightMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellLeftMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; Document document = new Document(PageSize.A4, 30, 30, 100, 30); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new TextEvents(viewModel.DispositionNo); document.Open(); string fmString = "FM-PB-00-06-011"; Paragraph fm = new Paragraph(fmString, bold_font4) { Alignment = Element.ALIGN_RIGHT }; //string titleString = "DISPOSISI PEMBAYARAN"; //Paragraph title = new Paragraph(titleString, bold_font4) { Alignment = Element.ALIGN_CENTER }; //document.Add(title); bold_font.SetStyle(Font.NORMAL); //string NoString = "NO : " + viewModel.DispositionNo; //Paragraph dispoNumber = new Paragraph(NoString, bold_font4) { Alignment = Element.ALIGN_CENTER }; //dispoNumber.SpacingAfter = 20f; //document.Add(dispoNumber); #region Identity PdfPTable tableIdentity = new PdfPTable(5); tableIdentity.SetWidths(new float[] { 5f, 0.5f, 2f, 7f, 4f }); double dpp = 0; foreach (var item in viewModel.Items) { foreach (var detail in item.Details) { dpp += detail.PaidPrice; } } double ppn = (dpp * 0.1); string pph = ""; double pphRate = 0; foreach (var item in viewModel.Items) { if (!item.IsUseVat) { ppn = 0; } if (item.IsUseIncomeTax) { pph = item.IncomeTaxName; pphRate = dpp * (Convert.ToDouble(item.IncomeTaxRate) / 100); } break; } //Jumlah dibayar ke Supplier double paidToSupp = dpp + ppn - pphRate; //if (viewModel.IncomeTaxBy == "Dan Liris") //{ // paidToSupp = dpp + ppn; //} double amount = dpp + ppn; //if (viewModel.IncomeTaxBy == "Dan Liris") //{ // amount = dpp + ppn + pphRate; //} var payingDisposition = Math.Round((paidToSupp + viewModel.MiscAmount + pphRate), 2, MidpointRounding.AwayFromZero); cellLeftNoBorder.SetLeading(13f, 0f); cellLeftNoBorder.Phrase = new Phrase("Mohon Disposisi Pembayaran", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.PaymentType + " " + viewModel.CurrencyCode + " " + $"{(paidToSupp + viewModel.MiscAmount).ToString("N", new CultureInfo("id-ID"))}", normal_font); /*$"{viewModel.Amount.ToString("N", new CultureInfo("id-ID"))}", normal_font);*/ cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase( viewModel.Currency.code + " " + $"{(paidToSupp + viewModel.PaymentCorrection + pphRate).ToString("N", new CultureInfo("id-ID")) }", normal_font); //tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 0; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Terbilang", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{ NumberToTextIDN.terbilang(viewModel.Amount) }" + " " + (viewModel.CurrencyCode == "IDR"?"Rupiah":viewModel.CurrencyCode == "USD"?"Dollar":viewModel.CurrencyCode), normal_font); cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Perhitungan :", bold_font3); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); //calculate vat and incomeTax double vat = 0; double incomeTax = 0; foreach (var item in viewModel.Items) { if (item.IsPayVat) { vat += item.VatValue; } if (item.IsPayIncomeTax) { incomeTax += item.IncomeTaxValue; } } cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Biaya", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{viewModel.DPP.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("(PPn)", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{viewModel.VatValue.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Total", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{(viewModel.DPP + vat).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); var pphDanliris = pphRate; //if (viewModel.IncomeTaxBy == "Dan Liris") //{ // pphDanliris = 0; //} cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("PPh " + pph, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{viewModel.IncomeTaxValue.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Jumlah dibayar ke Supplier ", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 2; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{(viewModel.DPP+ vat - incomeTax).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Biaya Lain - Lain", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{viewModel.MiscAmount.ToString("N", new CultureInfo("id-ID"))}", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellSuppLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellSuppMid = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellSuppRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; cellSuppLeft.Phrase = new Phrase("Total dibayar ke Supplier", normal_font); tableIdentity.AddCell(cellSuppLeft); cellSuppMid.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellSuppMid); cellSuppRight.Colspan = 2; cellSuppRight.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{((viewModel.DPP + vat - incomeTax)+viewModel.MiscAmount).ToString("N", new CultureInfo("id-ID"))}", normal_font); tableIdentity.AddCell(cellSuppRight); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Pembayaran ditransfer ke", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Bank, normal_font); cellLeftNoBorder.Colspan = 3; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Dibayar ke Kas Negara", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{(viewModel.IncomeTaxValue).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellIdentity = new PdfPCell(tableIdentity); tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 15f; document.Add(tableIdentity); #endregion #region Content PdfPTable tableContent = new PdfPTable(9); tableContent.SetWidths(new float[] { 6f, 5f, 4f, 3f, 3f, 2.5f, 2.5f, 3.5f, 3f }); cellCenter.Phrase = new Phrase("Nama Barang", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PO Internal", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PO Eksternal", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("QTY Dipesan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("QTY Dibayar", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("QTY Sisa", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Satuan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga Satuan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("% Over Qty", bold_font); tableContent.AddCell(cellCenter); double total = 0; double totalPurchase = 0; foreach (FormItemDto item in viewModel.Items) { for (int indexItem = 0; indexItem < item.Details.Count; indexItem++) { FormDetailDto detail = item.Details[indexItem]; var unitName = detail.UnitName; //var unitName = ""; //var unitId = detail.Unit._id; //if (unitId == "50") //{ // unitName = "WEAVING"; //} //else if (unitId == "35") //{ // unitName = "SPINNING 1"; //} //else //{ //unitName = detail.UnitName; //} cellLeft.Colspan = 0; cellLeft.Phrase = new Phrase($"{detail.ProductName}", smaller_font); tableContent.AddCell(cellLeft); cellCenter.Colspan = 0; cellCenter.Phrase = new Phrase($"{detail.IPONo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{item.EPONo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.QTYOrder}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.QTYPaid}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.QTYRemains}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.QTYUnit}", smaller_font); tableContent.AddCell(cellCenter); cellRightMerge.Phrase = new Phrase($"{detail.PricePerQTY.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); cellCenter.Phrase = new Phrase($"{detail.PercentageOverQTY.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellCenter); double subtotalPrice = detail.PercentageOverQTY; total += detail.PaidPrice; totalPurchase += (detail.PricePerQTY * detail.QTYOrder); } } PdfPCell cellContent = new PdfPCell(tableContent); // dont remove tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 10f; document.Add(tableContent); #endregion #region note PdfPTable tableNote = new PdfPTable(3); tableNote.SetWidths(new float[] { 4f, 0.5f, 11f }); cellLeftNoBorder.Phrase = new Phrase("Note :", bold_font3); cellLeftNoBorder.Colspan = 4; tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Kategori", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Category, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Supplier / Agent", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.SupplierName, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Order Confirmation", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ConfirmationOrderNo, normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase("No Invoice", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(":", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(viewModel.InvoiceNo, normal_font); //tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Proforma/Invoice", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ProformaNo, normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase("Investasi", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(":", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(viewModel.Investation, normal_font); //tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Mohon dibayar Tanggal", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.PaymentDueDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase("Bank", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(":", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(viewModel.Bank, normal_font); //tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Keterangan", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Remark, normal_font); tableNote.AddCell(cellLeftNoBorder); var ppnPurchase = viewModel.VatValue > 0 ? (totalPurchase * 10 / 100) : 0; cellLeftNoBorder.Phrase = new Phrase("Total Pembelian", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase($"{viewModel.CurrencyCode}" + " " + $"{(totalPurchase + ppnPurchase).ToString("N", new CultureInfo("id-ID"))}", normal_font); cellLeftNoBorder.Phrase = new Phrase($"{viewModel.CurrencyCode}" + " " + $"{((viewModel.DPP + vat)- incomeTax).ToString("N", new CultureInfo("id-ID"))}", normal_font); tableNote.AddCell(cellLeftNoBorder); PdfPCell cellNote = new PdfPCell(tableNote); // dont remove tableNote.ExtendLastRow = false; tableNote.SpacingAfter = 20f; document.Add(tableNote); #endregion #region beban PdfPTable tableBeban = new PdfPTable(1); tableBeban.SetWidths(new float[] { 5f }); cellLeftNoBorder.Phrase = new Phrase("Beban Unit :", bold_font3);; tableBeban.AddCell(cellLeftNoBorder); var AmountPerUnit = viewModel.Items.SelectMany(s => s.Details) .GroupBy( key => new { key.UnitId, key.UnitName, key.UnitCode }, val => val, (key, val) => new { Key = key, Value = val } ).ToList(); foreach (var perUnit in AmountPerUnit) { var sumPerUnit = perUnit.Value.Sum(t => (t.PaidPrice) + (viewModel.Items.Where(a => a.Id == t.GarmentDispositionPurchaseItemId).FirstOrDefault().IsPayVat? t.PaidPrice * 0.1:0) - (t.PaidPrice * (viewModel.Items.Where(a => a.Id == t.GarmentDispositionPurchaseItemId).FirstOrDefault()?.IncomeTaxRate / 100)))?.ToString("N", new CultureInfo("id-ID")); cellLeftNoBorder.Phrase = new Phrase($"- {perUnit.Key.UnitName} = {sumPerUnit}", bold_font3); tableBeban.AddCell(cellLeftNoBorder); } PdfPCell cellBeban = new PdfPCell(tableBeban); // dont remove tableBeban.ExtendLastRow = false; document.Add(tableBeban); #endregion #region signature PdfPTable tableSignature = new PdfPTable(5); tableSignature.SetWidths(new float[] { 4f, 4f, 4f, 4f, 4.5f }); PdfPCell cellSignatureContent = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellSignatureContent.Phrase = new Phrase("", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("", bold_font3); cellSignatureContent.Colspan = 3; tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 0; cellSignatureContent.Phrase = new Phrase("Sukoharjo, " + viewModel.CreatedUtc.ToString("dd MMMM yyyy", new CultureInfo("id-ID")), bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 2; cellSignatureContent.Phrase = new Phrase("Menyetujui,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("Mengetahui,", bold_font3); cellSignatureContent.Colspan = 2; tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 0; cellSignatureContent.Phrase = new Phrase("Hormat Kami,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( Hendro Suseno )\n Direktur Keuangan", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( Verifikasi )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( Kabag Pembelian )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( Kasie Pembelian )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( " + userName + " )", bold_font3); tableSignature.AddCell(cellSignatureContent); //PdfPCell cellSignatureContentDir = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER,VerticalAlignment=Element.ALIGN_TOP }; //cellSignatureContentDir.Phrase = new Phrase("\n\n\n\n\n\n\n Direktur Keuangan ", bold_font3); //tableSignature.AddCell(cellSignatureContentDir); //cellSignatureContentDir.Colspan = 4; //cellSignatureContentDir.Phrase = new Phrase("", bold_font3); //tableSignature.AddCell(cellSignatureContentDir); PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove tableSignature.ExtendLastRow = false; tableSignature.SpacingBefore = 10f; tableSignature.SpacingAfter = 20f; document.Add(tableSignature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingPaymentDispositionViewModel viewModel, List <GarmentShippingInvoiceViewModel> invoices, int timeoffset) { const int MARGIN = 20; Font header_font_bold_big = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font header_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12, Font.UNDERLINE); Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE); Font normal_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 40, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region header Paragraph title = new Paragraph("LAMPIRAN DISPOSISI PEMBAYARAN FORWARDER\n\n\n", header_font_bold); title.Alignment = Element.ALIGN_CENTER; Paragraph title1 = new Paragraph("DISPOSISI BIAYA SHIPMENT", normal_font_underlined); Paragraph no = new Paragraph(viewModel.dispositionNo, normal_font); Paragraph fwd = new Paragraph($"Invoice {viewModel.forwarder.name} No. {viewModel.invoiceNumber} Tgl. " + $"{viewModel.invoiceDate.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font); document.Add(title); document.Add(title1); document.Add(no); document.Add(fwd); document.Add(new Paragraph("\n", normal_font)); #endregion #region bodyTable List <string> inv = new List <string>(); List <string> como = new List <string>(); foreach (var i in invoices) { var dupInv = como.Find(a => a == i.InvoiceNo); if (string.IsNullOrEmpty(dupInv)) { inv.Add(i.InvoiceNo); } foreach (var item in i.Items) { var dupComo = como.Find(a => a == item.Comodity.Name); if (string.IsNullOrEmpty(dupComo)) { como.Add(item.Comodity.Name); } } } decimal invTotalQty = viewModel.invoiceDetails.Sum(a => a.quantity); decimal totalCtns = viewModel.invoiceDetails.Sum(a => a.totalCarton); PdfPTable tableBody = new PdfPTable(7); tableBody.WidthPercentage = 80; tableBody.SetWidths(new float[] { 3f, 0.5f, 5f, 0.5f, 1f, 4f, 1f }); PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellLeftNoBorder1 = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellLeftTopBorder = new PdfPCell() { Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRightTopBorder = new PdfPCell() { Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellRightNoLeftBorder = new PdfPCell() { Border = Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellLeftBottomBorder = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; cellLeftNoBorder.Phrase = new Phrase("Dikirim per", normal_font); cellLeftNoBorder.Colspan = 1; tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.sendBy, normal_font); cellLeftNoBorder1.Colspan = 5; tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Flight / Route", normal_font); cellLeftNoBorder.Colspan = 1; tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.flightVessel, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Destination To", normal_font); cellLeftNoBorder.Colspan = 1; tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.destination, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase(viewModel.freightBy == "AIR"?"AWB No." : "BL No.", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.freightNo, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Tgl", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.freightDate.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID")), normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Dscription", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(string.Join(", ", como), normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Shipping Co.", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.forwarder.name, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("Buyer", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.buyerAgent.Name, normal_font); tableBody.AddCell(cellLeftNoBorder1); cellLeftNoBorder.Phrase = new Phrase("LC No.", normal_font); tableBody.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBody.AddCell(cellCenterNoBorder); cellLeftNoBorder1.Phrase = new Phrase(viewModel.paymentTerm, normal_font); tableBody.AddCell(cellLeftNoBorder1); tableBody.SpacingAfter = 10; tableBody.SpacingBefore = 5; tableBody.HorizontalAlignment = Element.ALIGN_LEFT; document.Add(tableBody); #endregion #region unit PdfPTable tableUnit = new PdfPTable(8); tableUnit.WidthPercentage = 100; tableUnit.SetWidths(new float[] { 4f, 0.5f, 4f, 4f, 4f, 4f, 4f, 4f }); PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; cellCenter.Phrase = new Phrase("Invoice No", normal_font); tableUnit.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Amount", normal_font); cellCenter.Colspan = 2; tableUnit.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Qty", normal_font); cellCenter.Colspan = 1; tableUnit.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Volume", normal_font); tableUnit.AddCell(cellCenter); cellCenter.Phrase = new Phrase("G.W.", normal_font); tableUnit.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Chargeable Weight", normal_font); tableUnit.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Total Carton", normal_font); tableUnit.AddCell(cellCenter); foreach (var invoice in viewModel.invoiceDetails) { cellLeft.Phrase = new Phrase(invoice.invoiceNo, normal_font); tableUnit.AddCell(cellLeft); cellLeftBottomBorder.Phrase = new Phrase("$", normal_font); tableUnit.AddCell(cellLeftBottomBorder); cellRightNoLeftBorder.Phrase = new Phrase(string.Format("{0:n2}", invoice.amount), normal_font); tableUnit.AddCell(cellRightNoLeftBorder); cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.quantity) + " pcs", normal_font); tableUnit.AddCell(cellRight); cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.volume) + " cbm", normal_font); tableUnit.AddCell(cellRight); cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.grossWeight) + " kgs", normal_font); tableUnit.AddCell(cellRight); cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.chargeableWeight) + " kgs", normal_font); tableUnit.AddCell(cellRight); cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.totalCarton) + " ctns", normal_font); tableUnit.AddCell(cellRight); } tableUnit.SpacingAfter = 10; tableUnit.SpacingBefore = 5; tableUnit.HorizontalAlignment = Element.ALIGN_LEFT; document.Add(tableUnit); #endregion #region bill document.Add(new Phrase("Realisasi biaya :", normal_font)); PdfPTable tableBill = new PdfPTable(7); tableBill.WidthPercentage = 95; tableBill.SetWidths(new float[] { 2f, 0.5f, 7f, 0.5f, 1f, 3f, 1f }); var last = viewModel.billDetails.Last(); foreach (var bill in viewModel.billDetails) { cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("- " + bill.billDescription, normal_font); tableBill.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBill.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("IDR", normal_font); tableBill.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", bill.amount), normal_font); tableBill.AddCell(cellRightNoBorder); if (bill == last) { cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font); tableBill.AddCell(cellLeftNoBorder); } else { cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); } } cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold); tableBill.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("IDR", normal_font); tableBill.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue), normal_font); tableBill.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"- PPH {viewModel.incomeTax.name} ({viewModel.incomeTax.rate}%)", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font_bold); tableBill.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("IDR", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.IncomeTaxValue), normal_font_bold); tableBill.AddCell(cellRightNoBorder); cellLeftNoBorder.Phrase = new Phrase("(-)", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold); tableBill.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("IDR", normal_font); tableBill.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue - viewModel.IncomeTaxValue), normal_font); tableBill.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("- PPN", normal_font); tableBill.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase(":", normal_font); tableBill.AddCell(cellCenterNoBorder); cellLeftNoBorder.Phrase = new Phrase("IDR", normal_font); tableBill.AddCell(cellLeftNoBorder); cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.vatValue), normal_font); tableBill.AddCell(cellRightNoBorder); cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableBill.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"Total bayar setelah PPH {viewModel.incomeTax.name} & PPN", normal_font); tableBill.AddCell(cellLeftNoBorder); cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold); tableBill.AddCell(cellCenterNoBorder); cellLeftTopBorder.Phrase = new Phrase("IDR", normal_font_bold); tableBill.AddCell(cellLeftTopBorder); cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.totalBill), normal_font_bold); tableBill.AddCell(cellRightTopBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold); tableBill.AddCell(cellLeftNoBorder); tableBill.SpacingAfter = 10; tableBill.SpacingBefore = 5; tableBill.HorizontalAlignment = Element.ALIGN_CENTER; document.Add(tableBill); #endregion var terbilang = NumberToTextIDN.terbilang((double)viewModel.totalBill) + " rupiah"; Paragraph trbilang = new Paragraph($"[ Terbilang : {terbilang} ]\n\n", normal_font); document.Add(trbilang); document.Add(new Paragraph("Lampiran : " + viewModel.remark + "\n\n", normal_font)); #region sign PdfPTable tableSign = new PdfPTable(3); tableSign.WidthPercentage = 100; tableSign.SetWidths(new float[] { 1f, 1f, 1f }); PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodySignNoBorder.Phrase = new Phrase($"Solo, {DateTimeOffset.Now.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Hormat,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Dicheck,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("Mengetahui,\n\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySignNoBorder.Phrase = new Phrase("( )", normal_font); tableSign.AddCell(cellBodySignNoBorder); document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }