public async Task <int> Create(GarmentShippingPaymentDispositionViewModel viewModel)
        {
            var model = MapToModel(viewModel);

            int Created = await _repository.InsertAsync(model);

            return(Created);
        }
        private string GenerateNo(GarmentShippingPaymentDispositionViewModel vm)
        {
            var year = DateTime.Now.ToString("yy");

            var prefix = "";

            if (vm.paymentType == "FORWARDER")
            {
                if (vm.isFreightCharged)
                {
                    if (vm.freightBy == "AIR")
                    {
                        prefix = $"DL/AF.EG/{vm.paidAt}/{year}/";
                    }
                    else
                    {
                        prefix = $"DL/OF.EG/{vm.paidAt}/{year}/";
                    }
                }
                else
                {
                    prefix = $"DL/FRWD/{vm.paidAt}/{year}/";
                }
            }
            else if (vm.paymentType == "COURIER")
            {
                prefix = $"DL/COUR/{year}/";
            }
            else
            {
                prefix = $"DL/EMKL/{year}/";
            }

            var lastInvoiceNo = _repository.ReadAll().Where(w => w.DispositionNo.StartsWith(prefix))
                                .OrderByDescending(o => o.DispositionNo)
                                .Select(s => int.Parse(s.DispositionNo.Replace(prefix, "")))
                                .FirstOrDefault();
            var invoiceNo = $"{prefix}{(lastInvoiceNo + 1).ToString("D4")}";

            return(invoiceNo);
        }
        public GarmentShippingPaymentDispositionModel MapToModel(GarmentShippingPaymentDispositionViewModel vm)
        {
            var bills = (vm.billDetails ?? new List <GarmentShippingPaymentDispositionBillDetailViewModel>()).Select(i =>
            {
                return(new GarmentShippingPaymentDispositionBillDetailModel(i.billDescription, i.amount)
                {
                    Id = i.Id
                });
            }).ToList();

            var units = (vm.unitCharges ?? new List <GarmentShippingPaymentDispositionUnitChargeViewModel>()).Select(m => {
                m.unit = m.unit ?? new Unit();
                return(new GarmentShippingPaymentDispositionUnitChargeModel(m.unit.Id, m.unit.Code, m.amountPercentage, m.billAmount)
                {
                    Id = m.Id
                });
            }).ToList();

            var invoices = (vm.invoiceDetails ?? new List <GarmentShippingPaymentDispositionInvoiceDetailViewModel>()).Select(i =>
            {
                return(new GarmentShippingPaymentDispositionInvoiceDetailModel(i.invoiceNo, i.invoiceId, i.quantity, i.amount, i.volume, i.grossWeight, i.chargeableWeight, i.totalCarton)
                {
                    Id = i.Id
                });
            }).ToList();

            vm.forwarder  = vm.forwarder ?? new Forwarder();
            vm.buyerAgent = vm.buyerAgent ?? new BuyerAgent();
            vm.emkl       = vm.emkl ?? new EMKL();
            vm.courier    = vm.courier ?? new Courier();
            vm.incomeTax  = vm.incomeTax ?? new IncomeTax();
            return(new GarmentShippingPaymentDispositionModel(GenerateNo(vm), vm.paymentType, vm.paymentMethod, vm.paidAt, vm.sendBy,
                                                              vm.buyerAgent.Id, vm.buyerAgent.Code, vm.buyerAgent.Name, vm.paymentTerm, vm.forwarder.id, vm.forwarder.code, vm.forwarder.name,
                                                              vm.courier.Id, vm.courier.Code, vm.courier.Name, vm.emkl.Id, vm.emkl.Code, vm.emkl.Name, vm.address, vm.npwp, vm.invoiceNumber, vm.invoiceDate,
                                                              vm.invoiceTaxNumber, vm.billValue, vm.vatValue, vm.incomeTax.id, vm.incomeTax.name, (decimal)vm.incomeTax.rate, vm.IncomeTaxValue,
                                                              vm.totalBill, vm.paymentDate, vm.bank, vm.accNo, vm.isFreightCharged, vm.freightBy, vm.freightNo, vm.freightDate.GetValueOrDefault(), vm.flightVessel, vm.destination, vm.remark, invoices, bills, units)
            {
                Id = vm.Id
            });
        }
        public async Task <int> Update(int id, GarmentShippingPaymentDispositionViewModel viewModel)
        {
            var model = MapToModel(viewModel);

            return(await _repository.UpdateAsync(id, model));
        }
        public GarmentShippingPaymentDispositionViewModel MapToViewModel(GarmentShippingPaymentDispositionModel model)
        {
            GarmentShippingPaymentDispositionViewModel viewModel = new GarmentShippingPaymentDispositionViewModel
            {
                Active            = model.Active,
                Id                = model.Id,
                CreatedAgent      = model.CreatedAgent,
                CreatedBy         = model.CreatedBy,
                CreatedUtc        = model.CreatedUtc,
                DeletedAgent      = model.DeletedAgent,
                DeletedBy         = model.DeletedBy,
                DeletedUtc        = model.DeletedUtc,
                IsDeleted         = model.IsDeleted,
                LastModifiedAgent = model.LastModifiedAgent,
                LastModifiedBy    = model.LastModifiedBy,
                LastModifiedUtc   = model.LastModifiedUtc,

                dispositionNo = model.DispositionNo,
                accNo         = model.AccNo,
                address       = model.Address,
                paidAt        = model.PaidAt,
                buyerAgent    = new BuyerAgent
                {
                    Name = model.BuyerAgentName,
                    Id   = model.BuyerAgentId,
                    Code = model.BuyerAgentCode
                },
                bank      = model.Bank,
                billValue = model.BillValue,
                courier   = new Courier
                {
                    Name = model.CourierName,
                    Code = model.CourierCode,
                    Id   = model.CourierId
                },
                emkl = new EMKL
                {
                    Name = model.EMKLName,
                    Code = model.EMKLCode,
                    Id   = model.EMKLId
                },
                forwarder = new Forwarder
                {
                    name = model.ForwarderName,
                    code = model.ForwarderCode,
                    id   = model.ForwarderId
                },
                freightBy   = model.FreightBy,
                freightDate = model.FreightDate,
                freightNo   = model.FreightNo,
                incomeTax   = new IncomeTax
                {
                    id   = model.IncomeTaxId,
                    name = model.IncomeTaxName,
                    rate = (double)model.IncomeTaxRate
                },
                IncomeTaxValue   = model.IncomeTaxValue,
                invoiceDate      = model.InvoiceDate,
                invoiceNumber    = model.InvoiceNumber,
                invoiceTaxNumber = model.InvoiceTaxNumber,
                isFreightCharged = model.IsFreightCharged,
                npwp             = model.NPWP,
                paymentDate      = model.PaymentDate,
                paymentMethod    = model.PaymentMethod,
                paymentTerm      = model.PaymentTerm,
                paymentType      = model.PaymentType,
                remark           = model.Remark,
                sendBy           = model.SendBy,
                totalBill        = model.TotalBill,
                vatValue         = model.VatValue,
                flightVessel     = model.FlightVessel,
                destination      = model.Destination,
                unitCharges      = (model.UnitCharges ?? new List <GarmentShippingPaymentDispositionUnitChargeModel>()).Select(i => new GarmentShippingPaymentDispositionUnitChargeViewModel
                {
                    Active            = i.Active,
                    Id                = i.Id,
                    CreatedAgent      = i.CreatedAgent,
                    CreatedBy         = i.CreatedBy,
                    CreatedUtc        = i.CreatedUtc,
                    DeletedAgent      = i.DeletedAgent,
                    DeletedBy         = i.DeletedBy,
                    DeletedUtc        = i.DeletedUtc,
                    IsDeleted         = i.IsDeleted,
                    LastModifiedAgent = i.LastModifiedAgent,
                    LastModifiedBy    = i.LastModifiedBy,
                    LastModifiedUtc   = i.LastModifiedUtc,

                    amountPercentage     = i.AmountPercentage,
                    billAmount           = i.BillAmount,
                    paymentDispositionId = i.PaymentDispositionId,
                    unit = new Unit
                    {
                        Id   = i.UnitId,
                        Code = i.UnitCode
                    }
                }).ToList(),
                invoiceDetails = (model.InvoiceDetails ?? new List <GarmentShippingPaymentDispositionInvoiceDetailModel>()).Select(i => new GarmentShippingPaymentDispositionInvoiceDetailViewModel
                {
                    Active            = i.Active,
                    Id                = i.Id,
                    CreatedAgent      = i.CreatedAgent,
                    CreatedBy         = i.CreatedBy,
                    CreatedUtc        = i.CreatedUtc,
                    DeletedAgent      = i.DeletedAgent,
                    DeletedBy         = i.DeletedBy,
                    DeletedUtc        = i.DeletedUtc,
                    IsDeleted         = i.IsDeleted,
                    LastModifiedAgent = i.LastModifiedAgent,
                    LastModifiedBy    = i.LastModifiedBy,
                    LastModifiedUtc   = i.LastModifiedUtc,

                    amount               = i.Amount,
                    chargeableWeight     = i.ChargeableWeight,
                    grossWeight          = i.GrossWeight,
                    invoiceId            = i.InvoiceId,
                    invoiceNo            = i.InvoiceNo,
                    paymentDispositionId = i.PaymentDispositionId,
                    quantity             = i.Quantity,
                    totalCarton          = i.TotalCarton,
                    volume               = i.Volume
                }).ToList(),
                billDetails = (model.BillDetails ?? new List <GarmentShippingPaymentDispositionBillDetailModel>()).Select(i => new GarmentShippingPaymentDispositionBillDetailViewModel
                {
                    Active            = i.Active,
                    Id                = i.Id,
                    CreatedAgent      = i.CreatedAgent,
                    CreatedBy         = i.CreatedBy,
                    CreatedUtc        = i.CreatedUtc,
                    DeletedAgent      = i.DeletedAgent,
                    DeletedBy         = i.DeletedBy,
                    DeletedUtc        = i.DeletedUtc,
                    IsDeleted         = i.IsDeleted,
                    LastModifiedAgent = i.LastModifiedAgent,
                    LastModifiedBy    = i.LastModifiedBy,
                    LastModifiedUtc   = i.LastModifiedUtc,

                    amount          = i.Amount,
                    billDescription = i.BillDescription
                }).ToList()
            };

            return(viewModel);
        }
        public MemoryStream GeneratePdfTemplate(GarmentShippingPaymentDispositionViewModel viewModel, List <GarmentShippingInvoiceViewModel> invoices, int timeoffset)
        {
            const int MARGIN = 20;

            Font header_font_bold_big        = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font header_font_bold            = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);
            Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12, Font.UNDERLINE);
            Font header_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font normal_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);
            Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE);
            Font normal_font_bold       = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);

            Document document = new Document(PageSize.A4, MARGIN, MARGIN, 40, MARGIN);

            MemoryStream stream = new MemoryStream();
            PdfWriter    writer = PdfWriter.GetInstance(document, stream);

            document.Open();

            #region header

            Paragraph title = new Paragraph("LAMPIRAN DISPOSISI PEMBAYARAN FORWARDER\n\n\n", header_font_bold);
            title.Alignment = Element.ALIGN_CENTER;

            Paragraph title1 = new Paragraph("DISPOSISI BIAYA SHIPMENT", normal_font_underlined);
            Paragraph no     = new Paragraph(viewModel.dispositionNo, normal_font);
            Paragraph fwd    = new Paragraph($"Invoice {viewModel.forwarder.name} No. {viewModel.invoiceNumber} Tgl. " +
                                             $"{viewModel.invoiceDate.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font);

            document.Add(title);
            document.Add(title1);
            document.Add(no);
            document.Add(fwd);
            document.Add(new Paragraph("\n", normal_font));
            #endregion



            #region bodyTable

            List <string> inv  = new List <string>();
            List <string> como = new List <string>();
            foreach (var i in invoices)
            {
                var dupInv = como.Find(a => a == i.InvoiceNo);
                if (string.IsNullOrEmpty(dupInv))
                {
                    inv.Add(i.InvoiceNo);
                }
                foreach (var item in i.Items)
                {
                    var dupComo = como.Find(a => a == item.Comodity.Name);
                    if (string.IsNullOrEmpty(dupComo))
                    {
                        como.Add(item.Comodity.Name);
                    }
                }
            }

            decimal invTotalQty = viewModel.invoiceDetails.Sum(a => a.quantity);
            decimal totalCtns   = viewModel.invoiceDetails.Sum(a => a.totalCarton);

            PdfPTable tableBody = new PdfPTable(7);
            tableBody.WidthPercentage = 80;
            tableBody.SetWidths(new float[] { 3f, 0.5f, 5f, 0.5f, 1f, 4f, 1f });

            PdfPCell cellCenterNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };
            PdfPCell cellLeftNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRightNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };
            PdfPCell cellLeftNoBorder1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellLeftTopBorder = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRightTopBorder = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };
            PdfPCell cellRightNoLeftBorder = new PdfPCell()
            {
                Border = Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };
            PdfPCell cellLeftBottomBorder = new PdfPCell()
            {
                Border = Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };

            cellLeftNoBorder.Phrase  = new Phrase("Dikirim per", normal_font);
            cellLeftNoBorder.Colspan = 1;
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase  = new Phrase(viewModel.sendBy, normal_font);
            cellLeftNoBorder1.Colspan = 5;
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase  = new Phrase("Flight / Route", normal_font);
            cellLeftNoBorder.Colspan = 1;
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.flightVessel, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase  = new Phrase("Destination To", normal_font);
            cellLeftNoBorder.Colspan = 1;
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.destination, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase(viewModel.freightBy == "AIR"?"AWB No." : "BL No.", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.freightNo, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Tgl", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.freightDate.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID")), normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Dscription", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(string.Join(", ", como), normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Shipping Co.", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.forwarder.name, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Buyer", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.buyerAgent.Name, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("LC No.", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.paymentTerm, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            tableBody.SpacingAfter        = 10;
            tableBody.SpacingBefore       = 5;
            tableBody.HorizontalAlignment = Element.ALIGN_LEFT;
            document.Add(tableBody);
            #endregion

            #region unit

            PdfPTable tableUnit = new PdfPTable(8);
            tableUnit.WidthPercentage = 100;
            tableUnit.SetWidths(new float[] { 4f, 0.5f, 4f, 4f, 4f, 4f, 4f, 4f });

            PdfPCell cellCenter = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };
            PdfPCell cellLeft = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRight = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };


            cellCenter.Phrase = new Phrase("Invoice No", normal_font);
            tableUnit.AddCell(cellCenter);
            cellCenter.Phrase  = new Phrase("Amount", normal_font);
            cellCenter.Colspan = 2;
            tableUnit.AddCell(cellCenter);
            cellCenter.Phrase  = new Phrase("Qty", normal_font);
            cellCenter.Colspan = 1;
            tableUnit.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Volume", normal_font);
            tableUnit.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("G.W.", normal_font);
            tableUnit.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Chargeable Weight", normal_font);
            tableUnit.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Total Carton", normal_font);
            tableUnit.AddCell(cellCenter);

            foreach (var invoice in viewModel.invoiceDetails)
            {
                cellLeft.Phrase = new Phrase(invoice.invoiceNo, normal_font);
                tableUnit.AddCell(cellLeft);
                cellLeftBottomBorder.Phrase = new Phrase("$", normal_font);
                tableUnit.AddCell(cellLeftBottomBorder);
                cellRightNoLeftBorder.Phrase = new Phrase(string.Format("{0:n2}", invoice.amount), normal_font);
                tableUnit.AddCell(cellRightNoLeftBorder);
                cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.quantity) + " pcs", normal_font);
                tableUnit.AddCell(cellRight);
                cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.volume) + " cbm", normal_font);
                tableUnit.AddCell(cellRight);
                cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.grossWeight) + " kgs", normal_font);
                tableUnit.AddCell(cellRight);
                cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.chargeableWeight) + " kgs", normal_font);
                tableUnit.AddCell(cellRight);
                cellRight.Phrase = new Phrase(string.Format("{0:n2}", invoice.totalCarton) + " ctns", normal_font);
                tableUnit.AddCell(cellRight);
            }

            tableUnit.SpacingAfter        = 10;
            tableUnit.SpacingBefore       = 5;
            tableUnit.HorizontalAlignment = Element.ALIGN_LEFT;
            document.Add(tableUnit);

            #endregion

            #region bill
            document.Add(new Phrase("Realisasi biaya :", normal_font));

            PdfPTable tableBill = new PdfPTable(7);
            tableBill.WidthPercentage = 95;
            tableBill.SetWidths(new float[] { 2f, 0.5f, 7f, 0.5f, 1f, 3f, 1f });
            var last = viewModel.billDetails.Last();
            foreach (var bill in viewModel.billDetails)
            {
                cellLeftNoBorder.Phrase = new Phrase("", normal_font);
                tableBill.AddCell(cellLeftNoBorder);
                cellLeftNoBorder.Phrase = new Phrase("", normal_font);
                tableBill.AddCell(cellLeftNoBorder);
                cellLeftNoBorder.Phrase = new Phrase("- " + bill.billDescription, normal_font);
                tableBill.AddCell(cellLeftNoBorder);
                cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
                tableBill.AddCell(cellCenterNoBorder);
                cellLeftNoBorder.Phrase = new Phrase("IDR", normal_font);
                tableBill.AddCell(cellLeftNoBorder);
                cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", bill.amount), normal_font);
                tableBill.AddCell(cellRightNoBorder);
                if (bill == last)
                {
                    cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font);
                    tableBill.AddCell(cellLeftNoBorder);
                }
                else
                {
                    cellLeftNoBorder.Phrase = new Phrase("", normal_font);
                    tableBill.AddCell(cellLeftNoBorder);
                }
            }

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBill.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("IDR", normal_font);
            tableBill.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue), normal_font);
            tableBill.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase($"- PPH {viewModel.incomeTax.name} ({viewModel.incomeTax.rate}%)", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font_bold);
            tableBill.AddCell(cellCenterNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("IDR", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);
            cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.IncomeTaxValue), normal_font_bold);
            tableBill.AddCell(cellRightNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("(-)", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBill.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("IDR", normal_font);
            tableBill.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue - viewModel.IncomeTaxValue), normal_font);
            tableBill.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("- PPN", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBill.AddCell(cellCenterNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("IDR", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.vatValue), normal_font);
            tableBill.AddCell(cellRightNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase($"Total bayar setelah PPH {viewModel.incomeTax.name} & PPN", normal_font);
            tableBill.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBill.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("IDR", normal_font_bold);
            tableBill.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.totalBill), normal_font_bold);
            tableBill.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBill.AddCell(cellLeftNoBorder);

            tableBill.SpacingAfter        = 10;
            tableBill.SpacingBefore       = 5;
            tableBill.HorizontalAlignment = Element.ALIGN_CENTER;
            document.Add(tableBill);
            #endregion

            var terbilang = NumberToTextIDN.terbilang((double)viewModel.totalBill) + " rupiah";

            Paragraph trbilang = new Paragraph($"[ Terbilang : {terbilang} ]\n\n", normal_font);
            document.Add(trbilang);

            document.Add(new Paragraph("Lampiran    : " + viewModel.remark + "\n\n", normal_font));

            #region sign
            PdfPTable tableSign = new PdfPTable(3);
            tableSign.WidthPercentage = 100;
            tableSign.SetWidths(new float[] { 1f, 1f, 1f });

            PdfPCell cellBodySignNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };

            cellBodySignNoBorder.Phrase = new Phrase($"Solo, {DateTimeOffset.Now.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);


            cellBodySignNoBorder.Phrase = new Phrase("Hormat,\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("Dicheck,\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("Mengetahui,\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);


            cellBodySignNoBorder.Phrase = new Phrase("(                           )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("(                           )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("(                           )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);

            document.Add(tableSign);
            #endregion

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }
        public MemoryStream GeneratePdfTemplate(GarmentShippingPaymentDispositionViewModel viewModel, List <GarmentShippingInvoiceViewModel> invoices, List <GarmentPackingListViewModel> packingLists, int timeoffset)
        {
            const int MARGIN = 20;

            Font header_font_bold_big        = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font header_font_bold            = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);
            Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12, Font.UNDERLINE);
            Font header_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font normal_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);
            Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE);
            Font normal_font_bold       = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);

            Document document = new Document(PageSize.A4, MARGIN, MARGIN, 40, MARGIN);

            MemoryStream stream = new MemoryStream();
            PdfWriter    writer = PdfWriter.GetInstance(document, stream);

            document.Open();

            #region header

            Paragraph title = new Paragraph("LAMPIRAN DISPOSISI PEMBAYARAN FORWARDER\n\n\n", header_font_bold);
            title.Alignment = Element.ALIGN_CENTER;

            Paragraph title1 = new Paragraph("DISPOSISI BIAYA SHIPMENT", normal_font_underlined);
            Paragraph no     = new Paragraph(viewModel.dispositionNo, normal_font);

            document.Add(title);
            document.Add(title1);
            document.Add(no);
            document.Add(new Paragraph("\n", normal_font));
            #endregion



            #region bodyTable

            List <string> inv  = new List <string>();
            List <string> como = new List <string>();
            foreach (var i in invoices)
            {
                var dupInv = como.Find(a => a == i.InvoiceNo);
                if (string.IsNullOrEmpty(dupInv))
                {
                    inv.Add(i.InvoiceNo);
                }
                foreach (var item in i.Items)
                {
                    var dupComo = como.Find(a => a == item.Comodity.Name);
                    if (string.IsNullOrEmpty(dupComo))
                    {
                        como.Add(item.Comodity.Name);
                    }
                }
            }

            decimal invTotalQty = viewModel.invoiceDetails.Sum(a => a.quantity);
            decimal totalCtns   = viewModel.invoiceDetails.Sum(a => a.totalCarton);
            double  totalcbm    = packingLists.Sum(a => a.Measurements.Sum(m => m.Length * m.Width * m.Height * m.CartonsQuantity / 1000000));

            PdfPTable tableBody = new PdfPTable(7);
            tableBody.WidthPercentage = 80;
            tableBody.SetWidths(new float[] { 3f, 0.5f, 5f, 0.5f, 1f, 4f, 1f });

            PdfPCell cellCenterNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };
            PdfPCell cellLeftNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRightNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };
            PdfPCell cellLeftNoBorder1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellLeftTopBorder = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRightTopBorder = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };

            cellLeftNoBorder.Phrase = new Phrase("Subject", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase  = new Phrase(viewModel.invoiceNumber, normal_font);
            cellLeftNoBorder1.Colspan = 5;
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase  = new Phrase("Dikirim per", normal_font);
            cellLeftNoBorder.Colspan = 1;
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.sendBy, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Forwarder", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.forwarder.name, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Material", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(string.Join(", ", como), normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Pembeli", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.buyerAgent.Name, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("LCNo", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(viewModel.paymentTerm, normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Invoice", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase(string.Join(", ", inv), normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Party", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase($"{string.Format("{0:n2}", invTotalQty)} pcs / {string.Format("{0:n2}", totalCtns)} ctns =  {string.Format("{0:n2}", totalcbm)} cbm", normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            cellLeftNoBorder.Phrase = new Phrase("Biaya", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder1.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder1);

            var last = viewModel.billDetails.Last();
            foreach (var bill in viewModel.billDetails)
            {
                cellLeftNoBorder.Phrase = new Phrase("", normal_font);
                tableBody.AddCell(cellLeftNoBorder);
                cellLeftNoBorder.Phrase = new Phrase("", normal_font);
                tableBody.AddCell(cellLeftNoBorder);
                cellLeftNoBorder.Phrase = new Phrase(bill.billDescription, normal_font);
                tableBody.AddCell(cellLeftNoBorder);
                cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
                tableBody.AddCell(cellCenterNoBorder);
                cellLeftNoBorder.Phrase = new Phrase("RP", normal_font);
                tableBody.AddCell(cellLeftNoBorder);
                cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", bill.amount), normal_font);
                tableBody.AddCell(cellRightNoBorder);
                if (bill == last)
                {
                    cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font);
                    tableBody.AddCell(cellLeftNoBorder);
                }
                else
                {
                    cellLeftNoBorder.Phrase = new Phrase("", normal_font);
                    tableBody.AddCell(cellLeftNoBorder);
                }
            }

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("RP", normal_font);
            tableBody.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue), normal_font);
            tableBody.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase($"PPH {viewModel.incomeTax.name} ({viewModel.incomeTax.rate}%)", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font_bold);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("RP", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);
            cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.IncomeTaxValue), normal_font_bold);
            tableBody.AddCell(cellRightNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("(-)", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("RP", normal_font);
            tableBody.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue - viewModel.IncomeTaxValue), normal_font);
            tableBody.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("PPN", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("RP", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.vatValue), normal_font);
            tableBody.AddCell(cellRightNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("RP", normal_font_bold);
            tableBody.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.totalBill), normal_font_bold);
            tableBody.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            tableBody.SpacingAfter        = 10;
            tableBody.SpacingBefore       = 5;
            tableBody.HorizontalAlignment = Element.ALIGN_LEFT;
            document.Add(tableBody);

            var terbilang = NumberToTextIDN.terbilang((double)viewModel.totalBill) + " rupiah";

            Paragraph trbilang = new Paragraph($"[ Terbilang : {terbilang} ]\n\n", normal_font);
            document.Add(trbilang);
            #endregion

            #region unit
            Paragraph units = new Paragraph("Beban Per Unit", normal_font_bold);
            document.Add(units);

            PdfPTable tableUnit = new PdfPTable(2);
            tableUnit.WidthPercentage = 50;
            tableUnit.SetWidths(new float[] { 1f, 1f });

            PdfPCell cellCenter = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };
            PdfPCell cellLeft = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRight = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };


            cellCenter.Phrase = new Phrase("Unit", normal_font_bold);
            tableUnit.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Amount", normal_font_bold);
            tableUnit.AddCell(cellCenter);

            foreach (var unitItem in viewModel.unitCharges)
            {
                cellLeft.Phrase = new Phrase(unitItem.unit.Code, normal_font);
                tableUnit.AddCell(cellLeft);
                cellRight.Phrase = new Phrase(string.Format("{0:n2}", unitItem.billAmount), normal_font);
                tableUnit.AddCell(cellRight);
            }

            tableUnit.SpacingAfter        = 10;
            tableUnit.SpacingBefore       = 5;
            tableUnit.HorizontalAlignment = Element.ALIGN_LEFT;
            document.Add(tableUnit);

            #endregion

            #region sign
            PdfPTable tableSign = new PdfPTable(3);
            tableSign.WidthPercentage = 100;
            tableSign.SetWidths(new float[] { 1f, 1f, 1f });

            PdfPCell cellBodySignNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };

            cellBodySignNoBorder.Phrase = new Phrase($"Solo, {DateTimeOffset.Now.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);


            cellBodySignNoBorder.Phrase = new Phrase("Bag. Exp garment,\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("Mengetahui,\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("Diterima,\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);


            cellBodySignNoBorder.Phrase = new Phrase("(                           )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("(                           )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("(                           )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);

            document.Add(tableSign);
            #endregion

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }
        public MemoryStream GeneratePdfTemplate(GarmentShippingPaymentDispositionViewModel viewModel, int timeoffset)
        {
            const int MARGIN = 20;

            Font header_font_bold_big        = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font header_font_bold            = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);
            Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12, Font.UNDERLINE);
            Font header_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font normal_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);
            Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE);
            Font normal_font_bold       = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10);

            Document document = new Document(PageSize.A4, MARGIN, MARGIN, 40, MARGIN);

            MemoryStream stream = new MemoryStream();
            PdfWriter    writer = PdfWriter.GetInstance(document, stream);

            document.Open();

            #region header

            Paragraph title = new Paragraph("LAMPIRAN DISPOSISI PEMBAYARAN COURIER\n\n\n", header_font_bold);
            title.Alignment = Element.ALIGN_CENTER;

            Paragraph title1 = new Paragraph("DISPOSISI BIAYA SHIPMENT", normal_font_underlined);
            Paragraph no     = new Paragraph(viewModel.dispositionNo, normal_font);
            Paragraph title2 = new Paragraph("Kepada : \nBp./Ibu Kasir Exp Garment PT Danliris", normal_font);

            Paragraph words = new Paragraph($"\nHarap dibayarkan kepada {viewModel.courier.Name} {viewModel.address} " +
                                            $"NPWP {viewModel.npwp} untuk tagihan Invoice No. {viewModel.invoiceNumber} Tgl. " +
                                            $"{viewModel.invoiceDate.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}" +
                                            $" Faktur Pajak No.{viewModel.invoiceTaxNumber} dengan rincian sbb : ", normal_font);

            document.Add(title);
            document.Add(title1);
            document.Add(no);
            document.Add(title2);
            document.Add(words);
            #endregion



            #region bodyTable

            PdfPTable tableBody = new PdfPTable(5);
            tableBody.WidthPercentage = 70;
            tableBody.SetWidths(new float[] { 3f, 0.5f, 1f, 2.8f, 1f });

            PdfPCell cellCenterNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };
            PdfPCell cellLeftNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRightNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };
            PdfPCell cellLeftNoBorder1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellLeftTopBorder = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRightTopBorder = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };

            var last = viewModel.billDetails.Last();
            foreach (var bill in viewModel.billDetails)
            {
                cellLeftNoBorder.Phrase = new Phrase("- " + bill.billDescription, normal_font);
                tableBody.AddCell(cellLeftNoBorder);
                cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
                tableBody.AddCell(cellCenterNoBorder);
                cellLeftNoBorder.Phrase = new Phrase("RP", normal_font);
                tableBody.AddCell(cellLeftNoBorder);
                cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", bill.amount), normal_font);
                tableBody.AddCell(cellRightNoBorder);
                if (bill == last)
                {
                    cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font);
                    tableBody.AddCell(cellLeftNoBorder);
                }
                else
                {
                    cellLeftNoBorder.Phrase = new Phrase("", normal_font);
                    tableBody.AddCell(cellLeftNoBorder);
                }
            }

            cellLeftNoBorder.Phrase = new Phrase("- Total Amount", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("RP", normal_font);
            tableBody.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue), normal_font);
            tableBody.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase($"- PPH {viewModel.incomeTax.name} ({viewModel.incomeTax.rate}%)", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font_bold);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("RP", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);
            cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.IncomeTaxValue), normal_font_bold);
            tableBody.AddCell(cellRightNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("(-)", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("RP", normal_font);
            tableBody.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.billValue - viewModel.IncomeTaxValue), normal_font);
            tableBody.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("- PPN", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("RP", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.vatValue), normal_font);
            tableBody.AddCell(cellRightNoBorder);
            cellLeftNoBorder.Phrase = new Phrase("(+)", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            cellLeftNoBorder.Phrase = new Phrase("- Total Bayar", normal_font);
            tableBody.AddCell(cellLeftNoBorder);
            cellCenterNoBorder.Phrase = new Phrase(":", normal_font_bold);
            tableBody.AddCell(cellCenterNoBorder);
            cellLeftTopBorder.Phrase = new Phrase("RP", normal_font_bold);
            tableBody.AddCell(cellLeftTopBorder);
            cellRightTopBorder.Phrase = new Phrase(string.Format("{0:n2}", viewModel.totalBill), normal_font_bold);
            tableBody.AddCell(cellRightTopBorder);
            cellLeftNoBorder.Phrase = new Phrase("", normal_font_bold);
            tableBody.AddCell(cellLeftNoBorder);

            tableBody.SpacingAfter        = 10;
            tableBody.SpacingBefore       = 5;
            tableBody.HorizontalAlignment = Element.ALIGN_LEFT;
            document.Add(tableBody);

            var terbilang = NumberToTextIDN.terbilang((double)viewModel.totalBill) + " rupiah";

            Paragraph trbilang = new Paragraph($"[ Terbilang : {terbilang} ]\n", normal_font);
            document.Add(trbilang);
            #endregion

            #region bank
            Paragraph units = new Paragraph("\nBeban Per Unit", normal_font_bold);
            document.Add(units);

            PdfPTable tableUnit = new PdfPTable(2);
            tableUnit.WidthPercentage = 50;
            tableUnit.SetWidths(new float[] { 1f, 1f });

            PdfPCell cellCenter = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };
            PdfPCell cellLeft = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };
            PdfPCell cellRight = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };


            cellCenter.Phrase = new Phrase("Unit", normal_font_bold);
            tableUnit.AddCell(cellCenter);
            cellCenter.Phrase = new Phrase("Amount", normal_font_bold);
            tableUnit.AddCell(cellCenter);

            foreach (var unitItem in viewModel.unitCharges)
            {
                cellLeft.Phrase = new Phrase(unitItem.unit.Code, normal_font);
                tableUnit.AddCell(cellLeft);
                cellRight.Phrase = new Phrase(string.Format("{0:n2}", unitItem.billAmount), normal_font);
                tableUnit.AddCell(cellRight);
            }

            tableUnit.SpacingAfter        = 10;
            tableUnit.SpacingBefore       = 5;
            tableUnit.HorizontalAlignment = Element.ALIGN_LEFT;
            document.Add(tableUnit);


            Paragraph closing = new Paragraph("Demikian permohonan kami, terima kasih.\n\n", normal_font);
            document.Add(closing);
            #endregion

            #region sign
            PdfPTable tableSign = new PdfPTable(4);
            tableSign.WidthPercentage = 100;
            tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f });

            PdfPCell cellBodySignNoBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT
            };

            cellBodySignNoBorder.Phrase = new Phrase($"Terima kasih, \nSolo, {DateTimeOffset.Now.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID"))}", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);


            cellBodySignNoBorder.Phrase = new Phrase("Hormat kami,\n\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("Mengetahui,\n\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("Menyetujui,\n\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("Dicek oleh,\n\n\n\n\n", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);


            cellBodySignNoBorder.Phrase = new Phrase("( Etty / Andrei )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("( Adriyana / Amumpuni )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("( Hendro Suseno )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);
            cellBodySignNoBorder.Phrase = new Phrase("(    L  i  a    )", normal_font);
            tableSign.AddCell(cellBodySignNoBorder);

            document.Add(tableSign);
            #endregion

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }