예제 #1
0
        public virtual decimal?CalculateEmployeeCost(CR.EPActivity activity, int?employeeID, DateTime date)
        {
            decimal?cost;
            Rate    employeeRate = GetEmployeeRate(activity.ProjectID, activity.ProjectTaskID, employeeID, date);

            if (employeeRate.Type == RateTypesAttribute.SalaryWithExemption && activity.TimeCardCD != null)
            {
                //Overtime is not applicable. Rate is prorated based on actual hours worked on the given week

                EPTimeCard timecard = PXSelect <EPTimeCard, Where <EPTimeCard.timeCardCD, Equal <Required <EPTimeCard.timeCardCD> > > > .Select(graph, activity.TimeCardCD);

                if (timecard.TotalSpentCalc <= employeeRate.RegularHours * 60)
                {
                    cost = employeeRate.RateByType / employeeRate.RegularHours;
                }
                else
                {
                    cost = employeeRate.RateByType / (timecard.TotalSpentCalc / 60);
                }
            }
            else
            {
                cost = employeeRate.HourlyRate * GetOvertimeMultiplier(activity.EarningTypeID, (int)employeeID, date);
            }

            return(cost);
        }
예제 #2
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);
        }
        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);
            }
        }
예제 #4
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);
            }
        }
        public virtual IEnumerable editDetail(PXAdapter adapter)
        {
            if (Records.Current != null && Records.Current.RefNoteID != null)
            {
                bool navigate = true;

                EntityHelper helper = new EntityHelper(this);
                Note         note   = helper.SelectNote(Records.Current.RefNoteID);

                if (note != null && note.EntityType == typeof(EPExpenseClaim).FullName)
                {
                    EPExpenseClaim claim = PXSelect <EPExpenseClaim, Where <EPExpenseClaim.noteID, Equal <Required <EPExpenseClaim.noteID> > > > .Select(this, note.NoteID);

                    if (claim != null)
                    {
                        ExpenseClaimEntry graph  = PXGraph.CreateInstance <ExpenseClaimEntry>();
                        EPExpenseClaim    target = graph.ExpenseClaim.Search <EPExpenseClaim.refNbr>(claim.RefNbr);
                        if (target == null)
                        {
                            navigate = false;
                        }
                    }
                    else
                    {
                        using (new PXReadBranchRestrictedScope())
                        {
                            claim = PXSelect <EPExpenseClaim, Where <EPExpenseClaim.noteID, Equal <Required <EPExpenseClaim.noteID> > > > .Select(this, note.NoteID);

                            if (claim != null)
                            {
                                throw new PXException(Messages.YouAreNotAlowedToViewTheDetails);
                            }
                        }
                    }
                }

                if (note != null && note.EntityType == typeof(EPTimeCard).FullName)
                {
                    EPTimeCard timecard = PXSelect <EPTimeCard, Where <EPTimeCard.noteID, Equal <Required <EPTimeCard.noteID> > > > .Select(this, note.NoteID);

                    if (timecard != null)
                    {
                        TimeCardMaint graph  = PXGraph.CreateInstance <TimeCardMaint>();
                        EPTimeCard    target = graph.Document.Search <EPTimeCard.timeCardCD>(timecard.TimeCardCD);
                        if (target == null)
                        {
                            navigate = false;
                        }
                    }
                }

                if (navigate)
                {
                    helper.NavigateToRow(Records.Current.RefNoteID.Value, PXRedirectHelper.WindowMode.InlineWindow);
                }
            }
            return(adapter.Get());
        }
