Implementa conferencia de facturas e consumo por empresa

This commit is contained in:
2026-10-28 14:26:18 +02:00
parent f86ecef44d
commit 332cb9f1b7
28 changed files with 1356 additions and 8 deletions
@@ -0,0 +1,55 @@
<?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.');
}
};