mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New converters for #180 (Budget)
This commit is contained in:
parent
e4d93cad27
commit
429ef80fb9
@ -4,6 +4,7 @@ namespace FireflyIII\Helpers\Csv\Converter;
|
|||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BudgetId
|
* Class BudgetId
|
||||||
@ -18,11 +19,15 @@ class BudgetId extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
|
/** @var BudgetRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
|
||||||
|
|
||||||
// is mapped? Then it's easy!
|
// is mapped? Then it's easy!
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$budget = Auth::user()->budgets()->find($this->mapped[$this->index][$this->value]);
|
$budget = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
} else {
|
||||||
$budget = Auth::user()->budgets()->find($this->value);
|
$budget = $repository->find($this->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $budget;
|
return $budget;
|
||||||
|
@ -4,6 +4,7 @@ namespace FireflyIII\Helpers\Csv\Converter;
|
|||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BudgetName
|
* Class BudgetName
|
||||||
@ -18,12 +19,14 @@ class BudgetName extends BasicConverter implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert()
|
public function convert()
|
||||||
{
|
{
|
||||||
|
/** @var BudgetRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
|
||||||
// is mapped? Then it's easy!
|
// is mapped? Then it's easy!
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$budget = Auth::user()->budgets()->find($this->mapped[$this->index][$this->value]); // see issue #180
|
$budget = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
} else {
|
||||||
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
$budget = $repository->store(['name' => $this->value, 'user' => Auth::user()->id]);
|
||||||
$budget = $repository->store(['name' => $this->value, 'user' => Auth::user()->id]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $budget;
|
return $budget;
|
||||||
|
@ -74,6 +74,23 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a budget.
|
||||||
|
*
|
||||||
|
* @param int $budgetId
|
||||||
|
*
|
||||||
|
* @return Budget
|
||||||
|
*/
|
||||||
|
public function find(int $budgetId): Budget
|
||||||
|
{
|
||||||
|
$budget = $this->user->budgets()->find($budgetId);
|
||||||
|
if (is_null($budget)) {
|
||||||
|
$budget = new Budget;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $budget;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
|
@ -17,7 +17,6 @@ use Illuminate\Support\Collection;
|
|||||||
interface BudgetRepositoryInterface
|
interface BudgetRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Same as ::spentInPeriod but corrects journals for a set of accounts
|
* Same as ::spentInPeriod but corrects journals for a set of accounts
|
||||||
@ -43,6 +42,15 @@ interface BudgetRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(Budget $budget);
|
public function destroy(Budget $budget);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a budget.
|
||||||
|
*
|
||||||
|
* @param int $budgetId
|
||||||
|
*
|
||||||
|
* @return Budget
|
||||||
|
*/
|
||||||
|
public function find(int $budgetId): Budget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user