From d5fd300b6af62f1bc52fbdc68cd9d8a37a0f65f1 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Tue, 2 Dec 2025 09:29:42 +0700 Subject: [PATCH] new feature for suhu kuda --- app/Controllers/Organization/Department.php | 7 ++++-- app/Controllers/Organization/Workstation.php | 6 ++++- .../2025-10-23-110105_Organization.php | 2 +- app/Models/Organization/DepartmentModel.php | 16 +++++++++---- app/Models/Organization/WorkstationModel.php | 24 +++++++++++-------- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/app/Controllers/Organization/Department.php b/app/Controllers/Organization/Department.php index 689ff82..ae3a43c 100644 --- a/app/Controllers/Organization/Department.php +++ b/app/Controllers/Organization/Department.php @@ -18,8 +18,11 @@ class Department extends BaseController { } public function index() { - //$rows = $this->model->findAll(); - $rows = $this->model->getDepartments(); + $filter = [ + 'DepartmentCode' => $this->request->getVar('DepartmentCode'), + 'DepartmentName' => $this->request->getVar('DepartmentName'), + ]; + $rows = $this->model->getDepartments($filter); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); diff --git a/app/Controllers/Organization/Workstation.php b/app/Controllers/Organization/Workstation.php index 4c052fc..153505e 100644 --- a/app/Controllers/Organization/Workstation.php +++ b/app/Controllers/Organization/Workstation.php @@ -18,7 +18,11 @@ class Workstation extends BaseController { } public function index() { - $rows = $this->model->getWorkstations(); + $filter = [ + 'WorkstationCode' => $this->request->getVar('WorkstationCode'), + 'WorkstationName' => $this->request->getVar('WorkstationName'), + ]; + $rows = $this->model->getWorkstations($filter); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); diff --git a/app/Database/Migrations/2025-10-23-110105_Organization.php b/app/Database/Migrations/2025-10-23-110105_Organization.php index 0c8fcd7..609a63f 100644 --- a/app/Database/Migrations/2025-10-23-110105_Organization.php +++ b/app/Database/Migrations/2025-10-23-110105_Organization.php @@ -35,7 +35,7 @@ class Organization extends Migration { 'WorkstationName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true], 'Type' => ['type' => 'tinyint', 'null'=> true], 'LinkTo' => ['type' => 'int', 'null'=> true], - 'Enable' => ['type' => 'bit', 'null'=> true], + 'Enable' => ['type' => 'int', 'null'=> true], 'CreateDate' => ['type'=>'DATETIME', 'null' => true], 'EndDate' => ['type'=>'DATETIME', 'null' => true] ]); diff --git a/app/Models/Organization/DepartmentModel.php b/app/Models/Organization/DepartmentModel.php index 5a8a435..b51218b 100644 --- a/app/Models/Organization/DepartmentModel.php +++ b/app/Models/Organization/DepartmentModel.php @@ -13,11 +13,19 @@ class DepartmentModel extends BaseModel { protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; - public function getDepartments() { - $rows = $this->select('department.*, discipline.DisciplineCode, discipline.DisciplineName, site.SiteCode, site.SiteName') + public function getDepartments($filter = []) { + $this->select('department.*, discipline.DisciplineCode, discipline.DisciplineName, site.SiteCode, site.SiteName') ->join('discipline', 'discipline.DisciplineID=department.DisciplineID', 'left') - ->join('site', 'department.SiteID=site.SiteID', 'left') - ->findAll(); + ->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(); + return $rows; } diff --git a/app/Models/Organization/WorkstationModel.php b/app/Models/Organization/WorkstationModel.php index 9b81ede..ea4d701 100644 --- a/app/Models/Organization/WorkstationModel.php +++ b/app/Models/Organization/WorkstationModel.php @@ -14,23 +14,27 @@ class WorkstationModel extends BaseModel { protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; - public function getWorkstations() { - $rows = $this->select('workstation.*, department.DepartmentName, wst1.WorkstationName as LinkToName') + public function getWorkstations($filter = []) { + $this->select('workstation.*, department.DepartmentName, wst1.WorkstationName as LinkToName') ->join('workstation wst1', 'workstation.LinkTo=wst1.WorkstationID', 'left') - ->join('department', 'department.DepartmentID=workstation.DepartmentID', 'left') - ->findAll(); + ->join('department', 'department.DepartmentID=workstation.DepartmentID', 'left'); + + if (!empty($filter['WorkstationCode'])) { + $this->like('workstation.WorkstationCode', $filter['WorkstationCode'], 'both'); + } + if (!empty($filter['WorkstationName'])) { + $this->like('workstation.WorkstationName', $filter['WorkstationName'], 'both'); + } + $rows = $this->findAll(); return $rows; } public function getWorkstation($WorkstationID) { - $rows = $this->select("workstation.*, department.DepartmentName, wst1.WorkstationName as LinkToName, - CASE - WHEN workstation.Enable = 1 THEN 'Enabled' - ELSE 'Disabled' - END AS EnableText, valueset.VValue as TypeName") + $rows = $this->select("workstation.*, department.DepartmentName, wst1.WorkstationName as LinkToName,enable.VDesc as EnableName, wstype.VDesc as TypeName") ->join('workstation wst1', 'workstation.LinkTo=wst1.WorkstationID', 'left') ->join('department', 'department.DepartmentID=workstation.DepartmentID', 'left') - ->join('valueset', 'valueset.VID=workstation.Type', 'left') + ->join('valueset wstype', 'wstype.VID=workstation.Type', 'left') + ->join('valueset enable', 'enable.VID=workstation.Enable', 'left') ->where('workstation.WorkstationID', $WorkstationID) ->findAll(); return $rows;