public CostCalculationGarmentViewModel GetNewData()
        {
            long nowTicks = DateTimeOffset.Now.Ticks;

            var data = new CostCalculationGarmentViewModel
            {
                RO_Number = $"RO_Number{nowTicks}",
                CostCalculationGarment_Materials = new List <CostCalculationGarment_MaterialViewModel>
                {
                    new CostCalculationGarment_MaterialViewModel
                    {
                        PO_SerialNumber = $"PO_SerialNumber{nowTicks}",
                        Product         = new GarmentProductViewModel {
                            Id   = 1,
                            Code = $"ProductCode{nowTicks}",
                        },
                        BudgetQuantity = 100,
                        UOMPrice       = new UomViewModel {
                            Id   = "1",
                            Unit = $"UOMPriceUnit{nowTicks}",
                        },
                        IsPRMaster = true,
                    }
                }
            };

            return(data);
        }
        private async Task <Tuple <List <MonitoringROJobOrderViewModel>, CostCalculationGarmentViewModel> > GetData(long costCalculationId)
        {
            CostCalculationGarmentViewModel costCalculationGarmentViewModel = await GetCostCalculation(costCalculationId);

            if (costCalculationGarmentViewModel.CostCalculationGarment_Materials != null && costCalculationGarmentViewModel.CostCalculationGarment_Materials.Count() > 0)
            {
                HashSet <long>            productIds   = costCalculationGarmentViewModel.CostCalculationGarment_Materials.Select(m => m.Product.Id).ToHashSet();
                Dictionary <long, string> productNames = await GetProducts(productIds);

                var result = costCalculationGarmentViewModel.CostCalculationGarment_Materials.Select(m =>
                {
                    List <MonitoringROJobOrderItemViewModel> garmentPOMasterDistributions = new List <MonitoringROJobOrderItemViewModel>();
                    if (m.IsPRMaster.GetValueOrDefault())
                    {
                        var Query = from prmasteritem in dbContext.GarmentPurchaseRequestItems
                                    join prmaster in dbContext.GarmentPurchaseRequests on prmasteritem.GarmentPRId equals prmaster.Id
                                    join doDetail in dbContext.GarmentDeliveryOrderDetails on prmasteritem.Id equals doDetail.PRItemId into a
                                    from DODTL in a.DefaultIfEmpty()
                                    join poDistItem in dbContext.GarmentPOMasterDistributionItems on DODTL.Id equals poDistItem.DODetailId into b
                                    from DISTITEM in b.DefaultIfEmpty()
                                    join poDistDetail in dbContext.GarmentPOMasterDistributionDetails on DISTITEM.Id equals poDistDetail.POMasterDistributionItemId into c
                                    from DISTDTL in c.DefaultIfEmpty()
                                    join poDist in dbContext.GarmentPOMasterDistributions on DISTITEM.POMasterDistributionId equals poDist.Id into d
                                    from DISTHDR in d.DefaultIfEmpty()
                                    where DISTDTL.POSerialNumber == m.PO_SerialNumber || prmasteritem.PO_SerialNumber == m.POMaster

                                    select new MonitoringROJobOrderItemViewModel
                        {
                            ROMaster             = prmaster.RONo,
                            POMaster             = prmasteritem.PO_SerialNumber,
                            DistributionQuantity = DISTDTL == null ? 0 : DISTDTL.Quantity,
                            Conversion           = DISTDTL == null ? 0 : DISTDTL.Conversion,
                            UomCCUnit            = DISTDTL == null ? "-" : DISTDTL.UomCCUnit,
                            DONo            = DISTHDR == null ? "-" : DISTHDR.DONo,
                            SupplierName    = DISTHDR == null ? "-" : DISTHDR.SupplierName,
                            OverUsageReason = DISTDTL == null ? "-" : DISTDTL.OverUsageReason
                        };
                        garmentPOMasterDistributions = Query.ToList();
                    }

                    return(new MonitoringROJobOrderViewModel
                    {
                        POSerialNumber = m.PO_SerialNumber,
                        POMasterNumber = m.POMaster,
                        ProductCode = m.Product.Code,
                        Description = m.Description,
                        ProductName = productNames.GetValueOrDefault(m.Product.Id),
                        BudgetQuantity = m.BudgetQuantity,
                        UomPriceUnit = m.UOMPrice.Unit,
                        Status = m.IsPRMaster.GetValueOrDefault() ? "MASTER" : "JOB ORDER",
                        Items = garmentPOMasterDistributions
                    });
                }).ToList();

                return(new Tuple <List <MonitoringROJobOrderViewModel>, CostCalculationGarmentViewModel>(result, costCalculationGarmentViewModel));
            }

            throw new Exception("Tidak ada Product");
        }
        public Dictionary <string, object> GetResultFormatterOk(CostCalculationGarmentViewModel costCalculationGarmentViewModel)
        {
            var data = costCalculationGarmentViewModel;

            Dictionary <string, object> result =
                new ResultFormatter("1.0", General.OK_STATUS_CODE, General.OK_MESSAGE)
                .Ok(data);

            return(result);
        }
