1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/database/migrations/2022_08_05_023357_bank_integration.php

100 lines
4.2 KiB
PHP
Raw Normal View History

2022-08-05 04:58:45 +02:00
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
2023-02-16 02:36:09 +01:00
return new class extends Migration {
2022-08-05 04:58:45 +02:00
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
2022-08-05 06:25:06 +02:00
Schema::create('bank_integrations', function (Blueprint $table) {
2022-08-05 04:58:45 +02:00
$table->id();
$table->unsignedInteger('account_id');
$table->unsignedInteger('company_id');
$table->unsignedInteger('user_id');
2022-09-21 07:30:57 +02:00
2022-08-11 06:19:35 +02:00
$table->text('provider_name'); //providerName ie Chase
2022-08-11 04:39:43 +02:00
$table->bigInteger('provider_id'); //id of the bank
$table->bigInteger('bank_account_id'); //id
2022-08-05 06:25:06 +02:00
$table->text('bank_account_name')->nullable(); //accountName
$table->text('bank_account_number')->nullable(); //accountNumber
$table->text('bank_account_status')->nullable(); //accountStatus
$table->text('bank_account_type')->nullable(); //CONTAINER
2022-08-05 04:58:45 +02:00
$table->decimal('balance', 20, 6)->default(0); //currentBalance.amount
$table->text('currency')->nullable(); //currentBalance.currency
2022-08-11 03:49:39 +02:00
$table->text('nickname')->default(''); //accountName
2022-08-12 03:40:35 +02:00
$table->date('from_date')->nullable();
2022-08-11 03:49:39 +02:00
$table->boolean('is_deleted')->default(0);
2022-08-05 04:58:45 +02:00
$table->timestamps(6);
$table->softDeletes('deleted_at', 6);
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade')->onUpdate('cascade');
});
2022-08-06 08:58:48 +02:00
Schema::table('accounts', function (Blueprint $table) {
$table->text('bank_integration_account_id')->nullable();
2023-02-16 02:36:09 +01:00
});
2022-08-10 03:56:46 +02:00
2023-02-16 02:36:09 +01:00
Schema::create('bank_transactions', function (Blueprint $table) {
2022-08-10 03:56:46 +02:00
$table->id();
$table->unsignedInteger('company_id');
$table->unsignedInteger('user_id');
2022-08-12 03:40:35 +02:00
$table->unsignedBigInteger('bank_integration_id');
2022-08-12 05:41:55 +02:00
$table->unsignedBigInteger('transaction_id')->index();
2022-09-21 05:21:52 +02:00
$table->decimal('amount', 20, 6)->default(0);
$table->string('currency_code')->nullable();
2022-09-22 07:54:58 +02:00
$table->unsignedInteger('currency_id')->nullable();
2022-09-21 05:21:52 +02:00
$table->string('account_type')->nullable();
$table->unsignedInteger('category_id')->nullable();
$table->unsignedInteger('ninja_category_id')->nullable();
2022-08-17 03:52:16 +02:00
$table->string('category_type')->index();
2022-09-21 07:30:57 +02:00
$table->string('base_type')->index();
2022-09-21 05:21:52 +02:00
$table->date('date')->nullable();
2022-08-11 06:47:08 +02:00
$table->unsignedBigInteger('bank_account_id');
2022-09-21 05:21:52 +02:00
$table->text('description')->nullable();
$table->text('invoice_ids')->default('');
2022-08-11 09:05:33 +02:00
$table->unsignedInteger('expense_id')->nullable();
2022-09-21 05:21:52 +02:00
$table->unsignedInteger('vendor_id')->nullable();
$table->unsignedInteger('status_id')->default(1); //unmatched / matched / converted
2022-08-11 09:18:53 +02:00
$table->boolean('is_deleted')->default(0);
2022-08-11 09:05:33 +02:00
$table->timestamps(6);
2022-08-10 03:56:46 +02:00
2022-08-11 09:05:33 +02:00
$table->softDeletes('deleted_at', 6);
2022-08-12 03:40:35 +02:00
$table->foreign('bank_integration_id')->references('id')->on('bank_integrations')->onDelete('cascade')->onUpdate('cascade');
2022-08-10 03:56:46 +02:00
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade')->onUpdate('cascade');
});
2022-09-15 08:15:57 +02:00
Schema::table('expense_categories', function (Blueprint $table) {
$table->unsignedInteger('bank_category_id')->nullable();
2023-02-16 02:36:09 +01:00
});
2022-09-15 08:15:57 +02:00
2022-09-21 07:43:35 +02:00
Schema::table('payments', function (Blueprint $table) {
$table->unsignedBigInteger('transaction_id')->nullable();
2023-02-16 02:36:09 +01:00
});
2022-09-21 07:43:35 +02:00
Schema::table('expenses', function (Illuminate\Database\Schema\Blueprint $table) {
$table->unsignedBigInteger('transaction_id')->nullable()->change();
2023-02-16 02:36:09 +01:00
});
2022-08-05 04:58:45 +02:00
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
};