1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Transaction matching service

This commit is contained in:
David Bomba 2022-08-08 19:07:35 +10:00
parent 357cb17ebf
commit 3d397b40e3
2 changed files with 65 additions and 0 deletions

View File

@ -22,6 +22,7 @@ use App\Http\Requests\BankIntegration\StoreBankIntegrationRequest;
use App\Http\Requests\BankIntegration\UpdateBankIntegrationRequest;
use App\Models\BankIntegration;
use App\Repositories\BankIntegrationRepository;
use App\Services\Bank\BankService;
use App\Transformers\BankIntegrationTransformer;
use Illuminate\Http\Request;
@ -495,6 +496,9 @@ class BankIntegrationController extends BaseController
$transactions = $yodlee->getTransactions($data);
$transactions = (new BankService(auth()->user()->company()))->match();
return response()->json($transactions, 200, [], JSON_PRETTY_PRINT);
}

View File

@ -0,0 +1,61 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Bank;
use App\Models\Company;
class BankService
{
public Company $company;
private $invoices;
public function __construct(Company $company)
{
$this->company = $company;
$this->invoices = $this->company->invoices()->whereIn('status_id', [1,2,3])
->where('is_deleted', 0)
->get();
}
public function match($transactions): array
{
foreach($transactions as $transaction)
{
$this->matchIncome($transaction);
}
return $transactions;
}
private function matchExpense()
{
}
private function matchIncome($transaction)
{
$description = str_replace(" ", "", $transaction->description);
$invoice = $this->invoices->where('number', $description)->first();
if($invoice)
$transaction['invocie_id'] = $invoice->hashed_id;
return $transaction;
}
}