예제 #1
0
        protected override bool IsThereSomeContactAddressSourceValue(PXCache cache, Extensions.ContactAddress.Document row)
        {
            FSSrvOrdType   fSSrvOrdTypeRow   = (FSSrvOrdType)GetSrvOrdTypeView().Current;
            FSServiceOrder fsServiceOrderRow = (FSServiceOrder)cache.GetMain <Extensions.ContactAddress.Document>(row);

            if (fSSrvOrdTypeRow == null || fsServiceOrderRow == null)
            {
                return(false);
            }

            return(
                (fSSrvOrdTypeRow.AppAddressSource == ID.SrvOrdType_AppAddressSource.BUSINESS_ACCOUNT &&
                 (row.LocationID != null)
                )
                ||
                (fSSrvOrdTypeRow.AppAddressSource == ID.SrvOrdType_AppAddressSource.CUSTOMER_CONTACT &&
                 (row.ContactID != null)
                )
                ||
                (fSSrvOrdTypeRow.AppAddressSource == ID.SrvOrdType_AppAddressSource.BRANCH_LOCATION &&
                 fsServiceOrderRow.BranchLocationID != null
                )
                );
        }
예제 #2
0
        protected void SetDefaultContactAndAddress(PXCache cache, object Row, int?oldContactID, int?oldLocationID,
                                                   int?oldBranchLocationID, ContacAddressCallerEnum callerID)
        {
            Extensions.ContactAddress.Document row;
            FSServiceOrder fsServiceOrderRow = null;

            if (Row is FSServiceOrder)
            {
                row = cache.GetExtension <Extensions.ContactAddress.Document>(Row);
                fsServiceOrderRow = (FSServiceOrder)Row;
            }
            else
            {
                row = Row as Extensions.ContactAddress.Document;
                fsServiceOrderRow = (FSServiceOrder)cache.GetMain <Extensions.ContactAddress.Document>(row);
            }
            if (row == null)
            {
                return;
            }

            Contact oldContact = null;
            Address oldAddress = null;

            FSSrvOrdType fsSrvOrdTypeRow = null;

            if (cache.Graph is ServiceOrderEntry)
            {
                fsSrvOrdTypeRow = ((ServiceOrderEntry)cache.Graph).ServiceOrderTypeSelected.Current;
            }
            else if (cache.Graph is AppointmentEntry)
            {
                fsSrvOrdTypeRow = ((AppointmentEntry)cache.Graph).ServiceOrderTypeSelected.Current;
            }

            if (fsSrvOrdTypeRow != null &&
                fsSrvOrdTypeRow.AppAddressSource == ID.SrvOrdType_AppAddressSource.BRANCH_LOCATION &&
                oldBranchLocationID != null)
            {
                oldContact = ContactAddressHelper.GetContact(
                    (FSContact)PXSelectJoin <
                        FSContact,
                        InnerJoin <FSBranchLocation,
                                   On <FSBranchLocation.branchLocationContactID, Equal <FSContact.contactID> > >,
                        Where <FSBranchLocation.branchLocationID, Equal <Required <FSBranchLocation.branchLocationID> > > >
                    .Select(Base, oldBranchLocationID));
                oldAddress = ContactAddressHelper.GetAddress(
                    (FSAddress)PXSelectJoin <
                        FSAddress,
                        InnerJoin <FSBranchLocation,
                                   On <FSBranchLocation.branchLocationAddressID, Equal <FSAddress.addressID> > >,
                        Where <FSBranchLocation.branchLocationID, Equal <Required <FSBranchLocation.branchLocationID> > > >
                    .Select(Base, oldBranchLocationID));
            }
            else if (fsSrvOrdTypeRow != null &&
                     fsSrvOrdTypeRow.AppAddressSource == ID.SrvOrdType_AppAddressSource.CUSTOMER_CONTACT &&
                     oldContactID != null)
            {
                oldContact = PXSelect <Contact,
                                       Where <Contact.contactID, Equal <Required <Extensions.ContactAddress.Document.contactID> > > > .Select(Base, oldContactID);

                oldAddress = PXSelectJoin <Address,
                                           LeftJoin <Contact, On <Contact.defAddressID, Equal <Address.addressID> > >,
                                           Where <Contact.contactID, Equal <Required <Extensions.ContactAddress.Document.contactID> > > > .Select(Base, oldContactID);
            }
            else if (fsSrvOrdTypeRow != null &&
                     fsSrvOrdTypeRow.AppAddressSource == ID.SrvOrdType_AppAddressSource.BUSINESS_ACCOUNT &&
                     oldLocationID != null)
            {
                oldContact = PXSelectJoin <Contact,
                                           LeftJoin <Location, On <Location.locationID, Equal <Required <Extensions.ContactAddress.Document.locationID> > > >,
                                           Where <Contact.contactID, Equal <Location.defContactID> > > .Select(Base, oldLocationID);

                oldAddress = PXSelectJoin <Address,
                                           LeftJoin <Contact, On <Contact.defAddressID, Equal <Address.addressID> >,
                                                     LeftJoin <Location, On <Location.locationID, Equal <Required <Extensions.ContactAddress.Document.locationID> > > > >,
                                           Where <Address.addressID, Equal <Location.defAddressID> > > .Select(Base, oldLocationID);
            }

            bool CallDefaults = false;

            switch (callerID)
            {
            case ContacAddressCallerEnum.Insert:
                CallDefaults = true;
                break;

            case ContacAddressCallerEnum.BranchLocationID:
                CallDefaults = fsSrvOrdTypeRow?.AppAddressSource == ID.SrvOrdType_AppAddressSource.BRANCH_LOCATION &&
                               fsServiceOrderRow.BranchLocationID != null;
                break;

            case ContacAddressCallerEnum.BAccountID:
                CallDefaults = fsSrvOrdTypeRow?.AppAddressSource != ID.SrvOrdType_AppAddressSource.BRANCH_LOCATION &&
                               fsServiceOrderRow.CustomerID != null;
                break;

            case ContacAddressCallerEnum.ContactID:
                CallDefaults = fsSrvOrdTypeRow?.AppAddressSource == ID.SrvOrdType_AppAddressSource.CUSTOMER_CONTACT &&
                               fsServiceOrderRow.ContactID != null;
                break;

            case ContacAddressCallerEnum.LocationID:
                CallDefaults = fsSrvOrdTypeRow?.AppAddressSource == ID.SrvOrdType_AppAddressSource.BUSINESS_ACCOUNT &&
                               fsServiceOrderRow.LocationID != null;
                break;
            }

            if (CallDefaults)
            {
                ChangedData forContactInfo = new ChangedData();
                forContactInfo.OldContact = oldContact;
                forContactInfo.OldAddress = oldAddress;

                DefaultRecords(row, forContactInfo, new ChangedData(false));
            }
        }
