can edit, delete and see in api autobudget

This commit is contained in:
James Cole
2020-03-14 07:01:31 +01:00
parent 2ece754927
commit 309633069c
14 changed files with 185 additions and 53 deletions

View File

@@ -25,7 +25,7 @@ namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon;
use DB;
use Exception;
use FireflyIII\AutoBudget;
use FireflyIII\Models\AutoBudget;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
@@ -316,6 +316,22 @@ class BudgetRepository implements BudgetRepositoryInterface
$budget->name = $data['name'];
$budget->active = $data['active'];
$budget->save();
// update or create auto-budget:
$autoBudgetType = $data['auto_budget_option'] ?? 0;
if (0 !== $autoBudgetType) {
$autoBudget = $this->getAutoBudget($budget);
if (null === $autoBudget) {
$autoBudget = new AutoBudget;
$autoBudget->budget()->associate($budget);
}
$autoBudget->transaction_currency_id = $data['transaction_currency_id'] ?? 1;
$autoBudget->auto_budget_type = $autoBudgetType;
$autoBudget->amount = $data['auto_budget_amount'] ?? '0';
$autoBudget->period = $data['auto_budget_period'] ?? 'monthly';
$autoBudget->save();
}
$this->updateRuleTriggers($oldName, $data['name']);
$this->updateRuleActions($oldName, $data['name']);
app('preferences')->mark();
@@ -380,4 +396,12 @@ class BudgetRepository implements BudgetRepositoryInterface
$budget->delete();
}
}
/**
* @inheritDoc
*/
public function getAutoBudget(Budget $budget): ?AutoBudget
{
return $budget->autoBudgets()->first();
}
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon;
use FireflyIII\Models\AutoBudget;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\User;
@@ -38,6 +39,13 @@ interface BudgetRepositoryInterface
*/
public function destroyAll(): void;
/**
* @param Budget $budget
*
* @return AutoBudget|null
*/
public function getAutoBudget(Budget $budget): ?AutoBudget;
/**
* @return bool