コード例 #1
0
ファイル: ClockEvents.cs プロジェクト: steev90/opendental
        /// <summary>Used to sum a partial weeks worth of regular hours from clock events and time spans.</summary>
        private static TimeSpan prevWeekRegHoursHelper(long employeeNum, DateTime startDate, DateTime endDate)
        {
            string            errors = "";
            List <ClockEvent> listCE = new List <ClockEvent>();
            List <TimeAdjust> listTA = new List <TimeAdjust>();

            try { listCE = ClockEvents.GetListForTimeCardManage(employeeNum, startDate, endDate); }catch (Exception ex) { errors += ex.Message; }
            try { listTA = TimeAdjusts.GetListForTimeCardManage(employeeNum, startDate, endDate); }catch (Exception ex) { errors += ex.Message; }
            TimeSpan retVal = TimeSpan.Zero;

            for (int i = 0; i < listCE.Count; i++)
            {
                retVal += listCE[i].TimeDisplayed2 - listCE[i].TimeDisplayed1;
                if (listCE[i].AdjustIsOverridden)                 //Manual override
                {
                    retVal += listCE[i].Adjust;
                }
                else
                {
                    retVal += listCE[i].AdjustAuto;
                }
            }
            for (int i = 0; i < listTA.Count; i++)
            {
                retVal += listTA[i].RegHours;
            }
            return(retVal);
        }
コード例 #2
0
ファイル: ClockEvents.cs プロジェクト: steev90/opendental
        /// <summary>Used to sum a partial weeks worth of OT hours from clock events and time spans.</summary>
        private static TimeSpan prevWeekOTHoursHelper(long employeeNum, DateTime startDate, DateTime endDate)
        {
            List <ClockEvent> listCE = ClockEvents.GetListForTimeCardManage(employeeNum, startDate, endDate);
            List <TimeAdjust> listTA = TimeAdjusts.GetListForTimeCardManage(employeeNum, startDate, endDate);
            TimeSpan          retVal = TimeSpan.Zero;

            for (int i = 0; i < listCE.Count; i++)
            {
                if (listCE[i].OTimeHours != TimeSpan.FromHours(-1))               //Manual override
                {
                    retVal += listCE[i].OTimeHours;
                }
                else
                {
                    retVal += listCE[i].OTimeAuto;
                }
            }
            for (int i = 0; i < listTA.Count; i++)
            {
                retVal += listTA[i].OTimeHours;
            }
            return(retVal);
        }