예제 #3
0
        protected virtual void DefaultRecords(Document row, ChangedData changedForContactInfo, ChangedData changedForShippingInfo)
        {
            PXCache cache = Documents.Cache;

            bool needAskFromContactAddress         = AskForConfirmationForAddress(row, changedForContactInfo);
            bool needAskFromShippingContactAddress = AskForConfirmationForShippingAddress(row, changedForShippingInfo);

            if ((needAskFromContactAddress || needAskFromShippingContactAddress) && (row.LocationID != null || row.ContactID != null))
            {
                string message = needAskFromContactAddress && needAskFromShippingContactAddress ?
                                 CR.Messages.ReplaceContactDetailsAndShippingInfo :
                                 needAskFromContactAddress ? CR.Messages.ReplaceContactDetails :
                                 CR.Messages.ReplaceShippingInfo;
                WebDialogResult dialogResult = this.Documents.View.Ask((object)null, CR.Messages.Warning, message,
                                                                       MessageButtons.AbortRetryIgnore,
                                                                       new Dictionary <WebDialogResult, string>()
                {
                    { WebDialogResult.Abort, "Yes" },
                    { WebDialogResult.Retry, "No" },
                    { WebDialogResult.Ignore, "Cancel" }
                }, MessageIcon.Warning);

                if (dialogResult == WebDialogResult.Abort)
                {
                    if (needAskFromContactAddress)
                    {
                        CRAddressAttribute.DefaultRecord <Document.documentAddressID>(cache, cache.GetMain(row));
                        CRContactAttribute.DefaultRecord <Document.documentContactID>(cache, cache.GetMain(row));
                        cache.SetValue <Document.allowOverrideContactAddress>(row, false);
                    }
                    if (needAskFromShippingContactAddress)
                    {
                        CRShippingContactAttribute.DefaultRecord <Document.shipContactID>(cache, cache.GetMain(row));
                        CRShippingAddressAttribute.DefaultRecord <Document.shipAddressID>(cache, cache.GetMain(row));
                        cache.SetValue <Document.allowOverrideShippingContactAddress>(row, false);
                    }
                }
                else if (dialogResult == WebDialogResult.Ignore)
                {
                    cache.SetValue <Document.bAccountID>(row, cache.GetValueOriginal <Document.bAccountID>(cache.GetMain(row)));
                    cache.SetValue <Document.contactID>(row, cache.GetValueOriginal <Document.contactID>(cache.GetMain(row)));
                }
                else if (dialogResult == WebDialogResult.Retry)
                {
                    if (row.AllowOverrideContactAddress == false)
                    {
                        CRAddressAttribute.DefaultRecord <Document.documentAddressID>(cache, cache.GetMain(row));
                        CRContactAttribute.DefaultRecord <Document.documentContactID>(cache, cache.GetMain(row));
                        cache.SetValue <Document.allowOverrideContactAddress>(row, false);
                    }
                    else if (row.AllowOverrideShippingContactAddress == false)
                    {
                        CRShippingContactAttribute.DefaultRecord <Document.shipContactID>(cache, cache.GetMain(row));
                        CRShippingAddressAttribute.DefaultRecord <Document.shipAddressID>(cache, cache.GetMain(row));
                        cache.SetValue <Document.allowOverrideShippingContactAddress>(row, false);
                    }
                }
            }
            else
            {
                if (IsThereSomeContactAddressSourceValue(cache, row))
                {
                    if (changedForContactInfo.CanBeReplace)
                    {
                        CRAddressAttribute.DefaultRecord <Document.documentAddressID>(cache, cache.GetMain(row));
                        CRContactAttribute.DefaultRecord <Document.documentContactID>(cache, cache.GetMain(row));
                        cache.SetValue <Document.allowOverrideContactAddress>(row, false);
                    }

                    if (changedForShippingInfo.CanBeReplace)
                    {
                        CRShippingContactAttribute.DefaultRecord <Document.shipContactID>(cache, cache.GetMain(row));
                        CRShippingAddressAttribute.DefaultRecord <Document.shipAddressID>(cache, cache.GetMain(row));
                        cache.SetValue <Document.allowOverrideShippingContactAddress>(row, false);
                    }
                }
            }

            if (row.LocationID == null && row.ContactID == null && row.BAccountID == null)
            {
                if (row.AllowOverrideContactAddress == false)
                {
                    CRAddressAttribute.DefaultRecord <Document.documentAddressID>(cache, cache.GetMain(row));
                    CRContactAttribute.DefaultRecord <Document.documentContactID>(cache, cache.GetMain(row));
                    cache.SetValue <Document.allowOverrideContactAddress>(row, false);
                }
                if (row.AllowOverrideShippingContactAddress == false)
                {
                    CRShippingContactAttribute.DefaultRecord <Document.shipContactID>(cache, cache.GetMain(row));
                    CRShippingAddressAttribute.DefaultRecord <Document.shipAddressID>(cache, cache.GetMain(row));
                    cache.SetValue <Document.allowOverrideShippingContactAddress>(row, false);
                    PXCache cacheContact = GetContactCache();
                    var     contact      = GetCurrentContact();
                    cacheContact.RaiseRowUpdated(contact, contact);
                    PXCache cacheAddress = GetAddressCache();
                    var     address      = GetCurrentAddress();
                    cacheAddress.RaiseRowUpdated(address, address);
                }
            }

            if (IsDefaultContactAdress())
            {
                cache.SetValue <Document.allowOverrideContactAddress>(row, true);
            }
        }
