From 1755105af113907eae48d719b5072313f59defc5 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Tue, 2 Dec 2025 07:09:24 +0700 Subject: [PATCH] till discipline --- app/Config/Routes.php | 38 +++---- app/Controllers/Organization/Account.php | 20 ++-- app/Controllers/Organization/Discipline.php | 114 ++++++++++---------- app/Controllers/Organization/Site.php | 21 ++-- app/Controllers/Specimen/ContainerDef.php | 94 ++++++++-------- app/Controllers/ValueSet/ValueSetDef.php | 6 +- app/Models/Organization/AccountModel.php | 27 +++-- app/Models/Organization/DisciplineModel.php | 13 +++ app/Models/Organization/SiteModel.php | 17 ++- app/Models/Specimen/ContainerDefModel.php | 17 +++ 10 files changed, 212 insertions(+), 155 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 736b5d4..4ac56de 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -93,12 +93,6 @@ $routes->post('/api/counter', 'Counter::create'); $routes->patch('/api/counter', 'Counter::update'); $routes->delete('/api/counter', 'Counter::delete'); -$routes->get('/api/containerdef/', 'Specimen\ContainerDef::index'); -$routes->get('/api/containerdef/(:num)', 'Specimen\ContainerDef::show/$1'); -$routes->post('/api/containerdef', 'Specimen\ContainerDef::create'); -$routes->patch('/api/containerdef', 'Specimen\ContainerDef::update'); -$routes->delete('/api/containerdef', 'Specimen\ContainerDef::delete'); - $routes->get('/api/areageo', 'AreaGeo::index'); $routes->get('/api/areageo/provinces', 'AreaGeo::getProvinces'); $routes->get('/api/areageo/cities', 'AreaGeo::getCities'); @@ -136,25 +130,25 @@ $routes->patch('/api/organization/workstation', 'Organization\Workstation::updat $routes->delete('/api/organization/workstation', 'Organization\Workstation::delete'); $routes->group('api/specimen', function($routes) { - $routes->get('/containerdef/(:num)', 'Specimen\ContainerDef::show/$1'); - $routes->post('/containerdef', 'Specimen\ContainerDef::create'); - $routes->patch('/containerdef', 'Specimen\ContainerDef::update'); - $routes->get('/containerdef', 'Specimen\ContainerDef::index'); + $routes->get('containerdef/(:num)', 'Specimen\ContainerDef::show/$1'); + $routes->post('containerdef', 'Specimen\ContainerDef::create'); + $routes->patch('containerdef', 'Specimen\ContainerDef::update'); + $routes->get('containerdef', 'Specimen\ContainerDef::index'); - $routes->get('/prep/(:num)', 'Specimen\Prep::show/$1'); - $routes->post('/prep', 'Specimen\Prep::create'); - $routes->patch('/prep', 'Specimen\Prep::update'); - $routes->get('/prep', 'Specimen\Prep::index'); + $routes->get('prep/(:num)', 'Specimen\Prep::show/$1'); + $routes->post('prep', 'Specimen\Prep::create'); + $routes->patch('prep', 'Specimen\Prep::update'); + $routes->get('prep', 'Specimen\Prep::index'); - $routes->get('/status/(:num)', 'Specimen\Status::show/$1'); - $routes->post('/status', 'Specimen\Status::create'); - $routes->patch('/status', 'Specimen\Status::update'); - $routes->get('/status', 'Specimen\Status::index'); + $routes->get('status/(:num)', 'Specimen\Status::show/$1'); + $routes->post('status', 'Specimen\Status::create'); + $routes->patch('status', 'Specimen\Status::update'); + $routes->get('status', 'Specimen\Status::index'); - $routes->get('/collection/(:num)', 'Specimen\Collection::show/$1'); - $routes->post('/collection', 'Specimen\Collection::create'); - $routes->patch('/collection', 'Specimen\Collection::update'); - $routes->get('/collection', 'Specimen\Collection::index'); + $routes->get('collection/(:num)', 'Specimen\Collection::show/$1'); + $routes->post('collection', 'Specimen\Collection::create'); + $routes->patch('collection', 'Specimen\Collection::update'); + $routes->get('collection', 'Specimen\Collection::index'); $routes->get('(:num)', 'Specimen\Specimen::show/$1'); $routes->post('', 'Specimen\Specimen::create'); diff --git a/app/Controllers/Organization/Account.php b/app/Controllers/Organization/Account.php index 5598d8c..1bdf83b 100644 --- a/app/Controllers/Organization/Account.php +++ b/app/Controllers/Organization/Account.php @@ -17,15 +17,19 @@ class Account extends BaseController { $this->model = new AccountModel(); } - public function index() { - //$rows = $this->model->findAll(); - $rows = $this->model->getAccounts(); - - if (empty($rows)) { - return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); - } + public function index() { + $filter = [ + 'Parent' => $this->request->getVar('Parent'), + 'AccountName' => $this->request->getVar('AccountName'), + ]; - return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + $rows = $this->model->getAccounts($filter); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); } public function show($AccountID = null) { diff --git a/app/Controllers/Organization/Discipline.php b/app/Controllers/Organization/Discipline.php index 56a429a..6bcb314 100644 --- a/app/Controllers/Organization/Discipline.php +++ b/app/Controllers/Organization/Discipline.php @@ -7,72 +7,76 @@ use App\Controllers\BaseController; use App\Models\Organization\DisciplineModel; class Discipline extends BaseController { - use ResponseTrait; + use ResponseTrait; - protected $db; - protected $model; + protected $db; + protected $model; - public function __construct() { - $this->db = \Config\Database::connect(); - $this->model = new DisciplineModel(); + public function __construct() { + $this->db = \Config\Database::connect(); + $this->model = new DisciplineModel(); + } + + public function index() { + $filter = [ + 'DisciplineCode' => $this->request->getVar('DisciplineCode'), + 'DisciplineName' => $this->request->getVar('DisciplineName'), + ]; + $rows = $this->model->getDisciplines($filter); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } - public function index() { - $rows = $this->model->findAll(); - - if (empty($rows)) { - return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); - } + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } - return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + public function show($DisciplineID = null) { + $rows = $this->model->where('DisciplineID', $DisciplineID)->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } - public function show($DisciplineID = null) { - $rows = $this->model->where('DisciplineID', $DisciplineID)->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } - if (empty($rows)) { - return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); - } - - return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + public function delete() { + try { + $input = $this->request->getJSON(true); + $id = $input["DisciplineID"]; + if (!$id) { return $this->failValidationErrors('ID is required.'); } + $this->model->delete($id); + return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); } + } - public function delete() { - try { - $input = $this->request->getJSON(true); - $id = $input["DisciplineID"]; - if (!$id) { return $this->failValidationErrors('ID is required.'); } - $this->model->delete($id); - return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]); - } catch (\Throwable $e) { - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } + public function create() { + $input = $this->request->getJSON(true); + try { + $id = $this->model->insert($input,true); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); } + } - public function create() { - $input = $this->request->getJSON(true); - try { - $id = $this->model->insert($input,true); - return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201); - } catch (\Throwable $e) { - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - - public function update() { - $input = $this->request->getJSON(true); - $id = $input['DisciplineID']; - $this->model->update($id, $input); - return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); - /* - try { - $id = $input['DisciplineID']; - $this->model->where('DisciplineID', $id)->update(); - echo $this->model->getLastQuery(); - return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); - } catch (\Throwable $e) { - return $this->failServerError('Something went wrong: ' . $e->getMessage() ); - } - */ + public function update() { + $input = $this->request->getJSON(true); + $id = $input['DisciplineID']; + $this->model->update($id, $input); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); + /* + try { + $id = $input['DisciplineID']; + $this->model->where('DisciplineID', $id)->update(); + echo $this->model->getLastQuery(); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage() ); } + */ + } } \ No newline at end of file diff --git a/app/Controllers/Organization/Site.php b/app/Controllers/Organization/Site.php index 4891c3e..03ccc19 100644 --- a/app/Controllers/Organization/Site.php +++ b/app/Controllers/Organization/Site.php @@ -17,17 +17,20 @@ class Site extends BaseController { $this->model = new SiteModel(); } - public function index() { - //$rows = $this->model->findAll(); - $rows = $this->model->getSites(); - - if (empty($rows)) { - return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); - } - - return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + public function index() { + $filter = [ + 'SiteCode' => $this->request->getVar('SiteCode'), + 'SiteName' => $this->request->getVar('SiteName'), + ]; + $rows = $this->model->getSites($filter); + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); } + + public function show($SiteID = null) { //$rows = $this->model->where('SiteID', $SiteID)->findAll(); $rows = $this->model->getSite($SiteID); diff --git a/app/Controllers/Specimen/ContainerDef.php b/app/Controllers/Specimen/ContainerDef.php index d1f10c3..0c4271d 100644 --- a/app/Controllers/Specimen/ContainerDef.php +++ b/app/Controllers/Specimen/ContainerDef.php @@ -7,59 +7,63 @@ use App\Controllers\BaseController; use App\Models\Specimen\ContainerDefModel; class ContainerDef extends BaseController { - use ResponseTrait; + use ResponseTrait; - protected $db; - protected $model; - protected $rules; + protected $db; + protected $model; + protected $rules; - public function __construct() { - $this->db = \Config\Database::connect(); - $this->model = new ContainerDefModel(); - $this->rules = [ - 'ConCode' => 'required|max_length[50]', - 'ConName' => 'required|max_length[50]' - ]; + public function __construct() { + $this->db = \Config\Database::connect(); + $this->model = new ContainerDefModel(); + $this->rules = [ + 'ConCode' => 'required|max_length[50]', + 'ConName' => 'required|max_length[50]' + ]; + } + + public function index() { + try { + $filter = [ + 'ConCode' => $this->request->getVar('ConCode'), + 'ConName' => $this->request->getVar('ConName') + ]; + $rows = $this->model->getContainers($filter); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); } + } - public function index() { - try { - $rows = $this->model->findAll(); - return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); - } catch (\Exception $e) { - return $this->failServerError('Exception : '.$e->getMessage()); - } + public function show($ConDefID) { + try { + $rows = $this->model->getContainer($ConDefID); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); } + } - public function show($ConDefID) { - try { - $rows = $this->model->getContainer($ConDefID); - return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); - } catch (\Exception $e) { - return $this->failServerError('Exception : '.$e->getMessage()); - } + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $ConDefID = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); } + } - public function create() { - $input = $this->request->getJSON(true); - if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } - try { - $ConDefID = $this->model->insert($input); - return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID created successfully" ]); - } catch (\Exception $e) { - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - - public function update() { - $input = $this->request->getJSON(true); - if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } - try { - $ConDefID = $this->model->update($input['ConDefID'], $input); - return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID updated successfully" ]); - } catch (\Exception $e) { - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } + public function update() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $ConDefID = $this->model->update($input['ConDefID'], $input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); } + } } \ No newline at end of file diff --git a/app/Controllers/ValueSet/ValueSetDef.php b/app/Controllers/ValueSet/ValueSetDef.php index 110cb80..a20a7f5 100644 --- a/app/Controllers/ValueSet/ValueSetDef.php +++ b/app/Controllers/ValueSet/ValueSetDef.php @@ -47,12 +47,12 @@ class ValueSetDef extends BaseController { public function update() { $input = $this->request->getJSON(true); - $VSetID = $input["VID"]; + $VSetID = $input["VSetID"]; if (!$VSetID) { return $this->failValidationErrors('VSetID is required.'); } if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); } try { - $this->model->update($VSetID,$input); - return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID updated successfully" ]); + $this->model->update($VSetID,$input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID updated successfully" ]); } catch (\Exception $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } diff --git a/app/Models/Organization/AccountModel.php b/app/Models/Organization/AccountModel.php index d2c841e..4127c8b 100644 --- a/app/Models/Organization/AccountModel.php +++ b/app/Models/Organization/AccountModel.php @@ -15,20 +15,29 @@ class AccountModel extends BaseModel { protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; - public function getAccounts() { - $rows = $this->select('account.AccountID, account.AccountName, account.Parent, pa.AccountName as ParentName, account.AreaCode, zones.ZoneName as AreaName') - ->join('account pa', 'pa.AccountID=account.Parent', 'left') - ->join('zones', 'zones.zonecode=account.AreaCode', 'left') - ->findAll(); + public function getAccounts($filter=[]) { + $builder = $this->select('account.AccountID, account.AccountName, account.Parent, pa.AccountName as ParentName, account.Initial') + ->join('account pa', 'pa.AccountID=account.Parent', 'left'); + + if (!empty($filter['Parent'])) { + $builder->where('account.Parent', $filter['Parent']); + } + if (!empty($filter['AccountName'])) { + $builder->like('account.AccountName', $filter['AccountName'], 'both'); + } + + $rows = $builder->findAll(); return $rows; } public function getAccount($AccountID) { - $rows = $this->select('account.*, pa.AccountName as ParentName, zones.ZoneName as AreaName, city.ZoneName as CityName, prov.ZoneName as ProvName, country.VValue as CountryName') + $rows = $this->select('account.*, pa.AccountName as ParentName, areageo.AreaName, areageo.AreaGeoID, + city.AreaName as CityName, city.AreaGeoID as City, prov.AreaName as ProvName, prov.AreaGeoID as Prov, + country.VValue as CountryName, country.VID as country') ->join('account pa', 'pa.AccountID=account.Parent', 'left') - ->join('zones', 'zones.zonecode=account.AreaCode', 'left') - ->join('zones city', 'city.zoneid=account.City', 'left') - ->join('zones prov', 'prov.zoneid=account.Province', 'left') + ->join('areageo', 'areageo.AreaCode=account.AreaCode', 'left') + ->join('areageo city', 'city.AreaGeoID=account.City', 'left') + ->join('areageo prov', 'prov.AreaGeoID=account.Province', 'left') ->join('valueset country', 'country.VID=account.Country', 'left') ->where('account.AccountID', $AccountID) ->findAll(); diff --git a/app/Models/Organization/DisciplineModel.php b/app/Models/Organization/DisciplineModel.php index 1b2dd4e..a4d2d7a 100644 --- a/app/Models/Organization/DisciplineModel.php +++ b/app/Models/Organization/DisciplineModel.php @@ -13,4 +13,17 @@ class DisciplineModel extends BaseModel { protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; + public function getDisciplines($filter) { + $builder = $this->select('*'); + + if (!empty($filter['DisciplineCode'])) { + $builder->like('DisciplineCode', $filter['DisciplineCode'], 'both'); + } + if (!empty($filter['DisciplineName'])) { + $builder->like('DisciplineName', $filter['DisciplineName'], 'both'); + } + + $rows = $builder->findAll(); + return $rows; + } } diff --git a/app/Models/Organization/SiteModel.php b/app/Models/Organization/SiteModel.php index 1a51cec..f2d4797 100644 --- a/app/Models/Organization/SiteModel.php +++ b/app/Models/Organization/SiteModel.php @@ -14,11 +14,20 @@ class SiteModel extends BaseModel { protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; - public function getSites() { - $rows = $this->select('site.SiteID, site.SiteCode, site.SiteName, s1.SiteName as ParentName, account.AccountName') + public function getSites($filter) { + $builder = $this->select('site.SiteID, site.SiteCode, site.SiteName, s1.SiteName as ParentName, account.AccountName') ->join('account', 'account.AccountID=site.AccountID', 'left') - ->join('site s1', 's1.SiteID=site.Parent', 'left') - ->findAll(); + ->join('site s1', 's1.SiteID=site.Parent', 'left'); + + if (!empty($filter['SiteCode'])) { + $builder->like('site.SiteCode', $filter['SiteCode'], 'both'); + } + if (!empty($filter['SiteName'])) { + $builder->like('site.SiteName', $filter['SiteName'], 'both'); + } + + $rows = $builder->findAll(); + return $rows; } diff --git a/app/Models/Specimen/ContainerDefModel.php b/app/Models/Specimen/ContainerDefModel.php index bec4a8f..b20b1ec 100644 --- a/app/Models/Specimen/ContainerDefModel.php +++ b/app/Models/Specimen/ContainerDefModel.php @@ -15,6 +15,23 @@ class ContainerDefModel extends BaseModel { protected $deletedField = 'EndDate'; + public function getContainers($filter = []) { + $builder = $this->select('containerdef.*, vscol.VValue as ColorTxt, vscla.VValue as ConClassTxt, vsadd.VValue as AdditiveTxt') + ->join('valueset vscol', 'vscol.VID=containerdef.Color', 'left') + ->join('valueset vscla', 'vscla.VID=containerdef.ConClass', 'left') + ->join('valueset vsadd', 'vsadd.VID=containerdef.Additive', 'left'); + + if (!empty($filter['ConCode'])) { + $builder->like('containerdef.ConCode', $filter['ConCode'], 'both'); + } + if (!empty($filter['ConName'])) { + $builder->like('containerdef.ConName', $filter['ConName'], 'both'); + } + + $rows = $builder->findAll(); + return $rows; + } + public function getContainer($ConDefID) { $rows = $this->select('containerdef.*, vscol.VValue as ColorTxt, vscla.VValue as ConClassTxt, vsadd.VValue as AdditiveTxt') ->join('valueset vscol', 'vscol.VID=containerdef.Color', 'left')