feat(account): perbarui logika pemrosesan data akun
- Ganti penggunaan model TempAccount dengan Account. - Perbarui jalur file CSV yang digunakan untuk pemrosesan. - Tambahkan logika untuk mengatur nilai default untuk 'start_year_bal' dan 'closure_date'. - Gunakan firstOrNew untuk menyimpan data akun.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Log;
|
use Log;
|
||||||
use Modules\Webstatement\Models\TempAccount;
|
use Modules\Webstatement\Models\Account;
|
||||||
|
|
||||||
class ProcessAccountDataJob implements ShouldQueue
|
class ProcessAccountDataJob implements ShouldQueue
|
||||||
{
|
{
|
||||||
@@ -29,28 +29,41 @@
|
|||||||
public function handle()
|
public function handle()
|
||||||
: void
|
: void
|
||||||
{
|
{
|
||||||
$filePath = storage_path('app/20240901.ST.ACCOUNT.csv'); // Adjust this path as needed
|
$filePath = storage_path('app/20250207.ST.ACCOUNT.csv'); // Use Storage facade
|
||||||
try {
|
try {
|
||||||
if (!file_exists($filePath)) {
|
|
||||||
throw new Exception("File not found: $filePath");
|
|
||||||
}
|
|
||||||
|
|
||||||
set_time_limit(24 * 60 * 60);
|
|
||||||
|
|
||||||
if (!file_exists($filePath)) {
|
if (!file_exists($filePath)) {
|
||||||
throw new Exception("File not found: {$filePath}");
|
throw new Exception("File not found: {$filePath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$handle = fopen($filePath, "r");
|
set_time_limit(24 * 60 * 60);
|
||||||
|
|
||||||
|
$handle = fopen($filePath, "r");
|
||||||
if ($handle !== false) {
|
if ($handle !== false) {
|
||||||
$headers = (new TempAccount())->getFillable();
|
|
||||||
while (($row = fgetcsv($handle, 0, ";")) !== false) {
|
// Use the header row to determine the order of columns
|
||||||
|
$headers = (new Account())->getFillable();
|
||||||
|
Log::info('Headers: ' . implode(", ", $headers));
|
||||||
|
$rowCount = 0;
|
||||||
|
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||||
if (count($headers) === count($row)) {
|
if (count($headers) === count($row)) {
|
||||||
$data = array_combine($headers, $row);
|
$data = array_combine($headers, $row);
|
||||||
|
|
||||||
|
// Check if start_year_bal is empty and set it to 0 if so
|
||||||
|
if (empty($data['start_year_bal']) || $data['start_year_bal'] ="" || $data['start_year_bal']== null) {
|
||||||
|
$data['start_year_bal'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($data['closure_date']) || $data['closure_date'] ="" || $data['closure_date']== null) {
|
||||||
|
$data['closure_date'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TempAccount::updateOrCreate(['account_number' => $data['account_number']], $data);
|
// Use firstOrNew instead of updateOrCreate
|
||||||
|
$account = Account::firstOrNew(['account_number' => $data['account_number']]);
|
||||||
|
$account->fill($data);
|
||||||
|
$account->save();
|
||||||
|
$rowCount++;
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error('Error processing Account: ' . $e->getMessage());
|
Log::error('Error processing Account: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,18 @@ class Account extends Model
|
|||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'account_number',
|
'account_number',
|
||||||
'customer_code',
|
'customer_no',
|
||||||
'currency',
|
'currency',
|
||||||
'opening_date',
|
'opening_date',
|
||||||
'branch_code',
|
'co_code',
|
||||||
'product_category',
|
'open_category',
|
||||||
|
'start_year_bal',
|
||||||
|
'closure_date',
|
||||||
|
'account_type',
|
||||||
|
'stmt_email',
|
||||||
|
'stmt_sent_type'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
// Relationships
|
// Relationships
|
||||||
public function customer()
|
public function customer()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user