protected void _(Events.RowDeleting <POOrder> e) { var row = e.Row as POOrder; if (row == null) { return; } var curPOOrder = (POOrder)Base.Caches[typeof(POOrder)].Current; POOrderExt pOOrderExt = curPOOrder.GetExtension <POOrderExt>(); if ((bool)pOOrderExt.UsrICSOCreated) { var curUserName = PXLogin.ExtractUsername(PXContext.PXIdentity.IdentityName); var curLMICVendor = PXSelect <LMICVendor, Where <LMICVendor.vendorid, Equal <Required <LMICVendor.vendorid> > > > .Select(Base, curPOOrder.VendorID).TopFirst; using (PXLoginScope pXLoginScope = new PXLoginScope($"{curUserName}@{curLMICVendor.LoginName}")) { SOOrderEntry sOOrderEntry = PXGraph.CreateInstance <SOOrderEntry>(); // check the shipment base on this SO is created or not var isShipmentCreated = PXSelect <SOOrderShipment, Where <SOOrderShipment.orderNbr, Equal <Required <SOOrderShipment.orderNbr> > > > .Select(sOOrderEntry, row.VendorRefNbr).Count() > 0 ? true : false; if (isShipmentCreated) { throw new PXException("You cannot delete the PO because there is shipment created in IC SO."); } } } }
protected void _(Events.RowDeleted <POOrder> e) { var row = e.Row as POOrder; if (row == null) { return; } var curPOOrder = (POOrder)Base.Caches[typeof(POOrder)].Current; POOrderExt pOOrderExt = curPOOrder.GetExtension <POOrderExt>(); if ((bool)pOOrderExt.UsrICSOCreated) { var curPOLines = (POLine)Base.Caches[typeof(POLine)].Current; var curUserName = PXLogin.ExtractUsername(PXContext.PXIdentity.IdentityName); var curLMICVendor = PXSelect <LMICVendor, Where <LMICVendor.vendorid, Equal <Required <LMICVendor.vendorid> > > > .Select(Base, curPOOrder.VendorID)?.TopFirst; if (curLMICVendor != null) { using (PXLoginScope pXLoginScope = new PXLoginScope($"{curUserName}@{curLMICVendor.LoginName}")) { // set SOorder.ICPOCreated = False, SOOrder.Customerordernbr = Blank SOOrderEntry sOOrderEntry = PXGraph.CreateInstance <SOOrderEntry>(); SOOrder sOOrder = PXSelect <SOOrder, Where <SOOrder.orderNbr, Equal <Required <SOOrder.orderNbr> > > > .Select(sOOrderEntry, row.VendorRefNbr)?.TopFirst; sOOrder.CustomerOrderNbr = "IC PO had been deleted"; SOOrderExt sOOrderExt = sOOrder.GetExtension <SOOrderExt>(); sOOrderExt.UsrICPOCreated = false; sOOrder = sOOrderEntry.Document.Update(sOOrder); sOOrderEntry.Actions.PressSave(); } Base.Document.Delete(curPOOrder); Base.Transactions.Delete(curPOLines); Base.Actions.PressSave(); } } }
protected void createICPOAction() { Base.Save.Press(); var curCompanyID = PXInstanceHelper.CurrentCompany; var curUserName = PXLogin.ExtractUsername(PXContext.PXIdentity.IdentityName); //A.By using LMICCustomer table to identify the destination tenant of PO need to be created var curSOOrder = (SOOrder)Base.Caches[typeof(SOOrder)].Current; var curLMICCustomer = PXSelect <LMICCustomer, Where <LMICCustomer.customerID, Equal <Required <LMICCustomer.customerID> > > > .Select(Base, curSOOrder.CustomerID).TopFirst; //B.Go to the destination tenant, and ensure vendor is defined in LMICVendor.If not, throw error message “The vendor is not defined in destination tenant”. var curCompanyName = PXLogin.ExtractCompany(PXContext.PXIdentity.IdentityName); var curLMICVendor = new LMICVendor(); try { using (PXLoginScope pXLoginScope = new PXLoginScope($"{curUserName}@{curLMICCustomer.LoginName}")) { curLMICVendor = PXSelect <LMICVendor, Where <LMICVendor.tenantID, Equal <Required <LMICVendor.tenantID> > > > .Select(PXGraph.CreateInstance <POOrderEntry>(), curCompanyID).TopFirst; } } catch (Exception) { throw new PXException("Please try again."); } /*Get InventoryCD in each line*/ var inventoryCDList = new List <string>(); foreach (SOLine line in Base.Transactions.Cache.Cached) { inventoryCDList.Add(PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, line.InventoryID).TopFirst?.InventoryCD); } if (curLMICCustomer != null) { if (curLMICVendor != null) { try { PXLongOperation.StartOperation(Base, () => { var SOOrderCustomerOrderNbr = string.Empty; //C.Create a purchase order in destination tenant by uing the following mapping. using (PXLoginScope pXLoginScope = new PXLoginScope($"{curUserName}@{curLMICCustomer.LoginName}")) { POOrderEntry pOOrderEntry = PXGraph.CreateInstance <POOrderEntry>(); /* PO Header */ POOrder pOOrder = new POOrder(); pOOrder = pOOrderEntry.Document.Insert(pOOrder); pOOrder.BranchID = curLMICVendor.BranchID; pOOrder.VendorID = curLMICVendor.VendorID; pOOrderEntry.Document.Cache.RaiseFieldUpdated <POOrder.vendorID>(pOOrder, pOOrder.VendorID); pOOrder.VendorRefNbr = curSOOrder.OrderNbr; pOOrder.OrderDate = curSOOrder.OrderDate; pOOrder.OrderDesc = "IC PO | " + curCompanyName + " | " + curSOOrder.OrderNbr; /* PO Line */ int i = 0; foreach (SOLine line in Base.Transactions.Cache.Cached) { POLine pOLine = new POLine(); var tempInventoryID = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> > > > .Select(pOOrderEntry, inventoryCDList[i])?.TopFirst?.InventoryID; pOLine.InventoryID = tempInventoryID == null ? PXSelect <INItemXRef, Where <INItemXRef.alternateID, Equal <Required <INItemXRef.alternateID> > > > .Select(pOOrderEntry, inventoryCDList[i])?.TopFirst?.InventoryID : tempInventoryID; pOLine.OrderQty = line.OrderQty; pOLine = pOOrderEntry.Transactions.Insert(pOLine); pOLine.CuryUnitCost = line.CuryUnitPrice; pOLine = pOOrderEntry.Transactions.Update(pOLine); i++; } //D.If the PO is saved successfully, please update the following fields // - POOrder, ICSOCreated = true POOrderExt pOOrderExt = pOOrder.GetExtension <POOrderExt>(); pOOrderExt.UsrICSOCreated = true; pOOrderEntry.Document.Update(pOOrder); pOOrderEntry.Actions.PressSave(); SOOrderCustomerOrderNbr = pOOrder.OrderNbr; } //D.If the PO is saved successfully, please update the following fields // - SOOrder, ICPOCreated = true; Customer Order Nbr = POOrder.OrderNbr SOOrderExt sOOrderExt = curSOOrder.GetExtension <SOOrderExt>(); sOOrderExt.UsrICPOCreated = true; curSOOrder.CustomerOrderNbr = SOOrderCustomerOrderNbr; Base.Document.Update(curSOOrder); Base.Save.Press(); }); } catch (Exception) { throw new PXException("Please try again."); } } else { throw new PXException("The vendor is not defined in destination tenant"); } } }