mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 12:11:19 +00:00
Various code reshuffelling.
This commit is contained in:
@@ -25,12 +25,9 @@ namespace FireflyIII\Repositories\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
@@ -59,15 +56,15 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
foreach ($budget->budgetlimits as $limit) {
|
||||
$diff = $limit->start_date->diffInDays($limit->end_date);
|
||||
$diff = 0 === $diff ? 1 : $diff;
|
||||
$amount = (string) $limit->amount;
|
||||
$perDay = bcdiv($amount, (string) $diff);
|
||||
$amount = (string)$limit->amount;
|
||||
$perDay = bcdiv($amount, (string)$diff);
|
||||
$total = bcadd($total, $perDay);
|
||||
$count++;
|
||||
Log::debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total));
|
||||
}
|
||||
$avg = $total;
|
||||
if ($count > 0) {
|
||||
$avg = bcdiv($total, (string) $count);
|
||||
$avg = bcdiv($total, (string)$count);
|
||||
}
|
||||
Log::debug(sprintf('%s / %d = %s = average.', $total, $count, $avg));
|
||||
|
||||
@@ -103,9 +100,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
// prep data array for currency:
|
||||
$budgetId = (int) $journal['budget_id'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = $journal['budget_name'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$key = sprintf('%d-%d', $budgetId, $currencyId);
|
||||
|
||||
$data[$key] = $data[$key] ?? [
|
||||
@@ -157,9 +154,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$budgetId = (int) $journal['budget_id'];
|
||||
$budgetName = (string) $journal['budget_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = (string)$journal['budget_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $budgetId) {
|
||||
@@ -185,7 +182,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
// add journal to array:
|
||||
// only a subset of the fields.
|
||||
$journalId = (int) $journal['transaction_journal_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
|
||||
|
||||
$array[$currencyId]['budgets'][$budgetId]['transaction_journals'][$journalId] = [
|
||||
@@ -269,7 +266,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
'currency_name' => $currency['name'],
|
||||
'currency_symbol' => $currency['symbol'],
|
||||
'currency_decimal_places' => $currency['decimal_places'],
|
||||
'amount' => number_format((float) $spent, $currency['decimal_places'], '.', ''),
|
||||
'amount' => number_format((float)$spent, $currency['decimal_places'], '.', ''),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -286,8 +283,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
* @return array
|
||||
*/
|
||||
public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null, ?TransactionCurrency $currency = null
|
||||
): array
|
||||
{
|
||||
): array {
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
$start->startOfDay();
|
||||
$end->endOfDay();
|
||||
@@ -326,7 +322,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] = $array[$currencyId] ?? [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
@@ -338,8 +334,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
if(0 !== $foreignId) {
|
||||
$foreignId = (int)$journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] = $array[$foreignId] ?? [
|
||||
'sum' => '0',
|
||||
'currency_id' => $foreignId,
|
||||
@@ -356,6 +352,17 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
private function getBudgets(): Collection
|
||||
{
|
||||
/** @var BudgetRepositoryInterface $repos */
|
||||
$repos = app(BudgetRepositoryInterface::class);
|
||||
|
||||
return $repos->getActiveBudgets();
|
||||
}
|
||||
|
||||
/**
|
||||
* For now, simply refer to whichever repository holds this function.
|
||||
* TODO might be done better in the future.
|
||||
@@ -373,15 +380,4 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
return $blRepository->getBudgetLimits($budget, $start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
private function getBudgets(): Collection
|
||||
{
|
||||
/** @var BudgetRepositoryInterface $repos */
|
||||
$repos = app(BudgetRepositoryInterface::class);
|
||||
|
||||
return $repos->getActiveBudgets();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user