feat(jobs): tambahkan job untuk memproses data entry statement
- Menambahkan kelas ProcessStmtEntryDataJob untuk memproses file CSV yang berisi data entry statement. - Membuat model TempStmtEntry untuk menyimpan data entry statement ke dalam database. - Menambahkan migrasi untuk membuat tabel temp_stmt_entry dengan kolom yang sesuai.
This commit is contained in:
68
app/Jobs/ProcessStmtEntryDataJob.php
Normal file
68
app/Jobs/ProcessStmtEntryDataJob.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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\TempStmtEntry;
|
||||
|
||||
class ProcessStmtEntryDataJob 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.STMT.ENTRY.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 TempStmtEntry())->getFillable();
|
||||
while (($row = fgetcsv($handle, 0, "/")) !== false) {
|
||||
if (count($headers) === count($row)) {
|
||||
$data = array_combine($headers, $row);
|
||||
|
||||
try {
|
||||
TempStmtEntry::updateOrCreate(['_id' => $data['_id']], $data);
|
||||
} catch (Exception $e) {
|
||||
Log::error('Error processing stmt entry: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
} else {
|
||||
throw new Exception("Unable to open file: {$filePath}");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::error('Error in ProcessStmtEntryDataJob: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
app/Models/TempStmtEntry.php
Normal file
24
app/Models/TempStmtEntry.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
// use Modules\Webstatement\Database\Factories\TempStmtEntryFactory;
|
||||
|
||||
class TempStmtEntry extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'temp_stmt_entry';
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = ['_id','stmt_entry_id','account_number','company_code','amount_lcy','transaction_code','their_reference','narrative','pl_category','customer_id','account_officer','product_category','value_date','amount_fcy','exchange_rate','negotiated_ref_num','position_type','our_reference','reversal_marker','exposure_date','currency_market','local_ref','department_code','trans_reference','system_id','booking_date','stmt_no','override','record_status','curr_no','inputter','date_time','authoriser','reserved_account_no','reserved_account','currency','reserved_acct_sel','amt_lcy','suspense_category','reserved_account_id','reserved_account_sel','suspnse_value_date','suppress_position','crf_type','crf_txn_code','crf_currency','crf_mat_date','reserved_fwd_acct_ids','reserved_statement_id','reserved_internal_category','crf_prod_cat','reserved_acct_vb_no','reserved_account_num','reserved_sel_value_date','reserved_include_liq_int','reserved_value_date_sel','reserved_select_account','reserved_stmt_date','reserved_stmt_freq','reserved_include_fwd_ent','pm_type','dealer_desk','counterparty','liquidation_mode','repayment_date','repayment_type','repayment_amt','outstanding_bal','contract_int_rate','contract_int_key','reserved_show_narrative','reserved_appl_drilldown','reserved_long_pos_sign','cycle_forward','reserved_overdue_entry','orig_local_equiv','original_amount','original_ccy','original_acct','original_exch_rate','exp_split_date','exp_split_amt','orig_amount_lcy','consol_key','bank_sort_cde','cheque_number','chq_coll_id','drawn_account','accounting_date','pc_period_end','pc_applied','amount_deal_ccy','deal_ccy','deal_exch_rate','mask_print','mask_narrative','stmt1_date','stmt2_date','chq_type','tax_exch_rate','net_param','master_account','addl_trans_ref','interest_rate','dd_mandate_ref','dd_item_ref','dd_mandate_date','reserved_co_code','contract_bal_id','trade_date','processing_date','balance_type','aa_item_ref','accrual_data','orig_ccy_market','reserved_11','reserved_12','card_number','card_txn_detail','reserved_acct_id','draft_payee_name','reserved_incl_sub_acct','reserved_show_reversal','process_forward','reserved_entry_ids','reserved_rmb1_account','reserved_no_of_entries','reserved_max_history_months','reserved_txn_date','reserved_in_start_date','reserved_in_end_date','aa_suspense_ref','pos_exp_date','rc_detail_id','tax_data','cus_pl_account','tdgl_details','reserved_bundle_arrangement','add_detail_name','add_detail_value','do_credit_check','posting_type','original_vd','reserved_sum_or_detail','reserved_in_end_time','reserved_txn_hist_acct_id','projection_details','credit_chk_dtls_name','credit_chk_dtls_value','reserved_order_by_dsnd','reserved_skip_token','reserved_with_balance','reserved_delta_list','reserved_booking_status','booked_balance_audit','soft_acctng_dtls','system_date_time','external_sepa_id'
|
||||
];
|
||||
|
||||
// protected static function newFactory(): TempStmtEntryFactory
|
||||
// {
|
||||
// // return TempStmtEntryFactory::new();
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user