mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Move method to correct repository.
This commit is contained in:
@@ -52,58 +52,6 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriodWoBudgetMc(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->withoutBudget();
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
$total = [];
|
||||
$currencies = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$code = $journal['currency_code'];
|
||||
if (!isset($currencies[$code])) {
|
||||
$currencies[$code] = [
|
||||
'id' => $journal['currency_id'],
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $journal['amount']) : $journal['amount'];
|
||||
}
|
||||
foreach ($total as $code => $spent) {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $currencies[$code];
|
||||
$return[] = [
|
||||
'currency_id' => $currency['id'],
|
||||
'currency_code' => $code,
|
||||
'currency_name' => $currency['name'],
|
||||
'currency_symbol' => $currency['symbol'],
|
||||
'currency_decimal_places' => $currency['decimal_places'],
|
||||
'amount' => $spent,
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
@@ -157,4 +105,56 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public function spentInPeriodWoBudgetMc(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->withoutBudget();
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
$total = [];
|
||||
$currencies = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$code = $journal['currency_code'];
|
||||
if (!isset($currencies[$code])) {
|
||||
$currencies[$code] = [
|
||||
'id' => $journal['currency_id'],
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $journal['amount']) : $journal['amount'];
|
||||
}
|
||||
foreach ($total as $code => $spent) {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $currencies[$code];
|
||||
$return[] = [
|
||||
'currency_id' => $currency['id'],
|
||||
'currency_code' => $code,
|
||||
'currency_name' => $currency['name'],
|
||||
'currency_symbol' => $currency['symbol'],
|
||||
'currency_decimal_places' => $currency['decimal_places'],
|
||||
'amount' => $spent,
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user