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(); } } }
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(); } } }