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)
|
public function single(Bill $bill, Collection $entries)
|
||||||
{
|
{
|
||||||
// language:
|
$format = trans('config.month');
|
||||||
$format = trans('config.month');
|
$data = [
|
||||||
|
|
||||||
$data = [
|
|
||||||
'count' => 3,
|
'count' => 3,
|
||||||
'labels' => [],
|
'labels' => [],
|
||||||
'datasets' => [],
|
'datasets' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
// dataset: max amount
|
|
||||||
// dataset: min amount
|
|
||||||
// dataset: actual amount
|
|
||||||
|
|
||||||
$minAmount = [];
|
$minAmount = [];
|
||||||
$maxAmount = [];
|
$maxAmount = [];
|
||||||
$actualAmount = [];
|
$actualAmount = [];
|
||||||
|
@ -68,24 +68,24 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
|||||||
*/
|
*/
|
||||||
public function frontpage(Collection $entries)
|
public function frontpage(Collection $entries)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'labels' => [],
|
'labels' => [],
|
||||||
'datasets' => [],
|
'datasets' => [],
|
||||||
];
|
];
|
||||||
// dataset: left
|
|
||||||
// dataset: spent
|
|
||||||
// dataset: overspent
|
|
||||||
$left = [];
|
$left = [];
|
||||||
$spent = [];
|
$spent = [];
|
||||||
$overspent = [];
|
$overspent = [];
|
||||||
foreach ($entries as $entry) {
|
$filtered = $entries->filter(
|
||||||
if ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0) {
|
function ($entry) {
|
||||||
$data['labels'][] = $entry[0];
|
return ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 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
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
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'][] = [
|
$data['datasets'][] = [
|
||||||
|
@ -154,29 +154,20 @@ class AccountController extends Controller
|
|||||||
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
||||||
$types = Config::get('firefly.accountTypesByIdentifier.' . $what);
|
$types = Config::get('firefly.accountTypesByIdentifier.' . $what);
|
||||||
$accounts = $repository->getAccounts($types);
|
$accounts = $repository->getAccounts($types);
|
||||||
// last activity:
|
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||||
/**
|
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
||||||
* HERE WE ARE
|
|
||||||
*/
|
|
||||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
|
||||||
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
// start balances:
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
$ids = [];
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$ids[] = $account->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$startBalances = Steam::balancesById($ids, $start);
|
$startBalances = Steam::balancesById($ids, $start);
|
||||||
$endBalances = Steam::balancesById($ids, $end);
|
$endBalances = Steam::balancesById($ids, $end);
|
||||||
$activities = Steam::getLastActivities($ids);
|
$activities = Steam::getLastActivities($ids);
|
||||||
|
|
||||||
$accounts->each(
|
$accounts->each(
|
||||||
function (Account $account) use ($activities, $startBalances, $endBalances) {
|
function (Account $account) use ($activities, $startBalances, $endBalances) {
|
||||||
$account->lastActivityDate = isset($activities[$account->id]) ? $activities[$account->id] : null;
|
$account->lastActivityDate = $this->isInArray($activities, $account->id);
|
||||||
$account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null;
|
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||||
$account->endBalance = isset($endBalances[$account->id]) ? $endBalances[$account->id] : null;
|
$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);
|
$spentArray = $query->spentPerMonth($accounts, $start, $end);
|
||||||
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
||||||
|
|
||||||
// per year? put all months together.
|
|
||||||
if ($start->diffInMonths($end) > 12) {
|
if ($start->diffInMonths($end) > 12) {
|
||||||
$entries = new Collection;
|
// data = method X
|
||||||
while ($start < $end) {
|
$data = $this->multiYearInOut($earnedArray, $spentArray, $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);
|
|
||||||
} else {
|
} else {
|
||||||
// per month? simply use each month.
|
// data = method Y
|
||||||
|
$data = $this->singleYearInOut($earnedArray, $spentArray, $start, $end);
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -125,47 +103,127 @@ class ReportController extends Controller
|
|||||||
// grouped by month
|
// grouped by month
|
||||||
$spentArray = $query->spentPerMonth($accounts, $start, $end);
|
$spentArray = $query->spentPerMonth($accounts, $start, $end);
|
||||||
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
||||||
$income = '0';
|
|
||||||
$expense = '0';
|
|
||||||
$count = 0;
|
|
||||||
|
|
||||||
bcscale(2);
|
|
||||||
|
|
||||||
if ($start->diffInMonths($end) > 12) {
|
if ($start->diffInMonths($end) > 12) {
|
||||||
// per year
|
// per year
|
||||||
while ($start < $end) {
|
$data = $this->multiYearInOutSummarized($earnedArray, $spentArray, $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);
|
|
||||||
} else {
|
} else {
|
||||||
// per month!
|
// per month!
|
||||||
while ($start < $end) {
|
$data = $this->singleYearInOutSummarized($earnedArray, $spentArray, $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);
|
|
||||||
}
|
}
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($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
|
* @param array $types
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getAccounts(array $types);
|
public function getAccounts(array $types);
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ class Steam
|
|||||||
* @param array $ids
|
* @param array $ids
|
||||||
* @param \Carbon\Carbon $date
|
* @param \Carbon\Carbon $date
|
||||||
*
|
*
|
||||||
* @return float
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function balancesById(array $ids, Carbon $date)
|
public function balancesById(array $ids, Carbon $date)
|
||||||
{
|
{
|
||||||
|
@ -43,8 +43,8 @@ class FireflyValidator extends Validator
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @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();
|
$count = DB::table($parameters[0])->where('user_id', Auth::user()->id)->where('id', $value)->count();
|
||||||
if ($count == 1) {
|
if ($count == 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user