protected virtual void EPWeekFilter_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            EPWeekFilter row = (EPWeekFilter)e.Row;

            if (row == null)
            {
                return;
            }

            DateTime?lastUsing = GetLasttUsingWeek();

            if (lastUsing != null && lastUsing.Value.Year > row.Year)
            {
                CustomWeek.Cache.AllowInsert = false;
                return;
            }

            EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .SelectSingleBound(this, null);

            if (lastWeek != null && lastWeek.EndDate != null && (lastWeek.EndDate.Value.AddDays(1)).Year != row.Year)
            {
                CustomWeek.Cache.AllowInsert = false;
            }
            else
            {
                CustomWeek.Cache.AllowInsert = true;
            }
        }
        private DateTime?GetLasttUsingWeek()
        {
            DateTime   dateFromActivity = new DateTime(1900, 1, 1);
            DateTime   startDate        = new DateTime(1900, 1, 1);
            EPTimeCard lastTimeCard     = (EPTimeCard)PXSelectOrderBy <EPTimeCard, OrderBy <Desc <EPTimeCard.weekId> > > .SelectSingleBound(this, null);

            CRPMTimeActivity lastActivity = PXSelect <CRPMTimeActivity,
                                                      Where <CRPMTimeActivity.weekID, IsNotNull,
                                                             And <CRPMTimeActivity.trackTime, Equal <True>,
                                                                  And <CRPMTimeActivity.classID, NotEqual <CRActivityClass.emailRouting>,
                                                                       And <CRPMTimeActivity.classID, NotEqual <CRActivityClass.task>,
                                                                            And <CRPMTimeActivity.classID, NotEqual <CRActivityClass.events> > > > > >,
                                                      OrderBy <
                                                          Desc <CRPMTimeActivity.weekID> > > .SelectSingleBound(this, null);

            if (lastTimeCard != null)
            {
                startDate = PXWeekSelectorAttribute.GetWeekStartDate(lastTimeCard.WeekID.Value);
            }
            if (lastActivity != null)
            {
                dateFromActivity = lastActivity.StartDate.Value;
            }

            startDate = startDate >= dateFromActivity ? startDate : dateFromActivity;

            if (startDate == new DateTime(1900, 1, 1))
            {
                return(null);
            }
            else
            {
                return(startDate);
            }
        }
Example #3
0
        private DateTime?GetFirstUsingWeek()
        {
            DateTime?startDate = GetFirstActivityDate();

            EPTimeCard firstTimeCard =
                (EPTimeCard)PXSelectOrderBy <EPTimeCard, OrderBy <Asc <EPTimeCard.weekId> > > .SelectSingleBound(this, null);

            if (firstTimeCard != null)
            {
                DateTime timecardStartDate = PXWeekSelectorAttribute.GetWeekStartDate(firstTimeCard.WeekID.Value);
                if (startDate == null)
                {
                    startDate = timecardStartDate;
                }
                else
                {
                    if (timecardStartDate < startDate.Value)
                    {
                        startDate = timecardStartDate;
                    }
                }
            }

            return(startDate);
        }
        protected virtual void EPSetup_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            var row = e.Row as EPSetup;

            if (row == null || e.Operation == PXDBOperation.Delete)
            {
                return;
            }
            if (row.PostToOffBalance == true && row.OffBalanceAccountGroupID == null)
            {
                if (cache.RaiseExceptionHandling <EPSetup.offBalanceAccountGroupID>(e.Row, row.OffBalanceAccountGroupID, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName <EPSetup.offBalanceAccountGroupID>(cache))))
                {
                    throw new PXRowPersistingException(typeof(EPSetup.offBalanceAccountGroupID).Name, row.OffBalanceAccountGroupID, ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName <EPSetup.offBalanceAccountGroupID>(cache));
                }
            }
            if (row.CustomWeek == true)
            {
                DateTime?firsUsing = GetFirstUsingWeek();
                DateTime?lastUsing = GetLasttUsingWeek();

                if (firsUsing != null && lastUsing != null)
                {
                    EPCustomWeek firstWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Asc <EPCustomWeek.weekID> > > .SelectSingleBound(this, null);

                    EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .SelectSingleBound(this, null);

                    if (firstWeek == null || firsUsing < firstWeek.StartDate || lastWeek == null || lastWeek.EndDate < lastUsing)
                    {
                        throw new PXRowPersistingException(typeof(EPSetup.customWeek).Name, row.CustomWeek, Messages.CustomWeekNotCreated, firsUsing, lastUsing);
                    }
                }
            }
        }
