<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateEmpPayIncomeDeduction extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'emppayinded_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true
            ],
            'emppay_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'payschedule_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'inded_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'is_fixed_amt' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false
            ],
            'is_percent_amt' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false
            ],
            'amount' => [
                'type' => 'DECIMAL',
                'constraint' => '12,4',
                'null' => false
            ],
            'is_override' => [
                '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('emppayinded_id', true);
        $this->forge->addForeignKey('emppay_id', 'emp_pay_info', 'emppay_id', 'CASCADE', 'RESTRICT');
        $this->forge->addForeignKey('payschedule_id', 'pay_schedule', 'payschedule_id', 'CASCADE', 'RESTRICT');
        $this->forge->addForeignKey('inded_id', 'pay_income_deduction', 'inded_id', 'CASCADE', 'RESTRICT');
        $this->forge->createTable('emp_pay_inded');
    }

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