Ejemplo n.º 1
0
        public static string getPaymentTermsExplained(string ptstr)
        {
            string              ptexplainrd   = "";
            PTDefinitionDB      ptddb         = new PTDefinitionDB();
            List <ptdefinition> PTDefinitions = ptddb.getPTDefinitions();

            string[] strArry1 = ptstr.Split(new string[] { ";" }, StringSplitOptions.None);
            for (int i = 0; i < strArry1.Length; i++)
            {
                if (strArry1[i].Trim().Length > 0)
                {
                    string[] strArry2 = strArry1[i].Split(new string[] { "-" }, StringSplitOptions.None);
                    foreach (ptdefinition ptd in PTDefinitions)
                    {
                        if (ptd.SequenceNo == Convert.ToInt32(strArry2[0]))
                        {
                            ptexplainrd = ptexplainrd + ptd.ShortDescription + " : " + strArry2[1] + "%";
                            if (Convert.ToInt32(strArry2[2]) != 0)
                            {
                                ptexplainrd = ptexplainrd + " in " + strArry2[2] + " days";
                            }
                            ptexplainrd = ptexplainrd + "\n";
                            break;
                        }
                    }
                }
            }
            return(ptexplainrd);
        }
Ejemplo n.º 2
0
        public void PrintWO(workorderheader woh, List <workorderdetail> WODetail, string totalTaxDetail)
        {
            string HeaderString = "No.: S-" + woh.WONo + Main.delimiter1 + "Date: " + woh.WODate.ToString("dd-MM-yyyy") + Main.delimiter1 +
                                  "Address:\n" + woh.CustomerName + "\n" + woh.POAddress + Main.delimiter1 +
                                  "Payment Terms:\n" + PTDefinitionDB.getPaymentTermString(woh.PaymentTerms) + Main.delimiter1 +
                                  "Target Date:\n" + woh.TargetDate.ToString("dd-MM-yyyy");
            string footer1         = "Amount Chargeable(In Words)\n\n";
            string ColHeader       = "SI No.;Description of Work;Location;Quantity;Rate;Amount";
            string footer2         = "";
            string footer3         = "for CELLCOMM SOLUTION LIMITED;Authorised Signatory";
            string termsAndCond    = getTCString(woh.TermsAndCond);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = WODetail.Count();

            //+ : main.delimeter1
            //; : main.delimiter2

            foreach (workorderdetail wod in WODetail)
            {
                if (n == count)
                {
                    //ColDetailString = ColDetailString + n + "+" + wod.Description + "+" + wod.WorkLocation + "+" + wod.Quantity + "+"
                    //                   + wod.Price + "+" + (wod.Quantity * wod.Price);
                    ColDetailString = ColDetailString + n + Main.delimiter1 + wod.Description + Main.delimiter1 + wod.WorkLocation + Main.delimiter1 + wod.Quantity + Main.delimiter1
                                      + wod.Price + Main.delimiter1 + (wod.Quantity * wod.Price);
                    if (wod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString + ";" +
                        //    "" + "+" +
                        //    wod.TaxCode + "+" +
                        //    "" + "+" +
                        //    "" + "+" +
                        //    "" + "+"  +
                        //    wod.Tax;
                        ColDetailString = ColDetailString + Main.delimiter2 +
                                          "" + Main.delimiter1 +
                                          wod.TaxCode + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          wod.Tax;
                    }
                }
                else
                {
                    //ColDetailString = ColDetailString + n + "+" + wod.Description + "+" + wod.WorkLocation + "+" + wod.Quantity + "+"
                    //                    + wod.Price + "+" + (wod.Quantity * wod.Price) + ";";
                    ColDetailString = ColDetailString + n + Main.delimiter1 + wod.Description + Main.delimiter1 + wod.WorkLocation + Main.delimiter1 + wod.Quantity + Main.delimiter1
                                      + wod.Price + Main.delimiter1 + (wod.Quantity * wod.Price) + Main.delimiter2;
                    if (wod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString +
                        //    "" + "+" +
                        //    wod.TaxCode + "+" +
                        //    "" + "+" +
                        //    "" + "+" +
                        //    "" + "+" +
                        //    wod.Tax + ";";

                        ColDetailString = ColDetailString +
                                          "" + Main.delimiter1 +
                                          wod.TaxCode + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          wod.Tax + Main.delimiter2;
                    }
                }
                totQuant = totQuant + wod.Quantity;
                totAmnt  = totAmnt + (wod.Quantity * wod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = woh.DocumentID + "-" + woh.WONo;
                //sfd.ShowDialog();
                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }

                FileStream fs  = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                //String imageURL = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                //iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                String URL = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;
                //--

                PdfPTable tableMain = new PdfPTable(2);

                tableMain.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableMain.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    string addr = det.companyname + "\n" + det.companyAddress;
                    ourAddr           = new Paragraph(new Phrase(addr, font2));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableMain.AddCell(cellAdd);
                //----
                Paragraph paragraph = new Paragraph(new Phrase("PURCHASE ORDER", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                //PrintPurchaseOrder prog = new PrintPurchaseOrder();
                string[] HeaderStr = HeaderString.Split(Main.delimiter1);

                PdfPTable table = new PdfPTable(2);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 4f, 3f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    cell = new PdfPCell();
                    string[] subHdr = HeaderStr[i].Split(Main.delimiter1);
                    if (i == 2)
                    {
                        cell                     = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Rowspan             = 2;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);
                    }
                    else
                    {
                        table.AddCell(new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1)));
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(6);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 4.5f, 2f, 2f, 2f, 3f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 6;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 3 || j == 4 || j == 5)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 5)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            pcell        = new PdfPCell(new Phrase(str[j], font1));
                            pcell.Border = 0;
                        }
                        //pcell.Border = 0;
                        //if (i == (DetailStr.Length - 1))
                        //{
                        //    pcell.MinimumHeight = 100;
                        //}
                        //else
                        pcell.MinimumHeight       = 10;
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        pcell.BorderWidthLeft     = 0.01f;
                        pcell.BorderWidthRight    = 0.01f;
                        table1.AddCell(pcell);
                    }

                    if (track == 1)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            PdfPCell pcell1;

                            if (j == 5)
                            {
                                pcell1                   = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(dc1 + dc2)), font1));
                                pcell1.Border            = 0;
                                pcell1.BorderWidthBottom = 0.01f;
                            }
                            else
                            {
                                pcell1        = new PdfPCell(new Phrase(""));
                                pcell1.Border = 0;
                            }
                            pcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            pcell1.BorderWidthLeft     = 0.01f;
                            pcell1.BorderWidthRight    = 0.01f;
                            table1.AddCell(pcell1);
                        }
                    }
                }
                double roundedAmt = Math.Round(woh.TotalAmount, 0);
                double diffAmount = roundedAmt - woh.TotalAmount;
                if (diffAmount != 0)
                {
                    table1.AddCell("");
                    table1.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Round off Adj.", font1));
                    cellRound.Colspan             = 3;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(cellRound);
                    table1.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                }
                table1.AddCell("");
                table1.AddCell("");
                PdfPCell cellTotal = new PdfPCell(new Phrase("Total", font1));
                cellTotal.Colspan             = 3;
                cellTotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.AddCell(cellTotal);
                table1.AddCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font1));

                //-----
                string   total  = footer1 + NumberToString.convert(roundedAmt.ToString());
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font3));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                table1.AddCell(fcell1);

                if (woh.SpecialNote.Trim().Length != 0)
                {
                    footer2 = "Note:\n" + woh.SpecialNote.Trim();
                }
                PdfPCell fcell2 = new PdfPCell(new Phrase(footer2, font1));
                fcell2.Colspan             = 4;
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell2.BorderWidthTop      = 0;
                fcell2.BorderWidthRight    = 0;
                table1.AddCell(fcell2);
                string[] ft = footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border  = 0;
                fcell3.Colspan = 2;
                //fcell3.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                //fcell3.BorderWidthTop = 0.5f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);
                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                //--------------------

                double    dd     = 0;
                PdfPTable taxTab = new PdfPTable(3);
                taxTab.WidthPercentage = 100;

                float[] twidth = new float[] { 3f, 3f, 10f };
                taxTab.SetWidths(twidth);
                if (woh.TaxAmount != 0)
                {
                    PdfPCell pcell;
                    pcell = new PdfPCell(new Phrase("Tax Details", font2));
                    taxTab.AddCell(pcell);
                    PdfPCell pcellc = new PdfPCell(new Phrase("Amount(" + woh.CurrencyID + ")", font2));
                    taxTab.AddCell(pcellc);
                    PdfPCell pcelllst = new PdfPCell(new Phrase("", font1));
                    pcelllst.Border = 0;
                    taxTab.AddCell(pcelllst);

                    string[] tax = totalTaxDetail.Split('\n');
                    for (int i = 0; i < tax.Length - 1; i++)
                    {
                        string[] subtax = tax[i].Split('-');
                        PdfPCell pcell1;
                        pcell1 = new PdfPCell(new Phrase(subtax[0], font1));
                        PdfPCell pcell2;
                        pcell2 = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(subtax[1])), font1));
                        PdfPCell pcell3 = new PdfPCell(new Phrase("", font1));
                        pcell3.Border = 0;
                        taxTab.AddCell(pcell1);
                        taxTab.AddCell(pcell2);
                        taxTab.AddCell(pcell3);
                    }
                    taxTab.AddCell(new Phrase("Total Tax Amount", font2));
                    taxTab.AddCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(woh.TaxAmount)), font2));
                    PdfPCell pcellt = new PdfPCell(new Phrase("", font1));
                    pcellt.Border = 0;
                    taxTab.AddCell(pcellt);
                    taxTab.KeepTogether  = true;
                    taxTab.SpacingAfter  = 2f;
                    taxTab.SpacingBefore = 3f;
                }

                //--------------------
                PdfPTable TCTab = new PdfPTable(2);
                if (woh.TermsAndCond.Trim().Length != 0)
                {
                    Chunk TCchunk = new Chunk("Terms And Conditoins:\n", font2);
                    TCchunk.SetUnderline(0.2f, -2f);
                    TCTab = new PdfPTable(2);
                    TCTab.WidthPercentage = 100;
                    PdfPCell TCCell = new PdfPCell();
                    TCCell.Colspan = 2;
                    TCCell.Border  = 0;
                    TCCell.AddElement(TCchunk);
                    TCTab.AddCell(TCCell);
                    try
                    {
                        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                        for (int i = 0; i < ParaTC.Length + 1; i++)
                        {
                            TCCell         = new PdfPCell();
                            TCCell.Colspan = 2;
                            TCCell.Border  = 0;
                            Paragraph header  = new Paragraph();
                            Paragraph details = new Paragraph();
                            details.IndentationLeft  = 12f;
                            details.IndentationRight = 12f;
                            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                            header.Add(new Phrase(paraHeaderStr, font2));
                            details.Add(new Phrase(paraFooterStr, font1));
                            TCCell.AddElement(header);
                            TCCell.AddElement(details);
                            TCTab.AddCell(TCCell);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        TCTab.KeepRowsTogether(0, 3);
                    }
                    catch (Exception ex)
                    {
                    }
                }
                doc.Add(tableMain);
                //doc.Add(img);
                //doc.Add(ourAddr);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);
                if (woh.TaxAmount != 0)
                {
                    doc.Add(taxTab);
                }
                if (woh.TermsAndCond.Length != 0)
                {
                    doc.Add(TCTab);
                }
                doc.Close();
                MessageBox.Show("Saved Sucessfully.");
            }
            catch (Exception ie)
            {
                MessageBox.Show("Failed TO Save");
            }
        }
