public static void Process(EMailAccountSyncFilter filter, List <EMailSyncAccount> accounts, Object uid, string screenid)
        {
            //Check that process is singleton
            foreach (RowTaskInfo info in PXLongOperation.GetTaskList())
            {
                if (Object.Equals(uid, info.NativeKey))
                {
                    continue;
                }

                PXLongRunStatus status = PXLongOperation.GetStatus(info.NativeKey);
                if (status != PXLongRunStatus.InProcess)
                {
                    continue;
                }

                string company = PXLogin.ExtractCompany(info.User);
                string screen  = (info.Screen ?? String.Empty).Replace(".", "");
                if (screen == screenid && company == PXAccess.GetCompanyName())
                {
                    throw new PXException(ErrorMessages.PrevOperationNotCompleteYet);
                }
            }

            EmailsSyncMaint graph = CreateInstance <EmailsSyncMaint>();

            using (new PXUTCTimeZoneScope())
            {
                graph.ProcessInternal(new ProcessingContext(filter, accounts, graph.GetPolicies()));
            }
        }
Example #2
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");
                }
            }
        }