File: /www/wwwroot/erp.nhatnamsst.com/database/migrations/2025_02_01_000000_create_debts_table.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
{
Schema::create('debts', function (Blueprint $table) {
$table->id();
$table->string('invoice_number')->unique()->nullable(); // Số hóa đơn (HD00000142)
$table->date('invoice_date')->nullable(); // Ngày xuất hóa đơn
$table->date('debt_aging_date')->nullable(); // Ngày công nợ
$table->unsignedBigInteger('sale_id')->nullable(); // Nhân viên sale
$table->unsignedBigInteger('sale_leader_id')->nullable(); // Sale Leader
$table->unsignedBigInteger('customer_id')->nullable(); // Khách hàng
$table->integer('customer_type')->nullable(); // Loại khách hàng (EU, TM, CN)
$table->integer('payment_days')->default(30); // Số ngày thanh toán
$table->decimal('total_po_price', 15, 2)->default(0); // Tổng giá PO
$table->decimal('vat_percent', 5, 2)->default(10); // % thuế VAT
$table->decimal('total_payment_amount', 15, 2)->default(0); // Tổng số tiền thanh toán
$table->decimal('advance_payment', 15, 2)->default(0); // Tiền trả trước
$table->string('due_date_warning')->nullable(); // Cảnh báo hạn thanh toán
$table->text('related_pos')->nullable(); // PO liên quan (PO230345;PO230766)
$table->decimal('remaining_amount', 15, 2)->default(0); // Số tiền còn lại
$table->integer('status')->default(1); // Trạng thái (1: Chưa thanh toán, 2: Đang thanh toán, 3: Hoàn thành)
$table->string('payment_method')->nullable(); // Phương thức thanh toán (Trả sau, Trả trước, etc.)
$table->text('accounting_note')->nullable(); // Ghi chú kế toán
$table->text('attached_file')->nullable(); // File đính kèm (JSON array)
$table->timestamps();
$table->foreign('sale_id')->references('id')->on('admins')->onDelete('set null');
$table->foreign('sale_leader_id')->references('id')->on('admins')->onDelete('set null');
$table->foreign('customer_id')->references('id')->on('customers')->onDelete('set null');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('debts');
}
};