From 7233f5979eb4aab5e237a4fd749a5b06704e2992 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sat, 11 Apr 2026 04:45:45 +0530 Subject: [PATCH] feat: auto visit-done on scan save and add scan delete actions --- app/Controllers/Opd.php | 32 ++++++++++++------- app/Views/billing/opd_scan_carousel_list.php | 6 +--- app/Views/billing/opd_scan_last_list.php | 2 +- app/Views/billing/opd_scan_modal_body.php | 33 +++++++++++--------- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index d3ee82a..661feed 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -4939,6 +4939,25 @@ class Opd extends BaseController } } + $opdStatusUpdated = 0; + if ($insertId > 0 && $this->db->tableExists('opd_master')) { + $opdFields = $this->db->getFieldNames('opd_master') ?? []; + $currentStatus = (int) ($opdRow['opd_status'] ?? 0); + if ($currentStatus !== 2 && $currentStatus !== 3) { + $statusUpdate = []; + if (in_array('opd_status', $opdFields, true)) { + $statusUpdate['opd_status'] = 2; + } + if (in_array('opd_status_remark', $opdFields, true)) { + $statusUpdate['opd_status_remark'] = 'Auto Visit Done after scan upload'; + } + if (! empty($statusUpdate)) { + $this->db->table('opd_master')->where('opd_id', $opdid)->update($statusUpdate); + $opdStatusUpdated = 1; + } + } + } + return $this->response->setJSON([ 'update' => 1, 'filename' => $filename, @@ -4950,6 +4969,8 @@ class Opd extends BaseController 'opd_session_id' => 0, 'target_field' => '', 'ai_status' => 'pending', + 'opd_status' => 2, + 'opd_status_updated' => $opdStatusUpdated, 'error_text' => 'File uploaded successfully', 'csrfName' => csrf_token(), 'csrfHash' => csrf_hash(), @@ -5231,17 +5252,6 @@ class Opd extends BaseController ]); } - $insertDate = (string) ($row['insert_date'] ?? ''); - $isToday = $insertDate !== '' && date('Y-m-d', strtotime($insertDate)) === date('Y-m-d'); - if (! $isToday) { - return $this->response->setJSON([ - 'update' => 0, - 'error_text' => 'Delete allowed only for current date uploads', - 'csrfName' => csrf_token(), - 'csrfHash' => csrf_hash(), - ]); - } - $fullPath = (string) ($row['full_path'] ?? ''); if ($fullPath !== '' && is_file($fullPath)) { @unlink($fullPath); diff --git a/app/Views/billing/opd_scan_carousel_list.php b/app/Views/billing/opd_scan_carousel_list.php index 0d9856d..2caaa4c 100644 --- a/app/Views/billing/opd_scan_carousel_list.php +++ b/app/Views/billing/opd_scan_carousel_list.php @@ -25,11 +25,7 @@
Uploaded:
- - - - Delete allowed only for today upload - + diff --git a/app/Views/billing/opd_scan_last_list.php b/app/Views/billing/opd_scan_last_list.php index c30ad96..0939c97 100644 --- a/app/Views/billing/opd_scan_last_list.php +++ b/app/Views/billing/opd_scan_last_list.php @@ -30,7 +30,7 @@
- + diff --git a/app/Views/billing/opd_scan_modal_body.php b/app/Views/billing/opd_scan_modal_body.php index dbb5631..6934f18 100644 --- a/app/Views/billing/opd_scan_modal_body.php +++ b/app/Views/billing/opd_scan_modal_body.php @@ -57,7 +57,6 @@ var $textBox = $('#opd_scan_text_box'); var $aiResult = $('#opd_scan_ai_result'); var opdid = parseInt($('#opd_scan_opdid').val() || '0', 10); - var listPollingTimer = null; var latestFileId = 0; function getCsrfPair() { @@ -167,13 +166,6 @@ queueAiProcessing(latestFileId); } - function startListPolling() { - if (listPollingTimer) { - clearInterval(listPollingTimer); - } - listPollingTimer = setInterval(loadLastList, 5000); - } - function submitScanFormData(formData) { // Common upload handler used by both camera capture and file upload. $.ajax({ @@ -287,21 +279,32 @@ if (!fileId) { return; } - $.post('/' + fileId, {}, function(html) { - $('#opd_scan_list').html(html || ''); + if (!window.confirm('Delete this scan file?')) { + return; + } + + var csrf = getCsrfPair(); + var payload = {}; + payload[csrf.name] = csrf.value; + + $.post('/' + fileId, payload, function(resp) { + updateCsrf(resp || {}); + if (!resp || parseInt(resp.update || 0, 10) !== 1) { + $results.html('
' + ((resp && resp.error_text) ? $('
').text(resp.error_text).html() : 'Unable to delete scan file.') + '
'); + return; + } + loadLastList(); + $results.html('
Scan deleted successfully.
'); + }, 'json').fail(function() { + $results.html('
Unable to delete scan file.
'); }); }; startCamera(); loadLastList(); - startListPolling(); $('#tallModal').off('hidden.bs.modal.opdscan').on('hidden.bs.modal.opdscan', function() { stopCamera(); - if (listPollingTimer) { - clearInterval(listPollingTimer); - listPollingTimer = null; - } $('#opd_scan_results').html('Captured image will appear here.'); }); })();