function createExceptionPolicy($company_id) { $epcf = new ExceptionPolicyControlFactory(); $epcf->setCompany($company_id); $epcf->setName('Default'); if ($epcf->isValid()) { $epc_id = $epcf->Save(); Debug::Text('aException Policy Control ID: ' . $epc_id, __FILE__, __LINE__, __METHOD__, 10); if ($epc_id === TRUE) { $epc_id = $data['id']; } Debug::Text('bException Policy Control ID: ' . $epc_id, __FILE__, __LINE__, __METHOD__, 10); $data['exceptions'] = array('S1' => array('active' => TRUE, 'severity_id' => 10), 'S2' => array('active' => TRUE, 'severity_id' => 30), 'S3' => array('active' => TRUE, 'severity_id' => 10, 'grace' => 300, 'watch_window' => 3600), 'S4' => array('active' => TRUE, 'severity_id' => 20, 'grace' => 300, 'watch_window' => 3600), 'S5' => array('active' => TRUE, 'severity_id' => 20, 'grace' => 300, 'watch_window' => 3600), 'S6' => array('active' => TRUE, 'severity_id' => 10, 'grace' => 300, 'watch_window' => 3600), 'S7' => array('active' => TRUE, 'severity_id' => 30), 'S8' => array('active' => TRUE, 'severity_id' => 10), 'M1' => array('active' => TRUE, 'severity_id' => 30), 'M2' => array('active' => TRUE, 'severity_id' => 30), 'L3' => array('active' => TRUE, 'severity_id' => 30), 'M3' => array('active' => TRUE, 'severity_id' => 30)); if (count($data['exceptions']) > 0) { foreach ($data['exceptions'] as $code => $exception_data) { Debug::Text('Looping Code: ' . $code, __FILE__, __LINE__, __METHOD__, 10); $epf = new ExceptionPolicyFactory(); $epf->setExceptionPolicyControl($epc_id); if (isset($exception_data['active'])) { $epf->setActive(TRUE); } else { $epf->setActive(FALSE); } $epf->setType($code); $epf->setSeverity($exception_data['severity_id']); if (isset($exception_data['demerit']) and $exception_data['demerit'] != '') { $epf->setDemerit($exception_data['demerit']); } if (isset($exception_data['grace']) and $exception_data['grace'] != '') { $epf->setGrace($exception_data['grace']); } if (isset($exception_data['watch_window']) and $exception_data['watch_window'] != '') { $epf->setWatchWindow($exception_data['watch_window']); } if ($epf->isValid()) { $epf->Save(); } } Debug::Text('Creating Exception Policy ID: ' . $epc_id, __FILE__, __LINE__, __METHOD__, 10); return $epc_id; } } Debug::Text('Failed Creating Exception Policy!', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
* Get FORM variables */ extract(FormVariables::GetVariables(array('action', 'id', 'data'))); if (isset($data['exceptions'])) { foreach ($data['exceptions'] as $code => $exception) { if (isset($exception['grace']) and $exception['grace'] != '') { Debug::Text('Grace: ' . $exception['grace'], __FILE__, __LINE__, __METHOD__, 10); $data['exceptions'][$code]['grace'] = TTDate::parseTimeUnit($exception['grace']); } if (isset($exception['watch_window']) and $exception['watch_window'] != '') { $data['exceptions'][$code]['watch_window'] = TTDate::parseTimeUnit($exception['watch_window']); } } } $epf = new ExceptionPolicyFactory(); $epcf = new ExceptionPolicyControlFactory(); $action = Misc::findSubmitButton(); $action = strtolower($action); switch ($action) { case 'submit': //Debug::setVerbosity(11); Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10); $epcf->setId($data['id']); $epcf->setCompany($current_company->getId()); $epcf->setName($data['name']); if ($epcf->isValid()) { $epc_id = $epcf->Save(); Debug::Text('aException Policy Control ID: ' . $epc_id, __FILE__, __LINE__, __METHOD__, 10); if ($epc_id === TRUE) { $epc_id = $data['id']; }
function getAPISearchByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } 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']); } } $additional_order_fields = array('type_id'); $sort_column_aliases = array('type' => 'type_id'); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { //$order = array( 'type_id' => 'asc'); $order = array('id' => 'asc'); //Type ID is the wrong order, but ID is proper. $strict = FALSE; } else { //Always try to order by status first so INACTIVE employees go to the bottom. if (!isset($order['type_id'])) { $order = Misc::prependArray(array('type_id' => 'asc'), $order); } //Always sort by last name,first name after other columns if (!isset($order['name'])) { $order['name'] = 'asc'; } $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); $uf = new UserFactory(); $epcf = new ExceptionPolicyControlFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, y.first_name as created_by_first_name, y.middle_name as created_by_middle_name, y.last_name as created_by_last_name, z.first_name as updated_by_first_name, z.middle_name as updated_by_middle_name, z.last_name as updated_by_last_name from ' . $this->getTable() . ' as a 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 ) LEFT JOIN ' . $epcf->getTable() . ' as b ON ( a.exception_policy_control_id = b.id AND b.deleted = 0 ) where b.company_id = ? '; if (isset($filter_data['permission_children_ids']) and isset($filter_data['permission_children_ids'][0]) and !in_array(-1, (array) $filter_data['permission_children_ids'])) { $query .= ' AND a.created_by in (' . $this->getListSQL($filter_data['permission_children_ids'], $ph) . ') '; } if (isset($filter_data['id']) and isset($filter_data['id'][0]) and !in_array(-1, (array) $filter_data['id'])) { $query .= ' AND a.id in (' . $this->getListSQL($filter_data['id'], $ph) . ') '; } if (isset($filter_data['exclude_id']) and isset($filter_data['exclude_id'][0]) and !in_array(-1, (array) $filter_data['exclude_id'])) { $query .= ' AND a.id not in (' . $this->getListSQL($filter_data['exclude_id'], $ph) . ') '; } if (isset($filter_data['exception_policy_control_id']) and isset($filter_data['exception_policy_control_id'][0]) and !in_array(-1, (array) $filter_data['exception_policy_control_id'])) { $query .= ' AND a.exception_policy_control_id in (' . $this->getListSQL($filter_data['exception_policy_control_id'], $ph) . ') '; } if (isset($filter_data['type_id']) and isset($filter_data['type_id'][0]) and !in_array(-1, (array) $filter_data['type_id'])) { $query .= ' AND a.type_id in (' . $this->getListSQL($filter_data['type_id'], $ph) . ') '; } if (isset($filter_data['name']) and trim($filter_data['name']) != '') { $ph[] = strtolower(trim($filter_data['name'])); $query .= ' AND lower(a.name) LIKE ?'; } $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; $query .= ' AND a.deleted = 0 '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); $this->ExecuteSQL($query, $ph, $limit, $page); return $this; }
function getAPISearchByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } 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['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['exception_policy_severity_id'])) { $filter_data['severity_id'] = $filter_data['exception_policy_severity_id']; } $additional_order_fields = array('d.name', 'e.name', 'f.name', 'g.name', 'h.status_id', 'i.severity_id', 'i.type_id', 'c.first_name', 'c.last_name', 'c.country', 'c.province', 'b.date_stamp', 'pgf.name', 'pscf.name', 'ppsf.name'); $sort_column_aliases = array('status' => 'status_id', 'type' => 'type_id'); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { //$order = array( 'status_id' => 'asc', 'last_name' => 'asc', 'first_name' => 'asc', 'middle_name' => 'asc'); $order = array('i.severity_id' => 'desc', 'c.last_name' => 'asc', 'b.date_stamp' => 'asc', 'i.type_id' => 'asc'); $strict = FALSE; } else { //Do order by column conversions, because if we include these columns in the SQL //query, they contaminate the data array. if (isset($order['default_branch'])) { $order['d.name'] = $order['default_branch']; unset($order['default_branch']); } if (isset($order['default_department'])) { $order['e.name'] = $order['default_department']; unset($order['default_department']); } if (isset($order['user_group'])) { $order['f.name'] = $order['user_group']; unset($order['user_group']); } if (isset($order['title'])) { $order['g.name'] = $order['title']; unset($order['title']); } if (isset($order['exception_policy_type_id'])) { $order['i.type_id'] = $order['exception_policy_type_id']; unset($order['exception_policy_type_id']); } if (isset($order['severity_id'])) { $order['i.severity_id'] = $order['severity_id']; unset($order['severity_id']); } if (isset($order['severity'])) { $order['i.severity_id'] = $order['severity']; unset($order['severity']); } if (isset($order['exception_policy_type'])) { $order['i.type_id'] = $order['exception_policy_type']; unset($order['exception_policy_type']); } if (isset($order['exception_policy_type_id'])) { $order['i.type_id'] = $order['exception_policy_type_id']; unset($order['exception_policy_type_id']); } if (isset($order['first_name'])) { $order['c.first_name'] = $order['first_name']; unset($order['first_name']); } if (isset($order['last_name'])) { $order['c.last_name'] = $order['last_name']; unset($order['last_name']); } if (isset($order['country'])) { $order['c.country'] = $order['country']; unset($order['country']); } if (isset($order['province'])) { $order['c.province'] = $order['province']; unset($order['province']); } if (isset($order['date_stamp'])) { $order['b.date_stamp'] = $order['date_stamp']; unset($order['date_stamp']); } if (isset($order['policy_group'])) { $order['pgf.name'] = $order['policy_group']; unset($order['policy_group']); } if (isset($order['permission_group'])) { $order['pscf.name'] = $order['permission_group']; unset($order['permission_group']); } if (isset($order['pay_period_schedule'])) { $order['ppsf.name'] = $order['pay_period_schedule']; unset($order['pay_period_schedule']); } //Always sort by last name,first name after other columns if (!isset($order['c.last_name'])) { $order['c.last_name'] = 'asc'; } if (!isset($order['c.first_name'])) { $order['c.first_name'] = 'asc'; } if (!isset($order['b.date_stamp'])) { $order['b.date_stamp'] = 'asc'; } if (!isset($order['i.severity_id'])) { $order['i.severity_id'] = 'desc'; } $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); $udf = new UserDateFactory(); $uf = new UserFactory(); $bf = new BranchFactory(); $df = new DepartmentFactory(); $ugf = new UserGroupFactory(); $utf = new UserTitleFactory(); $ppf = new PayPeriodFactory(); $ppsf = new PayPeriodScheduleFactory(); $epf = new ExceptionPolicyFactory(); $epcf = new ExceptionPolicyControlFactory(); $pguf = new PolicyGroupUserFactory(); $pgf = new PolicyGroupFactory(); $pf = new PunchFactory(); $pcf = new PunchControlFactory(); $pscf = new PermissionControlFactory(); $puf = new PermissionUserFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, b.date_stamp as date_stamp, b.pay_period_id as pay_period_id, h.pay_period_schedule_id as pay_period_schedule_id, i.severity_id as severity_id, i.type_id as exception_policy_type_id, b.user_id as user_id, h.start_date as pay_period_start_date, h.end_date as pay_period_end_date, h.transaction_date as pay_period_transaction_date, c.first_name as first_name, c.last_name as last_name, c.country as country, c.province as province, c.status_id as user_status_id, c.group_id as group_id, f.name as "group", c.title_id as title_id, g.name as title, c.default_branch_id as default_branch_id, d.name as default_branch, c.default_department_id as default_department_id, e.name as default_department, pcf.branch_id as branch_id, bf.name as branch, pcf.department_id as department_id, df.name as department, pgf.name as policy_group, pscf.name as permission_group, ppsf.name as pay_period_schedule, y.first_name as created_by_first_name, y.middle_name as created_by_middle_name, y.last_name as created_by_last_name, z.first_name as updated_by_first_name, z.middle_name as updated_by_middle_name, z.last_name as updated_by_last_name from ' . $this->getTable() . ' as a LEFT JOIN ' . $pf->getTable() . ' as pf ON ( a.punch_id IS NOT NULL AND a.punch_id = pf.id AND pf.deleted = 0) LEFT JOIN ' . $pcf->getTable() . ' as pcf ON ( ( ( pf.id IS NOT NULL AND pf.punch_control_id = pcf.id ) OR ( a.punch_control_id is NOT NULL AND a.punch_control_id = pcf.id ) ) AND pcf.deleted = 0) LEFT JOIN ' . $bf->getTable() . ' as bf ON pcf.branch_id = bf.id LEFT JOIN ' . $df->getTable() . ' as df ON pcf.department_id = df.id LEFT JOIN ' . $udf->getTable() . ' as b ON a.user_date_id = b.id LEFT JOIN ' . $uf->getTable() . ' as c ON b.user_id = c.id LEFT JOIN ' . $bf->getTable() . ' as d ON c.default_branch_id = d.id LEFT JOIN ' . $df->getTable() . ' as e ON c.default_department_id = e.id LEFT JOIN ' . $ugf->getTable() . ' as f ON c.group_id = f.id LEFT JOIN ' . $utf->getTable() . ' as g ON c.title_id = g.id LEFT JOIN ' . $ppf->getTable() . ' as h ON b.pay_period_id = h.id LEFT JOIN ' . $ppsf->getTable() . ' as ppsf ON ppsf.id = h.pay_period_schedule_id LEFT JOIN ' . $epf->getTable() . ' as i ON a.exception_policy_id = i.id LEFT JOIN ' . $epcf->getTable() . ' as epcf ON epcf.id = i.exception_policy_control_id LEFT JOIN ' . $pguf->getTable() . ' as pguf ON b.user_id = pguf.user_id LEFT JOIN ' . $pgf->getTable() . ' as pgf ON pguf.policy_group_id = pgf.id LEFT JOIN ' . $puf->getTable() . ' as puf ON c.id = puf.user_id LEFT JOIN ' . $pscf->getTable() . ' as pscf ON pscf.id = puf.permission_control_id 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 c.company_id = ? '; if (isset($filter_data['permission_children_ids']) and isset($filter_data['permission_children_ids'][0]) and !in_array(-1, (array) $filter_data['permission_children_ids'])) { $query .= ' AND c.id in (' . $this->getListSQL($filter_data['permission_children_ids'], $ph) . ') '; } if (isset($filter_data['id']) and isset($filter_data['id'][0]) and !in_array(-1, (array) $filter_data['id'])) { $query .= ' AND a.id in (' . $this->getListSQL($filter_data['id'], $ph) . ') '; } if (isset($filter_data['user_id']) and isset($filter_data['user_id'][0]) and !in_array(-1, (array) $filter_data['user_id'])) { $query .= ' AND c.id in (' . $this->getListSQL($filter_data['user_id'], $ph) . ') '; } $query .= isset($filter_data['exclude_user_id']) ? $this->getWhereClauseSQL('c.id', $filter_data['exclude_user_id'], 'not_numeric_list', $ph) : NULL; if (isset($filter_data['user_status_id']) and isset($filter_data['user_status_id'][0]) and !in_array(-1, (array) $filter_data['user_status_id'])) { $query .= ' AND c.status_id in (' . $this->getListSQL($filter_data['user_status_id'], $ph) . ') '; } if (isset($filter_data['type_id']) and isset($filter_data['type_id'][0]) and !in_array(-1, (array) $filter_data['type_id'])) { $query .= ' AND a.type_id in (' . $this->getListSQL($filter_data['type_id'], $ph) . ') '; } if (isset($filter_data['severity_id']) and isset($filter_data['severity_id'][0]) and !in_array(-1, (array) $filter_data['severity_id'])) { $query .= ' AND i.severity_id in (' . $this->getListSQL($filter_data['severity_id'], $ph) . ') '; } if (isset($filter_data['exception_policy_type_id']) and isset($filter_data['exception_policy_type_id'][0]) and !in_array(-1, (array) $filter_data['exception_policy_type_id'])) { $query .= ' AND i.type_id in (' . $this->getListSQL($filter_data['exception_policy_type_id'], $ph) . ') '; } if (isset($filter_data['pay_period_id']) and isset($filter_data['pay_period_id'][0]) and !in_array(-1, (array) $filter_data['pay_period_id'])) { $query .= ' AND b.pay_period_id in (' . $this->getListSQL($filter_data['pay_period_id'], $ph) . ') '; } if (isset($filter_data['pay_period_status_id']) and isset($filter_data['pay_period_status_id'][0]) and !in_array(-1, (array) $filter_data['pay_period_status_id'])) { $query .= ' AND h.status_id in (' . $this->getListSQL($filter_data['pay_period_status_id'], $ph) . ') '; } if (isset($filter_data['group_id']) and isset($filter_data['group_id'][0]) and !in_array(-1, (array) $filter_data['group_id'])) { if (isset($filter_data['include_subgroups']) and (bool) $filter_data['include_subgroups'] == TRUE) { $uglf = new UserGroupListFactory(); $filter_data['group_id'] = $uglf->getByCompanyIdAndGroupIdAndSubGroupsArray($company_id, $filter_data['group_id'], TRUE); } $query .= ' AND c.group_id in (' . $this->getListSQL($filter_data['group_id'], $ph) . ') '; } if (isset($filter_data['default_branch_id']) and isset($filter_data['default_branch_id'][0]) and !in_array(-1, (array) $filter_data['default_branch_id'])) { $query .= ' AND c.default_branch_id in (' . $this->getListSQL($filter_data['default_branch_id'], $ph) . ') '; } if (isset($filter_data['default_department_id']) and isset($filter_data['default_department_id'][0]) and !in_array(-1, (array) $filter_data['default_department_id'])) { $query .= ' AND c.default_department_id in (' . $this->getListSQL($filter_data['default_department_id'], $ph) . ') '; } if (isset($filter_data['title_id']) and isset($filter_data['title_id'][0]) and !in_array(-1, (array) $filter_data['title_id'])) { $query .= ' AND c.title_id in (' . $this->getListSQL($filter_data['title_id'], $ph) . ') '; } if (isset($filter_data['branch_id']) and isset($filter_data['branch_id'][0]) and !in_array(-1, (array) $filter_data['branch_id'])) { $query .= ' AND pcf.branch_id in (' . $this->getListSQL($filter_data['branch_id'], $ph) . ') '; } if (isset($filter_data['department_id']) and isset($filter_data['department_id'][0]) and !in_array(-1, (array) $filter_data['department_id'])) { $query .= ' AND pcf.department_id in (' . $this->getListSQL($filter_data['department_id'], $ph) . ') '; } if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') { $ph[] = $this->db->BindDate($filter_data['start_date']); $query .= ' AND b.date_stamp >= ?'; } if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $ph[] = $this->db->BindDate($filter_data['end_date']); $query .= ' AND b.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 accept exception rows assign to pay_period_id = 0 (no pay period), as this can happen when punches exist in the future. $query .= ' AND ( a.deleted = 0 AND b.deleted = 0 AND c.deleted = 0 AND pgf.deleted = 0 AND ( h.deleted = 0 OR h.deleted is NULL ) ) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); //Debug::Arr($ph, 'Query: '. $query, __FILE__, __LINE__, __METHOD__,10); $this->ExecuteSQL($query, $ph, $limit, $page); return $this; }
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; }