private void VerifyPrepaidContractRelated(PXCache cache, FSCustomerBillingSetup fsCustomerBillingSetupRow)
        {
            if (fsCustomerBillingSetupRow.BillingCycleID == (int?)cache.GetValueOriginal <FSCustomerBillingSetup.billingCycleID>(fsCustomerBillingSetupRow))
            {
                return;
            }

            if (Setup.Current != null &&
                Setup.Current.CustomerMultipleBillingOptions == true)
            {
                int count = PXSelectJoin <FSServiceOrder,
                                          InnerJoin <FSSrvOrdType,
                                                     On <FSSrvOrdType.srvOrdType, Equal <FSServiceOrder.srvOrdType> > >,
                                          Where <
                                              FSServiceOrder.billContractPeriodID, IsNotNull,
                                              And <
                                                  FSServiceOrder.customerID, Equal <Required <FSServiceOrder.customerID> >,
                                                  And <
                                                      FSServiceOrder.srvOrdType, Equal <Required <FSServiceOrder.srvOrdType> > > > > >
                            .Select(Base, fsCustomerBillingSetupRow.CustomerID, fsCustomerBillingSetupRow.SrvOrdType).Count;

                if (count > 0)
                {
                    cache.RaiseExceptionHandling <FSCustomerBillingSetup.srvOrdType>(fsCustomerBillingSetupRow,
                                                                                     fsCustomerBillingSetupRow.SrvOrdType,
                                                                                     new PXSetPropertyException(TX.Error.NO_UPDATE_BILLING_CYCLE_SERVICE_CONTRACT_RELATED, PXErrorLevel.Error));
                    throw new PXException(TX.Error.NO_UPDATE_BILLING_CYCLE_SERVICE_CONTRACT_RELATED);
                }
            }
        }
        private void InsertUpdateCustomerBillingSetup(PXCache cache, Customer customerRow, FSxCustomer fsxCustomerRow)
        {
            FSSetup fsSetupRow = PXSelect <FSSetup> .Select(Base);

            if (fsSetupRow != null &&
                fsSetupRow.CustomerMultipleBillingOptions == false)
            {
                FSCustomerBillingSetup fsCustomerBillingSetupRow = CustomerBillingCycles.Select();

                if (fsxCustomerRow.BillingCycleID == null)
                {
                    CustomerBillingCycles.Delete(fsCustomerBillingSetupRow);
                    return;
                }

                if (fsCustomerBillingSetupRow == null)
                {
                    fsCustomerBillingSetupRow            = CustomerBillingCycles.Insert(new FSCustomerBillingSetup());
                    fsCustomerBillingSetupRow.SrvOrdType = null;
                }

                fsCustomerBillingSetupRow.BillingCycleID     = fsxCustomerRow.BillingCycleID;
                fsCustomerBillingSetupRow.SendInvoicesTo     = fsxCustomerRow.SendInvoicesTo;
                fsCustomerBillingSetupRow.BillShipmentSource = fsxCustomerRow.BillShipmentSource;
                fsCustomerBillingSetupRow.FrequencyType      = ID.Frequency_Type.NONE;

                CustomerBillingCycles.Update(fsCustomerBillingSetupRow);
            }
        }
