Ejemplo n.º 1
0
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            PdfPTable _thead_page_break = new PdfPTable(10);

            _thead_page_break.WidthPercentage = 100f;
            float[] _columnWidths = { 130, 30, 40, 40, 40, 40, 40, 40, 40, 40 };
            _thead_page_break.SetWidths(_columnWidths);
            _thead_page_break.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; //this centers [table]


            //FIRST ROW
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("P/A/P/ ALLOTMENT CLASS / OBJECT OF EXPENDITURE", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_CENTER, Rowspan = 4
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("EXPENSES CODE", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 4
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("ALLOTMENT RECEIVED", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 4
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("REALIGNMENT", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Colspan = 3
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("OBLIGATIONS INCURRED", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Colspan = 2
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("UNOBLIGATED BALANCE OF ALLOTMENT", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 4
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("DISBURSEMENTS", new Font(Font.FontFamily.HELVETICA, 7f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 4
            });


            //SECOND ROW

            _thead_page_break.AddCell(new PdfPCell(new Paragraph("REALIGNMENT", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 3
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("TRANSFER TO", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 3
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("TOTAL AFTER REALIGNMENT", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 3
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph(month, new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 3
            });
            _thead_page_break.AddCell(new PdfPCell(new Paragraph("As of " + month, new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER, Rowspan = 3
            });



            _thead_page_break.WriteSelectedRows(0, -1, 36, 608, writer.DirectContentUnder);



            /*
             * PdfPTable table = new PdfPTable(1);
             * //table.WidthPercentage = 100; //PdfPTable.writeselectedrows below didn't like this
             * table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; //this centers [table]
             * PdfPTable table2 = new PdfPTable(2);
             *
             * //logo
             * PdfPCell cell2 = new PdfPCell(new Phrase("\nTITLE", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)));
             * cell2.Colspan = 2;
             * table2.AddCell(cell2);
             *
             * //title
             * cell2 = new PdfPCell(new Phrase("\nTITLE", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)));
             * cell2.HorizontalAlignment = Element.ALIGN_CENTER;
             * cell2.Colspan = 2;
             * table2.AddCell(cell2);
             *
             * PdfPCell cell = new PdfPCell(table2);
             * table.AddCell(cell);
             *
             * table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 36, writer.DirectContentUnder);
             */
        }
Ejemplo n.º 2
0
        public string CreaContrato(ContratosCliente contratosCliente)
        {
            try
            {
                if (!Directory.Exists(Directory.GetCurrentDirectory() + ConfigurationManager.AppSettings["folder:pdf"].ToString() + "Contratos"))
                {
                    Directory.CreateDirectory(Environment.CurrentDirectory + ConfigurationManager.AppSettings["folder:pdf"].ToString() + "Contratos");
                }

                string nameFile = "Contratos//ORDEN 1046_PERSHING_" + contratosCliente.NombreCliente + " " + DateTime.Now.ToString("ddMMyy_HHmmssfff") + ".pdf";
                string path     = Environment.CurrentDirectory + ConfigurationManager.AppSettings["folder:pdf"].ToString() + nameFile;

                Document  documento = new Document(PageSize.LETTER, 30, 30, 30, 30);
                PdfWriter writer    = PdfWriter.GetInstance(documento, new FileStream(path, FileMode.Create));

                documento.Open();

                string imagenTanner = "LogoTCB.PNG";
                string imagenPath   = Path.Combine(@"img/", imagenTanner);
                Image  imgHeader    = Image.GetInstance(imagenPath);
                imgHeader.ScalePercent(6);

                Paragraph sep      = new Paragraph(" ");
                Font      fntTitle = FontFactory.GetFont("Calibri", "utf-8", true, 10, Font.BOLD, BaseColor.BLACK);
                Paragraph para     = new Paragraph("ORDEN DE COMPRAVENTA DE VALORES EXTRANJEROS EN MERCADOS EXTERNOS", fntTitle);
                para.Leading   = 3;
                para.Alignment = 1;

                Font fntText  = FontFactory.GetFont("Calibri", "utf-8", true, 7.5f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
                Font fntTextN = FontFactory.GetFont("Calibri", "utf-8", true, 7.5f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);

                //Concatenar Nombre al mes
                Paragraph pharse    = new Paragraph("Santiago, " + contratosCliente.FechaProceso.Day + " " + contratosCliente.FechaProceso.Month + " de " + contratosCliente.FechaProceso.Year, fntText);
                Paragraph chunk_    = new Paragraph("Señores", fntText);
                Paragraph chunk_cli = new Paragraph("Tanner Corredores de Bolsa S.A.", fntText);
                Paragraph chunk_a   = new Paragraph("Presente", fntText);

                Paragraph para_a = new Paragraph("De mi consideración, ", fntText);
                Paragraph para_b = new Paragraph("Por medio de la presente, confirmo y ratifico que las operaciones más abajo detalladas, fueron todas y cada una de ellas instruidas por mí persona a Tanner Corredores de bolsa S.A. en adelante tambien Tanner para ser ejecutadas a través de Pershing LLC., en mi cuenta N° " + contratosCliente.NumCuenta, fntText);
                para_b.Alignment = Element.ALIGN_JUSTIFIED;

                Font fntTextA   = FontFactory.GetFont("Calibri", "utf-8", true, 6.5f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
                Font fntTxtFoot = FontFactory.GetFont("Calibri", "utf-8", true, 4f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);

                PdfPTable tablaOp = new PdfPTable(11);
                tablaOp.WidthPercentage = 100;
                tablaOp.SetWidths(new Single[] { 5.0f, 3.0f, 7.0F, 3.0f, 5.0f, 8.0f, 7.0f, 6.0f, 6.0f, 8.0f, 5.0f });

                PdfPCell cellA = new PdfPCell(new Phrase("Fecha Op.", fntTextN));
                cellA.HorizontalAlignment = 1;
                cellA.FixedHeight         = 20;
                PdfPCell cellB = new PdfPCell(new Phrase("Folio", fntTextN));
                cellB.HorizontalAlignment = 1;
                PdfPCell cellBc = new PdfPCell(new Phrase("Emisor", fntTextN));
                cellBc.HorizontalAlignment = 1;
                PdfPCell cellC = new PdfPCell(new Phrase("MDA", fntTextN));
                cellC.HorizontalAlignment = 1;
                PdfPCell cellD = new PdfPCell(new Phrase("Tipo/Inst", fntTextN));
                cellD.HorizontalAlignment = 1;
                PdfPCell cellE = new PdfPCell(new Phrase("ISIN", fntTextN));
                cellE.HorizontalAlignment = 1;
                PdfPCell cellF = new PdfPCell(new Phrase("Nominales", fntTextN));
                cellF.HorizontalAlignment = 1;
                PdfPCell cellG = new PdfPCell(new Phrase("Precio", fntTextN));
                cellG.HorizontalAlignment = 1;
                PdfPCell cellH = new PdfPCell(new Phrase("Tipo Ope.", fntTextN));
                cellH.HorizontalAlignment = 1;
                PdfPCell cellI = new PdfPCell(new Phrase("Remuneración", fntTextN));
                cellI.HorizontalAlignment = 1;
                PdfPCell cellJ = new PdfPCell(new Phrase("Mercado", fntTextN));
                cellJ.HorizontalAlignment = 1;

                tablaOp.AddCell(cellA);
                tablaOp.AddCell(cellB);
                tablaOp.AddCell(cellBc);
                tablaOp.AddCell(cellC);
                tablaOp.AddCell(cellD);
                tablaOp.AddCell(cellE);
                tablaOp.AddCell(cellF);
                tablaOp.AddCell(cellG);
                tablaOp.AddCell(cellH);
                tablaOp.AddCell(cellI);
                tablaOp.AddCell(cellJ);

                foreach (Contrato contratos in contratosCliente.ListadoContratos)
                {
                    //Fecha Op.
                    PdfPCell cellCA = new PdfPCell(new Phrase(contratosCliente.FechaProceso.ToShortDateString(), fntTextA));
                    cellCA.FixedHeight         = 25;
                    cellCA.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCA);

                    //Folio
                    PdfPCell cellCB = new PdfPCell(new Phrase(contratos.Folio.ToString(), fntTextA));
                    cellCB.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCB);

                    //Emisor
                    PdfPCell cellCC = new PdfPCell(new Phrase(contratos.Simbol, fntTextA));
                    cellCC.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCC);

                    //Moneda
                    PdfPCell cellCD = new PdfPCell(new Phrase(contratos.Currency, fntTextA));
                    cellCD.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCD);

                    //Tipo/Inst
                    PdfPCell cellCE;
                    if (contratos.Currency.Length <= 4)
                    {
                        cellCE = new PdfPCell(new Phrase("Acción", fntTextA));
                    }
                    else
                    {
                        cellCE = new PdfPCell(new Phrase("Bono", fntTextA));
                    }

                    cellCE.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCE);

                    //Isin
                    PdfPCell cellCF = new PdfPCell(new Phrase(contratos.Isin, fntTextA));
                    cellCF.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCF);

                    //Nominales
                    PdfPCell cellCG = new PdfPCell(new Phrase(contratos.Nominales.ToString(), fntTextA));
                    cellCG.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCG);

                    //Precio
                    PdfPCell cellCH = new PdfPCell(new Phrase(contratos.Precio.ToString(), fntTextA));
                    cellCH.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCH);

                    //Tipo Ope.
                    PdfPCell cellCI = new PdfPCell(new Phrase(contratos.TipoOperacion, fntTextA));
                    cellCI.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCI);

                    //Remuneración
                    PdfPCell cellCJ = new PdfPCell(new Phrase(contratos.Comision.ToString(), fntTextA));
                    cellCJ.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCJ);

                    //Mercado
                    PdfPCell cellCK = new PdfPCell(new Phrase("EEUU", fntTextA));
                    cellCK.HorizontalAlignment = Element.ALIGN_CENTER;
                    tablaOp.AddCell(cellCK);
                }

                documento.Add(imgHeader);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(para);
                documento.Add(sep);
                documento.Add(pharse);
                documento.Add(sep);
                documento.Add(chunk_);
                documento.Add(chunk_cli);
                documento.Add(chunk_a);
                documento.Add(sep);
                documento.Add(para_a);
                documento.Add(sep);
                documento.Add(para_b);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(tablaOp);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(sep);

                Paragraph countpage = new Paragraph();
                countpage.Alignment = Element.ALIGN_RIGHT;
                countpage.Add(new Chunk("Página 1 de 3", fntTxtFoot));

                PdfPTable footTbl = new PdfPTable(1);
                footTbl.TotalWidth          = 300;
                footTbl.HorizontalAlignment = Element.ALIGN_CENTER;

                PdfPCell cellFoot = new PdfPCell(countpage);
                cellFoot.Border  = 0;
                cellFoot.Padding = 5;

                footTbl.AddCell(cellFoot);
                footTbl.WriteSelectedRows(0, -1, 515, 30, writer.DirectContent);

                documento.NewPage();

                documento.Add(imgHeader);

                Font fntTextB = FontFactory.GetFont("Calibri", "utf-8", true, 7.5f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);
                Font fntTextR = FontFactory.GetFont("Calibri", "utf-8", true, 7.5f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);

                Paragraph para_c = new Paragraph();
                para_c.Alignment = Element.ALIGN_JUSTIFIED;
                para_c.Add(new Chunk("a) Entrega, recepcion de valores y liquidación: ", fntTextB));
                para_c.Add(new Chunk("Los procedimientos para efectuar la entrega, recepción y liquidación de la(s) orden(es) constan en el contrato de comisión para la compra y venta de valores extranjeros en mercados externos celebrado entre el Cliente y Tanner Corredores de Bolsa S.A., el cual está vigente.", fntTextR));

                Paragraph para_d = new Paragraph();
                para_d.Alignment = Element.ALIGN_JUSTIFIED;
                para_d.Add(new Chunk("b) Custodia: ", fntTextB));
                para_d.Add(new Chunk("Solicito que los instrumentos adquiridos a través de esta(s) orden(es), sean ingresador a mi nombre en mi cuenta que mantengo en Pershing; quien ejercerá el servicio de custodia del mismo.", fntTextR));

                Paragraph para_e = new Paragraph();
                para_e.Alignment = Element.ALIGN_JUSTIFIED;
                para_e.Add(new Chunk("c) Egreso de Custodia: ", fntTextB));
                para_e.Add(new Chunk("Solicito que (el) los intrumento(s) vendido(s) a través de estas comisiones, sean egresados desde mi cuenta que mantengo en Pershing.", fntTextR));

                Paragraph para_f = new Paragraph();
                para_f.Alignment = Element.ALIGN_JUSTIFIED;
                para_f.Add(new Chunk("d) Autorización: ", fntTextB));
                para_f.Add(new Chunk("Faculto expresamente a Tanner para actual a nombre propio en el cumplimiento de esta(s) orden(es).", fntTextR));

                Paragraph para_g = new Paragraph();
                para_g.Alignment = Element.ALIGN_JUSTIFIED;
                para_g.Add(new Chunk("e) Responsabilidades: ", fntTextB));
                para_g.Add(new Chunk("Declaro estar en conocimiento y aceptar que: (i) Tanner Corredores de Bolsa S.A. no asume responsabilidad alguna por la solvencia de los emisores de los valores que adquiera en virtud de estas instrucciones, o por la rentabilidad de los mismos; (ii) Tanner Corredores de Bolsa S.A. no se hace responsable por las variaciones en el tipo de cambio que pudieran producirse; (iii) Tanner Corredores de Bolsa S.A. no se hace responsable de retornar las divisas si por disposiciones de derecho interno del país donde se realiza la orden, se restrinja o impida el acceso a la compra o remesa de divisas; (iv) Tanner Corredores de Bolsa S.A. no se hace responsable de las variaciones impositivas a empresas y/o inversionistas en los mercados donde se realizan las órdenes; (v) Tanner Corredores de Bolsa S.A. se declara responsable por los dineros recibidos y por la ejecución de la orden de acuerdo a las instrucciones del Cliente; (vi) El Cliente será el único responsable de cumplir con las normas de cambios internacionales y demás disposiciones establecidas por el Banco Central de Chile, no asumiendo Tanner Corredores de Bolsa S.A., o el intermediario extranjero, obligación alguna a este respecto; (vii) El Cliente será el responsable de informar las operaciones, inversiones y resultados de éstas al Servicio de Impuestos Internos, conforme a las disposiciones que al efecto estén vigentes; (viii) Tanner no cobrará comisión directa por la ejecución de esta(s) orden(es), sin perjuicio que puede compartir los ingresos que obtengan los intermediarios o emisores extranjeros con ocasión del cumplimiento de la misma, ya sea producto de comisiones, de diferencias de precio de los valores que el Cliente ordene adquirir o enajenar o por otros conceptos; (ix) Pershing efectuó los cobros indicados por concepto de remuneración y de derechos, los que se cargaron en el monto neto de la(s) orden(es). En virtud de lo anterior, otorgo a Tanner un completo, total e irrevocable finiquito con relación a la(s) mencionada(s) operación(es)efectuada(s) sobre mi cuenta en Pershing LLC, declarando que, en su calidad de comisionista, Tanner Corredores de Bolsa S.A. ha dado cabal y oportuno cumplimiento a todas las obligaciones derivadas en la ejecución de dicha(s) orden(es).", fntTextR));

                Paragraph para_h = new Paragraph();
                para_h.Alignment = Element.ALIGN_JUSTIFIED;
                para_h.Add(new Chunk("f) ", fntTextB));
                para_h.Add(new Chunk(" El Cliente declara conocer y aceptar los riesgos asociados las operaciones de compra y venta que realiza a través de Tanner, por lo que acepta los eventuales riesgos que se puedan producir respecto al resultado de las inversiones producto de esta orden, entre los que se encuentran que el emisor de los valores entre en cesación de pagos o quiebra, o por las fluctuaciones de mercado, o por la mayor o menor rentabilidad que puedan experimentar estas inversiones.", fntTextR));

                Paragraph para_i = new Paragraph();
                para_i.Alignment = Element.ALIGN_JUSTIFIED;
                para_i.Add(new Chunk("g) ", fntTextB));
                para_i.Add(new Chunk("  Esta orden se realiza en virtud de la Circular No. 1.046 de la Superintendencia de Valores y Seguros, en donde se autoriza a los Corredores de Bolsa, prestar a sus clientes el servicio de asesorías, estudios, y comisión de compra y venta de valores extranjeros en mercados de valores externos, a través de intermediarios de valores autorizados. En dicha se especifica el procedimiento y los requisitos que deben ser observados por los clientes para instruir las comisiones de compra y venta, y los requisitos que deben ser cumplidos por los corredores nacionales, para ejecutar las comisiones conferidas. ", fntTextR));

                Paragraph para_j = new Paragraph("Sin otro particular, saluda atentamente a Usted", fntTextR);
                para_j.Alignment = Element.ALIGN_JUSTIFIED;

                documento.Add(sep);
                documento.Add(para_c);
                documento.Add(para_d);
                documento.Add(para_e);
                documento.Add(para_f);
                documento.Add(para_g);
                documento.Add(para_h);
                documento.Add(sep);

                countpage           = new Paragraph();
                countpage.Alignment = Element.ALIGN_RIGHT;
                countpage.Add(new Chunk("Página 2 de 3", fntTxtFoot));

                footTbl                     = new PdfPTable(1);
                footTbl.TotalWidth          = 300;
                footTbl.HorizontalAlignment = Element.ALIGN_CENTER;

                cellFoot         = new PdfPCell(countpage);
                cellFoot.Border  = 0;
                cellFoot.Padding = 10;

                footTbl.AddCell(cellFoot);
                footTbl.WriteSelectedRows(0, -1, 515, 30, writer.DirectContent);

                documento.NewPage();
                documento.Add(imgHeader);
                documento.Add(para_i);
                documento.Add(sep);
                documento.Add(para_j);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(sep);

                PdfPTable tablaFirma = new PdfPTable(2);
                tablaFirma.WidthPercentage = 90;

                PdfPCell cellFirmaImg   = new PdfPCell();
                PdfPCell cellFirmaDummy = new PdfPCell();
                cellFirmaDummy.Border            = 0;
                cellFirmaImg.Border              = 0;
                cellFirmaImg.HorizontalAlignment = PdfPCell.LEFT_BORDER;


                string imagenFirma     = "firma_rm.PNG";
                string imagenPathFirma = Path.Combine(@"img/", imagenFirma);
                Image  imgFirmaR       = Image.GetInstance(imagenPathFirma);

                imgFirmaR.ScalePercent(50);
                imgFirmaR.Alignment = Image.ALIGN_LEFT;

                cellFirmaImg.AddElement(imgFirmaR);
                tablaFirma.AddCell(cellFirmaImg);
                tablaFirma.AddCell(cellFirmaDummy);

                PdfPCell cellFirmaT = new PdfPCell();
                cellFirmaT.Border = 0;

                cellFirmaT.AddElement(new Paragraph("Tanner Corredores de Bolsa S.A.", fntTextB));
                cellFirmaT.AddElement(new Paragraph("RUT N° 80.962.600-8", fntText));
                cellFirmaT.AddElement(new Paragraph("Domicilio: Apoquindo 3650 Of. 902", fntText));
                cellFirmaT.AddElement(new Paragraph("p.p. Renato Madrid", fntText));
                cellFirmaT.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;

                tablaFirma.AddCell(cellFirmaT);

                PdfPCell cellFirmaC = new PdfPCell();
                cellFirmaC.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                cellFirmaC.Border = 0;

                cellFirmaC.AddElement(new Paragraph("Cliente: " + contratosCliente.NombreCliente, fntText));
                cellFirmaC.AddElement(new Paragraph("Rut: " + contratosCliente.RutCliente, fntText));

                DataTable dtDomicilio = new DataTable();
                string    Domicilio, Ciudad;
                //dtDomicilio = clnte.cl_cn_direccion_cliente(txtRutCliente.Text.Substring(0, Len(txtRutCliente.Text) - 2))

                if (dtDomicilio.Rows.Count > 0)
                {
                    dtDomicilio.Rows[0][0] = dtDomicilio.Rows[0][0].ToString().Trim().Replace("¥", "Ñ");
                    dtDomicilio.Rows[0][1] = dtDomicilio.Rows[0][1].ToString().Trim().Replace("San Fabi n", "San Fabián");
                    dtDomicilio.Rows[0][1] = dtDomicilio.Rows[0][1].ToString().Trim().Replace("San Nicol s", "San Nicolás");
                    dtDomicilio.Rows[0][1] = dtDomicilio.Rows[0][1].ToString().Trim().Replace("R nquil", "Ránquil");
                    dtDomicilio.Rows[0][1] = dtDomicilio.Rows[0][1].ToString().Trim().Replace("Chill n Viejo", "Chillán Viejo");
                    dtDomicilio.Rows[0][1] = dtDomicilio.Rows[0][1].ToString().Trim().Replace("Chill n", "Chillán");
                    dtDomicilio.Rows[0][1] = dtDomicilio.Rows[0][1].ToString().Trim().Replace("Santa B rbara", "Santa Bárbara");
                    dtDomicilio.Rows[0][1] = dtDomicilio.Rows[0][1].ToString().Trim().Replace("Juan Fern ndez", "Juan Fernández");
                    dtDomicilio.Rows[0][1] = dtDomicilio.Rows[0][1].ToString().Trim().Replace("Santa B rbara", "Santa Bárbara");

                    Domicilio = dtDomicilio.Rows[0][0].ToString().Trim() + ", " + dtDomicilio.Rows[0][1].ToString().Trim();

                    //Chaflán para solucionar el problema de las "a" con acento.
                    dtDomicilio.Rows[0][2] = dtDomicilio.Rows[0][2].ToString().Trim().Replace("San Fabi n", "San Fabián");
                    dtDomicilio.Rows[0][2] = dtDomicilio.Rows[0][2].ToString().Trim().Replace("San Nicol s", "San Nicolás");
                    dtDomicilio.Rows[0][2] = dtDomicilio.Rows[0][2].ToString().Trim().Replace("R nquil", "Ránquil");
                    dtDomicilio.Rows[0][2] = dtDomicilio.Rows[0][2].ToString().Trim().Replace("Chill n Viejo", "Chillán Viejo");
                    dtDomicilio.Rows[0][2] = dtDomicilio.Rows[0][2].ToString().Trim().Replace("Chill n", "Chillán");
                    dtDomicilio.Rows[0][2] = dtDomicilio.Rows[0][2].ToString().Trim().Replace("Santa B rbara", "Santa Bárbara");
                    dtDomicilio.Rows[0][2] = dtDomicilio.Rows[0][2].ToString().Trim().Replace("Juan Fern ndez", "Juan Fernández");
                    dtDomicilio.Rows[0][2] = dtDomicilio.Rows[0][2].ToString().Trim().Replace("Santa B rbara", "Santa Bárbara");

                    Ciudad = dtDomicilio.Rows[0][2].ToString().Trim();
                }
                else
                {
                    Domicilio = "";
                    Ciudad    = "";
                }

                cellFirmaC.AddElement(new Paragraph("Domicilio:." + Domicilio, fntText));
                cellFirmaC.AddElement(new Paragraph(Ciudad, fntText));

                DataTable RepLegal = new DataTable(); /*clnte.cl_cn_rep_legal_cliente(txtRutCliente.Text.Substring(0, Len(txtRutCliente.Text) - 2))*/

                foreach (DataRow dtRep in RepLegal.Rows)
                {
                    cellFirmaC.AddElement(new Paragraph("Apoderado: " + dtRep[1].ToString().Trim(), fntText));
                    cellFirmaC.AddElement(new Paragraph("Rut:" + dtRep[0].ToString().Trim(), fntText));
                }

                tablaFirma.AddCell(cellFirmaC);
                documento.Add(tablaFirma);

                documento.Add(sep);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(sep);
                documento.Add(sep);

                countpage           = new Paragraph();
                countpage.Alignment = Element.ALIGN_RIGHT;
                countpage.Add(new Chunk("Página 3 de 3", fntTxtFoot));

                footTbl                     = new PdfPTable(1);
                footTbl.TotalWidth          = 300;
                footTbl.HorizontalAlignment = Element.ALIGN_CENTER;

                cellFoot         = new PdfPCell(countpage);
                cellFoot.Border  = 0;
                cellFoot.Padding = 10;

                footTbl.AddCell(cellFoot);
                footTbl.WriteSelectedRows(0, -1, 515, 30, writer.DirectContent);

                documento.Close();

                return(nameFile);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
        {
            base.OnEndPage(writer, document);
            iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
            iTextSharp.text.Font baseFontBig    = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);
            Phrase p1Header = new Phrase("Sample Header Here", baseFontNormal);

            //Create PdfTable object
            PdfPTable pdfTab = new PdfPTable(3);

            //We will have to create separate cells to include image logo and 2 separate strings
            //Row 1
            PdfPCell pdfCell1 = new PdfPCell();
            PdfPCell pdfCell2 = new PdfPCell(p1Header);
            PdfPCell pdfCell3 = new PdfPCell();
            String   text     = "Page " + writer.PageNumber + " of ";

            //Add paging to header
            {
                cb.BeginText();
                cb.SetFontAndSize(bf, 12);
                cb.SetTextMatrix(document.PageSize.GetRight(200), document.PageSize.GetTop(45));
                cb.ShowText(text);
                cb.EndText();
                float len = bf.GetWidthPoint(text, 12);
                //Adds "12" in Page 1 of 12
                cb.AddTemplate(headerTemplate, document.PageSize.GetRight(200) + len, document.PageSize.GetTop(45));
            }
            //Add paging to footer
            {
                //cb.BeginText();
                //cb.SetFontAndSize(bf, 12);
                //cb.SetTextMatrix(document.PageSize.GetRight(180), document.PageSize.GetBottom(30));
                //cb.ShowText(text);
                //cb.EndText();
                //float len = bf.GetWidthPoint(text, 12);
                //cb.AddTemplate(footerTemplate, document.PageSize.GetRight(180) + len, document.PageSize.GetBottom(30));
            }

            //Row 2
            PdfPCell pdfCell4 = new PdfPCell(new Phrase("Sub Header Description", baseFontNormal));

            //Row 3
            PdfPCell pdfCell5 = new PdfPCell(new Phrase("Date:" + PrintTime.ToShortDateString(), baseFontBig));
            PdfPCell pdfCell6 = new PdfPCell();
            PdfPCell pdfCell7 = new PdfPCell(new Phrase("TIME:" + string.Format("{0:t}", DateTime.Now), baseFontBig));

            //set the alignment of all three cells and set border to 0
            pdfCell1.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell2.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell3.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell4.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell5.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell6.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell7.HorizontalAlignment = Element.ALIGN_CENTER;

            pdfCell2.VerticalAlignment = Element.ALIGN_BOTTOM;
            pdfCell3.VerticalAlignment = Element.ALIGN_MIDDLE;
            pdfCell4.VerticalAlignment = Element.ALIGN_TOP;
            pdfCell5.VerticalAlignment = Element.ALIGN_MIDDLE;
            pdfCell6.VerticalAlignment = Element.ALIGN_MIDDLE;
            pdfCell7.VerticalAlignment = Element.ALIGN_MIDDLE;

            pdfCell4.Colspan = 3;

            pdfCell1.Border = 0;
            pdfCell2.Border = 0;
            pdfCell3.Border = 0;
            pdfCell4.Border = 0;
            pdfCell5.Border = 0;
            pdfCell6.Border = 0;
            pdfCell7.Border = 0;

            //add all three cells into PdfTable
            pdfTab.AddCell(pdfCell1);
            pdfTab.AddCell(pdfCell2);
            pdfTab.AddCell(pdfCell3);
            pdfTab.AddCell(pdfCell4);
            pdfTab.AddCell(pdfCell5);
            pdfTab.AddCell(pdfCell6);
            pdfTab.AddCell(pdfCell7);

            pdfTab.TotalWidth      = document.PageSize.Width - 80f;
            pdfTab.WidthPercentage = 70;
            //pdfTab.HorizontalAlignment = Element.ALIGN_CENTER;

            //call WriteSelectedRows of PdfTable. This writes rows from PdfWriter in PdfTable
            //first param is start row. -1 indicates there is no end row and all the rows to be included to write
            //Third and fourth param is x and y position to start writing
            pdfTab.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 30, writer.DirectContent);
            //set pdfContent value

            //Move the pointer and draw line to separate header section from rest of page
            cb.MoveTo(40, document.PageSize.Height - 100);
            cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 100);
            cb.Stroke();

            //Move the pointer and draw line to separate footer section from rest of page
            cb.MoveTo(40, document.PageSize.GetBottom(50));
            cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(50));
            cb.Stroke();
        }
        public MemoryStream GeneratePdfTemplate(CostCalculationGarmentViewModel viewModel)
        {
            BaseFont bf          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            BaseFont bf_bold     = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            Font     normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7);
            Font     bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7);
            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. EFRATA RETAILINDO", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "COST CALCULATION PENJUALAN UMUM", 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}", 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.Name}", 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}", 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}", 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("LINE", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.Line.Name}", 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 (Bottom, Column 1)
            PdfPTable table_detail2 = new PdfPTable(2);
            table_detail2.TotalWidth = 180f;

            float[] detail2_widths = new float[] { 1f, 2f };
            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("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("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("CONT/STYLE", 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("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("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 Detail 3 (Bottom, Column 2)
            PdfPTable table_detail3 = new PdfPTable(3);
            table_detail3.TotalWidth = 190f;

            float[] detail3_widths = new float[] { 1.7f, 1f, 1.3f };
            table_detail3.SetWidths(detail3_widths);

            PdfPCell cell_detail3 = 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_detail3_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_detail3.Phrase = new Phrase("TOTAL (OL+Material)", normal_font);
            table_detail3.AddCell(cell_detail3);
            double total = 0;
            foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials)
            {
                total += item.Total;
            }
            total += viewModel.ProductionCost;
            cell_detail3_colspan2.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(total), normal_font);
            table_detail3.AddCell(cell_detail3_colspan2);

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

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

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

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

            cell_detail3.Phrase = new Phrase("SUB TOTAL", normal_font);
            table_detail3.AddCell(cell_detail3);
            cell_detail3_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterFreightCost)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan2);

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

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

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

            ////cell_detail3.Phrase = new Phrase("PROCESS COST" + "".PadRight(5), normal_font);
            cell_detail3.Phrase = new Phrase("OL" + "".PadRight(5), normal_font);
            table_detail3.AddCell(cell_detail3);
            double processCost = viewModel.ProductionCost;
            ////cell_detail3_colspan2.Phrase = new Phrase($"{GetCurrencyValue(processCost, isDollar)}", normal_font);
            cell_detail3_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(processCost)}", normal_font);
            //cell_detail3_colspan2.Phrase = new Phrase($"{(processCost)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan2);

            cell_detail3.Phrase = new Phrase("OTL1" + "".PadRight(5), normal_font);
            table_detail3.AddCell(cell_detail3);
            double NOTL1CalculatedValue = viewModel.OTL1.CalculatedValue ?? 0;
            cell_detail3_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(NOTL1CalculatedValue)}", normal_font);
            //cell_detail3_colspan2.Phrase = new Phrase($"{(NOTL1CalculatedValue)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan2);

            cell_detail3.Phrase = new Phrase("OTL2" + "".PadRight(5), normal_font);
            table_detail3.AddCell(cell_detail3);
            double NOTL2CalculatedValue = viewModel.OTL2.CalculatedValue ?? 0;
            cell_detail3_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(NOTL2CalculatedValue)}", normal_font);
            //cell_detail3_colspan2.Phrase = new Phrase($"{(NOTL2CalculatedValue)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan2);

            cell_detail3.Phrase = new Phrase("Total (OL+OTL1+OTL2)" + "".PadRight(5), normal_font);
            table_detail3.AddCell(cell_detail3);
            double totale = viewModel.ProductionCost + NOTL1CalculatedValue + NOTL2CalculatedValue;
            cell_detail3_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(totale)}", normal_font);
            //cell_detail3_colspan2.Phrase = new Phrase($"{(totale)}", normal_font);
            table_detail3.AddCell(cell_detail3_colspan2);
            #endregion
            #region Detail 4.1 (Bottom, Column 3.1)
            PdfPTable table_detail4_1 = new PdfPTable(2);
            table_detail4_1.TotalWidth = 180f;

            float[] detail4_1_widths = new float[] { 1f, 1f };
            table_detail4_1.SetWidths(detail4_1_widths);

            PdfPCell cell_detail4_1 = 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_detail4_1.Phrase = new Phrase("FOB PRICE", bold_font);
            table_detail4_1.AddCell(cell_detail4_1);
            cell_detail4_1.Phrase = new Phrase("CMT PRICE", bold_font);
            table_detail4_1.AddCell(cell_detail4_1);

            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_detail4_1.Phrase = new Phrase($"{FOB_Price}", normal_font);
            table_detail4_1.AddCell(cell_detail4_1);
            cell_detail4_1.Phrase = new Phrase($"{CMT_Price}", normal_font);
            table_detail4_1.AddCell(cell_detail4_1);
            #endregion

            #region Detail 4.2 (Bottom, Column 3.2)
            PdfPTable table_detail4_2 = new PdfPTable(2);
            table_detail4_2.TotalWidth = 180f;

            float[] detail4_2_widths = new float[] { 1f, 1f };
            table_detail4_2.SetWidths(detail4_2_widths);

            PdfPCell cell_detail4_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_detail4_2.Phrase = new Phrase("CNF PRICE", bold_font);
            table_detail4_2.AddCell(cell_detail4_2);
            cell_detail4_2.Phrase = new Phrase("CIF PRICE", bold_font);
            table_detail4_2.AddCell(cell_detail4_2);

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

            #region Detail 5 (Bottom, Column 3.3)
            PdfPTable table_detail5 = new PdfPTable(4);
            table_detail5.TotalWidth = 180f;

            float[] detail5_widths = new float[] { 1f, 1.25f, 1f, 1.25f };
            table_detail5.SetWidths(detail5_widths);
            PdfPCell cell_detail5 = 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_detail5 = 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_detail5.Phrase = new Phrase("FREIGHT", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase($"= {freight}", normal_font);
            table_detail5.AddCell(cell_detail5);

            cell_detail5 = 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_detail5.Phrase = new Phrase("INSURANCE", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase($"= {insurance}", normal_font);
            table_detail5.AddCell(cell_detail5);

            cell_detail5 = 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_detail5.Phrase = new Phrase("CONFIRM PRICE", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase($"= {confirmPriceFOB}", normal_font);
            table_detail5.AddCell(cell_detail5);

            cell_detail5 = 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_detail5.Phrase = new Phrase("SMV CUT", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase($"= {viewModel.SMV_Cutting}", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase("SMV SEW", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase($"= {viewModel.SMV_Sewing}", normal_font);
            table_detail5.AddCell(cell_detail5);

            cell_detail5 = 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_detail5.Phrase = new Phrase("SMV FIN", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase($"= {viewModel.SMV_Finishing}", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase("SMV TOT", normal_font);
            table_detail5.AddCell(cell_detail5);
            cell_detail5 = 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_detail5.Phrase = new Phrase($"= {viewModel.SMV_Total}", normal_font);
            table_detail5.AddCell(cell_detail5);
            #endregion

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

            float[] signature_widths = new float[] { 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("Yg Membuat,", 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 < 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("Merchandiser", normal_font);
            table_signature.AddCell(cell_signature);
            cell_signature.Phrase = new Phrase("Marketing Director", 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, 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_detail1.TotalHeight ? imageHeight : table_detail1.TotalHeight;
            float   row2Y              = row1Y - row1Height - 10;
            float[] row3Heights        = { table_detail2.TotalHeight, table_detail3.TotalHeight, table_detail4_1.TotalHeight + 10 + table_detail4_2.TotalHeight + 10 + table_detail5.TotalHeight };
            float   dollarDetailHeight = 10;
            if (isDollar)
            {
                row3Heights[2] += 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++)
            {
                cell_ccm_center.Phrase = new Phrase((i + 1).ToString(), normal_font);
                table_ccm.AddCell(cell_ccm_center);

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

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

                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.Name), 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.Name), 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_detail2.WriteSelectedRows(0, -1, 10, row3Y, cb);

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

            table_detail4_1.WriteSelectedRows(0, -1, 400, row3Y, cb);

            float detail4_2Y = row3Y - table_detail4_1.TotalHeight - 10;
            table_detail4_2.WriteSelectedRows(0, -1, 400, detail4_2Y, cb);

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

            float table_signatureX;
            float table_signatureY;
            if (signatureInsideRow3)
            {
                table_signatureX           = margin + table_detail2.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);
        }
Ejemplo n.º 5
0
        private static float MaterialTable(PdfWriter writer, Order infor, IType model)
        {
            PdfPTable table = new PdfPTable(4);
            PdfPCell  cell  = new PdfPCell(new Phrase("SPECIFICATION OF MATERIAL"));

            table.HorizontalAlignment = 2;
            var allData = model.GetAllValues();

            cell.Colspan             = 4;
            cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("No."));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("Name"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("Length (mm)"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase("Quantity"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            // No 1.
            cell = new PdfPCell(new Phrase("1"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            table.AddCell(model.ShaftRow.DisplayName);
            //int value = Nearest5(allData["A3"]);
            cell = new PdfPCell(new Phrase(model.ShaftRow.Length.ToString()));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("01"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);

            // No 2
            cell = new PdfPCell(new Phrase("2"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            table.AddCell(model.RollerPineRow.DisplayName);
            //value = Nearest5(allData["L"]);
            cell = new PdfPCell(new Phrase(model.RollerPineRow.Length.ToString()));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("01"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);

            // No 3
            cell = new PdfPCell(new Phrase("3"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            table.AddCell(model.BearingStandRow.DisplayName);
            cell = new PdfPCell(new Phrase(""));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("02"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);

            // No 4
            cell = new PdfPCell(new Phrase("4"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            table.AddCell(model.BearingRow.DisplayName);
            cell = new PdfPCell(new Phrase(""));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("02"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);

            // No 5
            cell = new PdfPCell(new Phrase("5"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            table.AddCell(model.SealRow.DisplayName);
            cell = new PdfPCell(new Phrase(""));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("02"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);

            // No 6
            cell = new PdfPCell(new Phrase("6"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            table.AddCell(model.CirclipRow.DisplayName);
            cell = new PdfPCell(new Phrase(""));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("02"));
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            //table.WidthPercentage = 50.0f;

            table.SetTotalWidth(new float[] { 25f, 200f, 80f, 50f });
            float h = table.TotalHeight;

            table.WriteSelectedRows(0, -1, 14, h + 14, writer.DirectContent);
            return(table.TotalHeight);
        }
        public MemoryStream GeneratePdfTemplate(RO_GarmentViewModel viewModel)
        {
            //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. EFRATA RETAILINDO", 10, 820, 0);
            cb.SetFontAndSize(bf_bold, 12);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "RO PENJUALAN UMUM", 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.CostCalculationGarment.RO}", 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.ToString("dd MMMM yyyy")}", normal_font);
            table_top.AddCell(cell_top);

            cell_top.Phrase = new Phrase("LINE", normal_font);
            table_top.AddCell(cell_top);
            table_top.AddCell(cell_colon);
            cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.Line.Name}", 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.Buyer.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.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()}", 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.Name}", normal_font);
            table_top.AddCell(cell_top);

            byte[] imageByte;
            float  imageHeight;
            try
            {
                imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.CostCalculationGarment.ImageFile));
                Image image = Image.GetInstance(imgb: imageByte);

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

                float imageY = 800 - image.ScaledHeight;
                imageHeight = image.ScaledHeight;
                image.SetAbsolutePosition(520, imageY);
                cb.AddImage(image, inlineImage: true);
            }
            catch (Exception)
            {
                imageHeight = 0;
            }


            float row1Y = 800;

            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 = 500f;

            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        = imageHeight > table_top.TotalHeight ? imageHeight : 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(5);
            table_fabric.TotalWidth = 500f;

            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.CostCalculationGarment.CostCalculationGarment_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.ToString() != null ? String.Format("{0} " + materialModel.UOMQuantity.Name, 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 = 500f;

            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(5);
            table_accessories.TotalWidth = 500f;

            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.CostCalculationGarment.CostCalculationGarment_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.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 Ongkos
            //Ongkos Title
            PdfPTable table_ong_top = new PdfPTable(1);
            table_ong_top.TotalWidth = 500f;

            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;


            //Main Table Ongkos
            PdfPTable table_budget = new PdfPTable(5);
            table_budget.TotalWidth = 500f;

            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.CostCalculationGarment.CostCalculationGarment_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.ToString()) : "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 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        = rowYBudget - table_budget.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.Name != null ? size.Size.Name : "", 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();
                        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)
            {
                PdfPTable table_ro_image = new PdfPTable(8);
                table_ro_image.DefaultCell.Border = Rectangle.NO_BORDER;
                float[] ro_widths = new float[8];

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

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

                table_ro_image.TotalWidth = 570f;

                for (var i = 0; i < viewModel.ImagesFile.Count; i++)
                {
                    try
                    {
                        roImage = Convert.FromBase64String(Base64.GetBase64File(viewModel.ImagesFile[i]));
                    }
                    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);
                    var   imageName = viewModel.ImagesName[i];

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

                    PdfPCell imageCell = new PdfPCell(images);
                    imageCell.Border  = 0;
                    imageCell.Padding = 4;

                    PdfPCell nameCell = new PdfPCell();
                    nameCell.Border  = 0;
                    nameCell.Padding = 4;

                    nameCell.Phrase = new Phrase(imageName, normal_font);
                    PdfPTable table_ro_name = new PdfPTable(1);
                    table_ro_name.DefaultCell.Border = Rectangle.NO_BORDER;

                    table_ro_name.AddCell(imageCell);
                    table_ro_name.AddCell(nameCell);
                    table_ro_name.CompleteRow();
                    table_ro_image.AddCell(table_ro_name);
                }

                table_ro_image.CompleteRow();

                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("(Bekti Wahyuningsih)", 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);
        }
        public MemoryStream GeneratePdfTemplate(CostCalculationGarmentViewModel viewModel)
        {
            BaseFont bf          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            BaseFont bf_bold     = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            Font     normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7);
            Font     bold_font   = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7);
            DateTime now         = DateTime.Now;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                cell_ccm.HorizontalAlignment = Element.ALIGN_LEFT;

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

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

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

                cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT;

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

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

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

                quantity = Math.Ceiling(quantity);

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

            document.Close();

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

            return(stream);
        }
Ejemplo n.º 8
0
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            //Regular
            string fontpath = Path.Combine(PathAplicacion, "Content/fonts/ubuntu/Raleway-Regular.ttf");
            //Bold
            string fontpathbold = Path.Combine(PathAplicacion, "Content/fonts/ubuntu/Raleway-Bold.ttf");
            //Fonts para el PDF
            BaseFont customfont     = BaseFont.CreateFont(fontpath, BaseFont.CP1252, BaseFont.EMBEDDED);
            BaseFont customfontbold = BaseFont.CreateFont(fontpathbold, BaseFont.CP1252, BaseFont.EMBEDDED);

            Font baseFontNormal = new Font(customfont, 12f, 0, new BaseColor(0, 0, 0));     //new Font(Font.FontFamily.HELVETICA, 12f, Font.NORMAL, BaseColor.BLACK);
            Font baseFontBig    = new Font(customfontbold, 12f, 0, new BaseColor(0, 0, 0)); //new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD, BaseColor.BLACK);

            Phrase p1Header = new Phrase("R E P O R T E", baseFontNormal);

            string FilePath = Path.Combine(PathAplicacion, "Content/img/Logo QPH Reportes Final.png");

            //Imagen
            Image imagen = Image.GetInstance(FilePath);

            imagen.SetAbsolutePosition(document.LeftMargin, writer.PageSize.GetTop(document.TopMargin) + 25);
            imagen.ScaleAbsolute(150f, 50f);
            document.Add(imagen);
            //imagen.WidthPercentage = 50;

            //PdfPCell logocell = new PdfPCell(imagen, true);

            //Create PdfTable object
            PdfPTable pdfTab = new PdfPTable(3);

            //We will have to create separate cells to include image logo and 2 separate strings
            //Row 1
            PdfPCell pdfCell1 = new PdfPCell();
            PdfPCell pdfCell2 = new PdfPCell(p1Header);
            PdfPCell pdfCell3 = new PdfPCell();
            String   text     = "Página " + writer.PageNumber + " de ";

            //Add paging to header
            //{
            //    cb.BeginText();
            //    cb.SetFontAndSize(bf, 12);
            //    cb.SetTextMatrix(document.PageSize.GetRight(200), document.PageSize.GetTop(45));
            //    cb.ShowText(text);
            //    cb.EndText();
            //    float len = bf.GetWidthPoint(text, 12);
            //    //Adds "12" in Page 1 of 12
            //    cb.AddTemplate(headerTemplate, document.PageSize.GetRight(200) + len, document.PageSize.GetTop(45));
            //}
            //Add paging to footer
            {
                cb.BeginText();
                cb.SetFontAndSize(customfont, 12);
                cb.SetTextMatrix(document.PageSize.GetRight(180), document.PageSize.GetBottom(30));
                cb.ShowText(text);
                cb.EndText();
                float len = customfont.GetWidthPoint(text, 12);
                cb.AddTemplate(footerTemplate, document.PageSize.GetRight(180) + len, document.PageSize.GetBottom(30));
            }

            //Row 2
            PdfPCell pdfCell4 = new PdfPCell(new Phrase(TituloReporte, baseFontNormal));

            //Row 3
            PdfPCell pdfCell5 = new PdfPCell(new Phrase("Date:" + PrintTime.ToShortDateString(), baseFontBig));
            PdfPCell pdfCell6 = new PdfPCell();
            PdfPCell pdfCell7 = new PdfPCell(new Phrase("Hora:" + string.Format("{0:t}", DateTime.Now), baseFontBig));

            //set the alignment of all three cells and set border to 0
            pdfCell1.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell2.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell3.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell4.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell5.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell6.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell7.HorizontalAlignment = Element.ALIGN_CENTER;

            pdfCell2.VerticalAlignment = Element.ALIGN_BOTTOM;
            pdfCell3.VerticalAlignment = Element.ALIGN_MIDDLE;
            pdfCell4.VerticalAlignment = Element.ALIGN_TOP;
            pdfCell5.VerticalAlignment = Element.ALIGN_MIDDLE;
            pdfCell6.VerticalAlignment = Element.ALIGN_MIDDLE;
            pdfCell7.VerticalAlignment = Element.ALIGN_MIDDLE;

            pdfCell4.Colspan = 3;

            pdfCell1.Border = 0;
            pdfCell2.Border = 0;
            pdfCell3.Border = 0;
            pdfCell4.Border = 0;
            pdfCell5.Border = 0;
            pdfCell6.Border = 0;
            pdfCell7.Border = 0;

            //add all three cells into PdfTable
            pdfTab.AddCell(pdfCell1);
            pdfTab.AddCell(pdfCell2);
            pdfTab.AddCell(pdfCell3);
            pdfTab.AddCell(pdfCell4);
            //pdfTab.AddCell(pdfCell5);
            //pdfTab.AddCell(pdfCell6);
            pdfTab.AddCell(pdfCell7);

            pdfTab.TotalWidth      = document.PageSize.Width - 80f;
            pdfTab.WidthPercentage = 70;
            //pdfTab.HorizontalAlignment = Element.ALIGN_CENTER;

            //call WriteSelectedRows of PdfTable. This writes rows from PdfWriter in PdfTable
            //first param is start row. -1 indicates there is no end row and all the rows to be included to write
            //Third and fourth param is x and y position to start writing
            pdfTab.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 30, writer.DirectContent);
            //set pdfContent value

            //Move the pointer and draw line to separate header section from rest of page
            cb.MoveTo(40, document.PageSize.Height - 100);
            cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 100);
            cb.Stroke();

            //Move the pointer and draw line to separate footer section from rest of page
            cb.MoveTo(40, document.PageSize.GetBottom(50));
            cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(50));
            cb.Stroke();
        }
Ejemplo n.º 9
0
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            base.OnStartPage(writer, document);
            Rectangle pageSize = document.PageSize;

            if (this.Title != string.Empty)
            {
                cb.BeginText();
                cb.SetFontAndSize(bf, 13);
                cb.SetRGBColorFill(0, 0, 0);
                cb.SetTextMatrix(180, pageSize.GetTop(40));
                cb.ShowText(this.Title);



                Rectangle page = document.PageSize;

                // Step 2 - create two column table;
                PdfPTable head = new PdfPTable(1);
                head.TotalWidth = page.Width / 6;


                // add header image; PdfPCell() overload sizes image to fit cell
                iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(this.TESTE);
                // logo.Width = 100;


                PdfPCell imghead = new PdfPCell(logo, true);

                imghead.HorizontalAlignment = 0;
                imghead.Border = Rectangle.NO_BORDER;
                head.AddCell(imghead);



                // write (write) table to PDF document;
                // WriteSelectedRows() requires you to specify absolute position!


                head.WriteSelectedRows(0, -1, page.Width / 30, page.Height - document.TopMargin + head.TotalHeight, writer.DirectContent);



                cb.EndText();
            }
            if (HeaderLeft + HeaderRight != string.Empty)
            {
                PdfPTable HeaderTable = new PdfPTable(2);
                HeaderTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                HeaderTable.TotalWidth = pageSize.Width - 80;
                HeaderTable.SetWidthPercentage(new float[] { 45, 45 }, pageSize);

                PdfPCell HeaderLeftCell = new PdfPCell(new Phrase(8, HeaderLeft, HeaderFont));
                HeaderLeftCell.Padding          = 5;
                HeaderLeftCell.PaddingBottom    = 8;
                HeaderLeftCell.BorderWidthRight = 0;
                HeaderTable.AddCell(HeaderLeftCell);
                PdfPCell HeaderRightCell = new PdfPCell(new Phrase(8, HeaderRight, HeaderFont));
                HeaderRightCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                HeaderRightCell.Padding             = 5;
                HeaderRightCell.PaddingBottom       = 8;
                HeaderRightCell.BorderWidthLeft     = 0;
                HeaderTable.AddCell(HeaderRightCell);
                cb.SetRGBColorFill(0, 0, 0);
                HeaderTable.WriteSelectedRows(0, -1, pageSize.GetLeft(40), pageSize.GetTop(50), cb);
            }
        }
Ejemplo n.º 10
0
        public bool GenerateMCDSlipDocument()
        {
            storeNumber  = GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber;
            reportNumber = "CL-OP-68";
            DataTable checkInfoDetails;
            string    errorCode;
            string    errorText;

            //Get the report data
            ShopProcedures.GetStoreManualCheckDepositData(GlobalDataAccessor.Instance.OracleDA,
                                                          GlobalDataAccessor.Instance.CurrentSiteId.StoreId,
                                                          ShopDateTime.Instance.ShopDate,
                                                          out checkInfoDetails, out errorCode, out errorText);
            if (checkInfoDetails == null || checkInfoDetails.Rows.Count == 0)
            {
                FileLogger.Instance.logMessage(LogLevel.ERROR, this, "No data returned from stored procedure for manual check deposit slips " + errorText);
                return(false);
            }
            //Initialize fonts
            RptFont =
                FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL);
            this.HeaderTitleFont =
                new Font(BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 10);

            this.MCDSlipReportTitle =
                @"Check Cash Deposit Slip";

            document = new Document(PageSize.LETTER);
            document.AddTitle(MCDSlipReportTitle);
            PdfPTable table = new PdfPTable(8);

            rptFileName =
                SecurityAccessor.Instance.EncryptConfig.ClientConfig.GlobalConfiguration.BaseLogPath + "\\MCD" + DateTime.Now.ToString("MMddyyyyhhmmssFFFFFFF") + ".pdf";
            PdfWriter     writer = PdfWriter.GetInstance(document, new FileStream(rptFileName, FileMode.Create));
            MCDPageEvents events = new MCDPageEvents();

            writer.PageEvent = events;
            document.SetPageSize(PageSize.LETTER);
            document.SetMargins(0, 0, 10, 45);

            Image image = Image.GetInstance(Properties.Resources.logo, BaseColor.WHITE);

            image.ScalePercent(25);

            //Insert the report header
            InsertReportHeader(table, image);

            document.Open();
            document.Add(table);

            PdfPTable newtable = new PdfPTable(4);

            //Insert the column headers
            InsertColumnHeaders(newtable);
            table.HeaderRows = 7;
            decimal totalCheckAmount = 0;
            int     totalNumChecks   = 0;

            foreach (DataRow dr in checkInfoDetails.Rows)
            {
                string  makerName   = Common.Libraries.Utility.Utilities.GetStringValue(dr["makername"]);
                string  cdName      = Utilities.GetStringValue(dr["username"]);
                decimal chkAmount   = Utilities.GetDecimalValue(dr["checkamount"]);
                string  depositDate = Utilities.GetDateTimeValue(dr["creationdate"]).FormatDate();
                totalNumChecks++;
                totalCheckAmount += chkAmount;
                PdfPCell pCell = new PdfPCell();
                pCell.Colspan             = 1;
                pCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
                pCell.Border = Rectangle.NO_BORDER;
                pCell.Phrase = new Phrase(makerName, RptFont);
                newtable.AddCell(pCell);
                pCell.Phrase = new Phrase(cdName, RptFont);
                newtable.AddCell(pCell);
                pCell.Phrase = new Phrase(depositDate, RptFont);
                newtable.AddCell(pCell);
                pCell.Phrase = new Phrase(String.Format("{0:n}", chkAmount), RptFont);
                pCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                newtable.AddCell(pCell);
            }

            //Add a blank line before summary
            newtable.AddCell(generateBlankLine(8));

            //Insert summary table
            PdfPCell newCell = new PdfPCell(new Paragraph("", RptFont));

            newCell.HorizontalAlignment = Element.ALIGN_LEFT;
            newCell.Border  = Rectangle.TOP_BORDER;
            newCell.Colspan = 4;
            newtable.AddCell(newCell);
            newCell.Colspan             = 1;
            newCell.HorizontalAlignment = Element.ALIGN_LEFT;
            newCell.Border = Rectangle.NO_BORDER;
            newCell.Phrase = new Phrase("Count of all Checks", RptFont);
            newtable.AddCell(newCell);
            newCell.Phrase = new Phrase(totalNumChecks.ToString(), RptFont);
            newtable.AddCell(newCell);
            newCell.Phrase = new Phrase("Total Amount of all Checks:", RptFont);
            newtable.AddCell(newCell);
            newCell.Phrase = new Phrase(string.Format("{0:n}", totalCheckAmount), RptFont);
            newCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            newtable.AddCell(newCell);
            newCell = new PdfPCell(new Paragraph("", RptFont));
            newCell.HorizontalAlignment = Element.ALIGN_LEFT;
            newCell.Border  = Rectangle.BOTTOM_BORDER;
            newCell.Colspan = 4;
            newtable.AddCell(newCell);

            document.Add(newtable);

            //Insert report footer
            PdfPTable finalSummaryTable = new PdfPTable(8);

            finalSummaryTable.TotalWidth = 500f;
            InsertReportFooter(ref finalSummaryTable);

            float yAbsolutePosition = newtable.CalculateHeights(true);

            finalSummaryTable.WriteSelectedRows(0, -1, document.LeftMargin + 30, yAbsolutePosition + 30, writer.DirectContent);

            document.Close();

            //Print and save the document
            PrintDocument();

            return(true);
        }
Ejemplo n.º 11
0
        private static MemoryStream _GetPayslipPDF(PayslipModelForPDF model)
        {
            bool grossRowAdded = false;

            using (var memoryStream = new MemoryStream())
            {
                string   ARIALUNI_TFF = Path.Combine(Path.Combine(Environment.GetEnvironmentVariable("windir"), "Fonts"), "ARIALUNI.TTF");
                BaseFont bf           = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);


                string   Courier_TFF = Path.Combine(Path.Combine(System.Environment.GetEnvironmentVariable("windir"), "Fonts"), "COUR.TTF");
                BaseFont bf3         = BaseFont.CreateFont(Courier_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                Font     cf9         = new Font(bf3, 9, Font.NORMAL);


                Font big  = new Font(bf, 18, Font.NORMAL);
                Font f9   = new Font(bf, 9, Font.NORMAL);
                Font f9b  = new Font(bf, 9, Font.BOLD);
                Font f20b = new Font(bf, 20, Font.BOLD);
                Font f12  = new Font(bf, 12, Font.NORMAL);
                Font i    = new Font(bf, 9, Font.ITALIC);
                Font u    = new Font(bf, 9, Font.UNDERLINE);
                Font fb   = new Font(bf, 9, Font.BOLD);



                PdfPCell emptyCell = new PdfPCell();
                emptyCell.Border = Rectangle.NO_BORDER;

                Document  document = new Document(PageSize.A4, 20, 20, 10, 10);
                PdfWriter writer   = PdfWriter.GetInstance(document, memoryStream);
                document.Open();

                //
                PdfPTable CompanyTable = new PdfPTable(1);
                CompanyTable.WidthPercentage = 100f;

                PdfPCell c1 = new PdfPCell();
                c1.VerticalAlignment = Element.ALIGN_MIDDLE;

                if (model.CompanyName.Contains("ERSAI"))
                {
                    c1.AddElement(new Paragraph("ERSAI Caspian Contractor, LLC", big));
                }

                if (model.CompanyName.Contains("SAKAZ"))
                {
                    c1.AddElement(new Paragraph("SAIPEM Kazakhstan, LLC", big));
                }


                if (model.CompanyName.Contains("PROTC"))
                {
                    c1.AddElement(new Paragraph("Proffecianal Training Center, LLC", big));
                }

                c1.Border            = PdfPCell.BOTTOM_BORDER;
                c1.BorderWidthBottom = 1f;
                c1.FixedHeight       = 37f;

                CompanyTable.AddCell(c1);
                document.Add(CompanyTable);

                //
                PdfPTable secondLine = new PdfPTable(3);

                secondLine.WidthPercentage = 100f;
                float[] widths = new float[] { 2f, 2f, 2f };
                secondLine.SetWidths(widths);

                PdfPCell r2c1 = new PdfPCell();
                r2c1.Border = Rectangle.NO_BORDER;

                if (model.LangCode == "1")
                {
                    r2c1.AddElement(new Paragraph(model.MonthName, f12));
                }
                else if (model.LangCode == "3")
                {
                    r2c1.AddElement(new Paragraph(model.MonthName, f12));
                }
                else
                {
                    r2c1.AddElement(new Paragraph(model.MonthName, f12));
                }

                PdfPCell r2c3 = new PdfPCell();
                r2c3.Border = Rectangle.NO_BORDER;
                if (model.LangCode == "1")
                {
                    r2c3.AddElement(new Paragraph("КОНФИДЕНЦИАЛЬНО", f12));
                }
                else if (model.LangCode == "3")
                {
                    r2c3.AddElement(new Paragraph("КОНФИДЕНЦИАЛЬНО", f12));
                }
                else
                {
                    r2c3.AddElement(new Paragraph("PRIVATE/CONFIDENTIAL", f12));
                }

                r2c3.HorizontalAlignment = Element.ALIGN_RIGHT;

                secondLine.AddCell(r2c1);
                secondLine.AddCell(emptyCell);
                secondLine.AddCell(r2c3);

                secondLine.SpacingAfter = 30f;

                document.Add(secondLine);

                //description table
                PdfPTable descTable = new PdfPTable(11);
                //float[] widths2 = new float[] { 6f, 1f, 3f, 1f, 8f, 1f, 8f, 1f, 13f, 1f, 6f };
                float[] widths2 = new float[] { 6f, 1f, 3f, 1f, 8f, 1f, 8f, 1f, 3f, 1f, 6f };
                descTable.SetWidths(widths2);
                descTable.TotalWidth  = PageSize.A4.Width - 40;
                descTable.LockedWidth = true;

                PdfPCell rr1c1;
                if (model.LangCode == "1")
                {
                    rr1c1 = new PdfPCell(new Phrase("Таб. Номері", cf9));
                }
                else if (model.LangCode == "3")
                {
                    rr1c1 = new PdfPCell(new Phrase("Таб. номер", cf9));
                }
                else
                {
                    rr1c1 = new PdfPCell(new Phrase("Badge No.", cf9));
                }

                rr1c1.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr1c1);

                PdfPCell rr1c2 = new PdfPCell(new Phrase(":", cf9));
                rr1c2.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr1c2);


                PdfPCell rr1c3 = new PdfPCell(new Phrase(model.BadgeNumber, cf9));
                rr1c3.Colspan = 2;
                rr1c3.Border  = Rectangle.NO_BORDER;
                descTable.AddCell(rr1c3);

                descTable.AddCell(emptyCell);
                descTable.AddCell(emptyCell);

                PdfPCell rr1c7;
                if (model.LangCode == "1")
                {
                    rr1c7 = new PdfPCell(new Phrase("Шығын орталығы", cf9));
                }
                else if (model.LangCode == "3")
                {
                    rr1c7 = new PdfPCell(new Phrase("Центр расходов", cf9));
                }
                else
                {
                    rr1c7 = new PdfPCell(new Phrase("Cost Center", cf9));
                }

                rr1c7.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr1c7);

                PdfPCell rr1c8 = new PdfPCell(new Phrase(":", cf9));
                rr1c8.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr1c8);

                PdfPCell rr1c9 = new PdfPCell(new Phrase(model.CostCenter, cf9));
                rr1c9.Border  = Rectangle.NO_BORDER;
                rr1c9.Colspan = 3;
                descTable.AddCell(rr1c9);


                //second row!!!
                PdfPCell rr2c1;
                if (model.LangCode == "1")
                {
                    rr2c1 = new PdfPCell(new Phrase("Қызметкердің аты-жөні", cf9));
                }
                else if (model.LangCode == "3")
                {
                    rr2c1 = new PdfPCell(new Phrase("Ф.И.О работника", cf9));
                }
                else
                {
                    rr2c1 = new PdfPCell(new Phrase("Employee Name", cf9));
                }

                rr2c1.Border = Rectangle.NO_BORDER;

                descTable.AddCell(rr2c1);

                PdfPCell rr2c2 = new PdfPCell(new Phrase(":", cf9));
                rr2c2.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr2c2);

                PdfPCell rr2c3 = new PdfPCell(new Phrase(model.Name, cf9));
                rr2c3.Colspan = 3;
                rr2c3.Border  = Rectangle.NO_BORDER;
                descTable.AddCell(rr2c3);

                descTable.AddCell(emptyCell);

                PdfPCell rr2c7;
                if (model.LangCode == "1")
                {
                    rr2c7 = new PdfPCell(new Phrase("Бөлімі", cf9));
                }
                else if (model.LangCode == "3")
                {
                    rr2c7 = new PdfPCell(new Phrase("Департамент", cf9));
                }
                else
                {
                    rr2c7 = new PdfPCell(new Phrase("Department", cf9));
                }

                rr2c7.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr2c7);

                PdfPCell rr2c8 = new PdfPCell(new Phrase(":", cf9));
                rr2c8.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr2c8);

                PdfPCell rr2c9 = new PdfPCell(new Phrase(model.Department, cf9));
                rr2c9.Border  = Rectangle.NO_BORDER;
                rr2c9.Colspan = 3;
                descTable.AddCell(rr2c9);

                //third row!!!
                PdfPCell rr3c1;
                if (model.LangCode == "1")
                {
                    rr3c1 = new PdfPCell(new Phrase("Лауазымы", cf9));
                }
                else if (model.LangCode == "3")
                {
                    rr3c1 = new PdfPCell(new Phrase("Должность", cf9));
                }
                else
                {
                    rr3c1 = new PdfPCell(new Phrase("Position", cf9));
                }

                rr3c1.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr3c1);

                PdfPCell rr3c2 = new PdfPCell(new Phrase(":", cf9));
                rr3c2.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr3c2);


                PdfPCell rr3c3 = new PdfPCell(new Phrase(model.Position, cf9));
                rr3c3.Colspan = 3;
                rr3c3.Border  = Rectangle.NO_BORDER;
                descTable.AddCell(rr3c3);

                descTable.AddCell(emptyCell);

                PdfPCell rr3c7;
                if (model.LangCode == "1")
                {
                    rr3c7 = new PdfPCell(new Phrase("Жұмыс орыны", cf9));
                }
                else if (model.LangCode == "3")
                {
                    rr3c7 = new PdfPCell(new Phrase("Место работы", cf9));
                }
                else
                {
                    rr3c7 = new PdfPCell(new Phrase("Work Location", cf9));
                }

                rr3c7.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr3c7);

                PdfPCell rr3c8 = new PdfPCell(new Phrase(":", cf9));
                rr3c8.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr3c8);

                PdfPCell rr3c9 = new PdfPCell(new Phrase(model.WorkLocation, cf9));
                rr3c9.Border  = Rectangle.NO_BORDER;
                rr3c9.Colspan = 3;
                descTable.AddCell(rr3c9);

                //fourth row!!!

                PdfPCell rr4c1;

                /*
                 * if (langCode == "1")
                 *  {
                 *      rr4c1 = new PdfPCell(new Phrase("Айлық жалақысы", cf9));
                 *  }
                 * else if (langCode == "3")
                 *  {
                 *      rr4c1 = new PdfPCell(new Phrase("Ежемесячная заработная плата", cf9));
                 *  }
                 * else
                 *  {
                 *      rr4c1 = new PdfPCell(new Phrase("Monthly Basic Salary", cf9));
                 *  }
                 */
                rr4c1 = new PdfPCell(new Phrase(model.ContractType, cf9));


                rr4c1.Colspan = 3;
                rr4c1.Border  = Rectangle.NO_BORDER;
                descTable.AddCell(rr4c1);


                PdfPCell rr4c2 = new PdfPCell(new Phrase(":", cf9));
                rr4c2.Border = Rectangle.NO_BORDER;
                descTable.AddCell(rr4c2);

                PdfPCell rr4c3 = new PdfPCell(new Phrase(model.Currency + " " + model.BasicSalary, cf9));
                rr4c3.Colspan = 2;
                rr4c3.Border  = Rectangle.NO_BORDER;
                descTable.AddCell(rr4c3);


                if (model.EmpCategory == "E")  // exspats ONLY!!
                {
                    PdfPCell rr4c4;
                    if (model.LangCode == "1")
                    {
                        rr4c4 = new PdfPCell(new Phrase("Демалыс соммасы", cf9));
                    }
                    else if (model.LangCode == "3")
                    {
                        rr4c4 = new PdfPCell(new Phrase("Сумма отпуска", cf9));
                    }
                    else
                    {
                        rr4c4 = new PdfPCell(new Phrase("Y-T-D Vacation Amount", cf9));
                    }

                    rr4c4.Colspan = 3;
                    rr4c4.Border  = Rectangle.NO_BORDER;
                    descTable.AddCell(rr4c4);

                    PdfPCell rr4c5 = new PdfPCell(new Phrase(":", cf9));
                    rr4c5.Border = Rectangle.NO_BORDER;
                    descTable.AddCell(rr4c5);

                    PdfPCell rr4c6 = new PdfPCell(new Phrase(model.Currency + " " + model.ytdVac, cf9));
                    rr4c6.Border = Rectangle.NO_BORDER;
                    descTable.AddCell(rr4c6);
                }
                else
                {
                    PdfPCell rr4c4;
                    rr4c4         = new PdfPCell(new Phrase("", cf9));
                    rr4c4.Colspan = 3;
                    rr4c4.Border  = Rectangle.NO_BORDER;
                    descTable.AddCell(rr4c4);

                    PdfPCell rr4c5 = new PdfPCell(new Phrase("", cf9));
                    rr4c5.Border = Rectangle.NO_BORDER;
                    descTable.AddCell(rr4c5);

                    PdfPCell rr4c6 = new PdfPCell(new Phrase("", cf9));
                    rr4c6.Border = Rectangle.NO_BORDER;
                    descTable.AddCell(rr4c6);
                }

                //fifth row!!!

                if (model.EmpCategory == "E")  // exspats ONLY!!
                {
                    PdfPCell rr5c1;
                    if (model.LangCode == "1")
                    {
                        rr5c1 = new PdfPCell(new Phrase("Үстеме жұмыс үшін төлем мөлшері", cf9));
                    }
                    else if (model.LangCode == "3")
                    {
                        rr5c1 = new PdfPCell(new Phrase("Ставка  за сверхурочную работу", cf9));
                    }
                    else
                    {
                        rr5c1 = new PdfPCell(new Phrase("Overtime Rate", cf9));
                    }

                    rr5c1.Colspan = 3;
                    rr5c1.Border  = Rectangle.NO_BORDER;
                    descTable.AddCell(rr5c1);

                    PdfPCell rr5c2 = new PdfPCell(new Phrase(":", cf9));
                    rr5c2.Border = Rectangle.NO_BORDER;
                    descTable.AddCell(rr5c2);

                    PdfPCell rr5c3 = new PdfPCell(new Phrase(model.Currency + " " + model.otRate, cf9));
                    rr5c3.Colspan = 2;
                    rr5c3.Border  = Rectangle.NO_BORDER;
                    descTable.AddCell(rr5c3);

                    PdfPCell rr5c4;
                    if (model.LangCode == "1")
                    {
                        rr5c4 = new PdfPCell(new Phrase("Демалыс күндері", cf9));
                    }
                    else if (model.LangCode == "3")
                    {
                        rr5c4 = new PdfPCell(new Phrase("Дни отпуска", cf9));
                    }
                    else
                    {
                        rr5c4 = new PdfPCell(new Phrase("Y-T-D Vacation Days", cf9));
                    }

                    rr5c4.Colspan = 3;
                    rr5c4.Border  = Rectangle.NO_BORDER;
                    descTable.AddCell(rr5c4);

                    PdfPCell rr5c5 = new PdfPCell(new Phrase(":", cf9));
                    rr5c5.Border = Rectangle.NO_BORDER;
                    descTable.AddCell(rr5c5);

                    PdfPCell rr5c6 = new PdfPCell(new Phrase(model.hFund, cf9));
                    rr5c6.Border = Rectangle.NO_BORDER;
                    descTable.AddCell(rr5c6);
                }

                descTable.SpacingAfter = 30f;
                document.Add(descTable);

                //PAY SLIP CENTER

                PdfPTable payslipTitle = new PdfPTable(1);
                payslipTitle.HorizontalAlignment = Element.ALIGN_CENTER;

                PdfPCell payslipCell;
                if (model.LangCode == "1")
                {
                    payslipCell = new PdfPCell(new Phrase("Есеп айырысу парағы", f20b));
                }
                else if (model.LangCode == "3")
                {
                    payslipCell = new PdfPCell(new Phrase("Расчетный лист", f20b));
                }
                else
                {
                    payslipCell = new PdfPCell(new Phrase("PAYSLIP", f20b));
                }

                payslipCell.HorizontalAlignment = Element.ALIGN_CENTER;
                payslipCell.Border = Rectangle.NO_BORDER;
                payslipTitle.AddCell(payslipCell);

                payslipTitle.SpacingAfter = 20f;

                document.Add(payslipTitle);

                //CREDITS TABLE
                //header
                PdfPTable CreditTable = new PdfPTable(6);
                float[]   widths3     = new float[] { 3f, 11f, 11f, 6f, 6f, 7f };

                CreditTable.TotalWidth  = PageSize.A4.Width - 40;
                CreditTable.LockedWidth = true;

                CreditTable.SetWidths(widths3);

                PdfPCell row1c1 = new PdfPCell(new Phrase("No.", cf9));
                row1c1.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER;
                CreditTable.AddCell(row1c1);

                PdfPCell row1c2;
                if (model.LangCode == "1")
                {
                    row1c2 = new PdfPCell(new Phrase("Жалақы сипаттамасы", cf9));
                }
                else if (model.LangCode == "3")
                {
                    row1c2 = new PdfPCell(new Phrase("Описание", cf9));
                }
                else
                {
                    row1c2 = new PdfPCell(new Phrase("Pay Description", cf9));
                }

                row1c2.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER;
                CreditTable.AddCell(row1c2);

                PdfPCell row1c3;
                if (model.LangCode == "1")
                {
                    row1c3 = new PdfPCell(new Phrase("Ескертулер", cf9));
                }
                else if (model.LangCode == "3")
                {
                    row1c3 = new PdfPCell(new Phrase("Помечание", cf9));
                }
                else
                {
                    row1c3 = new PdfPCell(new Phrase("Pay Remarks", cf9));
                }

                row1c3.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER;
                CreditTable.AddCell(row1c3);

                PdfPCell row1c4;
                if (model.LangCode == "1")
                {
                    row1c4 = new PdfPCell(new Phrase("Сағат  ", cf9));
                }
                else if (model.LangCode == "3")
                {
                    row1c4 = new PdfPCell(new Phrase("Часы", cf9));
                }
                else
                {
                    row1c4 = new PdfPCell(new Phrase("Unit", cf9));
                }

                row1c4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                row1c4.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER;
                CreditTable.AddCell(row1c4);

                PdfPCell row1c5;
                if (model.LangCode == "1")
                {
                    row1c5 = new PdfPCell(new Phrase("Төлеу м-лшері", cf9));
                }
                else if (model.LangCode == "3")
                {
                    row1c5 = new PdfPCell(new Phrase("Ставка", cf9));
                }
                else
                {
                    row1c5 = new PdfPCell(new Phrase("Rate", cf9));
                }

                row1c5.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                row1c5.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER;
                CreditTable.AddCell(row1c5);

                PdfPCell row1c6;
                if (model.LangCode == "1")
                {
                    row1c6 = new PdfPCell(new Phrase("Жиыны", cf9));
                }
                else if (model.LangCode == "3")
                {
                    row1c6 = new PdfPCell(new Phrase("Итого", cf9));
                }
                else
                {
                    row1c6 = new PdfPCell(new Phrase("Amount", cf9));
                }

                row1c6.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                row1c6.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;
                CreditTable.AddCell(row1c6);


                using (var con = new SqlConnection(model.ConnectionString))
                {
                    con.Open();
                    using (SqlCommand command = new SqlCommand("exec dbo.SP_GetPaySlip_Details @payMonthSelected, @badge, @Language_Code", con))
                    {
                        command.Parameters.AddWithValue("@payMonthSelected", model.PayMonthSelected);
                        command.Parameters.AddWithValue("@badge", model.BadgeNumber);
                        command.Parameters.AddWithValue("@Language_Code", model.LangCode);

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                //loop through credist and debits. NESTED QUERY!
                                //adding row here
                                var PayCode    = reader["PayCode"].ToString();
                                var PayDesc    = reader["PayDesc"].ToString();
                                var PayRemarks = reader["PayRemarks"].ToString();
                                var PayUnit    = reader["PayUnit"].ToString();
                                var PayRate    = reader["PayRate"].ToString();
                                var PaymentAmt = reader["PayAmount"].ToString();
                                var payType    = reader["PayType"].ToString();

                                //dynamic row credit

                                if (payType == "2") //credit
                                {
                                    PdfPCell dynamicCell1 = new PdfPCell(new Phrase(PayCode, cf9));
                                    dynamicCell1.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(dynamicCell1);

                                    PdfPCell dynamicCell2 = new PdfPCell(new Phrase(PayDesc, cf9));
                                    dynamicCell2.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(dynamicCell2);

                                    PdfPCell dynamicCell3 = new PdfPCell(new Phrase(PayRemarks, cf9));
                                    dynamicCell3.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(dynamicCell3);

                                    PdfPCell dynamicCell4 = new PdfPCell(new Phrase(PayUnit, cf9));
                                    dynamicCell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    dynamicCell4.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(dynamicCell4);

                                    PdfPCell dynamicCell5 = new PdfPCell(new Phrase(PayRate, cf9));
                                    dynamicCell5.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    dynamicCell5.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(dynamicCell5);

                                    PdfPCell dynamicCell6 = new PdfPCell(new Phrase(PaymentAmt, cf9));
                                    dynamicCell6.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    dynamicCell6.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(dynamicCell6);
                                }

                                if (payType == "3") //debit
                                {
                                    //gross row   <----- add total credit gross row first, then debits

                                    if (grossRowAdded == false)
                                    {
                                        PdfPCell rowGc1;
                                        if (model.LangCode == "1")
                                        {
                                            rowGc1 = new PdfPCell(new Phrase("Салыққа дейін жалпы жалақы сомасы", cf9));
                                        }
                                        else if (model.LangCode == "3")
                                        {
                                            rowGc1 = new PdfPCell(new Phrase("Сумма до обложения налога", cf9));
                                        }
                                        else
                                        {
                                            rowGc1 = new PdfPCell(new Phrase("Gross Salary", cf9));
                                        }

                                        rowGc1.Colspan = 5;
                                        rowGc1.Border  = Rectangle.BOTTOM_BORDER;

                                        CreditTable.AddCell(rowGc1);

                                        PdfPCell rowGc2 = new PdfPCell(new Phrase(model.GrossSalary, cf9));
                                        rowGc2.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                        rowGc2.Border = Rectangle.BOTTOM_BORDER;
                                        CreditTable.AddCell(rowGc2);

                                        //empty row (spacing) after gross salary
                                        PdfPCell rowEmpty = new PdfPCell(new Phrase(" "));
                                        rowEmpty.Border  = Rectangle.NO_BORDER;
                                        rowEmpty.Colspan = 6;
                                        CreditTable.AddCell(rowEmpty);
                                        //

                                        grossRowAdded = true;
                                    }

                                    //dynamic debit rows:

                                    PdfPCell debitCell1 = new PdfPCell(new Phrase(PayCode, cf9));
                                    debitCell1.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(debitCell1);

                                    PdfPCell debitCell2 = new PdfPCell(new Phrase(PayDesc, cf9));
                                    debitCell2.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(debitCell2);

                                    PdfPCell debitCell3 = new PdfPCell(new Phrase(PayRemarks, cf9));
                                    debitCell3.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(debitCell3);

                                    PdfPCell debitCell4 = new PdfPCell(new Phrase(PayUnit, cf9));
                                    debitCell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    debitCell4.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(debitCell4);

                                    PdfPCell debitCell5 = new PdfPCell(new Phrase(PayRate, cf9));
                                    debitCell5.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    debitCell5.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(debitCell5);

                                    PdfPCell debitCell6 = new PdfPCell(new Phrase(PaymentAmt, cf9));
                                    debitCell6.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    debitCell6.Border = Rectangle.NO_BORDER;
                                    CreditTable.AddCell(debitCell6);
                                }
                            }
                        }
                    }
                }

                if (grossRowAdded == false)
                {
                    //gross row   <----- add gross row first, then debits IF THERE WERE NO DEBITS:
                    PdfPCell rowGc1;
                    if (model.LangCode == "1")
                    {
                        rowGc1 = new PdfPCell(new Phrase("Салыққа дейін жалпы жалақы сомасы", cf9));
                    }
                    else if (model.LangCode == "3")
                    {
                        rowGc1 = new PdfPCell(new Phrase("Сумма до обложения налога", cf9));
                    }
                    else
                    {
                        rowGc1 = new PdfPCell(new Phrase("Gross Salary", cf9));
                    }

                    rowGc1.Colspan = 5;
                    rowGc1.Border  = Rectangle.BOTTOM_BORDER;
                    CreditTable.AddCell(rowGc1);

                    PdfPCell rowGc2 = new PdfPCell(new Phrase(model.GrossSalary, cf9));
                    rowGc2.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    rowGc2.Border = Rectangle.BOTTOM_BORDER;
                    CreditTable.AddCell(rowGc2);

                    //empty row (spacing) after gross salary
                    PdfPCell rowEmpty = new PdfPCell(new Phrase(" "));
                    rowEmpty.Border  = Rectangle.NO_BORDER;
                    rowEmpty.Colspan = 6;
                    CreditTable.AddCell(rowEmpty);
                    //
                }

                if (model.salaryDeduction != "")
                {
                    //deduction amount row   if deduction is not 0
                    PdfPCell rowGc1;
                    if (model.LangCode == "1")
                    {
                        rowGc1 = new PdfPCell(new Phrase("Жалпы аударымдар", cf9));
                    }
                    else if (model.LangCode == "3")
                    {
                        rowGc1 = new PdfPCell(new Phrase("Общие удержания", cf9));
                    }
                    else
                    {
                        rowGc1 = new PdfPCell(new Phrase("Deductions", cf9));
                    }

                    rowGc1.Colspan = 5;
                    rowGc1.Border  = Rectangle.BOTTOM_BORDER;
                    CreditTable.AddCell(rowGc1);

                    PdfPCell rowGc2 = new PdfPCell(new Phrase(model.salaryDeduction, cf9));
                    rowGc2.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    rowGc2.Border = Rectangle.BOTTOM_BORDER;
                    CreditTable.AddCell(rowGc2);
                }

                document.Add(CreditTable);

                //footer table
                PdfPTable TableNet = new PdfPTable(3);
                TableNet.SetWidths(new float[] { 10f, 50f, 20f });

                TableNet.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;

                PdfPCell lastC1;
                if (model.LangCode == "1")
                {
                    lastC1 = new PdfPCell(new Phrase("Төлеуге жататын сома", cf9));
                }
                else if (model.LangCode == "3")
                {
                    lastC1 = new PdfPCell(new Phrase("Сумма к выдаче", cf9));
                }
                else
                {
                    lastC1 = new PdfPCell(new Phrase("Net Payment", cf9));
                }

                lastC1.Colspan = 2;
                lastC1.Border  = Rectangle.BOTTOM_BORDER;
                TableNet.AddCell(lastC1);

                PdfPCell lastC3 = new PdfPCell(new Phrase(model.Currency + " " + model.NetSalary, f9b));
                lastC3.HorizontalAlignment = Element.ALIGN_RIGHT;
                lastC3.Border = Rectangle.BOTTOM_BORDER;
                TableNet.AddCell(lastC3);

                TableNet.WriteSelectedRows(0, -1, document.LeftMargin, 100, writer.DirectContent);

                document.Close();
                return(memoryStream);
            }
        }
