Exemplo n.º 1
0
        private static void ReportBuilderPatronage(List <ListStatementPatRetainItem> stateList,
                                                   int cropYear, DateTime certificateDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs,
                                                   string sigName, string sigTitle, string sigImagePath)
        {
            const string METHOD_NAME = "ReportBuilderPatronage: ";

            string SHID               = "";
            string equityCropYear     = "";
            string rptTitle           = "";
            string certificateDateStr = certificateDate.ToString(HEADER_DATE_FORMAT);
            string qualifiedStr       = "";
            float  pdfYPos            = 0;
            float  pdfXPos            = -4;

            Document        document    = null;
            PdfWriter       writer      = null;
            PdfPTable       bottomTable = null;
            ColumnText      ct          = null;
            PdfImportedPage pdfImport   = null;

            CertificateEvent pgEvent = null;

            try {
                if (stateList.Count > 0)
                {
                    qualifiedStr = (stateList[0].Qualified.ToLower() == "qualified" ? "Qualified" : "NonQualified");
                }

                iTextSharp.text.Image imgSignature = PdfReports.GetImage(sigImagePath, 228, 68, iTextSharp.text.Element.ALIGN_LEFT);

                foreach (ListStatementPatRetainItem state in stateList)
                {
                    if (rptTitle.Length == 0)
                    {
                        rptTitle = qualifiedStr.ToUpper() + " PATRONAGE REFUND NOTICE\n" + "CROP YEAR " + cropYear.ToString();
                    }

                    SHID           = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        // Attach my override event handler(s)
                        pgEvent = new CertificateEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                        // ** ROTATE ** ROTATE **  ---------------------------------------------------------------------------------------
                        //PdfReader reader = new PdfReader(...);
                        //for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
                        //    reader.getPageN(k).put(PdfName.ROTATE, new PdfNumber(90));
                        //}
                        //PdfStamper stp = new PdfStamper(reader, ...);
                        //stp.close();
                        // ** ROTATE ** ROTATE **  ---------------------------------------------------------------------------------------
                        //string tmpFilePath = sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate.pdf");
                        //PdfReader rdr = new PdfReader(tmpFilePath);
                        //rdr.GetPageN(1).Put(PdfName.ROTATE, new PdfNumber(90));

                        //Document docCopy = new Document(rdr.GetPageSizeWithRotation(1));
                        //PdfCopy pCopy = new PdfCopy(docCopy, new System.IO.FileStream(sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate90.pdf"),
                        //    System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read));

                        //docCopy.Open();

                        //docCopy.AddCreationDate();
                        //docCopy.AddCreator("");
                        //docCopy.AddTitle("CertificateTemplate.pdf");

                        //pCopy.AddPage(pCopy.GetImportedPage(rdr, 1));
                        //docCopy.Close();

                        //using (System.IO.FileStream fsTmpOut = new FileStream(sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate90.pdf"),
                        //    System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read)) {

                        //    PdfStamper tmpStamp = new PdfStamper(rdr, fsTmpOut);
                        //    tmpStamp.Close();
                        //}

                        // ================================================================================================================
                        // FROM PDF -- Pulls a background image out of a pdf and uses it as the under layer! Works BUT NEEDS ADJUSTMENT
                        // ================================================================================================================
                        string    _certBorderPath = sigImagePath.Replace("CertificateSignature.gif", "CertBorders.pdf");
                        PdfReader rdrCertBorder   = new PdfReader(_certBorderPath);
                        pdfImport = writer.GetImportedPage(rdrCertBorder, 1); // import only page 1.

                        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        // ================================================================================================================
                        // FROM JPG -- Uses a jpg image as the under layer!!! This ROUGHLY WORKS -- NEEDS HELP !
                        // ================================================================================================================
                        //string _logo = sigImagePath.Replace("CertificateSignature.gif", "MyBorders.gif");

                        //iTextSharp.text.Image imgBack = PdfReports.GetImage(_logo, Convert.ToInt32(document.Right - document.RightMargin - document.LeftMargin),
                        //    Convert.ToInt32(document.Top - document.TopMargin - document.BottomMargin), iTextSharp.text.Element.ALIGN_CENTER);

                        //float imageYPos = document.Top - imgBack.Height;
                        //float imageXPos = 0;

                        //// To position an image  at (x,y) use addImage(image, image_width, 0, 0, image_height, x, y)
                        //writer.DirectContentUnder.AddImage(imgBack, imgBack.Width, 0, 0, imgBack.Height, imageXPos, imageYPos);

                        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    }
                    else
                    {
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        document.NewPage();
                    }

                    writer.DirectContentUnder.AddTemplate(pdfImport, pdfXPos, pdfYPos);

                    // =======================================================
                    // Build Report
                    // =======================================================

                    // Fill report Body
                    ct = pgEvent.GetColumnObject();
                    BuildPatronageBodyText(cropYear, qualifiedStr, ct);

                    // Add Bottom section -- Date, Amount, SigLine.
                    bottomTable = PdfReports.CreateTable(_bottomPatLayout, 0);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);
                    PdfReports.AddText2Table(bottomTable, "Dated: " + certificateDateStr, _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, "Total patronage refund: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.EquityAmt).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, "Paid by check: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.PatInitPayment).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, "Patronage equity: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.RedeemAmt).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    ct.AddElement(bottomTable);

                    //----------------------------------
                    // Add Signature
                    //----------------------------------
                    //  this is odd, but use the RET layout for sig line.
                    bottomTable = PdfReports.CreateTable(_bottomRetLayout, 0);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddImage2Table(bottomTable, imgSignature);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    // add signature info
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigName, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigTitle, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    ct.AddElement(bottomTable);
                    ct.Go(false);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 2
0
        private static void ReportBuilderRetainRedeems(int cropYear, string paymentDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilderRetainRedeems: ";

            string  SHID               = "";
            string  equityCropYear     = "";
            string  lastSHID           = "";
            string  lastEquityCropYear = "";
            decimal totalCheckAmount   = 0;
            string  rptTitle           = "";
            string  statementDate      = Convert.ToDateTime(paymentDate).ToString(HEADER_DATE_FORMAT);

            Document  document    = null;
            PdfWriter writer      = null;
            PdfPTable detailTable = null;

            iTextSharp.text.Image         imgLogo = null;
            StatementPatronageRetainEvent pgEvent = null;

            try {
                List <ListStatementPatRetainItem> stateList = WSCReportsExec.RptStatementRetainRedeem(cropYear, shid, fromShid, toShid, paymentDate);

                for (int i = 0; i < stateList.Count; i++)
                {
                    ListStatementPatRetainItem state = stateList[i];

                    if (rptTitle.Length == 0)
                    {
                        rptTitle = "Unit Retain -- " + state.Qualified + " -- " + statementDate;
                    }

                    SHID           = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null)
                    {
                        // Create the detail table
                        detailTable = PdfReports.CreateTable(_primaryTableLayout, 0);
                        AddRetainRedeemDetailHeader(detailTable);

                        lastSHID         = state.SHID;
                        totalCheckAmount = CalcRedeemCheck(stateList, i);

                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        imgLogo = PdfReports.GetImage(logoUrl, 77, 45, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        pgEvent = new StatementPatronageRetainEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, totalCheckAmount, 0, rptTitle, imgLogo);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();
                    }
                    else
                    {
                        if (lastSHID != SHID)
                        {
                            //-------------------------------------------------------------------------------------
                            // When you change members, kick out the page and move on to the next member,
                            // and reset flags.
                            //-------------------------------------------------------------------------------------

                            lastSHID           = SHID;
                            lastEquityCropYear = "";

                            // Add Grand Total Line
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                            PdfReports.AddText2Table(detailTable, "Total Amount", _labelFont, "center");
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, 2);
                            PdfReports.AddText2Table(detailTable, totalCheckAmount.ToString("$#,##0.00"), _normalFont, "right");

                            // Add this members detail lines to the document
                            PdfReports.AddTableNoSplit(document, pgEvent, detailTable);

                            // Calc the total for the new SHID
                            totalCheckAmount = CalcRedeemCheck(stateList, i);

                            pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, totalCheckAmount, 0, rptTitle, imgLogo);
                            document.NewPage();

                            // Refresh the detail table
                            detailTable = PdfReports.CreateTable(_primaryTableLayout, 0);
                            AddRetainRedeemDetailHeader(detailTable);
                        }
                    }

                    // =======================================================
                    // Build Report
                    // =======================================================
                    if (state.EquityCropYear != lastEquityCropYear)
                    {
                        // Before resetting the lastEquityCropYear, a non-blank crop year means this is a subsequent
                        // crop year for the same shid. Add a blank
                        if (lastEquityCropYear.Length > 0)
                        {
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                        }

                        lastEquityCropYear = state.EquityCropYear;

                        // Show Equity Data for Crop Year
                        PdfReports.AddText2Table(detailTable, state.EquityCropYear, _normalFont, "center");
                        PdfReports.AddText2Table(detailTable, state.EquityTons, _normalFont, "right");
                        PdfReports.AddText2Table(detailTable, state.RatePerTon, _normalFont, "right");
                        PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.RedeemAmt).ToString("$#,##0.00"), _normalFont, "right");

                        if (state.DeductionDesc.Length > 0)
                        {
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);

                            PdfReports.AddText2Table(detailTable, " ", _normalFont);
                            PdfReports.AddText2Table(detailTable, "Less Deductions: ", _normalItalicFont, "left", 3);

                            PdfReports.AddText2Table(detailTable, " ", _normalFont);
                            PdfReports.AddText2Table(detailTable, state.DeductionDesc, _normalFont, "left", 2);
                            PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.DeductionAmt).ToString("$#,##0.00"), _normalFont, "right");
                        }
                    }
                    else
                    {
                        //----------------------------------------------------------
                        // This is a deduction only line, a subsequent deduction.
                        //----------------------------------------------------------
                        PdfReports.AddText2Table(detailTable, " ", _normalFont);
                        PdfReports.AddText2Table(detailTable, state.DeductionDesc, _normalFont, "left", 2);
                        PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.DeductionAmt).ToString("$#,##0.00"), _normalFont, "right");
                    }
                }

                if (detailTable != null)
                {
                    // Add Grand Total Line
                    PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                    PdfReports.AddText2Table(detailTable, "Total Amount", _labelFont, "center");
                    PdfReports.AddText2Table(detailTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(detailTable, totalCheckAmount.ToString("$#,##0.00"), _normalFont, "right");

                    // Add this members detail lines to the document
                    PdfReports.AddTableNoSplit(document, pgEvent, detailTable);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 3
0
        private static void ReportBuilder(SqlDataReader drPay, int cropYear, int paymentNumber, string paymentDescription,
                                          string fromDate, string toDate, string statementDate, bool isCumulative, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "rptTransmittal.ReportBuilder: ";
            const int    resetFlag   = 0;

            Document  document             = null;
            PdfWriter writer               = null;
            PdfPTable table                = null;
            TransmittalReportEvent pgEvent = null;

            iTextSharp.text.Image imgLogo = null;

            int contractNumber     = 0;
            int lastContractNumber = 0;
            int payeeNumber        = 0;
            int lastPayeeNumber    = 0;

            decimal ytdEHBonus       = 0;
            decimal ytdEHAmount      = 0;
            decimal ytdRHAmount      = 0;
            decimal ytdDeductions    = 0;
            decimal ytdEHAmountMoved = 0;
            decimal ytdRHAmountMoved = 0;
            decimal ytdNet           = 0;
            decimal curSLM           = 0;
            decimal pctPaid          = 0;
            decimal actualSugar      = 0;

            string rptTitle = "Western Sugar Cooperative Payment Transmittal";

            Font headerFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font normalFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font labelFont  = FontFactory.GetFont("HELVETICA", 8F, Font.BOLD);

            try {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BeetConn"].ToString())) {
                    while (drPay.Read())
                    {
                        try {
                            contractNumber = Convert.ToInt32(drPay.GetString(drPay.GetOrdinal("Contract_Number")));
                            payeeNumber    = drPay.GetInt16(drPay.GetOrdinal("Payee_Number"));

                            if (document == null)
                            {
                                lastContractNumber = contractNumber;
                                lastPayeeNumber    = payeeNumber;

                                // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                                //  ***  US LETTER: 612 X 792  ***
                                //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                                document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                        PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                                // we create a writer that listens to the document
                                // and directs a PDF-stream to a file
                                writer = PdfWriter.GetInstance(document, fs);

                                imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                                // Attach my override event handler(s)
                                pgEvent = new TransmittalReportEvent();
                                pgEvent.FillEvent(drPay, cropYear, statementDate, resetFlag, rptTitle, paymentDescription, imgLogo);
                                writer.PageEvent = pgEvent;

                                // Open the document
                                document.Open();
                            }
                            else
                            {
                                if (contractNumber != lastContractNumber || payeeNumber != lastPayeeNumber)
                                {
                                    ytdEHBonus       = 0;
                                    ytdEHAmount      = 0;
                                    ytdRHAmount      = 0;
                                    ytdDeductions    = 0;
                                    ytdNet           = 0;
                                    ytdEHAmountMoved = 0;
                                    ytdRHAmountMoved = 0;

                                    lastContractNumber = contractNumber;
                                    if (payeeNumber != lastPayeeNumber)
                                    {
                                        lastPayeeNumber = payeeNumber;
                                    }
                                    pgEvent.FillEvent(drPay, cropYear, statementDate, resetFlag, rptTitle, paymentDescription, imgLogo);
                                    document.NewPage();
                                }
                            }

                            // =======================================================
                            // Add Payment Detail
                            // =======================================================
                            table = PdfReports.CreateTable(_primaryTableLayout, 1);
                            PdfReports.AddText2Table(table, drPay.GetString(drPay.GetOrdinal("Payment_Description")) + " Payment", labelFont, 8);

                            // Header
                            PdfReports.AddText2Table(table, " ", labelFont);
                            PdfReports.AddText2Table(table, "SLM", labelFont, "center");
                            PdfReports.AddText2Table(table, "% Sugar", labelFont);
                            PdfReports.AddText2Table(table, "% Paid", labelFont);
                            PdfReports.AddText2Table(table, "Price/Ton", labelFont);
                            PdfReports.AddText2Table(table, "Tons", labelFont);
                            PdfReports.AddText2Table(table, "YTD Amount", labelFont);
                            PdfReports.AddText2Table(table, "Current Amount", labelFont);

                            // EH Premium
                            PdfReports.AddText2Table(table, "Early Harvest Premium", labelFont, "left");
                            PdfReports.AddText2Table(table, " ", labelFont);
                            PdfReports.AddText2Table(table, " ", labelFont);
                            PdfReports.AddText2Table(table, " ", labelFont);
                            PdfReports.AddText2Table(table, " ", labelFont);
                            PdfReports.AddText2Table(table, " ", labelFont);

                            if (isCumulative)
                            {
                                ytdEHBonus += drPay.GetDecimal(drPay.GetOrdinal("EH_Bonus"));
                            }
                            else
                            {
                                ytdEHBonus = drPay.GetDecimal(drPay.GetOrdinal("ncYtdEhBonus"));
                            }

                            PdfReports.AddText2Table(table, ytdEHBonus.ToString("$#,##0.00"), normalFont);
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("EH_Bonus")).ToString("$#,##0.00"), normalFont);

                            // Early Harvest
                            actualSugar = drPay.GetDecimal(drPay.GetOrdinal("EH_Sugar"));
                            curSLM      = drPay.GetDecimal(drPay.GetOrdinal("EH_SLM"));
                            pctPaid     = drPay.GetDecimal(drPay.GetOrdinal("Pct_EH_Paid"));

                            PdfReports.AddText2Table(table, "Early Harvest   ", labelFont, "left");

                            if (drPay.GetDecimal(drPay.GetOrdinal("EH_SLM")) != 0)
                            {
                                PdfReports.AddText2Table(table, curSLM.ToString("N4"), normalFont, "center");
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", normalFont, "center");
                            }

                            if (drPay.GetDecimal(drPay.GetOrdinal("EH_Sugar")) != 0)
                            {
                                PdfReports.AddText2Table(table, actualSugar.ToString("N2"), normalFont);
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", normalFont);
                            }

                            if (drPay.GetDecimal(drPay.GetOrdinal("Pct_EH_Paid")) != 0)
                            {
                                PdfReports.AddText2Table(table, pctPaid.ToString("N3"), normalFont);
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", normalFont);
                            }

                            if (drPay.GetDecimal(drPay.GetOrdinal("EH_Price")) != 0)
                            {
                                PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("EH_Price")).ToString("$#,##0.000"), normalFont);
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", normalFont);
                            }

                            if (drPay.GetDecimal(drPay.GetOrdinal("EH_Tons")) != 0 || drPay.GetDecimal(drPay.GetOrdinal("EH_tons_moved")) != 0)
                            {
                                PdfReports.AddText2Table(table, (drPay.GetDecimal(drPay.GetOrdinal("EH_Tons")) - drPay.GetDecimal(drPay.GetOrdinal("EH_tons_moved"))).ToString("N4"), normalFont);
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", normalFont);
                            }

                            if (isCumulative)
                            {
                                ytdEHAmount += drPay.GetDecimal(drPay.GetOrdinal("EH_Gross_Pay")) - drPay.GetDecimal(drPay.GetOrdinal("EH_amt_moved"));
                            }
                            else
                            {
                                ytdEHAmount = drPay.GetDecimal(drPay.GetOrdinal("ncYtdEhGrossPay")) - drPay.GetDecimal(drPay.GetOrdinal("ncYtdEhAmtMoved"));
                            }
                            PdfReports.AddText2Table(table, ytdEHAmount.ToString("$#,##0.00"), normalFont);
                            PdfReports.AddText2Table(table, (drPay.GetDecimal(drPay.GetOrdinal("EH_Gross_Pay")) - drPay.GetDecimal(drPay.GetOrdinal("EH_amt_moved"))).ToString("$#,##0.00"), normalFont);

                            // Regular Harvest
                            actualSugar = drPay.GetDecimal(drPay.GetOrdinal("RH_Sugar"));
                            curSLM      = drPay.GetDecimal(drPay.GetOrdinal("RH_SLM"));
                            pctPaid     = drPay.GetDecimal(drPay.GetOrdinal("Pct_RH_Paid"));

                            PdfReports.AddText2Table(table, "Regular Harvest ", labelFont, "left");
                            PdfReports.AddText2Table(table, curSLM.ToString("N4"), normalFont, "center");
                            PdfReports.AddText2Table(table, actualSugar.ToString("N2"), normalFont);
                            PdfReports.AddText2Table(table, pctPaid.ToString("N3"), normalFont);
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("RH_Price")).ToString("$#,##0.000"), normalFont);
                            PdfReports.AddText2Table(table, (drPay.GetDecimal(drPay.GetOrdinal("RH_Tons"))
                                                             - drPay.GetDecimal(drPay.GetOrdinal("RH_Tons_moved"))).ToString("N4"), normalFont);
                            if (isCumulative)
                            {
                                ytdRHAmount += drPay.GetDecimal(drPay.GetOrdinal("RH_Gross_Pay")) - drPay.GetDecimal(drPay.GetOrdinal("RH_amt_moved"));
                            }
                            else
                            {
                                ytdRHAmount = drPay.GetDecimal(drPay.GetOrdinal("ncYtdRhGrossPay")) - drPay.GetDecimal(drPay.GetOrdinal("ncYtdRhAmtMoved"));
                            }
                            // YTD Amount
                            PdfReports.AddText2Table(table, ytdRHAmount.ToString("$#,##0.00"), normalFont);
                            // Current Amount
                            PdfReports.AddText2Table(table, (drPay.GetDecimal(drPay.GetOrdinal("RH_Gross_Pay")) - drPay.GetDecimal(drPay.GetOrdinal("RH_amt_moved"))).ToString("$#,##0.00"), normalFont);

                            // Reduced Early Harvest
                            PdfReports.AddText2Table(table, "Reduced Early Harvest Excess Beets  ", labelFont, "left", 4);
                            PdfReports.AddText2Table(table, " ", normalFont);
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("EH_tons_moved")).ToString("#,#.0000;(#,#.0000)"), normalFont);

                            if (isCumulative)
                            {
                                ytdEHAmountMoved += drPay.GetDecimal(drPay.GetOrdinal("EH_amt_moved"));
                            }
                            else
                            {
                                ytdEHAmountMoved = drPay.GetDecimal(drPay.GetOrdinal("ncYtdEhAmtMoved"));
                            }
                            PdfReports.AddText2Table(table, ytdEHAmountMoved.ToString("$#,#.00;$(#,#.00)"), normalFont);
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("EH_amt_moved")).ToString("$#,#.00;$(#,#.00)"), normalFont);

                            // Reduced Regular Harvest
                            PdfReports.AddText2Table(table, "Reduced Regular Harvest Excess Beets", labelFont, "left", 4);
                            PdfReports.AddText2Table(table, " ", normalFont);
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("RH_tons_moved")).ToString("#,#.0000;(#,#.0000)"), normalFont);
                            if (isCumulative)
                            {
                                ytdRHAmountMoved += drPay.GetDecimal(drPay.GetOrdinal("RH_amt_moved"));
                            }
                            else
                            {
                                ytdRHAmountMoved = drPay.GetDecimal(drPay.GetOrdinal("ncYtdRhAmtMoved"));
                            }
                            PdfReports.AddText2Table(table, ytdRHAmountMoved.ToString("$#,#.00;$(#,#.00)"), normalFont);
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("RH_amt_moved")).ToString("$#,#.00;$(#,#.00)"), normalFont);

                            PdfReports.AddText2Table(table, " ", normalFont, 8);

                            // Total lines
                            //		YTD Amount
                            PdfReports.AddText2Table(table, " ", normalFont, 4);
                            PdfReports.AddText2Table(table, "Total Gross Amount: ", labelFont, "right", 2);
                            PdfReports.AddText2Table(table, ((ytdEHBonus + ytdEHAmount + ytdRHAmount)
                                                             + ytdEHAmountMoved
                                                             + ytdRHAmountMoved
                                                             //+ drPay.GetDecimal(drPay.GetOrdinal("ncYtdEhAmtMoved"))
                                                             //+ drPay.GetDecimal(drPay.GetOrdinal("ncYtdRhAmtMoved"))
                                                             ).ToString("#,##0.00"), normalFont);

                            //		Current Amount
                            PdfReports.AddText2Table(table, (drPay.GetDecimal(drPay.GetOrdinal("EH_Bonus")) +
                                                             drPay.GetDecimal(drPay.GetOrdinal("EH_Gross_Pay")) +
                                                             drPay.GetDecimal(drPay.GetOrdinal("RH_Gross_Pay")) //+
                                                                                                                //drPay.GetDecimal(drPay.GetOrdinal("EH_amt_moved")) +
                                                                                                                //drPay.GetDecimal(drPay.GetOrdinal("RH_amt_moved"))
                                                             ).ToString("#,##0.00"), normalFont);

                            PdfReports.AddText2Table(table, " ", normalFont, 5);
                            PdfReports.AddText2Table(table, "Deduction Total: ", labelFont, "right");

                            if (isCumulative)
                            {
                                ytdDeductions += drPay.GetDecimal(drPay.GetOrdinal("Deduct_Total"));
                            }
                            else
                            {
                                ytdDeductions = drPay.GetDecimal(drPay.GetOrdinal("ncYtdDeductTotal"));
                            }
                            PdfReports.AddText2Table(table, ytdDeductions.ToString("#,##0.00"), normalFont);
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("Deduct_Total")).ToString("#,##0.00"), normalFont);

                            PdfReports.AddText2Table(table, " ", normalFont, 5);
                            PdfReports.AddText2Table(table, "Net Payment: ", labelFont, "right");

                            decimal currentNet = drPay.GetDecimal(drPay.GetOrdinal("EH_Bonus"))
                                                 + drPay.GetDecimal(drPay.GetOrdinal("EH_Gross_Pay"))
                                                 + drPay.GetDecimal(drPay.GetOrdinal("RH_Gross_Pay"))
                                                 //drPay.GetDecimal(drPay.GetOrdinal("EH_amt_moved"))
                                                 //drPay.GetDecimal(drPay.GetOrdinal("RH_amt_moved"))
                                                 - drPay.GetDecimal(drPay.GetOrdinal("Deduct_Total"));

                            if (isCumulative)
                            {
                                ytdNet += currentNet;
                            }
                            else
                            {
                                ytdNet = drPay.GetDecimal(drPay.GetOrdinal("ncYtdEhBonus"))
                                         + drPay.GetDecimal(drPay.GetOrdinal("ncYtdEhGrossPay"))
                                         + drPay.GetDecimal(drPay.GetOrdinal("ncYtdRhGrossPay"))
                                         //drPay.GetDecimal(drPay.GetOrdinal("ncYtdEhAmtMoved"))
                                         //drPay.GetDecimal(drPay.GetOrdinal("ncYtdRhAmtMoved"))
                                         - drPay.GetDecimal(drPay.GetOrdinal("ncYtdDeductTotal"));
                            }

                            PdfReports.AddText2Table(table, ytdNet.ToString("#,##0.00"), normalFont);
                            PdfReports.AddText2Table(table, currentNet.ToString("#,##0.00"), normalFont);

                            PdfReports.AddText2Table(table, " ", normalFont, 8);
                            PdfReports.AddText2Table(table, " ", normalFont, 6);
                            PdfReports.AddText2Table(table, "Grower Net: ", labelFont, "right");
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("Payment_Amount")).ToString("#,##0.00"), normalFont);

                            PdfReports.AddText2Table(table, " ", normalFont, 6);
                            PdfReports.AddText2Table(table, "Landowner Net: ", labelFont, "right");
                            PdfReports.AddText2Table(table, drPay.GetDecimal(drPay.GetOrdinal("Split_Payment")).ToString("#,##0.00"), normalFont);

                            PdfReports.AddText2Table(table, " ", normalFont, 8);

                            PdfReports.AddTableNoSplit(document, pgEvent, table);

                            if (paymentNumber == drPay.GetInt16(drPay.GetOrdinal("Payment_Number")))
                            {
                                //================================================================
                                // Add Deduction information
                                //================================================================
                                table = PdfReports.CreateTable(_primaryTableLayout, 1);

                                using (SqlDataReader drDed = WSCPayment.GetTransmittalDeduction(conn,
                                                                                                cropYear, contractNumber,
                                                                                                drPay.GetInt16(drPay.GetOrdinal("Payment_Number")), isCumulative)) {
                                    PdfReports.AddText2Table(table, "Deduction", labelFont, 5);
                                    PdfReports.AddText2Table(table, "Payment", labelFont);
                                    PdfReports.AddText2Table(table, "Amount", labelFont);
                                    PdfReports.AddText2Table(table, " ", labelFont);

                                    while (drDed.Read())
                                    {
                                        PdfReports.AddText2Table(table, drDed.GetString(drDed.GetOrdinal("Deduction_Desc")), normalFont, 5);
                                        PdfReports.AddText2Table(table, drDed.GetString(drDed.GetOrdinal("Payment_Description")), normalFont);
                                        PdfReports.AddText2Table(table, drDed.GetDecimal(drDed.GetOrdinal("Amount")).ToString("$#,##0.00"), normalFont);
                                        PdfReports.AddText2Table(table, " ", labelFont);
                                    }
                                    PdfReports.AddText2Table(table, " ", normalFont, 8);

                                    PdfReports.AddTableNoSplit(document, pgEvent, table);
                                }

                                //================================================================
                                // Add Delivery information
                                //================================================================
                                float[] deliveryLayout = new float[] { 110.8F, 110.8F, 55.4F, 110.8F, 55.4F, 55.4F, 55.4F };
                                table = PdfReports.CreateTable(deliveryLayout, 1);

                                List <TransmittalDeliveryItem> deliveryList = WSCPayment.GetTransmittalDelivery(cropYear, contractNumber, paymentNumber, fromDate, toDate);

                                PdfReports.AddText2Table(table, "Delivery Date", labelFont);
                                PdfReports.AddText2Table(table, "First Net Pounds", labelFont);
                                PdfReports.AddText2Table(table, "Tare %", labelFont);
                                PdfReports.AddText2Table(table, "Final Net Lbs", labelFont);
                                PdfReports.AddText2Table(table, "Sugar %", labelFont);
                                PdfReports.AddText2Table(table, "SLM", labelFont);
                                PdfReports.AddText2Table(table, "Loads", labelFont);

                                foreach (TransmittalDeliveryItem deliveryDay in deliveryList)
                                {
                                    PdfReports.AddText2Table(table, deliveryDay.Delivery_Date.ToShortDateString(), normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.First_Net_Pounds.ToString("###,###"), normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.Tare.ToString("N2"), normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.Final_Net_Pounds.ToString("###,###"), normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.Sugar_Content.ToString("N2"), normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.SLM_Pct.ToString("N4"), normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.Loads.ToString(), normalFont);
                                }
                                PdfReports.AddText2Table(table, " ", normalFont, 6);
                                PdfReports.AddTableNoSplit(document, pgEvent, table);
                            }
                        }
                        catch (System.Exception ex) {
                            WSCIEMP.Common.CException wscEx = new WSCIEMP.Common.CException(METHOD_NAME, ex);
                            throw (wscEx);
                        }
                    }
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    document.Close();
                }
                if (drPay != null)
                {
                    if (!drPay.IsClosed)
                    {
                        drPay.Close();
                    }
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 4
0
        private static void ReportBuilderRetain(List <ListStatementPatRetainItem> stateList,
                                                int cropYear, DateTime certificateDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs,
                                                string sigName, string sigTitle, string sigImagePath)
        {
            const string METHOD_NAME = "ReportBuilderRetain: ";

            string SHID               = "";
            string equityCropYear     = "";
            string rptTitle           = "";
            string certificateDateStr = certificateDate.ToString(HEADER_DATE_FORMAT);
            string qualifiedStr       = "";
            float  pdfYPos            = 0;
            float  pdfXPos            = -4;

            Document        document    = null;
            PdfWriter       writer      = null;
            PdfPTable       bottomTable = null;
            ColumnText      ct          = null;
            PdfImportedPage pdfImport   = null;

            CertificateEvent pgEvent = null;

            try {
                if (stateList.Count > 0)
                {
                    qualifiedStr = (stateList[0].Qualified.ToLower() == "qualified" ? "Qualified" : "NonQualified");
                }

                iTextSharp.text.Image imgSignature = PdfReports.GetImage(sigImagePath, 228, 68, iTextSharp.text.Element.ALIGN_LEFT);

                foreach (ListStatementPatRetainItem state in stateList)
                {
                    if (rptTitle.Length == 0)
                    {
                        rptTitle = qualifiedStr.ToUpper() + " UNIT RETAIN NOTICE\n" + "CROP YEAR " + cropYear.ToString();
                    }

                    SHID           = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        // Attach my override event handler(s)
                        pgEvent = new CertificateEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        // ================================================================================================================
                        // FROM PDF -- Pulls a background image out of a pdf and uses it as the under layer! Works BUT NEEDS ADJUSTMENT
                        // ================================================================================================================
                        string    _certBorderPath = sigImagePath.Replace("CertificateSignature.gif", "CertBorders.pdf");
                        PdfReader rdrCertBorder   = new PdfReader(_certBorderPath);
                        pdfImport = writer.GetImportedPage(rdrCertBorder, 1); // import only page 1.
                    }
                    else
                    {
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        document.NewPage();
                    }

                    writer.DirectContentUnder.AddTemplate(pdfImport, pdfXPos, pdfYPos);

                    // =======================================================
                    // Build Report
                    // =======================================================

                    // Fill report Body
                    ct = pgEvent.GetColumnObject();
                    BuildRetainBodyText(cropYear, qualifiedStr, ct);

                    // Add Bottom section -- Date, Amount, SigLine.
                    bottomTable = PdfReports.CreateTable(_bottomRetLayout, 0);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);
                    PdfReports.AddText2Table(bottomTable, "Dated: " + certificateDateStr, _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, "Amount: " + Convert.ToDecimal(state.EquityAmt).ToString("$#,##0.00"), _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);

                    //----------------------------------
                    // Add Signature
                    //----------------------------------
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddImage2Table(bottomTable, imgSignature);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    // add signature info
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigName, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigTitle, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    ct.AddElement(bottomTable);
                    ct.Go(false);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 5
0
        public static void ReportBuilder(SqlDataReader dr, int cropYear, int shid, string busName, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder";
            Document     document    = null;
            PdfWriter    writer      = null;
            PdfPTable    table       = null;

            iTextSharp.text.Image imgLogo = null;
            ContractSummaryEvent  pgEvent = null;

            int resetFlag = 0;

            string rptTitle = "Contract Summary\nCrop Year " + cropYear.ToString();

            Font headerFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font normalFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font labelFont  = FontFactory.GetFont("HELVETICA", 8F, Font.BOLD);

            try {
                while (dr.Read())
                {
                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        pgEvent = new ContractSummaryEvent();
                        pgEvent.FillEvent(busName, shid, resetFlag, rptTitle, imgLogo, _primaryTableLayout);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        //table = PdfReports.CreateTable(_primaryTableLayout, 1);
                        //AddDetailSectionHdr(ref table, labelFont, normalFont);
                    }

                    table = PdfReports.CreateTable(_primaryTableLayout, 1);

                    // =======================================================
                    // Add Delivery information
                    // =======================================================
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractFactory")),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractStation")),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractNo")),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("LandownerName")),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("FinalNetTons")).ToString("#,##0.0000"),
                                             normalFont, "right");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("SugarPct")).ToString("##0.00"),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("TarePct")).ToString("##0.00"),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("TonsPerAcre")).ToString("#,##0.00"),
                                             normalFont, "right");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("SLMPct")).ToString("##0.0000"),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetInt32(dr.GetOrdinal("ExtSugarTon")).ToString("#,##0"),
                                             normalFont, "center");

                    PdfReports.AddTableNoSplit(document, pgEvent, table);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (table == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 6
0
        public static void ReportBuilder(SqlDataReader dr, int cropYear,
                                         int shid, string busName, string deliveryDate, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder";
            Document     document    = null;
            PdfWriter    writer      = null;
            PdfPTable    table       = null;

            iTextSharp.text.Image imgLogo = null;
            DeliveryByDayEvent    pgEvent = null;

            const int RowBlockSize = 4;
            int       rowCount     = 1;
            int       resetFlag    = 0;

            string rptTitle = "Delivery By Day - Summary";

            try {
                while (dr.Read())
                {
                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        pgEvent = new DeliveryByDayEvent();
                        pgEvent.FillEvent(busName, shid, deliveryDate, resetFlag, rptTitle, imgLogo, _detailTableNames, _primaryTableLayout);

                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();
                    }

                    table = PdfReports.CreateTable(_primaryTableLayout, 1);

                    // =======================================================
                    // Add Delivery information
                    // =======================================================
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractFactory")),
                                             _normalFont, "left");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("DeliveryStation")),
                                             _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractNo")),
                                             _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("LandownerName")),
                                             _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("FinalNetTons")).ToString("#,##0.0000"),
                                             _normalFont, "right");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("SugarPct")).ToString("##0.00"),
                                             _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("TarePct")).ToString("##0.00"),
                                             _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("SLMPct")).ToString("##0.0000"),
                                             _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetInt32(dr.GetOrdinal("ExtractableSugarPerTon")).ToString("#,##0"),
                                             _normalFont, "center");

                    // add a blank after every row-block-size for visual breaks.
                    if (rowCount % RowBlockSize == 0)
                    {
                        PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);
                        rowCount = 1;
                    }
                    else
                    {
                        rowCount++;
                    }

                    PdfReports.AddTableNoSplit(document, pgEvent, table);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 7