Exemplo n.º 4
0
        private async Task <Tuple <List <MonitoringROJobOrderViewModel>, CostCalculationGarmentViewModel> > GetData(long costCalculationId)
        {
            CostCalculationGarmentViewModel costCalculationGarmentViewModel = await GetCostCalculation(costCalculationId);

            if (costCalculationGarmentViewModel.CostCalculationGarment_Materials != null && costCalculationGarmentViewModel.CostCalculationGarment_Materials.Count() > 0)
            {
                HashSet <long>            productIds   = costCalculationGarmentViewModel.CostCalculationGarment_Materials.Select(m => m.Product.Id).ToHashSet();
                Dictionary <long, string> productNames = await GetProducts(productIds);

                var result = costCalculationGarmentViewModel.CostCalculationGarment_Materials.Select(m =>
                {
                    List <MonitoringROJobOrderItemViewModel> garmentPOMasterDistributions = new List <MonitoringROJobOrderItemViewModel>();
                    if (m.IsPRMaster.GetValueOrDefault())
                    {
                        var Query = from poDistDetail in dbContext.GarmentPOMasterDistributionDetails
                                    join poDistItem in dbContext.GarmentPOMasterDistributionItems on poDistDetail.POMasterDistributionItemId equals poDistItem.Id
                                    join poDist in dbContext.GarmentPOMasterDistributions on poDistItem.POMasterDistributionId equals poDist.Id
                                    join doDetail in dbContext.GarmentDeliveryOrderDetails on poDistItem.DODetailId equals doDetail.Id
                                    where poDistDetail.POSerialNumber == m.PO_SerialNumber
                                    select new MonitoringROJobOrderItemViewModel
                        {
                            ROMaster             = doDetail.RONo,
                            POMaster             = doDetail.POSerialNumber,
                            DistributionQuantity = poDistDetail.Quantity,
                            Conversion           = poDistDetail.Conversion,
                            UomCCUnit            = poDistDetail.UomCCUnit,
                            DONo            = poDist.DONo,
                            SupplierName    = poDist.SupplierName,
                            OverUsageReason = poDistDetail.OverUsageReason
                        };
                        garmentPOMasterDistributions = Query.ToList();
                    }

                    return(new MonitoringROJobOrderViewModel
                    {
                        POSerialNumber = m.PO_SerialNumber,
                        ProductCode = m.Product.Code,
                        ProductName = productNames.GetValueOrDefault(m.Product.Id),
                        BudgetQuantity = m.BudgetQuantity,
                        UomPriceUnit = m.UOMPrice.Unit,
                        Status = m.IsPRMaster.GetValueOrDefault() ? "MASTER" : "JOB ORDER",
                        Items = garmentPOMasterDistributions
                    });
                }).ToList();

                return(new Tuple <List <MonitoringROJobOrderViewModel>, CostCalculationGarmentViewModel>(result, costCalculationGarmentViewModel));
            }

            throw new Exception("Tidak ada Product");
        }
        private async Task <CostCalculationGarmentViewModel> GetCostCalculation(long costCalculationId)
        {
            var httpClient = (IHttpClientService)serviceProvider.GetService(typeof(IHttpClientService));
            var response   = await httpClient.GetAsync($"{APIEndpoint.Sales}cost-calculation-garments/{costCalculationId}");

            var content = await response.Content.ReadAsStringAsync();

            Dictionary <string, object> result = JsonConvert.DeserializeObject <Dictionary <string, object> >(content) ?? new Dictionary <string, object>();

            if (response.IsSuccessStatusCode)
            {
                CostCalculationGarmentViewModel data = JsonConvert.DeserializeObject <CostCalculationGarmentViewModel>(result.GetValueOrDefault("data").ToString());
                return(data);
            }
            else
            {
                throw new Exception(string.Concat("Failed Get CostCalculation : ", (string)result.GetValueOrDefault("error") ?? "- ", ". Message : ", (string)result.GetValueOrDefault("message") ?? "- ", ". Status : ", response.StatusCode, "."));
            }
        }
        public MemoryStream GeneratePdfTemplate(CostCalculationGarmentViewModel viewModel)
        {
            BaseFont bf          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            BaseFont bf_bold     = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            Font     normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7);
            Font     bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7);
            DateTime now         = DateTime.Now;

            Document     document = new Document(PageSize.A4, 10, 10, 10, 10);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            writer.CloseStream = false;
            document.Open();
            PdfContentByte cb = writer.DirectContent;

            float    margin          = 10;
            float    printedOnHeight = 10;
            float    startY          = 840 - margin;
            PdfPCell cell_colon      = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Phrase = new Phrase(":", normal_font)
            };

            #region Header
            cb.BeginText();
            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. EFRATA RETAILINDO", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "BUDGET PRODUCTION", 10, 805, 0);
            cb.EndText();
            #endregion

            #region Detail 1 (Top)
            PdfPTable table_detail1 = new PdfPTable(9);
            table_detail1.TotalWidth = 570f;

            float[] detail1_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1.5f, 0.1f, 2f };
            table_detail1.SetWidths(detail1_widths);

            PdfPCell cell_detail1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2
            };

            cell_detail1.Phrase = new Phrase("RO", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.RO}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("SECTION", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Section}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("CONFIRM ORDER", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.ConfirmDate.ToString("dd/MM/yyyy")}", normal_font);
            table_detail1.AddCell(cell_detail1);
            #endregion

            #region Draw Detail 1
            float row1Y = 800;
            table_detail1.WriteSelectedRows(0, -1, 10, row1Y, cb);
            #endregion

            bool isDollar = viewModel.Rate.Id != 0;

            #region Detail 2 (Bottom, Column 1)
            PdfPTable table_detail2 = new PdfPTable(2);
            table_detail2.TotalWidth = 230f;

            float[] detail2_widths = new float[] { 2f, 5f };
            table_detail2.SetWidths(detail2_widths);

            PdfPCell cell_detail2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };

            cell_detail2.Phrase = new Phrase("BUYER", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.Buyer.Name}", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("ARTICLE", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.Article}", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("DESCRIPTION", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.Description}", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("QTY", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.Quantity} PCS", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("DELIVERY", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.DeliveryDate.ToString("dd/MM/yyyy")}", normal_font);
            table_detail2.AddCell(cell_detail2);
            #endregion

            #region Signature
            PdfPTable table_signature = new PdfPTable(5);
            table_signature.TotalWidth = 570f;

            float[] signature_widths = new float[] { 1f, 1f, 1f, 1f, 1f };
            table_signature.SetWidths(signature_widths);

            PdfPCell cell_signature = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };

            cell_signature.Phrase = new Phrase("Membuat,", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Mengetahui,", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Menyetujui,", normal_font);
            table_signature.AddCell(cell_signature);

            string signatureArea = string.Empty;
            for (int i = 0; i < 4; i++)
            {
                signatureArea += Environment.NewLine;
            }

            cell_signature.Phrase = new Phrase(signatureArea, normal_font);
            table_signature.AddCell(cell_signature);
            table_signature.AddCell(cell_signature);
            table_signature.AddCell(cell_signature);
            table_signature.AddCell(cell_signature);
            table_signature.AddCell(cell_signature);

            cell_signature.Phrase = new Phrase("Merchandiser", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Sie Merchandiser", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Sie Pembelian", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Bag Produksi", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Direktur Marketing", normal_font);
            table_signature.AddCell(cell_signature);
            #endregion

            #region Cost Calculation Material
            PdfPTable table_ccm = new PdfPTable(10);
            table_ccm.TotalWidth = 570f;

            float[] ccm_widths = new float[] { 1f, 3f, 4f, 6f, 2f, 3f, 3f, 2f, 3f, 3f };
            table_ccm.SetWidths(ccm_widths);

            PdfPCell cell_ccm = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };

            cell_ccm.Phrase = new Phrase("NO", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("CATEGORIES", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("MATERIALS", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("DESCRIPTION", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("USAGE", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("PRICE", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("QUANTITY", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("UNIT", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("AMOUNT", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("PO NUMBER", bold_font);
            table_ccm.AddCell(cell_ccm);

            float  row2Y               = row1Y - table_detail1.TotalHeight - 10;
            float  row3Height          = table_detail2.TotalHeight;
            float  row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin;
            float  row2AllowedHeight   = row2Y - printedOnHeight - margin;
            double totalBudget         = 0;

            #region Process Cost
            double processCost = viewModel.ProductionCost;
            #endregion

            for (int i = 0; i < viewModel.CostCalculationGarment_Materials.Count; i++)
            {
                cell_ccm.Phrase = new Phrase((i + 1).ToString(), normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_LEFT;

                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Category.SubCategory != null ? String.Format("{0} - {1}", viewModel.CostCalculationGarment_Materials[i].Category.Name, viewModel.CostCalculationGarment_Materials[i].Category.SubCategory) : viewModel.CostCalculationGarment_Materials[i].Category.Name, normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Material.Name, normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Description, normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT;

                double usage = viewModel.CostCalculationGarment_Materials[i].Quantity ?? 0;
                cell_ccm.Phrase = new Phrase(usage.ToString(), normal_font);
                table_ccm.AddCell(cell_ccm);

                double price = viewModel.CostCalculationGarment_Materials[i].Price ?? 0;
                cell_ccm.Phrase = new Phrase(String.Format("{0}/{1}", Number.ToRupiahWithoutSymbol(price), viewModel.CostCalculationGarment_Materials[i].UOMPrice.Name), normal_font);
                table_ccm.AddCell(cell_ccm);

                double factor;
                if (viewModel.CostCalculationGarment_Materials[i].Category.Name == "ACC")
                {
                    factor = viewModel.AccessoriesAllowance ?? 0;
                }
                else
                {
                    factor = viewModel.FabricAllowance ?? 0;
                }
                double totalQuantity   = viewModel.Quantity ?? 0;
                double conversion      = (double)viewModel.CostCalculationGarment_Materials[i].Conversion;
                double usageConversion = usage / conversion;
                double quantity        = (100 + factor) / 100 * usageConversion * totalQuantity;

                quantity = Math.Ceiling(quantity);

                cell_ccm.Phrase = new Phrase(quantity.ToString(), normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_CENTER;
                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].UOMQuantity.Name, normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT;
                double amount = quantity * price;
                cell_ccm.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(amount), normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_CENTER;
                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].PO, normal_font);
                table_ccm.AddCell(cell_ccm);

                totalBudget += amount;
                float currentHeight = table_ccm.TotalHeight;
                if (currentHeight / row2RemainingHeight > 1)
                {
                    if (currentHeight / row2AllowedHeight > 1)
                    {
                        PdfPRow headerRow = table_ccm.GetRow(0);
                        PdfPRow lastRow   = table_ccm.GetRow(table_ccm.Rows.Count - 1);
                        table_ccm.DeleteLastRow();
                        table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb);
                        table_ccm.DeleteBodyRows();
                        this.DrawPrintedOn(now, bf, cb);
                        document.NewPage();
                        table_ccm.Rows.Add(headerRow);
                        table_ccm.Rows.Add(lastRow);
                        table_ccm.CalculateHeights();
                        row2Y = startY;
                        row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin;
                        row2AllowedHeight   = row2Y - printedOnHeight - margin;
                    }
                }
            }
            #endregion

            #region Detail 3 (Bottom, Column 2)
            PdfPTable table_detail3 = new PdfPTable(8);
            table_detail3.TotalWidth = 330f;

            float[] detail3_widths = new float[] { 3.25f, 4.75f, 1.9f, 0.2f, 1.9f, 1.9f, 0.2f, 1.9f };
            table_detail3.SetWidths(detail3_widths);

            //double budgetCost = isDollar ? viewModel.ConfirmPrice * viewModel.Rate.Value ?? 0 : viewModel.ConfirmPrice ?? 0;
            double totalProcessCost = processCost * (double)viewModel.Quantity;
            double budgetCost       = totalBudget / (double)viewModel.Quantity;

            PdfPCell cell_detail3 = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };
            PdfPCell cell_detail3_right = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };
            PdfPCell cell_detail3_colspan6 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7, Colspan = 6
            };
            PdfPCell cell_detail3_colspan8 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7, Colspan = 8
            };

            cell_detail3.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("TOTAL BUDGET", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase($"{Number.ToRupiah(totalBudget)}", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3_colspan6.Phrase = new Phrase("STANDARD HOURS", normal_font);
            table_detail3.AddCell(cell_detail3_colspan6);

            double freightCost = 0;
            foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials)
            {
                freightCost += item.TotalShippingFee;
            }

            cell_detail3.Border = Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("BEA ANGKUT", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase($"{Number.ToRupiah(freightCost)}", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("SMV. CUT", normal_font);
            table_detail3.AddCell(cell_detail3);
            table_detail3.AddCell(cell_colon);
            cell_detail3.Border = Rectangle.NO_BORDER;
            cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Cutting}", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.NO_BORDER;
            cell_detail3.Phrase = new Phrase("SMV. SEW", normal_font);
            table_detail3.AddCell(cell_detail3);
            table_detail3.AddCell(cell_colon);
            cell_detail3.Border = Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Sewing}", normal_font);
            table_detail3.AddCell(cell_detail3);

            cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase("", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("SMV. FIN", normal_font);
            table_detail3.AddCell(cell_detail3);
            table_detail3.AddCell(cell_colon);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER;
            cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Finishing}", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER;
            cell_detail3.Phrase = new Phrase("SMV. TOT", normal_font);
            table_detail3.AddCell(cell_detail3);
            table_detail3.AddCell(cell_colon);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Total}", normal_font);
            table_detail3.AddCell(cell_detail3);


            cell_detail3_colspan8.Phrase = new Phrase("BUDGET COST / PCS" + "".PadRight(5) + $"{Number.ToRupiah(budgetCost)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan8);
            cell_detail3_colspan8.Phrase = new Phrase("PROCESS COST" + "".PadRight(5) + $"{Number.ToRupiah(processCost)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan8);
            cell_detail3_colspan8.Phrase = new Phrase("TOTAL PROCESS COST" + "".PadRight(5) + $"{Number.ToRupiah(totalProcessCost)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan8);

            double rateValue    = (double)viewModel.Rate.Value;
            double confirmPrice = (double)viewModel.ConfirmPrice;

            cell_detail3_colspan8.Phrase = isDollar ? new Phrase($"US$ 1 = {Number.ToRupiah(rateValue)}" + "".PadRight(10) + $"CONFIRM PRICE : {Number.ToDollar(confirmPrice)} / PCS", normal_font) : new Phrase($"CONFIRM PRICE : {Number.ToRupiah(confirmPrice)} / PCS", normal_font);
            table_detail3.AddCell(cell_detail3_colspan8);
            cell_detail3_colspan8.Border = Rectangle.NO_BORDER;
            cell_detail3_colspan8.HorizontalAlignment = Element.ALIGN_CENTER;
            cell_detail3_colspan8.Phrase = new Phrase($"ALLOWANCE >> FAB = {viewModel.FabricAllowance}%, ACC = {viewModel.AccessoriesAllowance}%", normal_font);
            table_detail3.AddCell(cell_detail3_colspan8);
            #endregion

            #region Draw Others
            table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb);

            float row3Y = row2Y - table_ccm.TotalHeight - 10;
            float row3RemainigHeight = row3Y - printedOnHeight - margin;
            if (row3RemainigHeight < row3Height)
            {
                this.DrawPrintedOn(now, bf, cb);
                row3Y = startY;
                document.NewPage();
            }

            table_detail2.WriteSelectedRows(0, -1, margin, row3Y, cb);

            table_detail3.WriteSelectedRows(0, -1, margin + table_detail2.TotalWidth + 10, row3Y, cb);

            float signatureY = row3Y - row3Height - 10;
            signatureY = signatureY - 50;
            float signatureRemainingHeight = signatureY - printedOnHeight - margin;
            if (signatureRemainingHeight < table_signature.TotalHeight)
            {
                this.DrawPrintedOn(now, bf, cb);
                signatureY = startY;
                document.NewPage();
            }
            table_signature.WriteSelectedRows(0, -1, margin, signatureY, cb);

            this.DrawPrintedOn(now, bf, cb);
            #endregion

            document.Close();

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

            return(stream);
        }
        public CostCalculationGarment MapToModel(CostCalculationGarmentViewModel viewModel)
        {
            CostCalculationGarment model = new CostCalculationGarment();

            PropertyCopier <CostCalculationGarmentViewModel, CostCalculationGarment> .Copy(viewModel, model);

            model.Convection = viewModel.Convection;

            model.FabricAllowance      = Percentage.ToFraction(viewModel.FabricAllowance);
            model.AccessoriesAllowance = Percentage.ToFraction(viewModel.AccessoriesAllowance);

            model.SizeRange = viewModel.SizeRange;

            model.BuyerId   = viewModel.Buyer._id;
            model.BuyerName = viewModel.Buyer.name;

            model.EfficiencyId    = viewModel.Efficiency.Id;
            model.EfficiencyValue = Percentage.ToFraction(viewModel.Efficiency.Value);

            model.UOMID   = viewModel.UOM._id;
            model.UOMCode = viewModel.UOM.code;
            model.UOMUnit = viewModel.UOM.unit;

            model.WageId   = viewModel.Wage.Id;
            model.WageRate = viewModel.Wage.Value != null ? (double)viewModel.Wage.Value : 0;

            model.ComodityID           = viewModel.Commodity._id;
            model.Commodity            = viewModel.Commodity.name;
            model.CommodityDescription = viewModel.CommodityDescription;

            model.THRId   = viewModel.THR.Id;
            model.THRRate = viewModel.THR.Value != null ? (double)viewModel.THR.Value : 0;

            model.RateId    = viewModel.Rate.Id;
            model.RateValue = viewModel.Rate.Value != null ? (double)viewModel.Rate.Value : 0;

            model.CostCalculationGarment_Materials = new List <CostCalculationGarment_Material>();

            foreach (CostCalculationGarment_MaterialViewModel CostCalculationGarment_MaterialVM in viewModel.CostCalculationGarment_Materials)
            {
                CostCalculationGarment_Material CostCalculationGarment_Material = new CostCalculationGarment_Material();
                PropertyCopier <CostCalculationGarment_MaterialViewModel, CostCalculationGarment_Material> .Copy(CostCalculationGarment_MaterialVM, CostCalculationGarment_Material);

                CostCalculationGarment_Material.Convection         = model.Convection;
                CostCalculationGarment_Material.ProductId          = CostCalculationGarment_MaterialVM.Product._id;
                CostCalculationGarment_Material.ProductCode        = CostCalculationGarment_MaterialVM.Product.code;
                CostCalculationGarment_Material.Construction       = CostCalculationGarment_MaterialVM.Product.construction;
                CostCalculationGarment_Material.Yarn               = CostCalculationGarment_MaterialVM.Product.yarn;
                CostCalculationGarment_Material.Width              = CostCalculationGarment_MaterialVM.Product.width;
                CostCalculationGarment_Material.Composition        = CostCalculationGarment_MaterialVM.Product.composition;
                CostCalculationGarment_Material.CategoryId         = CostCalculationGarment_MaterialVM.Category._id;
                CostCalculationGarment_Material.CategoryName       = CostCalculationGarment_MaterialVM.Category.SubCategory != null ? CostCalculationGarment_MaterialVM.Category.name + " - " + CostCalculationGarment_MaterialVM.Category.SubCategory : CostCalculationGarment_MaterialVM.Category.name;
                CostCalculationGarment_Material.UOMQuantityId      = CostCalculationGarment_MaterialVM.UOMQuantity._id;
                CostCalculationGarment_Material.UOMQuantityName    = CostCalculationGarment_MaterialVM.UOMQuantity.unit;
                CostCalculationGarment_Material.UOMPriceId         = CostCalculationGarment_MaterialVM.UOMPrice._id;
                CostCalculationGarment_Material.UOMPriceName       = CostCalculationGarment_MaterialVM.UOMPrice.unit;
                CostCalculationGarment_Material.ShippingFeePortion = Percentage.ToFraction(CostCalculationGarment_MaterialVM.ShippingFeePortion);

                model.CostCalculationGarment_Materials.Add(CostCalculationGarment_Material);
            }

            model.CommissionPortion = Percentage.ToFraction(viewModel.CommissionPortion);
            model.Risk = Percentage.ToFraction(viewModel.Risk);

            model.OTL1Id             = viewModel.OTL1.Id;
            model.OTL1Rate           = viewModel.OTL1.Value != null ? (double)viewModel.OTL1.Value : 0;
            model.OTL1CalculatedRate = viewModel.OTL1.CalculatedValue != null ? (double)viewModel.OTL1.CalculatedValue : 0;

            model.OTL2Id             = viewModel.OTL2.Id;
            model.OTL2Rate           = viewModel.OTL2.Value != null ? (double)viewModel.OTL2.Value : 0;
            model.OTL2CalculatedRate = viewModel.OTL2.CalculatedValue != null ? (double)viewModel.OTL2.CalculatedValue : 0;

            model.NETFOBP = Percentage.ToFraction(viewModel.NETFOBP);

            return(model);
        }
        public CostCalculationGarmentViewModel MapToViewModel(CostCalculationGarment model)
        {
            CostCalculationGarmentViewModel viewModel = new CostCalculationGarmentViewModel();

            PropertyCopier <CostCalculationGarment, CostCalculationGarmentViewModel> .Copy(model, viewModel);

            viewModel.Convection          = model.Convection;
            viewModel.AutoIncrementNumber = model.AutoIncrementNumber;

            viewModel.FabricAllowance      = Percentage.ToPercent(model.FabricAllowance);
            viewModel.AccessoriesAllowance = Percentage.ToPercent(model.AccessoriesAllowance);

            viewModel.SizeRange = model.SizeRange;

            viewModel.Buyer      = new BuyerViewModel();
            viewModel.Buyer._id  = model.BuyerId;
            viewModel.Buyer.name = model.BuyerName;

            viewModel.Efficiency       = new EfficiencyViewModel();
            viewModel.Efficiency.Id    = model.EfficiencyId;
            viewModel.Efficiency.Value = Percentage.ToPercent(model.EfficiencyValue);

            viewModel.UOM = new UOMViewModel()
            {
                _id  = model.UOMID,
                code = model.UOMCode,
                unit = model.UOMUnit
            };

            viewModel.Wage       = new RateViewModel();
            viewModel.Wage.Id    = model.WageId;
            viewModel.Wage.Value = model.WageRate;

            viewModel.THR       = new RateViewModel();
            viewModel.THR.Id    = model.THRId;
            viewModel.THR.Value = model.THRRate;

            viewModel.Rate       = new RateViewModel();
            viewModel.Rate.Id    = model.RateId;
            viewModel.Rate.Value = model.RateValue;

            viewModel.Commodity            = new MasterPlanComodityViewModel();
            viewModel.Commodity.name       = model.Commodity;
            viewModel.Commodity._id        = model.ComodityID;
            viewModel.CommodityDescription = model.CommodityDescription;

            viewModel.CostCalculationGarment_Materials = new List <CostCalculationGarment_MaterialViewModel>();
            if (model.CostCalculationGarment_Materials != null)
            {
                foreach (CostCalculationGarment_Material CostCalculationGarment_Material in model.CostCalculationGarment_Materials)
                {
                    CostCalculationGarment_MaterialViewModel CostCalculationGarment_MaterialVM = new CostCalculationGarment_MaterialViewModel();
                    PropertyCopier <CostCalculationGarment_Material, CostCalculationGarment_MaterialViewModel> .Copy(CostCalculationGarment_Material, CostCalculationGarment_MaterialVM);

                    CostCalculationGarment_Material.Convection = model.Convection;

                    CategoryViewModel categoryVM = new CategoryViewModel()
                    {
                        _id = CostCalculationGarment_Material.CategoryId
                    };
                    string[] names = CostCalculationGarment_Material.CategoryName.Split(new[] { " - " }, StringSplitOptions.None);
                    categoryVM.name = names[0];
                    try
                    {
                        categoryVM.SubCategory = names[1];
                    }
                    catch (IndexOutOfRangeException)
                    {
                        categoryVM.SubCategory = null;
                    }
                    CostCalculationGarment_MaterialVM.Category = categoryVM;

                    //CostCalculationGarment_Material.ProductId = new GarmentProductViewModel();

                    UOMViewModel uomQuantityVM = new UOMViewModel()
                    {
                        _id  = CostCalculationGarment_Material.UOMQuantityId,
                        unit = CostCalculationGarment_Material.UOMQuantityName
                    };
                    CostCalculationGarment_MaterialVM.UOMQuantity = uomQuantityVM;

                    UOMViewModel uomPriceVM = new UOMViewModel()
                    {
                        _id  = CostCalculationGarment_Material.UOMPriceId,
                        unit = CostCalculationGarment_Material.UOMPriceName
                    };
                    CostCalculationGarment_MaterialVM.UOMPrice = uomPriceVM;

                    CostCalculationGarment_MaterialVM.ShippingFeePortion = Percentage.ToPercent(CostCalculationGarment_Material.ShippingFeePortion);

                    CostCalculationGarment_MaterialVM.Product = new GarmentProductViewModel
                    {
                        _id          = CostCalculationGarment_Material.ProductId,
                        code         = CostCalculationGarment_Material.ProductCode,
                        composition  = CostCalculationGarment_Material.Composition,
                        construction = CostCalculationGarment_Material.Construction,
                        yarn         = CostCalculationGarment_Material.Yarn,
                        width        = CostCalculationGarment_Material.Width
                    };

                    //CostCalculationGarment_MaterialVM.PO_SerialNumber =

                    viewModel.CostCalculationGarment_Materials.Add(CostCalculationGarment_MaterialVM);
                }
            }

            viewModel.CommissionPortion = Percentage.ToPercent(model.CommissionPortion);
            viewModel.Risk = Percentage.ToPercent(model.Risk);

            viewModel.OTL1                 = new RateCalculatedViewModel();
            viewModel.OTL1.Id              = model.OTL1Id;
            viewModel.OTL1.Value           = model.OTL1Rate;
            viewModel.OTL1.CalculatedValue = model.OTL1CalculatedRate;

            viewModel.OTL2                 = new RateCalculatedViewModel();
            viewModel.OTL2.Id              = model.OTL2Id;
            viewModel.OTL2.Value           = model.OTL2Rate;
            viewModel.OTL2.CalculatedValue = model.OTL2CalculatedRate;

            viewModel.NETFOBP = Percentage.ToPercent((double)model.NETFOBP);

            return(viewModel);
        }
        public MemoryStream GeneratePdfTemplate(CostCalculationGarmentViewModel viewModel, int timeoffset)
        {
            BaseFont bf          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            BaseFont bf_bold     = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            Font     normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7);
            Font     bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7);
            Font     bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            DateTime now         = DateTime.Now;

            Document     document = new Document(PageSize.A4, 10, 10, 10, 10);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            writer.CloseStream = false;
            document.Open();
            PdfContentByte cb = writer.DirectContent;

            float margin          = 10;
            float printedOnHeight = 10;
            float startY          = 840 - margin;

            #region Header
            cb.BeginText();
            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. DAN LIRIS", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "COST CALCULATION EXPORT GARMENT", 10, 805, 0);
            cb.EndText();
            #endregion

            #region Detail 1 (Top)
            PdfPTable table_detail1 = new PdfPTable(9);
            table_detail1.TotalWidth = 500f;

            float[] detail1_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1f, 0.1f, 2f };
            table_detail1.SetWidths(detail1_widths);

            PdfPCell cell_detail1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2
            };
            PdfPCell cell_colon = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE
            };
            cell_colon.Phrase = new Phrase(":", normal_font);

            cell_detail1.Phrase = new Phrase("RO", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.RO_Number}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("SIZE RANGE", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.SizeRange}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("LEAD TIME", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.LeadTime} hari", normal_font);
            table_detail1.AddCell(cell_detail1);

            cell_detail1.Phrase = new Phrase("ARTICLE", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Article}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("SECTION", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Section}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("FABRIC", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.FabricAllowance}%", normal_font);
            table_detail1.AddCell(cell_detail1);

            cell_detail1.Phrase = new Phrase("DATE", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel._CreatedUtc.ToString("dd MMMM yyyy")}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("COMMODITY", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Commodity.name}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("ACC", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.AccessoriesAllowance}%", normal_font);
            table_detail1.AddCell(cell_detail1);

            cell_detail1.Phrase = new Phrase("KONVEKSI", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Convection}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            #endregion

            #region Image
            float imageHeight;
            try
            {
                byte[] imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.ImageFile));
                Image  image     = Image.GetInstance(imgb: imageByte);
                if (image.Width > 60)
                {
                    float percentage = 0.0f;
                    percentage = 60 / image.Width;
                    image.ScalePercent(percentage * 100);
                }
                imageHeight = image.ScaledHeight;
                float imageY = 800 - imageHeight;
                image.SetAbsolutePosition(520, imageY);
                cb.AddImage(image, inlineImage: true);
            }
            catch (Exception)
            {
                imageHeight = 0;
            }
            #endregion

            #region Draw Top
            float row1Y = 800;
            table_detail1.WriteSelectedRows(0, -1, 10, row1Y, cb);
            #endregion

            bool isDollar = viewModel.Rate.Id != 0;

            #region Detail 2.1 (Bottom, Column 1.1)
            PdfPTable table_bottom_column1_1 = new PdfPTable(2);
            table_bottom_column1_1.TotalWidth = 180f;

            float[] table_bottom_column1_1_widths = new float[] { 1f, 2f };
            table_bottom_column1_1.SetWidths(table_bottom_column1_1_widths);

            PdfPCell cell_bottom_column1_1 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };

            cell_bottom_column1_1.Phrase = new Phrase("QTY", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Quantity} {viewModel.UOM.unit}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("DESCRIPTION", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.CommodityDescription}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("CONT/STYLE", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Article}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("BUYER", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Buyer.name}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("DELIVERY", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.DeliveryDate.AddHours(timeoffset).ToString("dd/MM/yyyy")}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            #endregion

            #region Detail 2_2 (Bottom, Column 1.2)
            PdfPTable table_bottom_column1_2 = new PdfPTable(2);
            table_bottom_column1_2.TotalWidth = 180f;

            float[] table_bottom_column1_2_widths = new float[] { 1f, 1f };
            table_bottom_column1_2.SetWidths(table_bottom_column1_2_widths);

            PdfPCell cell_bottom_column1_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3
            };

            cell_bottom_column1_2.Phrase = new Phrase("FOB PRICE", bold_font);
            table_bottom_column1_2.AddCell(cell_bottom_column1_2);
            cell_bottom_column1_2.Phrase = new Phrase("CMT PRICE", bold_font);
            table_bottom_column1_2.AddCell(cell_bottom_column1_2);

            double CM_Price = 0;
            foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials)
            {
                CM_Price += item.CM_Price ?? 0;
            }
            double ConfirmPrice = viewModel.ConfirmPrice ?? 0;
            double CMT          = CM_Price > 0 ? ConfirmPrice : 0;
            string CMT_Price    = this.GetCurrencyValue(CMT, isDollar);
            double FOB          = ConfirmPrice + CM_Price;
            string FOB_Price    = this.GetCurrencyValue(FOB, isDollar);
            cell_bottom_column1_2.Phrase = new Phrase($"{FOB_Price}", normal_font);
            table_bottom_column1_2.AddCell(cell_bottom_column1_2);
            cell_bottom_column1_2.Phrase = new Phrase($"{CMT_Price}", normal_font);
            table_bottom_column1_2.AddCell(cell_bottom_column1_2);
            #endregion

            #region Detail 2.3 (Bottom, Column 1.3)
            PdfPTable table_bottom_column1_3 = new PdfPTable(2);
            table_bottom_column1_3.TotalWidth = 180f;

            float[] table_bottom_column1_3_widths = new float[] { 1f, 1f };
            table_bottom_column1_3.SetWidths(table_bottom_column1_3_widths);

            PdfPCell cell_bottom_column1_3 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3
            };

            cell_bottom_column1_3.Phrase = new Phrase("CNF PRICE", bold_font);
            table_bottom_column1_3.AddCell(cell_bottom_column1_3);
            cell_bottom_column1_3.Phrase = new Phrase("CIF PRICE", bold_font);
            table_bottom_column1_3.AddCell(cell_bottom_column1_3);

            string CNF_Price = this.GetCurrencyValue(0, isDollar);
            cell_bottom_column1_3.Phrase = new Phrase($"{CNF_Price}", normal_font);
            table_bottom_column1_3.AddCell(cell_bottom_column1_3);
            string CIF_Price = this.GetCurrencyValue(0, isDollar);
            cell_bottom_column1_3.Phrase = new Phrase($"{CIF_Price}", normal_font);
            table_bottom_column1_3.AddCell(cell_bottom_column1_3);
            #endregion

            #region Detail 3.1 (Bottom, Column 2.1)
            PdfPTable table_bottom_column2_1 = new PdfPTable(3);
            table_bottom_column2_1.TotalWidth = 190f;

            float[] table_bottom_column2_1_widths = new float[] { 1.5f, 1f, 1.5f };
            table_bottom_column2_1.SetWidths(table_bottom_column2_1_widths);

            PdfPCell cell_bottom_column2_1 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3
            };

            PdfPCell cell_bottom_column2_1_colspan2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3, Colspan = 2
            };

            cell_bottom_column2_1.Phrase = new Phrase("TOTAL", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double total = 0;
            foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials)
            {
                total += item.Total;
            }
            total += viewModel.ProductionCost;
            cell_bottom_column2_1_colspan2.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(total), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2);

            cell_bottom_column2_1.Phrase = new Phrase("OTL 1", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double OTL1CalculatedValue = viewModel.OTL1.CalculatedValue ?? 0;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(OTL1CalculatedValue)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double afterOTL1 = total + OTL1CalculatedValue;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterOTL1)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("OTL 2", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double OTL2CalculatedValue = viewModel.OTL2.CalculatedValue ?? 0;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(OTL2CalculatedValue)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double afterOTL2 = afterOTL1 + OTL2CalculatedValue;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterOTL2)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("RISK", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.Risk), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double afterRisk = (100 + viewModel.Risk) * afterOTL2 / 100;;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterRisk)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("BEA ANGKUT", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.FreightCost)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double afterFreightCost = afterRisk + viewModel.FreightCost;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterFreightCost)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("SUB TOTAL", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterFreightCost)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2);

            cell_bottom_column2_1.Phrase = new Phrase("NET/FOB (%)", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.NETFOBP), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.NETFOB)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("COMM (%)", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.CommissionPortion), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.CommissionRate)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("CONFIRM PRICE", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);;
            double confirmPrice         = viewModel.ConfirmPrice ?? 0 + viewModel.Rate.Value ?? 0;
            double confirmPriceWithRate = isDollar ? confirmPrice * viewModel.Rate.Value ?? 1 : confirmPrice;
            cell_bottom_column2_1_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(confirmPriceWithRate)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2);
            #endregion

            #region Detail 3.2 (Bottom, Column 2.2)
            PdfPTable table_bottom_column2_2 = new PdfPTable(4);
            table_bottom_column2_2.TotalWidth = 190f;

            float[] table_bottom_column2_2_widths = new float[] { 1f, 1.25f, 1f, 1.25f };
            table_bottom_column2_2.SetWidths(table_bottom_column2_2_widths);
            PdfPCell cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2
            };

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2
            };
            cell_bottom_column2_2.Phrase = new Phrase("FREIGHT", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2
            };
            string freight = this.GetCurrencyValue(viewModel.Freight ?? 0, isDollar);
            cell_bottom_column2_2.Phrase = new Phrase($"= {freight}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2
            };
            cell_bottom_column2_2.Phrase = new Phrase("INSURANCE", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2
            };
            string insurance = this.GetCurrencyValue(viewModel.Insurance ?? 0, isDollar);
            cell_bottom_column2_2.Phrase = new Phrase($"= {insurance}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2
            };
            cell_bottom_column2_2.Phrase = new Phrase("CONFIRM PRICE", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2
            };
            string confirmPriceFOB = this.GetCurrencyValue(viewModel.ConfirmPrice ?? 0, isDollar);
            cell_bottom_column2_2.Phrase = new Phrase($"= {confirmPriceFOB}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase("SMV CUT", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Cutting}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase("SMV SEW", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Sewing}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase("SMV FIN", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Finishing}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase("SMV TOT", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Total}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            #endregion

            #region Detail 4 (Bottom, Column 3.1)
            PdfPTable table_bottom_column3_1 = new PdfPTable(2);
            table_bottom_column3_1.TotalWidth = 180f;

            float[] table_bottom_column3_1_widths = new float[] { 1f, 2f };
            table_bottom_column3_1.SetWidths(table_bottom_column3_1_widths);

            PdfPCell cell_bottom_column3_1 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };

            cell_bottom_column3_1.Phrase = new Phrase("DESCRIPTION", normal_font);
            table_bottom_column3_1.AddCell(cell_bottom_column3_1);
            cell_bottom_column3_1.Phrase = new Phrase($"{viewModel.Description}", normal_font);
            table_bottom_column3_1.AddCell(cell_bottom_column3_1);
            #endregion

            #region Signature
            PdfPTable table_signature = new PdfPTable(3);
            table_signature.TotalWidth = 570f;

            float[] signature_widths = new float[] { 1f, 1f, 1f };
            table_signature.SetWidths(signature_widths);

            PdfPCell cell_signature = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };

            //cell_signature.Phrase = new Phrase("", normal_font);
            //table_signature.AddCell(cell_signature);
            //cell_signature.Phrase = new Phrase("", normal_font);
            //table_signature.AddCell(cell_signature);

            string signatureArea = string.Empty;
            for (int i = 0; i < 5; i++)
            {
                signatureArea += Environment.NewLine;
            }
            cell_signature.Phrase = new Phrase(signatureArea, normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase(signatureArea, normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase(signatureArea, normal_font);
            table_signature.AddCell(cell_signature);

            cell_signature.Phrase = new Phrase("Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Kasie. Kabag. Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Kadiv. Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            #endregion

            #region Cost Calculation Material
            PdfPTable table_ccm = new PdfPTable(7);
            table_ccm.TotalWidth = 570f;

            float[] ccm_widths = new float[] { 1.25f, 3.5f, 3.5f, 5f, 3f, 4f, 4f };
            table_ccm.SetWidths(ccm_widths);

            PdfPCell cell_ccm_center = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };
            PdfPCell cell_ccm_left = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };
            PdfPCell cell_ccm_right = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };

            cell_ccm_center.Phrase = new Phrase("NO", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("KATEGORI", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("KODE PRODUK", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("DESKRIPSI", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("QUANTITY", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("USD. PTC/PC", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("USD. TOTAL", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            double  Total              = 0;
            float   row1Height         = imageHeight > table_detail1.TotalHeight ? imageHeight : table_detail1.TotalHeight;
            float   row2Y              = row1Y - row1Height - 10;
            float[] row3Heights        = { table_bottom_column1_1.TotalHeight + 10 + table_bottom_column1_2.TotalHeight + 10 + table_bottom_column1_3.TotalHeight, table_bottom_column2_1.TotalHeight + 10 + table_bottom_column2_2.TotalHeight, table_bottom_column3_1.TotalHeight };
            float   dollarDetailHeight = 10;
            if (isDollar)
            {
                row3Heights[1] += dollarDetailHeight;
            }
            float row3Height = row3Heights.Max();
            float secondHighestRow3Height = row3Heights[1] > row3Heights[2] ? row3Heights[1] : row3Heights[2];
            bool  signatureInsideRow3     = row3Heights.Max() == row3Heights[0] && row3Heights[0] - 10 - secondHighestRow3Height > table_signature.TotalHeight;
            float row2RemainingHeight     = row2Y - 10 - row3Height - printedOnHeight - margin;
            float row2AllowedHeight       = row2Y - printedOnHeight - margin;

            for (int i = 0; i < viewModel.CostCalculationGarment_Materials.Count; i++)
            {
                //NO
                cell_ccm_center.Phrase = new Phrase((i + 1).ToString(), normal_font);
                table_ccm.AddCell(cell_ccm_center);

                //KATEGORI
                cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Category.name, normal_font);
                table_ccm.AddCell(cell_ccm_left);

                //KODE PRODUK
                cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Product.code, normal_font);
                table_ccm.AddCell(cell_ccm_left);

                //DESKRIPSI
                cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Description, normal_font);
                table_ccm.AddCell(cell_ccm_left);

                cell_ccm_right.Phrase = new Phrase(String.Format("{0} {1}", viewModel.CostCalculationGarment_Materials[i].Quantity, viewModel.CostCalculationGarment_Materials[i].UOMQuantity.unit), normal_font);
                table_ccm.AddCell(cell_ccm_right);

                cell_ccm_right.Phrase = new Phrase(String.Format("{0}/{1}", Number.ToRupiahWithoutSymbol(viewModel.CostCalculationGarment_Materials[i].Price), viewModel.CostCalculationGarment_Materials[i].UOMPrice.unit), normal_font);
                table_ccm.AddCell(cell_ccm_right);

                cell_ccm_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.CostCalculationGarment_Materials[i].Total), normal_font);
                table_ccm.AddCell(cell_ccm_right);

                Total += viewModel.CostCalculationGarment_Materials[i].Total;
                float currentHeight = table_ccm.TotalHeight;
                if (currentHeight / row2RemainingHeight > 1)
                {
                    if (currentHeight / row2AllowedHeight > 1)
                    {
                        PdfPRow headerRow = table_ccm.GetRow(0);
                        PdfPRow lastRow   = table_ccm.GetRow(table_ccm.Rows.Count - 1);
                        table_ccm.DeleteLastRow();
                        table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb);
                        table_ccm.DeleteBodyRows();
                        this.DrawPrintedOn(now, bf, cb);
                        document.NewPage();
                        table_ccm.Rows.Add(headerRow);
                        table_ccm.Rows.Add(lastRow);
                        table_ccm.CalculateHeights();
                        row2Y = startY;
                        row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin;
                        row2AllowedHeight   = row2Y - printedOnHeight - margin;
                    }
                }
            }

            cell_ccm_right = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2, Colspan = 6
            };
            cell_ccm_right.Phrase = new Phrase("TOTAL", bold_font_8);
            table_ccm.AddCell(cell_ccm_right);

            cell_ccm_right = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };
            cell_ccm_right.Phrase = new Phrase(Number.ToRupiah(Total), bold_font_8);
            table_ccm.AddCell(cell_ccm_right);
            #endregion

            #region Draw Middle and Bottom
            table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb);

            float row3Y = row2Y - table_ccm.TotalHeight - 10;
            float row3RemainingHeight = row3Y - printedOnHeight - margin;
            if (row3RemainingHeight < row3Height)
            {
                this.DrawPrintedOn(now, bf, cb);
                row3Y = startY;
                document.NewPage();
            }

            table_bottom_column1_1.WriteSelectedRows(0, -1, 10, row3Y, cb);

            float detail1_2Y = row3Y - table_bottom_column1_1.TotalHeight - 10;
            table_bottom_column1_2.WriteSelectedRows(0, -1, 10, detail1_2Y, cb);

            float detail1_3Y = detail1_2Y - table_bottom_column1_2.TotalHeight - 10;
            table_bottom_column1_3.WriteSelectedRows(0, -1, 10, detail1_3Y, cb);

            table_bottom_column2_1.WriteSelectedRows(0, -1, 200, row3Y, cb);

            float noteY = row3Y - table_bottom_column2_1.TotalHeight;
            float table_bottom_column2_2Y;
            if (isDollar)
            {
                noteY = noteY - 15;
                table_bottom_column2_2Y = noteY - 5;
                cb.BeginText();
                cb.SetFontAndSize(bf, 7);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, $"NOTE: 1 US$ = {Number.ToRupiah(viewModel.Rate.Value)}", 200, noteY, 0);
                cb.EndText();
            }
            else
            {
                table_bottom_column2_2Y = noteY - 10;
            }
            table_bottom_column2_2.WriteSelectedRows(0, -1, 200, table_bottom_column2_2Y, cb);

            //table_bottom_column1_2.WriteSelectedRows(0, -1, 400, row3Y, cb);
            table_bottom_column3_1.WriteSelectedRows(0, -1, 400, row3Y, cb);

            float table_signatureX;
            float table_signatureY;
            if (signatureInsideRow3)
            {
                table_signatureX           = margin + table_bottom_column2_2.TotalWidth + 10;
                table_signatureY           = row3Y - row3Height + table_signature.TotalHeight;
                table_signature.TotalWidth = 390f;
            }
            else
            {
                table_signatureX = margin;
                table_signatureY = row3Y - row3Height - 10;
                float signatureRemainingHeight = table_signatureY - printedOnHeight - margin;
                if (signatureRemainingHeight < table_signature.TotalHeight)
                {
                    this.DrawPrintedOn(now, bf, cb);
                    table_signatureY = startY;
                    document.NewPage();
                }
            }
            table_signature.WriteSelectedRows(0, -1, table_signatureX, table_signatureY, cb);

            this.DrawPrintedOn(now, bf, cb);
            #endregion

            document.Close();

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

            return(stream);
        }
        public void GeneratePdfTemplate_Return_Success()
        {
            string imagelogo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAABVlBMVEX///8AVJsAVpwAR5UAUpoYSJsATZgAS5cQXa0ASZYAU5sARJQAUJkWTqAeNYoPYLAOZ7YTVaYbPZEYRJcfMIYWTJ4UVKYNarkcO5AKcb8AN44eM4kSWqsOZLQANI0AQpPs8vcAO5AIdsPC0eIhKoDq8PbX4u0He8gDiNOmu9TQ3OkATaWpvtZchbWctNAAQJgAL48+caq4yd2PqsoAUqsAAHUhYqJUf7Fqj7p5msAAW7Iza6d/nsNHd60AJ4cANJMAEHwAG3+HlsCPsdhwntAAF3/Iy92lsM+So8m7wtlwdaclH3cKIH94ksK1uNFMWZs/gsQ3XaVTca9Ac7Vrg7dYaKR3fKydosNDZKgAKJRuZ5kAAGOMh6w3M4AbEHGrqMNOVZY2Qo5bkMl6qtivzelEldOZvuJanNQAftEsl9rW6feAvOhGebpfrOI/m9m/2vBVUI2YlLYo0RhJAAAgAElEQVR4nNV9+1/iyLYvSSCIBBVB1IghCEk3QQgP5SHIw25EbbRbW1vv7Nl7+nVm7zvHe+f0///LrXdCiCgP7b7rs/dIk5DUt9azVlWt8niem1Q9tVuu1w4bFa+IyC+KEl85zNXLmZKuPvv7n5PUVL7W8CdlOSnwjWqtXi7nM5Dy+XKzlitW8KVKrpzSfnZTpyAjn+OTcpI7rOdTDzIKsDfTrFYSclI6LKceuusXJKPZEOREpZYx1Cfdr+qlOvpFvfS0H/xUUjNV0Nbi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+dgZTLftlp6PQ81VJAChhqwNCgG/UmvndVErXNVVTVRVuNk2V8s1akfcLAb+0CO8T/IdlB9ONXDLx0+RziDIVmRuJavR8rgKaLQGc/KIkiX4AVYBE/uv3i4BvHM8BXgcqVSc6jwqeKjmKs/5EAg5aPhz1+KqRqR8iPokShoOJBx+8kigGAgG+CARZdX3gXEOI2UnN83Kw5hpUAV3bLddzxQrPQ1giYCtfKVZr5cwDOmrUJTnQ/Nnq50J6U1QSuZI621NSdb+ScO+qX4GMOi/LjRGdeirp+cOkItZ+LekcIdDKhBwsliddtm7kqwE52ZghIHpJSjUbgpys5PKpp9h6YI9qlYScqNRmlfAXJdXIw2bLQiXXBBbFDSmyQLWGmJSTXHVinv8apBq7zSovJGVZTop8o1jN5Wq1Wi5XPWxUpAT8NrhYrGf+/wRnJ8CsUqbcrOUOi41GpdIoHlZr9TKIclxZO2/6f2sdG2l/6JCoAAAAAElFTkSuQmCC";
            CostCalculationGarmentPdfTemplate pdf       = new CostCalculationGarmentPdfTemplate();
            CostCalculationGarmentViewModel   viewModel = new CostCalculationGarmentViewModel()
            {
                AccessoriesAllowance = 1,
                ApprovalIE           = new Approval()
                {
                    ApprovedBy   = "fetih",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                ApprovalKadivMD = new Approval()
                {
                    ApprovedBy   = "fetih",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                ApprovalMD = new Approval()
                {
                    ApprovedBy   = "fetih",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                ApprovalPPIC = new Approval()
                {
                    ApprovedBy   = "fetih",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                ApprovalPurchasing = new Approval()
                {
                    ApprovedBy   = "fetih",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                Article             = "Article",
                Active              = true,
                AutoIncrementNumber = 1,
                Buyer = new BuyerViewModel()
                {
                    address1  = "address1",
                    address2  = "address2",
                    Code      = "Code",
                    email     = "*****@*****.**",
                    IsDeleted = false,
                    Name      = "Name",
                    UId       = "Uid"
                },
                BuyerBrand = new BuyerBrandViewModel()
                {
                    Active = true,
                    Code   = "Code",
                    Name   = "name",
                    UId    = "Uid",
                },
                Code = "Code",
                CommissionPortion    = 1,
                CommissionRate       = 1,
                CommodityDescription = "CommodityDescription",
                Comodity             = new MasterPlanComodityViewModel()
                {
                    Code = "Code",
                    Name = "Name",
                    UId  = "UId",
                },
                ConfirmDate  = DateTimeOffset.Now,
                ConfirmPrice = 1,
                CostCalculationGarment_Materials = new List <CostCalculationGarment_MaterialViewModel>()
                {
                    new CostCalculationGarment_MaterialViewModel()
                    {
                        Category = new CategoryViewModel()
                        {
                            name = "FABRIC",
                            code = "code",
                            UId  = "Uid"
                        },
                        CM_Price            = 1,
                        AutoIncrementNumber = 1,
                        AvailableQuantity   = 1,
                        Active          = true,
                        BudgetQuantity  = 1,
                        Code            = "Code",
                        Conversion      = 1,
                        Description     = "Description",
                        IsDeleted       = true,
                        isFabricCM      = true,
                        IsPosted        = true,
                        IsPRMaster      = true,
                        Information     = "Information",
                        MaterialIndex   = 1,
                        PO              = "PO",
                        POMaster        = "POMaster",
                        PO_SerialNumber = "PO_SerialNumber",
                        Price           = 1,
                        PRMasterId      = 1,
                        PRMasterItemId  = 1,
                        Product         = new GarmentProductViewModel()
                        {
                            Code        = "Code",
                            Composition = "Composition",
                            Const       = "Const",
                            Name        = "Name",
                            UId         = "Uid"
                        },
                        ProductRemark      = "ProductRemark",
                        ShippingFeePortion = 1,
                        Quantity           = 1,
                        Total            = 1,
                        UId              = "Uid",
                        TotalShippingFee = 1,
                        UOMPrice         = new UOMViewModel()
                        {
                            code = "code",
                            Unit = "Unit",
                            UId  = "Uid"
                        },
                        UOMQuantity = new UOMViewModel()
                        {
                            code = "code",
                            Unit = "Unit",
                            UId  = "Uid"
                        },
                        CreatedBy = "Fetih han"
                    },
                },
                DeliveryDate = DateTimeOffset.Now,
                Description  = "Description",
                Efficiency   = new EfficiencyViewModel()
                {
                    Code         = "code",
                    FinalRange   = 1,
                    InitialRange = 1,
                    IsDeleted    = true,
                    UId          = "Uid",
                    Name         = "Name",
                    Value        = 1
                },
                FabricAllowance     = 1,
                Freight             = 1,
                FreightCost         = 1,
                ImageFile           = imagelogo,
                ImagePath           = "",
                Index               = 1,
                Insurance           = 1,
                IsPosted            = true,
                IsROAccepted        = true,
                IsROAvailable       = true,
                IsRODistributed     = true,
                IsValidatedROMD     = true,
                IsValidatedROPPIC   = true,
                IsValidatedROSample = true,
                IsDeleted           = false,
                CreatedAgent        = "CreatedAgent",
                LeadTime            = 1,
                SMV_Cutting         = 1,
                SCGarmentId         = 1,
                Section             = "Section",
                SectionName         = "SectionName",
                SizeRange           = "SizeRange",
                ROAcceptedBy        = "ROAcceptedBy",
                Rate = new RateViewModel()
                {
                    CreatedAgent = "CreatedAgent",
                    Code         = "code"
                },
                NETFOB  = 1,
                NETFOBP = 1,
                PreSCNo = "PreSCNo",
                OTL1    = new RateCalculatedViewModel()
                {
                    Code            = "Code",
                    CalculatedValue = 1,
                    Name            = "Name",
                    Unit            = new UnitViewModel()
                    {
                        Name = "Name",
                        Code = "Code",
                        UId  = "Uid"
                    }
                },
                OTL2 = new RateCalculatedViewModel()
                {
                    Code            = "Code",
                    CalculatedValue = 1,
                    Name            = "Name",
                    Unit            = new UnitViewModel()
                    {
                        Name = "Name",
                        Code = "Code",
                        UId  = "Uid"
                    }
                },
                PreSCId              = 1,
                ProductionCost       = 1,
                ValidationPPICBy     = "fetih han",
                ValidationMDBy       = "fetih han",
                ValidationMDDate     = DateTimeOffset.Now,
                ValidationPPICDate   = DateTimeOffset.Now,
                ValidationSampleBy   = "fetih han",
                ValidationSampleDate = DateTimeOffset.Now,
                Quantity             = 1,
                Risk               = 1,
                ROAcceptedDate     = DateTimeOffset.Now,
                ROAvailableBy      = "fetih han",
                ROAvailableDate    = DateTimeOffset.Now,
                RODistributionBy   = "fetih han",
                RODistributionDate = DateTimeOffset.Now,
                RO_GarmentId       = 1,
                RO_Number          = "RO_Number",
                RO_RetailId        = 1,
                THR = new RateViewModel()
                {
                    Id   = 1,
                    Unit = new UnitViewModel()
                    {
                        Id   = 1,
                        Code = "Code",
                        Name = "Name"
                    },
                    UId   = "Uid",
                    Name  = "Name",
                    Value = 1,
                },
                Wage = new RateViewModel()
                {
                    Id   = 1,
                    Unit = new UnitViewModel()
                    {
                        Id   = 1,
                        Code = "Code",
                        Name = "Name"
                    },
                    UId   = "Uid",
                    Name  = "Name",
                    Value = 1,
                },
                CreatedBy     = "fetih han",
                SMV_Finishing = 1,
                SMV_Sewing    = 1,
                SMV_Total     = 1,
                Unit          = new UnitViewModel()
                {
                    Id   = 1,
                    Code = "Code",
                    Name = "Name"
                },
                UId      = "UId",
                UnitName = "UnitName",
                UOM      = new UOMViewModel()
                {
                    Unit = "Unit"
                },
            };
            var result = pdf.GeneratePdfTemplate(viewModel, 2);

            Assert.NotNull(result);
            Assert.IsType <MemoryStream>(result);
        }
        public MemoryStream GeneratePdfTemplate(CostCalculationGarmentViewModel viewModel, int timeoffset)
        {
            BaseFont bf          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            BaseFont bf_bold     = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            Font     normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 6);
            Font     bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 6);
            Font     bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            DateTime now         = DateTime.Now;

            Document     document = new Document(PageSize.A4, 10, 10, 10, 10);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            writer.CloseStream = false;
            document.Open();
            PdfContentByte cb = writer.DirectContent;

            float margin          = 10;
            float printedOnHeight = 10;
            float startY          = 840 - margin;

            #region Header
            cb.BeginText();
            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. DAN LIRIS", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "COST CALCULATION EXPORT GARMENT" + (viewModel.IsPosted ? "" : " (DRAFT)"), 10, 805, 0);
            cb.EndText();
            #endregion

            #region Detail 1 (Top)
            PdfPTable table_detail1 = new PdfPTable(9);
            table_detail1.TotalWidth = 500f;

            float[] detail1_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1f, 0.1f, 2f };
            table_detail1.SetWidths(detail1_widths);

            PdfPCell cell_detail1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2
            };
            PdfPCell cell_colon = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE
            };
            cell_colon.Phrase = new Phrase(":", normal_font);

            cell_detail1.Phrase = new Phrase("NO. RO", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.RO_Number}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("NO. PRE SC", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.PreSCNo}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("LEAD TIME", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.LeadTime} hari", normal_font);
            table_detail1.AddCell(cell_detail1);

            cell_detail1.Phrase = new Phrase("ARTICLE", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Article}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("SECTION", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Section}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("FABRIC", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.FabricAllowance}%", normal_font);
            table_detail1.AddCell(cell_detail1);

            cell_detail1.Phrase = new Phrase("DATE", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.CreatedUtc.ToString("dd MMMM yyyy")}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("COMMODITY", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Comodity.Name}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("ACC", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.AccessoriesAllowance}%", normal_font);
            table_detail1.AddCell(cell_detail1);

            cell_detail1.Phrase = new Phrase("KONVEKSI", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Unit.Code}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("SIZE RANGE", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.SizeRange}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_detail1);
            #endregion

            #region Image
            float imageHeight;
            try
            {
                byte[] imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.ImageFile));
                Image  image     = Image.GetInstance(imgb: imageByte);
                if (image.Width > 60)
                {
                    float percentage = 0.0f;
                    percentage = 60 / image.Width;
                    image.ScalePercent(percentage * 100);
                }
                imageHeight = image.ScaledHeight;
                float imageY = 800 - imageHeight;
                image.SetAbsolutePosition(520, imageY);
                cb.AddImage(image, inlineImage: true);
            }
            catch (Exception)
            {
                imageHeight = 0;
            }
            #endregion

            #region Draw Top
            float row1Y = 800;
            table_detail1.WriteSelectedRows(0, -1, 10, row1Y, cb);
            #endregion

            bool isDollar = viewModel.Rate.Id != 0;

            #region Detail 2.1 (Bottom, Column 1.1)
            string        fabric = "";
            List <string> remark = new List <string>();
            for (int i = 0; i < viewModel.CostCalculationGarment_Materials.Count; i++)
            {
                if (viewModel.CostCalculationGarment_Materials[i].Category.name == "FABRIC")
                {
                    remark.Add(viewModel.CostCalculationGarment_Materials[i].Product.Composition + " " + viewModel.CostCalculationGarment_Materials[i].Product.Const + " " + viewModel.CostCalculationGarment_Materials[i].Product.Yarn + " " + viewModel.CostCalculationGarment_Materials[i].Product.Width);
                }
            }
            if (remark.Count == 0)
            {
                fabric = viewModel.Description;
            }
            else
            {
                foreach (var data in remark)
                {
                    fabric += "FABRIC \n" + data + "\n\n";
                }
                fabric += viewModel.Description + "\n";
            }
            PdfPTable table_bottom_column1_1 = new PdfPTable(2);
            table_bottom_column1_1.TotalWidth = 180f;

            float[] table_bottom_column1_1_widths = new float[] { 1f, 2f };
            table_bottom_column1_1.SetWidths(table_bottom_column1_1_widths);

            PdfPCell cell_bottom_column1_1 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 4, PaddingLeft = 2, PaddingTop = 4
            };

            cell_bottom_column1_1.Phrase = new Phrase("QTY", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Quantity} {viewModel.UOM.Unit}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("DESCRIPTION", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.CommodityDescription}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("CONT/STYLE", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Article}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("BUYER AGENT", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Buyer.Code}" + " - " + $"{viewModel.Buyer.Name}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("BUYER BRAND", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.BuyerBrand.Code}" + " - " + $"{viewModel.BuyerBrand.Name}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

            cell_bottom_column1_1.Phrase = new Phrase("DELIVERY", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.DeliveryDate.AddHours(timeoffset).ToString("dd/MM/yyyy")}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            #endregion

            #region Detail 2_2 (Bottom, Column 1.2)
            PdfPTable table_bottom_column1_2 = new PdfPTable(2);
            table_bottom_column1_2.TotalWidth = 180f;

            float[] table_bottom_column1_2_widths = new float[] { 1f, 1f };
            table_bottom_column1_2.SetWidths(table_bottom_column1_2_widths);

            PdfPCell cell_bottom_column1_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3
            };

            cell_bottom_column1_2.Phrase = new Phrase("FOB PRICE", bold_font);
            table_bottom_column1_2.AddCell(cell_bottom_column1_2);
            cell_bottom_column1_2.Phrase = new Phrase("CMT PRICE", bold_font);
            table_bottom_column1_2.AddCell(cell_bottom_column1_2);

            double CM_Price = 0;
            foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials)
            {
                CM_Price += item.CM_Price ?? 0;
            }
            double ConfirmPrice = viewModel.ConfirmPrice ?? 0;
            double CMT          = CM_Price > 0 ? ConfirmPrice : 0;
            string CMT_Price    = this.GetCurrencyValue(CMT, isDollar);
            double FOB          = ConfirmPrice;
            double FOB_Remark   = 0;
            if (CMT > 0)
            {
                FOB = 0;
                var    b = Convert.ToDouble(viewModel.Rate.Value);
                double a = (1.05 * CM_Price / Convert.ToDouble(viewModel.Rate.Value)) - (viewModel.Insurance.GetValueOrDefault() + viewModel.Freight.GetValueOrDefault());
                FOB_Remark = ConfirmPrice + a;
            }
            string FOB_Price = this.GetCurrencyValue(FOB, isDollar);
            cell_bottom_column1_2.Phrase = new Phrase($"{FOB_Price}", normal_font);
            table_bottom_column1_2.AddCell(cell_bottom_column1_2);
            cell_bottom_column1_2.Phrase = new Phrase($"{CMT_Price}", normal_font);
            table_bottom_column1_2.AddCell(cell_bottom_column1_2);
            #endregion

            #region Detail 2.3 (Bottom, Column 1.3)
            PdfPTable table_bottom_column1_3 = new PdfPTable(2);
            table_bottom_column1_3.TotalWidth = 180f;

            float[] table_bottom_column1_3_widths = new float[] { 1f, 1f };
            table_bottom_column1_3.SetWidths(table_bottom_column1_3_widths);

            PdfPCell cell_bottom_column1_3 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3
            };

            cell_bottom_column1_3.Phrase = new Phrase("CNF PRICE", bold_font);
            table_bottom_column1_3.AddCell(cell_bottom_column1_3);
            cell_bottom_column1_3.Phrase = new Phrase("CIF PRICE", bold_font);
            table_bottom_column1_3.AddCell(cell_bottom_column1_3);

            string CNF_Price = this.GetCurrencyValue(Convert.ToDouble(viewModel.Freight + viewModel.ConfirmPrice), isDollar);
            if (viewModel.Freight == 0)
            {
                CNF_Price = "$";
            }
            cell_bottom_column1_3.Phrase = new Phrase($"{CNF_Price}", normal_font);
            table_bottom_column1_3.AddCell(cell_bottom_column1_3);
            string CIF_Price = this.GetCurrencyValue(Convert.ToDouble(viewModel.Insurance + viewModel.ConfirmPrice), isDollar);
            if (viewModel.Insurance == 0)
            {
                CIF_Price = "$";
            }
            cell_bottom_column1_3.Phrase = new Phrase($"{CIF_Price}", normal_font);
            table_bottom_column1_3.AddCell(cell_bottom_column1_3);
            #endregion

            #region Detail 3.1 (Bottom, Column 2.1)
            PdfPTable table_bottom_column2_1 = new PdfPTable(3);
            table_bottom_column2_1.TotalWidth = 190f;

            float[] table_bottom_column2_1_widths = new float[] { 1.5f, 1f, 1.5f };
            table_bottom_column2_1.SetWidths(table_bottom_column2_1_widths);

            PdfPCell cell_bottom_column2_1 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3
            };

            PdfPCell cell_bottom_column2_1_colspan2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3, Colspan = 3
            };

            cell_bottom_column2_1.Phrase = new Phrase("TOTAL", normal_font);

            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double total = 0;
            foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials)
            {
                total += item.Total;
            }
            //total += viewModel.ProductionCost;
            cell_bottom_column2_1_colspan2.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(total), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2);

            cell_bottom_column2_1.Phrase = new Phrase("OTL 1", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double OTL1CalculatedValue = viewModel.OTL1.CalculatedValue ?? 0;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(OTL1CalculatedValue)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double afterOTL1 = total + OTL1CalculatedValue;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterOTL1)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("OTL 2", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double OTL2CalculatedValue = viewModel.OTL2.CalculatedValue ?? 0;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(OTL2CalculatedValue)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double afterOTL2 = afterOTL1 + OTL2CalculatedValue;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterOTL2)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("RISK", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.Risk), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double afterRisk = (100 + viewModel.Risk) * afterOTL2 / 100;;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterRisk)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("BEA ANGKUT", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.FreightCost)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            double afterFreightCost = afterRisk + viewModel.FreightCost;
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterFreightCost)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("SUB TOTAL", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterFreightCost)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2);

            cell_bottom_column2_1.Phrase = new Phrase("NET/FOB (%)", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.NETFOBP), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.NETFOB)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("COMM (%)", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.CommissionPortion), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);
            cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.CommissionRate)}", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);

            cell_bottom_column2_1.Phrase = new Phrase("CONFIRM PRICE", normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1);;
            double confirmPrice         = viewModel.ConfirmPrice ?? 0 + viewModel.Rate.Value ?? 0;
            double confirmPriceWithRate = isDollar ? confirmPrice * viewModel.Rate.Value ?? 1 : confirmPrice;
            cell_bottom_column2_1_colspan2.Phrase = new Phrase(string.Format("{0:n4}", confirmPriceWithRate), normal_font);
            table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2);
            #endregion

            #region Detail 3.2 (Bottom, Column 2.2)
            PdfPTable table_bottom_column2_2 = new PdfPTable(4);
            table_bottom_column2_2.TotalWidth = 180f;

            float[] table_bottom_column2_2_widths = new float[] { 1f, 1.25f, 1f, 1.25f };
            table_bottom_column2_2.SetWidths(table_bottom_column2_2_widths);
            PdfPCell cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 2, PaddingBottom = 4, PaddingLeft = 2, Colspan = 2
            };

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 2, PaddingLeft = 2, Colspan = 2
            };
            cell_bottom_column2_2.Phrase = new Phrase("FREIGHT", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 2, PaddingLeft = 2, Colspan = 2
            };
            string freight = this.GetCurrencyValue(viewModel.Freight ?? 0, isDollar);
            cell_bottom_column2_2.Phrase = new Phrase($"= {freight}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 2, PaddingBottom = 4, PaddingLeft = 2, Colspan = 2
            };
            cell_bottom_column2_2.Phrase = new Phrase("INSURANCE", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 2, PaddingBottom = 4, PaddingLeft = 2, Colspan = 2
            };
            string insurance = this.GetCurrencyValue(viewModel.Insurance ?? 0, isDollar);
            cell_bottom_column2_2.Phrase = new Phrase($"= {insurance}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3, Colspan = 2
            };
            cell_bottom_column2_2.Phrase = new Phrase("CONFIRM PRICE", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3, Colspan = 2
            };
            string confirmPriceFOB = this.GetCurrencyValue(viewModel.ConfirmPrice ?? 0, isDollar);
            cell_bottom_column2_2.Phrase = new Phrase($"= {confirmPriceFOB}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase("SMV CUT", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Cutting}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase("SMV SEW", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Sewing}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase("SMV FIN", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Finishing}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase("SMV TOT", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 4, PaddingRight = 3, PaddingBottom = 4, PaddingLeft = 3
            };
            cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Total}", normal_font);
            table_bottom_column2_2.AddCell(cell_bottom_column2_2);
            #endregion

            #region Detail 4 (Bottom, Column 3.1)
            PdfPTable table_bottom_column3_1 = new PdfPTable(2);
            table_bottom_column3_1.TotalWidth = 180f;

            float[] table_bottom_column3_1_widths = new float[] { 1f, 2f };
            table_bottom_column3_1.SetWidths(table_bottom_column3_1_widths);

            PdfPCell cell_bottom_column3_1 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };



            var DESC = (viewModel.CostCalculationGarment_Materials.Any(m => m.isFabricCM) ? "FOB PRICE : $ " + Number.ToRupiahWithoutSymbol(FOB_Remark) + "\n\n" : string.Empty) + fabric;
            //         cell_bottom_column3_1.Phrase = new Phrase("DESCRIPTION", normal_font);
            //table_bottom_column3_1.AddCell(cell_bottom_column3_1);
            //cell_bottom_column3_1.Phrase = new Phrase($"{viewModel.SizeRange + "\n" + viewModel.FabricAllowance + " - " + viewModel.AccessoriesAllowance + "\n" + fabric}", normal_font);
            //table_bottom_column3_1.AddCell(cell_bottom_column3_1);
            #endregion

            #region Signature
            PdfPTable table_signature = new PdfPTable(3);
            table_signature.TotalWidth = 570f;

            float[] signature_widths = new float[] { 1f, 1f, 1f };
            table_signature.SetWidths(signature_widths);

            PdfPCell cell_signature = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };

            //cell_signature.Phrase = new Phrase("", normal_font);
            //table_signature.AddCell(cell_signature);
            //cell_signature.Phrase = new Phrase("", normal_font);
            //table_signature.AddCell(cell_signature);

            string signatureArea = string.Empty;
            for (int i = 0; i < 5; i++)
            {
                signatureArea += Environment.NewLine;
            }
            cell_signature.Phrase = new Phrase(signatureArea, normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase(signatureArea, normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase(signatureArea, normal_font);
            table_signature.AddCell(cell_signature);

            var AssignmentKabag = "";
            var AssignmentKadiv = "";


            if (viewModel.ApprovalMD.IsApproved)
            {
                AssignmentKabag = viewModel.ApprovalMD.ApprovedBy;
            }
            else
            {
                AssignmentKabag = " ____________________ ";
            }

            if (viewModel.ApprovalKadivMD.IsApproved)
            {
                AssignmentKadiv = viewModel.ApprovalKadivMD.ApprovedBy;
            }
            else
            {
                AssignmentKadiv = " ____________________ ";
            }

            string AssignMD = viewModel.IsPosted ? viewModel.CreatedBy : " ";

            cell_signature.Phrase = new Phrase("(  " + AssignMD + "  )", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("(  " + AssignmentKabag + "  )", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("(  " + AssignmentKadiv + "  )", normal_font);
            table_signature.AddCell(cell_signature);

            cell_signature.Phrase = new Phrase("Bag. Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Sie/Ka. Bag Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Div Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            #endregion

            #region Cost Calculation Material


            PdfPTable table_outer = new PdfPTable(2);
            table_outer.TotalWidth = 570f;

            float[] outer_widths = new float[] { 10f, 5f };
            table_outer.SetWidths(outer_widths);

            PdfPTable table_ccm = new PdfPTable(7);
            table_ccm.TotalWidth = 520f;

            float[] ccm_widths = new float[] { 1f, 2f, 1.5f, 3.5f, 2.5f, 3f, 2f };
            table_ccm.SetWidths(ccm_widths);

            PdfPCell cell_ccm_center = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };
            PdfPCell cell_ccm_left = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };
            PdfPCell cell_ccm_right = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };

            cell_ccm_center.Phrase = new Phrase("NO", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("KATEGORI", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("KODE", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("DESKRIPSI", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("QUANTITY", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("RP.PTC/PC", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            cell_ccm_center.Phrase = new Phrase("RP.TOTAL", bold_font);
            table_ccm.AddCell(cell_ccm_center);

            //double Total = 0;
            float   row1Height         = imageHeight > table_detail1.TotalHeight ? imageHeight : table_detail1.TotalHeight;
            float   row2Y              = row1Y - row1Height - 10;
            float[] row3Heights        = { table_bottom_column1_1.TotalHeight, table_bottom_column2_1.TotalHeight, table_bottom_column3_1.TotalHeight + 10 + table_bottom_column2_2.TotalHeight + table_bottom_column1_2.TotalHeight + 2 + table_bottom_column1_3.TotalHeight + 2 };
            float   dollarDetailHeight = 10;
            if (isDollar)
            {
                row3Heights[1] += dollarDetailHeight;
            }
            float row3Height = row3Heights.Max();
            float secondHighestRow3Height = row3Heights[1] > row3Heights[2] ? row3Heights[1] : row3Heights[2];
            bool  signatureInsideRow3     = row3Heights.Max() == row3Heights[0] && row3Heights[0] - 10 - secondHighestRow3Height > table_signature.TotalHeight;
            float row2RemainingHeight     = row2Y - 10 - row3Height - printedOnHeight - margin;
            float row2AllowedHeight       = row2Y - printedOnHeight - margin;

            for (int i = 0; i < viewModel.CostCalculationGarment_Materials.Count; i++)
            {
                //NO
                cell_ccm_center.Phrase = new Phrase((i + 1).ToString(), normal_font);
                table_ccm.AddCell(cell_ccm_center);

                //KATEGORI
                cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Category.name, normal_font);
                table_ccm.AddCell(cell_ccm_left);

                //KODE PRODUK
                cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Product.Code, normal_font);
                table_ccm.AddCell(cell_ccm_left);

                //DESKRIPSI
                cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Description, normal_font);
                table_ccm.AddCell(cell_ccm_left);

                cell_ccm_right.Phrase = new Phrase(String.Format("{0} {1}", viewModel.CostCalculationGarment_Materials[i].Quantity, viewModel.CostCalculationGarment_Materials[i].UOMQuantity.Unit), normal_font);
                table_ccm.AddCell(cell_ccm_right);

                cell_ccm_right.Phrase = new Phrase(String.Format("{0} / {1}", string.Format("{0:n2}", viewModel.CostCalculationGarment_Materials[i].isFabricCM ? 0 : viewModel.CostCalculationGarment_Materials[i].Price), viewModel.CostCalculationGarment_Materials[i].UOMPrice.Unit), normal_font);
                table_ccm.AddCell(cell_ccm_right);

                cell_ccm_right.Phrase = new Phrase(string.Format("{0:n2}", viewModel.CostCalculationGarment_Materials[i].Total), normal_font);
                table_ccm.AddCell(cell_ccm_right);

                //Total += viewModel.CostCalculationGarment_Materials[i].Total;
                //float currentHeight = table_ccm.TotalHeight;
                //if (currentHeight / row2RemainingHeight > 1)
                //{
                //	if (currentHeight / row2AllowedHeight > 1)
                //	{
                //		PdfPRow headerRow = table_ccm.GetRow(0);
                //		PdfPRow lastRow = table_ccm.GetRow(table_ccm.Rows.Count - 1);
                //		table_ccm.DeleteLastRow();
                //		table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb);
                //		table_ccm.DeleteBodyRows();
                //		this.DrawPrintedOn(now, bf, cb);
                //		document.NewPage();
                //		table_ccm.Rows.Add(headerRow);
                //		table_ccm.Rows.Add(lastRow);
                //		table_ccm.CalculateHeightsFast();
                //		row2Y = startY;
                //		row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin;
                //		row2AllowedHeight = row2Y - printedOnHeight - margin;
                //	}
                //}
            }

            cell_ccm_right = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2, Colspan = 6
            };
            cell_ccm_right.Phrase = new Phrase("", bold_font_8);
            table_ccm.AddCell(cell_ccm_right);

            cell_ccm_right = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };
            cell_ccm_right.Phrase = new Phrase("", bold_font_8);
            table_ccm.AddCell(cell_ccm_right);
            table_outer.AddCell(table_ccm);

            PdfPCell cell_breakDown_center = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_TOP,
                Padding             = 2
            };
            cell_breakDown_center.Phrase = new Phrase("REMARK : \n\n" + DESC, normal_font);

            table_outer.AddCell(cell_breakDown_center);
            #endregion

            #region Draw Middle and Bottom

            //        // table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb);
            //         table_outer.WriteSelectedRows(0, -1, 10, row2Y, cb);

            //         float row3Y = row2Y - table_outer.TotalHeight - 10;
            //float row3RemainingHeight = row3Y - printedOnHeight - margin;
            //if (row3RemainingHeight < row3Height)
            //{
            //	this.DrawPrintedOn(now, bf, cb);
            //	row3Y = startY;
            //	document.NewPage();
            //}

            //table_bottom_column1_1.WriteSelectedRows(0, -1, 10, row3Y, cb);

            //         table_bottom_column2_1.WriteSelectedRows(0, -1, 200, row3Y, cb);

            //float noteY = row3Y - table_bottom_column2_1.TotalHeight;
            //float table_bottom_column2_2Y;
            //if (isDollar)
            //{
            //	noteY = noteY - 15;
            //	table_bottom_column2_2Y = noteY - 5;
            //	cb.BeginText();
            //	cb.SetFontAndSize(bf, 6);
            //	cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, $"NOTE: 1 US$ = {Number.ToRupiah(viewModel.Rate.Value)}", 200, noteY, 0);
            //	cb.EndText();
            //}
            //else
            //{
            //	table_bottom_column2_2Y = noteY - 10;
            //}
            //         table_bottom_column2_2.WriteSelectedRows(0, -1, 400, row3Y, cb);

            //         float detail1_2Y = row3Y - table_bottom_column2_2.TotalHeight - 2;
            //         table_bottom_column1_2.WriteSelectedRows(0, -1, 400, detail1_2Y, cb);

            //         float detail1_3Y = detail1_2Y - table_bottom_column1_2.TotalHeight - 2;
            //         table_bottom_column1_3.WriteSelectedRows(0, -1, 400, detail1_3Y, cb);


            //         //table_bottom_column1_2.WriteSelectedRows(0, -1, 400, row3Y, cb);
            //         table_bottom_column3_1.WriteSelectedRows(0, -1, 400, row3Y, cb);

            //float table_signatureX;
            //float table_signatureY;
            //if (signatureInsideRow3)
            //{
            //	table_signatureX = margin + table_bottom_column2_2.TotalWidth + 10;
            //	table_signatureY = row3Y - row3Height + table_signature.TotalHeight;
            //	table_signature.TotalWidth = 390f;
            //}
            //else
            //{
            //	table_signatureX = margin;
            //	table_signatureY = row3Y - row3Height - 10;
            //	float signatureRemainingHeight = table_signatureY - printedOnHeight - margin;
            //	if (signatureRemainingHeight < table_signature.TotalHeight)
            //	{
            //		this.DrawPrintedOn(now, bf, cb);
            //		table_signatureY = startY;
            //		document.NewPage();
            //	}
            //}
            //table_signature.WriteSelectedRows(0, -1, table_signatureX, table_signatureY, cb);

            //this.DrawPrintedOn(now, bf, cb);
            #endregion

            #region Add Middle and Bottom

            document.Add(new Paragraph("\n")
            {
                SpacingAfter = row1Height + 20
            });
            new PdfPCell(table_outer);
            table_outer.ExtendLastRow = false;
            table_outer.SplitLate     = false;
            table_outer.SpacingAfter  = 10f;
            document.Add(table_outer);

            PdfPTable table_bottom = new PdfPTable(5);
            table_bottom.SetWidths(new float[] { 1f, 0.05f, 1f, 0.05f, 1f });
            table_bottom.DefaultCell.Border  = Rectangle.NO_BORDER;
            table_bottom.DefaultCell.Padding = 0;

            var cell_bottom_left = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            new PdfPCell(table_bottom_column1_1);
            table_bottom_column1_1.ExtendLastRow = false;
            cell_bottom_left.AddElement(table_bottom_column1_1);
            table_bottom.AddCell(cell_bottom_left);

            table_bottom.AddCell("\n");

            var cell_bottom_center = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            new PdfPCell(table_bottom_column2_1);
            table_bottom_column2_1.ExtendLastRow = false;
            cell_bottom_center.AddElement(table_bottom_column2_1);
            if (isDollar)
            {
                cell_bottom_center.AddElement(new Paragraph($"NOTE: 1 US$ = {Number.ToRupiah(viewModel.Rate.Value)}", normal_font));
            }
            table_bottom.AddCell(cell_bottom_center);

            table_bottom.AddCell("\n");

            var cell_bottom_right = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };

            new PdfPCell(table_bottom_column2_2);
            table_bottom_column2_2.ExtendLastRow = false;
            cell_bottom_right.AddElement(table_bottom_column2_2);
            new PdfPCell(table_bottom_column1_2);
            table_bottom_column1_2.ExtendLastRow = false;
            cell_bottom_right.AddElement(table_bottom_column1_2);
            new PdfPCell(table_bottom_column1_3);
            table_bottom_column1_3.ExtendLastRow = false;
            cell_bottom_right.AddElement(table_bottom_column1_3);

            table_bottom.AddCell(cell_bottom_right);

            new PdfPCell(table_bottom);
            table_bottom.ExtendLastRow = false;
            table_bottom.SpacingAfter  = 20f;
            document.Add(table_bottom);

            new PdfPCell(table_signature);
            table_signature.ExtendLastRow = false;
            document.Add(table_signature);

            #endregion

            document.Close();

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

            return(stream);
        }
