<?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('sy_zones_report', function (Blueprint $blueprint) {
            $blueprint->id();
            $blueprint->unsignedBigInteger('fk_site');
            $blueprint->unsignedBigInteger('fk_office');
            $blueprint->unsignedBigInteger('fk_executive');
            $blueprint->date('reportdate');
            $blueprint->double('extraweek')->default(0);
            $blueprint->double('fund')->default(0);
            $blueprint->double('delivery')->default(0);
            $blueprint->double('incoming')->default(0);
            $blueprint->double('total_incoming')->default(0);
            $blueprint->double('commissions')->default(0);
            $blueprint->double('outgoing')->default(0);
            $blueprint->double('bills')->default(0);
            $blueprint->double('sales')->default(0);
            $blueprint->double('total_outgoing')->default(0);
            $blueprint->double('total')->default(0);
            $blueprint->boolean('visible')->default(true);
            $blueprint->boolean('available')->default(true);
            $blueprint->unsignedBigInteger('fk_usercreator')->nullable();
            $blueprint->timestamp('created_at')->useCurrent();
            $blueprint->unsignedBigInteger('fk_userupdater')->nullable();
            $blueprint->timestamp('updated_at')->useCurrentOnUpdate()->nullable();
            $blueprint->boolean('is_active')->default(true);

            $blueprint->foreign('fk_site')->references('id')->on('sy_sites');
            $blueprint->foreign('fk_office')->references('id')->on('sy_offices');
            $blueprint->foreign('fk_executive')->references('id')->on('ct_collaborators');
            $blueprint->foreign('fk_usercreator')->references('id')->on('sc_users');
            $blueprint->foreign('fk_userupdater')->references('id')->on('sc_users');
        });
    }

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