Files
compras/database/migrations/2026_10_28_000010_create_invoices.php
T

56 lines
2.5 KiB
PHP

<?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('invoices', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained()->restrictOnDelete();
$table->foreignId('purchase_order_id')->constrained()->restrictOnDelete();
$table->foreignId('supplier_id')->constrained()->restrictOnDelete();
$table->foreignId('created_by')->constrained('users')->restrictOnDelete();
$table->foreignId('validated_by')->nullable()->constrained('users')->restrictOnDelete();
$table->string('number', 100);
$table->date('issued_on');
$table->string('status')->default('pending');
$table->bigInteger('subtotal_minor');
$table->bigInteger('tax_minor');
$table->bigInteger('total_minor');
$table->json('snapshot');
$table->timestamp('validated_at')->nullable();
$table->timestamps();
$table->unique(['tenant_id', 'supplier_id', 'number']);
});
Schema::create('invoice_items', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained()->restrictOnDelete();
$table->foreignId('invoice_id')->constrained()->restrictOnDelete();
$table->foreignId('purchase_order_item_id')->constrained()->restrictOnDelete();
$table->bigInteger('quantity_milli');
$table->bigInteger('subtotal_minor');
$table->bigInteger('tax_minor');
$table->json('snapshot');
$table->unique(['invoice_id', 'purchase_order_item_id']);
});
Schema::create('budget_consumptions', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained()->restrictOnDelete();
$table->foreignId('budget_id')->constrained()->restrictOnDelete();
$table->foreignId('invoice_id')->unique()->constrained()->restrictOnDelete();
$table->foreignId('created_by')->constrained('users')->restrictOnDelete();
$table->bigInteger('amount_minor');
$table->timestamp('created_at');
});
}
public function down(): void
{
throw new LogicException('Preservar facturas, conferências e consumo.');
}
};