Example #1
0
 public void LimpaTabela(PdfPTable tabela)
 {
     while (tabela.Rows.Count > 0)
     {
         tabela.DeleteLastRow();
     }
 }
        /// <summary>
        /// Add a row of pdfpcell to table.
        /// return True, current page have enought size for that row
        /// return False, current page not enought size for that row, row will be remove and need to draw on
        /// next page
        /// 20130606 :: jaimelopez :: mellorasinxelas to support absolute footer.
        /// </summary>
        /// <param name="table"></param>
        /// <param name="tableRowElement"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected bool DrawTableRow(
            PdfPTable table,
            TableRow tableRowElement,
            IDictionary data)
        {
            bool enoughSpace = true;

            PDFDrawItextSharp.PDFDrawItextSharp pdfDraw = (PDFDrawItextSharp.PDFDrawItextSharp)pdfDrawer;
            foreach (TableCell tableCell in tableRowElement.TableCells)
            {
                PdfPCell cell = pdfDraw.CreateTableCell(tableCell.Attributes, data);
                foreach (DrawElement drawElement in tableCell.DrawElements)
                {
                    if (drawElement is TextBox)
                    {
                        //iTextSharp.text.Phrase phrase = _pdfDraw.CreatePhrase(
                        //    ((PDFTemplate.TextBox)drawElement).GetText(data), drawElement.FontAttributes);
                        Paragraph paragraph = pdfDraw.CreateParagraph(((TextBox)drawElement).GetText(data), drawElement.FontAttributes);
                        paragraph.Alignment = PDFDrawItextSharpHelper.Align(Helper.GetAttributeValue("align", drawElement.Attributes, "Left"));

                        cell.AddElement(paragraph);
                    }
                    else if (drawElement is PDFTemplate.Image)
                    {
                        //iTextSharp.text.Image image = pdfDraw.CreateImageFromAttribute(drawElement.Attributes);
                        //image.Alignment = PDFDrawItextSharpHelper.Align(Helper.GetAttributeValue("align", drawElement.Attributes, "Left"));

                        //cell.AddElement(image);

                        // 2017-11-23 : fix error image in table
                        string src = Moon.PDFDraw.Helper.GetAttributeValue("src", drawElement.Attributes, "");
                        if (data.Contains(src))
                        {
                            iTextSharp.text.Image image = pdfDraw.CreateImageFromAttribute(data[src].ToString(), drawElement.Attributes);
                            image.Alignment = PDFDrawItextSharpHelper.Align(Helper.GetAttributeValue("align", drawElement.Attributes, "Left"));

                            cell.AddElement(image);
                        }
                    }
                }
                table.AddCell(cell);
            }
            table.CompleteRow();

            //if(table.row
            //fixme need to check if any row span
            if (pdfDrawer.isNoMoreY(table.TotalHeight, DocumentGroup.Table))
            {
                enoughSpace = false;
                table.DeleteLastRow();
            }

            return(enoughSpace);
        }
Example #3
0
        private string AddCell(PdfPTable table, string content, Font font, int page)
        {
            int      s = 0, b = content.Length - 1, m = b + 1;
            string   str;
            PdfPCell cell = new PdfPCell(new Phrase(content, font));

            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            cell.MinimumHeight       = 300f;
            cell.SetLeading(0, 1.5f);
            cell.BorderWidthTop  = 0;
            cell.BorderWidthLeft = 0;
            table.AddCell(cell);
            while (b > s)
            {
                float f = table.TotalHeight;

                if (table.TotalHeight > 675 * page)
                {
                    b = m - 1;
                }
                else
                {
                    s = m + 1;
                }
                m = (b + s) / 2;
                table.DeleteLastRow();
                str  = content.Substring(0, m);
                cell = new PdfPCell(new Phrase(str, font));
                cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
                cell.MinimumHeight       = 300f;
                cell.SetLeading(0, 1.5f);
                cell.BorderWidthTop  = 0;
                cell.BorderWidthLeft = 0;
                table.AddCell(cell);
            }
            s = content.Length - 1;
            return(content.Substring(b, s - b));
        }
