Пример #1
0
 case 'add_mass_schedule':
     if (isset($filter_user_id) and is_array($filter_user_id) and count($filter_user_id) > 0) {
         $init_progress_bar = TRUE;
         if ($init_progress_bar == TRUE) {
             InitProgressBar();
             $init_progress_bar = FALSE;
         }
         $progress_bar->setValue(0);
         $progress_bar->display();
         //This will be slightly off depending on which days of the week they choose.
         $total_shifts = count($filter_user_id) * TTDate::getDays($data['end_full_time_stamp'] - $data['start_full_time_stamp']);
         Debug::Text('Total Shifts: ' . $total_shifts . ' Users: ' . count($filter_user_id) . ' Days: ' . TTDate::getDays($data['end_full_time_stamp'] - $data['start_full_time_stamp']), __FILE__, __LINE__, __METHOD__, 10);
         $sf = new ScheduleFactory();
         $ulf = new UserListFactory();
         $sf->StartTransaction();
         TTLog::addEntry($current_user->getId(), 500, 'Mass Schedule: Start Time: ' . TTDate::getDate('TIME', $data['start_full_time_stamp']) . ' End Time: ' . TTDate::getDate('TIME', $data['end_full_time_stamp']) . ' Total Employees: ' . count($filter_user_id) . ' Total Days: ' . round(TTDate::getDays($data['end_full_time_stamp'] - $data['start_full_time_stamp'])), $current_user->getId(), $sf->getTable());
         $time_stamp = $data['start_full_time_stamp'];
         $fail_transaction = FALSE;
         $x = 0;
         while ($time_stamp <= $data['end_full_time_stamp']) {
             if (isset($data['dow'][TTDate::getDayOfWeek($time_stamp)]) and $data['dow'][TTDate::getDayOfWeek($time_stamp)] == 1) {
                 foreach ($filter_user_id as $user_id) {
                     if ($data['start_time'] != '') {
                         $start_time = strtotime($data['start_time'], $time_stamp);
                     } else {
                         $start_time = NULL;
                     }
                     if ($data['end_time'] != '') {
                         Debug::Text('End Time: ' . $data['end_time'] . ' Date Stamp: ' . $time_stamp, __FILE__, __LINE__, __METHOD__, 10);
                         $end_time = strtotime($data['end_time'], $time_stamp);
                         //Debug::Text('bEnd Time: '. $data['end_time'] .' - '. TTDate::getDate('DATE+TIME',$data['end_time']) , __FILE__, __LINE__, __METHOD__,10);
 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;
 }
 function postInstall()
 {
     global $config_vars;
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Update permission for new modules.
     $clf = TTnew('CompanyListFactory');
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         $i = 0;
         foreach ($clf as $c_obj) {
             if ($c_obj->getStatus() != 30) {
                 Debug::text($i . '/' . $clf->getRecordCount() . '. Company: ' . $c_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
                 //Disable detailed audit logging while updating permissions, as this can create millions of records and slow the upgrade down substantially.
                 $config_vars['other']['disable_audit_log_detail'] = TRUE;
                 $config_vars['other']['disable_audit_log'] = TRUE;
                 $pclf = TTnew('PermissionControlListFactory');
                 // Update all the HR related permissions for the Standard/Business Edition (KPIs, reviews, qualifications, etc..., but *not* job vacancy or job applicants)
                 $pclf->getByCompanyID($c_obj->getID(), NULL, NULL, NULL, array('id' => 'asc'));
                 if ($pclf->getRecordCount() > 0) {
                     $pf = TTnew('PermissionFactory');
                     $preset_options = $pf->getOptions('preset');
                     $preset_level_options = $pf->getOptions('preset_level');
                     ksort($preset_options);
                     foreach ($pclf as $pc_obj) {
                         $level = $pc_obj->getLevel();
                         // 1, 10, 12, 15, 20, 25
                         if ($level >= 10) {
                             //Only process levels 10 and higher, as those are supervisors and only ones that need adjusting.
                             $old_permission_arr = $pc_obj->getPermission();
                             if (is_array($old_permission_arr)) {
                                 foreach ($preset_options as $preset => $preset_name) {
                                     // preset: 10, 18, 20, 30, 40
                                     if ($level == $preset_level_options[$preset]) {
                                         $permission_arr = $pf->getPresetPermissions($preset, array(70, 75, 80));
                                         //Module: Human Resources
                                         //Debug::Arr( $permission_arr, ' New Permissions: ', __FILE__, __LINE__, __METHOD__,10);
                                         $pc_obj->setPermission($permission_arr, $old_permission_arr);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 unset($pclf, $pf, $preset_options, $preset_level_options, $old_permission_arr, $level, $pc_obj);
                 //Re-enable audit logging after permissions were updated.
                 $config_vars['other']['disable_audit_log_detail'] = FALSE;
                 $config_vars['other']['disable_audit_log'] = FALSE;
                 //Delete duplicate OPEN shifts before todays date.
                 $sf = new ScheduleFactory();
                 $udf = new UserDateFactory();
                 $ph = array('id' => $this->db->BindDate(time()));
                 $query = 'update ' . $sf->getTable() . ' set deleted = 1 where user_date_id in ( select id from ' . $udf->getTable() . ' where user_id = 0 and date_stamp <= ? and deleted = 0 ) and created_by is NULL AND deleted = 0';
                 $this->db->Execute($query, $ph);
                 unset($query, $ph);
                 //Assign all absence policies to every policy group.
                 $aplf = TTnew('AbsencePolicyListFactory');
                 $aplf->getByCompanyId($c_obj->getId());
                 if ($aplf->getRecordCount() > 0) {
                     foreach ($aplf as $ap_obj) {
                         $ap_ids[] = $ap_obj->getId();
                     }
                 }
                 $pglf = TTnew('PolicyGroupListFactory');
                 $pglf->getByCompanyId($c_obj->getId());
                 if ($pglf->getRecordCount() > 0) {
                     foreach ($pglf as $pg_obj) {
                         if (isset($ap_ids)) {
                             $pg_obj->setAbsencePolicy($ap_ids);
                             if ($pg_obj->isValid()) {
                                 $pg_obj->Save();
                             }
                         }
                     }
                 }
                 unset($aplf, $pglf, $ap_obj, $pg_obj, $ap_ids);
             }
             $i++;
         }
     }
     return TRUE;
 }
 function postSave()
 {
     if ($this->getDeleted() == TRUE) {
         Debug::Text('UnAssign Schedule Policy from Schedule/Recurring Schedules...' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10);
         $sf = new ScheduleFactory();
         $rstf = new RecurringScheduleTemplateFactory();
         $query = 'update ' . $sf->getTable() . ' set schedule_policy_id = 0 where schedule_policy_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $rstf->getTable() . ' set schedule_policy_id = 0 where schedule_policy_id = ' . $this->getId();
         $this->db->Execute($query);
     }
     $this->removeCache($this->getId());
     return TRUE;
 }
    function getMidDayExceptionsByStartDateAndEndDateAndPayPeriodStatus($start_date, $end_date, $pay_period_status_id)
    {
        if ($start_date == '') {
            return FALSE;
        }
        if ($end_date == '') {
            return FALSE;
        }
        if ($pay_period_status_id == '') {
            return FALSE;
        }
        $epf = new ExceptionPolicyFactory();
        $ef = new ExceptionFactory();
        $epcf = new ExceptionPolicyControlFactory();
        $pgf = new PolicyGroupFactory();
        $pguf = new PolicyGroupUserFactory();
        $uf = new UserFactory();
        $cf = new CompanyFactory();
        $udf = new UserDateFactory();
        $sf = new ScheduleFactory();
        $pcf = new PunchControlFactory();
        $pf = new PunchFactory();
        $ppf = new PayPeriodFactory();
        $current_epoch = time();
        if (strncmp($this->db->databaseType, 'mysql', 5) == 0) {
            $to_timestamp_sql = 'FROM_UNIXTIME';
        } else {
            $to_timestamp_sql = 'to_timestamp';
        }
        $ph = array('current_time1' => $this->db->BindTimeStamp($current_epoch), 'current_time2' => $this->db->BindTimeStamp($current_epoch), 'current_epoch1' => $current_epoch, 'start_date' => $this->db->BindDate($start_date), 'end_date' => $this->db->BindDate($end_date));
        //Exceptions that need to be calculated in the middle of the day:
        //Definitely: In Late, Out Late, Missed CheckIn
        //Possible: Over Daily Scheduled Time, Over Weekly Scheduled Time, Over Daily Time, Over Weekly Time, Long Lunch (can't run this fast enough), Long Break (can't run this fast enough),
        //Optimize calcQuickExceptions:
        // Loop through exception policies where In Late/Out Late/Missed CheckIn are enabled.
        // Loop through ACTIVE users assigned to these exceptions policies.
        // Only find days that are scheduled AND ( NO punch after schedule start time OR NO punch after schedule end time )
        //      For Missed CheckIn they do not need to be scheduled.
        // Exclude days that already have the exceptions triggered on them (?) (What about split shifts?)
        //	- Just exclude exceptions not assigned to punch/punch_control_id, if there is more than one in the day I don't think it helps much anyways.
        //
        //Currently Over Weekly/Daily time exceptions are only triggered on a Out punch.
        $query = '	select distinct udf.*
					FROM ' . $epf->getTable() . ' as epf
					LEFT JOIN ' . $epcf->getTable() . ' as epcf ON ( epf.exception_policy_control_id = epcf.id )
					LEFT JOIN ' . $pgf->getTable() . ' as pgf ON ( epcf.id = pgf.exception_policy_control_id )
					LEFT JOIN ' . $pguf->getTable() . ' as pguf ON ( pgf.id = pguf.policy_group_id )
					LEFT JOIN ' . $uf->getTable() . ' as uf ON ( pguf.user_id = uf.id )
					LEFT JOIN ' . $cf->getTable() . ' as cf ON ( uf.company_id = cf.id )
					LEFT JOIN ' . $udf->getTable() . ' as udf ON ( uf.id = udf.user_id )
					LEFT JOIN ' . $ppf->getTable() . ' as ppf ON ( ppf.id = udf.pay_period_id )
					LEFT JOIN ' . $ef->getTable() . ' as ef ON ( udf.id = ef.user_date_id AND ef.exception_policy_id = epf.id AND ef.type_id != 5 )
					LEFT JOIN ' . $sf->getTable() . ' as sf ON ( udf.id = sf.user_date_id AND ( sf.start_time <= ? OR sf.end_time <= ? ) )
					LEFT JOIN ' . $pcf->getTable() . ' as pcf ON ( udf.id = pcf.user_date_id AND pcf.deleted = 0 )
					LEFT JOIN ' . $pf->getTable() . ' as pf ON 	(
																pcf.id = pf.punch_control_id AND pf.deleted = 0
																AND (
																		( epf.type_id = \'S4\' AND ( pf.time_stamp >= sf.start_time OR pf.time_stamp <= sf.end_time ) )
																		OR
																		( epf.type_id = \'S6\' AND ( pf.time_stamp >= sf.end_time ) )
																		OR
																		( epf.type_id = \'C1\' AND ( pf.status_id = 10 AND pf.time_stamp <= ' . $to_timestamp_sql . '(?-epf.grace) ) )
																	)
																)
					WHERE ( epf.type_id in (\'S4\',\'S6\', \'C1\') AND epf.active = 1 )
						AND ( uf.status_id = 10 AND cf.status_id != 30 )
						AND ( udf.date_stamp >= ? AND udf.date_stamp <= ? )
						AND ppf.status_id in (' . $this->getListSQL($pay_period_status_id, $ph) . ')
						AND ( ( ( epf.type_id in (\'S4\',\'S6\') AND ( sf.id IS NOT NULL AND sf.deleted = 0 ) AND pf.id IS NULL ) OR epf.type_id = \'C1\' ) AND ef.id IS NULL  )
						AND ( epf.deleted = 0 AND epcf.deleted = 0 AND pgf.deleted = 0 AND uf.deleted = 0 AND cf.deleted = 0 AND udf.deleted = 0 )
				';
        //Don't check deleted = 0 on PCF/PF tables, as we need to check IS NULL on them instead.
        //Debug::Arr($ph, 'Query: '. $query, __FILE__, __LINE__, __METHOD__, 10);
        $this->ExecuteSQL($query, $ph);
        return $this;
    }