function getByCompanyId($company_id, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } $uf = new UserFactory(); $ph = array('company_id' => $company_id); $query = ' select a.* from ' . $this->getTable() . ' as a LEFT JOIN ' . $uf->getTable() . ' as uf ON a.user_id = uf.id where uf.company_id = ? AND ( uf.deleted = 0 )'; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order); $this->ExecuteSQL($query, $ph); 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']); } } $additional_order_fields = array('status_id'); $sort_column_aliases = array('status' => 'status_id'); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('status_id' => 'asc', 'name' => 'asc'); $strict = FALSE; } else { //Always try to order by status first so INACTIVE employees go to the bottom. if (!isset($order['status_id'])) { $order = Misc::prependArray(array('status_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(); $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 ) 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['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['status_id']) and isset($filter_data['status_id'][0]) and !in_array(-1, (array) $filter_data['status_id'])) { $query .= ' AND a.status_id in (' . $this->getListSQL($filter_data['status_id'], $ph) . ') '; } if (isset($filter_data['name']) and trim($filter_data['name']) != '') { $ph[] = strtolower(trim($filter_data['name'])); $query .= ' AND lower(a.name) LIKE ?'; } if (isset($filter_data['country']) and isset($filter_data['country'][0]) and !in_array(-1, (array) $filter_data['country'])) { $query .= ' AND a.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 a.province in (' . $this->getListSQL($filter_data['province'], $ph) . ') '; } if (isset($filter_data['manual_id']) and trim($filter_data['manual_id']) != '') { $ph[] = $this->Validator->stripNonNumeric(trim($filter_data['manual_id'])); $query .= ' AND a.manual_id = ?'; } if (isset($filter_data['work_phone']) and trim($filter_data['work_phone']) != '') { $ph[] = strtolower(trim($filter_data['work_phone'])); $query .= ' AND a.work_phone LIKE ?'; } if (isset($filter_data['fax_phone']) and trim($filter_data['fax_phone']) != '') { $ph[] = strtolower(trim($filter_data['fax_phone'])); $query .= ' AND a.fax_phone LIKE ?'; } if (isset($filter_data['address1']) and trim($filter_data['address1']) != '') { $ph[] = strtolower(trim($filter_data['address1'])); $query .= ' AND lower(a.address1) LIKE ?'; } if (isset($filter_data['address2']) and trim($filter_data['address2']) != '') { $ph[] = strtolower(trim($filter_data['address2'])); $query .= ' AND lower(a.address2) LIKE ?'; } if (isset($filter_data['postal_code']) and trim($filter_data['postal_code']) != '') { $ph[] = strtolower(trim($filter_data['postal_code'])); $query .= ' AND lower(a.postal_code) LIKE ?'; } if (isset($filter_data['city']) and trim($filter_data['city']) != '') { $ph[] = strtolower(trim($filter_data['city'])); $query .= ' AND lower(a.city) LIKE ?'; } if (isset($filter_data['created_by']) and isset($filter_data['created_by'][0]) and !in_array(-1, (array) $filter_data['created_by'])) { $query .= ' AND a.created_by in (' . $this->getListSQL($filter_data['created_by'], $ph) . ') '; } if (isset($filter_data['updated_by']) and isset($filter_data['updated_by'][0]) and !in_array(-1, (array) $filter_data['updated_by'])) { $query .= ' AND a.updated_by in (' . $this->getListSQL($filter_data['updated_by'], $ph) . ') '; } $query .= ' AND a.deleted = 0 '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); if ($limit == NULL) { $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } return $this; }
function isUniqueValue($user_id, $type_id, $value) { $ph = array('user_id' => (int) $user_id, 'type_id' => (int) $type_id, 'value' => (string) $value); $uf = new UserFactory(); $query = 'select a.id from ' . $this->getTable() . ' as a, ' . $uf->getTable() . ' as b where a.user_id = b.id AND b.company_id = ( select z.company_id from ' . $uf->getTable() . ' as z where z.id = ? and z.deleted = 0 ) AND a.type_id = ? AND a.value = ? AND ( a.deleted = 0 AND b.deleted = 0 )'; $id = $this->db->GetOne($query, $ph); //Debug::Arr($id,'Unique Value: '. $value, __FILE__, __LINE__, __METHOD__,10); if ($id === FALSE) { return TRUE; } else { if ($id == $this->getId()) { return TRUE; } } return FALSE; }
function getAPILastWageSearchByCompanyIdAndArrayCriteria($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['effective_date'])) { $filter_data['effective_date'] = TTDate::getTime(); } 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']; } $additional_order_fields = array('wage_group'); if ($order == NULL) { $order = array('effective_date' => 'desc', 'wage_group_id' => 'asc', 'type_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(); $cf = new CurrencyFactory(); $wgf = new WageGroupFactory(); $ph = array('effective_date' => $this->db->BindTimeStamp($filter_data['effective_date']), 'company_id' => $company_id); /* $query = ' select a.* from '. $this->getTable() .' as a, ( select z.user_id, max(effective_date) as effective_date from '. $this->getTable() .' as z where z.effective_date <= ? AND z.wage_group_id = 0 AND z.user_id in ('. $this->getListSQL( $user_id, $ph ) .') AND ( z.deleted = 0 ) GROUP BY z.user_id ) as b, '. $uf->getTable() .' as c WHERE a.user_id = b.user_id AND a.effective_date = b.effective_date AND a.user_id = c.id AND ( c.deleted = 0 AND a.deleted = 0) '; */ $query = ' select a.*, CASE WHEN a.wage_group_id = 0 THEN \'' . TTi18n::getText('-Default-') . '\' ELSE ab.name END as wage_group, 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, g.id as currency_id, g.iso_code as iso_code, 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 ( select uwf.user_id as user_id, uwf.wage_group_id as wage_group_id, max(effective_date) as effective_date from ' . $this->getTable() . ' as uwf where uwf.effective_date <= ? AND uwf.deleted = 0 GROUP BY uwf.wage_group_id, uwf.user_id ) as uwf_b LEFT JOIN ' . $this->getTable() . ' as a ON ( a.user_id = uwf_b.user_id AND a.wage_group_id = uwf_b.wage_group_id AND a.effective_date = uwf_b.effective_date ) LEFT JOIN ' . $wgf->getTable() . ' as ab ON ( a.wage_group_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 ' . $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 ' . $cf->getTable() . ' as g ON ( b.currency_id = g.id AND g.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 = ? '; 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.user_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['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['user_id']) and isset($filter_data['user_id'][0]) and !in_array(-1, (array) $filter_data['user_id'])) { $query .= ' AND a.user_id in (' . $this->getListSQL($filter_data['user_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['wage_group_id']) and isset($filter_data['wage_group_id'][0]) and !in_array(-1, (array) $filter_data['wage_group_id'])) { $query .= ' AND a.wage_group_id in (' . $this->getListSQL($filter_data['wage_group_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 '; $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']); } } $additional_order_fields = array('status_id'); $sort_column_aliases = array('status' => 'status_id'); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('status_id' => 'asc', 'name' => 'asc'); $strict = FALSE; } else { //Always try to order by status first so INACTIVE employees go to the bottom. if (!isset($order['status_id'])) { $order = Misc::prependArray(array('status_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(); $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 ) where a.company_id = ?'; $query .= isset($filter_data['permission_children_ids']) ? $this->getWhereClauseSQL('a.created_by', $filter_data['permission_children_ids'], '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.id', $filter_data['exclude_id'], 'not_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['status_id']) ? $this->getWhereClauseSQL('a.status_id', $filter_data['status_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['name']) ? $this->getWhereClauseSQL('a.name', $filter_data['name'], 'text_metaphone', $ph) : NULL; $query .= isset($filter_data['country']) ? $this->getWhereClauseSQL('a.country', $filter_data['country'], 'upper_text_list', $ph) : NULL; $query .= isset($filter_data['province']) ? $this->getWhereClauseSQL('a.province', $filter_data['province'], 'upper_text_list', $ph) : NULL; $query .= isset($filter_data['city']) ? $this->getWhereClauseSQL('a.city', $filter_data['city'], 'text', $ph) : NULL; $query .= isset($filter_data['manual_id']) ? $this->getWhereClauseSQL('a.manual_id', $this->Validator->stripNon32bitInteger($filter_data['manual_id']), 'numeric', $ph) : NULL; $query .= isset($filter_data['work_phone']) ? $this->getWhereClauseSQL('a.work_phone', $filter_data['work_phone'], 'phone', $ph) : NULL; $query .= isset($filter_data['fax_phone']) ? $this->getWhereClauseSQL('a.work_phone', $filter_data['fax_phone'], 'phone', $ph) : NULL; $query .= isset($filter_data['address1']) ? $this->getWhereClauseSQL('a.address1', $filter_data['address1'], 'text', $ph) : NULL; $query .= isset($filter_data['address2']) ? $this->getWhereClauseSQL('a.address2', $filter_data['address2'], 'text', $ph) : NULL; $query .= isset($filter_data['postal_code']) ? $this->getWhereClauseSQL('a.postal_code', $filter_data['postal_code'], 'text', $ph) : NULL; $query .= isset($filter_data['tag']) ? $this->getWhereClauseSQL('a.id', array('company_id' => $company_id, 'object_type_id' => 110, 'tag' => $filter_data['tag']), 'tag', $ph) : NULL; $query .= isset($filter_data['created_date']) ? $this->getWhereClauseSQL('a.created_date', $filter_data['created_date'], 'date_range', $ph) : NULL; $query .= isset($filter_data['updated_date']) ? $this->getWhereClauseSQL('a.updated_date', $filter_data['updated_date'], 'date_range', $ph) : NULL; /* $query .= ( isset($filter_data['created_by']) AND is_array($filter_data['created_by']) ) ? $this->getWhereClauseSQL( 'a.created_by', $filter_data['created_by'], 'numeric_list', $ph ) : NULL; $query .= ( isset($filter_data['updated_by']) AND is_array($filter_data['updated_by']) ) ? $this->getWhereClauseSQL( 'a.updated_by', $filter_data['updated_by'], 'numeric_list', $ph ) : NULL; if ( isset($filter_data['created_by']) AND !is_array($filter_data['created_by']) AND trim($filter_data['created_by']) != '' ) { $ph[] = $ph[] = $this->handleSQLSyntax(strtolower(trim($filter_data['created_by']))); $query .= ' AND (lower(y.first_name) LIKE ? OR lower(y.last_name) LIKE ? ) '; } if ( isset($filter_data['updated_by']) AND !is_array($filter_data['updated_by']) AND trim($filter_data['updated_by']) != '' ) { $ph[] = $ph[] = $this->handleSQLSyntax(strtolower(trim($filter_data['updated_by']))); $query .= ' AND (lower(z.first_name) LIKE ? OR lower(z.last_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_date_total_type_id'])) { $filter_data['type_id'] = $filter_data['user_date_total_type_id']; } $additional_order_fields = array('first_name', 'last_name', 'date_stamp', 'time_stamp', 'type_id', 'status_id', 'branch', 'department', 'default_branch', 'default_department', 'group', 'title'); if ($order == NULL) { $order = array('c.date_stamp' => 'asc', 'a.status_id' => 'asc', 'a.type_id' => 'asc', 'a.total_time' => 'asc', 'a.status_id' => 'asc'); $strict = FALSE; } else { $strict = FALSE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); 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['user_id'] = $filter_data['include_user_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['branch_ids'])) { $filter_data['default_branch_id'] = $filter_data['branch_ids']; } if (isset($filter_data['department_ids'])) { $filter_data['default_department_id'] = $filter_data['department_ids']; } if (isset($filter_data['pay_period_ids'])) { $filter_data['pay_period_id'] = $filter_data['pay_period_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']; } $uf = new UserFactory(); $udf = new UserDateFactory(); $uwf = new UserWageFactory(); $bf = new BranchFactory(); $df = new DepartmentFactory(); $ugf = new UserGroupFactory(); $utf = new UserTitleFactory(); $otpf = new OverTimePolicyFactory(); $apf = new AbsencePolicyFactory(); $ppf = new PremiumPolicyFactory(); $mpf = new MealPolicyFactory(); $bpf = new BreakPolicyFactory(); if (getTTProductEdition() >= TT_PRODUCT_CORPORATE) { $jf = new JobFactory(); $jif = new JobItemFactory(); } $ph = array('company_id' => $company_id); $query = ' select a.id as id, a.user_date_id as user_date_id, a.type_id as type_id, a.status_id as status_id, a.punch_control_id as punch_control_id, a.over_time_policy_id as over_time_policy_id, otpf.name as over_time_policy, a.absence_policy_id as absence_policy_id, apf.name as absence_policy, apf.type_id as absence_policy_type_id, a.premium_policy_id as premium_policy_id, ppf.name as premium_policy, a.meal_policy_id as meal_policy_id, mpf.name as meal_policy, a.break_policy_id as break_policy_id, bpf.name as break_policy, a.start_time_stamp as start_time_stamp, a.end_time_stamp as end_time_stamp, a.override as override, a.branch_id as branch_id, j.name as branch, a.department_id as department_id, k.name as department, a.job_id as job_id, a.job_item_id as job_item_id, a.quantity as quantity, a.bad_quantity as bad_quantity, a.total_time as total_time, a.actual_total_time as actual_total_time, c.user_id as user_id, c.date_stamp as date_stamp, c.pay_period_id as pay_period_id, d.first_name as first_name, d.last_name as last_name, d.status_id as user_status_id, d.group_id as group_id, g.name as "group", d.title_id as title_id, h.name as title, d.default_branch_id as default_branch_id, e.name as default_branch, d.default_department_id as default_department_id, f.name as default_department, d.created_by as user_created_by, z.id as user_wage_id, z.effective_date as user_wage_effective_date '; if (getTTProductEdition() >= TT_PRODUCT_CORPORATE) { $query .= ', x.name as job, x.name as job_name, x.status_id as job_status_id, x.manual_id as job_manual_id, x.branch_id as job_branch_id, x.department_id as job_department_id, x.group_id as job_group_id, y.name as job_item'; } $query .= ' from ' . $this->getTable() . ' as a LEFT JOIN ' . $udf->getTable() . ' as c ON a.user_date_id = c.id LEFT JOIN ' . $uf->getTable() . ' as d ON c.user_id = d.id LEFT JOIN ' . $bf->getTable() . ' as e ON ( d.default_branch_id = e.id AND e.deleted = 0) LEFT JOIN ' . $df->getTable() . ' as f ON ( d.default_department_id = f.id AND f.deleted = 0) LEFT JOIN ' . $ugf->getTable() . ' as g ON ( d.group_id = g.id AND g.deleted = 0 ) LEFT JOIN ' . $utf->getTable() . ' as h ON ( d.title_id = h.id AND h.deleted = 0 ) LEFT JOIN ' . $bf->getTable() . ' as j ON ( a.branch_id = j.id AND j.deleted = 0) LEFT JOIN ' . $df->getTable() . ' as k ON ( a.department_id = k.id AND k.deleted = 0) LEFT JOIN ' . $otpf->getTable() . ' as otpf ON ( a.over_time_policy_id > 0 AND a.over_time_policy_id = otpf.id AND otpf.deleted = 0 ) LEFT JOIN ' . $apf->getTable() . ' as apf ON ( a.absence_policy_id > 0 AND a.absence_policy_id = apf.id AND apf.deleted = 0 ) LEFT JOIN ' . $ppf->getTable() . ' as ppf ON ( a.premium_policy_id > 0 AND a.premium_policy_id = ppf.id AND ppf.deleted = 0 ) LEFT JOIN ' . $mpf->getTable() . ' as mpf ON ( a.meal_policy_id > 0 AND a.meal_policy_id = mpf.id AND mpf.deleted = 0 ) LEFT JOIN ' . $bpf->getTable() . ' as bpf ON ( a.break_policy_id > 0 AND a.break_policy_id = bpf.id AND bpf.deleted = 0 ) LEFT JOIN ' . $uwf->getTable() . ' as z ON z.id = (select z.id from ' . $uwf->getTable() . ' as z where z.user_id = c.user_id and z.effective_date <= c.date_stamp and z.wage_group_id = 0 and z.deleted = 0 order by z.effective_date desc LiMiT 1) '; if (getTTProductEdition() >= TT_PRODUCT_CORPORATE) { $query .= ' LEFT JOIN ' . $jf->getTable() . ' as x ON a.job_id = x.id'; $query .= ' LEFT JOIN ' . $jif->getTable() . ' as y ON a.job_item_id = y.id'; } $query .= ' WHERE d.company_id = ?'; $query .= isset($filter_data['permission_children_ids']) ? $this->getWhereClauseSQL('d.id', $filter_data['permission_children_ids'], '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('d.id', $filter_data['exclude_id'], 'not_numeric_list', $ph) : NULL; $query .= isset($filter_data['user_id']) ? $this->getWhereClauseSQL('c.user_id', $filter_data['user_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['user_status_id']) ? $this->getWhereClauseSQL('d.status_id', $filter_data['user_status_id'], 'numeric_list', $ph) : NULL; if (isset($filter_data['include_subgroups']) and (bool) $filter_data['include_subgroups'] == TRUE) { $uglf = new UserGroupListFactory(); $filter_data['user_group_id'] = $uglf->getByCompanyIdAndGroupIdAndSubGroupsArray($company_id, $filter_data['user_group_id'], TRUE); } $query .= isset($filter_data['user_group_id']) ? $this->getWhereClauseSQL('d.group_id', $filter_data['user_group_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['user_group']) ? $this->getWhereClauseSQL('g.name', $filter_data['user_group'], 'text', $ph) : NULL; $query .= isset($filter_data['group_id']) ? $this->getWhereClauseSQL('d.group_id', $filter_data['group_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['default_branch_id']) ? $this->getWhereClauseSQL('d.default_branch_id', $filter_data['default_branch_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['default_department_id']) ? $this->getWhereClauseSQL('d.default_department_id', $filter_data['default_department_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['title_id']) ? $this->getWhereClauseSQL('d.title_id', $filter_data['title_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['status_id']) ? $this->getWhereClauseSQL('a.status_id', $filter_data['status_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['type_id']) ? $this->getWhereClauseSQL('a.type_id', $filter_data['type_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['pay_period_id']) ? $this->getWhereClauseSQL('c.pay_period_id', $filter_data['pay_period_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['branch_id']) ? $this->getWhereClauseSQL('a.branch_id', $filter_data['branch_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['department_id']) ? $this->getWhereClauseSQL('a.department_id', $filter_data['department_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['job_id']) ? $this->getWhereClauseSQL('a.job_id', $filter_data['job_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['include_job_id']) ? $this->getWhereClauseSQL('a.job_id', $filter_data['include_job_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['exclude_job_id']) ? $this->getWhereClauseSQL('a.job_id', $filter_data['exclude_job_id'], 'not_numeric_list', $ph) : NULL; $query .= isset($filter_data['job_group_id']) ? $this->getWhereClauseSQL('x.group_id', $filter_data['job_group_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['job_item_id']) ? $this->getWhereClauseSQL('a.job_item_id', $filter_data['job_item_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['include_job_item_id']) ? $this->getWhereClauseSQL('a.job_item_id', $filter_data['include_job_item_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['exclude_job_item_id']) ? $this->getWhereClauseSQL('a.job_item_id', $filter_data['exclude_job_item_id'], 'not_numeric_list', $ph) : NULL; /* 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['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 d.id not in ('. $this->getListSQL($filter_data['exclude_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.user_id in ('. $this->getListSQL($filter_data['user_id'], $ph) .') '; } 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 d.status_id in ('. $this->getListSQL($filter_data['user_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['branch_id']) AND isset($filter_data['branch_id'][0]) AND !in_array(-1, (array)$filter_data['branch_id']) ) { $query .= ' AND a.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 a.department_id in ('. $this->getListSQL($filter_data['department_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 a.status_id in ('. $this->getListSQL($filter_data['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['pay_period_id']) AND isset($filter_data['pay_period_id'][0]) AND !in_array(-1, (array)$filter_data['pay_period_id']) ) { $query .= ' AND c.pay_period_id in ('. $this->getListSQL($filter_data['pay_period_id'], $ph) .') '; } //Use the job_id in the punch_control table so we can filter by '0' or No Job if ( isset($filter_data['include_job_id']) AND isset($filter_data['include_job_id'][0]) AND !in_array(-1, (array)$filter_data['include_job_id']) ) { $query .= ' AND a.job_id in ('. $this->getListSQL($filter_data['include_job_id'], $ph) .') '; } if ( isset($filter_data['exclude_job_id']) AND isset($filter_data['exclude_job_id'][0]) AND !in_array(-1, (array)$filter_data['exclude_job_id']) ) { $query .= ' AND a.job_id not in ('. $this->getListSQL($filter_data['exclude_job_id'], $ph) .') '; } if ( isset($filter_data['job_group_id']) AND isset($filter_data['job_group_id'][0]) AND !in_array(-1, (array)$filter_data['job_group_id']) ) { if ( isset($filter_data['include_job_subgroups']) AND (bool)$filter_data['include_job_subgroups'] == TRUE ) { $uglf = new UserGroupListFactory(); $filter_data['job_group_id'] = $uglf->getByCompanyIdAndGroupIdAndjob_subgroupsArray( $company_id, $filter_data['job_group_id'], TRUE); } $query .= ' AND x.group_id in ('. $this->getListSQL($filter_data['job_group_id'], $ph) .') '; } if ( isset($filter_data['job_item_id']) AND isset($filter_data['job_item_id'][0]) AND !in_array(-1, (array)$filter_data['job_item_id']) ) { $query .= ' AND a.job_item_id in ('. $this->getListSQL($filter_data['job_item_id'], $ph) .') '; } */ if (isset($filter_data['date']) and trim($filter_data['date']) != '') { $ph[] = $this->db->BindDate($filter_data['date']); $query .= ' AND c.date_stamp = ?'; } if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') { $ph[] = $this->db->BindDate($filter_data['start_date']); $query .= ' AND c.date_stamp >= ?'; } if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $ph[] = $this->db->BindDate($filter_data['end_date']); $query .= ' AND c.date_stamp <= ?'; } $query .= ' AND (a.deleted = 0 AND c.deleted = 0 AND d.deleted = 0) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); $this->ExecuteSQL($query, $ph, $limit, $page); //Debug::Arr($ph, 'Query: '. $query, __FILE__, __LINE__, __METHOD__,10); return $this; }
function getAPISearchByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } if (isset($filter_data['qualification_group_id'])) { $filter_data['group_id'] = $filter_data['qualification_group_id']; } if (isset($filter_data['qualification_type_id'])) { $filter_data['type_id'] = $filter_data['qualification_type_id']; } if (isset($filter_data['qualification_id'])) { $filter_data['id'] = $filter_data['qualification_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('type_id', 'group'); $sort_column_aliases = array('type' => 'type_id', 'group' => 'd.name'); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('type_id' => 'asc', 'name' => 'asc'); $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(); $qgf = new QualificationGroupFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, d.name as "group", 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 ' . $qgf->getTable() . ' as d ON ( a.group_id = d.id AND d.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 = ?'; $query .= isset($filter_data['permission_children_ids']) ? $this->getWhereClauseSQL('a.created_by', $filter_data['permission_children_ids'], '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.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; $query .= isset($filter_data['name']) ? $this->getWhereClauseSQL('a.name', $filter_data['name'], 'text_metaphone', $ph) : NULL; $query .= isset($filter_data['description']) ? $this->getWhereClauseSQL('a.description', $filter_data['description'], 'text', $ph) : NULL; $query .= isset($filter_data['group_id']) ? $this->getWhereClauseSQL('a.group_id', $filter_data['group_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['group']) ? $this->getWhereClauseSQL('d.name', $filter_data['group'], 'text', $ph) : NULL; $query .= isset($filter_data['tag']) ? $this->getWhereClauseSQL('a.id', array('company_id' => $company_id, 'object_type_id' => 250, 'tag' => $filter_data['tag']), 'tag', $ph) : NULL; if (isset($filter_data['created_date']) and trim($filter_data['created_date']) != '') { $date_filter = $this->getDateRangeSQL($filter_data['created_date'], 'a.created_date'); if ($date_filter != FALSE) { $query .= ' AND ' . $date_filter; } unset($date_filter); } if (isset($filter_data['updated_date']) and trim($filter_data['updated_date']) != '') { $date_filter = $this->getDateRangeSQL($filter_data['updated_date'], 'a.updated_date'); if ($date_filter != FALSE) { $query .= ' AND ' . $date_filter; } unset($date_filter); } $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); //Debug::Arr( $ph, 'Query: '.$query, __FILE__, __LINE__, __METHOD__, 10 ); $this->ExecuteSQL($query, $ph, $limit, $page); return $this; }
function getDaysWorkedByTimePeriodAndUserIdAndCompanyIdAndStartDateAndEndDate($time_period, $user_ids, $company_id, $start_date, $end_date, $where = NULL, $order = NULL) { if ($time_period == '') { return FALSE; } if ($user_ids == '') { return FALSE; } if ($company_id == '') { return FALSE; } if ($start_date == '') { return FALSE; } if ($end_date == '') { return FALSE; } /* if ( $order == NULL ) { $order = array( 'date_stamp' => 'asc' ); $strict = FALSE; } else { $strict = TRUE; } */ $uf = new UserFactory(); $pcf = new PunchControlFactory(); $ph = array('company_id' => $company_id, 'start_date' => $this->db->BindDate($start_date), 'end_date' => $this->db->BindDate($end_date)); $query = ' select user_id, avg(total) as avg, min(total) as min, max(total) as max from ( select a.user_id, (EXTRACT(' . $time_period . ' FROM a.date_stamp) || \'-\' || EXTRACT(year FROM a.date_stamp) ) as date, count(*) as total from ' . $this->getTable() . ' as a, ' . $uf->getTable() . ' as b where a.user_id = b.id AND b.company_id = ? AND a.date_stamp >= ? AND a.date_stamp <= ? AND a.user_id in (' . $this->getListSQL($user_ids, $ph) . ') AND exists( select id from ' . $pcf->getTable() . ' as z where z.user_date_id = a.id AND z.deleted=0 ) AND ( a.deleted = 0 AND b.deleted=0 ) GROUP BY user_id,(EXTRACT(' . $time_period . ' FROM a.date_stamp) || \'-\' || EXTRACT(year FROM a.date_stamp) ) ) tmp GROUP BY user_id '; /* $query = ' select user_id, avg(total) as avg, min(total) as min, max(total) as max from ( select a.user_id, (date_part(\''.$time_period.'\', a.date_stamp) || \'-\' || date_part(\'year\', a.date_stamp) ) as date, count(*) as total from '. $this->getTable() .' as a, '. $uf->getTable() .' as b where a.user_id = b.id AND b.company_id = ? AND a.date_stamp >= ? AND a.date_stamp <= ? AND a.user_id in ('. $this->getListSQL($user_ids, $ph) .') AND exists( select id from '. $pcf->getTable() .' as z where z.user_date_id = a.id AND z.deleted=0 ) AND ( a.deleted = 0 AND b.deleted=0 ) GROUP BY user_id,(date_part(\''. $time_period.'\', a.date_stamp) || \'-\' || date_part(\'year\', a.date_stamp) ) ) tmp GROUP BY user_id '; */ //$query .= $this->getWhereSQL( $where ); //$query .= $this->getSortSQL( $order ); $this->rs = $this->db->Execute($query, $ph); return $this; }
function getAPISearchByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } if (isset($filter_data['roe_id'])) { $filter_data['id'] = $filter_data['roe_id']; unset($filter_data['roe_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('uf.first_name', 'uf.last_name', 'code_id', 'pay_period_type_id'); $sort_column_aliases = array('code' => 'code_id', 'pay_period_type' => 'pay_period_type_id'); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('last_date' => 'desc'); //Order ROEs by last date for which paid. $strict = FALSE; } else { if (isset($order['first_name'])) { $order['uf.first_name'] = $order['first_name']; unset($order['first_name']); } if (isset($order['last_name'])) { $order['uf.last_name'] = $order['last_name']; unset($order['last_name']); } $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); $uf = new UserFactory(); //$ppsf = new PayPeriodScheduleFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, uf.first_name as first_name, uf.last_name as last_name, 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 uf ON ( a.user_id = uf.id AND uf.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 uf.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['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['code']) and trim($filter_data['code']) != '' and !isset($filter_data['code_id'])) { $filter_data['code_id'] = Option::getByFuzzyValue($filter_data['code'], $this->getOptions('code')); } $query .= isset($filter_data['first_name']) ? $this->getWhereClauseSQL('uf.first_name', $filter_data['first_name'], 'text_metaphone', $ph) : NULL; $query .= isset($filter_data['last_name']) ? $this->getWhereClauseSQL('uf.last_name', $filter_data['last_name'], 'text_metaphone', $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['code_id']) ? $this->getWhereClauseSQL('a.code_id', $filter_data['code_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['pay_period_type_id']) ? $this->getWhereClauseSQL('a.pay_period_type_id', $filter_data['pay_period_type_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['first_date']) ? $this->getWhereClauseSQL('a.first_date', $filter_data['first_date'], 'date_range', $ph) : NULL; $query .= isset($filter_data['last_date']) ? $this->getWhereClauseSQL('a.last_date', $filter_data['last_date'], 'date_range', $ph) : NULL; $query .= isset($filter_data['pay_period_end_date']) ? $this->getWhereClauseSQL('a.pay_period_end_date', $filter_data['pay_period_end_date'], 'date_range', $ph) : NULL; $query .= isset($filter_data['recall_date']) ? $this->getWhereClauseSQL('a.recall_date', $filter_data['recall_date'], 'date_range', $ph) : NULL; $query .= isset($filter_data['serial']) ? $this->getWhereClauseSQL('a.serial', $filter_data['serial'], 'text', $ph) : NULL; $query .= isset($filter_data['comments']) ? $this->getWhereClauseSQL('a.comments', $filter_data['comments'], 'text', $ph) : NULL; if (isset($filter_data['created_by']) and isset($filter_data['created_by'][0]) and !in_array(-1, (array) $filter_data['created_by'])) { $query .= ' AND a.created_by in (' . $this->getListSQL($filter_data['created_by'], $ph) . ') '; } if (isset($filter_data['updated_by']) and isset($filter_data['updated_by'][0]) and !in_array(-1, (array) $filter_data['updated_by'])) { $query .= ' AND a.updated_by in (' . $this->getListSQL($filter_data['updated_by'], $ph) . ') '; } $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 getLastPunchByCompanyIdAndArrayCriteria($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('b.name', 'c.name', 'd.name', 'e.name'); $additional_order_fields = array('b.branch_id', 'c.date_stamp', 'd.last_name', 'a.time_stamp', 'a.status_id', 'b.branch_id', 'b.department_id', 'e.type_id'); if ($order == NULL) { $order = array('b.branch_id' => 'asc', 'd.last_name' => 'asc', 'a.time_stamp' => 'desc', 'a.punch_control_id' => 'asc', 'a.status_id' => 'asc'); $strict = FALSE; } else { $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); 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['branch_ids'])) { $filter_data['default_branch_id'] = $filter_data['branch_ids']; } if (isset($filter_data['department_ids'])) { $filter_data['default_department_id'] = $filter_data['department_ids']; } if (isset($filter_data['punch_branch_ids'])) { $filter_data['punch_branch_id'] = $filter_data['punch_branch_ids']; } if (isset($filter_data['punch_department_ids'])) { $filter_data['punch_department_id'] = $filter_data['punch_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']; } $uf = new UserFactory(); $udf = new UserDateFactory(); $pcf = new PunchControlFactory(); $sf = new StationFactory(); if (getTTProductEdition() >= TT_PRODUCT_CORPORATE) { $jf = new JobFactory(); $jif = new JobItemFactory(); } $ph = array('company_id' => $company_id); $query = ' select a.id as punch_id, a.punch_control_id as punch_control_id, a.type_id as type_id, a.status_id as status_id, a.time_stamp as time_stamp, a.actual_time_stamp as actual_time_stamp, b.user_date_id as user_date_id, c.date_stamp as date_stamp, b.branch_id as branch_id, b.department_id as department_id, b.job_id as job_id, b.job_item_id as job_item_id, b.note as note, c.user_id as user_id, e.type_id as station_type_id, e.station_id as station_station_id, e.source as station_source, e.description as station_description from ' . $this->getTable() . ' as a LEFT JOIN ' . $pcf->getTable() . ' as b ON a.punch_control_id = b.id LEFT JOIN ' . $udf->getTable() . ' as c ON b.user_date_id = c.id LEFT JOIN ' . $uf->getTable() . ' as d ON c.user_id = d.id LEFT JOIN ' . $sf->getTable() . ' as e ON a.station_id = e.id LEFT JOIN ( select tmp2_d.id, max(tmp2_a.time_stamp) as max_punch_time_stamp from ' . $this->getTable() . ' as tmp2_a LEFT JOIN ' . $pcf->getTable() . ' as tmp2_b ON tmp2_a.punch_control_id = tmp2_b.id LEFT JOIN ' . $udf->getTable() . ' as tmp2_c ON tmp2_b.user_date_id = tmp2_c.id LEFT JOIN ' . $uf->getTable() . ' as tmp2_d ON tmp2_c.user_id = tmp2_d.id WHERE tmp2_d.company_id = ?'; if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') { $ph[] = $this->db->BindDate($filter_data['start_date']); $query .= ' AND tmp2_c.date_stamp >= ?'; } if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $ph[] = $this->db->BindDate($filter_data['end_date']); $query .= ' AND tmp2_c.date_stamp <= ?'; } $query .= ' AND tmp2_a.time_stamp is not null AND ( tmp2_a.deleted = 0 AND tmp2_b.deleted = 0 AND tmp2_c.deleted = 0 ) group by tmp2_d.id ) as tmp2 ON c.user_id = tmp2.id AND a.time_stamp = tmp2.max_punch_time_stamp '; if (getTTProductEdition() >= TT_PRODUCT_CORPORATE) { $query .= ' LEFT JOIN ' . $jf->getTable() . ' as x ON b.job_id = x.id'; $query .= ' LEFT JOIN ' . $jif->getTable() . ' as y ON b.job_item_id = y.id'; } $ph[] = $company_id; $query .= ' WHERE tmp2.id IS NOT NULL AND d.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 d.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 d.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 d.id not in (' . $this->getListSQL($filter_data['exclude_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['punch_branch_id']) and isset($filter_data['punch_branch_id'][0]) and !in_array(-1, (array) $filter_data['punch_branch_id'])) { $query .= ' AND b.branch_id in (' . $this->getListSQL($filter_data['punch_branch_id'], $ph) . ') '; } if (isset($filter_data['punch_department_id']) and isset($filter_data['punch_department_id'][0]) and !in_array(-1, (array) $filter_data['punch_department_id'])) { $query .= ' AND b.department_id in (' . $this->getListSQL($filter_data['punch_department_id'], $ph) . ') '; } //Use the job_id in the punch_control table so we can filter by '0' or No Job if (isset($filter_data['include_job_id']) and isset($filter_data['include_job_id'][0]) and !in_array(-1, (array) $filter_data['include_job_id'])) { $query .= ' AND b.job_id in (' . $this->getListSQL($filter_data['include_job_id'], $ph) . ') '; } if (isset($filter_data['exclude_job_id']) and isset($filter_data['exclude_job_id'][0]) and !in_array(-1, (array) $filter_data['exclude_job_id'])) { $query .= ' AND b.job_id not in (' . $this->getListSQL($filter_data['exclude_job_id'], $ph) . ') '; } if (isset($filter_data['job_group_id']) and isset($filter_data['job_group_id'][0]) and !in_array(-1, (array) $filter_data['job_group_id'])) { if (isset($filter_data['include_job_subgroups']) and (bool) $filter_data['include_job_subgroups'] == TRUE) { $uglf = new UserGroupListFactory(); $filter_data['job_group_id'] = $uglf->getByCompanyIdAndGroupIdAndjob_subgroupsArray($company_id, $filter_data['job_group_id'], TRUE); } $query .= ' AND x.group_id in (' . $this->getListSQL($filter_data['job_group_id'], $ph) . ') '; } if (isset($filter_data['job_item_id']) and isset($filter_data['job_item_id'][0]) and !in_array(-1, (array) $filter_data['job_item_id'])) { $query .= ' AND b.job_item_id in (' . $this->getListSQL($filter_data['job_item_id'], $ph) . ') '; } if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') { /* $ph[] = $this->db->BindDate($filter_data['start_date']); $query .= ' AND c.date_stamp >= ?'; */ $ph[] = $this->db->BindTimeStamp($filter_data['start_date']); $query .= ' AND a.time_stamp >= ?'; } if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $ph[] = $this->db->BindTimeStamp($filter_data['end_date']); $query .= ' AND a.time_stamp <= ?'; } //The Transfer where clause is an attempt to keep transferred punches from appearing twice. $query .= ' AND ( a.transfer = 0 OR ( a.transfer = 1 AND a.status_id = 10) ) AND ( a.deleted = 0 AND b.deleted =0 AND c.deleted = 0 AND d.deleted = 0 ) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); $this->ExecuteSQL($query, $ph, $limit, $page); return $this; }
function getUniqueCountryByCompanyId($id, $where = NULL, $order = NULL) { if ($id == '') { return FALSE; } $uf = new UserFactory(); $ph = array('id' => $id); $query = ' select distinct a.country from ' . $uf->getTable() . ' as a where a.company_id = ? AND ( a.deleted = 0 )'; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order); return $this->db->GetCol($query, $ph); }
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(); if ($order == NULL) { $order = array('name' => 'asc'); $strict = FALSE; } else { //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(); $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 ) where a.company_id = ? '; $query .= isset($filter_data['permission_children_ids']) ? $this->getWhereClauseSQL('a.created_by', $filter_data['permission_children_ids'], 'numeric_list', $ph) : NULL; //Use this method instead of the method below. $query .= isset($filter_data['id']) ? $this->getWhereClauseSQL('a.id', $filter_data['id'], 'numeric_list', $ph) : NULL; //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) .') '; //} $query .= isset($filter_data['exclude_id']) ? $this->getWhereClauseSQL('a.id', $filter_data['exclude_id'], 'not_numeric_list', $ph) : NULL; $query .= isset($filter_data['name']) ? $this->getWhereClauseSQL('a.name', $filter_data['name'], 'text', $ph) : NULL; if (isset($filter_data['created_date']) and trim($filter_data['created_date']) != '') { $date_filter = $this->getDateRangeSQL($filter_data['created_date'], 'a.created_date'); if ($date_filter != FALSE) { $query .= ' AND ' . $date_filter; } unset($date_filter); } if (isset($filter_data['updated_date']) and trim($filter_data['updated_date']) != '') { $date_filter = $this->getDateRangeSQL($filter_data['updated_date'], 'a.updated_date'); if ($date_filter != FALSE) { $query .= ' AND ' . $date_filter; } unset($date_filter); } $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 (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['qualification_group_id'])) { $filter_data['group_id'] = $filter_data['qualification_group_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('uf.first_name', 'uf.last_name', 'qf.name', 'qgf.name', 'df.name', 'bf.name', 'ugf.name', 'utf.name'); $sort_column_aliases = array(); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('qf.name' => 'asc', 'qgf.name' => 'asc'); $strict = FALSE; } else { if (isset($order['first_name'])) { $order['uf.first_name'] = $order['first_name']; unset($order['first_name']); } if (isset($order['last_name'])) { $order['uf.last_name'] = $order['last_name']; unset($order['last_name']); } if (isset($order['qualification'])) { $order['qf.name'] = $order['qualification']; unset($order['qualification']); } if (isset($order['group'])) { $order['qgf.name'] = $order['group']; unset($order['group']); } if (isset($order['default_department'])) { $order['df.name'] = $order['default_department']; unset($order['default_department']); } if (isset($order['default_branch'])) { $order['bf.name'] = $order['default_branch']; unset($order['default_branch']); } if (isset($order['user_group'])) { $order['ugf.name'] = $order['user_group']; unset($order['user_group']); } if (isset($order['title'])) { $order['utf.name'] = $order['title']; unset($order['title']); } $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(); $qf = new QualificationFactory(); $usf = new UserSkillFactory(); $ulf = new UserLanguageFactory(); $umf = new UserMembershipFactory(); $qgf = new QualificationGroupFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, uf.first_name as first_name, uf.last_name as last_name, qf.name as qualification, qgf.name as "group", bf.id as default_branch_id, bf.name as default_branch, df.id as default_department_id, df.name as default_department, ugf.id as user_group_id, ugf.name as user_group, utf.id as user_title_id, utf.name as title, 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 uf ON ( a.user_id = uf.id AND uf.deleted = 0) LEFT JOIN ' . $usf->getTable() . ' as usf ON ( a.qualification_id = usf.qualification_id AND usf.deleted = 0) LEFT JOIN ' . $ulf->getTable() . ' as ulf ON ( a.qualification_id = ulf.qualification_id AND ulf.deleted =0 ) LEFT JOIN ' . $umf->getTable() . ' as umf ON ( a.qualification_id = umf.qualification_id AND umf.deleted = 0 ) LEFT JOIN ' . $qf->getTable() . ' as qf ON ( a.qualification_id = qf.id AND qf.deleted = 0 ) LEFT JOIN ' . $bf->getTable() . ' as bf ON ( uf.default_branch_id = bf.id AND bf.deleted = 0) LEFT JOIN ' . $df->getTable() . ' as df ON ( uf.default_department_id = df.id AND df.deleted = 0) LEFT JOIN ' . $ugf->getTable() . ' as ugf ON ( uf.group_id = ugf.id AND ugf.deleted = 0 ) LEFT JOIN ' . $utf->getTable() . ' as utf ON ( uf.title_id = utf.id AND utf.deleted = 0 ) LEFT JOIN ' . $qgf->getTable() . ' as qgf ON ( qf.group_id = qgf.id AND qgf.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 qf.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; $query .= isset($filter_data['qualification_id']) ? $this->getWhereClauseSQL('a.qualification_id', $filter_data['qualification_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['qualification']) ? $this->getWhereClauseSQL('qf.name', $filter_data['qualification'], 'text', $ph) : NULL; $query .= isset($filter_data['proficiency_id']) ? $this->getWhereClauseSQL('usf.proficiency_id', $filter_data['proficiency_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['fluency_id']) ? $this->getWhereClauseSQL('ulf.fluency_id', $filter_data['fluency_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['competency_id']) ? $this->getWhereClauseSQL('ulf.competency_id', $filter_data['competency_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['ownership_id']) ? $this->getWhereClauseSQL('umf.ownership_id', $filter_data['ownership_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['institute']) ? $this->getWhereClauseSQL('a.institute', $filter_data['institute'], 'text', $ph) : NULL; $query .= isset($filter_data['major']) ? $this->getWhereClauseSQL('a.major', $filter_data['major'], 'text', $ph) : NULL; $query .= isset($filter_data['minor']) ? $this->getWhereClauseSQL('a.minor', $filter_data['minor'], 'text', $ph) : NULL; $query .= isset($filter_data['grade_score']) ? $this->getWhereClauseSQL('a.grade_score', $filter_data['grade_score'], 'numeric', $ph) : NULL; $query .= isset($filter_data['group_id']) ? $this->getWhereClauseSQL('qf.group_id', $filter_data['group_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['group']) ? $this->getWhereClauseSQL('qgf.name', $filter_data['group'], 'text', $ph) : NULL; $query .= isset($filter_data['qualification_type_id']) ? $this->getWhereClauseSQL('qf.type_id', $filter_data['qualification_type_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['default_branch_id']) ? $this->getWhereClauseSQL('uf.default_branch_id', $filter_data['default_branch_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['default_department_id']) ? $this->getWhereClauseSQL('uf.default_department_id', $filter_data['default_department_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['tag']) ? $this->getWhereClauseSQL('a.id', array('company_id' => $company_id, 'object_type_id' => 252, 'tag' => $filter_data['tag']), 'tag', $ph) : NULL; $query .= isset($filter_data['start_date']) ? $this->getWhereClauseSQL('a.start_date', $filter_data['start_date'], 'date_range', $ph) : NULL; $query .= isset($filter_data['end_date']) ? $this->getWhereClauseSQL('a.end_date', $filter_data['end_date'], 'date_range', $ph) : NULL; $query .= isset($filter_data['graduate_date']) ? $this->getWhereClauseSQL('a.graduate_date', $filter_data['graduate_date'], 'date_range', $ph) : NULL; if (isset($filter_data['created_date']) and trim($filter_data['created_date']) != '') { $date_filter = $this->getDateRangeSQL($filter_data['created_date'], 'a.created_date'); if ($date_filter != FALSE) { $query .= ' AND ' . $date_filter; } unset($date_filter); } if (isset($filter_data['updated_date']) and trim($filter_data['updated_date']) != '') { $date_filter = $this->getDateRangeSQL($filter_data['updated_date'], 'a.updated_date'); if ($date_filter != FALSE) { $query .= ' AND ' . $date_filter; } unset($date_filter); } $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']); } } $additional_order_fields = array('action_id', 'object_id', 'last_name', 'first_name'); $sort_column_aliases = array('action' => 'action_id', 'object' => 'table_name'); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('date' => 'desc', 'table_name' => 'asc', 'object_id' => 'asc'); $strict = FALSE; } else { //Always try to order by status first so INACTIVE employees go to the bottom. if (!isset($order['date'])) { $order['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(); $ph = array('company_id' => $company_id); $query = ' select a.*, uf.first_name as first_name, uf.middle_name as middle_name, uf.last_name as last_name from ' . $this->getTable() . ' as a LEFT JOIN ' . $uf->getTable() . ' as uf ON ( a.user_id = uf.id AND uf.deleted = 0 ) where uf.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.user_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['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['user_id']) and isset($filter_data['user_id'][0]) and !in_array(-1, (array) $filter_data['user_id'])) { $query .= ' AND a.user_id in (' . $this->getListSQL($filter_data['user_id'], $ph) . ') '; } if (isset($filter_data['action']) and trim($filter_data['action']) != '' and !isset($filter_data['action_id'])) { $filter_data['action_id'] = Option::getByFuzzyValue($filter_data['action'], $this->getOptions('action')); } if (isset($filter_data['table_name']) and isset($filter_data['table_name'][0]) and !in_array(-1, (array) $filter_data['table_name'])) { $query .= ' AND a.table_name in (' . $this->getListSQL($filter_data['table_name'], $ph) . ') '; } if (isset($filter_data['object_id']) and isset($filter_data['object_id'][0]) and !in_array(-1, (array) $filter_data['object_id'])) { $query .= ' AND a.object_id in (' . $this->getListSQL($filter_data['object_id'], $ph) . ') '; } $query .= isset($filter_data['action_id']) ? $this->getWhereClauseSQL('a.action_id', $filter_data['action_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['date']) ? $this->getWhereClauseSQL('a.date', $filter_data['date'], 'date_range', $ph) : NULL; if (isset($filter_data['first_name']) and trim($filter_data['first_name']) != '') { $ph[] = $this->handleSQLSyntax(strtolower(trim($filter_data['first_name']))); $query .= ' AND (lower(uf.first_name) LIKE ? ) '; } if (isset($filter_data['last_name']) and trim($filter_data['last_name']) != '') { $ph[] = $this->handleSQLSyntax(strtolower(trim($filter_data['last_name']))); $query .= ' AND (lower(uf.last_name) LIKE ? ) '; } //Need to support table_name -> object_id pairs for including log entires from different tables/objects. if (isset($filter_data['table_name_object_id']) and is_array($filter_data['table_name_object_id']) and count($filter_data['table_name_object_id']) > 0) { foreach ($filter_data['table_name_object_id'] as $table_name => $object_id) { $ph[] = strtolower(trim($table_name)); $sub_query[] = '(a.table_name = ? AND a.object_id in (' . $this->getListSQL($object_id, $ph) . ') )'; } if (isset($sub_query)) { $query .= ' AND ( ' . implode(' OR ', $sub_query) . ' ) '; } unset($table_name, $object_id, $sub_query); } if (isset($filter_data['description']) and trim($filter_data['description']) != '') { $ph[] = strtolower(trim($filter_data['description'])); $query .= ' AND lower(a.description) LIKE ?'; } $query .= ''; $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 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('name' => 'asc'); $strict = FALSE; } else { //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(); $mpf = new MealPolicyFactory(); $apf = new AbsencePolicyFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, b.name as meal_policy, c.name as absence_policy, 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 ' . $mpf->getTable() . ' as b ON a.meal_policy_id = b.id LEFT JOIN ' . $apf->getTable() . ' as c ON a.absence_policy_id = c.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 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['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['meal_policy_id']) and isset($filter_data['meal_policy_id'][0]) and !in_array(-1, (array) $filter_data['meal_policy_id'])) { $query .= ' AND a.meal_policy_id in (' . $this->getListSQL($filter_data['meal_policy_id'], $ph) . ') '; } if (isset($filter_data['absence_policy_id']) and isset($filter_data['absence_policy_id'][0]) and !in_array(-1, (array) $filter_data['absence_policy_id'])) { $query .= ' AND a.absence_policy_id in (' . $this->getListSQL($filter_data['absence_policy_id'], $ph) . ') '; } if (isset($filter_data['name']) and trim($filter_data['name']) != '') { $ph[] = strtolower(trim($filter_data['name'])); $query .= ' AND lower(a.name) LIKE ?'; } if (isset($filter_data['created_by']) and isset($filter_data['created_by'][0]) and !in_array(-1, (array) $filter_data['created_by'])) { $query .= ' AND a.created_by in (' . $this->getListSQL($filter_data['created_by'], $ph) . ') '; } if (isset($filter_data['updated_by']) and isset($filter_data['updated_by'][0]) and !in_array(-1, (array) $filter_data['updated_by'])) { $query .= ' AND a.updated_by in (' . $this->getListSQL($filter_data['updated_by'], $ph) . ') '; } $query .= ' AND a.deleted = 0 '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); if ($limit == NULL) { $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } return $this; }
function getByUserIdAndCompanyId($user_id, $company_id, $limit = NULL, $page = NULL, $where = NULL, $order = NULL) { if (empty($user_id)) { return FALSE; } if (empty($company_id)) { return FALSE; } if ($order == NULL) { $strict = FALSE; } else { $strict = TRUE; } $uf = new UserFactory(); $ph = array('company_id' => $company_id, 'user_id' => $user_id); $query = ' select * from ' . $uf->getTable() . ' as a, ' . $this->getTable() . ' as b where a.id = b.user_id AND a.company_id = ? AND b.user_id = ? AND b.deleted = 0'; $query .= $this->getSortSQL($order, $strict); if ($limit == NULL) { $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } 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']); } } $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', 'name' => 'asc'); $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(); $apf = new AccrualPolicyFactory(); $cgmf = new CompanyGenericMapFactory(); $pgf = new PolicyGroupFactory(); $pguf = new PolicyGroupUserFactory(); $ph = array('company_id' => $company_id); $query = ' select DISTINCT a.*, apf.name as accrual_policy, 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 ' . $cgmf->getTable() . ' as cgmf ON ( a.id = cgmf.map_id AND cgmf.object_type_id = 170 ) LEFT JOIN ' . $pgf->getTable() . ' as pgf ON ( cgmf.object_id = pgf.id AND pgf.deleted = 0 ) LEFT JOIN ' . $pguf->getTable() . ' as pguf ON ( pguf.policy_group_id = pgf.id ) LEFT JOIN ' . $apf->getTable() . ' as apf ON ( a.accrual_policy_id = apf.id AND apf.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 = ? '; $query .= isset($filter_data['permission_children_ids']) ? $this->getWhereClauseSQL('a.created_by', $filter_data['permission_children_ids'], '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.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; $query .= isset($filter_data['user_id']) ? $this->getWhereClauseSQL('pguf.user_id', $filter_data['user_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['pay_stub_entry_account_id']) ? $this->getWhereClauseSQL('a.pay_stub_entry_account_id', $filter_data['pay_stub_entry_account_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['wage_group_id']) ? $this->getWhereClauseSQL('a.wage_group_id', $filter_data['wage_group_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['name']) ? $this->getWhereClauseSQL('a.name', $filter_data['name'], 'text', $ph) : NULL; $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']); } } $additional_order_fields = array(); if ($order == NULL) { $order = array('name' => 'asc'); $strict = FALSE; } else { //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(); $pguf = new PolicyGroupUserFactory(); $cgmf = new CompanyGenericMapFactory(); $ph = array('company_id' => $company_id); $query = ' select distinct 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 ' . $pguf->getTable() . ' as b ON a.id = b.policy_group_id LEFT JOIN ' . $cgmf->getTable() . ' as c ON ( a.id = c.object_id AND c.company_id = a.company_id AND c.object_type_id = 130) LEFT JOIN ' . $cgmf->getTable() . ' as d ON ( a.id = d.object_id AND d.company_id = a.company_id AND d.object_type_id = 110) LEFT JOIN ' . $cgmf->getTable() . ' as e ON ( a.id = e.object_id AND e.company_id = a.company_id AND e.object_type_id = 120) LEFT JOIN ' . $cgmf->getTable() . ' as f ON ( a.id = f.object_id AND f.company_id = a.company_id AND f.object_type_id = 140) 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['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['exception_policy_control']) and isset($filter_data['exception_policy_control'][0]) and !in_array(-1, (array) $filter_data['exception_policy_control'])) { $query .= ' AND a.exception_policy_control_id in (' . $this->getListSQL($filter_data['exception_policy_control'], $ph) . ') '; } if (isset($filter_data['holiday_policy']) and isset($filter_data['holiday_policy'][0]) and !in_array(-1, (array) $filter_data['holiday_policy'])) { $query .= ' AND a.holiday_policy_id in (' . $this->getListSQL($filter_data['holiday_policy'], $ph) . ') '; } if (isset($filter_data['user']) and isset($filter_data['user'][0]) and !in_array(-1, (array) $filter_data['user'])) { $query .= ' AND b.user_id in (' . $this->getListSQL($filter_data['user'], $ph) . ') '; } if (isset($filter_data['round_interval_policy']) and isset($filter_data['round_interval_policy'][0]) and !in_array(-1, (array) $filter_data['round_interval_policy'])) { $query .= ' AND c.map_id in (' . $this->getListSQL($filter_data['round_interval_policy'], $ph) . ') '; } if (isset($filter_data['over_time_policy']) and isset($filter_data['over_time_policy'][0]) and !in_array(-1, (array) $filter_data['over_time_policy'])) { $query .= ' AND d.map_id in (' . $this->getListSQL($filter_data['over_time_policy'], $ph) . ') '; } if (isset($filter_data['premium_policy']) and isset($filter_data['premium_policy'][0]) and !in_array(-1, (array) $filter_data['premium_policy'])) { $query .= ' AND e.map_id in (' . $this->getListSQL($filter_data['premium_policy'], $ph) . ') '; } if (isset($filter_data['accrual_policy']) and isset($filter_data['accrual_policy'][0]) and !in_array(-1, (array) $filter_data['accrual_policy'])) { $query .= ' AND f.map_id in (' . $this->getListSQL($filter_data['accrual_policy'], $ph) . ') '; } if (isset($filter_data['name']) and trim($filter_data['name']) != '') { $ph[] = strtolower(trim($filter_data['name'])); $query .= ' AND lower(a.name) LIKE ?'; } if (isset($filter_data['created_by']) and isset($filter_data['created_by'][0]) and !in_array(-1, (array) $filter_data['created_by'])) { $query .= ' AND a.created_by in (' . $this->getListSQL($filter_data['created_by'], $ph) . ') '; } if (isset($filter_data['updated_by']) and isset($filter_data['updated_by'][0]) and !in_array(-1, (array) $filter_data['updated_by'])) { $query .= ' AND a.updated_by in (' . $this->getListSQL($filter_data['updated_by'], $ph) . ') '; } $query .= ' AND a.deleted = 0 '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); if ($limit == NULL) { $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } return $this; }
function getReportByCompanyIdAndArrayCriteria($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('pay_period_id'); if ($order == NULL) { $order = array('b.user_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['b.name'] = $order['default_branch']; unset($order['default_branch']); } //Always try to order by status first so INACTIVE employees go to the bottom. if ( !isset($order['status_id']) ) { $order = Misc::prependArray( array('status_id' => 'asc'), $order ); } //Always sort by last name,first name after other columns if ( !isset($order['last_name']) ) { $order['last_name'] = 'asc'; } if ( !isset($order['first_name']) ) { $order['first_name'] = 'asc'; } */ $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); 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['branch_ids'])) { $filter_data['default_branch_id'] = $filter_data['branch_ids']; } if (isset($filter_data['department_ids'])) { $filter_data['default_department_id'] = $filter_data['department_ids']; } if (isset($filter_data['currency_ids'])) { $filter_data['currency_id'] = $filter_data['currency_ids']; } $bf = new BranchFactory(); $df = new DepartmentFactory(); $ugf = new UserGroupFactory(); $utf = new UserTitleFactory(); $psf = new PayStubFactory(); $uf = new UserFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, b.user_id as user_id, b.pay_period_id as pay_period_id, b.start_date as pay_stub_start_date, b.end_date as pay_stub_end_date, b.transaction_date as pay_stub_transaction_date, b.currency_id as currency_id, b.currency_rate as currency_rate, a.pay_stub_entry_name_id as pay_stub_entry_name_id, a.amount as amount, a.ytd_amount as ytd_amount from ( select aa.pay_stub_id as pay_stub_id, aa.pay_stub_entry_name_id as pay_stub_entry_name_id, sum(aa.amount) as amount, max(aa.ytd_amount) as ytd_amount from ' . $this->getTable() . ' as aa LEFT JOIN ' . $psf->getTable() . ' as bb ON aa.pay_stub_id = bb.id LEFT JOIN ' . $uf->getTable() . ' as cc ON bb.user_id = cc.id LEFT JOIN ' . $bf->getTable() . ' as dd ON cc.default_branch_id = dd.id LEFT JOIN ' . $df->getTable() . ' as ee ON cc.default_department_id = ee.id LEFT JOIN ' . $ugf->getTable() . ' as ff ON cc.group_id = ff.id LEFT JOIN ' . $utf->getTable() . ' as gg ON cc.title_id = gg.id where cc.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 cc.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 cc.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 cc.id in (' . $this->getListSQL($filter_data['user_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 cc.id not in (' . $this->getListSQL($filter_data['exclude_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 cc.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 cc.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 cc.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 cc.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 cc.title_id in (' . $this->getListSQL($filter_data['title_id'], $ph) . ') '; } if (isset($filter_data['sex_id']) and isset($filter_data['sex_id'][0]) and !in_array(-1, (array) $filter_data['sex_id'])) { $query .= ' AND cc.sex_id in (' . $this->getListSQL($filter_data['sex_id'], $ph) . ') '; } if (isset($filter_data['currency_id']) and isset($filter_data['currency_id'][0]) and !in_array(-1, (array) $filter_data['currency_id'])) { $query .= ' AND bb.currency_id in (' . $this->getListSQL($filter_data['currency_id'], $ph) . ') '; } if (isset($filter_data['pay_period_ids']) and isset($filter_data['pay_period_ids'][0]) and !in_array(-1, (array) $filter_data['pay_period_ids'])) { $query .= ' AND bb.pay_period_id in (' . $this->getListSQL($filter_data['pay_period_ids'], $ph) . ') '; } if (isset($filter_data['transaction_start_date']) and trim($filter_data['transaction_start_date']) != '') { $ph[] = $this->db->BindTimeStamp(strtolower(trim($filter_data['transaction_start_date']))); $query .= ' AND bb.transaction_date >= ?'; } if (isset($filter_data['transaction_end_date']) and trim($filter_data['transaction_end_date']) != '') { $ph[] = $this->db->BindTimeStamp(strtolower(trim($filter_data['transaction_end_date']))); $query .= ' AND bb.transaction_date <= ?'; } if (isset($filter_data['transaction_date']) and trim($filter_data['transaction_date']) != '') { $ph[] = $this->db->BindTimeStamp(strtolower(trim($filter_data['transaction_date']))); $query .= ' AND bb.transaction_date = ?'; } $query .= ' AND (aa.deleted = 0 AND bb.deleted = 0 AND cc.deleted=0) group by aa.pay_stub_id,aa.pay_stub_entry_name_id ) a LEFT JOIN ' . $psf->getTable() . ' as b ON a.pay_stub_id = b.id LEFT JOIN ' . $uf->getTable() . ' as c ON b.user_id = c.id where 1=1 '; $query .= ' AND (c.deleted=0) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); if ($limit == NULL) { $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } 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']); } } $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 getByUserName($user_name, $where = NULL, $order = NULL) { if ($user_name == '') { return FALSE; } $uf = new UserFactory(); $ph = array('user_name' => strtolower($user_name)); $query = ' select a.* from ' . $this->getTable() . ' as a, ' . $uf->getTable() . ' as b where a.id = b.company_id AND b.status_id = 10 AND b.user_name = ? AND ( a.deleted = 0 AND b.deleted = 0 )'; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order); $this->rs = $this->db->Execute($query, $ph); return $this; }
function getByAccrualPolicyId($accrual_policy_id, $where = NULL, $order = NULL) { if ($accrual_policy_id == '') { return FALSE; } $ph = array('accrual_policy_id' => $accrual_policy_id); $uf = new UserFactory(); $query = ' select a.* from ' . $this->getTable() . ' as a LEFT JOIN ' . $uf->getTable() . ' as b ON a.user_id = b.id where a.accrual_policy_id = ? AND a.deleted = 0 AND b.deleted = 0 LIMIT 1 '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order); $this->rs = $this->db->Execute($query, $ph); return $this; }
function getByUserIdAndFolder($user_id, $folder, $limit = NULL, $page = NULL, $where = NULL, $order = NULL) { if ($user_id == '') { return FALSE; } $strict = TRUE; if ($order == NULL) { $strict = FALSE; $order = array('a.status_id' => '= 10 desc', 'a.created_date' => 'desc'); } //Folder is: INBOX, SENT $key = Option::getByValue($folder, $this->getOptions('folder')); if ($key !== FALSE) { $folder = $key; } $rf = new RequestFactory(); $uf = new UserFactory(); $udf = new UserDateFactory(); $pptsvf = new PayPeriodTimeSheetVerifyFactory(); $ph = array('user_id' => $user_id); $folder_sent_query = NULL; $folder_inbox_query = NULL; $folder_inbox_query_a = NULL; $folder_inbox_query_ab = NULL; $folder_inbox_query_b = NULL; $folder_inbox_query_c = NULL; if ($folder == 10) { $ph['id'] = $user_id; $ph['created_by1'] = $user_id; $ph['created_by2'] = $user_id; $ph['created_by3'] = $user_id; $ph['created_by4'] = $user_id; $folder_inbox_query = ' AND a.created_by != ?'; $folder_inbox_query_a = ' OR d.id = ?'; $folder_inbox_query_ab = ' OR e.user_id = ?'; //$folder_inbox_query_b = ' OR a.parent_id in ( select parent_id FROM '. $this->getTable() .' WHERE created_by = '. $user_id .' ) '; $folder_inbox_query_b = ' OR a.parent_id in ( select parent_id FROM ' . $this->getTable() . ' WHERE created_by = ? AND parent_id != 0 ) '; $folder_inbox_query_c = ' OR a.parent_id in ( select id FROM ' . $this->getTable() . ' WHERE created_by = ? AND parent_id = 0 ) '; } elseif ($folder == 20) { $ph['created_by4'] = $user_id; $folder_sent_query = ' OR a.created_by = ?'; } //Need to include all threads that user has posted to. $query = ' SELECT a.*, CASE WHEN a.object_type_id = 5 THEN d.id WHEN a.object_type_id = 50 THEN c.user_id WHEN a.object_type_id = 90 THEN e.user_id END as sent_to_user_id FROM ' . $this->getTable() . ' as a LEFT JOIN ' . $uf->getTable() . ' as d ON a.object_type_id = 5 AND a.object_id = d.id LEFT JOIN ' . $uf->getTable() . ' as f ON a.created_by = f.id LEFT JOIN ' . $rf->getTable() . ' as b ON a.object_type_id = 50 AND a.object_id = b.id LEFT JOIN ' . $udf->getTable() . ' as c ON b.user_date_id = c.id LEFT JOIN ' . $pptsvf->getTable() . ' as e ON a.object_type_id = 90 AND a.object_id = e.id WHERE a.object_type_id in (5,50,90) AND ( ( ( c.user_id = ? ' . $folder_sent_query . ' ' . $folder_inbox_query_a . ' ' . $folder_inbox_query_ab . ' ' . $folder_inbox_query_b . ' ' . $folder_inbox_query_c . ' ) ' . $folder_inbox_query . ' ) ) AND ( a.deleted = 0 AND f.deleted = 0 AND ( b.id IS NULL OR ( b.id IS NOT NULL AND b.deleted = 0 ) ) AND ( c.id IS NULL OR ( c.id IS NOT NULL AND c.deleted = 0 ) ) AND ( d.id IS NULL OR ( d.id IS NOT NULL AND d.deleted = 0 ) ) AND ( e.id IS NULL OR ( e.id IS NOT NULL AND e.deleted = 0 ) ) AND NOT ( b.id IS NULL AND c.id IS NULL AND d.id IS NULL AND e.id IS NULL ) ) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, array('sent_to_user_id')); //Debug::text('Query: '. $query , __FILE__, __LINE__, __METHOD__,9); if ($limit == NULL) { //Run query without limit $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } return $this; }
function getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($company_id, $user_id, $object_type_id = 100) { global $profiler; $profiler->startTimer("getPermissionHierarchyChildrenByCompanyIdAndUserId"); if ($company_id == '') { return FALSE; } if ($user_id == '') { return FALSE; } if ($object_type_id == '') { return FALSE; } $retval = FALSE; $uf = new UserFactory(); $hlf = new HierarchyLevelFactory(); $huf = new HierarchyUserFactory(); $hotf = new HierarchyObjectTypeFactory(); $hcf = new HierarchyControlFactory(); //When it comes to permissions we only consider subordinates, not other supervisors/managers in the hierarchy. $ph = array('user_id' => $user_id, 'company_id' => $company_id); //w.user_id != x.user_id, is there to make sure we exclude the current user from the subordinate list, //as we now allow superiors to also be subordinates in the same hierarchy. $query = ' select w.user_id as user_id from ' . $huf->getTable() . ' as w LEFT JOIN ' . $hlf->getTable() . ' as x ON w.hierarchy_control_id = x.hierarchy_control_id LEFT JOIN ' . $hotf->getTable() . ' as y ON w.hierarchy_control_id = y.hierarchy_control_id LEFT JOIN ' . $uf->getTable() . ' as z ON x.user_id = z.id LEFT JOIN ' . $hcf->getTable() . ' as z2 ON w.hierarchy_control_id = z2.id WHERE x.user_id = ? AND z.company_id = ? AND y.object_type_id in (' . $this->getListSQL($object_type_id, $ph) . ') AND w.user_id != x.user_id AND ( x.deleted = 0 AND z2.deleted = 0 AND z.deleted = 0 ) '; //Debug::Text(' Query: '. $query, __FILE__, __LINE__, __METHOD__,10); $rs = $this->db->Execute($query, $ph); //Debug::Text(' Rows: '. $rs->RecordCount(), __FILE__, __LINE__, __METHOD__,10); if ($rs->RecordCount() > 0) { foreach ($rs as $row) { $retval[] = $row['user_id']; } } $profiler->stopTimer("getPermissionHierarchyChildrenByCompanyIdAndUserId"); return $retval; }
function getReportHoursByTimePeriodAndUserIdAndCompanyIdAndStartDateAndEndDate($time_period, $user_ids, $company_id, $start_date, $end_date, $where = NULL, $order = NULL) { if ($time_period == '') { return FALSE; } if ($user_ids == '') { return FALSE; } if ($company_id == '') { return FALSE; } if ($start_date == '') { return FALSE; } if ($end_date == '') { return FALSE; } /* if ( $order == NULL ) { $order = array( 'date_stamp' => 'asc' ); $strict = FALSE; } else { $strict = TRUE; } */ $uf = new UserFactory(); $udf = new UserDateFactory(); $ph = array('company_id' => $company_id, 'start_date' => $this->db->BindDate($start_date), 'end_date' => $this->db->BindDate($end_date)); $query = ' select user_id, status_id, type_id, over_time_policy_id, absence_policy_id, premium_policy_id, avg(total_time) as avg, min(total_time) as min, max(total_time) as max, count(*) as date_units from ( select b.user_id, (EXTRACT(' . $time_period . ' FROM b.date_stamp) || \'-\' || EXTRACT(month FROM b.date_stamp) || \'-\' || EXTRACT(year FROM b.date_stamp) ) as date, a.type_id, a.status_id, over_time_policy_id, absence_policy_id, premium_policy_id, sum(total_time) as total_time from ' . $this->getTable() . ' as a, ' . $udf->getTable() . ' as b, ' . $uf->getTable() . ' as c where a.user_date_id = b.id AND b.user_id = c.id AND c.company_id = ? AND b.date_stamp >= ? AND b.date_stamp <= ? AND b.user_id in (' . $this->getListSQL($user_ids, $ph) . ') AND a.total_time > 0 AND ( a.deleted = 0 AND b.deleted=0 AND c.deleted=0) GROUP BY user_id,(EXTRACT(' . $time_period . ' FROM b.date_stamp) || \'-\' || EXTRACT(month FROM b.date_stamp) || \'-\' || EXTRACT(year FROM b.date_stamp) ),a.status_id,a.type_id,over_time_policy_id,absence_policy_id,premium_policy_id ) tmp GROUP BY user_id,status_id,type_id,over_time_policy_id,absence_policy_id,premium_policy_id '; /* $query = ' select user_id, status_id, type_id, over_time_policy_id, absence_policy_id, premium_policy_id, avg(total_time) as avg, min(total_time) as min, max(total_time) as max, count(*) as date_units from ( select b.user_id, (date_part(\''.$time_period.'\', b.date_stamp) || \'-\' || date_part(\'month\', b.date_stamp) || \'-\' || date_part(\'year\', b.date_stamp) ) as date, a.type_id, a.status_id, over_time_policy_id, absence_policy_id, premium_policy_id, sum(total_time) as total_time from '. $this->getTable() .' as a, '. $udf->getTable() .' as b, '. $uf->getTable() .' as c where a.user_date_id = b.id AND b.user_id = c.id AND c.company_id = ? AND b.date_stamp >= ? AND b.date_stamp <= ? AND b.user_id in ('. $this->getListSQL($user_ids, $ph) .') AND a.total_time > 0 AND ( a.deleted = 0 AND b.deleted=0 AND c.deleted=0) GROUP BY user_id,(date_part(\''. $time_period.'\', b.date_stamp) || \'-\' || date_part(\'month\', b.date_stamp) || \'-\' || date_part(\'year\', b.date_stamp) ),a.status_id,a.type_id,over_time_policy_id,absence_policy_id,premium_policy_id ) tmp GROUP BY user_id,status_id,type_id,over_time_policy_id,absence_policy_id,premium_policy_id '; */ //$query .= $this->getWhereSQL( $where ); //$query .= $this->getSortSQL( $order ); $this->rs = $this->db->Execute($query, $ph); 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']); } } $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', 'name' => 'asc'); $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(); $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 ) 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 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['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']); } } $additional_order_fields = array('status_id', 'type_id', 'pay_period_schedule'); $sort_column_aliases = array('status' => 'status_id', 'type' => 'type_id'); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('transaction_date' => 'desc', 'end_date' => 'desc', 'start_date' => 'desc', 'pay_period_schedule_id' => 'asc'); $strict = FALSE; } else { //Always try to order by status first so INACTIVE employees go to the bottom. if (!isset($order['transaction_date'])) { $order = Misc::prependArray(array('transaction_date' => 'desc'), $order); } $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); $ppsf = new PayPeriodScheduleFactory(); $uf = new UserFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, b.name as pay_period_schedule, b.type_id as type_id, 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 ' . $ppsf->getTable() . ' as b ON ( a.pay_period_schedule_id = b.id AND b.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['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['pay_period_schedule_id']) and isset($filter_data['pay_period_schedule_id'][0]) and !in_array(-1, (array) $filter_data['pay_period_schedule_id'])) { $query .= ' AND a.pay_period_schedule_id in (' . $this->getListSQL($filter_data['pay_period_schedule_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 a.status_id in (' . $this->getListSQL($filter_data['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 b.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(b.name) LIKE ?'; } if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') { $ph[] = $this->db->BindTimeStamp($filter_data['start_date']); $query .= ' AND a.start_date >= ?'; } if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $ph[] = $this->db->BindTimeStamp($filter_data['end_date']); $query .= ' AND a.start_date <= ?'; } if (isset($filter_data['created_by']) and isset($filter_data['created_by'][0]) and !in_array(-1, (array) $filter_data['created_by'])) { $query .= ' AND a.created_by in (' . $this->getListSQL($filter_data['created_by'], $ph) . ') '; } if (isset($filter_data['updated_by']) and isset($filter_data['updated_by'][0]) and !in_array(-1, (array) $filter_data['updated_by'])) { $query .= ' AND a.updated_by in (' . $this->getListSQL($filter_data['updated_by'], $ph) . ') '; } $query .= ' AND a.deleted = 0 '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); if ($limit == NULL) { $this->rs = $this->db->Execute($query, $ph); } else { $this->rs = $this->db->PageExecute($query, $limit, $page, $ph); } return $this; }
function getByCompanyIdAndUserIdAndId($company_id, $user_id, $id, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } if ($user_id == '') { return FALSE; } if ($id == '') { return FALSE; } $uf = new UserFactory(); $ph = array('company_id' => $company_id, 'user_id' => $user_id); $query = ' SELECT a.* FROM ' . $this->getTable() . ' as a LEFT JOIN ' . $uf->getTable() . ' as b ON a.user_id = b.id WHERE b.company_id = ? AND a.user_id = ? AND a.id in (' . $this->getListSQL($id, $ph) . ') AND a.deleted = 0 '; $this->ExecuteSQL($query, $ph); 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']); } } $additional_order_fields = array(); $sort_column_aliases = array(); $order = $this->getColumnsFromAliases($order, $sort_column_aliases); if ($order == NULL) { $order = array('date_stamp' => 'desc', 'name' => 'asc'); $strict = FALSE; } else { if (!isset($order['date_stamp'])) { $order = Misc::prependArray(array('date_stamp' => 'desc'), $order); } $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); $uf = new UserFactory(); $pgf = new PolicyGroupFactory(); $pguf = new PolicyGroupUserFactory(); $hpf = new HolidayPolicyFactory(); $cgmf = new CompanyGenericMapFactory(); $ph = array('company_id' => $company_id); $query = ' select distinct 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 ' . $hpf->getTable() . ' as hpf ON ( a.holiday_policy_id = hpf.id AND hpf.deleted = 0 ) LEFT JOIN ' . $cgmf->getTable() . ' as cgmf ON ( cgmf.company_id = hpf.company_id AND cgmf.object_type_id = 180 AND cgmf.map_id = a.holiday_policy_id ) LEFT JOIN ' . $pgf->getTable() . ' as pgf ON ( pgf.id = cgmf.object_id AND pgf.deleted = 0 ) LEFT JOIN ' . $pguf->getTable() . ' as pguf ON ( pguf.policy_group_id = pgf.id AND pgf.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 hpf.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['holiday_policy_id']) and isset($filter_data['holiday_policy_id'][0]) and !in_array(-1, (array) $filter_data['holiday_policy_id'])) { $query .= ' AND a.holiday_policy_id in (' . $this->getListSQL($filter_data['holiday_policy_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 pguf.user_id in (' . $this->getListSQL($filter_data['user_id'], $ph) . ') '; } if (isset($filter_data['name']) and trim($filter_data['name']) != '') { $ph[] = strtolower(trim($filter_data['name'])); $query .= ' AND lower(a.name) LIKE ?'; } if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') { $ph[] = $this->db->BindDate($filter_data['start_date']); $query .= ' AND a.date_stamp >= ?'; } if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $ph[] = $this->db->BindDate($filter_data['end_date']); $query .= ' AND a.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; $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; }