firefly-iii/app/Helpers/Csv/Converter/OpposingAccountIban.php

58 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Account;
2015-07-05 14:47:59 -05:00
use Log;
/**
* Class OpposingAccountIban
*
* @package FireflyIII\Helpers\Csv\Converter
*/
class OpposingAccountIban extends BasicConverter implements ConverterInterface
{
/**
* If mapped, return account. Otherwise, only return the name itself.
*
* @return Account|string
*/
public function convert()
{
if (isset($this->mapped[$this->index][$this->value])) {
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
return $account;
} else {
2015-07-05 14:47:59 -05:00
if (strlen($this->value) > 0) {
2015-07-06 18:07:19 -05:00
$account = $this->findAccount();
if (!is_null($account)) {
return $account;
}
}
return $this->value;
}
}
2015-07-06 18:07:19 -05:00
/**
* @return Account|null
*/
protected function findAccount()
{
$set = Auth::user()->accounts()->get();
/** @var Account $account */
foreach ($set as $account) {
if ($account->iban == $this->value) {
Log::debug('OpposingAccountIban::convert found an Account (#' . $account->id . ': ' . $account->name . ') with IBAN ' . $this->value);
return $account;
}
}
return null;
}
2015-07-09 14:26:40 -05:00
}