diff --git a/app/Http/Controllers/BankIntegrationController.php b/app/Http/Controllers/BankIntegrationController.php index 29ac2592cc..725bd2275a 100644 --- a/app/Http/Controllers/BankIntegrationController.php +++ b/app/Http/Controllers/BankIntegrationController.php @@ -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); } diff --git a/app/Services/Bank/BankService.php b/app/Services/Bank/BankService.php new file mode 100644 index 0000000000..f22946b87e --- /dev/null +++ b/app/Services/Bank/BankService.php @@ -0,0 +1,61 @@ +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; + } + +}