Ejemplo n.º 12
0
        private const float milimetro = 2.83465f; // 1 milímetro equicala a 2.83465 puntos.

        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            PdfPTable tCabecera = new PdfPTable(3);                              // Tabla para poner la información en la cabecera.
            PdfPTable tPie      = new PdfPTable(3);                              // Tabla para poner la información en el pie.

            PdfPCell celdaLogo      = new PdfPCell();                            // Celda para poner el logo.
            PdfPCell celdaTitulo    = new PdfPCell();                            // Celda para pone el título.
            PdfPCell celdaFecha     = new PdfPCell();                            // Celda para poner la fecha.
            PdfPCell celdaNumPagina = new PdfPCell();                            // Celda para poner el número de página

            iTextSharp.text.Font fontTitulo = FontFactory.GetFont("Arial", 18f); // Fuente para utilizar en el título.
            iTextSharp.text.Font fontPie    = FontFactory.GetFont("Arial", 10f); // Fuente para utilizar en el pie.

            fontTitulo.Color = new BaseColor(0, 71, 185);                        // Color y
            fontTitulo.SetStyle(iTextSharp.text.Font.BOLD);                      // estilo.

            fontPie.Color = fontTitulo.Color;                                    // Color y
            fontPie.SetStyle(iTextSharp.text.Font.NORMAL);                       // estilo.

            celdaLogo.VerticalAlignment = Element.ALIGN_MIDDLE;                  // Alineación vertical de la celda.
            celdaLogo.Border            = 0;                                     // Sin borde.

            celdaTitulo.VerticalAlignment   = Element.ALIGN_BOTTOM;
            celdaTitulo.HorizontalAlignment = Element.ALIGN_RIGHT; // Alineación horizontal de la celda.
            celdaTitulo.Border = 0;

            celdaFecha.HorizontalAlignment = Element.ALIGN_LEFT;
            celdaFecha.Border = 0;

            celdaNumPagina.HorizontalAlignment = Element.ALIGN_RIGHT;
            celdaNumPagina.Border = 0;

            tCabecera.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin; // El tamaño de la tabla para poner la cabecera es del 100%
            tCabecera.DefaultCell.Border = 0;

            string url = "https://www.igformacion.com/wp-content/uploads/2019/04/logo-igformacion.png"; // Dirección del logo.

            celdaLogo.Image = iTextSharp.text.Image.GetInstance(new Uri(url));                          // Cargamos la imagen desde la dirección indicada en la celda.

            celdaTitulo.Phrase = new Phrase("Listado de productos", fontTitulo);                        // Ponemos el título del listado.

            tCabecera.AddCell(celdaLogo);                                                               // Añadimos el logo a la tabla cabecera.
            tCabecera.AddCell("");
            tCabecera.AddCell(celdaTitulo);                                                             // Añadimos el título a la tabla cabecera.

            // Escribimos la tabla cabecera
            tCabecera.WriteSelectedRows(0,                                                              // Desde la posición 0.
                                        -1,                                                             // Toda la tabla (Sólo hay una fila)
                                        document.LeftMargin,                                            // Left -> Margen izquierda.
                                        writer.PageSize.GetTop(document.TopMargin) + (25f * milimetro), // Top -> Márgen superior más 25 mm.
                                        writer.DirectContent);                                          // Dirección.

            tPie.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;
            tPie.DefaultCell.Border = 0;

            celdaFecha.Phrase = new Phrase(DateTime.Now.ToString("dd/MM/yyyy"), fontPie); // Fecha de impresión.

            celdaNumPagina.Phrase = new Phrase("Página " + writer.PageNumber, fontPie);   // Número de página.

            tPie.AddCell(celdaFecha);
            tPie.AddCell("");
            tPie.AddCell(celdaNumPagina);

            tPie.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetBottom(document.BottomMargin), writer.DirectContent);
        }
Ejemplo n.º 13
0
            public override void OnEndPage(PdfWriter writer, Document document)
            {
                base.OnEndPage(writer, document);

                if (_Documento.IsOpen())
                {
                    BaseColor Grey       = new BaseColor(128, 128, 128);
                    PdfPTable footerTbl  = new PdfPTable(3);
                    PdfPTable footerTbl2 = new PdfPTable(1);
                    PdfPCell  Cell;
                    string    DocName      = string.Empty;
                    string    Footerstring = string.Empty;

                    Image Imagen = Image.GetInstance(_ImagenApliredPath);
                    Imagen.Alignment = Element.ALIGN_CENTER;
                    Imagen.ScalePercent(10);

                    footerTbl.SetWidths(new float[] { 20, 60, 20 });
                    footerTbl.TotalWidth          = document.PageSize.Width;
                    footerTbl.WidthPercentage     = 70;
                    footerTbl.SpacingBefore       = 10.0F;
                    footerTbl.SpacingAfter        = 5.0F;
                    footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
                    footerTbl.DefaultCell.Border  = 0;

                    Footerstring = Resources.PDFResource.FooterStringLinea1 + System.Environment.NewLine + Resources.PDFResource.FooterStringLinea2;
                    DocName      = _FileName;


                    /* ************************************
                    ***** Armando el pie de página *****
                    ************************************ */

                    if (writer.PageNumber != 1)
                    {
                        footerTbl2.DefaultCell.Border = Rectangle.NO_BORDER;
                        _Phrase = new Phrase(DocName, _Font8Normal);
                        Cell    = new PdfPCell(_Phrase)
                        {
                            HorizontalAlignment = Element.ALIGN_LEFT,
                            VerticalAlignment   = Element.ALIGN_MIDDLE,
                            Border  = Rectangle.NO_BORDER,
                            Padding = 10
                        };
                        footerTbl.AddCell(Cell);

                        Cell = new PdfPCell(Imagen)
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER,
                            Border = Rectangle.NO_BORDER
                        };
                        footerTbl2.AddCell(Cell);
                        _Phrase = new Phrase(Footerstring, _FontPieNormal);
                        Cell    = new PdfPCell(_Phrase)
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER,
                            Border = Rectangle.NO_BORDER
                        };
                        footerTbl2.AddCell(Cell);

                        if (_FileName.ToUpper().Substring(0, 3) != "PAD")
                        {
                            _Phrase = new Phrase(string.Format("Pág. {0}", writer.PageNumber.ToString("#0")), _FontPieNormal);
                        }
                        else
                        {
                            _Phrase = new Phrase("", _FontPieNormal);
                        }

                        Cell = new PdfPCell(_Phrase)
                        {
                            HorizontalAlignment = Element.ALIGN_RIGHT,
                            VerticalAlignment   = Element.ALIGN_MIDDLE,
                            Border  = Rectangle.NO_BORDER,
                            Padding = 10
                        };

                        footerTbl.AddCell(footerTbl2);
                        footerTbl.AddCell(Cell);
                        footerTbl.WriteSelectedRows(0, -1, 0, (document.BottomMargin), writer.DirectContent);
                    }
                }
            }
Ejemplo n.º 14
0
        protected void imgPdfButton_Click(object sender, EventArgs e)
        {
            try
            {
                string text  = Session[ApplicationSession.OrganisationName].ToString();
                string text1 = Session[ApplicationSession.OrganisationAddress].ToString();
                string text2 = "Lab Report SMP";

                using (StringWriter sw = new StringWriter())
                {
                    using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("<div align='center' style='font-size:16px;font-weight:bold;color:Black;'>");
                        sb.Append(text);
                        sb.Append("</div>");
                        sb.Append("<br/>");
                        sb.Append("<div align='center' style='font-size:13px;font-weight:bold;color:Black;'>");
                        sb.Append(text1);
                        sb.Append("</div>");
                        sb.Append("<br/>");
                        sb.Append("<div align='center' style='font-size:26px;color:Maroon;'><b>");
                        sb.Append(text2);
                        sb.Append("</b></div>");
                        sb.Append("<br/>");


                        sb.Append("<br/>");

                        PdfPTable pdfPTable = new PdfPTable(gvLabReportSMP.HeaderRow.Cells.Count);

                        //TableCell headerCell = new TableCell();

                        PdfPCell headerCell = new PdfPCell(new Phrase("Sr No."));
                        headerCell.Padding             = 5;
                        headerCell.BorderWidth         = 1.5f;
                        headerCell.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell);

                        PdfPCell headerCell1 = new PdfPCell(new Phrase("Date"));
                        headerCell1.Padding             = 5;
                        headerCell1.BorderWidth         = 1.5f;
                        headerCell1.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell1.VerticalAlignment   = Element.ALIGN_MIDDLE;

                        pdfPTable.AddCell(headerCell1);


                        PdfPCell headerCell2 = new PdfPCell(new Phrase("Type Of Powder"));
                        headerCell2.Padding             = 5;
                        headerCell2.BorderWidth         = 1.5f;
                        headerCell2.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell2.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell2);

                        PdfPCell headerCell3 = new PdfPCell(new Phrase("Time"));
                        headerCell3.Padding             = 5;
                        headerCell3.BorderWidth         = 1.5f;
                        headerCell3.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell3.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell3);

                        PdfPCell headerCell4 = new PdfPCell(new Phrase("Batch no"));
                        headerCell4.Padding             = 5;
                        headerCell4.BorderWidth         = 1.5f;
                        headerCell4.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell4.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell4);

                        PdfPCell headerCell5 = new PdfPCell(new Phrase("Bag No"));
                        headerCell5.Padding             = 5;
                        headerCell5.BorderWidth         = 1.5f;
                        headerCell5.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell5.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell5);

                        PdfPCell headerCell6 = new PdfPCell(new Phrase("Weight."));
                        headerCell6.Padding             = 5;
                        headerCell6.BorderWidth         = 1.5f;
                        headerCell6.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell6.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell6);

                        PdfPCell headerCell7 = new PdfPCell(new Phrase("Appearance"));
                        headerCell7.Padding             = 5;
                        headerCell7.BorderWidth         = 1.5f;
                        headerCell7.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell7.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell7);

                        PdfPCell headerCell8 = new PdfPCell(new Phrase("Moisture"));
                        headerCell8.Padding             = 5;
                        headerCell8.BorderWidth         = 1.5f;
                        headerCell8.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell8.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell8);

                        PdfPCell headerCell9 = new PdfPCell(new Phrase("Total solids"));
                        headerCell9.Padding             = 5;
                        headerCell9.BorderWidth         = 1.5f;
                        headerCell9.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell9.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell9);

                        PdfPCell headerCell10 = new PdfPCell(new Phrase("Bulk density"));
                        headerCell10.Padding             = 5;
                        headerCell10.BorderWidth         = 1.5f;
                        headerCell10.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell10.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell10);

                        PdfPCell headerCell11 = new PdfPCell(new Phrase("Milk Fat"));
                        headerCell11.Padding             = 5;
                        headerCell11.BorderWidth         = 1.5f;
                        headerCell11.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell11.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell11);

                        PdfPCell headerCell12 = new PdfPCell(new Phrase("Acidity LA"));
                        headerCell12.Padding             = 5;
                        headerCell12.BorderWidth         = 1.5f;
                        headerCell12.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell12.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell12);

                        PdfPCell headerCell13 = new PdfPCell(new Phrase("Wettability"));
                        headerCell13.Padding             = 5;
                        headerCell13.BorderWidth         = 1.5f;
                        headerCell13.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell13.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell13);

                        PdfPCell headerCell14 = new PdfPCell(new Phrase("Scorched particle"));
                        headerCell14.Padding             = 5;
                        headerCell14.BorderWidth         = 1.5f;
                        headerCell14.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell14.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell14);

                        PdfPCell headerCel15 = new PdfPCell(new Phrase("Sol Index (MI)"));
                        headerCel15.Padding             = 5;
                        headerCel15.BorderWidth         = 1.5f;
                        headerCel15.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCel15.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCel15);

                        PdfPCell headerCell16 = new PdfPCell(new Phrase("Coffee Test"));
                        headerCell16.Padding             = 5;
                        headerCell16.BorderWidth         = 1.5f;
                        headerCell16.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell16.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell16);

                        PdfPCell headerCell17 = new PdfPCell(new Phrase("Flavour"));
                        headerCell17.Padding             = 5;
                        headerCell17.BorderWidth         = 1.5f;
                        headerCell17.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell17.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell17);

                        PdfPCell headerCell18 = new PdfPCell(new Phrase("Protein (%)"));
                        headerCell18.Padding             = 5;
                        headerCell18.BorderWidth         = 1.5f;
                        headerCell18.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell18.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell18);

                        PdfPCell headerCell19 = new PdfPCell(new Phrase("Ash (%)"));
                        headerCell19.Padding             = 5;
                        headerCell19.BorderWidth         = 1.5f;
                        headerCell19.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell19.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell19);

                        PdfPCell headerCell20 = new PdfPCell(new Phrase("Lumpiness"));
                        headerCell20.Padding             = 5;
                        headerCell20.BorderWidth         = 1.5f;
                        headerCell20.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell20.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell20);

                        PdfPCell headerCell21 = new PdfPCell(new Phrase("Adultration"));
                        headerCell21.Padding             = 5;
                        headerCell21.BorderWidth         = 1.5f;
                        headerCell21.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell21.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell21);

                        PdfPCell headerCell22 = new PdfPCell(new Phrase("User Id"));
                        headerCell22.Padding             = 5;
                        headerCell22.BorderWidth         = 1.5f;
                        headerCell22.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell22.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell22);

                        PdfPCell headerCell23 = new PdfPCell(new Phrase("Edit"));
                        headerCell23.Padding             = 5;
                        headerCell23.BorderWidth         = 1.5f;
                        headerCell23.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell23.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell23);

                        PdfPCell headerCell24 = new PdfPCell(new Phrase("Delete"));
                        headerCell24.Padding             = 5;
                        headerCell24.BorderWidth         = 1.5f;
                        headerCell24.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell24.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell24);



                        float[] widthsTAS = { 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f, 300f };
                        pdfPTable.SetWidths(widthsTAS);

                        for (int i = 0; i < gvLabReportSMP.Rows.Count; i++)
                        {
                            if (gvLabReportSMP.Rows[i].RowType == DataControlRowType.DataRow)
                            {
                                for (int j = 0; j < gvLabReportSMP.Columns.Count; j++)
                                {
                                    string cellText = Server.HtmlDecode(gvLabReportSMP.Rows[i].Cells[j].Text);
                                    gvLabReportSMP.Columns[1].Visible = false;
                                    DateTime dDate;
                                    double   dbvalue;
                                    int      intvalue;

                                    if (DateTime.TryParse(cellText, out dDate))
                                    {
                                        PdfPCell CellTwoHdr = new PdfPCell(new Phrase(cellText));
                                        CellTwoHdr.HorizontalAlignment = Element.ALIGN_CENTER;
                                        CellTwoHdr.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                        CellTwoHdr.Padding             = 5;
                                        pdfPTable.AddCell(CellTwoHdr);
                                    }
                                    else if (double.TryParse(cellText, out dbvalue) || Int32.TryParse(cellText, out intvalue))
                                    {
                                        PdfPCell CellTwoHdr = new PdfPCell(new Phrase(cellText));
                                        CellTwoHdr.HorizontalAlignment = Element.ALIGN_CENTER;
                                        CellTwoHdr.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                        CellTwoHdr.Padding             = 5;
                                        pdfPTable.AddCell(CellTwoHdr);
                                    }
                                    else
                                    {
                                        PdfPCell CellTwoHdr = new PdfPCell(new Phrase(cellText));
                                        CellTwoHdr.HorizontalAlignment = Element.ALIGN_CENTER;
                                        CellTwoHdr.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                        CellTwoHdr.Padding             = 5;
                                        pdfPTable.AddCell(CellTwoHdr);
                                    }
                                }
                                pdfPTable.HeaderRows = 1;
                            }
                        }

                        var imageURL = Server.MapPath("\\images") + "\\GEAProcess_large_20122024.jpg";
                        iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);

                        jpg.Alignment = Element.ALIGN_CENTER;
                        jpg.SetAbsolutePosition(30, 1060);

                        //For IDMC Logo
                        var imageURL1 = Server.MapPath("\\images") + "\\GEAProcess_large_20122024.jpg";
                        iTextSharp.text.Image jpg1 = iTextSharp.text.Image.GetInstance(imageURL1);

                        jpg1.Alignment = Element.ALIGN_RIGHT;
                        jpg1.SetAbsolutePosition(700, 1060);

                        StringReader sr = new StringReader(sb.ToString());

                        Document pdfDoc = new Document(PageSize.A1, -150f, -150f, 10f, 0f);

                        HTMLWorker          htmlparser      = new HTMLWorker(pdfDoc);
                        PdfWriter           writer          = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                        PDFBackgroundHelper pageEventHelper = new PDFBackgroundHelper();
                        writer.PageEvent = pageEventHelper;
                        pdfDoc.Open();
                        htmlparser.Parse(sr);
                        pdfDoc.Add(jpg);
                        pdfDoc.Add(jpg1);
                        pdfDoc.Add(pdfPTable);


                        //----------- FOOTER -----------
                        PdfPTable footer        = new PdfPTable(2);
                        PdfPTable footer2       = new PdfPTable(2);
                        PdfPCell  footer_Cell1  = new PdfPCell(new Phrase("Shift"));
                        PdfPCell  footer2_Cell1 = new PdfPCell(new Phrase("Shift Incharge"));
                        PdfPCell  common_Cell   = new PdfPCell(new Phrase(": ____________________"));

                        float[] cols = new float[] { 100, 300 };

                        footer.SetWidthPercentage(cols, PageSize.A3);
                        footer2.SetWidthPercentage(cols, PageSize.A3);
                        footer_Cell1.Border  = 0;
                        footer2_Cell1.Border = 0;
                        common_Cell.Border   = 0;
                        footer.AddCell(footer_Cell1);
                        footer.AddCell(common_Cell);
                        footer2.AddCell(footer2_Cell1);
                        footer2.AddCell(common_Cell);
                        footer.WriteSelectedRows(0, -1, pdfDoc.LeftMargin + 125, 90, writer.DirectContent);
                        footer2.WriteSelectedRows(0, -1, pdfDoc.LeftMargin + 125, 70, writer.DirectContent);
                        //----------- /FOOTER -----------

                        pdfDoc.Close();
                        Response.ContentType = "application/pdf";

                        Response.AddHeader("content-disposition", "attachment;" + "filename=LabReportSMP" + DateTime.Now.Date.ToString("dd-MM-yyyy") + ".pdf");
                        Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        Response.Write(pdfDoc);
                        Response.Flush();
                        Response.Clear();
                        Response.End();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Error", ex);
                ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp",
                                                   "<script>alert('Oops! There is some technical Problem. Contact to your Administrator.');</script>");
            }
        }
Ejemplo n.º 15
0
 private void WriteHeader(PdfWriter writer)
 {
     writer.DirectContent.SaveState();
     _header.WriteSelectedRows(0, _header.Rows.Count, 72, writer.PageSize.Height - 72, writer.DirectContent);
     writer.DirectContent.RestoreState();
 }
        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.Comodity.Name}", normal_font);
            table_detail1.AddCell(cell_detail1);
            cell_detail1.Phrase = new Phrase("ACC", normal_font);
            table_detail1.AddCell(cell_detail1);
            table_detail1.AddCell(cell_colon);
            cell_detail1.Phrase = new Phrase($"{viewModel.AccessoriesAllowance}%", normal_font);
            table_detail1.AddCell(cell_detail1);

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

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

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

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

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

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

            PdfPCell cell_bottom_column1_1 = new PdfPCell()
            {
                Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 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 AGENT", 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("BUYER BRAND", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);
            cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.BuyerBrand.Name}", normal_font);
            table_bottom_column1_1.AddCell(cell_bottom_column1_1);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            cell_bottom_column2_2 = new PdfPCell()
            {
                Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 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
            };



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

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

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

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

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

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

            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_outer = new PdfPTable(2);
            table_outer.TotalWidth = 570f;

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

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

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

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

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

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

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

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

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

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

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

            double  Total              = 0;
            float   row1Height         = imageHeight > table_detail1.TotalHeight ? imageHeight : table_detail1.TotalHeight;
            float   row2Y              = row1Y - row1Height - 10;
            float[] row3Heights        = { table_bottom_column1_1.TotalHeight + 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}", string.Format("{0:n2}", viewModel.CostCalculationGarment_Materials[i].Price), viewModel.CostCalculationGarment_Materials[i].UOMPrice.Unit), normal_font);
                table_ccm.AddCell(cell_ccm_right);

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

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

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

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

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

            table_outer.AddCell(cell_breakDown_center);
            #endregion

            #region Draw Middle and Bottom

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

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

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

            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, 200, detail1_2Y, 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, 400, row3Y, 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);
        }
Ejemplo n.º 17
0
 private void WriteFooter(PdfWriter writer)
 {
     writer.DirectContent.SaveState();
     _footer.WriteSelectedRows(0, _footer.Rows.Count, 72, 72, writer.DirectContent);
     writer.DirectContent.RestoreState();
 }