Example #4
0
        public MemoryStream GeneratePdfTemplate(CostCalculationRetailViewModel 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);
            Font     bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font     font_9      = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);
            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. EFRATA RETAILINDO", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "COST CALCULATION RETAIL", 10, 805, 0);
            cb.EndText();
            #endregion

            #region Top
            PdfPTable table_top = new PdfPTable(9);
            table_top.TotalWidth = 500f;

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

            PdfPCell cell_top = 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
            };
            PdfPCell cell_top_keterangan = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2, Colspan = 7
            };
            cell_colon.Phrase = new Phrase(":", normal_font);

            cell_top.Phrase = new Phrase("RO", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.RO}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("BUYER", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Buyer.Name}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("OL", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            double OLValue = viewModel.OL.Value ?? 0;
            string OL      = OLValue > 0 ? OLValue.ToString() + " menit" : OLValue.ToString();
            cell_top.Phrase = new Phrase($"{OL}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("ARTICLE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Article}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("DELIVERY", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.DeliveryDate.ToString("dd MMMM yyyy")}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("OTL 1", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            double OTL1Value = viewModel.OTL1.Value ?? 0;
            string OTL1      = OTL1Value > 0 ? OTL1Value.ToString() + " detik" : OTL1Value.ToString();
            cell_top.Phrase = new Phrase($"{OTL1}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("STYLE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Style.name}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("SIZE RANGE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.SizeRange.Name}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("OTL 2", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            double OTL2Value = viewModel.OTL2.Value ?? 0;
            string OTL2      = OTL2Value > 0 ? OTL2Value.ToString() + " detik" : OTL2Value.ToString();
            cell_top.Phrase = new Phrase($"{OTL2}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("SEASON", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Season.name}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("EFFICIENCY", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Efficiency.Value}%", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("OTL 3", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            double OTL3Value = viewModel.OTL3.Value ?? 0;
            string OTL3      = OTL3Value > 0 ? OTL3Value.ToString() + " detik" : OTL3Value.ToString();
            cell_top.Phrase = new Phrase($"{OTL3}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("COUNTER", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Counter.name}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("RISK", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Risk}%", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("TOTAL SMV", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            double STD_HourValue = viewModel.SH_Cutting.Value + viewModel.SH_Finishing.Value + viewModel.SH_Sewing.Value;
            string STD_Hour      = STD_HourValue > 0 ? STD_HourValue.ToString() : STD_HourValue.ToString();
            cell_top.Phrase = new Phrase($"{STD_Hour}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("KETERANGAN", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top_keterangan.Phrase = new Phrase($"{viewModel.Description}", normal_font);
            table_top.AddCell(cell_top_keterangan);
            #endregion

            #region Draw 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_top.WriteSelectedRows(0, -1, 10, row1Y, cb);
            #endregion

            #region Detail (Bottom, Column 1.2)
            PdfPTable table_detail = new PdfPTable(2);
            table_detail.TotalWidth = 280f;

            float[] detail_widths = new float[] { 1f, 1f };
            table_detail.SetWidths(detail_widths);

            PdfPCell cell_detail = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5, Rowspan = 4
            };

            double total = Convert.ToDouble(viewModel.OL.CalculatedValue + viewModel.OTL1.CalculatedValue + viewModel.OTL2.CalculatedValue + viewModel.OTL3.CalculatedValue);
            cell_detail.Phrase = new Phrase(
                "OL".PadRight(22) + ": " + viewModel.OL.CalculatedValue + Environment.NewLine + Environment.NewLine +
                "OTL 1".PadRight(20) + ": " + viewModel.OTL1.CalculatedValue + Environment.NewLine + Environment.NewLine +
                "OTL 2".PadRight(20) + ": " + viewModel.OTL2.CalculatedValue + Environment.NewLine + Environment.NewLine +
                "OTL 3".PadRight(20) + ": " + viewModel.OTL3.CalculatedValue + Environment.NewLine + Environment.NewLine +
                "Total".PadRight(22) + ": " + total + Environment.NewLine
                , normal_font);
            table_detail.AddCell(cell_detail);

            cell_detail = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_BOTTOM, Padding = 5
            };
            cell_detail.Phrase = new Phrase("HPP", normal_font);
            table_detail.AddCell(cell_detail);
            cell_detail = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5
            };
            cell_detail.Phrase = new Phrase(Number.ToRupiah(viewModel.HPP), font_9);
            table_detail.AddCell(cell_detail);
            cell_detail = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_BOTTOM, Padding = 5
            };
            cell_detail.Phrase = new Phrase("Wholesale Price: HPP X 2.20", normal_font);
            table_detail.AddCell(cell_detail);
            cell_detail = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5
            };
            cell_detail.Phrase = new Phrase(Number.ToRupiah(viewModel.WholesalePrice), font_9);
            table_detail.AddCell(cell_detail);
            #endregion

            #region Signature (Bottom, Column 1.2)
            PdfPTable table_signature = new PdfPTable(3);
            table_signature.TotalWidth = 280f;

            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("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);
            cell_signature.Phrase = new Phrase("Ka. Sie Merchandiser", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Direktur Operasional", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Wakil Direktur Utama", 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("(                           )", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Haenis Gunarto ", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ninuk Setyawati", normal_font);
            table_signature.AddCell(cell_signature);
            #endregion

            #region Price (Bottom, Column 2)
            PdfPTable table_price = new PdfPTable(5);
            table_price.TotalWidth = 280f;

            float[] price_widths = new float[] { 1.6f, 3f, 3f, 4f, 1f };
            table_price.SetWidths(price_widths);

            PdfPCell cell_price_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_price_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_price_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_price_center.Phrase = new Phrase("KET (X)", bold_font);
            table_price.AddCell(cell_price_center);
            cell_price_center.Phrase = new Phrase("HARGA (Rp)", bold_font);
            table_price.AddCell(cell_price_center);
            cell_price_center.Phrase = new Phrase("PEMBULATAN HARGA (Rp)", bold_font);
            table_price.AddCell(cell_price_center);
            cell_price_center.Phrase = new Phrase("KETERANGAN", bold_font);
            table_price.AddCell(cell_price_center);
            cell_price_center.Phrase = new Phrase("", bold_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed20), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding20), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding20") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.1", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed21), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding21), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding21") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.2", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed22), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding22), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding22") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.3", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed23), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding23), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding23") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.4", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed24), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding24), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding24") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.5", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed25), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding25), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding25") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.6", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed26), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding26), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding26") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.7", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed27), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding27), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding27") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.8", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed28), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding28), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding28") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("2.9", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed29), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding29), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding29") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("3.0", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed30), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding30), normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding30") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);

            cell_price_left.Phrase = new Phrase("Others", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_right.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_right.Phrase = new Phrase(viewModel.RoundingOthers > 0 ? Number.ToRupiahWithoutSymbol(viewModel.RoundingOthers) : "", normal_font);
            table_price.AddCell(cell_price_right);
            cell_price_left.Phrase = new Phrase("", normal_font);
            table_price.AddCell(cell_price_left);
            cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("RoundingOthers") ? "*" : "", normal_font);
            table_price.AddCell(cell_price_center);
            #endregion

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

            float[] ccm_widths = new float[] { 1.25f, 3.5f, 4f, 9f, 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("CATEGORIES", bold_font);
            table_ccm.AddCell(cell_ccm_center);

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

            cell_ccm_center.Phrase = new Phrase("DESCRIPTION", 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_top.TotalHeight ? imageHeight : table_top.TotalHeight;
            float  row2Y               = row1Y - row1Height - 10;
            float  calculatedHppHeight = 7;
            float  row3LeftHeight      = table_detail.TotalHeight + 5 + table_signature.TotalHeight;
            float  row3RightHeight     = table_price.TotalHeight;
            float  row3Height          = row3LeftHeight > row3RightHeight ? row3LeftHeight : row3RightHeight;
            float  remainingRow2Height = row2Y - 10 - row3Height - printedOnHeight - margin;
            float  allowedRow2Height   = row2Y - printedOnHeight - margin;
            for (int i = 0; i < viewModel.CostCalculationRetail_Materials.Count; i++)
            {
                cell_ccm_center.Phrase = new Phrase((i + 1).ToString(), normal_font);
                table_ccm.AddCell(cell_ccm_center);

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

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

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

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

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

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

                float currentHeight = table_ccm.TotalHeight;
                if (currentHeight / remainingRow2Height > 1)
                {
                    if (currentHeight / allowedRow2Height > 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;
                        remainingRow2Height = row2Y - 10 - row3Height - printedOnHeight - margin;
                        allowedRow2Height   = 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 remainingRow3Height = row3Y - printedOnHeight - margin;
            if (remainingRow3Height < row3Height)
            {
                this.DrawPrintedOn(now, bf, cb);
                row3Y = startY;
                document.NewPage();
            }

            #region Calculated HPP
            float calculatedHppY = row3Y - calculatedHppHeight;
            cb.BeginText();
            cb.SetFontAndSize(bf, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "KALKULASI HPP: (OL + OTL1 + OTL2 + FABRIC + ACC) + ((OL + OTL1 + OTL2 + FABRIC + ACC) * Risk)", 10, calculatedHppY, 0);
            cb.EndText();
            #endregion

            float table_detailY = calculatedHppY - 5;
            table_detail.WriteSelectedRows(0, -1, 10, table_detailY, cb);

            float table_signatureY = table_detailY - row3Height + table_signature.TotalHeight;
            table_signature.WriteSelectedRows(0, -1, 10, table_signatureY, cb);

            table_price.WriteSelectedRows(0, -1, 300, table_detailY, 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 MemoryStream GeneratePdfTemplate(CostCalculationRetailViewModel 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(8);
            table_detail1.TotalWidth = 570f;

            float[] detail1_widths = new float[] { 1f, 0.1f, 2f, 3f, 1f, 0.1f, 2f, 3f };
            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("", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("SEASON", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Season.name}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("", normal_font);
            table_detail1.AddCell(cell_detail1);
            #endregion

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

            #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 ol          = viewModel.OL.CalculatedValue ?? 0;
            double processCost = ol;
            #endregion

            for (int i = 0; i < viewModel.CostCalculationRetail_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.CostCalculationRetail_Materials[i].Category.SubCategory != null ? String.Format("{0} - {1}", viewModel.CostCalculationRetail_Materials[i].Category.Name, viewModel.CostCalculationRetail_Materials[i].Category.SubCategory) : viewModel.CostCalculationRetail_Materials[i].Category.Name, normal_font);
                table_ccm.AddCell(cell_ccm);

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

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

                cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT;

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

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

                double factor;
                if (viewModel.CostCalculationRetail_Materials[i].Category.Name == "ACC")
                {
                    factor = viewModel.AccessoriesAllowance ?? 0;
                }
                else
                {
                    factor = viewModel.FabricAllowance ?? 0;
                }
                double totalQuantity   = viewModel.Quantity ?? 0;
                double conversion      = (double)viewModel.CostCalculationRetail_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.CostCalculationRetail_Materials[i].UOMPrice.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.CostCalculationRetail_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 = viewModel.HPP;
            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);

            cell_detail3.Border = Rectangle.LEFT_BORDER;
            cell_detail3.Phrase = new Phrase("", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3.Border = Rectangle.RIGHT_BORDER;
            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;
            double SH_Cutting = viewModel.SH_Cutting ?? 0;
            cell_detail3.Phrase = new Phrase($"{SH_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;
            double SH_Sewing = viewModel.SH_Sewing ?? 0;
            cell_detail3.Phrase = new Phrase($"{SH_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;
            double SH_Finishing = viewModel.SH_Finishing ?? 0;
            cell_detail3.Phrase = new Phrase($"{SH_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;
            double SH_Total = SH_Cutting + SH_Sewing + SH_Finishing;
            cell_detail3.Phrase = new Phrase($"{SH_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);
            #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 - 20;
            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);
        }
Example #6
0
    private decimal GeneraReporte(Document document)
    {
        // Tipo de Font que vamos utilizar
        iTextSharp.text.Font fuente1 = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
        iTextSharp.text.Font fuente2 = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 7, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);

        PdfPTable tblCierres = new PdfPTable(11);

        tblCierres.WidthPercentage = 100f;
        PdfPCell clfe = new PdfPCell(new Phrase("FECHA", fuente1));

        clfe.BorderWidthBottom   = 1;
        clfe.HorizontalAlignment = 1;
        clfe.VerticalAlignment   = 1;
        clfe.Padding             = 1;
        PdfPCell clIsla = new PdfPCell(new Phrase("TIENDA", fuente1));

        clIsla.BorderWidthBottom   = 1;
        clIsla.HorizontalAlignment = 1;
        clIsla.VerticalAlignment   = 1;
        clIsla.Padding             = 1;
        PdfPCell clefec = new PdfPCell(new Phrase("EFECTIVO", fuente1));

        clefec.BorderWidthBottom   = 1;
        clefec.HorizontalAlignment = 1;
        clefec.VerticalAlignment   = 1;
        clefec.Padding             = 1;
        PdfPCell cldeb = new PdfPCell(new Phrase("T.DÉBITO", fuente1));

        cldeb.BorderWidthBottom   = 1;
        cldeb.HorizontalAlignment = 1;
        cldeb.VerticalAlignment   = 1;
        cldeb.Padding             = 1;
        PdfPCell clcred = new PdfPCell(new Phrase("T.CRÉDITO", fuente1));

        clcred.BorderWidthBottom   = 1;
        clcred.HorizontalAlignment = 1;
        clcred.VerticalAlignment   = 1;
        clcred.Padding             = 1;

        PdfPCell clpagserv = new PdfPCell(new Phrase("PAGO SERVICIOS", fuente1));

        clcred.BorderWidthBottom   = 1;
        clcred.HorizontalAlignment = 1;
        clcred.VerticalAlignment   = 1;
        clcred.Padding             = 1;
        PdfPCell clrecar = new PdfPCell(new Phrase("RECARGAS", fuente1));

        clcred.BorderWidthBottom   = 1;
        clcred.HorizontalAlignment = 1;
        clcred.VerticalAlignment   = 1;
        clcred.Padding             = 1;

        PdfPCell clgas = new PdfPCell(new Phrase("GASTOS", fuente1));

        clgas.BorderWidthBottom   = 1;
        clgas.HorizontalAlignment = 1;
        clgas.VerticalAlignment   = 1;
        clgas.Padding             = 1;
        PdfPCell clcan = new PdfPCell(new Phrase("CANCELACION", fuente1));

        clcan.BorderWidthBottom   = 1;
        clcan.HorizontalAlignment = 1;
        clcan.VerticalAlignment   = 1;
        clcan.Padding             = 1;
        PdfPCell clfon = new PdfPCell(new Phrase("FONDO", fuente1));

        clfon.BorderWidthBottom   = 1;
        clfon.HorizontalAlignment = 1;
        clfon.VerticalAlignment   = 1;
        clfon.Padding             = 1;
        PdfPCell cltotal = new PdfPCell(new Phrase("TOTAL", fuente1));

        cltotal.BorderWidthBottom   = 1;
        cltotal.HorizontalAlignment = 1;
        cltotal.VerticalAlignment   = 1;
        cltotal.Padding             = 1;

        tblCierres.AddCell(clfe);
        tblCierres.AddCell(clIsla);
        tblCierres.AddCell(clefec);
        tblCierres.AddCell(cldeb);
        tblCierres.AddCell(clcred);

        tblCierres.AddCell(clpagserv);
        tblCierres.AddCell(clrecar);

        tblCierres.AddCell(clgas);
        tblCierres.AddCell(clcan);
        tblCierres.AddCell(clfon);
        tblCierres.AddCell(cltotal);

        int       tamañodatos = 0;
        BaseDatos data        = new BaseDatos();

        string sqlCierres = string.Format("SELECT CONVERT(char(10), c.fecha_cierre, 126) AS fecha, c.efectivo, c.debito, c.credito, c.gastos, c.fondo, c.total, g.nombre, c.id_punto_venta, c.usuario_cierre,c.id_cierre, c.cancelaciones,c.pagoservicios,c.recargas " +
                                          "FROM cierres_diarios AS c " +
                                          "INNER JOIN usuarios_PV AS u ON u.usuario = c.usuario_cierre " +
                                          "INNER JOIN catalmacenes AS g ON c.id_punto_venta = g.idAlmacen " +
                                          "WHERE (fecha_cierre BETWEEN '{0}' AND '{1}')", fecha_ini, fecha_fin);

        if (_usuSelec != "")
        {
            sqlCierres = string.Format(sqlCierres + " AND usuario_cierre IN({0})", _usuSelec);
        }

        sqlCierres = sqlCierres + " ORDER BY fecha_cierre";

        object[] camposcab = data.scalarData(sqlCierres);
        decimal  acumulado = 0;

        if (Convert.ToBoolean(camposcab[0]))
        {
            DataSet datos = (DataSet)camposcab[1];

            foreach (DataRow fila in datos.Tables[0].Rows)
            {
                PdfPCell fecha   = new PdfPCell(new Phrase(fila[0].ToString(), fuente2));
                PdfPCell isla    = new PdfPCell(new Phrase(fila[7].ToString(), fuente2));
                PdfPCell efect   = new PdfPCell(new Phrase(Convert.ToDecimal(fila[1].ToString()).ToString("C2"), fuente2));
                PdfPCell debi    = new PdfPCell(new Phrase(Convert.ToDecimal(fila[2].ToString()).ToString("C2"), fuente2));
                PdfPCell cred    = new PdfPCell(new Phrase(Convert.ToDecimal(fila[3].ToString()).ToString("C2"), fuente2));
                PdfPCell gast    = new PdfPCell(new Phrase(Convert.ToDecimal(fila[4].ToString()).ToString("C2"), fuente2));
                PdfPCell canc    = new PdfPCell(new Phrase(Convert.ToDecimal(fila[11].ToString()).ToString("C2"), fuente2));
                PdfPCell recar   = new PdfPCell(new Phrase(Convert.ToDecimal(fila[12].ToString()).ToString("C2"), fuente2));
                PdfPCell pagServ = new PdfPCell(new Phrase(Convert.ToDecimal(fila[13].ToString()).ToString("C2"), fuente2));
                decimal  fodos   = 0;
                try { fodos = Convert.ToDecimal(fila[5].ToString()); }
                catch (Exception) { fodos = 0; }
                PdfPCell fond = new PdfPCell(new Phrase(fodos.ToString("C2"), fuente2));
                PdfPCell tota = new PdfPCell(new Phrase(Convert.ToDecimal(fila[6].ToString()).ToString("C2"), fuente2));

                fecha.BorderWidth         = 0;
                fecha.HorizontalAlignment = 1;
                fecha.VerticalAlignment   = 1;
                fecha.Padding             = 1;
                isla.BorderWidth          = 0;
                isla.HorizontalAlignment  = 1;
                isla.VerticalAlignment    = 1;
                isla.Padding              = 1;
                efect.BorderWidth         = 0;
                efect.HorizontalAlignment = 1;
                efect.VerticalAlignment   = 1;
                efect.Padding             = 1;
                debi.BorderWidth          = 0;
                debi.HorizontalAlignment  = 1;
                debi.VerticalAlignment    = 1;
                debi.Padding              = 1;
                cred.BorderWidth          = 0;
                cred.HorizontalAlignment  = 1;
                cred.VerticalAlignment    = 1;
                cred.Padding              = 1;
                gast.BorderWidth          = 0;
                gast.HorizontalAlignment  = 1;
                gast.VerticalAlignment    = 1;
                gast.Padding              = 1;
                canc.BorderWidth          = 0;
                canc.HorizontalAlignment  = 1;
                canc.VerticalAlignment    = 1;
                canc.Padding              = 1;

                pagServ.BorderWidth         = 0;
                pagServ.HorizontalAlignment = 1;
                pagServ.VerticalAlignment   = 1;
                pagServ.Padding             = 1;

                recar.BorderWidth         = 0;
                recar.HorizontalAlignment = 1;
                recar.VerticalAlignment   = 1;
                recar.Padding             = 1;

                fond.BorderWidth         = 0;
                fond.HorizontalAlignment = 1;
                fond.VerticalAlignment   = 1;
                fond.Padding             = 1;
                tota.BorderWidth         = 0;
                tota.HorizontalAlignment = 1;
                tota.VerticalAlignment   = 1;
                tota.Padding             = 1;

                tblCierres.AddCell(fecha);
                tblCierres.AddCell(isla);
                tblCierres.AddCell(efect);
                tblCierres.AddCell(debi);
                tblCierres.AddCell(cred);

                tblCierres.AddCell(pagServ);
                tblCierres.AddCell(recar);

                tblCierres.AddCell(gast);
                tblCierres.AddCell(canc);
                tblCierres.AddCell(fond);
                tblCierres.AddCell(tota);

                document.Add(tblCierres);
                document.Add(new Paragraph(" "));
                obtieneUsuarios(document, fila[0].ToString(), fila[8].ToString(), Convert.ToInt32(fila[10].ToString()));
                tblCierres.DeleteLastRow();

                tamañodatos++;
            }
        }

        return(acumulado);
    }
        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);
        }
Example #8
0
        public MemoryStream GeneratePdfTemplate(RO_RetailViewModel 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);
            Font     bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font     font_9      = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);
            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. EFRATA RETAILINDO", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "RO RETAIL", 10, 805, 0);
            cb.EndText();
            #endregion


            #region Top

            PdfPTable table_top  = new PdfPTable(9);
            float[]   top_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1f, 0.1f, 2f };

            table_top.TotalWidth = 500f;
            table_top.SetWidths(top_widths);

            PdfPCell cell_top = 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
            };

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

            cell_colon.Phrase = new Phrase(":", normal_font);
            cell_top.Phrase   = new Phrase("NO RO", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationRetail.RO}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("ARTICLE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationRetail.Article}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("STYLE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationRetail.Style.name}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("COUNTER", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationRetail.Counter.name}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("COLOUR", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Color.name}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("DELIVERY DATE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationRetail.DeliveryDate.ToString("dd MMMM yyyy")}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("RO QUANTITY", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top_keterangan.Phrase = new Phrase($"{viewModel.Total}", normal_font);
            table_top.AddCell(cell_top_keterangan);
            #endregion

            #region Image

            byte[] imageByte;
            try
            {
                imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.CostCalculationRetail.ImageFile));
            }
            catch (Exception)
            {
                var webClient = new WebClient();
                imageByte = webClient.DownloadData("https://bateeqstorage.blob.core.windows.net/other/no-image.jpg");
            }

            Image image = Image.GetInstance(imgb: imageByte);

            if (image.Width > 60)
            {
                float percentage = 0.0f;
                percentage = 60 / image.Width;
                image.ScalePercent(percentage * 100);
            }
            #endregion

            #region Draw Top

            float row1Y  = 800;
            float imageY = 800 - image.ScaledHeight;

            table_top.WriteSelectedRows(0, -1, 10, row1Y, cb);
            image.SetAbsolutePosition(520, imageY);
            cb.AddImage(image, inlineImage: true);
            #endregion

            #region Fabric Table Title

            PdfPTable table_fabric_top = new PdfPTable(1);
            table_fabric_top.TotalWidth = 570f;

            float[] fabric_widths_top = new float[] { 5f };
            table_fabric_top.SetWidths(fabric_widths_top);

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

            cell_top_fabric.Phrase = new Phrase("FABRIC", bold_font);
            table_fabric_top.AddCell(cell_top_fabric);

            float row1Height        = image.ScaledHeight > table_top.TotalHeight ? image.ScaledHeight : table_top.TotalHeight;
            float rowYTittleFab     = row1Y - row1Height - 10;
            float allowedRow2Height = rowYTittleFab - printedOnHeight - margin;
            table_fabric_top.WriteSelectedRows(0, -1, 10, rowYTittleFab, cb);
            #endregion

            #region Fabric Table
            PdfPTable table_fabric = new PdfPTable(5);
            table_fabric.TotalWidth = 570f;

            float[] fabric_widths = new float[] { 5f, 5f, 5f, 5f, 5f };
            table_fabric.SetWidths(fabric_widths);

            PdfPCell cell_fabric_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_fabric_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
            };

            float rowYFab = rowYTittleFab - table_fabric_top.TotalHeight - 5;
            float allowedRow2HeightFab = rowYFab - printedOnHeight - margin;

            cell_fabric_center.Phrase = new Phrase("FABRIC", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("NAME", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("DESCRIPTION", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("QUANTITY", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("REMARK", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            foreach (var materialModel in viewModel.CostCalculationRetail.CostCalculationRetail_Materials)
            {
                if (materialModel.Category.Name == "FAB")
                {
                    cell_fabric_left.Phrase = new Phrase(materialModel.Category.SubCategory != null ? materialModel.Category.SubCategory : "", normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Material.Name != null ? materialModel.Material.Name : "", normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Description != null ? materialModel.Description : "", normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Quantity != null ? String.Format("{0} " + materialModel.UOMQuantity.Name, materialModel.Quantity) : "0", normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Information != null ? materialModel.Information : "", normal_font);
                    table_fabric.AddCell(cell_fabric_left);
                }
            }

            table_fabric.WriteSelectedRows(0, -1, 10, rowYFab, cb);
            #endregion


            #region Accessoris Table Title

            PdfPTable table_acc_top = new PdfPTable(1);
            table_acc_top.TotalWidth = 570f;

            float[] acc_width_top = new float[] { 5f };
            table_acc_top.SetWidths(acc_width_top);

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

            cell_top_acc.Phrase = new Phrase("ACCESSORIES", bold_font);
            table_acc_top.AddCell(cell_top_acc);

            float rowYTittleAcc           = rowYFab - table_fabric.TotalHeight - 10;
            float allowedRow2HeightTopAcc = rowYTittleFab - printedOnHeight - margin;
            table_acc_top.WriteSelectedRows(0, -1, 10, rowYTittleAcc, cb);
            #endregion

            #region Accessoris Table

            PdfPTable table_accessories = new PdfPTable(5);
            table_accessories.TotalWidth = 570f;

            float[] accessories_widths = new float[] { 5f, 5f, 5f, 5f, 5f };
            table_accessories.SetWidths(accessories_widths);

            PdfPCell cell_acc_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_acc_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
            };

            float rowYAcc = rowYTittleAcc - table_fabric_top.TotalHeight - 5;
            float allowedRow2HeightAcc = rowYAcc - printedOnHeight - margin;

            cell_acc_center.Phrase = new Phrase("ACCESSORIES", bold_font);
            table_accessories.AddCell(cell_acc_center);

            cell_acc_center.Phrase = new Phrase("NAME", bold_font);
            table_accessories.AddCell(cell_acc_center);

            cell_acc_center.Phrase = new Phrase("DESCRIPTION", bold_font);
            table_accessories.AddCell(cell_acc_center);

            cell_acc_center.Phrase = new Phrase("QUANTITY", bold_font);
            table_accessories.AddCell(cell_acc_center);

            cell_acc_center.Phrase = new Phrase("REMARK", bold_font);
            table_accessories.AddCell(cell_acc_center);

            foreach (var materialModel in viewModel.CostCalculationRetail.CostCalculationRetail_Materials)
            {
                if (materialModel.Category.Name == "ACC")
                {
                    cell_acc_left.Phrase = new Phrase(materialModel.Category.SubCategory != null ? materialModel.Category.SubCategory : "", normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Material.Name != null ? materialModel.Material.Name : "", normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Description != null ? materialModel.Description : "", normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Quantity != null ? String.Format("{0} " + materialModel.UOMQuantity.Name, materialModel.Quantity) : "0", normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Information != null ? materialModel.Information : "", normal_font);
                    table_accessories.AddCell(cell_acc_left);
                }
            }

            table_accessories.WriteSelectedRows(0, -1, 10, rowYAcc, cb);
            #endregion

            #region Ongkos Table Title

            PdfPTable table_ong_top = new PdfPTable(1);
            table_ong_top.TotalWidth = 570f;

            float[] ong_width_top = new float[] { 5f };
            table_ong_top.SetWidths(ong_width_top);

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

            cell_top_ong.Phrase = new Phrase("ONGKOS", bold_font);
            table_ong_top.AddCell(cell_top_ong);

            float rowYTittleOng           = rowYAcc - table_accessories.TotalHeight - 10;
            float allowedRow2HeightTopOng = rowYTittleOng - printedOnHeight - margin;

            #endregion

            #region Ongkos Table

            PdfPTable table_budget = new PdfPTable(5);
            table_budget.TotalWidth = 570f;

            float[] budget_widths = new float[] { 5f, 5f, 5f, 5f, 5f };
            table_budget.SetWidths(budget_widths);

            var ongIndex = 0;

            PdfPCell cell_budget_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_budget_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
            };

            float rowYBudget = rowYTittleOng - table_ong_top.TotalHeight - 5;
            float allowedRow2HeightBudget = rowYBudget - printedOnHeight - margin;

            cell_budget_center.Phrase = new Phrase("ONGKOS", bold_font);
            table_budget.AddCell(cell_budget_center);

            cell_budget_center.Phrase = new Phrase("NAME", bold_font);
            table_budget.AddCell(cell_budget_center);

            cell_budget_center.Phrase = new Phrase("DESCRIPTION", bold_font);
            table_budget.AddCell(cell_budget_center);

            cell_budget_center.Phrase = new Phrase("QUANTITY", bold_font);
            table_budget.AddCell(cell_budget_center);

            cell_budget_center.Phrase = new Phrase("REMARK", bold_font);
            table_budget.AddCell(cell_budget_center);

            foreach (var materialModel in viewModel.CostCalculationRetail.CostCalculationRetail_Materials)
            {
                if (materialModel.Category.Name == "ONG")
                {
                    cell_budget_left.Phrase = new Phrase(materialModel.Category.SubCategory != null ? materialModel.Category.SubCategory : "", normal_font);
                    table_budget.AddCell(cell_budget_left);

                    cell_budget_left.Phrase = new Phrase(materialModel.Material.Name != null ? materialModel.Material.Name : "", normal_font);
                    table_budget.AddCell(cell_budget_left);

                    cell_budget_left.Phrase = new Phrase(materialModel.Description != null ? materialModel.Description : "", normal_font);
                    table_budget.AddCell(cell_budget_left);

                    cell_budget_left.Phrase = new Phrase(materialModel.Quantity != null ? String.Format("{0} " + materialModel.UOMQuantity.Name, materialModel.Quantity) : "0", normal_font);
                    table_budget.AddCell(cell_budget_left);

                    cell_budget_left.Phrase = new Phrase(materialModel.Information != null ? materialModel.Information : "", normal_font);
                    table_budget.AddCell(cell_budget_left);

                    ongIndex++;
                }
            }

            if (ongIndex != 0)
            {
                table_budget.WriteSelectedRows(0, -1, 10, rowYBudget, cb);
                table_ong_top.WriteSelectedRows(0, -1, 10, rowYTittleOng, cb);
            }
            #endregion

            #region Size Breakdown Title

            PdfPTable table_breakdown_top = new PdfPTable(1);
            table_breakdown_top.TotalWidth = 570f;

            float[] breakdown_width_top = new float[] { 5f };
            table_breakdown_top.SetWidths(breakdown_width_top);

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

            cell_top_breakdown.Phrase = new Phrase("SIZE BREAKDOWN", bold_font);
            table_breakdown_top.AddCell(cell_top_breakdown);

            float rowYTittleBreakDown        = rowYBudget - table_budget.TotalHeight - 10;
            float allowedRow2HeightBreakdown = rowYTittleBreakDown - printedOnHeight - margin;
            table_breakdown_top.WriteSelectedRows(0, -1, 10, rowYTittleBreakDown, cb);
            #endregion

            #region == Table Size Breakdown ==
            var tableBreakdownColumn = 3;

            PdfPCell cell_breakDown_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_breakDown_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_breakDown_total = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
                Padding             = 2
            };

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

            float rowYbreakDown = rowYTittleBreakDown - table_breakdown_top.TotalHeight - 5;
            float allowedRow2HeightBreakDown   = rowYbreakDown - printedOnHeight - margin;
            var   remainingRowToHeightBrekdown = rowYbreakDown - 5 - printedOnHeight - margin;

            List <String> breakdownSizes = new List <string>();

            foreach (var size in viewModel.RO_Retail_SizeBreakdowns)
            {
                var sizes = size.SizeQuantity.Keys;

                foreach (var values in sizes)
                {
                    if (!breakdownSizes.Contains(values))
                    {
                        breakdownSizes.Add(values);
                        tableBreakdownColumn++;
                    }
                }
            }

            PdfPTable table_breakDown = new PdfPTable(tableBreakdownColumn);
            table_breakDown.TotalWidth = 570f;


            cell_breakDown_center.Phrase = new Phrase("STORE CODE", bold_font);
            table_breakDown.AddCell(cell_breakDown_center);

            cell_breakDown_center.Phrase = new Phrase("STORE", bold_font);
            table_breakDown.AddCell(cell_breakDown_center);

            foreach (var size in breakdownSizes)
            {
                cell_breakDown_center.Phrase = new Phrase(size, bold_font);
                table_breakDown.AddCell(cell_breakDown_center);
            }

            cell_breakDown_center.Phrase = new Phrase("TOTAL", bold_font);
            table_breakDown.AddCell(cell_breakDown_center);

            foreach (var productRetail in viewModel.RO_Retail_SizeBreakdowns)
            {
                if (productRetail.Total != 0)
                {
                    cell_breakDown_left.Phrase = new Phrase(productRetail.Store.code != null ? productRetail.Store.code : "", normal_font);
                    table_breakDown.AddCell(cell_breakDown_left);

                    cell_breakDown_left.Phrase = new Phrase(productRetail.Store.name != null ? productRetail.Store.name : "", normal_font);
                    table_breakDown.AddCell(cell_breakDown_left);

                    foreach (var size in productRetail.SizeQuantity)
                    {
                        foreach (var sizeHeader in breakdownSizes)
                        {
                            if (size.Key == sizeHeader)
                            {
                                cell_breakDown_left.Phrase = new Phrase(size.Value.ToString() != null ? size.Value.ToString() : "0", normal_font);
                                table_breakDown.AddCell(cell_breakDown_left);
                            }
                        }
                    }

                    cell_breakDown_left.Phrase = new Phrase(productRetail.Total.ToString() != null ? productRetail.Total.ToString() : "0", normal_font);
                    table_breakDown.AddCell(cell_breakDown_left);
                }

                var tableBreakdownCurrentHeight = table_breakDown.TotalHeight;

                if (tableBreakdownCurrentHeight / remainingRowToHeightBrekdown > 1)
                {
                    if (tableBreakdownCurrentHeight / allowedRow2HeightBreakDown > 1)
                    {
                        PdfPRow headerRow = table_breakDown.GetRow(0);
                        PdfPRow lastRow   = table_breakDown.GetRow(table_breakDown.Rows.Count - 1);
                        table_breakDown.DeleteLastRow();
                        table_breakDown.WriteSelectedRows(0, -1, 10, rowYbreakDown, cb);
                        table_breakDown.DeleteBodyRows();
                        this.DrawPrintedOn(now, bf, cb);
                        document.NewPage();
                        table_breakDown.Rows.Add(headerRow);
                        table_breakDown.Rows.Add(lastRow);
                        table_breakDown.CalculateHeights();
                        rowYbreakDown = startY;
                        remainingRowToHeightBrekdown = rowYbreakDown - 5 - printedOnHeight - margin;
                        allowedRow2HeightBreakDown   = remainingRowToHeightBrekdown - printedOnHeight - margin;
                    }
                }
            }

            cell_breakDown_total.Phrase = new Phrase(" ", bold_font);
            table_breakDown.AddCell(cell_breakDown_total);

            cell_breakDown_total_2.Phrase = new Phrase("TOTAL", bold_font);
            table_breakDown.AddCell(cell_breakDown_total_2);

            foreach (var sizeTotal in viewModel.SizeQuantityTotal)
            {
                cell_breakDown_left.Phrase = new Phrase(sizeTotal.Value.ToString() != null ? sizeTotal.Value.ToString() : "0", normal_font);
                table_breakDown.AddCell(cell_breakDown_left);
            }
            cell_breakDown_left.Phrase = new Phrase(viewModel.Total.ToString() != null ? viewModel.Total.ToString() : "0", normal_font);
            table_breakDown.AddCell(cell_breakDown_left);

            table_breakDown.WriteSelectedRows(0, -1, 10, rowYbreakDown, cb);
            #endregion

            #region Table Instruksi

            PdfPTable table_instruction  = new PdfPTable(1);
            float[]   instruction_widths = new float[] { 5f };

            table_instruction.TotalWidth = 500f;
            table_instruction.SetWidths(instruction_widths);

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

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

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

            cell_top_instruction.Phrase = new Phrase("INSTRUCTION", normal_font);
            table_instruction.AddCell(cell_top_instruction);
            table_instruction.AddCell(cell_colon_instruction);
            cell_top_keterangan_instruction.Phrase = new Phrase($"{viewModel.Instruction}", normal_font);
            table_instruction.AddCell(cell_top_keterangan_instruction);

            float rowYInstruction = rowYbreakDown - table_breakDown.TotalHeight - 5;
            float allowedRow2HeightInstruction    = rowYInstruction - printedOnHeight - margin;
            var   remainingRowToHeightInstruction = rowYInstruction - 5 - printedOnHeight - margin;
            var   tableInstructionCurrentHeight   = table_instruction.TotalHeight;

            if (remainingRowToHeightInstruction < 0)
            {
                remainingRowToHeightInstruction = remainingRowToHeightInstruction * -1;
            }

            if (allowedRow2HeightInstruction < 0)
            {
                allowedRow2HeightInstruction = allowedRow2HeightInstruction * -1;
            }

            if (tableInstructionCurrentHeight / remainingRowToHeightInstruction > 1)
            {
                if (tableInstructionCurrentHeight / allowedRow2HeightInstruction > 1)
                {
                    PdfPRow headerRow = table_instruction.GetRow(0);
                    PdfPRow lastRow   = table_instruction.GetRow(table_instruction.Rows.Count - 1);
                    table_instruction.DeleteLastRow();
                    table_instruction.WriteSelectedRows(0, -1, 10, rowYInstruction, cb);
                    table_instruction.DeleteBodyRows();
                    this.DrawPrintedOn(now, bf, cb);
                    document.NewPage();
                    table_instruction.Rows.Add(headerRow);
                    table_instruction.Rows.Add(lastRow);
                    table_instruction.CalculateHeights();
                    rowYInstruction = startY;
                    remainingRowToHeightInstruction = rowYInstruction - 5 - printedOnHeight - margin;
                    allowedRow2HeightInstruction    = remainingRowToHeightInstruction - printedOnHeight - margin;
                }
            }

            table_instruction.WriteSelectedRows(0, -1, 10, rowYInstruction, cb);
            #endregion

            #region RO Image
            var    countImageRo = 0;
            byte[] roImage;

            foreach (var index in viewModel.ImagesFile)
            {
                countImageRo++;
            }

            if (countImageRo > 5)
            {
                countImageRo = 5;
            }

            PdfPTable table_ro_image = new PdfPTable(countImageRo);
            float[]   ro_widths      = new float[countImageRo];

            for (var i = 0; i < countImageRo; i++)
            {
                ro_widths.SetValue(5f, i);
            }

            if (countImageRo != 0)
            {
                table_ro_image.SetWidths(ro_widths);
            }

            table_ro_image.TotalWidth = 570f;
            float rowYRoImage = rowYInstruction - table_instruction.TotalHeight - 5;

            foreach (var imageFromRo in viewModel.ImagesFile)
            {
                try
                {
                    roImage = Convert.FromBase64String(Base64.GetBase64File(imageFromRo));
                }
                catch (Exception)
                {
                    var webClient = new WebClient();
                    roImage = webClient.DownloadData("https://bateeqstorage.blob.core.windows.net/other/no-image.jpg");
                }

                Image images = Image.GetInstance(imgb: roImage);

                if (images.Width > 60)
                {
                    float percentage = 0.0f;
                    percentage = 60 / images.Width;
                    images.ScalePercent(percentage * 100);
                }

                PdfPCell imageCell = new PdfPCell(images);
                imageCell.Border = 0;
                table_ro_image.AddCell(imageCell);
            }

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

            foreach (var name in viewModel.ImagesName)
            {
                cell_image.Phrase = new Phrase(name, normal_font);
                table_ro_image.AddCell(cell_image);
            }

            table_ro_image.WriteSelectedRows(0, -1, 10, rowYRoImage, cb);
            #endregion

            #region Signature (Bottom, Column 1.2)

            PdfPTable table_signature = new PdfPTable(6);
            table_signature.TotalWidth = 570f;

            float[] signature_widths = new float[] { 1f, 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,
            };

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

            cell_signature.Phrase = new Phrase("Dibuat", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Kasie Merchandiser", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("R & D", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka Produksi", 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("Menyetujui", normal_font);
            table_signature.AddCell(cell_signature);

            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(Haenis Gunarto)", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(Michelle Tjokrosaputro)", normal_font);
            table_signature.AddCell(cell_signature_noted);

            float table_signatureY = rowYRoImage - table_ro_image.TotalHeight - 5;
            table_signature.WriteSelectedRows(0, -1, 10, table_signatureY, cb);
            #endregion

            this.DrawPrintedOn(now, bf, cb);
            document.Close();

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

            return(stream);
        }
Example #9
0
        public MemoryStream GeneratePdfTemplate(MaterialsRequestNoteViewModel viewModel)
        {
            bool IsTestOrPurchasing = string.Equals(viewModel.RequestType.ToUpper(), "TEST") || string.Equals(viewModel.RequestType.ToUpper(), "PEMBELIAN");
            //Declaring fonts.

            BaseFont bf          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            BaseFont bf_bold     = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            var      normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);
            var      small_font  = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            var      bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);

            //Creating page.

            Document     document = new Document(PageSize.A5);
            MemoryStream stream   = new MemoryStream();



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

            writer.CloseStream = false;

            document.Open();


            PdfContentByte cb = writer.DirectContent;

            //Set Header
            #region SetHeader

            cb.BeginText();
            cb.SetTextMatrix(15, 23);

            //LEFT
            cb.SetFontAndSize(bf_bold, 14);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "PT DAN LIRIS", 100, 550, 0);
            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "INDUSTRIAL & TRADING CO.LTD", 100, 535, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Kel. Banaran - Sukoharjo", 100, 520, 0);

            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "UNIT", 20, 495, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, $": {viewModel.Unit.Name}", 55, 495, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "NO", 20, 480, 0);
            cb.SetFontAndSize(bf_bold, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, $": {viewModel.Code}", 55, 480, 0);
            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "TIPE", 20, 465, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, $": {viewModel.RequestType}", 55, 465, 0);

            //RIGHT
            cb.SetFontAndSize(bf_bold, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "FM.FP-00-PC-19-008", 275, 550, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, $"Sukoharjo, {viewModel._CreatedUtc.Day} {Bulan[viewModel._CreatedUtc.Month - 1]} {viewModel._CreatedUtc.Year}", 275, 535, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Kepada Yth.", 275, 495, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "GUDANG GREIGE", 275, 480, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT DAN LIRIS - SUKOHARJO", 275, 465, 0);

            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "SURAT PERMINTAAN BARANG", 220, 435, 0);

            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Untuk memenuhi permintaan order kami mohon bantuan Saudara mengusahakan / menyiapkan", 20, 405, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "barang tersebut dibawah:", 20, 395, 0);

            cb.EndText();

            #endregion

            //Creating new table.
            #region CreateTable
            PdfPTable table = IsTestOrPurchasing ? new PdfPTable(5) : new PdfPTable(6);
            table.TotalWidth = 380f;

            //535 pixels width distribute into 8 rows.
            //string.Equals(viewModel.RequestType.ToUpper(), "TEST") ? new float[] { 2f, 2f, 15f, 5f, 5f, 5f, 5f, 5f } :
            float[] widths = IsTestOrPurchasing ? new float[] { 3f, 10f, 5f, 5f, 10f } : new float[] { 3f, 7f, 10f, 4f, 4f, 10f };
            table.SetWidths(widths);

            var cell = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            var rightCell = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            var leftCell = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            //Create cells headers.
            if (IsTestOrPurchasing)
            {
                cell.Phrase = new Phrase("No", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("Nama Barang", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("Grade", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("Meter", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("Keterangan", bold_font);
                table.AddCell(cell);
            }
            else
            {
                cell.Phrase = new Phrase("No", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("No. SPP", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("Nama Barang", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("Grade", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("Meter", bold_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("Keterangan", bold_font);
                table.AddCell(cell);
            }


            //Add all items.
            int index       = 1;
            int TotalRows   = viewModel.MaterialsRequestNote_Items.Count;
            int rowsPerPage = 8;

            foreach (var item in viewModel.MaterialsRequestNote_Items)
            {
                if (IsTestOrPurchasing)
                {
                    cell.Phrase = new Phrase(index.ToString(), small_font);
                    table.AddCell(cell);

                    leftCell.Phrase = new Phrase(item.Product.Name.Trim(), small_font);
                    table.AddCell(leftCell);

                    cell.Phrase = new Phrase(item.Grade.Trim(), small_font);
                    table.AddCell(cell);

                    rightCell.Phrase = new Phrase(item.Length.ToString(), small_font);
                    table.AddCell(rightCell);

                    leftCell.Phrase = string.IsNullOrWhiteSpace(item.Remark) ? new Phrase("-", small_font) : new Phrase(item.Remark.Trim(), small_font);
                    table.AddCell(leftCell);
                }
                else
                {
                    cell.Phrase = new Phrase(index.ToString(), small_font);
                    table.AddCell(cell);

                    leftCell.Phrase = new Phrase(item.ProductionOrder.OrderNo.Trim(), small_font);
                    table.AddCell(leftCell);

                    leftCell.Phrase = new Phrase(item.Product.Name.Trim(), small_font);
                    table.AddCell(leftCell);

                    cell.Phrase = new Phrase(item.Grade.Trim(), small_font);
                    table.AddCell(cell);

                    rightCell.Phrase = new Phrase(item.Length.ToString(), small_font);
                    table.AddCell(rightCell);

                    leftCell.Phrase = string.IsNullOrWhiteSpace(item.Remark) ? new Phrase("-", small_font) : new Phrase(item.Remark.Trim(), small_font);
                    table.AddCell(leftCell);
                }

                if (index % rowsPerPage == 0)
                {
                    if (index == rowsPerPage)
                    {
                        table.WriteSelectedRows(0, -1, 20, 385, cb);
                    }
                    else
                    {
                        table.WriteSelectedRows(0, -1, 15, 550, cb);
                    }

                    for (var i = 0; i < rowsPerPage; i++)
                    {
                        table.DeleteLastRow();
                    }

                    if (index != TotalRows)
                    {
                        document.NewPage();
                    }
                }

                index++;
            }

            leftCell.Phrase  = string.IsNullOrWhiteSpace(viewModel.Remark) ? new Phrase($"Keterangan : -", normal_font) : new Phrase($"Keterangan : {viewModel.Remark.Trim()}", normal_font);
            leftCell.Colspan = IsTestOrPurchasing ? 5 : 6;
            leftCell.Border  = Rectangle.NO_BORDER;
            table.AddCell(leftCell);

            var footerCell = new PdfPCell(new Phrase("Atas bantuan Saudara, kami ucapkan terima kasih.", normal_font));
            footerCell.Colspan = IsTestOrPurchasing ? 5 : 6;
            footerCell.Border  = Rectangle.NO_BORDER;

            table.AddCell(footerCell);
            //Save tables.

            index--;
            if (index % rowsPerPage != 0)
            {
                if (index < rowsPerPage)
                {
                    table.WriteSelectedRows(0, -1, 20, 385, cb);
                }
                else
                {
                    table.WriteSelectedRows(0, -1, 15, 550, cb);
                }
            }

            //table.WriteSelectedRows(0, -1, 20, 385, cb);
            #endregion

            //Set footer
            #region Footer

            cb.BeginText();
            cb.SetTextMatrix(15, 23);

            //LEFT
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Penerima", 60, 100, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(..........................)", 60, 50, 0);

            //CENTER
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Mengetahui", 210, 100, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(..........................)", 210, 50, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, $"Kabag {viewModel.Unit.Name}", 210, 35, 0);

            //RIGHT
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Hormat Kami", 360, 100, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, $"{viewModel._CreatedBy}", 360, 55, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(..........................)", 360, 50, 0);
            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Bag. PPIC", 360, 35, 0);

            cb.EndText();

            #endregion

            document.Close();

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

            return(stream);
        }
        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);
            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. DAN LIRIS", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "BUDGET EXPORT 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 != 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.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 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 = 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);


            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("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(10);
            table_ccm.TotalWidth = 570f;

            float[] ccm_widths = new float[] { 1f, 3f, 3f, 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("KODE PRODUK", 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 > 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(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.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;
                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.unit, 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_SerialNumber, 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.CalculateHeights();
                        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 - 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;
            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);
        }
Example #11
0
        public MemoryStream GeneratePdfTemplate(RO_GarmentViewModel viewModel, int offset)
        {
            //set pdf stream
            MemoryStream stream   = new MemoryStream();
            Document     document = new Document(PageSize.A4, 10, 10, 10, 10);
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            writer.CloseStream = false;
            document.Open();
            PdfContentByte cb = writer.DirectContent;
            //set content configuration
            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);
            Font     font_9          = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);
            DateTime now             = DateTime.Now;
            float    margin          = 10;
            float    printedOnHeight = 10;
            float    startY          = 840 - margin;

            #region Header
            cb.BeginText();
            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. DANLIRIS", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "RO EKSPOR GARMENT", 10, 805, 0);
            cb.EndText();
            #endregion

            #region Top
            PdfPTable table_top  = new PdfPTable(9);
            float[]   top_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1.2f, 0.1f, 2f };

            table_top.TotalWidth = 500f;
            table_top.SetWidths(top_widths);

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

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

            PdfPCell cell_top_keterangan = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_TOP,
                PaddingRight        = 1,
                PaddingBottom       = 2,
                PaddingTop          = 2,
                Colspan             = 7
            };

            cell_colon.Phrase = new Phrase(":", normal_font);
            cell_top.Phrase   = new Phrase("NO RO", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);

            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.RO_Number}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("SECTION", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.Section}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("DATE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.ConfirmDate.AddHours(offset).ToString("dd MMMM yyyy")}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("Konveksi", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.Unit.Code}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("BUYER", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.BuyerBrand.Name}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("DELIVERY DATE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.DeliveryDate.AddHours(offset).ToString("dd MMMM yyyy")}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("DESC", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.Description}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("QUANTITY", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.Total.ToString()} {viewModel.CostCalculationGarment.UOM.Unit}", normal_font);
            table_top.AddCell(cell_top);
            cell_top.Phrase = new Phrase("SIZE RANGE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.SizeRange}", normal_font);
            table_top.AddCell(cell_top);

            byte[] imageByte;
            try
            {
                imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.CostCalculationGarment.ImageFile));
            }
            catch (Exception)
            {
                var webClient = new WebClient();
                imageByte = webClient.DownloadData("http://babakunyho.eu/img/default-no-image.png");
            }

            Image image = Image.GetInstance(imgb: imageByte);

            if (image.Width > 60)
            {
                float percentage = 0.0f;
                percentage = 60 / image.Width;
                image.ScalePercent(percentage * 100);
            }

            float row1Y  = 800;
            float imageY = 800 - image.ScaledHeight;

            image.SetAbsolutePosition(520, imageY);
            cb.AddImage(image, inlineImage: true);
            table_top.WriteSelectedRows(0, -1, 10, row1Y, cb);
            #endregion

            #region Table Fabric
            //Fabric title
            PdfPTable table_fabric_top = new PdfPTable(1);
            table_fabric_top.TotalWidth = 570f;

            float[] fabric_widths_top = new float[] { 5f };
            table_fabric_top.SetWidths(fabric_widths_top);

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

            cell_top_fabric.Phrase = new Phrase("FABRIC", bold_font);
            table_fabric_top.AddCell(cell_top_fabric);

            float row1Height        = image.ScaledHeight > table_top.TotalHeight ? image.ScaledHeight : table_top.TotalHeight;
            float rowYTittleFab     = row1Y - row1Height - 10;
            float allowedRow2Height = rowYTittleFab - printedOnHeight - margin;
            table_fabric_top.WriteSelectedRows(0, -1, 10, rowYTittleFab, cb);

            //Main fabric table
            PdfPTable table_fabric = new PdfPTable(8);
            table_fabric.TotalWidth = 570f;

            float[] fabric_widths = new float[] { 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f };
            table_fabric.SetWidths(fabric_widths);

            PdfPCell cell_fabric_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_fabric_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
            };

            float rowYFab = rowYTittleFab - table_fabric_top.TotalHeight - 5;
            float allowedRow2HeightFab = rowYFab - printedOnHeight - margin;

            //cell_fabric_center.Phrase = new Phrase("FABRIC", bold_font);
            //table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("PRODUCT CODE", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("COMPOSITION", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("CONSTRUCTION", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("YARN", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("WIDTH", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("DESCRIPTION", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("QUANTITY", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("REMARK", bold_font);
            table_fabric.AddCell(cell_fabric_center);

            foreach (var materialModel in viewModel.CostCalculationGarment.CostCalculationGarment_Materials)
            {
                if (materialModel.Category.name == "FABRIC")
                {
                    //cell_fabric_left.Phrase = new Phrase(materialModel.Category.SubCategory != null ? materialModel.Category.SubCategory : "", normal_font);
                    //table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Product.Code, normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Product.Composition, normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Product.Const, normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Product.Yarn, normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Product.Width, normal_font);

                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Description != null ? materialModel.Description : "", normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Quantity.ToString() != null ? String.Format("{0} " + materialModel.UOMQuantity.Unit, materialModel.Quantity.ToString()) : "0", normal_font);
                    table_fabric.AddCell(cell_fabric_left);

                    cell_fabric_left.Phrase = new Phrase(materialModel.Information != null ? materialModel.Information : "", normal_font);
                    table_fabric.AddCell(cell_fabric_left);
                }
            }
            table_fabric.WriteSelectedRows(0, -1, 10, rowYFab, cb);
            #endregion

            #region Table Accessories
            //Accessories Title
            PdfPTable table_acc_top = new PdfPTable(1);
            table_acc_top.TotalWidth = 570f;

            float[] acc_width_top = new float[] { 5f };
            table_acc_top.SetWidths(acc_width_top);

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

            cell_top_acc.Phrase = new Phrase("ACCESSORIES", bold_font);
            table_acc_top.AddCell(cell_top_acc);

            float rowYTittleAcc           = rowYFab - table_fabric.TotalHeight - 10;
            float allowedRow2HeightTopAcc = rowYTittleFab - printedOnHeight - margin;
            table_acc_top.WriteSelectedRows(0, -1, 10, rowYTittleAcc, cb);

            //Main Accessories Table
            PdfPTable table_accessories = new PdfPTable(8);
            table_accessories.TotalWidth = 570f;

            float[] accessories_widths = new float[] { 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f };
            table_accessories.SetWidths(accessories_widths);

            PdfPCell cell_acc_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_acc_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
            };

            float rowYAcc = rowYTittleAcc - table_fabric_top.TotalHeight - 5;
            float allowedRow2HeightAcc = rowYAcc - printedOnHeight - margin;

            //cell_acc_center.Phrase = new Phrase("ACCESSORIES", bold_font);
            //table_accessories.AddCell(cell_acc_center);

            cell_fabric_center.Phrase = new Phrase("PRODUCT CODE", bold_font);
            table_accessories.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("COMPOSITION", bold_font);
            table_accessories.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("CONSTRUCTION", bold_font);
            table_accessories.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("YARN", bold_font);
            table_accessories.AddCell(cell_fabric_center);

            cell_fabric_center.Phrase = new Phrase("WIDTH", bold_font);
            table_accessories.AddCell(cell_fabric_center);

            cell_acc_center.Phrase = new Phrase("DESCRIPTION", bold_font);
            table_accessories.AddCell(cell_acc_center);

            cell_acc_center.Phrase = new Phrase("QUANTITY", bold_font);
            table_accessories.AddCell(cell_acc_center);

            cell_acc_center.Phrase = new Phrase("REMARK", bold_font);
            table_accessories.AddCell(cell_acc_center);

            foreach (var materialModel in viewModel.CostCalculationGarment.CostCalculationGarment_Materials)
            {
                if (materialModel.Category.name != "FABRIC")
                {
                    cell_acc_left.Phrase = new Phrase(materialModel.Product.Code, normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Product.Composition, normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Product.Const, normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Product.Yarn, normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Product.Width, normal_font);

                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Description != null ? materialModel.Description : "", normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Quantity != null ? String.Format("{0} " + materialModel.UOMQuantity.Unit, materialModel.Quantity.ToString()) : "0", normal_font);
                    table_accessories.AddCell(cell_acc_left);

                    cell_acc_left.Phrase = new Phrase(materialModel.Information != null ? materialModel.Information : "", normal_font);
                    table_accessories.AddCell(cell_acc_left);
                }
            }
            table_accessories.WriteSelectedRows(0, -1, 10, rowYAcc, cb);
            #endregion


            #region Table Size Breakdown
            //Title
            PdfPTable table_breakdown_top = new PdfPTable(1);
            table_breakdown_top.TotalWidth = 570f;

            float[] breakdown_width_top = new float[] { 5f };
            table_breakdown_top.SetWidths(breakdown_width_top);

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

            cell_top_breakdown.Phrase = new Phrase("SIZE BREAKDOWN", bold_font);
            table_breakdown_top.AddCell(cell_top_breakdown);

            float rowYTittleBreakDown        = rowYAcc - table_accessories.TotalHeight - 10;
            float allowedRow2HeightBreakdown = rowYTittleBreakDown - printedOnHeight - margin;
            table_breakdown_top.WriteSelectedRows(0, -1, 10, rowYTittleBreakDown, cb);

            //Main Table Size Breakdown
            PdfPTable table_breakDown = new PdfPTable(2);
            table_breakDown.TotalWidth = 570f;

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

            PdfPCell cell_breakDown_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_breakDown_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_breakDown_total = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
                Padding             = 2
            };

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

            float rowYbreakDown = rowYTittleBreakDown - table_breakdown_top.TotalHeight - 5;
            float allowedRow2HeightBreakDown   = rowYbreakDown - printedOnHeight - margin;
            var   remainingRowToHeightBrekdown = rowYbreakDown - 5 - printedOnHeight - margin;

            cell_breakDown_center.Phrase = new Phrase("WARNA", bold_font);
            table_breakDown.AddCell(cell_breakDown_center);

            cell_breakDown_center.Phrase = new Phrase("SIZE RANGE", bold_font);
            table_breakDown.AddCell(cell_breakDown_center);

            foreach (var productRetail in viewModel.RO_Garment_SizeBreakdowns)
            {
                if (productRetail.Total != 0)
                {
                    cell_breakDown_left.Phrase = new Phrase(productRetail.Color.Name != null ? productRetail.Color.Name : "", normal_font);
                    table_breakDown.AddCell(cell_breakDown_left);

                    PdfPTable table_breakDown_child = new PdfPTable(3);
                    table_breakDown_child.TotalWidth = 300f;

                    float[] breakDown_child_widths = new float[] { 5f, 5f, 5f };
                    table_breakDown_child.SetWidths(breakDown_child_widths);

                    PdfPCell cell_breakDown_child_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_breakDown_child_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
                    };

                    cell_breakDown_child_center.Phrase = new Phrase("KETERANGAN", bold_font);
                    table_breakDown_child.AddCell(cell_breakDown_child_center);

                    cell_breakDown_child_center.Phrase = new Phrase("SIZE", bold_font);
                    table_breakDown_child.AddCell(cell_breakDown_child_center);

                    cell_breakDown_child_center.Phrase = new Phrase("QUANTITY", bold_font);
                    table_breakDown_child.AddCell(cell_breakDown_child_center);

                    foreach (var size in productRetail.RO_Garment_SizeBreakdown_Details)
                    {
                        cell_breakDown_child_left.Phrase = new Phrase(size.Information != null ? size.Information : "", normal_font);
                        table_breakDown_child.AddCell(cell_breakDown_child_left);

                        cell_breakDown_child_left.Phrase = new Phrase(size.Size != null ? size.Size : "", normal_font);
                        table_breakDown_child.AddCell(cell_breakDown_child_left);

                        cell_breakDown_child_left.Phrase = new Phrase(size.Quantity.ToString() != null ? size.Quantity.ToString() : "0", normal_font);
                        table_breakDown_child.AddCell(cell_breakDown_child_left);
                    }

                    cell_breakDown_child_left.Phrase = new Phrase(" ", bold_font);
                    table_breakDown_child.AddCell(cell_breakDown_child_left);

                    cell_breakDown_child_left.Phrase = new Phrase("TOTAL", bold_font);
                    table_breakDown_child.AddCell(cell_breakDown_child_left);

                    cell_breakDown_child_left.Phrase = new Phrase(productRetail.Total.ToString() != null ? productRetail.Total.ToString() : "0", normal_font);
                    table_breakDown_child.AddCell(cell_breakDown_child_left);

                    table_breakDown_child.WriteSelectedRows(0, -1, 10, 0, cb);

                    table_breakDown.AddCell(table_breakDown_child);
                }

                var tableBreakdownCurrentHeight = table_breakDown.TotalHeight;

                if (tableBreakdownCurrentHeight / remainingRowToHeightBrekdown > 1)
                {
                    if (tableBreakdownCurrentHeight / allowedRow2HeightBreakDown > 1)
                    {
                        PdfPRow headerRow = table_breakDown.GetRow(0);
                        PdfPRow lastRow   = table_breakDown.GetRow(table_breakDown.Rows.Count - 1);
                        table_breakDown.DeleteLastRow();
                        table_breakDown.WriteSelectedRows(0, -1, 10, rowYbreakDown, cb);
                        table_breakDown.DeleteBodyRows();
                        this.DrawPrintedOn(now, bf, cb);
                        document.NewPage();
                        table_breakDown.Rows.Add(headerRow);
                        table_breakDown.Rows.Add(lastRow);
                        table_breakDown.CalculateHeights(true);
                        rowYbreakDown = startY;
                        remainingRowToHeightBrekdown = rowYbreakDown - 5 - printedOnHeight - margin;
                        allowedRow2HeightBreakDown   = remainingRowToHeightBrekdown - printedOnHeight - margin;
                    }
                }
            }

            cell_breakDown_total_2.Phrase = new Phrase("TOTAL", bold_font);
            table_breakDown.AddCell(cell_breakDown_total_2);

            cell_breakDown_total_2.Phrase = new Phrase(viewModel.Total.ToString(), bold_font);
            table_breakDown.AddCell(cell_breakDown_total_2);

            table_breakDown.WriteSelectedRows(0, -1, 10, rowYbreakDown, cb);
            #endregion

            #region Table Instruksi
            //Title
            PdfPTable table_instruction  = new PdfPTable(1);
            float[]   instruction_widths = new float[] { 5f };

            table_instruction.TotalWidth = 500f;
            table_instruction.SetWidths(instruction_widths);

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

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

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

            cell_top_instruction.Phrase = new Phrase("INSTRUCTION", normal_font);
            table_instruction.AddCell(cell_top_instruction);
            table_instruction.AddCell(cell_colon_instruction);
            cell_top_keterangan_instruction.Phrase = new Phrase($"{viewModel.Instruction}", normal_font);
            table_instruction.AddCell(cell_top_keterangan_instruction);

            float rowYInstruction = rowYbreakDown - table_breakDown.TotalHeight - 10;
            float allowedRow2HeightInstruction = rowYInstruction - printedOnHeight - margin;

            table_instruction.WriteSelectedRows(0, -1, 10, rowYInstruction, cb);
            #endregion

            #region RO Image
            var    countImageRo = 0;
            byte[] roImage;

            foreach (var index in viewModel.ImagesFile)
            {
                countImageRo++;
            }


            float rowYRoImage = rowYInstruction - table_instruction.TotalHeight - 10;
            float imageRoHeight;

            if (countImageRo != 0)
            {
                if (countImageRo > 5)
                {
                    countImageRo = 5;
                }

                PdfPTable table_ro_image = new PdfPTable(countImageRo);
                float[]   ro_widths      = new float[countImageRo];

                for (var i = 0; i < countImageRo; i++)
                {
                    ro_widths.SetValue(5f, i);
                }

                if (countImageRo != 0)
                {
                    table_ro_image.SetWidths(ro_widths);
                }

                table_ro_image.TotalWidth = 570f;

                foreach (var imageFromRo in viewModel.ImagesFile)
                {
                    try
                    {
                        roImage = Convert.FromBase64String(Base64.GetBase64File(imageFromRo));
                    }
                    catch (Exception)
                    {
                        var webClient = new WebClient();
                        roImage = webClient.DownloadData("https://bateeqstorage.blob.core.windows.net/other/no-image.jpg");
                    }

                    Image images = Image.GetInstance(imgb: roImage);

                    if (images.Width > 60)
                    {
                        float percentage = 0.0f;
                        percentage = 60 / images.Width;
                        images.ScalePercent(percentage * 100);
                    }

                    PdfPCell imageCell = new PdfPCell(images);
                    imageCell.Border = 0;
                    table_ro_image.AddCell(imageCell);
                }

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

                foreach (var name in viewModel.ImagesName)
                {
                    cell_image.Phrase = new Phrase(name, normal_font);
                    table_ro_image.AddCell(cell_image);
                }

                imageRoHeight = table_ro_image.TotalHeight;
                table_ro_image.WriteSelectedRows(0, -1, 10, rowYRoImage, cb);
            }
            else
            {
                imageRoHeight = 0;
            }
            #endregion

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

            float[] signature_widths = new float[] { 1f, 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,
            };

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

            cell_signature.Phrase = new Phrase("Dibuat", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Kasie Merchandiser", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("R & D", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Ka Produksi", 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("Menyetujui", normal_font);
            table_signature.AddCell(cell_signature);

            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(                           )", normal_font);
            table_signature.AddCell(cell_signature_noted);
            cell_signature_noted.Phrase = new Phrase("(Michelle Tjokrosaputro)", normal_font);
            table_signature.AddCell(cell_signature_noted);

            float table_signatureY = rowYRoImage - imageRoHeight - 10;
            table_signature.WriteSelectedRows(0, -1, 10, table_signatureY, cb);
            #endregion

            this.DrawPrintedOn(now, bf, cb);
            document.Close();

            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;
            return(stream);
        }
