public virtual void CopyBAccountContactInfo()
        {
            var row = ContactCurrent.Current as Contact;

            if (row == null || row.BAccountID == null)
            {
                return;
            }

            var acct = (BAccount)PXSelect <BAccount,
                                           Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .
                       Select(this, row.BAccountID);

            if (acct != null && acct.DefContactID != null)
            {
                var defContact = (Contact)PXSelect <Contact,
                                                    Where <Contact.contactID, Equal <Required <Contact.contactID> > > > .
                                 Select(this, acct.DefContactID);

                if (defContact != null)
                {
                    CopyContactInfo(row, defContact);
                }
                ContactCurrent.Update(row);
            }
        }
        private void InsertUpdateCustomerBillingSetup(PXCache cache, Customer customerRow, FSxCustomer fsxCustomerRow)
        {
            FSSetup fsSetupRow = PXSelect <FSSetup> .Select(Base);

            if (fsSetupRow != null &&
                fsSetupRow.CustomerMultipleBillingOptions == false)
            {
                FSCustomerBillingSetup fsCustomerBillingSetupRow = CustomerBillingCycles.Select();

                if (fsxCustomerRow.BillingCycleID == null)
                {
                    CustomerBillingCycles.Delete(fsCustomerBillingSetupRow);
                    return;
                }

                if (fsCustomerBillingSetupRow == null)
                {
                    fsCustomerBillingSetupRow            = CustomerBillingCycles.Insert(new FSCustomerBillingSetup());
                    fsCustomerBillingSetupRow.SrvOrdType = null;
                }

                fsCustomerBillingSetupRow.BillingCycleID     = fsxCustomerRow.BillingCycleID;
                fsCustomerBillingSetupRow.SendInvoicesTo     = fsxCustomerRow.SendInvoicesTo;
                fsCustomerBillingSetupRow.BillShipmentSource = fsxCustomerRow.BillShipmentSource;
                fsCustomerBillingSetupRow.FrequencyType      = ID.Frequency_Type.NONE;

                CustomerBillingCycles.Update(fsCustomerBillingSetupRow);
            }
        }
