<?php
// Nowills SQC ERP — B7: tax filing tracker (returns filed, GRA receipts, credits)
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void {
        Schema::create('tax_filings', function (Blueprint $table) {
            $table->id();
            $table->string('tax_type', 30)->index(); // vat, wht, paye, ssnit1, ssnit2, cit, levies
            $table->char('period', 7)->index();      // YYYY-MM
            $table->date('due_date');
            $table->decimal('taxable_base', 15, 2)->default(0);
            $table->decimal('liability', 15, 2)->default(0);
            $table->decimal('amount_paid', 15, 2)->default(0);
            $table->decimal('credit_cf', 15, 2)->default(0); // overpayment carried forward
            $table->date('filing_date')->nullable();
            $table->string('gra_receipt_no', 60)->nullable();
            $table->string('status', 20)->default('draft')->index();
            $table->text('notes')->nullable();
            $table->foreignId('filed_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
            $table->unique(['tax_type', 'period']);
        });
    }
    public function down(): void {
        Schema::dropIfExists('tax_filings');
    }
};
