mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code cleanup according to PHPStorm.
This commit is contained in:
parent
294df4a2b3
commit
3888b8cceb
@ -49,19 +49,12 @@ class ChartJsBillChartGenerator implements BillChartGenerator
|
||||
*/
|
||||
public function single(Bill $bill, Collection $entries)
|
||||
{
|
||||
// language:
|
||||
$format = trans('config.month');
|
||||
|
||||
$data = [
|
||||
$format = trans('config.month');
|
||||
$data = [
|
||||
'count' => 3,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
// dataset: max amount
|
||||
// dataset: min amount
|
||||
// dataset: actual amount
|
||||
|
||||
$minAmount = [];
|
||||
$maxAmount = [];
|
||||
$actualAmount = [];
|
||||
|
@ -68,24 +68,24 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
*/
|
||||
public function frontpage(Collection $entries)
|
||||
{
|
||||
$data = [
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
// dataset: left
|
||||
// dataset: spent
|
||||
// dataset: overspent
|
||||
$left = [];
|
||||
$spent = [];
|
||||
$overspent = [];
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0) {
|
||||
$data['labels'][] = $entry[0];
|
||||
$left[] = round($entry[1], 2);
|
||||
$spent[] = round($entry[2] * -1, 2); // spent is coming in negative, must be positive
|
||||
$overspent[] = round($entry[3] * -1, 2); // same
|
||||
$filtered = $entries->filter(
|
||||
function ($entry) {
|
||||
return ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0);
|
||||
}
|
||||
);
|
||||
foreach ($filtered as $entry) {
|
||||
$data['labels'][] = $entry[0];
|
||||
$left[] = round($entry[1], 2);
|
||||
$spent[] = round($entry[2] * -1, 2); // spent is coming in negative, must be positive
|
||||
$overspent[] = round($entry[3] * -1, 2); // same
|
||||
}
|
||||
|
||||
$data['datasets'][] = [
|
||||
|
@ -154,29 +154,20 @@ class AccountController extends Controller
|
||||
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
||||
$types = Config::get('firefly.accountTypesByIdentifier.' . $what);
|
||||
$accounts = $repository->getAccounts($types);
|
||||
// last activity:
|
||||
/**
|
||||
* HERE WE ARE
|
||||
*/
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
||||
$start->subDay();
|
||||
|
||||
// start balances:
|
||||
$ids = [];
|
||||
foreach ($accounts as $account) {
|
||||
$ids[] = $account->id;
|
||||
}
|
||||
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$startBalances = Steam::balancesById($ids, $start);
|
||||
$endBalances = Steam::balancesById($ids, $end);
|
||||
$activities = Steam::getLastActivities($ids);
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($activities, $startBalances, $endBalances) {
|
||||
$account->lastActivityDate = isset($activities[$account->id]) ? $activities[$account->id] : null;
|
||||
$account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null;
|
||||
$account->endBalance = isset($endBalances[$account->id]) ? $endBalances[$account->id] : null;
|
||||
$account->lastActivityDate = $this->isInArray($activities, $account->id);
|
||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||
}
|
||||
);
|
||||
|
||||
@ -283,4 +274,20 @@ class AccountController extends Controller
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param $entryId
|
||||
*
|
||||
* @return null|mixed
|
||||
*/
|
||||
protected function isInArray(array $array, $entryId)
|
||||
{
|
||||
if (isset($array[$entryId])) {
|
||||
return $array[$entryId];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,38 +61,16 @@ class ReportController extends Controller
|
||||
$spentArray = $query->spentPerMonth($accounts, $start, $end);
|
||||
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
||||
|
||||
// per year? put all months together.
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
|
||||
$incomeSum = $this->pluckFromArray($start->year, $earnedArray);
|
||||
$expenseSum = $this->pluckFromArray($start->year, $spentArray) * -1;
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOut($entries);
|
||||
$cache->store($data);
|
||||
// data = method X
|
||||
$data = $this->multiYearInOut($earnedArray, $spentArray, $start, $end);
|
||||
} else {
|
||||
// per month? simply use each month.
|
||||
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
// total income and total expenses:
|
||||
$date = $start->format('Y-m');
|
||||
$incomeSum = isset($earnedArray[$date]) ? $earnedArray[$date] : 0;
|
||||
$expenseSum = isset($spentArray[$date]) ? ($spentArray[$date] * -1) : 0;
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOut($entries);
|
||||
$cache->store($data);
|
||||
// data = method Y
|
||||
$data = $this->singleYearInOut($earnedArray, $spentArray, $start, $end);
|
||||
}
|
||||
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
@ -125,47 +103,127 @@ class ReportController extends Controller
|
||||
// grouped by month
|
||||
$spentArray = $query->spentPerMonth($accounts, $start, $end);
|
||||
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
||||
$income = '0';
|
||||
$expense = '0';
|
||||
$count = 0;
|
||||
|
||||
bcscale(2);
|
||||
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
// per year
|
||||
while ($start < $end) {
|
||||
|
||||
$currentIncome = $this->pluckFromArray($start->year, $earnedArray);
|
||||
$currentExpense = $this->pluckFromArray($start->year, $spentArray) * -1;
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOutSummarized($income, $expense, $count);
|
||||
$cache->store($data);
|
||||
$data = $this->multiYearInOutSummarized($earnedArray, $spentArray, $start, $end);
|
||||
} else {
|
||||
// per month!
|
||||
while ($start < $end) {
|
||||
$date = $start->format('Y-m');
|
||||
$currentIncome = isset($earnedArray[$date]) ? $earnedArray[$date] : 0;
|
||||
$currentExpense = isset($spentArray[$date]) ? ($spentArray[$date] * -1) : 0;
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOutSummarized($income, $expense, $count);
|
||||
$cache->store($data);
|
||||
$data = $this->singleYearInOutSummarized($earnedArray, $spentArray, $start, $end);
|
||||
}
|
||||
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function singleYearInOutSummarized(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$income = '0';
|
||||
$expense = '0';
|
||||
$count = 0;
|
||||
while ($start < $end) {
|
||||
$date = $start->format('Y-m');
|
||||
$currentIncome = isset($earned[$date]) ? $earned[$date] : 0;
|
||||
$currentExpense = isset($spent[$date]) ? ($spent[$date] * -1) : 0;
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOutSummarized($income, $expense, $count);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function multiYearInOutSummarized(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$income = '0';
|
||||
$expense = '0';
|
||||
$count = 0;
|
||||
while ($start < $end) {
|
||||
|
||||
$currentIncome = $this->pluckFromArray($start->year, $earned);
|
||||
$currentExpense = $this->pluckFromArray($start->year, $spent) * -1;
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOutSummarized($income, $expense, $count);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function multiYearInOut(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
|
||||
$incomeSum = $this->pluckFromArray($start->year, $earned);
|
||||
$expenseSum = $this->pluckFromArray($start->year, $spent) * -1;
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOut($entries);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function singleYearInOut(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
// per month? simply use each month.
|
||||
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
// total income and total expenses:
|
||||
$date = $start->format('Y-m');
|
||||
$incomeSum = isset($earned[$date]) ? $earned[$date] : 0;
|
||||
$expenseSum = isset($spent[$date]) ? ($spent[$date] * -1) : 0;
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOut($entries);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return mixed
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccounts(array $types);
|
||||
|
||||
|
@ -127,7 +127,7 @@ class Steam
|
||||
* @param array $ids
|
||||
* @param \Carbon\Carbon $date
|
||||
*
|
||||
* @return float
|
||||
* @return array
|
||||
*/
|
||||
public function balancesById(array $ids, Carbon $date)
|
||||
{
|
||||
|
@ -43,8 +43,8 @@ class FireflyValidator extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateBelongsToUser($attribute, $value, $parameters
|
||||
) {
|
||||
public function validateBelongsToUser($attribute, $value, $parameters)
|
||||
{
|
||||
|
||||
$count = DB::table($parameters[0])->where('user_id', Auth::user()->id)->where('id', $value)->count();
|
||||
if ($count == 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user