<?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('facturas', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('numero')->unique();
            $table->foreignId('cliente_id')->constrained('clientes');
            $table->foreignId('user_id')->constrained('users');
            $table->decimal('subtotal_gravado', 10, 2)->default(0);
            $table->decimal('subtotal_exento', 10, 2)->default(0);
            $table->decimal('iva_porcentaje', 5, 2)->default(0);
            $table->decimal('iva_monto', 10, 2)->default(0);
            $table->decimal('total', 10, 2)->default(0);
            $table->decimal('efectivo', 10, 2)->default(0);
            $table->decimal('debito', 10, 2)->default(0);
            $table->decimal('credito', 10, 2)->default(0);
            $table->decimal('cheque', 10, 2)->default(0);
            $table->decimal('vuelto', 10, 2)->default(0);
            $table->text('observaciones')->nullable();
            $table->unsignedTinyInteger('status')->default(0);
            $table->timestamp('pagado_en')->nullable();
            $table->timestamps();
        });
    }

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