From 1cab4d65785134e3525685ca916513c864ab9639 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Tue, 4 Nov 2025 12:22:29 +0700 Subject: [PATCH 1/4] fix organization --- app/Config/Routes.php | 18 +++-- app/Controllers/Organization/Account.php | 73 +++++++++++++++++++ .../Organization/{Workbench.php => Site.php} | 15 ++-- .../2025-10-23-100001_CRM_Organizations.php | 56 +++++++++----- .../2025-10-23-110105_Organization.php | 11 --- app/Models/Organization/AccountModel.php | 18 +++++ .../{WorkbenchModel.php => SiteModel.php} | 9 ++- 7 files changed, 152 insertions(+), 48 deletions(-) create mode 100644 app/Controllers/Organization/Account.php rename app/Controllers/Organization/{Workbench.php => Site.php} (85%) create mode 100644 app/Models/Organization/AccountModel.php rename app/Models/Organization/{WorkbenchModel.php => SiteModel.php} (51%) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index bc30f0b..398871f 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -95,6 +95,18 @@ $routes->patch('/api/containerdef', 'Specimen\ContainerDef::update'); $routes->delete('/api/containerdef', 'Specimen\ContainerDef::delete'); //organization +// account +$routes->get('/api/organization/account/', 'Organization\Account::index'); +$routes->get('/api/organization/account/(:num)', 'Organization\Account::show/$1'); +$routes->post('/api/organization/account', 'Organization\Account::create'); +$routes->patch('/api/organization/account', 'Organization\Account::update'); +$routes->delete('/api/organization/account', 'Organization\Account::delete'); +// site +$routes->get('/api/organization/site/', 'Organization\Site::index'); +$routes->get('/api/organization/site/(:num)', 'Organization\Site::show/$1'); +$routes->post('/api/organization/site', 'Organization\Site::create'); +$routes->patch('/api/organization/site', 'Organization\Site::update'); +$routes->delete('/api/organization/site', 'Organization\Site::delete'); // discipline $routes->get('/api/organization/discipline/', 'Organization\Discipline::index'); $routes->get('/api/organization/discipline/(:num)', 'Organization\Discipline::show/$1'); @@ -113,12 +125,6 @@ $routes->get('/api/organization/workstation/(:num)', 'Organization\Workstation:: $routes->post('/api/organization/workstation', 'Organization\Workstation::create'); $routes->patch('/api/organization/workstation', 'Organization\Workstation::update'); $routes->delete('/api/organization/workstation', 'Organization\Workstation::delete'); -// workbench -$routes->get('/api/organization/workbench/', 'Organization\Workbench::index'); -$routes->get('/api/organization/workbench/(:num)', 'Organization\Workbench::show/$1'); -$routes->post('/api/organization/workbench', 'Organization\Workbench::create'); -$routes->patch('/api/organization/workbench', 'Organization\Workbench::update'); -$routes->delete('/api/organization/workbench', 'Organization\Workbench::delete'); // Khusus $routes->get('/api/zones', 'Zones::index'); diff --git a/app/Controllers/Organization/Account.php b/app/Controllers/Organization/Account.php new file mode 100644 index 0000000..9007ba4 --- /dev/null +++ b/app/Controllers/Organization/Account.php @@ -0,0 +1,73 @@ +db = \Config\Database::connect(); + $this->model = new AccountModel(); + } + + 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); + } + + public function show($AccountID = null) { + $rows = $this->model->where('AccountID', $AccountID)->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); + } + + public function delete() { + try { + $input = $this->request->getJSON(true); + $id = $input["AccountID"]; + 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 update() { + $input = $this->request->getJSON(true); + try { + $id = $input['AccountID']; + if (!$id) { return $this->failValidationErrors('ID is required.'); } + $this->model->update($id, $input); + 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/Workbench.php b/app/Controllers/Organization/Site.php similarity index 85% rename from app/Controllers/Organization/Workbench.php rename to app/Controllers/Organization/Site.php index 60b05d4..38b9b35 100644 --- a/app/Controllers/Organization/Workbench.php +++ b/app/Controllers/Organization/Site.php @@ -4,9 +4,9 @@ namespace App\Controllers\Organization; use CodeIgniter\API\ResponseTrait; use App\Controllers\BaseController; -use App\Models\Organization\WorkbenchModel; +use App\Models\Organization\SiteModel; -class Workbench extends BaseController { +class Site extends BaseController { use ResponseTrait; protected $db; @@ -14,7 +14,7 @@ class Workbench extends BaseController { public function __construct() { $this->db = \Config\Database::connect(); - $this->model = new WorkbenchModel(); + $this->model = new SiteModel(); } public function index() { @@ -27,8 +27,8 @@ class Workbench extends BaseController { return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); } - public function show($WorkbenchID = null) { - $rows = $this->model->where('WorkbenchID', $WorkbenchID)->findAll(); + public function show($SiteID = null) { + $rows = $this->model->where('SiteID', $SiteID)->findAll(); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); @@ -40,7 +40,7 @@ class Workbench extends BaseController { public function delete() { try { $input = $this->request->getJSON(true); - $id = $input["WorkbenchID"]; + $id = $input["SiteID"]; if (!$id) { return $this->failValidationErrors('ID is required.'); } $this->model->delete($id); return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]); @@ -62,7 +62,8 @@ class Workbench extends BaseController { public function update() { $input = $this->request->getJSON(true); try { - $id = $input['WorkbenchID']; + $id = $input['SiteID']; + if (!$id) { return $this->failValidationErrors('ID is required.'); } $this->model->update($id, $input); return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); } catch (\Throwable $e) { diff --git a/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php b/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php index a0d167e..2e3ef30 100644 --- a/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php +++ b/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php @@ -8,30 +8,46 @@ class CreateCRMOrgTable extends Migration { public function up() { $this->forge->addField([ - 'accountid' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true], - 'parrentaccount' => ['type' => 'INT', 'null' => true], - 'accountname' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false], - 'accountnpwp' => ['type' => 'VARCHAR', 'constraint' => 5, 'null' => false], - 'inital' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false], - 'street_1' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], - 'street_2' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], - 'street_3' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], - 'zoneid' => ['type' => 'int', 'null' => true], - 'zip' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true], - 'country' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], - 'email_1' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], - 'email_2' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], - 'phone' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], - 'fax' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], - 'createdate' => ['type' => 'datetime', 'null'=> true], - 'enddate' => ['type' => 'datetime', 'null'=> true] + 'AccountID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true], + 'ParentAccount' => ['type' => 'INT', 'null' => true], + 'AccountName' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false], + 'Inital' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false], + 'Street_1' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], + 'Street_2' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], + 'Street_3' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], + 'City' => ['type' => 'varchar', 'constraint' => 150, 'null' => true], + 'Province' => ['type' => 'varchar', 'constraint' => 150, 'null' => true], + 'Zip' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true], + 'Country' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], + 'AreaCode' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], + 'EmailAddress1' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], + 'EmailAddress2' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], + 'Phone' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], + 'Fax' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], + 'CreateDate' => ['type' => 'datetime', 'null'=> true], + 'EndDate' => ['type' => 'datetime', 'null'=> true] ]); - - $this->forge->addKey('accountid', true); - $this->forge->createTable('accounts'); + $this->forge->addKey('AccountID', true); + $this->forge->createTable('account'); + + $this->forge->addField([ + 'SiteID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true], + 'SiteCode' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false], + 'SiteName' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false], + 'AccountID' => ['type' => 'int', 'null' => true], + 'SiteTypeID' => ['type' => 'int', 'null' => true], + 'Parent' => ['type' => 'int', 'null' => true], + 'SiteClassID' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], + 'ME' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], + 'CreateDate' => ['type' => 'datetime', 'null'=> true], + 'EndDate' => ['type' => 'datetime', 'null'=> true] + ]); + $this->forge->addKey('SiteID', true); + $this->forge->createTable('site'); } public function down() { $this->forge->dropTable('accounts'); + $this->forge->dropTable('sites'); } } \ No newline at end of file diff --git a/app/Database/Migrations/2025-10-23-110105_Organization.php b/app/Database/Migrations/2025-10-23-110105_Organization.php index 34fe3ba..e5451d2 100644 --- a/app/Database/Migrations/2025-10-23-110105_Organization.php +++ b/app/Database/Migrations/2025-10-23-110105_Organization.php @@ -43,22 +43,11 @@ class Organization extends Migration { $this->forge->addKey('WorkstationID', true); $this->forge->createTable('workstation'); - $this->forge->addField([ - 'WorkbenchID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true], - 'DepartmentID' => ['type' => 'int', 'null'=> false], - 'WorkbenchCode' => ['type' => 'varchar', 'constraint'=>10, 'null'=> false], - 'WorkbenchName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true], - 'CreateDate' => ['type'=>'DATETIME', 'null' => true], - 'EndDate' => ['type'=>'DATETIME', 'null' => true] - ]); - $this->forge->addKey('WorkbenchID', true); - $this->forge->createTable('workbench'); } public function down() { $this->forge->dropTable('discipline', true); $this->forge->dropTable('department', true); $this->forge->dropTable('workstation', true); - $this->forge->dropTable('workbench', true); } } diff --git a/app/Models/Organization/AccountModel.php b/app/Models/Organization/AccountModel.php new file mode 100644 index 0000000..96df3e1 --- /dev/null +++ b/app/Models/Organization/AccountModel.php @@ -0,0 +1,18 @@ + Date: Tue, 4 Nov 2025 13:07:04 +0700 Subject: [PATCH 2/4] add dummy data for organization --- .../2025-10-23-100001_CRM_Organizations.php | 4 +-- .../2025-10-23-110105_Organization.php | 1 - app/Database/Seeds/DBSeeder.php | 2 +- app/Database/Seeds/DummySeeder.php | 27 +++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php b/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php index 2e3ef30..61af7e5 100644 --- a/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php +++ b/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php @@ -9,9 +9,9 @@ class CreateCRMOrgTable extends Migration { $this->forge->addField([ 'AccountID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true], - 'ParentAccount' => ['type' => 'INT', 'null' => true], + 'Parent' => ['type' => 'INT', 'null' => true], 'AccountName' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false], - 'Inital' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false], + 'Initial' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false], 'Street_1' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], 'Street_2' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], 'Street_3' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], diff --git a/app/Database/Migrations/2025-10-23-110105_Organization.php b/app/Database/Migrations/2025-10-23-110105_Organization.php index e5451d2..0c8fcd7 100644 --- a/app/Database/Migrations/2025-10-23-110105_Organization.php +++ b/app/Database/Migrations/2025-10-23-110105_Organization.php @@ -36,7 +36,6 @@ class Organization extends Migration { 'Type' => ['type' => 'tinyint', 'null'=> true], 'LinkTo' => ['type' => 'int', 'null'=> true], 'Enable' => ['type' => 'bit', 'null'=> true], - 'EquipmentID' => ['type' => 'varchar', 'constraint'=>'10', 'null'=> true], 'CreateDate' => ['type'=>'DATETIME', 'null' => true], 'EndDate' => ['type'=>'DATETIME', 'null' => true] ]); diff --git a/app/Database/Seeds/DBSeeder.php b/app/Database/Seeds/DBSeeder.php index 5e60c4b..5205c04 100644 --- a/app/Database/Seeds/DBSeeder.php +++ b/app/Database/Seeds/DBSeeder.php @@ -10,4 +10,4 @@ class DBSeeder extends Seeder { $this->call('DummySeeder'); $this->call('CounterSeeder'); } -} +} \ No newline at end of file diff --git a/app/Database/Seeds/DummySeeder.php b/app/Database/Seeds/DummySeeder.php index b6c8819..3cbe194 100644 --- a/app/Database/Seeds/DummySeeder.php +++ b/app/Database/Seeds/DummySeeder.php @@ -94,5 +94,32 @@ class DummySeeder extends Seeder { ['ConCode' => '900','ConName' => 'Packing Pengiriman', 'ConDesc' =>'Specimen Transport Packaging', 'Additive' => "71", 'ConClass' => '81', 'CreateDate'=> "$now"], ]; $this->db->table('containerdef')->insertBatch($data); + + // Organization + $data = [ + [ 'AccountID' => 1, 'Parent' => null, 'AccountName' => 'Dummy Account', 'Initial'=>'QAC', 'Street_1'=>'Dummy Address', 'City'=>'Siti', 'Province'=>'Prop', + 'Zip'=>'505', 'Country'=>'Arab', 'AreaCode'=>'', 'EmailAddress1'=>'dummy@summit.co.id', 'Phone'=>'092029', 'Fax'=>'092029', 'CreateDate' => "$now" ] + ]; + $this->db->table('account')->insertBatch($data); + + $data = [ + [ 'SiteID' => 1, 'SiteCode' => 'QSIT', 'SiteName' => 'Dummy Site', 'AccountID'=>1, 'SiteTypeID'=>null, 'Parent'=>null, 'SiteClassID'=>null, 'ME'=>null, 'CreateDate' => "$now" ] + ]; + $this->db->table('site')->insertBatch($data); + + $data = [ + [ 'DisciplineID' => 1, 'DisciplineCode' => 'QDIS', 'DisciplineName' => 'Dummy Discipline', 'CreateDate' => "$now" ], + ]; + $this->db->table('discipline')->insertBatch($data); + + $data = [ + [ 'DepartmentID' => 1, 'DisciplineID' => 1, 'SiteID' => 1, 'DepartmentCode'=> 'QDEP', 'DepartmentName'=>'Dummy Department', 'CreateDate' => "$now" ], + ]; + $this->db->table('department')->insertBatch($data); + + $data = [ + [ 'WorkstationID' => 1, 'DepartmentID' => 1, 'WorkstationCode' => 'QWST', 'WorkstationName'=>'Dummy Workstation', 'Type'=>null, 'LinkTo'=> null, 'Enable'=>1,'CreateDate' => "$now" ], + ]; + $this->db->table('workstation')->insertBatch($data); } } \ No newline at end of file From 8680454db33d4e325efd6ca4e5a87c1d0e28ff8f Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Wed, 5 Nov 2025 10:35:15 +0700 Subject: [PATCH 3/4] fix account zip and parent --- .../Migrations/2025-10-23-100001_CRM_Organizations.php | 2 +- app/Models/Organization/AccountModel.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php b/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php index 61af7e5..ccad68b 100644 --- a/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php +++ b/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php @@ -17,7 +17,7 @@ class CreateCRMOrgTable extends Migration { 'Street_3' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true], 'City' => ['type' => 'varchar', 'constraint' => 150, 'null' => true], 'Province' => ['type' => 'varchar', 'constraint' => 150, 'null' => true], - 'Zip' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true], + 'ZIP' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true], 'Country' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], 'AreaCode' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], 'EmailAddress1' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], diff --git a/app/Models/Organization/AccountModel.php b/app/Models/Organization/AccountModel.php index 96df3e1..53a00b6 100644 --- a/app/Models/Organization/AccountModel.php +++ b/app/Models/Organization/AccountModel.php @@ -5,8 +5,8 @@ use App\Models\BaseModel; class AccountModel extends BaseModel { protected $table = 'account'; protected $primaryKey = 'AccountID'; - protected $allowedFields = ['ParentAccount', 'AccountName', 'Initial', 'Street_1', 'Street_2', 'Street_3', - 'City', 'Province', 'Zip', 'Country', 'AreaCode', 'EmailAddress1', 'EmailAddress2', + protected $allowedFields = ['Parent', 'AccountName', 'Initial', 'Street_1', 'Street_2', 'Street_3', + 'City', 'Province', 'ZIP', 'Country', 'AreaCode', 'EmailAddress1', 'EmailAddress2', 'Phone', 'Fax', 'CreateDate', 'EndDate']; protected $useTimestamps = true; From 56b8012e4a0412210ab2d5f469f202b774809e12 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Wed, 5 Nov 2025 15:03:55 +0700 Subject: [PATCH 4/4] update join account --- app/Controllers/Organization/Account.php | 6 ++++-- app/Controllers/Zones.php | 12 ++++++++---- app/Database/Seeds/DummySeeder.php | 2 +- app/Database/Seeds/ValueSetSeeder.php | 2 +- app/Models/Organization/AccountModel.php | 19 +++++++++++++++++++ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/Controllers/Organization/Account.php b/app/Controllers/Organization/Account.php index 9007ba4..5598d8c 100644 --- a/app/Controllers/Organization/Account.php +++ b/app/Controllers/Organization/Account.php @@ -18,7 +18,8 @@ class Account extends BaseController { } public function index() { - $rows = $this->model->findAll(); + //$rows = $this->model->findAll(); + $rows = $this->model->getAccounts(); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); @@ -28,7 +29,8 @@ class Account extends BaseController { } public function show($AccountID = null) { - $rows = $this->model->where('AccountID', $AccountID)->findAll(); + //$rows = $this->model->where('AccountID', $AccountID)->findAll(); + $rows = $this->model->getAccount($AccountID); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); diff --git a/app/Controllers/Zones.php b/app/Controllers/Zones.php index 62ea9e1..30935b1 100644 --- a/app/Controllers/Zones.php +++ b/app/Controllers/Zones.php @@ -50,14 +50,18 @@ class Zones extends BaseController { } public function synchronize() { - $client = \Config\Services::curlrequest(); + $client = \Config\Services::curlrequest([ + 'headers' => [ + 'User-Agent' => 'Mozilla/5.0 (CI4 cURL Request)', + 'Accept' => 'application/json', + ], + ]); try { // Ambil data dari API pusat (CRM) - $response = $client->get('http://services-summit.my.id/api/zones'); - // $response = $client->get('http://crmcomposer.local/api/zones'); + $response = $client->get('https://services-summit.my.id/api/zones'); $result = json_decode($response->getBody(), true); - + if (!isset($result['data']) || !is_array($result['data'])) { return $this->response->setJSON([ 'status' => 'error', diff --git a/app/Database/Seeds/DummySeeder.php b/app/Database/Seeds/DummySeeder.php index 3cbe194..d0b3857 100644 --- a/app/Database/Seeds/DummySeeder.php +++ b/app/Database/Seeds/DummySeeder.php @@ -98,7 +98,7 @@ class DummySeeder extends Seeder { // Organization $data = [ [ 'AccountID' => 1, 'Parent' => null, 'AccountName' => 'Dummy Account', 'Initial'=>'QAC', 'Street_1'=>'Dummy Address', 'City'=>'Siti', 'Province'=>'Prop', - 'Zip'=>'505', 'Country'=>'Arab', 'AreaCode'=>'', 'EmailAddress1'=>'dummy@summit.co.id', 'Phone'=>'092029', 'Fax'=>'092029', 'CreateDate' => "$now" ] + 'ZIP'=>'505', 'Country'=>'Arab', 'AreaCode'=>'', 'EmailAddress1'=>'dummy@summit.co.id', 'Phone'=>'092029', 'Fax'=>'092029', 'CreateDate' => "$now" ] ]; $this->db->table('account')->insertBatch($data); diff --git a/app/Database/Seeds/ValueSetSeeder.php b/app/Database/Seeds/ValueSetSeeder.php index 4477701..df69ede 100644 --- a/app/Database/Seeds/ValueSetSeeder.php +++ b/app/Database/Seeds/ValueSetSeeder.php @@ -514,4 +514,4 @@ class ValueSetSeeder extends Seeder { ]; $this->db->table('valuesetdef')->insertBatch($data); } -} +} \ No newline at end of file diff --git a/app/Models/Organization/AccountModel.php b/app/Models/Organization/AccountModel.php index 53a00b6..8e82879 100644 --- a/app/Models/Organization/AccountModel.php +++ b/app/Models/Organization/AccountModel.php @@ -15,4 +15,23 @@ class AccountModel extends BaseModel { protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; + public function getAccounts() { + $rows = $this->select('account.*, pa.AccountName as ParentName, zones.ZoneName as AreaName') + ->join('account pa', 'pa.AccountID=account.Parent', 'left') + ->join('zones', 'zones.zonecode=account.AreaCode', 'left') + ->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') + ->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('valueset country', 'country.VID=account.Country', 'left') + ->where('account.AccountID', $AccountID) + ->findAll(); + return $rows; + } }