Ejemplo n.º 18
0
        public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
        {
            base.OnEndPage(writer, document);

            iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);

            iTextSharp.text.Font baseFontBig = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 14f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);

            Phrase p1Header = new Phrase(NombreDoc, verdana);

            #region LOGOTIPO

            string   fileName = "LOGODESCOELECTRIC.jpg";
            FileInfo f        = new FileInfo(fileName);
            string   fullname = f.FullName;


            //  FileInfo direccion = new FileInfo(@"C:\Documents and Settings\User\My Documents\Dropbox\DESCO\COTIZAR LUIGI");
            // string imageFilePath = @"C:\logoDesco/DESCO log.GIF";
            string imageFilePath      = @"C:\logoDesco/LOGODESCOELECTRIC.jpg";
            iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);
            jpg.ScaleToFit(80f, 80f);
            // jpg.IsNestable();
            jpg.SetAbsolutePosition(0, 0);
            //LOGOTIPO
            //  jpg.SpacingBefore = 30f;
            // jpg.SpacingAfter = 1f;
            // jpg.Alignment = Element.ALIGN_LEFT;

            //  FileInfo direccion2 = new FileInfo("LOG2.PNG");
            //  string imageFilePath2 = direccion2.DirectoryName + "/LOG2.PNG";

            /*
             * string imageFilePath2 = @"C:\logoDesco/LOG2.PNG";
             * iTextSharp.text.Image jpg2 = iTextSharp.text.Image.GetInstance(imageFilePath2);
             * jpg2.ScaleToFit(115f, 115f);
             * // jpg.IsNestable();
             * jpg2.SetAbsolutePosition(0, 0);
             */

            #endregion LOGOTIPO

            String text2 = "Blvd. Federico Benítez 401-B La mesa, Tijuana B.C. C.P.22105 Tel/Fax: 6262712 http//:www.descoelectric.com";
            String text  = "Page " + writer.PageNumber + " of ";

            #region Numeracion de pagina y Fijacion de LOGOTIPO
            //Add paging to header
            {
                headerTemplate.AddImage(jpg);
                //     headerTemplate.AddImage(jpg2);
                cb.AddTemplate(headerTemplate, 50, 842 - 125);

                /*  cb.BeginText();
                 * cb.SetFontAndSize(bf, 12);
                 * cb.SetTextMatrix(document.PageSize.GetRight(200), document.PageSize.GetTop(45));
                 * cb.ShowText(text);
                 * cb.EndText();
                 * float len = bf.GetWidthPoint(text, 12);
                 * //Adds "12" in Page 1 of 12
                 * cb.AddTemplate(headerTemplate, document.PageSize.GetRight(200) + len, document.PageSize.GetTop(45));
                 */
            }

            //Agregar la direccion al Footer
            {
                cb.BeginText();
                cb.SetFontAndSize(bf, 8);
                cb.SetTextMatrix(document.PageSize.GetRight(480), document.PageSize.GetBottom(10));
                cb.ShowText(text2);
                cb.EndText();
                //  float len = bf.GetWidthPoint(text, 10);
                //   cb.AddTemplate(footerTemplate2, document.PageSize.GetRight(700), document.PageSize.GetBottom(25));
            }
            //Add paging to footer
            {
                cb.BeginText();
                cb.SetFontAndSize(bf, 8);
                cb.SetTextMatrix(document.PageSize.GetRight(330), document.PageSize.GetBottom(25));
                cb.ShowText(text);
                cb.EndText();
                float len = bf.GetWidthPoint(text, 8);
                cb.AddTemplate(footerTemplate, document.PageSize.GetRight(330) + len, document.PageSize.GetBottom(25));
            }

            #endregion Numeracion de pagina y Fijacion de LOGOTIPO

            #region Tabla Titulo y Numero de Cotizacion
            //Create PdfTable object
            PdfPTable pdfTab = new PdfPTable(3);

            //We will have to create separate cells to include image logo and 2 separate strings
            //Row 1
            PdfPCell pdfCell1 = new PdfPCell();
            PdfPCell pdfCell2 = new PdfPCell(p1Header);
            //set the alignment of all three cells and set border to 0
            pdfCell1.HorizontalAlignment = Element.ALIGN_LEFT;
            pdfCell2.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell2.VerticalAlignment   = Element.ALIGN_TOP;

            pdfCell1.Border = 0;
            pdfCell2.Border = 0;

            //TABLA ANIDADA DE NUMERO DE COTIZACION Y FECHA

            PdfPTable table = new PdfPTable(1);
            table.TotalWidth          = 124f;
            table.LockedWidth         = true;
            table.HorizontalAlignment = 2;

            PdfPTable nestedTable = new PdfPTable(1);
            table.WidthPercentage = 100;

            PdfPCell header = new PdfPCell(new Phrase(8, "No. " + NoDoc, arial2));
            header.HorizontalAlignment = 1;
            // header.BackgroundColor = BaseColor.LIGHT_GRAY;



            /*
             * PdfPCell header2 = new PdfPCell(new Phrase(8,CodigoDoc, arial2));
             * header2.HorizontalAlignment = 1;
             * header2.Border = 0;
             * nestedTable.AddCell(header2);
             */


            PdfPCell header3 = new PdfPCell(new Phrase(8, "Fecha: " + FechaDoc.Day + "/" + FechaDoc.Month + "/" + FechaDoc.Year, arial2));
            header3.HorizontalAlignment = 1;
            // header2.BackgroundColor = BaseColor.LIGHT_GRAY;

            PdfPCell header4 = new PdfPCell(new Phrase(8, "Factura: " + NoFactura, arial2));
            header4.HorizontalAlignment = 1;
            //   header3.BackgroundColor = BaseColor.LIGHT_GRAY;

            PdfPCell header5 = new PdfPCell(new Phrase(8, "Remision: " + NoRemision, arial2));
            header5.HorizontalAlignment = 1;

            PdfPCell header6 = new PdfPCell(new Phrase(8, "Cotizacion: " + NoCotizacion, arial));
            header6.HorizontalAlignment = 1;


            PdfPCell header7 = new PdfPCell(new Phrase(8, "Total USD: " + total, arial));
            header7.HorizontalAlignment = 1;

            //TITULO,NUMERO Y FECHA

            table.AddCell(header);
            table.AddCell(header4);
            table.AddCell(header3);
            table.AddCell(header5);
            table.AddCell(header6);
            table.AddCell(header7);


            PdfPCell anidado = new PdfPCell(table);
            anidado.HorizontalAlignment = 2;
            anidado.Border = 0;


            //TITULO,NUMERO Y FECHA

            //add all three cells into PdfTable
            pdfTab.AddCell(pdfCell1);
            pdfTab.AddCell(pdfCell2);
            pdfTab.AddCell(anidado);

            pdfTab.TotalWidth      = document.PageSize.Width - 80f;
            pdfTab.WidthPercentage = 70;
            //pdfTab.HorizontalAlignment = Element.ALIGN_CENTER;



            //call WriteSelectedRows of PdfTable. This writes rows from PdfWriter in PdfTable
            //first param is start row. -1 indicates there is no end row and all the rows to be included to write
            //Third and fourth param is x and y position to start writing
            pdfTab.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 50, writer.DirectContent);

            #endregion Tabla Titulo y Numero de Cotizacion

            #region Tabla Nombre del cliente

            PdfPTable tablaCte = new PdfPTable(2);
            tablaCte.TotalWidth      = document.PageSize.Width - 95f;
            tablaCte.LockedWidth     = true;
            tablaCte.WidthPercentage = 70;
            float[] widths = new float[] { 1f, 3f };
            tablaCte.SetWidths(widths);
            tablaCte.SpacingAfter = 10;

            PdfPCell cte = new PdfPCell(new Phrase("CLIENTE:", arial));
            cte.Border            = 0;
            cte.VerticalAlignment = Element.ALIGN_CENTER;
            tablaCte.AddCell(cte);

            PdfPCell cte2 = new PdfPCell(new Phrase(NombreCte, arial));
            cte2.Border            = 0;
            cte2.VerticalAlignment = Element.ALIGN_CENTER;
            tablaCte.AddCell(cte2);

            /*      PdfPCell b = new PdfPCell();
             *    b.Border = 0;
             *    b.Colspan = 2;
             *    // cte.VerticalAlignment = Element.ALIGN_CENTER;
             *    tablaCte.AddCell(b);
             */
            PdfPCell cto = new PdfPCell(new Phrase("CONTACTO:", arial));
            cto.Border            = 0;
            cto.VerticalAlignment = Element.ALIGN_MIDDLE;
            tablaCte.AddCell(cto);

            PdfPCell cto2 = new PdfPCell(new Phrase(NombreContacto, arial2));
            cto2.Border            = 0;
            cto2.VerticalAlignment = Element.ALIGN_MIDDLE;
            tablaCte.AddCell(cto2);

            PdfPCell vendedor = new PdfPCell(new Phrase("VENDEDOR:", arial));
            vendedor.Border            = 0;
            vendedor.VerticalAlignment = Element.ALIGN_CENTER;
            tablaCte.AddCell(vendedor);

            PdfPCell vendedor2 = new PdfPCell(new Phrase(NombreVendedor, arial2));
            vendedor2.Border            = 0;
            vendedor2.VerticalAlignment = Element.ALIGN_CENTER;
            tablaCte.AddCell(vendedor2);

            PdfPCell proyecto = new PdfPCell(new Phrase("PROYECTO:", arial));
            proyecto.Border            = 0;
            proyecto.VerticalAlignment = Element.ALIGN_CENTER;
            tablaCte.AddCell(proyecto);

            PdfPCell proyecto2 = new PdfPCell(new Phrase(NombreProyecto, arial2));
            proyecto2.Border            = 0;
            proyecto2.VerticalAlignment = Element.ALIGN_CENTER;
            tablaCte.AddCell(proyecto2);

            /*
             *                          PdfPCell lugar = new PdfPCell(new Phrase("LUGAR DE ENTREGA: TIJUANA B.C.", ITextEvents.arial));
             *                             lugar.Border = 0;
             *                          lugar.VerticalAlignment = Element.ALIGN_CENTER;
             *                          tablaCte.AddCell(lugar);
             */

            tablaCte.WriteSelectedRows(0, -1, 50, document.PageSize.Height - 110, writer.DirectContent);

            #endregion Tabla Nombre del cliente

            #region Titulos de Columnas

            PdfPTable NombreColumnas = new PdfPTable(4);
            NombreColumnas.TotalWidth      = document.PageSize.Width - 90f;
            NombreColumnas.LockedWidth     = true;
            NombreColumnas.WidthPercentage = 70;
            float[] widths2 = new float[] { 1f, 4f, 8f, 1f };
            NombreColumnas.SetWidths(widths2);

            PdfPCell item = new PdfPCell(new Phrase("ITEM", arial2));
            item.HorizontalAlignment = 1;
            item.VerticalAlignment   = Element.ALIGN_MIDDLE;
            item.BackgroundColor     = BaseColor.LIGHT_GRAY;
            NombreColumnas.AddCell(item);

            PdfPCell Catalogo = new PdfPCell(new Phrase("CATALOGO", arial2));
            Catalogo.HorizontalAlignment = 1;
            Catalogo.VerticalAlignment   = Element.ALIGN_MIDDLE;
            Catalogo.BackgroundColor     = BaseColor.LIGHT_GRAY;
            NombreColumnas.AddCell(Catalogo);

            PdfPCell Descrip = new PdfPCell(new Phrase("DESCRIPCION", arial2));
            Descrip.HorizontalAlignment = 1;
            Descrip.VerticalAlignment   = Element.ALIGN_MIDDLE;
            Descrip.BackgroundColor     = BaseColor.LIGHT_GRAY;
            NombreColumnas.AddCell(Descrip);

            PdfPCell Cantidad = new PdfPCell(new Phrase("CANT.", arial2));
            Cantidad.HorizontalAlignment = 1;
            Cantidad.VerticalAlignment   = Element.ALIGN_MIDDLE;
            Cantidad.BackgroundColor     = BaseColor.LIGHT_GRAY;
            NombreColumnas.AddCell(Cantidad);

            NombreColumnas.WriteSelectedRows(0, -1, 51, document.PageSize.Height - 170, writer.DirectContent);

            #endregion Titulos de Columnas

            //set pdfContent value

            //Move the pointer and draw line to separate header section from rest of page

            /*   cb.MoveTo(40, document.PageSize.Height - 100);
             *  cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 100);
             *  cb.Stroke();
             *
             *  //Move the pointer and draw line to separate footer section from rest of page
             *  cb.MoveTo(40, document.PageSize.GetBottom(50));
             *  cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(50));
             *  cb.Stroke();
             */
        }
Ejemplo n.º 19
0
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);
            int       pageN         = writer.PageNumber;
            string    text          = string.Format("Pág. {0} / ", writer.PageNumber);
            float     len           = bf.GetWidthPoint(text, 8);
            Rectangle pageSize      = document.PageSize;
            float     altoPiepagina = document.RightMargin + 40;

            PdfPTable footer_linea = new PdfPTable(1);

            if (HasLeyenda)
            {
                footer_linea.AddCell(leyendas);
                altoPiepagina = altoPiepagina + 25;
            }

            footer_linea.AddCell(DrawTable.DrawCell("\n", 6, CellBorder.NONE, CellAlignment.Left, 0, CellFontStyle.Normal));
            footer_linea.TotalWidth = pageSize.Width - LimitBorderTop;

            footer_linea.WidthPercentage               = 100;
            footer_linea.DefaultCell.BorderWidthLeft   = 0;
            footer_linea.DefaultCell.BorderWidthRight  = 0;
            footer_linea.DefaultCell.BorderWidthTop    = 1;
            footer_linea.DefaultCell.BorderWidthBottom = 0;
            footer_linea.DefaultCell.BorderColor       = BaseColor.BLACK;
            footer_linea.AddCell("");

            PdfPTable footer_Logos = new PdfPTable(2);

            LogoAbajoIzquierda.ScaleToFit(90f, 40f);
            LogoAbajoDerecha.ScaleToFit(90f, 40f);
            PdfPCell cellImg = new PdfPCell(LogoAbajoIzquierda);

            cellImg.Border     = PdfPCell.NO_BORDER;
            cellImg.PaddingTop = 10;

            footer_Logos.AddCell(cellImg);
            cellImg = new PdfPCell(LogoAbajoDerecha);
            cellImg.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
            cellImg.Border     = PdfPCell.NO_BORDER;
            cellImg.PaddingTop = 10;
            footer_Logos.AddCell(cellImg);

            footer_linea.AddCell(footer_Logos);
            footer_linea.WriteSelectedRows(0, -1, pageSize.GetLeft(document.LeftMargin), pageSize.GetBottom(altoPiepagina), cb);

            cb.SetRGBColorFill(100, 100, 100);
            cb.BeginText();
            cb.SetFontAndSize(bf, 8);
            cb.SetTextMatrix(pageSize.GetRight(LimitBorderBottom), pageSize.GetBottom(LimitMargin + 30));
            cb.ShowText(text);
            cb.EndText();

            cb.AddTemplate(template, pageSize.GetRight(LimitBorderBottom) + len, pageSize.GetBottom(LimitMargin + 30));

            cb.BeginText();
            cb.SetFontAndSize(bf, 8);
            cb.SetTextMatrix(pageSize.GetLeft(document.LeftMargin), pageSize.GetBottom(LimitMargin + 30));
            cb.ShowText("Hammer v1.1");
            cb.EndText();

            cb.BeginText();
            cb.SetFontAndSize(bf, 6);
            string datosImpresion;

            datosImpresion = string.Format("{0} - {1:dddd,d MMMM yyyy HH:mm:ss}", User, DateTime.Now);
            cb.SetTextMatrix(((pageSize.Width / 2) - datosImpresion.Length), pageSize.GetBottom(LimitMargin + 30));
            cb.ShowText(datosImpresion);
            cb.EndText();
        }
