From 99d9f6cce1747e12a8430b7f2c577c091b329042 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 29 Jan 2025 19:41:21 +0700 Subject: [PATCH] feat(jobs): tambahkan job untuk memproses data pelanggan - Menambahkan kelas ProcessCustomerDataJob untuk memproses file CSV cusromer. - Menggunakan metode updateOrCreate untuk menyimpan atau memperbarui data customer. - Menangani pengecualian jika file tidak ditemukan atau tidak dapat dibuka. - Mengatur batas waktu eksekusi job menjadi 24 jam. --- app/Jobs/ProcessCustomerDataJob.php | 60 +++++++++++++++++++ ..._10_030946_create_temp_customers_table.php | 4 +- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 app/Jobs/ProcessCustomerDataJob.php diff --git a/app/Jobs/ProcessCustomerDataJob.php b/app/Jobs/ProcessCustomerDataJob.php new file mode 100644 index 0000000..518af43 --- /dev/null +++ b/app/Jobs/ProcessCustomerDataJob.php @@ -0,0 +1,60 @@ +getFillable(); + while (($row = fgetcsv($handle, 0, "~")) !== false) { + unset($row[0]); // Remove the first empty column if present + if (count($headers) === count($row)) { + $data = array_combine($headers, $row); + TempCustomer::updateOrCreate( + ['customer_code' => $data['customer_code']], // key to find existing record + $data // data to update or create + ); + } + } + fclose($handle); + } else { + throw new Exception("Unable to open file: {$filePath}"); + } + + return response()->json(['message' => 'Data Customer processing job has been successfully']); + } catch (Exception $e) { + return response()->json(['error' => $e->getMessage()], 500); + } + } +} diff --git a/database/migrations/2024_12_10_030946_create_temp_customers_table.php b/database/migrations/2024_12_10_030946_create_temp_customers_table.php index b2ea52c..5e08040 100644 --- a/database/migrations/2024_12_10_030946_create_temp_customers_table.php +++ b/database/migrations/2024_12_10_030946_create_temp_customers_table.php @@ -11,7 +11,7 @@ return new class extends Migration */ public function up(): void { - $fields = "@id,customer_code,customer_no,mnemonic,short_name,name_1,name_2,street,town_country,relation_code,rel_customer,revers_rel_code,sector,account_officer,other_officer,industry,target,nationality,customer_status,residence,contact_date,introducer,text,legal_id,review_frequency,birth_incorp_date,global_customer,customer_liability,language,local_ref,override,record_status,curr_no,inputter,date_time,authoriser,co_code,dept_code,auditor_code,audit_date_time,sector_name,posting_restrict,dispo_officer,post_code,country,confid_txt,dispo_exempt,issue_cheques,cls_cparty,fx_comm_group_id,residence_region,company_book,asset_class,customer_rating,address,cr_profile_type,cr_profile,no_update_crm,title,given_names,family_name,gender,date_of_birth,marital_status,no_of_dependents,phone_1,sms_1,email_1,employment_status,occupation,employers_name,employers_add,employers_buss,employment_start,customer_currency,salary,annual_bonus,salary_date_freq,net_monthly_in,net_monthly_out,residence_status,residence_type,residence_since,residence_value,mortgage_amt,other_fin_rel,other_fin_inst,comm_type,pref_channel,interests,fax_1,previous_name,change_date,change_reason,customer_since,reserved_account,customer_type,date_last_verified,rel_deliv_opt,rel_reserv6,rel_reserv5,rel_reserv4,rel_reserv3,rel_reserv2,rel_reserv1,reserved_51,role,role_more_info,role_notes,legal_doc_name,legal_iss_auth,legal_iss_date,legal_exp_date,off_phone,legal_holder_name,job_title,spoken_language,pastimes,further_details,domicile,other_nationality,calc_risk_class,manual_risk_class,override_reason,tax_id,vis_type,vis_comment,vis_internal_review,former_vis_type,former_vis_comment,risk_asset_type,risk_level,risk_tolerance,risk_from_date,last_kyc_review_date,auto_next_kyc_review_date,manual_next_kyc_review_date,last_suit_review_date,auto_next_suit_review_date,manual_next_suit_review_date,kyc_relationship,mandate_appl,mandate_reg,mandate_record,secure_message,aml_check,aml_result,last_aml_result_date,kyc_complete,internet_banking_service,mobile_banking_service,allow_bulk_process,report_template,holdings_pivot,reserved_account_no,reserved_card_no,reserved_include_image,reserved_portfolio_no,addr_location,legal_id_doc_name,merged_to,merged_status,alt_cus_id,extern_sys_id,extern_cus_id,social_ntw_ids,person_entity_id,reg_country,cr_user_profile_type,cr_calc_profile,cr_user_profile,cr_calc_reset_date,ref_data_item,ref_data_value,prob_of_deft,local_content,death_date,notification_of_death,probate_date,vulnerability,update_prev_address,name_alias,address_country,address_item1,address_item2,address_type,address_purpose,building_number,building_name,flat_number,po_box_number,country_subdivision,salutation,idd_prefix_phone,auto_upd_del_add,address_validated_by,contact_type,contact_data,exit_status,exit_reason,exit_date,department,sub_department,floor,town_location_name,district_name,cust_birth_province,cust_birth_city,cust_birth_country,legal_iss_ctry,segment,cu_eff_date,indus_classify,birth_province,vat_gst_id,wht_exempt,perm_est,tax_cert,eff_tax_res,last_version,otor_version,dhn_ac_closed,dhn_acct_no,dhn_amount,dhn_br_code,dhn_cheque,dhn_chq_type,dhn_date,dhn_flag,serial_token,credit_card,seg_industry,subseg_industry,desseg_industry,delivery_chnl,fdsl_crd_number,l_alias,l_no_of_dep,l_manual_tax,l_pisah_harta,l_share_data,l_hub_nasabah,l_cust_cash_mgm,email_address,inactive_cust,duplicate_cif,dup_of_cust,cus_npwp,badan_hukum,company_type,relasi_bisnis,contact_person,waive_tax_flag,mother_maid_nam,religion,last_education,place_of_birth,phone_area,phone2_area,alt_cust_id,cus_open_date,comp_permit_no,company_bank,no_akta_awal,tgl_akta_awal,no_akta_akhir,tgl_akta_akhir,reason_code,bank_name,type_of_loan,loan_value,fixed_allowance,other_income,no_of_wife,no_of_child,no_of_parents,no_daf_hit_nat,no_referensi,peng_id,peng_identitas,peng_id_jabatan,peng_nama,peng_npwp,peng_jenis_kela,peng_alamat,peng_dati2,peng_kelurahan,peng_kecamatan,peng_pemilikan,peng_saham,peng_date,peng_status,peng_reserved1,peng_reserved2,peng_reserved3,ktp_rt,ktp_rw,ktp_kelurahan,ktp_kecamatan,ktp_provinsi,ktp_coordinate,ktp_addr_flag,ktp_reserved1,ktp_reserved2,ktp_reserved3,kyc_fund_src,kyc_income_src,kyc_incom_rng,kyc_intend_fund,kyc_purpose_acc,kyc_cash_dep_li,kyc_cash_dep_fq,kyc_cash_wd_lim,kyc_cash_wd_fq,kyc_noncash_lim,kyc_noncash_fq,kyc_busi_lic_no,kyc_revenue,kyc_jenis_peng,kyc_sumber_dana,kyc_non_cash_wd,kyc_noncash_fqu,kyc_juml_kary,kyc_bus_lic_dt,kyc_cap_owner,kyc_akte_no,home_street,home_rt,home_rw,home_kelurahan,home_kecamatan,home_provinsi,home_coordinate,home_post_code,hm_town_country,spouse_id,spouse_name,spouse_address,spouse_phone,spou_dt_of_birt,spou_pl_of_birt,con_nama,con_date_birth,con_rt,con_rw,con_kelurahan,con_kecamatan,con_kota,con_provinsi,con_post_code,con_warganegara,con_negara_asal,con_phone_area,con_phone_no,con_fax_no,con_jenis_id,con_id_exp,con_id_no,con_jenis_kerja,con_pangkat,con_email,con_npwp,con_reserved1,con_reserved2,con_reserved3,cp_relation,cp_address,residence_month,residence_year,parent_customer,rel_to_parent,sid_id_debitur,sid_gelar,sid_hub_bank,sid_din,sid_gol_deb,sid_jenis_usaha,sid_sektor_econ,sid_dati2debtor,sid_tmp_akte_ak,sid_tgl_akte_ak,sid_group_id,sid_group_name,sid_melanggar,sid_melampaui,sid_rating_deb,sid_lembaga,sid_go_public,sid_related,sid_sifat_kredi,sid_pihak_kait,sid_kat_deb,sid_kat_port,sid_lokasi_pryk,sid_rating_tgl,sid_dati2_lahir,sid_tmpt_usaha,sid_reserved1,sid_reserved2,sid_reserved3,lbu_gol_deb,lbu_status_deb,lbu_sandi_bank,ben_name,ben_agama,ben_alamat,ben_kelurahan,ben_kecamatan,ben_kodepos,ben_provinsi,ben_domisili,ben_handphone,ben_telephone,ben_income,ben_info_lain,ben_izin_usaha,ben_jenis_peng,ben_jns_kelamin,ben_lahir_tgl,ben_lahir_tmp,ben_status,ben_sumber_dana,ben_usaha_bid,ben_usaha_btk,ben_corp_name,ben_corp_info,ben_corp_smb_dn,ben_corp_tp_dn,ben_corp_alamat,off_street,off_town_city,off_provinsi,off_post_code,con_relation,con_phone,con_address,fdsl_cu_rsk_flg,red_flag,mailing_address,l_cus_gelar,lbu_gol_jamin,term_id,mail_address,mail_city,mail_kecamatan,mail_kelurahan,mail_provinsi,mail_rt,mail_rw,mail_post_code,is_cust_doc,is_corp_doc,off_phone_1,dhn_otc,l_ph_area,l_ph_no,l_email_addr,l_fax_no,off_ph_area,off_ph_no,oth_mobile_no,off_email,ben_npwp,ben_nationality,ben_town_countr,ben_legal_no,ben_occupation,ben_legal_doc_n,l_dukcapil_flag,sp_npwp,sp_religion,sp_gender,sp_province,sp_town_country,sp_kecamatan,sp_kelurahan,sp_rt,sp_rw,sp_education,sp_mother_name,sp_con_address,sp_sms_1,sp_email_1,sp_occupation,sp_salary,sp_net_income,sp_empl_name,sp_job_title,sp_empl_add,sp_empl_start,sp_empl_phone,sp_empl_fax,sikp_no_reg,l_bsns_start,l_bsns_addr,l_bsns_permit,l_bsns_capital,l_ttl_employ,l_ttl_credit,l_is_linkage,l_linkage,l_is_subsidized,l_subsidize_bfr,sikp_kode_wlyh,l_chn_status,l_chn_ref,sikp_coll_desc,l_nama_waris,l_alamat_waris,l_hub_waris,l_last_cek_no,trans_reff,term_type,recipt_no,l_nama_kuasa,l_alamat_kuasa,l_kd_id_kuasa,l_no_id_kuasa,l_hub_dgn_nsb,l_no_fdn,l_jns_pinjaman,l_kd_dati_i,l_kd_dati_ii,l_kd_kecamatan,l_kelurahan,l_alt_loan_sikp,atm_number,bo_nama_id,bo_jns_kelamin,bo_st_nikah,bo_alamat_id,bo_kel_id,bo_kec_id,bo_kota_id,bo_prov_id,bo_kodepos_id,bo_domisili,bo_nation_id,bo_telephone,bo_handphone,bo_info_lain,bo_lahir_tmp,bo_lahir_tgl,bo_occupation,bo_sumber_dana,bo_income,bo_jenis_peng,bo_npwp,bo_legal_no,bo_legal_doc,bo_corp_name,bo_usaha_bid,bo_usaha_btk,bo_corp_alamat,bo_corp_sumb_dn,bo_corp_tp_dn,bo_corp_info,l_status_data,l_full_name,l_cif_syariah,referral_code,l_kelurahan_des,l_province_desc,kyc_income_amt,ben_addr_flag,suspected_type,suspected_news,l_tm_akt_keluar,l_sms_no,kode_bekerja,l_kel_nasabah,last_upd_apuppt,l_cus_note,l_prd_bnk,l_kyc_asset,l_kyc_laba_rugi,score_date,credit_score,credit_bureau,l_share_product,ben_hub_nasabah,kyc_juml_kry,ben_kota,kyc_income_oth,l_bo_relation,l_dom_street,l_dom_rt,l_dom_rw,l_dom_kelurahan,l_dom_kecamatan,l_dom_provinsi,l_dom_post_code,l_dom_t_country,l_alasan,l_pep_suspect,l_pep_name,l_kyc_segment,l_bank_code"; + $fields = "_id,customer_code,customer_no,mnemonic,short_name,name_1,name_2,street,town_country,relation_code,rel_customer,revers_rel_code,sector,account_officer,other_officer,industry,target,nationality,customer_status,residence,contact_date,introducer,text,legal_id,review_frequency,birth_incorp_date,global_customer,customer_liability,language,local_ref,override,record_status,curr_no,inputter,date_time,authoriser,co_code,dept_code,auditor_code,audit_date_time,sector_name,posting_restrict,dispo_officer,post_code,country,confid_txt,dispo_exempt,issue_cheques,cls_cparty,fx_comm_group_id,residence_region,company_book,asset_class,customer_rating,address,cr_profile_type,cr_profile,no_update_crm,title,given_names,family_name,gender,date_of_birth,marital_status,no_of_dependents,phone_1,sms_1,email_1,employment_status,occupation,employers_name,employers_add,employers_buss,employment_start,customer_currency,salary,annual_bonus,salary_date_freq,net_monthly_in,net_monthly_out,residence_status,residence_type,residence_since,residence_value,mortgage_amt,other_fin_rel,other_fin_inst,comm_type,pref_channel,interests,fax_1,previous_name,change_date,change_reason,customer_since,reserved_account,customer_type,date_last_verified,rel_deliv_opt,rel_reserv6,rel_reserv5,rel_reserv4,rel_reserv3,rel_reserv2,rel_reserv1,reserved_51,role,role_more_info,role_notes,legal_doc_name,legal_iss_auth,legal_iss_date,legal_exp_date,off_phone,legal_holder_name,job_title,spoken_language,pastimes,further_details,domicile,other_nationality,calc_risk_class,manual_risk_class,override_reason,tax_id,vis_type,vis_comment,vis_internal_review,former_vis_type,former_vis_comment,risk_asset_type,risk_level,risk_tolerance,risk_from_date,last_kyc_review_date,auto_next_kyc_review_date,manual_next_kyc_review_date,last_suit_review_date,auto_next_suit_review_date,manual_next_suit_review_date,kyc_relationship,mandate_appl,mandate_reg,mandate_record,secure_message,aml_check,aml_result,last_aml_result_date,kyc_complete,internet_banking_service,mobile_banking_service,allow_bulk_process,report_template,holdings_pivot,reserved_account_no,reserved_card_no,reserved_include_image,reserved_portfolio_no,addr_location,legal_id_doc_name,merged_to,merged_status,alt_cus_id,extern_sys_id,extern_cus_id,social_ntw_ids,person_entity_id,reg_country,cr_user_profile_type,cr_calc_profile,cr_user_profile,cr_calc_reset_date,ref_data_item,ref_data_value,prob_of_deft,local_content,death_date,notification_of_death,probate_date,vulnerability,update_prev_address,name_alias,address_country,address_item1,address_item2,address_type,address_purpose,building_number,building_name,flat_number,po_box_number,country_subdivision,salutation,idd_prefix_phone,auto_upd_del_add,address_validated_by,contact_type,contact_data,exit_status,exit_reason,exit_date,department,sub_department,floor,town_location_name,district_name,cust_birth_province,cust_birth_city,cust_birth_country,legal_iss_ctry,segment,cu_eff_date,indus_classify,birth_province,vat_gst_id,wht_exempt,perm_est,tax_cert,eff_tax_res,last_version,otor_version,dhn_ac_closed,dhn_acct_no,dhn_amount,dhn_br_code,dhn_cheque,dhn_chq_type,dhn_date,dhn_flag,serial_token,credit_card,seg_industry,subseg_industry,desseg_industry,delivery_chnl,fdsl_crd_number,l_alias,l_no_of_dep,l_manual_tax,l_pisah_harta,l_share_data,l_hub_nasabah,l_cust_cash_mgm,email_address,inactive_cust,duplicate_cif,dup_of_cust,cus_npwp,badan_hukum,company_type,relasi_bisnis,contact_person,waive_tax_flag,mother_maid_nam,religion,last_education,place_of_birth,phone_area,phone2_area,alt_cust_id,cus_open_date,comp_permit_no,company_bank,no_akta_awal,tgl_akta_awal,no_akta_akhir,tgl_akta_akhir,reason_code,bank_name,type_of_loan,loan_value,fixed_allowance,other_income,no_of_wife,no_of_child,no_of_parents,no_daf_hit_nat,no_referensi,peng_id,peng_identitas,peng_id_jabatan,peng_nama,peng_npwp,peng_jenis_kela,peng_alamat,peng_dati2,peng_kelurahan,peng_kecamatan,peng_pemilikan,peng_saham,peng_date,peng_status,peng_reserved1,peng_reserved2,peng_reserved3,ktp_rt,ktp_rw,ktp_kelurahan,ktp_kecamatan,ktp_provinsi,ktp_coordinate,ktp_addr_flag,ktp_reserved1,ktp_reserved2,ktp_reserved3,kyc_fund_src,kyc_income_src,kyc_incom_rng,kyc_intend_fund,kyc_purpose_acc,kyc_cash_dep_li,kyc_cash_dep_fq,kyc_cash_wd_lim,kyc_cash_wd_fq,kyc_noncash_lim,kyc_noncash_fq,kyc_busi_lic_no,kyc_revenue,kyc_jenis_peng,kyc_sumber_dana,kyc_non_cash_wd,kyc_noncash_fqu,kyc_juml_kary,kyc_bus_lic_dt,kyc_cap_owner,kyc_akte_no,home_street,home_rt,home_rw,home_kelurahan,home_kecamatan,home_provinsi,home_coordinate,home_post_code,hm_town_country,spouse_id,spouse_name,spouse_address,spouse_phone,spou_dt_of_birt,spou_pl_of_birt,con_nama,con_date_birth,con_rt,con_rw,con_kelurahan,con_kecamatan,con_kota,con_provinsi,con_post_code,con_warganegara,con_negara_asal,con_phone_area,con_phone_no,con_fax_no,con_jenis_id,con_id_exp,con_id_no,con_jenis_kerja,con_pangkat,con_email,con_npwp,con_reserved1,con_reserved2,con_reserved3,cp_relation,cp_address,residence_month,residence_year,parent_customer,rel_to_parent,sid_id_debitur,sid_gelar,sid_hub_bank,sid_din,sid_gol_deb,sid_jenis_usaha,sid_sektor_econ,sid_dati2debtor,sid_tmp_akte_ak,sid_tgl_akte_ak,sid_group_id,sid_group_name,sid_melanggar,sid_melampaui,sid_rating_deb,sid_lembaga,sid_go_public,sid_related,sid_sifat_kredi,sid_pihak_kait,sid_kat_deb,sid_kat_port,sid_lokasi_pryk,sid_rating_tgl,sid_dati2_lahir,sid_tmpt_usaha,sid_reserved1,sid_reserved2,sid_reserved3,lbu_gol_deb,lbu_status_deb,lbu_sandi_bank,ben_name,ben_agama,ben_alamat,ben_kelurahan,ben_kecamatan,ben_kodepos,ben_provinsi,ben_domisili,ben_handphone,ben_telephone,ben_income,ben_info_lain,ben_izin_usaha,ben_jenis_peng,ben_jns_kelamin,ben_lahir_tgl,ben_lahir_tmp,ben_status,ben_sumber_dana,ben_usaha_bid,ben_usaha_btk,ben_corp_name,ben_corp_info,ben_corp_smb_dn,ben_corp_tp_dn,ben_corp_alamat,off_street,off_town_city,off_provinsi,off_post_code,con_relation,con_phone,con_address,fdsl_cu_rsk_flg,red_flag,mailing_address,l_cus_gelar,lbu_gol_jamin,term_id,mail_address,mail_city,mail_kecamatan,mail_kelurahan,mail_provinsi,mail_rt,mail_rw,mail_post_code,is_cust_doc,is_corp_doc,off_phone_1,dhn_otc,l_ph_area,l_ph_no,l_email_addr,l_fax_no,off_ph_area,off_ph_no,oth_mobile_no,off_email,ben_npwp,ben_nationality,ben_town_countr,ben_legal_no,ben_occupation,ben_legal_doc_n,l_dukcapil_flag,sp_npwp,sp_religion,sp_gender,sp_province,sp_town_country,sp_kecamatan,sp_kelurahan,sp_rt,sp_rw,sp_education,sp_mother_name,sp_con_address,sp_sms_1,sp_email_1,sp_occupation,sp_salary,sp_net_income,sp_empl_name,sp_job_title,sp_empl_add,sp_empl_start,sp_empl_phone,sp_empl_fax,sikp_no_reg,l_bsns_start,l_bsns_addr,l_bsns_permit,l_bsns_capital,l_ttl_employ,l_ttl_credit,l_is_linkage,l_linkage,l_is_subsidized,l_subsidize_bfr,sikp_kode_wlyh,l_chn_status,l_chn_ref,sikp_coll_desc,l_nama_waris,l_alamat_waris,l_hub_waris,l_last_cek_no,trans_reff,term_type,recipt_no,l_nama_kuasa,l_alamat_kuasa,l_kd_id_kuasa,l_no_id_kuasa,l_hub_dgn_nsb,l_no_fdn,l_jns_pinjaman,l_kd_dati_i,l_kd_dati_ii,l_kd_kecamatan,l_kelurahan,l_alt_loan_sikp,atm_number,bo_nama_id,bo_jns_kelamin,bo_st_nikah,bo_alamat_id,bo_kel_id,bo_kec_id,bo_kota_id,bo_prov_id,bo_kodepos_id,bo_domisili,bo_nation_id,bo_telephone,bo_handphone,bo_info_lain,bo_lahir_tmp,bo_lahir_tgl,bo_occupation,bo_sumber_dana,bo_income,bo_jenis_peng,bo_npwp,bo_legal_no,bo_legal_doc,bo_corp_name,bo_usaha_bid,bo_usaha_btk,bo_corp_alamat,bo_corp_sumb_dn,bo_corp_tp_dn,bo_corp_info,l_status_data,l_full_name,l_cif_syariah,referral_code,l_kelurahan_des,l_province_desc,kyc_income_amt,ben_addr_flag,suspected_type,suspected_news,l_tm_akt_keluar,l_sms_no,kode_bekerja,l_kel_nasabah,last_upd_apuppt,l_cus_note,l_prd_bnk,l_kyc_asset,l_kyc_laba_rugi,score_date,credit_score,credit_bureau,l_share_product,ben_hub_nasabah,kyc_juml_kry,ben_kota,kyc_income_oth,l_bo_relation,l_dom_street,l_dom_rt,l_dom_rw,l_dom_kelurahan,l_dom_kecamatan,l_dom_provinsi,l_dom_post_code,l_dom_t_country,l_alasan,l_pep_suspect,l_pep_name,l_kyc_segment,l_bank_code"; $fieldArray = explode(',', $fields); @@ -19,7 +19,7 @@ return new class extends Migration $table->id(); foreach ($fieldArray as $field) { $field = trim($field); - if ($field !== '@id') { // Skip @id as we already have $table->id() + if ($field !== '_id') { // Skip @id as we already have $table->id() $table->text($field)->nullable(); } }