feat(webstatement): tambah stmt_entry_detail migrasi, model, dan job processing
Menambahkan fitur pengelolaan data stmt_entry_detail untuk integrasi transaksi dengan detail yang lebih lengkap. Perubahan yang dilakukan: - Membuat migrasi create_stmt_entry_detail_table dengan struktur field sesuai kebutuhan bisnis - Menambahkan index pada kolom penting untuk meningkatkan performa query - Membuat model StmtEntryDetail dengan relasi ke: - Account - TempFundsTransfer - TempTransaction - Teller - DataCapture - TempArrangement - Mengimplementasikan $fillable dan $casts sesuai struktur tabel - Menambahkan relasi untuk memudahkan integrasi antar modul - Membuat job ProcessStmtEntryDetailDataJob untuk memproses file CSV dengan batch processing - Mengimplementasikan chunking untuk menangani file besar secara efisien - Membersihkan trans_reference dari karakter tidak valid sebelum penyimpanan - Menggunakan updateOrCreate untuk mencegah duplikasi primary key - Menggunakan database transaction untuk menjaga konsistensi data - Menambahkan logging komprehensif untuk monitoring dan debugging - Mengimplementasikan error handling yang robust untuk menghindari job failure tanpa informasi - Memastikan penggunaan resource memory tetap optimal saat memproses data besar - Menambahkan case baru di MigrasiController untuk memproses stmt_entry_detail - Konsisten dengan pattern migrasi data yang sudah ada di sistem Tujuan perubahan: - Menyediakan sistem import dan pengolahan data stmt_entry_detail dengan proses yang aman dan efisien - Memudahkan integrasi transaksi dengan detail tambahan di modul Webstatement - Menjamin integritas data dengan penggunaan transaction, logging, dan error handling yang komprehensif
This commit is contained in:
@@ -136,72 +136,6 @@ class LaporanClosingBalanceController extends Controller
|
|||||||
return view('webstatement::laporan-closing-balance.show', compact('closingBalanceReport'));
|
return view('webstatement::laporan-closing-balance.show', compact('closingBalanceReport'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Download laporan jika tersedia
|
|
||||||
*
|
|
||||||
* @param ClosingBalanceReportLog $closingBalanceReport
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function download(ClosingBalanceReportLog $closingBalanceReport)
|
|
||||||
{
|
|
||||||
Log::info('Download laporan closing balance', [
|
|
||||||
'report_id' => $closingBalanceReport->id,
|
|
||||||
'user_id' => Auth::id()
|
|
||||||
]);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check if report is available
|
|
||||||
if ($closingBalanceReport->status !== 'completed' || !$closingBalanceReport->file_path) {
|
|
||||||
Log::warning('Laporan tidak tersedia untuk download', [
|
|
||||||
'report_id' => $closingBalanceReport->id,
|
|
||||||
'status' => $closingBalanceReport->status
|
|
||||||
]);
|
|
||||||
return back()->with('error', 'Laporan tidak tersedia untuk download.');
|
|
||||||
}
|
|
||||||
|
|
||||||
DB::beginTransaction();
|
|
||||||
|
|
||||||
// Update download status
|
|
||||||
$closingBalanceReport->update([
|
|
||||||
'is_downloaded' => true,
|
|
||||||
'downloaded_at' => now(),
|
|
||||||
'updated_by' => Auth::id()
|
|
||||||
]);
|
|
||||||
|
|
||||||
DB::commit();
|
|
||||||
|
|
||||||
// Download the file
|
|
||||||
$filePath = $closingBalanceReport->file_path;
|
|
||||||
if (Storage::exists($filePath)) {
|
|
||||||
$fileName = "closing_balance_report_{$closingBalanceReport->account_number}_{$closingBalanceReport->period}.csv";
|
|
||||||
|
|
||||||
Log::info('File laporan berhasil didownload', [
|
|
||||||
'report_id' => $closingBalanceReport->id,
|
|
||||||
'file_path' => $filePath
|
|
||||||
]);
|
|
||||||
|
|
||||||
return Storage::download($filePath, $fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::error('File laporan tidak ditemukan', [
|
|
||||||
'report_id' => $closingBalanceReport->id,
|
|
||||||
'file_path' => $filePath
|
|
||||||
]);
|
|
||||||
|
|
||||||
return back()->with('error', 'File laporan tidak ditemukan.');
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
DB::rollback();
|
|
||||||
|
|
||||||
Log::error('Error saat download laporan', [
|
|
||||||
'report_id' => $closingBalanceReport->id,
|
|
||||||
'error' => $e->getMessage()
|
|
||||||
]);
|
|
||||||
|
|
||||||
return back()->with('error', 'Terjadi kesalahan saat download laporan.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authorize permintaan laporan
|
* Authorize permintaan laporan
|
||||||
*
|
*
|
||||||
@@ -273,15 +207,53 @@ class LaporanClosingBalanceController extends Controller
|
|||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
$query = ClosingBalanceReportLog::query();
|
$query = ClosingBalanceReportLog::query();
|
||||||
|
|
||||||
// Apply search filter if provided
|
// Apply search filter if provided (handle JSON search parameters)
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
|
||||||
$q->where('account_number', 'LIKE', "%$search%")
|
// Check if search is JSON format
|
||||||
->orWhere('period', 'LIKE', "%$search%")
|
if (is_string($search) && json_decode($search, true) !== null) {
|
||||||
->orWhere('status', 'LIKE', "%$search%")
|
$searchParams = json_decode($search, true);
|
||||||
->orWhere('authorization_status', 'LIKE', "%$search%");
|
|
||||||
});
|
// Apply account number filter
|
||||||
|
if (!empty($searchParams['account_number'])) {
|
||||||
|
$query->where('account_number', 'LIKE', "%{$searchParams['account_number']}%");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply date range filter
|
||||||
|
if (!empty($searchParams['start_date'])) {
|
||||||
|
$startPeriod = Carbon::createFromFormat('Y-m-d', $searchParams['start_date'])->format('Ymd');
|
||||||
|
$query->where('period', '>=', $startPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($searchParams['end_date'])) {
|
||||||
|
$endPeriod = Carbon::createFromFormat('Y-m-d', $searchParams['end_date'])->format('Ymd');
|
||||||
|
$query->where('period', '<=', $endPeriod);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Handle regular string search (fallback)
|
||||||
|
$query->where(function ($q) use ($search) {
|
||||||
|
$q->where('account_number', 'LIKE', "%$search%")
|
||||||
|
->orWhere('period', 'LIKE', "%$search%")
|
||||||
|
->orWhere('status', 'LIKE', "%$search%")
|
||||||
|
->orWhere('authorization_status', 'LIKE', "%$search%");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply individual parameter filters (for backward compatibility)
|
||||||
|
if ($request->has('account_number') && !empty($request->get('account_number'))) {
|
||||||
|
$query->where('account_number', 'LIKE', "%{$request->get('account_number')}%");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->has('start_date') && !empty($request->get('start_date'))) {
|
||||||
|
$startPeriod = Carbon::createFromFormat('Y-m-d', $request->get('start_date'))->format('Ymd');
|
||||||
|
$query->where('period', '>=', $startPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->has('end_date') && !empty($request->get('end_date'))) {
|
||||||
|
$endPeriod = Carbon::createFromFormat('Y-m-d', $request->get('end_date'))->format('Ymd');
|
||||||
|
$query->where('period', '<=', $endPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply column filters if provided
|
// Apply column filters if provided
|
||||||
@@ -519,4 +491,81 @@ class LaporanClosingBalanceController extends Controller
|
|||||||
return back()->with('error', 'Gagal mengulang generate laporan: ' . $e->getMessage());
|
return back()->with('error', 'Gagal mengulang generate laporan: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download laporan berdasarkan nomor rekening dan periode
|
||||||
|
*
|
||||||
|
* @param string $accountNumber
|
||||||
|
* @param string $period
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function download($accountNumber, $period)
|
||||||
|
{
|
||||||
|
Log::info('Download laporan closing balance', [
|
||||||
|
'account_number' => $accountNumber,
|
||||||
|
'period' => $period,
|
||||||
|
'user_id' => Auth::id()
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Cari laporan berdasarkan account number dan period
|
||||||
|
$closingBalanceReport = ClosingBalanceReportLog::where('account_number', $accountNumber)
|
||||||
|
->where('period', $period)
|
||||||
|
->where('status', 'completed')
|
||||||
|
->whereNotNull('file_path')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$closingBalanceReport) {
|
||||||
|
Log::warning('Laporan tidak ditemukan atau belum selesai', [
|
||||||
|
'account_number' => $accountNumber,
|
||||||
|
'period' => $period
|
||||||
|
]);
|
||||||
|
return back()->with('error', 'Laporan tidak ditemukan atau belum selesai diproses.');
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
// Update download status
|
||||||
|
$closingBalanceReport->update([
|
||||||
|
'is_downloaded' => true,
|
||||||
|
'downloaded_at' => now(),
|
||||||
|
'updated_by' => Auth::id()
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
// Download the file
|
||||||
|
$filePath = $closingBalanceReport->file_path;
|
||||||
|
if (Storage::exists($filePath)) {
|
||||||
|
$fileName = "closing_balance_report_{$accountNumber}_{$period}.csv";
|
||||||
|
|
||||||
|
Log::info('File laporan berhasil didownload', [
|
||||||
|
'account_number' => $accountNumber,
|
||||||
|
'period' => $period,
|
||||||
|
'file_path' => $filePath
|
||||||
|
]);
|
||||||
|
|
||||||
|
return Storage::download($filePath, $fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::error('File laporan tidak ditemukan di storage', [
|
||||||
|
'account_number' => $accountNumber,
|
||||||
|
'period' => $period,
|
||||||
|
'file_path' => $filePath
|
||||||
|
]);
|
||||||
|
|
||||||
|
return back()->with('error', 'File laporan tidak ditemukan.');
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
DB::rollback();
|
||||||
|
|
||||||
|
Log::error('Error saat download laporan', [
|
||||||
|
'account_number' => $accountNumber,
|
||||||
|
'period' => $period,
|
||||||
|
'error' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
|
||||||
|
return back()->with('error', 'Terjadi kesalahan saat mengunduh laporan: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
ProcessTellerDataJob,
|
ProcessTellerDataJob,
|
||||||
ProcessTransactionDataJob,
|
ProcessTransactionDataJob,
|
||||||
ProcessSectorDataJob,
|
ProcessSectorDataJob,
|
||||||
ProcessProvinceDataJob};
|
ProcessProvinceDataJob,
|
||||||
|
ProcessStmtEntryDetailDataJob};
|
||||||
|
|
||||||
class MigrasiController extends Controller
|
class MigrasiController extends Controller
|
||||||
{
|
{
|
||||||
@@ -38,6 +39,7 @@
|
|||||||
'customer' => ProcessCustomerDataJob::class,
|
'customer' => ProcessCustomerDataJob::class,
|
||||||
'account' => ProcessAccountDataJob::class,
|
'account' => ProcessAccountDataJob::class,
|
||||||
'stmtEntry' => ProcessStmtEntryDataJob::class,
|
'stmtEntry' => ProcessStmtEntryDataJob::class,
|
||||||
|
'stmtEntryDetail' => ProcessStmtEntryDetailDataJob::class, // Tambahan baru
|
||||||
'dataCapture' => ProcessDataCaptureDataJob::class,
|
'dataCapture' => ProcessDataCaptureDataJob::class,
|
||||||
'fundsTransfer' => ProcessFundsTransferDataJob::class,
|
'fundsTransfer' => ProcessFundsTransferDataJob::class,
|
||||||
'teller' => ProcessTellerDataJob::class,
|
'teller' => ProcessTellerDataJob::class,
|
||||||
@@ -63,6 +65,7 @@
|
|||||||
'customer',
|
'customer',
|
||||||
'account',
|
'account',
|
||||||
'stmtEntry',
|
'stmtEntry',
|
||||||
|
'stmtEntryDetail', // Tambahan baru
|
||||||
'dataCapture',
|
'dataCapture',
|
||||||
'fundsTransfer',
|
'fundsTransfer',
|
||||||
'teller',
|
'teller',
|
||||||
|
|||||||
@@ -191,11 +191,11 @@
|
|||||||
$subQuery->where('product_code', '!=', '6021')
|
$subQuery->where('product_code', '!=', '6021')
|
||||||
->orWhere(function($nestedQuery) {
|
->orWhere(function($nestedQuery) {
|
||||||
$nestedQuery->where('product_code', '6021')
|
$nestedQuery->where('product_code', '6021')
|
||||||
->where('ctdesc', '!=', 'gold');
|
->where('ctdesc', '!=', 'GOLD');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$cards = $query->get();
|
$cards = $query->get();
|
||||||
|
|
||||||
|
|||||||
340
app/Jobs/ProcessStmtEntryDetailDataJob.php
Normal file
340
app/Jobs/ProcessStmtEntryDetailDataJob.php
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Webstatement\Jobs;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Modules\Webstatement\Models\StmtEntryDetail;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ProcessStmtEntryDetailDataJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
private const CSV_DELIMITER = '~';
|
||||||
|
private const MAX_EXECUTION_TIME = 86400; // 24 hours in seconds
|
||||||
|
private const FILENAME = 'ST.STMT.ENTRY.DETAIL.csv';
|
||||||
|
private const DISK_NAME = 'sftpStatement';
|
||||||
|
private const CHUNK_SIZE = 1000; // Process data in chunks to reduce memory usage
|
||||||
|
|
||||||
|
private string $period = '';
|
||||||
|
private int $processedCount = 0;
|
||||||
|
private int $errorCount = 0;
|
||||||
|
private array $entryBatch = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @param string $period Periode data yang akan diproses
|
||||||
|
*/
|
||||||
|
public function __construct(string $period = '')
|
||||||
|
{
|
||||||
|
$this->period = $period;
|
||||||
|
Log::info('ProcessStmtEntryDetailDataJob initialized', ['period' => $period]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Log::info('Memulai ProcessStmtEntryDetailDataJob', ['period' => $this->period]);
|
||||||
|
|
||||||
|
$this->initializeJob();
|
||||||
|
|
||||||
|
if ($this->period === '') {
|
||||||
|
Log::warning('No period provided for statement entry detail data processing');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->processPeriod();
|
||||||
|
$this->logJobCompletion();
|
||||||
|
|
||||||
|
Log::info('ProcessStmtEntryDetailDataJob selesai berhasil');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error('Error in ProcessStmtEntryDetailDataJob: ' . $e->getMessage());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inisialisasi job dengan pengaturan awal
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function initializeJob(): void
|
||||||
|
{
|
||||||
|
set_time_limit(self::MAX_EXECUTION_TIME);
|
||||||
|
$this->processedCount = 0;
|
||||||
|
$this->errorCount = 0;
|
||||||
|
$this->entryBatch = [];
|
||||||
|
|
||||||
|
Log::info('Job initialized', [
|
||||||
|
'max_execution_time' => self::MAX_EXECUTION_TIME,
|
||||||
|
'chunk_size' => self::CHUNK_SIZE
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proses data untuk periode tertentu
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function processPeriod(): void
|
||||||
|
{
|
||||||
|
$disk = Storage::disk(self::DISK_NAME);
|
||||||
|
$filename = "{$this->period}." . self::FILENAME;
|
||||||
|
$filePath = "{$this->period}/$filename";
|
||||||
|
|
||||||
|
Log::info('Memulai proses periode', ['file_path' => $filePath]);
|
||||||
|
|
||||||
|
if (!$this->validateFile($disk, $filePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tempFilePath = $this->createTemporaryFile($disk, $filePath, $filename);
|
||||||
|
$this->processFile($tempFilePath, $filePath);
|
||||||
|
$this->cleanup($tempFilePath);
|
||||||
|
|
||||||
|
Log::info('Proses periode selesai', ['file_path' => $filePath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validasi keberadaan file
|
||||||
|
*
|
||||||
|
* @param mixed $disk Storage disk instance
|
||||||
|
* @param string $filePath Path file yang akan divalidasi
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function validateFile($disk, string $filePath): bool
|
||||||
|
{
|
||||||
|
Log::info("Processing statement entry detail file: $filePath");
|
||||||
|
|
||||||
|
if (!$disk->exists($filePath)) {
|
||||||
|
Log::warning("File not found: $filePath");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info("File validated successfully: $filePath");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buat file temporary untuk proses
|
||||||
|
*
|
||||||
|
* @param mixed $disk Storage disk instance
|
||||||
|
* @param string $filePath Path file sumber
|
||||||
|
* @param string $filename Nama file
|
||||||
|
* @return string Path file temporary
|
||||||
|
*/
|
||||||
|
private function createTemporaryFile($disk, string $filePath, string $filename): string
|
||||||
|
{
|
||||||
|
$tempFilePath = storage_path("app/temp_$filename");
|
||||||
|
file_put_contents($tempFilePath, $disk->get($filePath));
|
||||||
|
|
||||||
|
Log::info('Temporary file created', ['temp_path' => $tempFilePath]);
|
||||||
|
return $tempFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proses file CSV
|
||||||
|
*
|
||||||
|
* @param string $tempFilePath Path file temporary
|
||||||
|
* @param string $filePath Path file asli
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function processFile(string $tempFilePath, string $filePath): void
|
||||||
|
{
|
||||||
|
$handle = fopen($tempFilePath, "r");
|
||||||
|
if ($handle === false) {
|
||||||
|
Log::error("Unable to open file: $filePath");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$headers = (new StmtEntryDetail())->getFillable();
|
||||||
|
$rowCount = 0;
|
||||||
|
$chunkCount = 0;
|
||||||
|
|
||||||
|
Log::info('Memulai proses file', [
|
||||||
|
'file_path' => $filePath,
|
||||||
|
'headers_count' => count($headers)
|
||||||
|
]);
|
||||||
|
|
||||||
|
while (($row = fgetcsv($handle, 0, self::CSV_DELIMITER)) !== false) {
|
||||||
|
$rowCount++;
|
||||||
|
$this->processRow($row, $headers, $rowCount, $filePath);
|
||||||
|
|
||||||
|
// Process in chunks to avoid memory issues
|
||||||
|
if (count($this->entryBatch) >= self::CHUNK_SIZE) {
|
||||||
|
$this->saveBatch();
|
||||||
|
$chunkCount++;
|
||||||
|
Log::info("Processed chunk $chunkCount ({$this->processedCount} records so far)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process any remaining records
|
||||||
|
if (!empty($this->entryBatch)) {
|
||||||
|
$this->saveBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($handle);
|
||||||
|
Log::info("Completed processing $filePath. Processed {$this->processedCount} records with {$this->errorCount} errors.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proses setiap baris data
|
||||||
|
*
|
||||||
|
* @param array $row Data baris
|
||||||
|
* @param array $headers Header kolom
|
||||||
|
* @param int $rowCount Nomor baris
|
||||||
|
* @param string $filePath Path file
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function processRow(array $row, array $headers, int $rowCount, string $filePath): void
|
||||||
|
{
|
||||||
|
if (count($headers) !== count($row)) {
|
||||||
|
Log::warning("Row $rowCount in $filePath has incorrect column count. Expected: " .
|
||||||
|
count($headers) . ", Got: " . count($row));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array_combine($headers, $row);
|
||||||
|
$this->cleanTransReference($data);
|
||||||
|
$this->addToBatch($data, $rowCount, $filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bersihkan trans_reference dari karakter tidak diinginkan
|
||||||
|
*
|
||||||
|
* @param array $data Data yang akan dibersihkan
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function cleanTransReference(array &$data): void
|
||||||
|
{
|
||||||
|
if (isset($data['trans_reference'])) {
|
||||||
|
// Clean trans_reference from \\BNK if present
|
||||||
|
$data['trans_reference'] = preg_replace('/\\\\.*$/', '', $data['trans_reference']);
|
||||||
|
Log::debug('Trans reference cleaned', ['original' => $data['trans_reference']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tambahkan record ke batch untuk proses bulk insert
|
||||||
|
*
|
||||||
|
* @param array $data Data record
|
||||||
|
* @param int $rowCount Nomor baris
|
||||||
|
* @param string $filePath Path file
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function addToBatch(array $data, int $rowCount, string $filePath): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (isset($data['stmt_entry_id']) && $data['stmt_entry_id'] !== 'stmt_entry_id') {
|
||||||
|
// Add timestamp fields
|
||||||
|
$now = now();
|
||||||
|
$data['created_at'] = $now;
|
||||||
|
$data['updated_at'] = $now;
|
||||||
|
|
||||||
|
// Add to entry batch
|
||||||
|
$this->entryBatch[] = $data;
|
||||||
|
$this->processedCount++;
|
||||||
|
|
||||||
|
Log::debug('Record added to batch', ['row' => $rowCount, 'stmt_entry_id' => $data['stmt_entry_id']]);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->errorCount++;
|
||||||
|
Log::error("Error processing Statement Entry Detail at row $rowCount in $filePath: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simpan batch data ke database menggunakan updateOrCreate
|
||||||
|
* untuk menghindari error unique constraint
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function saveBatch(): void
|
||||||
|
{
|
||||||
|
Log::info('Memulai proses saveBatch dengan updateOrCreate');
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!empty($this->entryBatch)) {
|
||||||
|
$totalProcessed = 0;
|
||||||
|
|
||||||
|
// Process each entry data directly
|
||||||
|
foreach ($this->entryBatch as $entryData) {
|
||||||
|
// Validasi bahwa entryData adalah array dan memiliki stmt_entry_id
|
||||||
|
if (is_array($entryData) && isset($entryData['stmt_entry_id'])) {
|
||||||
|
// Gunakan updateOrCreate untuk menghindari duplicate key error
|
||||||
|
StmtEntryDetail::updateOrCreate(
|
||||||
|
[
|
||||||
|
'stmt_entry_id' => $entryData['stmt_entry_id']
|
||||||
|
],
|
||||||
|
$entryData
|
||||||
|
);
|
||||||
|
|
||||||
|
$totalProcessed++;
|
||||||
|
} else {
|
||||||
|
Log::warning('Invalid entry data structure', ['data' => $entryData]);
|
||||||
|
$this->errorCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
Log::info("Berhasil memproses {$totalProcessed} record dengan updateOrCreate");
|
||||||
|
|
||||||
|
// Reset entry batch after successful processing
|
||||||
|
$this->entryBatch = [];
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
DB::rollback();
|
||||||
|
|
||||||
|
Log::error("Error in saveBatch: " . $e->getMessage() . "\n" . $e->getTraceAsString());
|
||||||
|
$this->errorCount += count($this->entryBatch);
|
||||||
|
|
||||||
|
// Reset batch even if there's an error to prevent reprocessing the same failed records
|
||||||
|
$this->entryBatch = [];
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bersihkan file temporary
|
||||||
|
*
|
||||||
|
* @param string $tempFilePath Path file temporary
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function cleanup(string $tempFilePath): void
|
||||||
|
{
|
||||||
|
if (file_exists($tempFilePath)) {
|
||||||
|
unlink($tempFilePath);
|
||||||
|
Log::info('Temporary file cleaned up', ['temp_path' => $tempFilePath]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log penyelesaian job
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function logJobCompletion(): void
|
||||||
|
{
|
||||||
|
Log::info("Statement Entry Detail data processing completed. " .
|
||||||
|
"Total processed: {$this->processedCount}, Total errors: {$this->errorCount}");
|
||||||
|
}
|
||||||
|
}
|
||||||
113
app/Models/StmtEntryDetail.php
Normal file
113
app/Models/StmtEntryDetail.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Webstatement\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
|
class StmtEntryDetail extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'stmt_entry_detail';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'stmt_entry_id',
|
||||||
|
'account_number',
|
||||||
|
'company_code',
|
||||||
|
'amount_lcy',
|
||||||
|
'transaction_code',
|
||||||
|
'narrative',
|
||||||
|
'product_category',
|
||||||
|
'value_date',
|
||||||
|
'amount_fcy',
|
||||||
|
'exchange_rate',
|
||||||
|
'trans_reference',
|
||||||
|
'booking_date',
|
||||||
|
'stmt_no',
|
||||||
|
'date_time',
|
||||||
|
'currency',
|
||||||
|
'crf_type',
|
||||||
|
'consol_key',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'created_at' => 'datetime',
|
||||||
|
'updated_at' => 'datetime',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relasi ke model Account
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function account()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Account::class, 'account_number', 'account_number');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relasi ke model TempFundsTransfer
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function ft()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(TempFundsTransfer::class, 'trans_reference', 'ref_no');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relasi ke model TempTransaction
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function transaction()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(TempTransaction::class, 'transaction_code', 'transaction_code');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relasi ke model Teller
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function tt()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Teller::class, 'trans_reference', 'id_teller');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relasi ke model DataCapture
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function dc()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(DataCapture::class, 'trans_reference', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relasi ke model TempArrangement
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function aa()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(TempArrangement::class, 'trans_reference', 'arrangement_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('stmt_entry_detail', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('stmt_entry_detail');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -6,8 +6,10 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="10" data-datatable-state-save="false" id="laporan-closing-balance-table" data-api-url="{{ route('laporan-closing-balance.datatables') }}">
|
<div class="min-w-full card card-grid" data-datatable="false" data-datatable-page-size="10"
|
||||||
<div class="card-header py-5 flex-wrap">
|
data-datatable-state-save="false" id="laporan-closing-balance-table"
|
||||||
|
data-api-url="{{ route('laporan-closing-balance.datatables') }}">
|
||||||
|
<div class="flex-wrap py-5 card-header">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">
|
||||||
Laporan Closing Balance
|
Laporan Closing Balance
|
||||||
</h3>
|
</h3>
|
||||||
@@ -16,93 +18,73 @@
|
|||||||
<div class="flex flex-wrap gap-2.5 items-end">
|
<div class="flex flex-wrap gap-2.5 items-end">
|
||||||
<!-- Nomor Rekening Filter -->
|
<!-- Nomor Rekening Filter -->
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label class="text-sm font-medium text-gray-700 mb-1">Nomor Rekening</label>
|
<input type="text" id="account-number-filter" class="input w-[200px]"
|
||||||
<input type="text" id="account-number-filter" class="input w-[200px]" placeholder="Masukkan nomor rekening">
|
placeholder="Masukkan nomor rekening">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tanggal Mulai Filter -->
|
<!-- Tanggal Mulai Filter -->
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label class="text-sm font-medium text-gray-700 mb-1">Tanggal Mulai</label>
|
|
||||||
<input type="date" id="start-date-filter" class="input w-[150px]">
|
<input type="date" id="start-date-filter" class="input w-[150px]">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tanggal Akhir Filter -->
|
<!-- Tanggal Akhir Filter -->
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label class="text-sm font-medium text-gray-700 mb-1">Tanggal Akhir</label>
|
|
||||||
<input type="date" id="end-date-filter" class="input w-[150px]">
|
<input type="date" id="end-date-filter" class="input w-[150px]">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tombol Filter -->
|
<!-- Tombol Filter -->
|
||||||
<button type="button" id="apply-filter" class="btn btn-primary">
|
<button type="button" id="apply-filter" class="btn btn-primary">
|
||||||
<i class="ki-filled ki-magnifier"></i>
|
<i class="ki-filled ki-magnifier"></i>
|
||||||
Filter
|
Filter
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Tombol Reset -->
|
<!-- Tombol Reset -->
|
||||||
<button type="button" id="reset-filter" class="btn btn-light">
|
<button type="button" id="reset-filter" class="btn btn-light">
|
||||||
<i class="ki-filled ki-arrows-circle"></i>
|
<i class="ki-filled ki-arrows-circle"></i>
|
||||||
Reset
|
Reset
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-wrap gap-2.5">
|
|
||||||
<div class="h-[24px] border border-r-gray-200"></div>
|
|
||||||
<a class="btn btn-light" href="{{ route('laporan-closing-balance.export') }}" id="export-btn">
|
|
||||||
<i class="ki-filled ki-file-down"></i>
|
|
||||||
Export to CSV
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="scrollable-x-auto">
|
<div class="scrollable-x-auto">
|
||||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
|
||||||
|
data-datatable-table="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-14">
|
<th class="w-14">
|
||||||
<input class="checkbox checkbox-sm" data-datatable-check="true" type="checkbox"/>
|
<input class="checkbox checkbox-sm" data-datatable-check="true" type="checkbox" />
|
||||||
</th>
|
</th>
|
||||||
<th class="min-w-[200px]" data-datatable-column="account_number">
|
<th class="min-w-[200px]" data-datatable-column="account_number">
|
||||||
<span class="sort">
|
<span class="sort">
|
||||||
<span class="sort-label">Nomor Rekening</span>
|
<span class="sort-label">Nomor Rekening</span>
|
||||||
<span class="sort-icon"></span>
|
<span class="sort-icon"></span>
|
||||||
</span>
|
</span>
|
||||||
</th>
|
</th>
|
||||||
<th class="min-w-[150px]" data-datatable-column="period">
|
<th class="min-w-[150px]" data-datatable-column="period">
|
||||||
<span class="sort">
|
<span class="sort">
|
||||||
<span class="sort-label">Periode</span>
|
<span class="sort-label">Periode</span>
|
||||||
<span class="sort-icon"></span>
|
<span class="sort-icon"></span>
|
||||||
</span>
|
</span>
|
||||||
</th>
|
</th>
|
||||||
<th class="min-w-[150px]" data-datatable-column="cleared_balance">
|
<th class="min-w-[150px]" data-datatable-column="updated_at">
|
||||||
<span class="sort">
|
<span class="sort">
|
||||||
<span class="sort-label">Saldo Cleared</span>
|
<span class="sort-label">Tanggal Update</span>
|
||||||
<span class="sort-icon"></span>
|
<span class="sort-icon"></span>
|
||||||
</span>
|
</span>
|
||||||
</th>
|
</th>
|
||||||
<th class="min-w-[150px]" data-datatable-column="actual_balance">
|
<th class="min-w-[100px] text-center" data-datatable-column="actions">Action</th>
|
||||||
<span class="sort">
|
</tr>
|
||||||
<span class="sort-label">Saldo Akhir</span>
|
|
||||||
<span class="sort-icon"></span>
|
|
||||||
</span>
|
|
||||||
</th>
|
|
||||||
<th class="min-w-[150px]" data-datatable-column="updated_at">
|
|
||||||
<span class="sort">
|
|
||||||
<span class="sort-label">Tanggal Update</span>
|
|
||||||
<span class="sort-icon"></span>
|
|
||||||
</span>
|
|
||||||
</th>
|
|
||||||
<th class="min-w-[100px] text-center" data-datatable-column="actions">Action</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
<div
|
||||||
<div class="flex items-center gap-2">
|
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
|
||||||
|
<div class="flex gap-2 items-center">
|
||||||
Show
|
Show
|
||||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"></select> per page
|
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"></select> per page
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<span data-datatable-info="true"></span>
|
<span data-datatable-info="true"></span>
|
||||||
<div class="pagination" data-datatable-pagination="true">
|
<div class="pagination" data-datatable-pagination="true">
|
||||||
</div>
|
</div>
|
||||||
@@ -135,11 +117,11 @@
|
|||||||
*/
|
*/
|
||||||
function formatPeriod(period) {
|
function formatPeriod(period) {
|
||||||
if (!period || period.length !== 8) return period;
|
if (!period || period.length !== 8) return period;
|
||||||
|
|
||||||
const year = period.substring(0, 4);
|
const year = period.substring(0, 4);
|
||||||
const month = period.substring(4, 6);
|
const month = period.substring(4, 6);
|
||||||
const day = period.substring(6, 8);
|
const day = period.substring(6, 8);
|
||||||
|
|
||||||
return `${day}/${month}/${year}`;
|
return `${day}/${month}/${year}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +132,7 @@
|
|||||||
*/
|
*/
|
||||||
function formatDate(dateString) {
|
function formatDate(dateString) {
|
||||||
if (!dateString) return '-';
|
if (!dateString) return '-';
|
||||||
|
|
||||||
const date = new Date(dateString);
|
const date = new Date(dateString);
|
||||||
return date.toLocaleDateString('id-ID', {
|
return date.toLocaleDateString('id-ID', {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
@@ -171,11 +153,25 @@
|
|||||||
const exportBtn = document.getElementById('export-btn');
|
const exportBtn = document.getElementById('export-btn');
|
||||||
|
|
||||||
const apiUrl = element.getAttribute('data-api-url');
|
const apiUrl = element.getAttribute('data-api-url');
|
||||||
|
|
||||||
// Konfigurasi DataTable
|
// Set default date range (last 30 days) SEBELUM inisialisasi DataTable
|
||||||
|
const today = new Date();
|
||||||
|
const thirtyDaysAgo = new Date(today.getTime() - (30 * 24 * 60 * 60 * 1000));
|
||||||
|
|
||||||
|
endDateFilter.value = today.toISOString().split('T')[0];
|
||||||
|
startDateFilter.value = thirtyDaysAgo.toISOString().split('T')[0];
|
||||||
|
|
||||||
|
// Prepare initial filters
|
||||||
|
let initialFilters = {
|
||||||
|
start_date: startDateFilter.value,
|
||||||
|
end_date: endDateFilter.value
|
||||||
|
};
|
||||||
|
|
||||||
|
// Konfigurasi DataTable dengan filter awal
|
||||||
const dataTableOptions = {
|
const dataTableOptions = {
|
||||||
apiEndpoint: apiUrl,
|
apiEndpoint: apiUrl,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
|
searchParams: initialFilters, // Set filter awal di sini
|
||||||
columns: {
|
columns: {
|
||||||
select: {
|
select: {
|
||||||
render: (item, data, context) => {
|
render: (item, data, context) => {
|
||||||
@@ -199,36 +195,26 @@
|
|||||||
return `<span class="text-gray-700">${formatPeriod(data.period)}</span>`;
|
return `<span class="text-gray-700">${formatPeriod(data.period)}</span>`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cleared_balance: {
|
|
||||||
title: 'Saldo Cleared',
|
|
||||||
render: (item, data) => {
|
|
||||||
const amount = parseFloat(data.cleared_balance) || 0;
|
|
||||||
return `<span class="text-blue-600 font-medium">${formatCurrency(amount)}</span>`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actual_balance: {
|
|
||||||
title: 'Saldo Akhir',
|
|
||||||
render: (item, data) => {
|
|
||||||
const amount = parseFloat(data.actual_balance) || 0;
|
|
||||||
return `<span class="text-green-600 font-medium">${formatCurrency(amount)}</span>`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
updated_at: {
|
updated_at: {
|
||||||
title: 'Tanggal Update',
|
title: 'Tanggal Update',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
return `<span class="text-gray-600 text-sm">${formatDate(data.updated_at)}</span>`;
|
return `<span class="text-sm text-gray-600">${formatDate(data.created_at)}</span>`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
title: 'Action',
|
title: 'Action',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
|
const downloadUrl =
|
||||||
|
`{{ route('laporan-closing-balance.download', ['accountNumber' => '__ACCOUNT__', 'period' => '__PERIOD__']) }}`
|
||||||
|
.replace('__ACCOUNT__', data.account_number)
|
||||||
|
.replace('__PERIOD__', data.period);
|
||||||
|
|
||||||
return `<div class="flex flex-nowrap justify-center">
|
return `<div class="flex flex-nowrap justify-center">
|
||||||
<a class="btn btn-sm btn-icon btn-clear btn-info"
|
<a class="btn btn-sm btn-icon btn-clear btn-success"
|
||||||
href="{{ route('laporan-closing-balance.show', ['accountNumber' => '__ACCOUNT__', 'period' => '__PERIOD__']) }}"
|
href="${downloadUrl}"
|
||||||
.replace('__ACCOUNT__', data.account_number)
|
title="Download Laporan"
|
||||||
.replace('__PERIOD__', data.period)
|
download>
|
||||||
title="Lihat Detail">
|
<i class="ki-outline ki-file-down"></i>
|
||||||
<i class="ki-outline ki-eye"></i>
|
|
||||||
</a>
|
</a>
|
||||||
</div>`;
|
</div>`;
|
||||||
},
|
},
|
||||||
@@ -236,9 +222,11 @@
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Inisialisasi DataTable
|
// Inisialisasi DataTable dengan filter awal sudah terset
|
||||||
let dataTable = new KTDataTable(element, dataTableOptions);
|
let dataTable = new KTDataTable(element, dataTableOptions);
|
||||||
dataTable.showSpinner();
|
|
||||||
|
// Update export URL dengan filter awal
|
||||||
|
updateExportUrl(initialFilters);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fungsi untuk menerapkan filter
|
* Fungsi untuk menerapkan filter
|
||||||
@@ -260,7 +248,7 @@
|
|||||||
|
|
||||||
console.log('Applying filters:', filters);
|
console.log('Applying filters:', filters);
|
||||||
dataTable.search(filters);
|
dataTable.search(filters);
|
||||||
|
|
||||||
// Update export URL dengan filter
|
// Update export URL dengan filter
|
||||||
updateExportUrl(filters);
|
updateExportUrl(filters);
|
||||||
}
|
}
|
||||||
@@ -272,7 +260,7 @@
|
|||||||
accountNumberFilter.value = '';
|
accountNumberFilter.value = '';
|
||||||
startDateFilter.value = '';
|
startDateFilter.value = '';
|
||||||
endDateFilter.value = '';
|
endDateFilter.value = '';
|
||||||
|
|
||||||
dataTable.search({});
|
dataTable.search({});
|
||||||
updateExportUrl({});
|
updateExportUrl({});
|
||||||
}
|
}
|
||||||
@@ -281,15 +269,15 @@
|
|||||||
* Fungsi untuk update URL export dengan parameter filter
|
* Fungsi untuk update URL export dengan parameter filter
|
||||||
*/
|
*/
|
||||||
function updateExportUrl(filters) {
|
function updateExportUrl(filters) {
|
||||||
const baseUrl = '{{ route("laporan-closing-balance.export") }}';
|
const baseUrl = '{{ route('laporan-closing-balance.export') }}';
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
Object.keys(filters).forEach(key => {
|
Object.keys(filters).forEach(key => {
|
||||||
if (filters[key]) {
|
if (filters[key]) {
|
||||||
params.append(key, filters[key]);
|
params.append(key, filters[key]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const newUrl = params.toString() ? `${baseUrl}?${params.toString()}` : baseUrl;
|
const newUrl = params.toString() ? `${baseUrl}?${params.toString()}` : baseUrl;
|
||||||
exportBtn.href = newUrl;
|
exportBtn.href = newUrl;
|
||||||
}
|
}
|
||||||
@@ -297,7 +285,7 @@
|
|||||||
// Event listeners
|
// Event listeners
|
||||||
applyFilterBtn.addEventListener('click', applyFilters);
|
applyFilterBtn.addEventListener('click', applyFilters);
|
||||||
resetFilterBtn.addEventListener('click', resetFilters);
|
resetFilterBtn.addEventListener('click', resetFilters);
|
||||||
|
|
||||||
// Auto apply filter saat enter di input
|
// Auto apply filter saat enter di input
|
||||||
[accountNumberFilter, startDateFilter, endDateFilter].forEach(input => {
|
[accountNumberFilter, startDateFilter, endDateFilter].forEach(input => {
|
||||||
input.addEventListener('keypress', function(e) {
|
input.addEventListener('keypress', function(e) {
|
||||||
@@ -307,16 +295,9 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set default date range (last 30 days)
|
// HAPUS bagian ini yang menyebabkan double API call:
|
||||||
const today = new Date();
|
// setTimeout(() => {
|
||||||
const thirtyDaysAgo = new Date(today.getTime() - (30 * 24 * 60 * 60 * 1000));
|
// applyFilters();
|
||||||
|
// }, 100);
|
||||||
endDateFilter.value = today.toISOString().split('T')[0];
|
|
||||||
startDateFilter.value = thirtyDaysAgo.toISOString().split('T')[0];
|
|
||||||
|
|
||||||
// Apply default filter
|
|
||||||
setTimeout(() => {
|
|
||||||
applyFilters();
|
|
||||||
}, 100);
|
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
Route::group(['prefix' => 'laporan-closing-balance', 'as' => 'laporan-closing-balance.', 'middleware' => ['auth']], function () {
|
Route::group(['prefix' => 'laporan-closing-balance', 'as' => 'laporan-closing-balance.', 'middleware' => ['auth']], function () {
|
||||||
Route::get('/datatables', [LaporanClosingBalanceController::class, 'dataForDatatables'])->name('datatables');
|
Route::get('/datatables', [LaporanClosingBalanceController::class, 'dataForDatatables'])->name('datatables');
|
||||||
Route::get('/export', [LaporanClosingBalanceController::class, 'export'])->name('export');
|
Route::get('/export', [LaporanClosingBalanceController::class, 'export'])->name('export');
|
||||||
|
Route::get('/{accountNumber}/{period}/download', [LaporanClosingBalanceController::class, 'download'])->name('download');
|
||||||
Route::get('/{accountNumber}/{period}', [LaporanClosingBalanceController::class, 'show'])->name('show');
|
Route::get('/{accountNumber}/{period}', [LaporanClosingBalanceController::class, 'show'])->name('show');
|
||||||
});
|
});
|
||||||
Route::resource('laporan-closing-balance', LaporanClosingBalanceController::class)->only(['index']);
|
Route::resource('laporan-closing-balance', LaporanClosingBalanceController::class)->only(['index']);
|
||||||
|
|||||||
Reference in New Issue
Block a user