0
        public static void ReportBuilder(SqlDataReader dr, int cropYear, DateTime letterDate, DateTime deadlineDate, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME       = "ReportBuilder";
            const float  primaryLeading    = 13.5F;
            const float  primaryLeftIndent = 20F;
            string       strLetterDate     = letterDate.ToString("MMMM dd, yyyy");
            string       strDeadlineDate   = deadlineDate.ToString("MMMM dd, yyyy");
            string       LdoBusinessName   = "";
            string       tmpStr            = "";
            string       tmpStr2           = "";

            Document             document = null;
            PdfWriter            writer   = null;
            LandownerLetterEvent pgEvent  = null;
            ColumnText           ct       = null;

            iTextSharp.text.Image imgLogo = null;

            try {
                while (dr.Read())
                {
                    LdoBusinessName = dr["LdoBusinessName"].ToString();
                    string LdoAddressLine1 = dr["LdoAddressLine1"].ToString();
                    string LdoAddressLine2 = dr["LdoAddressLine2"].ToString();
                    string LdoCityStateZip = dr["LdoCityStateZip"].ToString();

                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        // Attach my override event handler(s)
                        pgEvent = new LandownerLetterEvent();
                        pgEvent.FillEvent(imgLogo, strLetterDate, LdoBusinessName, LdoAddressLine1, LdoAddressLine2, LdoCityStateZip);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();
                    }
                    else
                    {
                        pgEvent.FillEvent(imgLogo, strLetterDate, LdoBusinessName, LdoAddressLine1, LdoAddressLine2, LdoCityStateZip);
                        document.NewPage();
                    }

                    ct = pgEvent.GetColumnObject();

                    Paragraph p = new Paragraph(primaryLeading, "Your tenant, " + dr["GroBusinessName"].ToString() +
                                                ", has indicated that the proceeds for sugar beets grown on your land in\n" +
                                                cropYear.ToString() + " are to be split and you will be receiving " + dr.GetDecimal(dr.GetOrdinal("LdoSplitPercent")).ToString("##.0##") +
                                                "% of the proceeds. Since Western Sugar Cooperative no\n" +
                                                "longer requires signatures for the second payees, this letter has been sent for your verification.\n\n", _normalFont);

                    ct.AddElement(p);

                    p = new Paragraph(new Phrase(primaryLeading, "Your check will be made payable as follows:", _normalFont));
                    ct.AddElement(p);
                    p = new Paragraph(primaryLeading, dr["ldoPayeeDescription"].ToString(), _normalFont);
                    p.IndentationLeft = primaryLeftIndent;
                    ct.AddElement(p);

                    p = new Paragraph(primaryLeading, "If you have a lien on the beets, the lien holder’s name should be included above.\n\n" +
                                      "In addition, the following options were selected by your tenant.", _normalFont);
                    ct.AddElement(p);

                    decimal ldoChemPct = dr.GetDecimal(dr.GetOrdinal("LdoChemicalSplitPct"));
                    if (dr.GetBoolean(dr.GetOrdinal("IsSplitChemical")) && ldoChemPct != 0)
                    {
                        tmpStr = ldoChemPct.ToString("##.0##") + "%";
                    }
                    else
                    {
                        tmpStr = "No";
                    }

                    decimal ldoRetainPct = dr.GetDecimal(dr.GetOrdinal("LdoSplitPercent"));
                    if (dr.GetBoolean(dr.GetOrdinal("IsSplitRetain")) && ldoRetainPct != 0)
                    {
                        tmpStr2 = ldoRetainPct.ToString("##.0##") + "% of the";
                    }
                    else
                    {
                        tmpStr2 = "No";
                    }

                    p = new Paragraph(primaryLeading, tmpStr2 + " Unit Retains on this contract will be deducted from your proceeds.\n" +
                                      tmpStr + " seed & chemical receivables charged to this contract will be deducted from your proceeds.", _normalFont);
                    p.IndentationLeft = primaryLeftIndent;
                    ct.AddElement(p);

                    p = new Paragraph(primaryLeading, "If the above information is correct, no response is needed.\n\n", _normalFont);
                    ct.AddElement(p);

                    p = new Paragraph(primaryLeading, "If any of the above information is not correct, please contact your tenant’s agriculturist, " +
                                      dr["AgriculturistName"].ToString() +
                                      " at\n" + WSCIEMP.Common.CodeLib.FormatPhoneNumber2Display(dr["AgriculturistPhone"].ToString()) +
                                      " by " + strDeadlineDate + ", or mail the corrections to:\n\n", _normalFont);
                    ct.AddElement(p);

                    p = new Paragraph(12F, "Western Sugar Cooperative\n" +
                                      "Attn: Marty Smith\n" +
                                      "1221 8th Avenue Unit E\n" +
                                      "Greeley, CO  80631\n\n", _normalFont);
                    p.IndentationLeft = primaryLeftIndent;
                    ct.AddElement(p);

                    p = new Paragraph(primaryLeading, "Sincerely,\n\n" +
                                      "Marty Smith\n" +
                                      "Beet Accounting Manager\n\n" +
                                      "Ref: " + dr["ContractNo"].ToString(), _normalFont);
                    ct.AddElement(p);

                    ct.Go(false);
                }
                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null || String.IsNullOrEmpty(LdoBusinessName))
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(MOD_NAME + METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 8
0
        private static void ReportBuilder(SqlDataReader dr, int cropYear, string logoUrl, System.IO.FileStream fs)
        {
            const string           METHOD_NAME = "rptFieldContracting.ReportBuilder: ";
            string                 rptTitle    = "";
            StringBuilder          sb          = new StringBuilder();
            Document               document    = null;
            PdfWriter              writer      = null;
            PdfPTable              table       = null;
            ContractingReportEvent pgEvent     = null;

            iTextSharp.text.Image imgLogo = null;

            Font titleFont    = FontFactory.GetFont("HELVETICA", 12F, Font.BOLD);
            Font subTitleFont = FontFactory.GetFont("HELVETICA", 9F, Font.NORMAL);
            Font headerFont   = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font normalFont   = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font labelFont    = FontFactory.GetFont("HELVETICA", 8F, Font.BOLD);

            try {
                while (dr.Read())
                {
                    try {
                        if (document == null)
                        {
                            // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                            //  ***  US LETTER: 612 X 792  ***
                            //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                            document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                    PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                            // we create a writer that listens to the document
                            // and directs a PDF-stream to a file
                            writer = PdfWriter.GetInstance(document, fs);

                            imgLogo  = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);
                            rptTitle = cropYear.ToString() + " Shareholder Contracting\nJanuary 15th through March 30th";

                            // Attach my override event handler(s)
                            pgEvent = new ContractingReportEvent();
                            pgEvent.FillEvent(DateTime.Now.ToShortDateString(), 0, rptTitle, imgLogo);
                            writer.PageEvent = pgEvent;

                            // Open the document
                            document.Open();
                        }

                        // ======================================================
                        // Generate a new page.
                        // ======================================================
                        if (table != null)
                        {
                            pgEvent.FillEvent(DateTime.Now.ToShortDateString(), 0, rptTitle, imgLogo);
                            document.NewPage();
                        }

                        // ======================================================
                        // Shareholder Block
                        // ======================================================
                        string  cntNo      = "Contract #: " + dr.GetString(dr.GetOrdinal("cntg_contract_no"));
                        float[] addrLayout = new float[] { 270F, 270F };
                        table = PdfReports.CreateTable(addrLayout, 0);

                        PdfReports.AddText2Table(table, "\nSHID: " + dr.GetString(dr.GetOrdinal("cntg_shid")),
                                                 normalFont, "left");
                        PdfReports.AddText2Table(table, cntNo, normalFont, "right");

                        Paragraph p = PdfReports.GetAddressBlock(dr.GetString(dr.GetOrdinal("cntg_business_name")),
                                                                 dr.GetString(dr.GetOrdinal("cntg_address1")),
                                                                 dr.GetString(dr.GetOrdinal("cntg_address2")),
                                                                 dr.GetString(dr.GetOrdinal("cntg_city")) + ", " +
                                                                 dr.GetString(dr.GetOrdinal("cntg_state")) + " " +
                                                                 dr.GetString(dr.GetOrdinal("cntg_zip")),
                                                                 0F, 15F, iTextSharp.text.Element.ALIGN_LEFT, normalFont);
                        PdfReports.AddText2Table(table, p);

                        string landOwner = "Land Owner: " + dr.GetString(dr.GetOrdinal("cntg_landowner_name"));
                        PdfReports.AddText2Table(table, landOwner, normalFont, "right");

                        // Add a blank line.
                        PdfReports.AddText2Table(table, " ", normalFont, "center", addrLayout.Length);

                        PdfReports.AddTableNoSplit(document, pgEvent, table);

                        // ======================================================
                        // Legal Land Description
                        // ======================================================

                        // ***  ROW 1  ***
                        float[] tmpLayout = new float[] { 13F, 13.5F, 11F, 13.5F, 11F, 13.5F, 11F, 13.5F };
                        table = PdfReports.CreateTable(tmpLayout, 0);

                        PdfReports.AddText2Table(table, "Field Name: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_field_name")), normalFont);

                        PdfReports.AddText2Table(table, "Acres: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetInt32(dr.GetOrdinal("cntg_acres")).ToString(), normalFont);

                        PdfReports.AddText2Table(table, "State: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_lld_state")), normalFont);

                        PdfReports.AddText2Table(table, "County: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_lld_county")), normalFont);

                        // ***  ROW 2  ***
                        PdfReports.AddText2Table(table, "1/4 Quadrant: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_lld_quarter_quadrant")), normalFont);

                        PdfReports.AddText2Table(table, "Quadrant: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_lld_quadrant")), normalFont);

                        PdfReports.AddText2Table(table, "Section: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_lld_section")), normalFont);

                        PdfReports.AddText2Table(table, "Township: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_lld_township")), normalFont);


                        // ***  ROW 3  ***
                        PdfReports.AddText2Table(table, "Range: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_lld_range")), normalFont);

                        PdfReports.AddText2Table(table, "Latitude: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("cntg_latitude")).ToString(), normalFont);

                        PdfReports.AddText2Table(table, "Longitude: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("cntg_longitude")).ToString(), normalFont);

                        PdfReports.AddText2Table(table, "FSA Official: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_fsa_official")), normalFont);


                        // ***  ROW 4  ***
                        PdfReports.AddText2Table(table, "FSA Number: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_fsa_number")), normalFont, 3);

                        PdfReports.AddText2Table(table, "FSA State: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_fsa_state")), normalFont);

                        PdfReports.AddText2Table(table, "FSA County: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_fsa_county")), normalFont);

                        // ***  ROW 5  ***
                        PdfReports.AddText2Table(table, "Farm No: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_farm_number")), normalFont);

                        PdfReports.AddText2Table(table, "Tract No: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_tract_number")), normalFont);

                        PdfReports.AddText2Table(table, "Field No: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_field_number")), normalFont);

                        PdfReports.AddText2Table(table, "1/4 Field: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_quarter_field")), normalFont, 7);


                        // ***  ROW 6  ***
                        PdfReports.AddText2Table(table, "Description", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_description")), normalFont, 7);
                        PdfReports.AddText2Table(table, " ", normalFont, tmpLayout.Length);

                        PdfReports.AddTableNoSplit(document, pgEvent, table);

                        // ======================================================
                        // Field Contracting
                        // ======================================================
                        float[] fcLayout = new float[] { 120.0F, 150.0F, 100.0F, 170.0F };
                        table = PdfReports.CreateTable(fcLayout, 1);
                        table.DefaultCell.PaddingTop          = 3.0F;
                        table.DefaultCell.PaddingBottom       = 0;
                        table.DefaultCell.PaddingLeft         = 0;
                        table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                        table.DefaultCell.VerticalAlignment   = Element.ALIGN_BOTTOM;

                        // Row 1
                        PdfReports.AddText2Table(table, "Land Ownership: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_ownership")).ToString(), normalFont);
                        PdfReports.AddText2Table(table, " ", normalFont, 2);

                        // Row 2
                        PdfReports.AddText2Table(table, "Rotation Length (years): ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_rotation_len")).ToString(), normalFont);
                        PdfReports.AddText2Table(table, "Prior Crop: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_prev_crop_type")).ToString(), normalFont);

                        // Row 3
                        PdfReports.AddText2Table(table, "Years field has had beets: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_beet_years")).ToString(), normalFont);
                        PdfReports.AddText2Table(table, "Tillage: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_tillage")).ToString(), normalFont);

                        // blank
                        PdfReports.AddText2Table(table, " ", normalFont, fcLayout.Length);

                        PdfReports.AddText2Table(table, " ", normalFont);
                        PdfReports.AddText2Table(table, "Pre-Harvest", labelFont, "center");
                        PdfReports.AddText2Table(table, "Post-Harvest", labelFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Rhizomania Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_rhizomania")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_rhizomania")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Aphanomyces Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_aphanomyces")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_aphanomyces")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Curly Top Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_curly_top")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_curlytop")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Fusarium Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_fusarium")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_fusarium")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Rhizoctonia Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_rhizoctonia")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_rhizoctonia")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Nematode Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_nematode")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_nematode")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Cercospora Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_cercospora")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_cercospora")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Root Aphid Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_root_aphid")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_rootaphid")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, "Powdery Mildew Suspect: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_suspect_powdery_mildew")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_powderymildew")).ToString(), normalFont, "center");
                        PdfReports.AddText2Table(table, " ", normalFont);

                        PdfReports.AddText2Table(table, " ", normalFont, 4);
                        PdfReports.AddTableNoSplit(document, pgEvent, table);

                        float[] lld2Layout = new float[] { 67.5F, 67.5F, 55F, 80F, 67.5F, 67.5F, 67.5F, 67.5F };
                        table = PdfReports.CreateTable(lld2Layout, 1);

                        PdfReports.AddText2Table(table, "Irrigation System: ", labelFont, 2);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_irrigation_method")).ToString(), normalFont, "left", 2);
                        PdfReports.AddText2Table(table, " ", labelFont, 4);

                        PdfReports.AddText2Table(table, "Water Source: ", labelFont, 2);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_irrigation_source")).ToString(), normalFont, "left", 2);
                        PdfReports.AddText2Table(table, "Water: ", labelFont);
                        PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("cntg_post_water")).ToString(), normalFont, "left");
                        PdfReports.AddText2Table(table, " ", labelFont, 2);

                        PdfReports.AddTableNoSplit(document, pgEvent, table);
                    }
                    catch (System.Exception ex) {
                        WSCIEMP.Common.CException wscEx = new WSCIEMP.Common.CException(METHOD_NAME, ex);
                        throw (wscEx);
                    }
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "sb is null: " + (sb == null).ToString() + "; " +
                                "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 9
