till discipline

This commit is contained in:
mahdahar 2025-12-02 07:09:24 +07:00
parent 09717bb081
commit 1755105af1
10 changed files with 212 additions and 155 deletions

View File

@ -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');

View File

@ -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) {

View File

@ -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() );
}
*/
}
}

View File

@ -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);

View File

@ -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());
}
}
}

View File

@ -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());
}

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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')