public override void Record_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Insert && ((FSContact)e.Row).IsDefaultContact == true)
            {
                PXView view = sender.Graph.TypedViews.GetView(_DuplicateSelect, true);
                view.Clear();

                FSContact previousAddress = (FSContact)view.SelectSingle(((FSContact)e.Row).BAccountID, ((FSContact)e.Row).BAccountContactID, ((FSContact)e.Row).RevisionID);

                if (previousAddress != null)
                {
                    _KeyToAbort = sender.GetValue(e.Row, _RecordID);
                    object newkey = sender.Graph.Caches[typeof(FSContact)].GetValue(previousAddress, _RecordID);

                    PXCache cache = sender.Graph.Caches[_ItemType];

                    foreach (object data in cache.Updated)
                    {
                        object datakey = cache.GetValue(data, _FieldOrdinal);

                        if (Equals(_KeyToAbort, datakey))
                        {
                            cache.SetValue(data, _FieldOrdinal, newkey);
                        }
                    }

                    _KeyToAbort = null;
                    e.Cancel    = true;
                    return;
                }
            }

            base.Record_RowPersisting(sender, e);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add the Customer info as a recipient in the Email template generated by Appointment.
        /// </summary>
        private static void AddCustomerRecipient(AppointmentEntry graphAppointmentEntry, NotificationRecipient recSetup, RecipientList recipients)
        {
            NotificationRecipient recipient = null;

            Customer customerRow = PXSelect <Customer,
                                             Where <
                                                 Customer.bAccountID, Equal <Required <Customer.bAccountID> > > >
                                   .Select(graphAppointmentEntry, graphAppointmentEntry.ServiceOrderRelated.Current.CustomerID);

            if (customerRow == null)
            {
                return;
            }

            FSContact fsContactRow = graphAppointmentEntry.ServiceOrder_Contact.SelectSingle();

            if (fsContactRow != null && fsContactRow.Email != null)
            {
                recipient = new NotificationRecipient()
                {
                    Active = true,
                    Email  = fsContactRow.Email,
                    Hidden = recSetup.Hidden,
                    Format = recSetup.Format
                };
            }
            else
            {
                Contact srvOrdContactRow = PXSelect <Contact,
                                                     Where <
                                                         Contact.contactID, Equal <Required <Contact.contactID> > > >
                                           .Select(graphAppointmentEntry, graphAppointmentEntry.ServiceOrderRelated.Current.ContactID);

                if (srvOrdContactRow != null && srvOrdContactRow.EMail != null)
                {
                    recipient = new NotificationRecipient()
                    {
                        Active = true,
                        Email  = srvOrdContactRow.EMail,
                        Hidden = recSetup.Hidden,
                        Format = recSetup.Format
                    };
                }
            }

            if (recipient != null)
            {
                recipients.Add(recipient);
            }
        }
        public override void RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            object key = sender.GetValue(e.Row, _FieldOrdinal);

            if (key != null)
            {
                PXCache cache = sender.Graph.Caches[_RecordType];

                if (Convert.ToInt32(key) < 0)
                {
                    foreach (object data in cache.Inserted)
                    {
                        object dataKey = cache.GetValue(data, _RecordID);

                        if (Equals(key, dataKey))
                        {
                            if (((FSContact)data).IsDefaultContact == true)
                            {
                                PXView view = sender.Graph.TypedViews.GetView(_DuplicateSelect, true);
                                view.Clear();

                                FSContact previousAddress = (FSContact)view.SelectSingle(((FSContact)data).BAccountID, ((FSContact)data).BAccountContactID, ((FSContact)data).RevisionID);

                                if (previousAddress != null)
                                {
                                    _KeyToAbort = sender.GetValue(e.Row, _FieldOrdinal);
                                    object id = sender.Graph.Caches[typeof(FSContact)].GetValue(previousAddress, _RecordID);
                                    sender.SetValue(e.Row, _FieldOrdinal, id);
                                }
                            }
                            break;
                        }
                    }
                }
            }

            base.RowPersisting(sender, e);
        }
