Đóng gói cuối tuần
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
<?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('projects', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('code')->unique(); // STH03
|
||||
$table->string('name');
|
||||
$table->string('type');
|
||||
$table->string('address')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('projects'); }
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,22 +1,47 @@
|
||||
<?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('products', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('project_id')->constrained('projects')->cascadeOnDelete();
|
||||
$table->string('product_type');
|
||||
$table->string('code')->unique();
|
||||
$table->decimal('area', 10, 2);
|
||||
$table->decimal('price_per_unit', 15, 2)->nullable();
|
||||
$table->string('product_type'); // LAND, APARTMENT, SHOPHOUSE...
|
||||
|
||||
// === TRƯỜNG CHUNG ===
|
||||
$table->string('code')->unique(); // Khu + Lô (STH03.01)
|
||||
$table->decimal('area', 12, 2);
|
||||
$table->decimal('price_per_unit', 15, 2);
|
||||
$table->decimal('total_price', 15, 2);
|
||||
$table->jsonb('custom_data')->nullable(); // Chứa thông tin tầng, view, hướng...
|
||||
|
||||
// === TÀI CHÍNH BỔ SUNG ===
|
||||
$table->decimal('qsdd_value', 15, 2)->default(0);
|
||||
$table->decimal('foundation_temp_value', 15, 2)->default(0);
|
||||
$table->decimal('contract_temp_value', 15, 2)->default(0);
|
||||
|
||||
// === KỸ THUẬT & XÂY DỰNG ===
|
||||
$table->string('adjacent_road')->nullable();
|
||||
$table->integer('frontage_count')->nullable();
|
||||
$table->integer('max_floors')->nullable();
|
||||
$table->decimal('building_density', 5, 2)->nullable();
|
||||
$table->string('construction_status')->nullable();
|
||||
|
||||
// === HẠ TẦNG (NESTED) ===
|
||||
$table->text('infrastructure_raw_text')->nullable();
|
||||
$table->jsonb('infrastructure_status')->nullable();
|
||||
|
||||
// === TRẠNG THÁI ===
|
||||
$table->string('status')->default('Đang mở bán');
|
||||
$table->string('red_book_status')->default('Chưa có dữ liệu');
|
||||
|
||||
// === LINH HOẠT ===
|
||||
$table->jsonb('custom_data')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('products'); }
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<?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('customers', function (Blueprint $table) {
|
||||
@@ -10,10 +12,10 @@ return new class extends Migration {
|
||||
$table->string('full_name');
|
||||
$table->string('phone')->nullable();
|
||||
$table->string('email')->nullable();
|
||||
$table->jsonb('address')->nullable(); // Lưu cấu trúc: số nhà, phường, quận...
|
||||
$table->jsonb('address')->nullable();
|
||||
$table->date('dob')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('customers'); }
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<?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('contracts', function (Blueprint $table) {
|
||||
@@ -14,11 +16,11 @@ return new class extends Migration {
|
||||
$table->string('status')->default('Đang hiệu lực');
|
||||
$table->decimal('total_value', 15, 2);
|
||||
$table->decimal('paid_amount', 15, 2)->default(0);
|
||||
// Cột ảo tự động tính số tiền còn lại, dev không cần query tính toán
|
||||
$table->decimal('remaining_amount', 15, 2)->virtualAs('total_value - paid_amount');
|
||||
$table->decimal('remaining_amount', 15, 2)->default(0);
|
||||
$table->decimal('excess_amount', 15, 2)->default(0); // Tiền dư từ đợt trước
|
||||
$table->jsonb('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('contracts'); }
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?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('appendices', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->foreignUuid('product_id')->constrained('products')->cascadeOnDelete();
|
||||
$table->string('type');
|
||||
$table->integer('apply_from_order')->default(0);
|
||||
$table->date('signing_date')->nullable();
|
||||
$table->jsonb('custom_data')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('appendices'); }
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
<?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('settlements', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('product_id')->constrained('products')->cascadeOnDelete();
|
||||
$table->string('type'); // "MÓNG", "THÂN", "CP THI CÔNG"
|
||||
$table->decimal('temp_value', 15, 2)->default(0);
|
||||
$table->decimal('final_value', 15, 2)->default(0);
|
||||
$table->decimal('difference', 15, 2)->virtualAs('final_value - temp_value');
|
||||
$table->string('red_book_status')->nullable();
|
||||
$table->date('issue_date')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('settlements'); }
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
<?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('payments', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->string('payment_type');
|
||||
$table->integer('installment_no')->default(1);
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->date('due_date')->nullable();
|
||||
$table->date('paid_date')->nullable();
|
||||
$table->string('status')->default('PENDING'); // PENDING, PAID, OVERDUE, CANCELLED
|
||||
$table->string('receipt_number')->nullable();
|
||||
$table->jsonb('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('payments'); }
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
<?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 {
|
||||
// Mẫu thanh toán
|
||||
Schema::create('payment_templates', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('project_id')->constrained('projects')->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->boolean('is_default')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Lịch trình thanh toán
|
||||
Schema::create('payment_schedules', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->foreignUuid('template_id')->constrained('payment_templates')->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Chi tiết từng đợt thanh toán
|
||||
Schema::create('payment_schedule_items', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('template_id')->nullable()->constrained('payment_templates')->cascadeOnDelete();
|
||||
$table->foreignUuid('schedule_id')->nullable()->constrained('payment_schedules')->cascadeOnDelete();
|
||||
$table->integer('installment_no');
|
||||
$table->decimal('amount', 15, 2)->nullable();
|
||||
$table->decimal('percentage', 5, 2)->nullable();
|
||||
|
||||
// --- LOGIC NGÀY ĐẾN HẠN ---
|
||||
$table->integer('days_after_signing')->nullable(); // Cách 1: X ngày sau ngày ký
|
||||
$table->integer('days_after_previous')->nullable(); // Cách 2: X ngày sau đợt trước
|
||||
$table->date('due_date')->nullable(); // Cách 3: Ngày chính xác
|
||||
|
||||
$table->string('type'); // QSDD, MONG, THAN...
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Phiếu thu thực tế
|
||||
Schema::create('payments', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->foreignUuid('schedule_item_id')->nullable()->constrained('payment_schedule_items')->nullOnDelete();
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->date('paid_date');
|
||||
$table->string('receipt_number')->nullable();
|
||||
$table->string('method')->default('Chuyển khoản');
|
||||
$table->jsonb('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Tiền phạt chậm nộp
|
||||
Schema::create('payment_fines', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->string('reason');
|
||||
$table->date('due_date');
|
||||
$table->date('paid_date')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void {
|
||||
Schema::dropIfExists('payment_fines');
|
||||
Schema::dropIfExists('payments');
|
||||
Schema::dropIfExists('payment_schedule_items');
|
||||
Schema::dropIfExists('payment_schedules');
|
||||
Schema::dropIfExists('payment_templates');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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 {
|
||||
// Phụ lục hợp đồng
|
||||
Schema::create('appendices', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->foreignUuid('product_id')->constrained('products')->cascadeOnDelete();
|
||||
$table->string('type');
|
||||
$table->integer('apply_from_order'); // Kế thừa từ CN số mấy
|
||||
$table->date('signing_date');
|
||||
$table->jsonb('custom_data')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Quyết toán & Sổ đỏ
|
||||
Schema::create('settlements', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('product_id')->constrained('products')->cascadeOnDelete();
|
||||
$table->string('type'); // MONG, THAN, CP THI CONG
|
||||
$table->decimal('temp_value', 15, 2);
|
||||
$table->decimal('final_value', 15, 2);
|
||||
$table->decimal('difference', 15, 2);
|
||||
$table->string('red_book_status');
|
||||
$table->date('issue_date')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void {
|
||||
Schema::dropIfExists('settlements');
|
||||
Schema::dropIfExists('appendices');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user