Ejemplo n.º 3
0
        public void PrintPO(poheader poh, List <podetail> PODetail, string taxStr)
        {
            Dictionary <string, string> companyInfo = getCompanyInformation();
            //string stateDetail =
            customer custDetail = CustomerDB.getCustomerDetailForPO(poh.CustomerID);

            string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
            string   poNoSuffix        = "";
            string   supplAdd          = "";
            string   stype             = "";

            if (poh.DocumentID == "POGENERAL")
            {
                poNoSuffix = "G-"; supplAdd = "Contractor:\n" + custDetail.name + Main.delimiter1 + "\n" + custDetail.BillingAddress + "\n";
                stype      = "Contractor";
            }
            else if (poh.DocumentID == "PURCHASEORDER")
            {
                poNoSuffix = "P-";
                stype      = "Supplier";
            }

            supplAdd = stype + ":\n" + custDetail.name + Main.delimiter1 + "\n" + custDetail.BillingAddress + "\n";
            if (custDetail.StateName.ToString().Length != 0)
            {
                supplAdd = supplAdd + "Sate Name:" + custDetail.StateName;
            }
            if (custDetail.StateCode.ToString().Length != 0)
            {
                supplAdd = supplAdd + "\nState Code:" + custDetail.StateCode;
            }
            if (custDetail.OfficeName.ToString().Length != 0)
            {
                supplAdd = supplAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
            }
            //; : main.delimiter2
            //$ : main.delimiter1
            string InvoiceTo    = "Invoice To: \n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + companyBillingAdd[1] + "\nGST:" + companyInfo["GST"] + "\nCIN:" + companyInfo["CIN"] + "\nPAN:" + companyInfo["PAN"];
            string DespatchTo   = "Dispatch To:\n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + poh.DeliveryAddress + "\nGST:" + companyInfo["GST"];
            string HeaderString = supplAdd +
                                  Main.delimiter2 + "PO No : " + poNoSuffix + poh.PONo + " , Date: " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(poh.PODate)) +
                                  Main.delimiter2 + stype + " Reference : " + poh.ReferenceQuotation.Replace(";", ",\n") +
                                  Main.delimiter2 + "Mode Of Dispatch:" + CatalogueValueDB.getParamValue("TransportationMode", poh.TransportationMode) +
                                  Main.delimiter2 + "Delivery Period : " + poh.DeliveryPeriod + " Days" + Main.delimiter2 +

                                  InvoiceTo +

                                  Main.delimiter2 + "Price basis : " + CatalogueValueDB.getParamValue("PriceBasis", poh.PriceBasis) +
                                  Main.delimiter2 + "Delivery at : " + poh.DeliveryAt +
                                  Main.delimiter2 + "Terms of Payment : " + PTDefinitionDB.getPaymentTermString(poh.PaymentTerms) +
                                  Main.delimiter2 + "Tax : " + CatalogueValueDB.getParamValue("TaxStatus", poh.TaxTerms) + Main.delimiter2 +

                                  DespatchTo +

                                  Main.delimiter2 + "Partial Shipment : " + poh.PartialShipment +
                                  Main.delimiter2 + "Transhipment : " + poh.Transhipment +
                                  Main.delimiter2 + "Packaging Specification : " + poh.PackingSpec +
                                  Main.delimiter2 + poh.SpecialNote;
            string footer1     = "Amount In Words\n\n";
            string ColHeader   = "SI No.;Description of Goods;Quantity;Unit;Unit Rate;Amount;Warranty\nIn Days";
            string footer2     = "This Purchase Order, being computer generated, does not require physical signature.";
            string declaration = "We, Cellcomm Solutions Limited (also referred to as “CSL”), are pleased to place" +
                                 " this Purchase Order (also referred to as 'PO') with the " + stype + " addressed below.In accepting this Purchase Order, the " + stype +
                                 " undertakes to supply the Goods described herein as per the details and instructions shown below" +
                                 " (such details and instructions being the Specific Terms and Conditions agreed between the Parties) " +
                                 "and also subject to the General Terms & Conditions contained herein.";
            string termsAndCond    = getTCString(poh.TermsAndCondition, poh.DocumentID);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = PODetail.Count();

            foreach (podetail pod in PODetail)
            {
                if (n == count)
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + pod.Description + Main.delimiter1 + pod.Quantity + Main.delimiter1
                                      + pod.Unit + Main.delimiter1 + pod.Price + Main.delimiter1 + (pod.Quantity * pod.Price) + Main.delimiter1 + pod.WarrantyDays;
                }
                else
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + pod.Description + Main.delimiter1 + pod.Quantity + Main.delimiter1
                                      + pod.Unit + Main.delimiter1 + pod.Price + Main.delimiter1 + (pod.Quantity * pod.Price) + Main.delimiter1 + pod.WarrantyDays + Main.delimiter2;
                }
                totQuant = totQuant + pod.Quantity;
                totAmnt  = totAmnt + (pod.Quantity * pod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                if (poh.Status == 0 && poh.DocumentStatus < 99)
                {
                    sfd.FileName = poh.DocumentID + "-Temp-" + poh.TemporaryNo;
                }
                else
                {
                    sfd.FileName = poh.DocumentID + "-" + poh.PONo;
                }
                ///sfd.FileName = poh.DocumentID + "-" + poh.PONo;

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();

                Font   font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font   font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                Font   font4 = FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                String URL   = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;


                PdfPTable tableHeader = new PdfPTable(2);

                tableHeader.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableHeader.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    ourAddr.Add(new Chunk(det.companyname + "\n", font2));
                    ourAddr.Add(new Chunk(det.companyAddress.Replace("\r\n", "\n"), font4));
                    StringBuilder sb = new StringBuilder();
                    sb.Append("\nGST : " + companyInfo["GST"] + "\nState Code for GST : " + companyInfo["StateCode"] + "\nCIN : " + companyInfo["CIN"] + "\nPAN : " + companyInfo["PAN"]);
                    ourAddr.Add(new Chunk(sb.ToString(), font4));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                    ourAddr.SetLeading(0.0f, 1.5f);
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableHeader.AddCell(cellAdd);

                PdfPTable tableDocName = new PdfPTable(1);
                tableDocName.WidthPercentage = 100;
                PdfPCell cellHdr = new PdfPCell(new Phrase("PURCHASE ORDER", font2));
                cellHdr.Border = 0;
                cellHdr.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableDocName.AddCell(cellHdr);
                if (poh.CountryID != null && poh.CountryID != "India")
                {
                    PdfPCell cellHdrInr = new PdfPCell(new Phrase("(Import)", font2));
                    cellHdrInr.Border = 0;
                    cellHdrInr.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    tableDocName.AddCell(cellHdrInr);
                }

                Paragraph paragraphOpenCluse = new Paragraph(new Phrase(declaration, font1));
                paragraphOpenCluse.Alignment     = Element.ALIGN_JUSTIFIED;
                paragraphOpenCluse.SpacingBefore = 10;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(Main.delimiter2);

                PdfPTable TableAddress = new PdfPTable(7);

                TableAddress.SpacingBefore   = 20f;
                TableAddress.WidthPercentage = 100;
                float[] HWidths = new float[] { 1f, 8f, 2f, 1.5f, 1.5f, 3f, 1.5f };
                TableAddress.SetWidths(HWidths);
                PdfPCell cell;
                int[]    arr = { 6, 7, 9, 10 };
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0 || i == 5 || i == 10)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter1);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        cell                     = new PdfPCell(phr);
                        cell.Colspan             = 2;
                        cell.Rowspan             = 4;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        TableAddress.AddCell(cell);
                    }
                    else
                    {
                        cell               = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan       = 5;
                        cell.MinimumHeight = wid;
                        TableAddress.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable TableItemDetails = new PdfPTable(7);
                TableItemDetails.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                TableItemDetails.WidthPercentage = 100;
                float[] width = new float[] { 1f, 8f, 2f, 1.5f, 2f, 2.5f, 1.5f };
                TableItemDetails.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    if (i == 4 || i == 5)
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim() + "\n(" + poh.CurrencyID + ")", font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        TableItemDetails.AddCell(hcell);
                    }
                    else
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        TableItemDetails.AddCell(hcell);
                    }
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 7;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                TableItemDetails.AddCell(foot);

                TableItemDetails.HeaderRows = 2;
                TableItemDetails.FooterRows = 1;

                TableItemDetails.SkipFirstHeader = false;
                TableItemDetails.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = TableItemDetails.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;

                        if (j == 2 || j == 4 || j == 5)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 5)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            if (j == 6)
                            {
                                if ((str[j].Trim().Length == 0 || Convert.ToInt32(str[j]) == 0) && (track != 1))
                                {
                                    pcell = new PdfPCell(new Phrase("NA", font1));
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else if (j == 3)
                            {
                                int m = 1;
                                if (Int32.TryParse(str[j], out m) == true)
                                {
                                    if (Convert.ToInt32(str[j]) == 0)
                                    {
                                        pcell = new PdfPCell(new Phrase("", font1));
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(str[j], font1));
                            }

                            pcell.Border = 0;
                        }

                        pcell.MinimumHeight = 10;
                        //pcell.MinimumHeight = 20;
                        if (j == 1)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        pcell.BorderWidthLeft  = 0.01f;
                        pcell.BorderWidthRight = 0.01f;

                        TableItemDetails.AddCell(pcell);
                    }
                }
                double roundedAmt = Math.Round(totAmnt, 0);
                double diffAmount = roundedAmt - totAmnt;

                if (diffAmount != 0)
                {
                    TableItemDetails.AddCell("");
                    TableItemDetails.AddCell("");
                    PdfPCell cellTot = new PdfPCell(new Phrase("", font1));
                    cellTot.Colspan             = 3;
                    cellTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(cellTot);
                    TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", totAmnt), font1));
                    TableItemDetails.AddCell("");

                    TableItemDetails.AddCell("");
                    TableItemDetails.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Rounding off", font1));
                    cellRound.Colspan             = 3;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(cellRound);
                    TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                    TableItemDetails.AddCell("");
                }

                TableItemDetails.AddCell("");
                TableItemDetails.AddCell("");
                PdfPCell cellTotal = new PdfPCell(new Phrase("Total", font1));
                cellTotal.Colspan             = 3;
                cellTotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                TableItemDetails.AddCell(cellTotal);
                TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font1));
                TableItemDetails.AddCell("");

                string   total  = footer1 + NumberToString.convert(roundedAmt.ToString()).Replace("INR", poh.CurrencyID) + "\n\n";
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font1));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthRight    = 0;
                fcell1.BorderWidthTop      = 0;
                TableItemDetails.AddCell(fcell1);

                PdfPCell fcell4 = new PdfPCell(new Phrase("E. & O.E", font1));
                fcell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell4.BorderWidthLeft     = 0;
                fcell4.BorderWidthTop      = 0;
                TableItemDetails.AddCell(fcell4);

                PdfPTable tableSub = new PdfPTable(1);
                tableSub.DefaultCell.Border = 0;
                tableSub.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableSub.AddCell(new Phrase("Subject To Bangalore Jurisdiction", font2));
                PdfPCell celSub = new PdfPCell(tableSub);
                celSub.Border  = 0;
                celSub.Colspan = 7;
                TableItemDetails.AddCell(celSub);

                TableItemDetails.KeepRowsTogether(TableItemDetails.Rows.Count - 6, TableItemDetails.Rows.Count);

                Paragraph footer = new Paragraph(new Phrase("Note : " + footer2, font3));
                footer.Alignment = Element.ALIGN_LEFT;

                PdfPTable TCTab = new PdfPTable(2);
                if (poh.TermsAndCondition.Trim().Length != 0)
                {
                    Chunk TCchunk = new Chunk("General Terms & Conditions\n", font2);
                    TCchunk.SetUnderline(0.2f, -2f);
                    TCTab = new PdfPTable(2);
                    TCTab.WidthPercentage = 100;
                    PdfPCell TCCell = new PdfPCell();
                    TCCell.Colspan = 2;
                    TCCell.Border  = 0;
                    TCCell.AddElement(TCchunk);
                    TCTab.AddCell(TCCell);
                    try
                    {
                        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                        for (int i = 0; i < ParaTC.Length - 1; i++)
                        {
                            TCCell         = new PdfPCell();
                            TCCell.Colspan = 2;
                            TCCell.Border  = 0;
                            Paragraph header  = new Paragraph();
                            Paragraph details = new Paragraph();
                            details.IndentationLeft  = 12f;
                            details.IndentationRight = 12f;
                            details.Alignment        = Element.ALIGN_JUSTIFIED;
                            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                            header.Add(new Phrase(paraHeaderStr, font2));
                            details.Add(new Phrase(paraFooterStr, font1));
                            TCCell.AddElement(header);
                            TCCell.AddElement(details);
                            TCTab.AddCell(TCCell);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    }
                    try
                    {
                        if (TCTab.Rows.Count >= 3)
                        {
                            TCTab.KeepRowsTogether(0, 3);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    }
                }

                doc.Add(tableHeader);
                doc.Add(tableDocName);
                doc.Add(paragraphOpenCluse);
                doc.Add(TableAddress);
                doc.Add(TableItemDetails);
                doc.Add(footer);
                if (poh.TermsAndCondition.Trim().Length != 0)
                {
                    doc.Add(TCTab);
                }
                doc.Close();

                if (poh.Status == 0 && poh.DocumentStatus < 99)
                {
                    String wmurl = "";
                    wmurl = "004.png";
                    PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
                }
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Save Document");
            }
        }
