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_27_223015_create_invoices_table.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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('invoices', function (Blueprint $table) {
  13. $table->id();
  14. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  15. $table->foreignId('client_id')->nullable()->constrained('clients')->nullOnDelete();
  16. $table->string('logo')->nullable();
  17. $table->string('header')->nullable();
  18. $table->string('subheader')->nullable();
  19. $table->string('invoice_number')->nullable();
  20. $table->string('order_number')->nullable(); // PO, SO, etc.
  21. $table->date('date')->nullable();
  22. $table->date('due_date')->nullable();
  23. $table->timestamp('approved_at')->nullable();
  24. $table->timestamp('paid_at')->nullable();
  25. $table->timestamp('last_sent')->nullable();
  26. $table->string('status')->default('draft');
  27. $table->string('currency_code')->nullable();
  28. $table->string('discount_method')->default('per_line_item');
  29. $table->string('discount_computation')->default('percentage');
  30. $table->integer('discount_rate')->default(0);
  31. $table->integer('subtotal')->default(0);
  32. $table->integer('tax_total')->default(0);
  33. $table->integer('discount_total')->default(0);
  34. $table->integer('total')->default(0);
  35. $table->integer('amount_paid')->default(0);
  36. $table->integer('amount_due')->storedAs('total - amount_paid');
  37. $table->text('terms')->nullable(); // terms, notes
  38. $table->text('footer')->nullable();
  39. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  40. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  41. $table->timestamps();
  42. });
  43. }
  44. /**
  45. * Reverse the migrations.
  46. */
  47. public function down(): void
  48. {
  49. Schema::dropIfExists('invoices');
  50. }
  51. };