示例#1
0
 public static void RecalculateSchedule(DraftScheduleMaint graph)
 {
     try
     {
         graph.CurrentContext = DraftScheduleMaint.Context.Recalculate;
         RecalculateScheduleProc(graph);
     }
     finally
     {
         graph.CurrentContext = DraftScheduleMaint.Context.Normal;
     }
 }
        public virtual IEnumerable ViewSchedule(PXAdapter adapter)
        {
            if (Items.Current != null)
            {
                DraftScheduleMaint target = PXGraph.CreateInstance <DraftScheduleMaint>();
                target.Schedule.Current = PXSelect <DRSchedule, Where <DRSchedule.scheduleID, Equal <Required <DRSchedule.scheduleID> > > > .Select(this, Items.Current.ScheduleID);

                throw new PXRedirectRequiredException(target, true, "ViewSchedule")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            return(adapter.Get());
        }
        protected virtual void Create()
        {
            using (new PXPreserveScope())
            {
                DraftScheduleMaint scheduleMaintenanceGraph = PXGraph.CreateInstance <DraftScheduleMaint>();

                scheduleMaintenanceGraph.Clear(PXClearOption.ClearAll);

                scheduleMaintenanceGraph.Schedule.Insert();
                scheduleMaintenanceGraph.Schedule.Cache.IsDirty = false;

                PXRedirectHelper.TryRedirect(scheduleMaintenanceGraph, PXRedirectHelper.WindowMode.InlineWindow);
            }
        }
示例#4
0
        private static void DeleteAssociatedScheduleIfDeferralCodeChanged(
            PXGraph graph,
            IDocumentLine documentLine,
            IDocumentLine oldLine)
        {
            bool deferralCodeRemoved = documentLine.DeferredCode == null;

            bool deferralCodeChanged =
                oldLine?.DeferredCode != null &&
                documentLine.DeferredCode != null &&
                oldLine.DeferredCode != documentLine.DeferredCode;

            if (deferralCodeRemoved || deferralCodeChanged)
            {
                DRSchedule correspondingSchedule = PXSelect <
                    DRSchedule,
                    Where <DRSchedule.module, Equal <Required <DRSchedule.module> >,
                           And <DRSchedule.docType, Equal <Required <DRSchedule.docType> >,
                                And <DRSchedule.refNbr, Equal <Required <DRSchedule.refNbr> >,
                                     And <DRSchedule.lineNbr, Equal <Required <DRSchedule.lineNbr> > > > > > >
                                                   .Select(
                    graph,
                    documentLine.Module,
                    documentLine.TranType,
                    documentLine.RefNbr,
                    documentLine.LineNbr);

                if (correspondingSchedule == null)
                {
                    return;
                }

                DraftScheduleMaint scheduleGraph = PXGraph.CreateInstance <DraftScheduleMaint>();
                scheduleGraph.Schedule.Delete(correspondingSchedule);
                scheduleGraph.Save.Press();
            }
        }
示例#5
0
        /// <summary>
        /// Checks if deferral code has been changed or removed from the line.
        /// If so, ensures the removal of any associated deferral schedules.
        /// </summary>
        public static void DeleteAssociatedScheduleIfDeferralCodeChanged(
            PXGraph graph,
            IDocumentLine documentLine)
        {
            IDocumentLine oldLine;

            // Obtain the document line last saved into the database
            // to check if the new line's deferral code differs from it.
            // -
            if (documentLine.Module == GL.BatchModule.AR)
            {
                oldLine = (ARTran)PXSelectReadonly <
                    ARTran,
                    Where <
                        ARTran.tranType, Equal <Required <ARTran.tranType> >,
                        And <ARTran.refNbr, Equal <Required <ARTran.refNbr> >,
                             And <ARTran.lineNbr, Equal <Required <ARTran.lineNbr> > > > > >
                          .Select(graph, documentLine.TranType, documentLine.RefNbr, documentLine.LineNbr);
            }
            else if (documentLine.Module == GL.BatchModule.AP)
            {
                oldLine = (APTran)PXSelectReadonly <
                    APTran,
                    Where <
                        APTran.tranType, Equal <Required <APTran.tranType> >,
                        And <APTran.refNbr, Equal <Required <APTran.refNbr> >,
                             And <APTran.lineNbr, Equal <Required <APTran.lineNbr> > > > > >
                          .Select(graph, documentLine.TranType, documentLine.RefNbr, documentLine.LineNbr);
            }
            else
            {
                throw new PXException(Messages.UnexpectedDocumentLineModule);
            }

            DRSchedule correspondingSchedule = PXSelect <
                DRSchedule,
                Where <
                    DRSchedule.module, Equal <Required <DRSchedule.module> >,
                    And <DRSchedule.docType, Equal <Required <DRSchedule.docType> >,
                         And <DRSchedule.refNbr, Equal <Required <DRSchedule.refNbr> >,
                              And <DRSchedule.lineNbr, Equal <Required <DRSchedule.lineNbr> > > > > > >
                                               .Select(
                graph,
                documentLine.Module,
                documentLine.TranType,
                documentLine.RefNbr,
                documentLine.LineNbr);

            if (correspondingSchedule == null)
            {
                return;
            }

            bool deferralCodeRemoved = documentLine.DeferredCode == null;

            bool deferralCodeChanged =
                oldLine?.DeferredCode != null &&
                documentLine.DeferredCode != null &&
                oldLine.DeferredCode != documentLine.DeferredCode;

            if (deferralCodeRemoved || deferralCodeChanged)
            {
                DraftScheduleMaint scheduleGraph = PXGraph.CreateInstance <DraftScheduleMaint>();

                scheduleGraph.Schedule.Current = correspondingSchedule;

                scheduleGraph
                .Components
                .Select()
                .ForEach(component => scheduleGraph.Components.Delete(component));

                scheduleGraph.Schedule.Delete(correspondingSchedule);

                scheduleGraph.Save.Press();
            }
        }
示例#6
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);
            }
        }