protected override PXGraph GetGraphForDetails(CRBAccountBatch selectedItem) { BusinessAccountMaint target = CreateGraph <BusinessAccountMaint>(); target.BAccount.Current = target.BAccount.Search <BAccount.acctCD>(selectedItem.AcctCD); return(target); }
private static void ProcessValidation(BusinessAccountMaint graph, Contact record, ValidationFilter Filter) { Type itemType = record.GetType(); PXCache cache = PXGraph.CreateInstance <PXGraph>().Caches[itemType]; Type graphType; object copy = cache.CreateCopy(record); PXPrimaryGraphAttribute.FindPrimaryGraph(cache, ref copy, out graphType); graph.Views[graph.PrimaryView].Cache.Current = copy as BAccount; CRDuplicateEntities <PXGraph, BAccount> .RunActionWithAppliedAutomation( graph, copy, nameof(CRDuplicateEntities <PXGraph, BAccount> .CheckForDuplicates)); }
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"); }
private static void ProcessValidation(ValidationFilter filter, Contact record) { BusinessAccountMaint graph = PXGraph.CreateInstance <BusinessAccountMaint>(); PXView view = graph.BAccount.View; int startRow = 0, totalRows = 0; BAccount baccount = null; Contact contact = null; if (record.ContactType == ContactTypesAttribute.BAccountProperty && record.BAccountID != null) { List <object> list_baccount = view.Select(null, null, new object[] { record.BAccountID }, new string[] { typeof(BAccount.bAccountID).Name }, null, null, ref startRow, 1, ref totalRows); if (list_baccount != null && list_baccount.Count >= 1) { baccount = PXResult.Unwrap <BAccount>(list_baccount[0]); } } if (baccount == null || baccount.DefContactID != record.ContactID) { throw new PXException(Messages.ContactNotFound); } contact = graph.DefContact.Current = graph.DefContact.SelectWindowed(0, 1); contact.DuplicateFound = true; PXView viewDuplicates = graph.Duplicates.View; if (viewDuplicates == null) { throw new PXException(Messages.DuplicateViewNotFound); } viewDuplicates.Clear(); List <object> duplicates = viewDuplicates.SelectMulti(); contact = (Contact)graph.DefContact.Cache.CreateCopy(contact); contact.DuplicateStatus = DuplicateStatusAttribute.Validated; Decimal?score = 0; foreach (PXResult <CRDuplicateRecord, Contact, CRLeadContactValidationProcess.Contact2> r in duplicates) { CRLeadContactValidationProcess.Contact2 duplicate = r; CRDuplicateRecord contactScore = r; int duplicateWeight = ContactMaint.GetContactWeight(duplicate); int currentWeight = ContactMaint.GetContactWeight(contact); if (duplicateWeight > currentWeight || (duplicateWeight == currentWeight && duplicate.ContactID < contact.ContactID)) { contact.DuplicateStatus = DuplicateStatusAttribute.PossibleDuplicated; if (contactScore.Score > score) { score = contactScore.Score; } } } graph.DefContact.Cache.Update(contact); graph.DefContact.Cache.RestoreCopy(record, contact); graph.Actions.PressSave(); }