<?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
    {
        // Add invoice_no to sales
        Schema::table('sales', function (Blueprint $table) {
            $table->string('invoice_no', 50)->nullable()->after('id');
        });

        // Add invoice_no to purchases
        Schema::table('purchases', function (Blueprint $table) {
            $table->string('invoice_no', 50)->nullable()->after('id');
        });

        // Add invoice_no / expense_no to expenses
        Schema::table('expenses', function (Blueprint $table) {
            $table->string('expense_no', 50)->nullable()->after('id');
        });

        // Make duty_date nullable on rosters
        Schema::table('rosters', function (Blueprint $table) {
            $table->date('duty_date')->nullable()->change();
        });
    }

    public function down(): void
    {
        Schema::table('rosters', function (Blueprint $table) {
            $table->date('duty_date')->nullable(false)->change();
        });
        Schema::table('expenses', function (Blueprint $table) {
            $table->dropColumn('expense_no');
        });
        Schema::table('purchases', function (Blueprint $table) {
            $table->dropColumn('invoice_no');
        });
        Schema::table('sales', function (Blueprint $table) {
            $table->dropColumn('invoice_no');
        });
    }
};