コード例 #3
0
ファイル: ClockEvents.cs プロジェクト: steev90/opendental
        ///<summary>Returns clockevent information for all non-hidden employees.  Used only in the time card manage window.</summary>
        /// <param name="IsPrintReport">Only applicable to ODHQ. If true, will add ADP pay numer and note. The query takes about 9 seconds if this is set top true vs. about 2 seconds if set to false.</param>
        public static DataTable GetTimeCardManage(DateTime startDate, DateTime stopDate)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <DataTable>(MethodBase.GetCurrentMethod(), startDate, stopDate));
            }
            //Construct empty table------------------------------------------------------------------------------------------------------------------------
            DataTable retVal = new DataTable();

            retVal.Columns.Add("PayrollID");
            retVal.Columns.Add("EmployeeNum");
            retVal.Columns.Add("firstName");
            retVal.Columns.Add("lastName");
            retVal.Columns.Add("totalHours");            //should be sum of RegularHours and OvertimeHours
            retVal.Columns.Add("rate1Hours");
            retVal.Columns.Add("rate1OTHours");
            retVal.Columns.Add("rate2Hours");
            retVal.Columns.Add("rate2OTHours");
            //retVal.Columns.Add("ClockEventAdjustTotal");
            //retVal.Columns.Add("TimeAdjust");//adjustments to regular time from timeAdjust entries. Not a net zero effect on total hours worked.
            //retVal.Columns.Add("TimeAdjustOT");//OT adjustments from timeAdjust entries. OT time adjust has net zero effect. Non-OT time adjust alters total hours worked.
            //retVal.Columns.Add("PaidBreakTime");//paid breaks. Is adjusted by pressing calcDaily.
            retVal.Columns.Add("Note");
            //Loop through employees.  Each employee adds one row to table --------------------------------------------------------------------------------
            List <ClockEvent> listClockEventsAllPlusPevWeek       = new List <ClockEvent>();
            List <ClockEvent> listClockEventsBreakAllPlusPrevWeek = new List <ClockEvent>();
            List <TimeAdjust> listTimeAdjustAllPlusPrevWeek       = new List <TimeAdjust>();
            List <Employee>   listEmployees = Employees.GetForTimeCard();

            for (int e = 0; e < listEmployees.Count; e++)
            {
                string  employeeErrors = "";
                string  note           = "";
                DataRow dataRowCur     = retVal.NewRow();
                dataRowCur.ItemArray.Initialize();                //changes all nulls to blanks and zeros.
                //PayrollID-------------------------------------------------------------------------------------------------------------------------------------
                dataRowCur["PayrollID"] = listEmployees[e].PayrollID;
                //EmployeeNum and Name----------------------------------------------------------------------------------------------------------------------------------
                dataRowCur["EmployeeNum"] = listEmployees[e].EmployeeNum;
                dataRowCur["firstName"]   = listEmployees[e].FName;
                dataRowCur["lastName"]    = listEmployees[e].LName;
                //Begin calculations------------------------------------------------------------------------------------------------------------------------------------
                //each list below will contain one entry per week.
                List <TimeSpan> listTsRegularHoursWeekly      = new List <TimeSpan>();            //Total non-overtime hours.  Used for calculation, not displayed or part of dataTable.
                List <TimeSpan> listTsOTHoursWeekly           = new List <TimeSpan>();            //Total overtime hours.  Used for calculation, not displayed or part of dataTable.
                List <TimeSpan> listTsDifferentialHoursWeekly = new List <TimeSpan>();            //Not included in total hours worked.  tsDifferentialHours is differant than r2Hours and r2OTHours
                //TimeSpan tsClockEventNetAdjust    =new TimeSpan();
                //TimeSpan tsTimeAdjust             =new TimeSpan();
                //TimeSpan tsTimeAdjustOT           =new TimeSpan();
                //TimeSpan tsPaidBreakTime          =new TimeSpan();
                List <ClockEvent> listClockEvents = new List <ClockEvent>();
                List <TimeAdjust> listTimeAdjusts = new List <TimeAdjust>();
                try { listClockEvents = ClockEvents.GetListForTimeCardManage(listEmployees[e].EmployeeNum, startDate, stopDate); }catch (Exception ex) { employeeErrors += ex.Message; }
                try { listTimeAdjusts = TimeAdjusts.GetListForTimeCardManage(listEmployees[e].EmployeeNum, startDate, stopDate); }catch (Exception ex) { employeeErrors += ex.Message; }
                //report errors in note column and move to next employee.----------------------------------------------------------------
                if (employeeErrors != "")
                {
                    dataRowCur["Note"] = employeeErrors.Trim();
                    retVal.Rows.Add(dataRowCur);
                    continue;                    //display employee errors in note field for employee. All columns will be blank for just this employee.
                }
                //sum values for each week----------------------------------------------------------------------------------------------------
                List <DateTime> weekStartDates = weekStartHelper(startDate, stopDate);
                for (int i = 0; i < weekStartDates.Count; i++)
                {
                    listTsRegularHoursWeekly.Add(TimeSpan.Zero);
                    listTsOTHoursWeekly.Add(TimeSpan.Zero);
                    listTsDifferentialHoursWeekly.Add(TimeSpan.Zero);
                }
                int weekCur = 0;
                for (int i = 0; i < listClockEvents.Count; i++)
                {
                    //set current week for clock event
                    for (int j = 0; j < weekStartDates.Count; j++)
                    {
                        if (listClockEvents[i].TimeDisplayed1 < weekStartDates[j].AddDays(7))
                        {
                            weekCur = j;                          //clock event occurs during the week "j"
                            break;
                        }
                    }
                    if (i == 0)                   //we only want the comment from the first clock event entry.
                    {
                        note = listClockEvents[i].Note;
                    }
                    //TimeDisplayed-----
                    listTsRegularHoursWeekly[weekCur] += listClockEvents[i].TimeDisplayed2 - listClockEvents[i].TimeDisplayed1;
                    //Adjusts-----
                    if (listClockEvents[i].AdjustIsOverridden)
                    {
                        listTsRegularHoursWeekly[weekCur] += listClockEvents[i].Adjust;
                    }
                    else
                    {
                        listTsRegularHoursWeekly[weekCur] += listClockEvents[i].AdjustAuto;
                    }
                    //OverTime-----
                    if (listClockEvents[i].OTimeHours != TimeSpan.FromHours(-1))                   //Manual override
                    {
                        listTsOTHoursWeekly[weekCur]      += listClockEvents[i].OTimeHours;
                        listTsRegularHoursWeekly[weekCur] += -listClockEvents[i].OTimeHours;
                    }
                    else
                    {
                        listTsOTHoursWeekly[weekCur]      += listClockEvents[i].OTimeAuto;
                        listTsRegularHoursWeekly[weekCur] += -listClockEvents[i].OTimeAuto;
                    }
                    //Differential/Rate2
                    if (listClockEvents[i].Rate2Hours != TimeSpan.FromHours(-1))                   //Manual override
                    {
                        listTsDifferentialHoursWeekly[weekCur] += listClockEvents[i].Rate2Hours;
                    }
                    else
                    {
                        listTsDifferentialHoursWeekly[weekCur] += listClockEvents[i].Rate2Auto;
                    }
                }
                //reset current week to itterate through time adjusts
                weekCur = 0;
                for (int i = 0; i < listTimeAdjusts.Count; i++)           //list of timeAdjusts have already been filtered. All timeAdjusts in this list are applicable.
                //set current week for time adjusts-----
                {
                    for (int j = 0; j < weekStartDates.Count; j++)
                    {
                        if (listTimeAdjusts[i].TimeEntry < weekStartDates[j].AddDays(7))
                        {
                            weekCur = j;                          //clock event occurs during the week "j"
                            break;
                        }
                    }
                    listTsRegularHoursWeekly[weekCur] += listTimeAdjusts[i].RegHours;
                    listTsOTHoursWeekly[weekCur]      += listTimeAdjusts[i].OTimeHours;
                }
                //Overtime should have already been calculated by CalcWeekly(); No calculations needed, just sum values.------------------------------------------------------
                double totalHoursWorked        = 0;
                double totalRegularHoursWorked = 0;
                double totalOTHoursWorked      = 0;
                double totalDiffHoursWorked    = 0;
                //sum weekly totals.
                for (int i = 0; i < weekStartDates.Count; i++)
                {
                    totalHoursWorked        += listTsRegularHoursWeekly[i].TotalHours;
                    totalHoursWorked        += listTsOTHoursWeekly[i].TotalHours;
                    totalRegularHoursWorked += listTsRegularHoursWeekly[i].TotalHours;
                    totalOTHoursWorked      += listTsOTHoursWeekly[i].TotalHours;
                    totalDiffHoursWorked    += listTsDifferentialHoursWeekly[i].TotalHours;
                }
                //Regular time at R1 and R2
                double rate1ratio = 0;
                if (totalHoursWorked != 0)
                {
                    rate1ratio = 1 - totalDiffHoursWorked / totalHoursWorked;
                }
                dataRowCur["totalHours"] = TimeSpan.FromHours(totalHoursWorked).ToString();
                double r1Hours   = rate1ratio * totalRegularHoursWorked;
                double r2Hours   = totalRegularHoursWorked - r1Hours;
                double r1OTHours = rate1ratio * totalOTHoursWorked;
                double r2OTHours = totalHoursWorked - r1Hours - r2Hours - r1OTHours;        //"self correcting math" uses guaranteed to total correctly.
                dataRowCur["rate1Hours"]   = TimeSpan.FromHours(r1Hours).ToString();
                dataRowCur["rate2Hours"]   = TimeSpan.FromHours(r2Hours).ToString();
                dataRowCur["rate1OTHours"] = TimeSpan.FromHours(r1OTHours).ToString();
                dataRowCur["rate2OTHours"] = TimeSpan.FromHours(r2OTHours).ToString();
                dataRowCur["Note"]         = note;
                retVal.Rows.Add(dataRowCur);
                continue;
            }
            return(retVal);
        }