Ejemplo n.º 1
0
        public virtual IEnumerable ConvertToBAccount(PXAdapter adapter)
        {
            List <Contact> contacts = new List <Contact>(adapter.Get().Cast <Contact>());

            foreach (Contact contact in contacts.Where(contact => contact != null))
            {
                if (AccountInfo.AskExt((graph, view) => graph.Views[view].Cache.Clear(), true) != WebDialogResult.Yes)
                {
                    return(contacts);
                }
                bool     empty_required = !AccountInfo.VerifyRequired();
                BAccount existing       = PXSelect <BAccount, Where <BAccount.acctCD, Equal <Required <BAccount.acctCD> > > > .SelectSingleBound(this, null, AccountInfo.Current.BAccountID);

                if (existing != null)
                {
                    AccountInfo.Cache.RaiseExceptionHandling <LeadMaint.AccountsFilter.bAccountID>(AccountInfo.Current, AccountInfo.Current.BAccountID, new PXSetPropertyException(Messages.BAccountAlreadyExists, AccountInfo.Current.BAccountID));
                    return(contacts);
                }
                if (empty_required)
                {
                    return(contacts);
                }

                Save.Press();
                Contact c = contact;
                PXLongOperation.StartOperation(this, () => LeadMaint.ConvertToAccount(c, AccountInfo.Current, this.IsContractBasedAPI));
            }
            return(contacts);
        }
        protected override bool Process(Package package)
        {
            var account = package.Account;

            if (account.IncomingProcessing != true ||
                account.CreateLead != true)
            {
                return(false);
            }

            var message = package.Message;

            if (!string.IsNullOrEmpty(message.Exception) ||
                message.IsIncome != true ||
                message.RefNoteID != null ||
                message.ClassID == CRActivityClass.EmailRouting)
            {
                return(false);
            }

            var copy = package.Graph.Caches[typeof(CRSMEmail)].CreateCopy(message);

            try
            {
                LeadMaint graph     = PXGraph.CreateInstance <LeadMaint>();
                var       leadCache = graph.Lead.Cache;
                var       lead      = (Contact)leadCache.Insert();
                lead = PXCache <Contact> .CreateCopy(graph.Lead.Search <Contact.contactID>(lead.ContactID));

                lead.EMail    = package.Address;
                lead.LastName = package.Description;

                CREmailActivityMaint.EmailAddress address = CREmailActivityMaint.ParseNames(message.MailFrom);

                lead.FirstName = address.FirstName;
                lead.LastName  = address.LastName;
                if (account.CreateLeadClassID != null)
                {
                    lead.ClassID = account.CreateLeadClassID;
                }

                lead = (Contact)leadCache.Update(lead);

                message.RefNoteID = PXNoteAttribute.GetNoteID <Contact.noteID>(leadCache, lead);
                graph.Actions.PressSave();
                message.ContactID = message.ContactID ?? lead.ContactID;
            }
            catch (Exception e)
            {
                package.Graph.Caches[typeof(CRSMEmail)].RestoreCopy(message, copy);
                throw new PXException(Messages.CreateLeadException, e is PXOuterException ? ("\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages)) : e.Message);
            }

            return(true);
        }
Ejemplo n.º 3
0
        protected override PXGraph GetGraphForDetails(CRContactBatch selectedItem)
        {
            if (CRLeadBatch.IsLead(selectedItem))
            {
                LeadMaint leadGraph = CreateGraph <LeadMaint>();
                leadGraph.Lead.Current = leadGraph.Lead.Search <Lead.contactID>(selectedItem.ContactID);
                return(leadGraph);
            }
            ContactMaint contactGraph = new ContactMaint();

            contactGraph.Contact.Current = contactGraph.Contact.Search <Contact.contactID>(selectedItem.ContactID);
            return(contactGraph);
        }
Ejemplo n.º 4
0
        protected override bool Process(Package package)
        {
            var account = package.Account;

            if (account.IncomingProcessing != true ||
                account.CreateLead != true)
            {
                return(false);
            }

            var message = package.Message;

            if (!string.IsNullOrEmpty(message.Exception) ||
                message.IsIncome != true ||
                message.RefNoteID != null ||
                message.ClassID == CRActivityClass.EmailRouting)
            {
                return(false);
            }

            var copy = package.Graph.Caches[typeof(CRSMEmail)].CreateCopy(message);

            try
            {
                LeadMaint graph     = PXGraph.CreateInstance <LeadMaint>();
                var       leadCache = graph.Lead.Cache;
                var       lead      = (CRLead)leadCache.Insert();
                lead = PXCache <CRLead> .CreateCopy(graph.Lead.Search <CRLead.contactID>(lead.ContactID));

                lead.EMail        = package.Address;
                lead.LastName     = package.Description;
                lead.RefContactID = message.ContactID;

                lead.OverrideRefContact = true;

                CREmailActivityMaint.EmailAddress address = CREmailActivityMaint.ParseNames(message.MailFrom);

                lead.FirstName = address.FirstName;
                lead.LastName  = string.IsNullOrEmpty(address.LastName) ? address.Email : address.LastName;
                if (account.CreateLeadClassID != null)
                {
                    lead.ClassID = account.CreateLeadClassID;
                }

                lead = (CRLead)leadCache.Update(lead);

                if (lead.ClassID != null)
                {
                    CRLeadClass cls = PXSelect <
                        CRLeadClass,
                        Where <
                            CRLeadClass.classID, Equal <Required <CRLeadClass.classID> > > >
                                      .SelectSingleBound(graph, null, lead.ClassID);

                    if (cls?.DefaultOwner == CRDefaultOwnerAttribute.Source)
                    {
                        lead.WorkgroupID = message.WorkgroupID;
                        lead.OwnerID     = message.OwnerID;
                    }
                }

                message.RefNoteID = PXNoteAttribute.GetNoteID <CRLead.noteID>(leadCache, lead);
                graph.Actions.PressSave();
            }
            catch (Exception e)
            {
                package.Graph.Caches[typeof(CRSMEmail)].RestoreCopy(message, copy);
                throw new PXException(Messages.CreateLeadException, e is PXOuterException ? ("\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages)) : e.Message);
            }

            return(true);
        }