<?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('customer_settlements', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id');
            $table->string('period', 7);
            $table->string('customer', 100);
            $table->bigInteger('total_sales')->default(0);
            $table->bigInteger('commission')->default(0);
            $table->bigInteger('expense')->default(0);
            $table->bigInteger('net_amount')->default(0);
            $table->string('status', 20)->default('pending');
            $table->date('settled_date')->nullable();
            $table->text('memo')->nullable();
            $table->timestamps();
            $table->softDeletes();
            $table->index(['tenant_id', 'status']);
            $table->index(['tenant_id', 'period']);
        });
    }

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