Example #5
0
        private DateTime?GetLasttUsingWeek()
        {
            DateTime   dateFromActivity = new DateTime(1900, 1, 1);
            DateTime   startDate        = new DateTime(1900, 1, 1);
            EPTimeCard lastTimeCard     =
                (EPTimeCard)PXSelectOrderBy <EPTimeCard, OrderBy <Desc <EPTimeCard.weekId> > > .SelectSingleBound(this, null);

            EPActivity lastActivity =
                (EPActivity)PXSelect <EPActivity, Where <EPActivity.startDate, IsNotNull>, OrderBy <Desc <EPActivity.weekID> > > .SelectSingleBound(this, null);

            if (lastTimeCard != null)
            {
                startDate = PXWeekSelectorAttribute.GetWeekSrartDate(lastTimeCard.WeekID.Value);
            }
            if (lastActivity != null)
            {
                dateFromActivity = lastActivity.StartDate.Value;
            }

            startDate = startDate >= dateFromActivity ? startDate : dateFromActivity;

            if (startDate == new DateTime(1900, 1, 1))
            {
                return(null);
            }
            else
            {
                return(startDate);
            }
        }
        protected virtual void EPSetup_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            EPSetup row = e.Row as EPSetup;

            if (row != null)
            {
                PXUIFieldAttribute.SetEnabled <EPSetup.offBalanceAccountGroupID>(cache, row, row.PostToOffBalance == true);
                if (row.CustomWeek == true)
                {
                    EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .SelectSingleBound(this, null);

                    PXUIFieldAttribute.SetEnabled <EPSetup.customWeek>(cache, row, lastWeek == null);
                }
            }
        }
        protected virtual void EPCustomWeek_StartDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            EPCustomWeek row = (EPCustomWeek)e.Row;

            if (row == null)
            {
                return;
            }
            // EPCustomWeek lastWeek = PXSelectOrderBy<EPCustomWeek, OrderBy<Desc<EPCustomWeek.weekID>>>.Select(this); //TODO: why dont worked?
            EPCustomWeek lastWeek = PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.year, Desc <EPCustomWeek.number> > > > .SelectSingleBound(this, new object[] { });

            if (lastWeek != null && lastWeek.EndDate != null)
            {
                e.NewValue = GetBeginOfDate(lastWeek.EndDate.Value.AddDays(1d));
            }
        }
        protected virtual void EPSetup_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            EPSetup row = e.Row as EPSetup;

            if (row != null)
            {
                PXUIFieldAttribute.SetEnabled <EPSetup.useReceiptAccountForTips>(cache, row, row.NonTaxableTipItem.HasValue);
                PXUIFieldAttribute.SetEnabled <EPSetup.offBalanceAccountGroupID>(cache, row, row.PostingOption == EPPostOptions.PostToOffBalance);
                if (row.CustomWeek == true)
                {
                    EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .SelectSingleBound(this, null);

                    PXUIFieldAttribute.SetEnabled <EPSetup.customWeek>(cache, row, lastWeek == null);
                }
            }
        }
Example #9
0
        public static FABook FindByBookMarker(PXGraph graph, int marker)
        {
            if (marker == FABook.bookID.Markers.GLBook)
            {
                return(PXSelect <FABook,
                                 Where <FABook.updateGL, Equal <True> > >
                       .Select(graph));
            }

            if (marker == FABook.bookID.Markers.GLOrAnyBook)
            {
                return(PXSelectOrderBy <FABook,
                                        OrderBy <Desc <FABook.updateGL> > >
                       .SelectSingleBound(graph, null));
            }

            throw new NotImplementedException();
        }