Ejemplo n.º 20
0
        public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
        {
            base.OnEndPage(writer, document);

            iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);

            //iTextSharp.text.Font baseFontBig = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);

            //Phrase p1Header = new Phrase("Sample Header Here", baseFontNormal);
            //Create PdfTable object
            PdfPTable pdfTab = new PdfPTable(1);

            pdfTab.WidthPercentage = 100;

            //We will have to create separate cells to include image logo and 2 separate strings
            //Row 1
            PdfPCell pdfCell1 = null;

            if (!string.IsNullOrEmpty(Util.Configuracao.PerfilSelecionadoLogado.Cliente.Logotipo))
            {
                string img = Util.Configuracao.PerfilSelecionadoLogado.Cliente.Logotipo;
                img = img.Split('?')[0];

                iTextSharp.text.Image imgAMORC = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(img));
                imgAMORC.ScaleAbsoluteWidth(48);
                imgAMORC.ScaleAbsoluteHeight(48);
                pdfCell1             = new PdfPCell(imgAMORC);
                pdfCell1.PaddingLeft = 20;
            }
            else
            {
                pdfCell1 = new PdfPCell();
            }
            PdfPCell pdfCell2 = new PdfPCell();
            PdfPCell pdfCell3 = new PdfPCell();

            string textPage = "Página:" + writer.PageNumber + "/";

            float len;

            ////Add paging to header
            //{
            //    string textCell = "Seção 211";
            //    len = bf.GetWidthPoint(textCell, 8);
            //    cb.BeginText();
            //    cb.SetFontAndSize(bf, 8);
            //    cb.SetTextMatrix(document.PageSize.GetRight(40 + len), document.PageSize.GetTop(40));
            //    cb.ShowText(textCell);
            //    cb.EndText();
            //    //cb.AddTemplate(headerTemplate, document.PageSize.GetRight(40) + len, document.PageSize.GetTop(40));

            //    len = bf.GetWidthPoint(textPage + "1", 8);
            //    cb.BeginText();
            //    cb.SetFontAndSize(bf, 8);
            //    cb.SetTextMatrix(document.PageSize.GetRight(40 + len), document.PageSize.GetTop(50));
            //    cb.ShowText(textPage);
            //    cb.EndText();

            //    textCell = "Revisão de 12/2007";
            //    len = bf.GetWidthPoint(textCell, 8);
            //    cb.BeginText();
            //    cb.SetFontAndSize(bf, 8);
            //    cb.SetTextMatrix(document.PageSize.GetRight(40 + len), document.PageSize.GetTop(60));
            //    cb.ShowText(textCell);
            //    cb.EndText();

            //    textCell = "Substitui e Cancela";
            //    len = bf.GetWidthPoint(textCell, 8);
            //    cb.BeginText();
            //    cb.SetFontAndSize(bf, 8);
            //    cb.SetTextMatrix(document.PageSize.GetRight(40 + len), document.PageSize.GetTop(70));
            //    cb.ShowText(textCell);
            //    cb.EndText();

            //    textCell = "Revisão de 03/2003";
            //    len = bf.GetWidthPoint(textCell, 8);
            //    cb.BeginText();
            //    cb.SetFontAndSize(bf, 8);
            //    cb.SetTextMatrix(document.PageSize.GetRight(40 + len), document.PageSize.GetTop(80));
            //    cb.ShowText(textCell);
            //    cb.EndText();

            //    cb.AddTemplate(headerTemplate, document.PageSize.GetRight(44), document.PageSize.GetTop(50));
            //}

            //Add paging to footer
            {
                len = bf.GetWidthPoint(textPage + "1", 8);
                cb.BeginText();
                cb.SetFontAndSize(bf, 8);
                cb.SetTextMatrix(document.PageSize.GetRight(40) - len, document.PageSize.GetBottom(30));
                cb.ShowText(textPage);
                cb.EndText();

                string textCell = _footer;
                len = bf.GetWidthPoint(textCell, 8);
                cb.BeginText();
                cb.SetFontAndSize(bf, 8);
                cb.SetTextMatrix(document.PageSize.GetLeft(40), document.PageSize.GetBottom(30));
                cb.ShowText(textCell);
                cb.EndText();

                cb.AddTemplate(footerTemplate, document.PageSize.GetRight(44), document.PageSize.GetBottom(30));
            }
            //Row 2
            //PdfPCell pdfCell4 = new PdfPCell(new Phrase("Sub Header Description", baseFontNormal));
            //Row 3


            //PdfPCell pdfCell5 = new PdfPCell(new Phrase("Date:" + PrintTime.ToShortDateString(), baseFontBig));
            //PdfPCell pdfCell6 = new PdfPCell();
            //PdfPCell pdfCell7 = new PdfPCell(new Phrase("TIME:" + string.Format("{0:t}", DateTime.Now), baseFontBig));


            //set the alignment of all three cells and set border to 0
            pdfCell1.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell2.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell3.HorizontalAlignment = Element.ALIGN_CENTER;
            //pdfCell4.HorizontalAlignment = Element.ALIGN_CENTER;
            //pdfCell5.HorizontalAlignment = Element.ALIGN_CENTER;
            //pdfCell6.HorizontalAlignment = Element.ALIGN_CENTER;
            //pdfCell7.HorizontalAlignment = Element.ALIGN_CENTER;


            pdfCell2.VerticalAlignment = Element.ALIGN_BOTTOM;
            pdfCell3.VerticalAlignment = Element.ALIGN_MIDDLE;
            //pdfCell4.VerticalAlignment = Element.ALIGN_TOP;
            //pdfCell5.VerticalAlignment = Element.ALIGN_MIDDLE;
            //pdfCell6.VerticalAlignment = Element.ALIGN_MIDDLE;
            //pdfCell7.VerticalAlignment = Element.ALIGN_MIDDLE;


            //pdfCell4.Colspan = 3;



            pdfCell1.Border = 0;
            pdfCell2.Border = 0;
            pdfCell3.Border = 0;
            //pdfCell4.Border = 0;
            //pdfCell5.Border = 0;
            //pdfCell6.Border = 0;
            //pdfCell7.Border = 0;


            //add all three cells into PdfTable
            pdfTab.AddCell(pdfCell1);
            //pdfTab.AddCell(pdfCell4);
            //pdfTab.AddCell(pdfCell5);
            //pdfTab.AddCell(pdfCell6);
            //pdfTab.AddCell(pdfCell7);

            pdfTab.TotalWidth      = document.PageSize.Width - 80f;
            pdfTab.WidthPercentage = 100;



            //call WriteSelectedRows of PdfTable. This writes rows from PdfWriter in PdfTable
            //first param is start row. -1 indicates there is no end row and all the rows to be included to write
            //Third and fourth param is x and y position to start writing
            if (_allPages == true || writer.PageNumber == 1)
            {
                pdfTab.WriteSelectedRows(0, -1, 30, document.PageSize.Height - 10, writer.DirectContent);
            }
            //Move the pointer and draw line to separate header section from rest of page
            //cb.MoveTo(40, document.PageSize.Height - 90);
            //cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 90);
            //cb.Stroke();

            //Move the pointer and draw line to separate footer section from rest of page
            //cb.MoveTo(40, document.PageSize.GetBottom(45));
            //cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(45));
            //cb.Stroke();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Evento de final de pagina, permite agregar encabezados y pie de pagina
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="factura"></param>
        public override void OnEndPage(PdfWriter writer, Document comprobante)
        {
            base.OnEndPage(writer, comprobante);
            float topMarg = comprobante.TopMargin, rightMarg = comprobante.RightMargin,
                  leftMarg = comprobante.LeftMargin, bottomMarg = comprobante.BottomMargin;

            #region Encabezado

            Rectangle pagina = comprobante.PageSize;

            PdfPTable p = cuerpoComprobante.Emisor(infoComprobantes,
                                                   domicilioFiscal, comprobante, docNum);

            //Se crea la tabla
            PdfPTable encabezado = new PdfPTable(new float[] { 2.5f, 1f, 1.5f });

            //Se ajustan las propiedades de la tabla
            encabezado.TotalWidth    = pagina.Width - rightMarg - leftMarg;
            encabezado.SpacingBefore = 20f;

            PdfPCell contenido = new PdfPCell(p);
            contenido.Border      = 0;
            contenido.FixedHeight = topMarg;

            #region Logo

            PdfPCell cLogo = new PdfPCell();
            cLogo.HorizontalAlignment = Element.ALIGN_CENTER;
            cLogo.Border      = 0;
            cLogo.FixedHeight = topMarg;

            if (logo.Equals(""))
            {
                encabezado.AddCell(cLogo);
            }
            else
            {
                try
                {
                    //Agrega la imagen a la celda
                    Image iLogo = Image.GetInstance(logo);
                    iLogo.ScaleAbsolute(395f, topMarg + 70);
                    cLogo.AddElement(iLogo);

                    //Se agrega las celda a la tabla
                    encabezado.AddCell(cLogo);
                }
                catch (Exception)
                {
                    errorRutaLogo     = true;
                    contenido.Colspan = 3;
                }
            }

            PdfPCell sinDatos = new PdfPCell();
            sinDatos.Border = 0;
            encabezado.AddCell(sinDatos);

            #endregion Logo

            //Se agrega la celda a la tabla
            encabezado.AddCell(contenido);

            //Se escribe el header directamente en el documento
            encabezado.WriteSelectedRows(0, -1, 10, pagina.Height, writer.DirectContent);

            #endregion Encabezado

            #region Pie de página

            //Se crea la tabla
            PdfPTable contenedor = new PdfPTable(new float[] { 1.75f, 5.0f, 4.25f, 0.5f });
            contenedor.TotalWidth = pagina.Width - rightMarg - leftMarg;

            Paragraph contPie;

            //Instancia de la clase COdigo Qr
            CodigoQr.CodigoQr codigo = new CodigoQr.CodigoQr();

            //monto = monto.Replace(",",".");
            monto = infoComprobantes.MontoTotalPagar.ToString();
            monto = monto.Replace(",", ".");

            //Se genera el QR
            //bool generoCodigo = codigo.generadorQR(Mensaje.pdfDirCodigoQrQas,
            //    rucEmisor, tipoCFEInt, serie, nroCFE, monto, fecha, hash1);
            bool generoCodigo = codigo.generadorQR(Mensaje.pdfDirCodigoQrQas,
                                                   infoComprobantes, monto);

            //Se obtiene el numero de pagina
            string numeroPagina = "Página " + comprobante.PageNumber.ToString() + " de ";

            //Se valida si se genero el codigo
            if (generoCodigo)
            {
                //Se agrega el codigo
                contPie = cuerpoComprobante.CodigoQr(infoComprobantes.CodigoSeguridad);
            }
            else
            {
                contPie = new Paragraph();
            }

            //Se agrega el numero de pagina al parrafo
            contPie.Add(new Chunk(new VerticalPositionMark()));
            //contPie.Add(numeroPagina);

            PdfPTable infoCAEQr;

            //infoCAEQr = cuerpoComprobante.finArchivo(serieCAE, numDesde, numHasta, numResolucion, numAutorizacion, fechaVenc);
            infoCAEQr = cuerpoComprobante.FinArchivo(infoCAE, infoComprobantes);

            //Se agrega el parrafo a la celda
            PdfPCell qr = new PdfPCell(contPie);

            qr.Border = PdfPCell.NO_BORDER;

            //Se agrega la informacion de CAE y Qr
            PdfPCell infoQr = new PdfPCell(infoCAEQr);
            infoQr.Border = PdfPCell.NO_BORDER;

            PdfPCell vacio = new PdfPCell();
            vacio.Border = PdfPCell.NO_BORDER;

            //Se agrega el numero de pagina a la celda
            PdfPCell numPag = new PdfPCell(Image.GetInstance(totalPaginas));

            //Se ajustan propiedades de la celda
            numPag.Border = PdfPCell.NO_BORDER;
            numPag.HorizontalAlignment = Element.ALIGN_LEFT;
            numPag.VerticalAlignment   = Element.ALIGN_BOTTOM;

            //Se crea la celda con la informacion para el numero de pagina
            Paragraph numPagInfo = new Paragraph(numeroPagina);
            numPagInfo.Add(Chunk.NEWLINE);
            PdfPCell infoNumPag = new PdfPCell(numPagInfo);
            infoNumPag.Border = PdfPCell.NO_BORDER;
            infoNumPag.HorizontalAlignment = Element.ALIGN_RIGHT;

            BaseFont letraTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            Font     times      = new Font(letraTimes, 11, Font.BOLD, Color.BLACK);

            Paragraph textoFecha = new Paragraph("", times);
            textoFecha.Add(Chunk.NEWLINE);
            textoFecha.Add("        " + infoCAE.FechaVencimiento + "             __________________");

            textoFecha.Add(Chunk.NEWLINE);
            //textoFecha.Add("        " + fechaVenc);
            textoFecha.Add(Mensaje.pdfFechaVencimiento + "                  CI ");
            textoFecha.Add(Chunk.NEWLINE);
            textoFecha.Add(Chunk.NEWLINE);
            textoFecha.Add("                                       __________________");
            textoFecha.Add(Chunk.NEWLINE);
            textoFecha.Add("                                                   Firma");

            PdfPCell fechaVencimiento = new PdfPCell(textoFecha);
            fechaVencimiento.Border = PdfPCell.NO_BORDER;

            contenedor.AddCell(qr);
            contenedor.AddCell(infoQr);
            contenedor.AddCell(fechaVencimiento);
            contenedor.AddCell(vacio);

            Paragraph pleyenda1 = new Paragraph("", times);
            pleyenda1.Add("                   CONFORME por los servicios yo mercadería recibida según lo detallado en esta factura y             ");
            pleyenda1.Add(Chunk.NEWLINE);
            pleyenda1.Add("                   CONFORME por su importe, que fuera detallado en el cuerpo de esta factura. La falta de pago al     ");
            pleyenda1.Add(Chunk.NEWLINE);
            pleyenda1.Add("                   vencimiento producirá la mora de pleno derecho y devengará un interés moratorio máximo legal.");

            PdfPCell leyenda1 = new PdfPCell();
            leyenda1.Border  = PdfPCell.NO_BORDER;
            leyenda1.Colspan = 4;

            leyenda1.AddElement(pleyenda1);

            contenedor.AddCell(leyenda1);

            contenedor.AddCell(vacio);
            contenedor.AddCell(vacio);
            contenedor.AddCell(infoNumPag);
            contenedor.AddCell(numPag);

            //Se escribe el footer directamente en el documento
            contenedor.WriteSelectedRows(0, -1, 10, 160, writer.DirectContent);

            #endregion Pie de página
        }
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            fontDocContent     = FontFactory.GetFont("Arial", 18, Font.NORMAL);
            fontDocContentBOLD = FontFactory.GetFont("Arial", 18, Font.BOLD);
            fontDocNormal      = FontFactory.GetFont("Arial", 8, Font.BOLD);
            fontDocNormalNote  = FontFactory.GetFont("Arial", 9, Font.BOLD);
            fontDocContentNote = FontFactory.GetFont("CourierNew", 9, Font.BOLD);
            strCompanyName     = "MSIG Insurance (Singapore) Pte. Ltd.";
            strCompanyAdd1     = "(Company Registration No. 200412212G)";
            strCompanyAdd2     = "4 Shenton Way #21-01 SGX Centre 2 Singapore 068807";
            strCompanyAdd3     = "Tel : 68277888 Fax : 68277800 www.msig.com.sg";
            try
            {
                intPageCnt++;

                Rectangle page = document.PageSize;

                PdfPTable tblHeader  = new PdfPTable(3);
                int[]     flColWidth = { 12, 73, 15 };
                tblHeader.SetWidths(flColWidth);
                tblHeader.WidthPercentage    = 100;
                tblHeader.TotalWidth         = page.Width - document.LeftMargin - document.RightMargin;
                tblHeader.DefaultCell.Border = Rectangle.NO_BORDER;
                tblHeader.DefaultCell.HorizontalAlignment = Rectangle.ALIGN_CENTER;

                PdfPCell pdfcel = new PdfPCell();
                pdfcel.HorizontalAlignment = Rectangle.ALIGN_TOP;
                pdfcel.Border = Rectangle.NO_BORDER;
                int[] iTransp1 = { 0, 0 };
                Image imgLogo  = Image.GetInstance(strLogoFilePath);
                imgLogo.ScalePercent(90F);
                imgLogo.Transparency = iTransp1;
                pdfcel.AddElement(imgLogo);
                tblHeader.AddCell(pdfcel);

                pdfcel = new PdfPCell();
                pdfcel.HorizontalAlignment = Rectangle.ALIGN_TOP;
                pdfcel.Border = Rectangle.NO_BORDER;
                Paragraph mypara = new Paragraph(strCompanyName + "\n", fontDocContent);
                mypara.Leading = 15;
                Paragraph paraAddr = new Paragraph(strCompanyAdd1 + "\n", fontDocNormal);
                paraAddr.Add(new Phrase(strCompanyAdd2 + "\n" + strCompanyAdd3, fontDocNormalNote));
                paraAddr.Leading = 10;
                pdfcel.AddElement(mypara);
                pdfcel.AddElement(paraAddr);
                tblHeader.AddCell(pdfcel);

                pdfcel = new PdfPCell();
                pdfcel.HorizontalAlignment = Rectangle.ALIGN_TOP;
                pdfcel.Border = Rectangle.NO_BORDER;
                tblHeader.AddCell(pdfcel);
                tblHeader.WriteSelectedRows(0, -1, document.LeftMargin, 835, writer.DirectContent);


                pdfcel = new PdfPCell();
                pdfcel.HorizontalAlignment = Rectangle.ALIGN_JUSTIFIED;
                pdfcel.Border = Rectangle.NO_BORDER;

                PdfPTable tblfooter   = new PdfPTable(5);
                int[]     flColWidth1 = { 49, 3, 14, 18, 16 };
                tblfooter.SetWidths(flColWidth1);
                tblfooter.WidthPercentage    = 100;
                tblfooter.TotalWidth         = page.Width - document.LeftMargin - document.RightMargin;
                tblfooter.DefaultCell.Border = Rectangle.NO_BORDER;
                tblfooter.DefaultCell.HorizontalAlignment = Rectangle.ALIGN_CENTER;

                pdfcel = new PdfPCell();
                pdfcel.HorizontalAlignment = Rectangle.ALIGN_JUSTIFIED;
                pdfcel.Border = Rectangle.NO_BORDER;

                Paragraph paraFooter1 = new Paragraph("", FontFactory.GetFont(FontFactory.COURIER, 6, Font.UNDERLINE, Color.RED));
                paraFooter1.FirstLineIndent = 10;
                paraFooter1.Leading         = 6;
                paraFooter1.Alignment       = Element.ALIGN_CENTER;
                paraFooter1.Font.SetStyle(1);
                pdfcel.AddElement(paraFooter1);
                tblfooter.AddCell(pdfcel);

                pdfcel = new PdfPCell();
                pdfcel.HorizontalAlignment = Rectangle.ALIGN_JUSTIFIED;
                pdfcel.Border = Rectangle.NO_BORDER;
                tblfooter.WriteSelectedRows(0, -1, document.LeftMargin, document.BottomMargin + 270, writer.DirectContent);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 23
0
    protected void InvoiceTest(DataSet dsinvoiceinfo, string szinvoiceid, string szFilePath, string szFileName)
    {
        string id = string.Format("Id: {0} Uri: {1}", Guid.NewGuid(), HttpContext.Current.Request.Url);

        using (Utils utility = new Utils())
        {
            utility.MethodStart(id, System.Reflection.MethodBase.GetCurrentMethod());
        }

        try
        {
            Bill_Sys_invoice _Bill_Sys_invoice = new Bill_Sys_invoice();

            DataSet dsinvoicetransinfo = new DataSet();
            dsinvoicetransinfo = _Bill_Sys_invoice.GetInvoiceTransdetails(txtCompanyID.Text, "Software");

            DataSet dscompanyinfo = new DataSet();
            dscompanyinfo = _Bill_Sys_invoice.Getcompanydetails(txtCompanyID.Text);

            DataSet dscompanyaddrss = new DataSet();
            dscompanyaddrss = _Bill_Sys_invoice.Getcompanyaddress("Software");

            string                   strBill = "";
            string                   szfilename;
            MemoryStream             m        = new MemoryStream();
            iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.A4, 36, 36, 20, 36);
            //create pdf
            float[]   widthbase = { 4f };
            PdfPTable tblBase   = new PdfPTable(widthbase);
            tblBase.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
            tblBase.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            tblBase.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_TOP;
            tblBase.DefaultCell.Colspan             = 1;
            PdfWriter writer = PdfWriter.GetInstance(document, m);
            document.Open();

            float[]   width3   = { 4f };
            PdfPTable heading3 = new PdfPTable(width3);
            heading3.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;
            heading3.DefaultCell.Border = Rectangle.NO_BORDER;
            heading3.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
            heading3.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_LEFT;
            heading3.DefaultCell.Colspan             = 1;


            tblBase.DefaultCell.Border = Rectangle.NO_BORDER;

            heading3.AddCell(new Phrase(dscompanyaddrss.Tables[0].Rows[0]["SZ_COMPANY_INFO"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 12, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading3.AddCell(new Phrase(dscompanyaddrss.Tables[0].Rows[0]["SZ_COMPANY_ADDR"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading3.AddCell(new Phrase(dscompanyaddrss.Tables[0].Rows[0]["SZ_COMPANY_ZIP"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading3.AddCell(new Phrase("Phone : " + dscompanyaddrss.Tables[0].Rows[0]["SZ_PHONE_NO"].ToString() + " ", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading3.AddCell(new Phrase("Tax Id : " + dscompanyaddrss.Tables[0].Rows[0]["SZ_TAX_ID"].ToString() + " ", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));

            heading3.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
            heading3.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_RIGHT;

            heading3.AddCell(new Phrase(dscompanyinfo.Tables[0].Rows[0]["SZ_COMPANY_NAME"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 12, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading3.AddCell(new Phrase(dscompanyinfo.Tables[0].Rows[0]["SZ_ADDRESS_STREET"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading3.AddCell(new Phrase(dscompanyinfo.Tables[0].Rows[0]["SZ_COMPANY_ADD"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));

            tblBase.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
            heading3.AddCell(new Phrase(""));
            tblBase.AddCell(heading3);


            float[]   width2   = { 2f };
            PdfPTable heading2 = new PdfPTable(width2);
            heading2.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;
            heading2.DefaultCell.Border = Rectangle.NO_BORDER;
            heading2.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            heading2.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_MIDDLE;
            tblBase.DefaultCell.Border = Rectangle.NO_BORDER;
            heading2.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
            heading2.AddCell(new Phrase("Invoice Id : " + szinvoiceid + " ", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            //heading2.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
            //heading2.AddCell(new Phrase("Date : " + currentdate + " ", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            tblBase.AddCell(heading2);


            float[]   width1   = { 1f, 3f, 2f, 3f, 3f, 2f };
            PdfPTable heading1 = new PdfPTable(width1);
            heading1.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;

            heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            heading1.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_MIDDLE;
            heading1.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_TOP;
            tblBase.DefaultCell.Border  = Rectangle.NO_BORDER;
            heading1.DefaultCell.Border = Rectangle.BOX;
            heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            heading1.DefaultCell.BackgroundColor     = iTextSharp.text.Color.LIGHT_GRAY;
            heading1.AddCell(new Phrase("Bill Number", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading1.AddCell(new Phrase("Patient Name[Case No]", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading1.AddCell(new Phrase("Bill Date", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading1.AddCell(new Phrase("Date of Service", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading1.AddCell(new Phrase("Transaction Description", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading1.AddCell(new Phrase("Cost", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading1.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;



            int    j = 0;
            double n = 0;

            for (int i = 0; i < dsinvoiceinfo.Tables[0].Rows.Count; i++)
            {
                for (int k = 0; k < dsinvoicetransinfo.Tables[0].Rows.Count; k++)
                {
                    if (j >= 40)
                    {
                        #region New Page Code
                        j = 0;
                        tblBase.AddCell(heading1);
                        tblBase.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - document.TopMargin - heading2.TotalHeight - 1, writer.DirectContent);

                        tblBase            = new PdfPTable(widthbase);
                        tblBase.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
                        tblBase.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                        tblBase.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_TOP;
                        tblBase.DefaultCell.Colspan             = 1;

                        document.NewPage();
                        heading3                    = new PdfPTable(width3);
                        heading3.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;
                        heading3.DefaultCell.Border = Rectangle.NO_BORDER;
                        heading3.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                        heading3.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_LEFT;
                        tblBase.DefaultCell.Border = Rectangle.NO_BORDER;

                        heading3.AddCell(new Phrase(dscompanyaddrss.Tables[0].Rows[0]["SZ_COMPANY_INFO"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 12, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading3.AddCell(new Phrase(dscompanyaddrss.Tables[0].Rows[0]["SZ_COMPANY_ADDR"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading3.AddCell(new Phrase(dscompanyaddrss.Tables[0].Rows[0]["SZ_COMPANY_ZIP"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading3.AddCell(new Phrase("Phone : " + dscompanyaddrss.Tables[0].Rows[0]["SZ_PHONE_NO"].ToString() + " ", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading3.AddCell(new Phrase("Tax Id : " + dscompanyaddrss.Tables[0].Rows[0]["SZ_TAX_ID"].ToString() + " ", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));


                        heading3.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                        heading3.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_RIGHT;

                        heading3.AddCell(new Phrase(dscompanyinfo.Tables[0].Rows[0]["SZ_COMPANY_NAME"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 12, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading3.AddCell(new Phrase(dscompanyinfo.Tables[0].Rows[0]["SZ_ADDRESS_STREET"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading3.AddCell(new Phrase(dscompanyinfo.Tables[0].Rows[0]["SZ_COMPANY_ADD"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));

                        tblBase.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                        heading3.AddCell(new Phrase(""));
                        tblBase.AddCell(heading3);

                        heading2                    = new PdfPTable(width2);
                        heading2.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;
                        heading2.DefaultCell.Border = Rectangle.NO_BORDER;
                        heading2.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                        heading2.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_MIDDLE;
                        tblBase.DefaultCell.Border = Rectangle.NO_BORDER;
                        heading2.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                        heading2.AddCell(new Phrase("Invoice Id : " + szinvoiceid + " ", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        //heading2.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                        //heading2.AddCell(new Phrase("Date : " + currentdate + " ", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        tblBase.AddCell(heading2);

                        heading1            = new PdfPTable(width1);
                        heading1.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;

                        heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                        heading1.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_MIDDLE;
                        heading1.DefaultCell.VerticalAlignment   = iTextSharp.text.Element.ALIGN_TOP;
                        tblBase.DefaultCell.Border  = Rectangle.NO_BORDER;
                        heading1.DefaultCell.Border = Rectangle.BOX;
                        heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                        heading1.DefaultCell.BackgroundColor     = iTextSharp.text.Color.LIGHT_GRAY;
                        heading1.AddCell(new Phrase("Bill Number", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading1.AddCell(new Phrase("Patient Name[Case No]", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading1.AddCell(new Phrase("Bill Date", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading1.AddCell(new Phrase("Date of Service", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading1.AddCell(new Phrase("Transaction Description", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading1.AddCell(new Phrase("Cost", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
                        heading1.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;



                        #endregion
                    }
                    double sztotalcost = Convert.ToDouble(dsinvoicetransinfo.Tables[0].Rows[k]["mn_cost"]);
                    heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                    heading1.AddCell(new Phrase(dsinvoiceinfo.Tables[0].Rows[i]["SZ_BILL_NUMBER"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Color.BLACK)));
                    heading1.AddCell(new Phrase(dsinvoiceinfo.Tables[0].Rows[i]["SZ_PATIENT_NAME"].ToString() + " " + "[" + dsinvoiceinfo.Tables[0].Rows[i]["SZ_CASE_NO"].ToString() + "]", iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Color.BLACK)));
                    heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                    heading1.AddCell(new Phrase(dsinvoiceinfo.Tables[0].Rows[i]["DT_BILL_DATE"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Color.BLACK)));
                    heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                    heading1.AddCell(new Phrase(dsinvoiceinfo.Tables[0].Rows[i]["SZ_SERVICE_DATE"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Color.BLACK)));
                    heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                    heading1.AddCell(new Phrase(dsinvoicetransinfo.Tables[0].Rows[k]["sz_transaction_desc"].ToString(), iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Color.BLACK)));
                    heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                    heading1.AddCell(new Phrase(sztotalcost.ToString("0.00"), iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Color.BLACK)));


                    if (i == 0)
                    {
                        n = Convert.ToDouble(dsinvoicetransinfo.Tables[0].Rows[k]["mn_cost"]);
                    }
                    else
                    {
                        n = n + Convert.ToDouble(dsinvoicetransinfo.Tables[0].Rows[k]["mn_cost"]);
                    }

                    j++;
                }
            }
            heading1.DefaultCell.Border = Rectangle.NO_BORDER;
            heading1.AddCell(new Phrase(""));
            heading1.AddCell(new Phrase(""));
            heading1.AddCell(new Phrase(""));
            heading1.AddCell(new Phrase(""));
            heading1.DefaultCell.Border = Rectangle.RECTANGLE;
            heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
            heading1.AddCell(new Phrase("Total Software Cost", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            heading1.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
            heading1.AddCell(new Phrase(n.ToString("0.00"), iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK)));
            tblBase.AddCell(heading1);

            tblBase.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - document.TopMargin - heading2.TotalHeight - 1, writer.DirectContent);
            document.Close();
            if (!Directory.Exists(ApplicationSettings.GetParameterValue("PhysicalBasePath") + szFilePath))
            {
                Directory.CreateDirectory(ApplicationSettings.GetParameterValue("PhysicalBasePath") + szFilePath);
            }
            //if (!Directory.Exists(sz_file_path))
            //    Directory.CreateDirectory(sz_file_path);
            string szSavePath = ApplicationSettings.GetParameterValue("PhysicalBasePath") + szFilePath + szFileName;
            string szOpenPath = ApplicationSettings.GetParameterValue("DocumentManagerURL") + szFilePath + szFileName;
            System.IO.File.WriteAllBytes(szSavePath, m.GetBuffer());
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "Done", "window.open('" + szOpenPath + "');", true);
        }
        catch (Exception ex)
        {
            Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            using (Utils utility = new Utils())
            {
                utility.MethodEnd(id, System.Reflection.MethodBase.GetCurrentMethod());
            }
            string str2 = "Error Request=" + id + ".Please share with Technical support.";
            base.Response.Redirect("../Bill_Sys_ErrorPage.aspx?ErrMsg=" + str2);
        }
        finally
        {
        }


        //Method End
        using (Utils utility = new Utils())
        {
            utility.MethodEnd(id, System.Reflection.MethodBase.GetCurrentMethod());
        }
    }
Ejemplo n.º 24
0
        public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document)
        {
            float     cellHeight = document.TopMargin;
            BaseColor grey       = new BaseColor(128, 128, 128);
            Font      font       = FontFactory.GetFont("Arial", 9, Font.NORMAL, grey);
            Rectangle page       = document.PageSize;

            //tbl footer
            PdfPTable footerTbl = new PdfPTable(1);
            PdfPTable headTbl   = new PdfPTable(2);

            headTbl.HorizontalAlignment = Element.ALIGN_LEFT;
            headTbl.SpacingBefore       = 100f;
            headTbl.TotalWidth          = page.Width - document.LeftMargin - document.RightMargin;
            //headTbl.SetWidths(new float[] { 100, 500 });

            PdfPCell c = new PdfPCell(new Phrase(
                                          "Museo de las Momias de Guanajuato",
                                          new Font(FontFactory.GetFont("Consolas", 14, Font.BOLD))
                                          ));

            c.Colspan             = 2;
            c.Border              = PdfPCell.NO_BORDER;
            c.HorizontalAlignment = Element.ALIGN_CENTER;
            c.VerticalAlignment   = Element.ALIGN_MIDDLE;
            headTbl.AddCell(c);

            c = new PdfPCell(new Phrase(
                                 "Reporte de " + Movimiento,
                                 new Font(FontFactory.GetFont("Consolas", 12, Font.BOLD))
                                 ));
            c.Border = PdfPCell.NO_BORDER;
            c.HorizontalAlignment = Element.ALIGN_LEFT;
            c.VerticalAlignment   = Element.ALIGN_MIDDLE;
            headTbl.AddCell(c);

            c = new PdfPCell(new Phrase(
                                 DateTime.Today.ToString("dd-MMM-yyyy"),
                                 new Font(FontFactory.GetFont("Arial", 11, Font.NORMAL))
                                 ));
            c.Border = PdfPCell.NO_BORDER;
            c.HorizontalAlignment = Element.ALIGN_RIGHT;
            c.VerticalAlignment   = Element.ALIGN_MIDDLE;
            headTbl.AddCell(c);

            headTbl.WriteSelectedRows(
                0, -1,               // first/last row; -1 flags all write all rows
                document.LeftMargin, // left offset
                // ** bottom** yPos of the table
                page.Height,         // - cellHeight + headTbl.TotalHeight,
                writer.DirectContent
                );

            footerTbl.TotalWidth = document.PageSize.Width;

            //page number
            Chunk    myFooter = new Chunk("Página " + (document.PageNumber), FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 8, grey));
            PdfPCell footer   = new PdfPCell(new Phrase(myFooter));

            //footer.BackgroundColor = BaseColor.GRAY;
            footer.Border = Rectangle.NO_BORDER;
            footer.HorizontalAlignment = Element.ALIGN_RIGHT;
            footerTbl.AddCell(footer);

            //this is for the position of the footer ... im my case is "+80"
            footerTbl.WriteSelectedRows(0, -1, -10, (document.BottomMargin), writer.DirectContent);
        }
Ejemplo n.º 25
0
        public void Run(Stream stream, CMSDataContext db, IEnumerable <ContributorInfo> q, StatementSpecification cs, int set = 0)
        {
            pageEvents.set      = set;
            pageEvents.PeopleId = 0;
            IEnumerable <ContributorInfo> contributors = q;
            var toDate = ToDate.Date.AddHours(24).AddSeconds(-1);

            PdfContentByte dc;
            var            font     = FontFactory.GetFont(FontFactory.HELVETICA, 11);
            var            boldfont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 11);

            var doc = new Document(PageSize.LETTER);

            doc.SetMargins(36f, 30f, 24f, 36f);
            var w = PdfWriter.GetInstance(doc, stream);

            w.PageEvent = pageEvents;
            doc.Open();
            dc = w.DirectContent;

            var prevfid       = 0;
            var runningtotals = db.ContributionsRuns.OrderByDescending(mm => mm.Id).First();

            runningtotals.Processed = 0;
            db.SubmitChanges();
            var count = 0;

            foreach (var ci in contributors)
            {
                if (set > 0 && pageEvents.FamilySet[ci.PeopleId] != set)
                {
                    continue;
                }

                var contributions = APIContribution.Contributions(db, ci, FromDate, toDate, cs.Funds).ToList();
                var pledges       = APIContribution.Pledges(db, ci, toDate, cs.Funds).ToList();
                var giftsinkind   = APIContribution.GiftsInKind(db, ci, FromDate, toDate, cs.Funds).ToList();
                var nontaxitems   = db.Setting("DisplayNonTaxOnStatement", "false").ToBool()
                    ? APIContribution.NonTaxItems(db, ci, FromDate, toDate, cs.Funds).ToList()
                    : new List <NonTaxContribution>();

                if ((contributions.Count + pledges.Count + giftsinkind.Count + nontaxitems.Count) == 0)
                {
                    runningtotals.Processed += 1;
                    runningtotals.CurrSet    = set;
                    db.SubmitChanges();
                    if (set == 0)
                    {
                        pageEvents.FamilySet[ci.PeopleId] = 0;
                    }
                    continue;
                }

                pageEvents.NextPeopleId = ci.PeopleId;
                doc.NewPage();
                if (prevfid != ci.FamilyId)
                {
                    prevfid = ci.FamilyId;
                    pageEvents.EndPageSet();
                    pageEvents.PeopleId = ci.PeopleId;
                }
                if (set == 0)
                {
                    pageEvents.FamilySet[ci.PeopleId] = 0;
                }
                count++;

                var css = @"
<style>
h1 { font-size: 24px; font-weight:normal; margin-bottom:0; }
h2 { font-size: 11px; font-weight:normal; margin-top: 0; }
p { font-size: 11px; }
</style>
";
                //----Church Name

                var t1 = new PdfPTable(1);
                t1.TotalWidth         = 72f * 5f;
                t1.DefaultCell.Border = Rectangle.NO_BORDER;
                string html1 = db.ContentHtml("StatementHeader", Resource1.ContributionStatementHeader);
                string html2 = db.ContentHtml("StatementNotice", Resource1.ContributionStatementNotice);

                var mh = new MyHandler();
                using (var sr = new StringReader(css + html1))
                    XMLWorkerHelper.GetInstance().ParseXHtml(mh, sr);

                var cell = new PdfPCell(t1.DefaultCell);
                foreach (var e in mh.elements)
                {
                    if (e.Chunks.Count > 0)
                    {
                        cell.AddElement(e);
                    }
                }
                //cell.FixedHeight = 72f * 1.25f;
                t1.AddCell(cell);
                t1.AddCell("\n");

                var t1a = new PdfPTable(1);
                t1a.TotalWidth         = 72f * 5f;
                t1a.DefaultCell.Border = Rectangle.NO_BORDER;

                var ae = new PdfPTable(1);
                ae.DefaultCell.Border = Rectangle.NO_BORDER;
                ae.WidthPercentage    = 100;

                var a = new PdfPTable(1);
                a.DefaultCell.Indent = 25f;
                a.DefaultCell.Border = Rectangle.NO_BORDER;
                a.AddCell(new Phrase(ci.Name, font));
                foreach (var line in ci.MailingAddress.SplitLines())
                {
                    a.AddCell(new Phrase(line, font));
                }
                cell = new PdfPCell(a)
                {
                    Border = Rectangle.NO_BORDER
                };
                //cell.FixedHeight = 72f * 1.0625f;
                ae.AddCell(cell);

                cell = new PdfPCell(t1a.DefaultCell);
                cell.AddElement(ae);
                t1a.AddCell(ae);

                //-----Notice

                var t2 = new PdfPTable(1);
                t2.TotalWidth         = 72f * 3f;
                t2.DefaultCell.Border = Rectangle.NO_BORDER;

                var envno = "";
                if (db.Setting("PrintEnvelopeNumberOnStatement"))
                {
                    var ev = Person.GetExtraValue(db, ci.PeopleId, "EnvelopeNumber");
                    var s  = Util.PickFirst(ev.Data, ev.IntValue.ToString(), ev.StrValue);
                    if (s.HasValue())
                    {
                        envno = $" env: {Util.PickFirst(ev.Data, ev.IntValue.ToString(), ev.StrValue)}";
                    }
                }

                t2.AddCell(db.Setting("NoPrintDateOnStatement")
                    ? new Phrase($"\nid:{ci.PeopleId}{envno} {ci.CampusId}", font)
                    : new Phrase($"\nprinted: {DateTime.Now:M/d/yy} id:{ci.PeopleId}{envno} {ci.CampusId}", font));

                t2.AddCell("");
                var mh2 = new MyHandler();
                using (var sr = new StringReader(css + html2))
                    XMLWorkerHelper.GetInstance().ParseXHtml(mh2, sr);
                cell = new PdfPCell(t1.DefaultCell);
                foreach (var e in mh2.elements)
                {
                    if (e.Chunks.Count > 0)
                    {
                        cell.AddElement(e);
                    }
                }
                t2.AddCell(cell);

                // POSITIONING OF ADDRESSES
                //----Header

                var yp = doc.BottomMargin +
                         db.Setting("StatementRetAddrPos", "10.125").ToFloat() * 72f;
                t1.WriteSelectedRows(0, -1,
                                     doc.LeftMargin - 0.1875f * 72f, yp, dc);

                yp = doc.BottomMargin +
                     db.Setting("StatementAddrPos", "8.3375").ToFloat() * 72f;
                t1a.WriteSelectedRows(0, -1, doc.LeftMargin, yp, dc);

                yp = doc.BottomMargin + 10.125f * 72f;
                t2.WriteSelectedRows(0, -1, doc.LeftMargin + 72f * 4.4f, yp, dc);

                //----Contributions

                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph(" ")
                {
                    SpacingBefore = 72f * 2.125f
                });

                doc.Add(new Phrase($"\n  Period: {FromDate:d} - {toDate:d}", boldfont));

                var pos = w.GetVerticalPosition(true);

                var   ct       = new ColumnText(dc);
                float gutter   = 20f;
                float colwidth = (doc.Right - doc.Left - gutter) / 2;

                var t = new PdfPTable(new[] { 10f, 24f, 10f });
                t.WidthPercentage    = 100;
                t.DefaultCell.Border = Rectangle.NO_BORDER;
                t.HeaderRows         = 2;

                cell         = new PdfPCell(t.DefaultCell);
                cell.Colspan = 3;
                cell.Phrase  = new Phrase("Contributions\n", boldfont);
                t.AddCell(cell);

                t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                t.AddCell(new Phrase("Date", boldfont));
                t.AddCell(new Phrase("Description", boldfont));
                cell = new PdfPCell(t.DefaultCell);
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.Phrase = new Phrase("Amount", boldfont);
                t.AddCell(cell);

                t.DefaultCell.Border = Rectangle.NO_BORDER;

                var total = 0m;
                foreach (var c in contributions)
                {
                    t.AddCell(new Phrase(c.ContributionDate.ToString2("d"), font));
                    t.AddCell(new Phrase(c.FundName, font));
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase(c.ContributionAmount.ToString2("N2"), font);
                    t.AddCell(cell);
                    total += (c.ContributionAmount ?? 0);
                }
                t.DefaultCell.Border = Rectangle.TOP_BORDER;
                cell         = new PdfPCell(t.DefaultCell);
                cell.Colspan = 2;
                cell.Phrase  = new Phrase("Total Contributions for period", boldfont);
                t.AddCell(cell);
                cell = new PdfPCell(t.DefaultCell);
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.Phrase = new Phrase(total.ToString("N2"), font);
                t.AddCell(cell);

                ct.AddElement(t);

                //------Pledges

                if (pledges.Count > 0)
                {
                    t = new PdfPTable(new float[] { 16f, 12f, 12f });
                    t.WidthPercentage    = 100;
                    t.DefaultCell.Border = Rectangle.NO_BORDER;
                    t.HeaderRows         = 2;

                    cell         = new PdfPCell(t.DefaultCell);
                    cell.Colspan = 3;
                    cell.Phrase  = new Phrase("\n\nPledges\n", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                    t.AddCell(new Phrase("Fund", boldfont));
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase("Pledge", boldfont);
                    t.AddCell(cell);
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase("Given", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.NO_BORDER;

                    foreach (var c in pledges)
                    {
                        t.AddCell(new Phrase(c.FundName, font));
                        cell = new PdfPCell(t.DefaultCell);
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.Phrase = new Phrase(c.Pledged.ToString2("N2"), font);
                        t.AddCell(cell);
                        cell = new PdfPCell(t.DefaultCell);
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.Phrase = new Phrase(c.Given.ToString2("N2"), font);
                        t.AddCell(cell);
                    }
                    ct.AddElement(t);
                }

                //------Gifts In Kind

                if (giftsinkind.Count > 0)
                {
                    t = new PdfPTable(new float[] { 12f, 18f, 20f });
                    t.WidthPercentage    = 100;
                    t.DefaultCell.Border = Rectangle.NO_BORDER;
                    t.HeaderRows         = 2;

                    cell         = new PdfPCell(t.DefaultCell);
                    cell.Colspan = 3;
                    cell.Phrase  = new Phrase("\n\nGifts in Kind\n", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                    t.AddCell(new Phrase("Date", boldfont));
                    cell        = new PdfPCell(t.DefaultCell);
                    cell.Phrase = new Phrase("Fund", boldfont);
                    t.AddCell(cell);
                    cell        = new PdfPCell(t.DefaultCell);
                    cell.Phrase = new Phrase("Description", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.NO_BORDER;

                    foreach (var c in giftsinkind)
                    {
                        t.AddCell(new Phrase(c.ContributionDate.ToString2("d"), font));
                        cell        = new PdfPCell(t.DefaultCell);
                        cell.Phrase = new Phrase(c.FundName, font);
                        t.AddCell(cell);
                        cell        = new PdfPCell(t.DefaultCell);
                        cell.Phrase = new Phrase(c.Description, font);
                        t.AddCell(cell);
                    }
                    ct.AddElement(t);
                }

                //-----Summary

                t = new PdfPTable(new float[] { 29f, 9f });
                t.WidthPercentage    = 100;
                t.DefaultCell.Border = Rectangle.NO_BORDER;
                t.HeaderRows         = 2;

                cell         = new PdfPCell(t.DefaultCell);
                cell.Colspan = 2;
                cell.Phrase  = new Phrase("\n\nPeriod Summary\n", boldfont);
                t.AddCell(cell);

                t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                t.AddCell(new Phrase("Fund", boldfont));
                cell = new PdfPCell(t.DefaultCell);
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.Phrase = new Phrase("Amount", boldfont);
                t.AddCell(cell);

                t.DefaultCell.Border = Rectangle.NO_BORDER;
                foreach (var c in APIContribution.GiftSummary(db, ci, FromDate, toDate, cs.Funds))
                {
                    t.AddCell(new Phrase(c.FundName, font));
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase(c.Total.ToString2("N2"), font);
                    t.AddCell(cell);
                }
                t.DefaultCell.Border = Rectangle.TOP_BORDER;
                t.AddCell(new Phrase("Total contributions for period", boldfont));
                cell = new PdfPCell(t.DefaultCell);
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.Phrase = new Phrase(total.ToString("N2"), font);
                t.AddCell(cell);
                ct.AddElement(t);

                //------NonTax

                if (nontaxitems.Count > 0)
                {
                    t = new PdfPTable(new float[] { 10f, 24f, 10f });
                    t.WidthPercentage    = 100;
                    t.DefaultCell.Border = Rectangle.NO_BORDER;
                    t.HeaderRows         = 2;

                    cell         = new PdfPCell(t.DefaultCell);
                    cell.Colspan = 3;
                    cell.Phrase  = new Phrase("\n\nNon Tax-Deductible Items\n", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                    t.AddCell(new Phrase("Date", boldfont));
                    t.AddCell(new Phrase("Description", boldfont));
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase("Amount", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.NO_BORDER;

                    var ntotal = 0m;
                    foreach (var c in nontaxitems)
                    {
                        t.AddCell(new Phrase(c.ContributionDate.ToString2("d"), font));
                        t.AddCell(new Phrase(c.FundName, font));
                        cell = new PdfPCell(t.DefaultCell);
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.Phrase = new Phrase(c.ContributionAmount.ToString2("N2"), font);
                        t.AddCell(cell);
                        ntotal += (c.ContributionAmount ?? 0);
                    }
                    t.DefaultCell.Border = Rectangle.TOP_BORDER;
                    cell         = new PdfPCell(t.DefaultCell);
                    cell.Colspan = 2;
                    cell.Phrase  = new Phrase("Total Non Tax-Deductible Items for period", boldfont);
                    t.AddCell(cell);
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase(ntotal.ToString("N2"), font);
                    t.AddCell(cell);

                    ct.AddElement(t);
                }

                var col    = 0;
                var status = 0;
                while (ColumnText.HasMoreText(status))
                {
                    if (col == 0)
                    {
                        ct.SetSimpleColumn(doc.Left, doc.Bottom, doc.Left + colwidth, pos);
                    }
                    else if (col == 1)
                    {
                        ct.SetSimpleColumn(doc.Right - colwidth, doc.Bottom, doc.Right, pos);
                    }
                    status = ct.Go();
                    ++col;
                    if (col > 1)
                    {
                        col = 0;
                        pos = doc.Top;
                        doc.NewPage();
                    }
                }

                runningtotals.Processed += 1;
                runningtotals.CurrSet    = set;
                db.SubmitChanges();
            }

            if (count == 0)
            {
                doc.NewPage();
                doc.Add(new Paragraph("no data"));
                var a = new Anchor("see this help document docs.touchpointsoftware.com/Finance/ContributionStatements.html")
                {
                    Reference = "http://docs.touchpointsoftware.com/Finance/ContributionStatements.html#troubleshooting"
                };
                doc.Add(a);
            }
            doc.Close();

            if (set == LastSet())
            {
                runningtotals.Completed = DateTime.Now;
            }
            db.SubmitChanges();
        }
Ejemplo n.º 26
0
        public static void CreatePDF(DataTable dataTable, string destinationPath, int value)
        {
            if (!Directory.Exists(destinationPath))
            {
                Directory.CreateDirectory(destinationPath);
            }

            try
            {
                string path = destinationPath + $"\\{value}_test.pdf";

                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                #region -- ************* --

                Document document = new Document(PageSize.A4, 10, 10, 42, 35);
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    string _imagePath = "https://ftp.mediaperf.com/img/logo.gif";

                    _imagePath = @"C:\Users\Sweet Family\Desktop\logo.jpg";

                    PdfWriter.GetInstance(document, fileStream);
                    document.Open();

                    #region --  --
                    document.AddAuthor("Micke Blomquist");
                    document.AddCreator("Sample application using iTextSharp");
                    document.AddKeywords("PDF tutorial education");
                    document.AddSubject("Document subject - Describing the steps creating a PDF document");
                    document.AddTitle("The document title - PDF creation using iTextSharp");
                    #endregion

                    //Document _document = new Document();
                    using (Document _document = new Document(PageSize.LETTER, 26, 16, 25, 10))
                    {
                        PdfWriter pdfWriter = PdfWriter.GetInstance(_document, fileStream);
                        _document.Open();

                        // -- Set the left header --
                        OnBeginPage(pdfWriter, _document);

                        // -- Set the rigth header --
                        OnRigthBeginPage(pdfWriter, _document);

                        ////InitalisePDFHelper(dataTable);
                        //SetImageLogo();

                        PdfPTable table = new PdfPTable(dataTable.Columns.Count)
                        {
                            WidthPercentage = 100
                        };

                        #region -- Set Logo --
                        Image imagePath = Image.GetInstance(_imagePath);
                        imagePath.ScalePercent(45f);
                        //imagePath.ScaleToFit(100f, 200f);
                        //imagePath.SetAbsolutePosition(250, 300);
                        _document.Add(imagePath);
                        #endregion

                        #region -- Set the left title --
                        var Title = new Paragraph("Relevé de redévences",
                                                  new Font(Font.FontFamily.TIMES_ROMAN,
                                                           18, Font.NORMAL,
                                                           BaseColor.BLACK)
                                                  );
                        Title.Alignment = Element.ALIGN_RIGHT;
                        _document.Add(Title);
                        #endregion

                        //_document.Add(new Paragraph("\n\n\r"));

                        Chunk verticalPositionMark = new Chunk(new VerticalPositionMark());

                        BaseFont baseFont = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, false);

                        #region ---  ---

                        // -----------------------------

                        // -------------------------------------------

                        _document.Add(new Paragraph("\n\r"));
                        _document.Add(new Paragraph("\n\r"));

                        #region -- Set first ligne --
                        Font     font     = new Font(baseFont, 11, Font.BOLD, BaseColor.BLACK);
                        PdfPCell pdfPCell = new PdfPCell(new Phrase("N° RdR      $NoRdR", font))
                        {
                            VerticalAlignment   = Element.ALIGN_MIDDLE,
                            HorizontalAlignment = Element.ALIGN_CENTER,
                            BorderWidth         = 1
                        };

                        PdfPTable      table0 = new PdfPTable(2);
                        PdfContentByte cb     = pdfWriter.DirectContent;
                        table0            = new PdfPTable(1);
                        table0.TotalWidth = 160;
                        table0.AddCell(pdfPCell);
                        table0.WriteSelectedRows(0, -1, 35, 650, cb);

                        pdfPCell = new PdfPCell(new Phrase("Date       $Date", font))
                        {
                            VerticalAlignment   = Element.ALIGN_MIDDLE,
                            HorizontalAlignment = Element.ALIGN_CENTER,
                            BorderWidth         = 1
                        };

                        PdfPTable table10 = new PdfPTable(2);
                        table10            = new PdfPTable(1);
                        table10.TotalWidth = 160;
                        table10.AddCell(pdfPCell);
                        table10.WriteSelectedRows(0, -1, 220, 650, cb);

                        pdfPCell = new PdfPCell(new Phrase("Destinataire", font))
                        {
                            VerticalAlignment   = Element.ALIGN_MIDDLE,
                            HorizontalAlignment = Element.ALIGN_CENTER,
                            BorderWidth         = 1
                        };

                        PdfPTable table30 = new PdfPTable(2);
                        table30 = new PdfPTable(1);
                        table30.HorizontalAlignment = Element.ALIGN_CENTER;
                        table30.TotalWidth          = 190;
                        //table30. = 65;
                        table10.AddCell(pdfPCell);
                        var p = new Paragraph
                        {
                            new Phrase("Destinataire", new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.NORMAL, BaseColor.BLACK)),
                            "$Destinataire \n\n",
                            "$Prestataire \n\n",
                            "$Adresse$Prestataire \n\n\n"
                        };
                        pdfPCell.Border = 2;
                        table30.AddCell(p);
                        table30.WriteSelectedRows(0, -1, 400, 650, cb);

                        #endregion

                        _document.Add(new Paragraph("\n\r"));
                        // ----------------------------------------------

                        //var image = Image.GetInstance(_imagePath);
                        //var paragraph = new Paragraph();
                        //paragraph.Add(new Chunk(image, 0, 0));
                        //var tables = new PdfPTable(1);
                        //var cell = new PdfPCell { PaddingLeft = 5, PaddingTop = 5, PaddingBottom = 5, PaddingRight = 5 };
                        //cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        //cell.AddElement(paragraph);
                        //tables.AddCell(cell);

                        //_document.Add(new Paragraph("\n\r"));
                        //_document.Add(tables);

                        #endregion

                        #region --- Set images side by side !!!!!!!!! ---
                        //PdfPTable resimtable = new PdfPTable(2); // two colmns create tabble
                        //resimtable.WidthPercentage = 100f;//table %100 width
                        //Image imgsag = Image.GetInstance(_imagePath);
                        //resimtable.AddCell(imgsag);//Table One colmns added first image
                        //imgsag.ScalePercent(60f);

                        //Image imgsol = Image.GetInstance(_imagePath);
                        //imgsol.ScalePercent(60f);
                        //resimtable.AddCell(imgsag);//Table One colmns added first image
                        //resimtable.AddCell(imgsol);//Table two colmns added second image
                        //_document.Add(resimtable);
                        #endregion

                        #region -- Set Text Side by side --

                        //var docTitle = new Paragraph();
                        //var titleFont = FontFactory.GetFont(FontFactory.TIMES_BOLD, 10f, BaseColor.BLACK);
                        //docTitle.Font = titleFont;

                        //docTitle.Add("Simulation n° : " + 013235 + "\n");
                        //docTitle.Add(new Chunk("TS : " + "AZ5462132032003." + "\n", titleFont));
                        //docTitle.Add(new Chunk("Société : " + "CUST NAME" + "\n", titleFont));
                        //docTitle.Add(new Chunk("Date de simulation :  " + DateTime.Now.ToString() + "\n", titleFont));
                        //docTitle.Add(new Chunk("Montant total dû : " + 5265.20 + " €\n\n", titleFont));
                        ////docTitle.Font.Size = 6f;

                        //// -- Set Interline --
                        ////docTitle.SetLeading(1.8f, 1.2f);
                        //_document.Add(docTitle);

                        // -- Ajout de saut ligne --
                        _document.Add(new Paragraph("\n\n"));

                        //Chunk verticalPositionMark = new Chunk(new VerticalPositionMark());
                        Paragraph footerParagraph = new Paragraph("Text to the left");
                        var       titleFont       = FontFactory.GetFont(FontFactory.TIMES_BOLD, 10f, BaseColor.BLACK);
                        footerParagraph.Font = titleFont;
                        footerParagraph.Add(new Chunk(verticalPositionMark));
                        footerParagraph.Add("Suppose that some day, somebody asks you");

                        _document.Add(footerParagraph);

                        //// -- Set Interligne --
                        //footerParagraph.SetLeading(2.8f, 1.2f);
                        #endregion

                        _document.Add(new Paragraph("\n\r"));
                        VerticalPositionMark seperator = new LineSeparator();
                        seperator.Offset = -6f;

                        // -- Ajout de saut ligne --
                        _document.Add(new Paragraph("\n"));

                        #region --  Fill PDF DataGrid  --
                        ////Set columns names in the pdf file
                        for (int k = 0; k < dataTable.Columns.Count; k++)
                        {
                            PdfPCell pdfColumnCell = new PdfPCell(new Phrase(dataTable.Columns[k].ColumnName));

                            pdfColumnCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            pdfColumnCell.VerticalAlignment   = PdfPCell.ALIGN_CENTER;
                            pdfColumnCell.BackgroundColor     = new BaseColor(51, 102, 102);

                            table.AddCell(pdfColumnCell);
                        }

                        ////Add values of DataTable in pdf file
                        for (int i = 0; i < dataTable.Rows.Count; i++)
                        {
                            for (int j = 0; j < dataTable.Columns.Count; j++)
                            {
                                PdfPCell pdfColumnCell = new PdfPCell(new Phrase(dataTable.Rows[i][j].ToString()));

                                //Align the pdfColumnCell in the center
                                pdfColumnCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                                pdfColumnCell.VerticalAlignment   = PdfPCell.ALIGN_CENTER;

                                table.AddCell(pdfColumnCell);
                            }
                        }
                        #endregion

                        // -- Ajout de saut ligne --
                        _document.Add(new Paragraph("\n"));

                        System.Drawing.Font fonts = new System.Drawing.Font("Courier", 16);


                        //// -- Set Interligne --
                        //table.SetLeading(9.8f, 1.2f);

                        table.GetFooter();

                        //PdfPCell cell = new PdfPCell(new Phrase("Liste des machines déclarées par le client", new Font(Font.NORMAL, 9f, Font.NORMAL, BaseColor.WHITE)));
                        //cell.BackgroundColor = new BaseColor(223, 0, 27);    // -- RGB couleur --
                        //table.AddCell(cell);

                        var docFooter  = new Paragraph();
                        var footerFont = FontFactory.GetFont(FontFactory.TIMES_BOLD, 10f, BaseColor.BLACK);
                        //docFooter.Font = titleFont;

                        //////// -- A supprimer -- **************************
                        //docFooter.Add("Simulation n° : \n");
                        //docFooter.Add(new Chunk("Montant total dû : "));
                        //docFooter.Alignment = Element.ALIGN_RIGHT;
                        //_document.Add(docFooter);

                        OnEndPage(pdfWriter, _document);

                        _document.Add(table);
                        _document.Close();
                        pdfWriter.Close();
                        fileStream.Close();

                        #region Display PDF
                        //Process.Start(path);
                        #endregion
                    }
                }
                #endregion
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                throw;
            }
        }
Ejemplo n.º 27
0
        private void btn_cutlist_Click(object sender, EventArgs e)
        {
            //   List<string> selectedFiles = new List<string>();
            string FileNameCL = fileName.fileName.selectedFile;

            string[] lines   = File.ReadAllLines(FileNameCL).ToArray();
            int      count   = lines.Length;
            int      counter = 0;

            for (int x = 0; x < count; x++) // x lines in file
            {
                counter++;
                if (counter == 3)
                {
                    lbl_customer.Text = lines[3];
                }
                if (counter == 4)
                {
                    lbl_details.Text = lines[4];
                }
                if (counter == 5)
                {
                    lbl_1Item.Text = lines[5];
                }
                if (counter == 6)
                {
                    lbl_itemDetails.Text = lines[6];
                }
                if (counter == 7)
                {
                    lbl_task.Text = lines[7];
                }

                string[] Items = File.ReadAllLines(FileNameCL).Reverse().ToArray();
                if (Items[x].Contains("***") && !string.IsNullOrEmpty(Items[x]))
                {
                    var nextItemIdex = x;
                    if (nextItemIdex > 0)
                    {
                        lbl_2Item.Text        = Items[nextItemIdex - 1];
                        lbl_2itemDetails.Text = Items[nextItemIdex - 2];
                        lbl_2task.Text        = Items[nextItemIdex - 3];
                    }
                }
                if (lbl_2Item.Text == "lbl_2Item")
                {
                    lbl_2Item.Text        = "";
                    lbl_2itemDetails.Text = "";
                    lbl_2task.Text        = "";
                }
            }
            string FileNameCL1 = fileName.fileName.selectedFile;

            string[] linesi = File.ReadAllLines(FileNameCL1).ToArray();
            int      counti = lines.Length;

            for (int i = 0; i < counti; i++) // x lines in file
            {
                while (!linesi[i].Contains("___") && !linesi[i].Contains("CUTTING") && linesi[i] != " " && linesi[i] != lbl_2Item.Text && linesi[i] != lbl_2itemDetails.Text && linesi[i] != lbl_2task.Text &&
                       linesi[i] != lbl_customer.Text && linesi[i] != lbl_details.Text && linesi[i] != lbl_1Item.Text && linesi[i] != lbl_itemDetails.Text && linesi[i] != lbl_task.Text)
                {
                    linesi[i].TrimStart(' ');
                    string[] numbers = Regex.Split(linesi[i], @"\D+");
                    string   text    = Regex.Replace(linesi[i], @"^\d+", "");
                    textBox1.AppendText(text);
                    textBox1.AppendText(Environment.NewLine);
                    textBox1.Text.Trim(' ');
                    i++;
                    //if (linesi[i] ==)
                    //{
                    //    textBox2.AppendText(text);
                    //    textBox2.AppendText(Environment.NewLine);
                    //    textBox2.Text.Trim(' ');
                    //    i++;
                    //}
                }
            }
            using (MemoryStream myMemoryStream = new MemoryStream())
            {
                iTextSharp.text.Font fdefault = FontFactory.GetFont("HELVETICA", 8, BaseColor.BLACK);
                iTextSharp.text.Font fdetails = FontFactory.GetFont("HELVETICA", 9, BaseColor.BLACK);
                iTextSharp.text.Font fBold    = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10);
                ////////////////////////////////////////////////////////////////////////////////////////////////////////
                Document  myDocument  = new Document();
                PdfWriter myPDFWriter = PdfWriter.GetInstance(myDocument, myMemoryStream);
                myDocument.Open();
                PdfPTable table = new PdfPTable(2);
                ///////////////////////////////////////////////////////////////////////////////////////////////////////
                Paragraph para1stItem      = new Paragraph(lbl_customer.Text + "\n" + lbl_details.Text + "\n" + lbl_1Item.Text + "\n" + lbl_itemDetails.Text + "\n" + lbl_task.Text + "\n", fBold);
                Paragraph para2ndItem      = new Paragraph("\n" + lbl_2Item.Text + "\n" + lbl_2itemDetails.Text + "\n" + lbl_2task.Text + "\n", fBold);
                Paragraph paraQuote        = new Paragraph("\n" + textBox1.Text, fdefault);
                Paragraph para2Quote       = new Paragraph("\n" + textBox2.Text, fdefault);
                Paragraph paraOtherDetails = new Paragraph("\n" + "Other Details:" + "____________________________________________________________________________"
                                                           + "\n" + "                        " + "____________________________________________________________________________"
                                                           + "\n" + "                        " + "____________________________________________________________________________"
                                                           , fBold);
                Paragraph paraCompletedBy = new Paragraph("\n" + "Completed By:" + "____________________________________________________________________________"
                                                          + "\n" + "                         " + "____________________________________________________________________________"
                                                          + "\n" + "                         " + "____________________________________________________________________________"
                                                          , fBold);
                PdfPTable tableFP = new PdfPTable(1);
                tableFP.TotalWidth         = 500f;
                tableFP.DefaultCell.Border = 0;
                //  tableFP.DefaultCell.SetLeading(3, 1);
                tableFP.AddCell(paraOtherDetails);
                tableFP.AddCell(paraCompletedBy);
                tableFP.WriteSelectedRows(0, -1, 0, 120, myPDFWriter.DirectContent);
                ////////////////////////////////////////////////////////////////////////////////////////////////////////
                var image     = iTextSharp.text.Image.GetInstance("I:/Connor/Images/Rogers Fencing Supplies Logo.jpg");
                var imageCell = new PdfPCell(image);
                image.ScaleToFit(300f, 300f);
                image.SetAbsolutePosition(60, 700);
                PdfPCell imageHeader = new PdfPCell(image);
                imageHeader.Colspan             = 2;
                imageHeader.HorizontalAlignment = 1;
                imageHeader.Border       = 0;
                table.DefaultCell.Border = 0;
                table.AddCell(imageHeader);
                ///////////////////////////////////////////////////////////////////////////////////////////////////////
                myDocument.Add(table);
                myDocument.Add(para1stItem);
                myDocument.Add(paraQuote);
                myDocument.Add(para2ndItem);
                myDocument.Add(para2Quote);
                myDocument.Close();
                ////////////////////////////////////////////////////////////////////////////////////////////////////////
                byte[]   content    = myMemoryStream.ToArray();
                DateTime date       = DateTime.Parse(System.DateTime.Now.ToString());
                string   dateForPDF = date.ToString("HHmmss");
                using (FileStream fs = File.Create("I:/Connor/Cutlist/" + dateForPDF + lbl_listBox.Text + ".pdf"))
                {
                    fs.Write(content, 0, (int)content.Length);
                    DialogResult saved = MessageBox.Show("Saved on Inova Server,Connor Folder", "File Saved", MessageBoxButtons.OK);
                }
                this.Controls.Clear();
                this.InitializeComponent();
                Cutlist_Load(sender, e);
            }
        }
Ejemplo n.º 28
0
        private void LayoutCompleted(object sender, PdfLayout.LayoutEventArgs e)
        {
            var pdfLayout = sender as PdfLayout;
            var layout    = this.layoutInstances
                            .Where(x => x.Key.Equals(pdfLayout))
                            .Single();

            Exception toThrow = null;

            lock (layout.Value)
            {
                try
                {
                    var numeroMaxOpzioni = e.MessagesWithOptions
                                           .Max(x => x.Options.Length);

                    //PdfPTable tabella = new PdfPTable(new[] { e.MaxMessageLength, e.MaxOptionLength }), tabellaOpzione;
                    //PdfPTable tabella = new PdfPTable(new[] { 20.0f, 80.0f }), tabellaOpzione;
                    PdfPTable tabella = new PdfPTable(2), tabellaOpzione;
                    tabella.WidthPercentage = 100.0f;

                    PdfPCell cellaMessaggio, cellaOpzione;
                    int      optCount;

                    foreach (var elemento in e.MessagesWithOptions)
                    {
                        cellaMessaggio = this.createCellTemplate(elemento.Message);
                        tabellaOpzione = new PdfPTable(numeroMaxOpzioni);
                        tabellaOpzione.WidthPercentage = 100.0f;

                        optCount = 0;

                        foreach (var opzione in elemento.Options)
                        {
                            cellaOpzione = this.createCellTemplate(opzione, true, elemento.SelectedValue, elemento.Options.Length < 2 && elemento.SelectedValue != null);
                            tabellaOpzione.AddCell(cellaOpzione);
                            optCount++;
                        }

                        for (; optCount < numeroMaxOpzioni; optCount++)
                        {
                            cellaOpzione        = new PdfPCell(new Phrase());
                            cellaOpzione.Border = Rectangle.NO_BORDER;
                            tabellaOpzione.AddCell(cellaOpzione);
                        }

                        tabella.AddCell(cellaMessaggio);
                        tabella.AddCell(new PdfPCell(tabellaOpzione, this.CellStyle));
                    }
                    //Calcola le dimensioni effettive della form.
                    var w1 = 0.0f;
                    var w2 = 0.0f;

                    #region AMPIEZZA

                    var totWidth = e.MaxMessageLength + optCfg.Spacing.Value;
                    totWidth += (e.MaxOptionLength + optCfg.Width.Value + optCfg.Spacing.Value) * numeroMaxOpzioni + optCfg.Spacing.Value;
                    //Controlla se l'ampiezza minima è impostata o se l'ampiezza viene calcolata automaticamente.
                    if (msgConfig.Width.HasValue && totWidth < msgConfig.Width.Value) //Tiene conto dell'ampiezza minima solo se
                    {
                        //CASO 1: casella singola senza opzioni.
                        if (e.MessagesWithOptions.All(x => x.Options == null || x.Options.Length < 2 || x.Options.All(o => (o ?? string.Empty).Trim().Length < 1)))
                        {
                            w1 = msgConfig.Width.Value - optCfg.Width.Value - optCfg.Spacing.Value;
                            w2 = optCfg.Width.Value + optCfg.Spacing.Value;
                        }
                        else //CASO 2: una o più caselle con o senza opzioni.
                        {
                            w2 = (e.MaxOptionLength + optCfg.Width.Value + optCfg.Spacing.Value) * numeroMaxOpzioni + optCfg.Spacing.Value;
                            w1 = Math.Abs(msgConfig.Width.Value - w2);
                        }
                    }
                    else //Ampiezza calcolata automaticamente in funzione delle dimensioni massime delle celle.
                    {
                        w1 = e.MaxMessageLength + optCfg.Spacing.Value;
                        w2 = (e.MaxOptionLength + optCfg.Width.Value + optCfg.Spacing.Value) * numeroMaxOpzioni + optCfg.Spacing.Value;
                    }

                    //Imposta l'ampiezza definitiva.
                    tabella.SetTotalWidth(new[] { w1, w2 });

                    #endregion
                    #region LARGHEZZA

                    var larghezzaTotale = tabella.CalculateHeights();

                    if (msgConfig.Height.HasValue && tabella.Rows.Count > 0 && larghezzaTotale < msgConfig.Height.Value)
                    {
                        //Aggiunge una riga vuota (due celle alte N).
                        var differenza = msgConfig.Height.Value - larghezzaTotale;
                        var cellaVuota = this.CellStyle;
                        //cellaVuota.MinimumHeight = differenza;
                        cellaVuota.FixedHeight = differenza;
                        tabella.AddCell(cellaVuota);
                        tabella.AddCell(cellaVuota);
                    }

                    #endregion

                    //Disegna i bordi...
                    tabella = this.drawTableBorders(ref tabella);
                    //...e scrive la tabella nel documento.
                    tabella.WriteSelectedRows(0, tabella.Rows.Count, msgConfig.X.Value, msgConfig.Y.Value, this.canvas);
                }
                catch (Exception ex)
                {
                    toThrow = ex;
                }
            }

            if (toThrow != null)
            {
                throw toThrow;
            }
        }
Ejemplo n.º 29
0
        public void Run(Stream stream, CMSDataContext Db, IEnumerable <ContributorInfo> q, int set = 0)
        {
            pageEvents.set = set;
            var contributors = q;

            PdfContentByte dc;
            var            font     = FontFactory.GetFont(FontFactory.HELVETICA, 11);
            var            boldfont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 11);

            var doc = new Document(PageSize.LETTER);

            doc.SetMargins(36f, 30f, 24f, 36f);
            var w = PdfWriter.GetInstance(doc, stream);

            w.PageEvent = pageEvents;
            doc.Open();
            dc = w.DirectContent;

            var prevfid       = 0;
            var runningtotals = Db.ContributionsRuns.OrderByDescending(mm => mm.Id).FirstOrDefault();

            runningtotals.Processed = 0;
            Db.SubmitChanges();
            var count = 0;

            foreach (var ci in contributors)
            {
                if (set > 0 && pageEvents.FamilySet[ci.PeopleId] != set)
                {
                    continue;
                }

                var contributions = APIContribution.contributions(Db, ci, FromDate, ToDate).ToList();
                var pledges       = APIContribution.pledges(Db, ci, ToDate).ToList();
                var giftsinkind   = APIContribution.GiftsInKind(Db, ci, FromDate, ToDate).ToList();
                var nontaxitems   = Db.Setting("DisplayNonTaxOnStatement", "false").ToBool()
                    ? APIContribution.NonTaxItems(Db, ci, FromDate, ToDate).ToList()
                    : new List <ContributionInfo>();

                if ((contributions.Count + pledges.Count + giftsinkind.Count + nontaxitems.Count) == 0)
                {
                    runningtotals.Processed += 1;
                    runningtotals.CurrSet    = set;
                    Db.SubmitChanges();
                    if (set == 0)
                    {
                        pageEvents.FamilySet[ci.PeopleId] = 0;
                    }
                    continue;
                }

                doc.NewPage();
                if (prevfid != ci.FamilyId)
                {
                    prevfid = ci.FamilyId;
                    pageEvents.EndPageSet();
                }
                if (set == 0)
                {
                    pageEvents.FamilySet[ci.PeopleId] = 0;
                }
                count++;

                var css = @"
<style>
h1 { font-size: 24px; font-weight:normal; margin-bottom:0; }
h2 { font-size: 11px; font-weight:normal; margin-top: 0; }
p { font-size: 11px; }
</style>
";
                //----Church Name

                var t1 = new PdfPTable(1);
                t1.TotalWidth         = 72f * 5f;
                t1.DefaultCell.Border = Rectangle.NO_BORDER;
                var html1 = Db.ContentHtml("StatementHeader", Resource1.ContributionStatementHeader);
                var html2 = Db.ContentHtml("StatementNotice", Resource1.ContributionStatementNotice);

                var mh = new MyHandler();
                using (var sr = new StringReader(css + html1))
                    XMLWorkerHelper.GetInstance().ParseXHtml(mh, sr);

                var cell = new PdfPCell(t1.DefaultCell);
                foreach (var e in mh.elements)
                {
                    if (e.Chunks.Count > 0)
                    {
                        cell.AddElement(e);
                    }
                }
                //cell.FixedHeight = 72f * 1.25f;
                t1.AddCell(cell);
                t1.AddCell("\n");

                var t1a = new PdfPTable(1);
                t1a.TotalWidth         = 72f * 5f;
                t1a.DefaultCell.Border = Rectangle.NO_BORDER;

                var ae = new PdfPTable(1);
                ae.DefaultCell.Border = Rectangle.NO_BORDER;
                ae.WidthPercentage    = 100;

                var a = new PdfPTable(1);
                a.DefaultCell.Indent = 25f;
                a.DefaultCell.Border = Rectangle.NO_BORDER;
                a.AddCell(new Phrase(ci.Name, font));
                foreach (var line in ci.MailingAddress.SplitLines())
                {
                    a.AddCell(new Phrase(line, font));
                }
                cell = new PdfPCell(a)
                {
                    Border = Rectangle.NO_BORDER
                };
                //cell.FixedHeight = 72f * 1.0625f;
                ae.AddCell(cell);

                cell = new PdfPCell(t1a.DefaultCell);
                cell.AddElement(ae);
                t1a.AddCell(ae);

                //-----Notice

                var t2 = new PdfPTable(1);
                t2.TotalWidth         = 72f * 3f;
                t2.DefaultCell.Border = Rectangle.NO_BORDER;
                t2.AddCell(new Phrase($"\nPrint Date: {DateTime.Now:d}   (id:{ci.PeopleId} {ci.CampusId})", font));
                t2.AddCell("");
                var mh2 = new MyHandler();
                using (var sr = new StringReader(css + html2))
                    XMLWorkerHelper.GetInstance().ParseXHtml(mh2, sr);
                cell = new PdfPCell(t1.DefaultCell);
                foreach (var e in mh2.elements)
                {
                    if (e.Chunks.Count > 0)
                    {
                        cell.AddElement(e);
                    }
                }
                t2.AddCell(cell);

                // POSITIONING OF ADDRESSES
                //----Header

                var yp = doc.BottomMargin +
                         Db.Setting("StatementRetAddrPos", "10.125").ToFloat() * 72f;
                t1.WriteSelectedRows(0, -1,
                                     doc.LeftMargin - 0.1875f * 72f, yp, dc);

                yp = doc.BottomMargin +
                     Db.Setting("StatementAddrPos", "8.3375").ToFloat() * 72f;
                t1a.WriteSelectedRows(0, -1, doc.LeftMargin, yp, dc);

                yp = doc.BottomMargin + 10.125f * 72f;
                t2.WriteSelectedRows(0, -1, doc.LeftMargin + 72f * 4.4f, yp, dc);

                //----Contributions

                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph(" ")
                {
                    SpacingBefore = 72f * 2.125f
                });

                doc.Add(new Phrase($"\n  Period: {FromDate:d} - {ToDate:d}", boldfont));

                var pos = w.GetVerticalPosition(true);

                var ct       = new ColumnText(dc);
                var colwidth = (doc.Right - doc.Left);

                var t = new PdfPTable(new[] { 15f, 25f, 15f, 15f, 30f });
                t.WidthPercentage    = 100;
                t.DefaultCell.Border = Rectangle.NO_BORDER;
                t.HeaderRows         = 2;

                cell         = new PdfPCell(t.DefaultCell);
                cell.Colspan = 5;
                cell.Phrase  = new Phrase("Contributions\n", boldfont);
                t.AddCell(cell);

                t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                t.AddCell(new Phrase("Date", boldfont));
                t.AddCell(new Phrase("Description", boldfont));

                cell = new PdfPCell(t.DefaultCell);
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.Phrase = new Phrase("Amount", boldfont);
                t.AddCell(cell);

                cell = new PdfPCell(t.DefaultCell);
                cell.HorizontalAlignment = Element.ALIGN_CENTER;

                if (ShowCheckNo)
                {
                    cell.Phrase = new Phrase("Check No", boldfont);
                }
                else
                {
                    cell.Phrase = new Phrase("", boldfont);
                }

                t.AddCell(cell);

                if (ShowNotes)
                {
                    t.AddCell(new Phrase("Notes", boldfont));
                }
                else
                {
                    t.AddCell(new Phrase("", boldfont));
                }

                t.DefaultCell.Border = Rectangle.NO_BORDER;

                var total = 0m;
                foreach (var c in contributions)
                {
                    t.AddCell(new Phrase(c.ContributionDate.ToShortDateString(), font));
                    t.AddCell(new Phrase(c.Fund, font));

                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase(c.ContributionAmount.ToString("N2"), font);
                    t.AddCell(cell);

                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;

                    if (ShowCheckNo)
                    {
                        cell.Phrase = new Phrase(c.CheckNo, font);
                    }
                    else
                    {
                        cell.Phrase = new Phrase("", font);
                    }

                    t.AddCell(cell);

                    if (ShowNotes)
                    {
                        t.AddCell(new Phrase(c.Description, font));
                    }
                    else
                    {
                        t.AddCell(new Phrase("", font));
                    }

                    total += (c.ContributionAmount);
                }

                t.DefaultCell.Border = Rectangle.TOP_BORDER;

                cell         = new PdfPCell(t.DefaultCell);
                cell.Colspan = 2;
                cell.Phrase  = new Phrase("Total Contributions for period", boldfont);
                t.AddCell(cell);

                cell = new PdfPCell(t.DefaultCell);
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.Phrase = new Phrase(total.ToString("N2"), font);
                t.AddCell(cell);

                cell         = new PdfPCell(t.DefaultCell);
                cell.Colspan = 2;
                cell.Phrase  = new Phrase("");
                t.AddCell(cell);

                ct.AddElement(t);

                //------Pledges

                if (pledges.Count > 0)
                {
                    t = new PdfPTable(new[] { 25f, 15f, 15f, 15f, 30f });
                    t.WidthPercentage    = 100;
                    t.DefaultCell.Border = Rectangle.NO_BORDER;
                    t.HeaderRows         = 2;

                    cell         = new PdfPCell(t.DefaultCell);
                    cell.Colspan = 5;
                    cell.Phrase  = new Phrase("\n\nPledges\n", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                    t.AddCell(new Phrase("Fund", boldfont));
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase("Pledge", boldfont);
                    t.AddCell(cell);
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase("Given", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.NO_BORDER;
                    t.AddCell(new Phrase("", boldfont));
                    t.AddCell(new Phrase("", boldfont));

                    foreach (var c in pledges)
                    {
                        t.AddCell(new Phrase(c.Fund, font));

                        cell = new PdfPCell(t.DefaultCell);
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.Phrase = new Phrase(c.PledgeAmount.ToString2("N2"), font);
                        t.AddCell(cell);

                        cell = new PdfPCell(t.DefaultCell);
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.Phrase = new Phrase(c.ContributionAmount.ToString2("N2"), font);
                        t.AddCell(cell);

                        t.AddCell(new Phrase("", boldfont));
                        t.AddCell(new Phrase("", boldfont));
                    }
                    ct.AddElement(t);
                }

                //------Gifts In Kind

                if (giftsinkind.Count > 0)
                {
                    t = new PdfPTable(new[] { 15f, 25f, 15f, 15f, 30f });
                    t.WidthPercentage    = 100;
                    t.DefaultCell.Border = Rectangle.NO_BORDER;
                    t.HeaderRows         = 2;

                    // Headers
                    cell         = new PdfPCell(t.DefaultCell);
                    cell.Colspan = 5;
                    cell.Phrase  = new Phrase("\n\nGifts in Kind\n", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                    t.AddCell(new Phrase("Date", boldfont));
                    cell        = new PdfPCell(t.DefaultCell);
                    cell.Phrase = new Phrase("Fund", boldfont);
                    t.AddCell(cell);
                    cell        = new PdfPCell(t.DefaultCell);
                    cell.Phrase = new Phrase("Description", boldfont);
                    t.AddCell(cell);

                    t.AddCell(new Phrase("", boldfont));
                    t.AddCell(new Phrase("", boldfont));

                    t.DefaultCell.Border = Rectangle.NO_BORDER;

                    foreach (var c in giftsinkind)
                    {
                        t.AddCell(new Phrase(c.ContributionDate.ToShortDateString(), font));
                        cell = new PdfPCell(t.DefaultCell);

                        cell.Phrase = new Phrase(c.Fund, font);
                        t.AddCell(cell);

                        cell         = new PdfPCell(t.DefaultCell);
                        cell.Colspan = 3;
                        cell.Phrase  = new Phrase(c.Description, font);
                        t.AddCell(cell);
                    }
                    ct.AddElement(t);
                }

                //-----Summary

                t = new PdfPTable(new[] { 40f, 15f, 45f });
                t.WidthPercentage    = 100;
                t.DefaultCell.Border = Rectangle.NO_BORDER;
                t.HeaderRows         = 2;

                cell         = new PdfPCell(t.DefaultCell);
                cell.Colspan = 3;
                cell.Phrase  = new Phrase("\n\nPeriod Summary\n", boldfont);
                t.AddCell(cell);

                t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                t.AddCell(new Phrase("Fund", boldfont));

                cell = new PdfPCell(t.DefaultCell);
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.Phrase = new Phrase("Amount", boldfont);
                t.AddCell(cell);

                t.DefaultCell.Border = Rectangle.NO_BORDER;
                t.AddCell(new Phrase("", boldfont));

                foreach (var c in APIContribution.quarterlySummary(Db, ci, FromDate, ToDate))
                {
                    t.AddCell(new Phrase(c.Fund, font));

                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase(c.ContributionAmount.ToString("N2"), font);
                    t.AddCell(cell);

                    t.AddCell(new Phrase("", boldfont));
                }

                t.DefaultCell.Border = Rectangle.NO_BORDER;

                cell         = new PdfPCell(t.DefaultCell);
                cell.Border  = Rectangle.TOP_BORDER;
                cell.Colspan = 1;
                cell.Phrase  = new Phrase("Total Contributions for period", boldfont);
                t.AddCell(cell);

                cell        = new PdfPCell(t.DefaultCell);
                cell.Border = Rectangle.TOP_BORDER;
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.Phrase = new Phrase(total.ToString("N2"), font);
                t.AddCell(cell);

                cell        = new PdfPCell(t.DefaultCell);
                cell.Phrase = new Phrase("");
                t.AddCell(cell);

                ct.AddElement(t);

                //------NonTax

                if (nontaxitems.Count > 0)
                {
                    t = new PdfPTable(new[] { 15f, 25f, 15f, 15f, 30f });
                    t.WidthPercentage    = 100;
                    t.DefaultCell.Border = Rectangle.NO_BORDER;
                    t.HeaderRows         = 2;

                    cell         = new PdfPCell(t.DefaultCell);
                    cell.Colspan = 5;
                    cell.Phrase  = new Phrase("\n\nNon Tax-Deductible Items\n", boldfont);
                    t.AddCell(cell);

                    t.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                    t.AddCell(new Phrase("Date", boldfont));
                    t.AddCell(new Phrase("Description", boldfont));
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase("Amount", boldfont);
                    t.AddCell(cell);
                    t.AddCell(new Phrase("", boldfont));
                    t.AddCell(new Phrase("", boldfont));

                    t.DefaultCell.Border = Rectangle.NO_BORDER;

                    var ntotal = 0m;
                    foreach (var c in nontaxitems)
                    {
                        t.AddCell(new Phrase(c.ContributionDate.ToShortDateString(), font));
                        t.AddCell(new Phrase(c.Fund, font));
                        cell = new PdfPCell(t.DefaultCell);
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.Phrase = new Phrase(c.ContributionAmount.ToString("N2"), font);
                        t.AddCell(cell);
                        t.AddCell(new Phrase("", boldfont));
                        if (ShowNotes)
                        {
                            t.AddCell(new Phrase(c.Description, font));
                        }
                        else
                        {
                            t.AddCell(new Phrase("", font));
                        }

                        ntotal += (c.ContributionAmount);
                    }
                    t.DefaultCell.Border = Rectangle.TOP_BORDER;
                    cell         = new PdfPCell(t.DefaultCell);
                    cell.Colspan = 2;
                    cell.Phrase  = new Phrase("Total Non Tax-Deductible Items for period", boldfont);
                    t.AddCell(cell);
                    cell = new PdfPCell(t.DefaultCell);
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.Phrase = new Phrase(ntotal.ToString("N2"), font);
                    t.AddCell(cell);
                    t.AddCell(new Phrase("", boldfont));
                    t.AddCell(new Phrase("", boldfont));


                    ct.AddElement(t);
                }

                var status = 0;
                while (ColumnText.HasMoreText(status))
                {
                    ct.SetSimpleColumn(doc.Left, doc.Bottom, doc.Left + colwidth, pos);

                    status = ct.Go();
                    pos    = doc.Top;
                    doc.NewPage();
                }

                runningtotals.Processed += 1;
                runningtotals.CurrSet    = set;
                Db.SubmitChanges();
            }

            if (count == 0)
            {
                doc.NewPage();
                doc.Add(new Phrase("no data"));
            }
            doc.Close();

            if (set == LastSet())
            {
                runningtotals.Completed = DateTime.Now;
            }
            Db.SubmitChanges();
        }
Ejemplo n.º 30
0
        private void CreateEliminatorias(bool showOnlyPartidaValida, bool fim, PdfWriter writer, string imagePath, IList <Model.Boloes.JogoUsuario> oitavas, IList <Model.Boloes.JogoUsuario> quartas, IList <Model.Boloes.JogoUsuario> semiFinais, IList <Model.Boloes.JogoUsuario> finais)
        {
            float[]   relative = new float[] { 10, 0.5f, 9, 0.5f, 9, 0.5f, 9, 0.5f, 9, 0.5f, 9, 0.5f, 10 };
            PdfPTable table    = new PdfPTable(relative);

            table.DefaultCell.BorderWidth = 0;
            table.DefaultCell.Padding     = 0;



            table.AddCell(CreateOitavasLeft(showOnlyPartidaValida, fim, imagePath, oitavas));
            table.AddCell("");
            table.AddCell(CreateQuartasLeft(showOnlyPartidaValida, fim, imagePath, quartas));
            table.AddCell("");
            table.AddCell(CreateSemiFinaisLeft(showOnlyPartidaValida, fim, imagePath, semiFinais));
            table.AddCell("");
            table.AddCell(CreateFinais(showOnlyPartidaValida, fim, imagePath, finais));
            table.AddCell("");
            table.AddCell(CreateSemiFinaisRight(showOnlyPartidaValida, fim, imagePath, semiFinais));
            table.AddCell("");
            table.AddCell(CreateQuartasRight(showOnlyPartidaValida, fim, imagePath, quartas));
            table.AddCell("");
            table.AddCell(CreateOitavasRight(showOnlyPartidaValida, fim, imagePath, oitavas));

            table.TotalWidth = 580;

            table.WriteSelectedRows(0, -1, 5, 280, writer.DirectContent);


            int oitavasLeft  = 45;
            int oitavasRight = 541;

            PdfContentByte cb = writer.DirectContent;

            cb.MoveTo(oitavasLeft, 247);
            cb.LineTo(oitavasLeft, 223);
            cb.Stroke();

            cb.MoveTo(oitavasLeft, 133);
            cb.LineTo(oitavasLeft, 109);
            cb.Stroke();


            cb.MoveTo(oitavasRight, 247);
            cb.LineTo(oitavasRight, 223);
            cb.Stroke();

            cb.MoveTo(oitavasRight, 133);
            cb.LineTo(oitavasRight, 109);
            cb.Stroke();

            cb.MoveTo(oitavasLeft, 233);
            cb.LineTo(oitavasLeft + 49, 233);
            cb.Stroke();


            cb.MoveTo(oitavasLeft, 121);
            cb.LineTo(oitavasLeft + 49, 121);
            cb.Stroke();


            cb.MoveTo(oitavasRight, 233);
            cb.LineTo(oitavasRight - 45, 233);
            cb.Stroke();


            cb.MoveTo(oitavasRight, 121);
            cb.LineTo(oitavasRight - 45, 121);
            cb.Stroke();


            //   |
            cb.MoveTo(130, 223);
            cb.LineTo(130, 139);
            cb.Stroke();
            //   |
            cb.MoveTo(460, 223);
            cb.LineTo(460, 139);
            cb.Stroke();

            // -
            cb.MoveTo(130, 180);
            cb.LineTo(180 - 4, 180);
            cb.Stroke();
            // -
            cb.MoveTo(460, 180);
            cb.LineTo(410 + 3, 180);
            cb.Stroke();



            cb.MoveTo(280, 211);
            cb.LineTo(280, 180);
            cb.Stroke();



            cb.MoveTo(310, 211);
            cb.LineTo(310, 180);
            cb.Stroke();



            cb.MoveTo(280, 180);
            cb.LineTo(247 + 6, 180);
            cb.Stroke();


            cb.MoveTo(310, 180);
            cb.LineTo(343 - 6, 180);
            cb.Stroke();
        }