Report Script: Filter Overdue Letter with specific age that is due: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 85: Line 85:
</syntaxhighlight>
</syntaxhighlight>


<br/>


===Add/Replace a label to show the letter overdue message with ''Total Amount Due''===
[[File:ReportScript.OverdueLetter2.png|link=]]
<br/><br/>
#Add/Replace a label, and amend the (Name) to "xrLabelOverdueTitle"
#Type in the text "Our record shows that an amount of {0} is now overdue. A list of overdue invoices is shown as below:"
#*{0} is a parameter that will be replaced with the value of '''Total Amount Due''' in string.Format(...).
#In Property Grid, Click [+] button of Scripts to reveal the events
#Find Before Print, and click into the text box on the right
#Then click the arrow button, and click (New)
#:Report Designer will switch to Scripts editor,
#:and '''xrLabelOverdueTitle_BeforePrint''' event is created.

===Calculate Total Overdue Amount after records in detail table is updated===
This sample code, a method '''Compute(...)''' of DataTable object is used to calculate the sum of AmountDue.<br/>
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
private void xrLabelOverdueTitle_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
object oAccNo = GetCurrentColumnValue("AccNo");
if (oAccNo == null) return;

//Temporary store the original text of this label
string orgText = (sender as XRLabel).Text;

//Calculate the current debtor total overdue amount
object oTotalAmtDue = (__report.DataSource as DataSet).Tables["Detail"]
.Compute("SUM(AmountDue)", string.Format("DebtorCode='{0}'", oAccNo.ToString()));
decimal totalAmtDue = oTotalAmtDue == null ? 0 : BCE.Data.Convert.ToDecimal(oTotalAmtDue);

//Assign 'total amount due' to this label, while format the decimal digit with currency formatting
(sender as XRLabel).Text = string.Format(orgText, __report.DecimalSetting.FormatCurrency(totalAmtDue));
}
</syntaxhighlight>
</syntaxhighlight>