mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-22 20:16:22 +00:00 
			
		
		
		
	Code cleanup according to PHPStorm.
This commit is contained in:
		| @@ -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; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user