<?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
    {
        if (Schema::hasTable('sales_records')) {
            return;
        }
        Schema::create('sales_records', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id');
            $table->date('date');
            $table->string('customer', 100);
            $table->string('project', 200)->nullable();
            $table->string('type', 50)->default('프로젝트');
            $table->bigInteger('amount')->default(0);
            $table->bigInteger('vat')->default(0);
            $table->string('status', 20)->default('negotiating');
            $table->string('invoice_no', 50)->nullable();
            $table->text('memo')->nullable();
            $table->timestamps();
            $table->softDeletes();
            $table->index(['tenant_id', 'status']);
            $table->index(['tenant_id', 'date']);
        });
    }

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