Add cancel_email endpoint: only cancels when status is S

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sas.fajri
2026-05-24 22:13:02 +07:00
parent 6dec35217f
commit bc8b0dd0df

View File

@@ -371,5 +371,62 @@ class Done extends MY_Controller
}
}
function cancel_email()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
return;
}
$prm = $this->sys_input;
$userid = isset($this->sys_user['M_UserID']) ? $this->sys_user['M_UserID'] : 0;
$order_header_id = isset($prm['T_OrderHeaderID']) ? (int) $prm['T_OrderHeaderID'] : 0;
$recepient_email = isset($prm['T_SendEmailRecepient']) ? trim($prm['T_SendEmailRecepient']) : '';
if ($order_header_id == 0 || $recepient_email == '') {
$this->sys_error("Order ID dan Email wajib diisi");
return;
}
// Hanya boleh cancel jika status masih S (Sending/queued)
$check = $this->db_onedev->query("
SELECT T_SendEmailID, T_SendEmailStatus
FROM t_send_email
WHERE T_SendEmailT_OrderHeaderID = ?
AND T_SendEmailRecepient = ?
AND T_SendEmailIsActive = 'Y'
LIMIT 1
", [$order_header_id, $recepient_email])->row_array();
if (!$check) {
$this->sys_error("Data email tidak ditemukan");
return;
}
if ($check['T_SendEmailStatus'] !== 'S') {
$this->sys_error("Tidak bisa dicancel, status saat ini: " . $check['T_SendEmailStatus']);
return;
}
$this->db_onedev->query("
UPDATE t_send_email
SET T_SendEmailStatus = 'C',
T_SendEmailLastUpdated = NOW(),
T_SendEmailLastUpdatedUserID = ?
WHERE T_SendEmailID = ?
", [$userid, $check['T_SendEmailID']]);
$this->sys_ok([
"status" => "OK",
"message" => "Email berhasil dicancel"
]);
} catch (Exception $e) {
$this->sys_error($e->getMessage());
}
}
}