Fix database error in complaint field update - remove non-existent updated_at column

BUGFIX: Database error when saving editable complaint fields

PROBLEM: After adding X-Requested-With header, the request reached
the controller but threw 'Database error' when trying to update the
complaint field.

ROOT CAUSE: The ipd_discharge_complaint table does not have an
'updated_at' column. The update query was trying to set:
  - comp_report or comp_remark (correct)
  - updated_at (does not exist) ← DATABASE ERROR

INVESTIGATION: Checked how complaint rows are inserted elsewhere in
the codebase (line 4117-4130). The table has 'update_by' column for
tracking changes, not 'updated_at'.

SOLUTION:
1. Removed hardcoded 'updated_at' => date(...) from update data
2. Only update the target field (comp_report or comp_remark)
3. Conditionally set 'update_by' if column exists (audit trail)
4. Use session full_name for user tracking

Now editable complaint fields save successfully without database errors.
This commit is contained in:
DevSoftTech Server 2026-06-06 05:33:18 +05:30
parent 57691e6a7f
commit 5aad2b0950

View File

@ -2836,12 +2836,16 @@ class Ipd_discharge extends BaseController
$columnName = $fieldType === 'name' ? 'comp_report' : 'comp_remark';
try {
$updateData = [$columnName => $fieldValue];
// Only set update_by if column exists
if ($this->db->fieldExists('update_by', $table)) {
$updateData['update_by'] = $this->session->get('full_name') ?? 'System';
}
$updated = $this->db->table($table)
->where('id', $complaintId)
->update([
$columnName => $fieldValue,
'updated_at' => date('Y-m-d H:i:s')
]);
->update($updateData);
if ($updated) {
return $this->response->setJSON(['success' => true]);