
    {

        Schema::create('users', function (Blueprint $table) {

            $table->id();

            $table->string('username')->unique();

            $table->string('password');

            $table->rememberToken();

            $table->tinyInteger('user_type_value');

            $table->bigInteger('detail_id')->nullable();

            $table->string('detail_type')->nullable();

            $table->tinyInteger('isActive');

            $table->string('card_number')->nullable();

            $table->string('fcmTokenId')->nullable();

            $table->integer('admin_employee_id')->nullable();//creator

            $table->string('family_code')->nullable();

            $table->string('activation_code')->nullable();

            $table->string('barcode')->nullable();

            $table->timestamps();

        });

    }

    {

        Schema::create('parents', function (Blueprint $table) {

            $table->id();

            $table->bigInteger('user_id')->nullable();

            $table->string('name',50);

            $table->string('ktp',20)->nullable();

            $table->string('nkk',20)->nullable();

            $table->string('email',50)->nullable();

            $table->string('mobilePhone',20)->nullable();

            $table->date('birthDate')->nullable();

            $table->string('birthPlace')->nullable();

            $table->tinyInteger('sex_type_value');

            $table->tinyInteger('religion_value');

            $table->tinyInteger('parent_type_value');

            $table->tinyInteger('wali_type_value')->nullable();

            $table->tinyInteger('education_type_value')->nullable();

            $table->tinyInteger('salary_type_value')->nullable();

            $table->tinyInteger('job_type_value')->nullable();

            $table->string('jobCorporateName',50)->nullable();

            $table->string('jobPositionName',30)->nullable();

            $table->string('jobWorkAddress')->nullable();

            $table->char('province_id', 2)->nullable();

            $table->char('regency_id', 5)->nullable();

            $table->char('district_id', 8)->nullable();

            $table->char('village_id', 13)->nullable();

            $table->text('address')->nullable();

            $table->string('family_code')->nullable();

            $table->string('photo')->nullable();

            $table->tinyInteger('isAlive')->default(1);

            $table->timestamps();

        });

    }

    {

        Schema::create('bills', function (Blueprint $table) {

            $table->id();

            $table->tinyInteger('tahun_id');

            $table->tinyInteger('school_id')->nullable();

            $table->tinyInteger('kelas_id')->nullable();

            $table->integer('parallel_id')->nullable();

            $table->tinyInteger('psb_flow_id')->nullable();

            $table->bigInteger('new_student_id')->nullable();

            $table->bigInteger('student_id')->nullable();

            $table->integer('bill_type_id');

            $table->string('billNumber');

            $table->bigInteger('amount');

            $table->bigInteger('paidAmount');

            $table->bigInteger('discount')->nullable();

            $table->tinyInteger('billed_status_value');

            $table->tinyInteger('pay_status_value');

            $table->tinyInteger('month_value')->nullable();

            $table->integer('year_value')->nullable();

            $table->bigInteger('admin_employee_id')->nullable();

            $table->tinyInteger('sex_type_value')->nullable();

            $table->timestamps();

        });

    }
    {

        Schema::create('bill_types', function (Blueprint $table) {

            $table->id();

            $table->string('name');

            $table->tinyInteger('school_id')->nullable();

            $table->tinyInteger('kelas_id')->nullable();

            $table->tinyInteger('jurusan_id')->nullable();

            $table->integer('parallel_id')->nullable();

            $table->bigInteger('normalPrice');

            $table->tinyInteger('tahun_id');

            $table->tinyInteger('isCicil')->default(0);

            $table->bigInteger('minimumCicil')->nullable();

            $table->integer('coa_kas_id')->nullable();

            $table->integer('coa_bank_id')->nullable();

            $table->integer('coa_pdpt_id')->nullable();

            $table->integer('coa_piutang_id')->nullable();

            $table->integer('coa_utang_id')->nullable();

            $table->integer('coa_diskon_id')->nullable();

            $table->tinyInteger('bank_account_id')->nullable();

            $table->tinyInteger('sex_type_value')->nullable();

        });

    }
    {

        Schema::create('bank_accounts', function (Blueprint $table) {

            $table->id();

            $table->string('name');

            $table->string('number');

            $table->string('bank');

            $table->string('code');

            $table->integer('school_id')->nullable();

            $table->tinyInteger('isForPaymentGateway');

            $table->tinyInteger('male')->nullable();

            $table->tinyInteger('female')->nullable();

            $table->tinyInteger('bill')->nullable();

            $table->tinyInteger('saving')->nullable();

            $table->tinyInteger('donation')->nullable();

            $table->tinyInteger('student')->nullable();

            $table->tinyInteger('employee')->nullable();

        });

    }
    {

        Schema::create('students', function (Blueprint $table) {

            $table->id();

            $table->bigInteger('user_id')->nullable();

            $table->string('name');

            $table->string('virtual_account')->nullable();

            $table->bigInteger('father_parent_id')->nullable();

            $table->bigInteger('mother_parent_id')->nullable();

            $table->bigInteger('father_employee_id')->nullable();

            $table->bigInteger('mother_employee_id')->nullable();

            $table->bigInteger('wali_parent_id')->nullable();

            $table->bigInteger('wali_employee_id')->nullable();

            $table->tinyInteger('jenjang_id');

            $table->tinyInteger('school_id');

            $table->tinyInteger('kelas_id');

            $table->tinyInteger('jurusan_id')->nullable();

            $table->integer('parallel_id')->nullable();

            $table->tinyInteger('masuk_tahun_id');

            $table->tinyInteger('masuk_jenjang_id');

            $table->tinyInteger('masuk_kelas_id');

            $table->tinyInteger('isFatherAlive');

            $table->tinyInteger('isMotherAlive');

            $table->tinyInteger('isPoor');

            $table->tinyInteger('bill_price_type_value')->default(1);

            $table->string('npsn')->nullable();

            $table->string('nis');

            $table->string('nisn')->nullable();

            $table->string('nkk')->nullable();

            $table->string('nik')->nullable();

            $table->string('akta')->nullable();

            $table->string('mobilePhone')->nullable();

            $table->string('email')->nullable();

            $table->string('skhun')->nullable();

            $table->string('pesertaUN')->nullable();

            $table->string('ijazah')->nullable();

            $table->tinyInteger('isKps')->default(0);

            $table->string('kps')->nullable();

            $table->tinyInteger('isKip')->default(0);

            $table->string('kip')->nullable();

            $table->string('kipName')->nullable();

            $table->string('kks')->nullable();

            $table->string('pip_bank_account_number')->nullable();

            $table->string('pip_bank_account_name')->nullable();

            $table->smallInteger('height')->nullable();

            $table->smallInteger('weight')->nullable();

            $table->tinyInteger('head')->nullable();

            $table->smallInteger('homeDistance')->nullable();

            $table->smallInteger('travelTime')->nullable();

            $table->string('card_number')->nullable();

            $table->tinyInteger('sex_type_value');

            $table->char('province_id', 2)->nullable();

            $table->char('regency_id', 5)->nullable();

            $table->char('district_id', 8)->nullable();

            $table->char('village_id', 13)->nullable();

            $table->text('address');

            $table->char('rw',3)->nullable();

            $table->char('rt',3)->nullable();

            $table->char('postalCode',5)->nullable();

            $table->tinyInteger('vehicle_type_value')->nullable();

            $table->string('photo')->nullable();

            $table->string('birthPlace');

            $table->date('birthDate');

            $table->tinyInteger('birthOrder');

            $table->tinyInteger('religion_value');

            $table->tinyInteger('nationality_value');

            $table->tinyInteger('isAdopted');

            $table->tinyInteger('stay_with_value');

            $table->tinyInteger('siblings');

            $table->string('hoby')->nullable();

            $table->string('dream')->nullable();

            $table->string('medicalHistory')->nullable();

            $table->text('achievementHistory')->nullable();

            $table->tinyInteger('isActive');

            $table->tinyInteger('student_status_value');

            $table->tinyInteger('lulus_tahun_id')->nullable();

            $table->year('tahunLulus')->nullable();

            $table->string('family_code')->nullable();

            $table->tinyInteger('mutation_tahun_id')->nullable();

            $table->string('scholarship')->nullable();

            $table->integer('points')->nullable();

            $table->integer('violation_points')->nullable();

            $table->integer('achievement_points')->nullable();

            $table->tinyInteger('isTransfered')->nullable();

            $table->string('parent_category')->nullable();

            $table->string('nickname', 50)->nullable();

            $table->timestamps();

        });

    }
    {

        Schema::create('new_students', function (Blueprint $table) {

            $table->id();

            $table->string('name');

            $table->string('registration_number');

            $table->tinyInteger('isContinue');

            $table->tinyInteger('old_school_id')->nullable();

            $table->string('oldNis')->nullable();

            $table->bigInteger('user_id')->nullable();

            $table->bigInteger('father_employee_id')->nullable();

            $table->bigInteger('mother_employee_id')->nullable();

            $table->bigInteger('wali_employee_id')->nullable();

            $table->bigInteger('new_parent_id')->nullable();

            $table->bigInteger('father_parent_id')->nullable();

            $table->bigInteger('mother_parent_id')->nullable();

            $table->bigInteger('wali_parent_id')->nullable();

            $table->bigInteger('student_id')->nullable();

            $table->tinyInteger('psb_flow_id'); //saat ini

            $table->tinyInteger('flow_done_status_value');

            $table->tinyInteger('psb_flow_status_value')->nullable();

            $table->tinyInteger('isPoor')->default(0);

            $table->tinyInteger('isPsbDone');

            $table->string('rejectReason')->nullable();

            $table->tinyInteger('tahun_id')->nullable();

            $table->tinyInteger('jenjang_id')->nullable();

            $table->tinyInteger('school_id')->nullable();

            $table->tinyInteger('kelas_id')->nullable();

            $table->tinyInteger('jurusan_id')->nullable();

            $table->string('oldSchoolName')->nullable();

            $table->string('npsn')->nullable();

            $table->string('nisn')->nullable();

            $table->string('nkk')->nullable();

            $table->string('nik')->nullable();

            $table->string('akta')->nullable();

            $table->string('mobilePhone')->nullable();

            $table->string('email')->nullable();

            $table->string('skhun')->nullable();

            $table->string('pesertaUN')->nullable();

            $table->string('ijazah')->nullable();

            $table->tinyInteger('isKps')->default(0);

            $table->string('kps')->nullable();

            $table->tinyInteger('isKip')->default(0);

            $table->string('kip')->nullable();

            $table->string('kipName')->nullable();

            $table->string('kks')->nullable();

            $table->string('pip_bank_account_number')->nullable();

            $table->string('pip_bank_account_name')->nullable();

            $table->smallInteger('height')->nullable();

            $table->smallInteger('weight')->nullable();

            $table->tinyInteger('head')->nullable();

            $table->smallInteger('homeDistance')->nullable();

            $table->smallInteger('travelTime')->nullable();

            $table->tinyInteger('sex_type_value')->nullable();

            $table->char('province_id', 2)->nullable();

            $table->char('regency_id', 5)->nullable();

            $table->char('district_id', 8)->nullable();

            $table->char('village_id', 13)->nullable();

            $table->text('address')->nullable();

            $table->char('rw',3)->nullable();

            $table->char('rt',3)->nullable();

            $table->char('postalCode',5)->nullable();

            $table->tinyInteger('vehicle_type_value')->nullable();

            $table->string('photo')->nullable();

            $table->string('birthPlace')->nullable();

            $table->date('birthDate')->nullable();

            $table->tinyInteger('birthOrder')->nullable();

            $table->tinyInteger('religion_value')->nullable();

            $table->tinyInteger('nationality_value')->nullable();

            $table->tinyInteger('isAdopted')->nullable();

            $table->tinyInteger('stay_with_value')->nullable();

            $table->tinyInteger('siblings')->nullable();

            $table->string('hoby')->nullable();

            $table->string('dream')->nullable();

            $table->string('medicalHistory')->nullable();

            $table->text('achievementHistory')->nullable();

            $table->string('scholarship')->nullable();

            $table->string('family_code')->nullable();

            $table->string('examParticipantNumber')->nullable();

            $table->tinyInteger('bill_price_type_value')->default(1);

            $table->tinyInteger('isAccepted')->nullable();

            $table->bigInteger('admin_employee_id')->nullable();

            $table->tinyInteger('referal_source_value')->nullable();

            $table->string('referal_source_description')->nullable();

            $table->tinyInteger('is_transfered')->default(0);

            $table->string('old_school_address')->nullable();

            $table->string('nickname', 50)->nullable();

            $table->timestamps();

        });

    }

    {

        Schema::create('payments', function (Blueprint $table) {

            $table->id();

            $table->bigInteger('user_id')->nullable();

            $table->bigInteger('balance_id')->nullable();

            $table->bigInteger('donation_campaign_id')->nullable();

            $table->tinyInteger('installment_type_value');

            $table->string('payment_type');

            $table->string('order_id');

            $table->bigInteger('amount');

            $table->bigInteger('gross_amount');

            $table->tinyInteger('channel_id');

            $table->string('channel_type');

            $table->string('channel_name');

            $table->string('channel_corp');

            $table->string('payment_number');

            $table->bigInteger('expired');

            $table->tinyInteger('payment_status_value');

            $table->timestamps();

        });

    }

    {

        Schema::create('bill_payment', function (Blueprint $table) {

            $table->id();

            $table->bigInteger('bill_id');

            $table->bigInteger('payment_id');

        });

    }
    {

        Schema::create('payment_bank_settlement', function (Blueprint $table) {

            $table->id();

            $table->bigInteger('payment_id');

            $table->tinyInteger('bank_account_id');

            $table->bigInteger('amount');

        });

    }
    {
        Schema::create('transactions', function (Blueprint $table) {
            $table->id();
            $table->string('number',30);
            $table->tinyInteger('transaction_mode_value')->nullable();//1-cashless, 2 cash
            $table->tinyInteger('transaction_type_value');
            $table->char('school_cashflow', 1)->nullable();
            $table->char('user_cashflow', 1)->nullable();
            $table->char('to_user_cashflow', 1)->nullable();
            $table->bigInteger('user_id')->nullable();
            $table->bigInteger('user_type_value')->nullable();
            $table->bigInteger('user_detail_id')->nullable();
            $table->bigInteger('new_student_id')->nullable();
            $table->bigInteger('student_id')->nullable();
            $table->bigInteger('to_student_id')->nullable();
            $table->bigInteger('employee_id')->nullable();
            $table->bigInteger('parent_id')->nullable();
            $table->bigInteger('visitor_id')->nullable();
            $table->bigInteger('vendor_id')->nullable();
            $table->tinyInteger('school_id')->nullable();
            $table->tinyInteger('kelas_id')->nullable();
            $table->integer('parallel_id')->nullable();
            $table->bigInteger('amount');
            $table->bigInteger('payment_id')->nullable();
            $table->bigInteger('balance_id')->nullable();
            $table->bigInteger('to_balance_id')->nullable();
            $table->string('description')->nullable();
            $table->string('additionalInfo')->nullable();
            $table->integer('store_id')->nullable();
            $table->bigInteger('store_withdrawal_id')->nullable();
            $table->integer('donation_campaign_id')->nullable();
            $table->bigInteger('autodebet_id')->nullable();
            $table->bigInteger('admin_employee_id')->nullable();
            $table->date('transactionDate');
            $table->integer('tahun_id');
            $table->tinyInteger('sex_type_value')->nullable();
            $table->string('receiptUrl')->nullable();
            $table->timestamps();
        });
    }

    {
        Schema::create('journals', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('transaction_id')->nullable();
            $table->date('transactionDate');
            $table->integer('coa_id');  
            $table->string('coa_name');
            $table->integer('tahun_id');
            $table->bigInteger('debit');
            $table->bigInteger('credit');
            $table->timestamps();
        });
    }
    {
        Schema::create('balances', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('balance');
            $table->bigInteger('sisa')->default(100000);
            $table->bigInteger('dailyLimit')->nullable();
            $table->tinyInteger('balance_type_value'); //1=transaksi, 2=wajib
            $table->string('card_number')->nullable();
            $table->bigInteger('user_id');
            $table->tinyInteger('user_type_value');
            $table->bigInteger('student_id')->nullable();
            $table->bigInteger('employee_id')->nullable();
            $table->string('pin')->nullable();
            //$table->bigInteger('visitor_id')->nullable(); visitor langsung saldonya di card
        });
    }
    {
        Schema::create('stores', function (Blueprint $table) {
            $table->id();
            $table->string('code')->nullable();
            $table->string('name');
            $table->tinyInteger('store_type_value');
            $table->bigInteger('balance');
            $table->tinyInteger('smart_reader_number')->nullable();
            $table->tinyInteger('isUseBarcodeScanner')->default(0);
            $table->bigInteger('fixed_amount')->nullable();
            $table->tinyInteger('profitSharingPercent')->default(0);

        });
    }
    {
        Schema::create('bill_transaction', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('transaction_id');
            $table->bigInteger('bill_id');
            $table->integer('bill_type_id');
            $table->bigInteger('pay');
            $table->bigInteger('paid');
            $table->bigInteger('outstanding');
        });
    }
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->integer('store_id');
            $table->integer('category_id')->nullable();
            $table->string('name');
            $table->string('barcode')->nullable();
            $table->text('description')->nullable();
            $table->string('image')->nullable();
            $table->tinyInteger('isCountStock');
            $table->integer('stock')->nullable();
            $table->bigInteger('buyPrice')->nullable();
            $table->bigInteger('sellPrice');
            $table->bigInteger('vendor_id')->nullable();
        });
    }

    {
        Schema::create('transaction_debt', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('transaction_id');
            $table->bigInteger('debt_id');
            $table->bigInteger('amount');
            $table->timestamps();
        });
    }

    {
        Schema::create('store_withdrawals', function (Blueprint $table) {
            $table->id();
            $table->tinyInteger('store_id');
            $table->bigInteger('amount');
            $table->tinyInteger('withdrawal_status_value');
            $table->bigInteger('store_employee_id');
            $table->bigInteger('admin_employee_id')->nullable();
            $table->integer('coa_kas_id')->nullable();
            $table->string('description')->nullable();
            $table->tinyInteger('profitSharingPercent')->default(0);
            $table->bigInteger('profitSharingAmount')->default(0);
            $table->tinyInteger('profit_sharing_status_value')->default(0); //0=tidak ada, 1=ada dan belum diterima, 2=sudah diterima
            $table->timestamps();
        });
    }

    {
        Schema::create('autodebets', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('autodebet_type_id');
            $table->date('date');
            $table->tinyInteger('month_value');
            $table->integer('year_value');
            $table->integer('successCount');
            $table->integer('failedCount');
            $table->bigInteger('successAmount');
            $table->bigInteger('failedAmount');
            $table->bigInteger('withdrawal');
            $table->timestamps();
        });
    }

    {
        if (Schema::hasTable('inventory_adjustments')) return;
        Schema::create('inventory_adjustments', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('inventory_id');
            $table->bigInteger('transaction_id');
            $table->tinyInteger('adjustment_type_value');
            $table->string('adjustment_date');
            $table->integer('quantity');
            $table->bigInteger('admin_employee_id');
            $table->string('description')->nullable();
            $table->timestamps();
        });
    }

    {
        Schema::create('inventories', function (Blueprint $table) {
            $table->id();
            $table->tinyInteger('category_id');
            $table->string('name');
            $table->string('number')->nullable();
            $table->string('brand')->nullable();
            $table->date('receiveDate');
            $table->bigInteger('price');
            $table->integer('quantity');
            $table->integer('broken')->default(0);
            $table->integer('lended')->default(0);
            $table->integer('lost')->default(0);
            $table->timestamps();
        });
    }

    {
        Schema::create('inventories', function (Blueprint $table) {
            $table->id();
            $table->tinyInteger('category_id');
            $table->string('name');
            $table->string('number')->nullable();
            $table->string('brand')->nullable();
            $table->date('receiveDate');
            $table->bigInteger('price');
            $table->integer('quantity');
            $table->integer('broken')->default(0);
            $table->integer('lended')->default(0);
            $table->integer('lost')->default(0);
            $table->timestamps();
        });
    }

    {
        Schema::create('donations', function (Blueprint $table) {
            $table->id();
            $table->integer('donation_campaign_id');
            $table->bigInteger('user_id')->nullable();
            $table->bigInteger('user_type_value')->nullable();
            $table->bigInteger('student_id')->nullable();
            $table->bigInteger('employee_id')->nullable();
            $table->bigInteger('parent_id')->nullable();
            $table->bigInteger('visitor_id')->nullable();
            $table->bigInteger('amount');
            $table->bigInteger('transaction_id');
            $table->bigInteger('payment_id')->nullable();
            $table->bigInteger('admin_employee_id')->nullable();  
            $table->timestamps();
        });
    }