Ejemplo n.º 4
0
        public void PrintWO(workorderheader woh, List <workorderdetail> WODetail, string totalTaxDetail)
        {
            Dictionary <string, string> companyInfo = getCompanyInformation();

            customer custDetail = CustomerDB.getCustomerDetailForPO(woh.CustomerID);

            string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
            string   contractorAdd     = "Contractor:\n" + custDetail.name + Main.delimiter1 + "\n" + woh.POAddress + "\n";

            if (custDetail.StateName.ToString().Length != 0)
            {
                contractorAdd = contractorAdd + "Sate Name:" + custDetail.StateName;
            }
            if (custDetail.StateCode.ToString().Length != 0)
            {
                contractorAdd = contractorAdd + "\nState Code:" + custDetail.StateCode;
            }
            if (custDetail.OfficeName.ToString().Length != 0)
            {
                contractorAdd = contractorAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
            }
            string InvoiceTo   = "Invoice To: \n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + companyBillingAdd[1] + "\nGST:" + companyInfo["GST"] + "\nCIN:" + companyInfo["CIN"] + "\nPAN:" + companyInfo["PAN"];
            string declaration = "We, Cellcomm Solutions Limited (also referred to as “CSL”), are pleased to place" +
                                 " this Purchase Order (also referred to as 'PO') with the Contractor addressed below.In accepting this Purchase Order, the Contractor" +
                                 " undertakes to execute the work described herein as per the details and instructions shown below" +
                                 " (such details and instructions being the Specific Terms and Conditions agreed between the Parties) " +
                                 "and also subject to the General Terms & Conditions contained herein.";

            string HeaderString = contractorAdd +
                                  Main.delimiter2 + "PO No : S-" + woh.WONo + " , Date : " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(woh.WODate)) +
                                  Main.delimiter2 + "Contractor Reference : " + woh.ContractorReference +
                                  Main.delimiter2 + "Target Date : " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(woh.TargetDate)) + Main.delimiter2 +

                                  InvoiceTo +

                                  Main.delimiter2 + "Payment Terms : " + PTDefinitionDB.getPaymentTermString(woh.PaymentTerms) +
                                  Main.delimiter2 + woh.SpecialNote;


            string footer1         = "Amount in words\n\n";
            string ColHeader       = "SI No.;Description of Work;Location;Quantity;Rate;Amount";
            string footer2         = "This Purchase Order, being computer generated, does not require physical signature.";
            string footer3         = "for Cellcomm Solutions Limited;Authorised Signatory";
            string termsAndCond    = getTCString(woh.TermsAndCond, woh.DocumentID);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = WODetail.Count();

            //+ : main.delimeter1
            //; : main.delimiter2

            try
            {
                foreach (workorderdetail wod in WODetail)
                {
                    if (n == count)
                    {
                        ColDetailString = ColDetailString + n + Main.delimiter1 + wod.Description + Main.delimiter1 + wod.WorkLocation + Main.delimiter1 + wod.Quantity + Main.delimiter1
                                          + wod.Price + Main.delimiter1 + (wod.Quantity * wod.Price);
                    }
                    else
                    {
                        ColDetailString = ColDetailString + n + Main.delimiter1 + wod.Description + Main.delimiter1 + wod.WorkLocation + Main.delimiter1 + wod.Quantity + Main.delimiter1
                                          + wod.Price + Main.delimiter1 + (wod.Quantity * wod.Price) + Main.delimiter2;
                    }
                    totQuant = totQuant + wod.Quantity;
                    totAmnt  = totAmnt + (wod.Quantity * wod.Price);
                    n++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Save 1 : " + ex.ToString());
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                if (woh.Status == 0 && woh.DocumentStatus < 99)
                {
                    sfd.FileName = woh.DocumentID + "-Temp-" + woh.TemporaryNo;
                }
                else
                {
                    sfd.FileName = woh.DocumentID + "-" + woh.WONo;
                }

                //sfd.ShowDialog();
                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }

                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                //rec.Bottom = 10;
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                Font font4 = FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                //String imageURL = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                //iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                String URL = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;
                //--

                PdfPTable tableHeader = new PdfPTable(2);

                tableHeader.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableHeader.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    ourAddr.Add(new Chunk(det.companyname + "\n", font2));
                    ourAddr.Add(new Chunk(det.companyAddress.Replace("\r\n", "\n"), font4));
                    StringBuilder sb = new StringBuilder();
                    sb.Append("\nGST : " + companyInfo["GST"] + "\nState Code for GST : " + companyInfo["StateCode"] + "\nCIN : " + companyInfo["CIN"] + "\nPAN : " + companyInfo["PAN"]);
                    ourAddr.Add(new Chunk(sb.ToString(), font4));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                    ourAddr.SetLeading(0.0f, 1.5f);
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableHeader.AddCell(cellAdd);
                //----
                Paragraph paragraphDocumentName = new Paragraph(new Phrase("PURCHASE ORDER", font2));
                paragraphDocumentName.Alignment = Element.ALIGN_CENTER;
                Paragraph paragraphOpenCluse = new Paragraph(new Phrase(declaration, font1));
                paragraphOpenCluse.Alignment       = Element.ALIGN_JUSTIFIED;
                paragraphDocumentName.SpacingAfter = 15;
                //PrintPurchaseOrder prog = new PrintPurchaseOrder();
                string[] HeaderStr = HeaderString.Split(Main.delimiter2);

                PdfPTable TableAddress = new PdfPTable(6);

                TableAddress.SpacingBefore   = 20f;
                TableAddress.WidthPercentage = 100;
                float[] HWidths = new float[] { 0.5f, 4.5f, 2f, 2f, 2f, 3f };
                TableAddress.SetWidths(HWidths);
                PdfPCell cell;
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0 || i == 4)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter1);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        cell         = new PdfPCell(phr);
                        cell.Colspan = 3;
                        if (i == 0)
                        {
                            cell.Rowspan = 3;
                        }
                        else
                        {
                            cell.Rowspan = 2;
                        }
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        TableAddress.AddCell(cell);
                    }
                    else
                    {
                        cell               = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan       = 3;
                        cell.MinimumHeight = wid;
                        TableAddress.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable TableItemDetails = new PdfPTable(6);
                TableItemDetails.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                TableItemDetails.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 4.5f, 2f, 2f, 2f, 3f };
                TableItemDetails.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 6;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                TableItemDetails.AddCell(foot);

                TableItemDetails.HeaderRows = 2;
                TableItemDetails.FooterRows = 1;

                TableItemDetails.SkipFirstHeader = false;
                TableItemDetails.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    hg = TableItemDetails.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 3 || j == 4 || j == 5)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 5)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            pcell        = new PdfPCell(new Phrase(str[j], font1));
                            pcell.Border = 0;
                        }
                        pcell.MinimumHeight       = 10;
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        pcell.BorderWidthLeft     = 0.01f;
                        pcell.BorderWidthRight    = 0.01f;
                        TableItemDetails.AddCell(pcell);
                    }
                }
                double roundedAmt = Math.Round(totAmnt, 0);
                double diffAmount = roundedAmt - totAmnt;
                if (diffAmount != 0)
                {
                    TableItemDetails.AddCell("");
                    TableItemDetails.AddCell("");
                    PdfPCell cellTot = new PdfPCell(new Phrase("", font1));
                    cellTot.Colspan             = 3;
                    cellTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(cellTot);
                    TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", totAmnt), font2));

                    TableItemDetails.AddCell("");
                    TableItemDetails.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Rounding off", font1));
                    cellRound.Colspan             = 3;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(cellRound);
                    TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                }
                TableItemDetails.AddCell("");
                TableItemDetails.AddCell("");
                PdfPCell cellTotal = new PdfPCell(new Phrase("Total", font1));
                cellTotal.Colspan             = 3;
                cellTotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                TableItemDetails.AddCell(cellTotal);
                TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font2));

                //-----
                string   total  = footer1 + NumberToString.convert(roundedAmt.ToString());
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font3));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                //fcell1.BorderWidthBottom = 0;
                TableItemDetails.AddCell(fcell1);

                PdfPTable tableSub = new PdfPTable(1);
                tableSub.DefaultCell.Border = 0;
                tableSub.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableSub.AddCell(new Phrase("Subject To Bangalore Jurisdiction", font2));
                PdfPCell celSub = new PdfPCell(tableSub);
                celSub.Border  = 0;
                celSub.Colspan = 6;
                TableItemDetails.AddCell(celSub);
                TableItemDetails.KeepRowsTogether(TableItemDetails.Rows.Count - 5, TableItemDetails.Rows.Count);
                Paragraph footer = new Paragraph(new Phrase("Note : " + footer2, font3));
                footer.Alignment = Element.ALIGN_LEFT;
                //--------------------
                PdfPTable TCTab = new PdfPTable(2);
                if (woh.TermsAndCond.Trim().Length != 0)
                {
                    Chunk TCchunk = new Chunk("General Terms & Conditions\n", font2);
                    TCchunk.SetUnderline(0.2f, -2f);
                    TCTab = new PdfPTable(2);
                    TCTab.WidthPercentage = 100;
                    PdfPCell TCCell = new PdfPCell();
                    TCCell.Colspan = 2;
                    TCCell.Border  = 0;
                    TCCell.AddElement(TCchunk);
                    TCTab.AddCell(TCCell);
                    try
                    {
                        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                        for (int i = 0; i < ParaTC.Length + 1; i++)
                        {
                            TCCell         = new PdfPCell();
                            TCCell.Colspan = 2;
                            TCCell.Border  = 0;
                            Paragraph header  = new Paragraph();
                            Paragraph details = new Paragraph();
                            details.IndentationLeft  = 12f;
                            details.IndentationRight = 12f;
                            details.Alignment        = Element.ALIGN_JUSTIFIED;
                            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                            header.Add(new Phrase(paraHeaderStr, font2));
                            details.Add(new Phrase(paraFooterStr, font1));
                            TCCell.AddElement(header);
                            TCCell.AddElement(details);
                            TCTab.AddCell(TCCell);
                        }
                    }
                    catch (Exception ex)
                    {
                        ////MessageBox.Show("Failed to Save 2 : "+ex.ToString());
                    }
                    try
                    {
                        TCTab.KeepRowsTogether(0, 3);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Failed to Save 3 : " + ex.ToString());
                    }
                }
                doc.Add(tableHeader);
                doc.Add(paragraphDocumentName);
                doc.Add(paragraphOpenCluse);
                doc.Add(TableAddress);
                doc.Add(TableItemDetails);
                doc.Add(footer);
                if (woh.TermsAndCond.Length != 0)
                {
                    doc.Add(TCTab);
                }
                doc.Close();

                if (woh.Status == 0 && woh.DocumentStatus < 99)
                {
                    String wmurl = "";
                    wmurl = "004.png";
                    PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
                }
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Save 4 : " + ex.ToString());
            }
        }
