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.

2023_09_03_100000_create_accounting_tables.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. use App\Enums\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('accounts', function (Blueprint $table) {
  36. $table->id();
  37. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  38. $table->foreignId('subtype_id')->nullable()->constrained('account_subtypes')->nullOnDelete();
  39. $table->foreignId('parent_id')->nullable()->constrained('accounts')->nullOnDelete();
  40. $table->string('category')->nullable();
  41. $table->string('type')->nullable();
  42. $table->string('code')->nullable()->index();
  43. $table->string('name')->nullable()->index();
  44. $table->string('currency_code')->nullable();
  45. $table->text('description')->nullable();
  46. $table->boolean('active')->default(true);
  47. $table->boolean('default')->default(false);
  48. $table->unsignedBigInteger('accountable_id')->nullable();
  49. $table->string('accountable_type')->nullable();
  50. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  51. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  52. $table->timestamps();
  53. $table->unique(['company_id', 'code']);
  54. });
  55. Schema::create('bank_accounts', function (Blueprint $table) {
  56. $table->id();
  57. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  58. $table->foreignId('institution_id')->nullable()->constrained('institutions')->nullOnDelete();
  59. $table->string('type')->default(BankAccountType::DEFAULT);
  60. $table->string('number', 20)->nullable();
  61. $table->boolean('enabled')->default(true);
  62. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  63. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  64. $table->timestamps();
  65. });
  66. Schema::create('connected_bank_accounts', function (Blueprint $table) {
  67. $table->id();
  68. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  69. $table->foreignId('institution_id')->nullable()->constrained('institutions')->nullOnDelete();
  70. $table->foreignId('bank_account_id')->nullable()->constrained('bank_accounts')->nullOnDelete();
  71. $table->string('external_account_id')->nullable();
  72. $table->text('access_token')->nullable();
  73. $table->string('identifier')->unique()->nullable(); // Plaid
  74. $table->string('item_id')->nullable();
  75. $table->string('currency_code')->nullable();
  76. $table->double('current_balance')->default(0);
  77. $table->string('name');
  78. $table->string('mask');
  79. $table->string('type')->default(BankAccountType::DEFAULT);
  80. $table->string('subtype')->nullable();
  81. $table->boolean('import_transactions')->default(false);
  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. };