Exemplo n.º 4
0
        public static bool DefaultBLOCContact <TContact, TContactID>(PXCache sender, string fieldName, object documentRow, object contactRow, object sourceRow)
            where TContact : class, IBqlTable, IContact, new()
            where TContactID : IBqlField
        {
            bool contactFound = false;

            if (sourceRow != null)
            {
                FSContact contact = contactRow as FSContact;

                if (contact == null)
                {
                    contact = PXSelect <FSContact,
                                        Where <
                                            FSContact.contactID, Equal <Required <TContactID> > > >
                              .Select(sender.Graph, sender.GetValue(documentRow, fieldName));
                }

                if (PXResult.Unwrap <FSContact>(sourceRow)?.ContactID == null || sender.GetValue(documentRow, fieldName) == null)
                {
                    if (contact == null || contact.ContactID > 0)
                    {
                        contact = new FSContact();
                    }

                    contact.BAccountContactID = PXResult.Unwrap <TContact>(sourceRow).ContactID;
                    contact.BAccountID        = PXResult.Unwrap <TContact>(sourceRow).BAccountID;
                    contact.RevisionID        = PXResult.Unwrap <TContact>(sourceRow).RevisionID;
                    contact.IsDefaultContact  = true;
                    contact.FullName          = PXResult.Unwrap <TContact>(sourceRow).FullName;
                    contact.Salutation        = PXResult.Unwrap <TContact>(sourceRow).Salutation;
                    contact.Attention         = PXResult.Unwrap <TContact>(sourceRow).Attention;
                    contact.Title             = PXResult.Unwrap <TContact>(sourceRow).Title;
                    contact.Phone1            = PXResult.Unwrap <TContact>(sourceRow).Phone1;
                    contact.Phone1Type        = PXResult.Unwrap <TContact>(sourceRow).Phone1Type;
                    contact.Phone2            = PXResult.Unwrap <TContact>(sourceRow).Phone2;
                    contact.Phone2Type        = PXResult.Unwrap <TContact>(sourceRow).Phone2Type;
                    contact.Phone3            = PXResult.Unwrap <TContact>(sourceRow).Phone3;
                    contact.Phone3Type        = PXResult.Unwrap <TContact>(sourceRow).Phone3Type;
                    contact.Fax     = PXResult.Unwrap <TContact>(sourceRow).Fax;
                    contact.FaxType = PXResult.Unwrap <TContact>(sourceRow).FaxType;
                    contact.Email   = PXResult.Unwrap <TContact>(sourceRow).Email;

                    contactFound = contact.BAccountContactID != null && contact.BAccountID != null && contact.RevisionID != null;

                    if (contact.ContactID == null)
                    {
                        contact = (FSContact)sender.Graph.Caches[typeof(FSContact)].Insert(contact);
                        sender.SetValue(documentRow, fieldName, contact.ContactID);
                    }
                    else if (contactRow == null)
                    {
                        sender.Graph.Caches[typeof(FSContact)].Update(contact);
                    }
                }
                else
                {
                    if (contact != null && contact.ContactID < 0)
                    {
                        sender.Graph.Caches[typeof(FSContact)].Delete(contact);
                    }

                    sender.SetValue(documentRow, fieldName, PXResult.Unwrap <TContact>(sourceRow).ContactID);
                    contactFound = PXResult.Unwrap <FSContact>(sourceRow).ContactID != null;
                }
            }

            return(contactFound);
        }
Exemplo n.º 5
0
        private static void ApplyChangesfromContactInfo(ServiceOrderEntry graphServiceOrderEntry, CRContact crContactRow, FSContact fsContactRow, ref bool somethingChanged)
        {
            if (crContactRow == null)
            {
                return;
            }

            if (fsContactRow.Title != crContactRow.Title)
            {
                graphServiceOrderEntry.ServiceOrder_Contact.SetValueExt <FSContact.title>(fsContactRow, crContactRow.Title);
                somethingChanged = true;
            }

            if (fsContactRow.Attention != crContactRow.Attention)
            {
                graphServiceOrderEntry.ServiceOrder_Contact.SetValueExt <FSContact.attention>(fsContactRow, crContactRow.Attention);
                somethingChanged = true;
            }

            if (fsContactRow.Email != crContactRow.Email)
            {
                graphServiceOrderEntry.ServiceOrder_Contact.SetValueExt <FSContact.email>(fsContactRow, crContactRow.Email);
                somethingChanged = true;
            }

            if (fsContactRow.Phone1 != crContactRow.Phone1)
            {
                graphServiceOrderEntry.ServiceOrder_Contact.SetValueExt <FSContact.phone1>(fsContactRow, crContactRow.Phone1);
                somethingChanged = true;
            }

            if (fsContactRow.Phone2 != crContactRow.Phone2)
            {
                graphServiceOrderEntry.ServiceOrder_Contact.SetValueExt <FSContact.phone2>(fsContactRow, crContactRow.Phone2);
                somethingChanged = true;
            }

            if (fsContactRow.Phone3 != crContactRow.Phone3)
            {
                graphServiceOrderEntry.ServiceOrder_Contact.SetValueExt <FSContact.phone3>(fsContactRow, crContactRow.Phone3);
                somethingChanged = true;
            }

            if (fsContactRow.Fax != crContactRow.Fax)
            {
                graphServiceOrderEntry.ServiceOrder_Contact.SetValueExt <FSContact.fax>(fsContactRow, crContactRow.Fax);
                somethingChanged = true;
            }
        }
