Ejemplo n.º 1
0
 function postSave()
 {
     if ($this->getEnableTimeSheetVerificationCheck()) {
         //Check to see if schedule is verified, if so unverify it on modified punch.
         //Make sure exceptions are calculated *after* this so TimeSheet Not Verified exceptions can be triggered again.
         if (is_object($this->getUserDateObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject()) and $this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject()->getTimeSheetVerifyType() != 10) {
             //Find out if timesheet is verified or not.
             $pptsvlf = TTnew('PayPeriodTimeSheetVerifyListFactory');
             $pptsvlf->getByPayPeriodIdAndUserId($this->getUserDateObject()->getPayPeriod(), $this->getUserDateObject()->getUser());
             if ($pptsvlf->getRecordCount() > 0) {
                 //Pay period is verified, delete all records and make log entry.
                 //These can be added during the maintenance jobs, so the audit records are recorded as user_id=0, check those first.
                 Debug::text('Pay Period is verified, deleting verification records: ' . $pptsvlf->getRecordCount() . ' User ID: ' . $this->getUserDateObject()->getUser() . ' Pay Period ID: ' . $this->getUserDateObject()->getPayPeriod(), __FILE__, __LINE__, __METHOD__, 10);
                 foreach ($pptsvlf as $pptsv_obj) {
                     TTLog::addEntry($pptsv_obj->getId(), 500, TTi18n::getText('Schedule Modified After Verification') . ': ' . UserListFactory::getFullNameById($this->getUserDateObject()->getUser()) . ' ' . TTi18n::getText('Schedule') . ': ' . TTDate::getDate('DATE', $this->getStartTime()), NULL, $pptsvlf->getTable());
                     $pptsv_obj->setDeleted(TRUE);
                     if ($pptsv_obj->isValid()) {
                         $pptsv_obj->Save();
                     }
                 }
             }
         }
     }
     if ($this->getEnableReCalculateDay() == TRUE) {
         //Calculate total time. Mainly for docked.
         //Calculate entire week as Over Schedule (Weekly) OT policy needs to be reapplied if the schedule changes.
         if (is_object($this->getUserDateObject()) and $this->getUserDateObject()->getUser() > 0) {
             //When shifts are assigned to different days, we need to calculate both days the schedule touches, as the shift could be assigned to either of them.
             UserDateTotalFactory::smartReCalculate($this->getUserDateObject()->getUser(), array($this->getUserDateID(), $this->getOldUserDateID(), UserDateFactory::findOrInsertUserDate($this->getUserDateObject()->getUser(), $this->getStartTime()), UserDateFactory::findOrInsertUserDate($this->getUserDateObject()->getUser(), $this->getEndTime())), TRUE, FALSE);
         }
     }
     return TRUE;
 }