Example #12
0
        //כפתור יצירת דוח שעות של העובד
        private void BTN_PRINT_Click(object sender, EventArgs e)
        {
            if (TB_WORKER_ID.Text == string.Empty)
            {
                MessageBox.Show("הכנס מספר עובד", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (DGV_SHIFTS.Rows.Count == 0)
            {
                MessageBox.Show("טבלת המשמרות ריקה", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                Document Doc = new Document(PageSize.A4, 25, 25, 30, 30);

                using (FileStream fs = new FileStream(@"C:\" + "עובד "
                                                      + DGV_SHIFTS.Rows[0].Cells[0].Value + ".pdf", FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    PdfWriter writer = PdfWriter.GetInstance(Doc, fs);
                    Doc.Open();
                    Doc.NewPage();
                    string    ARIALUNI_TFF = Path.Combine(@"C:\arial.tff location here", "ARIAL.TTF");
                    BaseFont  bf           = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                    Font      f1           = new Font(bf, 8);
                    PdfPTable Table        = new PdfPTable(3);
                    PdfPTable Table1       = new PdfPTable(1);

                    Table.RunDirection             = PdfWriter.RUN_DIRECTION_RTL;
                    Table1.RunDirection            = PdfWriter.RUN_DIRECTION_RTL;
                    Table1.DefaultCell.BorderWidth = 0;

                    //-------------------------------------------------------------------------
                    //הוספת תמונה
                    Image image = Image.GetInstance("C:\\Logo image location here\\logo_transparent.png");
                    image.ScaleAbsolute(100, 100);
                    image.Alignment = Element.ALIGN_CENTER;
                    Doc.Add(image);

                    PdfPCell employee = new PdfPCell(new Phrase("תאריך הדפסה:" + " " + DateTime.Now.ToString("dd/MM/yyyy HH:mm ")
                                                                + "\n" + "שם מלא:" + " " + DGV_SHIFTS.Rows[0].Cells[1].Value + " " + DGV_SHIFTS.Rows[0].Cells[2].Value, f1))
                    {
                        ExtraParagraphSpace = 5,
                        HorizontalAlignment = 2,
                    };
                    employee.Border = 0;
                    Table1.AddCell(employee);
                    Doc.Add(Table1);

                    Table.AddCell(new Phrase("תאריך משמרת", f1));
                    Table.AddCell(new Phrase("תחילת משמרת", f1));
                    Table.AddCell(new Phrase("סיום משמרת", f1));


                    for (int i = 0; i < DGV_SHIFTS.Rows.Count; i++)
                    {
                        var date       = Convert.ToDateTime(DGV_SHIFTS.Rows[i].Cells[5].Value).ToString("dd/MM/yyy");
                        var startshift = Convert.ToDateTime(DGV_SHIFTS.Rows[i].Cells[5].Value).ToString("H:mm");
                        var endshift   = Convert.ToDateTime(DGV_SHIFTS.Rows[i].Cells[6].Value).ToString("H:mm");
                        Table.AddCell(new Phrase(date, f1));
                        Table.AddCell(new Phrase(startshift, f1));
                        Table.AddCell(new Phrase(endshift, f1));
                    }
                    Doc.Add(Table);


                    //חישוב שעות העבודה של העובד
                    TimeSpan totalhours = new TimeSpan();
                    for (int i = 0; i < DGV_SHIFTS.Rows.Count; i++)
                    {
                        totalhours += Convert.ToDateTime(DGV_SHIFTS.Rows[i].Cells[6].Value) - Convert.ToDateTime(DGV_SHIFTS.Rows[i].Cells[5].Value);
                    }

                    Table1.DeleteLastRow();
                    PdfPCell cellAmount = new PdfPCell
                                              (new Phrase("סה\"כ שעות עבודה:" + " " + String.Format("{0:0.00}", Convert.ToDecimal(totalhours.TotalHours)), f1))
                    {
                        HorizontalAlignment = 2,
                        ExtraParagraphSpace = 10
                    };
                    cellAmount.Border = 0;
                    Table1.AddCell(cellAmount);
                    Doc.Add(Table1);

                    //---------------------------------------------------------
                    Doc.Close();
                    MessageBox.Show("דוח השעות נוצר בהצלחה");
                }
            }
        }
Example #13
0
        public MemoryStream GeneratePdfTemplate(MaterialDistributionNoteViewModel 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);
            var      normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            var      bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);

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

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

            cb.BeginText();

            cb.SetFontAndSize(bf, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT DAN LIRIS", 15, 820, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "INDUSTRIAL & TRADING CO LTD", 15, 810, 0);

            cb.SetFontAndSize(bf_bold, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "FM.FP-00-GG-15-002", 485, 815, 0);

            cb.SetFontAndSize(bf_bold, 14);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "BON PENGANTAR GREIGE", 300, 785, 0);

            cb.SetFontAndSize(bf, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "TANGGAL", 15, 760, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 70, 760, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel._CreatedUtc.AddHours(7).ToString("dd-MM-yyyy"), 80, 760, 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "BAGIAN", 15, 750, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 70, 750, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.Unit.Name, 80, 750, 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "NO", 450, 760, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 485, 760, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.No, 495, 760, 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "TIPE", 450, 750, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 485, 750, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.Type, 495, 750, 0);

            cb.EndText();

            PdfPTable table = new PdfPTable(8);
            PdfPCell  cell;

            table.TotalWidth = 565f;
            int rowsPerPage = 20;

            float[] widths = new float[] { 2f, 7f, 5f, 9f, 4f, 4f, 8f, 8f };
            table.SetWidths(widths);

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

            cell.Phrase = new Phrase("NO", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("NO SPB", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("NO SPP", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("NAMA BARANG", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("GRADE", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("PIECE", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("METER", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("ASAL", bold_font);
            table.AddCell(cell);

            int    Number = 1;
            double?TotalQuantity = 0, TotalReceivedLength = 0;


            int TotalRows = 0;

            foreach (var item in viewModel.MaterialDistributionNoteItems)
            {
                TotalRows += item.MaterialDistributionNoteDetails.Count;
            }

            foreach (var item in viewModel.MaterialDistributionNoteItems)
            {
                foreach (var detail in item.MaterialDistributionNoteDetails)
                {
                    cell = new PdfPCell()
                    {
                        Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
                    };
                    cell.Phrase = new Phrase(Number.ToString(), normal_font);
                    table.AddCell(cell);

                    cell.Phrase = new Phrase(item.MaterialRequestNoteCode, normal_font);
                    table.AddCell(cell);

                    cell.Phrase = new Phrase(detail.ProductionOrder.OrderNo, normal_font);
                    table.AddCell(cell);

                    cell = new PdfPCell()
                    {
                        Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
                    };
                    cell.Phrase = new Phrase(detail.Product.Name, normal_font);
                    table.AddCell(cell);

                    cell = new PdfPCell()
                    {
                        Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
                    };
                    cell.Phrase = new Phrase(detail.Grade, normal_font);
                    table.AddCell(cell);

                    cell = new PdfPCell()
                    {
                        Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
                    };
                    cell.Phrase = new Phrase(string.Format("{0:n}", detail.Quantity), normal_font);
                    table.AddCell(cell);

                    cell.Phrase = new Phrase(string.Format("{0:n}", detail.ReceivedLength), normal_font);
                    table.AddCell(cell);

                    cell = new PdfPCell()
                    {
                        Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
                    };
                    cell.Phrase = new Phrase(detail.Supplier.name, normal_font);
                    table.AddCell(cell);

                    TotalQuantity       += detail.Quantity;
                    TotalReceivedLength += detail.ReceivedLength;

                    if (Number == TotalRows)
                    {
                        cell = new PdfPCell()
                        {
                            Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Colspan = 5, Phrase = new Phrase("Jumlah", normal_font), Padding = 5
                        };
                        table.AddCell(cell);

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

                        cell.Phrase = new Phrase(string.Format("{0:n}", TotalQuantity), normal_font);
                        table.AddCell(cell);

                        cell.Phrase = new Phrase(string.Format("{0:n}", TotalReceivedLength), normal_font);
                        table.AddCell(cell);
                        table.AddCell(new Phrase("", normal_font));
                    }

                    if (Number % rowsPerPage == 0)
                    {
                        if (Number == rowsPerPage)
                        {
                            table.WriteSelectedRows(0, -1, 15, 735, cb);
                        }
                        else
                        {
                            table.WriteSelectedRows(0, -1, 15, 815, cb);
                        }

                        for (var i = 0; i < rowsPerPage; i++)
                        {
                            table.DeleteLastRow();
                        }

                        if (Number != TotalRows)
                        {
                            document.NewPage();
                        }
                    }

                    Number++;
                }
            }

            Number--;
            if (Number % rowsPerPage != 0)
            {
                if (Number < rowsPerPage)
                {
                    table.WriteSelectedRows(0, -1, 15, 735, cb);
                }
                else
                {
                    table.WriteSelectedRows(0, -1, 15, 815, cb);
                }
            }

            cb.BeginText();
            cb.SetTextMatrix(15, 23);

            cb.SetFontAndSize(bf, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Pengirim,", 130, 110, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, $"{viewModel._CreatedBy}", 130, 55, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(.................................)", 130, 50, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Bag. Gd Material", 130, 35, 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Penerima,", 460, 110, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(.................................)", 460, 50, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Bag. Produksi", 460, 35, 0);

            cb.EndText();

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;
            return(stream);
        }
Example #14
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog()
            {
                Filter = "PDF file|*.pdf", ValidateNames = true
            })
            {
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A3.Rotate());
                    try
                    {
                        PdfWriter Writer = PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
                        doc.Open();
                        PdfPTable tabledestring = new PdfPTable(1);
                        //remplissage de tableau des indexes
                        PdfPTable table = ListTopdfTable(Lsmachines);
                        doc.Add(table);

                        //remplissage des autres tableaux
                        tabledestring = ListEnStringTopdfTable(Lssgaz, "Liste de gaz", textBox2.Text);
                        //doc.Add(tabledestring);
                        tabledestring.WriteSelectedRows(0, -1, doc.Left + 315 + 215, doc.Top, Writer.DirectContent);

                        tabledestring = ListEnStringTopdfTable(Lsspayment, "Liste des payments", textBox5.Text);
                        //doc.Add(tabledestring);
                        tabledestring.WriteSelectedRows(0, -1, doc.Left + 315, doc.Top, Writer.DirectContent);

                        tabledestring            = ListEnStringTopdfTable(Lsscredits, "Liste des credits", textBox14.Text);
                        tabledestring.TotalWidth = 300f;
                        //doc.Add(tabledestring);
                        tabledestring.WriteSelectedRows(0, -1, doc.Left, doc.Top - 400, Writer.DirectContent);

                        tabledestring = ListEnStringTopdfTable(Lssbons, "Liste des bons", textBox13.Text);
                        //doc.Add(tabledestring);
                        tabledestring.WriteSelectedRows(0, -1, doc.Left + 315, doc.Top - 400, Writer.DirectContent);

                        tabledestring = ListEnStringTopdfTable(Lssespeces, "Liste des especes", textBox10.Text);
                        //doc.Add(tabledestring);
                        tabledestring.WriteSelectedRows(0, -1, doc.Left + 315 + 215, doc.Top - 400, Writer.DirectContent);

                        //test
                        PdfPTable pTable = new PdfPTable(1);
                        pTable.TotalWidth = 200f;
                        Phrase   phrase = new Phrase();
                        PdfPCell cell   = new PdfPCell();
                        cell.DisableBorderSide(1); cell.DisableBorderSide(3); cell.HorizontalAlignment = 1;

                        phrase.Add("Identifiant De l'employé = " + textBox17.Text);
                        cell.AddElement(phrase); cell.HorizontalAlignment = 1;
                        pTable.AddCell(cell);
                        pTable.WriteSelectedRows(0, -1, doc.Left + 760, doc.Top, Writer.DirectContent);
                        pTable.DeleteLastRow();
                        cell = new PdfPCell();
                        cell.DisableBorderSide(1); cell.DisableBorderSide(3); cell.HorizontalAlignment = 1;

                        Phrase phrase1 = new Phrase("somme de vente = " + textBox6.Text);
                        cell.AddElement(phrase1); cell.HorizontalAlignment = 1;
                        pTable.AddCell(cell);
                        pTable.WriteSelectedRows(0, -1, doc.Left + 760, doc.Top - 120, Writer.DirectContent);
                        pTable.DeleteLastRow();
                        cell = new PdfPCell();
                        cell.DisableBorderSide(1); cell.DisableBorderSide(3); cell.HorizontalAlignment = 1;

                        Phrase phrase2 = new Phrase("somme fourni = " + textBox8.Text);
                        cell.AddElement(phrase2); cell.HorizontalAlignment = 1;
                        pTable.AddCell(cell);
                        pTable.WriteSelectedRows(0, -1, doc.Left + 760, doc.Top - 240, Writer.DirectContent);
                        pTable.DeleteLastRow();
                        cell = new PdfPCell();
                        cell.DisableBorderSide(1); cell.DisableBorderSide(3); cell.HorizontalAlignment = 1;

                        Phrase phrase3 = new Phrase("recette = " + textBox16.Text);
                        phrase3.Font.Size = 18;
                        cell.AddElement(phrase3); cell.HorizontalAlignment = 1;
                        pTable.AddCell(cell);
                        pTable.WriteSelectedRows(0, -1, doc.Left + 760, doc.Top - 360, Writer.DirectContent);
                        pTable.DeleteLastRow();


                        //ecriture des somme des litres
                        cell = new PdfPCell();
                        cell.DisableBorderSide(-1); cell.HorizontalAlignment = 1;
                        Phrase phrase4 = new Phrase("Litrage gasoil = " + totaleLitresGasoil.ToString());
                        phrase4.Font.Size = 11;
                        cell.AddElement(phrase4); cell.HorizontalAlignment = 1;
                        pTable.AddCell(cell);
                        pTable.WriteSelectedRows(0, -1, doc.Left + 985, doc.Top, Writer.DirectContent);
                        pTable.DeleteLastRow();

                        cell = new PdfPCell();
                        cell.DisableBorderSide(-1); cell.HorizontalAlignment = 1;
                        Phrase phrase5 = new Phrase("Litrage sans plomb = " + totaleLitresSansPlomb.ToString());
                        phrase5.Font.Size = 11;
                        cell.AddElement(phrase5); cell.HorizontalAlignment = 1;
                        pTable.AddCell(cell);
                        pTable.WriteSelectedRows(0, -1, doc.Left + 985, doc.Top - 30, Writer.DirectContent);
                        pTable.DeleteLastRow();

                        cell = new PdfPCell();
                        cell.DisableBorderSide(-1); cell.HorizontalAlignment = 1;
                        Phrase phrase6 = new Phrase("Litrage 50 = " + totaleLitres50.ToString());
                        phrase6.Font.Size = 11;
                        cell.AddElement(phrase6); cell.HorizontalAlignment = 1;
                        pTable.AddCell(cell);
                        pTable.WriteSelectedRows(0, -1, doc.Left + 985, doc.Top - 60, Writer.DirectContent);
                        pTable.DeleteLastRow();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        doc.Close();
                    }
                }
            }
        }
        public MemoryStream GeneratePdfTemplate(List <MaterialDistributionNoteReportViewModel> data, DateTime date, string unitName)
        {
            BaseFont bf          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            BaseFont bf_bold     = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            var      normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            var      bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);

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

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

            cb.BeginText();

            cb.SetFontAndSize(bf, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT DAN LIRIS", 15, 820, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "INDUSTRIAL & TRADING CO LTD", 15, 810, 0);

            cb.SetFontAndSize(bf_bold, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "FM.FP-00-GG-15-002", 485, 815, 0);

            cb.SetFontAndSize(bf_bold, 14);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "BON PENGANTAR Here", 300, 785, 0);

            cb.SetFontAndSize(bf, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Date", 15, 760, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 70, 760, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, date.ToString("dd-MM-yyyy"), 80, 760, 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "BAGIAN", 15, 750, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 70, 750, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, unitName, 80, 750, 0);

            cb.EndText();

            PdfPTable table = new PdfPTable(10);
            PdfPCell  cell;

            table.TotalWidth = 565f;
            int rowsPerPage = 20;

            float[] widths = new float[] { 0.5f, 1.5f, 2f, 2f, 1.5f, 2.5f, 0.7f, 1.5f, 2f, 2.5f };
            table.SetWidths(widths);

            cell = 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.Phrase = new Phrase("NO", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("NO BON", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("TIPE BON", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("NO SPB", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("NO SPP", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("Item name", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("GRD", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("PIECE", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("METER", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("ASAL", bold_font);
            table.AddCell(cell);

            int    Number = 1;
            double?TotalQuantity = 0, TotalReceivedLength = 0;

            int TotalRows = data.Count;

            foreach (var d in data)
            {
                cell = 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.Phrase = new Phrase(Number.ToString(), normal_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase(d.No, normal_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase(d.Type, normal_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase(d.MaterialRequestNoteNo, normal_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase(d.ProductionOrderNo, normal_font);
                table.AddCell(cell);

                cell = 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
                };
                cell.Phrase = new Phrase(d.ProductName.Replace("Here ", "", StringComparison.CurrentCultureIgnoreCase), normal_font);
                table.AddCell(cell);

                cell = 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.Phrase = new Phrase(d.Grade, normal_font);
                table.AddCell(cell);

                cell = 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.Phrase = new Phrase(string.Format("{0:n}", d.Quantity), normal_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase(string.Format("{0:n}", d.Length), normal_font);
                table.AddCell(cell);

                cell = 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
                };
                cell.Phrase = new Phrase(d.SupplierName, normal_font);
                table.AddCell(cell);

                TotalQuantity       += d.Quantity;
                TotalReceivedLength += d.Length;

                if (Number == TotalRows)
                {
                    cell = new PdfPCell()
                    {
                        Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Colspan = 7, Phrase = new Phrase("Amount", normal_font), Padding = 2
                    };
                    table.AddCell(cell);

                    cell = 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.Phrase = new Phrase(string.Format("{0:n}", TotalQuantity), normal_font);
                    table.AddCell(cell);

                    cell.Phrase = new Phrase(string.Format("{0:n}", TotalReceivedLength), normal_font);
                    table.AddCell(cell);
                    table.AddCell(new Phrase("", normal_font));
                }

                if (Number % rowsPerPage == 0)
                {
                    if (Number == rowsPerPage)
                    {
                        table.WriteSelectedRows(0, -1, 15, 735, cb);
                    }
                    else
                    {
                        table.WriteSelectedRows(0, -1, 15, 815, cb);
                    }

                    for (var i = 0; i < rowsPerPage; i++)
                    {
                        table.DeleteLastRow();
                    }

                    if (Number != TotalRows)
                    {
                        document.NewPage();
                    }
                }

                Number++;
            }

            Number--;
            if (Number % rowsPerPage != 0)
            {
                if (Number < rowsPerPage)
                {
                    table.WriteSelectedRows(0, -1, 15, 735, cb);
                }
                else
                {
                    table.WriteSelectedRows(0, -1, 15, 815, cb);
                }
            }

            cb.BeginText();
            cb.SetTextMatrix(15, 23);

            cb.SetFontAndSize(bf, 8);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Pengirim,", 130, 110, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(.................................)", 130, 50, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Bag. Gd Material", 130, 35, 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Penerima,", 460, 110, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(.................................)", 460, 50, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Bag. PRODUCTION", 460, 35, 0);

            cb.EndText();

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;
            return(stream);
        }
Example #16
0
        public MemoryStream GeneratePdfTemplate(TransferRequestViewModel 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);
            var      normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);
            var      bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);

            //Creating page.

            Document     document = new Document(PageSize.A5);
            MemoryStream stream   = new MemoryStream();



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

            writer.CloseStream = false;

            document.Open();

            PdfContentByte cb = writer.DirectContent;

            cb.BeginText();
            cb.SetTextMatrix(15, 23);

            cb.SetFontAndSize(bf_bold, 14);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "PT DAN LIRIS", 200, 550, 0);
            cb.SetFontAndSize(bf, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "BANARAN, GROGOL, SUKOHARJO", 200, 540, 0);

            cb.SetFontAndSize(bf_bold, 10);
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "PERMOHONAN TRANSFER", 200, 520, 0);

            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Nomor", 20, 500, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 55, 500, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.trNo, 65, 500, 0);

            cb.SetFontAndSize(bf, 9);
            cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Sukoharjo, ", 320, 500, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, $"{ viewModel.trDate.Day} { Bulan[viewModel.trDate.Month - 1]} { viewModel.trDate.Year}", 330, 500, 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Dari", 20, 490, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 55, 490, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.unit.name, 65, 490, 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Mohon ditransfer barang tersebut di bawah ini:", 20, 470, 0);

            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Kepada", 50, 306, 0);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 110, 306, 0);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Gudang Material", 120, 306, 0);

            cb.EndText();

            #region CreateTable
            PdfPTable table = new PdfPTable(5);
            PdfPCell  cell;
            table.TotalWidth = 360f;
            int rowsPerPage = 10;

            float[] widths = new float[] { 2f, 4f, 10f, 4f, 4f };
            table.SetWidths(widths);

            cell = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            var rightCell = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            var leftCell = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            //Create cells headers.


            cell.Phrase = new Phrase("NO", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("KODE", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("BARANG", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("JUMLAH", bold_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("HARGA", bold_font);
            table.AddCell(cell);

            int index = 1;

            int TotalRows = viewModel.details.Count;

            foreach (var detail in viewModel.details)
            {
                cell = new PdfPCell()
                {
                    Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
                };
                cell.Phrase = new Phrase(index.ToString(), normal_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase(detail.product.code, normal_font);
                table.AddCell(cell);

                string productGrade = detail.grade == "" ? " " : " GRADE " + detail.grade + " ";

                cell.Phrase = new Phrase(detail.product.name + productGrade + detail.productRemark, normal_font);
                table.AddCell(cell);


                cell.Phrase = new Phrase(string.Format("{0:n}", detail.quantity), normal_font);
                table.AddCell(cell);

                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);

                //if(index )

                if (index % rowsPerPage == 0)
                {
                    if (index == TotalRows)
                    {
                        continue;
                    }
                    else if (index == rowsPerPage)
                    {
                        table.WriteSelectedRows(0, -1, 15, 460, cb);
                    }
                    else
                    {
                        table.WriteSelectedRows(0, -1, 15, 500, cb);
                    }

                    for (var i = 0; i < rowsPerPage; i++)
                    {
                        table.DeleteLastRow();
                    }

                    if (index != TotalRows)
                    {
                        document.NewPage();
                    }
                }

                index++;
            }

            var footerCell = new PdfPCell();
            footerCell.Phrase  = new Phrase("Kategori                   :", normal_font);
            footerCell.Colspan = 2;
            footerCell.Border  = Rectangle.NO_BORDER;
            table.AddCell(footerCell);

            footerCell.Phrase  = new Phrase(viewModel.category.name, normal_font);
            footerCell.Colspan = 3;
            footerCell.Border  = Rectangle.NO_BORDER;
            table.AddCell(footerCell);

            var footerCell1 = new PdfPCell();
            footerCell1.Phrase  = new Phrase("Diminta Datang        :", normal_font);
            footerCell1.Colspan = 2;
            footerCell1.Border  = Rectangle.NO_BORDER;
            table.AddCell(footerCell1);

            footerCell1.Phrase  = new Phrase($"{ viewModel.requestedArrivalDate.Day} { Bulan[viewModel.requestedArrivalDate.Month - 1]} { viewModel.requestedArrivalDate.Year}", normal_font);
            footerCell1.Colspan = 3;
            footerCell1.Border  = Rectangle.NO_BORDER;
            table.AddCell(footerCell1);

            var footerCell2 = new PdfPCell();
            footerCell2.Phrase  = new Phrase("Keterangan              :", normal_font);
            footerCell2.Colspan = 2;
            footerCell2.Border  = Rectangle.NO_BORDER;
            table.AddCell(footerCell2);

            footerCell2.Phrase  = new Phrase(viewModel.remark, normal_font);
            footerCell2.Colspan = 3;
            footerCell2.Border  = Rectangle.NO_BORDER;
            table.AddCell(footerCell2);


            index--;
            if (index % rowsPerPage != 0)
            {
                if (index < rowsPerPage)
                {
                    table.WriteSelectedRows(0, -1, 15, 460, cb);
                }
                else
                {
                    table.WriteSelectedRows(0, -1, 15, 500, cb);
                }
            }
            #endregion

            #region CreateTable2
            PdfPTable table2 = new PdfPTable(5);
            PdfPCell  cell2;
            table2.TotalWidth = 360f;

            float[] widths2 = new float[] { 5f, 5f, 5f, 5.5f, 5f };
            table2.SetWidths(widths2);

            cell2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            var rightCell2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            var leftCell2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            //Create cells headers.


            cell2.Phrase = new Phrase("ACC MENGETAHUI", bold_font);
            table2.AddCell(cell2);

            cell2.Phrase = new Phrase("BAGIAN PEMBELIAN", bold_font);
            table2.AddCell(cell2);

            cell2.Phrase = new Phrase("KEPALA BAGIAN", bold_font);
            table2.AddCell(cell2);

            cell2.Phrase = new Phrase("YANG MEMERLUKAN", bold_font);
            table2.AddCell(cell2);

            cell2.Phrase = new Phrase("PPIC", bold_font);
            table2.AddCell(cell2);

            cell2 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5
            };
            cell2.MinimumHeight = 50;
            cell2.Phrase        = new Phrase("", normal_font);
            table2.AddCell(cell);

            cell2.Phrase = new Phrase("", normal_font);
            table2.AddCell(cell2);

            cell2.Phrase = new Phrase("", normal_font);
            table2.AddCell(cell2);


            cell2.Phrase = new Phrase("", normal_font);
            table2.AddCell(cell2);

            cell2.Phrase = new Phrase("", normal_font);
            table2.AddCell(cell2);


            table2.WriteSelectedRows(0, -1, 20, 130, cb);
            #endregion

            //cb.BeginText();
            //cb.SetTextMatrix(15, 23);

            //cb.SetFontAndSize(bf, 9);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Kategori", 20, 200, 0);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 70, 200, 0);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.category.name, 75, 200, 0);

            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Diminta Datang", 20, 190, 0);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 70, 190, 0);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.requestedArrivalDate.ToString("dd-MM-yyyy"), 75, 190, 0);

            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Keterangan", 20, 180, 0);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 70, 180, 0);
            //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.remark, 75, 180, 0);


            //cb.EndText();

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

            return(stream);
        }