feat(webstatement): tambah optimasi pemrosesan multi_account dan validasi statement
Perubahan yang dilakukan: - Memodifikasi PrintStatementController untuk mendukung request_type baru: multi_account. - Menambahkan validasi stmt_sent_type dan branch_code khusus pada request multi_account. - Menambahkan pengecekan branch_id: ID0019999 dengan penanganan error yang lebih spesifik. - Menambahkan metode processMultiAccountStatement untuk pemrosesan berdasarkan branch_code dan stmt_sent_type. Optimasi PDF: - Melakukan refaktor pada GenerateMultiAccountPdfJob agar mendukung kalkulasi tanggal dinamis (startDate dan endDate). - Mengimplementasikan Browsershot untuk opsi tambahan background dan optimasi waktu proses. - Menambahkan validasi status dan update log pada PrintStatementLog setelah PDF berhasil dibuat. - Menambahkan penanganan penggunaan memori secara granular untuk proses batch PDF dan pembersihan resource otomatis. Logging dan Validasi: - Menambahkan logging pada proses kalkulasi tanggal multi_account. - Logging tambahan dan rollback untuk error yang terjadi saat proses statement atau PDF. - Mengubah penggunaan Auth:: untuk konsistensi role checking. - Mengubah validasi stmt_sent_type dari JSON menjadi array dengan implode(). UI dan Output: - Memodifikasi blade template agar mendukung tampilan stmt_sent_type untuk kasus multi_account. - Menambahkan logika kolom dinamis berdasarkan account_number atau stmt_sent_type. Refaktor umum: - Memisahkan logika antara single dan multi account di PrintStatementController. - Perbaikan minor pada query SQL untuk entri ProcessedStatement. Tujuan perubahan: - Mendukung pemrosesan batch statement multi account secara lebih efisien dan terstruktur. - Menjamin validasi dan logging yang lebih kuat. - Meningkatkan performa pembuatan PDF dan kontrol terhadap penggunaan resource. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -45,33 +45,45 @@ ini_set('max_execution_time', 300000);
|
||||
// Add account verification before storing
|
||||
$accountNumber = $request->input('account_number'); // Assuming this is the field name for account number
|
||||
// First, check if the account exists and get branch information
|
||||
$account = Account::where('account_number', $accountNumber)->first();
|
||||
if ($account) {
|
||||
$branch_code = $account->branch_code;
|
||||
$userBranchId = session('branch_id'); // Assuming branch ID is stored in session
|
||||
$multiBranch = session('MULTI_BRANCH');
|
||||
$request_type = "single_account";
|
||||
if($request->input('branch_code') && !empty($request->input('stmt_sent_type'))){
|
||||
$request_type = 'multi_account'; // Default untuk request manual
|
||||
}
|
||||
|
||||
if($request_type=='single_account'){
|
||||
$account = Account::where('account_number', $accountNumber)->first();
|
||||
if ($account) {
|
||||
$branch_code = $account->branch_code;
|
||||
$userBranchId = session('branch_id'); // Assuming branch ID is stored in session
|
||||
$multiBranch = session('MULTI_BRANCH');
|
||||
|
||||
if (!$multiBranch) {
|
||||
// Check if account branch matches user's branch
|
||||
if ($account->branch_id !== $userBranchId) {
|
||||
return redirect()->route('statements.index')
|
||||
->with('error', 'Nomor rekening tidak sesuai dengan cabang Anda. Transaksi tidak dapat dilanjutkan.');
|
||||
if (!$multiBranch) {
|
||||
// Check if account branch matches user's branch
|
||||
if ($account->branch_id !== $userBranchId) {
|
||||
return redirect()->route('statements.index')
|
||||
->with('error', 'Nomor rekening tidak sesuai dengan cabang Anda. Transaksi tidak dapat dilanjutkan.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if account belongs to restricted branch ID0019999
|
||||
if ($account->branch_id === 'ID0019999') {
|
||||
// Check if account belongs to restricted branch ID0019999
|
||||
if ($account->branch_id === 'ID0019999') {
|
||||
return redirect()->route('statements.index')
|
||||
->with('error', 'Nomor rekening terdaftar pada cabang khusus. Silakan hubungi bagian HC untuk informasi lebih lanjut.');
|
||||
}
|
||||
|
||||
// If all checks pass, proceed with storing data
|
||||
// Your existing store logic here
|
||||
|
||||
} else {
|
||||
// Account not found
|
||||
return redirect()->route('statements.index')
|
||||
->with('error', 'Nomor rekening terdaftar pada cabang khusus. Silakan hubungi bagian HC untuk informasi lebih lanjut.');
|
||||
->with('error', 'Nomor rekening tidak ditemukan dalam sistem.');
|
||||
}
|
||||
|
||||
// If all checks pass, proceed with storing data
|
||||
// Your existing store logic here
|
||||
|
||||
} else {
|
||||
// Account not found
|
||||
return redirect()->route('statements.index')
|
||||
->with('error', 'Nomor rekening tidak ditemukan dalam sistem.');
|
||||
if($request->input('branch_code')=== 'ID0019999') {
|
||||
return redirect()->route('statements.index')
|
||||
->with('error', 'tidak dapat dilakukan print statement unruk cabang khusus. Silakan hubungi bagian HC untuk informasi lebih lanjut.');
|
||||
}
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
@@ -96,7 +108,7 @@ ini_set('max_execution_time', 300000);
|
||||
$validated['processed_accounts'] = 0;
|
||||
$validated['success_count'] = 0;
|
||||
$validated['failed_count'] = 0;
|
||||
$validated['stmt_sent_type'] = $request->input('stmt_sent_type') ? json_encode($request->input('stmt_sent_type')) : '';
|
||||
$validated['stmt_sent_type'] = $request->input('stmt_sent_type') ? implode(",",$request->input('stmt_sent_type')) : '';
|
||||
$validated['branch_code'] = $validated['branch_code'] ?? $branch_code; // Awal tidak tersedia
|
||||
|
||||
// Create the statement log
|
||||
@@ -116,10 +128,9 @@ ini_set('max_execution_time', 300000);
|
||||
$this->printStatementRekening($statement);
|
||||
}
|
||||
|
||||
$statement = PrintStatementLog::find($statement->id);
|
||||
if($statement->email){
|
||||
$this->sendEmail($statement->id);
|
||||
}
|
||||
//if($statement->email){
|
||||
// $this->sendEmail($statement->id);
|
||||
//}
|
||||
DB::commit();
|
||||
|
||||
return redirect()->route('statements.index')
|
||||
@@ -428,7 +439,10 @@ ini_set('max_execution_time', 300000);
|
||||
'file_path' => $filePath
|
||||
]);
|
||||
|
||||
return $disk->download($filePath, "{$statement->account_number}_{$statement->period_from}.pdf");
|
||||
return response()->download(
|
||||
$disk->path($filePath),
|
||||
"{$statement->account_number}_{$statement->period_from}.pdf"
|
||||
);
|
||||
} else {
|
||||
Log::warning('Statement file not found', [
|
||||
'statement_id' => $statement->id,
|
||||
@@ -489,7 +503,7 @@ ini_set('max_execution_time', 300000);
|
||||
$query = PrintStatementLog::query();
|
||||
$query->whereNotNull('user_id');
|
||||
|
||||
if (!auth()->user()->hasRole('administrator')) {
|
||||
if (!Auth::user()->role === 'administrator') {
|
||||
$query->where(function($q) {
|
||||
$q->where('user_id', Auth::id())
|
||||
->orWhere('branch_code', Auth::user()->branch->code);
|
||||
@@ -591,6 +605,7 @@ ini_set('max_execution_time', 300000);
|
||||
'authorized_by' => $item->authorizer ? $item->authorizer->name : null,
|
||||
'authorized_at' => $item->authorized_at ? $item->authorized_at->format('Y-m-d H:i:s') : null,
|
||||
'remarks' => $item->remarks,
|
||||
'request_type' => $item->request_type ?? 'N/A',
|
||||
];
|
||||
});
|
||||
|
||||
@@ -1274,6 +1289,7 @@ ini_set('max_execution_time', 300000);
|
||||
'branch_code' => $statement->branch_code
|
||||
]);
|
||||
|
||||
|
||||
if ($statement->request_type === 'multi_account') {
|
||||
return $this->processMultiAccountStatement($statement);
|
||||
} else {
|
||||
@@ -1307,7 +1323,6 @@ ini_set('max_execution_time', 300000);
|
||||
{
|
||||
try {
|
||||
$period = $statement->period_from ?? date('Ym');
|
||||
$clientName = 'client1';
|
||||
|
||||
// Validasi stmt_sent_type
|
||||
if (empty($statement->stmt_sent_type)) {
|
||||
@@ -1315,13 +1330,7 @@ ini_set('max_execution_time', 300000);
|
||||
}
|
||||
|
||||
// Decode stmt_sent_type jika dalam format JSON array
|
||||
$stmtSentTypes = is_string($statement->stmt_sent_type)
|
||||
? json_decode($statement->stmt_sent_type, true)
|
||||
: $statement->stmt_sent_type;
|
||||
|
||||
if (!is_array($stmtSentTypes)) {
|
||||
$stmtSentTypes = [$stmtSentTypes];
|
||||
}
|
||||
$stmtSentTypes = explode(',', $statement->stmt_sent_type);
|
||||
|
||||
Log::info('Processing multi account statement', [
|
||||
'statement_id' => $statement->id,
|
||||
@@ -1330,12 +1339,16 @@ ini_set('max_execution_time', 300000);
|
||||
'period' => $period
|
||||
]);
|
||||
|
||||
|
||||
|
||||
$clientName = $statement->branch_code.'_'.$period.'_';//.implode('_'.$stmtSentTypes);
|
||||
// Ambil accounts berdasarkan branch_code dan stmt_sent_type
|
||||
$accounts = Account::where('branch_code', $statement->branch_code)
|
||||
->whereIn('stmt_sent_type', $stmtSentTypes)
|
||||
->with('customer')
|
||||
->limit(5)
|
||||
->get();
|
||||
|
||||
|
||||
if ($accounts->isEmpty()) {
|
||||
throw new \Exception('No accounts found for the specified criteria');
|
||||
}
|
||||
@@ -1348,8 +1361,9 @@ ini_set('max_execution_time', 300000);
|
||||
|
||||
// Update statement log dengan informasi accounts
|
||||
$accountNumbers = $accounts->pluck('account_number')->toArray();
|
||||
|
||||
$statement->update([
|
||||
'target_accounts' => $accountNumbers,
|
||||
'target_accounts' => implode(",",$accountNumbers),
|
||||
'total_accounts' => $accounts->count(),
|
||||
'status' => 'processing',
|
||||
'started_at' => now()
|
||||
@@ -1522,7 +1536,7 @@ ini_set('max_execution_time', 300000);
|
||||
Log::info('Multi account ZIP downloaded', [
|
||||
'statement_id' => $statementId,
|
||||
'zip_file' => $zipFile,
|
||||
'user_id' => auth()->id()
|
||||
'user_id' => Auth::id()
|
||||
]);
|
||||
|
||||
return response()->download($zipPath, $filename, [
|
||||
|
||||
Reference in New Issue
Block a user