feat(webstatement): tambahkan fitur retry dengan handling timeout pada laporan transaksi ATM

- Memperbarui logika retry pada `AtmTransactionReportController`:
  - Memperbolehkan retry jika status laporan adalah `failed`, `pending`, atau laporan dengan status `processing` yang telah melebihi batas waktu (1 jam).
  - Menambahkan atribut baru seperti `processing_hours` dan `is_processing_timeout` pada data untuk menampilkan informasi durasi proses dan flag timeout.
  - Mengubah status laporan menjadi `failed` jika melebihi batas waktu sebelum dilakukan retry.
  - Memperbarui error message untuk mencatat alasan timeout.

- Menambahkan metode baru `canRetry` pada controller:
  - Mengembalikan boolean jika laporan dapat di-retry berdasarkan status dan kondisi laporan.

- Memperbarui tampilan untuk bagian daftar laporan (`atm-reports/index.blade.php`):
  - Menambahkan tombol retry dengan warna yang disesuaikan (kuning/oranye untuk `failed`/`pending`, merah untuk timeout).
  - Memperbarui tampilan status laporan menjadi lebih informatif, termasuk keterangan durasi proses jika timeout.

- Memperbarui tampilan detail laporan (`atm-reports/show.blade.php`):
  - Menambahkan tombol retry dengan label tambahan "Retry (Timeout)" jika melebihi batas waktu proses.
  - Menampilkan informasi tambahan seperti waktu proses jika laporan dalam status `processing`.

- Menyediakan fungsi JavaScript baru `retryReport` untuk handling retry via AJAX:
  - Menyertakan konfirmasi sebelum retry.
  - Memperbarui tombol retry agar lebih reaktif terhadap perubahan status laporan.

Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
Daeng Deni Mardaeni
2025-06-10 11:17:17 +07:00
parent 8a7d4f351c
commit 55313fb0b0
3 changed files with 119 additions and 35 deletions

View File

@@ -210,11 +210,17 @@ class AtmTransactionReportController extends Controller
// Get the data for the current page
$data = $query->get()->map(function ($item) {
$processingHours = $item->status === 'processing' ? $item->updated_at->diffInHours(now()) : 0;
$isProcessingTimeout = $item->status === 'processing' && $processingHours >= 1;
return [
'id' => $item->id,
'period' => $item->period,
'report_date' => Carbon::createFromFormat('Ymd', $item->period)->format('Y-m-d'),
'status' => $item->status,
'status_display' => $item->status . ($isProcessingTimeout ? ' (Timeout)' : ''),
'processing_hours' => $processingHours,
'is_processing_timeout' => $isProcessingTimeout,
'authorization_status' => $item->authorization_status,
'is_downloaded' => $item->is_downloaded,
'created_at' => dateFormat($item->created_at, 1, 1),
@@ -222,6 +228,7 @@ class AtmTransactionReportController extends Controller
'authorized_by' => $item->authorizer ? $item->authorizer->name : null,
'authorized_at' => $item->authorized_at ? $item->authorized_at->format('Y-m-d H:i:s') : null,
'file_path' => $item->file_path,
'can_retry' => in_array($item->status, ['failed', 'pending']) || $isProcessingTimeout || ($item->status === 'completed' && !$item->file_path),
];
});
@@ -298,13 +305,26 @@ class AtmTransactionReportController extends Controller
*/
public function retry(AtmTransactionReportLog $atmReport)
{
// Check if retry is allowed (only for failed or pending status)
if (!in_array($atmReport->status, ['failed', 'pending'])) {
return back()->with('error', 'Report can only be retried if status is failed or pending.');
// Check if retry is allowed (failed, pending, or processing for more than 1 hour)
$allowedStatuses = ['failed', 'pending'];
$isProcessingTooLong = $atmReport->status === 'processing' &&
$atmReport->updated_at->diffInHours(now()) >= 1;
if (!in_array($atmReport->status, $allowedStatuses) && !$isProcessingTooLong) {
return back()->with('error', 'Report can only be retried if status is failed, pending, or processing for more than 1 hour.');
}
try {
// Reset the report status and clear error message
// If it was processing for too long, mark it as failed first
if ($isProcessingTooLong) {
$atmReport->update([
'status' => 'failed',
'error_message' => 'Processing timeout - exceeded 1 hour limit',
'updated_by' => Auth::id()
]);
}
// Reset the report status and clear previous data
$atmReport->update([
'status' => 'processing',
'error_message' => null,
@@ -329,4 +349,18 @@ class AtmTransactionReportController extends Controller
return back()->with('error', 'Failed to retry report generation: ' . $e->getMessage());
}
}
/**
* Check if report can be retried
*/
public function canRetry(AtmTransactionReportLog $atmReport)
{
$allowedStatuses = ['failed', 'pending'];
$isProcessingTooLong = $atmReport->status === 'processing' &&
$atmReport->updated_at->diffInHours(now()) >= 1;
return in_array($atmReport->status, $allowedStatuses) ||
$isProcessingTooLong ||
($atmReport->status === 'completed' && !$atmReport->file_path);
}
}