public async Task <IActionResult> Put([FromRoute] int id, [FromBody] GarmentPackingListViewModel viewModel) { try { VerifyUser(); _validateService.Validate(viewModel); var result = await _service.Update(id, viewModel); return(Ok(result)); } catch (ServiceValidationException ex) { var Result = new { error = ResultFormatter.Fail(ex), apiVersion = "1.0.0", statusCode = HttpStatusCode.BadRequest, message = "Data does not pass validation" }; return(new BadRequestObjectResult(Result)); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public void Validate_DefaultValue() { GarmentPackingListViewModel viewModel = ViewModel; var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }
public async Task <IActionResult> GetWHPDF([FromRoute] int Id, [FromRoute] string type) { if (!ModelState.IsValid) { var exception = new { error = ResultFormatter.FormatErrorMessage(ModelState) }; return(new BadRequestObjectResult(exception)); } try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); int timeoffsset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); var model = await _service.ReadById(Id); if (model == null) { return(StatusCode((int)HttpStatusCode.NotFound, "Not Found")); } else { Buyer buyer = _service.GetBuyer(model.BuyerAgent.Id); BankAccount bank = _service.GetBank(model.BankAccountId); GarmentPackingListViewModel pl = await _packingListService.ReadById(model.PackingListId); if (type == "fob") { var PdfTemplate = new GarmentShippingInvoiceWithHeaderPdfTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, buyer, bank, pl, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = model.InvoiceNo + "-Invoice" + ".pdf" }); } else { var PdfTemplate = new GarmentShippingInvoiceCMTWithHeaderPdfTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, buyer, bank, pl, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = model.InvoiceNo + "-CMT" + ".pdf" }); } } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public void Validate_DateMoreThanToday() { GarmentPackingListViewModel viewModel = ViewModel; viewModel.Date = DateTimeOffset.Now.AddDays(1); viewModel.Items = new List <GarmentPackingListItemViewModel>(); viewModel.Measurements = new List <GarmentPackingListMeasurementViewModel>(); var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }
public void Validate_MeasurementsDefaultValue() { GarmentPackingListViewModel viewModel = ViewModel; viewModel.Measurements = new List <GarmentPackingListMeasurementViewModel> { new GarmentPackingListMeasurementViewModel() }; var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }
public void Validate_DefaultValue() { GarmentPackingListViewModel viewModel = ViewModel; foreach (var activity in viewModel.StatusActivities) { activity.Id = activity.Id; activity.CreatedDate = activity.CreatedDate; activity.CreatedBy = activity.CreatedBy; activity.CreatedAgent = activity.CreatedAgent; activity.Remark = activity.Remark; activity.Status = activity.Status; } var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }
public void Validate_DetailsDefaultValue() { GarmentPackingListViewModel viewModel = ViewModel; viewModel.Items = new List <GarmentPackingListItemViewModel> { new GarmentPackingListItemViewModel { Details = new List <GarmentPackingListDetailViewModel> { new GarmentPackingListDetailViewModel() } } }; var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }
public async Task <IActionResult> GetPDF([FromRoute] int Id) { if (!ModelState.IsValid) { var exception = new { error = ResultFormatter.FormatErrorMessage(ModelState) }; return(new BadRequestObjectResult(exception)); } try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); int timeoffsset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); var model = await _service.ReadById(Id); if (model == null) { return(StatusCode((int)HttpStatusCode.NotFound, "Not Found")); } else { GarmentShippingInvoiceViewModel invoice = await _invoiceService.ReadById(model.InvoiceId); GarmentPackingListViewModel pl = await _packingListService.ReadById(invoice.PackingListId); GarmentCoverLetterViewModel cl = await _coverletterService.ReadByInvoiceId(invoice.Id); var PdfTemplate = new GarmentShippingInstructionPdfTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, cl, pl, invoice, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = "Shipping Instruction - " + model.InvoiceNo + ".pdf" }); } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public void Validate_QuantityDifferent() { GarmentPackingListViewModel viewModel = ViewModel; foreach (var item in viewModel.Items) { foreach (var detail in item.Details) { foreach (var size in detail.Sizes) { size.Quantity = 1; } detail.QuantityPCS = 2; detail.CartonQuantity = 3; } item.Quantity = 4; } var result = viewModel.Validate(null); Assert.NotEmpty(result.ToList()); }
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, 14); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font body_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 bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); //Font body_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 290, 150); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new GarmentShippingInvoicePDFTemplatePageEvent(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.8f, 0.5f, 1f, 1.3f }; bodyTable.SetWidths(bodyTableWidths); bodyTable.WidthPercentage = 100; #region Set Body Table Header PdfPCell bodyTableHeader = new PdfPCell();// { FixedHeight = 30 }; //PdfPCell table1RightCellHeader = new PdfPCell() { FixedHeight = 20, Colspan = 4 }; 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.Rowspan = 1; 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); //bodyTableHeader.Phrase = new Phrase("", normal_font); //bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; //bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; ////bodyTableHeader.Rowspan = 2; //bodyTableHeader.Colspan = 4; //bodyTable.AddCell(bodyTableHeader); //bodyTableHeader.Phrase = new Phrase("", normal_font); //bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; //bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; //bodyTableHeader.Colspan = 2; //bodyTable.AddCell(bodyTableHeader); //bodyTableHeader.Phrase = new Phrase(viewModel.CPrice + " IN USD", normal_font); //bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; //bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; //bodyTableHeader.Colspan = 2; //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); ////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); //// //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); //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); // 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 string amountToText = NumberToTextEN.toWords((double)totalAmount); document.Add(new Paragraph("SAY : US DOLLARS " + amountToText.ToUpper() + " ONLY ///", normal_font)); document.Add(new Paragraph("\n", normal_font)); 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("SIDE MARKS :", normal_font_underlined)); cellMarkContentR.AddElement(new Phrase(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(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(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[] { 1f, 1f, 1f, 1.5f, 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(measurement.Length + " CM X ", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); cellMeasurementDetail.Phrase = new Phrase(measurement.Width + " CM X ", normal_font); tableMeasurementDetail.AddCell(cellMeasurementDetail); cellMeasurementDetail.Phrase = new Phrase(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 //document.Add(new Paragraph("REMARK : ", normal_font_underlined)); //document.Add(new Paragraph(pl.Remark, normal_font)); //document.Add(new Paragraph("\n", normal_font)); //document.Add(new Paragraph("\n", normal_font)); //document.Add(new Paragraph("\n", normal_font)); //document.Add(new Paragraph("\n", normal_font)); //document.Add(new Paragraph("\n", normal_font)); // #region REMARK 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 // //Paragraph sign = new Paragraph("( MRS. ADRIYANA DAMAYANTI )", normal_font_underlined); //sign.Alignment = Element.ALIGN_RIGHT; //Paragraph author = new Paragraph("AUTHORIZED SIGNATURE ", normal_font); //author.Alignment = Element.ALIGN_RIGHT; //document.Add(sign); //document.Add(author); document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingInvoiceViewModel viewModel, Buyer buyer, BankAccount bank, GarmentPackingListViewModel pl, int timeoffset) { const int MARGIN = 20; Font header_font = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 14); Font normal_font = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font body_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 bold_font = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); //Font body_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 300, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new GarmentShippingInvoicePDFTemplatePageEvent(viewModel, timeoffset); document.Open(); #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("\n", normal_font)); //cellHeaderContentLeft.AddElement(new Phrase("Invoice No. : " + viewModel.InvoiceNo, normal_font)); //tableHeader.AddCell(cellHeaderContentLeft); //PdfPCell cellHeaderContentCenter = new PdfPCell() { Border = Rectangle.NO_BORDER }; //cellHeaderContentCenter.AddElement(new Phrase("\n", normal_font)); //cellHeaderContentCenter.AddElement(new Paragraph("Date : " + viewModel.InvoiceDate.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font)); //tableHeader.AddCell(cellHeaderContentCenter); //PdfPCell cellHeaderContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER }; //cellHeaderContentRight.AddElement(new Phrase("", bold_font)); //tableHeader.AddCell(cellHeaderContentRight); //PdfPCell cellHeader = new PdfPCell(tableHeader); //tableHeader.ExtendLastRow = false; //tableHeader.SpacingAfter = 15f; //document.Add(tableHeader); #endregion #region detailOrders //PdfPTable tabledetailOrders = new PdfPTable(3); //tabledetailOrders.SetWidths(new float[] { 0.6f, 1.4f, 2f }); //PdfPCell cellDetailContentLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER }; //PdfPCell cellDetailContentRight = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER }; //PdfPCell cellDetailContentCenter = new PdfPCell() { Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER }; //cellDetailContentLeft.Phrase = new Phrase("SOLD BY ORDERS AND FOR ACCOUNT AND RISK OF", normal_font); //cellDetailContentLeft.Colspan = 2; //tabledetailOrders.AddCell(cellDetailContentLeft); //cellDetailContentLeft.Phrase = new Phrase("CO NO. : " + viewModel.CO, normal_font); //cellDetailContentLeft.Colspan = 1; //cellDetailContentLeft.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER; //tabledetailOrders.AddCell(cellDetailContentLeft); //cellDetailContentRight.AddElement(new Phrase("MESSRS : ", normal_font)); //cellDetailContentRight.Border = Rectangle.NO_BORDER; //tabledetailOrders.AddCell(cellDetailContentRight); //cellDetailContentCenter.AddElement(new Phrase(viewModel.BuyerAgent.Name, normal_font)); //cellDetailContentCenter.AddElement(new Phrase(viewModel.ConsigneeAddress, normal_font)); //cellDetailContentCenter.Border = Rectangle.NO_BORDER; ////cellDetailContentCenter.AddElement(new Phrase(buyer.Country, normal_font)); //tabledetailOrders.AddCell(cellDetailContentCenter); //cellDetailContentRight.Phrase=new Phrase("", normal_font); //cellDetailContentRight.AddElement(new Phrase("CONFIRMATION OF ORDER NO. : " + viewModel.ConfirmationOfOrderNo, normal_font)); //cellDetailContentRight.AddElement(new Phrase("SHIPPED PER : " + viewModel.ShippingPer, normal_font)); //cellDetailContentRight.AddElement(new Phrase("SAILING ON OR ABOUT : " + viewModel.SailingDate.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font)); //cellDetailContentRight.AddElement(new Phrase("FROM : " + viewModel.From, normal_font)); //cellDetailContentRight.AddElement(new Phrase("TO : " + viewModel.To, normal_font)); //// cellDetailContentRight.AddElement(new Phrase("\n", normal_font)); //cellDetailContentRight.Border = Rectangle.LEFT_BORDER; //tabledetailOrders.AddCell(cellDetailContentRight); //cellDetailContentRight.Phrase = new Phrase("DELIVERED TO : ", normal_font); //cellDetailContentRight.Colspan = 1; //cellDetailContentRight.Border = Rectangle.BOTTOM_BORDER; //tabledetailOrders.AddCell(cellDetailContentRight); //cellDetailContentCenter.Phrase=new Phrase(viewModel.DeliverTo, normal_font); //cellDetailContentCenter.Border = Rectangle.BOTTOM_BORDER; //tabledetailOrders.AddCell(cellDetailContentCenter); //cellDetailContentRight.Phrase = new Phrase("", normal_font); //cellDetailContentRight.Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER; //tabledetailOrders.AddCell(cellDetailContentRight); //PdfPCell cellDetail = new PdfPCell(tabledetailOrders); //tabledetailOrders.ExtendLastRow = false; //tabledetailOrders.SpacingAfter = 5f; //tabledetailOrders.HeaderRows = 3; //document.Add(tabledetailOrders); #endregion #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 = 15f; document.Add(tableLC); #endregion #region Body Table PdfPTable bodyTable = new PdfPTable(10); float[] bodyTableWidths = new float[] { 1.6f, 1.6f, 1.6f, 1.6f, 1.2f, 0.8f, 1.5f, 1.8f, 1.5f, 1.8f }; bodyTable.SetWidths(bodyTableWidths); bodyTable.WidthPercentage = 100; #region Set Body Table Header PdfPCell bodyTableHeader = new PdfPCell() { FixedHeight = 20 }; //PdfPCell table1RightCellHeader = new PdfPCell() { FixedHeight = 20, Colspan = 4 }; bodyTableHeader.Phrase = new Phrase("DESCRIPTION", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; //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", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTableHeader.Rowspan = 1; bodyTableHeader.Colspan = 1; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("TOTAL PRICE", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("UNIT PRICE", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("TOTAL PRICE", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; //bodyTableHeader.Rowspan = 2; bodyTableHeader.Colspan = 4; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTableHeader.Colspan = 2; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase(viewModel.CPrice + " IN USD", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTableHeader.Colspan = 2; bodyTable.AddCell(bodyTableHeader); bodyTableHeader.Phrase = new Phrase("CMT IN USD", normal_font); bodyTableHeader.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableHeader.VerticalAlignment = Element.ALIGN_CENTER; bodyTableHeader.Colspan = 2; 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 }; PdfPCell bodyTableCellNoBorder = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.NO_BORDER }; bodyTableCellLeftBorder.Phrase = new Phrase(viewModel.Description, 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); 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); 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; double totalCMTPrice = 0; decimal totalPrice = 0; Dictionary <string, double> total = new Dictionary <string, double>(); foreach (var item in viewModel.Items) { totalAmount += item.Amount; totalQuantity += item.Quantity; totalCMTPrice += item.Quantity * (double)item.CMTPrice; if (item.CMTPrice > 0) { totalPrice += item.Amount; } bodyTableCellLeftBorder.Phrase = new Phrase(item.ComodityDesc, body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.Colspan = 1; bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellNoBorder.Phrase = new Phrase(item.Desc2, body_font); bodyTableCellNoBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellNoBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellNoBorder.Colspan = 1; bodyTable.AddCell(bodyTableCellNoBorder); bodyTableCellNoBorder.Phrase = new Phrase(item.Desc3, body_font); bodyTableCellNoBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellNoBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellNoBorder.Colspan = 1; bodyTable.AddCell(bodyTableCellNoBorder); bodyTableCellRightBorder.Phrase = new Phrase(item.Desc4, body_font); bodyTableCellRightBorder.HorizontalAlignment = Element.ALIGN_LEFT; bodyTableCellRightBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellRightBorder.Colspan = 1; bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellLeftBorder.Phrase = new Phrase(string.Format("{0:n2}", item.Quantity), body_font); bodyTableCellLeftBorder.HorizontalAlignment = Element.ALIGN_RIGHT; bodyTableCellLeftBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTableCellLeftBorder.BorderColorRight = BaseColor.White; 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); bodyTableCellRightBorder.Phrase = new Phrase(item.CMTPrice != 0 ? string.Format("{0:n4}", item.CMTPrice) : "", body_font); bodyTableCellRightBorder.HorizontalAlignment = Element.ALIGN_RIGHT; bodyTableCellRightBorder.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellRightBorder.Phrase = new Phrase(item.CMTPrice != 0 ? string.Format("{0:n2}", item.Quantity * (double)item.CMTPrice) : "", 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:n2}", 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); bodyTableCellFooter.Phrase = new Phrase("", body_font); bodyTableCellFooter.HorizontalAlignment = Element.ALIGN_CENTER; bodyTableCellFooter.VerticalAlignment = Element.ALIGN_CENTER; bodyTable.AddCell(bodyTableCellFooter); bodyTableCellFooter.Phrase = new Phrase(totalCMTPrice != 0 ? string.Format("{0:n2}", totalCMTPrice) : "", 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 = 2; document.Add(bodyTable); #endregion #region calculationTable PdfPTable calculationTable = new PdfPTable(4); calculationTable.HorizontalAlignment = Element.ALIGN_LEFT; float[] calculationTableWidths = new float[] { 4f, 2f, 2f, 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); calculationCellLeft.Phrase = new Phrase("LESS FABRIC COST ", normal_font); calculationTable.AddCell(calculationCellLeft); calculationCellLeft.Phrase = new Phrase(": USD ", normal_font); calculationTable.AddCell(calculationCellLeft); calculationCellRight.Phrase = new Phrase(string.Format("{0:n2}", (totalPrice - (decimal)totalCMTPrice) * -1), normal_font); calculationTable.AddCell(calculationCellRight); calculationCellRight.Phrase = new Phrase("", normal_font); calculationTable.AddCell(calculationCellRight); decimal totalAmountCMT = totalAmount - (totalPrice - (decimal)totalCMTPrice); calculationCellLeft.Phrase = new Phrase("TOTAL AMOUNT CMT ", normal_font); calculationTable.AddCell(calculationCellLeft); calculationCellLeft.Phrase = new Phrase(": USD ", normal_font); calculationTable.AddCell(calculationCellLeft); calculationCellRight.Phrase = new Phrase(string.Format("{0:n2}", totalAmountCMT), normal_font); calculationTable.AddCell(calculationCellRight); calculationCellRight.Phrase = new Phrase("", normal_font); calculationTable.AddCell(calculationCellRight); decimal totalPaid = totalAmountCMT; if (viewModel.GarmentShippingInvoiceAdjustments.Count > 0) { 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 " + NumberToTextEN.toWords((double)totalPaid); } else { amountToText = NumberToTextEN.toWords((double)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); #endregion document.Add(new Paragraph("\n", normal_font)); if (bank != null) { document.Add(new Paragraph("PLEASE TT THE ABOVE PAYMENT TO OUR CORRESPONDENCE BANK AS FOLLOW : ", normal_font)); document.Add(new Paragraph(viewModel.BankAccount, 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 " + bank.accountName, 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("SIDE MARKS :", normal_font_underlined)); cellMarkContentR.AddElement(new Phrase(pl.SideMark, normal_font)); tableMark.AddCell(cellMarkContentR); tableMark.ExtendLastRow = false; tableMark.SpacingAfter = 15f; document.Add(tableMark); #endregion #region Weight PdfPTable tableWeight = new PdfPTable(3); tableWeight.SetWidths(new float[] { 3f, 1f, 6f }); tableWeight.WidthPercentage = 100; PdfPCell cellWeightContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellWeightContentLeft.AddElement(new Phrase("GROSS WEIGHT ", normal_font)); cellWeightContentLeft.AddElement(new Phrase("NETT WEIGHT ", normal_font)); cellWeightContentLeft.AddElement(new Phrase("MEASSUREMENT ", normal_font)); tableWeight.AddCell(cellWeightContentLeft); PdfPCell cellWeightContentCenter = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellWeightContentCenter.AddElement(new Phrase(" : ", normal_font)); cellWeightContentCenter.AddElement(new Phrase(" : ", normal_font)); cellWeightContentCenter.AddElement(new Phrase(" : ", normal_font)); tableWeight.AddCell(cellWeightContentCenter); PdfPCell cellWeightContentRight = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellWeightContentRight.AddElement(new Phrase($"{pl.GrossWeight} KGS", normal_font)); cellWeightContentRight.AddElement(new Phrase($"{pl.NettWeight} KGS", normal_font)); PdfPTable tableMeasurement = new PdfPTable(5); tableMeasurement.SetWidths(new float[] { 1f, 1f, 1f, 2f, 2f }); tableMeasurement.WidthPercentage = 100; PdfPCell cellMeasurement = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; if (pl.Measurements.Count > 0) { double totalctns = 0; double totalCM = 0; foreach (var m in pl.Measurements) { double cbm = (m.Length * m.Width * m.Height * m.CartonsQuantity) / 1000000; cellMeasurement.Phrase = new Phrase($"{m.Length} X", normal_font); cellMeasurement.PaddingLeft = 1; tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase($"{m.Width} X", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase($"{m.Height} X", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase($"{m.CartonsQuantity} CTNS = ", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(string.Format("{0:n2}", cbm) + " CBM", normal_font); tableMeasurement.AddCell(cellMeasurement); totalctns += m.CartonsQuantity; totalCM += cbm; } cellMeasurement.Phrase = new Phrase("", normal_font); cellMeasurement.Colspan = 2; tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase($"{totalctns} CTNS", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(string.Format("{0:n2}", totalCM) + " CBM", normal_font); tableMeasurement.AddCell(cellMeasurement); cellWeightContentRight.AddElement(tableMeasurement); } tableWeight.AddCell(cellWeightContentRight); tableWeight.SpacingAfter = 15f; document.Add(tableWeight); #endregion document.Add(new Paragraph("REMARK : ", normal_font_underlined)); document.Add(new Paragraph(pl.Remark, normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("\n", normal_font)); Paragraph sign = new Paragraph("( MRS. ADRIYANA DAMAYANTI )", normal_font_underlined); sign.Alignment = Element.ALIGN_RIGHT; Paragraph author = new Paragraph("AUTHORIZED SIGNATURE ", normal_font); author.Alignment = Element.ALIGN_RIGHT; document.Add(sign); document.Add(author); document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentCoverLetterViewModel viewModel, GarmentPackingListViewModel pl, Buyer buyer, int timeoffset) { const int MARGIN = 20; Font header_font_bold = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); 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, 8); Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8, Font.UNDERLINE); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font small_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 5); //Font body_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 140, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new GarmentCoverLetterPdfTemplatePageEvent(); document.Open(); PdfPTable tableTitle = new PdfPTable(3); tableTitle.WidthPercentage = 100; tableTitle.SetWidths(new float[] { 2f, 2f, 2f }); PdfPCell cellTitle = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellTitle.Phrase = new Phrase("Ref No. : FM-00-SP-24-008", header_font); tableTitle.AddCell(cellTitle); cellTitle.Phrase = new Phrase("SURAT PENGANTAR", header_font_bold); tableTitle.AddCell(cellTitle); cellTitle.Phrase = new Phrase(viewModel.invoiceNo, header_font); tableTitle.AddCell(cellTitle); tableTitle.SpacingAfter = 10; document.Add(tableTitle); #region header PdfPTable tableHeader = new PdfPTable(3); tableHeader.WidthPercentage = 100; tableHeader.SetWidths(new float[] { 3f, 1.5f, 2f }); PdfPCell cellHeaderLeft = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; cellHeaderLeft.Phrase = new Phrase("Kepada Yth.\n\n" + //$"{viewModel.emkl.Name} \n\n" + $"{viewModel.destination} \n" + $"{viewModel.address} \n" + $"PIC : {viewModel.pic} \n\n" + $"Forwarder : {viewModel.forwarder.name} \n\n" + $"ATTN : {viewModel.attn} \n" + $"PHONE : {viewModel.phone}", normal_font); cellHeaderLeft.Rowspan = 7; tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase("Tanggal", normal_font); cellHeaderLeft.Rowspan = 1; tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase(viewModel.date.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase("Order ", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase(viewModel.order.Name, normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase("Jumlah Pcs ", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase(viewModel.pcsQuantity == 0 ? "-" : $"{ string.Format("{0:n0}", viewModel.pcsQuantity)} PCS", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase("Jumlah Sets", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase(viewModel.setsQuantity == 0 ? "-" : $"{ string.Format("{0:n0}", viewModel.setsQuantity)} SETS", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase("Jumlah Packs", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase(viewModel.packQuantity == 0 ? "-" : $"{ string.Format("{0:n0}", viewModel.packQuantity)} PACKS", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase("Jumlah Collie", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase($"{ string.Format("{0:n0}", viewModel.cartoonQuantity)} COLLIE", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase("Invoice No.", normal_font); tableHeader.AddCell(cellHeaderLeft); cellHeaderLeft.Phrase = new Phrase(viewModel.invoiceNo, normal_font); tableHeader.AddCell(cellHeaderLeft); tableHeader.SpacingAfter = 10; document.Add(tableHeader); #endregion document.Add(new Paragraph("Dengan hormat,", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph(" Bersama ini kami kirimkan kepada Bapak sejumlah barang dengan", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("\n", normal_font)); #region detail PdfPTable tableDetail = new PdfPTable(6); tableDetail.WidthPercentage = 100; tableDetail.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f }); PdfPCell cellDetail = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; double cbmtotal = 0; if (pl.Measurements.Count > 0) { foreach (var m in pl.Measurements) { double cbm = (m.Length * m.Width * m.Height * m.CartonsQuantity) / 1000000; cbmtotal += cbm; } } cellDetail.Phrase = new Phrase("Truck", normal_font); tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase("Nomor Polisi", normal_font); tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase("Pengemudi", normal_font); tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase("Seal Pelayaran", normal_font); tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase("Seal Dan Liris", normal_font); tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase("Jumlah Muatan", normal_font); tableDetail.AddCell(cellDetail); Paragraph Truck = new Paragraph($"EMKL : {viewModel.emkl.Name} \n\n" + $"Truk : {viewModel.truck}", normal_font); cellDetail.Phrase = Truck; cellDetail.VerticalAlignment = Element.ALIGN_TOP; tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase(viewModel.plateNumber, normal_font); tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase(viewModel.driver, normal_font); tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase(viewModel.shippingSeal, normal_font); tableDetail.AddCell(cellDetail); cellDetail.Phrase = new Phrase(viewModel.dlSeal, normal_font); tableDetail.AddCell(cellDetail); Paragraph weight = new Paragraph($"GW : {string.Format("{0:n2}", pl.GrossWeight)} KGS \n\n" + $"NW : {string.Format("{0:n2}", pl.NettWeight)} KGS \n\n" + $"Volume : {string.Format("{0:n2}", Math.Round(cbmtotal, 2))} m", normal_font); Chunk chunk = new Chunk("3", small_font); chunk.SetTextRise(2); Paragraph m2 = new Paragraph(chunk); m2.Alignment = Element.ALIGN_TOP; weight.Add(m2); cellDetail.Phrase = weight; cellDetail.VerticalAlignment = Element.ALIGN_TOP; tableDetail.AddCell(cellDetail); tableDetail.SpacingAfter = 10; document.Add(tableDetail); #endregion #region marks PdfPTable tableMark = new PdfPTable(4); tableMark.WidthPercentage = 100; tableMark.SetWidths(new float[] { 1f, 3f, 1f, 3f }); PdfPCell cellMark = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; cellMark.Phrase = new Phrase("Shippig Mark :", normal_font); cellMark.Rowspan = 2; tableMark.AddCell(cellMark); cellMark.Phrase = new Phrase(pl.ShippingMark, normal_font); tableMark.AddCell(cellMark); string sealType = ""; string seal = ""; if (!string.IsNullOrEmpty(viewModel.shippingSeal)) { sealType += "Seal Pelayaran \n"; seal += ": " + viewModel.shippingSeal + "\n"; } if (!string.IsNullOrEmpty(viewModel.dlSeal)) { sealType += "Seal DL \n"; seal += ": " + viewModel.dlSeal + "\n"; } if (!string.IsNullOrEmpty(viewModel.emklSeal)) { sealType += "Seal EMKL \n"; seal += ": " + viewModel.emklSeal + "\n"; } cellMark.Phrase = new Phrase(sealType, normal_font); cellMark.Rowspan = 1; cellMark.Border = Rectangle.NO_BORDER; cellMark.HorizontalAlignment = Element.ALIGN_LEFT; tableMark.AddCell(cellMark); cellMark.Phrase = new Phrase(seal, normal_font); cellMark.Rowspan = 1; cellMark.Border = Rectangle.NO_BORDER; cellMark.HorizontalAlignment = Element.ALIGN_LEFT; tableMark.AddCell(cellMark); //cellMark.Phrase = new Phrase("SEND TO :", normal_font); //cellMark.Colspan = 1; //cellMark.HorizontalAlignment = Element.ALIGN_RIGHT; //cellMark.Border = Rectangle.BOTTOM_BORDER; //tableMark.AddCell(cellMark); //cellMark.Phrase = new Phrase($"{buyer.Name} \n" + // $"{buyer.Address} \n", normal_font); //cellMark.HorizontalAlignment = Element.ALIGN_LEFT; //tableMark.AddCell(cellMark); //tableMark.SpacingAfter = 15; //document.Add(tableMark); #endregion document.Add(new Paragraph("Demikian harap diterima dengan baik dan terima kasih.", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("\n", normal_font)); #region sign PdfPTable tableSign = new PdfPTable(5); tableSign.WidthPercentage = 100; tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f }); PdfPCell cellSign = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellSign.Phrase = new Phrase("Pengemudi Truck, \n\n\n\n\n\n", normal_font); cellSign.Colspan = 1; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("Mengetahui, \n\n\n\n\n\n", normal_font); cellSign.Colspan = 2; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" Hormat Kami, \n\n\n\n\n\n", normal_font); cellSign.Colspan = 1; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" \n\n\n\n\n\n", normal_font); cellSign.Colspan = 1; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("__________________", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("__________________", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("__________________", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("__________________", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("( " + viewModel.shippingStaff.name + " )", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("Pembukuan DL", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("Sat Pam", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("Konfeksi " + $"{viewModel.unit}", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("Shipping Staff", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n\n\n\n\n\n\n\n\n\n\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n\n\n\n\n\n\n\n\n\n\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n\n\n\n\n\n\n\n\n\n\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n\n\n\n\n\n\n\n\n\n\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n\n\n\n\n\n\n\n\n\n\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("JAM MASUK : ______", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("JAM KELUAR : ______", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("\n\n", normal_font); tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("CATATAN : \n" + "1. Mohon bisa dikirim kembali Pengantar ini apabila barang sudah diterima \n" + "2. ....................................................", normal_font); cellSign.Colspan = 3; cellSign.HorizontalAlignment = Element.ALIGN_LEFT; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("Diterima, \n\n\n\n\n\n", normal_font); cellSign.Rowspan = 1; cellSign.HorizontalAlignment = Element.ALIGN_CENTER; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase("", normal_font); cellSign.Colspan = 3; cellSign.HorizontalAlignment = Element.ALIGN_LEFT; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" (__________________)", normal_font); cellSign.Rowspan = 1; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" ", normal_font); cellSign.Colspan = 3; cellSign.HorizontalAlignment = Element.ALIGN_LEFT; tableSign.AddCell(cellSign); cellSign.Phrase = new Phrase(" JAM DITERIMA : ______", normal_font); cellSign.Rowspan = 1; tableSign.AddCell(cellSign); document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(GarmentShippingInstructionViewModel viewModel, GarmentCoverLetterViewModel cl, GarmentPackingListViewModel pl, GarmentShippingInvoiceViewModel invoice, int timeoffset) { const int MARGIN = 25; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font body_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 bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); //Font body_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A4, MARGIN, MARGIN, 100, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new GarmentShippingInstructionPDFTemplatePageEvent(); document.Open(); #region header PdfPTable tableHeader = new PdfPTable(4); tableHeader.WidthPercentage = 100; tableHeader.SetWidths(new float[] { 2f, 4f, 2f, 4f }); PdfPCell cellHeaderContent1 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER }; cellHeaderContent1.AddElement(new Phrase("TO", normal_font)); cellHeaderContent1.AddElement(new Phrase("ATTN", normal_font)); cellHeaderContent1.AddElement(new Phrase("CC", normal_font)); cellHeaderContent1.AddElement(new Phrase("FROM", normal_font)); tableHeader.AddCell(cellHeaderContent1); PdfPCell cellHeaderContent2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER }; cellHeaderContent2.AddElement(new Phrase(": " + viewModel.forwarder.name, normal_font)); cellHeaderContent2.AddElement(new Phrase(": " + viewModel.ATTN, normal_font)); cellHeaderContent2.AddElement(new Phrase(": " + viewModel.CC, normal_font)); cellHeaderContent2.AddElement(new Phrase(": " + viewModel.ShippingStaffName + "/" + viewModel.Phone, normal_font)); tableHeader.AddCell(cellHeaderContent2); PdfPCell cellHeaderContent3 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER }; cellHeaderContent3.AddElement(new Phrase("FAX", normal_font)); cellHeaderContent3.AddElement(new Phrase("REF", normal_font)); cellHeaderContent3.AddElement(new Phrase("DATE", normal_font)); tableHeader.AddCell(cellHeaderContent3); PdfPCell cellHeaderContent4 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER }; cellHeaderContent4.AddElement(new Phrase(": " + viewModel.forwarder.fax, normal_font)); cellHeaderContent4.AddElement(new Phrase(": " + viewModel.InvoiceNo, normal_font)); cellHeaderContent4.AddElement(new Phrase(": " + viewModel.Date.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font)); tableHeader.AddCell(cellHeaderContent4); document.Add(tableHeader); #endregion Paragraph sub = new Paragraph("SUBJECT : SHIPPING INSTRUCTION", header_font); sub.Alignment = Element.ALIGN_CENTER; document.Add(sub); document.Add(new Paragraph("DEAR SIRS,", normal_font)); document.Add(new Paragraph("WE REQUEST YOU TO ARRANGE THE FOLLOWING SHIPMENT", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph($"{invoice.Description}", normal_font)); document.Add(new Paragraph("\n", normal_font)); #region detail PdfPTable detailTable = new PdfPTable(3); detailTable.HorizontalAlignment = Element.ALIGN_LEFT; float[] detailTableWidths = new float[] { 2.5f, 0.5f, 6f }; detailTable.SetWidths(detailTableWidths); detailTable.WidthPercentage = 100; PdfPCell cellLeft = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; double qty = 0; foreach (var invItem in invoice.Items) { qty += invItem.Quantity; } cellLeft.Phrase = new Phrase("QUANTITY", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(string.Format("{0:n0}", qty), normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("GROSS WEIGHT", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{string.Format("{0:n2}", pl.GrossWeight)} KGS", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("NETT WEIGHT", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{string.Format("{0:n2}", pl.NettWeight)} KGS", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("MEASUREMENT", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); PdfPTable tableMeasurement = new PdfPTable(5); tableMeasurement.SetWidths(new float[] { 1f, 1f, 1f, 2f, 2f }); tableMeasurement.WidthPercentage = 100; double totcbm = 0; double volweight = 0; PdfPCell cellMeasurement = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; if (pl.Measurements.Count > 0) { foreach (var m in pl.Measurements) { double cbm = (m.Length * m.Width * m.Height * m.CartonsQuantity) / 1000000; double vlm = (m.Length * m.Width * m.Height * m.CartonsQuantity) / 6000; cellMeasurement.Phrase = new Phrase($"{string.Format("{0:n2}", m.Length)} X", normal_font); cellMeasurement.PaddingLeft = 1; tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase($"{string.Format("{0:n2}", m.Width)} X", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase($"{string.Format("{0:n2}", m.Height)} X", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase($"{string.Format("{0:n2}", m.CartonsQuantity)} CTNS = ", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(string.Format("{0:n2}", cbm) + " CBM", normal_font); tableMeasurement.AddCell(cellMeasurement); totcbm += cbm; volweight += vlm; } cellMeasurement.Phrase = new Phrase("", normal_font); cellMeasurement.PaddingLeft = 1; tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("---------------------", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("", normal_font); cellMeasurement.PaddingLeft = 1; tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase("TOTAL CBM = ", normal_font); tableMeasurement.AddCell(cellMeasurement); cellMeasurement.Phrase = new Phrase(string.Format("{0:n2}", totcbm) + " CBM", normal_font); tableMeasurement.AddCell(cellMeasurement); cellLeft.AddElement(tableMeasurement); } detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("VOLUME WEIGHT", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{string.Format("{0:n0}", volweight)} KGS", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("CARTON", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{string.Format("{0:n0}", viewModel.CartonNo)} CTNS", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("MARKS", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(viewModel.Marks, normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("PORT OF LOADING", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{invoice.From}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("PORT OF DISCHARGE", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(viewModel.PortOfDischarge, normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("PLACE OF DELIVERY", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{viewModel.PlaceOfDelivery}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("FEEDER VESSEL BY/DATE", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{viewModel.FeederVessel}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("OCEAN VESSEL BY/DATE", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{viewModel.OceanVessel}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("SHIPPER", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("PT. DAN LIRIS, JL. MERAPI NO. 23, KELURAHAN BANARAN, KECAMATAN GROGOL,\n" + "SUKOHARJO 57193, INDONESIA.\n" + "PHONE : 0271-714400 FAX : 0271-735222", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("CONSIGNEE", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{viewModel.BuyerAgent.Name} \n" + $"{viewModel.BuyerAgentAddress}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("NOTIFY ADDRESS", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{viewModel.Notify}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("BILL OF LADING", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{viewModel.LadingBill}", normal_font); detailTable.AddCell(cellLeft); string ladingDate = viewModel.LadingDate == DateTimeOffset.MinValue ? "" : viewModel.LadingDate.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")); cellLeft.Phrase = new Phrase("DATE OF BILL OF LADING", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{ladingDate}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("FREIGHT", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{viewModel.Freight}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("CONTAINER NO.", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(cl == null ? "-" : cl.containerNo, normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("SHIPPING SEAL.", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(cl == null ? "-" : cl.shippingSeal, normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("LETTER OF CREDIT NO.", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{pl.LCNo}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("ISSUING BANK", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{pl.IssuedBy}", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase("SPECIAL INSTRUCTION", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase(":", normal_font); detailTable.AddCell(cellLeft); cellLeft.Phrase = new Phrase($"{viewModel.SpecialInstruction}", normal_font); detailTable.AddCell(cellLeft); document.Add(detailTable); #endregion #region SIGN document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("THANK YOU,", normal_font)); document.Add(new Paragraph("WITH BEST REGARDS,", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph("\n", normal_font)); document.Add(new Paragraph($"{invoice.ShippingStaff}", normal_font)); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public async Task <IActionResult> GetPDF([FromRoute] int Id) { if (!ModelState.IsValid) { var exception = new { error = ResultFormatter.FormatErrorMessage(ModelState) }; return(new BadRequestObjectResult(exception)); } try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); int timeoffsset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); var model = await _service.ReadById(Id); if (model == null) { return(StatusCode((int)HttpStatusCode.NotFound, "Not Found")); } else { List <GarmentShippingInvoiceViewModel> invoices = new List <GarmentShippingInvoiceViewModel>(); List <GarmentPackingListViewModel> packingLists = new List <GarmentPackingListViewModel>(); foreach (var invoiceItem in model.invoiceDetails) { GarmentShippingInvoiceViewModel invoice = await _invoiceService.ReadById(invoiceItem.invoiceId); GarmentPackingListViewModel pl = await _packingListService.ReadByInvoiceNo(invoiceItem.invoiceNo); invoices.Add(invoice); packingLists.Add(pl); } if (model.paymentType == "FORWARDER") { if (model.isFreightCharged) { var PdfTemplate = new GarmentShippingPaymentDispositionForwarderFCPDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, invoices, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = model.dispositionNo + ".pdf" }); } else { var PdfTemplate = new GarmentShippingPaymentDispositionForwarderPDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, invoices, packingLists, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = model.dispositionNo + ".pdf" }); } } else if (model.paymentType == "EMKL") { var PdfTemplate = new GarmentShippingPaymentDispositionEMKLPDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, invoices, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = model.dispositionNo + ".pdf" }); } else { var PdfTemplate = new GarmentShippingPaymentDispositionCourierPDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = model.dispositionNo + ".pdf" }); } } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }