mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-08 22:44:36 -04:00
Data matching for bank integration
This commit is contained in:
parent
de33548908
commit
2da7f4e17c
@ -12,6 +12,7 @@
|
|||||||
namespace App\Jobs\Bank;
|
namespace App\Jobs\Bank;
|
||||||
|
|
||||||
use App\Helpers\Bank\Yodlee\Yodlee;
|
use App\Helpers\Bank\Yodlee\Yodlee;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
use App\Models\BankIntegration;
|
use App\Models\BankIntegration;
|
||||||
use App\Models\BankTransaction;
|
use App\Models\BankTransaction;
|
||||||
use App\Services\Bank\BankService;
|
use App\Services\Bank\BankService;
|
||||||
@ -112,6 +113,11 @@ class ProcessBankTransactions implements ShouldQueue
|
|||||||
|
|
||||||
BankService::dispatch($company->id, $company->db);
|
BankService::dispatch($company->id, $company->db);
|
||||||
|
|
||||||
|
MultiDB::setDb($company->db);
|
||||||
|
|
||||||
|
$this->bank_integration->from_date = now();
|
||||||
|
$this->bank_integration->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Services\Bank;
|
namespace App\Services\Bank;
|
||||||
|
|
||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Models\BankTransaction;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -55,6 +56,7 @@ class BankService implements ShouldQueue
|
|||||||
{
|
{
|
||||||
BankTransaction::where('company_id', $this->company->id)
|
BankTransaction::where('company_id', $this->company->id)
|
||||||
->where('is_matched', false)
|
->where('is_matched', false)
|
||||||
|
->where('provisional_match', false)
|
||||||
->cursor()
|
->cursor()
|
||||||
->each(function ($bt){
|
->each(function ($bt){
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ class BankService implements ShouldQueue
|
|||||||
if($invoice)
|
if($invoice)
|
||||||
{
|
{
|
||||||
$bt->invoice_id = $invoice->id;
|
$bt->invoice_id = $invoice->id;
|
||||||
|
$bt->provisional_match = true;
|
||||||
$bt->save();
|
$bt->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ return new class extends Migration
|
|||||||
$table->unsignedInteger('invoice_id')->nullable();
|
$table->unsignedInteger('invoice_id')->nullable();
|
||||||
$table->unsignedInteger('expense_id')->nullable();
|
$table->unsignedInteger('expense_id')->nullable();
|
||||||
$table->boolean('is_matched')->default(0);
|
$table->boolean('is_matched')->default(0);
|
||||||
|
$table->boolean('provisional_match')->default(0);
|
||||||
$table->boolean('is_deleted')->default(0);
|
$table->boolean('is_deleted')->default(0);
|
||||||
|
|
||||||
$table->timestamps(6);
|
$table->timestamps(6);
|
||||||
|
@ -487,5 +487,4 @@ nlog($accounts);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
126
tests/Feature/Bank/YodleeBankTransactionTest.php
Normal file
126
tests/Feature/Bank/YodleeBankTransactionTest.php
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Feature\Bank;
|
||||||
|
|
||||||
|
use App\Models\BankTransaction;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class YodleeBankTransactionTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use DatabaseTransactions;
|
||||||
|
use MockAccountData;
|
||||||
|
|
||||||
|
protected function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
if(!config('ninja.yodlee.client_id'))
|
||||||
|
$this->markTestSkipped('Skip test no Yodlee API credentials found');
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->withoutMiddleware(
|
||||||
|
ThrottleRequests::class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDataMatching1()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->invoice->number = "super-funk-1234";
|
||||||
|
$this->invoice->save();
|
||||||
|
|
||||||
|
$bank_transaction = BankTransaction::where('company_id', $this->company->id)->first();
|
||||||
|
$bank_transaction->description = "super-funk-1234";
|
||||||
|
$bank_transaction->save();
|
||||||
|
|
||||||
|
$this->assertNotNull($this->invoice);
|
||||||
|
$this->assertNotNull($bank_transaction);
|
||||||
|
|
||||||
|
$invoices = Invoice::where('company_id', $this->company->id)->get();
|
||||||
|
|
||||||
|
BankTransaction::where('company_id', $this->company->id)
|
||||||
|
->where('is_matched', false)
|
||||||
|
->where('provisional_match', false)
|
||||||
|
->cursor()
|
||||||
|
->each(function ($bt) use($invoices){
|
||||||
|
|
||||||
|
$invoice = $invoices->first(function ($value, $key) use ($bt){
|
||||||
|
|
||||||
|
return str_contains($value->number, $bt->description);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if($invoice)
|
||||||
|
{
|
||||||
|
$bt->invoice_id = $invoice->id;
|
||||||
|
$bt->provisional_match = $invoice->id;
|
||||||
|
$bt->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$this->assertTrue(BankTransaction::where('invoice_id', $this->invoice->id)->exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testDataMatching2()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->invoice->number = "super-funk-1234";
|
||||||
|
$this->invoice->save();
|
||||||
|
|
||||||
|
$bank_transaction = BankTransaction::where('company_id', $this->company->id)->first();
|
||||||
|
$bank_transaction->description = "super-funk-123";
|
||||||
|
$bank_transaction->save();
|
||||||
|
|
||||||
|
$this->assertNotNull($this->invoice);
|
||||||
|
$this->assertNotNull($bank_transaction);
|
||||||
|
|
||||||
|
$invoices = Invoice::where('company_id', $this->company->id)->get();
|
||||||
|
|
||||||
|
BankTransaction::where('company_id', $this->company->id)
|
||||||
|
->where('is_matched', false)
|
||||||
|
->where('provisional_match', false)
|
||||||
|
->cursor()
|
||||||
|
->each(function ($bt) use($invoices){
|
||||||
|
|
||||||
|
$invoice = $invoices->first(function ($value, $key) use ($bt){
|
||||||
|
|
||||||
|
return str_contains($value->number, $bt->description);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if($invoice)
|
||||||
|
{
|
||||||
|
$bt->invoice_id = $invoice->id;
|
||||||
|
$bt->provisional_match = $invoice->id;
|
||||||
|
$bt->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$this->assertTrue(BankTransaction::where('invoice_id', $this->invoice->id)->exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -545,26 +545,31 @@ trait MockAccountData
|
|||||||
$this->bank_transaction = BankTransaction::factory()->create([
|
$this->bank_transaction = BankTransaction::factory()->create([
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $this->company->id,
|
||||||
|
'bank_integration_id' => $this->bank_integration->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
BankTransaction::factory()->create([
|
BankTransaction::factory()->create([
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $this->company->id,
|
||||||
|
'bank_integration_id' => $this->bank_integration->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
BankTransaction::factory()->create([
|
BankTransaction::factory()->create([
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $this->company->id,
|
||||||
|
'bank_integration_id' => $this->bank_integration->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
BankTransaction::factory()->create([
|
BankTransaction::factory()->create([
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $this->company->id,
|
||||||
|
'bank_integration_id' => $this->bank_integration->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
BankTransaction::factory()->create([
|
BankTransaction::factory()->create([
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $this->company->id,
|
||||||
|
'bank_integration_id' => $this->bank_integration->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$invitations = CreditInvitation::whereCompanyId($this->credit->company_id)
|
$invitations = CreditInvitation::whereCompanyId($this->credit->company_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user