function createRecurringScheduleTemplate($company_id, $type, $schedule_policy_id = NULL) { $rstcf = new RecurringScheduleTemplateControlFactory(); $rstcf->setCompany($company_id); switch ($type) { case 10: //Morning Shift $rstcf->setName('Morning Shift'); $rstcf->setDescription('6:00AM - 3:00PM'); if ($rstcf->isValid()) { $rstc_id = $rstcf->Save(); Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10); //Week 1 $rstf = new RecurringScheduleTemplateFactory(); $rstf->setRecurringScheduleTemplateControl($rstc_id); $rstf->setWeek(1); $rstf->setSun(FALSE); $rstf->setMon(TRUE); $rstf->setTue(TRUE); $rstf->setWed(TRUE); $rstf->setThu(TRUE); $rstf->setFri(TRUE); $rstf->setSat(FALSE); $rstf->setStartTime(strtotime('06:00 AM')); $rstf->setEndTime(strtotime('03:00 PM')); if ($schedule_policy_id > 0) { $rstf->setSchedulePolicyID($schedule_policy_id); } $rstf->setBranch('-1'); //Default $rstf->setDepartment('-1'); //Default if ($rstf->isValid()) { Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10); $rstf->Save(); } return $rstc_id; } break; case 20: //Afternoon Shift $rstcf->setName('Afternoon Shift'); $rstcf->setDescription('10:00AM - 7:00PM'); if ($rstcf->isValid()) { $rstc_id = $rstcf->Save(); Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10); //Week 1 $rstf = new RecurringScheduleTemplateFactory(); $rstf->setRecurringScheduleTemplateControl($rstc_id); $rstf->setWeek(1); $rstf->setSun(FALSE); $rstf->setMon(TRUE); $rstf->setTue(TRUE); $rstf->setWed(TRUE); $rstf->setThu(TRUE); $rstf->setFri(TRUE); $rstf->setSat(FALSE); $rstf->setStartTime(strtotime('10:00 AM')); $rstf->setEndTime(strtotime('07:00 PM')); if ($schedule_policy_id > 0) { $rstf->setSchedulePolicyID($schedule_policy_id); } $rstf->setBranch('-1'); //Default $rstf->setDepartment('-1'); //Default if ($rstf->isValid()) { Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10); $rstf->Save(); } return $rstc_id; } break; case 30: //Evening Shift $rstcf->setName('Evening Shift'); $rstcf->setDescription('2:00PM - 11:00PM'); if ($rstcf->isValid()) { $rstc_id = $rstcf->Save(); Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10); //Week 1 $rstf = new RecurringScheduleTemplateFactory(); $rstf->setRecurringScheduleTemplateControl($rstc_id); $rstf->setWeek(1); $rstf->setSun(FALSE); $rstf->setMon(TRUE); $rstf->setTue(TRUE); $rstf->setWed(TRUE); $rstf->setThu(TRUE); $rstf->setFri(TRUE); $rstf->setSat(FALSE); $rstf->setStartTime(strtotime('02:00 PM')); $rstf->setEndTime(strtotime('11:00 PM')); if ($schedule_policy_id > 0) { $rstf->setSchedulePolicyID($schedule_policy_id); } $rstf->setBranch('-1'); //Default $rstf->setDepartment('-1'); //Default if ($rstf->isValid()) { Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10); $rstf->Save(); } return $rstc_id; } break; case 40: //Split Shift $rstcf->setName('Split Shift'); $rstcf->setDescription('8:00AM-12:00PM, 5:00PM-9:00PM '); if ($rstcf->isValid()) { $rstc_id = $rstcf->Save(); Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10); //Week 1 $rstf = new RecurringScheduleTemplateFactory(); $rstf->setRecurringScheduleTemplateControl($rstc_id); $rstf->setWeek(1); $rstf->setSun(FALSE); $rstf->setMon(TRUE); $rstf->setTue(TRUE); $rstf->setWed(TRUE); $rstf->setThu(TRUE); $rstf->setFri(TRUE); $rstf->setSat(FALSE); $rstf->setStartTime(strtotime('08:00 AM')); $rstf->setEndTime(strtotime('12:00 PM')); if ($schedule_policy_id > 0) { $rstf->setSchedulePolicyID($schedule_policy_id); } $rstf->setBranch('-1'); //Default $rstf->setDepartment('-1'); //Default if ($rstf->isValid()) { Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10); $rstf->Save(); } //Week 1 $rstf = new RecurringScheduleTemplateFactory(); $rstf->setRecurringScheduleTemplateControl($rstc_id); $rstf->setWeek(1); $rstf->setSun(FALSE); $rstf->setMon(TRUE); $rstf->setTue(TRUE); $rstf->setWed(TRUE); $rstf->setThu(TRUE); $rstf->setFri(TRUE); $rstf->setSat(FALSE); $rstf->setStartTime(strtotime('05:00 PM')); $rstf->setEndTime(strtotime('9:00 PM')); if ($schedule_policy_id > 0) { $rstf->setSchedulePolicyID($schedule_policy_id); } $rstf->setBranch('-1'); //Default $rstf->setDepartment('-1'); //Default if ($rstf->isValid()) { Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10); $rstf->Save(); } return $rstc_id; } break; case 50: //Full Rotation $rstcf->setName('Full Rotation'); $rstcf->setDescription('1wk-Morning, 1wk-Afternoon, 1wk-Evening'); if ($rstcf->isValid()) { $rstc_id = $rstcf->Save(); Debug::Text('bRecurring Schedule Template Control ID: ' . $rstc_id, __FILE__, __LINE__, __METHOD__, 10); //Week 1 $rstf = new RecurringScheduleTemplateFactory(); $rstf->setRecurringScheduleTemplateControl($rstc_id); $rstf->setWeek(1); $rstf->setSun(FALSE); $rstf->setMon(TRUE); $rstf->setTue(TRUE); $rstf->setWed(TRUE); $rstf->setThu(TRUE); $rstf->setFri(TRUE); $rstf->setSat(FALSE); $rstf->setStartTime(strtotime('06:00 AM')); $rstf->setEndTime(strtotime('03:00 PM')); if ($schedule_policy_id > 0) { $rstf->setSchedulePolicyID($schedule_policy_id); } $rstf->setBranch('-1'); //Default $rstf->setDepartment('-1'); //Default if ($rstf->isValid()) { Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10); $rstf->Save(); } //Week 2 $rstf = new RecurringScheduleTemplateFactory(); $rstf->setRecurringScheduleTemplateControl($rstc_id); $rstf->setWeek(2); $rstf->setSun(FALSE); $rstf->setMon(TRUE); $rstf->setTue(TRUE); $rstf->setWed(TRUE); $rstf->setThu(TRUE); $rstf->setFri(TRUE); $rstf->setSat(FALSE); $rstf->setStartTime(strtotime('10:00 AM')); $rstf->setEndTime(strtotime('07:00 PM')); if ($schedule_policy_id > 0) { $rstf->setSchedulePolicyID($schedule_policy_id); } $rstf->setBranch('-1'); //Default $rstf->setDepartment('-1'); //Default if ($rstf->isValid()) { Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10); $rstf->Save(); } //Week 3 $rstf = new RecurringScheduleTemplateFactory(); $rstf->setRecurringScheduleTemplateControl($rstc_id); $rstf->setWeek(3); $rstf->setSun(FALSE); $rstf->setMon(TRUE); $rstf->setTue(TRUE); $rstf->setWed(TRUE); $rstf->setThu(TRUE); $rstf->setFri(TRUE); $rstf->setSat(FALSE); $rstf->setStartTime(strtotime('02:00 PM')); $rstf->setEndTime(strtotime('11:00 PM')); if ($schedule_policy_id > 0) { $rstf->setSchedulePolicyID($schedule_policy_id); } $rstf->setBranch('-1'); //Default $rstf->setDepartment('-1'); //Default if ($rstf->isValid()) { Debug::Text('Saving Recurring Schedule Week...', __FILE__, __LINE__, __METHOD__, 10); $rstf->Save(); } return $rstc_id; } break; } Debug::Text('ERROR Saving schedule template!', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
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(); $sort_column_aliases = array(); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('week' => 'asc', 'sun' => 'asc', 'mon' => 'asc', 'tue' => 'asc', 'wed' => 'asc', 'thu' => 'asc', 'fri' => 'asc', 'sat' => 'asc', 'start_time' => 'asc', 'end_time' => 'asc'); $strict = FALSE; } else { //Always sort by last name,first name after other columns if (!isset($order['week'])) { $order['week'] = 'asc'; } if (!isset($order['start_time'])) { $order['start_time'] = 'asc'; } $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); $rstcf = new RecurringScheduleTemplateControlFactory(); $uf = new UserFactory(); $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 ' . $rstcf->getTable() . ' as b ON a.recurring_schedule_template_control_id = b.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 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['recurring_schedule_template_control_id']) and isset($filter_data['recurring_schedule_template_control_id'][0]) and !in_array(-1, (array) $filter_data['recurring_schedule_template_control_id'])) { $query .= ' AND a.recurring_schedule_template_control_id in (' . $this->getListSQL($filter_data['recurring_schedule_template_control_id'], $ph) . ') '; } $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 getSearchByCompanyIdAndArrayCriteria($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']); } } Debug::Arr($order, 'aOrder Data:', __FILE__, __LINE__, __METHOD__, 10); $additional_order_fields = array('name', 'description', 'last_name', 'template_id'); if ($order == NULL) { $order = array('last_name' => 'asc', 'd.id' => 'asc', 'a.start_date' => 'desc'); $strict = FALSE; } else { //Always try to order by status first so UNPAID employees go to the bottom. if (isset($order['last_name'])) { $order['d.last_name'] = $order['last_name']; unset($order['last_name']); } if (isset($order['first_name'])) { $order['d.first_name'] = $order['first_name']; unset($order['first_name']); } if (isset($order['template_id'])) { $order['b.id'] = $order['template_id']; unset($order['template_id']); } /* if ( isset($order['status']) ) { $order['status_id'] = $order['status']; unset($order['status']); } if ( isset($order['transaction_date']) ) { $order['last_name'] = 'asc'; } else { $order['transaction_date'] = 'desc'; } */ $strict = TRUE; } Debug::Arr($order, 'bOrder Data:', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($filter_data, 'Filter Data:', __FILE__, __LINE__, __METHOD__, 10); $uf = new UserFactory(); $rsuf = new RecurringScheduleUserFactory(); $rstcf = new RecurringScheduleTemplateControlFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, b.name as name, b.description as description, c.user_id as user_id, d.last_name as last_name from ' . $this->getTable() . ' as a LEFT JOIN ' . $rstcf->getTable() . ' as b ON a.recurring_schedule_template_control_id = b.id LEFT JOIN ' . $rsuf->getTable() . ' as c ON a.id = c.recurring_schedule_control_id LEFT JOIN ' . $uf->getTable() . ' as d ON c.user_id = d.id where a.company_id = ? '; 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['permission_children_ids']) and isset($filter_data['permission_children_ids'][0]) and !in_array(-1, (array) $filter_data['permission_children_ids'])) { $query .= ' AND d.id in (' . $this->getListSQL($filter_data['permission_children_ids'], $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 d.id in (' . $this->getListSQL($filter_data['user_id'], $ph) . ') '; } if (isset($filter_data['template_id']) and isset($filter_data['template_id'][0]) and !in_array(-1, (array) $filter_data['template_id'])) { $query .= ' AND b.id in (' . $this->getListSQL($filter_data['template_id'], $ph) . ') '; } if (isset($filter_data['status_id']) and isset($filter_data['status_id'][0]) and !in_array(-1, (array) $filter_data['status_id'])) { $query .= ' AND d.status_id in (' . $this->getListSQL($filter_data['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 d.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 d.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 d.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 d.title_id in (' . $this->getListSQL($filter_data['title_id'], $ph) . ') '; } if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') { $ph[] = $this->db->BindDate($filter_data['start_date']); $query .= ' AND a.start_date >= ?'; } if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $ph[] = $this->db->BindDate($filter_data['end_date']); $query .= ' AND a.start_date <= ?'; } $query .= ' AND (a.deleted = 0 AND b.deleted = 0 AND d.deleted=0) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); Debug::Text('Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10); if ($limit == NULL) { $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } return $this; }
function getAPIExpandedSearchByCompanyIdAndArrayCriteria($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']; unset($filter_data['user_status_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']); } } $additional_order_fields = array('first_name', 'last_name', 'title', 'user_group', 'default_branch', 'default_department', 'recurring_schedule_template_control', 'recurring_schedule_template_control_description'); if ($order == NULL) { $order = array('recurring_schedule_template_control_id' => 'asc'); $strict = FALSE; } else { //Always sort by last name,first name after other columns /* if ( !isset($order['effective_date']) ) { $order['effective_date'] = 'desc'; } */ $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); $uf = new UserFactory(); $bf = new BranchFactory(); $df = new DepartmentFactory(); $ugf = new UserGroupFactory(); $utf = new UserTitleFactory(); $rsuf = new RecurringScheduleUserFactory(); $rstcf = new RecurringScheduleTemplateControlFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, ac.user_id as user_id, ab.name as recurring_schedule_template_control, ab.description as recurring_schedule_template_control_description, 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 ' . $rstcf->getTable() . ' as ab ON ( a.recurring_schedule_template_control_id = ab.id ) LEFT JOIN ' . $rsuf->getTable() . ' as ac ON a.id = ac.recurring_schedule_control_id LEFT JOIN ' . $uf->getTable() . ' as b ON ( ac.user_id = b.id AND b.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 a.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 ac.user_id in (' . $this->getListSQL($filter_data['permission_children_ids'], $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 ac.user_id in (' . $this->getListSQL($filter_data['user_id'], $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 ac.user_id not in (' . $this->getListSQL($filter_data['exclude_id'], $ph) . ') '; } if (isset($filter_data['recurring_schedule_template_control_id']) and isset($filter_data['recurring_schedule_template_control_id'][0]) and !in_array(-1, (array) $filter_data['recurring_schedule_template_control_id'])) { $query .= ' AND a.recurring_schedule_template_control_id in (' . $this->getListSQL($filter_data['recurring_schedule_template_control_id'], $ph) . ') '; } if (isset($filter_data['status_id']) and isset($filter_data['status_id'][0]) and !in_array(-1, (array) $filter_data['status_id'])) { $query .= ' AND b.status_id in (' . $this->getListSQL($filter_data['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 b.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 b.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 b.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 b.title_id in (' . $this->getListSQL($filter_data['title_id'], $ph) . ') '; } if (isset($filter_data['country']) and isset($filter_data['country'][0]) and !in_array(-1, (array) $filter_data['country'])) { $query .= ' AND b.country in (' . $this->getListSQL($filter_data['country'], $ph) . ') '; } if (isset($filter_data['province']) and isset($filter_data['province'][0]) and !in_array(-1, (array) $filter_data['province']) and !in_array('00', (array) $filter_data['province'])) { $query .= ' AND b.province in (' . $this->getListSQL($filter_data['province'], $ph) . ') '; } $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 AND ab.deleted = 0 ) '; $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; }
/* * Get FORM variables */ extract(FormVariables::GetVariables(array('action', 'id', 'ids', 'data', 'week_rows'))); if (isset($week_rows)) { foreach ($week_rows as $week_row_id => $week_row) { Debug::Text('Start Time: ' . $week_row['start_time'], __FILE__, __LINE__, __METHOD__, 10); if (isset($week_row['start_time']) and $week_row['start_time'] != '') { $week_rows[$week_row_id]['start_time'] = TTDate::strtotime($week_row['start_time']); } if (isset($week_row['end_time']) and $week_row['end_time'] != '') { $week_rows[$week_row_id]['end_time'] = TTDate::strtotime($week_row['end_time']); } } } $rstcf = new RecurringScheduleTemplateControlFactory(); $rstf = new RecurringScheduleTemplateFactory(); $action = Misc::findSubmitButton(); $action = strtolower($action); switch ($action) { case 'submit': Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10); //Debug::setVerbosity(11); $redirect = 0; $rstcf->StartTransaction(); $rstcf->setId($data['id']); $rstcf->setCompany($current_company->getId()); $rstcf->setName($data['name']); $rstcf->setDescription($data['description']); if ($rstcf->isValid()) { $rstc_id = $rstcf->Save();
function getSearchByCompanyIdAndArrayCriteria($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']); } } Debug::Arr($order, 'aOrder Data:', __FILE__, __LINE__, __METHOD__, 10); $additional_order_fields = array('name', 'description', 'last_name'); if ($order == NULL) { $order = array('c.start_date' => 'asc', 'd.user_id' => 'asc', 'a.week' => 'asc'); $strict = FALSE; } else { $strict = TRUE; } if (isset($filter_data['exclude_user_ids'])) { $filter_data['exclude_id'] = $filter_data['exclude_user_ids']; } if (isset($filter_data['include_user_ids'])) { $filter_data['id'] = $filter_data['include_user_ids']; } if (isset($filter_data['user_status_ids'])) { $filter_data['status_id'] = $filter_data['user_status_ids']; } if (isset($filter_data['user_title_ids'])) { $filter_data['title_id'] = $filter_data['user_title_ids']; } if (isset($filter_data['group_ids'])) { $filter_data['group_id'] = $filter_data['group_ids']; } if (isset($filter_data['default_branch_ids'])) { $filter_data['default_branch_id'] = $filter_data['default_branch_ids']; } if (isset($filter_data['default_department_ids'])) { $filter_data['default_department_id'] = $filter_data['default_department_ids']; } if (isset($filter_data['schedule_branch_ids'])) { $filter_data['schedule_branch_id'] = $filter_data['schedule_branch_ids']; } if (isset($filter_data['schedule_department_ids'])) { $filter_data['schedule_department_id'] = $filter_data['schedule_department_ids']; } if (isset($filter_data['exclude_job_ids'])) { $filter_data['exclude_id'] = $filter_data['exclude_job_ids']; } if (isset($filter_data['include_job_ids'])) { $filter_data['include_job_id'] = $filter_data['include_job_ids']; } if (isset($filter_data['job_group_ids'])) { $filter_data['job_group_id'] = $filter_data['job_group_ids']; } if (isset($filter_data['job_item_ids'])) { $filter_data['job_item_id'] = $filter_data['job_item_ids']; } Debug::Arr($order, 'bOrder Data:', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($filter_data, 'Filter Data:', __FILE__, __LINE__, __METHOD__, 10); $uf = new UserFactory(); $rscf = new RecurringScheduleControlFactory(); $rsuf = new RecurringScheduleUserFactory(); $rstcf = new RecurringScheduleTemplateControlFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, d.user_id as user_id, e.first_name as first_name, e.last_name as last_name, e.created_by as user_created_by, CASE WHEN a.branch_id = -1 THEN e.default_branch_id ELSE a.branch_id END as schedule_branch_id, CASE WHEN a.department_id = -1 THEN e.default_department_id ELSE a.department_id END as schedule_department_id, c.start_date as recurring_schedule_control_start_date, c.end_date as recurring_schedule_control_end_date, c.start_week as recurring_schedule_control_start_week, y.max_week as max_week, ( (((a.week-1)+y.max_week-(c.start_week-1))%y.max_week) + 1) as remapped_week, e.hire_date as hire_date, e.termination_date as termination_date from ' . $this->getTable() . ' as a LEFT JOIN ( select z.recurring_schedule_template_control_id, max(z.week) as max_week from recurring_schedule_template as z where deleted = 0 group by z.recurring_schedule_template_control_id ) as y ON a.recurring_schedule_template_control_id = y.recurring_schedule_template_control_id LEFT JOIN ' . $rstcf->getTable() . ' as b ON a.recurring_schedule_template_control_id = b.id LEFT JOIN ' . $rscf->getTable() . ' as c ON a.recurring_schedule_template_control_id = c.recurring_schedule_template_control_id LEFT JOIN ' . $rsuf->getTable() . ' as d ON c.id = d.recurring_schedule_control_id LEFT JOIN ' . $uf->getTable() . ' as e ON d.user_id = e.id where b.company_id = ? '; if (isset($filter_data['id']) and isset($filter_data['id'][0]) and !in_array(-1, (array) $filter_data['id'])) { $query .= ' AND e.id in (' . $this->getListSQL($filter_data['id'], $ph) . ') '; } 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 e.id in (' . $this->getListSQL($filter_data['permission_children_ids'], $ph) . ') '; } if (isset($filter_data['status_id']) and isset($filter_data['status_id'][0]) and !in_array(-1, (array) $filter_data['status_id'])) { $query .= ' AND e.status_id in (' . $this->getListSQL($filter_data['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 e.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 e.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 e.default_department_id in (' . $this->getListSQL($filter_data['default_department_id'], $ph) . ') '; } if (isset($filter_data['schedule_branch_id']) and isset($filter_data['schedule_branch_id'][0]) and !in_array(-1, (array) $filter_data['schedule_branch_id'])) { $query .= ' AND ( a.branch_id in (' . $this->getListSQL($filter_data['schedule_branch_id'], $ph) . ') OR ( a.branch_id = -1 AND e.default_branch_id in (' . $this->getListSQL($filter_data['schedule_branch_id'], $ph) . ') ) )'; } if (isset($filter_data['schedule_department_id']) and isset($filter_data['schedule_department_id'][0]) and !in_array(-1, (array) $filter_data['schedule_department_id'])) { $query .= ' AND ( a.department_id in (' . $this->getListSQL($filter_data['schedule_department_id'], $ph) . ') OR ( a.department_id = -1 AND e.default_department_id in (' . $this->getListSQL($filter_data['schedule_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 e.title_id in (' . $this->getListSQL($filter_data['title_id'], $ph) . ') '; } if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '' and isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $start_date_stamp = $this->db->BindDate($filter_data['start_date']); $end_date_stamp = $this->db->BindDate($filter_data['end_date']); $ph[] = $start_date_stamp; $ph[] = $end_date_stamp; $ph[] = $start_date_stamp; $ph[] = $start_date_stamp; $ph[] = $end_date_stamp; $ph[] = $start_date_stamp; $ph[] = $end_date_stamp; $ph[] = $start_date_stamp; $ph[] = $end_date_stamp; $ph[] = $start_date_stamp; $ph[] = $end_date_stamp; $ph[] = $start_date_stamp; $ph[] = $end_date_stamp; $ph[] = $filter_data['end_date']; $ph[] = $filter_data['start_date']; $query .= ' AND ( (c.start_date >= ? AND c.start_date <= ? AND c.end_date IS NULL ) OR (c.start_date <= ? AND c.end_date IS NULL ) OR (c.start_date <= ? AND c.end_date >= ? ) OR (c.start_date >= ? AND c.end_date <= ? ) OR (c.start_date >= ? AND c.start_date <= ? ) OR (c.end_date >= ? AND c.end_date <= ? ) OR (c.start_date <= ? AND c.end_date >= ? ) ) AND ( ( e.hire_date is NULL OR e.hire_date <= ? ) AND ( e.termination_date is NULL OR e.termination_date >= ? ) ) '; } $query .= ' AND ( a.deleted = 0 AND b.deleted = 0 AND c.deleted = 0 AND e.deleted = 0 ) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); Debug::Text('Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10); if ($limit == NULL) { $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } return $this; }