<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateIncomeDeduction extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'inded_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true
            ],
            'payslip_display' => [
                'type' => 'VARCHAR',
                'constraint' => 25,
                'null' => false
            ],
            'inded_name' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
                'null' => false
            ],
            'coa_code' => [
                'type' => 'VARCHAR',
                'constraint' => 25,
                'null' => true,
            ],
            'is_income' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false
            ],
            'is_taxable' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false
            ],
            'include_in_gross' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false
            ],

            // Common fields
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'created_by' => [
                'type' => 'VARCHAR', 
                'constraint' => '20', 
                'null' => true
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_by' => [
                'type' => 'VARCHAR', 
                'constraint' => '20', 
                'null' => true
            ],
            'deleted_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('inded_id', true);
        $this->forge->createTable('pay_income_deduction');
    }

    public function down()
    {
        $this->forge->dropTable('pay_income_deduction');
    }
}
