50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*/
|
|
public function up(): void
|
|
{
|
|
if (!Schema::hasTable('conguaglios')) {
|
|
Schema::create('conguaglios', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->unsignedBigInteger('bilancio_id');
|
|
$table->unsignedBigInteger('unita_immobiliare_id')->nullable();
|
|
$table->string('descrizione');
|
|
$table->decimal('importo_precedente', 15, 2)->default(0);
|
|
$table->decimal('importo_attuale', 15, 2)->default(0);
|
|
$table->decimal('differenza', 15, 2)->default(0);
|
|
$table->enum('tipo', ['CREDITO', 'DEBITO'])->default('CREDITO');
|
|
$table->enum('stato', ['calcolato', 'confermato', 'applicato', 'annullato'])->default('calcolato');
|
|
$table->date('data_calcolo');
|
|
$table->date('data_applicazione')->nullable();
|
|
$table->text('note')->nullable();
|
|
$table->timestamps();
|
|
$table->softDeletes();
|
|
|
|
// Foreign keys
|
|
$table->foreign('bilancio_id')->references('id')->on('bilanci')->onDelete('cascade');
|
|
$table->foreign('unita_immobiliare_id')->references('id')->on('unita_immobiliari')->onDelete('cascade');
|
|
|
|
// Indexes
|
|
$table->index(['bilancio_id', 'stato']);
|
|
$table->index(['unita_immobiliare_id', 'stato']);
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('conguaglios');
|
|
}
|
|
};
|