<?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(),
            ]);
        }

        $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(),
            ]);
        }

        $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(),
            ]);
        }

        $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(),
            ]);
        }

        $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(),
            ]);
        }

        $pendapatanusaha = Akun::where('name', '=', $pendapatan1)->first();
        $pendapatanlainlain = Akun::where('name', '=', $pendapatan2)->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]);
        }
    }
}
