選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

2024_11_27_223015_create_invoices_table.php 2.5KB

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