From 5d0dbfcf21b3609b0429f82794226db3d1d74b73 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Tue, 9 Sep 2025 08:51:53 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20refactor(jobs):=20perbaikan=20lo?= =?UTF-8?q?gika=20pada=20beberapa=20controller=20dan=20job?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - **WebstatementController.php**: - Menyederhanakan fungsi `index()` dengan mengubah parameter menjadi langsung `string $queueName='default'`. - Menghapus pengambilan parameter `$queueName` dari objek `Request`. - **ExportStatementPeriodJob.php**: - Memperbaiki perhitungan saldo berjalan (`running balance`) dengan mempertimbangkan mata uang. - Menambahkan logika penggunaan `amount_fcy` jika mata uang bukan IDR. - Menyesuaikan tipe transaksi (D/C) menggunakan nilai `amount` yang telah disesuaikan. - **GenerateBiayaKartuCsvJob.php**: - Mengubah daftar produk yang dikecualikan menjadi `['6031','6021','6042']`. - Memperbaiki filter khusus dengan mengecualikan `product_code` 6004 jika `ctdesc` = CLASSIC. - Menambahkan kolom hash unik 16 digit pada data CSV untuk identifikasi setiap record. - **ProcessCustomerDataJob.php**: - Menambahkan mapping baru `name_1` → `name` pada `getHeaderMapping`. - Menambahkan logging untuk field `fillable` agar debugging lebih mudah. --- .../Controllers/WebstatementController.php | 4 +--- app/Jobs/ExportStatementPeriodJob.php | 12 ++++++---- app/Jobs/GenerateBiayaKartuCsvJob.php | 23 ++++++++++--------- app/Jobs/ProcessCustomerDataJob.php | 5 ++-- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/WebstatementController.php b/app/Http/Controllers/WebstatementController.php index e67be10..a345a24 100644 --- a/app/Http/Controllers/WebstatementController.php +++ b/app/Http/Controllers/WebstatementController.php @@ -20,10 +20,8 @@ class WebstatementController extends Controller * @param Request $request * @return \Illuminate\Http\JsonResponse */ - public function index(Request $request) + public function index(string $queueName='default') { - $queueName = $request->get('queue_name', 'default'); - Log::info('Starting statement export process', [ 'queue_name' => $queueName ]); diff --git a/app/Jobs/ExportStatementPeriodJob.php b/app/Jobs/ExportStatementPeriodJob.php index 7534243..f4882e3 100644 --- a/app/Jobs/ExportStatementPeriodJob.php +++ b/app/Jobs/ExportStatementPeriodJob.php @@ -202,19 +202,23 @@ class ExportStatementPeriodJob implements ShouldQueue foreach ($entries as $item) { $globalSequence++; - $runningBalance += (float) $item->amount_lcy; - $transactionDate = $this->formatTransactionDate($item); $actualDate = $this->formatActualDate($item); + $amount = $item->amount_fcy; + if($item->currency=='IDR'){ + $amount = $item->amount_lcy; + } + $runningBalance += (float) $amount; + $processedData[] = [ 'account_number' => $this->account_number, 'period' => $this->period, 'sequence_no' => $globalSequence, 'transaction_date' => $item->booking_date, 'reference_number' => $item->trans_reference, - 'transaction_amount' => $item->amount_lcy, - 'transaction_type' => $item->amount_lcy < 0 ? 'D' : 'C', + 'transaction_amount' => $amount, + 'transaction_type' => $amount < 0 ? 'D' : 'C', 'description' => $this->generateNarrative($item), 'end_balance' => $runningBalance, 'actual_date' => $actualDate, diff --git a/app/Jobs/GenerateBiayaKartuCsvJob.php b/app/Jobs/GenerateBiayaKartuCsvJob.php index c2a238f..996b348 100644 --- a/app/Jobs/GenerateBiayaKartuCsvJob.php +++ b/app/Jobs/GenerateBiayaKartuCsvJob.php @@ -184,15 +184,13 @@ ->whereNotNull('currency') ->where('currency', '!=', '') ->whereIn('ctdesc', $cardTypes) - ->whereNotIn('product_code',['6002','6004','6042','6031']) // Hapus 6021 dari sini + ->whereNotIn('product_code',['6031','6021','6042']) // Hapus 6021 dari sini ->where('branch','!=','ID0019999') - // Filter khusus: Kecualikan product_code 6021 yang ctdesc nya gold - ->where(function($subQuery) { - $subQuery->where('product_code', '!=', '6021') - ->orWhere(function($nestedQuery) { - $nestedQuery->where('product_code', '6021') - ->where('ctdesc', '!=', 'GOLD'); - }); + ->where(function($query) { + $query->whereNot(function($q) { + $q->where('product_code', '6004') + ->where('ctdesc', 'CLASSIC'); + }); }); @@ -203,8 +201,8 @@ Log::info('Eligible ATM cards fetched successfully', [ 'total_cards' => $cards->count(), 'periode' => $this->periode, - 'excluded_product_codes' => ['6002','6004','6042','6031'], - 'special_filter' => 'product_code 6021 dengan ctdesc gold dikecualikan' + 'excluded_product_codes' => ['6021','6042','6031'], + 'special_filter' => 'product_code 6004 dengan ctdesc classic dikecualikan' ]); return $cards; @@ -251,6 +249,8 @@ : array { $today = date('Ymd'); + // Generate hash string unik 16 digit + $uniqueHash = substr(hash('sha256', $card->crdno . $today . microtime(true) . uniqid()), 0, 16); return [ '', @@ -272,7 +272,8 @@ '', '', '', - 'ACAT' + 'ACAT', + $uniqueHash ]; } diff --git a/app/Jobs/ProcessCustomerDataJob.php b/app/Jobs/ProcessCustomerDataJob.php index 1bd4408..9dc46f7 100644 --- a/app/Jobs/ProcessCustomerDataJob.php +++ b/app/Jobs/ProcessCustomerDataJob.php @@ -170,12 +170,13 @@ $mapping[$index] = $csvHeader; continue; } - + // Custom mapping untuk field yang berbeda nama $customMapping = [ 'co_code' => 'branch_code', // co_code di CSV menjadi branch_code di database + 'name_1' => 'name' ]; - + if (isset($customMapping[$csvHeader])) { $mapping[$index] = $customMapping[$csvHeader]; } else {