From AutoCount Resource Center
Revision as of 06:16, 2 October 2017 by (talk) (Created page with "{{NavigateDeveloper|collapsed}} __notoc__ ==CalcSubTotal== '''CalcSubTotal''' is triggered when system is about to calculate the sub total of a detail row. ===Usage=== *Ove...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Go to menu

IconAC81.png Go to top
ProgrammerGo.jpg Resources For AutoCount Software Developers


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