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
131 lines
4.8 KiB
PHP
131 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use BadMethodCallException;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Modules\Webstatement\Jobs\{ProcessAccountDataJob,
|
|
ProcessArrangementDataJob,
|
|
ProcessAtmTransactionJob,
|
|
ProcessBillDetailDataJob,
|
|
ProcessCategoryDataJob,
|
|
ProcessCompanyDataJob,
|
|
ProcessCustomerDataJob,
|
|
ProcessDataCaptureDataJob,
|
|
ProcessFtTxnTypeConditionJob,
|
|
ProcessFundsTransferDataJob,
|
|
ProcessStmtEntryDataJob,
|
|
ProcessStmtNarrFormatDataJob,
|
|
ProcessStmtNarrParamDataJob,
|
|
ProcessTellerDataJob,
|
|
ProcessTransactionDataJob,
|
|
ProcessSectorDataJob,
|
|
ProcessProvinceDataJob,
|
|
ProcessStmtEntryDetailDataJob};
|
|
|
|
class MigrasiController extends Controller
|
|
{
|
|
private const PROCESS_TYPES = [
|
|
'transaction' => ProcessTransactionDataJob::class,
|
|
'stmtNarrParam' => ProcessStmtNarrParamDataJob::class,
|
|
'stmtNarrFormat' => ProcessStmtNarrFormatDataJob::class,
|
|
'ftTxnTypeCondition' => ProcessFtTxnTypeConditionJob::class,
|
|
'category' => ProcessCategoryDataJob::class,
|
|
'company' => ProcessCompanyDataJob::class,
|
|
'customer' => ProcessCustomerDataJob::class,
|
|
'account' => ProcessAccountDataJob::class,
|
|
'stmtEntry' => ProcessStmtEntryDataJob::class,
|
|
'stmtEntryDetail' => ProcessStmtEntryDetailDataJob::class, // Tambahan baru
|
|
'dataCapture' => ProcessDataCaptureDataJob::class,
|
|
'fundsTransfer' => ProcessFundsTransferDataJob::class,
|
|
'teller' => ProcessTellerDataJob::class,
|
|
'atmTransaction' => ProcessAtmTransactionJob::class,
|
|
'arrangement' => ProcessArrangementDataJob::class,
|
|
'billDetail' => ProcessBillDetailDataJob::class,
|
|
'sector' => ProcessSectorDataJob::class,
|
|
'province' => ProcessProvinceDataJob::class
|
|
];
|
|
|
|
private const PARAMETER_PROCESSES = [
|
|
'transaction',
|
|
'stmtNarrParam',
|
|
'stmtNarrFormat',
|
|
'ftTxnTypeCondition',
|
|
'sector',
|
|
'province'
|
|
];
|
|
|
|
private const DATA_PROCESSES = [
|
|
'category',
|
|
'company',
|
|
'customer',
|
|
'account',
|
|
'stmtEntry',
|
|
'stmtEntryDetail', // Tambahan baru
|
|
'dataCapture',
|
|
'fundsTransfer',
|
|
'teller',
|
|
'atmTransaction',
|
|
'arrangement',
|
|
'billDetail'
|
|
];
|
|
|
|
public function __call($method, $parameters)
|
|
{
|
|
if (strpos($method, 'process') === 0) {
|
|
$type = lcfirst(substr($method, 7));
|
|
if (isset(self::PROCESS_TYPES[$type])) {
|
|
return $this->processData($type, $parameters[0] ?? '');
|
|
}
|
|
}
|
|
throw new BadMethodCallException("Method {$method} does not exist.");
|
|
}
|
|
|
|
private function processData(string $type, string $period)
|
|
: JsonResponse
|
|
{
|
|
try {
|
|
$jobClass = self::PROCESS_TYPES[$type];
|
|
$jobClass::dispatch($period);
|
|
|
|
$message = sprintf('%s data processing job has been queued successfully', ucfirst($type));
|
|
Log::info($message);
|
|
|
|
return response()->json(['message' => $message]);
|
|
} catch (Exception $e) {
|
|
Log::error(sprintf('Error in %s processing: %s', $type, $e->getMessage()));
|
|
return response()->json(['error' => $e->getMessage()], 500);
|
|
}
|
|
}
|
|
public function index($processParameter = false)
|
|
{
|
|
$disk = Storage::disk('sftpStatement');
|
|
|
|
if ($processParameter) {
|
|
foreach (self::PARAMETER_PROCESSES as $process) {
|
|
$this->processData($process, '_parameter');
|
|
}
|
|
return response()->json(['message' => 'Parameter processes completed successfully']);
|
|
}
|
|
|
|
$period = date('Ymd', strtotime('-1 day'));
|
|
if (!$disk->exists($period)) {
|
|
return response()->json([
|
|
"message" => "Period {$period} folder not found in SFTP storage"
|
|
], 404);
|
|
}
|
|
|
|
foreach (self::DATA_PROCESSES as $process) {
|
|
$this->processData($process, $period);
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => "Data processing for period {$period} has been queued successfully"
|
|
]);
|
|
}
|
|
}
|