feat(webstatement): tambahkan pengaturan ekspor dan optimasi fungsionalitas print statement
- **Pembaruan pada `ExportStatementPeriodJob`:** - Menambahkan atribut baru `toCsv` untuk mendukung validasi sebelum proses ekspor CSV. - Menyesuaikan method `__construct` untuk menerima parameter tambahan `toCsv`. - Menambahkan validasi ekspor CSV dengan conditional check pada `toCsv` sebelum menjalankan `exportToCsv`. - Memperbaiki logika di `getTotalEntryCount` menggunakan `booking_date` untuk query lebih akurat. - Menambahkan logging terperinci pada proses penghitungan jumlah entri untuk meningkatkan debugging. - **Integrasi Log Print Statement:** - Mengupdate status kolom `is_generated` pada model `PrintStatementLog` setelah entri diproses. - Menambahkan mekanisme pembaruan data log print statement melalui validasi entry statement. - **Peningkatan pada Controller `PrintStatementController`:** - Memampukan proses ekspor otomatis jika statement tidak tersedia dengan metode baru `printStatementRekening`. - Menambahkan parameter `stmt_sent_type` untuk log print pada proses pencatatan data. - Mengimplementasikan pemrosesan period statement melalui job `ExportStatementPeriodJob`. - **Perubahan pada UI/Blade `statements/index`:** - Menambahkan opsi pemilihan multiple untuk tipe laporan `stmt_sent_type`. - Mengupdate dan merapikan komponen form untuk input branch, akun, email, dan periode laporan. - Menambahkan kolom baru `is_generated` pada tabel untuk menampilkan status log hasil pembuatan laporan. - **Pembaruan pada Datatable dan Skrip Frontend:** - Menambahkan render visual dengan badge untuk status `is_generated`. - Memperbaiki dan mengoptimalkan element HTML untuk datatable termasuk pagination dan search. - Menambahkan konfirmasi aksi dengan Ajax untuk retry pembuatan laporan jika diperlukan. - **Optimisasi dan Refactor:** - Menggunakan group import pada controller untuk meningkatkan keterbacaan. - Memperbaiki alignment dan indentasi pada beberapa file blade. - Menghapus kode yang tidak digunakan atau redundan seperti conditional unprocessed data. Dengan perubahan ini, sistem print statement lebih fleksibel, mencatat log lebih baik, dan mendukung fitur tracking pengeluaran laporan. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@ use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Modules\Webstatement\Models\PrintStatementLog;
|
||||
use Modules\Webstatement\Models\ProcessedStatement;
|
||||
use Modules\Webstatement\Models\StmtEntry;
|
||||
use Modules\Webstatement\Models\TempFundsTransfer;
|
||||
@@ -31,6 +32,7 @@ class ExportStatementPeriodJob implements ShouldQueue
|
||||
protected $chunkSize = 1000;
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
protected $toCsv;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
@@ -41,7 +43,7 @@ class ExportStatementPeriodJob implements ShouldQueue
|
||||
* @param string $client
|
||||
* @param string $disk
|
||||
*/
|
||||
public function __construct(string $account_number, string $period, string $saldo, string $client = '', string $disk = 'local')
|
||||
public function __construct(string $account_number, string $period, string $saldo, string $client = '', string $disk = 'local', bool $toCsv = true)
|
||||
{
|
||||
$this->account_number = $account_number;
|
||||
$this->period = $period;
|
||||
@@ -49,6 +51,7 @@ class ExportStatementPeriodJob implements ShouldQueue
|
||||
$this->disk = $disk;
|
||||
$this->client = $client;
|
||||
$this->fileName = "{$account_number}_{$period}.csv";
|
||||
$this->toCsv = $toCsv;
|
||||
|
||||
// Calculate start and end dates based on period
|
||||
$this->calculatePeriodDates();
|
||||
@@ -84,8 +87,9 @@ class ExportStatementPeriodJob implements ShouldQueue
|
||||
Log::info("Date range: {$this->startDate->format('Y-m-d')} to {$this->endDate->format('Y-m-d')}");
|
||||
|
||||
$this->processStatementData();
|
||||
$this->exportToCsv();
|
||||
|
||||
if($this->toCsv){
|
||||
$this->exportToCsv();
|
||||
}
|
||||
Log::info("Export statement period job completed successfully for account: {$this->account_number}, period: {$this->period}");
|
||||
} catch (Exception $e) {
|
||||
Log::error("Error in ExportStatementPeriodJob: " . $e->getMessage());
|
||||
@@ -104,20 +108,28 @@ class ExportStatementPeriodJob implements ShouldQueue
|
||||
$existingDataCount = $this->getExistingProcessedCount($accountQuery);
|
||||
|
||||
// Only process if data is not fully processed
|
||||
if ($existingDataCount !== $totalCount) {
|
||||
//if ($existingDataCount !== $totalCount) {
|
||||
$this->deleteExistingProcessedData($accountQuery);
|
||||
$this->processAndSaveStatementEntries($totalCount);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
private function getTotalEntryCount(): int
|
||||
{
|
||||
return StmtEntry::where('account_number', $this->account_number)
|
||||
->whereBetween('date_time', [
|
||||
$this->startDate->format('ymdHi'),
|
||||
$this->endDate->format('ymdHi')
|
||||
])
|
||||
->count();
|
||||
$query = StmtEntry::where('account_number', $this->account_number)
|
||||
->whereBetween('booking_date', [
|
||||
$this->startDate->format('Ymd'),
|
||||
$this->endDate->format('Ymd')
|
||||
]);
|
||||
|
||||
Log::info("Getting total entry count with query: " . $query->toSql(), [
|
||||
'bindings' => $query->getBindings(),
|
||||
'account' => $this->account_number,
|
||||
'start_date' => $this->startDate->format('Ymd'),
|
||||
'end_date' => $this->endDate->format('Ymd')
|
||||
]);
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
private function getExistingProcessedCount(array $criteria): int
|
||||
@@ -141,11 +153,11 @@ class ExportStatementPeriodJob implements ShouldQueue
|
||||
|
||||
Log::info("Processing {$totalCount} statement entries for account: {$this->account_number}");
|
||||
|
||||
StmtEntry::with(['ft', 'transaction'])
|
||||
$entry = StmtEntry::with(['ft', 'transaction'])
|
||||
->where('account_number', $this->account_number)
|
||||
->whereBetween('date_time', [
|
||||
$this->startDate->format('ymdHi'),
|
||||
$this->endDate->format('ymdHi')
|
||||
->whereBetween('booking_date', [
|
||||
$this->startDate->format('Ymd'),
|
||||
$this->endDate->format('Ymd')
|
||||
])
|
||||
->orderBy('date_time', 'ASC')
|
||||
->orderBy('trans_reference', 'ASC')
|
||||
@@ -156,6 +168,16 @@ class ExportStatementPeriodJob implements ShouldQueue
|
||||
DB::table('processed_statements')->insert($processedData);
|
||||
}
|
||||
});
|
||||
|
||||
if($entry){
|
||||
$printLog = PrintStatementLog::where('account_number', $this->account_number)
|
||||
->where('period_from', $this->period)
|
||||
->latest()
|
||||
->first();
|
||||
if($printLog){
|
||||
$printLog->update(['is_generated' => true]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareProcessedData($entries, &$runningBalance, &$globalSequence): array
|
||||
@@ -166,14 +188,13 @@ class ExportStatementPeriodJob implements ShouldQueue
|
||||
$globalSequence++;
|
||||
$runningBalance += (float) $item->amount_lcy;
|
||||
|
||||
$transactionDate = $this->formatTransactionDate($item);
|
||||
$actualDate = $this->formatActualDate($item);
|
||||
|
||||
$processedData[] = [
|
||||
'account_number' => $this->account_number,
|
||||
'period' => $this->period,
|
||||
'sequence_no' => $globalSequence,
|
||||
'transaction_date' => $transactionDate,
|
||||
'transaction_date' => $item->booking_date,
|
||||
'reference_number' => $item->trans_reference,
|
||||
'transaction_amount' => $item->amount_lcy,
|
||||
'transaction_type' => $item->amount_lcy < 0 ? 'D' : 'C',
|
||||
|
||||
Reference in New Issue
Block a user