Ejemplo n.º 5
0
        public void PrintPO(poheader poh, List <podetail> PODetail, string taxStr)
        {
            Dictionary <string, string> companyInfo = getCompanyInformation();
            //string stateDetail =
            customer custDetail = CustomerDB.getCustomerDetailForPO(poh.CustomerID);

            string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
            string   poNoSuffix        = "";

            if (poh.DocumentID == "POGENERAL")
            {
                poNoSuffix = "G-";
            }
            else if (poh.DocumentID == "PURCHASEORDER")
            {
                poNoSuffix = "P-";
            }
            string supplAdd = "Supplier:\n" + custDetail.name + Main.delimiter1 + "\n" + custDetail.BillingAddress + "\n";

            if (custDetail.StateName.ToString().Length != 0)
            {
                supplAdd = supplAdd + "Sate Name:" + custDetail.StateName;
            }
            if (custDetail.StateCode.ToString().Length != 0)
            {
                supplAdd = supplAdd + "\nState Code:" + custDetail.StateCode;
            }
            if (custDetail.OfficeName.ToString().Length != 0)
            {
                supplAdd = supplAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
            }
            //; : main.delimiter2
            //$ : main.delimiter1
            string InvoiceTo    = "Invoice To: \n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + companyBillingAdd[1] + "\nGST:" + companyInfo["GST"] + "\nCIN:" + companyInfo["CIN"] + "\nPAN:" + companyInfo["PAN"];
            string DespatchTo   = "Dispatch To:\n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + poh.DeliveryAddress + "\nGST:" + companyInfo["GST"];
            string HeaderString = supplAdd +
                                  Main.delimiter2 + "PO No : " + poNoSuffix + poh.PONo + Main.delimiter2 + "Date: " + poh.PODate.ToString("dd-MM-yyyy") +
                                  Main.delimiter2 + "Supplier Ref./Order No.\n" + poh.ReferenceQuotation.Replace(";", ",\n") +
                                  Main.delimiter2 + "Despatch Through:\n" + CatalogueValueDB.getParamValue("TransportationMode", poh.TransportationMode) +
                                  Main.delimiter2 + InvoiceTo +
                                  Main.delimiter2 + "Freight:\n" + CatalogueValueDB.getParamValue("Freight", poh.FreightTerms) +
                                  Main.delimiter2 + "Delivery Period:\n" + poh.DeliveryPeriod + " Days" + Main.delimiter2 +
                                  DespatchTo +
                                  Main.delimiter2 + "Tax And Duties:\n" + CatalogueValueDB.getParamValue("TaxStatus", poh.TaxTerms) +
                                  Main.delimiter2 + "Mode/Terms of Payment:\n" + CatalogueValueDB.getParamValue("PaymentMode", poh.ModeOfPayment) + "\n" + PTDefinitionDB.getPaymentTermString(poh.PaymentTerms);
            string footer1         = "Amount In Words\n\n";
            string ColHeader       = "SI No.;Description of Goods;Quantity;Unit;Unit Rate;Amount;Warranty\nIn Days";
            string footer2         = "";
            string footer3         = "for CELLCOMM SOLUTION LIMITED;Authorised Signatory";
            string termsAndCond    = getTCString(poh.TermsAndCondition);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = PODetail.Count();

            foreach (podetail pod in PODetail)
            {
                if (n == count)
                {
                    //ColDetailString = ColDetailString + n + "+" + pod.Description + "+" + pod.Quantity + "+"
                    //                  + pod.Unit + "+" + pod.Price + "+" + (pod.Quantity * pod.Price) + "+" + pod.WarrantyDays;
                    ColDetailString = ColDetailString + n + Main.delimiter1 + pod.Description + Main.delimiter1 + pod.Quantity + Main.delimiter1
                                      + pod.Unit + Main.delimiter1 + pod.Price + Main.delimiter1 + (pod.Quantity * pod.Price) + Main.delimiter1 + pod.WarrantyDays;
                    if (pod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString + ";" +"" + "+" + pod.TaxCode + "+" + "" + "+"
                        //              + "" + "+" + "" + "+" + pod.Tax + "+" + "";
                        ColDetailString = ColDetailString + Main.delimiter2 + "" + Main.delimiter1 + pod.TaxCode + Main.delimiter1 + "" + Main.delimiter1
                                          + "" + Main.delimiter1 + "" + Main.delimiter1 + pod.Tax + Main.delimiter1 + "";
                    }
                    // ColDetailString = ColDetailString
                }
                else
                {
                    //ColDetailString = ColDetailString + n + "+" + pod.Description + "+" + pod.Quantity + "+"
                    //                  + pod.Unit + "+" + pod.Price + "+" + (pod.Quantity * pod.Price) + "+" + pod.WarrantyDays + ";";
                    ColDetailString = ColDetailString + n + Main.delimiter1 + pod.Description + Main.delimiter1 + pod.Quantity + Main.delimiter1
                                      + pod.Unit + Main.delimiter1 + pod.Price + Main.delimiter1 + (pod.Quantity * pod.Price) + Main.delimiter1 + pod.WarrantyDays + Main.delimiter2;
                    if (pod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString + "" + "+" + pod.TaxCode + "+" + "" + "+"
                        //             + "" + "+" + "" + "+" + pod.Tax + "+" + "" + Main.delimiter2;
                        ColDetailString = ColDetailString + "" + Main.delimiter1 + pod.TaxCode + Main.delimiter1 + "" + Main.delimiter1
                                          + "" + Main.delimiter1 + "" + Main.delimiter1 + pod.Tax + Main.delimiter1 + "" + Main.delimiter2;
                    }
                }
                totQuant = totQuant + pod.Quantity;
                totAmnt  = totAmnt + (pod.Quantity * pod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                sfd.FileName = poh.DocumentID + "-" + poh.PONo;

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font   font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font   font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                String URL   = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;


                PdfPTable tableMain = new PdfPTable(2);

                tableMain.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableMain.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    string addr = det.companyname + "\n" + det.companyAddress;
                    ourAddr           = new Paragraph(new Phrase(addr, font2));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableMain.AddCell(cellAdd);


                Paragraph paragraph = new Paragraph(new Phrase("PURCHASE ORDER", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(Main.delimiter2);

                PdfPTable table = new PdfPTable(7);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 0.5f, 8f, 2f, 1.5f, 1.5f, 3f, 1.5f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                int[]    arr = { 6, 7, 9, 10 };
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0 || i == 5 || i == 8)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter1);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        //cell = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell                     = new PdfPCell(phr);
                        cell.Rowspan             = 2;
                        cell.Colspan             = 2;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        //wid = cell.MinimumHeight / 2;
                        table.AddCell(cell);
                    }
                    else if (arr.Contains(i))
                    {
                        cell               = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan       = 5;
                        cell.MinimumHeight = wid;
                        table.AddCell(cell);
                    }
                    else
                    {
                        cell = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        if (i % 2 != 0)
                        {
                            cell.Colspan = 3;
                        }
                        else
                        {
                            cell.Colspan = 2;
                        }
                        table.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(7);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 8f, 2f, 1.5f, 2f, 2.5f, 1.5f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    if (i == 4 || i == 5)
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim() + "\n(" + poh.CurrencyID + ")", font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                    else
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 7;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;

                        if (j == 2 || j == 4 || j == 5)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 5)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            if (j == 6)
                            {
                                if ((str[j].Trim().Length == 0 || Convert.ToInt32(str[j]) == 0) && (track != 1))
                                {
                                    pcell = new PdfPCell(new Phrase("NA", font1));
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else if (j == 3)
                            {
                                int m = 1;
                                if (Int32.TryParse(str[j], out m) == true)
                                {
                                    if (Convert.ToInt32(str[j]) == 0)
                                    {
                                        pcell = new PdfPCell(new Phrase("", font1));
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(str[j], font1));
                            }

                            pcell.Border = 0;
                        }

                        //if (i == DetailStr.Length - 1)
                        //{
                        //    pcell.MinimumHeight = 50;
                        //}
                        //else
                        pcell.MinimumHeight = 10;
                        //pcell.MinimumHeight = 20;
                        if (j == 1)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        pcell.BorderWidthLeft  = 0.01f;
                        pcell.BorderWidthRight = 0.01f;

                        table1.AddCell(pcell);
                    }
                    //foreach()
                    if (track == 1)
                    {
                        for (int j = 0; j < 7; j++)
                        {
                            PdfPCell pcell1;

                            if (j == 5)
                            {
                                pcell1                   = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(dc1 + dc2)), font1));
                                pcell1.Border            = 0;
                                pcell1.BorderWidthBottom = 0.01f;
                            }
                            else
                            {
                                pcell1        = new PdfPCell(new Phrase(""));
                                pcell1.Border = 0;
                            }
                            pcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            pcell1.BorderWidthLeft     = 0.01f;
                            pcell1.BorderWidthRight    = 0.01f;
                            table1.AddCell(pcell1);
                        }
                    }
                }

                double roundedAmt = Math.Round(poh.POValue, 0);
                double diffAmount = roundedAmt - poh.POValue;

                if (diffAmount != 0)
                {
                    table1.AddCell("");
                    table1.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Round off Adj.", font1));
                    cellRound.Colspan             = 3;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(cellRound);
                    table1.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                    table1.AddCell("");
                }

                table1.AddCell("");
                table1.AddCell("");
                PdfPCell cellTotal = new PdfPCell(new Phrase("Total", font1));
                cellTotal.Colspan             = 3;
                cellTotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.AddCell(cellTotal);
                table1.AddCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font1));
                table1.AddCell("");

                string   total  = footer1 + NumberToString.convert(roundedAmt.ToString()).Replace("INR", poh.CurrencyID) + "\n\n";
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font1));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                fcell1.BorderWidthRight    = 0;
                fcell1.BorderWidthTop      = 0;
                table1.AddCell(fcell1);

                PdfPCell fcell4 = new PdfPCell(new Phrase("E. & O.E", font1));
                //fcell4.MinimumHeight = 50;
                fcell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell4.BorderWidthBottom   = 0;
                //fcell4.BorderWidthRight = 0;
                fcell4.BorderWidthLeft = 0;
                fcell4.BorderWidthTop  = 0;
                table1.AddCell(fcell4);

                if (poh.SpecialNote.Trim().Length != 0)
                {
                    footer2 = "Note:\n" + poh.SpecialNote.Trim();
                }
                PdfPCell fcell2 = new PdfPCell(new Phrase(footer2, font1));
                fcell2.Colspan             = 4;
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell2.BorderWidthTop      = 0;
                fcell2.BorderWidthRight    = 0;
                table1.AddCell(fcell2);
                string[] ft = footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border            = 0;
                fcell3.Colspan           = 4;
                fcell3.BorderWidthTop    = 0f;
                fcell3.BorderWidthLeft   = 0f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);
                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                PdfPTable taxTab = new PdfPTable(3);
                //taxTab.
                taxTab.WidthPercentage = 100;

                float[] twidth = new float[] { 3f, 3f, 10f };
                taxTab.SetWidths(twidth);
                double dd = 0;
                if (poh.TaxAmount != 0)
                {
                    PdfPCell pcell;
                    pcell = new PdfPCell(new Phrase("Tax Details", font2));
                    taxTab.AddCell(pcell);
                    PdfPCell pcellc = new PdfPCell(new Phrase("Amount(" + poh.CurrencyID + ")", font2));
                    taxTab.AddCell(pcellc);
                    PdfPCell pcelllst = new PdfPCell(new Phrase("", font1));
                    pcelllst.Border = 0;
                    taxTab.AddCell(pcelllst);
                    //for (int i = 0; i < 2; i++)
                    //{

                    //    if (i == 1)
                    //        pcell = new PdfPCell(new Phrase("Tax Details", font2));
                    //    else

                    //    //pcell.Border = 0;
                    //    //pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                    //    //pcell.MinimumHeight = 20;
                    //    //pcell.BorderWidthLeft = 0.01f;
                    //    //pcell.BorderWidthRight = 0.01f;
                    //    table1.AddCell(pcell);
                    //}
                    string[] tax = taxStr.Split(Main.delimiter2);
                    for (int i = 0; i < tax.Length - 1; i++)
                    {
                        string[] subtax = tax[i].Split(Main.delimiter1);
                        PdfPCell pcell1;
                        pcell1 = new PdfPCell(new Phrase(subtax[0], font1));
                        PdfPCell pcell2;
                        pcell2 = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(subtax[1])), font1));
                        PdfPCell pcell3 = new PdfPCell(new Phrase("", font1));
                        pcell3.Border = 0;
                        //taxTab.AddCell(pcell3);
                        //pcell1.Border = 0;
                        //pcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        //pcell1.BorderWidthLeft = 0.01f;
                        //pcell1.BorderWidthRight = 0.01f;
                        //if (i == (tax.Length - 2))
                        //{
                        //    pcell1.MinimumHeight = 100;
                        //}
                        //else
                        //pcell1.MinimumHeight = 20;
                        taxTab.AddCell(pcell1);
                        //pcell2.MinimumHeight = 20;
                        taxTab.AddCell(pcell2);
                        taxTab.AddCell(pcell3);
                    }
                    taxTab.AddCell(new Phrase("Total Tax Amount", font2));
                    taxTab.AddCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(poh.TaxAmount)), font2));
                    PdfPCell pcellt = new PdfPCell(new Phrase("", font1));
                    pcellt.Border = 0;
                    taxTab.AddCell(pcellt);
                    taxTab.KeepTogether  = true;
                    taxTab.SpacingAfter  = 2f;
                    taxTab.SpacingBefore = 3f;
                }
                PdfPTable TCTab = new PdfPTable(2);
                if (poh.TermsAndCondition.Trim().Length != 0)
                {
                    Chunk TCchunk = new Chunk("Terms And Conditoins:\n", font2);
                    TCchunk.SetUnderline(0.2f, -2f);
                    TCTab = new PdfPTable(2);
                    TCTab.WidthPercentage = 100;
                    PdfPCell TCCell = new PdfPCell();
                    TCCell.Colspan = 2;
                    TCCell.Border  = 0;
                    TCCell.AddElement(TCchunk);
                    TCTab.AddCell(TCCell);
                    try
                    {
                        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                        for (int i = 0; i < ParaTC.Length - 1; i++)
                        {
                            TCCell         = new PdfPCell();
                            TCCell.Colspan = 2;
                            TCCell.Border  = 0;
                            Paragraph header  = new Paragraph();
                            Paragraph details = new Paragraph();
                            details.IndentationLeft  = 12f;
                            details.IndentationRight = 12f;
                            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                            header.Add(new Phrase(paraHeaderStr, font2));
                            details.Add(new Phrase(paraFooterStr, font1));
                            TCCell.AddElement(header);
                            TCCell.AddElement(details);
                            TCTab.AddCell(TCCell);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    }
                    try
                    {
                        if (TCTab.Rows.Count >= 3)
                        {
                            TCTab.KeepRowsTogether(0, 3);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    }
                }
                doc.Add(tableMain);
                //doc.Add(jpg);
                //doc.Add(img);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);
                if (poh.TaxAmount != 0)
                {
                    doc.Add(taxTab);
                }
                if (poh.TermsAndCondition.Trim().Length != 0)
                {
                    doc.Add(TCTab);
                }
                doc.Close();
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Save Document");
            }
        }