public static void ViewScheduleForDocument(PXGraph graph, ARInvoice document)
        {
            PXSelectBase <DRSchedule> correspondingScheduleView = new PXSelect <
                DRSchedule,
                Where <
                    DRSchedule.module, Equal <BatchModule.moduleAR>,
                    And <DRSchedule.docType, Equal <Required <ARTran.tranType> >,
                         And <DRSchedule.refNbr, Equal <Required <ARTran.refNbr> > > > > >
                                                                      (graph);

            DRSchedule correspondingSchedule = correspondingScheduleView.Select(document.DocType, document.RefNbr);

            if (correspondingSchedule?.LineNbr != null && document.Released == false)
            {
                throw new PXException(Messages.CantCompleteBecauseASC606FeatureIsEnabled);
            }

            if (correspondingSchedule?.IsOverridden != true && document.Released == false)
            {
                var netLinesAmount = ASC606Helper.CalculateNetAmount(graph, document);
                int?defScheduleID  = null;

                if (netLinesAmount.Cury != 0m)
                {
                    DRSingleProcess process = PXGraph.CreateInstance <DRSingleProcess>();

                    process.CreateSingleSchedule(document, netLinesAmount, defScheduleID, true);
                    process.Actions.PressSave();

                    correspondingScheduleView.Cache.Clear();
                    correspondingScheduleView.Cache.ClearQueryCacheObsolete();
                    correspondingScheduleView.View.Clear();

                    correspondingSchedule = correspondingScheduleView.Select(document.DocType, document.RefNbr);
                }
            }

            if (correspondingSchedule != null)
            {
                PXRedirectHelper.TryRedirect(
                    graph.Caches[typeof(DRSchedule)],
                    correspondingSchedule,
                    "View Schedule",
                    PXRedirectHelper.WindowMode.NewWindow);
            }
        }
예제 #2
0
        private static void RecalculateScheduleProc(DraftScheduleMaint graph)
        {
            var schedule = graph.Schedule.Current;

            bool isUnable = graph.Schedule.Cache.GetStatus(graph.Schedule.Current) != PXEntryStatus.Notchanged &&
                            graph.Schedule.Cache.GetStatus(graph.Schedule.Current) != PXEntryStatus.Updated;

            if (isUnable || schedule.IsRecalculated == true || graph.Components.Any() == false)
            {
                return;
            }

            ARInvoice document = PXSelect <ARInvoice,
                                           Where <ARInvoice.docType, Equal <Required <ARRegister.docType> >,
                                                  And <ARInvoice.refNbr, Equal <Required <ARRegister.refNbr> > > > > .Select(graph, schedule.DocType, schedule.RefNbr);

            PXSelectBase <DRSchedule> correspondingScheduleView = new PXSelect <
                DRSchedule,
                Where <
                    DRSchedule.module, Equal <BatchModule.moduleAR>,
                    And <DRSchedule.docType, Equal <Required <ARTran.tranType> >,
                         And <DRSchedule.refNbr, Equal <Required <ARTran.refNbr> > > > > >
                                                                      (graph);

            DRSchedule correspondingSchedule = correspondingScheduleView.Select(document.DocType, document.RefNbr);

            var newDetails = new List <DRScheduleDetail>();


            var        netLinesAmount = ASC606Helper.CalculateNetAmount(graph, document);
            int?       defScheduleID  = null;
            DRSchedule scheduleResult = null;

            if (netLinesAmount.Cury != 0m)
            {
                DRSingleProcess process = PXGraph.CreateInstance <DRSingleProcess>();
                process.CreateSingleSchedule(document, netLinesAmount, defScheduleID, true);

                scheduleResult = process.Schedule.Current;

                foreach (DRScheduleDetail detail in process.ScheduleDetail.Cache.Inserted)
                {
                    newDetails.Add(detail);
                }
            }

            foreach (DRScheduleDetail detail in graph.Components.Select())
            {
                graph.Components.Delete(detail);
            }

            schedule.DocDate        = scheduleResult.DocDate;
            schedule.BAccountID     = scheduleResult.BAccountID;
            schedule.BAccountLocID  = scheduleResult.BAccountLocID;
            schedule.FinPeriodID    = scheduleResult.FinPeriodID;
            schedule.TranDesc       = scheduleResult.TranDesc;
            schedule.IsCustom       = false;
            schedule.BAccountType   = schedule.Module == BatchModule.AP ? BAccountType.VendorType : BAccountType.CustomerType;
            schedule.TermStartDate  = scheduleResult.TermStartDate;
            schedule.TermEndDate    = scheduleResult.TermEndDate;
            schedule.ProjectID      = scheduleResult.ProjectID;
            schedule.TaskID         = scheduleResult.TaskID;
            schedule.IsRecalculated = true;

            schedule = graph.Schedule.Update(schedule);

            foreach (DRScheduleDetail detail in newDetails)
            {
                graph.Components.Insert(detail);
            }
        }