Exemplo n.º 6
0
        public static void UpdateServiceOrderHeader(ServiceOrderEntry graphServiceOrderEntry,
                                                    PXCache cache,
                                                    CROpportunity crOpportunityRow,
                                                    FSCreateServiceOrderFilter fsCreateServiceOrderOnOpportunityFilterRow,
                                                    FSServiceOrder fsServiceOrderRow,
                                                    CRContact crContactRow,
                                                    CRAddress crAddressRow,
                                                    bool updatingExistingSO)
        {
            bool somethingChanged = false;

            FSSrvOrdType fsSrvOrdTypeRow = GetServiceOrderType(graphServiceOrderEntry, fsServiceOrderRow.SrvOrdType);

            if (fsSrvOrdTypeRow.Behavior != ID.Behavior_SrvOrderType.INTERNAL_APPOINTMENT)
            {
                if (fsServiceOrderRow.CustomerID != crOpportunityRow.BAccountID)
                {
                    graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.customerID>(fsServiceOrderRow, crOpportunityRow.BAccountID);
                    somethingChanged = true;
                }

                if (fsServiceOrderRow.LocationID != crOpportunityRow.LocationID)
                {
                    graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.locationID>(fsServiceOrderRow, crOpportunityRow.LocationID);
                    somethingChanged = true;
                }
            }

            if (fsServiceOrderRow.CuryID != crOpportunityRow.CuryID)
            {
                graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.curyID>(fsServiceOrderRow, crOpportunityRow.CuryID);
                somethingChanged = true;
            }

            if (fsServiceOrderRow.BranchID != crOpportunityRow.BranchID)
            {
                graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.branchID>(fsServiceOrderRow, crOpportunityRow.BranchID);
                somethingChanged = true;
            }

            if (fsServiceOrderRow.BranchLocationID != fsCreateServiceOrderOnOpportunityFilterRow.BranchLocationID)
            {
                graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.branchLocationID>(fsServiceOrderRow, fsCreateServiceOrderOnOpportunityFilterRow.BranchLocationID);
                somethingChanged = true;
            }

            if (fsServiceOrderRow.ContactID != crOpportunityRow.ContactID)
            {
                graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.contactID>(fsServiceOrderRow, crOpportunityRow.ContactID);
                somethingChanged = true;
            }

            if (fsServiceOrderRow.DocDesc != crOpportunityRow.Subject)
            {
                graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.docDesc>(fsServiceOrderRow, crOpportunityRow.Subject);
                somethingChanged = true;
            }

            if (fsServiceOrderRow.ProjectID != crOpportunityRow.ProjectID)
            {
                graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.projectID>(fsServiceOrderRow, crOpportunityRow.ProjectID);
                somethingChanged = true;
            }

            if (crOpportunityRow.OwnerID != null)
            {
                if (crOpportunityRow.OwnerID != (Guid?)cache.GetValueOriginal <CROpportunity.ownerID>(crOpportunityRow))
                {
                    int?salesPersonID = GetSalesPersonID(graphServiceOrderEntry, crOpportunityRow.OwnerID);

                    if (salesPersonID != null)
                    {
                        graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.salesPersonID>(fsServiceOrderRow, salesPersonID);
                        somethingChanged = true;
                    }
                }
            }

            if (fsServiceOrderRow.OrderDate != crOpportunityRow.CloseDate)
            {
                graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.orderDate>(fsServiceOrderRow, crOpportunityRow.CloseDate);
                somethingChanged = true;
            }

            FSAddress fsAddressRow = graphServiceOrderEntry.ServiceOrder_Address.Select();
            FSContact fsContactRow = graphServiceOrderEntry.ServiceOrder_Contact.Select();

            ApplyChangesfromContactInfo(graphServiceOrderEntry, crContactRow, fsContactRow, ref somethingChanged);
            ApplyChangesfromAddressInfo(graphServiceOrderEntry, crAddressRow, fsAddressRow, ref somethingChanged);

            if (fsServiceOrderRow.TaxZoneID != crOpportunityRow.TaxZoneID)
            {
                graphServiceOrderEntry.ServiceOrderRecords.SetValueExt <FSServiceOrder.taxZoneID>(fsServiceOrderRow, crOpportunityRow.TaxZoneID);
                somethingChanged = true;
            }

            if (somethingChanged && updatingExistingSO)
            {
                graphServiceOrderEntry.ServiceOrderRecords.Update(fsServiceOrderRow);
            }
        }