0
創建貨件並向其中添加多個訂單的最簡單方法是什麼?如何以編程方式從多個訂單創建貨件?
創建貨件並向其中添加多個訂單的最簡單方法是什麼?如何以編程方式從多個訂單創建貨件?
以下示例利用在銷售訂單和出貨屏幕上使用的CreateShipment方法。基本上這個示例所做的是循環所有給定客戶和給定倉庫的SOShipmentPlan計劃,以類似於添加銷售訂單彈出窗口在貨件屏幕上的工作方式來選擇它們。唯一的區別是執行單個BQL查詢來檢索所有SOShipmentPlan記錄,這些記錄可以添加到Shipment中,而不是使用Add Sales Orders彈出式思考代碼進行操作。
string operation = SOOperation.Issue;
var graph = PXGraph.CreateInstance<SOShipmentEntry>();
var shipment = graph.Document.Insert();
var customer = (BAccountR)PXSelect<BAccountR,
Where<BAccountR.acctCD, Equal<Required<BAccountR.acctCD>>>>
.SelectSingleBound(graph, new object[] { }, "ABARTENDE");
shipment.CustomerID = customer.BAccountID;
shipment = graph.Document.Update(shipment);
var warehouse = (INSite)PXSelect<INSite,
Where<INSite.siteCD, Equal<Required<INSite.siteCD>>>>
.SelectSingleBound(graph, new object[] { }, "RETAIL");
shipment.SiteID = warehouse.SiteID;
graph.Document.Update(shipment);
SOOrder prevOrder = null;
foreach (PXResult<SOShipmentPlan, SOLineSplit, SOOrderShipment, SOOrder> res in
PXSelectJoin<SOShipmentPlan,
InnerJoin<SOLineSplit,
On<SOLineSplit.planID, Equal<SOShipmentPlan.planID>>,
LeftJoin<SOOrderShipment,
On<SOOrderShipment.orderType, Equal<SOShipmentPlan.orderType>,
And<SOOrderShipment.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<SOOrderShipment.operation, Equal<SOLineSplit.operation>,
And<SOOrderShipment.siteID, Equal<SOShipmentPlan.siteID>,
And<SOOrderShipment.confirmed, Equal<boolFalse>,
And<SOOrderShipment.shipmentNbr, NotEqual<Current<SOShipment.shipmentNbr>>>>>>>>,
InnerJoin<SOOrder,
On<SOOrder.orderType, Equal<SOShipmentPlan.orderType>,
And<SOOrder.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<SOOrder.customerID, Equal<Current<SOShipment.customerID>>,
And<SOOrder.cancelled, Equal<boolFalse>,
And<SOOrder.completed, Equal<boolFalse>,
And<SOOrder.hold, Equal<False>,
And<SOOrder.creditHold, Equal<False>>>>>>>>>>>,
Where<SOShipmentPlan.orderType, Equal<Required<SOShipmentPlan.orderType>>,
And<SOShipmentPlan.siteID, Equal<Current<SOShipment.siteID>>,
And<SOOrderShipment.shipmentNbr, IsNull,
And<SOLineSplit.operation, Equal<Required<SOLineSplit.operation>>,
And2<
Where<Current<SOShipment.destinationSiteID>, IsNull,
Or<SOShipmentPlan.destinationSiteID, Equal<Current<SOShipment.destinationSiteID>>>>,
And<
Where<SOShipmentPlan.inclQtySOShipping, Equal<True>,
Or<SOShipmentPlan.inclQtySOShipped, Equal<True>,
Or<SOShipmentPlan.requireAllocation, Equal<False>,
Or<SOLineSplit.lineType, Equal<SOLineType.nonInventory>>>>>>>>>>>>
.Select(graph, "SO", operation))
{
var plan = (SOShipmentPlan)res;
plan.Selected = true;
graph.soshipmentplan.Update(plan);
var order = (SOOrder)res;
prevOrder = prevOrder ?? order;
if (order.OrderNbr == prevOrder.OrderNbr) continue;
graph.CreateShipment(prevOrder, shipment.SiteID, shipment.ShipDate, false, operation, null);
graph.soshipmentplan.Cache.Clear();
prevOrder = order;
}
if (prevOrder != null)
{
graph.CreateShipment(prevOrder, shipment.SiteID, shipment.ShipDate, false, operation, null);
graph.soshipmentplan.Cache.Clear();
}
graph.Actions.PressSave();