mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-24 07:16:35 -06:00
35 lines
814 B
PHP
35 lines
814 B
PHP
|
<?php
|
||
|
namespace FireflyIII\Helpers\Csv\Converter;
|
||
|
|
||
|
use Auth;
|
||
|
use FireflyIII\Models\Budget;
|
||
|
|
||
|
/**
|
||
|
* Class BudgetName
|
||
|
*
|
||
|
* @package FireflyIII\Helpers\Csv\Converter
|
||
|
*/
|
||
|
class BudgetName extends BasicConverter implements ConverterInterface
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* @return Budget
|
||
|
*/
|
||
|
public function convert()
|
||
|
{
|
||
|
// is mapped? Then it's easy!
|
||
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||
|
$budget = Auth::user()->budgets()->find($this->mapped[$this->index][$this->value]);
|
||
|
} else {
|
||
|
$budget = Budget::firstOrCreateEncrypted(
|
||
|
[
|
||
|
'name' => $this->value,
|
||
|
'user_id' => Auth::user()->id,
|
||
|
'active' => true,
|
||
|
]
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return $budget;
|
||
|
}
|
||
|
}
|