feat: auto visit-done on scan save and add scan delete actions
This commit is contained in:
parent
f748224cd0
commit
7233f5979e
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -25,11 +25,7 @@
|
|||
<div class="small text-muted">
|
||||
Uploaded: <?= esc($item['insert_date'] ?? '') ?>
|
||||
</div>
|
||||
<?php if ((int) ($item['can_delete_today'] ?? 0) === 1) : ?>
|
||||
<button type="button" class="btn btn-outline-danger btn-sm" onclick="deleteOpdScanFromList(<?= (int) ($item['id'] ?? 0) ?>, <?= (int) ($opdid ?? 0) ?>)">Delete</button>
|
||||
<?php else : ?>
|
||||
<span class="badge bg-secondary">Delete allowed only for today upload</span>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="btn btn-outline-danger btn-sm" onclick="deleteOpdScanFromList(<?= (int) ($item['id'] ?? 0) ?>, <?= (int) ($opdid ?? 0) ?>)">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
<div class="small text-muted mt-1" style="line-height:1.2"><?= nl2br(esc((string) ($item['content_description'] ?? ''))) ?></div>
|
||||
<?php } ?>
|
||||
<div class="small text-muted mt-1"><?= esc($item['insert_date'] ?? '') ?></div>
|
||||
<button type="button" class="btn btn-link btn-sm text-danger p-0" onclick="removeOpdScanImage(<?= (int) ($item['id'] ?? 0) ?>)">Hide</button>
|
||||
<button type="button" class="btn btn-link btn-sm text-danger p-0" onclick="removeOpdScanImage(<?= (int) ($item['id'] ?? 0) ?>)">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
<?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('<?= base_url('Opd/opd_file_hide') ?>/' + 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('<?= base_url('Opd/opd_file_delete') ?>/' + fileId, payload, function(resp) {
|
||||
updateCsrf(resp || {});
|
||||
if (!resp || parseInt(resp.update || 0, 10) !== 1) {
|
||||
$results.html('<div class="text-danger">' + ((resp && resp.error_text) ? $('<div>').text(resp.error_text).html() : 'Unable to delete scan file.') + '</div>');
|
||||
return;
|
||||
}
|
||||
loadLastList();
|
||||
$results.html('<div class="text-success">Scan deleted successfully.</div>');
|
||||
}, 'json').fail(function() {
|
||||
$results.html('<div class="text-danger">Unable to delete scan file.</div>');
|
||||
});
|
||||
};
|
||||
|
||||
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.');
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user