Calculate SubTotal of a detail record with debtor's markup rate.
Add using Directive
using BCE.Data;
using BCE.AutoCount.Data;
using BCE.Parser;
publicvoidCalcSubTotal(BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCalcSubTotalEventArgse){//Instead of passing DebtorRecord, or DBSetting & DebtorCode as parameters,//Create a delegate to get DebtorRecordFunc<DebtorRecord>debtorRecord=()=>CommonRecordUtils.GetDebtor(e.DBSetting,e.MasterRecord.DebtorCode);decimalprice=e.CurrentDetailRecord.UnitPrice;decimalqty=e.CurrentDetailRecord.Qty;stringdisc=e.CurrentDetailRecord.Discount;decimal?subTotal=CalculateDebtorMarkup(debtorRecord,price,qty,disc);if(subTotal.HasValue){//Set the subtotal with new valuee.CurrentDetailRecord.SubTotal=subTotal.Value;//Avoid system to recalculate by telling system, it has been handled.e.Handled=true;}else{//default e.Handled is false}}privatedecimal?CalculateDebtorMarkup(Func<DebtorRecord>debtorRecord,decimalprice,decimalqty,stringdisc){DebtorRecorddebtor=debtorRecord();if(debtor==null)returnnull;decimalmarkup=BCE.Data.Convert.ToDecimal(debtor.UDF["MarkupPercent"]);returnMarkupDiscountParser.CalcDiscount(price*(1+markup/100)*qty,disc);}