Exemple #3
0
        private void UpdateAcitivtyRemindInfo(object id, UpdateRemindInfo handler)
        {
            EPReminder remindInfo = RemindInfo.Select(id);

            if (remindInfo == null)
            {
                remindInfo = (EPReminder)RemindInfo.Cache.Insert();
                EPActivity activity = PXSelect <EPActivity, Where <EPActivity.taskID, Equal <Required <EPActivity.taskID> > > > .
                                      Select(this, id);

                remindInfo.NoteID = PXNoteAttribute.GetNoteID(Caches[typeof(EPActivity)], activity,
                                                              EntityHelper.GetNoteField(typeof(EPActivity)));
                remindInfo.UserID = PXAccess.GetUserID();
                remindInfo.Date   = PXTimeZoneInfo.Now;
                RemindInfo.Cache.Normalize();
            }
            handler(remindInfo);
            RemindInfo.Update(remindInfo);
            using (var ts = new PXTransactionScope())
            {
                RemindInfo.Cache.Persist(PXDBOperation.Insert);
                RemindInfo.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
            RemindInfo.Cache.Persisted(false);
            ActivityList.Cache.Clear();
            ActivityList.View.Clear();
            ActivityCount.Cache.Clear();
            ActivityCount.View.Clear();
            ReminderList.Cache.Clear();
            ReminderList.View.Clear();
            ReminderListCurrent.View.Clear();
        }
        public virtual IEnumerable prepareAdd(PXAdapter adapter)
        {
            if (Transfer.Current != null && Transfer.Current.Released != true)
            {
                Save.Press();
                Transfer.JustPersisted = true;

                //recreate currencyinfo on CurrencyInfoAttribute.RowUpdating
                AddFilter.Update(AddFilter.Current);

                if (this.Views.ContainsKey("AddFilter"))
                {
                    WebDialogResult result = this.Views["AddFilter"].AskExt(true);
                    if (result == WebDialogResult.OK)
                    {
                        using (new PXTimeStampScope(this.TimeStamp))
                        {
                            CATran catran = null;
                            catran = (catran ?? AddTrxFilter.AddAPTransaction(this, AddFilter, currencyinfo_addfilter));
                            catran = (catran ?? AddTrxFilter.AddARTransaction(this, AddFilter, currencyinfo_addfilter));
                            catran = (catran ?? AddTrxFilter.AddCATransaction(this, AddFilter, currencyinfo_addfilter));
                            AddTrxFilter.Clear(this, AddFilter);

                            catran = TransferTran.Update(catran);
                            Save.Press();
                        }
                    }
                }
            }
            else
            {
                throw new Exception(Messages.DocumentStatusInvalid);
            }
            return(adapter.Get());
        }
Exemple #5
0
        private void UpdateAcitivtyRemindInfo(object id, UpdateRemindInfo handler)
        {
            CRReminder remindInfo = RemindInfo.Select(id);

            if (remindInfo == null && id is Guid)
            {
                remindInfo              = (CRReminder)RemindInfo.Cache.Insert();
                remindInfo.RefNoteID    = (Guid)id;
                remindInfo.Owner        = PXAccess.GetUserID();
                remindInfo.ReminderDate = PXTimeZoneInfo.Now;
                RemindInfo.Cache.Normalize();
            }
            handler(remindInfo);
            RemindInfo.Update(remindInfo);
            using (var ts = new PXTransactionScope())
            {
                RemindInfo.Cache.Persist(PXDBOperation.Insert);
                RemindInfo.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
            RemindInfo.Cache.Persisted(false);
            ActivityList.Cache.Clear();
            ActivityList.View.Clear();
            ActivityCount.Cache.Clear();
            ActivityCount.View.Clear();
            ReminderList.Cache.Clear();
            ReminderList.View.Clear();
            ReminderListCurrent.View.Clear();
        }
Exemple #6
0
        public virtual IEnumerable prepareAdd(PXAdapter adapter)
        {
            if (Transfer.Current != null && Transfer.Current.Released != true)
            {
                Save.Press();
                //Current should be the only one inserted
                PXCache currencycache = Caches[typeof(CM.CurrencyInfo)];
                currencycache.SetStatus(currencycache.Current, PXEntryStatus.Inserted);
                Transfer.JustPersisted = true;

                //recreate currencyinfo on CurrencyInfoAttribute.RowUpdating
                AddFilter.Update(AddFilter.Current);

                WebDialogResult result = AddFilter.AskExt(true);
                if (result == WebDialogResult.OK)
                {
                    using (new PXTimeStampScope(this.TimeStamp))
                    {
                        CATran catran = AddTrxFilter.VerifyAndCreateTransaction(this, AddFilter, currencyinfo_addfilter);
                        catran = TransferTran.Update(catran);
                        Save.Press();
                    }
                }
                AddFilter.Cache.Clear();
            }
            else
            {
                throw new Exception(Messages.DocumentStatusInvalid);
            }
            return(adapter.Get());
        }
        protected virtual void _(Events.RowDeleted <APInvoice> args)
        {
            var bill = args.Row;

            if (bill == null)
            {
                return;
            }
            var compliances = GetComplianceDocuments();

            foreach (var compliance in compliances)
            {
                compliance.BillID = null;
                ComplianceDocuments.Update(compliance);
            }
        }
Exemple #8
0
        protected virtual void Contact_Email_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            Contact contact = (Contact)e.Row;

            foreach (EMailSyncAccount syncAccount in SyncAccount.Select(contact.ContactID)
                     .RowCast <EMailSyncAccount>()
                     .Select(account => (EMailSyncAccount)SyncAccount.Cache.CreateCopy(account)))
            {
                syncAccount.Address = contact.EMail;

                syncAccount.ContactsExportDate = null;
                syncAccount.ContactsImportDate = null;
                syncAccount.EmailsExportDate   = null;
                syncAccount.EmailsImportDate   = null;
                syncAccount.TasksExportDate    = null;
                syncAccount.TasksImportDate    = null;
                syncAccount.EventsExportDate   = null;
                syncAccount.EventsImportDate   = null;

                EMailAccount mailAccount = EMailAccounts.Select(syncAccount.EmailAccountID);
                mailAccount.Address = syncAccount.Address;

                EMailAccounts.Update(mailAccount);
                SyncAccount.Update(syncAccount);
            }
        }
        public virtual IEnumerable Up(PXAdapter adapter)
        {
            IList <EPAssignmentRoute> routes = GetSortedItems();

            int?selectedItem     = Items.Current.AssignmentRouteID;
            int currentItemIndex = 0;

            for (int i = 0; i < routes.Count; i++)
            {
                if (routes[i].AssignmentRouteID == selectedItem)
                {
                    currentItemIndex = i;
                }

                routes[i].Sequence = i + 1;
                Items.Update(routes[i]);
            }

            if (currentItemIndex > 0)
            {
                routes[currentItemIndex].Sequence--;
                routes[currentItemIndex - 1].Sequence++;

                Items.Update(routes[currentItemIndex]);
                Items.Update(routes[currentItemIndex - 1]);
            }

            return(adapter.Get());
        }
Exemple #10
0
        protected virtual void InsertUpdatePOAdjust(APAdjust apadjust)
        {
            if (Base.Document.Current?.DocType.IsNotIn(APDocType.Prepayment, APDocType.VoidCheck) == true ||
                apadjust?.AdjdDocType != APDocType.Prepayment)
            {
                return;
            }

            var prepaymentRequests = new PXSelectJoin <POOrderPrepayment,
                                                       InnerJoin <POOrder, On <POOrderPrepayment.orderType, Equal <POOrder.orderType>, And <POOrderPrepayment.orderNbr, Equal <POOrder.orderNbr> > > >,
                                                       Where <POOrderPrepayment.aPDocType, Equal <Required <APAdjust.adjdDocType> >,
                                                              And <POOrderPrepayment.aPRefNbr, Equal <Required <APAdjust.adjdRefNbr> >,
                                                                   And <POOrderPrepayment.aPDocType, Equal <APDocType.prepayment> > > > >(Base)
                                     .Select(apadjust.AdjdDocType, apadjust.AdjdRefNbr);

            foreach (PXResult <POOrderPrepayment, POOrder> row in prepaymentRequests)
            {
                POOrder           order             = row;
                POOrderPrepayment prepaymentRequest = row;

                POAdjust poadjustment = new PXSelect <POAdjust,
                                                      Where <POAdjust.adjgDocType, Equal <Current <APPayment.docType> >,
                                                             And <POAdjust.adjgRefNbr, Equal <Current <APPayment.refNbr> >,
                                                                  And <POAdjust.adjNbr, Equal <Current <APPayment.adjCntr> >,
                                                                       And <POAdjust.adjdDocType, Equal <Required <APInvoice.docType> >,
                                                                            And <POAdjust.adjdRefNbr, Equal <Required <APInvoice.refNbr> > > > > > > >(Base)
                                        .Select(apadjust.AdjdDocType, apadjust.AdjdRefNbr);

                if (poadjustment == null)
                {
                    poadjustment = POAdjustments.Insert(new POAdjust()
                    {
                        AdjgDocType   = Base.Document.Current.DocType,
                        AdjgRefNbr    = Base.Document.Current.RefNbr,
                        AdjdOrderType = prepaymentRequest.OrderType,
                        AdjdOrderNbr  = prepaymentRequest.OrderNbr,
                        AdjdDocType   = apadjust.AdjdDocType,
                        AdjdRefNbr    = apadjust.AdjdRefNbr,
                        AdjNbr        = Base.Document.Current.AdjCntr,
                        IsRequest     = true,
                    });
                }

                if (order.CuryID == Base.Document.Current.CuryID)
                {
                    POAdjustments.Cache.SetValueExt <POAdjust.curyAdjgAmt>(poadjustment, apadjust.CuryAdjgAmt);
                }
                else
                {
                    PXCurrencyAttribute.CuryConvCury(Base.Document.Cache, Base.Document.Current, apadjust.AdjAmt ?? 0, out decimal curyamount);
                    POAdjustments.Cache.SetValueExt <POAdjust.curyAdjgAmt>(poadjustment, curyamount);
                }

                POAdjustments.Update(poadjustment);
            }
        }
        public virtual IEnumerable Unmatch(PXAdapter adapter)
        {
            CABankTran detail = Details.Current;

            if (detail.DocumentMatched == true)
            {
                if (detail.Processed == true)
                {
                    if (Details.Ask(Messages.ClearMatch, Messages.UnmatchTranMsg, MessageButtons.OKCancel) == WebDialogResult.Cancel)
                    {
                        return(adapter.Get());
                    }
                    detail.Processed = false;
                }
                foreach (CABankTranMatch match in TranMatch.Select(detail.TranID))
                {
                    if (match.DocModule == GL.BatchModule.AP && match.DocType == CATranType.CABatch)
                    {
                        foreach (CATran tran in CATransInBatch.Select(match.DocRefNbr))
                        {
                            if (tran != null && tran.TranID != null && tran.ReconNbr == null)
                            {
                                tran.ClearDate = null;
                                tran.Cleared   = false;
                                CATransInBatch.Update(tran);
                            }
                        }
                    }
                    else
                    {
                        CATran tran = CATrans.Select(match.CATranID);
                        if (tran != null && tran.TranID != null && tran.ReconNbr == null)
                        {
                            tran.ClearDate = null;
                            tran.Cleared   = false;
                            CATrans.Update(tran);
                        }
                    }
                    TranMatch.Delete(match);
                }
                foreach (var adj in TranAdj.Select(detail.TranID))
                {
                    TranAdj.Delete(adj);
                }
                foreach (var split in CABankTranSplits.Select(detail.TranID))
                {
                    CABankTranSplits.Delete(split);
                }
                CABankTransactionsMaint.ClearFields(detail);
                Details.Cache.SetDefaultExt <CABankTran.curyApplAmt>(detail);
                Details.Cache.SetDefaultExt <CABankTran.curyApplAmtCA>(detail);
                Details.Update(detail);
            }
            return(adapter.Get());
        }
 private void RemoveComplianceReference(ComplianceDocument document)
 {
     if (IsSubcontractScreen())
     {
         document.Subcontract = null;
     }
     else
     {
         document.PurchaseOrder = null;
     }
     ComplianceDocuments.Update(document);
 }
Exemple #13
0
        protected virtual void Users_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            Users   oldRow = e.OldRow as Users;
            Users   row    = e.Row as Users;
            Contact c      = PXSelect <Contact, Where <Contact.userID, Equal <Current <Users.pKID> > > > .SelectSingleBound(this, new object[] { row });

            if (row == null || oldRow == null || row.Guest == oldRow.Guest || c == null)
            {
                return;
            }

            c.UserID = null;
            contact.Update(c);

            EPEmployee emp = Employee.Select(c.ContactID);

            if (emp != null)
            {
                emp = PXCache <EPEmployee> .CreateCopy(emp);

                emp.UserID = null;
                Employee.Update(emp);
            }

            foreach (EPCompanyTreeMember member in Members.View.SelectMultiBound(new[] { e.Row }))
            {
                Members.Delete(member);
            }
        }
        protected virtual void PaymentMethod_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
        {
            PaymentMethod row    = (PaymentMethod)e.Row;
            PaymentMethod oldRow = (PaymentMethod)e.OldRow;

            if (oldRow.PaymentType != row.PaymentType)
            {
                foreach (PaymentMethodDetail iDet in this.Details.Select())
                {
                    this.Details.Cache.Delete(iDet);
                }
                if (row.PaymentType == PaymentMethodType.CreditCard)
                {
                    this.fillCreditCardDefaults();
                }
                row.ARIsOnePerCustomer = row.PaymentType == PaymentMethodType.CashOrCheck;
            }

            if ((oldRow.UseForAR != row.UseForAR) && row.UseForAR.GetValueOrDefault(false) == false)
            {
                row.ARIsProcessingRequired = false;

                foreach (PaymentMethodAccount pma in CashAccounts.Select())
                {
                    pma.UseForAR = pma.ARIsDefault = pma.ARIsDefaultForRefund = false;
                    CashAccounts.Update(pma);
                }
            }

            if ((oldRow.UseForAP != row.UseForAP) && row.UseForAP.GetValueOrDefault(false) == false)
            {
                foreach (PaymentMethodAccount pma in CashAccounts.Select())
                {
                    pma.UseForAP = pma.APIsDefault = false;
                    CashAccounts.Update(pma);
                }
            }
        }
        protected virtual void PmRegister_RowDeleted(PXCache cache, PXRowDeletedEventArgs arguments)
        {
            if (!(arguments.Row is PMRegister))
            {
                return;
            }
            var documents = GetComplianceDocuments();

            foreach (var document in documents)
            {
                document.ProjectTransactionID = null;
                ComplianceDocuments.Update(document);
            }
        }
Exemple #16
0
        protected virtual void FixedAsset_UsefulLife_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            FixedAsset header = (FixedAsset)e.Row;

            if (header == null)
            {
                return;
            }

            foreach (FABookSettings set in PXSelect <FABookSettings, Where <FABookSettings.assetID, Equal <Required <FABookSettings.assetID> > > > .Select(this, header.AssetID))
            {
                FABookSettings newSettings = (FABookSettings)DepreciationSettings.Cache.CreateCopy(set);
                newSettings.UsefulLife = header.UsefulLife;
                DepreciationSettings.Update(newSettings);
            }
        }
        protected virtual void _(Events.RowDeleted <APPayment> args)
        {
            var payment = args.Row;

            if (payment == null)
            {
                return;
            }
            var documents = GetComplianceDocuments();

            foreach (var document in documents)
            {
                document.ApCheckID = null;
                ComplianceDocuments.Update(document);
            }
        }
Exemple #18
0
        protected virtual void ARInvoice_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            ARInvoice row = (ARInvoice)e.Row;

            if (row != null && !String.IsNullOrEmpty(row.DocType) &&
                !String.IsNullOrEmpty(row.RefNbr))
            {
                CCPayments.Insert(row);
                CCPayments.Update(row);
                CCPayments.Delete(row);

                CCPayments.View.Insert(row);
                CCPayments.View.Update(row);
                CCPayments.View.Delete(row);
            }
        }
