<?php

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('sales_invoices', function (Blueprint $table) {

            $table->id();

            $table->string('invoice_no',30)->unique();

            $table->foreignId('sales_order_id')
                ->constrained()
                ->restrictOnDelete();

            $table->foreignId('client_id')
                ->constrained()
                ->restrictOnDelete();

            $table->date('invoice_date');

            $table->decimal('total_amount',15,2)->default(0);

            $table->decimal('discount_amount',15,2)->default(0);

            $table->decimal('tax_amount',15,2)->default(0);

            $table->decimal('grand_total',15,2)->default(0);

            $table->decimal('paid_amount',15,2)->default(0);

            $table->decimal('balance_amount',15,2)->default(0);

            $table->enum('payment_status',[
                'Pending',
                'Partial',
                'Paid'
            ])->default('Pending');

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

            $table->unsignedBigInteger('created_by')->nullable();

            $table->unsignedBigInteger('updated_by')->nullable();

            $table->timestamps();

            $table->softDeletes();

        });
    }

    public function down(): void
    {
        Schema::dropIfExists('sales_invoices');
    }
};