以下 总结了三种情况下的以装箱单过发票
1.简单的对某个销售订单开票
public static str60 shipSalesOrder(str salesId) { SalesFormLetter clsSalesFormLetter; SalesTable salesTable; str ret=''; System.Exception err; ; try { //Get SalesTable tSalesTable = SalesTable::find(salesId); //Packing Slip update clsSalesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip); clsSalesFormLetter.update(salesTable,systemDateGet(),SalesUpdate::All,AccountOrder::None,NoYes::No,NoYes::No); clsSalesFormLetter.checkCloseDialog(clsSalesFormLetter); //Invoice update clsSalesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice); clsSalesFormLetter.update(salesTable,systemDateGet(),SalesUpdate::PackingSlip,AccountOrder::None,NoYes::No,NoYes::No); clsSalesFormLetter= null; ret = 'OK'; return ret; } catch (Exception::CLRError) { err = CLRInterop::getLastException(); ret = err.ToString(); return ret; } }
2.合并装箱单批量开票(系统原有功能),可以根据某些条件筛选对装箱单开票
static void RB_PostSalesInvoice(Args _args) { SalesTable salesTable; SalesFormLetter salesFormLetter; Query query; QueryRun queryRun; QueryBuildDataSource qbds; salesTable = SalesTable::find('CNMF_00001'); query = new Query(QueryStr(SalesUpdatePackingSlip)); qbds = query.dataSourceTable(tableNum(SalesLine)); // Build query range to find those lines which needs to be posted. qbds.addRange(fieldNum(SalesLine, SalesId)).value('CNMF_00001'); qbds.addRange(fieldNum(SalesLine, SalesStatus)).value(queryValue(SalesStatus::Backorder)); qbds.addRange(fieldNum(SalesLine, itemId)).value('D0001'); queryRun = new queryRun(query); salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice); salesFormLetter.chooseLinesQuery(queryRun); salesFormLetter.update(salesTable); }
3. 多选装箱单以当前交货量的方法批量开票
class PostInvoiceBySettle { public static void main(Args _args) { Test_SalesParmLine salesParmLine, salesParmLineUpdate, salesParmLineTmp; Test_SalesSettleTable salesSettleTable; FormDataSource formDataSource; SalesLine salesline, saleslineUpdate,salesLineTmp; SettlePostInvoiceTmp settlePostInvoiceTmp; PostInvoiceBySettle postInvoiceBySettle = new PostInvoiceBySettle(); SalesFormLetter salesFormLetter; SalesTable salesTable; SalesParmLine parmLine; Qty deliveryQty, settleQty,salesPrice, salesLineAmount; Query query; SysQueryRun queryRun; QueryBuildDataSource qbds; container con, conParmLine; CustInvoiceJour custInvoiceJour; SalesParmUpdate salesParmUpdate; int i, conLenth; SalesId salesId; InventTransId inventTransId; ; if(!_args) { throw Error("@SYS22539"); } if(_args.dataset() == tableNum(Test_SalesSettleTable)) { salesSettleTable = _args.record(); if(salesSettleTable) { ttsbegin; while select sum(SettleQty), sum(SettleAmount) from salesParmLineTmp group by salesParmLineTmp.InventTransId where salesParmLineTmp.SalesSettlementId == salesSettleTable.SalesSettlementId && salesParmLineTmp.SettledQty != salesParmLineTmp.DeliverNow { salesline = SalesLine::findInventTransId(salesParmLineTmp.InventTransId, true); if(salesline) { salesline.SalesDeliverNow = salesParmLineTmp.SettleQty; salesline.modifiedField(fieldNum(SalesLine, SalesDeliverNow)); salesline.update(); } if(!salesId || salesId != salesParmLine.OrigSalesId) { con += salesParmLine.OrigSalesId; } salesId = salesParmLine.OrigSalesId; } query = new Query(queryStr(SalesUpdate)); qbds = query.dataSourceTable(tableNum(SalesTable)); qbds.addRange(fieldNum(SalesTable, SalesId)).value(con2Str(con)); queryRun = new SysQueryRun(query); salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice); salesFormLetter.chooseLinesQuery(queryRun); salesFormLetter.transDate (systemDateGet()); salesFormLetter.specQty (SalesUpdate::DeliverNow); salesFormLetter.printFormLetter(false); salesFormLetter.chooseLines(false, true); salesFormLetter.reArrangeNow(true); salesFormLetter.sumBy(AccountOrder::Account); salesParmUpdate = salesFormLetter.salesParmUpdate(); salesFormLetter.run(); ttscommit; select firstonly custInvoiceJour where custInvoiceJour.ParmId == salesParmUpdate.ParmId; if(custInvoiceJour) { ttsbegin; salesSettleTable.selectForUpdate(true); salesSettleTable.InvoiceId = salesSettleTable.InvoiceId ? (salesSettleTable.InvoiceId + ',' + custInvoiceJour.InvoiceId) : custInvoiceJour.InvoiceId; salesSettleTable.doUpdate(); while select settlePostInvoiceTmp where settlePostInvoiceTmp.InventTransId { saleslineUpdate = SalesLine::findInventTransId(settlePostInvoiceTmp.InventTransId, true); if(saleslineUpdate) { saleslineUpdate.SalesDeliverNow = settlePostInvoiceTmp.DeliveryQty; salesline.modifiedField(fieldNum(SalesLine, SalesDeliverNow)); saleslineUpdate.update(); } } ttscommit; } } } } }