private void FillFromContact()
        {
            Contact relatedContact = PXSelect <
                Contact,
                Where <
                    Contact.contactID, Equal <Current <Document.refContactID> > > >
                                     .SelectSingleBound(Base, new[] { Documents.Current });

            Address relatedContactAddress = PXSelect <
                Address,
                Where <
                    Address.addressID, Equal <Current <Contact.defAddressID> > > >
                                            .SelectSingleBound(Base, new[] { relatedContact });

            DocumentContact docContact = Contacts.Cache.Current as DocumentContact;
            DocumentAddress docAddress = Addresses.SelectSingle(docContact.DefAddressID);

            FillToDocumentContact(Contacts.Cache, docContact, relatedContact);
            FillToDocumentAddress(Addresses.Cache, docAddress, relatedContactAddress);
        }
Beispiel #2
0
        protected virtual void _(Events.FieldUpdated <Document, Document.allowOverrideContactAddress> e)
        {
            var row = e.Row as Document;

            if (row == null)
            {
                return;
            }

            DocumentAddress address = Addresses.SelectSingle();
            DocumentContact contact = Contacts.SelectSingle();


            if (contact != null)
            {
                Contacts.Cache.SetValue <DocumentContact.overrideContact>(contact, row.AllowOverrideContactAddress);
                PXCache cache = GetContactCache();
                if (cache != null)
                {
                    CRContact crContact = GetCurrentContact();
                    if (crContact != null)
                    {
                        cache.SetValue <CRContact.isDefaultContact>(crContact, row.AllowOverrideContactAddress != true);
                    }
                }
            }
            if (address != null)
            {
                Addresses.Cache.SetValue <DocumentAddress.overrideAddress>(address, row.AllowOverrideContactAddress);
                PXCache cache = GetAddressCache();
                if (cache != null)
                {
                    CRAddress crAddress = GetCurrentAddress();
                    if (crAddress != null)
                    {
                        cache.SetValue <CRAddress.isDefaultAddress>(crAddress, row.AllowOverrideContactAddress != true);
                    }
                }
            }

            Addresses.Cache.Update(address);
            Contacts.Cache.Update(contact);
        }
        protected override Contact CreateMaster(ContactMaint graph, ContactConversionOptions _)
        {
            var entity           = Documents.Current;
            var param            = ContactInfo.Current;
            var docContact       = Contacts.Current ?? Contacts.SelectSingle();
            var docContactMethod = ContactMethod.Current ?? ContactMethod.SelectSingle();
            var docAddress       = Addresses.Current ?? Addresses.SelectSingle();

            Contact contact = new Contact
            {
                ContactType      = ContactTypesAttribute.Person,
                ParentBAccountID = entity.ParentBAccountID
            };

            MapContact(docContact, contact);
            MapConsentable(docContact, contact);

            contact.FirstName        = param.FirstName;
            contact.LastName         = param.LastName;
            contact.Salutation       = param.Salutation;
            contact.Phone1           = param.Phone1;
            contact.Phone1Type       = param.Phone1Type;
            contact.EMail            = param.Email;
            contact.ContactType      = ContactTypesAttribute.Person;
            contact.ParentBAccountID = entity.ParentBAccountID;
            contact.BAccountID       = entity.BAccountID;
            contact.Source           = entity.Source;

            MapContactMethod(docContactMethod, contact);

            var address = (Address)graph.AddressCurrent.Cache.CreateInstance();

            address = graph.AddressCurrent.Insert(address);

            contact = graph.Contact.Insert(contact);

            contact.ClassID = param.ContactClass;

            CRContactClass cls = PXSelect <
                CRContactClass,
                Where <
                    CRContactClass.classID, Equal <Required <CRContactClass.classID> > > >
                                 .SelectSingleBound(graph, null, contact.ClassID);

            if (cls?.DefaultOwner == CRDefaultOwnerAttribute.Source)
            {
                contact.WorkgroupID = entity.WorkgroupID;
                contact.OwnerID     = entity.OwnerID;
            }

            MapAddress(docAddress, address);

            address = (Address)graph.AddressCurrent.Cache.Update(address);

            contact.DefAddressID = address.AddressID;

            contact = graph.Contact.Update(contact);

            ReverseDocumentUpdate(graph, contact);

            FillRelations(graph.Relations, contact);

            FillAttributes(graph.Answers, contact);

            TransferActivities(graph, contact);

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

            PXNoteAttribute.CopyNoteAndFiles(graph.Caches <TMain>(), Documents.Cache.GetMain(entity), graph.Contact.Cache, contact, setup);

            return(graph.Contact.Update(contact));
        }