<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('transactions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('account_id')->constrained()->onDelete('cascade');
            $table->string('description')->nullable();
            $table->decimal('gross_amount');
            $table->decimal('exempt')->nullable();
            $table->decimal('zero_rated')->nullable();
            $table->decimal('vatable_amount')->nullable();

            $table->decimal('net_amount')->nullable();
            $table->decimal('input_tax')->nullable();
            $table->decimal('output_tax')->nullable();

            $table->boolean('with_tax')->default(false);

            $table->decimal('payable_withholding_tax')->nullable();
            $table->decimal('creditable_withholding_tax')->nullable();

            $table->morphs('transactionable');

            $table->foreignId('branch_id')->constrained()->onDelete('cascade');
            $table->date('happened_on');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('transactions');
    }
};