Exemplo n.º 12
0
        public MemoryStream GeneratePdfTemplate(CostCalculationGarmentViewModel viewModel, int timeoffset)
        {
            BaseFont bf          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            BaseFont bf_bold     = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            Font     normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 6);
            Font     bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 6);
            DateTime now         = DateTime.Now;

            Document     document = new Document(PageSize.A4, 10, 10, 10, 10);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            writer.CloseStream = false;
            document.Open();
            PdfContentByte cb = writer.DirectContent;

            float    margin          = 10;
            float    printedOnHeight = 10;
            float    startY          = 840 - margin;
            PdfPCell cell_colon      = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Phrase = new Phrase(":", normal_font)
            };

            #region Header
            string    codeNoString = "FM-02-PJ-01-03/R1";
            Paragraph codeNo       = new Paragraph(codeNoString, bold_font)
            {
                Alignment = Element.ALIGN_RIGHT
            };
            codeNo.SpacingAfter = 10f;
            document.Add(codeNo);

            cb.BeginText();
            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. AMBASSADOR GARMINDO", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "BUDGET GARMENT", 10, 805, 0);
            cb.EndText();
            #endregion

            #region Detail 1 (Top)
            PdfPTable table_detail1 = new PdfPTable(9);
            table_detail1.TotalWidth = 570f;

            float[] detail1_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1.5f, 0.1f, 2f };
            table_detail1.SetWidths(detail1_widths);

            PdfPCell cell_detail1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2
            };

            cell_detail1.Phrase = new Phrase("RO", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.RO_Number}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("SECTION", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Section}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("CONFIRM ORDER", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.ConfirmDate.AddHours(timeoffset).ToString("dd/MM/yyyy")}", normal_font);
            table_detail1.AddCell(cell_detail1);
            #endregion

            #region Draw Detail 1
            float row1Y = 800;
            table_detail1.WriteSelectedRows(0, -1, 10, row1Y, cb);
            #endregion

            bool isDollar = viewModel.Rate.Id != 6;

            #region Detail 2 (Bottom, Column 1)
            PdfPTable table_detail2 = new PdfPTable(2);
            table_detail2.TotalWidth = 230f;

            float[] detail2_widths = new float[] { 2f, 5f };
            table_detail2.SetWidths(detail2_widths);

            PdfPCell cell_detail2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };

            cell_detail2.Phrase = new Phrase("BUYER AGENT", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.Buyer.Code}" + " - " + $"{viewModel.Buyer.Name}", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("BUYER BRAND", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.BuyerBrand.Code}" + " - " + $"{viewModel.BuyerBrand.Name}", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("ARTICLE", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.Article}", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("DESCRIPTION", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.CommodityDescription}", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("QTY", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.Quantity} PCS", normal_font);
            table_detail2.AddCell(cell_detail2);

            cell_detail2.Phrase = new Phrase("DELIVERY", normal_font);
            table_detail2.AddCell(cell_detail2);
            cell_detail2.Phrase = new Phrase($"{viewModel.DeliveryDate.AddHours(timeoffset).ToString("dd/MM/yyyy")}", normal_font);
            table_detail2.AddCell(cell_detail2);
            #endregion

            #region Detail 3 (Bottom, Column 2)
            PdfPTable table_detail3 = new PdfPTable(8);
            table_detail3.TotalWidth = 330f;

            float[] detail3_widths = new float[] { 3.25f, 4.75f, 1.9f, 0.2f, 1.9f, 1.9f, 0.2f, 1.9f };
            table_detail3.SetWidths(detail3_widths);

            double   budgetCost   = isDollar ? viewModel.ConfirmPrice * viewModel.Rate.Value ?? 0 : viewModel.ConfirmPrice ?? 0;
            double   totalBudget  = budgetCost * viewModel.Quantity ?? 0;
            PdfPCell cell_detail3 = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };
            PdfPCell cell_detail3_right = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7
            };
            PdfPCell cell_detail3_colspan6 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7, Colspan = 6
            };
            PdfPCell cell_detail3_colspan8 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7, Colspan = 8
            };

            cell_detail3.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("TOTAL BUDGET", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase($"{Number.ToRupiah(totalBudget)}", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3_colspan6.Phrase = new Phrase("STANDARD MINUTE VALUE", normal_font);
            table_detail3.AddCell(cell_detail3_colspan6);

            double freightCost = 0;
            foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials)
            {
                freightCost += item.TotalShippingFee * viewModel.Quantity.GetValueOrDefault();
            }

            cell_detail3.Border = Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("BEA ANGKUT", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase($"{Number.ToRupiah(freightCost)}", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("SMV. CUT", normal_font);
            table_detail3.AddCell(cell_detail3);
            table_detail3.AddCell(cell_colon);
            cell_detail3.Border = Rectangle.NO_BORDER;
            cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Cutting}", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.NO_BORDER;
            cell_detail3.Phrase = new Phrase("SMV. SEW", normal_font);
            table_detail3.AddCell(cell_detail3);
            table_detail3.AddCell(cell_colon);
            cell_detail3.Border = Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Sewing}", normal_font);
            table_detail3.AddCell(cell_detail3);

            cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase("", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("SMV. FIN", normal_font);
            table_detail3.AddCell(cell_detail3);
            table_detail3.AddCell(cell_colon);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER;
            cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Finishing}", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER;
            cell_detail3.Phrase = new Phrase("SMV. TOT", normal_font);
            table_detail3.AddCell(cell_detail3);
            table_detail3.AddCell(cell_colon);
            cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;
            cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Total}", normal_font);
            table_detail3.AddCell(cell_detail3);

            cell_detail3_colspan8.Phrase = new Phrase("BUDGET COST / PCS" + "".PadRight(5) + $"{Number.ToRupiah(budgetCost)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan8);
            cell_detail3_colspan8.Phrase = isDollar ? new Phrase($"US$ 1 = {Number.ToRupiah(viewModel.Rate.Value)}" + "".PadRight(10) + $"CONFIRM PRICE : {Number.ToDollar(viewModel.ConfirmPrice)} / PCS", normal_font) : new Phrase($"CONFIRM PRICE : {Number.ToRupiah(viewModel.ConfirmPrice)} / PCS", normal_font);
            table_detail3.AddCell(cell_detail3_colspan8);
            cell_detail3_colspan8.Border = Rectangle.NO_BORDER;
            cell_detail3_colspan8.HorizontalAlignment = Element.ALIGN_CENTER;
            cell_detail3_colspan8.Phrase = new Phrase($"ALLOWANCE >> FABRIC = {viewModel.FabricAllowance}%, ACC = {viewModel.AccessoriesAllowance}%", normal_font);
            table_detail3.AddCell(cell_detail3_colspan8);
            #endregion

            #region Signature
            PdfPTable table_signature = new PdfPTable(5);
            table_signature.TotalWidth = 570f;

            float[] signature_widths = new float[] { 1f, 1f, 1f, 1f, 1f };
            table_signature.SetWidths(signature_widths);

            PdfPCell cell_signature = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };

            cell_signature.Phrase = new Phrase("", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("", normal_font);
            table_signature.AddCell(cell_signature);

            string signatureArea = string.Empty;
            for (int i = 0; i < 5; i++)
            {
                signatureArea += Environment.NewLine;
            }

            cell_signature.Phrase = new Phrase(signatureArea, normal_font);
            table_signature.AddCell(cell_signature);
            table_signature.AddCell(cell_signature);
            table_signature.AddCell(cell_signature);
            table_signature.AddCell(cell_signature);
            table_signature.AddCell(cell_signature);

            var AssignmentKabag = "";
            var AssignmentPurch = "";
            var AssignmentKadiv = "";

            if (viewModel.ApprovalMD.IsApproved)
            {
                AssignmentKabag = viewModel.ApprovalMD.ApprovedBy;
            }
            else
            {
                AssignmentKabag = " ____________________ ";
            }

            if (viewModel.ApprovalPurchasing.IsApproved)
            {
                AssignmentPurch = viewModel.ApprovalPurchasing.ApprovedBy;
            }
            else
            {
                AssignmentPurch = " ____________________ ";
            }

            if (viewModel.ApprovalKadivMD.IsApproved)
            {
                AssignmentKadiv = viewModel.ApprovalKadivMD.ApprovedBy;
            }
            else
            {
                AssignmentKadiv = " ____________________ ";
            }

            string AssignMD = viewModel.IsPosted ? viewModel.CreatedBy : " ";

            //cell_signature.Phrase = new Phrase("(................)", normal_font);
            //table_signature.AddCell(cell_signature);
            //cell_signature.Phrase = new Phrase("(................)", normal_font);
            //table_signature.AddCell(cell_signature);
            //cell_signature.Phrase = new Phrase("(................)", normal_font);
            //table_signature.AddCell(cell_signature);
            //cell_signature.Phrase = new Phrase("(................)", normal_font);
            //table_signature.AddCell(cell_signature);
            //cell_signature.Phrase = new Phrase("(................)", normal_font);
            //table_signature.AddCell(cell_signature);

            cell_signature.Phrase = new Phrase("( " + AssignMD + " )", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("( " + AssignmentKabag + " )", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("( " + AssignmentPurch + " )", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("( ____________________ )", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("( " + AssignmentKadiv + " )", normal_font);
            table_signature.AddCell(cell_signature);


            cell_signature.Phrase = new Phrase("Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Sie/Ka. Bag Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Bag Pembelian", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Div Produksi Garment", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka. Div Penjualan", normal_font);
            table_signature.AddCell(cell_signature);
            #endregion

            #region Cost Calculation Material
            PdfPTable table_ccm = new PdfPTable(11);
            table_ccm.TotalWidth = 570f;

            float[] ccm_widths = new float[] { 1f, 3f, 2f, 6f, 2f, 3f, 2f, 2f, 3f, 3f, 3f };
            table_ccm.SetWidths(ccm_widths);

            PdfPCell cell_ccm = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2
            };

            cell_ccm.Phrase = new Phrase("NO", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("CATEGORIES", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("KODE", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("DESCRIPTION", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("USAGE", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("PRICE", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("QTY", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("UNIT", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("AMOUNT", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("PO NUMBER", bold_font);
            table_ccm.AddCell(cell_ccm);
            cell_ccm.Phrase = new Phrase("BEA KIRIM", bold_font);
            table_ccm.AddCell(cell_ccm);

            float row2Y               = row1Y - table_detail1.TotalHeight - 5;
            float row3Height          = table_detail2.TotalHeight > table_detail3.TotalHeight ? table_detail2.TotalHeight : table_detail3.TotalHeight;
            float row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin;
            float row2AllowedHeight   = row2Y - printedOnHeight - margin;

            for (int i = 0; i < viewModel.CostCalculationGarment_Materials.Count; i++)
            {
                //NO
                cell_ccm.Phrase = new Phrase((i + 1).ToString(), normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_LEFT;

                //CATEGORY
                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Category.name, normal_font);
                table_ccm.AddCell(cell_ccm);

                //KODE PRODUK
                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Product.Code, normal_font);
                table_ccm.AddCell(cell_ccm);

                //DESCRIPTION
                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Description, normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT;

                double usage = viewModel.CostCalculationGarment_Materials[i].Quantity ?? 0;
                cell_ccm.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(usage), normal_font);
                table_ccm.AddCell(cell_ccm);

                double price = viewModel.CostCalculationGarment_Materials[i].Price ?? 0;
                cell_ccm.Phrase = new Phrase(String.Format("{0}/{1}", Number.ToRupiahWithoutSymbol(price), viewModel.CostCalculationGarment_Materials[i].UOMPrice.Unit), normal_font);
                table_ccm.AddCell(cell_ccm);

                double factor;
                if (viewModel.CostCalculationGarment_Materials[i].Category.name == "FABRIC")
                {
                    factor = viewModel.FabricAllowance ?? 0;
                }
                else
                {
                    factor = viewModel.AccessoriesAllowance ?? 0;
                }
                double totalQuantity  = viewModel.Quantity ?? 0;
                double quantity       = (100 + factor) / 100 * usage * totalQuantity;
                var    budgetQuantity = Number.ToRupiahWithoutSymbol(Math.Ceiling(viewModel.CostCalculationGarment_Materials[i].BudgetQuantity));
                cell_ccm.Phrase = new Phrase(budgetQuantity.Substring(0, budgetQuantity.Length - 3), normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_CENTER;
                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].UOMQuantity.Unit, normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT;

                if (viewModel.CostCalculationGarment_Materials[i].isFabricCM == true)
                {
                    cell_ccm.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(0), normal_font);
                    table_ccm.AddCell(cell_ccm);
                }
                else
                {
                    double amount = viewModel.CostCalculationGarment_Materials[i].BudgetQuantity * price;
                    cell_ccm.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(amount), normal_font);
                    table_ccm.AddCell(cell_ccm);
                }


                cell_ccm.HorizontalAlignment = Element.ALIGN_CENTER;
                cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].PO_SerialNumber, normal_font);
                table_ccm.AddCell(cell_ccm);

                cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT;
                var beaKirim = Number.ToRupiahWithoutSymbol(Math.Ceiling(viewModel.CostCalculationGarment_Materials[i].TotalShippingFee * viewModel.Quantity.GetValueOrDefault()));
                cell_ccm.Phrase = new Phrase(beaKirim.Substring(0, beaKirim.Length - 3), normal_font);
                table_ccm.AddCell(cell_ccm);

                float currentHeight = table_ccm.TotalHeight;
                if (currentHeight / row2RemainingHeight > 1)
                {
                    if (currentHeight / row2AllowedHeight > 1)
                    {
                        PdfPRow headerRow = table_ccm.GetRow(0);
                        PdfPRow lastRow   = table_ccm.GetRow(table_ccm.Rows.Count - 1);
                        table_ccm.DeleteLastRow();
                        table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb);
                        table_ccm.DeleteBodyRows();
                        this.DrawPrintedOn(now, bf, cb);
                        document.NewPage();
                        table_ccm.Rows.Add(headerRow);
                        table_ccm.Rows.Add(lastRow);
                        table_ccm.CalculateHeightsFast();
                        row2Y = startY;
                        row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin;
                        row2AllowedHeight   = row2Y - printedOnHeight - margin;
                    }
                }
            }
            #endregion

            #region Draw Others
            table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb);

            float row3Y = row2Y - table_ccm.TotalHeight - 5;
            float row3RemainigHeight = row3Y - printedOnHeight - margin;
            if (row3RemainigHeight < row3Height)
            {
                this.DrawPrintedOn(now, bf, cb);
                row3Y = startY;
                document.NewPage();
            }

            table_detail2.WriteSelectedRows(0, -1, margin, row3Y, cb);

            table_detail3.WriteSelectedRows(0, -1, margin + table_detail2.TotalWidth + 10, row3Y, cb);

            float signatureY = row3Y - row3Height - 10;
            float signatureRemainingHeight = signatureY - printedOnHeight - margin;
            if (signatureRemainingHeight < table_signature.TotalHeight)
            {
                this.DrawPrintedOn(now, bf, cb);
                signatureY = startY;
                document.NewPage();
            }
            table_signature.WriteSelectedRows(0, -1, margin, signatureY, cb);

            this.DrawPrintedOn(now, bf, cb);
            #endregion

            document.Close();

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

            return(stream);
        }
        public void GeneratePdfTemplate_Return_Success()
        {
            CostCalculationGarmentBudgetPdfTemplate pdf       = new CostCalculationGarmentBudgetPdfTemplate();
            CostCalculationGarmentViewModel         viewModel = new CostCalculationGarmentViewModel()
            {
                AccessoriesAllowance = 1,
                Active     = true,
                ApprovalIE = new Approval()
                {
                    ApprovedBy   = "fetih",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                ApprovalKadivMD = new Approval()
                {
                    ApprovedBy   = "fetih han",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                ApprovalMD = new Approval()
                {
                    ApprovedBy   = "fetih han",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                ApprovalPPIC = new Approval
                {
                    ApprovedBy   = "fetih han",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                ApprovalPurchasing = new Approval
                {
                    ApprovedBy   = "fetih han",
                    ApprovedDate = DateTimeOffset.Now,
                    IsApproved   = true
                },
                Article             = "Article",
                AutoIncrementNumber = 1,
                Buyer = new BuyerViewModel
                {
                    Active   = true,
                    address1 = "jakarta",
                    address2 = "solo",
                    Code     = "Code",
                    email    = "*****@*****.**",
                    Name     = "Name",
                    Id       = 1,
                    UId      = "Uid"
                },
                SMV_Finishing = 1,
                BuyerBrand    = new BuyerBrandViewModel()
                {
                    Active    = true,
                    UId       = "UId",
                    Code      = "Code",
                    Id        = 1,
                    Name      = "Name",
                    CreatedBy = "Fetih han",
                },
                Code = "Code",
                CommissionPortion    = 1,
                CommissionRate       = 1,
                CommodityDescription = "CommodityDescription",
                Comodity             = new MasterPlanComodityViewModel
                {
                    Name = "Name",
                    Code = "Code",
                    UId  = "UId"
                },
                ConfirmDate  = DateTimeOffset.Now,
                ConfirmPrice = 1,
                CostCalculationGarment_Materials = new List <CostCalculationGarment_MaterialViewModel>()
                {
                    new CostCalculationGarment_MaterialViewModel()
                    {
                        AutoIncrementNumber = 1,
                        AvailableQuantity   = 1,
                        BudgetQuantity      = 1,
                        Category            = new CategoryViewModel()
                        {
                            name = "FABRIC",
                            code = "code",
                            UId  = "UId"
                        },
                        CM_Price        = 1,
                        Code            = "Code",
                        Conversion      = 1,
                        Description     = "Description",
                        Information     = "Information",
                        isFabricCM      = true,
                        IsPosted        = true,
                        IsPRMaster      = true,
                        MaterialIndex   = 1,
                        PO              = "PO",
                        POMaster        = "POMaster",
                        PO_SerialNumber = "PO_SerialNumber",
                        Price           = 1,
                        PRMasterId      = 1,
                        PRMasterItemId  = 1,
                        Product         = new GarmentProductViewModel()
                        {
                            Code        = "Code",
                            Composition = "Composition",
                            Const       = "Const",
                            Name        = "Name",
                            Width       = "1",
                            UId         = "Uid",
                            Yarn        = "Yarn",
                        },
                        ProductRemark      = "ProductRemark",
                        Quantity           = 1,
                        ShippingFeePortion = 1,
                        Total            = 1,
                        TotalShippingFee = 1,
                        UId      = "Uid",
                        UOMPrice = new UOMViewModel()
                        {
                            UId  = "Uid",
                            Unit = "meter",
                            code = "code"
                        },
                        UOMQuantity = new UOMViewModel()
                        {
                            UId  = "Uid",
                            Unit = "meter",
                            code = "code"
                        },
                    }
                },
                Description  = "Description",
                DeliveryDate = DateTimeOffset.Now,
                SMV_Sewing   = 1,
                SMV_Cutting  = 1,
                Efficiency   = new EfficiencyViewModel()
                {
                    Code         = "Code",
                    FinalRange   = 1,
                    InitialRange = 1,
                    Name         = "Name",
                    Value        = 1,
                    UId          = "Uid"
                },
                FabricAllowance     = 1,
                Freight             = 1,
                FreightCost         = 1,
                ImageFile           = "",
                ImagePath           = "",
                Index               = 1,
                Insurance           = 1,
                IsPosted            = true,
                IsROAccepted        = true,
                IsROAvailable       = true,
                IsDeleted           = false,
                IsRODistributed     = true,
                IsValidatedROMD     = true,
                IsValidatedROPPIC   = true,
                IsValidatedROSample = true,
                Id        = 1,
                NETFOB    = 1,
                NETFOBP   = 1,
                SMV_Total = 1,
                UOM       = new UOMViewModel()
                {
                    UId  = "Uid",
                    Unit = "meter",
                    code = "code"
                },
                UId  = "Uid",
                Unit = new UnitViewModel()
                {
                    Id   = 1,
                    Code = "Code",
                    Name = "Name"
                },
                LeadTime = 1,
                OTL1     = new RateCalculatedViewModel()
                {
                    Code = "Code",
                    Name = "Name",
                    Unit = new UnitViewModel()
                    {
                        Id   = 1,
                        Code = "Code",
                        Name = "Name"
                    },
                    Value = 1,
                    UId   = "Uid"
                },
                UnitName = "UnitName",
                OTL2     = new RateCalculatedViewModel()
                {
                    Code = "Code",
                    Name = "Name",
                    Unit = new UnitViewModel()
                    {
                        Id   = 1,
                        Code = "Code",
                        Name = "Name"
                    },
                    Value = 1,
                    UId   = "Uid"
                },
                ROAcceptedBy = "fetih han",
                Rate         = new RateViewModel()
                {
                    Id   = 1,
                    Unit = new UnitViewModel()
                    {
                        Id   = 1,
                        Code = "Code",
                        Name = "Name"
                    },
                    UId   = "Uid",
                    Name  = "Name",
                    Value = 1,
                },
                PreSCId              = 1,
                PreSCNo              = "PreSCNo",
                ProductionCost       = 1,
                ValidationPPICBy     = "fetih han",
                ValidationMDBy       = "fetih han",
                ValidationMDDate     = DateTimeOffset.Now,
                ValidationPPICDate   = DateTimeOffset.Now,
                ValidationSampleBy   = "fetih han",
                ValidationSampleDate = DateTimeOffset.Now,
                Quantity             = 1,
                Risk               = 1,
                ROAcceptedDate     = DateTimeOffset.Now,
                ROAvailableBy      = "fetih han",
                ROAvailableDate    = DateTimeOffset.Now,
                RODistributionBy   = "fetih han",
                RODistributionDate = DateTimeOffset.Now,
                RO_GarmentId       = 1,
                RO_Number          = "RO_Number",
                RO_RetailId        = 1,
                SCGarmentId        = 1,
                Section            = "Section",
                SectionName        = "SectionName",
                SizeRange          = "SizeRange",
                THR = new RateViewModel()
                {
                    Id   = 1,
                    Unit = new UnitViewModel()
                    {
                        Id   = 1,
                        Code = "Code",
                        Name = "Name"
                    },
                    UId   = "Uid",
                    Name  = "Name",
                    Value = 1,
                },
                Wage = new RateViewModel()
                {
                    Id   = 1,
                    Unit = new UnitViewModel()
                    {
                        Id   = 1,
                        Code = "Code",
                        Name = "Name"
                    },
                    UId   = "Uid",
                    Name  = "Name",
                    Value = 1,
                },
                CreatedBy = "fetih han"
            };
            var result = pdf.GeneratePdfTemplate(viewModel, 2);

            Assert.NotNull(result);
            Assert.IsType <MemoryStream>(result);
        }
        public string GetResultFormatterOkString(CostCalculationGarmentViewModel costCalculationGarmentViewModel)
        {
            var result = GetResultFormatterOk(costCalculationGarmentViewModel);

            return(JsonConvert.SerializeObject(result));
        }
        public CostCalculationGarment MapToModel(CostCalculationGarmentViewModel viewModel)
        {
            CostCalculationGarment model = new CostCalculationGarment();

            PropertyCopier <CostCalculationGarmentViewModel, CostCalculationGarment> .Copy(viewModel, model);

            model.LineId   = viewModel.Line.Id;
            model.LineCode = viewModel.Line.Code;
            model.LineName = viewModel.Line.Name;

            model.FabricAllowance      = Percentage.ToFraction(viewModel.FabricAllowance);
            model.AccessoriesAllowance = Percentage.ToFraction(viewModel.AccessoriesAllowance);

            model.SizeRangeId   = viewModel.SizeRange.Id;
            model.SizeRangeName = viewModel.SizeRange.Name;

            model.BuyerId   = viewModel.Buyer.Id;
            model.BuyerName = viewModel.Buyer.Name;

            model.EfficiencyId    = viewModel.Efficiency.Id;
            model.EfficiencyValue = Percentage.ToFraction(viewModel.Efficiency.Value);

            model.WageId   = viewModel.Wage.Id;
            model.WageRate = viewModel.Wage.Value != null ? (double)viewModel.Wage.Value : 0;

            model.THRId   = viewModel.THR.Id;
            model.THRRate = viewModel.THR.Value != null ? (double)viewModel.THR.Value : 0;

            model.RateId    = viewModel.Rate.Id;
            model.RateValue = viewModel.Rate.Value != null ? (double)viewModel.Rate.Value : 0;

            model.CostCalculationGarment_Materials = new List <CostCalculationGarment_Material>();

            foreach (CostCalculationGarment_MaterialViewModel CostCalculationGarment_MaterialVM in viewModel.CostCalculationGarment_Materials)
            {
                CostCalculationGarment_Material CostCalculationGarment_Material = new CostCalculationGarment_Material();
                PropertyCopier <CostCalculationGarment_MaterialViewModel, CostCalculationGarment_Material> .Copy(CostCalculationGarment_MaterialVM, CostCalculationGarment_Material);

                CostCalculationGarment_Material.CategoryId         = CostCalculationGarment_MaterialVM.Category.Id;
                CostCalculationGarment_Material.CategoryName       = CostCalculationGarment_MaterialVM.Category.SubCategory != null ? CostCalculationGarment_MaterialVM.Category.Name + " - " + CostCalculationGarment_MaterialVM.Category.SubCategory : CostCalculationGarment_MaterialVM.Category.Name;
                CostCalculationGarment_Material.MaterialId         = CostCalculationGarment_MaterialVM.Material.Id;
                CostCalculationGarment_Material.MaterialName       = CostCalculationGarment_MaterialVM.Material.Name;
                CostCalculationGarment_Material.UOMQuantityId      = CostCalculationGarment_MaterialVM.UOMQuantity.Id;
                CostCalculationGarment_Material.UOMQuantityName    = CostCalculationGarment_MaterialVM.UOMQuantity.Name;
                CostCalculationGarment_Material.UOMPriceId         = CostCalculationGarment_MaterialVM.UOMPrice.Id;
                CostCalculationGarment_Material.UOMPriceName       = CostCalculationGarment_MaterialVM.UOMPrice.Name;
                CostCalculationGarment_Material.ShippingFeePortion = Percentage.ToFraction(CostCalculationGarment_MaterialVM.ShippingFeePortion);

                model.CostCalculationGarment_Materials.Add(CostCalculationGarment_Material);
            }

            model.CommissionPortion = Percentage.ToFraction(viewModel.CommissionPortion);
            model.Risk = Percentage.ToFraction(viewModel.Risk);

            model.OTL1Id             = viewModel.OTL1.Id;
            model.OTL1Rate           = viewModel.OTL1.Value != null ? (double)viewModel.OTL1.Value : 0;
            model.OTL1CalculatedRate = viewModel.OTL1.CalculatedValue != null ? (double)viewModel.OTL1.CalculatedValue : 0;

            model.OTL2Id             = viewModel.OTL2.Id;
            model.OTL2Rate           = viewModel.OTL2.Value != null ? (double)viewModel.OTL2.Value : 0;
            model.OTL2CalculatedRate = viewModel.OTL2.CalculatedValue != null ? (double)viewModel.OTL2.CalculatedValue : 0;

            model.NETFOBP = Percentage.ToFraction(viewModel.NETFOBP);

            return(model);
        }
        public CostCalculationGarmentViewModel MapToViewModel(CostCalculationGarment model)
        {
            CostCalculationGarmentViewModel viewModel = new CostCalculationGarmentViewModel();

            PropertyCopier <CostCalculationGarment, CostCalculationGarmentViewModel> .Copy(model, viewModel);

            viewModel.Line      = new LineViewModel();
            viewModel.Line.Id   = model.LineId;
            viewModel.Line.Name = model.LineName;

            viewModel.FabricAllowance      = Percentage.ToPercent(model.FabricAllowance);
            viewModel.AccessoriesAllowance = Percentage.ToPercent(model.AccessoriesAllowance);

            viewModel.SizeRange      = new SizeRangeViewModel();
            viewModel.SizeRange.Id   = model.SizeRangeId;
            viewModel.SizeRange.Name = model.SizeRangeName;

            viewModel.Buyer      = new BuyerViewModel();
            viewModel.Buyer.Id   = model.BuyerId;
            viewModel.Buyer.Name = model.BuyerName;

            viewModel.Efficiency       = new EfficiencyViewModel();
            viewModel.Efficiency.Id    = model.EfficiencyId;
            viewModel.Efficiency.Value = Percentage.ToPercent(model.EfficiencyValue);

            viewModel.Wage       = new RateViewModel();
            viewModel.Wage.Id    = model.WageId;
            viewModel.Wage.Value = model.WageRate;

            viewModel.THR       = new RateViewModel();
            viewModel.THR.Id    = model.THRId;
            viewModel.THR.Value = model.THRRate;

            viewModel.Rate       = new RateViewModel();
            viewModel.Rate.Id    = model.RateId;
            viewModel.Rate.Value = model.RateValue;

            viewModel.CostCalculationGarment_Materials = new List <CostCalculationGarment_MaterialViewModel>();
            if (model.CostCalculationGarment_Materials != null)
            {
                foreach (CostCalculationGarment_Material CostCalculationGarment_Material in model.CostCalculationGarment_Materials)
                {
                    CostCalculationGarment_MaterialViewModel CostCalculationGarment_MaterialVM = new CostCalculationGarment_MaterialViewModel();
                    PropertyCopier <CostCalculationGarment_Material, CostCalculationGarment_MaterialViewModel> .Copy(CostCalculationGarment_Material, CostCalculationGarment_MaterialVM);

                    CategoryViewModel categoryVM = new CategoryViewModel()
                    {
                        Id = CostCalculationGarment_Material.CategoryId
                    };
                    string[] names = CostCalculationGarment_Material.CategoryName.Split(new[] { " - " }, StringSplitOptions.None);
                    categoryVM.Name = names[0];
                    try
                    {
                        categoryVM.SubCategory = names[1];
                    }
                    catch (IndexOutOfRangeException)
                    {
                        categoryVM.SubCategory = null;
                    }
                    CostCalculationGarment_MaterialVM.Category = categoryVM;

                    MaterialViewModel materialVM = new MaterialViewModel()
                    {
                        Id   = CostCalculationGarment_Material.MaterialId,
                        Name = CostCalculationGarment_Material.MaterialName
                    };
                    CostCalculationGarment_MaterialVM.Material = materialVM;

                    UOMViewModel uomQuantityVM = new UOMViewModel()
                    {
                        Id   = CostCalculationGarment_Material.UOMQuantityId,
                        Name = CostCalculationGarment_Material.UOMQuantityName
                    };
                    CostCalculationGarment_MaterialVM.UOMQuantity = uomQuantityVM;

                    UOMViewModel uomPriceVM = new UOMViewModel()
                    {
                        Id   = CostCalculationGarment_Material.UOMPriceId,
                        Name = CostCalculationGarment_Material.UOMPriceName
                    };
                    CostCalculationGarment_MaterialVM.UOMPrice = uomPriceVM;

                    CostCalculationGarment_MaterialVM.ShippingFeePortion = Percentage.ToPercent(CostCalculationGarment_Material.ShippingFeePortion);

                    viewModel.CostCalculationGarment_Materials.Add(CostCalculationGarment_MaterialVM);
                }
            }

            viewModel.CommissionPortion = Percentage.ToPercent(model.CommissionPortion);
            viewModel.Risk = Percentage.ToPercent(model.Risk);

            viewModel.OTL1                 = new RateCalculatedViewModel();
            viewModel.OTL1.Id              = model.OTL1Id;
            viewModel.OTL1.Value           = model.OTL1Rate;
            viewModel.OTL1.CalculatedValue = model.OTL1CalculatedRate;

            viewModel.OTL2                 = new RateCalculatedViewModel();
            viewModel.OTL2.Id              = model.OTL2Id;
            viewModel.OTL2.Value           = model.OTL2Rate;
            viewModel.OTL2.CalculatedValue = model.OTL2CalculatedRate;

            viewModel.NETFOBP = Percentage.ToPercent((double)model.NETFOBP);

            return(viewModel);
        }