Open main menu


Revision as of 08:11, 17 January 2018 by DanielY (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


CalcSubTotal is triggered when system is about to calculate the sub total of a detail row.


  • 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)


  • 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;
        //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); 

Go to menu