company_id = $company_id; $this->db = $db; } public function handle() { MultiDB::setDb($this->db); $this->company = Company::find($this->company_id); $this->invoices = $this->company->invoices()->whereIn('status_id', [1,2,3]) ->where('is_deleted', 0) ->get(); $this->match(); } private function match() { BankTransaction::where('company_id', $this->company->id) ->where('is_matched', false) ->where('provisional_match', false) ->cursor() ->each(function ($bt){ $invoice = $this->invoices->first(function ($value, $key) use ($bt){ return str_contains($value->number, $bt->description); }); if($invoice) { $bt->invoice_id = $invoice->id; $bt->provisional_match = true; $bt->save(); } }); } // 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->first(function ($value, $key) use ($description){ // return str_contains($value->number, $description); // }); // if($invoice) // $transaction['invocie_id'] = $invoice->hashed_id; // return $transaction; // } }