Exemplo n.º 1
0
        public virtual void DoConvert(bool redirect)
        {
            ConversionResult <BAccount> result;

            using (var ts = new PXTransactionScope())
            {
                result = AccountExt.Convert(new AccountConversionOptions
                {
                    HoldCurrentsCallback = ContactExt.HoldCurrents
                });

                var contact = ContactExt.Convert(new ContactConversionOptions
                {
                    GraphWithRelation = result.Graph
                });

                if (AccountExt.Documents.Current.RefContactID == null)
                {
                    throw new PXException(Messages.CannotCreateAccount);
                }

                ts.Complete();
            }

            if (redirect)
            {
                AccountExt.Redirect(result);
            }
        }
        public virtual void DoConvert(bool redirect)
        {
            ConversionResult <CROpportunity> result;

            using (var ts = new PXTransactionScope())
            {
                // to save original value because it would be changed during contact/account creation
                var overrideContact =
                    OpportunityExt.Documents.Cache.GetValueOriginal <Document.overrideRefContact>(OpportunityExt.Documents.Current) as bool?;

                var account = AccountExt.Convert(new AccountConversionOptions
                {
                    HoldCurrentsCallback = AccountExt.JoinHoldCurrents(ContactExt.HoldCurrents, OpportunityExt.HoldCurrents)
                });

                var contact = ContactExt.Convert(new ContactConversionOptions
                {
                    HoldCurrentsCallback = OpportunityExt.HoldCurrents,
                    GraphWithRelation    = account.Graph
                });

                result = OpportunityExt.Convert(new OpportunityConversionOptions
                {
                    ForceOverrideContact = overrideContact,
                });

                if (OpportunityExt.Documents.Current.RefContactID == null)
                {
                    throw new PXException(Messages.CannotCreateOpportunity);
                }

                ts.Complete();
            }

            if (redirect)
            {
                OpportunityExt.Redirect(result);
            }
        }
Exemplo n.º 3
0
        public virtual IEnumerable createBothContactAndAccount(PXAdapter adapter)
        {
            var existingContact = ContactExt.ExistingContact.SelectSingle();
            var existingAccount = AccountExt.ExistingAccount.SelectSingle();

            if (existingContact?.BAccountID != null && existingAccount == null)
            {
                AccountExt.Documents.Cache.SetValue <Document.bAccountID>(AccountExt.Documents.Current, existingContact.BAccountID);

                Base.Caches <TMaster>().Update(AccountExt.GetMainCurrent());

                throw new PXSetPropertyException(Messages.AccountAlreadyExists);
            }

            if (AccountExt.AskExtConvert(out bool redirect, ContactExt.PopupValidator))
            {
                PXLongOperation.StartOperation(Base, () =>
                {
                    DoConvert(redirect);
                });
            }
            return(adapter.Get());
        }
        public virtual IEnumerable convertToOpportunityAll(PXAdapter adapter)
        {
            var existingContact = ContactExt.ExistingContact.SelectSingle();
            var existingAccount = AccountExt.ExistingAccount.SelectSingle();

            if (existingContact?.BAccountID != null && existingAccount == null)
            {
                AccountExt.Documents.Cache.SetValue <Document.bAccountID>(AccountExt.Documents.Current, existingContact.BAccountID);

                Base.Caches <TMaster>().Update(AccountExt.GetMainCurrent());
            }

            if (OpportunityExt.AskExtConvert(out bool redirect,
                                             ContactExt.PopupValidator, AccountExt.PopupValidator))
            {
                PXLongOperation.StartOperation(Base, () =>
                {
                    DoConvert(redirect);
                });
            }

            return(adapter.Get());
        }