Exemple #19
0
		protected virtual void FixedAsset_UsefulLife_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
		{
			FixedAsset header = (FixedAsset)e.Row;
			if (header == null) return;

			foreach (FABookSettings newSettings in PXSelect<FABookSettings, Where<FABookSettings.assetID, Equal<Required<FABookSettings.assetID>>>>.Select(this, header.AssetID)
					.RowCast<FABookSettings>()
					.Select(set => (FABookSettings)DepreciationSettings.Cache.CreateCopy(set)))
			{
				FADepreciationMethod deprMethod = PXSelectorAttribute.Select<FABookSettings.depreciationMethodID>(DepreciationSettings.Cache, newSettings) as FADepreciationMethod;
				if (deprMethod?.DepreciationMethod != FADepreciationMethod.depreciationMethod.AustralianPrimeCost
					&& deprMethod?.DepreciationMethod != FADepreciationMethod.depreciationMethod.NewZealandStraightLine
					&& deprMethod?.DepreciationMethod != FADepreciationMethod.depreciationMethod.NewZealandStraightLineEvenly)
				{
					newSettings.UsefulLife = header.UsefulLife;
					DepreciationSettings.Update(newSettings);
				}
			}
		}
 public virtual IEnumerable RemoveRecipient(PXAdapter adapter)
 {
     foreach (MailUnsubscriptionInfo item in Unsubscriptions.Select())
     {
         foreach (MarketingListInfo list in MailListsSubscription.Select())
         {
             foreach (PXResult <CRMarketingListMember> row in
                      PXSelectJoin <CRMarketingListMember,
                                    InnerJoin <Contact, On <Contact.contactID, Equal <CRMarketingListMember.contactID> > >,
                                    Where <CRMarketingListMember.marketingListID, Equal <Required <CRMarketingList.marketingListID> >,
                                           And <Contact.eMail, Equal <Required <Contact.eMail> > > > > .
                      Select(this, list.MarketingListID, item.Email))
             {
                 var sub = (CRMarketingListMember)row;
                 sub.Activated = false;
                 MailRecipients.Update(sub);
             }
         }
     }
     Save.Press();
     SelectTimeStamp();
     return(adapter.Get());
 }
        public override void changeEmail()
        {
            base.changeEmail();
            foreach (Contact copy in Contact.Select(UserProfile.Current.PKID)
                     .RowCast <Contact>()
                     .Select(contact => (Contact)Contact.Cache.CreateCopy(contact)))
            {
                copy.EMail = UserProfile.Current.Email;
                Contact.Update(copy);
            }

            foreach (EMailSyncAccount syncAccount in SyncAccount.Select(UserProfile.Current.PKID)
                     .RowCast <EMailSyncAccount>()
                     .Select(account => (EMailSyncAccount)SyncAccount.Cache.CreateCopy(account)))
            {
                syncAccount.Address = UserProfile.Current.Email;

                syncAccount.ContactsExportDate = null;
                syncAccount.ContactsImportDate = null;
                syncAccount.EmailsExportDate   = null;
                syncAccount.EmailsImportDate   = null;
                syncAccount.TasksExportDate    = null;
                syncAccount.TasksImportDate    = null;
                syncAccount.EventsExportDate   = null;
                syncAccount.EventsImportDate   = null;

                EMailAccount mailAccount = EMailAccountsNew.Select(syncAccount.EmailAccountID);
                mailAccount.Address = syncAccount.Address;

                EMailAccountsNew.Update(mailAccount);

                SyncAccount.Update(syncAccount);
            }

            Actions.PressSave();
        }
        public void ConvertCustomerPaymentMethod(CustomerPaymentMethod cpm, CCProcessingCenter newCCPC)
        {
            CCProcessingCenterPmntMethod newProcessingCenterPM = PXSelect <CCProcessingCenterPmntMethod,
                                                                           Where <CCProcessingCenterPmntMethod.paymentMethodID, Equal <Required <CCProcessingCenterPmntMethod.paymentMethodID> >,
                                                                                  And <CCProcessingCenterPmntMethod.processingCenterID, Equal <Required <CCProcessingCenterPmntMethod.processingCenterID> > > > > .Select(this, cpm.PaymentMethodID, newCCPC.ProcessingCenterID);

            if (newProcessingCenterPM == null)
            {
                newProcessingCenterPM = (CCProcessingCenterPmntMethod)ProcessingCenterPM.Cache.CreateInstance();
                newProcessingCenterPM.PaymentMethodID    = cpm.PaymentMethodID;
                newProcessingCenterPM.ProcessingCenterID = newCCPC.ProcessingCenterID;
                ProcessingCenterPM.Insert(newProcessingCenterPM);
            }

            CustomerPaymentMethod currCPM = (CustomerPaymentMethod)CustomerPM.Cache.CreateCopy(cpm);
            var oldCCProcessingCenterID   = currCPM.CCProcessingCenterID;

            currCPM.CCProcessingCenterID = newCCPC.ProcessingCenterID;
            if (currCPM.CustomerCCPID == null)
            {
                CustomerPM.Cache.SetDefaultExt <CustomerPaymentMethod.customerCCPID>(currCPM);
            }
            currCPM.Selected   = true;
            currCPM            = CustomerPM.Update(currCPM);
            CustomerPM.Current = currCPM;

            PXResultset <PaymentMethodDetail> oldDetails = PMDetails.Select(currCPM.PaymentMethodID);

            foreach (PaymentMethodDetail oldDetail in oldDetails)
            {
                PaymentMethodDetail newDetail = (PaymentMethodDetail)PMDetails.Cache.CreateCopy(oldDetail);
                newDetail.ValidRegexp = null;
                PMDetails.Update(newDetail);
            }

            PaymentMethod       CurrPM = PM.Select();
            PaymentMethodDetail CCPID  = FindCCPID(CurrPM);

            if (CCPID == null)
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    PaymentMethodDetail res;
                    CCPID = (PaymentMethodDetail)PMDetails.Cache.CreateInstance();
                    CCPID.PaymentMethodID  = currCPM.PaymentMethodID;
                    CCPID.UseFor           = PaymentMethodDetailUsage.UseForARCards;
                    CCPID.DetailID         = "CCPID";
                    CCPID.Descr            = Messages.PaymentProfileID;
                    CCPID.IsCCProcessingID = true;
                    CCPID.IsRequired       = true;
                    res = PMDetails.Insert(CCPID);
                    if (res == null)
                    {
                        throw new PXException(Messages.CouldNotInsertPMDetail);
                    }
                    else
                    {
                        PMDetails.Cache.Persist(PXDBOperation.Insert);
                    }
                    ts.Complete();
                }
            }

            CCProcessingCenter procCenter = PXSelect <CCProcessingCenter,
                                                      Where <CCProcessingCenter.processingCenterID, Equal <Required <CCProcessingCenter.processingCenterID> > > >
                                            .Select(this, oldCCProcessingCenterID);

            bool doesOldProcCenterSupportTokenizing = CCProcessingFeatureHelper.IsFeatureSupported(procCenter, CCProcessingFeature.ProfileManagement);
            bool doesNewProcCenterSupportTokenizing = CCProcessingFeatureHelper.IsFeatureSupported(newCCPC, CCProcessingFeature.ProfileManagement);

            if (!doesOldProcCenterSupportTokenizing && doesNewProcCenterSupportTokenizing)
            {
                CustomerPaymentMethodDetail newCCPIDPM = PXSelect <CustomerPaymentMethodDetail,
                                                                   Where <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethodDetail.pMInstanceID> >,
                                                                          And <CustomerPaymentMethodDetail.paymentMethodID, Equal <Required <CustomerPaymentMethodDetail.paymentMethodID> >,
                                                                               And <CustomerPaymentMethodDetail.detailID, Equal <Required <CustomerPaymentMethodDetail.detailID> > > > > >
                                                         .Select(this, currCPM.PMInstanceID, currCPM.PaymentMethodID, CCPID.DetailID);

                if (newCCPIDPM != null)
                {
                    newCCPIDPM.Value = null;
                    CustomerPMDetails.Update(newCCPIDPM);
                }
                else
                {
                    newCCPIDPM = new CustomerPaymentMethodDetail
                    {
                        PMInstanceID    = currCPM.PMInstanceID,
                        PaymentMethodID = currCPM.PaymentMethodID,
                        DetailID        = CCPID.DetailID
                    };
                    CustomerPMDetails.Insert(newCCPIDPM);
                }
                var graph = PXGraph.CreateInstance <CCCustomerInformationManagerGraph>();
                graph.GetOrCreatePaymentProfile(this, new GenericCustomerPaymentMethodAdaper <CustomerPaymentMethod>(CustomerPM),
                                                new GenericCustomerPaymentMethodDetailAdapter <CustomerPaymentMethodDetail>(CustomerPMDetails));
            }

            if (doesNewProcCenterSupportTokenizing)
            {
                if (currCPM.CustomerCCPID == null)
                {
                    currCPM.CustomerCCPID = cpm.CustomerCCPID;
                }
                CustomerProcessingCenterID newCustomerProcessingCenterID = new CustomerProcessingCenterID
                {
                    CCProcessingCenterID = newCCPC.ProcessingCenterID,
                    BAccountID           = cpm.BAccountID,
                    CustomerCCPID        = currCPM.CustomerCCPID
                };
                AddCustomerProcessingCenterIfNeeded(newCustomerProcessingCenterID);
            }
            currCPM = CustomerPM.Update(currCPM);
            this.Save.Press();
        }
        protected virtual void _(Events.RowPersisted <INItemPlan> e)
        {
            if (e.Row == null)
            {
                return;
            }

            if (e.TranStatus == PXTranStatus.Open)
            {
                INItemPlan inItemPlanRow = (INItemPlan)e.Row;

                if (e.Operation == PXDBOperation.Update)
                {
                    if (inItemPlanRow.SupplyPlanID != null && inItemPlanRow.PlanType == INPlanConstants.PlanF6)
                    {
                        FSSODet fsSODetRow = FSSODetFixedDemand.Select(inItemPlanRow.PlanID);
                        if (fsSODetRow != null)
                        {
                            POLine poLineRow = Base.Transactions.Select().Where(x => ((POLine)x).PlanID == inItemPlanRow.SupplyPlanID).First();

                            fsSODetRow.POType    = Base.Document.Current.OrderType;
                            fsSODetRow.PONbr     = Base.Document.Current.OrderNbr;
                            fsSODetRow.POLineNbr = poLineRow.LineNbr;
                            fsSODetRow.POStatus  = Base.Document.Current.Status;

                            FSSODetFixedDemand.Update(fsSODetRow);
                            FSSODetFixedDemand.Cache.Persist(PXDBOperation.Update);

                            FSSODetSplit fsSODetSplitRow = FSSODetSplitFixedDemand.Select(inItemPlanRow.PlanID);
                            if (fsSODetSplitRow != null)
                            {
                                fsSODetSplitRow.POType    = Base.Document.Current.OrderType;
                                fsSODetSplitRow.PONbr     = Base.Document.Current.OrderNbr;
                                fsSODetSplitRow.POLineNbr = poLineRow.LineNbr;

                                FSSODetSplitFixedDemand.Update(fsSODetSplitRow);
                                FSSODetSplitFixedDemand.Cache.Persist(PXDBOperation.Update);
                            }
                        }
                    }
                }
                else if (e.Operation == PXDBOperation.Delete &&
                         (inItemPlanRow.PlanType == INPlanConstants.PlanF7 || inItemPlanRow.PlanType == INPlanConstants.PlanF8)
                         )
                {
                    inItemPlanRow = PXSelect <INItemPlan, Where <INItemPlan.supplyPlanID, Equal <Required <INItemPlan.supplyPlanID> > > > .Select(Base, inItemPlanRow.PlanID);

                    if (inItemPlanRow != null && inItemPlanRow.SupplyPlanID != null)
                    {
                        FSSODet fsSODetRow = FSSODetFixedDemand.Select(inItemPlanRow.PlanID);

                        if (fsSODetRow != null)
                        {
                            fsSODetRow.POType    = null;
                            fsSODetRow.PONbr     = null;
                            fsSODetRow.POLineNbr = null;
                            fsSODetRow.POStatus  = null;

                            FSSODetFixedDemand.Update(fsSODetRow);
                            FSSODetFixedDemand.Cache.Persist(PXDBOperation.Update);

                            inItemPlanRow.SupplyPlanID = null;
                            Base.Caches[typeof(INItemPlan)].Update(inItemPlanRow);
                            Base.Caches[typeof(INItemPlan)].Persist(PXDBOperation.Update);

                            FSSODetSplit fsSODetSplitRow = FSSODetSplitFixedDemand.Select(inItemPlanRow.PlanID);
                            if (fsSODetSplitRow != null)
                            {
                                fsSODetSplitRow.POType    = null;
                                fsSODetSplitRow.PONbr     = null;
                                fsSODetSplitRow.POLineNbr = null;

                                FSSODetSplitFixedDemand.Update(fsSODetSplitRow);
                                FSSODetSplitFixedDemand.Cache.Persist(PXDBOperation.Update);
                            }
                        }
                    }
                }
            }
        }
