Cloud 如何按代码准备发票和发布发票
我正在尝试创建一个导入SO的流程页面,我需要自动完成SO。这是我的密码Cloud 如何按代码准备发票和发布发票,cloud,erp,acumatica,Cloud,Erp,Acumatica,我正在尝试创建一个导入SO的流程页面,我需要自动完成SO。这是我的密码 using (var scope = new PXTransactionScope()) { SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>(); ImportSFA importGraph = PXGraph.CreateInstance<ImportSFA>();
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();
}
使用(var scope=new PXTransactionScope())
{
SOOrderEntry graph=PXGraph.CreateInstance();
ImportSFA importGraph=PXGraph.CreateInstance();
order.IsConvert=true;
importGraph.ImportProcessing.Update(订单);
SOOrder newOrder=新SOOrder();
graph.Document.Current=newOrder;
newOrder.Status=“N”;
//newOrder.OrderNbr=order.OrderNbr;
newOrder.OrderDate=order.OrderDate;
newOrder.RequestDate=order.OrderDate;
newOrder.OrderDesc=order.Note;
soorderexta=PXCache.GetExtension(newOrder);
a、 UsrRouteID=订单.路线;
a、 UsrTrueRoute=true;
var graphExt=graph.GetExtension();
//一行大写订单类型theo don tu PDA gui ve
如果(order.OrderType==“PA”)
{
newOrder.OrderType=“SO”;
}
else if(order.OrderType==“IV”)
{
newOrder.OrderType=“IN”;
}
其他的
{
newOrder.OrderType=“CS”;
}
if(newOrder.OrderType==“CS”)
{
newOrder.ExtRefNbr=“123”;
分支=PXSelect.Select(图形);
现金帐户=
选择,选择
(图表,
branch.BranchID).FirstTableItems.FirstOrDefault();
如果(ca!=null)
{
newOrder.CashAccountID=ca.CashAccountID;
}
其他的
{
抛出新的PXException(“找不到现金帐户”);
}
}
newOrder.CustomerOrderNbr=order.OrderNbr;
PXSelectBase cmdBaccount=新PXSelect(图形);
PXSelectBase cmdsaller=新的PXSelect(图形);
BAccount bacc=cmdBaccount.Select(order.CustomerID);
SalesPerson saller=cmdsaller.Select(order.SalesmanID);
如果(bacc!=null)
{
newOrder.CustomerID=bacc.BAccountID;
}
if(销售员!=null)
{
newOrder.salersonid=saller.salersonid;
}
graph.Document.Cache.Update(graph.Document.Current);
graph.Persist();
//插入行
PXSelectBase lines=新PXSelect(图形);
导入位置=空;
if(newOrder.OrderType==“SO”)
{
foreach(行中的DMSSODetail项。选择(order.OrderNbr))
{
如果(item.IsFree!=true)
{
INSite site=PXSelect.Select(图形、项目、仓库);
SOLine line=graph.Transactions.Insert();
line.InventoryID=item.InventoryID;
如果(站点!=null)
{
line.SiteID=site.SiteID;
}
行数量=项目确认数量;
SOLine updated=(SOLine)graph.Transactions.Cache.Update(line);
}
else if(item.IsFree==true&&item.ManualDiscount==true)
{
INSite site=PXSelect.Select(图形、项目、仓库);
SOLine line=graph.Transactions.Insert();
line.InventoryID=item.InventoryID;
line.ManualDisc=真;
line.IsFree=true;
solineextline=PXCache.GetExtension(line);
extLine.UsrManualPromoID=item.PromoDiscID;
如果(站点!=null)
{
line.SiteID=site.SiteID;
}
行数量=项目确认数量;
SOLine updated=(SOLine)graph.Transactions.Cache.Update(line);
}
}
}
else if(newOrder.OrderType==”在“| | newOrder.OrderType==”CS”中)
{
foreach(行中的DMSSODetail项。选择(order.OrderNbr))
{
INSite site=PXSelect.Select(图形、项目、仓库);
SOLine line=graph.Transactions.Insert();
line.InventoryID=item.InventoryID;
如果(站点!=null)
{
line.SiteID=site.SiteID;
}
//搜索位置
INLocation loc=PXSelect.Select(图形,项目.WHLocation);
如果(loc!=null)
{
line.LocationID=loc.LocationID;
位置=loc;
}
line.ManualDisc=true;//防止Acu自动折扣。
line.IsFree=item.IsFree;
solineextline=PXCache.GetExtension(line);
extLine.UsrManualPromoID=item.PromoDiscID;
行数量=项目确认数量;
SOLine updated=(SOLine)graph.Transactions.Cache.Update(line);
graph.Transactions.Current=已更新;
//搜索DMSSODetailSplit
PXSelectBase splits=新PXSelect
(图表);
foreach(DMSSODetailSplit in
拆分.Select(item.OrderNbr、item.InventoryID、item.IsFree、item.PromoDiscID))
{
//goi-ham插入条形码
graphExt.InsertScannedBarcod