working on data matching

This commit is contained in:
David Bomba 2022-08-12 14:23:23 +10:00
parent 3b1d0e07e2
commit de33548908

View File

@ -48,38 +48,61 @@ class BankService implements ShouldQueue
->where('is_deleted', 0) ->where('is_deleted', 0)
->get(); ->get();
$this->match();
} }
public function match($transactions): array private function match()
{ {
BankTransaction::where('company_id', $this->company->id)
->where('is_matched', false)
->cursor()
->each(function ($bt){
foreach($transactions as $transaction) $invoice = $this->invoices->first(function ($value, $key) use ($bt){
{
$this->matchIncome($transaction);
}
return $transactions; return str_contains($value->number, $bt->description);
}
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) if($invoice)
$transaction['invocie_id'] = $invoice->hashed_id; {
$bt->invoice_id = $invoice->id;
return $transaction; $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;
// }
} }