mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-10 13:21:21 +00:00
Code cleanup
This commit is contained in:
@@ -103,12 +103,12 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$rate = $converter->getCurrencyRate($currency, $defaultCurrency, $end);
|
||||
$currencyCode = $currency->code;
|
||||
$return[$currencyCode] ??= [
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_id' => (string) $currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'native_currency_id' => (string)$defaultCurrency->id,
|
||||
'native_currency_id' => (string) $defaultCurrency->id,
|
||||
'native_currency_name' => $defaultCurrency->name,
|
||||
'native_currency_symbol' => $defaultCurrency->symbol,
|
||||
'native_currency_code' => $defaultCurrency->code,
|
||||
@@ -134,13 +134,13 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
$total = $limit->start_date->diffInDays($limit->end_date, true) + 1; // include the day itself.
|
||||
$days = $this->daysInOverlap($limit, $start, $end);
|
||||
$amount = bcmul(bcdiv($limit->amount, (string)$total), (string)$days);
|
||||
$amount = bcmul(bcdiv($limit->amount, (string) $total), (string) $days);
|
||||
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $amount);
|
||||
$return[$currencyCode]['native_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
|
||||
app('log')->debug(
|
||||
sprintf(
|
||||
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',
|
||||
bcdiv($limit->amount, (string)$total),
|
||||
bcdiv($limit->amount, (string) $total),
|
||||
$limit->amount,
|
||||
$total,
|
||||
$days,
|
||||
@@ -183,21 +183,21 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
// |-----------|
|
||||
// |----------------|
|
||||
if ($start->gte($limit->start_date) && $end->lte($limit->end_date)) {
|
||||
return (int)$start->diffInDays($end, true) + 1; // add one day
|
||||
return (int) $start->diffInDays($end, true) + 1; // add one day
|
||||
}
|
||||
// limit starts earlier and limit ends first:
|
||||
// |-----------|
|
||||
// |-------|
|
||||
if ($limit->start_date->lte($start) && $limit->end_date->lte($end)) {
|
||||
// return days in the range $start-$limit_end
|
||||
return (int)$start->diffInDays($limit->end_date, true) + 1; // add one day, the day itself
|
||||
return (int) $start->diffInDays($limit->end_date, true) + 1; // add one day, the day itself
|
||||
}
|
||||
// limit starts later and limit ends earlier
|
||||
// |-----------|
|
||||
// |-------|
|
||||
if ($limit->start_date->gte($start) && $limit->end_date->gte($end)) {
|
||||
// return days in the range $limit_start - $end
|
||||
return (int)$limit->start_date->diffInDays($end, true) + 1; // add one day, the day itself
|
||||
return (int) $limit->start_date->diffInDays($end, true) + 1; // add one day, the day itself
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -220,7 +220,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
|
||||
$currency = $limit->transactionCurrency;
|
||||
$return[$currency->id] ??= [
|
||||
'id' => (string)$currency->id,
|
||||
'id' => (string) $currency->id,
|
||||
'name' => $currency->name,
|
||||
'symbol' => $currency->symbol,
|
||||
'code' => $currency->code,
|
||||
@@ -243,12 +243,12 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
$total = $limit->start_date->diffInDays($limit->end_date) + 1; // include the day itself.
|
||||
$days = $this->daysInOverlap($limit, $start, $end);
|
||||
$amount = bcmul(bcdiv($limit->amount, (string)$total), (string)$days);
|
||||
$amount = bcmul(bcdiv($limit->amount, (string) $total), (string) $days);
|
||||
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
|
||||
app('log')->debug(
|
||||
sprintf(
|
||||
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',
|
||||
bcdiv($limit->amount, (string)$total),
|
||||
bcdiv($limit->amount, (string) $total),
|
||||
$limit->amount,
|
||||
$total,
|
||||
$days,
|
||||
@@ -297,7 +297,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$budget->active = $data['active'];
|
||||
}
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->setNoteText($budget, (string)$data['notes']);
|
||||
$this->setNoteText($budget, (string) $data['notes']);
|
||||
}
|
||||
$budget->save();
|
||||
|
||||
@@ -408,8 +408,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
/** @var CurrencyRepositoryInterface $repos */
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currencyId = (int)($data['currency_id'] ?? 0);
|
||||
$currencyCode = (string)($data['currency_code'] ?? '');
|
||||
$currencyId = (int) ($data['currency_id'] ?? 0);
|
||||
$currencyCode = (string) ($data['currency_code'] ?? '');
|
||||
$currency = $repos->find($currencyId);
|
||||
if (null === $currency) {
|
||||
$currency = $repos->findByCode($currencyCode);
|
||||
@@ -463,8 +463,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
foreach ($budgets as $budget) {
|
||||
\DB::table('budget_transaction')->where('budget_id', $budget->id)->delete();
|
||||
\DB::table('budget_transaction_journal')->where('budget_id', $budget->id)->delete();
|
||||
RecurrenceTransactionMeta::where('name', 'budget_id')->where('value', (string)$budget->id)->delete();
|
||||
RuleAction::where('action_type', 'set_budget')->where('action_value', (string)$budget->id)->delete();
|
||||
RecurrenceTransactionMeta::where('name', 'budget_id')->where('value', (string) $budget->id)->delete();
|
||||
RuleAction::where('action_type', 'set_budget')->where('action_value', (string) $budget->id)->delete();
|
||||
$budget->delete();
|
||||
}
|
||||
Log::channel('audit')->info('Delete all budgets through destroyAll');
|
||||
@@ -489,7 +489,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
app('log')->debug('Now in findBudget()');
|
||||
app('log')->debug(sprintf('Searching for budget with ID #%d...', $budgetId));
|
||||
$result = $this->find((int)$budgetId);
|
||||
$result = $this->find((int) $budgetId);
|
||||
if (null === $result && null !== $budgetName && '' !== $budgetName) {
|
||||
app('log')->debug(sprintf('Searching for budget with name %s...', $budgetName));
|
||||
$result = $this->findByName($budgetName);
|
||||
@@ -625,9 +625,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'id' => (string)$currencyId,
|
||||
'id' => (string) $currencyId,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'code' => $journal['currency_code'],
|
||||
@@ -637,10 +637,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$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] ??= [
|
||||
'id' => (string)$foreignId,
|
||||
'id' => (string) $foreignId,
|
||||
'name' => $journal['foreign_currency_name'],
|
||||
'symbol' => $journal['foreign_currency_symbol'],
|
||||
'code' => $journal['foreign_currency_code'],
|
||||
@@ -687,9 +687,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'id' => (string)$currencyId,
|
||||
'id' => (string) $currencyId,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'code' => $journal['currency_code'],
|
||||
@@ -699,10 +699,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$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] ??= [
|
||||
'id' => (string)$foreignId,
|
||||
'id' => (string) $foreignId,
|
||||
'name' => $journal['foreign_currency_name'],
|
||||
'symbol' => $journal['foreign_currency_symbol'],
|
||||
'code' => $journal['foreign_currency_code'],
|
||||
@@ -744,7 +744,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
// set notes
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->setNoteText($newBudget, (string)$data['notes']);
|
||||
$this->setNoteText($newBudget, (string) $data['notes']);
|
||||
}
|
||||
|
||||
if (!array_key_exists('auto_budget_type', $data) || !array_key_exists('auto_budget_amount', $data) || !array_key_exists('auto_budget_period', $data)) {
|
||||
@@ -772,10 +772,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = null;
|
||||
if (array_key_exists('currency_id', $data)) {
|
||||
$currency = $repos->find((int)$data['currency_id']);
|
||||
$currency = $repos->find((int) $data['currency_id']);
|
||||
}
|
||||
if (array_key_exists('currency_code', $data)) {
|
||||
$currency = $repos->findByCode((string)$data['currency_code']);
|
||||
$currency = $repos->findByCode((string) $data['currency_code']);
|
||||
}
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
@@ -811,6 +811,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
public function getMaxOrder(): int
|
||||
{
|
||||
return (int)$this->user->budgets()->max('order');
|
||||
return (int) $this->user->budgets()->max('order');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user