2025-10-29 11:08:38 +07:00
|
|
|
<?php
|
|
|
|
|
namespace App\Models\Organization;
|
|
|
|
|
use App\Models\BaseModel;
|
|
|
|
|
|
|
|
|
|
class DepartmentModel extends BaseModel {
|
|
|
|
|
protected $table = 'department';
|
|
|
|
|
protected $primaryKey = 'DepartmentID';
|
|
|
|
|
protected $allowedFields = ['DisciplineID', 'SiteID', 'DepartmentCode', 'DepartmentName', 'CreateDate', 'EndDate'];
|
|
|
|
|
|
|
|
|
|
protected $useTimestamps = true;
|
|
|
|
|
protected $createdField = 'CreateDate';
|
|
|
|
|
protected $updatedField = '';
|
|
|
|
|
protected $useSoftDeletes = true;
|
|
|
|
|
protected $deletedField = 'EndDate';
|
|
|
|
|
|
2025-12-02 09:29:42 +07:00
|
|
|
public function getDepartments($filter = []) {
|
|
|
|
|
$this->select('department.*, discipline.DisciplineCode, discipline.DisciplineName, site.SiteCode, site.SiteName')
|
2025-11-06 12:28:42 +07:00
|
|
|
->join('discipline', 'discipline.DisciplineID=department.DisciplineID', 'left')
|
2025-12-02 09:29:42 +07:00
|
|
|
->join('site', 'department.SiteID=site.SiteID', 'left');
|
|
|
|
|
|
|
|
|
|
if (!empty($filter['DepartmentCode'])) {
|
|
|
|
|
$this->like('department.DepartmentCode', $filter['DepartmentCode'], 'both');
|
|
|
|
|
}
|
|
|
|
|
if (!empty($filter['DepartmentName'])) {
|
|
|
|
|
$this->like('department.DepartmentName', $filter['DepartmentName'], 'both');
|
|
|
|
|
}
|
|
|
|
|
$rows = $this->findAll();
|
|
|
|
|
|
2025-11-06 12:28:42 +07:00
|
|
|
return $rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDepartment($DepartmentID) {
|
2025-12-29 12:55:31 +07:00
|
|
|
$row = $this->select('department.*, discipline.DisciplineCode, discipline.DisciplineName, site.SiteCode, site.SiteName')
|
2025-11-06 12:28:42 +07:00
|
|
|
->join('discipline', 'discipline.DisciplineID=department.DisciplineID', 'left')
|
|
|
|
|
->join('site', 'site.SiteID=department.SiteID', 'left')
|
|
|
|
|
->where('department.DepartmentID', $DepartmentID)
|
2025-12-29 12:55:31 +07:00
|
|
|
->first();
|
|
|
|
|
return $row;
|
2025-11-06 12:28:42 +07:00
|
|
|
}
|
2025-10-29 11:08:38 +07:00
|
|
|
}
|