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.3KB

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