0
        private static void ReportBuilder(int cropYear, string shid, string fromShid, string toShid, string filePath, string logoUrl)
        {
            const string METHOD_NAME = "ReportBuilder";
            Document     document    = null;
            PdfWriter    writer      = null;

            iTextSharp.text.Image imgLogo = null;

            NoticeOfPassthroughEvent pgEvent = null;

            string rptTitle = "NOTICE OF PASSTHROUGH OF DOMESTIC PRODUCTION ACTIVITIES\n"
                              + "DEDUCTION FROM THE WESTERN SUGAR COOPERATIVE TO PATRONS  ";

            try {
                List <ListNoticeOfPassthrough> stateList = WSCReportsExec.PassthroughGetBySHID(cropYear, shid, fromShid, toShid);

                if (stateList.Count > 0)
                {
                    using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) {
                        foreach (ListNoticeOfPassthrough state in stateList)
                        {
                            if (document == null)
                            {
                                // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                                //  ***  US LETTER: 612 X 792  ***
                                //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                                document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                        PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                                // we create a writer that listens to the document
                                // and directs a PDF-stream to a file
                                writer = PdfWriter.GetInstance(document, fs);
                                ;
                                imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                                // Attach my override event handler(s)
                                pgEvent = new NoticeOfPassthroughEvent();
                                pgEvent.FillEvent(state, 0, rptTitle, imgLogo);

                                writer.PageEvent = pgEvent;

                                // Open the document
                                document.Open();
                            }
                            else
                            {
                                pgEvent.FillEvent(state, 0, rptTitle, imgLogo);
                                document.NewPage();
                            }

                            // ======================================================
                            // Fill in body of letter
                            // ======================================================
                            PdfPTable table = PdfReports.CreateTable(_bodyLayout, 0);

                            Paragraph para = new Paragraph("The purpose of this notice  is to inform you of your allocable share of the domestic production activities "
                                                           + "deduction (also known as the Section 199 deduction) which The Western Sugar Cooperative (“WSC”) is passing "
                                                           + "through to patrons.  The deduction will be reported on your " + state.TaxYear.ToString() + " Form 1099-PATR.",
                                                           _normalFont);
                            PdfReports.AddText2Table(table, para, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);
                            para = new Paragraph("Your share of the passthrough domestic production activities deduction amount is detailed below:",
                                                 _normalFont);
                            PdfReports.AddText2Table(table, para, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, " ", _normalFont);
                            PdfReports.AddText2Table(table, "Domestic Production Activities Deduction Allocated to Patron", _labelFont);
                            PdfReports.AddText2Table(table, " ", _normalFont);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, " ", _normalFont);
                            para = new Paragraph("SHID: " + state.SHID + "\n"
                                                 + "Member Name: " + state.MemberName + "\n"
                                                 + "Patron’s share of WSC Domestic Production Activities Deduction: $"
                                                 + state.PatronShareOfDeduction.ToString("#,###.00"), _normalFont);
                            PdfReports.AddText2Table(table, para, 2);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, "Explanation", _labelFont, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);
                            para = new Paragraph("Created by Congress, the domestic production activities deduction has been in effect since 2005.  It is designed "
                                                 + "to encourage businesses like WSC to engage in production and/or manufacturing activities in the United States "
                                                 + "and to employ workers in those activities.",
                                                 _normalFont);
                            PdfReports.AddText2Table(table, para, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);
                            para = new Paragraph("Section 199(d)(3) of the Internal Revenue Code contains special rules governing how cooperatives and their "
                                                 + "patrons must compute the deduction.  The Code permits a cooperative to elect to pass through to patrons all or a "
                                                 + "portion of its domestic production activities deduction.  Cooperatives typically pass through to patrons whatever "
                                                 + "part of the deduction they can not themselves use.",
                                                 _normalFont);
                            PdfReports.AddText2Table(table, para, _bodyLayout.Length);

                            string pctToApply = "All";
                            if (state.PercentageToApply != 100)
                            {
                                pctToApply = state.PercentageToApply.ToString("N3");
                                if (pctToApply.EndsWith("000"))
                                {
                                    pctToApply = state.PercentageToApply.ToString("N0");
                                }
                                pctToApply += "%";
                            }
                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);

                            para = new Paragraph("WSC is passing through to its patrons " + pctToApply + " of the domestic production activities deduction it earned "
                                                 + "for the fiscal year ending " + state.FiscalYearEndDate.ToShortDateString() + ".  The passthrough is being allocated to patrons based on sugar "
                                                 + "beet tonnage for Crop Year " + state.CropYear.ToString()
                                                 + " (fiscal year " + state.FiscalYear.ToString() + ").  This notice identifies your share of the "
                                                 + "passthrough. ",
                                                 _normalFont);
                            PdfReports.AddText2Table(table, para, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);
                            para = new Paragraph("A domestic production activities deduction passed through to a patron can generally be used to reduce the "
                                                 + "patron’s taxable income.  In order to claim this passed-through deduction, a patron must include a Form 8903 "
                                                 + "(Domestic Production Activities Deduction) with the patron’s income tax return and report the passthrough "
                                                 + "deduction on the appropriate line of that form.",
                                                 _normalFont);
                            PdfReports.AddText2Table(table, para, _bodyLayout.Length);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);
                            PdfReports.AddText2Table(table, " ", _normalFont);
                            PdfReports.AddText2Table(table, "We strongly advise you consult with your tax advisor to determine how to take\n"
                                                     + "advantage of this potential tax benefit.", _labelFont, "center");
                            PdfReports.AddText2Table(table, " ", _normalFont);

                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);
                            PdfReports.AddText2Table(table, " ", _subFont, _bodyLayout.Length);

                            para = new Paragraph("______________________________\n\n", _subFont);
                            Chunk ck = new Chunk("1", _subFont);
                            ck.SetTextRise(5);
                            para.Add(ck);
                            Chunk chunk = new Chunk(" This notice is issued pursuant to Section 199(d)(3) of the Internal Revenue Code.", _subFont);
                            para.Add(chunk);
                            PdfReports.AddText2Table(table, para, _bodyLayout.Length);

                            PdfReports.AddTableNoSplit(document, pgEvent, table);
                        }

                        // ======================================================
                        // Close document
                        // ======================================================
                        if (document != null)
                        {
                            pgEvent.IsDocumentClosing = true;
                            document.Close();
                            document = null;
                        }
                        if (writer == null)
                        {
                            // Warn that we have no data.
                            WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                            throw (warn);
                        }
                    }
                }
                else
                {
                    // No recs qualified for query.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your query.");
                    throw(warn);
                }
            }
            catch (System.Exception ex) {
                string errMsg = "cropYear: " + cropYear.ToString();
                WSCIEMP.Common.CException wscEx = new WSCIEMP.Common.CException(MOD_NAME + "." + METHOD_NAME + ": " + errMsg, ex);
                throw (wscEx);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 10
0
        public static void ReportBuilder(int cropYear, int contractNumber, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME             = "ReportBuilder";
            Document     document                = null;
            PdfWriter    writer                  = null;
            PdfPTable    table                   = null;
            ContractDeliverySummaryEvent pgEvent = null;

            iTextSharp.text.Image imgLogo = null;

            int contractID = 0;
            int stationNo  = 0;
            int factoryNo  = 0;

            int acresContracted = 0;
            int acresHarvested  = 0;
            int acresLost       = 0;
            int acresPlanted    = 0;

            try {
                if (document == null)
                {
                    // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                    //  ***  US LETTER: 612 X 792  ***  // margins: L, R, T, B
                    //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                    document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                            PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                    // we create a writer that listens to the document
                    // and directs a PDF-stream to a file
                    writer = PdfWriter.GetInstance(document, fs);

                    imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                    // Attach my override event handler(s)
                    pgEvent = new ContractDeliverySummaryEvent();
                    pgEvent.FillEvent(imgLogo, cropYear.ToString());
                    writer.PageEvent = pgEvent;

                    // Open the document
                    document.Open();
                }

                // =======================================================
                // Build Report
                // =======================================================

                int       staExSugar             = 0;
                int       ftyExSugar             = 0;
                decimal   extractableSugarPerTon = 0;
                PdfPTable addrTable = null;

                List <ContractGorwerLandownerItem> stateList = WSCReportsExec.ContractDeliverySummary1(cropYear, contractNumber);

                float[] addrLayout = new float[] { 9.3F, 67.6F, 23.1F };

                addrTable = PdfReports.CreateTable(addrLayout, 0);

                if (stateList.Count > 0)
                {
                    ContractGorwerLandownerItem item = stateList[0];

                    PdfReports.AddText2Table(addrTable, "Contract", _normalFont);
                    PdfReports.AddText2Table(addrTable,
                                             "Grower#: " + item.Gro_Address_Number, _normalFont);
                    PdfReports.AddText2Table(addrTable,
                                             "Landowner#: " + item.Ldo_Address_Number, _normalFont);

                    PdfReports.AddText2Table(addrTable, item.Contract_Number, _normalFont);

                    Paragraph p = PdfReports.GetAddressBlock(item.Grower_Name,
                                                             item.Gro_Address_1,
                                                             item.Gro_Address_2,
                                                             item.Grower_City + ", " +
                                                             item.Grower_State + " " +
                                                             item.Grower_Zip,
                                                             0F, 12F, iTextSharp.text.Element.ALIGN_LEFT, _uspsFont);
                    PdfReports.AddText2Table(addrTable, p);

                    p = PdfReports.GetAddressBlock(item.Landowner_Name,
                                                   item.Ldo_Address_1,
                                                   item.Ldo_Address_2,
                                                   item.Ldo_City + ", " +
                                                   item.Ldo_State + " " +
                                                   item.Ldo_Zip,
                                                   0F, 12F, iTextSharp.text.Element.ALIGN_LEFT, _normalFont);
                    PdfReports.AddText2Table(addrTable, p);

                    PdfReports.AddText2Table(addrTable, " ", _normalFont, 3);
                    PdfReports.AddText2Table(addrTable, " ", _normalFont, 3);

                    PdfReports.AddTableNoSplit(document, pgEvent, addrTable);

                    acresContracted = item.Contract_Acres;
                    acresHarvested  = item.Harvest_Acres;
                    acresPlanted    = item.Planted_Acres;
                    acresLost       = acresPlanted - acresHarvested;

                    contractID = item.cnt_contract_id;
                    stationNo  = Convert.ToInt32(item.Station_Number);
                    factoryNo  = Convert.ToInt32(item.Factory_Number);
                }

                table = PdfReports.CreateTable(_primaryTableLayout, 0);

                List <ContractDeliverySummary2Item> cntDelSumList = WSCReportsExec.ContractDeliverySummary2(contractID);

                if (cntDelSumList.Count > 0)
                {
                    ContractDeliverySummary2Item cntdsItem = cntDelSumList[0];

                    PdfReports.AddText2Table(table, "Contract Tons: " + cntdsItem.ContractTons.ToString("#,###.0000"),
                                             _normalFont, 3);
                    PdfReports.AddText2Table(table, "Contract % Sugar: " + cntdsItem.SugarPct.ToString("0.00") + "%",
                                             _normalFont, 3);
                    PdfReports.AddText2Table(table, "Contract % SLM: " + cntdsItem.SLMPct.ToString("0.0000") + "%",
                                             _normalFont, 3);

                    string tonsPerAcre = null;
                    if (acresHarvested == 0)
                    {
                        tonsPerAcre = String.Format("{0:#,##0.00}", 0);
                    }
                    else
                    {
                        tonsPerAcre = (cntdsItem.ContractTons / acresHarvested).ToString("#,###.00");
                    }
                    PdfReports.AddText2Table(table, "Tons Per Acre: " + tonsPerAcre, _normalFont, 3);

                    PdfReports.AddText2Table(table, " ", _normalFont, 3);

                    extractableSugarPerTon = cntdsItem.ExtractableSugarPerTon;
                    PdfReports.AddText2Table(table, "Pounds Extractable Sugar Per Ton Contract: " +
                                             extractableSugarPerTon.ToString("#,##0"),
                                             _normalFont, 3);
                }


                int factoryExtSugarAvg, stationExtSugarAvg;

                WSCReportsExec.FactoryStationGetExtractSugarAvg(factoryNo, stationNo, cropYear, out factoryExtSugarAvg, out stationExtSugarAvg);

                if (stationExtSugarAvg != 0)
                {
                    PdfReports.AddText2Table(table, "Pounds Extractable Sugar Per Ton Receiving Station: " +
                                             stationExtSugarAvg.ToString("#,##0"), _normalFont, 3);
                }

                if (factoryExtSugarAvg != 0)
                {
                    PdfReports.AddText2Table(table, "Pounds Extractable Sugar Per Ton Factory: " +
                                             factoryExtSugarAvg.ToString("#,##0"), _normalFont, 3);
                }

                string percentOfStation = String.Format("{0:##0.00}", 0);
                string percentOfFactory = String.Format("{0:##0.00}", 0);

                if (stationExtSugarAvg != 0)
                {
                    percentOfStation = String.Format("{0:##0.00}", (extractableSugarPerTon / stationExtSugarAvg) * 100);
                }
                if (factoryExtSugarAvg != 0)
                {
                    percentOfFactory = String.Format("{0:##0.00}", (extractableSugarPerTon / factoryExtSugarAvg) * 100);
                }

                PdfReports.AddText2Table(table, "Percent of Station: " +
                                         percentOfStation + "%", _normalFont, 3);

                PdfReports.AddText2Table(table, "Percent of Factory: " +
                                         percentOfFactory + "%", _normalFont, 3);

                PdfReports.AddText2Table(table, " ", _normalFont, 3);

                PdfReports.AddText2Table(table, "Acres Contracted: " + acresContracted.ToString("#,##0"),
                                         _normalFont, 3);
                PdfReports.AddText2Table(table, "Acres Planted: " + acresPlanted.ToString("#,##0"),
                                         _normalFont, 3);
                PdfReports.AddText2Table(table, "Acres Lost: " + acresLost.ToString("#,##0"),
                                         _normalFont, 3);
                PdfReports.AddText2Table(table, "Acres Harvested: " + acresHarvested.ToString("#,##0"),
                                         _normalFont, 3);

                PdfReports.AddTableNoSplit(document, pgEvent, table);

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (addrTable == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 11
0
        public static void ReportBuilder(int cropYear, string factoryList, string stationList, string contractList, int paymentNumber,
                                         string paymentDescription, string fromDate, string toDate, string statementDate, bool isCumulative, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "rptGroTransmittal.ReportBuilder: ";
            const int    resetFlag   = 0;

            Document  document = null;
            PdfWriter writer   = null;
            PdfPTable table    = null;

            iTextSharp.text.Image imgLogo = null;
            GroTransmittalEvent   pgEvent = null;

            int contractNumber     = 0;
            int lastContractNumber = 0;
            int payeeNumber        = 0;
            int lastPayeeNumber    = 0;

            decimal ytdEHBonus       = 0;
            decimal ytdEHAmount      = 0;
            decimal ytdRHAmount      = 0;
            decimal ytdDeductions    = 0;
            decimal ytdEHAmountMoved = 0;
            decimal ytdRHAmountMoved = 0;
            decimal ytdNet           = 0;
            decimal curSLM           = 0;
            decimal pctPaid          = 0;
            decimal actualSugar      = 0;

            string rptTitle = "Western Sugar Cooperative Payment Transmittal";

            try {
                List <TransmittalPaymentItem> stateList = WSCPayment.GetTransmittalPayment(cropYear, paymentNumber,
                                                                                           factoryList, stationList, contractList, isCumulative);

                int minContractNumber = stateList.Min(c => Convert.ToInt32(c.Contract_Number));
                int maxContractNumber = stateList.Max(c => Convert.ToInt32(c.Contract_Number));

                List <TransDeductionListItem> deductionList = WSCPayment.GetTransmittalDeduction2(ConfigurationManager.ConnectionStrings["BeetConn"].ToString(),
                                                                                                  cropYear, 0, paymentNumber, minContractNumber, maxContractNumber, isCumulative);

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BeetConn"].ToString())) {
                    foreach (TransmittalPaymentItem item in stateList)
                    {
                        try {
                            contractNumber = Convert.ToInt32(item.Contract_Number);
                            payeeNumber    = item.Payee_Number;

                            if (document == null)
                            {
                                lastContractNumber = contractNumber;
                                lastPayeeNumber    = payeeNumber;

                                // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                                //  ***  US LETTER: 612 X 792  ***
                                //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                                document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                        PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                                // we create a writer that listens to the document
                                // and directs a PDF-stream to a file
                                writer = PdfWriter.GetInstance(document, fs);

                                imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                                if (statementDate == null)
                                {
                                    statementDate = WSCPayment.GetPaymentTransmittalDate(paymentNumber, cropYear);
                                }

                                // Attach my override event handler(s)
                                pgEvent = new GroTransmittalEvent();
                                pgEvent.FillEvent(item, cropYear, statementDate, resetFlag, rptTitle, paymentDescription, imgLogo);

                                writer.PageEvent = pgEvent;

                                // Open the document
                                document.Open();
                            }
                            else
                            {
                                if (contractNumber != lastContractNumber || payeeNumber != lastPayeeNumber)
                                {
                                    ytdEHBonus       = 0;
                                    ytdEHAmount      = 0;
                                    ytdRHAmount      = 0;
                                    ytdDeductions    = 0;
                                    ytdNet           = 0;
                                    ytdEHAmountMoved = 0;
                                    ytdRHAmountMoved = 0;

                                    lastContractNumber = contractNumber;
                                    if (payeeNumber != lastPayeeNumber)
                                    {
                                        lastPayeeNumber = payeeNumber;
                                    }
                                    pgEvent.FillEvent(item, cropYear, statementDate, resetFlag, rptTitle, paymentDescription, imgLogo);
                                    document.NewPage();
                                }
                            }

                            // =======================================================
                            // Add Payment Detail
                            // =======================================================
                            table = PdfReports.CreateTable(_primaryTableLayout, 1);
                            PdfReports.AddText2Table(table, item.Payment_Description + " Payment", _labelFont, 8);

                            // Header
                            PdfReports.AddText2Table(table, " ", _labelFont);
                            PdfReports.AddText2Table(table, "SLM", _labelFont, "center");
                            PdfReports.AddText2Table(table, "% Sugar", _labelFont);
                            PdfReports.AddText2Table(table, "% Paid", _labelFont);
                            PdfReports.AddText2Table(table, "Price/Ton", _labelFont);
                            PdfReports.AddText2Table(table, "Tons", _labelFont);
                            PdfReports.AddText2Table(table, "YTD Amount", _labelFont);
                            PdfReports.AddText2Table(table, "Current Amount", _labelFont);

                            // EH Premium
                            PdfReports.AddText2Table(table, "Early Harvest Premium", _labelFont, "left");
                            PdfReports.AddText2Table(table, " ", _labelFont);
                            PdfReports.AddText2Table(table, " ", _labelFont);
                            PdfReports.AddText2Table(table, " ", _labelFont);
                            PdfReports.AddText2Table(table, " ", _labelFont);
                            PdfReports.AddText2Table(table, " ", _labelFont);

                            if (isCumulative)
                            {
                                ytdEHBonus += item.EH_Bonus;
                            }
                            else
                            {
                                ytdEHBonus = item.YtdEhBonus;
                            }

                            PdfReports.AddText2Table(table, ytdEHBonus.ToString("$#,##0.00"), _normalFont);
                            PdfReports.AddText2Table(table, item.EH_Bonus.ToString("$#,##0.00"), _normalFont);

                            // Early Harvest
                            actualSugar = item.EH_Sugar;
                            curSLM      = item.EH_SLM;
                            pctPaid     = item.Pct_EH_Paid;
                            PdfReports.AddText2Table(table, "Early Harvest", _labelFont, "left");

                            if (item.EH_SLM != 0)
                            {
                                PdfReports.AddText2Table(table, curSLM.ToString("N4"), _normalFont, "center");
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", _normalFont, "center");
                            }

                            if (item.EH_Sugar != 0)
                            {
                                PdfReports.AddText2Table(table, actualSugar.ToString("N2"), _normalFont);
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", _normalFont);
                            }

                            if (item.EH_Sugar != 0)
                            {
                                PdfReports.AddText2Table(table, pctPaid.ToString("N3"), _normalFont);
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", _normalFont);
                            }

                            if (item.EH_Price != 0)
                            {
                                PdfReports.AddText2Table(table, item.EH_Price.ToString("$#,##0.000"), _normalFont);
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", _normalFont);
                            }

                            if (item.EH_Tons != 0 || item.EH_Tons_Moved != 0)
                            {
                                PdfReports.AddText2Table(table, (item.EH_Tons - item.EH_Tons_Moved).ToString("N4"), _normalFont);
                            }
                            else
                            {
                                PdfReports.AddText2Table(table, "------", _normalFont);
                            }

                            if (isCumulative)
                            {
                                ytdEHAmount += item.EH_Gross_Pay - item.EH_Amt_Moved;
                            }
                            else
                            {
                                ytdEHAmount = item.YtdEhGrossPay - item.YtdEhAmtMoved;
                            }
                            PdfReports.AddText2Table(table, ytdEHAmount.ToString("$#,##0.00"), _normalFont);
                            PdfReports.AddText2Table(table, (item.EH_Gross_Pay - item.EH_Amt_Moved).ToString("$#,##0.00"), _normalFont);

                            // Regular Harvest
                            actualSugar = item.RH_Sugar;
                            curSLM      = item.RH_SLM;
                            pctPaid     = item.Pct_RH_Paid;

                            PdfReports.AddText2Table(table, "Regular Harvest", _labelFont, "left");
                            PdfReports.AddText2Table(table, curSLM.ToString("N4"), _normalFont, "center");
                            PdfReports.AddText2Table(table, actualSugar.ToString("N2"), _normalFont);
                            PdfReports.AddText2Table(table, pctPaid.ToString("N3"), _normalFont);
                            PdfReports.AddText2Table(table, item.RH_Price.ToString("$#,##0.000"), _normalFont);
                            PdfReports.AddText2Table(table, (item.RH_Tons - item.RH_Tons_Moved).ToString("N4"), _normalFont);
                            if (isCumulative)
                            {
                                ytdRHAmount += item.RH_Gross_Pay - item.RH_Amt_Moved;
                            }
                            else
                            {
                                ytdRHAmount = item.YtdRhGrossPay - item.YtdRhAmtMoved;
                            }
                            PdfReports.AddText2Table(table, ytdRHAmount.ToString("$#,##0.00"), _normalFont);
                            PdfReports.AddText2Table(table, (item.RH_Gross_Pay - item.RH_Amt_Moved).ToString("$#,##0.00"), _normalFont);

                            PdfReports.AddText2Table(table, " ", _normalFont, 8);

                            // Reduced Early Harvest
                            PdfReports.AddText2Table(table, "Reduced Early Harvest Excess Beets", _labelFont, "left", 4);
                            PdfReports.AddText2Table(table, " ", _normalFont);
                            PdfReports.AddText2Table(table, item.EH_Tons_Moved.ToString("#,#.0000;(#,#.0000)"), _normalFont);
                            if (isCumulative)
                            {
                                ytdEHAmountMoved += item.EH_Amt_Moved;
                            }
                            else
                            {
                                ytdEHAmountMoved = item.YtdEhAmtMoved;
                            }
                            PdfReports.AddText2Table(table, ytdEHAmountMoved.ToString("$#,#.00;$(#,#.00)"), _normalFont);
                            PdfReports.AddText2Table(table, item.EH_Amt_Moved.ToString("$#,#.00;$(#,#.00)"), _normalFont);

                            // Reduced Regular Harvest
                            PdfReports.AddText2Table(table, "Reduced Regular Harvest Excess Beets", _labelFont, "left", 4);
                            PdfReports.AddText2Table(table, " ", _normalFont);
                            PdfReports.AddText2Table(table, item.RH_Tons_Moved.ToString("#,#.0000;(#,#.0000)"), _normalFont);
                            if (isCumulative)
                            {
                                ytdRHAmountMoved += item.RH_Amt_Moved;
                            }
                            else
                            {
                                ytdRHAmountMoved = item.YtdRhAmtMoved;
                            }
                            PdfReports.AddText2Table(table, ytdRHAmountMoved.ToString("$#,#.00;$(#,#.00)"), _normalFont);
                            PdfReports.AddText2Table(table, item.RH_Amt_Moved.ToString("$#,#.00;$(#,#.00)"), _normalFont);

                            PdfReports.AddText2Table(table, " ", _normalFont, 8);

                            // Total lines
                            PdfReports.AddText2Table(table, " ", _normalFont, 4);
                            PdfReports.AddText2Table(table, "Total Gross Amount: ", _labelFont, "right", 2);
                            PdfReports.AddText2Table(table, (ytdEHBonus
                                                             + ytdEHAmount
                                                             + ytdRHAmount
                                                             + ytdEHAmountMoved
                                                             + ytdRHAmountMoved).ToString("#,##0.00"), _normalFont);
                            PdfReports.AddText2Table(table, (item.EH_Bonus
                                                             + item.EH_Gross_Pay
                                                             + item.RH_Gross_Pay
                                                             //+ item.EH_Amt_Moved
                                                             //+ item.RH_Amt_Moved
                                                             ).ToString("#,##0.00"), _normalFont);

                            PdfReports.AddText2Table(table, " ", _normalFont, 5);
                            PdfReports.AddText2Table(table, "Deduction Total: ", _labelFont, "right");

                            if (isCumulative)
                            {
                                ytdDeductions += item.Deduct_Total;
                            }
                            else
                            {
                                ytdDeductions = item.YtdDeductTotal;
                            }
                            PdfReports.AddText2Table(table, ytdDeductions.ToString("#,##0.00"), _normalFont);
                            PdfReports.AddText2Table(table, item.Deduct_Total.ToString("#,##0.00"), _normalFont);

                            PdfReports.AddText2Table(table, " ", _normalFont, 5);
                            PdfReports.AddText2Table(table, "Net Payment: ", _labelFont, "right");

                            decimal currentNet = item.EH_Bonus + item.EH_Gross_Pay + item.RH_Gross_Pay - item.Deduct_Total;

                            if (isCumulative)
                            {
                                ytdNet += currentNet;
                            }
                            else
                            {
                                ytdNet = item.YtdEhBonus + item.YtdEhGrossPay + item.YtdRhGrossPay - item.YtdDeductTotal;
                            }

                            PdfReports.AddText2Table(table, ytdNet.ToString("#,##0.00"), _normalFont);
                            PdfReports.AddText2Table(table, currentNet.ToString("#,##0.00"), _normalFont);

                            PdfReports.AddText2Table(table, " ", _normalFont, 8);
                            PdfReports.AddText2Table(table, " ", _normalFont, 6);
                            PdfReports.AddText2Table(table, "Grower Net: ", _labelFont, "right");
                            PdfReports.AddText2Table(table, item.Payment_Amount.ToString("#,##0.00"), _normalFont);

                            PdfReports.AddText2Table(table, " ", _normalFont, 6);
                            PdfReports.AddText2Table(table, "Landowner Net: ", _labelFont, "right");
                            PdfReports.AddText2Table(table, item.Split_Payment.ToString("#,##0.00"), _normalFont);

                            PdfReports.AddText2Table(table, " ", _normalFont, 8);

                            PdfReports.AddTableNoSplit(document, pgEvent, table);

                            if (paymentNumber == item.Payment_Number)
                            {
                                //================================================================
                                // Add Deduction information
                                //================================================================
                                table = PdfReports.CreateTable(_primaryTableLayout, 1);

                                //using (SqlDataReader drDed = WSCPayment.GetTransmittalDeduction(conn,
                                //          cropYear, contractNumber, item.Payment_Number, isCumulative)) {

                                PdfReports.AddText2Table(table, "Deduction", _labelFont, 5);
                                PdfReports.AddText2Table(table, "Payment", _labelFont);
                                PdfReports.AddText2Table(table, "Amount", _labelFont);
                                PdfReports.AddText2Table(table, " ", _labelFont);

                                var contractDeductions = from deduction in deductionList
                                                         where deduction.Contract_Number.ToString() == item.Contract_Number &&
                                                         deduction.Payment_Number <= item.Payment_Number
                                                         orderby deduction.Payment_Number, deduction.Deduction_Number
                                select deduction;

                                foreach (TransDeductionListItem dedItem in contractDeductions)
                                {
                                    if (dedItem.Amount != 0)
                                    {
                                        PdfReports.AddText2Table(table, dedItem.Deduction_Desc, _normalFont, 5);
                                        PdfReports.AddText2Table(table, dedItem.Payment_Description, _normalFont);
                                        PdfReports.AddText2Table(table, dedItem.Amount.ToString("$#,##0.00"), _normalFont);
                                        PdfReports.AddText2Table(table, " ", _labelFont);
                                    }
                                }


                                // OLD CODE - replace by For loop above
                                //while (drDed.Read()) {

                                //    PdfReports.AddText2Table(table, drDed.GetString(drDed.GetOrdinal("Deduction_Desc")), _normalFont, 5);
                                //    PdfReports.AddText2Table(table, drDed.GetString(drDed.GetOrdinal("Payment_Description")), _normalFont);
                                //    PdfReports.AddText2Table(table, drDed.GetDecimal(drDed.GetOrdinal("Amount")).ToString("$#,##0.00"), _normalFont);
                                //    PdfReports.AddText2Table(table, " ", _labelFont);
                                //}
                                PdfReports.AddText2Table(table, " ", _normalFont, 8);

                                PdfReports.AddTableNoSplit(document, pgEvent, table);
                                //}

                                //================================================================
                                // Add Delivery information
                                //================================================================
                                float[] deliveryLayout = new float[] { 110.8F, 110.8F, 55.4F, 110.8F, 55.4F, 55.4F, 55.4F };
                                table = PdfReports.CreateTable(deliveryLayout, 1);

                                List <TransmittalDeliveryItem> deliveryList = WSCPayment.GetTransmittalDelivery(cropYear, contractNumber, paymentNumber, null, null);

                                PdfReports.AddText2Table(table, "Delivery Date", _labelFont);
                                PdfReports.AddText2Table(table, "First Net Pounds", _labelFont);
                                PdfReports.AddText2Table(table, "Tare %", _labelFont);
                                PdfReports.AddText2Table(table, "Final Net Lbs", _labelFont);
                                PdfReports.AddText2Table(table, "Sugar %", _labelFont);
                                PdfReports.AddText2Table(table, "SLM", _labelFont);
                                PdfReports.AddText2Table(table, "Loads", _labelFont);

                                foreach (TransmittalDeliveryItem deliveryDay in deliveryList)
                                {
                                    PdfReports.AddText2Table(table, deliveryDay.Delivery_Date.ToShortDateString(), _normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.First_Net_Pounds.ToString("###,###"), _normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.Tare.ToString("N2"), _normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.Final_Net_Pounds.ToString("###,###"), _normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.Sugar_Content.ToString("N2"), _normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.SLM_Pct.ToString("N4"), _normalFont);
                                    PdfReports.AddText2Table(table, deliveryDay.Loads.ToString(), _normalFont);
                                }
                                PdfReports.AddText2Table(table, " ", _normalFont, 6);
                                PdfReports.AddTableNoSplit(document, pgEvent, table);
                            }
                        }
                        catch (System.Exception ex) {
                            WSCIEMP.Common.CException wscEx = new WSCIEMP.Common.CException(METHOD_NAME, ex);
                            throw (wscEx);
                        }
                    }
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 12
0
        private void ReportBuilder(SqlDataReader dr, int cropYear, DateTime reportDate, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "rptEquityStatement.ReportBuilder: ";
            const int    resetFlag   = 0;

            Document  document = null;
            PdfWriter writer   = null;
            PdfPTable table    = null;

            iTextSharp.text.Image imgLogo = null;
            EQStmtEvent           pgEvent = null;

            _cropYear   = cropYear;
            _reportDate = reportDate;
            int shid             = 0;
            int lastShid         = 0;
            int entityTypeID     = 0;
            int lastEntityTypeID = 0;

            string rptTitle = "Shareholder Equity Statement";

            try {
                while (dr.Read())
                {
                    entityTypeID = dr.GetInt32(dr.GetOrdinal("EntityTypeID"));
                    if (entityTypeID == _entTypeIDAddress)
                    {
                        shid = dr.GetInt32(dr.GetOrdinal("MemberNumber"));
                    }

                    // when you switch entities, close out the last entity when appropriate
                    if (entityTypeID != lastEntityTypeID || entityTypeID == _entTypeIDAddress)
                    {
                        FinishEntityBlock(writer, document, ref table, entityTypeID, lastEntityTypeID, pgEvent);
                    }

                    if (document == null)
                    {
                        lastShid = shid;

                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        pgEvent = new EQStmtEvent();
                        pgEvent.FillEvent(reportDate, shid, " ",
                                          dr.GetString(dr.GetOrdinal("BusinessName")),
                                          dr.GetString(dr.GetOrdinal("Addr1")),
                                          dr.GetString(dr.GetOrdinal("Addr2")),
                                          dr.GetString(dr.GetOrdinal("CityStateZip")),
                                          resetFlag, rptTitle, imgLogo);

                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();
                    }
                    else
                    {
                        if (lastShid != shid)
                        {
                            lastShid         = shid;
                            lastEntityTypeID = entityTypeID;

                            _financingBalance = 0;

                            pgEvent.FillEvent(reportDate, shid, " ",
                                              dr.GetString(dr.GetOrdinal("BusinessName")),
                                              dr.GetString(dr.GetOrdinal("Addr1")),
                                              dr.GetString(dr.GetOrdinal("Addr2")),
                                              dr.GetString(dr.GetOrdinal("CityStateZip")),
                                              resetFlag, rptTitle, imgLogo);

                            document.NewPage();
                        }
                    }

                    //=========================================================
                    // Add Common Stock
                    //=========================================================
                    if (entityTypeID == _entTypeIDCommonStock)
                    {
                        if (lastEntityTypeID != _entTypeIDCommonStock)
                        {
                            lastEntityTypeID = _entTypeIDCommonStock;
                            AddCommonHeader(ref table);
                        }
                        AddCommonData(dr, table);
                    }

                    //=========================================================
                    // Patron Stock
                    //=========================================================
                    if ((entityTypeID == _entTypeIDPatronStock ||
                         entityTypeID == _entTypeIDPatronPermTransfer) &&
                        ((lastEntityTypeID != _entTypeIDPatronStock &&
                          lastEntityTypeID != _entTypeIDPatronPermTransfer)))
                    {
                        AddPatronStockHeader(ref table);
                    }

                    if (entityTypeID == _entTypeIDPatronStock)
                    {
                        if (lastEntityTypeID != _entTypeIDPatronStock)
                        {
                            lastEntityTypeID = _entTypeIDPatronStock;
                            AddPatronStockPurchaseHeader(ref table);
                        }

                        AddPatronStockPurchaseData(dr, table);
                    }

                    if (entityTypeID == _entTypeIDPatronPermTransfer)
                    {
                        if (lastEntityTypeID != _entTypeIDPatronPermTransfer)
                        {
                            lastEntityTypeID = _entTypeIDPatronPermTransfer;
                            AddPatronStockTransferHeader(ref table);
                        }

                        AddPatronStockTransferData(dr, table);
                    }

                    //=========================================================
                    // Add Unit Retains
                    //=========================================================
                    if (entityTypeID == _entTypeIDUnitRetain)
                    {
                        if (lastEntityTypeID != _entTypeIDUnitRetain)
                        {
                            lastEntityTypeID = _entTypeIDUnitRetain;
                            AddUnitRetainHeader(ref table);
                        }

                        AddUnitRetainData(dr, table);
                    }

                    //=========================================================
                    // Add Patronage Refunds
                    //=========================================================
                    if (entityTypeID == _entTypeIDPatronageRefundCert)
                    {
                        if (lastEntityTypeID != _entTypeIDPatronageRefundCert)
                        {
                            lastEntityTypeID = _entTypeIDPatronageRefundCert;
                            AddPatronageRefundHeader(ref table);
                        }

                        AddPatronageRefundData(dr, table);
                    }

                    //=========================================================
                    // Add Equity Financing
                    //=========================================================
                    if (entityTypeID == _entTypeIDEquityFinancing ||
                        entityTypeID == _entTypeIDEquityFinancingPayment)
                    {
                        if (lastEntityTypeID != _entTypeIDEquityFinancing &&
                            lastEntityTypeID != _entTypeIDEquityFinancingPayment)
                        {
                            AddFinancingHeader(ref table);
                        }
                        lastEntityTypeID = entityTypeID;

                        if (entityTypeID == _entTypeIDEquityFinancing)
                        {
                            AddFinancingLoanData(dr, table);
                        }

                        if (entityTypeID == _entTypeIDEquityFinancingPayment)
                        {
                            AddFinancingLoanPaymentData(dr, table);
                        }
                    }
/*   */
                }

                entityTypeID = 0;
                FinishEntityBlock(writer, document, ref table, entityTypeID, lastEntityTypeID, pgEvent);

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (dr != null)
                {
                    if (!dr.IsClosed)
                    {
                        dr.Close();
                    }
                }
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 13
0
        private static void ReportBuilder(List <SHPaySumListItem> stateList, int cropYear, string statementDate, string shid,
                                          string fromShid, string toShid, int paymentDescID, bool isCumulative, string rptFooter, string logoUrl, FileStream fs)
        {
            const string        METHOD_NAME = "rptPaymentSummary.ReportBuilder: ";
            Document            document    = null;
            PdfWriter           writer      = null;
            PdfPTable           table       = null;
            PaymentSummaryEvent pgEvent     = null;

            iTextSharp.text.Image imgLogo = null;

            decimal totalTons         = 0;
            decimal totalEHPrem       = 0;
            decimal totalGross        = 0;
            decimal totalDeductions   = 0;
            decimal totalNet          = 0;
            decimal totalGrowerNet    = 0;
            decimal totalLandownerNet = 0;
            decimal checkAmount       = 0;
            int     resetFlag         = 0;
            int     checkSequence     = 0;
            int     payeeNumber       = 0;

            string rptTitle = "Western Sugar Cooperative Payment Summary";

            Font headerFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font normalFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font labelFont  = FontFactory.GetFont("HELVETICA", 8F, Font.BOLD);

            try {
                int firstContractNumber = stateList.Min(c => c.i_ContractNumber);
                int lastContractNumber  = stateList.Max(c => c.i_ContractNumber);

                List <TransDeductionListItem> deductionList = WSCPayment.GetTransmittalDeduction2(ConfigurationManager.ConnectionStrings["BeetConn"].ToString(),
                                                                                                  cropYear, paymentDescID, 0, firstContractNumber, lastContractNumber, isCumulative);

                foreach (SHPaySumListItem item in stateList)
                {
                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        checkSequence = item.i_CheckSequence;
                        pgEvent       = new PaymentSummaryEvent();
                        pgEvent.FillEvent(item, cropYear, statementDate, resetFlag, rptTitle, imgLogo);

                        writer.PageEvent          = pgEvent;
                        pgEvent.HeaderNameList    = _detailSectionHdrNames;
                        pgEvent.HeaderTableLayout = _primaryTableLayout;

                        // Open the document
                        document.Open();
                        pgEvent.HeaderTableLayout = null;

                        table       = PdfReports.CreateTable(_primaryTableLayout, 1);
                        checkAmount = item.d_checkAmount;
                        payeeNumber = item.i_Payee_Number;
                    }
                    else
                    {
                        if (checkSequence != item.i_CheckSequence)
                        {
                            AddTotals(ref writer, ref document, ref table, labelFont, normalFont, totalTons,
                                      totalEHPrem, totalGross, totalDeductions, totalNet, checkAmount,
                                      payeeNumber, totalGrowerNet, totalLandownerNet, pgEvent);
                            AddFooter(ref writer, ref document, normalFont, rptFooter, pgEvent);

                            // Clear totals values
                            totalTons         = 0;
                            totalEHPrem       = 0;
                            totalGross        = 0;
                            totalDeductions   = 0;
                            totalNet          = 0;
                            totalGrowerNet    = 0;
                            totalLandownerNet = 0;

                            checkSequence = item.i_CheckSequence;

                            // NEW CHECK
                            pgEvent.FillEvent(item, cropYear, statementDate, resetFlag, rptTitle, imgLogo);
                            pgEvent.HeaderTableLayout = _primaryTableLayout;

                            document.NewPage();
                            pgEvent.HeaderTableLayout = null;

                            table       = PdfReports.CreateTable(_primaryTableLayout, 1);
                            checkAmount = item.d_checkAmount;
                            payeeNumber = item.i_Payee_Number;

                            //AddDetailSectionHdr(ref table, labelFont, normalFont);
                        }
                    }

                    // =======================================================
                    // Contract Number Line
                    // =======================================================
                    PdfReports.AddText2Table(table, "Contract", labelFont, "left");
                    PdfReports.AddText2Table(table, item.i_ContractNumber.ToString(), labelFont, "center");
                    PdfReports.AddText2Table(table, " ", normalFont);
                    PdfReports.AddText2Table(table, item.d_Avg_SLM.ToString("N4"), normalFont, "right");

                    PdfReports.AddText2Table(table, " ", normalFont, 3);
                    PdfReports.AddText2Table(table, item.d_EH_Bonus.ToString("N2"), normalFont, "right", 2);
                    totalEHPrem += item.d_EH_Bonus;
                    PdfReports.AddText2Table(table, " ", normalFont, 4);

                    // =======================================================
                    // Station Name Line
                    // =======================================================
                    PdfReports.AddText2Table(table, "Station", normalFont);
                    PdfReports.AddText2Table(table, item.s_Station_Name, normalFont, "center");
                    PdfReports.AddText2Table(table, "EH", normalFont, "center");
                    PdfReports.AddText2Table(table, item.d_EH_SLM.ToString("N4"), normalFont, "right");
                    PdfReports.AddText2Table(table, item.d_EH_Sugar.ToString("N2"), normalFont, "right");
                    PdfReports.AddText2Table(table, item.d_EH_Paid.ToString("N3"), normalFont, "right");
                    PdfReports.AddText2Table(table, item.d_EH_Price.ToString("N3"), normalFont, "right");

                    PdfReports.AddText2Table(table, (item.d_EH_Tons - item.d_EH_tons_moved).ToString("N4"), normalFont, "right");
                    totalTons += item.d_EH_Tons;

                    PdfReports.AddText2Table(table, " ", normalFont);

                    PdfReports.AddText2Table(table, (item.d_EH_Gross_Pay - item.d_EH_amt_moved).ToString("N2"), normalFont, "right");
                    totalGross += item.d_EH_Gross_Pay;

                    PdfReports.AddText2Table(table, " ", normalFont, 3);

                    // =======================================================
                    // Landowner Name Line
                    // =======================================================
                    PdfReports.AddText2Table(table, "LO", normalFont);
                    PdfReports.AddText2Table(table, item.s_LOName, normalFont, "center");
                    PdfReports.AddText2Table(table, "RH", normalFont, "center");

                    PdfReports.AddText2Table(table, item.d_RH_SLM.ToString("N4"), normalFont, "right");
                    PdfReports.AddText2Table(table, item.d_RH_Sugar.ToString("N2"), normalFont, "right");
                    PdfReports.AddText2Table(table, item.d_RH_Paid.ToString("N3"), normalFont, "right");
                    PdfReports.AddText2Table(table, item.d_RH_Price.ToString("N3"), normalFont, "right");

                    PdfReports.AddText2Table(table, (item.d_RH_Tons - item.d_RH_tons_moved).ToString("N4"), normalFont, "right");
                    totalTons += item.d_RH_Tons;

                    PdfReports.AddText2Table(table, " ", normalFont);

                    PdfReports.AddText2Table(table, (item.d_RH_Gross_Pay - item.d_RH_amt_moved).ToString("N2"), normalFont, "right");
                    totalGross += item.d_RH_Gross_Pay;

                    PdfReports.AddText2Table(table, item.d_Deduct_Total.ToString("N2"), normalFont, "right");
                    totalDeductions += item.d_Deduct_Total;

                    PdfReports.AddText2Table(table, (item.d_Total_Net - item.d_EH_amt_moved - item.d_RH_amt_moved).ToString("N2"), normalFont, "right");
                    totalNet += item.d_Total_Net;

                    PdfReports.AddText2Table(table, " ", normalFont);

                    // =======================================================
                    // Reduced for Excess Beets
                    // =======================================================
                    // Reduced Early Harvest
                    PdfReports.AddText2Table(table, "Reduced Early Harvest Excess Beets", normalFont, 3);
                    PdfReports.AddText2Table(table, " ", normalFont, "right");
                    PdfReports.AddText2Table(table, " ", normalFont, "right");
                    PdfReports.AddText2Table(table, " ", normalFont, "right");
                    PdfReports.AddText2Table(table, " ", normalFont, "right");

                    PdfReports.AddText2Table(table, item.d_EH_tons_moved.ToString("#,#.0000;(#,#.0000)"), normalFont, "right");
                    //totalTons += item.d_RH_Tons;

                    PdfReports.AddText2Table(table, " ", normalFont);

                    PdfReports.AddText2Table(table, item.d_EH_amt_moved.ToString("#,#.00;(#,#.00)"), normalFont, "right");
                    //totalGross += item.d_RH_Gross_Pay;

                    PdfReports.AddText2Table(table, " ", normalFont, "right");
                    //totalDeductions += item.d_Deduct_Total;

                    PdfReports.AddText2Table(table, item.d_EH_amt_moved.ToString("#,#.00;(#,#.00)"), normalFont, "right");
                    //totalNet += item.d_Total_Net;

                    PdfReports.AddText2Table(table, " ", normalFont);

                    // Reduced Regular Harvest
                    PdfReports.AddText2Table(table, "Reduced Regular Harvest  Excess Beets", normalFont, 3);
                    PdfReports.AddText2Table(table, " ", normalFont, "right");
                    PdfReports.AddText2Table(table, " ", normalFont, "right");
                    PdfReports.AddText2Table(table, " ", normalFont, "right");
                    PdfReports.AddText2Table(table, " ", normalFont, "right");

                    PdfReports.AddText2Table(table, item.d_RH_tons_moved.ToString("#,#.0000;(#,#.0000)"), normalFont, "right");
                    //totalTons += item.d_RH_Tons;

                    PdfReports.AddText2Table(table, " ", normalFont);

                    PdfReports.AddText2Table(table, item.d_RH_amt_moved.ToString("#,#.00;(#,#.00)"), normalFont, "right");
                    //totalGross += item.d_RH_Gross_Pay;

                    PdfReports.AddText2Table(table, " ", normalFont, "right");
                    //totalDeductions += item.d_Deduct_Total;

                    PdfReports.AddText2Table(table, item.d_RH_amt_moved.ToString("#,#.00;(#,#.00)"), normalFont, "right");
                    //totalNet += item.d_Total_Net;

                    PdfReports.AddText2Table(table, " ", normalFont);

                    // =======================================================
                    // Grower / Landowner NET Split
                    // =======================================================
                    PdfReports.AddText2Table(table, " ", normalFont, 9);
                    PdfReports.AddText2Table(table, "Grower Net", labelFont, 2);
                    totalGrowerNet += item.d_groAmount;
                    PdfReports.AddText2Table(table, item.d_groAmount.ToString("N2"), normalFont, "right");
                    PdfReports.AddText2Table(table, " ", normalFont);

                    PdfReports.AddText2Table(table, " ", normalFont, 9);
                    PdfReports.AddText2Table(table, "Landowner Net", labelFont, 2);
                    totalLandownerNet += item.d_ldoAmount;
                    PdfReports.AddText2Table(table, item.d_ldoAmount.ToString("N2"), normalFont, "right");
                    PdfReports.AddText2Table(table, " ", normalFont);

                    // BLANK LINE
                    PdfReports.AddText2Table(table, " ", normalFont, 13);

                    pgEvent.HeaderTableLayout = _primaryTableLayout;
                    PdfReports.AddTableNoSplit(document, pgEvent, table);
                    pgEvent.HeaderTableLayout = null;

                    //================================================================
                    // Add Deduction information
                    //================================================================

                    table = PdfReports.CreateTable(_primaryTableLayout, 1);

                    PdfReports.AddText2Table(table, " ", labelFont, 4);
                    PdfReports.AddText2Table(table, "Deduction", labelFont, "left", 4);
                    PdfReports.AddText2Table(table, "Payment", labelFont, "left", 2);
                    PdfReports.AddText2Table(table, "Amount", labelFont, "center");
                    PdfReports.AddText2Table(table, " ", labelFont, 2);

                    var contractDeductions = from deduction in deductionList
                                             where deduction.Contract_Number == item.i_ContractNumber &&
                                             deduction.Payment_Number <= item.i_PaymentNumber
                                             orderby deduction.Payment_Number, deduction.Deduction_Number
                    select deduction;

                    foreach (TransDeductionListItem dedItem in contractDeductions)
                    {
                        if (dedItem.Amount != 0)
                        {
                            PdfReports.AddText2Table(table, " ", labelFont, 4);
                            PdfReports.AddText2Table(table, dedItem.Deduction_Desc, normalFont, "left", 4);
                            PdfReports.AddText2Table(table, dedItem.Payment_Description, normalFont, "left", 2);
                            PdfReports.AddText2Table(table, dedItem.Amount.ToString("$#,##0.00"), normalFont, "right");
                            PdfReports.AddText2Table(table, " ", labelFont, 2);
                        }
                    }

                    PdfReports.AddText2Table(table, " ", normalFont, 13);
                }

                // BLANK LINE
                PdfReports.AddText2Table(table, " ", normalFont, 13);
                PdfReports.AddTableNoSplit(document, pgEvent, table);

                table = PdfReports.CreateTable(_primaryTableLayout, 1);

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    table = PdfReports.CreateTable(_primaryTableLayout, 1);

                    AddTotals(ref writer, ref document, ref table, labelFont, normalFont, totalTons,
                              totalEHPrem, totalGross, totalDeductions, totalNet, checkAmount,
                              payeeNumber, totalGrowerNet, totalLandownerNet, pgEvent);

                    AddFooter(ref writer, ref document, normalFont, rptFooter, pgEvent);

                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 14
0
        private static void ReportBuilder(int cropYear, ArrayList shidList, string busName, ArrayList growerPerformanceList, ArrayList regionCodeList, ArrayList areaCodeList,
                                          ArrayList regionNameList, ArrayList areaNameList, string logoUrl, string filePath, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder: ";
            const string CharBlank   = " ";
            const string CharAffirm  = "X";

            Document  document = null;
            PdfWriter writer   = null;
            PdfPTable table    = null;
            ShareholderSummaryEvent pgEvent = null;

            iTextSharp.text.Image imgLogo = null;

            int    iShid               = 0;
            string areaCode            = "";
            string regionCode          = "";
            string regionName          = "";
            string areaName            = "";
            int    growerPerformanceID = 0;

            string rptTitle = "Western Sugar Cooperative\nShareholder Summary for " + cropYear.ToString() + " Crop Year";

            string okFertility  = "";
            string okIrrigation = "";
            string okStand      = "";
            string okWeed       = "";
            string okDisease    = "";
            string okVariety    = "";

            string descFertility  = "";
            string descIrrigation = "";
            string descStand      = "";
            string descWeed       = "";
            string descDisease    = "";
            string descVariety    = "";

            // Build the contract information.
            try {
                for (int j = 0; j < shidList.Count; j++)
                {
                    string shid = shidList[j].ToString();
                    iShid = Convert.ToInt32(shid);

                    if (growerPerformanceList.Count == 0)
                    {
                        busName = "";
                        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BeetConn"].ToString())) {
                            using (SqlDataReader dr = WSCField.SharholderSummaryGetAreas(conn, cropYear, iShid)) {
                                while (dr.Read())
                                {
                                    growerPerformanceList.Add(dr["GrowerPerformanceID"].ToString());
                                    regionCodeList.Add(dr["RegionCode"].ToString());
                                    areaCodeList.Add(dr["AreaCode"].ToString());
                                    regionNameList.Add(dr["RegionName"].ToString());
                                    areaNameList.Add(dr["AreaName"].ToString());
                                    if (busName.Length == 0)
                                    {
                                        busName = dr["BusName"].ToString();
                                    }
                                }
                            }
                        }
                    }

                    // ---------------------------------------------------------------------------------------------------------
                    // Given all of the pieces, crop year, shid, growerPerformanceID, region, and area, generate the report
                    // ---------------------------------------------------------------------------------------------------------
                    if (areaCodeList.Count > 0)
                    {
                        for (int i = 0; i < areaCodeList.Count; i++)
                        {
                            growerPerformanceID = Convert.ToInt32(growerPerformanceList[i]);
                            regionCode          = regionCodeList[i].ToString();
                            areaCode            = areaCodeList[i].ToString();
                            regionName          = regionNameList[i].ToString();
                            areaName            = areaNameList[i].ToString();

                            // ------------------------------------------------
                            // Collect the data: Get the report card.
                            // ------------------------------------------------
                            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BeetConn"].ToString())) {
                                using (SqlDataReader dr = WSCField.GrowerAdviceGetBySHID(conn, growerPerformanceID)) {
                                    if (dr.Read())
                                    {
                                        //busName = dr["gadBusinessName"].ToString();
                                        okFertility  = dr["gadGoodFertilityManagement"].ToString();
                                        okIrrigation = dr["gadGoodIrrigationManagement"].ToString();
                                        okStand      = dr["gadGoodStandEstablishment"].ToString();
                                        okWeed       = dr["gadGoodWeedControl"].ToString();
                                        okDisease    = dr["gadGoodDiseaseControl"].ToString();
                                        okVariety    = dr["gadGoodVarietySelection"].ToString();

                                        descFertility  = dr["gadTextFertilityManagement"].ToString();
                                        descIrrigation = dr["gadTextIrrigationManagement"].ToString();
                                        descStand      = dr["gadTextStandEstablishment"].ToString();
                                        descWeed       = dr["gadTextWeedControl"].ToString();
                                        descDisease    = dr["gadTextDiseaseControl"].ToString();
                                        descVariety    = dr["gadTextVarietySelection"].ToString();
                                    }
                                    else
                                    {
                                        //busName = "";
                                        okFertility  = "";
                                        okIrrigation = "";
                                        okStand      = "";
                                        okWeed       = "";
                                        okDisease    = "";
                                        okVariety    = "";

                                        descFertility  = "";
                                        descIrrigation = "";
                                        descStand      = "";
                                        descWeed       = "";
                                        descDisease    = "";
                                        descVariety    = "";
                                    }
                                }
                            }

                            if (document == null)
                            {
                                // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                                //  ***  US LETTER: 612 X 792  ***
                                //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                                document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                        PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                                // we create a writer that listens to the document
                                // and directs a PDF-stream to a file
                                writer = PdfWriter.GetInstance(document, fs);

                                imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                                // Attach my override event handler(s)
                                //busName = dr["Business Name"].ToString();
                                pgEvent = new ShareholderSummaryEvent();
                                pgEvent.FillEvent(cropYear, shid, busName, rptTitle, regionName, areaName, imgLogo);

                                writer.PageEvent = pgEvent;

                                // Open the document
                                document.Open();
                            }
                            else
                            {
                                // everytime thru kick out a new page because we're on a different shid/region/area combination.
                                pgEvent.FillEvent(cropYear, shid, busName, rptTitle, regionName, areaName, imgLogo);
                                document.NewPage();
                            }

                            // -----------------------------------------------------
                            // Create the report card
                            // -----------------------------------------------------
                            table = PdfReports.CreateTable(_adviceTableLayout, 1);

                            Color borderColor   = Color.BLACK;  //new Color(255, 0, 0);
                            float borderWidth   = 1.0F;
                            int   borderTypeAll = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER;
                            float fPadding      = 3;

                            // HEADER
                            iTextSharp.text.pdf.PdfPCell cell = PdfReports.AddText2Cell("Okay", _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                                                        fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell("Opportunity\nfor\nImprovement", _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell("Big Six Growing Practices", _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            /// ----------------------------------------
                            // TBODY
                            /// ----------------------------------------
                            // Fertility
                            cell = PdfReports.AddText2Cell((okFertility == "Y" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell((okFertility == "N" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell("Fertility Management", _labelFont, PdfPCell.ALIGN_LEFT, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            // Irrigation
                            cell = PdfReports.AddText2Cell((okIrrigation == "Y" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell((okIrrigation == "N" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell("Irrigation Water Management", _labelFont, PdfPCell.ALIGN_LEFT, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            // Stand
                            cell = PdfReports.AddText2Cell((okStand == "Y" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell((okStand == "N" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell("Stand Establishment (Harvest Plant Population)", _labelFont, PdfPCell.ALIGN_LEFT, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            // Weed
                            cell = PdfReports.AddText2Cell((okWeed == "Y" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell((okWeed == "N" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell("Weed Control", _labelFont, PdfPCell.ALIGN_LEFT, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            // Disease
                            cell = PdfReports.AddText2Cell((okDisease == "Y" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell((okDisease == "N" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell("Disease & Insect Control", _labelFont, PdfPCell.ALIGN_LEFT, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            // Varitey
                            cell = PdfReports.AddText2Cell((okVariety == "Y" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell((okVariety == "N" ? CharAffirm : CharBlank), _labelFont, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            cell = PdfReports.AddText2Cell("Proper Variety Selection", _labelFont, PdfPCell.ALIGN_LEFT, PdfPCell.ALIGN_BOTTOM,
                                                           fPadding, borderWidth, borderTypeAll, borderColor);
                            table.AddCell(cell);

                            PdfReports.AddText2Table(table, " ", _normalFont, 3);

                            PdfReports.AddTableNoSplit(document, pgEvent, table);

                            // ==========================================================
                            // Recommendations for Improvement.
                            // ==========================================================
                            table = PdfReports.CreateTable(_adviceTableLayout, 1);

                            // Caption
                            iTextSharp.text.Phrase phrase = new iTextSharp.text.Phrase("Recommendations for Improvement", _labelFont);
                            cell         = new iTextSharp.text.pdf.PdfPCell(phrase);
                            cell.Colspan = 3;

                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.VerticalAlignment   = PdfPCell.ALIGN_BOTTOM;
                            cell.Padding             = fPadding;
                            cell.BorderWidth         = borderWidth;
                            cell.Border      = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER | Rectangle.LEFT_BORDER;
                            cell.BorderColor = borderColor;
                            table.AddCell(cell);

                            // Content
                            phrase = new iTextSharp.text.Phrase((descFertility.Length > 0 ? descFertility + "\n\n" : "") +
                                                                (descIrrigation.Length > 0 ? descIrrigation + "\n\n" : "") +
                                                                (descStand.Length > 0 ? descStand + "\n\n" : "") +
                                                                (descWeed.Length > 0 ? descWeed + "\n\n" : "") +
                                                                (descDisease.Length > 0 ? descDisease + "\n\n" : "") +
                                                                (descVariety.Length > 0 ? descVariety + "\n\n" : ""), _normalFont);

                            cell         = new iTextSharp.text.pdf.PdfPCell(phrase);
                            cell.Colspan = 3;

                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.VerticalAlignment   = PdfPCell.ALIGN_BOTTOM;
                            cell.Padding             = fPadding;
                            cell.BorderWidth         = borderWidth;
                            cell.Border      = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER;
                            cell.BorderColor = borderColor;
                            table.AddCell(cell);

                            PdfReports.AddText2Table(table, " ", _normalFont, table.NumberOfColumns);
                            PdfReports.AddText2Table(table, " ", _normalFont, table.NumberOfColumns);

                            PdfReports.AddTableNoSplit(document, pgEvent, table);

                            // ------------------------------------------------
                            // Create the contract dump.
                            // ------------------------------------------------
                            ArrayList cntPerfs;
                            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BeetConn"].ToString())) {
                                cntPerfs = WSCField.ShareholderSummaryContracts(conn, iShid, cropYear, regionCode, areaCode);
                            }

                            // =======================================
                            // HEADER
                            // =======================================
                            table = PdfReports.CreateTable(_contractTableLayout, 0);
                            pgEvent.BuildContractDumpHeader(document, _contractTableLayout);
                            pgEvent.ContractTableLayout = _contractTableLayout;

                            // DATA
                            for (int k = 0; k < cntPerfs.Count; k++)
                            {
                                ContractPerformanceState perf = (ContractPerformanceState)cntPerfs[k];

                                switch (perf.RowType)
                                {
                                case 1:

                                    table = PdfReports.CreateTable(_contractTableLayout, 0);

                                    PdfReports.AddText2Table(table, perf.ContractNumber, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.ContractStation, _normalFont);
                                    PdfReports.AddText2Table(table, perf.FieldDescription, _normalFont);
                                    PdfReports.AddText2Table(table, perf.LandownerName, _normalFont);
                                    PdfReports.AddText2Table(table, perf.HarvestFinalNetTons, _normalFont, "right");
                                    PdfReports.AddText2Table(table, perf.TonsPerAcre, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSugarPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestTarePct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSLMPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestExtractableSugar, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.BeetsPerAcre, _normalFont, "center");

                                    PdfReports.AddTableNoSplit(document, pgEvent, table);

                                    break;

                                case 2:

                                    table = PdfReports.CreateTable(_contractTableLayout, 0);

                                    PdfReports.AddText2Table(table, " ", _normalFont, _contractTableLayout.Length);
                                    PdfReports.AddText2Table(table, " ", _normalFont);
                                    PdfReports.AddText2Table(table, "Overall Average", _labelFont, 3);
                                    PdfReports.AddText2Table(table, perf.HarvestFinalNetTons, _normalFont, "right");
                                    PdfReports.AddText2Table(table, perf.TonsPerAcre, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSugarPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestTarePct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSLMPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestExtractableSugar, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.BeetsPerAcre, _normalFont, "center");

                                    break;

                                case 3:

                                    PdfReports.AddText2Table(table, " ", _normalFont);
                                    PdfReports.AddText2Table(table, "Top 20% Area Average", _labelFont, 4);
                                    PdfReports.AddText2Table(table, perf.TonsPerAcre, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSugarPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestTarePct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSLMPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestExtractableSugar, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.BeetsPerAcre, _normalFont, "center");

                                    break;

                                case 4:

                                    PdfReports.AddText2Table(table, " ", _normalFont);
                                    PdfReports.AddText2Table(table, "Your Rankings", _labelFont, 10);

                                    PdfReports.AddText2Table(table, " ", _normalFont);
                                    PdfReports.AddText2Table(table, areaName, _labelFont, 4);
                                    PdfReports.AddText2Table(table, perf.TonsPerAcre, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSugarPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestTarePct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSLMPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestExtractableSugar, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.BeetsPerAcre, _normalFont, "center");

                                    break;

                                case 5:

                                    PdfReports.AddText2Table(table, " ", _normalFont);
                                    PdfReports.AddText2Table(table, regionName, _labelFont, 4);
                                    PdfReports.AddText2Table(table, perf.TonsPerAcre, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSugarPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestTarePct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestSLMPct, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.HarvestExtractableSugar, _normalFont, "center");
                                    PdfReports.AddText2Table(table, perf.BeetsPerAcre, _normalFont, "center");

                                    PdfReports.AddTableNoSplit(document, pgEvent, table);

                                    break;
                                }
                            }

                            pgEvent.ContractTableLayout = null;
                        }
                    }

                    // --------------------------------------------
                    // --------  reset for next iteration  --------
                    // --------------------------------------------
                    growerPerformanceList.Clear();
                    regionCodeList.Clear();
                    areaCodeList.Clear();
                    regionNameList.Clear();
                    areaNameList.Clear();
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(MOD_NAME + METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 15
0
        private void ReportBuilder(SqlDataReader dr, int cropYear, DateTime reportDate, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder: ";

            int contractNumber = 0;
            int groSHID        = 0;
            int lastGroSHID    = 0;

            Document  document = null;
            PdfWriter writer   = null;
            PdfPTable table    = null;

            iTextSharp.text.Image imgLogo = null;

            ContractPayeeSummaryEvent pgEvent = null;
            string rptTitle = "Western Sugar Cooperative\n" +
                              "Contract Payee Summary\n" +
                              "Crop Year " + cropYear;

            try {
                while (dr.Read())
                {
                    contractNumber = Convert.ToInt32(dr.GetString(dr.GetOrdinal("ContractNumber")));
                    groSHID        = Convert.ToInt32(dr.GetString(dr.GetOrdinal("GroAdrNumber")));
                    if (document == null)
                    {
                        lastGroSHID = groSHID;

                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        pgEvent = new ContractPayeeSummaryEvent();
                        pgEvent.FillEvent(dr, reportDate.ToShortDateString(), 0, rptTitle, imgLogo);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();
                    }
                    else
                    {
                        if (lastGroSHID != groSHID)
                        {
                            lastGroSHID = groSHID;
                            pgEvent.FillEvent(dr, reportDate.ToShortDateString(), 0, rptTitle, imgLogo);

                            document.NewPage();
                        }
                    }

                    // =======================================================
                    // Build Report
                    // =======================================================
                    table = PdfReports.CreateTable(_primaryTableLayout, 0);

                    Phrase    phrase = new Phrase("Contract: ", _labelFont);
                    Paragraph p      = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("ContractNumber")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p);

                    phrase = new Phrase("Grower #: ", _labelFont);
                    p      = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("GroAdrNumber")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p);

                    phrase = new Phrase("Landowner #: ", _labelFont);
                    p      = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("LdoAdrNumber")) + " - " + dr.GetString(dr.GetOrdinal("LandownerName")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p, 3);

                    PdfReports.AddText2Table(table, "Factory", _labelFont);
                    PdfReports.AddText2Table(table, "Station", _labelFont);
                    PdfReports.AddText2Table(table, "Assoc Member", _labelFont);
                    PdfReports.AddText2Table(table, "LO Name on Check", _labelFont);
                    PdfReports.AddText2Table(table, "Pac Dues", _labelFont);

                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("FactoryName")), _normalFont);
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("StationName")), _normalFont);
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("AssocMember")), _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("CashRent")), _normalFont, "center");
                    PdfReports.AddText2Table(table, "$" + dr.GetDecimal(dr.GetOrdinal("PacDues")).ToString("0.00"), _normalFont);

                    // Add Payee information
                    ShowPayeeInformation(table, contractNumber, cropYear, dr.GetBoolean(dr.GetOrdinal("SplitRetain")), dr.GetBoolean(dr.GetOrdinal("SplitChemical")));

                    ShowAcreage(table, dr.GetInt16(dr.GetOrdinal("ContractAcres")), dr.GetInt16(dr.GetOrdinal("PlantedAcres")),
                                dr.GetInt16(dr.GetOrdinal("AcresLost")), dr.GetInt16(dr.GetOrdinal("HarvestAcres")));

                    PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);
                    PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);

                    PdfReports.AddTableNoSplit(document, pgEvent, table);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 16
0
        private static void ReportBuilder(int shid, int cropYear, int calYear, string logoUrl, FileStream fs)
        {
            const string METHOD_NAME          = "rptBeetPaymentBreakdown.ReportBuilder: ";
            Document     document             = null;
            PdfWriter    writer               = null;
            PdfPTable    table                = null;
            BeetPaymentBreakdownEvent pgEvent = null;

            iTextSharp.text.Image imgLogo = null;

            int     curShid  = 0;
            int     lastShid = 0;
            decimal grossAmt = 0;
            decimal netAmt   = 0;

            string rptTitle = "Western Sugar Cooperative Beet Payments by Year";

            Font headerFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font normalFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font labelFont  = FontFactory.GetFont("HELVETICA", 8F, Font.BOLD);

            try {
                List <BeetPaymentListItem> stateList = WSCPayment.RptBeetPayBreakdown(ConfigurationManager.ConnectionStrings["BeetConn"].ToString(),
                                                                                      shid, cropYear, calYear);

                foreach (BeetPaymentListItem item in stateList)
                {
                    curShid = item.SHID;

                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        imgLogo  = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER);
                        lastShid = curShid;
                        grossAmt = 0;
                        netAmt   = 0;

                        // Attach my override event handler(s)
                        pgEvent = new BeetPaymentBreakdownEvent();
                        pgEvent.FillEvent(_primaryTableLayout, _hdrNames, curShid, item.PayeeName, rptTitle, imgLogo);

                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        table = PdfReports.CreateTable(_primaryTableLayout, 1);
                    }

                    if (curShid != lastShid)
                    {
                        // BLANK LINE
                        PdfReports.AddText2Table(table, " ", normalFont, "center", 5);
                        PdfReports.AddText2Table(table, grossAmt.ToString("c2"), labelFont, "right");
                        PdfReports.AddText2Table(table, netAmt.ToString("c2"), labelFont, "right");

                        PdfReports.AddText2Table(table, " ", normalFont, 13);
                        PdfReports.AddTableNoSplit(document, pgEvent, table);

                        lastShid = curShid;
                        grossAmt = 0;
                        netAmt   = 0;
                        pgEvent.FillEvent(_primaryTableLayout, _hdrNames, curShid, item.PayeeName, rptTitle, imgLogo);
                        document.NewPage();

                        table = PdfReports.CreateTable(_primaryTableLayout, 1);
                    }

                    PdfReports.AddText2Table(table, item.CalendarYear.ToString(), normalFont, "center");
                    PdfReports.AddText2Table(table, item.CropYear.ToString(), normalFont, "center");
                    PdfReports.AddText2Table(table, item.PaymentNumber.ToString("N0"), normalFont, "center");
                    PdfReports.AddText2Table(table, item.PaymentDescription, normalFont, "left");
                    PdfReports.AddText2Table(table, item.TransmittalDate.ToString("MM/dd/yyyy"), normalFont, "center");
                    PdfReports.AddText2Table(table, item.GrossDollars.ToString("c2"), normalFont, "right");
                    PdfReports.AddText2Table(table, item.PaymentAmount.ToString("c2"), normalFont, "right");
                    grossAmt += item.GrossDollars;
                    netAmt   += item.PaymentAmount;
                }

                if (document != null)
                {
                    // BLANK LINE
                    PdfReports.AddText2Table(table, " ", normalFont, "center", 5);
                    PdfReports.AddText2Table(table, grossAmt.ToString("c2"), labelFont, "right");
                    PdfReports.AddText2Table(table, netAmt.ToString("c2"), labelFont, "right");

                    PdfReports.AddText2Table(table, " ", normalFont, 13);
                    PdfReports.AddTableNoSplit(document, pgEvent, table);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 17
0
        private static void ReportBuilder(int cropYear, DateTime fromDate, DateTime toDate, string shid, string filePath, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder: ";

            string  lastPayee = "";
            decimal subTotalPayAmt;
            decimal subTotalNinetySixPct;
            decimal subTotalFirstNetTons;
            string  rptTitle = cropYear.ToString() + " Direct Deliveries";

            Document  document    = null;
            PdfWriter writer      = null;
            PdfPTable detailTable = null;
            PdfPTable bodyTable   = null;

            iTextSharp.text.Image        imgLogo = null;
            DirectDeliveryStatementEvent pgEvent = null;

            try {
                List <ListDirectDeliveryStatementItem> stateList = RptDirectDeliveryStatementData(cropYear, fromDate, toDate, shid);

                for (int i = 0; i < stateList.Count; i++)
                {
                    ListDirectDeliveryStatementItem state = stateList[i];

                    if (document == null)
                    {
                        lastPayee = state.Payee;
                        CalcSubTotals(stateList, i, out subTotalFirstNetTons, out subTotalNinetySixPct, out subTotalPayAmt);

                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        imgLogo = PdfReports.GetImage(logoUrl, 77, 45, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        pgEvent = new DirectDeliveryStatementEvent();
                        pgEvent.FillEvent(state.Shid, state.BusinessName, state.AddrLine1, state.AddrLine2, state.CSZ, subTotalPayAmt, 0, rptTitle, imgLogo);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        bodyTable   = PdfReports.CreateTable(_bodyTableLayout, 0);
                        detailTable = PdfReports.CreateTable(_detailTableLayout, 0);

                        AddBodyText(bodyTable, cropYear, fromDate.ToString(HEADER_DATE_FORMAT), toDate.ToString(HEADER_DATE_FORMAT), state.Payee);
                        AddDetailTable(detailTable, stateList, i, subTotalFirstNetTons, subTotalNinetySixPct, subTotalPayAmt);

                        PdfReports.AddTableNoSplit(document, pgEvent, bodyTable);
                        PdfReports.AddTableNoSplit(document, pgEvent, detailTable);
                    }


                    if (lastPayee != state.Payee)
                    {
                        //-------------------------------------------------------------------------------------
                        // When you change members, kick out the page and move on to the next member,
                        // and reset flags.
                        //-------------------------------------------------------------------------------------

                        lastPayee = state.Payee;

                        bodyTable   = PdfReports.CreateTable(_bodyTableLayout, 0);
                        detailTable = PdfReports.CreateTable(_detailTableLayout, 0);

                        CalcSubTotals(stateList, i, out subTotalFirstNetTons, out subTotalNinetySixPct, out subTotalPayAmt);

                        pgEvent.FillEvent(state.Shid, state.BusinessName, state.AddrLine1, state.AddrLine2, state.CSZ, subTotalPayAmt, 0, rptTitle, imgLogo);
                        document.NewPage();

                        AddBodyText(bodyTable, cropYear, fromDate.ToString(HEADER_DATE_FORMAT), toDate.ToString(HEADER_DATE_FORMAT), state.Payee);
                        AddDetailTable(detailTable, stateList, i, subTotalFirstNetTons, subTotalNinetySixPct, subTotalPayAmt);

                        PdfReports.AddTableNoSplit(document, pgEvent, bodyTable);
                        PdfReports.AddTableNoSplit(document, pgEvent, detailTable);
                    }
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }