protected virtual void FSRouteContractSchedule_EntityID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSRouteContractSchedule fsRouteContractScheduleRow = (FSRouteContractSchedule)e.Row;

            if (fsRouteContractScheduleRow.CustomerID != null && fsRouteContractScheduleRow.EntityID != null)
            {
                FSServiceContract fsServiceContract =
                    PXSelect <FSServiceContract,
                              Where <
                                  FSServiceContract.customerID, Equal <Required <FSServiceContract.customerID> >,
                                  And <FSServiceContract.serviceContractID, Equal <Required <FSServiceContract.serviceContractID> > > > >
                    .Select(this, fsRouteContractScheduleRow.CustomerID, fsRouteContractScheduleRow.EntityID);

                if (fsServiceContract != null)
                {
                    fsRouteContractScheduleRow.CustomerLocationID = fsServiceContract.CustomerLocationID;
                    fsRouteContractScheduleRow.BranchID           = fsServiceContract.BranchID;
                    fsRouteContractScheduleRow.BranchLocationID   = fsServiceContract.BranchLocationID;
                    fsRouteContractScheduleRow.StartDate          = fsServiceContract.StartDate;
                    fsRouteContractScheduleRow.EndDate            = fsServiceContract.EndDate;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows to calculate the <c>RefNbr</c> sequence when trying to insert a new register
        /// It's called from the Persisting event of FSServiceContract.
        /// </summary>
        protected override bool SetRefNbr(PXCache cache, object row)
        {
            FSServiceContract fsServiceContractRow = (FSServiceContract)row;

            FSServiceContract fsServiceContractRow_tmp = PXSelectGroupBy <FSServiceContract,
                                                                          Where <
                                                                              FSServiceContract.customerID, Equal <Current <FSServiceContract.customerID> > >,
                                                                          Aggregate <
                                                                              Max <FSServiceContract.refNbr,
                                                                                   GroupBy <
                                                                                       FSServiceContract.customerID> > > >
                                                         .Select(cache.Graph);

            string refNbr = fsServiceContractRow_tmp == null ? null : fsServiceContractRow_tmp.RefNbr;

            if (string.IsNullOrEmpty(refNbr))
            {
                refNbr = initialRefNbr;
            }
            else
            {
                refNbr = (int.Parse(refNbr) + 1).ToString().PadLeft(initialRefNbr.Length, '0');
            }

            fsServiceContractRow.RefNbr = refNbr;

            return(true);
        }
        protected virtual void _(Events.FieldUpdated <FSContractSchedule, FSContractSchedule.entityID> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSContractSchedule fsScheduleRow = (FSContractSchedule)e.Row;

            if (fsScheduleRow.EntityID != null)
            {
                FSServiceContract fsServiceContract = PXSelect <FSServiceContract,
                                                                Where <
                                                                    FSServiceContract.serviceContractID, Equal <Required <FSServiceContract.serviceContractID> > > >
                                                      .Select(this, fsScheduleRow.EntityID);

                if (fsServiceContract != null)
                {
                    fsScheduleRow.CustomerID         = fsServiceContract.CustomerID;
                    fsScheduleRow.CustomerLocationID = fsServiceContract.CustomerLocationID;
                    fsScheduleRow.BranchID           = fsServiceContract.BranchID;
                    fsScheduleRow.BranchLocationID   = fsServiceContract.BranchLocationID;
                    fsScheduleRow.StartDate          = fsServiceContract.StartDate;
                    fsScheduleRow.EndDate            = fsServiceContract.EndDate;
                }
            }
        }
        protected virtual void FSContractSchedule_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSContractSchedule fsScheduleRow        = (FSContractSchedule)e.Row;
            FSServiceContract  fsServiceContractRow = (FSServiceContract)ContractSelected.Current;

            ContractSchedule_RowPersisting_PartialHandler(cache, fsServiceContractRow, fsScheduleRow, e.Operation, TX.ModuleName.EQUIPMENT_MODULE);
        }
Ejemplo n.º 5
0
        public static bool TryParse(object row, out FSServiceContract fsServiceContractRow)
        {
            fsServiceContractRow = null;

            if (row is FSServiceContract)
            {
                fsServiceContractRow = (FSServiceContract)row;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        protected override void _(Events.RowSelected <FSServiceContract> e)
        {
            base._(e);

            if (e.Row == null)
            {
                return;
            }

            FSServiceContract fsServiceContractRow = (FSServiceContract)e.Row;

            SharedFunctions.ServiceContractDynamicDropdown(e.Cache, fsServiceContractRow);
        }
Ejemplo n.º 7
0
        protected override void FSServiceContract_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            base.FSServiceContract_RowSelected(cache, e);

            if (e.Row == null)
            {
                return;
            }

            FSServiceContract fsServiceContractRow = (FSServiceContract)e.Row;

            SharedFunctions.ServiceContractDynamicDropdown(cache, fsServiceContractRow);
        }
        /// <summary>
        /// Process all Schedules (FSSchedule) in each Contract (FSContract).
        /// </summary>
        public virtual void processServiceContract(PXCache cache, FSContractSchedule fsScheduleRow, DateTime?fromDate, DateTime?toDate)
        {
            List <Schedule> mapScheduleResults = new List <Schedule>();

            FSServiceContract fsServiceContractRow_Current = ServiceContractSelected.Select(fsScheduleRow.EntityID);

            if (fsServiceContractRow_Current != null)
            {
                fsScheduleRow.ContractDescr = fsServiceContractRow_Current.DocDesc;
            }

            mapScheduleResults = MapFSScheduleToSchedule.convertFSScheduleToSchedule(cache, fsScheduleRow, toDate, ID.RecordType_ServiceContract.SERVICE_CONTRACT);
            generate_APP_SO_UpdateContracts(mapScheduleResults, ID.RecordType_ServiceContract.SERVICE_CONTRACT, fromDate, toDate, fsScheduleRow);
        }
Ejemplo n.º 9
0
        public ContractInvoiceLine(PXResult <FSContractPeriodDet, FSContractPeriod, FSServiceContract, FSBranchLocation> row)
        {
            FSServiceContract   fsServiceContractRow   = (FSServiceContract)row;
            FSContractPeriodDet fsContractPeriodDetRow = (FSContractPeriodDet)row;
            FSBranchLocation    fsBranchLocationRow    = (FSBranchLocation)row;

            ServiceContractID   = fsServiceContractRow.ServiceContractID;
            ContractType        = fsServiceContractRow.RecordType;
            ContractPeriodID    = fsContractPeriodDetRow.ContractPeriodDetID;
            ContractPeriodDetID = fsContractPeriodDetRow.ContractPeriodID;

            BillingRule   = fsContractPeriodDetRow.BillingRule;
            InventoryID   = fsContractPeriodDetRow.InventoryID;
            UOM           = fsContractPeriodDetRow.UOM;
            SMEquipmentID = fsContractPeriodDetRow.SMEquipmentID;
            CuryUnitPrice = fsContractPeriodDetRow.RecurringUnitPrice;

            ContractRelated = false;
            SubItemID       = fsBranchLocationRow?.DfltSubItemID;
            SiteID          = fsBranchLocationRow?.DfltSiteID;
            SiteLocationID  = null;
            IsBillable      = true;

            if (BillingRule == ID.BillingRule.TIME)
            {
                Qty = decimal.Divide((decimal)(fsContractPeriodDetRow.Time ?? 0), 60);
            }
            else
            {
                Qty = fsContractPeriodDetRow.Qty;
            }

            OverageItemPrice          = fsContractPeriodDetRow.OverageItemPrice;
            AcctID                    = null;
            SubID                     = null;
            EquipmentAction           = ID.Equipment_Action.NONE;
            EquipmentLineRef          = null;
            NewTargetEquipmentLineNbr = null;
            ComponentID               = null;
            LineRef                   = string.Empty;
            SalesPersonID             = fsServiceContractRow.SalesPersonID;
            Commissionable            = fsServiceContractRow.Commissionable;

            TranDescPrefix = string.Empty;

            ProjectTaskID = fsContractPeriodDetRow.ProjectTaskID;
            CostCodeID    = fsContractPeriodDetRow.CostCodeID;

            Processed = false;
        }
        public override void openServiceContractScreenBySchedules()
        {
            ServiceContractEntry graphServiceContractEntry = PXGraph.CreateInstance <ServiceContractEntry>();
            FSServiceContract    fsServiceContractRow      =
                PXSelect <FSServiceContract,
                          Where <
                              FSServiceContract.serviceContractID, Equal <Required <FSServiceContract.serviceContractID> > > >
                .Select(this, ServiceContractSchedules.Current.EntityID);

            graphServiceContractEntry.ServiceContractRecords.Current = fsServiceContractRow;
            throw new PXRedirectRequiredException(graphServiceContractEntry, null)
                  {
                      Mode = PXBaseRedirectException.WindowMode.NewWindow
                  };
        }
        protected virtual void FSRouteContractSchedule_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSRouteContractSchedule fsRouteContractScheduleRow = (FSRouteContractSchedule)e.Row;
            FSServiceContract       fsServiceContractRow       = (FSServiceContract)ContractSelected.Current;

            ValidateWeekCode(cache, fsRouteContractScheduleRow);
            ValidateDays(cache, fsRouteContractScheduleRow);

            ForceFilling_RequiredFields_RouteTab(cache, fsRouteContractScheduleRow);
            ContractSchedule_RowPersisting_PartialHandler(cache, fsServiceContractRow, fsRouteContractScheduleRow, e.Operation, TX.ModuleName.ROUTES_MODULE);
        }
        protected override void FSServiceContract_EndDate_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            base.FSServiceContract_EndDate_FieldUpdated(cache, e);

            if (e.Row == null)
            {
                return;
            }

            FSServiceContract fsServiceContractRow = (FSServiceContract)e.Row;

            foreach (FSSchedule fsScheduleRow in ContractSchedules.Select())
            {
                fsScheduleRow.EndDate = fsServiceContractRow.EndDate;
                ContractSchedules.Cache.SetStatus(fsScheduleRow, PXEntryStatus.Updated);
            }
        }
Ejemplo n.º 13
0
        protected override void _(Events.FieldUpdated <FSServiceContract, FSServiceContract.endDate> e)
        {
            base._(e);

            if (e.Row == null)
            {
                return;
            }

            FSServiceContract fsServiceContractRow = (FSServiceContract)e.Row;

            foreach (FSSchedule fsScheduleRow in ContractSchedules.Select())
            {
                fsScheduleRow.EndDate = fsServiceContractRow.EndDate;
                ContractSchedules.Cache.SetStatus(fsScheduleRow, PXEntryStatus.Updated);
            }
        }
Ejemplo n.º 14
0
        protected virtual void openServiceContractScreen()
        {
            if (RouteAppointmentForecastingRecords.Current != null)
            {
                RouteServiceContractEntry graphServiceContractEntry = PXGraph.CreateInstance <RouteServiceContractEntry>();

                FSServiceContract fsServiceContractRow = PXSelect <FSServiceContract,
                                                                   Where <
                                                                       FSServiceContract.serviceContractID, Equal <Required <FSServiceContract.serviceContractID> > > >
                                                         .Select(this, RouteAppointmentForecastingRecords.Current.ServiceContractID);

                graphServiceContractEntry.ServiceContractRecords.Current = fsServiceContractRow;
                throw new PXRedirectRequiredException(graphServiceContractEntry, null)
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
        }
        public virtual void OpenContract()
        {
            RouteServiceContractEntry graphRouteServiceContractEntry = PXGraph.CreateInstance <RouteServiceContractEntry>();

            FSServiceContract fsServiceContractRow_Local = (FSServiceContract)PXSelectJoin <FSServiceContract,
                                                                                            InnerJoin <FSSchedule,
                                                                                                       On <FSSchedule.entityID, Equal <FSServiceContract.serviceContractID>,
                                                                                                           And <FSSchedule.customerID, Equal <FSServiceContract.customerID> > > >,
                                                                                            Where <
                                                                                                FSSchedule.scheduleID, Equal <Required <FSSchedule.scheduleID> > > >
                                                           .Select(this, ServiceContracts.Current.ScheduleID);

            graphRouteServiceContractEntry.ServiceContractRecords.Current = fsServiceContractRow_Local;
            throw new PXRedirectRequiredException(graphRouteServiceContractEntry, null)
                  {
                      Mode = PXBaseRedirectException.WindowMode.NewWindow
                  };
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Allows to calculate the <c>RefNbr</c> sequence when trying to insert a new register
        /// It's called from the Persisting event of FSServiceContract.
        /// </summary>
        protected override bool SetRefNbr(PXCache cache, object row)
        {
            FSServiceContract fsServiceContractRow = (FSServiceContract)row;

            FSServiceContract fsServiceContractRowTmp = PXSelectGroupBy <FSServiceContract,
                                                                         Where <
                                                                             FSServiceContract.customerID, Equal <Current <FSServiceContract.customerID> > >,
                                                                         Aggregate <
                                                                             Max <FSServiceContract.customerContractNbr,
                                                                                  GroupBy <FSServiceContract.customerID> > > >
                                                        .Select(cache.Graph);

            string lastRefNbr = fsServiceContractRowTmp?.CustomerContractNbr;

            fsServiceContractRow.CustomerContractNbr = GetNextRefNbr(null, lastRefNbr);

            return(true);
        }
        public override void openServiceContractScreenByGenerationLogError()
        {
            ServiceContractEntry graphServiceContractEntry = PXGraph.CreateInstance <ServiceContractEntry>();

            FSServiceContract fsServiceContractRow =
                PXSelectJoin <FSServiceContract,
                              InnerJoin <FSSchedule,
                                         On <FSSchedule.entityID, Equal <FSServiceContract.serviceContractID>,
                                             And <FSSchedule.customerID, Equal <FSServiceContract.customerID> > > >,
                              Where <FSSchedule.scheduleID, Equal <Required <FSSchedule.scheduleID> > > >
                .Select(this, ErrorMessageRecords.Current.ScheduleID);

            graphServiceContractEntry.ServiceContractRecords.Current = fsServiceContractRow;
            throw new PXRedirectRequiredException(graphServiceContractEntry, null)
                  {
                      Mode = PXBaseRedirectException.WindowMode.NewWindow
                  };
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Allows to calculate the <c>RefNbr</c> sequence when trying to insert a new register.
        /// </summary>
        protected override bool SetRefNbr(PXCache cache, object row)
        {
            FSContractSchedule fsContractScheduleRow = (FSContractSchedule)row;

            if (fsContractScheduleRow.EntityID == null)
            {
                return(false);
            }

            FSServiceContract fsServiceContractRow = ServiceContractCore.ServiceContract_View.Select(cache.Graph, fsContractScheduleRow.EntityID);

            if (fsServiceContractRow == null)
            {
                return(false);
            }

            FSContractSchedule fsContractScheduleRow_tmp = PXSelectReadonly <FSContractSchedule,
                                                                             Where <
                                                                                 FSContractSchedule.entityID, Equal <Current <FSContractSchedule.entityID> >,
                                                                                 And <FSContractSchedule.entityType, Equal <FSContractSchedule.entityType.Contract> > >,
                                                                             OrderBy <
                                                                                 Desc <FSContractSchedule.scheduleID> > >
                                                           .SelectWindowed(cache.Graph, 0, 1);

            string refNbr = string.Empty;

            if (fsContractScheduleRow_tmp != null &&
                fsContractScheduleRow_tmp.RefNbr != null)
            {
                refNbr = fsContractScheduleRow_tmp.RefNbr;
            }

            if (refNbr.LastIndexOf("<NEW>") != -1)
            {
                refNbr = string.Empty;
            }

            fsContractScheduleRow.RefNbr = SharedFunctions.GetNextRefNbr(fsServiceContractRow.RefNbr, refNbr);

            return(true);
        }
        public virtual void openContract()
        {
            ContractPostBatchDetail fsContractPostDocRow = ContractPostDocRecords.Current;

            if (fsContractPostDocRow == null)
            {
                return;
            }

            FSServiceContract fsServiceContractRow =
                PXSelect <FSServiceContract,
                          Where <
                              FSServiceContract.serviceContractID, Equal <Required <FSServiceContract.serviceContractID> > > >
                .Select(this, fsContractPostDocRow.ServiceContractID);

            if (fsServiceContractRow == null)
            {
                return;
            }

            if (fsServiceContractRow.RecordType == ID.RecordType_ServiceContract.SERVICE_CONTRACT)
            {
                ServiceContractEntry graphServiceContractEntry = PXGraph.CreateInstance <ServiceContractEntry>();
                graphServiceContractEntry.ServiceContractRecords.Current = graphServiceContractEntry.ServiceContractRecords.Search <FSServiceContract.serviceContractID>(fsServiceContractRow.ServiceContractID, fsServiceContractRow.CustomerID);
                throw new PXRedirectRequiredException(graphServiceContractEntry, null)
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else
            {
                RouteServiceContractEntry graphRouteServiceContractEntry = PXGraph.CreateInstance <RouteServiceContractEntry>();
                graphRouteServiceContractEntry.ServiceContractRecords.Current = graphRouteServiceContractEntry.ServiceContractRecords.Search <FSServiceContract.serviceContractID>(fsServiceContractRow.ServiceContractID, fsServiceContractRow.CustomerID);
                throw new PXRedirectRequiredException(graphRouteServiceContractEntry, null)
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
        }
        public virtual IEnumerable GenerateProjection(PXAdapter adapter)
        {
            if (RouteAppointmentForecastingFilter.Current != null &&
                RouteAppointmentForecastingFilter.Current.DateBegin != null &&
                RouteAppointmentForecastingFilter.Current.DateEnd != null &&
                RouteAppointmentForecastingFilter.Current.DateBegin < RouteAppointmentForecastingFilter.Current.DateEnd)
            {
                DateTime beginFromFilter = RouteAppointmentForecastingFilter.Current.DateBegin.Value;
                DateTime endToFilter     = RouteAppointmentForecastingFilter.Current.DateEnd.Value;
                string   recordType      = ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT;

                int?serviceID          = RouteAppointmentForecastingFilter.Current.ServiceID;
                int?customerID         = RouteAppointmentForecastingFilter.Current.CustomerID;
                int?customerLocationID = RouteAppointmentForecastingFilter.Current.CustomerLocationID;
                int?routeID            = RouteAppointmentForecastingFilter.Current.RouteID;

                PXLongOperation.StartOperation(
                    this,
                    delegate
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        if (beginFromFilter != null && endToFilter != null)
                        {
                            DateHandler requestDate = new DateHandler(endToFilter);

                            var period = new Period((DateTime)beginFromFilter, (DateTime)endToFilter);

                            List <Scheduler.Schedule> scheduleListToProcess = new List <Scheduler.Schedule>();
                            var generator = new TimeSlotGenerator();

                            var fsRouteContractScheduleRecords =
                                PXSelectJoinGroupBy <FSRouteContractSchedule,
                                                     InnerJoin <FSServiceContract,
                                                                On <FSServiceContract.serviceContractID, Equal <FSRouteContractSchedule.entityID> >,
                                                                InnerJoin <FSScheduleRoute,
                                                                           On <FSScheduleRoute.scheduleID, Equal <FSRouteContractSchedule.scheduleID> >,
                                                                           InnerJoin <FSScheduleDet,
                                                                                      On <FSScheduleDet.scheduleID, Equal <FSRouteContractSchedule.scheduleID> > > > >,
                                                     Where <
                                                         FSRouteContractSchedule.entityType, Equal <FSSchedule.entityType.Contract>,
                                                         And <FSServiceContract.recordType, Equal <FSServiceContract.recordType.RouteServiceContract>,
                                                              And <FSRouteContractSchedule.active, Equal <True>,
                                                                   And <FSServiceContract.status, Equal <FSServiceContract.status.Active>,
                                                                        And <FSRouteContractSchedule.startDate, LessEqual <Required <FSRouteContractSchedule.startDate> >,
                                                                             And2 <
                                                                                 Where <
                                                                                     Required <FSScheduleDet.inventoryID>, IsNull,
                                                                                     Or <FSScheduleDet.inventoryID, Equal <Required <FSScheduleDet.inventoryID> > > >,
                                                                                 And2 <
                                                                                     Where <
                                                                                         Required <FSRouteContractSchedule.customerID>, IsNull,
                                                                                         Or <FSRouteContractSchedule.customerID, Equal <Required <FSRouteContractSchedule.customerID> > > >,
                                                                                     And2 <
                                                                                         Where <
                                                                                             Required <FSRouteContractSchedule.customerLocationID>, IsNull,
                                                                                             Or <FSRouteContractSchedule.customerLocationID, Equal <Required <FSRouteContractSchedule.customerLocationID> > > >,
                                                                                         And2 <
                                                                                             Where <
                                                                                                 Required <FSScheduleRoute.dfltRouteID>, IsNull,
                                                                                                 Or <FSScheduleRoute.dfltRouteID, Equal <Required <FSScheduleRoute.dfltRouteID> > > >,
                                                                                             And <
                                                                                                 Where <FSRouteContractSchedule.endDate, IsNull,
                                                                                                        Or <FSRouteContractSchedule.endDate, GreaterEqual <Required <FSRouteContractSchedule.startDate> > > > > > > > > > > > > >,
                                                     Aggregate <
                                                         GroupBy <FSRouteContractSchedule.scheduleID> > >
                                .Select(this, beginFromFilter, serviceID, serviceID, customerID, customerID, customerLocationID, customerLocationID, routeID, routeID, endToFilter);

                            foreach (FSRouteContractSchedule fsRouteContractScheduleRecord in fsRouteContractScheduleRecords)
                            {
                                List <Scheduler.Schedule> mapScheduleResults = MapFSScheduleToSchedule.convertFSScheduleToSchedule(RouteAppointmentForecastingFilter.Cache, fsRouteContractScheduleRecord, endToFilter, recordType);

                                foreach (Scheduler.Schedule mapSchedule in mapScheduleResults)
                                {
                                    scheduleListToProcess.Add(mapSchedule);
                                }
                            }

                            if (recordType == ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT)
                            {
                                foreach (Scheduler.Schedule schedule in scheduleListToProcess)
                                {
                                    schedule.Priority      = (int?)RouteScheduleProcess.SetSchedulePriority(schedule, this);
                                    schedule.RouteInfoList = RouteScheduleProcess.getRouteListFromSchedule(schedule, this);
                                }
                            }

                            List <TimeSlot> timeSlots = generator.GenerateCalendar(period, scheduleListToProcess);

                            var fsRouteAppointmentForecastingRecords =
                                PXSelect <FSRouteAppointmentForecasting,
                                          Where <
                                              FSRouteAppointmentForecasting.startDate, GreaterEqual <Required <FSRouteAppointmentForecasting.startDate> >,
                                              And <
                                                  FSRouteAppointmentForecasting.startDate, LessEqual <Required <FSRouteAppointmentForecasting.startDate> > > > >
                                .Select(this, beginFromFilter, endToFilter);

                            PXCache <FSRouteAppointmentForecasting> cacheRouteForecasting = new PXCache <FSRouteAppointmentForecasting>(this);

                            foreach (FSRouteAppointmentForecasting fsRouteAppointmentDetailProjectionRecord in fsRouteAppointmentForecastingRecords)
                            {
                                cacheRouteForecasting.PersistDeleted(fsRouteAppointmentDetailProjectionRecord);
                            }

                            foreach (TimeSlot timeSlot in timeSlots)
                            {
                                requestDate.setDate(timeSlot.DateTimeBegin);

                                FSSchedule fsScheduleRow = ScheduleSelected.Select(timeSlot.ScheduleID);

                                FSScheduleRoute fsScheduleRouteRow = ScheduleRouteSelected.Select(fsScheduleRow.ScheduleID);

                                FSServiceContract fsServiceContractRow = ServiceContractSelected.Select(fsScheduleRow.EntityID);

                                FSRouteAppointmentForecasting fsRouteAppointmentForecastingRow = new FSRouteAppointmentForecasting();

                                fsRouteAppointmentForecastingRow.RouteID            = fsScheduleRouteRow.DfltRouteID;
                                fsRouteAppointmentForecastingRow.StartDate          = requestDate.StartOfDay();
                                fsRouteAppointmentForecastingRow.ScheduleID         = fsScheduleRow.ScheduleID;
                                fsRouteAppointmentForecastingRow.ServiceContractID  = fsServiceContractRow.ServiceContractID;
                                fsRouteAppointmentForecastingRow.CustomerLocationID = fsServiceContractRow.CustomerLocationID;
                                fsRouteAppointmentForecastingRow.CustomerID         = fsServiceContractRow.CustomerID;
                                fsRouteAppointmentForecastingRow.SequenceOrder      = int.Parse(fsScheduleRouteRow.GlobalSequence);

                                cacheRouteForecasting.PersistInserted(fsRouteAppointmentForecastingRow);
                            }
                        }

                        ts.Complete();
                    }
                });
            }

            return(adapter.Get());
        }
Ejemplo n.º 21
0
        public virtual FSContractPostDoc CreateInvoiceByContract(PXGraph graphProcess, DateTime?invoiceDate, string invoiceFinPeriodID, FSContractPostBatch fsContractPostBatchRow, FSServiceContract fsServiceContractRow, FSContractPeriod fsContractPeriodRow, List <ContractInvoiceLine> docLines)
        {
            if (docLines.Count == 0)
            {
                return(null);
            }

            FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graphProcess);

            ARInvoice arInvoiceRow = new ARInvoice();

            arInvoiceRow.DocType = ARInvoiceType.Invoice;
            AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().InvoiceNumberingID);

            arInvoiceRow.DocDate     = invoiceDate;
            arInvoiceRow.FinPeriodID = invoiceFinPeriodID;
            arInvoiceRow.Hold        = true;
            arInvoiceRow             = Base.Document.Insert(arInvoiceRow);

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerID>(arInvoiceRow, fsServiceContractRow.BillCustomerID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceContractRow.BillLocationID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.branchID>(arInvoiceRow, fsServiceContractRow.BranchID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.docDesc>(arInvoiceRow, (PXMessages.LocalizeFormatNoPrefix(TX.Messages.CONTRACT_WITH_STANDARDIZED_BILLING, fsServiceContractRow.RefNbr, (string.IsNullOrEmpty(fsServiceContractRow.DocDesc) ? string.Empty : fsServiceContractRow.DocDesc))));

            string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceContractRow.BillCustomerID, null);

            if (termsID != null)
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, termsID);
            }
            else
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, fsSetupRow.DfltContractTermIDARSO);
            }

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.projectID>(arInvoiceRow, fsServiceContractRow.ProjectID);

            ARTran    arTranRow    = null;
            FSxARTran fsxARTranRow = null;
            int?      acctID;

            foreach (ContractInvoiceLine docLine in docLines)
            {
                arTranRow = new ARTran();
                arTranRow = Base.Transactions.Insert(arTranRow);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.inventoryID>(arTranRow, docLine.InventoryID);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.uOM>(arTranRow, docLine.UOM);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.salesPersonID>(arTranRow, docLine.SalesPersonID);

                arTranRow = Base.Transactions.Update(arTranRow);

                if (docLine.AcctID != null)
                {
                    acctID = docLine.AcctID;
                }
                else
                {
                    acctID = (int?)ServiceOrderCore.Get_INItemAcctID_DefaultValue(graphProcess,
                                                                                  fsSetupRow.ContractSalesAcctSource,
                                                                                  docLine.InventoryID,
                                                                                  fsServiceContractRow);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.accountID>(arTranRow, acctID);

                if (docLine.SubID != null)
                {
                    try
                    {
                        Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.subID>(arTranRow, docLine.SubID);
                    }
                    catch (PXException)
                    {
                        arTranRow.SubID = null;
                    }
                }
                else
                {
                    InvoicingFunctions.SetCombinedSubID(graphProcess,
                                                        Base.Transactions.Cache,
                                                        arTranRow,
                                                        null,
                                                        null,
                                                        fsSetupRow,
                                                        arTranRow.BranchID,
                                                        arTranRow.InventoryID,
                                                        arInvoiceRow.CustomerLocationID,
                                                        fsServiceContractRow.BranchLocationID);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, docLine.Qty);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice);

                if (docLine.ServiceContractID != null &&
                    docLine.ContractRelated == false &&
                    (docLine.SODetID != null || docLine.AppDetID != null))
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyExtPrice>(arTranRow, docLine.CuryBillableExtPrice);
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.discPct>(arTranRow, docLine.DiscPct);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.tranDesc>(arTranRow, docLine.TranDescPrefix + arTranRow.TranDesc);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taskID>(arTranRow, docLine.ProjectTaskID);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.costCodeID>(arTranRow, docLine.CostCodeID);

                arTranRow = Base.Transactions.Update(arTranRow);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.commissionable>(arTranRow, docLine.Commissionable ?? false);

                fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow);

                fsxARTranRow.Source            = ID.DocumentSource.INVOICE_FROM_SERVICECONTRACT;
                fsxARTranRow.ServiceContractID = fsServiceContractRow.ServiceContractID;
                fsxARTranRow.ContractPeriodID  = fsContractPeriodRow.ContractPeriodID;

                fsxARTranRow.BillCustomerID     = fsServiceContractRow.CustomerID;
                fsxARTranRow.CustomerLocationID = fsServiceContractRow.CustomerLocationID;

                arTranRow = Base.Transactions.Update(arTranRow);
            }

            if (Base.ARSetup.Current.RequireControlTotal == true)
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal);
            }

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, false);

            Exception newException = null;

            try
            {
                Base.Save.Press();
            }
            catch (Exception e)
            {
                List <ErrorInfo> errorList = this.GetErrorInfo();
                newException = InvoicingFunctions.GetErrorInfoInLines(errorList, e);
            }

            if (newException != null)
            {
                throw newException;
            }

            arInvoiceRow = Base.Document.Current;

            FSContractPostDoc fsContractCreatedDocRow = new FSContractPostDoc()
            {
                ContractPeriodID    = fsContractPeriodRow.ContractPeriodID,
                ContractPostBatchID = fsContractPostBatchRow.ContractPostBatchID,
                PostDocType         = arInvoiceRow.DocType,
                PostedTO            = ID.Batch_PostTo.AR,
                PostRefNbr          = arInvoiceRow.RefNbr,
                ServiceContractID   = fsServiceContractRow.ServiceContractID
            };

            return(fsContractCreatedDocRow);
        }
Ejemplo n.º 22
0
        public virtual void GetContractAndPeriod(int?serviceContractID, int?contractPeriodID, out FSServiceContract fsServiceContractRow, out FSContractPeriod fsContractPeriodRow)
        {
            fsContractPeriodRow  = null;
            fsServiceContractRow = null;

            var result = (PXResult <FSServiceContract, FSContractPeriod>)
                         PXSelectJoin <FSServiceContract,
                                       InnerJoin <FSContractPeriod,
                                                  On <FSContractPeriod.contractPeriodID, Equal <FSContractPeriod.contractPeriodID> > >,
                                       Where <
                                           FSServiceContract.serviceContractID, Equal <Required <FSServiceContract.serviceContractID> >,
                                           And <
                                               FSContractPeriod.contractPeriodID, Equal <Required <FSContractPeriod.contractPeriodID> > > > >
                         .Select(this, serviceContractID, contractPeriodID);

            if (result != null)
            {
                fsServiceContractRow = (FSServiceContract)result;
                fsContractPeriodRow  = (FSContractPeriod)result;
            }
        }
        public virtual void processServiceContract(ProcessServiceContracts graphServiceContractStatusProcess, FSServiceContract fsServiceContractRow)
        {
            if (fsServiceContractRow.RecordType == ID.RecordType_ServiceContract.SERVICE_CONTRACT)
            {
                graphServiceContractStatusProcess.graphServiceContractEntry.ServiceContractRecords.Current =
                    graphServiceContractStatusProcess.graphServiceContractEntry.ServiceContractRecords.Search <FSServiceContract.serviceContractID>(fsServiceContractRow.ServiceContractID, fsServiceContractRow.CustomerID);

                var adapter = new PXAdapter(graphServiceContractStatusProcess.graphServiceContractEntry.ServiceContractRecords);
                adapter.SortColumns = new string[] { typeof(FSServiceContract.refNbr).Name };
                adapter.Searches    = new object[] { graphServiceContractStatusProcess.graphServiceContractEntry.ServiceContractRecords.Current.RefNbr };
                adapter.MaximumRows = 1;

                if (fsServiceContractRow.UpcomingStatus == ID.Status_ServiceContract.ACTIVE)
                {
                    graphServiceContractStatusProcess.graphServiceContractEntry.ActivateContract(adapter);
                }
                else if (fsServiceContractRow.UpcomingStatus == ID.Status_ServiceContract.CANCELED)
                {
                    graphServiceContractStatusProcess.graphServiceContractEntry.CancelContract(adapter);
                }
                else if (fsServiceContractRow.UpcomingStatus == ID.Status_ServiceContract.SUSPENDED)
                {
                    graphServiceContractStatusProcess.graphServiceContractEntry.SuspendContract(adapter);
                }
                else if (fsServiceContractRow.UpcomingStatus == ID.Status_ServiceContract.EXPIRED)
                {
                    graphServiceContractStatusProcess.graphServiceContractEntry.ExpireContract();
                }
            }
            else if (fsServiceContractRow.RecordType == ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT)
            {
                graphServiceContractStatusProcess.graphRouteServiceContractEntry.ServiceContractRecords.Current =
                    graphServiceContractStatusProcess.graphRouteServiceContractEntry.ServiceContractRecords.Search <FSServiceContract.serviceContractID>(fsServiceContractRow.ServiceContractID, fsServiceContractRow.CustomerID);
                if (fsServiceContractRow.UpcomingStatus == ID.Status_ServiceContract.ACTIVE)
                {
                    graphServiceContractStatusProcess.graphRouteServiceContractEntry.ActivateContract(new PXAdapter(graphServiceContractStatusProcess.graphRouteServiceContractEntry.ServiceContractRecords));
                }
                else if (fsServiceContractRow.UpcomingStatus == ID.Status_ServiceContract.CANCELED)
                {
                    graphServiceContractStatusProcess.graphRouteServiceContractEntry.CancelContract(new PXAdapter(graphServiceContractStatusProcess.graphRouteServiceContractEntry.ServiceContractRecords));
                }
                else if (fsServiceContractRow.UpcomingStatus == ID.Status_ServiceContract.SUSPENDED)
                {
                    graphServiceContractStatusProcess.graphRouteServiceContractEntry.SuspendContract(new PXAdapter(graphServiceContractStatusProcess.graphRouteServiceContractEntry.ServiceContractRecords));
                }
                else if (fsServiceContractRow.UpcomingStatus == ID.Status_ServiceContract.EXPIRED)
                {
                    graphServiceContractStatusProcess.graphRouteServiceContractEntry.ExpireContract();
                }
            }
        }
        public virtual void ProcessContractPeriod(ProcessServiceContracts graphServiceContractStatusProcess, FSServiceContract fsServiceContractRow)
        {
            if (fsServiceContractRow.RecordType == ID.RecordType_ServiceContract.SERVICE_CONTRACT)
            {
                graphServiceContractStatusProcess.graphServiceContractEntry.ServiceContractRecords.Current =
                    graphServiceContractStatusProcess.graphServiceContractEntry.ServiceContractRecords.Search <FSServiceContract.serviceContractID>(fsServiceContractRow.ServiceContractID, fsServiceContractRow.CustomerID);

                graphServiceContractStatusProcess.graphServiceContractEntry.ContractPeriodFilter.SetValueExt <FSContractPeriodFilter.actions>(graphServiceContractStatusProcess.graphServiceContractEntry.ContractPeriodFilter.Current, ID.ContractPeriod_Actions.MODIFY_UPCOMING_BILLING_PERIOD);
                graphServiceContractStatusProcess.graphServiceContractEntry.ActivatePeriod();
            }
            else if (fsServiceContractRow.RecordType == ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT)
            {
                graphServiceContractStatusProcess.graphRouteServiceContractEntry.ServiceContractRecords.Current =
                    graphServiceContractStatusProcess.graphRouteServiceContractEntry.ServiceContractRecords.Search <FSServiceContract.serviceContractID>(fsServiceContractRow.ServiceContractID, fsServiceContractRow.CustomerID);

                graphServiceContractStatusProcess.graphRouteServiceContractEntry.ContractPeriodFilter.SetValueExt <FSContractPeriodFilter.actions>(graphServiceContractStatusProcess.graphServiceContractEntry.ContractPeriodFilter.Current, ID.ContractPeriod_Actions.MODIFY_UPCOMING_BILLING_PERIOD);
                graphServiceContractStatusProcess.graphRouteServiceContractEntry.ActivatePeriod();
            }
        }
        public virtual FSContractPostDoc CreateInvoiceByContract(PXGraph graphProcess, DateTime?invoiceDate, string invoiceFinPeriodID, FSContractPostBatch fsContractPostBatchRow, FSServiceContract fsServiceContractRow, FSContractPeriod fsContractPeriodRow, List <ContractInvoiceLine> docLines)
        {
            if (docLines.Count == 0)
            {
                return(null);
            }

            FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graphProcess);

            ARInvoice arInvoiceRow = new ARInvoice();

            arInvoiceRow.DocType = ARInvoiceType.Invoice;

            arInvoiceRow.DocDate     = invoiceDate;
            arInvoiceRow.FinPeriodID = invoiceFinPeriodID;
            arInvoiceRow.Hold        = true;
            arInvoiceRow             = Base.Document.Insert(arInvoiceRow);

            Base.Document.Cache.SetValueExt <ARInvoice.customerID>(arInvoiceRow, fsServiceContractRow.BillCustomerID);
            Base.Document.Cache.SetValueExt <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceContractRow.BillLocationID);
            Base.Document.Cache.SetValueExt <ARInvoice.branchID>(arInvoiceRow, fsServiceContractRow.BranchID);
            Base.Document.Cache.SetValueExt <ARInvoice.docDesc>(arInvoiceRow, "Contract Standardized Billing: " + fsServiceContractRow.RefNbr + " " + fsServiceContractRow.DocDesc);

            string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceContractRow.BillCustomerID, null);

            if (termsID != null)
            {
                Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, termsID);
            }
            else
            {
                Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, fsSetupRow.DfltContractTermIDARSO);
            }

            ARTran    arTranRow    = null;
            FSxARTran fsxARTranRow = null;
            int?      acctID;

            foreach (ContractInvoiceLine docLine in docLines)
            {
                arTranRow = new ARTran();
                arTranRow = Base.Transactions.Insert(arTranRow);

                Base.Transactions.Cache.SetValueExt <ARTran.inventoryID>(arTranRow, docLine.InventoryID);
                Base.Transactions.Cache.SetValueExt <ARTran.uOM>(arTranRow, docLine.UOM);
                Base.Transactions.Cache.SetValueExt <ARTran.salesPersonID>(arTranRow, docLine.SalesPersonID);

                arTranRow = Base.Transactions.Update(arTranRow);

                if (docLine.AcctID != null)
                {
                    acctID = docLine.AcctID;
                }
                else
                {
                    acctID = (int?)ServiceOrderCore.Get_INItemAcctID_DefaultValue(
                        graphProcess,
                        fsSetupRow.ContractSalesAcctSource,
                        docLine.InventoryID,
                        fsServiceContractRow);
                }

                Base.Transactions.Cache.SetValueExt <ARTran.accountID>(arTranRow, acctID);

                if (docLine.SubID != null)
                {
                    try
                    {
                        Base.Transactions.Cache.SetValueExt <ARTran.subID>(arTranRow, docLine.SubID);
                    }
                    catch (PXException)
                    {
                        arTranRow.SubID = null;
                    }
                }
                else
                {
                    InvoicingFunctions.SetCombinedSubID(
                        graphProcess,
                        Base.Transactions.Cache,
                        arTranRow,
                        null,
                        null,
                        fsSetupRow,
                        arTranRow.BranchID,
                        arTranRow.InventoryID,
                        arInvoiceRow.CustomerLocationID,
                        fsServiceContractRow.BranchLocationID);
                }

                Base.Transactions.Cache.SetValueExt <ARTran.qty>(arTranRow, docLine.Qty);

                Base.Transactions.Cache.SetValueExt <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice);

                Base.Transactions.Cache.SetValueExt <ARTran.tranDesc>(arTranRow, docLine.TranDescPrefix + arTranRow.TranDesc);

                arTranRow = Base.Transactions.Update(arTranRow);

                Base.Transactions.Cache.SetValueExt <ARTran.commissionable>(arTranRow, docLine.Commissionable ?? false);

                fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow);

                fsxARTranRow.Source             = ID.Billing_By.CONTRACT;
                fsxARTranRow.ServiceContractID  = fsServiceContractRow.ServiceContractID;
                fsxARTranRow.ContractPeriodID   = fsContractPeriodRow.ContractPeriodID;
                fsxARTranRow.BillCustomerID     = fsServiceContractRow.BillCustomerID;
                fsxARTranRow.CustomerLocationID = fsServiceContractRow.BillLocationID;

                arTranRow = Base.Transactions.Update(arTranRow);
            }

            if (Base.ARSetup.Current.RequireControlTotal == true)
            {
                Base.Document.Cache.SetValueExt <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal);
            }

            Base.Document.Cache.SetValueExt <ARInvoice.hold>(arInvoiceRow, false);

            Exception newException = null;

            try
            {
                Base.Save.Press();
            }
            catch (Exception e)
            {
                List <ErrorInfo> errorList = this.GetErrorInfo();

                var exceptionWithContextMessage = ExceptionHelper.GetExceptionWithContextMessage(
                    PXMessages.Localize(TX.Messages.ERROR_CREATING_INVOICE_IN_POSTING_BATCH),
                    e);

                newException = InvoicingFunctions.GetErrorInfoInLines(errorList, exceptionWithContextMessage);
            }

            if (newException != null)
            {
                throw newException;
            }

            arInvoiceRow = Base.Document.Current;

            FSContractPostDoc fsContractCreatedDocRow = new FSContractPostDoc()
            {
                ContractPeriodID    = fsContractPeriodRow.ContractPeriodID,
                ContractPostBatchID = fsContractPostBatchRow.ContractPostBatchID,
                PostDocType         = arInvoiceRow.DocType,
                PostedTO            = ID.Batch_PostTo.AR,
                PostRefNbr          = arInvoiceRow.RefNbr,
                ServiceContractID   = fsServiceContractRow.ServiceContractID
            };

            return(fsContractCreatedDocRow);
        }
Ejemplo n.º 26
0
 public virtual void UpdateSourcePostDoc(FSSetup fsSetupRow, FSContractPostDoc fsContractPostDocRow, FSServiceContract fsServiceContractRow)
 {
     if (fsServiceContractRow.RecordType == ID.RecordType_ServiceContract.SERVICE_CONTRACT)
     {
         ServiceContractEntry ServiceContractGraph = PXGraph.CreateInstance <ServiceContractEntry>();
         ServiceContractGraph.ServiceContractRecords.Current = ServiceContractGraph.ServiceContractRecords.Search <FSServiceContract.serviceContractID>(fsContractPostDocRow.ServiceContractID, fsServiceContractRow.CustomerID);
         ServiceContractGraph.InvoiceBillingPeriod(fsSetupRow, fsContractPostDocRow);
     }
     else
     {
         RouteServiceContractEntry RouteServiceContractGraph = PXGraph.CreateInstance <RouteServiceContractEntry>();
         RouteServiceContractGraph.ServiceContractRecords.Current = RouteServiceContractGraph.ServiceContractRecords.Search <FSServiceContract.serviceContractID>(fsContractPostDocRow.ServiceContractID, fsServiceContractRow.CustomerID);
         RouteServiceContractGraph.InvoiceBillingPeriod(fsSetupRow, fsContractPostDocRow);
     }
 }
        /// <summary>
        /// Create a Service Order from a TimeSlot.
        /// </summary>
        protected void CreateServiceOrder(TimeSlot timeSlotServiceOrder, bool createAppointmentFlag = false, bool appointmentsBelongToRoute = false)
        {
            // This action allows to avoid errors related to cache
            if (graphServiceOrderEntry != null)
            {
                graphServiceOrderEntry.Clear(PXClearOption.ClearAll);
            }
            else
            {
                graphServiceOrderEntry = PXGraph.CreateInstance <ServiceOrderEntry>();
                graphServiceOrderEntry.DisableServiceOrderUnboundFieldCalc = true;
            }

            FSSchedule        fsScheduleRow        = ScheduleSelected.Select(timeSlotServiceOrder.ScheduleID);
            FSServiceContract fsServiceContractRow = ServiceContractSelected.Select(fsScheduleRow.EntityID);

            bool isPrepaidContract = fsServiceContractRow.BillingType == ID.Contract_BillingType.STANDARDIZED_BILLINGS;

            //Services from the Schedule
            var fsScheduleDetSet = ScheduleLinesSelected.Select(timeSlotServiceOrder.ScheduleID);

            //Templates from the Schedule
            var fsScheduleDetTemplateSet = ScheduleTemplatesSelected.Select(timeSlotServiceOrder.ScheduleID);

            FSServiceOrder fsServiceOrderRow = new FSServiceOrder();

            fsServiceOrderRow.SrvOrdType = fsScheduleRow.SrvOrdType;
            graphServiceOrderEntry.ServiceOrderRecords.Insert(fsServiceOrderRow);

            fsServiceOrderRow = graphServiceOrderEntry.ServiceOrderRecords.Cache.CreateCopy(graphServiceOrderEntry.ServiceOrderRecords.Current) as FSServiceOrder;

            fsServiceOrderRow.BranchID         = fsScheduleRow.BranchID;
            fsServiceOrderRow.BranchLocationID = fsScheduleRow.BranchLocationID;
            fsServiceOrderRow.OrderDate        = timeSlotServiceOrder.DateTimeBegin.Date;
            fsServiceOrderRow.CustomerID       = fsServiceContractRow.CustomerID;
            fsServiceOrderRow.LocationID       = fsScheduleRow.CustomerLocationID;

            graphServiceOrderEntry.ServiceOrderRecords.Update(fsServiceOrderRow);
            fsServiceOrderRow = graphServiceOrderEntry.ServiceOrderRecords.Cache.CreateCopy(graphServiceOrderEntry.ServiceOrderRecords.Current) as FSServiceOrder;

            // Currently Service-Management's contracts DO NOT support multi-currency specification
            // therefore their ServiceOrders MUST be created in customer base currency
            if (PXAccess.FeatureInstalled <FeaturesSet.multicurrency>())
            {
                string curyID = null;

                Customer customer = (Customer)PXSelect <Customer,
                                                        Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > >
                                    .Select(this, fsServiceContractRow.CustomerID);

                if (customer != null)
                {
                    curyID = customer.CuryID;
                }

                if (string.IsNullOrEmpty(curyID) == true)
                {
                    curyID = this.Accessinfo.BaseCuryID ?? new PXSetup <PX.Objects.GL.Company>(this).Current?.BaseCuryID;
                }

                fsServiceOrderRow.CuryID = curyID;
            }

            fsServiceOrderRow.DocDesc           = timeSlotServiceOrder.Descr;
            fsServiceOrderRow.BillCustomerID    = fsServiceContractRow.BillCustomerID;
            fsServiceOrderRow.BillLocationID    = fsServiceContractRow.BillLocationID;
            fsServiceOrderRow.ServiceContractID = fsServiceContractRow.ServiceContractID;
            fsServiceOrderRow.ProjectID         = fsServiceContractRow.ProjectID;
            fsServiceOrderRow.DfltProjectTaskID = fsServiceContractRow.DfltProjectTaskID;

            if (isPrepaidContract == true &&
                graphServiceOrderEntry.BillingCycleRelated.Current != null &&
                graphServiceOrderEntry.BillingCycleRelated.Current.BillingBy == ID.Billing_By.SERVICE_ORDER)
            {
                fsServiceOrderRow.BillServiceContractID = fsServiceContractRow.ServiceContractID;
            }

            fsServiceOrderRow.ScheduleID        = timeSlotServiceOrder.ScheduleID;
            fsServiceOrderRow.ServiceContractID = fsServiceContractRow.ServiceContractID;
            fsServiceOrderRow.GenerationID      = timeSlotServiceOrder.GenerationID;

            fsServiceOrderRow.SalesPersonID  = fsServiceContractRow.SalesPersonID;
            fsServiceOrderRow.Commissionable = fsServiceContractRow.Commissionable;

            fsServiceOrderRow = graphServiceOrderEntry.ServiceOrderRecords.Update(fsServiceOrderRow);

            if (fsServiceOrderRow.SalesPersonID == null)
            {
                object salesPersonID;
                graphServiceOrderEntry.ServiceOrderRecords.Cache.RaiseFieldDefaulting <FSServiceOrder.salesPersonID>(fsServiceOrderRow, out salesPersonID);
                fsServiceOrderRow.SalesPersonID = (int?)salesPersonID;

                object commissionable;
                graphServiceOrderEntry.ServiceOrderRecords.Cache.RaiseFieldDefaulting <FSServiceOrder.commissionable>(fsServiceOrderRow, out commissionable);
                fsServiceOrderRow.Commissionable = (bool?)commissionable;
            }

            graphServiceOrderEntry.Answers.CopyAllAttributes(fsServiceOrderRow, fsScheduleRow);

            #region Setting Service Order Details
            foreach (FSScheduleDet fsScheduleDetRow in fsScheduleDetSet)
            {
                if (fsScheduleDetRow.LineType == ID.LineType_ServiceContract.SERVICE_TEMPLATE)
                {
                    foreach (FSScheduleDet fsScheduleDetLocalRow in fsScheduleDetTemplateSet.Where(x => ((FSScheduleDet)x).ServiceTemplateID == fsScheduleDetRow.ServiceTemplateID))
                    {
                        var fsServiceTemplateDetSet_Service = ServiceTemplateSelected.Select(fsScheduleDetRow.ServiceTemplateID);

                        foreach (FSServiceTemplateDet fsServiceTemplateDetRow_Service in fsServiceTemplateDetSet_Service)
                        {
                            FSSODet fsSODetRow = new FSSODet();

                            // Insert the new row with key fields
                            fsSODetRow.ScheduleID    = fsScheduleDetLocalRow.ScheduleID;
                            fsSODetRow.ScheduleDetID = fsScheduleDetLocalRow.ScheduleDetID;
                            fsSODetRow.LineType      = fsServiceTemplateDetRow_Service.LineType;

                            fsSODetRow = graphServiceOrderEntry.ServiceOrderDetails.Insert(fsSODetRow);

                            fsSODetRow.InventoryID = fsServiceTemplateDetRow_Service.InventoryID;

                            fsSODetRow = graphServiceOrderEntry.ServiceOrderDetails.Update(fsSODetRow);

                            PXNoteAttribute.CopyNoteAndFiles(ScheduleLinesSelected.Cache,
                                                             fsScheduleDetLocalRow,
                                                             graphServiceOrderEntry.ServiceOrderDetails.Cache,
                                                             fsSODetRow,
                                                             copyNotes: true,
                                                             copyFiles: true);

                            // Create a copy to update the other fields
                            fsSODetRow = (FSSODet)graphServiceOrderEntry.ServiceOrderDetails.Cache.CreateCopy(fsSODetRow);

                            fsSODetRow.TranDesc = fsServiceTemplateDetRow_Service.TranDesc;

                            InventoryItem inventoryItemRow = SharedFunctions.GetInventoryItemRow(this, fsServiceTemplateDetRow_Service.InventoryID);

                            if (inventoryItemRow != null)
                            {
                                FSxService fsxServiceRow = PXCache <InventoryItem> .GetExtension <FSxService>(inventoryItemRow);

                                if (fsxServiceRow != null && fsxServiceRow.BillingRule == ID.BillingRule.TIME)
                                {
                                    int?estimatedDuration = CalculateEstimatedDuration(fsSODetRow, fsServiceTemplateDetRow_Service.Qty);
                                    fsSODetRow.EstimatedDuration = estimatedDuration;
                                }
                                else
                                {
                                    fsSODetRow.EstimatedQty = fsServiceTemplateDetRow_Service.Qty;
                                }
                            }

                            if (fsServiceContractRow.SourcePrice == ID.SourcePrice.CONTRACT)
                            {
                                fsSODetRow.ManualPrice = true;
                                // TODO: Check where is assigned the contract price?
                            }

                            if (createAppointmentFlag)
                            {
                                fsSODetRow.Scheduled = true;
                                fsSODetRow.Status    = ID.Status_SODet.SCHEDULED;
                            }

                            fsSODetRow.EquipmentAction  = fsScheduleDetRow.EquipmentAction;
                            fsSODetRow.SMEquipmentID    = fsScheduleDetRow.SMEquipmentID;
                            fsSODetRow.ComponentID      = fsScheduleDetRow.ComponentID;
                            fsSODetRow.EquipmentLineRef = fsScheduleDetRow.EquipmentLineRef;
                            fsSODetRow.ProjectTaskID    = fsScheduleDetRow.ProjectTaskID;
                            fsSODetRow.CostCodeID       = fsScheduleDetRow.CostCodeID;

                            if (fsSODetRow.InventoryID != null)
                            {
                                fsSODetRow.ProjectTaskID = fsScheduleDetRow.ProjectTaskID;
                                fsSODetRow.CostCodeID    = fsScheduleDetRow.CostCodeID;
                            }

                            graphServiceOrderEntry.ServiceOrderDetails.Update(fsSODetRow);
                        }
                    }
                }
                else
                {
                    FSSODet fsSODetRow = new FSSODet();

                    // Insert the new row with key fields
                    fsSODetRow.ScheduleID    = fsScheduleDetRow.ScheduleID;
                    fsSODetRow.ScheduleDetID = fsScheduleDetRow.ScheduleDetID;
                    fsSODetRow.LineType      = fsScheduleDetRow.LineType;

                    fsSODetRow = graphServiceOrderEntry.ServiceOrderDetails.Insert(fsSODetRow);

                    fsSODetRow.InventoryID = fsScheduleDetRow.InventoryID;

                    fsSODetRow = graphServiceOrderEntry.ServiceOrderDetails.Update(fsSODetRow);

                    PXNoteAttribute.CopyNoteAndFiles(ScheduleLinesSelected.Cache,
                                                     fsScheduleDetRow,
                                                     graphServiceOrderEntry.ServiceOrderDetails.Cache,
                                                     fsSODetRow,
                                                     copyNotes: true,
                                                     copyFiles: true);

                    // Create a copy to update the other fields
                    fsSODetRow = (FSSODet)graphServiceOrderEntry.ServiceOrderDetails.Cache.CreateCopy(fsSODetRow);

                    fsSODetRow.TranDesc    = fsScheduleDetRow.TranDesc;
                    fsSODetRow.BillingRule = fsScheduleDetRow.BillingRule;

                    if (fsSODetRow.BillingRule == ID.BillingRule.TIME)
                    {
                        int?estimatedDuration = CalculateEstimatedDuration(fsSODetRow, fsScheduleDetRow?.Qty);
                        fsSODetRow.EstimatedDuration = estimatedDuration;
                    }
                    else
                    {
                        fsSODetRow.EstimatedQty = fsScheduleDetRow.Qty;
                    }

                    if (fsServiceContractRow.SourcePrice == ID.SourcePrice.CONTRACT)
                    {
                        fsSODetRow.ManualPrice = true;
                        // TODO: AC-142850 Check where is assigned the contract price?
                    }

                    if (createAppointmentFlag)
                    {
                        fsSODetRow.Scheduled = true;
                        fsSODetRow.Status    = ID.Status_SODet.SCHEDULED;
                    }

                    fsSODetRow.EquipmentAction  = fsScheduleDetRow.EquipmentAction;
                    fsSODetRow.SMEquipmentID    = fsScheduleDetRow.SMEquipmentID;
                    fsSODetRow.ComponentID      = fsScheduleDetRow.ComponentID;
                    fsSODetRow.EquipmentLineRef = fsScheduleDetRow.EquipmentLineRef;
                    fsSODetRow.ProjectTaskID    = fsScheduleDetRow.ProjectTaskID;
                    fsSODetRow.CostCodeID       = fsScheduleDetRow.CostCodeID;

                    if (fsSODetRow.InventoryID != null)
                    {
                        fsSODetRow.ProjectTaskID = fsScheduleDetRow.ProjectTaskID;
                        fsSODetRow.CostCodeID    = fsScheduleDetRow.CostCodeID;
                    }

                    graphServiceOrderEntry.ServiceOrderDetails.Update(fsSODetRow);
                }
            }

            if (fsScheduleRow.VendorID != null)
            {
                FSSOEmployee fsSOEmployeeRow = new FSSOEmployee();
                fsSOEmployeeRow.EmployeeID = fsScheduleRow.VendorID;
                graphServiceOrderEntry.ServiceOrderEmployees.Insert(fsSOEmployeeRow);
            }

            #endregion

            graphServiceOrderEntry.Save.Press();

            if (createAppointmentFlag)
            {
                string origStatus = graphServiceOrderEntry.ServiceOrderRecords.Current.Status;

                if (origStatus != ID.Status_ServiceOrder.OPEN)
                {
                    //Due to FSAppointment.sORefNbr selector, Service Order status must be OPEN to allow the SetValueExt<SORefNbr> inside createAppointment() work properly.
                    //PXUpdate is used to avoid raising any ServiceOrderEntry event.
                    PXUpdate <
                        Set <FSServiceOrder.status, FSServiceOrder.status.Open>,
                        FSServiceOrder,
                        Where <
                            FSServiceOrder.sOID, Equal <Required <FSServiceOrder.sOID> > > >
                    .Update(this, graphServiceOrderEntry.ServiceOrderRecords.Current.SOID);
                }

                CreateAppointment(graphServiceOrderEntry.ServiceOrderRecords.Current, timeSlotServiceOrder, fsScheduleRow, true, appointmentsBelongToRoute, isPrepaidContract);

                if (origStatus != ID.Status_ServiceOrder.OPEN)
                {
                    PXUpdate <
                        Set <FSServiceOrder.status, Required <FSServiceOrder.status> >,
                        FSServiceOrder,
                        Where <
                            FSServiceOrder.sOID, Equal <Required <FSServiceOrder.sOID> > > >
                    .Update(this, origStatus, graphServiceOrderEntry.ServiceOrderRecords.Current.SOID);
                }
            }
        }
Ejemplo n.º 28
0
        public CreateInvoiceByContractPost()
        {
            CreateInvoiceByContractPost graphCreateInvoiceByServiceOrderPost = null;

            Contracts.SetProcessDelegate(
                delegate(List <ContractPeriodToPost> contractPeriodToPostRows)
            {
                graphCreateInvoiceByServiceOrderPost = PXGraph.CreateInstance <CreateInvoiceByContractPost>();

                int rowIndex = 0;
                InvoiceContractPeriodFilter filter = Filter.Current;
                FSSetup fsSetupRow = ServiceManagementSetup.GetServiceManagementSetup(graphCreateInvoiceByServiceOrderPost);

                ContractPostBatchEntry contractPostBatchGraph   = PXGraph.CreateInstance <ContractPostBatchEntry>();
                ContractPostPeriodEntry contractPostPeriodGraph = PXGraph.CreateInstance <ContractPostPeriodEntry>();

                FSContractPostDoc fsContractPostDocRow     = null;
                FSContractPostBatch fsContractPostBatchRow = null;

                List <ContractInvoiceLine> invoiceDet              = new List <ContractInvoiceLine>();
                List <ContractInvoiceLine> contractPeriodLines     = null;
                List <ContractInvoiceLine> contractInvoiceDetList  = null;
                List <ContractInvoiceLine> equipmentInvoiceDetList = null;

                FSServiceContract fsServiceContractRow = null;
                FSContractPeriod fsContractPeriodRow   = null;

                IInvoiceContractGraph invoiceGraph = GetInvoiceGraph(fsSetupRow);

                foreach (ContractPeriodToPost contractPeriodToPostRow in contractPeriodToPostRows)
                {
                    fsContractPostDocRow = null;
                    GetContractAndPeriod(contractPeriodToPostRow.ServiceContractID, contractPeriodToPostRow.ContractPeriodID, out fsServiceContractRow, out fsContractPeriodRow);
                    contractPeriodLines = GetContractPeriodLines(contractPeriodToPostRow);

                    if (contractPeriodLines.Count > 0 && fsServiceContractRow != null && fsContractPeriodRow != null)
                    {
                        contractInvoiceDetList = GetContractInvoiceLines(contractPeriodToPostRow);
                        invoiceDet.AddRange(contractInvoiceDetList);

                        if (fsSetupRow.ContractPostTo == ID.Contract_PostTo.SALES_ORDER_MODULE)
                        {
                            equipmentInvoiceDetList = GetEquipmentInvoiceLines(contractPeriodToPostRow);
                        }

                        List <ContractInvoiceLine> contractInvoiceLines = GetInvoiceLines(invoiceDet, contractPeriodLines, contractInvoiceDetList, fsSetupRow.ContractPostTo);

                        if (equipmentInvoiceDetList != null && equipmentInvoiceDetList.Count > 0)
                        {
                            contractInvoiceLines.AddRange(equipmentInvoiceDetList);
                            invoiceDet.AddRange(equipmentInvoiceDetList);
                        }

                        try
                        {
                            using (var ts = new PXTransactionScope())
                            {
                                if (fsContractPostBatchRow == null)
                                {
                                    fsContractPostBatchRow = contractPostBatchGraph.CreatePostingBatch(filter.UpToDate, filter.InvoiceDate, filter.InvoiceFinPeriodID, SetupRecord.Current.ContractPostTo);
                                }

                                fsContractPostDocRow = invoiceGraph.CreateInvoiceByContract(graphCreateInvoiceByServiceOrderPost, filter.InvoiceDate, filter.InvoiceFinPeriodID, fsContractPostBatchRow, fsServiceContractRow, fsContractPeriodRow, contractInvoiceLines);

                                fsContractPostDocRow = CreateContractPostDoc(contractPostPeriodGraph, fsContractPostDocRow);

                                CreateContractPostDet(contractPostPeriodGraph, fsContractPostDocRow, invoiceDet);

                                UpdateSourcePostDoc(fsSetupRow, fsContractPostDocRow, fsServiceContractRow);

                                CreateContractPostRegister(this, fsContractPostDocRow);

                                contractPeriodToPostRow.ContractPostBatchID = fsContractPostBatchRow.ContractPostBatchID;

                                ts.Complete();
                            }

                            PXProcessing <ContractPeriodToPost> .SetInfo(rowIndex, TX.Messages.RECORD_PROCESSED_SUCCESSFULLY);
                        }
                        catch (Exception e)
                        {
                            PXProcessing <ContractPeriodToPost> .SetError(rowIndex, e.Message);
                        }
                    }
                    else
                    {
                        PXProcessing <ContractPeriodToPost> .SetError(rowIndex, TX.Error.PERIOD_WITHOUT_DETAILS);
                    }

                    rowIndex++;
                }
            });
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Gets the price for the item in the contract if it exists.
        /// </summary>
        private static decimal?GetCustomerContractPrice(PXCache cache,
                                                        int?serviceContractID,
                                                        int?billServiceContractID,
                                                        int?billContractPeriodID,
                                                        bool?lineRelatedToContract,
                                                        int?inventoryID)
        {
            if (serviceContractID == null && billServiceContractID == null)
            {
                return(null);
            }

            decimal?salesPrice = null;

            FSServiceContract fsServiceContractRow = PXSelect <FSServiceContract,
                                                               Where <
                                                                   FSServiceContract.serviceContractID, Equal <Required <FSServiceContract.serviceContractID> > > >
                                                     .Select(cache.Graph, serviceContractID);

            if (fsServiceContractRow == null)
            {
                fsServiceContractRow = PXSelect <FSServiceContract,
                                                 Where <
                                                     FSServiceContract.serviceContractID, Equal <Required <FSServiceContract.serviceContractID> > > >
                                       .Select(cache.Graph, billServiceContractID);
            }

            if (fsServiceContractRow != null &&
                fsServiceContractRow.BillingType == ID.Contract_BillingType.AS_PERFORMED_BILLINGS &&
                fsServiceContractRow.SourcePrice == ID.SourcePrice.CONTRACT)
            {
                FSSalesPrice fsSalesPriceRow = PXSelect <FSSalesPrice,
                                                         Where <
                                                             FSSalesPrice.serviceContractID, Equal <Required <FSSalesPrice.serviceContractID> >,
                                                             And <
                                                                 FSSalesPrice.inventoryID, Equal <Required <FSSalesPrice.inventoryID> > > > >
                                               .Select(cache.Graph, serviceContractID, inventoryID);

                if (fsSalesPriceRow != null)
                {
                    salesPrice = fsSalesPriceRow.UnitPrice;
                }
            }
            else if (fsServiceContractRow != null &&
                     fsServiceContractRow.BillingType == ID.Contract_BillingType.STANDARDIZED_BILLINGS &&
                     lineRelatedToContract == true)
            {
                FSContractPeriodDet fsContractPeriodDetRow = PXSelect <FSContractPeriodDet,
                                                                       Where <
                                                                           FSContractPeriodDet.serviceContractID, Equal <Required <FSContractPeriodDet.serviceContractID> >,
                                                                           And <
                                                                               FSContractPeriodDet.contractPeriodID, Equal <Required <FSContractPeriodDet.contractPeriodID> >,
                                                                               And <
                                                                                   FSContractPeriodDet.inventoryID, Equal <Required <FSContractPeriodDet.inventoryID> > > > > >
                                                             .Select(cache.Graph, billServiceContractID, billContractPeriodID, inventoryID);

                if (fsContractPeriodDetRow != null)
                {
                    salesPrice = fsContractPeriodDetRow.RecurringUnitPrice;
                }
            }

            return(salesPrice);
        }