Exemple #24
0
        public void ConvertCustomerPaymentMethod(CustomerPaymentMethod cpm, CCProcessingCenter newCCPC)
        {
            CCProcessingCenterPmntMethod newProcessingCenterPM = PXSelect <CCProcessingCenterPmntMethod,
                                                                           Where <CCProcessingCenterPmntMethod.paymentMethodID, Equal <Required <CCProcessingCenterPmntMethod.paymentMethodID> >,
                                                                                  And <CCProcessingCenterPmntMethod.processingCenterID, Equal <Required <CCProcessingCenterPmntMethod.processingCenterID> > > > > .Select(this, cpm.PaymentMethodID, newCCPC.ProcessingCenterID);

            if (newProcessingCenterPM == null)
            {
                newProcessingCenterPM = (CCProcessingCenterPmntMethod)ProcessingCenterPM.Cache.CreateInstance();
                newProcessingCenterPM.PaymentMethodID    = cpm.PaymentMethodID;
                newProcessingCenterPM.ProcessingCenterID = newCCPC.ProcessingCenterID;
                ProcessingCenterPM.Insert(newProcessingCenterPM);
            }

            CustomerPaymentMethod currCPM = (CustomerPaymentMethod)CustomerPM.Cache.CreateCopy(cpm);

            currCPM.CCProcessingCenterID = newCCPC.ProcessingCenterID;
            CustomerPM.Cache.SetDefaultExt <CustomerPaymentMethod.customerCCPID>(currCPM);

            currCPM.Selected   = true;
            currCPM            = CustomerPM.Update(currCPM);
            CustomerPM.Current = currCPM;

            PXResultset <PaymentMethodDetail> oldDetails = PMDetails.Select(currCPM.PaymentMethodID);

            foreach (PaymentMethodDetail oldDetail in oldDetails)
            {
                PaymentMethodDetail newDetail = (PaymentMethodDetail)PMDetails.Cache.CreateCopy(oldDetail);
                newDetail.ValidRegexp = null;
                PMDetails.Update(newDetail);
            }

            PaymentMethod       CurrPM = PM.Select();
            PaymentMethodDetail CCPID  = FindCCPID(CurrPM);

            if (CCPID == null)
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    PaymentMethodDetail res;
                    CCPID = (PaymentMethodDetail)PMDetails.Cache.CreateInstance();
                    CCPID.PaymentMethodID  = currCPM.PaymentMethodID;
                    CCPID.UseFor           = PaymentMethodDetailUsage.UseForARCards;
                    CCPID.DetailID         = "CCPID";
                    CCPID.Descr            = "Payment Profile ID";
                    CCPID.IsCCProcessingID = true;
                    CCPID.IsRequired       = true;
                    res = PMDetails.Insert(CCPID);
                    if (res == null)
                    {
                        throw new PXException(Messages.CouldNotInsertPMDetail);
                    }
                    else
                    {
                        PMDetails.Cache.Persist(PXDBOperation.Insert);
                    }
                    ts.Complete();
                }
            }

            CustomerPaymentMethodDetail newCCPIDPM = PXSelect <CustomerPaymentMethodDetail, Where <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethodDetail.pMInstanceID> >,
                                                                                                   And <CustomerPaymentMethodDetail.paymentMethodID, Equal <Required <CustomerPaymentMethodDetail.paymentMethodID> >,
                                                                                                        And <CustomerPaymentMethodDetail.detailID, Equal <Required <CustomerPaymentMethodDetail.detailID> > > > > > .Select(this, currCPM.PMInstanceID, currCPM.PaymentMethodID, CCPID.DetailID);

            if (newCCPIDPM != null)
            {
                newCCPIDPM.Value = null;
                CustomerPMDetails.Update(newCCPIDPM);
            }
            else
            {
                newCCPIDPM = new CustomerPaymentMethodDetail();
                newCCPIDPM.PMInstanceID    = currCPM.PMInstanceID;
                newCCPIDPM.PaymentMethodID = currCPM.PaymentMethodID;
                newCCPIDPM.DetailID        = CCPID.DetailID;
                CustomerPMDetails.Insert(newCCPIDPM);
            }

            CustomerPaymentMethodMaint.SyncNewPMI(this, CustomerPM, CustomerPMDetails);
            currCPM.Converted = true;
            currCPM           = CustomerPM.Update(currCPM);
            this.Save.Press();
        }
        protected virtual void Users_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e)
        {
            Users oldRow = e.Row as Users;
            Users row    = e.NewRow as Users;

            if (row == null || oldRow == null)
            {
                return;
            }

            if (oldRow.ContactID != row.ContactID)
            {
                foreach (PXResult <Contact, EPEmployee> set in PXSelectJoin <Contact,
                                                                             LeftJoin <EPEmployee, On <Contact.contactID, Equal <EPEmployee.defContactID>,
                                                                                                       And <Contact.bAccountID, Equal <EPEmployee.parentBAccountID> > > >,
                                                                             Where <Contact.userID, Equal <Current <Users.pKID> > > > .SelectMultiBound(this, new object[] { oldRow }))
                {
                    var(cont, emp) = set;
                    cont.UserID    = null;
                    contact.Update(cont);

                    if (emp != null)
                    {
                        emp.UserID = null;
                        Employee.Update(emp);
                    }
                }

                Contact newContact = PXSelect <Contact, Where <Contact.contactID, Equal <Current <Users.contactID> > > > .SelectSingleBound(this, new object[] { row });

                if (newContact != null)
                {
                    newContact.UserID = row.PKID;
                    contact.Update(newContact);

                    EPEmployee emp = PXSelectJoin <EPEmployee,
                                                   InnerJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID>,
                                                                           And <Contact.bAccountID, Equal <EPEmployee.parentBAccountID> > > >,
                                                   Where <Contact.contactID, Equal <Required <Contact.contactID> > > > .Select(this, newContact.ContactID);

                    if (emp != null)
                    {
                        emp = PXCache <EPEmployee> .CreateCopy(emp);

                        emp.UserID = row.PKID;
                        Employee.Update(emp);
                    }
                }
            }

            if (row.Guest == true && oldRow.Guest != true)
            {
                if (contact.View.Ask(
                        MyMessages.EmployeeContactWouldBeCleared,
                        MessageButtons.YesNo) != WebDialogResult.Yes)
                {
                    e.Cancel = true;
                }
            }
            else if (row.Guest != true && oldRow.Guest == true)
            {
                if (contact.View.Ask(
                        MyMessages.ExternalUserContactWouldBeCleared,
                        MessageButtons.YesNo) != WebDialogResult.Yes)
                {
                    e.Cancel = true;
                }
            }
        }
        protected virtual IEnumerable filteredItems([PXString] string action)
        {
            if (!String.Equals(Operations.Current.Action, action, StringComparison.OrdinalIgnoreCase))
            {
                FilteredItems.Cache.Clear();
            }
            Operations.Current.Action = action;

            var mailListID = MailLists.Current.With(ml => ml.MarketingListID);

            //Dinamic)
            if (MailLists.Current.With(ml => ml.IsDynamic == true))
            {
                return(CRSubscriptionsSelect.Select(this, mailListID));
            }

            CRSubscriptionsSelect.MergeFilters(this, mailListID);

            if (_ProcessPending)
            {
                _ProcessPending = false;
                Contact saved = FilteredItems.Current;
                var     list  = new List <Contact>();
                int     start = 0;
                int     total = 0;
                foreach (PXResult <Contact> item in FilteredItems.View.Select(null, new object[] { action }, null, null, null, PXView.Filters, ref start, 0, ref total))
                {
                    ((Contact)item).Selected = true;
                    FilteredItems.Update(item);
                    list.Add(((Contact)item));
                }
                FilteredItems.Current       = saved;
                FilteredItems.Cache.IsDirty = false;
                PerformAction(list);
                PXRedirectHelper.TryRedirect(this, PXRedirectHelper.WindowMode.Same);
            }

            //Remove
            if (string.Equals(Operations.Current.Action, REMOVE_ACTION, StringComparison.OrdinalIgnoreCase))
            {
                return(this.QuickSelect(RemoveItems.View.BqlSelect, PXView.Filters));
            }

            //Add
            var command = FilteredItems.View.BqlSelect;

            if (MailLists.Current.With(ml => ml.NoCall == true))
            {
                command = command.WhereAnd(
                    typeof(Where <Contact.noCall, IsNull,
                                  Or <Contact.noCall, NotEqual <True> > >));
            }
            if (MailLists.Current.With(ml => ml.NoEMail == true))
            {
                command = command.WhereAnd(
                    typeof(Where <Contact.noEMail, IsNull,
                                  Or <Contact.noEMail, NotEqual <True> > >));
            }
            if (MailLists.Current.With(ml => ml.NoFax == true))
            {
                command = command.WhereAnd(
                    typeof(Where <Contact.noFax, IsNull,
                                  Or <Contact.noFax, NotEqual <True> > >));
            }
            if (MailLists.Current.With(ml => ml.NoMail == true))
            {
                command = command.WhereAnd(
                    typeof(Where <Contact.noMail, IsNull,
                                  Or <Contact.noMail, NotEqual <True> > >));
            }
            if (MailLists.Current.With(ml => ml.NoMarketing == true))
            {
                command = command.WhereAnd(
                    typeof(Where <Contact.noMarketing, IsNull,
                                  Or <Contact.noMarketing, NotEqual <True> > >));
            }
            if (MailLists.Current.With(ml => ml.NoMassMail == true))
            {
                command = command.WhereAnd(
                    typeof(Where <Contact.noMassMail, IsNull,
                                  Or <Contact.noMassMail, NotEqual <True> > >));
            }

            return(this.QuickSelect(command, PXView.Filters));
        }
        private void UnmatchBankTran(CABankTran origTran, bool isMassRelease)
        {
            if (origTran.DocumentMatched != true)
            {
                return;
            }

            CABankTran copy = (CABankTran)Details.Cache.CreateCopy(origTran);

            copy.Processed = false;
            foreach (CABankTranMatch match in TranMatch.Select(copy.TranID))
            {
                if (match.DocModule == GL.BatchModule.AP && match.DocType == CATranType.CABatch)
                {
                    foreach (CATran tran in CATransInBatch.Select(match.DocRefNbr))
                    {
                        if (tran != null && tran.TranID != null && tran.ReconNbr == null)
                        {
                            tran.ClearDate = null;
                            tran.Cleared   = false;
                            CATransInBatch.Update(tran);
                        }
                    }
                }
                else
                {
                    CATran tran = CATrans.Select(match.CATranID);
                    if (tran != null && tran.TranID != null && tran.ReconNbr == null)
                    {
                        tran.ClearDate = null;
                        tran.Cleared   = false;
                        CATrans.Update(tran);
                    }
                }

                if (CABankTransactionsMaint.IsMatchedToExpenseReceipt(match))
                {
                    EPExpenseClaimDetails receipt =
                        PXSelect <EPExpenseClaimDetails,
                                  Where <EPExpenseClaimDetails.claimDetailCD,
                                         Equal <Required <EPExpenseClaimDetails.claimDetailCD> > > >
                        .Select(this, match.DocRefNbr);

                    receipt.BankTranDate = null;

                    ExpenseReceipts.Update(receipt);
                }

                TranMatch.Delete(match);
            }
            foreach (var adj in TranAdj.Select(copy.TranID))
            {
                TranAdj.Delete(adj);
            }
            foreach (var split in CABankTranSplits.Select(copy.TranID))
            {
                CABankTranSplits.Delete(split);
            }
            CABankTransactionsMaint.ClearFields(copy);
            Details.Cache.SetDefaultExt <CABankTran.curyApplAmt>(copy);
            Details.Cache.SetDefaultExt <CABankTran.curyApplAmtCA>(copy);
            Details.Cache.SetDefaultExt <CABankTran.curyApplAmtMatch>(copy);
            Details.Update(copy);
            if (isMassRelease == false)
            {
                this.Save.Press();
            }
        }
        private void UpdatePhysicalQty()
        {
            INBarCodeItem item = AddByBarCode.Current;
            INPIHeader    d    = this.PIHeader.Current;

            this.SelectTimeStamp();

            using (PXTransactionScope sc = new PXTransactionScope())
            {
                INPIDetail detail =
                    PXSelectReadonly <INPIDetail,
                                      Where <INPIDetail.pIID, Equal <Current <INPIHeader.pIID> >,
                                             And <INPIDetail.inventoryID, Equal <Current <INBarCodeItem.inventoryID> >,
                                                  And <INPIDetail.subItemID, Equal <Current <INBarCodeItem.subItemID> >,
                                                       And <INPIDetail.locationID, Equal <Current <INBarCodeItem.locationID> >,
                                                            And <Where <INPIDetail.lotSerialNbr, IsNull,
                                                                        Or <INPIDetail.lotSerialNbr, Equal <Current <INBarCodeItem.lotSerialNbr> > > > > > > > > > .SelectWindowed(this, 0, 1);


                if (detail == null)
                {
                    INPIEntry entry = PXGraph.CreateInstance <INPIEntry>();
                    entry.PIHeader.Current = entry.PIHeader.Search <INPIHeader.pIID>(d.PIID);

                    detail = new INPIDetail {
                        InventoryID = item.InventoryID
                    };
                    detail = PXCache <INPIDetail> .CreateCopy(entry.PIDetail.Insert(detail));

                    detail.SubItemID    = item.SubItemID;
                    detail.LocationID   = item.LocationID;
                    detail.LotSerialNbr = item.LotSerialNbr;
                    detail = PXCache <INPIDetail> .CreateCopy(entry.PIDetail.Update(detail));

                    detail.PhysicalQty = item.Qty;
                    detail.ExpireDate  = item.ExpireDate;
                    entry.PIDetail.Update(detail);

                    entry.Save.Press();
                    var detailId = entry.PIDetail.Cache.GetValue(detail, nameof(INPIDetail.PIID));
                    var lineNbr  = entry.PIDetail.Cache.GetValue(detail, nameof(INPIDetail.LineNbr));
                    PIHeader.View.RequestRefresh();
                    PIDetail.Cache.Locate(new Dictionary <string, object>()
                    {
                        { nameof(INPIDetail.PIID), detailId }, { nameof(INPIDetail.LineNbr), lineNbr }
                    });
                }
                else
                {
                    detail = PXCache <INPIDetail> .CreateCopy(detail);

                    detail.PhysicalQty = detail.PhysicalQty.GetValueOrDefault() + item.Qty.GetValueOrDefault();
                    PIDetail.Update(detail);
                }

                sc.Complete();

                item.Description = PXMessages.LocalizeFormatNoPrefixNLA(Messages.PILineUpdated,
                                                                        AddByBarCode.GetValueExt <INBarCodeItem.inventoryID>(item).ToString().Trim(),
                                                                        Setup.Current.UseInventorySubItem == true ? ":" + AddByBarCode.GetValueExt <INBarCodeItem.subItemID>(item) : string.Empty,
                                                                        AddByBarCode.GetValueExt <INBarCodeItem.qty>(item),
                                                                        item.UOM,
                                                                        detail.LineNbr);
            }
            AddByBarCode.Reset(true);
            this.AddByBarCode.View.RequestRefresh();
            this.SelectTimeStamp();
        }
		private void DoConvert(CustomerPaymentMethod cpm, CCProcessingCenter newCCPC)
		{
			CCProcessingCenterPmntMethod newProcessingCenterPM = PXSelect<CCProcessingCenterPmntMethod,
				Where<CCProcessingCenterPmntMethod.paymentMethodID, Equal<Required<CCProcessingCenterPmntMethod.paymentMethodID>>,
				And<CCProcessingCenterPmntMethod.processingCenterID, Equal<Required<CCProcessingCenterPmntMethod.processingCenterID>>>>>.Select(this, cpm.PaymentMethodID, newCCPC.ProcessingCenterID);
			if (newProcessingCenterPM == null)
			{
				newProcessingCenterPM = (CCProcessingCenterPmntMethod)ProcessingCenterPM.Cache.CreateInstance();
				newProcessingCenterPM.PaymentMethodID = cpm.PaymentMethodID;
				newProcessingCenterPM.ProcessingCenterID = newCCPC.ProcessingCenterID;
				ProcessingCenterPM.Insert(newProcessingCenterPM);
			}

			CustomerPaymentMethod currCPM = (CustomerPaymentMethod)CustomerPM.Cache.CreateCopy(cpm);
			var oldCCProcessingCenterID = currCPM.CCProcessingCenterID;
			currCPM.CCProcessingCenterID = newCCPC.ProcessingCenterID;
			if (currCPM.CustomerCCPID == null)
			{
				CustomerPM.Cache.SetDefaultExt<CustomerPaymentMethod.customerCCPID>(currCPM);
			}
			currCPM.Selected = true;
			currCPM = CustomerPM.Update(currCPM);
			CustomerPM.Current = currCPM;

			PXResultset<PaymentMethodDetail> oldDetails = PMDetails.Select(currCPM.PaymentMethodID);
			foreach (PaymentMethodDetail oldDetail in oldDetails)
			{
				PaymentMethodDetail newDetail = (PaymentMethodDetail)PMDetails.Cache.CreateCopy(oldDetail);
				newDetail.ValidRegexp = null;
				PMDetails.Update(newDetail);
			}

			PaymentMethod CurrPM = PM.Select();
			PaymentMethodDetail CCPID = FindCCPID(CurrPM);

			if (CCPID == null)
			{
				using (PXTransactionScope ts = new PXTransactionScope())
				{
					PaymentMethodDetail res;
					CCPID = (PaymentMethodDetail)PMDetails.Cache.CreateInstance();
					CCPID.PaymentMethodID = currCPM.PaymentMethodID;
					CCPID.UseFor = PaymentMethodDetailUsage.UseForARCards;
					CCPID.DetailID = "CCPID";
					CCPID.Descr = Messages.PaymentProfileID;
					CCPID.IsCCProcessingID = true;
					CCPID.IsRequired = true;
					res = PMDetails.Insert(CCPID);
					if (res == null)
					{
						throw new PXException(Messages.CouldNotInsertPMDetail);
					}
					else
					{
						PMDetails.Cache.Persist(PXDBOperation.Insert);
					}
					ts.Complete();
				}
			}

			CCProcessingCenter procCenter = PXSelect<CCProcessingCenter,
				Where<CCProcessingCenter.processingCenterID, Equal<Required<CCProcessingCenter.processingCenterID>>>>
					.Select(this, oldCCProcessingCenterID);
			bool oldProcCenterSupportTokenizing = ProcCenterSupportTokenizing(oldCCProcessingCenterID);
			bool newProcCenterSupportTokenizing = ProcCenterSupportTokenizing(newCCPC.ProcessingCenterID);

			if (!oldProcCenterSupportTokenizing && newProcCenterSupportTokenizing)
			{
				CustomerPaymentMethodDetail newCCPIDPM = PXSelect<CustomerPaymentMethodDetail,
					Where<CustomerPaymentMethodDetail.pMInstanceID, Equal<Required<CustomerPaymentMethodDetail.pMInstanceID>>,
						And<CustomerPaymentMethodDetail.paymentMethodID, Equal<Required<CustomerPaymentMethodDetail.paymentMethodID>>,
						And<CustomerPaymentMethodDetail.detailID, Equal<Required<CustomerPaymentMethodDetail.detailID>>>>>>
							.Select(this, currCPM.PMInstanceID, currCPM.PaymentMethodID, CCPID.DetailID);
				if (newCCPIDPM != null)
				{
					newCCPIDPM.Value = null;
					CustomerPMDetails.Update(newCCPIDPM);
				}
				else
				{
					newCCPIDPM = new CustomerPaymentMethodDetail
					{
						PMInstanceID = currCPM.PMInstanceID,
						PaymentMethodID = currCPM.PaymentMethodID,
						DetailID = CCPID.DetailID
					};
					CustomerPMDetails.Insert(newCCPIDPM);
				}
				var graph = PXGraph.CreateInstance<CCCustomerInformationManagerGraph>();
				ICCPaymentProfileAdapter paymentProfile = new GenericCCPaymentProfileAdapter<CustomerPaymentMethod>(CustomerPM);
				ICCPaymentProfileDetailAdapter profileDetail = new GenericCCPaymentProfileDetailAdapter<CustomerPaymentMethodDetail,
					PaymentMethodDetail>(CustomerPMDetails, PMDetails);
				DateTime expiredDate;
				if (CheckCardIsExpired(currCPM, out expiredDate))
				{
					Customer cust =  new PXSelect<Customer, 
						Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>(this)
							.SelectSingle(currCPM.BAccountID);
					throw new PXException(AR.Messages.ERR_CCCreditCardHasExpired, expiredDate.ToString("d"), cust.AcctCD);
				}
				graph.GetOrCreatePaymentProfile(this, paymentProfile, profileDetail);
			}

			if (newProcCenterSupportTokenizing)
			{
				if (currCPM.CustomerCCPID == null)
				{
					currCPM.CustomerCCPID = cpm.CustomerCCPID;
				}
				CustomerProcessingCenterID newCustomerProcessingCenterID = new CustomerProcessingCenterID
				{
					CCProcessingCenterID = newCCPC.ProcessingCenterID,
					BAccountID = cpm.BAccountID,
					CustomerCCPID = currCPM.CustomerCCPID
				};
				AddCustomerProcessingCenterIfNeeded(newCustomerProcessingCenterID);
			}
			currCPM = CustomerPM.Update(currCPM);
		}