/** * @param Bill $bill * @param TransactionJournal $journal * * @return boolean|null */ public function scan(Bill $bill, TransactionJournal $journal) { $matches = explode(',', $bill->match); $description = strtolower($journal->description) . ' ' . strtolower($journal->destination_account->name); $wordMatch = $this->doWordMatch($matches, $description); $amountMatch = $this->doAmountMatch($journal->amount, $bill->amount_min, $bill->amount_max); /* * If both, update! */ if ($wordMatch && $amountMatch) { $journal->bill()->associate($bill); $journal->save(); return true; } if ($bill->id == $journal->bill_id) { // if no match, but bill used to match, remove it: $journal->bill_id = null; $journal->save(); return true; } return false; }
/** * @param Bill $bill * @param TransactionJournal $journal * * @return boolean|null */ public function scan(Bill $bill, TransactionJournal $journal) { $matches = explode(',', $bill->match); $description = strtolower($journal->description) . ' ' . strtolower($journal->destination_account->name); $wordMatch = $this->doWordMatch($matches, $description); $amountMatch = $this->doAmountMatch($journal->amount_positive, $bill->amount_min, $bill->amount_max); Log::debug('Journal #' . $journal->id . ' has description "' . $description . '"'); /* * If both, update! */ if ($wordMatch && $amountMatch) { $journal->bill()->associate($bill); $journal->save(); return true; } else { Log::debug('Wordmatch: ' . ($wordMatch ? 'true' : 'false') . ' AmountMatch: ' . ($amountMatch ? 'true' : 'false')); } if ($bill->id == $journal->bill_id) { // if no match, but bill used to match, remove it: $journal->bill_id = null; $journal->save(); return true; } return false; }
/** * @param TransactionJournal $journal * @param ImportEntry $entry */ private function storeBill(TransactionJournal $journal, ImportEntry $entry) { if (!is_null($entry->fields['bill']) && !is_null($entry->fields['bill']->id)) { $journal->bill()->associate($entry->fields['bill']); Log::debug('Attached bill', ['id' => $entry->fields['bill']->id, 'name' => $entry->fields['bill']->name]); $journal->save(); } }