Esempio n. 1
0
        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.");
                    }
                }
            }
        }
Esempio n. 2
0
        public void RunStepGroup()
        {
            Guid?longOperationKey = null;

            if (this._longOperationKey != null)
            {
                longOperationKey = (Guid)this._longOperationKey;
            }

            if (_singleThread == false)
            {
                using (var ls = new PXLoginScope(CurrentStepGroup.MainContext.UserNameForLoginScope))
                {
                    PXSessionContextFactory.AuthenticateRequest();
                    PXLogin.SetBranchID(CurrentStepGroup.MainContext.BranchID);

                    CurrentStepGroup.MainContext.SetContextValues();
                    ls.Keep();
                }

                lock (CurrentStepGroup.MainContext.childLongOperations)
                {
                    if (longOperationKey != null)
                    {
                        CurrentStepGroup.MainContext.childLongOperations.Add((Guid)longOperationKey);
                    }
                }

                PXLongOperation.StartOperation(
                    longOperationKey,
                    () =>
                {
                    if (Thread.CurrentThread.Name == null)
                    {
                        Thread.CurrentThread.Name = "Child - " + longOperationKey.ToString();
                    }

                    CurrentStepGroup.RunAllSteps(longOperationKey);
                });
            }
            else
            {
                CurrentStepGroup.RunAllSteps(longOperationKey);
            }
        }
Esempio n. 3
0
        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();
                }
            }
        }
Esempio n. 4
0
        public CBAPIService(String endpoint, string version)
        {
            EntityHelper = ServiceLocator.Current.GetInstance <Func <string, string, IEntityHelper> >()(endpoint, version);

            string userName = "******";

            if (PXDatabase.Companies.Length > 0)
            {
                var company = PXAccess.GetCompanyName();
                if (string.IsNullOrEmpty(company))
                {
                    company = PXDatabase.Companies[0];
                }
                userName = userName + "@" + company;
            }
            LoginScope   = new PXLoginScope(userName, PXAccess.GetAdministratorRoles());
            CultureScope = new PX.Common.PXInvariantCultureScope();

            if (PXContext.GetSlot <System.Web.SessionState.ISessionStateItemCollection>() == null)
            {
                PXContext.SetSlot <System.Web.SessionState.ISessionStateItemCollection>(new System.Web.SessionState.SessionStateItemCollection());
            }
        }
Esempio n. 5
0
        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");
                }
            }
        }