<?php

namespace Database\Seeders;

use App\Models\Akun;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;

class AkunsTableSeeder extends Seeder
{
    public function run()
    {
        $akun1 = 'Biaya yang Masih Harus Dibayar';
        $existing1 = DB::table('akuns')->where('name', $akun1)->first();
        if (!$existing1) {
            DB::table('akuns')->insert([
                'perent_id' => 48,
                'name' => $akun1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun2 = 'Hutang Pembelian Aset Tetap';
        $existing2 = DB::table('akuns')->where('name', $akun2)->first();
        if (!$existing2) {
            DB::table('akuns')->insert([
                'perent_id' => 48,
                'name' => $akun2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun3 = 'Cadangan Wajib';
        $existing3 = DB::table('akuns')->where('name', $akun3)->first();
        if (!$existing3) {
            DB::table('akuns')->insert([
                'perent_id' => 2,
                'name' => $akun3,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun4 = 'Simpanan Wajib';
        $existing4 = DB::table('akuns')->where('name', $akun4)->first();
        if (!$existing4) {
            DB::table('akuns')->insert([
                'perent_id' => 2,
                'name' => $akun4,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun4x2 = 'untuk_program_pendidikan';
        $existing4x2 = DB::table('akuns')->where('name', $akun4x2)->first();
        if (!$existing4x2) {
            DB::table('akuns')->insert([
                'perent_id' => 2,
                'name' => $akun4x2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun4x3 = 'untuk_program_kesehatan';
        $existing4x3 = DB::table('akuns')->where('name', $akun4x3)->first();
        if (!$existing4x3) {
            DB::table('akuns')->insert([
                'perent_id' => 2,
                'name' => $akun4x3,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun4x4 = 'dana_abadi_endowment_fund';
        $existing4x4 = DB::table('akuns')->where('name', $akun4x4)->first();
        if (!$existing4x4) {
            DB::table('akuns')->insert([
                'perent_id' => 2,
                'name' => $akun4x4,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun4x5 = 'pembatasan_waktu_temporer';
        $existing4x5 = DB::table('akuns')->where('name', $akun4x5)->first();
        if (!$existing4x5) {
            DB::table('akuns')->insert([
                'perent_id' => 2,
                'name' => $akun4x5,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun5 = 'Prive';
        $existing5 = DB::table('akuns')->where('name', $akun5)->first();
        if (!$existing5) {
            DB::table('akuns')->insert([
                'perent_id' => 2,
                'name' => $akun5,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun6 = 'Persediaan';
        $existing6 = DB::table('akuns')->where('name', $akun6)->first();
        if (!$existing6) {
            DB::table('akuns')->insert([
                'perent_id' => 7,
                'name' => $akun6,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun7 = 'Persediaan Bahan Baku';
        $existing7 = DB::table('akuns')->where('name', $akun7)->first();
        if (!$existing7) {
            DB::table('akuns')->insert([
                'perent_id' => 7,
                'name' => $akun7,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun8 = 'Persediaan Barang Dalam Proses';
        $existing8 = DB::table('akuns')->where('name', $akun8)->first();
        if (!$existing8) {
            DB::table('akuns')->insert([
                'perent_id' => 7,
                'name' => $akun8,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun9 = 'Persediaan Barang Jadi';
        $existing9 = DB::table('akuns')->where('name', $akun9)->first();
        if (!$existing9) {
            DB::table('akuns')->insert([
                'perent_id' => 7,
                'name' => $akun9,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun10 = 'hutang_upah_produksi_v1';
        $existing10 = DB::table('akuns')->where('name', $akun10)->first();
        if (!$existing10) {
            DB::table('akuns')->insert([
                'perent_id' => 48,
                'name' => $akun10,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akunHPP = DB::table('akuns')->where('name', 'HPP')->first();

        $akun11 = 'selisih_tenaga_kerja_langsung';
        $existing11 = DB::table('akuns')->where('name', $akun11)->first();
        if (!$existing11) {
            DB::table('akuns')->insert([
                'perent_id' => $akunHPP->id,
                'name' => $akun11,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun12 = 'selisih_overhead_pabrik';
        $existing12 = DB::table('akuns')->where('name', $akun12)->first();
        if (!$existing12) {
            DB::table('akuns')->insert([
                'perent_id' => $akunHPP->id,
                'name' => $akun12,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akunSelisihTenagaKerja = DB::table('akuns')->where('name', 'selisih_tenaga_kerja_langsung')->first();
        $akunSelisihOverhead = DB::table('akuns')->where('name', 'selisih_overhead_pabrik')->first();

        $akun13 = 'biaya_tenaga_kerja_langsung_aktual';
        $existing13 = DB::table('akuns')->where('name', $akun13)->first();
        if (!$existing13) {
            DB::table('akuns')->insert([
                'perent_id' => $akunSelisihTenagaKerja->id,
                'name' => $akun13,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun14 = 'biaya_tenaga_kerja_langsung_dibebankan';
        $existing14 = DB::table('akuns')->where('name', $akun14)->first();
        if (!$existing14) {
            DB::table('akuns')->insert([
                'perent_id' => $akunSelisihTenagaKerja->id,
                'name' => $akun14,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun15 = 'biaya_overhead_pabrik_aktual';
        $existing15 = DB::table('akuns')->where('name', $akun15)->first();
        if (!$existing15) {
            DB::table('akuns')->insert([
                'perent_id' => $akunSelisihOverhead->id,
                'name' => $akun15,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun16 = 'biaya_overhead_pabrik_dibebankan';
        $existing16 = DB::table('akuns')->where('name', $akun16)->first();
        if (!$existing16) {
            DB::table('akuns')->insert([
                'perent_id' => $akunSelisihOverhead->id,
                'name' => $akun16,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akunOverheadAktual = DB::table('akuns')->where('name', 'biaya_overhead_pabrik_aktual')->first();
        $akunOverheadDibebankan = DB::table('akuns')->where('name', 'biaya_overhead_pabrik_dibebankan')->first();
        Log::info('akunOverheadAktual: ' . $akunOverheadAktual->id);
        Log::info('akunOverheadDibebankan: ' . $akunOverheadDibebankan->id);

        $akun17 = 'biaya_listrik_aktual';
        $existing17 = DB::table('akuns')->where('name', $akun17)->first();
        if (!$existing17) {
            DB::table('akuns')->insert([
                'perent_id' => $akunOverheadAktual->id,
                'name' => $akun17,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun18 = 'biaya_listrik_dibebankan';
        $existing18 = DB::table('akuns')->where('name', $akun18)->first();
        if (!$existing18) {
            DB::table('akuns')->insert([
                'perent_id' => $akunOverheadDibebankan->id,
                'name' => $akun18,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun19 = 'biaya_tenaga_kerja_tidak_langsung_aktual';
        $existing19 = DB::table('akuns')->where('name', $akun19)->first();
        if (!$existing19) {
            DB::table('akuns')->insert([
                'perent_id' => $akunOverheadAktual->id,
                'name' => $akun19,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun20 = 'biaya_tenaga_kerja_tidak_langsung_dibebankan';
        $existing20 = DB::table('akuns')->where('name', $akun20)->first();
        if (!$existing20) {
            DB::table('akuns')->insert([
                'perent_id' => $akunOverheadDibebankan->id,
                'name' => $akun20,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun21 = 'biaya_penyusutan_pabrik_aktual';
        $existing21 = DB::table('akuns')->where('name', $akun21)->first();
        if (!$existing21) {
            DB::table('akuns')->insert([
                'perent_id' => $akunOverheadAktual->id,
                'name' => $akun21,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun21x2 = 'biaya_cukai_aktual';
        $existing21x2 = DB::table('akuns')->where('name', $akun21x2)->first();
        if (!$existing21x2) {
            DB::table('akuns')->insert([
                'perent_id' => $akunOverheadAktual->id,
                'name' => $akun21x2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun22 = 'biaya_penyusutan_pabrik_dibebankan';
        $existing22 = DB::table('akuns')->where('name', $akun22)->first();
        if (!$existing22) {
            DB::table('akuns')->insert([
                'perent_id' => $akunOverheadDibebankan->id,
                'name' => $akun22,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun22x2 = 'biaya_cukai_dibebankan';
        $existing22x2 = DB::table('akuns')->where('name', $akun22x2)->first();
        if (!$existing22x2) {
            DB::table('akuns')->insert([
                'perent_id' => $akunOverheadDibebankan->id,
                'name' => $akun22x2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun23 = 'hutang_biaya_overhead_v1';
        $existing23 = DB::table('akuns')->where('name', $akun23)->first();
        if (!$existing23) {
            DB::table('akuns')->insert([
                'perent_id' => 48,
                'name' => $akun23,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun24 = 'Utang_Dividen';
        $existingakun24 = DB::table('akuns')->where('name', $akun24)->first();
        if (!$existingakun24) {
            DB::table('akuns')->insert([
                'perent_id' => 5,
                'name' => $akun24,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $piutangdagang = Akun::where('name', '=', 'Piutang Dagang')->first();

        $akun25 = 'pendapatan_yang_masih_harus_diterima';
        $existingakun25 = DB::table('akuns')->where('name', $akun25)->first();
        if (!$existingakun25) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangdagang->id,
                'name' => $akun25,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $akun26 = 'piutang_penjualan_aset_tetap';
        $existingakun26 = DB::table('akuns')->where('name', $akun26)->first();
        if (!$existingakun26) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangdagang->id,
                'name' => $akun26,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak1 = 'Piutang_Pajak';
        $existingPajak1 = DB::table('akuns')->where('name', $pajak1)->first();
        if (!$existingPajak1) {
            DB::table('akuns')->insert([
                'perent_id' => 7,
                'name' => $pajak1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $piutangpajak = DB::table('akuns')->where('name', $pajak1)->first();

        $pajak2 = 'PPN_Masukan';
        $existingPajak2 = DB::table('akuns')->where('name', $pajak2)->first();
        if (!$existingPajak2) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangpajak->id,
                'name' => $pajak2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak3 = 'Piutang_PPh_Pasal_23';
        $existingPajak3 = DB::table('akuns')->where('name', $pajak3)->first();
        if (!$existingPajak3) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangpajak->id,
                'name' => $pajak3,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak4 = 'Piutang_PPh_Pasal_25';
        $existingPajak4 = DB::table('akuns')->where('name', $pajak4)->first();
        if (!$existingPajak4) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangpajak->id,
                'name' => $pajak4,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak3x = 'Uang_Muka_PPh_22';
        $existingPajak3x = DB::table('akuns')->where('name', $pajak3x)->first();
        if (!$existingPajak3x) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangpajak->id,
                'name' => $pajak3x,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak3x1 = 'Piutang_PPh_21';
        $existingPajak3x1 = DB::table('akuns')->where('name', $pajak3x1)->first();
        if (!$existingPajak3x1) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangpajak->id,
                'name' => $pajak3x1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak3x2 = 'Piutang_PPh_28';
        $existingPajak3x2 = DB::table('akuns')->where('name', $pajak3x2)->first();
        if (!$existingPajak3x2) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangpajak->id,
                'name' => $pajak3x2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak3x3 = 'Deposit_Pajak_Coretax';
        $existingPajak3x3 = DB::table('akuns')->where('name', $pajak3x3)->first();
        if (!$existingPajak3x3) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangpajak->id,
                'name' => $pajak3x3,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak3x4 = 'PPN_Lebih_Bayar';
        $existingPajak3x4 = DB::table('akuns')->where('name', $pajak3x4)->first();
        if (!$existingPajak3x4) {
            DB::table('akuns')->insert([
                'perent_id' => $piutangpajak->id,
                'name' => $pajak3x4,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak5 = 'Hutang_Pajak';
        $existingPajak5 = DB::table('akuns')->where('name', $pajak5)->first();
        if (!$existingPajak5) {
            DB::table('akuns')->insert([
                'perent_id' => 5,
                'name' => $pajak5,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $hutangpajak = DB::table('akuns')->where('name', $pajak5)->first();

        $pajak6 = 'PPN_Keluaran';
        $existingPajak6 = DB::table('akuns')->where('name', $pajak6)->first();
        if (!$existingPajak6) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak6,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak7 = 'Utang_Pajak_Daerah';
        $existingPajak7 = DB::table('akuns')->where('name', $pajak7)->first();
        if (!$existingPajak7) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak7,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak8 = 'Utang_PPh_21';
        $existingPajak8 = DB::table('akuns')->where('name', $pajak8)->first();
        if (!$existingPajak8) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak8,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak9 = 'Utang_PPh_Badan';
        $existingPajak9 = DB::table('akuns')->where('name', $pajak9)->first();
        if (!$existingPajak9) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak9,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak9x1 = 'Utang_PPh_23';
        $existingPajak9x1 = DB::table('akuns')->where('name', $pajak9x1)->first();
        if (!$existingPajak9x1) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak9x1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak9x2 = 'Utang_PPh_Pasal_4_ayat_2';
        $existingPajak9x2 = DB::table('akuns')->where('name', $pajak9x2)->first();
        if (!$existingPajak9x2) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak9x2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak9x3 = 'Utang_PPh_22';
        $existingPajak9x3 = DB::table('akuns')->where('name', $pajak9x3)->first();
        if (!$existingPajak9x3) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak9x3,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak9x3 = 'Utang_PPh_26';
        $existingPajak9x3 = DB::table('akuns')->where('name', $pajak9x3)->first();
        if (!$existingPajak9x3) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak9x3,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak9x4 = 'Utang_PPh_Final_UMKM';
        $existingPajak9x4 = DB::table('akuns')->where('name', $pajak9x4)->first();
        if (!$existingPajak9x4) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak9x4,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak9x5 = 'Utang_PPN';
        $existingPajak9x5 = DB::table('akuns')->where('name', $pajak9x5)->first();
        if (!$existingPajak9x5) {
            DB::table('akuns')->insert([
                'perent_id' => $hutangpajak->id,
                'name' => $pajak9x5,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak10 = 'biaya_beban_pajak';
        $existingPajak10 = DB::table('akuns')->where('name', $pajak10)->first();
        if (!$existingPajak10) {
            DB::table('akuns')->insert([
                'perent_id' => null,
                'name' => $pajak10,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $biayabebanpajak = DB::table('akuns')->where('name', $pajak10)->first();

        $pajak11 = 'Biaya_PPh_4_2';
        $existingPajak11 = DB::table('akuns')->where('name', $pajak11)->first();
        if (!$existingPajak11) {
            DB::table('akuns')->insert([
                'perent_id' => $biayabebanpajak->id,
                'name' => $pajak11,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak12 = 'Beban_Pph_Final_UMKM';
        $existingPajak12 = DB::table('akuns')->where('name', $pajak12)->first();
        if (!$existingPajak12) {
            DB::table('akuns')->insert([
                'perent_id' => $biayabebanpajak->id,
                'name' => $pajak12,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak13 = 'beban_pajak_kini';
        $existingPajak13 = DB::table('akuns')->where('name', $pajak13)->first();
        if (!$existingPajak13) {
            DB::table('akuns')->insert([
                'perent_id' => $biayabebanpajak->id,
                'name' => $pajak13,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak14 = 'beban_pajak_lainnya';
        $existingPajak14 = DB::table('akuns')->where('name', $pajak14)->first();
        if (!$existingPajak14) {
            DB::table('akuns')->insert([
                'perent_id' => $biayabebanpajak->id,
                'name' => $pajak14,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        // Child Biaya Gaji
        $pajak15 = 'Tunjangan_PPh_21_Gross-Up';
        $existingPajak15 = DB::table('akuns')->where('name', $pajak15)->first();
        if (!$existingPajak15) {
            DB::table('akuns')->insert([
                'perent_id' => 27,
                'name' => $pajak15,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak16 = 'Beban_PPh_21_Ditanggung_Perusahaan';
        $existingPajak16 = DB::table('akuns')->where('name', $pajak16)->first();
        if (!$existingPajak16) {
            DB::table('akuns')->insert([
                'perent_id' => 27,
                'name' => $pajak16,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'is_deductible' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak17 = 'Beban_Pajak_Perizinan_Admin';
        $existingPajak17 = DB::table('akuns')->where('name', $pajak17)->first();
        if (!$existingPajak17) {
            DB::table('akuns')->insert([
                'perent_id' => 3,
                'name' => $pajak17,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $bebanPajakPerizinanAdmin = Akun::where('name', '=', 'Beban_Pajak_Perizinan_Admin')->first();

        $pajak18 = 'Pajak_Bumi_dan_Bangunan_PBB';
        $existingPajak18 = DB::table('akuns')->where('name', $pajak18)->first();
        if (!$existingPajak18) {
            DB::table('akuns')->insert([
                'perent_id' => $bebanPajakPerizinanAdmin->id,
                'name' => $pajak18,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak19 = 'Pajak_Kendaraan_Bermotor_PKB';
        $existingPajak19 = DB::table('akuns')->where('name', $pajak19)->first();
        if (!$existingPajak19) {
            DB::table('akuns')->insert([
                'perent_id' => $bebanPajakPerizinanAdmin->id,
                'name' => $pajak19,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak20 = 'Beban_Pajak_Daerah_Reklame';
        $existingPajak20 = DB::table('akuns')->where('name', $pajak20)->first();
        if (!$existingPajak20) {
            DB::table('akuns')->insert([
                'perent_id' => $bebanPajakPerizinanAdmin->id,
                'name' => $pajak20,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak21 = 'Beban_Bea_Meterai';
        $existingPajak21 = DB::table('akuns')->where('name', $pajak21)->first();
        if (!$existingPajak21) {
            DB::table('akuns')->insert([
                'perent_id' => $bebanPajakPerizinanAdmin->id,
                'name' => $pajak21,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak22 = 'Beban_Denda_Sanksi_Pajak';
        $existingPajak22 = DB::table('akuns')->where('name', $pajak22)->first();
        if (!$existingPajak22) {
            DB::table('akuns')->insert([
                'perent_id' => $bebanPajakPerizinanAdmin->id,
                'name' => $pajak22,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'is_deductible' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        // Child Biaya Lain
        $pajak23 = 'Beban_PPN_Masukan_Non-Credit';
        $existingPajak23 = DB::table('akuns')->where('name', $pajak23)->first();
        if (!$existingPajak23) {
            DB::table('akuns')->insert([
                'perent_id' => 58,
                'name' => $pajak23,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pajak23 = 'Beban_PPh_23_Ditanggung_Perusahaan';
        $existingPajak23 = DB::table('akuns')->where('name', $pajak23)->first();
        if (!$existingPajak23) {
            DB::table('akuns')->insert([
                'perent_id' => 58,
                'name' => $pajak23,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'is_deductible' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan = Akun::where('name', '=', 'Pendapatan')->first();

        $pendapatan1 = 'Pendapatan_Usaha';
        $akunPendapatan1 = Akun::where('name', '=', $pendapatan1)->first();
        if (!$akunPendapatan1) {
            DB::table('akuns')->insert([
                'perent_id' => $pendapatan->id,
                'name' => $pendapatan1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan2 = 'Pendapatan_Lain_lain';
        $akunPendapatan2 = Akun::where('name', '=', $pendapatan2)->first();
        if (!$akunPendapatan2) {
            DB::table('akuns')->insert([
                'perent_id' => $pendapatan->id,
                'name' => $pendapatan2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan3 = 'Pendapatan_Terikat';
        $akunPendapatan3 = Akun::where('name', '=', $pendapatan3)->first();
        if (!$akunPendapatan3) {
            DB::table('akuns')->insert([
                'perent_id' => $pendapatan->id,
                'name' => $pendapatan3,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan3x1 = 'Pelepasan_Pembatasan';
        $akunPendapatan3x1 = Akun::where('name', '=', $pendapatan3x1)->first();
        if (!$akunPendapatan3x1) {
            DB::table('akuns')->insert([
                'perent_id' => $pendapatan->id,
                'name' => $pendapatan3x1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatanusaha = Akun::where('name', '=', $pendapatan1)->first();
        $pendapatanlainlain = Akun::where('name', '=', $pendapatan2)->first();
        $pendapatanterikat = Akun::where('name', '=', $pendapatan3)->first();
        $pelepasanpembatasan = Akun::where('name', '=', $pendapatan3x1)->first();

        if ($pendapatanusaha) {
            DB::table('akuns')
                ->whereIn('name', [
                    'Pendapatan Penjualan',
                    'Pendapatan Jasa',
                    'Retur Penjualan',
                    'Potongan Penjualan',
                ])
                ->update(['perent_id' => $pendapatanusaha->id]);
        }

        if ($pendapatanlainlain) {
            DB::table('akuns')
                ->whereIn('name', [
                    'Keuntungan Atas Pelepasan Aset Tetap',
                    'Keuntungan Atas Kenaikan Nilai Aset Tetap',
                    'Keuntungan Selisih Harga Pada Retur Pembelian',
                    'Pendapatan Bukan Uang',
                    'Pendapatan Lain',
                ])
                ->update(['perent_id' => $pendapatanlainlain->id]);
        }

        $pendapatan4 = 'untuk_program_pendidikan_v2';
        $akunPendapatan4 = Akun::where('name', '=', $pendapatan4)->first();
        if (!$akunPendapatan4) {
            DB::table('akuns')->insert([
                'perent_id' => $pendapatanterikat->id,
                'name' => $pendapatan4,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan5 = 'untuk_program_kesehatan_v2';
        $akunPendapatan5 = Akun::where('name', '=', $pendapatan5)->first();
        if (!$akunPendapatan5) {
            DB::table('akuns')->insert([
                'perent_id' => $pendapatanterikat->id,
                'name' => $pendapatan5,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan6 = 'dana_abadi_endowment_fund_v2';
        $akunPendapatan6 = Akun::where('name', '=', $pendapatan6)->first();
        if (!$akunPendapatan6) {
            DB::table('akuns')->insert([
                'perent_id' => $pendapatanterikat->id,
                'name' => $pendapatan6,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan7 = 'pembatasan_waktu_temporer_v2';
        $akunPendapatan7 = Akun::where('name', '=', $pendapatan7)->first();
        if (!$akunPendapatan7) {
            DB::table('akuns')->insert([
                'perent_id' => $pendapatanterikat->id,
                'name' => $pendapatan7,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan4x1 = 'untuk_program_pendidikan_v3';
        $akunPendapatan4x1 = Akun::where('name', '=', $pendapatan4x1)->first();
        if (!$akunPendapatan4x1) {
            DB::table('akuns')->insert([
                'perent_id' => $pelepasanpembatasan->id,
                'name' => $pendapatan4x1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan5x1 = 'untuk_program_kesehatan_v3';
        $akunPendapatan5x1 = Akun::where('name', '=', $pendapatan5x1)->first();
        if (!$akunPendapatan5x1) {
            DB::table('akuns')->insert([
                'perent_id' => $pelepasanpembatasan->id,
                'name' => $pendapatan5x1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan6x1 = 'dana_abadi_endowment_fund_v3';
        $akunPendapatan6x1 = Akun::where('name', '=', $pendapatan6x1)->first();
        if (!$akunPendapatan6x1) {
            DB::table('akuns')->insert([
                'perent_id' => $pelepasanpembatasan->id,
                'name' => $pendapatan6x1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $pendapatan7x1 = 'pembatasan_waktu_temporer_v3';
        $akunPendapatan7x1 = Akun::where('name', '=', $pendapatan7x1)->first();
        if (!$akunPendapatan7x1) {
            DB::table('akuns')->insert([
                'perent_id' => $pelepasanpembatasan->id,
                'name' => $pendapatan7x1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $biaya1 = 'Biaya_Program';
        $akunbiaya1 = DB::table('akuns')->where('name', $biaya1)->first();
        if (!$akunbiaya1) {
            DB::table('akuns')->insert([
                'perent_id' => 3,
                'name' => $biaya1,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 1,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $biayaprogram = Akun::where('name', '=', $biaya1)->first();

        $biaya2 = 'Program_Pendidikan';
        $akunbiaya2 = DB::table('akuns')->where('name', $biaya2)->first();
        if (!$akunbiaya2) {
            DB::table('akuns')->insert([
                'perent_id' => $biayaprogram->id,
                'name' => $biaya2,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }

        $biaya3 = 'Program_Kesehatan';
        $akunbiaya3 = DB::table('akuns')->where('name', $biaya3)->first();
        if (!$akunbiaya3) {
            DB::table('akuns')->insert([
                'perent_id' => $biayaprogram->id,
                'name' => $biaya3,
                'total' => 0,
                'iscash' => 0,
                'isheader' => 0,
                'iscashout' => 0,
                'iscashin' => 0,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }
    }
}
