我正在尝试创建一个流程页面来导入 SO,我需要自动完成 SO。这是我的代码
using (var scope = new PXTransactionScope())
{
SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
ImportSFA importGraph = PXGraph.CreateInstance<ImportSFA>();
order.IsConvert = true;
importGraph.ImportProcessing.Update(order);
SOOrder newOrder = new SOOrder();
graph.Document.Current = newOrder;
newOrder.Status = "N";
//newOrder.OrderNbr = order.OrderNbr;
newOrder.OrderDate = order.OrderDate;
newOrder.RequestDate = order.OrderDate;
newOrder.OrderDesc = order.Note;
SOOrderExt a = PXCache<SOOrder>.GetExtension<SOOrderExt>(newOrder);
a.UsrRouteID = order.Route;
a.UsrTrueRoute = true;
var graphExt = graph.GetExtension<SOOrderEntryExt1>();
// cap nhat order type theo don tu PDA gui ve
if (order.OrderType == "PA")
{
newOrder.OrderType = "SO";
}
else if (order.OrderType == "IV")
{
newOrder.OrderType = "IN";
}
else
{
newOrder.OrderType = "CS";
}
if (newOrder.OrderType == "CS")
{
newOrder.ExtRefNbr = "123";
Branch branch = PXSelect<Branch>.Select(graph);
CashAccount ca =
PXSelect<CashAccount, Where<CashAccount.branchID, Equal<Required<CashAccount.branchID>>>>.Select
(graph,
branch.BranchID).FirstTableItems.FirstOrDefault();
if (ca != null)
{
newOrder.CashAccountID = ca.CashAccountID;
}
else
{
throw new PXException("Cannot find the Cash Account.");
}
}
newOrder.CustomerOrderNbr = order.OrderNbr;
PXSelectBase<BAccount> cmdBaccount = new PXSelect<BAccount,
Where<BAccount.acctCD, Equal<Required<BAccount.acctCD>>>>(graph);
PXSelectBase<SalesPerson> cmdSalesman = new PXSelect<SalesPerson,
Where<SalesPerson.salesPersonCD, Equal<Required<SalesPerson.salesPersonCD>>>>(graph);
BAccount bacc = cmdBaccount.Select(order.CustomerID);
SalesPerson salesman = cmdSalesman.Select(order.SalesmanID);
if (bacc != null)
{
newOrder.CustomerID = bacc.BAccountID;
}
if (salesman != null)
{
newOrder.SalesPersonID = salesman.SalesPersonID;
}
graph.Document.Cache.Update(graph.Document.Current);
graph.Persist();
//Insert line
PXSelectBase<DMSSODetail> lines = new PXSelect<DMSSODetail,
Where<DMSSODetail.orderNbr, Equal<Required<DMSSODetail.orderNbr>>>>(graph);
INLocation location = null;
if (newOrder.OrderType == "SO")
{
foreach (DMSSODetail item in lines.Select(order.OrderNbr))
{
if (item.IsFree != true)
{
INSite site = PXSelect<INSite,
Where<INSite.siteCD, Equal<Required<INSite.siteCD>>>>.Select(graph, item.Warehouse);
SOLine line = graph.Transactions.Insert();
line.InventoryID = item.InventoryID;
if (site != null)
{
line.SiteID = site.SiteID;
}
line.Qty = item.ConfirmQty;
SOLine updated = (SOLine) graph.Transactions.Cache.Update(line);
}
else if (item.IsFree == true && item.ManualDiscount == true)
{
INSite site = PXSelect<INSite,
Where<INSite.siteCD, Equal<Required<INSite.siteCD>>>>.Select(graph, item.Warehouse);
SOLine line = graph.Transactions.Insert();
line.InventoryID = item.InventoryID;
line.ManualDisc = true;
line.IsFree = true;
SOLineExt extLine = PXCache<SOLine>.GetExtension<SOLineExt>(line);
extLine.UsrManualPromoID = item.PromoDiscID;
if (site != null)
{
line.SiteID = site.SiteID;
}
line.Qty = item.ConfirmQty;
SOLine updated = (SOLine) graph.Transactions.Cache.Update(line);
}
}
}
else if (newOrder.OrderType == "IN" || newOrder.OrderType == "CS")
{
foreach (DMSSODetail item in lines.Select(order.OrderNbr))
{
INSite site = PXSelect<INSite,
Where<INSite.siteCD, Equal<Required<INSite.siteCD>>>>.Select(graph, item.Warehouse);
SOLine line = graph.Transactions.Insert();
line.InventoryID = item.InventoryID;
if (site != null)
{
line.SiteID = site.SiteID;
}
//Search Location
INLocation loc = PXSelect<INLocation, Where<INLocation.locationCD,
Equal<Required<INLocation.locationCD>>>>.Select(graph, item.WHLocation);
if (loc != null)
{
line.LocationID = loc.LocationID;
location = loc;
}
line.ManualDisc = true; //Prevent Acu auto discount.
line.IsFree = item.IsFree;
SOLineExt extLine = PXCache<SOLine>.GetExtension<SOLineExt>(line);
extLine.UsrManualPromoID = item.PromoDiscID;
line.Qty = item.ConfirmQty;
SOLine updated = (SOLine) graph.Transactions.Cache.Update(line);
graph.Transactions.Current = updated;
//Search DMSSODetailSplit
PXSelectBase<DMSSODetailSplit> splits = new PXSelect<DMSSODetailSplit,
Where<DMSSODetailSplit.orderNbr, Equal<Required<DMSSODetailSplit.orderNbr>>,
And<DMSSODetailSplit.inventoryID, Equal<Required<DMSSODetailSplit.inventoryID>>,
And<DMSSODetailSplit.isFree, Equal<Required<DMSSODetailSplit.isFree>>,
And<DMSSODetailSplit.promoDiscID, Equal<Required<DMSSODetailSplit.promoDiscID>>>
>>>>
(graph);
foreach (DMSSODetailSplit split in
splits.Select(item.OrderNbr, item.InventoryID, item.IsFree, item.PromoDiscID))
{
// goi ham insert bar code
graphExt.InsertScannedBarcode(split.InventoryID, split.LotSerialNbr, newOrder);
}
}
}
int index = 0;
foreach (SOLine item in graph.Transactions.Select())
{
if (item.IsFree == true)
{
SOLine oldRow = item;
item.LocationID =
((SOLine) graph.Transactions.Select()[(index - 1) < 0 ? 0 : (index - 1)]).LocationID;
graph.Transactions.Cache.RaiseFieldUpdated<SOLine.locationID>(item, oldRow.LocationID);
}
index++;
}
graph.Persist();
importGraph.Actions.PressSave();
//graph.prepareInvoice.Press();
//kiem tra neu la don hang CS thi tu dong tao va release invoice
if (newOrder.OrderType == "CS")
{
graphExt.prepareInvoice.Press();
SOInvoiceEntry invoiceGraph = PXGraph.CreateInstance<SOInvoiceEntry>();
PXResultset<ARInvoice> arInv = PXSelectJoin<ARInvoice,
InnerJoin<SOOrderShipment, On<ARInvoice.docType,
Equal<SOOrderShipment.invoiceType>,
And<ARInvoice.refNbr, Equal<SOOrderShipment.invoiceNbr>>>>
, Where<SOOrderShipment.orderNbr, Equal<Required<SOOrderShipment.orderNbr>>
, And<SOOrderShipment.invtDocType, Equal<Required<SOOrderShipment.invtDocType>>>>>
.Select(invoiceGraph, newOrder.OrderNbr, "CSL");
invoiceGraph.Document.Current = arInv;
invoiceGraph.Save.Press();
//release invoice
invoiceGraph.release.Press();
}
scope.Complete();
}
当我处理我得到这个错误
24/01/2015 5:48:23 CH 错误:错误 #140:尚未处理一项或多项。
发票
在 PX.Data.PXProcessing 1.<>c__DisplayClass12.b__11(List
1 列表中)在 PX.Data.PXLongOperation.<>c__DisplayClass5.b__4()
我不知道如何解决。请帮我。谢谢你的支持。