- Menghapus logika dan kode terkait pengunduhan, pembuatan, dan pengelolaan file statement yang berlebihan. - Menambahkan fungsi `listAccount` untuk mendapatkan daftar nomor akun secara langsung. - Menambahkan fungsi `listPeriod` untuk mengatur daftar periode yang digunakan dalam proses. - Menambahkan fungsi `getAccountBalance` untuk mengakses saldo akun berdasarkan nomor akun dan periode. - Mengubah metode `index` menjadi lebih modular, menggunakan fungsi tambahan untuk menyederhanakan pembuatan data dan queue statement. - Menyederhanakan tanggapan JSON untuk pesan keberhasilan pengajuan job export. - Mengimpor model `AccountBalance` yang diperlukan untuk fungsi baru.
140 lines
4.2 KiB
PHP
140 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Contracts\Bus\Dispatcher;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Modules\Webstatement\Jobs\ExportStatementJob;
|
|
use Modules\Webstatement\Models\AccountBalance;
|
|
use Modules\Webstatement\Models\StmtEntry;
|
|
use Modules\Webstatement\Models\TempFundsTransfer;
|
|
use Modules\Webstatement\Models\TempStmtNarrFormat;
|
|
use Modules\Webstatement\Models\TempStmtNarrParam;
|
|
|
|
class WebstatementController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$jobIds = [];
|
|
$data = [];
|
|
|
|
foreach ($this->listAccount() as $accountNumber) {
|
|
foreach ($this->listPeriod() as $period) {
|
|
$job = new ExportStatementJob(
|
|
$accountNumber,
|
|
$period,
|
|
$this->getAccountBalance($accountNumber, $period)
|
|
);
|
|
$jobIds[] = app(Dispatcher::class)->dispatch($job);
|
|
$data[] = [
|
|
'account_number' => $accountNumber,
|
|
'period' => $period
|
|
];
|
|
}
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => 'Statement export jobs have been queued',
|
|
'jobs' => array_map(function ($index, $jobId) use ($data) {
|
|
return [
|
|
'job_id' => $jobId,
|
|
'account_number' => $data[$index]['account_number'],
|
|
'period' => $data[$index]['period'],
|
|
'file_name' => "{$data[$index]['account_number']}_{$data[$index]['period']}.csv"
|
|
];
|
|
}, array_keys($jobIds), $jobIds)
|
|
]);
|
|
}
|
|
|
|
function listAccount(){
|
|
return [
|
|
'1080426085',
|
|
'1080425781',
|
|
|
|
'1081647484',
|
|
'1081647485',
|
|
|
|
'1083123710',
|
|
'1083123711',
|
|
'1083123712',
|
|
'1083123713',
|
|
'1083123714',
|
|
'1083123715',
|
|
'1083123716',
|
|
'1083123718',
|
|
'1083123719',
|
|
'1083123721',
|
|
'1083123722',
|
|
'1083123723',
|
|
'1083123724',
|
|
'1083123726',
|
|
'1083123727',
|
|
'1083123728',
|
|
'1083123730',
|
|
'1083123731',
|
|
'1083123732',
|
|
'1083123734',
|
|
'1083123735',
|
|
|
|
'1086677889',
|
|
'1086677890',
|
|
'1086677891',
|
|
'1086677892',
|
|
'1086677893',
|
|
'1086677894',
|
|
'1086677895',
|
|
'1086677896',
|
|
'1086677897',
|
|
|
|
'1080119298',
|
|
'1080119361',
|
|
'1080119425',
|
|
'1080119387',
|
|
'1082208069',
|
|
|
|
'1085151668',
|
|
|
|
'1085368601',
|
|
|
|
'1078333878',
|
|
|
|
'0081272689'
|
|
];
|
|
}
|
|
|
|
function listPeriod(){
|
|
return [
|
|
'20250512',
|
|
'20250513',
|
|
'20250514',
|
|
'20250515',
|
|
'20250516',
|
|
'20250517',
|
|
'20250518',
|
|
'20250519',
|
|
'20250520',
|
|
'20250521',
|
|
'20250522'
|
|
];
|
|
}
|
|
|
|
|
|
function getAccountBalance($accountNumber, $period)
|
|
{
|
|
$accountBalance = AccountBalance::where('account_number', $accountNumber)
|
|
->where('period', '<', $period)
|
|
->orderBy('period', 'desc')
|
|
->first();
|
|
|
|
return $accountBalance->actual_balance ?? 0;
|
|
}
|
|
}
|
|
|