mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 18:40:12 +00:00
Code cleanup.
This commit is contained in:
@@ -33,13 +33,13 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class DoubleReportController
|
||||
*/
|
||||
class DoubleReportController extends Controller
|
||||
{
|
||||
/** @var GeneratorInterface Chart generation methods. */
|
||||
private $generator;
|
||||
|
||||
/** @var OperationsRepositoryInterface */
|
||||
private $opsRepository;
|
||||
|
||||
@@ -48,8 +48,6 @@ class DoubleReportController extends Controller
|
||||
|
||||
/**
|
||||
* CategoryReportController constructor.
|
||||
*
|
||||
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -65,14 +63,6 @@ class DoubleReportController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $others
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function budgetExpense(Collection $accounts, Collection $others, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
@@ -100,14 +90,6 @@ class DoubleReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $others
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function categoryExpense(Collection $accounts, Collection $others, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
@@ -135,14 +117,6 @@ class DoubleReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $others
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function categoryIncome(Collection $accounts, Collection $others, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
@@ -170,15 +144,6 @@ class DoubleReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
*/
|
||||
public function mainChart(Collection $accounts, Account $account, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$chartData = [];
|
||||
@@ -247,64 +212,6 @@ class DoubleReportController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param null|string $iban
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCounterpartName(Collection $accounts, int $id, string $name, ?string $iban): string
|
||||
{
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->name === $name && $account->id !== $id) {
|
||||
return $account->name;
|
||||
}
|
||||
if (null !== $account->iban && $account->iban === $iban && $account->id !== $id) {
|
||||
return $account->iban;
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function makeEntries(Carbon $start, Carbon $end): array
|
||||
{
|
||||
$return = [];
|
||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
|
||||
$currentStart = clone $start;
|
||||
while ($currentStart <= $end) {
|
||||
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
|
||||
$key = $currentStart->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $others
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function tagExpense(Collection $accounts, Collection $others, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
@@ -331,6 +238,60 @@ class DoubleReportController extends Controller
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
|
||||
}
|
||||
|
||||
// loop each tag:
|
||||
/** @var array $tag */
|
||||
foreach ($journal['tags'] as $tag) {
|
||||
if (in_array($journalId, $includedJournals, true)) {
|
||||
continue;
|
||||
}
|
||||
$includedJournals[] = $journalId;
|
||||
// do something
|
||||
$tagName = $tag['name'];
|
||||
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
];
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function tagIncome(Collection $accounts, Collection $others, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$result = [];
|
||||
$joined = $this->repository->expandWithDoubles($others);
|
||||
$accounts = $accounts->merge($joined);
|
||||
$income = $this->opsRepository->listIncome($start, $end, $accounts);
|
||||
$includedJournals = [];
|
||||
// loop income.
|
||||
foreach ($income as $currency) {
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$journalId = $journal['transaction_journal_id'];
|
||||
|
||||
// no tags? also deserves a sport
|
||||
if (0 === count($journal['tags'])) {
|
||||
$includedJournals[] = $journalId;
|
||||
// do something
|
||||
$tagName = trans('firefly.no_tags');
|
||||
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
];
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
|
||||
}
|
||||
|
||||
// loop each tag:
|
||||
/** @var array $tag */
|
||||
foreach ($journal['tags'] as $tag) {
|
||||
@@ -358,62 +319,40 @@ class DoubleReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $others
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
* TODO duplicate function
|
||||
*/
|
||||
public function tagIncome(Collection $accounts, Collection $others, Carbon $start, Carbon $end): JsonResponse
|
||||
private function getCounterpartName(Collection $accounts, int $id, string $name, ?string $iban): string
|
||||
{
|
||||
$result = [];
|
||||
$joined = $this->repository->expandWithDoubles($others);
|
||||
$accounts = $accounts->merge($joined);
|
||||
$income = $this->opsRepository->listIncome($start, $end, $accounts);
|
||||
$includedJournals = [];
|
||||
// loop income.
|
||||
foreach ($income as $currency) {
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$journalId = $journal['transaction_journal_id'];
|
||||
|
||||
// no tags? also deserves a sport
|
||||
if (0 === count($journal['tags'])) {
|
||||
$includedJournals[] = $journalId;
|
||||
// do something
|
||||
$tagName = trans('firefly.no_tags');
|
||||
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
];
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
|
||||
}
|
||||
// loop each tag:
|
||||
/** @var array $tag */
|
||||
foreach ($journal['tags'] as $tag) {
|
||||
if (in_array($journalId, $includedJournals, true)) {
|
||||
continue;
|
||||
}
|
||||
$includedJournals[] = $journalId;
|
||||
// do something
|
||||
$tagName = $tag['name'];
|
||||
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
];
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
|
||||
}
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->name === $name && $account->id !== $id) {
|
||||
return $account->name;
|
||||
}
|
||||
if (null !== $account->iban && $account->iban === $iban && $account->id !== $id) {
|
||||
return $account->iban;
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
return $name;
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
/**
|
||||
* TODO duplicate function
|
||||
*/
|
||||
private function makeEntries(Carbon $start, Carbon $end): array
|
||||
{
|
||||
$return = [];
|
||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
|
||||
$currentStart = clone $start;
|
||||
while ($currentStart <= $end) {
|
||||
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
|
||||
$key = $currentStart->isoFormat($format);
|
||||
$return[$key] = '0';
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user