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();
                }
            }
        }
Esempio n. 2
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();
                }
            }
        }