feat(jobs): tambahkan job untuk memproses data transfer dana
- Menambahkan kelas ProcessFundsTransferDataJob untuk memproses file CSV transfer dana. - Membuat migrasi untuk tabel temp_funds_transfer dengan berbagai field yang diperlukan. - Menangani kesalahan saat membaca file dan mencatat kesalahan ke log.
This commit is contained in:
71
app/Jobs/ProcessFundsTransferDataJob.php
Normal file
71
app/Jobs/ProcessFundsTransferDataJob.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?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 Log;
|
||||||
|
use Modules\Webstatement\Models\TempFundsTransfer;
|
||||||
|
|
||||||
|
class ProcessFundsTransferDataJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
: void
|
||||||
|
{
|
||||||
|
$filePath = storage_path('app/20240901.ST.FUNDS.TRANSFER.csv'); // Adjust this path as needed
|
||||||
|
try {
|
||||||
|
if (!file_exists($filePath)) {
|
||||||
|
throw new Exception("File not found: $filePath");
|
||||||
|
}
|
||||||
|
|
||||||
|
set_time_limit(24 * 60 * 60);
|
||||||
|
|
||||||
|
if (!file_exists($filePath)) {
|
||||||
|
throw new Exception("File not found: {$filePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$handle = fopen($filePath, "r");
|
||||||
|
|
||||||
|
if ($handle !== false) {
|
||||||
|
$headers = (new TempFundsTransfer())->getFillable();
|
||||||
|
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||||
|
if (count($row) > count($headers)) {
|
||||||
|
$row = array_slice($row, 0, count($headers));
|
||||||
|
}
|
||||||
|
if (count($headers) === count($row)) {
|
||||||
|
$data = array_combine($headers, $row);
|
||||||
|
|
||||||
|
try {
|
||||||
|
TempFundsTransfer::updateOrCreate(['_id' => $data['_id']], $data);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error('Error processing funds transfer: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($handle);
|
||||||
|
} else {
|
||||||
|
throw new Exception("Unable to open file: {$filePath}");
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error('Error in ProcessFundsTransferDataJob: ' . $e->getMessage());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Models/TempFundsTransfer.php
Normal file
23
app/Models/TempFundsTransfer.php
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user