chinh sua theo tieu chuan phan mem BDS_1

This commit is contained in:
2026-04-28 08:49:28 +00:00
parent e229da5e8c
commit 0712046f4b
18 changed files with 623 additions and 59 deletions

View File

@@ -0,0 +1,54 @@
<?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('sales_phases', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('project_id')->constrained('projects')->cascadeOnDelete();
$table->string('name'); // Tên đợt: Mở bán đợt 1, Đợt 2...
$table->string('code')->unique(); // Mã đợt: MB1, MB2...
$table->text('description')->nullable();
$table->date('start_date'); // Ngày bắt đầu mở bán
$table->date('end_date')->nullable(); // Ngày kết thúc
$table->string('status')->default('Đang mở bán'); // Đang mở bán, Đã đóng, Chuẩn bị
// Chính sách chiết khấu mặc định cho đợt
$table->jsonb('discount_policy')->nullable();
// Ví dụ: {"open_sale": "5%", "wholesale": "3%", "full_payment": "2%"}
// Mẫu thanh toán mặc định cho đợt
$table->foreignUuid('payment_template_id')->nullable()->constrained('payment_templates')->nullOnDelete();
$table->timestamps();
});
Schema::create('sales_phase_products', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('sales_phase_id')->constrained('sales_phases')->cascadeOnDelete();
$table->foreignUuid('product_id')->constrained('products')->cascadeOnDelete();
// Giá bán cụ thể trong đợt này (ghi đè giá gốc nếu có)
$table->decimal('sale_price', 15, 2)->nullable();
$table->decimal('land_value', 15, 2)->nullable();
$table->decimal('foundation_value', 15, 2)->nullable();
// Chiết khấu riêng cho sản phẩm này trong đợt
$table->jsonb('discount_details')->nullable();
// Trạng thái sản phẩm trong đợt
$table->string('status')->default('Còn hàng'); // Còn hàng, Đã giữ, Đã bán, Khóa
$table->unique(['sales_phase_id', 'product_id']);
$table->timestamps();
});
}
public function down(): void {
Schema::dropIfExists('sales_phase_products');
Schema::dropIfExists('sales_phases');
}
};

View File

@@ -0,0 +1,19 @@
<?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::table('contracts', function (Blueprint $table) {
$table->foreignUuid('sales_phase_id')->nullable()->constrained('sales_phases')->nullOnDelete();
});
}
public function down(): void {
Schema::table('contracts', function (Blueprint $table) {
$table->dropConstrainedForeignId('sales_phase_id');
});
}
};