mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-21 09:00:07 +00:00
Auto commit for release 'develop' on 2025-03-14
This commit is contained in:
@@ -63,7 +63,8 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$search->whereLike('name', sprintf('%%%s', $query));
|
||||
}
|
||||
$search->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')->where('active', true);
|
||||
->orderBy('name', 'ASC')->where('active', true)
|
||||
;
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
@@ -75,7 +76,8 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$search->whereLike('name', sprintf('%s%%', $query));
|
||||
}
|
||||
$search->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')->where('active', true);
|
||||
->orderBy('name', 'ASC')->where('active', true)
|
||||
;
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
@@ -83,7 +85,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
public function budgetedInPeriod(Carbon $start, Carbon $end): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in budgetedInPeriod("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
$return = [];
|
||||
$return = [];
|
||||
|
||||
/** @var BudgetLimitRepository $limitRepository */
|
||||
$limitRepository = app(BudgetLimitRepository::class);
|
||||
@@ -100,9 +102,9 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
/** @var BudgetLimit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
|
||||
$currency = $limit->transactionCurrency;
|
||||
$rate = $converter->getCurrencyRate($currency, $defaultCurrency, $end);
|
||||
$currencyCode = $currency->code;
|
||||
$currency = $limit->transactionCurrency;
|
||||
$rate = $converter->getCurrencyRate($currency, $defaultCurrency, $end);
|
||||
$currencyCode = $currency->code;
|
||||
$return[$currencyCode] ??= [
|
||||
'currency_id' => (string) $currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
@@ -157,9 +159,10 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
public function getActiveBudgets(): Collection
|
||||
{
|
||||
return $this->user->budgets()->where('active', true)
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')
|
||||
->get();
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')
|
||||
->get()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,19 +202,19 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
public function budgetedInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in budgetedInPeriod(#%d, "%s", "%s")', $budget->id, $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
$return = [];
|
||||
$return = [];
|
||||
|
||||
/** @var BudgetLimitRepository $limitRepository */
|
||||
$limitRepository = app(BudgetLimitRepository::class);
|
||||
$limitRepository->setUser($this->user);
|
||||
|
||||
app('log')->debug(sprintf('Budget #%d: "%s"', $budget->id, $budget->name));
|
||||
$limits = $limitRepository->getBudgetLimits($budget, $start, $end);
|
||||
$limits = $limitRepository->getBudgetLimits($budget, $start, $end);
|
||||
|
||||
/** @var BudgetLimit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
|
||||
$currency = $limit->transactionCurrency;
|
||||
$currency = $limit->transactionCurrency;
|
||||
$return[$currency->id] ??= [
|
||||
'id' => (string) $currency->id,
|
||||
'name' => $currency->name,
|
||||
@@ -280,7 +283,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
{
|
||||
app('log')->debug('Now in update()');
|
||||
|
||||
$oldName = $budget->name;
|
||||
$oldName = $budget->name;
|
||||
if (array_key_exists('name', $data)) {
|
||||
$budget->name = $data['name'];
|
||||
$this->updateRuleActions($oldName, $budget->name);
|
||||
@@ -295,7 +298,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$budget->save();
|
||||
|
||||
// update or create auto-budget:
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// first things first: delete when no longer required:
|
||||
$autoBudgetType = array_key_exists('auto_budget_type', $data) ? $data['auto_budget_type'] : null;
|
||||
@@ -321,10 +324,11 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
{
|
||||
$types = ['set_budget'];
|
||||
$actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_actions.action_type', $types)
|
||||
->where('rule_actions.action_value', $oldName)
|
||||
->get(['rule_actions.*']);
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_actions.action_type', $types)
|
||||
->where('rule_actions.action_value', $oldName)
|
||||
->get(['rule_actions.*'])
|
||||
;
|
||||
app('log')->debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||
|
||||
/** @var RuleAction $action */
|
||||
@@ -339,10 +343,11 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
{
|
||||
$types = ['budget_is'];
|
||||
$triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_triggers.trigger_type', $types)
|
||||
->where('rule_triggers.trigger_value', $oldName)
|
||||
->get(['rule_triggers.*']);
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_triggers.trigger_type', $types)
|
||||
->where('rule_triggers.trigger_value', $oldName)
|
||||
->get(['rule_triggers.*'])
|
||||
;
|
||||
app('log')->debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||
|
||||
/** @var RuleTrigger $trigger */
|
||||
@@ -386,7 +391,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// grab default currency:
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
if (null === $autoBudget) {
|
||||
// at this point it's a blind assumption auto_budget_type is 1 or 2.
|
||||
@@ -466,7 +471,8 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
public function getBudgets(): Collection
|
||||
{
|
||||
return $this->user->budgets()->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')->get();
|
||||
->orderBy('name', 'ASC')->get()
|
||||
;
|
||||
}
|
||||
|
||||
public function destroyAutoBudget(Budget $budget): void
|
||||
@@ -524,7 +530,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
|
||||
public function getAttachments(Budget $budget): Collection
|
||||
{
|
||||
$set = $budget->attachments()->get();
|
||||
$set = $budget->attachments()->get();
|
||||
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
@@ -550,8 +556,9 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
public function getInactiveBudgets(): Collection
|
||||
{
|
||||
return $this->user->budgets()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')->where('active', 0)->get();
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')->where('active', 0)->get()
|
||||
;
|
||||
}
|
||||
|
||||
public function getNoteText(Budget $budget): ?string
|
||||
@@ -571,7 +578,8 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$search->whereLike('name', sprintf('%%%s%%', $query));
|
||||
}
|
||||
$search->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')->where('active', true);
|
||||
->orderBy('name', 'ASC')->where('active', true)
|
||||
;
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
@@ -591,8 +599,8 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
// exclude specific liabilities
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($subset as $account) {
|
||||
@@ -603,19 +611,20 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
|
||||
// start collecting:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)
|
||||
->setRange($start, $end)
|
||||
->excludeDestinationAccounts($selection)
|
||||
->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
|
||||
->setBudgets($this->getActiveBudgets());
|
||||
->setRange($start, $end)
|
||||
->excludeDestinationAccounts($selection)
|
||||
->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
|
||||
->setBudgets($this->getActiveBudgets())
|
||||
;
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'id' => (string) $currencyId,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
@@ -626,9 +635,9 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] ??= [
|
||||
$array[$foreignId] ??= [
|
||||
'id' => (string) $foreignId,
|
||||
'name' => $journal['foreign_currency_name'],
|
||||
'symbol' => $journal['foreign_currency_symbol'],
|
||||
@@ -652,8 +661,8 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
// exclude specific liabilities
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($subset as $account) {
|
||||
@@ -664,19 +673,20 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
|
||||
// start collecting:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)
|
||||
->setRange($start, $end)
|
||||
->excludeDestinationAccounts($selection)
|
||||
->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
|
||||
->setBudget($budget);
|
||||
->setRange($start, $end)
|
||||
->excludeDestinationAccounts($selection)
|
||||
->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
|
||||
->setBudget($budget)
|
||||
;
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'id' => (string) $currencyId,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
@@ -687,9 +697,9 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] ??= [
|
||||
$array[$foreignId] ??= [
|
||||
'id' => (string) $foreignId,
|
||||
'name' => $journal['foreign_currency_name'],
|
||||
'symbol' => $journal['foreign_currency_symbol'],
|
||||
@@ -711,7 +721,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
*/
|
||||
public function store(array $data): Budget
|
||||
{
|
||||
$order = $this->getMaxOrder();
|
||||
$order = $this->getMaxOrder();
|
||||
|
||||
try {
|
||||
$newBudget = Budget::create(
|
||||
@@ -738,7 +748,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
if (!array_key_exists('auto_budget_type', $data) || !array_key_exists('auto_budget_amount', $data) || !array_key_exists('auto_budget_period', $data)) {
|
||||
return $newBudget;
|
||||
}
|
||||
$type = $data['auto_budget_type'];
|
||||
$type = $data['auto_budget_type'];
|
||||
if ('none' === $type) {
|
||||
return $newBudget;
|
||||
}
|
||||
@@ -757,8 +767,8 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
}
|
||||
|
||||
/** @var CurrencyRepositoryInterface $repos */
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = null;
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = null;
|
||||
if (array_key_exists('currency_id', $data)) {
|
||||
$currency = $repos->find((int) $data['currency_id']);
|
||||
}
|
||||
@@ -769,7 +779,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
|
||||
$autoBudget = new AutoBudget();
|
||||
$autoBudget = new AutoBudget();
|
||||
$autoBudget->budget()->associate($newBudget);
|
||||
$autoBudget->transaction_currency_id = $currency->id;
|
||||
$autoBudget->auto_budget_type = $type;
|
||||
@@ -778,11 +788,11 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$autoBudget->save();
|
||||
|
||||
// create initial budget limit.
|
||||
$today = today(config('app.timezone'));
|
||||
$start = app('navigation')->startOfPeriod($today, $autoBudget->period);
|
||||
$end = app('navigation')->endOfPeriod($start, $autoBudget->period);
|
||||
$today = today(config('app.timezone'));
|
||||
$start = app('navigation')->startOfPeriod($today, $autoBudget->period);
|
||||
$end = app('navigation')->endOfPeriod($start, $autoBudget->period);
|
||||
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$limitRepos->setUser($this->user);
|
||||
$limitRepos->store(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user