public virtual void CRSetup_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
 {
     if (!sender.ObjectsEqual <CRSetup.contactEmailUnique, CRSetup.leadValidationThreshold>(e.Row, e.OldRow))
     {
         CRSetup row = (CRSetup)e.Row;
         LeadContactValidationRules rule = LeadContactValidationRules.Search <CRValidationRules.matchingField>(typeof(Contact.eMail).Name);
         if (row.ContactEmailUnique == true)
         {
             var emailRule = (LeadContactValidationRules)(LeadContactValidationRules.Cache.CreateCopy(rule ?? LeadContactValidationRules.Cache.CreateInstance()));
             emailRule.ValidationType     = ValidationTypesAttribute.LeadContact;
             emailRule.MatchingField      = this.Caches[typeof(Contact)].GetField(typeof(Contact.eMail));
             emailRule.TransformationRule = TransformationRulesAttribute.None;
             emailRule.ScoreWeight        = row.LeadValidationThreshold;
             LeadContactValidationRules.Update(emailRule);
         }
         else
         {
             if (rule != null)
             {
                 LeadContactValidationRules.Cache.SetDefaultExt <CRValidationRules.scoreWeight>(rule);
                 LeadContactValidationRules.Cache.SetDefaultExt <CRValidationRules.transformationRule>(rule);
                 LeadContactValidationRules.Update(rule);
             }
         }
     }
 }
Beispiel #2
0
        private void UpdateGrammValidationDate()
        {
            CRSetup record = PXCache <CRSetup> .CreateCopy(this.CRSetupRecord.Current) as CRSetup;

            record.GrammValidationDateTime = null;
            CRSetupRecord.Update(record);
        }
Beispiel #3
0
        public IEnumerable AddMailActivity(PXAdapter adapter, string emailAddress)
        {
            if (!IsCurrentRedy)
            {
                return(adapter.Get());
            }
            PrepareGraph();

            CRActivityMaint graph    = CreateSpecGraph <CRActivityMaint>();
            CRActivity      activity = CreateActivity();
            CRSetup         setup    = PXSelect <CRSetup> .Select(this.Graph);

            activity.Type           = setup.EMailActivityType;
            activity.Status         = ActivityStatus.NotStarted;
            graph.Activites.Current = graph.Activites.Insert(activity);
            PXAdapter mailCreate = new PXAdapter(graph.Activites);

            mailCreate.StartRow    = 0;
            mailCreate.MaximumRows = 1;
            foreach (object e in graph.CreateMail.Press(mailCreate))
            {
                ;
            }
            if (!string.IsNullOrEmpty(emailAddress))
            {
                graph.Message.Current.MailTo = emailAddress;
            }

            throw new PXPopupRedirectException(true, graph, Messages.CRActivityMaint);
        }
Beispiel #4
0
        protected virtual void CRSetup_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            CRSetup row = e.Row as CRSetup;

            if (row != null && row.GrammValidationDateTime == null)
            {
                row.GrammValidationDateTime = PXTimeZoneInfo.Now;
            }
        }
Beispiel #5
0
        protected virtual void _(Events.RowDeleted <CRContactClass> e)
        {
            var row = e.Row;

            if (row == null)
            {
                return;
            }

            CRSetup s = Setup.Select();

            if (s != null && (s.DefaultContactClassID == row.ClassID))
            {
                s.DefaultContactClassID = null;
                Setup.Update(s);
            }
        }
Beispiel #6
0
        protected virtual void CROpportunityClass_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
        {
            var row = e.Row as CROpportunityClass;

            if (row == null)
            {
                return;
            }

            CRSetup s = Setup.Select();

            if (s != null && s.DefaultOpportunityClassID == row.CROpportunityClassID)
            {
                s.DefaultOpportunityClassID = null;
                Setup.Update(s);
            }
        }
        protected virtual void CRPurgeFilter_PurgePeriodWithoutActivity_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            if (e.NewValue == null)
            {
                return;
            }

            int     val     = (int)e.NewValue;
            CRSetup crSetup = setup.Current;

            if (val < 0)
            {
                throw new PXSetPropertyException(Messages.PurgeLimitCannotBeNegative);
            }
            if (crSetup.PurgePeriodWithoutActivity != null && val < crSetup.PurgePeriodWithoutActivity)
            {
                throw new PXSetPropertyException(Messages.PurgeLimitCannotBeLessThanInCRSetup);
            }
        }
Beispiel #8
0
        protected virtual void CRContactClass_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
        {
            var row = e.Row as CRContactClass;

            if (row == null)
            {
                return;
            }

            CRSetup s = Setup.Select();

            if (s != null && (s.DefaultLeadClassID == row.ClassID))
            {
                s.DefaultLeadClassID = null;
                Setup.Update(s);
            }

            if (s != null && (s.DefaultContactClassID == row.ClassID))
            {
                s.DefaultContactClassID = null;
                Setup.Update(s);
            }
        }
        public static void ConvertToAccount(Contact contact, AccountsFilter param)
        {
            BusinessAccountMaint accountMaint = CreateInstance <BusinessAccountMaint>();
            object cd = param.BAccountID;

            accountMaint.BAccount.Cache.RaiseFieldUpdating <BAccount.acctCD>(null, ref cd);
            BAccount account = new BAccount
            {
                AcctCD           = (string)cd,
                AcctName         = param.AccountName,
                Type             = BAccountType.ProspectType,
                ClassID          = param.AccountClass,
                ParentBAccountID = contact.ParentBAccountID
            };

            #region Set Contact and Address fields
            CRContactClass cls = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Current <Contact.classID> > > > .SelectSingleBound(accountMaint, new object[] { contact });

            if (cls != null && cls.OwnerToBAccount == true)
            {
                account.WorkgroupID = contact.WorkgroupID;
                account.OwnerID     = contact.OwnerID;
            }

            try
            {
                object newValue = account.OwnerID;
                accountMaint.BAccount.Cache.RaiseFieldVerifying <BAccount.ownerID>(account, ref newValue);
            }
            catch (PXSetPropertyException)
            {
                account.OwnerID = null;
            }

            account = accountMaint.BAccount.Insert(account);

            accountMaint.Answers.CopyAllAttributes(account, contact);

            Contact defContact = PXCache <Contact> .CreateCopy(PXSelect <Contact, Where <Contact.contactID, Equal <Current <BAccount.defContactID> > > > .SelectSingleBound(accountMaint, new object[] { account }));

            var defContactNoteID = defContact.NoteID;
            PXCache <Contact> .RestoreCopy(defContact, contact);

            defContact.ContactType     = ContactTypesAttribute.BAccountProperty;
            defContact.FullName        = account.AcctName;
            defContact.ContactID       = account.DefContactID;
            defContact.BAccountID      = account.BAccountID;
            defContact.DuplicateStatus = DuplicateStatusAttribute.NotValidated;
            defContact.DuplicateFound  = false;
            defContact.WorkgroupID     = null;
            defContact.OwnerID         = null;
            defContact.NoteID          = defContactNoteID;
            defContact = accountMaint.DefContact.Update(defContact);

            Address contactAddress = PXSelect <Address, Where <Address.addressID, Equal <Required <Contact.defAddressID> > > > .Select(accountMaint, contact.DefAddressID);

            if (contactAddress == null)
            {
                throw new PXException(Messages.DefAddressNotExists, contact.DisplayName);
            }
            contactAddress.BAccountID = account.BAccountID;
            accountMaint.AddressCurrent.Cache.Clear();

            defContact.DefAddressID = contactAddress.AddressID;
            defContact = accountMaint.DefContact.Update(defContact);

            contactAddress = accountMaint.AddressCurrent.Update(contactAddress);

            account.DefAddressID = contactAddress.AddressID;
            accountMaint.BAccount.Update(account);

            contact.BAccountID      = account.BAccountID;
            contact.DuplicateStatus = DuplicateStatusAttribute.NotValidated;
            contact.DuplicateFound  = false;
            if (contact.QualificationDate == null)
            {
                contact.QualificationDate = PXTimeZoneInfo.Now;
            }
            accountMaint.Contacts.Cache.SetStatus(contact, PXEntryStatus.Updated);
            CR.Location location = accountMaint.DefLocation.Select();
            location.DefAddressID = contactAddress.AddressID;
            accountMaint.DefLocation.Update(location);

            account.NoteID = PXNoteAttribute.GetNoteID <CRActivity.noteID>(accountMaint.CurrentBAccount.Cache, account);
            foreach (CRPMTimeActivity a in PXSelect <CRPMTimeActivity, Where <CRPMTimeActivity.refNoteID, Equal <Required <Contact.noteID> > > > .Select(accountMaint, contact.NoteID))
            {
                a.BAccountID = account.BAccountID;
                accountMaint.Activities.Cache.Update(a);
            }
            #endregion

            // Copy Note text and Files references
            CRSetup setup = PXSetupOptional <CRSetup> .Select(accountMaint);

            PXNoteAttribute.CopyNoteAndFiles(accountMaint.Contacts.Cache, contact, accountMaint.CurrentBAccount.Cache, account, setup);

            throw new PXRedirectRequiredException(accountMaint, "Business Account");
        }
        public virtual IEnumerable ConvertToOpportunity(PXAdapter adapter)
        {
            Save.Press();
            bool           isOpportunityAutoNumberOn = this.IsNumberingAutonumbered(Setup.Current.OpportunityNumberingID);
            List <Contact> contacts = new List <Contact>(adapter.Get().Cast <Contact>());

            foreach (Contact l in contacts)
            {
                OpportunityMaint opportunityMaint = CreateInstance <OpportunityMaint>();
                CROpportunity    opportunity      = (CROpportunity)opportunityMaint.Opportunity.Cache.Insert();

                if (!isOpportunityAutoNumberOn)
                {
                    if (OpportunityInfo.AskExt() != WebDialogResult.OK || !OpportunityInfo.VerifyRequired())
                    {
                        return(contacts);
                    }
                    CROpportunity existing = PXSelect <CROpportunity, Where <CROpportunity.opportunityID, Equal <Required <CROpportunity.opportunityID> > > > .SelectSingleBound(this, null, OpportunityInfo.Current.OpportunityID);

                    if (existing != null)
                    {
                        OpportunityInfo.Cache.RaiseExceptionHandling <OpportunityFilter.opportunityID>(OpportunityInfo.Current, OpportunityInfo.Current.OpportunityID, new PXSetPropertyException(Messages.OpportunityAlreadyExists, OpportunityInfo.Current.OpportunityID));
                        return(contacts);
                    }

                    object cd = OpportunityInfo.Current.OpportunityID;
                    opportunityMaint.Opportunity.Cache.RaiseFieldUpdating <CROpportunity.opportunityID>(null, ref cd);
                    opportunity.OpportunityID = (string)cd;
                }
                Contact lead = l;
                PXLongOperation.StartOperation(this, delegate()
                {
                    CRContactClass cls = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Current <Contact.classID> > > > .SelectSingleBound(this, new object[] { lead });
                    if (cls != null && cls.OwnerToOpportunity == true)
                    {
                        opportunity.WorkgroupID = lead.WorkgroupID;
                        opportunity.OwnerID     = lead.OwnerID;
                    }
                    if (cls != null && cls.TargetOpportunityClassID != null)
                    {
                        opportunity.CROpportunityClassID = cls.TargetOpportunityClassID;
                    }

                    if (lead.BAccountID != null)
                    {
                        opportunity.BAccountID = lead.BAccountID;
                    }

                    if (lead.ParentBAccountID != null)
                    {
                        opportunity.ParentBAccountID = lead.ParentBAccountID;
                    }

                    if (lead.CampaignID != null)
                    {
                        opportunity.CampaignSourceID = lead.CampaignID;
                    }
                    opportunity.ContactID       = lead.ContactID;
                    opportunity.ConvertedLeadID = lead.ContactID;
                    opportunity.OpportunityName = string.IsNullOrEmpty(lead.FullName) ? lead.DisplayName : lead.FullName;
                    opportunity = (CROpportunity)opportunityMaint.Opportunity.Cache.Update(opportunity);

                    ContactMaint contactGraph = CreateInstance <ContactMaint>();
                    lead.ContactType          = ContactTypesAttribute.Person;
                    lead.QualificationDate    = PXTimeZoneInfo.Now;
                    lead.ConvertedBy          = Accessinfo.UserID;
                    lead = contactGraph.Contact.Update(lead);

                    opportunityMaint.Opportunity.Search <CROpportunity.opportunityID>(opportunity.OpportunityID);
                    lead = opportunityMaint.Leads.Update(lead);

                    // Copy Note text and Files references
                    CRSetup setup = PXSetupOptional <CRSetup> .Select(opportunityMaint);
                    PXNoteAttribute.CopyNoteAndFiles(opportunityMaint.Leads.Cache, lead, opportunityMaint.OpportunityCurrent.Cache, opportunity, setup);

                    throw new PXRedirectRequiredException(opportunityMaint, "Opportunity", true);
                });
            }
            return(contacts);
        }