Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

2023_09_03_100000_create_accounting_tables.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. use App\Enums\Banking\BankAccountType;
  3. use Illuminate\Database\Migrations\Migration;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\Schema;
  6. return new class extends Migration
  7. {
  8. /**
  9. * Run the migrations.
  10. */
  11. public function up(): void
  12. {
  13. Schema::create('institutions', function (Blueprint $table) {
  14. $table->id();
  15. $table->string('external_institution_id')->nullable(); // Plaid
  16. $table->string('name')->index();
  17. $table->string('logo')->nullable();
  18. $table->string('website')->nullable();
  19. $table->string('phone', 20)->nullable();
  20. $table->text('address')->nullable();
  21. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  22. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  23. $table->timestamps();
  24. });
  25. Schema::create('account_subtypes', function (Blueprint $table) {
  26. $table->id();
  27. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  28. $table->boolean('multi_currency')->default(false);
  29. $table->string('category');
  30. $table->string('type');
  31. $table->string('name');
  32. $table->text('description')->nullable();
  33. $table->timestamps();
  34. });
  35. Schema::create('bank_accounts', function (Blueprint $table) {
  36. $table->id();
  37. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  38. $table->foreignId('institution_id')->nullable()->constrained('institutions')->nullOnDelete();
  39. $table->string('type')->default(BankAccountType::DEFAULT);
  40. $table->string('number', 20)->nullable();
  41. $table->boolean('enabled')->default(true);
  42. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  43. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  44. $table->timestamps();
  45. });
  46. Schema::create('accounts', function (Blueprint $table) {
  47. $table->id();
  48. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  49. $table->foreignId('subtype_id')->nullable()->constrained('account_subtypes')->nullOnDelete();
  50. $table->foreignId('parent_id')->nullable()->constrained('accounts')->nullOnDelete();
  51. $table->string('category')->nullable();
  52. $table->string('type')->nullable();
  53. $table->string('code')->nullable()->index();
  54. $table->string('name')->nullable()->index();
  55. $table->string('currency_code')->nullable();
  56. $table->text('description')->nullable();
  57. $table->boolean('archived')->default(false);
  58. $table->boolean('default')->default(false);
  59. $table->foreignId('bank_account_id')->nullable()->constrained('bank_accounts')->cascadeOnDelete();
  60. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  61. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  62. $table->timestamps();
  63. $table->unique(['company_id', 'code']);
  64. });
  65. Schema::create('connected_bank_accounts', function (Blueprint $table) {
  66. $table->id();
  67. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  68. $table->foreignId('institution_id')->nullable()->constrained('institutions')->nullOnDelete();
  69. $table->foreignId('bank_account_id')->nullable()->constrained('bank_accounts')->nullOnDelete();
  70. $table->string('external_account_id')->nullable();
  71. $table->text('access_token')->nullable();
  72. $table->string('identifier')->unique()->nullable(); // Plaid
  73. $table->string('item_id')->nullable();
  74. $table->string('currency_code')->nullable();
  75. $table->double('current_balance')->default(0);
  76. $table->string('name');
  77. $table->string('mask');
  78. $table->string('type')->default(BankAccountType::DEFAULT);
  79. $table->string('subtype')->nullable();
  80. $table->boolean('import_transactions')->default(false);
  81. $table->timestamp('last_imported_at')->nullable();
  82. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  83. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  84. $table->timestamps();
  85. });
  86. }
  87. /**
  88. * Reverse the migrations.
  89. */
  90. public function down(): void
  91. {
  92. Schema::dropIfExists('institutions');
  93. Schema::dropIfExists('account_subtypes');
  94. Schema::dropIfExists('accounts');
  95. Schema::dropIfExists('bank_accounts');
  96. Schema::dropIfExists('connected_bank_accounts');
  97. }
  98. };