CalcSubTotal: Difference between revisions
Content added Content deleted
No edit summary |
mNo edit summary |
||
Line 58: | Line 58: | ||
[[Category: |
[[Category:Programmer]] |
||
[[Category:Script Event]] |
[[Category:Script Event]] |
Revision as of 15:41, 27 November 2017
Go to top
|
Resources For AutoCount Software Developers
|
CalcSubTotal
CalcSubTotal is triggered when system is about to calculate the sub total of a detail row.
Usage
- Overwrite the line total (SubTotal)
- Cancel system default calculation of line total (SubTotal)
CalcSubTotal event in Sales Invoice
public void CalcSubTotal(BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCalcSubTotalEventArgs e)
Example
- Calculate SubTotal of a detail record with debtor's markup rate.
- Add using Directive
using BCE.Data; using BCE.AutoCount.Data; using BCE.Parser;
public void CalcSubTotal(BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCalcSubTotalEventArgs e)
{
//Instead of passing DebtorRecord, or DBSetting & DebtorCode as parameters,
//Create a delegate to get DebtorRecord
Func<DebtorRecord> debtorRecord = () =>
CommonRecordUtils.GetDebtor(e.DBSetting, e.MasterRecord.DebtorCode);
decimal price = e.CurrentDetailRecord.UnitPrice;
decimal qty = e.CurrentDetailRecord.Qty;
string disc = e.CurrentDetailRecord.Discount;
decimal? subTotal = CalculateDebtorMarkup(debtorRecord, price, qty, disc);
if (subTotal.HasValue)
{
//Set the subtotal with new value
e.CurrentDetailRecord.SubTotal = subTotal.Value;
//Avoid system to recalculate by telling system, it has been handled.
e.Handled = true;
}
else
{
//default e.Handled is false
}
}
private decimal? CalculateDebtorMarkup(Func<DebtorRecord> debtorRecord,
decimal price, decimal qty, string disc)
{
DebtorRecord debtor = debtorRecord();
if (debtor == null)
return null;
decimal markup = BCE.Data.Convert.ToDecimal(debtor.UDF["MarkupPercent"]);
return MarkupDiscountParser.CalcDiscount(price * (1 + markup / 100) * qty, disc);
}