Beispiel #3
0
        public virtual void UpdateBillingInfoInDocs(int?currentCustomerID, int?currentBillingCycleID)
        {
            var tempGraph       = new PXGraph();
            var cutOffDateCache = new Dictionary <BillingCycleIDAndDate, DateTime?>();

            var resultSet = PXSelectJoin <FSServiceOrder,
                                          CrossJoinSingleTable <FSSetup,
                                                                LeftJoin <FSCustomerBillingSetup,
                                                                          On <
                                                                              FSCustomerBillingSetup.customerID, Equal <FSServiceOrder.billCustomerID>,
                                                                              And <
                                                                                  Where2 <
                                                                                      Where <FSSetup.customerMultipleBillingOptions, Equal <False>,
                                                                                             And <FSCustomerBillingSetup.srvOrdType, IsNull,
                                                                                                  And <FSCustomerBillingSetup.active, Equal <True> > > >,
                                                                                      Or <
                                                                                          Where <FSSetup.customerMultipleBillingOptions, Equal <True>,
                                                                                                 And <FSCustomerBillingSetup.srvOrdType, Equal <FSServiceOrder.srvOrdType>,
                                                                                                      And <FSCustomerBillingSetup.active, Equal <True> > > > > > > > > >,
                                          Where2 <
                                              Where <FSServiceOrder.postedBy, IsNull>,
                                              And <
                                                  Where2 <
                                                      Where <Required <FSServiceOrder.billCustomerID>, IsNotNull,
                                                             And <FSServiceOrder.billCustomerID, Equal <Required <FSServiceOrder.billCustomerID> > > >,
                                                      Or <
                                                          Where2 <
                                                              Where <Required <FSServiceOrder.billCustomerID>, IsNull>,
                                                              And <
                                                                  Where2 <
                                                                      Where2 <
                                                                          Where <FSServiceOrder.cBID, IsNull,
                                                                                 And <FSCustomerBillingSetup.cBID, IsNotNull> >,
                                                                          Or <
                                                                              Where <FSServiceOrder.cBID, IsNotNull,
                                                                                     And <FSCustomerBillingSetup.cBID, IsNull> > > >,
                                                                      Or <
                                                                          Where2 <
                                                                              Where <
                                                                                  FSServiceOrder.cBID, NotEqual <FSCustomerBillingSetup.cBID>,
                                                                                  Or <
                                                                                      Where <
                                                                                          FSCustomerBillingSetup.cBID, IsNotNull,
                                                                                          And <
                                                                                              FSServiceOrder.cutOffDate, IsNull> > > >,
                                                                              Or <
                                                                                  Where <
                                                                                      FSCustomerBillingSetup.billingCycleID, Equal <Required <FSCustomerBillingSetup.billingCycleID> > > > > > > > > > > > > >
                            .Select(tempGraph, currentCustomerID, currentCustomerID, currentCustomerID, currentBillingCycleID);

            foreach (PXResult <FSServiceOrder, FSSetup, FSCustomerBillingSetup> result in resultSet)
            {
                FSServiceOrder         fsServiceOrderRow         = (FSServiceOrder)result;
                FSCustomerBillingSetup fsCustomerBillingSetupRow = (FSCustomerBillingSetup)result;

                UpdateBillingInfoInDoc(tempGraph, fsServiceOrderRow, fsCustomerBillingSetupRow.CBID, fsCustomerBillingSetupRow.BillingCycleID, currentBillingCycleID != null, currentCustomerID != null, cutOffDateCache);
            }
        }
        protected void FSCustomerBillingSetup_BillingCycleID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fsCustomerBillingSetupRow = (FSCustomerBillingSetup)e.Row;

            ResetSendInvoicesToFromBillingCycle(null, fsCustomerBillingSetupRow);
        }
Beispiel #5
0
        protected virtual void _(Events.RowSelecting <FSCustomerBillingSetup> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fscustomerBillingSetupRow = (FSCustomerBillingSetup)e.Row;

            fscustomerBillingSetupRow.IsBeingDeleted = false;
        }
Beispiel #6
0
        protected virtual void _(Events.RowUpdating <FSCustomerBillingSetup> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fsCustomerBillingSetupRow = (FSCustomerBillingSetup)e.NewRow;

            e.Cancel = CheckDuplicatedEntry(e.Cache, fsCustomerBillingSetupRow);
        }
Beispiel #7
0
        protected virtual void _(Events.FieldUpdated <FSCustomerBillingSetup, FSCustomerBillingSetup.billingCycleID> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fsCustomerBillingSetupRow = (FSCustomerBillingSetup)e.Row;

            ResetSendInvoicesToFromBillingCycle(null, fsCustomerBillingSetupRow);
        }
Beispiel #8
0
        protected virtual void _(Events.FieldUpdated <FSCustomerBillingSetup, FSCustomerBillingSetup.frequencyType> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fsCustomerBillingSetupRow = (FSCustomerBillingSetup)e.Row;

            ResetTimeCycleOptions(fsCustomerBillingSetupRow);
        }
        protected void FSCustomerBillingSetup_FrequencyType_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fsCustomerBillingSetupRow = (FSCustomerBillingSetup)e.Row;

            ResetTimeCycleOptions(fsCustomerBillingSetupRow);
        }
        /// <summary>
        /// Keep synchronized the Customer's Billing Cycle settings when Multiple Billing Cycle option is turn on from Setup screen.
        /// </summary>
        public virtual void KeepCustomerMultBillCyleSettings(PXGraph setupGraph)
        {
            PXResultset <FSServiceOrder> customersAffectedRows = PXSelectJoinGroupBy <FSServiceOrder,
                                                                                      InnerJoin <Customer,
                                                                                                 On <
                                                                                                     Customer.bAccountID, Equal <FSServiceOrder.customerID> >,
                                                                                                 InnerJoin <FSSrvOrdType,
                                                                                                            On <
                                                                                                                FSSrvOrdType.srvOrdType, Equal <FSServiceOrder.srvOrdType> >,
                                                                                                            LeftJoin <FSCustomerBillingSetup,
                                                                                                                      On <
                                                                                                                          FSCustomerBillingSetup.customerID, Equal <Customer.bAccountID>,
                                                                                                                          And <FSCustomerBillingSetup.srvOrdType, Equal <FSServiceOrder.srvOrdType>,
                                                                                                                               And <FSCustomerBillingSetup.billingCycleID, Equal <FSxCustomer.billingCycleID> > > > > > >,
                                                                                      Where <
                                                                                          FSCustomerBillingSetup.billingCycleID, IsNull,
                                                                                          And <FSxCustomer.billingCycleID, IsNotNull,
                                                                                               And <FSSrvOrdType.active, Equal <True>,
                                                                                                    And <FSSrvOrdType.behavior, NotEqual <FSSrvOrdType.behavior.Quote> > > > >,
                                                                                      Aggregate <
                                                                                          GroupBy <FSServiceOrder.customerID,
                                                                                                   GroupBy <FSServiceOrder.srvOrdType> > >,
                                                                                      OrderBy <
                                                                                          Asc <FSServiceOrder.customerID> > >
                                                                 .Select(this);

            var graphCustomer  = PXGraph.CreateInstance <CustomerMaint>();
            int?lastCustomerID = null;

            foreach (FSServiceOrder currentCustomer in customersAffectedRows)
            {
                if (currentCustomer.CustomerID != lastCustomerID)
                {
                    graphCustomer.BAccount.Current = graphCustomer.BAccount.Search <Customer.bAccountID>(currentCustomer.CustomerID);
                    lastCustomerID = currentCustomer.CustomerID;
                }

                FSxCustomer fsxCustomerRow = graphCustomer.BAccount.Cache.GetExtension <FSxCustomer>(graphCustomer.BAccount.Current);

                if (fsxCustomerRow != null)
                {
                    SM_CustomerMaint sm_CustomerMaintGraph = graphCustomer.GetExtension <SM_CustomerMaint>();

                    FSCustomerBillingSetup fsCustomerBillingSetupRow = new FSCustomerBillingSetup();
                    fsCustomerBillingSetupRow.SrvOrdType         = currentCustomer.SrvOrdType;
                    fsCustomerBillingSetupRow.BillingCycleID     = fsxCustomerRow.BillingCycleID;
                    fsCustomerBillingSetupRow.SendInvoicesTo     = fsxCustomerRow.SendInvoicesTo;
                    fsCustomerBillingSetupRow.BillShipmentSource = fsxCustomerRow.BillShipmentSource;

                    sm_CustomerMaintGraph.CustomerBillingCycles.Insert(fsCustomerBillingSetupRow);
                    graphCustomer.Save.Press();
                }
            }
        }
Beispiel #11
0
        protected virtual void _(Events.RowDeleted <FSCustomerBillingSetup> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fsCustomerBillingSetup = (FSCustomerBillingSetup)e.Row;
            FSxCustomer            fsxCustomerRow         = PXCache <Customer> .GetExtension <FSxCustomer>(Base.BAccount.Current);

            fsCustomerBillingSetup.IsBeingDeleted = true;
            e.Cache.SetValue <FSCustomerBillingSetup.active>(fsCustomerBillingSetup, false);
            fsxCustomerRow.BillingOptionsChanged = true;
        }
        /// <summary>
        /// Checks if the current row is valid for edition.
        /// The line is valid if there is not another line with the same Service Order Type.
        /// </summary>
        /// <param name="fsCustomerBillingSetupRow_Current"><c>currentFSCustomerBillingRow</c> row.</param>
        /// <returns>Returns true if the line is valid.</returns>
        private bool IsThisLineValid(FSCustomerBillingSetup fsCustomerBillingSetupRow_Current)
        {
            int count = 0;

            foreach (FSCustomerBillingSetup fsCustomerBillingRow in CustomerBillingCycles.Select())
            {
                if (fsCustomerBillingSetupRow_Current.SrvOrdType != null &&
                    fsCustomerBillingSetupRow_Current.SrvOrdType.Equals(fsCustomerBillingRow.SrvOrdType) &&
                    fsCustomerBillingSetupRow_Current.Active == true)
                {
                    count++;
                }
            }

            return(count <= 1);
        }
        protected virtual void FSCustomerBillingSetup_RowDeleting(PXCache cache, PXRowDeletingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fscustomerBillingSetupRow = (FSCustomerBillingSetup)e.Row;

            bool setDocumentToInactive = IsCBIDRelatedToPostedDocuments(fscustomerBillingSetupRow.CBID);

            if (setDocumentToInactive)
            {
                fscustomerBillingSetupRow.Active = false;
                cache.SetStatus(fscustomerBillingSetupRow, PXEntryStatus.Updated);
            }
        }
Beispiel #14
0
        protected virtual bool CheckDuplicatedEntry(PXCache cache, FSCustomerBillingSetup fsCustomerBillingSetupRow)
        {
            foreach (FSCustomerBillingSetup row in CustomerBillingCycles.Select())
            {
                if (row.SrvOrdType == fsCustomerBillingSetupRow.SrvOrdType &&
                    row.CBID != fsCustomerBillingSetupRow.CBID &&
                    (row.IsBeingDeleted == false && fsCustomerBillingSetupRow.IsBeingDeleted == false))
                {
                    cache.RaiseExceptionHandling <FSCustomerBillingSetup.srvOrdType>(
                        fsCustomerBillingSetupRow, fsCustomerBillingSetupRow.SrvOrdType,
                        new PXSetPropertyException(ErrorMessages.DuplicateEntryAdded));

                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Resets the values of the Frequency Fields depending on the Frequency Type value.
        /// </summary>
        /// <param name="fsCustomerBillingSetupRow"><c>fsCustomerBillingRow</c> row.</param>
        private void ResetTimeCycleOptions(FSCustomerBillingSetup fsCustomerBillingSetupRow)
        {
            switch (fsCustomerBillingSetupRow.FrequencyType)
            {
            case ID.Time_Cycle_Type.DAY_OF_MONTH:
                fsCustomerBillingSetupRow.MonthlyFrequency = 31;
                break;

            case ID.Time_Cycle_Type.WEEKDAY:
                fsCustomerBillingSetupRow.WeeklyFrequency = 5;
                break;

            default:
                fsCustomerBillingSetupRow.WeeklyFrequency  = null;
                fsCustomerBillingSetupRow.MonthlyFrequency = null;
                break;
            }
        }
        protected void FSCustomerBillingSetup_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fsCustomerBillingSetupRow = (FSCustomerBillingSetup)e.Row;

            bool lineValid = IsThisLineValid(fsCustomerBillingSetupRow);

            PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.billingCycleID>(cache, fsCustomerBillingSetupRow, lineValid);
            PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.sendInvoicesTo>(cache, fsCustomerBillingSetupRow, lineValid);
            PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.billShipmentSource>(cache, fsCustomerBillingSetupRow, lineValid);
            PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.frequencyType>(cache, fsCustomerBillingSetupRow, lineValid);

            bool enableFieldsBySrvOrdType = string.IsNullOrEmpty(fsCustomerBillingSetupRow.SrvOrdType) == false;
            bool enableSrvOrdType         = !enableFieldsBySrvOrdType || cache.GetStatus(fsCustomerBillingSetupRow) == PXEntryStatus.Inserted;

            PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.srvOrdType>(cache, fsCustomerBillingSetupRow, enableSrvOrdType);
            PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.billingCycleID>(cache, fsCustomerBillingSetupRow, enableFieldsBySrvOrdType);

            //Disables the TimeCycleType field if the type of the BillingCycleID selected is Time Cycle.
            if (fsCustomerBillingSetupRow.BillingCycleID != null)
            {
                FSBillingCycle fsBillingCycleRow =
                    PXSelect <FSBillingCycle,
                              Where <
                                  FSBillingCycle.billingCycleID, Equal <Required <FSBillingCycle.billingCycleID> > > >
                    .Select(Base, fsCustomerBillingSetupRow.BillingCycleID);

                PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.frequencyType>(cache, fsCustomerBillingSetupRow, fsBillingCycleRow.BillingCycleType != ID.Billing_Cycle_Type.TIME_FRAME);

                bool forbidUpdateBillingOptions = SharedFunctions.IsNotAllowedBillingOptionsModification(fsBillingCycleRow);

                PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.sendInvoicesTo>(cache, fsCustomerBillingSetupRow, forbidUpdateBillingOptions == false);
                PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.billShipmentSource>(cache, fsCustomerBillingSetupRow, forbidUpdateBillingOptions == false);
            }
            else
            {
                PXUIFieldAttribute.SetEnabled <FSCustomerBillingSetup.frequencyType>(cache, fsCustomerBillingSetupRow, false);
            }
        }
        /// <summary>
        /// Resets the value from Send to Invoices dropdown if the billing cycle can not be sent to specific locations.
        /// </summary>
        private void ResetSendInvoicesToFromBillingCycle(Customer customerRow, FSCustomerBillingSetup fsCustomerBillingSetupRow)
        {
            List <object>  args = new List <object>();
            FSBillingCycle fsBillingCycleRow   = null;
            BqlCommand     billingCycleCommand = new Select <FSBillingCycle,
                                                             Where <
                                                                 FSBillingCycle.billingCycleID, Equal <Required <FSBillingCycle.billingCycleID> > > >();

            PXView billingCycleView = new PXView(Base, true, billingCycleCommand);

            if (customerRow != null)
            {
                FSxCustomer fsxCustomerRow = PXCache <Customer> .GetExtension <FSxCustomer>(customerRow);

                args.Add(fsxCustomerRow.BillingCycleID);

                fsBillingCycleRow = (FSBillingCycle)billingCycleView.SelectSingle(args.ToArray());

                if (fsBillingCycleRow != null)
                {
                    if (SharedFunctions.IsNotAllowedBillingOptionsModification(fsBillingCycleRow))
                    {
                        fsxCustomerRow.SendInvoicesTo     = ID.Send_Invoices_To.BILLING_CUSTOMER_BILL_TO;
                        fsxCustomerRow.BillShipmentSource = ID.Ship_To.SERVICE_ORDER_ADDRESS;
                    }
                }
            }
            else if (fsCustomerBillingSetupRow != null)
            {
                args.Add(fsCustomerBillingSetupRow.BillingCycleID);
                fsBillingCycleRow = (FSBillingCycle)billingCycleView.SelectSingle(args.ToArray());

                if (fsBillingCycleRow != null)
                {
                    if (SharedFunctions.IsNotAllowedBillingOptionsModification(fsBillingCycleRow))
                    {
                        fsCustomerBillingSetupRow.SendInvoicesTo     = ID.Send_Invoices_To.BILLING_CUSTOMER_BILL_TO;
                        fsCustomerBillingSetupRow.BillShipmentSource = ID.Ship_To.SERVICE_ORDER_ADDRESS;
                    }
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// Sets the Customer Billing Cycle from its Customer Class.
        /// </summary>
        public virtual void SetBillingCycleFromCustomerClass(PXCache cache, Customer customerRow)
        {
            if (customerRow.CustomerClassID == null)
            {
                return;
            }

            FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(Base);

            if (fsSetupRow != null &&
                fsSetupRow.CustomerMultipleBillingOptions == true)
            {
                foreach (FSCustomerBillingSetup fsCustomerBillingSetupRow in this.CustomerBillingCycles.Select())
                {
                    this.CustomerBillingCycles.Delete(fsCustomerBillingSetupRow);
                }

                var customerClsBillingSetupRows = PXSelect <FSCustomerClassBillingSetup,
                                                            Where <
                                                                FSCustomerClassBillingSetup.customerClassID, Equal <Required <FSCustomerClassBillingSetup.customerClassID> > > >
                                                  .Select(Base, customerRow.CustomerClassID);

                foreach (FSCustomerClassBillingSetup fsCustomerClassBillingSetupRow in customerClsBillingSetupRows)
                {
                    FSCustomerBillingSetup fsCustomerBillingSetupRow = new FSCustomerBillingSetup();
                    fsCustomerBillingSetupRow.SrvOrdType         = fsCustomerClassBillingSetupRow.SrvOrdType;
                    fsCustomerBillingSetupRow.BillingCycleID     = fsCustomerClassBillingSetupRow.BillingCycleID;
                    fsCustomerBillingSetupRow.SendInvoicesTo     = fsCustomerClassBillingSetupRow.SendInvoicesTo;
                    fsCustomerBillingSetupRow.BillShipmentSource = fsCustomerClassBillingSetupRow.BillShipmentSource;
                    fsCustomerBillingSetupRow.FrequencyType      = fsCustomerClassBillingSetupRow.FrequencyType;

                    this.CustomerBillingCycles.Insert(fsCustomerBillingSetupRow);
                }

                return;
            }

            SetSingleBillingSettings(cache, customerRow);
        }
        protected virtual void FSCustomerBillingSetup_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSCustomerBillingSetup fsCustomerBillingSetup = (FSCustomerBillingSetup)e.Row;
            FSxCustomer            fsxCustomerRow         = PXCache <Customer> .GetExtension <FSxCustomer>(Base.BAccount.Current);

            if (cache.GetStatus(fsCustomerBillingSetup) == PXEntryStatus.Updated)
            {
                bool insertNewRow = IsCBIDRelatedToPostedDocuments(fsCustomerBillingSetup.CBID);

                if (insertNewRow)
                {
                    fsxCustomerRow.BillingOptionsChanged = true;

                    cache.SetValue <FSCustomerBillingSetup.active>(fsCustomerBillingSetup, false);

                    FSCustomerBillingSetup newCustomerBilingSetupRow = new FSCustomerBillingSetup();
                    var tempFSCustomerBillingSetupCache = new PXCache <FSCustomerBillingSetup>(Base);
                    newCustomerBilingSetupRow.CustomerID = fsCustomerBillingSetup.CustomerID;
                    newCustomerBilingSetupRow.SrvOrdType = fsCustomerBillingSetup.SrvOrdType;
                    newCustomerBilingSetupRow.Active     = true;
                    newCustomerBilingSetupRow            = (FSCustomerBillingSetup)tempFSCustomerBillingSetupCache.Insert(newCustomerBilingSetupRow);

                    foreach (var field in cache.Fields)
                    {
                        if (!cache.Keys.Contains(field) &&
                            field.ToLower() != typeof(FSCustomerBillingSetup.active).Name.ToLower())
                        {
                            tempFSCustomerBillingSetupCache.SetValue(
                                newCustomerBilingSetupRow,
                                field.ToString(),
                                cache.GetValue(
                                    fsCustomerBillingSetup, field.ToString()));
                        }
                    }

                    tempFSCustomerBillingSetupCache.Persist(PXDBOperation.Insert);

                    foreach (var field in cache.Fields)
                    {
                        if (!cache.Keys.Contains(field) &&
                            field.ToLower() != typeof(FSCustomerBillingSetup.active).Name.ToLower())
                        {
                            cache.SetValue(
                                fsCustomerBillingSetup,
                                field.ToString(),
                                cache.GetValueOriginal(
                                    fsCustomerBillingSetup,
                                    field.ToString()));
                        }
                    }

                    cache.SetValue <FSCustomerBillingSetup.active>(fsCustomerBillingSetup, false);
                }
            }

            if (e.Operation == PXDBOperation.Update)
            {
                VerifyPrepaidContractRelated(cache, fsCustomerBillingSetup);
            }
        }