Ejemplo n.º 2
0
                    //Because if its a Monday, it will also recalculate the rest of the days in the week.
                    //Shouldn't be a big deal though.
                    //This isn't needed, since we now do it in AddRecurringScheduleShift, so dock time is
                    //applied at the beginning of the day.
                    //The problem is that AddRecurringScheduleShift does it, then for the entire day someone with
                    //a dock policy shows up as dock time. Some users have complained about this a few times.
                    //Reason for doing two days ago is that if someone starts a shift at 11pm, but doesn't end it in
                    //time, it still needs to be re-calculated a day later.
                    //Could maybe get around this by getting all punches of yesterday, and getting their date_ids
                    //and just recalculating those.
                    //Enable pre-mature exceptions if we're recalculating just one day ago.
                    //Problem is a late shift on say Monday: 2:00PM to 11:00PM won't trigger the exception at 1AM the next day,
                    //but by 1AM the following day (2days later) its too late and emails are disabled if enable_premature_exceptions are disabled.
                    $enable_premature_exceptions = FALSE;
                    //if ( $end_date == TTDate::getMiddleDayEpoch( $ud_obj->getDateStamp() ) ) {
                    if (TTDate::getMiddleDayEpoch($ud_obj->getDateStamp()) >= TTDate::getMiddleDayEpoch($execution_time) - 86400 * 2) {
                        $enable_premature_exceptions = TRUE;
                    }
                    Debug::text($x . '(' . $i . '). User: '******' Date: ' . TTDate::getDate('DATE+TIME', $ud_obj->getDateStamp()) . ' User Date ID: ' . $ud_obj->getId() . ' Enable PreMature Exceptions: ' . (int) $enable_premature_exceptions, __FILE__, __LINE__, __METHOD__, 5);
                    UserDateTotalFactory::reCalculateDay($ud_obj->getId(), TRUE, $enable_premature_exceptions);
                    TTDate::setTimeZone();
                    $i++;
                    $x++;
                }
            }
            Debug::text('Company: ' . $c_obj->getName() . '(' . $c_obj->getId() . ') Finished In: ' . (microtime(TRUE) - $company_start_time) . 's', __FILE__, __LINE__, __METHOD__, 5);
        }
    }
}
Debug::writeToLog();
Debug::Display();
Ejemplo n.º 3
0
                 $udlf->getByCompanyIdAndPayPeriodID($current_company->getId(), $pay_period_ids);
             } else {
                 TTLog::addEntry($filter_user_id, 500, TTi18n::gettext('Recalculating Employee TimeSheet'), $current_user->getId(), 'user_date_total');
                 $udlf->getByUserIdAndPayPeriodID($filter_user_id, $pay_period_ids);
             }
             if ($udlf->getRecordCount() > 0) {
                 InitProgressBar();
                 $progress_bar->setValue(0);
                 $progress_bar->display();
                 Debug::text('Found days to re-calculate: ' . $udlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 $x = 1;
                 foreach ($udlf as $ud_obj) {
                     //Debug::text($x .' / '. $udlf->getRecordCount() .' - User Date Id: '. $ud_obj->getId() .' Date: '.$ud_obj->getDateStamp(TRUE) .' User ID: '. $ud_obj->getUser() , __FILE__, __LINE__, __METHOD__, 10);
                     $udlf->StartTransaction();
                     //If a transaction wraps the entire recalculation process, a deadlock is likely to occur for large batches.
                     UserDateTotalFactory::reCalculateDay($ud_obj->getId(), TRUE);
                     $udlf->CommitTransaction();
                     $progress_bar->setValue(Misc::calculatePercent($x, $udlf->getRecordCount()));
                     $progress_bar->display();
                     $x++;
                 }
             } else {
                 Debug::text('No User Date rows to calculate!', __FILE__, __LINE__, __METHOD__, 10);
             }
         } else {
             Debug::text('Pay Period is CLOSED: ', __FILE__, __LINE__, __METHOD__, 10);
         }
     }
     break;
 case 'generate_paystubs':
     //Debug::setVerbosity(11);
 function postSave()
 {
     $this->removeCache($this->getId());
     $this->calcUserDate();
     $this->calcUserDateTotal();
     if ($this->getEnableCalcSystemTotalTime() == TRUE) {
         $this->old_user_date_ids[] = $this->getUserDateID();
         if ($this->getUser() > 0) {
             //var_dump($this->old_user_date_ids);
             UserDateTotalFactory::smartReCalculate($this->getUser(), $this->old_user_date_ids, $this->getEnableCalcException(), $this->getEnablePreMatureException());
         }
     }
     return TRUE;
 }
    function getSumByUserIdAndAccrualPolicyId($user_id, $accrual_policy_id)
    {
        if ($user_id == '') {
            return FALSE;
        }
        if ($accrual_policy_id == '') {
            return FALSE;
        }
        $udtf = new UserDateTotalFactory();
        $ph = array('user_id' => $user_id, 'accrual_policy_id' => $accrual_policy_id);
        $query = '
					select 	sum(amount) as amount
					from	' . $this->getTable() . ' as a
					LEFT JOIN ' . $udtf->getTable() . ' as b ON a.user_date_total_id = b.id
					where	a.user_id = ?
						AND a.accrual_policy_id = ?
						AND ( (a.user_date_total_id is NOT NULL AND b.id is NOT NULL)
								OR a.user_date_total_id IS NULL AND b.id is NULL )
						AND a.deleted = 0';
        $total = $this->db->GetOne($query, $ph);
        if ($total === FALSE) {
            $total = 0;
        }
        Debug::text('Balance: ' . $total, __FILE__, __LINE__, __METHOD__, 10);
        return $total;
    }
