You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2024_11_13_214900_create_documents_table.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. */
  10. public function up(): void
  11. {
  12. Schema::create('documents', function (Blueprint $table) {
  13. $table->id();
  14. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  15. $table->foreignId('client_id')->nullable()->constrained('clients')->nullOnDelete();
  16. $table->foreignId('vendor_id')->nullable()->constrained('vendors')->nullOnDelete();
  17. $table->string('type'); // invoice, bill, etc.
  18. $table->string('logo')->nullable();
  19. $table->string('header')->nullable();
  20. $table->string('subheader')->nullable();
  21. $table->string('document_number')->nullable();
  22. $table->string('order_number')->nullable(); // PO, SO, etc.
  23. $table->date('date')->nullable();
  24. $table->date('due_date')->nullable();
  25. $table->string('status')->default('draft');
  26. $table->string('currency_code')->nullable();
  27. $table->integer('subtotal')->default(0);
  28. $table->integer('tax_total')->default(0);
  29. $table->integer('discount_total')->default(0);
  30. $table->integer('total')->default(0);
  31. $table->integer('amount_paid')->default(0);
  32. $table->integer('amount_due')->storedAs('total - amount_paid');
  33. $table->text('terms')->nullable(); // terms, notes
  34. $table->text('footer')->nullable();
  35. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  36. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  37. $table->timestamps();
  38. });
  39. }
  40. /**
  41. * Reverse the migrations.
  42. */
  43. public function down(): void
  44. {
  45. Schema::dropIfExists('documents');
  46. }
  47. };