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:
parent
357cb17ebf
commit
3d397b40e3
@ -22,6 +22,7 @@ use App\Http\Requests\BankIntegration\StoreBankIntegrationRequest;
|
|||||||
use App\Http\Requests\BankIntegration\UpdateBankIntegrationRequest;
|
use App\Http\Requests\BankIntegration\UpdateBankIntegrationRequest;
|
||||||
use App\Models\BankIntegration;
|
use App\Models\BankIntegration;
|
||||||
use App\Repositories\BankIntegrationRepository;
|
use App\Repositories\BankIntegrationRepository;
|
||||||
|
use App\Services\Bank\BankService;
|
||||||
use App\Transformers\BankIntegrationTransformer;
|
use App\Transformers\BankIntegrationTransformer;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@ -495,6 +496,9 @@ class BankIntegrationController extends BaseController
|
|||||||
|
|
||||||
$transactions = $yodlee->getTransactions($data);
|
$transactions = $yodlee->getTransactions($data);
|
||||||
|
|
||||||
|
$transactions = (new BankService(auth()->user()->company()))->match();
|
||||||
|
|
||||||
|
|
||||||
return response()->json($transactions, 200, [], JSON_PRETTY_PRINT);
|
return response()->json($transactions, 200, [], JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
61
app/Services/Bank/BankService.php
Normal file
61
app/Services/Bank/BankService.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user