96 lines
2.9 KiB
PHP
96 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class EmployeeModel extends Model
|
|
{
|
|
protected $table = 'employees';
|
|
protected $primaryKey = 'id';
|
|
protected $allowedFields = [
|
|
"id",
|
|
"client_id",
|
|
"employee_id",
|
|
"change_event",
|
|
"relationship_id",
|
|
"relationship",
|
|
"batch_id",
|
|
"emp_code",
|
|
"name",
|
|
"email_personal",
|
|
"email_corporate",
|
|
"mobile",
|
|
"gender",
|
|
"dob",
|
|
"doj",
|
|
"otp",
|
|
"family_floater_key",
|
|
"emp_status",
|
|
"created_by",
|
|
"updated_by",
|
|
"updated_at",
|
|
"is_active",
|
|
];
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
protected function checkAndADDCreatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['created_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['created_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['updated_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['updated_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
public function getEmployeePolicy($id)
|
|
{
|
|
|
|
return $this->db->table('employee_polices')
|
|
->select(' policies.name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment') // Select all columns from both tables
|
|
->join('client_policy', 'client_policy.id = employee_polices.client_policy_id')
|
|
->join('policies', 'policies.id = client_policy.policy_id')
|
|
->where('employee_polices.employee_id', $id)
|
|
->get()
|
|
->getResult();
|
|
}
|
|
|
|
|
|
|
|
|
|
// for EMP rest API process do not change
|
|
public function checkExistingEmployee($arr)
|
|
{
|
|
return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->first();
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|