예제 #6
0
        protected virtual void RecalculateTotals(EPTimeCard timecard)
        {
            if (timecard == null)
            {
                throw new ArgumentNullException();
            }

            int timeSpent        = 0;
            int regularTime      = 0;
            int overtimeSpent    = 0;
            int timeBillable     = 0;
            int overtimeBillable = 0;

            PXResultset <TimeCardMaint.EPTimecardDetail> resultset;

            if (timecard.IsHold == true)
            {
                resultset = PXSelectJoin <TimeCardMaint.EPTimecardDetail,
                                          InnerJoin <EPEarningType, On <TimeCardMaint.EPTimecardDetail.earningTypeID, Equal <EPEarningType.typeCD> >,
                                                     InnerJoin <EPEmployee, On <EPEmployee.userID, Equal <TimeCardMaint.EPTimecardDetail.owner> > > >,
                                          Where <TimeCardMaint.EPTimecardDetail.weekID, Equal <Required <EPActivity.weekID> >,
                                                 And <TimeCardMaint.EPTimecardDetail.timeCardCD, IsNull,
                                                      And <EPEmployee.bAccountID, Equal <Required <EPEmployee.bAccountID> > > > > > .Select(this, timecard.WeekID, timecard.EmployeeID);
            }
            else
            {
                resultset = PXSelectJoin <TimeCardMaint.EPTimecardDetail,
                                          InnerJoin <EPEarningType, On <TimeCardMaint.EPTimecardDetail.earningTypeID, Equal <EPEarningType.typeCD> >,
                                                     InnerJoin <EPEmployee, On <EPEmployee.userID, Equal <TimeCardMaint.EPTimecardDetail.owner> > > >,
                                          Where <TimeCardMaint.EPTimecardDetail.timeCardCD, Equal <Required <TimeCardMaint.EPTimecardDetail.timeCardCD> >,
                                                 And <EPEmployee.bAccountID, Equal <Required <EPEmployee.bAccountID> > > > > .Select(this, timecard.TimeCardCD, timecard.EmployeeID);
            }

            foreach (PXResult <TimeCardMaint.EPTimecardDetail, EPEarningType> res in resultset)
            {
                TimeCardMaint.EPTimecardDetail activity = (TimeCardMaint.EPTimecardDetail)res;
                EPEarningType et = (EPEarningType)res;
                activity.IsOvertimeCalc = et.IsOvertime;
                RecalculateFields(activity);

                timeSpent        += activity.TimeSpent.GetValueOrDefault();
                regularTime      += activity.RegularTimeCalc.GetValueOrDefault();
                timeBillable     += activity.BillableTimeCalc.GetValueOrDefault();
                overtimeSpent    += activity.OverTimeCalc.GetValueOrDefault();
                overtimeBillable += activity.BillableOvertimeCalc.GetValueOrDefault();
            }

            timecard.TimeSpentCalc     = regularTime;
            timecard.OvertimeSpentCalc = overtimeSpent;
            timecard.TotalSpentCalc    = timeSpent;

            timecard.TimeBillableCalc     = timeBillable;
            timecard.OvertimeBillableCalc = overtimeBillable;
            timecard.TotalBillableCalc    = timeBillable + overtimeBillable;
        }
        protected virtual void Update()
        {
            EPTimeCard row = PXSelect <EPTimeCard, Where <EPTimeCard.timeCardCD, Equal <Current <TimecardWithTotals.timeCardCD> > > > .Select(this);

            if (row == null)
            {
                return;
            }

            PXRedirectHelper.TryRedirect(this, row, PXRedirectHelper.WindowMode.InlineWindow);
        }
예제 #8
0
        protected virtual void EPTimeCard_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            EPTimeCard row = e.Row as EPTimeCard;

            if (row == null)
            {
                return;
            }

            RecalculateTotals(row);
        }
        protected void Delete()
        {
            EPTimeCard row = PXSelect <EPTimeCard, Where <EPTimeCard.timeCardCD, Equal <Current <TimecardWithTotals.timeCardCD> > > > .Select(this);

            if (row == null)
            {
                return;
            }

            using (new PXPreserveScope())
            {
                TimeCardMaint graph = (TimeCardMaint)CreateInstance(typeof(TimeCardMaint));
                graph.Clear(PXClearOption.ClearAll);
                graph.Document.Current = row;
                graph.Delete.Press();
            }
        }
예제 #10
0
        public virtual LaborCost CalculateEmployeeCost(string timeCardCD, string earningTypeID, int?laborItemID, int?projectID, int?projectTaskID, bool?certifiedJob, string unionID, int?employeeID, DateTime date)
        {
            decimal?cost;
            decimal overtimeMult = 1;
            Rate    employeeRate = GetEmployeeRate(laborItemID, projectID, projectTaskID, certifiedJob, unionID, employeeID, date);

            if (employeeRate == null)
            {
                return(null);
            }

            if (employeeRate.Type == RateTypesAttribute.SalaryWithExemption && timeCardCD != null)
            {
                //Overtime is not applicable. Rate is prorated based on actual hours worked on the given week

                EPTimeCard timecard = PXSelect <EPTimeCard,
                                                Where <EPTimeCard.timeCardCD, Equal <Required <PMTimeActivity.timeCardCD> > > > .Select(graph, timeCardCD);

                if (timecard.TotalSpentCalc == null)
                {
                    var            select = new PXSelectGroupBy <PMTimeActivity, Where <PMTimeActivity.timeCardCD, Equal <Required <PMTimeActivity.timeCardCD> > >, Aggregate <Sum <PMTimeActivity.timeSpent> > >(graph);
                    PMTimeActivity total  = select.Select(timeCardCD);

                    timecard.TotalSpentCalc = total.TimeSpent;
                }

                if (timecard.TotalSpentCalc <= employeeRate.RegularHours * 60m)
                {
                    cost = employeeRate.RateByType / employeeRate.RegularHours;
                }
                else
                {
                    cost = employeeRate.RateByType / (timecard.TotalSpentCalc / 60m);
                }
            }
            else
            {
                overtimeMult = GetOvertimeMultiplier(earningTypeID, employeeRate);
                cost         = employeeRate.HourlyRate * overtimeMult;
            }

            return(new LaborCost(cost, overtimeMult));
        }
        protected virtual string CalculateTimecardType(PXCache sender, EPTimeCard row)
        {
            string val = Normal;

            if (row != null)
            {
                if (!string.IsNullOrEmpty(row.OrigTimeCardCD))
                {
                    val = Correction;
                }

                if (row.IsReleased == true)
                {
                    EPTimeCard correction = PXSelect <EPTimeCard, Where <EPTimeCard.origTimeCardCD, Equal <Required <EPTimeCard.origTimeCardCD> > > > .Select(sender.Graph, row.TimeCardCD);

                    if (correction != null)
                    {
                        val = NormalCorrected;
                    }
                }
            }

            return(val);
        }