예제 #4
0
        protected virtual void DefaultRecords(Document row, Contact oldContact, Address oldAddress)
        {
            PXCache cache = Documents.Cache;

            if (row.AllowOverrideContactAddress == true && (row.LocationID != null || row.ContactID != null) &&
                !IsDefaultContactAdress() && !IsContactAddressNoChanged(oldContact, oldAddress))
            {
                WebDialogResult dialogResult = this.Documents.View.Ask((object)null, CR.Messages.Warning, CR.Messages.ReplaceContactDetails,
                                                                       MessageButtons.AbortRetryIgnore,
                                                                       new Dictionary <WebDialogResult, string>()
                {
                    { WebDialogResult.Abort, "Yes" },
                    { WebDialogResult.Retry, "No" },
                    { WebDialogResult.Ignore, "Cancel" }
                }, MessageIcon.Warning);

                if (dialogResult == WebDialogResult.Abort)
                {
                    CRAddressAttribute.DefaultRecord <Document.documentAddressID>(cache, cache.GetMain(row));
                    CRContactAttribute.DefaultRecord <Document.documentContactID>(cache, cache.GetMain(row));
                    cache.SetValue <Document.allowOverrideContactAddress>(row, false);
                }
                else if (dialogResult == WebDialogResult.Ignore)
                {
                    cache.SetValue <Document.bAccountID>(row, cache.GetValueOriginal <Document.bAccountID>(cache.GetMain(row)));
                    cache.SetValue <Document.contactID>(row, cache.GetValueOriginal <Document.contactID>(cache.GetMain(row)));
                }
            }
            else
            {
                if (row.LocationID != null || row.ContactID != null)
                {
                    CRAddressAttribute.DefaultRecord <Document.documentAddressID>(cache, cache.GetMain(row));
                    CRContactAttribute.DefaultRecord <Document.documentContactID>(cache, cache.GetMain(row));
                    cache.SetValue <Document.allowOverrideContactAddress>(row, false);
                }
            }

            if (row.LocationID == null && row.ContactID == null && row.BAccountID == null)
            {
                if (row.AllowOverrideContactAddress == false)
                {
                    CRAddressAttribute.DefaultRecord <Document.documentAddressID>(cache, cache.GetMain(row));
                    CRContactAttribute.DefaultRecord <Document.documentContactID>(cache, cache.GetMain(row));
                    cache.SetValue <Document.allowOverrideContactAddress>(row, false);
                }
            }

            if (IsDefaultContactAdress())
            {
                cache.SetValue <Document.allowOverrideContactAddress>(row, true);
            }
        }