refactor(webstatement): improve code readability and consistency in ExportStatementJob
- Menambahkan tipe return untuk beberapa method agar lebih eksplisit dan konsisten. - Memperbaiki indentasi dan alignment parameter untuk meningkatkan keterbacaan. - Menghapus method `getTransaction` dan memindahkannya ke bagian akhir kode dengan dokumentasi ulang. - Menambahkan logika untuk menghapus file CSV yang sudah ada sebelum membuat file baru di method `exportToCsv`. - Mengoreksi format data dan whitespace pada beberapa bagian kode untuk menjaga standar penulisan. - Memindahkan komentar terkait dokumentasi method ke posisi yang lebih relevan dan terstruktur. - Memastikan konsistensi penggunaan tanda kurung kurawal dan spasi pada query database agar lebih seragam. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -67,14 +67,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
private function processStatementData(): void
|
||||
private function processStatementData()
|
||||
: void
|
||||
{
|
||||
$accountQuery = [
|
||||
'account_number' => $this->account_number,
|
||||
'period' => $this->period
|
||||
'period' => $this->period
|
||||
];
|
||||
|
||||
$totalCount = $this->getTotalEntryCount($accountQuery);
|
||||
$totalCount = $this->getTotalEntryCount($accountQuery);
|
||||
$existingDataCount = $this->getExistingProcessedCount($accountQuery);
|
||||
|
||||
// Hanya proses jika data belum lengkap diproses
|
||||
@@ -84,28 +85,32 @@
|
||||
}
|
||||
}
|
||||
|
||||
private function getTotalEntryCount(array $criteria): int
|
||||
private function getTotalEntryCount(array $criteria)
|
||||
: int
|
||||
{
|
||||
return StmtEntry::where('account_number', $criteria['account_number'])
|
||||
->where('booking_date', $criteria['period'])
|
||||
->count();
|
||||
->where('booking_date', $criteria['period'])
|
||||
->count();
|
||||
}
|
||||
|
||||
private function getExistingProcessedCount(array $criteria): int
|
||||
private function getExistingProcessedCount(array $criteria)
|
||||
: int
|
||||
{
|
||||
return ProcessedStatement::where('account_number', $criteria['account_number'])
|
||||
->where('period', $criteria['period'])
|
||||
->count();
|
||||
}
|
||||
|
||||
private function deleteExistingProcessedData(array $criteria): void
|
||||
private function deleteExistingProcessedData(array $criteria)
|
||||
: void
|
||||
{
|
||||
ProcessedStatement::where('account_number', $criteria['account_number'])
|
||||
->where('period', $criteria['period'])
|
||||
->delete();
|
||||
}
|
||||
|
||||
private function processAndSaveStatementEntries(int $totalCount): void
|
||||
private function processAndSaveStatementEntries(int $totalCount)
|
||||
: void
|
||||
{
|
||||
$runningBalance = (float) $this->saldo;
|
||||
$globalSequence = 0;
|
||||
@@ -113,20 +118,21 @@
|
||||
Log::info("Processing {$totalCount} statement entries for account: {$this->account_number}");
|
||||
|
||||
StmtEntry::with(['ft', 'transaction'])
|
||||
->where('account_number', $this->account_number)
|
||||
->where('booking_date', $this->period)
|
||||
->orderBy('date_time', 'ASC')
|
||||
->orderBy('trans_reference', 'ASC')
|
||||
->chunk($this->chunkSize, function ($entries) use (&$runningBalance, &$globalSequence) {
|
||||
$processedData = $this->prepareProcessedData($entries, $runningBalance, $globalSequence);
|
||||
->where('account_number', $this->account_number)
|
||||
->where('booking_date', $this->period)
|
||||
->orderBy('date_time', 'ASC')
|
||||
->orderBy('trans_reference', 'ASC')
|
||||
->chunk($this->chunkSize, function ($entries) use (&$runningBalance, &$globalSequence) {
|
||||
$processedData = $this->prepareProcessedData($entries, $runningBalance, $globalSequence);
|
||||
|
||||
if (!empty($processedData)) {
|
||||
DB::table('processed_statements')->insert($processedData);
|
||||
}
|
||||
});
|
||||
if (!empty($processedData)) {
|
||||
DB::table('processed_statements')->insert($processedData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function prepareProcessedData($entries, &$runningBalance, &$globalSequence): array
|
||||
private function prepareProcessedData($entries, &$runningBalance, &$globalSequence)
|
||||
: array
|
||||
{
|
||||
$processedData = [];
|
||||
|
||||
@@ -135,7 +141,7 @@
|
||||
$runningBalance += (float) $item->amount_lcy;
|
||||
|
||||
$transactionDate = $this->formatTransactionDate($item);
|
||||
$actualDate = $this->formatActualDate($item);
|
||||
$actualDate = $this->formatActualDate($item);
|
||||
|
||||
$processedData[] = [
|
||||
'account_number' => $this->account_number,
|
||||
@@ -156,7 +162,8 @@
|
||||
return $processedData;
|
||||
}
|
||||
|
||||
private function formatTransactionDate($item): string
|
||||
private function formatTransactionDate($item)
|
||||
: string
|
||||
{
|
||||
try {
|
||||
return Carbon::createFromFormat(
|
||||
@@ -169,7 +176,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
private function formatActualDate($item): string
|
||||
private function formatActualDate($item)
|
||||
: string
|
||||
{
|
||||
try {
|
||||
return Carbon::createFromFormat(
|
||||
@@ -281,16 +289,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
return str_replace('<NL>','',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transaction data by reference and field
|
||||
*/
|
||||
private function getTransaction($ref, $field)
|
||||
{
|
||||
$trans = TempFundsTransfer::where('ref_no', $ref)->first();
|
||||
return $trans->$field ?? "";
|
||||
return str_replace('<NL>', '', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,6 +298,11 @@
|
||||
private function exportToCsv()
|
||||
: void
|
||||
{
|
||||
// Delete existing file if it exists
|
||||
if (Storage::disk($this->disk)->exists("statements/{$this->fileName}")) {
|
||||
Storage::disk($this->disk)->delete("statements/{$this->fileName}");
|
||||
}
|
||||
|
||||
$csvContent = "NO|TRANSACTION.DATE|REFERENCE.NUMBER|TRANSACTION.AMOUNT|TRANSACTION.TYPE|DESCRIPTION|END.BALANCE|ACTUAL.DATE\n";
|
||||
|
||||
// Ambil data yang sudah diproses dalam chunk untuk mengurangi penggunaan memori
|
||||
@@ -326,4 +330,13 @@
|
||||
|
||||
Log::info("Statement exported to {$this->disk} disk: statements/{$this->fileName}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transaction data by reference and field
|
||||
*/
|
||||
private function getTransaction($ref, $field)
|
||||
{
|
||||
$trans = TempFundsTransfer::where('ref_no', $ref)->first();
|
||||
return $trans->$field ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user