mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-05 21:53:08 -06:00
43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
declare(strict_types = 1);
|
|
namespace FireflyIII\Helpers\Csv\Converter;
|
|
|
|
use Auth;
|
|
use FireflyIII\Models\Account;
|
|
use Log;
|
|
|
|
/**
|
|
* Class AccountId
|
|
*
|
|
* @package FireflyIII\Helpers\Csv\Converter
|
|
*/
|
|
class AccountId extends BasicConverter implements ConverterInterface
|
|
{
|
|
|
|
/**
|
|
* @return Account
|
|
*/
|
|
public function convert(): Account
|
|
{
|
|
// is mapped? Then it's easy!
|
|
if (isset($this->mapped[$this->index][$this->value])) {
|
|
|
|
/** @var Account $account */
|
|
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
|
|
} else {
|
|
|
|
/** @var Account $account */
|
|
$account = Auth::user()->accounts()->find($this->value);
|
|
|
|
if (!is_null($account)) {
|
|
Log::debug('Found ' . $account->accountType->type . ' named "******" with ID: ' . $this->value . ' (not mapped) ');
|
|
} else {
|
|
// new account to prevent TypeErrors.
|
|
$account = new Account;
|
|
}
|
|
}
|
|
|
|
return $account;
|
|
}
|
|
}
|