Ejemplo n.º 6
0
    function getAPISearchByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL)
    {
        if ($company_id == '') {
            return FALSE;
        }
        if (isset($filter_data['user_status_id'])) {
            $filter_data['status_id'] = $filter_data['user_status_id'];
        }
        if (isset($filter_data['user_group_id'])) {
            $filter_data['group_id'] = $filter_data['user_group_id'];
        }
        if (isset($filter_data['user_title_id'])) {
            $filter_data['title_id'] = $filter_data['user_title_id'];
        }
        if (isset($filter_data['include_user_id'])) {
            $filter_data['user_id'] = $filter_data['include_user_id'];
        }
        if (isset($filter_data['exclude_user_id'])) {
            $filter_data['exclude_id'] = $filter_data['exclude_user_id'];
        }
        if (isset($filter_data['accrual_type_id'])) {
            $filter_data['type_id'] = $filter_data['accrual_type_id'];
        }
        if (!is_array($order)) {
            //Use Filter Data ordering if its set.
            if (isset($filter_data['sort_column']) and $filter_data['sort_order']) {
                $order = array(Misc::trimSortPrefix($filter_data['sort_column']) => $filter_data['sort_order']);
            }
        }
        if (isset($filter_data['accrual_type_id'])) {
            $filter_data['type_id'] = $filter_data['accrual_type_id'];
        }
        $additional_order_fields = array('accrual_policy', 'accrual_policy_type_id', 'date_stamp');
        $sort_column_aliases = array('accrual_policy_type' => 'accrual_policy_type_id', 'type' => 'type_id');
        $order = $this->getColumnsFromAliases($order, $sort_column_aliases);
        if ($order == NULL) {
            $order = array('accrual_policy_id' => 'asc', 'date_stamp' => 'desc');
            $strict = FALSE;
        } else {
            $strict = TRUE;
        }
        //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10);
        //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10);
        $uf = new UserFactory();
        $udtf = new UserDateTotalFactory();
        $udf = new UserDateFactory();
        $bf = new BranchFactory();
        $df = new DepartmentFactory();
        $ugf = new UserGroupFactory();
        $utf = new UserTitleFactory();
        $apf = new AccrualPolicyFactory();
        $ph = array('company_id' => $company_id);
        $query = '
					select 	a.*,
							ab.name as accrual_policy,
							ab.type_id as accrual_policy_type_id,
							CASE WHEN udf.date_stamp is NOT NULL THEN udf.date_stamp ELSE a.time_stamp END as date_stamp,
							b.first_name as first_name,
							b.last_name as last_name,
							b.country as country,
							b.province as province,

							c.id as default_branch_id,
							c.name as default_branch,
							d.id as default_department_id,
							d.name as default_department,
							e.id as group_id,
							e.name as "user_group",
							f.id as title_id,
							f.name as title
					from 	' . $this->getTable() . ' as a
						LEFT JOIN ' . $apf->getTable() . ' as ab ON ( a.accrual_policy_id = ab.id AND ab.deleted = 0 )
						LEFT JOIN ' . $uf->getTable() . ' as b ON ( a.user_id = b.id AND b.deleted = 0 )

						LEFT JOIN ' . $udtf->getTable() . ' as udtf ON ( a.user_date_total_id = udtf.id AND udtf.deleted = 0 )
						LEFT JOIN ' . $udf->getTable() . ' as udf ON ( udtf.user_date_id = udf.id AND udf.deleted = 0 )

						LEFT JOIN ' . $bf->getTable() . ' as c ON ( b.default_branch_id = c.id AND c.deleted = 0)
						LEFT JOIN ' . $df->getTable() . ' as d ON ( b.default_department_id = d.id AND d.deleted = 0)
						LEFT JOIN ' . $ugf->getTable() . ' as e ON ( b.group_id = e.id AND e.deleted = 0 )
						LEFT JOIN ' . $utf->getTable() . ' as f ON ( b.title_id = f.id AND f.deleted = 0 )
                        LEFT JOIN ' . $uf->getTable() . ' as y ON ( a.created_by = y.id AND y.deleted = 0 )
						LEFT JOIN ' . $uf->getTable() . ' as z ON ( a.updated_by = z.id AND z.deleted = 0 )

					where	b.company_id = ?
					';
        $query .= isset($filter_data['permission_children_ids']) ? $this->getWhereClauseSQL('a.user_id', $filter_data['permission_children_ids'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['user_id']) ? $this->getWhereClauseSQL('a.user_id', $filter_data['user_id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['id']) ? $this->getWhereClauseSQL('a.id', $filter_data['id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['exclude_id']) ? $this->getWhereClauseSQL('a.user_id', $filter_data['exclude_id'], 'not_numeric_list', $ph) : NULL;
        if (isset($filter_data['type']) and trim($filter_data['type']) != '' and !isset($filter_data['type_id'])) {
            $filter_data['type_id'] = Option::getByFuzzyValue($filter_data['type'], $this->getOptions('type'));
        }
        $query .= isset($filter_data['type_id']) ? $this->getWhereClauseSQL('a.type_id', $filter_data['type_id'], 'numeric_list', $ph) : NULL;
        if (isset($filter_data['status']) and trim($filter_data['status']) != '' and !isset($filter_data['status_id'])) {
            $filter_data['status_id'] = Option::getByFuzzyValue($filter_data['status'], $this->getOptions('status'));
        }
        $query .= isset($filter_data['accrual_policy_type_id']) ? $this->getWhereClauseSQL('ab.type_id', $filter_data['accrual_policy_type_id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['accrual_policy_id']) ? $this->getWhereClauseSQL('a.accrual_policy_id', $filter_data['accrual_policy_id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['status_id']) ? $this->getWhereClauseSQL('b.status_id', $filter_data['status_id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['group_id']) ? $this->getWhereClauseSQL('b.group_id', $filter_data['group_id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['default_branch_id']) ? $this->getWhereClauseSQL('b.default_branch_id', $filter_data['default_branch_id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['default_department_id']) ? $this->getWhereClauseSQL('b.default_department_id', $filter_data['default_department_id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['title_id']) ? $this->getWhereClauseSQL('b.title_id', $filter_data['title_id'], 'numeric_list', $ph) : NULL;
        $query .= isset($filter_data['country']) ? $this->getWhereClauseSQL('b.country', $filter_data['country'], 'upper_text_list', $ph) : NULL;
        $query .= isset($filter_data['province']) ? $this->getWhereClauseSQL('b.province', $filter_data['province'], 'upper_text_list', $ph) : NULL;
        $query .= isset($filter_data['pay_period_id']) ? $this->getWhereClauseSQL('udf.pay_period_id', $filter_data['pay_period_id'], 'numeric_list', $ph) : NULL;
        if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') {
            $ph[] = $this->db->BindDate($filter_data['start_date']);
            $ph[] = $this->db->BindDate($filter_data['start_date']);
            $query .= ' AND ( ( udf.date_stamp is NULL AND a.time_stamp >= ? ) OR ( udf.date_stamp is NOT NULL AND udf.date_stamp >= ? ) )';
        }
        if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') {
            $ph[] = $this->db->BindDate($filter_data['end_date']);
            $ph[] = $this->db->BindDate($filter_data['end_date']);
            $query .= ' AND ( ( udf.date_stamp is NULL AND a.time_stamp <= ? ) OR ( udf.date_stamp is NOT NULL AND udf.date_stamp <= ? ) )';
        }
        $query .= isset($filter_data['created_by']) ? $this->getWhereClauseSQL(array('a.created_by', 'y.first_name', 'y.last_name'), $filter_data['created_by'], 'user_id_or_name', $ph) : NULL;
        $query .= isset($filter_data['updated_by']) ? $this->getWhereClauseSQL(array('a.updated_by', 'z.first_name', 'z.last_name'), $filter_data['updated_by'], 'user_id_or_name', $ph) : NULL;
        //Make sure we exclude delete user_date_total records, so we match the accrual balances.
        $query .= '
						AND ( ( a.user_date_total_id is NOT NULL AND udtf.id is NOT NULL AND udtf.deleted = 0 ) OR ( a.user_date_total_id IS NULL AND udtf.id is NULL ) )
						AND a.deleted = 0
					';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order, $strict, $additional_order_fields);
        //Debug::Arr($ph,'Filter Data:'. $query, __FILE__, __LINE__, __METHOD__,10);
        $this->ExecuteSQL($query, $ph, $limit, $page);
        return $this;
    }
 function postSave()
 {
     Debug::text(' postSave()', __FILE__, __LINE__, __METHOD__, 10);
     if ($this->getEnableReCalculateDay() == TRUE) {
         //Calculate total time. Mainly for docked.
         UserDateTotalFactory::reCalculateDay($this->getUserDateID(), TRUE, FALSE);
         //ExceptionPolicyFactory::calcExceptions( $this->getUserDateID() );
     }
     return TRUE;
 }
Ejemplo n.º 8
0
 function postSave()
 {
     $this->removeCache($this->getId());
     if ($this->getDeleted() == TRUE) {
         Debug::Text('UnAssign Hours from Branch: ' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10);
         //Unassign hours from this branch.
         $pcf = new PunchControlFactory();
         $udtf = new UserDateTotalFactory();
         $uf = new UserFactory();
         $sf = new StationFactory();
         $sf_b = new ScheduleFactory();
         $udf = new UserDefaultFactory();
         $rstf = new RecurringScheduleTemplateFactory();
         $query = 'update ' . $pcf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $udtf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $sf_b->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $uf->getTable() . ' set default_branch_id = 0 where company_id = ' . $this->getCompany() . ' AND default_branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $udf->getTable() . ' set default_branch_id = 0 where company_id = ' . $this->getCompany() . ' AND default_branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $sf->getTable() . ' set branch_id = 0 where company_id = ' . $this->getCompany() . ' AND branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $rstf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
     }
     return TRUE;
 }
 static function smartReCalculate($user_id, $user_date_ids, $enable_exception = TRUE, $enable_premature_exceptions = FALSE, $enable_future_exceptions = TRUE)
 {
     if ($user_id == '') {
         return FALSE;
     }
     //Debug::Arr($user_date_ids, 'aUser Date IDs: ', __FILE__, __LINE__, __METHOD__, 10);
     if (!is_array($user_date_ids) and is_numeric($user_date_ids) and $user_date_ids > 0) {
         $user_date_ids = array($user_date_ids);
     }
     if (!is_array($user_date_ids)) {
         Debug::Text('Returning FALSE... User Date IDs not an array...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     $user_date_ids = array_unique($user_date_ids);
     //Debug::Arr($user_date_ids, 'bUser Date IDs: ', __FILE__, __LINE__, __METHOD__, 10);
     $start_week_day_id = 0;
     $ppslf = TTnew('PayPeriodScheduleListFactory');
     $ppslf->getByUserId($user_id);
     if ($ppslf->getRecordCount() == 1) {
         $pps_obj = $ppslf->getCurrent();
         $start_week_day_id = $pps_obj->getStartWeekDay();
     }
     Debug::text('Start Week Day ID: ' . $start_week_day_id, __FILE__, __LINE__, __METHOD__, 10);
     //Get date stamps for all user_date_ids.
     $udlf = TTnew('UserDateListFactory');
     $udlf->getByIds($user_date_ids, NULL, array('date_stamp' => 'asc'));
     //Order by date asc
     if ($udlf->getRecordCount() > 0) {
         //Order them, and get the one or more sets of date ranges that need to be recalculated.
         //Need to consider re-calculating multiple weeks at once.
         $i = 0;
         foreach ($udlf as $ud_obj) {
             $start_week_epoch = TTDate::getBeginWeekEpoch($ud_obj->getDateStamp(), $start_week_day_id);
             $end_week_epoch = TTDate::getEndWeekEpoch($ud_obj->getDateStamp(), $start_week_day_id);
             Debug::text('Current Date: ' . TTDate::getDate('DATE', $ud_obj->getDateStamp()) . ' Start Week: ' . TTDate::getDate('DATE', $start_week_epoch) . ' End Week: ' . TTDate::getDate('DATE', $end_week_epoch), __FILE__, __LINE__, __METHOD__, 10);
             if ($i == 0) {
                 $range_arr[$start_week_epoch] = array('start_date' => $ud_obj->getDateStamp(), 'end_date' => $end_week_epoch);
             } else {
                 //Loop through each range extending it if needed.
                 foreach ($range_arr as $tmp_start_week_epoch => $tmp_range) {
                     if ($ud_obj->getDateStamp() >= $tmp_range['start_date'] and $ud_obj->getDateStamp() <= $tmp_range['end_date']) {
                         //Date falls within already existing range
                         continue;
                     } elseif ($ud_obj->getDateStamp() < $tmp_range['start_date'] and $ud_obj->getDateStamp() >= $tmp_start_week_epoch) {
                         //Date falls within the same week, but before the current start date.
                         $range_arr[$tmp_start_week_epoch]['start_date'] = $ud_obj->getDateStamp();
                         Debug::text('Pushing Start Date back...', __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                         //Outside current range. Check to make sure it isn't within another range.
                         if (isset($range_arr[$start_week_epoch])) {
                             //Within another existing week, check to see if we need to extend it.
                             if ($ud_obj->getDateStamp() < $range_arr[$start_week_epoch]['start_date']) {
                                 Debug::text('bPushing Start Date back...', __FILE__, __LINE__, __METHOD__, 10);
                                 $range_arr[$start_week_epoch]['start_date'] = $ud_obj->getDateStamp();
                             }
                         } else {
                             //Not within another existing week
                             Debug::text('Adding new range...', __FILE__, __LINE__, __METHOD__, 10);
                             $range_arr[$start_week_epoch] = array('start_date' => $ud_obj->getDateStamp(), 'end_date' => $end_week_epoch);
                         }
                     }
                 }
                 unset($tmp_range, $tmp_start_week_epoch);
             }
             $i++;
         }
         unset($start_week_epoch, $end_week_epoch, $udlf, $ud_obj);
         if (is_array($range_arr)) {
             ksort($range_arr);
             //Sort range by start week, so recalculating goes in date order.
             //Debug::Arr($range_arr, 'Range Array: ', __FILE__, __LINE__, __METHOD__, 10);
             foreach ($range_arr as $week_range) {
                 $udlf = TTnew('UserDateListFactory');
                 $udlf->getByUserIdAndStartDateAndEndDate($user_id, $week_range['start_date'], $week_range['end_date']);
                 if ($udlf->getRecordCount() > 0) {
                     Debug::text('Found days to re-calculate: ' . $udlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                     $udlf->StartTransaction();
                     $z = 1;
                     $z_max = $udlf->getRecordCount();
                     foreach ($udlf as $ud_obj) {
                         //We only need to re-calculate exceptions on the exact days specified by user_date_ids.
                         //This was the case before we Over Weekly Time/Over Scheduled Weekly Time exceptions,
                         //Now we have to enable calculating exceptions for the entire week.
                         Debug::text('Re-calculating day with exceptions: ' . $ud_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                         if ($z == $z_max) {
                             //Enable recalculating holidays at the end of each week.
                             UserDateTotalFactory::reCalculateDay($ud_obj->getId(), $enable_exception, $enable_premature_exceptions, $enable_future_exceptions, TRUE);
                         } else {
                             UserDateTotalFactory::reCalculateDay($ud_obj->getId(), $enable_exception, $enable_premature_exceptions, $enable_future_exceptions);
                         }
                         $z++;
                     }
                     $udlf->CommitTransaction();
                 }
             }
             //Use the last date to base the future week calculation on. Make sure we don't unset $week_range['end_date']
             //When BiWeekly overtime policies are calculated, it sets getEnableCalcFutureWeek() to TRUE.
             if (isset($week_range['end_date']) and UserDateTotalFactory::getEnableCalcFutureWeek() == TRUE) {
                 $future_week_date = $week_range['end_date'] + 86400 * 7;
                 Debug::text('Found Biweekly overtime policy, calculate one week into the future: ' . TTDate::getDate('DATE', $future_week_date), __FILE__, __LINE__, __METHOD__, 10);
                 UserDateTotalFactory::reCalculateRange($user_id, TTDate::getBeginWeekEpoch($future_week_date, $start_week_day_id), TTDate::getEndWeekEpoch($future_week_date, $start_week_day_id));
                 UserDateTotalFactory::setEnableCalcFutureWeek(FALSE);
                 //Return to FALSE so future weeks aren't calculate for other users.
                 unset($future_week_date);
             }
             return TRUE;
         }
     }
     Debug::text('Returning FALSE!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
Ejemplo n.º 10
0
if (!$permission->Check('punch', 'enabled') or !($permission->Check('punch', 'edit') or $permission->Check('punch', 'edit_own'))) {
    $permission->Redirect(FALSE);
    //Redirect
}
$smarty->assign('title', TTi18n::gettext($title = 'Edit Hour'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'user_date_id', 'user_id', 'date', 'udt_data')));
if (isset($udt_data)) {
    if ($udt_data['total_time'] != '') {
        $udt_data['total_time'] = TTDate::parseTimeUnit($udt_data['total_time']);
    }
}
$udtf = new UserDateTotalFactory();
$action = strtolower($action);
switch ($action) {
    case 'submit':
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        $udtf->setId($udt_data['id']);
        $udtf->setUserDateId($udt_data['user_date_id']);
        $udtf->setStatus($udt_data['status_id']);
        $udtf->setType($udt_data['type_id']);
        $udtf->setBranch($udt_data['branch_id']);
        $udtf->setDepartment($udt_data['department_id']);
        if (isset($udt_data['job_id'])) {
            $udtf->setJob($udt_data['job_id']);
        }
        if (isset($udt_data['job_item_id'])) {
Ejemplo n.º 11
0
if (!$permission->Check('absence', 'enabled') or !($permission->Check('absence', 'edit') or $permission->Check('absence', 'edit_own') or $permission->Check('absence', 'edit_child'))) {
    $permission->Redirect(FALSE);
    //Redirect
}
$smarty->assign('title', TTi18n::gettext($title = 'Edit Absence'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'user_id', 'date_stamp', 'udt_data')));
if (isset($udt_data)) {
    if ($udt_data['total_time'] != '') {
        $udt_data['total_time'] = TTDate::parseTimeUnit($udt_data['total_time']);
    }
}
$udtf = new UserDateTotalFactory();
$action = Misc::findSubmitButton();
$action = strtolower($action);
switch ($action) {
    case 'delete':
        Debug::Text('Delete!', __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        $udtlf = new UserDateTotalListFactory();
        $udtlf->getById($udt_data['id']);
        if ($udtlf->getRecordCount() > 0) {
            foreach ($udtlf as $udt_obj) {
                $udt_obj->setDeleted(TRUE);
                if ($udt_obj->isValid()) {
                    $udt_obj->setEnableCalcSystemTotalTime(TRUE);
                    $udt_obj->setEnableCalcWeeklySystemTotalTime(TRUE);
                    $udt_obj->setEnableCalcException(TRUE);
Ejemplo n.º 12
0
 function testTimeBasedPartialPremiumPolicyF3()
 {
     global $dd;
     TTDate::setTimeZone('PST8PDT');
     $policy_ids['premium'][] = $this->createPremiumPolicy($this->company_id, 125);
     //Create Policy Group
     $dd->createPolicyGroup($this->company_id, NULL, NULL, NULL, NULL, $policy_ids['premium'], NULL, array($this->user_id));
     $date_epoch = $this->pay_period_objs[0]->getStartDate() + 86400 * 6;
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     //Test punching in before the premium start time, and out after the premium end time.
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 5:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //print_r($udt_arr);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 15 * 3600);
     //Regular Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 20);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 15 * 3600);
     //Premium Time1
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 40);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 12 * 3600);
     //Make sure no other hours
     $this->assertEquals(count($udt_arr[$date_epoch]), 3);
     $udlf = TTNew('UserDateListFactory');
     $udlf->getByID($udt_arr[$date_epoch][0]['user_date_id']);
     unset($udt_arr);
     $user_date_id = $udlf->getCurrent()->getId();
     TTDate::setTimeZone('EST5EDT');
     $recalc_result = UserDateTotalFactory::reCalculateDay($user_date_id, TRUE);
     TTDate::setTimeZone('PST8PDT');
     $date_epoch = $this->pay_period_objs[0]->getStartDate() + 86400 * 6;
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //print_r($udt_arr);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 15 * 3600);
     //Regular Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 20);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 15 * 3600);
     //Premium Time1
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 40);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 12 * 3600);
     //Make sure no other hours
     $this->assertEquals(count($udt_arr[$date_epoch]), 3);
     return TRUE;
 }
Ejemplo n.º 13
0
 /**
  * ReCalculate timesheet/policies
  * @return bool
  */
 function reCalculateTimeSheet($pay_period_ids, $user_ids = NULL)
 {
     //Debug::text('Recalculating Employee Timesheet: User ID: '. $user_ids .' Pay Period ID: '. $pay_period_ids, __FILE__, __LINE__, __METHOD__,10);
     //Debug::setVerbosity(11);
     if (!$this->getPermissionObject()->Check('punch', 'enabled') or !($this->getPermissionObject()->Check('punch', 'edit') or $this->getPermissionObject()->Check('punch', 'edit_child'))) {
         return $this->getPermissionObject()->PermissionDenied();
     }
     //Make sure pay period is not CLOSED.
     //We can re-calc on locked though.
     $pplf = TTnew('PayPeriodListFactory');
     $pplf->getByIdList($pay_period_ids);
     if ($pplf->getRecordCount() > 0) {
         $pp_obj = $pplf->getCurrent();
         if ($pp_obj->getStatus() != 20) {
             $udlf = TTnew('UserDateListFactory');
             if (is_array($user_ids) and count($user_ids) > 0 and isset($user_ids[0]) and $user_ids[0] > 0) {
                 $udlf->getByUserIdAndPayPeriodID($user_ids, $pay_period_ids);
             } elseif ($this->getPermissionObject()->Check('punch', 'edit') == TRUE) {
                 //Make sure they have the permissions to recalculate all employees.
                 TTLog::addEntry($this->getCurrentCompanyObject()->getId(), TTi18n::gettext('Notice'), TTi18n::gettext('Recalculating Company TimeSheet'), $this->getCurrentUserObject()->getId(), 'user_date_total');
                 $udlf->getByCompanyIdAndPayPeriodID($this->getCurrentCompanyObject()->getId(), $pay_period_ids);
             } else {
                 return $this->getPermissionObject()->PermissionDenied();
             }
             if ($udlf->getRecordCount() > 0) {
                 Debug::text('Found days to re-calculate: ' . $udlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 $this->getProgressBarObject()->start($this->getAMFMessageID(), $udlf->getRecordCount(), NULL, TTi18n::getText('ReCalculating...'));
                 $x = 1;
                 $prev_date_stamp = FALSE;
                 foreach ($udlf as $ud_obj) {
                     Debug::text($x . ' / ' . $udlf->getRecordCount() . ' - User Date Id: ' . $ud_obj->getId() . ' Date: ' . $ud_obj->getDateStamp(TRUE) . ' User ID: ' . $ud_obj->getUser(), __FILE__, __LINE__, __METHOD__, 10);
                     if ($prev_date_stamp != FALSE and abs($ud_obj->getDateStamp() - $prev_date_stamp) > 86400) {
                         Debug::text('Found gap between user_date rows! - User Date Id: ' . $ud_obj->getId() . ' Date: ' . $ud_obj->getDateStamp(TRUE) . ' Previous Date: ' . TTDate::getDate('DATE', $prev_date_stamp) . ' User ID: ' . $ud_obj->getUser(), __FILE__, __LINE__, __METHOD__, 10);
                         for ($n = $prev_date_stamp; $n < $ud_obj->getDateStamp(); $n += 86400) {
                             $tmp_user_date_id = UserDateFactory::findOrInsertUserDate($ud_obj->getUser(), TTDate::getBeginDayEpoch($n));
                             Debug::text('Filling gap in user_date rows! - Date: ' . TTDate::getDate('DATE', $n) . ' User ID: ' . $ud_obj->getUser() . ' New User Date ID: ' . $tmp_user_date_id, __FILE__, __LINE__, __METHOD__, 10);
                             UserDateTotalFactory::reCalculateDay($tmp_user_date_id, TRUE);
                         }
                         unset($n, $tmp_user_date_id);
                     }
                     TTLog::addEntry($ud_obj->getId(), 500, TTi18n::gettext('Recalculating Employee TimeSheet') . ': ' . $ud_obj->getUserObject()->getFullName() . ' ' . TTi18n::gettext('Date') . ': ' . TTDate::getDate('DATE', $ud_obj->getDateStamp()), $this->getCurrentUserObject()->getId(), 'user_date_total');
                     $udlf->StartTransaction();
                     //If a transaction wraps the entire recalculation process, a deadlock is likely to occur for large batches.
                     UserDateTotalFactory::reCalculateDay($ud_obj->getId(), TRUE);
                     $udlf->CommitTransaction();
                     $this->getProgressBarObject()->set($this->getAMFMessageID(), $x);
                     $prev_date_stamp = $ud_obj->getDateStamp();
                     $x++;
                 }
                 $this->getProgressBarObject()->stop($this->getAMFMessageID());
             } else {
                 Debug::text('No User Date rows to calculate!', __FILE__, __LINE__, __METHOD__, 10);
             }
         } else {
             Debug::text('Pay Period is CLOSED: ', __FILE__, __LINE__, __METHOD__, 10);
         }
     }
     return $this->returnHandler(TRUE);
 }
Ejemplo n.º 14
0
 function getTotalAccumulatedUserDateTotal($data, $disable_paging = FALSE)
 {
     $retarr = UserDateTotalFactory::calcAccumulatedTime($this->getUserDateTotal($data, TRUE));
     if (isset($retarr['total'])) {
         return $retarr['total'];
     }
     return FALSE;
 }