Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
<?php
|
2026-01-19 06:37:37 +07:00
|
|
|
namespace App\Controllers\Qc;
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
use CodeIgniter\API\ResponseTrait;
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
use App\Controllers\BaseController;
|
2026-01-19 06:37:37 +07:00
|
|
|
use App\Models\Qc\ResultsModel;
|
|
|
|
|
|
|
|
|
|
class ResultsController extends BaseController {
|
|
|
|
|
use ResponseTrait;
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
protected $model;
|
2026-01-15 10:44:09 +07:00
|
|
|
protected $rules;
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
public function __construct() {
|
|
|
|
|
$this->model = new ResultsModel();
|
|
|
|
|
$this->rules = [];
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
}
|
|
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
public function index() {
|
|
|
|
|
$keyword = $this->request->getGet('keyword');
|
2026-01-15 10:44:09 +07:00
|
|
|
try {
|
2026-01-19 06:37:37 +07:00
|
|
|
$rows = $this->model->search($keyword);
|
2026-01-15 10:44:09 +07:00
|
|
|
return $this->respond([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => 'fetch success',
|
|
|
|
|
'data' => $rows
|
|
|
|
|
], 200);
|
|
|
|
|
} catch (\Exception $e) {
|
2026-01-19 06:37:37 +07:00
|
|
|
return $this->failServerError($e->getMessage());
|
2026-01-15 10:44:09 +07:00
|
|
|
}
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
}
|
|
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
public function show($id = null) {
|
2026-01-15 10:44:09 +07:00
|
|
|
try {
|
2026-01-19 06:37:37 +07:00
|
|
|
$row = $this->model->find($id);
|
|
|
|
|
if (!$row) {
|
2026-01-15 10:44:09 +07:00
|
|
|
return $this->respond([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => 'data not found.'
|
|
|
|
|
], 200);
|
|
|
|
|
}
|
|
|
|
|
return $this->respond([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => 'fetch success',
|
2026-01-19 06:37:37 +07:00
|
|
|
'data' => [$row]
|
2026-01-15 10:44:09 +07:00
|
|
|
], 200);
|
|
|
|
|
} catch (\Exception $e) {
|
2026-01-19 06:37:37 +07:00
|
|
|
return $this->failServerError($e->getMessage());
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
public function create() {
|
2026-01-15 10:44:09 +07:00
|
|
|
$input = $this->request->getJSON(true);
|
2026-01-19 06:37:37 +07:00
|
|
|
$input = camel_to_snake_array($input);
|
2026-01-15 10:44:09 +07:00
|
|
|
if (!$this->validate($this->rules)) {
|
|
|
|
|
return $this->failValidationErrors($this->validator->getErrors());
|
|
|
|
|
}
|
|
|
|
|
try {
|
2026-01-19 06:37:37 +07:00
|
|
|
$id = $this->model->insert($input, true);
|
2026-01-15 10:44:09 +07:00
|
|
|
return $this->respondCreated([
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
'status' => 'success',
|
2026-01-15 10:44:09 +07:00
|
|
|
'message' => $id
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
]);
|
2026-01-15 10:44:09 +07:00
|
|
|
} catch (\Exception $e) {
|
2026-01-19 06:37:37 +07:00
|
|
|
return $this->failServerError($e->getMessage());
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
public function update($id = null) {
|
2026-01-15 10:44:09 +07:00
|
|
|
$input = $this->request->getJSON(true);
|
2026-01-19 06:37:37 +07:00
|
|
|
$input = camel_to_snake_array($input);
|
2026-01-15 10:44:09 +07:00
|
|
|
if (!$this->validate($this->rules)) {
|
|
|
|
|
return $this->failValidationErrors($this->validator->getErrors());
|
|
|
|
|
}
|
|
|
|
|
try {
|
2026-01-19 06:37:37 +07:00
|
|
|
$this->model->update($id, $input);
|
2026-01-15 10:44:09 +07:00
|
|
|
return $this->respond([
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
'status' => 'success',
|
2026-01-15 10:44:09 +07:00
|
|
|
'message' => 'update success',
|
2026-01-19 06:37:37 +07:00
|
|
|
'data' => [$id]
|
|
|
|
|
], 200);
|
2026-01-15 10:44:09 +07:00
|
|
|
} catch (\Exception $e) {
|
2026-01-19 06:37:37 +07:00
|
|
|
return $this->failServerError($e->getMessage());
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
public function delete($id = null) {
|
2026-01-15 10:44:09 +07:00
|
|
|
try {
|
2026-01-19 06:37:37 +07:00
|
|
|
$this->model->delete($id);
|
2026-01-15 10:44:09 +07:00
|
|
|
return $this->respond([
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
'status' => 'success',
|
2026-01-19 06:37:37 +07:00
|
|
|
'message' => 'delete success',
|
|
|
|
|
'data' => [$id]
|
|
|
|
|
], 200);
|
2026-01-15 10:44:09 +07:00
|
|
|
} catch (\Exception $e) {
|
2026-01-19 06:37:37 +07:00
|
|
|
return $this->failServerError($e->getMessage());
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|