Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

2023_09_03_100000_create_accounting_tables.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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('institutions', function (Blueprint $table) {
  13. $table->id();
  14. $table->string('external_institution_id')->nullable(); // Plaid
  15. $table->string('name')->index();
  16. $table->string('logo')->nullable();
  17. $table->string('website')->nullable();
  18. $table->string('phone', 20)->nullable();
  19. $table->text('address')->nullable();
  20. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  21. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  22. $table->timestamps();
  23. });
  24. Schema::create('account_subtypes', function (Blueprint $table) {
  25. $table->id();
  26. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  27. $table->boolean('multi_currency')->default(false);
  28. $table->string('category');
  29. $table->string('type');
  30. $table->string('name');
  31. $table->text('description')->nullable();
  32. $table->timestamps();
  33. });
  34. Schema::create('accounts', function (Blueprint $table) {
  35. $table->id();
  36. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  37. $table->foreignId('subtype_id')->nullable()->constrained('account_subtypes')->nullOnDelete();
  38. $table->foreignId('parent_id')->nullable()->constrained('accounts')->nullOnDelete();
  39. $table->string('category')->nullable();
  40. $table->string('type')->nullable();
  41. $table->string('code')->nullable()->index();
  42. $table->string('name')->nullable()->index();
  43. $table->string('currency_code')->nullable();
  44. $table->text('description')->nullable();
  45. $table->boolean('archived')->default(false);
  46. $table->boolean('default')->default(false);
  47. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  48. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  49. $table->timestamps();
  50. });
  51. Schema::create('bank_accounts', function (Blueprint $table) {
  52. $table->id();
  53. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  54. $table->foreignId('account_id')->nullable()->constrained('accounts')->nullOnDelete();
  55. $table->foreignId('institution_id')->nullable()->constrained('institutions')->nullOnDelete();
  56. $table->string('type')->default('depository');
  57. $table->string('number', 20)->nullable();
  58. $table->boolean('enabled')->default(true);
  59. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  60. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  61. $table->timestamps();
  62. });
  63. Schema::create('connected_bank_accounts', function (Blueprint $table) {
  64. $table->id();
  65. $table->foreignId('company_id')->constrained()->cascadeOnDelete();
  66. $table->foreignId('institution_id')->nullable()->constrained('institutions')->nullOnDelete();
  67. $table->foreignId('bank_account_id')->nullable()->constrained('bank_accounts')->nullOnDelete();
  68. $table->string('external_account_id')->nullable();
  69. $table->text('access_token')->nullable();
  70. $table->string('identifier')->unique()->nullable(); // Plaid
  71. $table->string('item_id')->nullable();
  72. $table->string('currency_code')->nullable();
  73. $table->double('current_balance')->default(0);
  74. $table->string('name');
  75. $table->string('mask');
  76. $table->string('type')->default('depository');
  77. $table->string('subtype')->nullable();
  78. $table->boolean('import_transactions')->default(false);
  79. $table->timestamp('last_imported_at')->nullable();
  80. $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
  81. $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
  82. $table->timestamps();
  83. });
  84. }
  85. /**
  86. * Reverse the migrations.
  87. */
  88. public function down(): void
  89. {
  90. Schema::dropIfExists('connected_bank_accounts');
  91. Schema::dropIfExists('bank_accounts');
  92. Schema::dropIfExists('accounts');
  93. Schema::dropIfExists('account_subtypes');
  94. Schema::dropIfExists('institutions');
  95. }
  96. };