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 void Should_Success_ConvertWithDecimal() { var currency = CurrencyToText.ToWords((decimal)30.45); Assert.NotEmpty(currency); }
public MemoryStream GeneratePdfTemplate(GarmentShippingInvoiceViewModel viewModel, Buyer buyer, BankAccount bank, GarmentPackingListViewModel pl, int timeoffset) { const int MARGIN = 20; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font body_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7, Font.UNDERLINE); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 90, 80); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new GarmentShippingInvoiceWithHeaderPdfTemplatePageEvent(viewModel, timeoffset); document.Open(); #region LC PdfPTable tableLC = new PdfPTable(3); tableLC.SetWidths(new float[] { 2f, 0.1f, 6f }); if (pl.PaymentTerm == "LC") { PdfPCell cellLCContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellLCContentLeft.AddElement(new Phrase("LETTER OF CREDIT NUMBER ", normal_font)); cellLCContentLeft.AddElement(new Phrase("LC DATE ", normal_font)); cellLCContentLeft.AddElement(new Phrase("ISSUED BY ", normal_font)); tableLC.AddCell(cellLCContentLeft); PdfPCell cellLCContentCenter = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellLCContentCenter.AddElement(new Phrase(": ", normal_font)); cellLCContentCenter.AddElement(new Phrase(": ", normal_font)); cellLCContentCenter.AddElement(new Phrase(": ", normal_font)); tableLC.AddCell(cellLCContentCenter); PdfPCell cellLCContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellLCContentRight.AddElement(new Phrase(viewModel.LCNo, normal_font)); cellLCContentRight.AddElement(new Phrase(pl.LCDate.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font)); cellLCContentRight.AddElement(new Phrase(viewModel.IssuedBy, normal_font)); tableLC.AddCell(cellLCContentRight); } else { PdfPCell cellLCContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellLCContentLeft.AddElement(new Phrase("PAYMENT TERM ", normal_font)); tableLC.AddCell(cellLCContentLeft); PdfPCell cellLCContentCenter = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellLCContentCenter.AddElement(new Phrase(": ", normal_font)); tableLC.AddCell(cellLCContentCenter); PdfPCell cellLCContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellLCContentRight.AddElement(new Phrase("TT PAYMENT", normal_font)); tableLC.AddCell(cellLCContentRight); } PdfPCell cellLC = new PdfPCell(tableLC); tableLC.ExtendLastRow = false; tableLC.SpacingAfter = 4f; document.Add(tableLC); #endregion #region Body Table PdfPTable bodyTable = new PdfPTable(8); //float[] bodyTableWidths = new float[] { 1.8f, 1.8f, 1.8f, 1.8f, 0.6f, 0.7f, 1f, 1.3f }; float[] bodyTableWidths = new float[] { 1.9f, 1.9f, 1.8f, 1.8f, 0.5f, 0.6f, 1f, 1.1f }; bodyTable.SetWidths(bodyTableWidths); bodyTable.WidthPercentage = 100; #region Set Body Table Header PdfPCell bodyTableHeader = new PdfPCell();// { FixedHeight = 30 }; bodyTableHeader.Phrase = new Phrase("DESCRIPTION", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTableHeader.SetLeading(0, 1.3f); bodyTableHeader.Rowspan = 2; bodyTableHeader.Colspan = 4; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("QUANTITY", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTableHeader.Colspan = 2; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("UNIT PRICE\n" + viewModel.CPrice + " IN USD", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTableHeader.Colspan = 1; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("TOTAL PRICE\n" + viewModel.CPrice + " IN USD", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableHeader); #endregion #region Set Body Table Value PdfPCell bodyTableCellRightBorder = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.RIGHT_BORDER }; PdfPCell bodyTableCellLeftBorder = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.LEFT_BORDER }; PdfPCell bodyTableCellCenterBorder = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER }; bodyTableCellLeftBorder.Phrase = new Phrase($"{viewModel.Description}", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.SetLeading(0, 1.3f); bodyTableCellLeftBorder.Colspan = 4; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase("", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Colspan = 2; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellCenterBorder.Phrase = new Phrase("", body_font); bodyTableCellCenterBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellCenterBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellCenterBorder.SetLeading(0, 1.3f); bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellRightBorder.Phrase = new Phrase("", body_font); bodyTableCellRightBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellRightBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellRightBorder.SetLeading(0, 1.3f); bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellLeftBorder.Phrase = new Phrase($"{viewModel.Remark}", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Colspan = 4; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase("", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Colspan = 2; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellCenterBorder.Phrase = new Phrase("", body_font); bodyTableCellCenterBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellCenterBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellRightBorder.Phrase = new Phrase("", body_font); bodyTableCellRightBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellRightBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellRightBorder); //SPACE bodyTableCellLeftBorder.Phrase = new Phrase("", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Colspan = 4; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase("", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Colspan = 2; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellCenterBorder.Phrase = new Phrase("", body_font); bodyTableCellCenterBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellCenterBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellRightBorder.Phrase = new Phrase("", body_font); bodyTableCellRightBorder.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellRightBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellRightBorder); decimal totalAmount = 0; double totalQuantity = 0; Dictionary <string, double> total = new Dictionary <string, double>(); foreach (var item in viewModel.Items.OrderBy(o => o.ComodityDesc)) { totalAmount += item.Amount; totalQuantity += item.Quantity; bodyTableCellLeftBorder.Phrase = new Phrase($"{item.ComodityDesc}", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Colspan = 1; bodyTableCellLeftBorder.Border = Rectangle.LEFT_BORDER; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase($"{item.Desc2}", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Border = Rectangle.NO_BORDER; bodyTableCellLeftBorder.Colspan = 1; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase($"{item.Desc3}", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Border = Rectangle.NO_BORDER; bodyTableCellLeftBorder.Colspan = 1; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase($"{item.Desc4}", body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Border = Rectangle.RIGHT_BORDER; bodyTableCellLeftBorder.Colspan = 1; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(string.Format("{0:n0}", item.Quantity), body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_RIGHT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.BorderColorRight = BaseColor.White; bodyTableCellLeftBorder.Border = Rectangle.LEFT_BORDER; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellRightBorder.Phrase = new Phrase(item.Uom.Unit, body_font); bodyTableCellRightBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellRightBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellRightBorder.BorderColorLeft = BaseColor.White; bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellRightBorder.Phrase = new Phrase(item.Price != 0 ? string.Format("{0:n4}", item.Price) : "", body_font); bodyTableCellRightBorder.HorizontalAlignment = Element.ALIGN_RIGHT; bodyTableCellRightBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellRightBorder.Phrase = new Phrase(item.Amount != 0 ? string.Format("{0:n2}", item.Amount) : "", body_font); bodyTableCellRightBorder.HorizontalAlignment = Element.ALIGN_RIGHT; bodyTableCellRightBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellRightBorder); if (total.ContainsKey(item.Uom.Unit)) { total[item.Uom.Unit] += item.Quantity; } else { total.Add(item.Uom.Unit, item.Quantity); } } PdfPCell bodyTableCellFooter = new PdfPCell() { FixedHeight = 20, Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER }; bodyTableCellFooter.Phrase = new Phrase("TOTAL ", body_font); bodyTableCellFooter.HorizontalAlignment = Element.ALIGN_RIGHT; bodyTableCellFooter.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellFooter.Colspan = 4; bodyTable.AddCell(bodyTableCellFooter); var val1 = total.Select(x => String.Format("{0:n0}", x.Value)); var result1 = String.Join("\n", val1); var key1 = total.Select(x => String.Format("{0}", x.Key)); var result2 = String.Join("\n", key1); bodyTableCellFooter.Phrase = new Phrase($"{result1}", body_font); bodyTableCellFooter.HorizontalAlignment = Element.ALIGN_RIGHT; bodyTableCellFooter.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellFooter.Colspan = 1; bodyTableCellFooter.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER; bodyTable.AddCell(bodyTableCellFooter); bodyTableCellFooter.Phrase = new Phrase($"{result2}", body_font); bodyTableCellFooter.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellFooter.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellFooter.Border = Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER; bodyTable.AddCell(bodyTableCellFooter); bodyTableCellFooter.Phrase = new Phrase("", body_font); bodyTableCellFooter.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellFooter.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellFooter); bodyTableCellFooter.Phrase = new Phrase(totalAmount != 0 ? string.Format("{0:n2}", totalAmount) : "", body_font); bodyTableCellFooter.HorizontalAlignment = Element.ALIGN_RIGHT; bodyTableCellFooter.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellFooter.Border = Rectangle.RIGHT_BORDER | Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER; bodyTable.AddCell(bodyTableCellFooter); #endregion bodyTable.HeaderRows = 1; document.Add(bodyTable); #endregion // #region calculationTable if (viewModel.GarmentShippingInvoiceAdjustments.Count > 0) { PdfPTable calculationTable = new PdfPTable(4); calculationTable.HorizontalAlignment = Element.ALIGN_LEFT; float[] calculationTableWidths = new float[] { 4f, 0.8f, 1.3f, 6f }; calculationTable.SetWidths(calculationTableWidths); calculationTable.WidthPercentage = 100; PdfPCell calculationCellRight = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell calculationCellLeft = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; calculationCellLeft.Phrase = new Phrase("TOTAL AMOUNT FOB ", normal_font); calculationTable.AddCell(calculationCellLeft); calculationCellLeft.Phrase = new Phrase(": USD ", normal_font); calculationTable.AddCell(calculationCellLeft); calculationCellRight.Phrase = new Phrase(string.Format("{0:n2}", totalAmount), normal_font); calculationTable.AddCell(calculationCellRight); calculationCellRight.Phrase = new Phrase("", normal_font); calculationTable.AddCell(calculationCellRight); decimal totalPaid = totalAmount; foreach (var adj in viewModel.GarmentShippingInvoiceAdjustments) { totalPaid += adj.AdjustmentValue; calculationCellLeft.Phrase = new Phrase($"{adj.AdjustmentDescription} ", normal_font); calculationTable.AddCell(calculationCellLeft); calculationCellLeft.Phrase = new Phrase(": USD ", normal_font); calculationTable.AddCell(calculationCellLeft); calculationCellRight.Phrase = new Phrase(string.Format("{0:n2}", adj.AdjustmentValue), normal_font); calculationTable.AddCell(calculationCellRight); calculationCellRight.Phrase = new Phrase("", normal_font); calculationTable.AddCell(calculationCellRight); } calculationCellLeft.Phrase = new Phrase($"TOTAL AMOUNT TO BE PAID ", bold_font); calculationCellLeft.Border = Rectangle.TOP_BORDER; calculationTable.AddCell(calculationCellLeft); calculationCellLeft.Phrase = new Phrase(": USD ", bold_font); calculationTable.AddCell(calculationCellLeft); calculationCellRight.Phrase = new Phrase(string.Format("{0:n2}", totalPaid), bold_font); calculationCellRight.Border = Rectangle.TOP_BORDER; calculationTable.AddCell(calculationCellRight); calculationCellRight.Phrase = new Phrase("", bold_font); calculationCellRight.Border = Rectangle.NO_BORDER; calculationTable.AddCell(calculationCellRight); string amountToText = ""; if (totalPaid < 0) { totalPaid = totalPaid * -1; amountToText = "MINUS " + CurrencyToText.ToWords(totalPaid); } else { amountToText = CurrencyToText.ToWords(totalPaid); } calculationCellLeft.Phrase = new Phrase($"SAY : US DOLLARS {amountToText.ToUpper()} ONLY ///", normal_font); calculationCellLeft.Colspan = 4; calculationCellLeft.Border = Rectangle.NO_BORDER; calculationTable.AddCell(calculationCellLeft); document.Add(calculationTable); } else { string amountToText = CurrencyToText.ToWords(totalAmount); document.Add(new Paragraph("SAY : US DOLLARS " + amountToText.ToUpper() + " ONLY ///", normal_font)); document.Add(new Paragraph("\n", normal_font)); } #endregion // if (bank != null) { document.Add(new Paragraph("PLEASE TT THE ABOVE PAYMENT TO OUR CORRESPONDENCE BANK AS FOLLOW : ", normal_font)); document.Add(new Paragraph(bank.bankName, normal_font)); document.Add(new Paragraph(bank.bankAddress, normal_font)); document.Add(new Paragraph("ACC NO. " + bank.AccountNumber + $"({bank.Currency.Code})", normal_font)); document.Add(new Paragraph("A/N. PT. DAN LIRIS", normal_font)); document.Add(new Paragraph("SWIFT CODE : " + bank.swiftCode, normal_font)); document.Add(new Paragraph("PURPOSE CODE : 1011", normal_font)); document.Add(new Paragraph("\n", normal_font)); } #region MARK PdfPTable tableMark = new PdfPTable(2); tableMark.SetWidths(new float[] { 2f, 4f }); tableMark.WidthPercentage = 100; PdfPCell cellMarkContent = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellMarkContent.AddElement(new Phrase("SHIPPING MARKS :", normal_font_underlined)); cellMarkContent.AddElement(new Phrase(pl.ShippingMark, normal_font)); tableMark.AddCell(cellMarkContent); PdfPCell cellMarkContentR = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellMarkContentR.AddElement(new Phrase(pl.SideMark != null ? "SIDE MARKS :" : "", normal_font_underlined)); cellMarkContentR.AddElement(new Phrase(pl.SideMark != null ? pl.SideMark : "", normal_font)); tableMark.AddCell(cellMarkContentR); tableMark.ExtendLastRow = false; tableMark.SpacingAfter = 10f; document.Add(tableMark); // PdfPTable tableMark1 = new PdfPTable(2); tableMark1.SetWidths(new float[] { 2f, 4f }); tableMark1.WidthPercentage = 100; var noImage = "data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAA0NDQ0ODQ4QEA4UFhMWFB4bGRkbHi0gIiAiIC1EKjIqKjIqRDxJOzc7STxsVUtLVWx9aWNpfZeHh5e+tb75+f8BDQ0NDQ4NDhAQDhQWExYUHhsZGRseLSAiICIgLUQqMioqMipEPEk7NztJPGxVS0tVbH1pY2l9l4eHl761vvn5///CABEIAAoACgMBIgACEQEDEQH/xAAVAAEBAAAAAAAAAAAAAAAAAAAAB//aAAgBAQAAAACnD//EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIQAAAAf//EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMQAAAAf//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAT8AH//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z"; byte[] shippingMarkImage; if (String.IsNullOrEmpty(pl.ShippingMarkImageFile)) { pl.ShippingMarkImageFile = noImage; } if (IsBase64String(Base64.GetBase64File(pl.ShippingMarkImageFile))) { shippingMarkImage = Convert.FromBase64String(Base64.GetBase64File(pl.ShippingMarkImageFile)); Image shipMarkImage = Image.GetInstance(imgb: shippingMarkImage); if (shipMarkImage.Width > 60) { float percentage = 0.0f; percentage = 100 / shipMarkImage.Width; shipMarkImage.ScalePercent(percentage * 100); } PdfPCell shipMarkImageCell = new PdfPCell(shipMarkImage); shipMarkImageCell.Border = Rectangle.NO_BORDER; tableMark1.AddCell(shipMarkImageCell); } byte[] sideMarkImage; if (String.IsNullOrEmpty(pl.SideMarkImageFile)) { pl.SideMarkImageFile = noImage; } if (IsBase64String(Base64.GetBase64File(pl.SideMarkImageFile))) { sideMarkImage = Convert.FromBase64String(Base64.GetBase64File(pl.SideMarkImageFile)); Image _sideMarkImage = Image.GetInstance(imgb: sideMarkImage); if (_sideMarkImage.Width > 60) { float percentage = 0.0f; percentage = 100 / _sideMarkImage.Width; _sideMarkImage.ScalePercent(percentage * 100); } PdfPCell _sideMarkImageCell = new PdfPCell(_sideMarkImage); _sideMarkImageCell.Border = Rectangle.NO_BORDER; tableMark1.AddCell(_sideMarkImageCell); } new PdfPCell(tableMark1); tableMark1.ExtendLastRow = false; tableMark1.SpacingAfter = 5f; document.Add(tableMark1); // #endregion #region Weight PdfPTable tableMeasurement = new PdfPTable(3); tableMeasurement.SetWidths(new float[] { 2f, 0.2f, 12f }); PdfPCell cellMeasurement = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellMeasurement.Phrase = new Phrase("GROSS WEIGHT", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(":", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(String.Format("{0:0.00}", pl.GrossWeight) + " KGS", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("NET WEIGHT", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(":", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(String.Format("{0:0.00}", pl.NettWeight) + " KGS", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("MEASUREMENT", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(":", normal_font); tableMeasurement.AddCell(cellMeasurement); PdfPTable tableMeasurementDetail = new PdfPTable(5); tableMeasurementDetail.SetWidths(new float[] { 2f, 2f, 2f, 2f, 2f }); PdfPCell cellMeasurementDetail = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; decimal totalCbm = 0; foreach (var measurement in pl.Measurements) { cellMeasurementDetail.Phrase = new Phrase(String.Format("{0:0.00}", measurement.Length) + " CM X ", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); cellMeasurementDetail.Phrase = new Phrase(String.Format("{0:0.00}", measurement.Width) + " CM X ", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); cellMeasurementDetail.Phrase = new Phrase(String.Format("{0:0.00}", measurement.Height) + " CM X ", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); cellMeasurementDetail.Phrase = new Phrase(measurement.CartonsQuantity + " CTNS = ", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); var cbm = (decimal)measurement.Length * (decimal)measurement.Width * (decimal)measurement.Height * (decimal)measurement.CartonsQuantity / 1000000; totalCbm += cbm; cellMeasurementDetail.Phrase = new Phrase(string.Format("{0:N2} CBM", cbm), normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); } cellMeasurementDetail.Border = Rectangle.TOP_BORDER; cellMeasurementDetail.Phrase = new Phrase("", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); tableMeasurementDetail.AddCell(cellMeasurementDetail); cellMeasurementDetail.Phrase = new Phrase("TOTAL", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); cellMeasurementDetail.Phrase = new Phrase(pl.Measurements.Sum(m => m.CartonsQuantity) + " CTNS .", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); cellMeasurementDetail.Phrase = new Phrase(string.Format("{0:N2} CBM", totalCbm), normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); new PdfPCell(tableMeasurementDetail); tableMeasurementDetail.ExtendLastRow = false; var paddingRight = 200; tableMeasurement.AddCell(new PdfPCell(tableMeasurementDetail) { Border = Rectangle.NO_BORDER, PaddingRight = paddingRight }); new PdfPCell(tableMeasurement); tableMeasurement.ExtendLastRow = false; tableMeasurement.SpacingAfter = 5f; document.Add(tableMeasurement); #endregion #region REMARK if (pl.Remark != null) { PdfPTable tableRemark = new PdfPTable(1); tableRemark.SetWidths(new float[] { 6f }); tableRemark.WidthPercentage = 100; PdfPCell cellRemarkContent = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellRemarkContent.AddElement(new Phrase("REMARK :", normal_font_underlined)); cellRemarkContent.AddElement(new Phrase(pl.Remark, normal_font)); tableRemark.AddCell(cellRemarkContent); tableRemark.ExtendLastRow = false; tableRemark.SpacingAfter = 10f; document.Add(tableRemark); // PdfPTable tableRemark2 = new PdfPTable(1); tableRemark2.SetWidths(new float[] { 6f }); tableRemark2.WidthPercentage = 100; byte[] shippingRemarkImage; if (String.IsNullOrEmpty(pl.RemarkImageFile)) { pl.RemarkImageFile = noImage; } if (IsBase64String(Base64.GetBase64File(pl.RemarkImageFile))) { shippingRemarkImage = Convert.FromBase64String(Base64.GetBase64File(pl.RemarkImageFile)); Image shipRemarkImage = Image.GetInstance(imgb: shippingRemarkImage); if (shipRemarkImage.Width > 60) { float percentage = 0.0f; percentage = 100 / shipRemarkImage.Width; shipRemarkImage.ScalePercent(percentage * 100); } PdfPCell shipRemarkImageCell = new PdfPCell(shipRemarkImage); shipRemarkImageCell.Border = Rectangle.NO_BORDER; shipRemarkImageCell.Colspan = 3; tableRemark2.AddCell(shipRemarkImageCell); } new PdfPCell(tableRemark2); tableRemark2.ExtendLastRow = false; tableRemark2.SpacingAfter = 5f; document.Add(tableRemark2); } #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public void Should_Success_ConvertWithoutDecimal() { var currency = CurrencyToText.ToWords(123123); Assert.NotEmpty(currency); }