Example #10
0
        protected virtual void EPCustomWeek_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
        {
            EPCustomWeek row = (EPCustomWeek)e.Row;

            if (row != null)
            {
                if (row.StartDate != null && row.EndDate != null && row.StartDate.Value.Year != row.Year.Value && row.EndDate.Value.Year != row.Year.Value)
                {
                    throw new PXException(Messages.EndOfYear);
                }
            }
            EPCustomWeek lastWeek = PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.year, Desc <EPCustomWeek.number> > > > .SelectSingleBound(this, new object[] { });

            if (lastWeek != null && lastWeek.EndDate == null)
            {
                throw new PXException(Messages.IncrorrectPrevWeek);
            }
        }
        protected virtual void EPGenerateWeeksDialog_FromDate_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            EPGenerateWeeksDialog row = (EPGenerateWeeksDialog)e.Row;

            if (e.NewValue == null || row == null)
            {
                return;
            }
            if ((DateTime)e.NewValue > row.TillDate)
            {
                e.Cancel = true;
                throw new PXSetPropertyException(ErrorMessages.StartDateGreaterThanEndDate, PXUIFieldAttribute.GetDisplayName <EPGenerateWeeksDialog.fromDate>(cache), PXUIFieldAttribute.GetDisplayName <EPGenerateWeeksDialog.tillDate>(cache), row.FromDate);
            }
            DateTime?    firstUsingDate = GetFirstUsingWeek();
            EPCustomWeek lastWeek       = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .SelectSingleBound(this, null);

            if (firstUsingDate != null && (DateTime)e.NewValue > firstUsingDate && lastWeek == null)
            {
                e.Cancel = true;
                throw new PXSetPropertyException(Messages.ExistsActivitiesGreateThanDate, PXUIFieldAttribute.GetDisplayName <EPGenerateWeeksDialog.fromDate>(cache), firstUsingDate);
            }
        }
Example #12
0
        protected virtual void EPSetup_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            EPSetup row = e.Row as EPSetup;

            if (row != null)
            {
                PXUIFieldAttribute.SetEnabled <EPSetup.useReceiptAccountForTips>(cache, row, row.NonTaxableTipItem.HasValue);
                PXUIFieldAttribute.SetEnabled <EPSetup.offBalanceAccountGroupID>(cache, row, row.PostingOption == EPPostOptions.PostToOffBalance);
                if (row.CustomWeek == true)
                {
                    EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .SelectSingleBound(this, null);

                    PXUIFieldAttribute.SetEnabled <EPSetup.customWeek>(cache, row, lastWeek == null);
                }

                bool claimApprovalVisible = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() &&
                                            PXAccess.FeatureInstalled <FeaturesSet.expenseManagement>();

                PXUIFieldAttribute.SetVisible <EPSetup.claimDetailsAssignmentMapID>(cache, null, claimApprovalVisible);
                PXUIFieldAttribute.SetVisible <EPSetup.claimAssignmentMapID>(cache, null, claimApprovalVisible);
                PXUIFieldAttribute.SetVisible <EPSetup.claimDetailsAssignmentNotificationID>(cache, null, claimApprovalVisible);
            }
        }
        private void GetNextUsingWeek(out DateTime startDate, out int number, out int year)
        {
            EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .SelectSingleBound(this, null);

            if (lastWeek != null)
            {
                startDate = lastWeek.EndDate.Value.AddDays(1d);
                if (lastWeek.Number > 1 && lastWeek.StartDate.Value.Year < startDate.Year)
                {
                    number = 1;
                }
                else
                {
                    number = lastWeek.Number.Value + 1;
                }
                year = startDate.Year;
            }
            else
            {
                DateTime?First = GetFirstUsingWeek();
                if (First != null)
                {
                    startDate = (DateTime)First;
                }
                else if (WeekFilter.Current != null)
                {
                    startDate = new DateTime(WeekFilter.Current.Year.Value, 1, 1);
                }
                else
                {
                    startDate = new DateTime(Accessinfo.BusinessDate.Value.Year, 1, 1);
                }

                number = PXWeekSelectorAttribute.GetWeekID(startDate) % 100;
                year   = PXWeekSelectorAttribute.GetWeekID(startDate) / 100;
            }
        }