publicvoidNewUpdateSalesOrderWithItemPackage(stringdocNo,UserSessionuserSession){AutoCount.Invoicing.Sales.SalesOrder.SalesOrderCommandcmd=AutoCount.Invoicing.Sales.SalesOrder.SalesOrderCommand.Create(userSession,userSession.DBSetting);AutoCount.Invoicing.Sales.SalesOrder.SalesOrderdoc=cmd.Edit(docNo);AutoCount.Invoicing.Sales.SalesOrder.SalesOrderDetaildtl=null;if(doc==null){doc=cmd.AddNew();}else{//Remove all details of existing documentdoc.ClearDetails();}doc.DebtorCode="300-A001";doc.DocNo="<<New>>";//use running numberingdoc.DocDate=DateTime.Today.Date;doc.Description="Description of this document";dtl=doc.AddDetail();dtl.ItemCode="ItemA";dtl.Description="Description of this item";dtl.UOM="UNIT";dtl.Qty=10;dtl.UnitPrice=20.89M;dtl.Discount="3%";//Do not update unit price of the item package//Should always update the unit price at package detaildtl=doc.AddPackage("PackA");dtl.Qty=1;doc.Save();}
Add item package with custom package detail
publicvoidNewUpdateSalesOrderWithItemPackageDetail(stringdocNo,UserSessionuserSession){AutoCount.Invoicing.Sales.SalesOrder.SalesOrderCommandcmd=AutoCount.Invoicing.Sales.SalesOrder.SalesOrderCommand.Create(userSession,userSession.DBSetting);AutoCount.Invoicing.Sales.SalesOrder.SalesOrderdoc=cmd.Edit(docNo);AutoCount.Invoicing.Sales.SalesOrder.SalesOrderDetaildtl=null;AutoCount.Invoicing.InvoicingPackageDetailRecordpackageDtl=null;if(doc==null){doc=cmd.AddNew();}else{//Remove all details of existing documentdoc.ClearDetails();}doc.DebtorCode="300-A001";doc.DocNo="<<New>>";//use running numberingdoc.DocDate=DateTime.Today.Date;doc.Description="Description of this document";dtl=doc.AddDetail();dtl.ItemCode="ItemA";dtl.Description="Description of this item";dtl.UOM="UNIT";dtl.Qty=10;dtl.UnitPrice=20.89M;dtl.Discount="3%";//Do not update the dtl.UnitPrice of ItemPackage//ItemPackage unit price is updated from the total of package detaildtl=doc.AddPackage("PackA");dtl.Qty=1;//clear the existing detail in the package before adding subitemsdoc.DeletePackageDetail(dtl.DtlKey);packageDtl=doc.AddPackageDetail(dtl.DtlKey);packageDtl.ItemCode="ItemA";packageDtl.Description="Description of ItemA";packageDtl.Qty=2;packageDtl.UnitPrice=10.60M;packageDtl=doc.AddPackageDetail(dtl.DtlKey);packageDtl.ItemCode="ItemB";packageDtl.Description="Description of ItemB";packageDtl.Qty=1;packageDtl.UnitPrice=30.90M;packageDtl=doc.AddPackageDetail(dtl.DtlKey);packageDtl.ItemCode="ItemC";packageDtl.Description="Description of ItemC";packageDtl.Qty=1;packageDtl.UnitPrice=100M;doc.Save();}