Create Sale Invoice and assign bonus point programmatically

When Bonus Point is calculated from external system, programmer can assign the bonus point earning to each item.

Highlighted lines are the assignment of bonus point to each item.

The total earning point of this document must be the sum of dtl.BonusPoint.

publicvoidNewInvoiceWithBonusPoint(AutoCount.Authentication.UserSessionuserSession){AutoCount.Invoicing.Sales.Invoice.InvoiceCommandcmd=AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(userSession,userSession.DBSetting);AutoCount.Invoicing.Sales.Invoice.Invoicedoc=cmd.AddNew();AutoCount.Invoicing.Sales.Invoice.InvoiceDetaildtl;doc.RecalculateMemberPoint=true;doc.DebtorCode="300-A001";doc.Description="Test API Bonus Point";doc.MemberNo="M-0001";dtl=doc.AddDetail();dtl.ItemCode="FG00001";dtl.Qty=1;dtl.UnitPrice=100;//Manual set bonus point earndtl.BonusPoint=50;dtl=doc.AddDetail();dtl.ItemCode="FG00001";dtl.Description="Test Item";dtl.Qty=1;dtl.UnitPrice=200;dtl.BonusPoint=20;//without ItemCode testdtl=doc.AddDetail();dtl.Description="Test Item";dtl.SubTotal=200;dtl.BonusPoint=20;//Call CalcNetTotal to update document total Bonus Point.//If CalcNetTotal() method is not called, total Bonus Point result can be incorrect.doc.CalcNetTotal();try{doc.Save();//Log successAutoCount.AppMessage.ShowMessage($"Invoice {doc.DocNo} is created.");}catch(AutoCount.AppExceptionex){//Log failureAutoCount.AppMessage.ShowMessage($"Fail to create new Invoice.\n{ex.Message}");}}