<?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('monthly_settlements', function (Blueprint $table) {
            $table->id();
            $table->date('date_from');
            $table->date('date_to');
            $table->unsignedBigInteger('total_sales')->default(0);
            $table->unsignedBigInteger('total_expenses')->default(0);
            $table->unsignedBigInteger('total_salaries')->default(0);
            $table->unsignedBigInteger('cash_box_amount')->default(0);
            $table->unsignedBigInteger('online_box_amount')->default(0);
            $table->unsignedBigInteger('transferred_to_reserve_cash')->default(0);
            $table->unsignedBigInteger('transferred_to_reserve_online')->default(0);
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamp('settled_at')->nullable();
            $table->timestamps();
            $table->unique(['date_from', 'date_to']);
        });
    }

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