mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Fixed all problems related to strict types.
This commit is contained in:
		| @@ -58,7 +58,7 @@ class Data | ||||
|      */ | ||||
|     public function getCsvFileContent() | ||||
|     { | ||||
|         return $this->csvFileContent; | ||||
|         return $this->csvFileContent ?? ''; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -171,7 +171,7 @@ class Data | ||||
|      */ | ||||
|     public function getReader() | ||||
|     { | ||||
|         if (strlen($this->csvFileContent) === 0) { | ||||
|         if (!is_null($this->csvFileContent) && strlen($this->csvFileContent) === 0) { | ||||
|             $this->loadCsvFile(); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -108,7 +108,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface | ||||
|                     return $model->account_id == $account->id && $model->budget_id == $budget->id; | ||||
|                 } | ||||
|             ); | ||||
|             $spent = 0; | ||||
|             $spent = '0'; | ||||
|             if (!is_null($entry->first())) { | ||||
|                 $spent = $entry->first()->spent; | ||||
|             } | ||||
|   | ||||
| @@ -132,7 +132,7 @@ class BudgetController extends Controller | ||||
|             /* | ||||
|              * Sum of expenses on this day: | ||||
|              */ | ||||
|             $amount = round(bcadd($amount, $sum), 2); | ||||
|             $amount = round(bcadd(strval($amount), $sum), 2); | ||||
|             $entries->push([clone $start, $amount]); | ||||
|             $start->addDay(); | ||||
|         } | ||||
|   | ||||
| @@ -126,24 +126,19 @@ class ReportController extends Controller | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function singleYearInOutSummarized(array $earned, array $spent, Carbon $start, Carbon $end) | ||||
|     protected function multiYearInOut(array $earned, array $spent, Carbon $start, Carbon $end) | ||||
|     { | ||||
|         bcscale(2); | ||||
|         $income  = '0'; | ||||
|         $expense = '0'; | ||||
|         $count   = 0; | ||||
|         $entries = new Collection; | ||||
|         while ($start < $end) { | ||||
|             $date           = $start->format('Y-m'); | ||||
|             $currentIncome  = $earned[$date] ?? 0; | ||||
|             $currentExpense = isset($spent[$date]) ? ($spent[$date] * -1) : 0; | ||||
|             $income         = bcadd($income, $currentIncome); | ||||
|             $expense        = bcadd($expense, $currentExpense); | ||||
|  | ||||
|             $count++; | ||||
|             $start->addMonth(); | ||||
|             $incomeSum  = $this->pluckFromArray($start->year, $earned); | ||||
|             $expenseSum = $this->pluckFromArray($start->year, $spent) * -1; | ||||
|  | ||||
|             $entries->push([clone $start, $incomeSum, $expenseSum]); | ||||
|             $start->addYear(); | ||||
|         } | ||||
|  | ||||
|         $data = $this->generator->yearInOutSummarized($income, $expense, $count); | ||||
|         $data = $this->generator->multiYearInOut($entries); | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
| @@ -179,28 +174,23 @@ class ReportController extends Controller | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array  $earned | ||||
|      * @param array  $spent | ||||
|      * @param Carbon $start | ||||
|      * @param Carbon $end | ||||
|      * @param int   $year | ||||
|      * @param array $set | ||||
|      * | ||||
|      * @return array | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function multiYearInOut(array $earned, array $spent, Carbon $start, Carbon $end) | ||||
|     protected function pluckFromArray($year, array $set) | ||||
|     { | ||||
|         $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(); | ||||
|         bcscale(2); | ||||
|         $sum = '0'; | ||||
|         foreach ($set as $date => $amount) { | ||||
|             if (substr($date, 0, 4) == $year) { | ||||
|                 $sum = bcadd($sum, $amount); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $data = $this->generator->multiYearInOut($entries); | ||||
|         return $sum; | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -232,22 +222,32 @@ class ReportController extends Controller | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param int   $year | ||||
|      * @param array $set | ||||
|      * @param array  $earned | ||||
|      * @param array  $spent | ||||
|      * @param Carbon $start | ||||
|      * @param Carbon $end | ||||
|      * | ||||
|      * @return string | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function pluckFromArray($year, array $set) | ||||
|     protected function singleYearInOutSummarized(array $earned, array $spent, Carbon $start, Carbon $end) | ||||
|     { | ||||
|         bcscale(2); | ||||
|         $sum = '0'; | ||||
|         foreach ($set as $date => $amount) { | ||||
|             if (substr($date, 0, 4) == $year) { | ||||
|                 $sum = bcadd($sum, $amount); | ||||
|             } | ||||
|         $income  = '0'; | ||||
|         $expense = '0'; | ||||
|         $count   = 0; | ||||
|         while ($start < $end) { | ||||
|             $date           = $start->format('Y-m'); | ||||
|             $currentIncome  = $earned[$date] ?? '0'; | ||||
|             $currentExpense = isset($spent[$date]) ? bcmul($spent[$date], '-1') : '0'; | ||||
|             $income         = bcadd($income, $currentIncome); | ||||
|             $expense        = bcadd($expense, $currentExpense); | ||||
|  | ||||
|             $count++; | ||||
|             $start->addMonth(); | ||||
|         } | ||||
|  | ||||
|         return $sum; | ||||
|         $data = $this->generator->yearInOutSummarized($income, $expense, $count); | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -242,10 +242,11 @@ class TagController extends Controller | ||||
|             $longitude = null; | ||||
|             $zoomLevel = null; | ||||
|         } | ||||
|         $date = $request->get('date') ?? ''; | ||||
|  | ||||
|         $data = [ | ||||
|             'tag'         => $request->get('tag'), | ||||
|             'date'        => strlen($request->get('date')) > 0 ? new Carbon($request->get('date')) : null, | ||||
|             'date'        => strlen($date) > 0 ? new Carbon($date) : null, | ||||
|             'description' => strlen($request->get('description')) > 0 ? $request->get('description') : '', | ||||
|             'latitude'    => $latitude, | ||||
|             'longitude'   => $longitude, | ||||
| @@ -287,10 +288,12 @@ class TagController extends Controller | ||||
|             $longitude = null; | ||||
|             $zoomLevel = null; | ||||
|         } | ||||
|         $date = $request->get('date') ?? ''; | ||||
|  | ||||
|  | ||||
|         $data = [ | ||||
|             'tag'         => $request->get('tag'), | ||||
|             'date'        => strlen($request->get('date')) > 0 ? new Carbon($request->get('date')) : null, | ||||
|             'date'        => strlen($date) > 0 ? new Carbon($date) : null, | ||||
|             'description' => strlen($request->get('description')) > 0 ? $request->get('description') : '', | ||||
|             'latitude'    => $latitude, | ||||
|             'longitude'   => $longitude, | ||||
|   | ||||
| @@ -31,6 +31,7 @@ class JournalFormRequest extends Request | ||||
|      */ | ||||
|     public function getJournalData() | ||||
|     { | ||||
|         $tags = $this->get('tags') ?? ''; | ||||
|         return [ | ||||
|             'what'                      => $this->get('what'), | ||||
|             'description'               => $this->get('description'), | ||||
| @@ -45,7 +46,7 @@ class JournalFormRequest extends Request | ||||
|             'date'                      => new Carbon($this->get('date')), | ||||
|             'budget_id'                 => intval($this->get('budget_id')), | ||||
|             'category'                  => $this->get('category'), | ||||
|             'tags'                      => explode(',', $this->get('tags')), | ||||
|             'tags'                      => explode(',', $tags), | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -253,10 +253,10 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|             function (Account $account) use ($start, $end) { | ||||
|                 $account->startBalance = Steam::balance($account, $start, true); | ||||
|                 $account->endBalance   = Steam::balance($account, $end, true); | ||||
|                 $account->piggyBalance = 0; | ||||
|                 $account->piggyBalance = '0'; | ||||
|                 /** @var PiggyBank $piggyBank */ | ||||
|                 foreach ($account->piggyBanks as $piggyBank) { | ||||
|                     $account->piggyBalance += $piggyBank->currentRelevantRep()->currentamount; | ||||
|                     $account->piggyBalance = bcadd($piggyBank->currentRelevantRep()->currentamount, $account->piggyBalance); | ||||
|                 } | ||||
|                 // sum of piggy bank amounts on this account: | ||||
|                 // diff between endBalance and piggyBalance. | ||||
|   | ||||
| @@ -162,16 +162,17 @@ class BillRepository implements BillRepositoryInterface | ||||
|             $ranges = $this->getRanges($bill, $start, $end); | ||||
|  | ||||
|             foreach ($ranges as $range) { | ||||
|                 $paid   = $bill->transactionjournals() | ||||
|                                ->before($range['end']) | ||||
|                                ->after($range['start']) | ||||
|                                ->leftJoin( | ||||
|                                    'transactions', function (JoinClause $join) { | ||||
|                                    $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0); | ||||
|                                } | ||||
|                                ) | ||||
|                                ->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]); | ||||
|                 $amount = bcadd($amount, $paid->sum_amount); | ||||
|                 $paid      = $bill->transactionjournals() | ||||
|                                   ->before($range['end']) | ||||
|                                   ->after($range['start']) | ||||
|                                   ->leftJoin( | ||||
|                                       'transactions', function (JoinClause $join) { | ||||
|                                       $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0); | ||||
|                                   } | ||||
|                                   ) | ||||
|                                   ->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]); | ||||
|                 $sumAmount = $paid->sum_amount ?? '0'; | ||||
|                 $amount    = bcadd($amount, $sumAmount); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -196,16 +197,17 @@ class BillRepository implements BillRepositoryInterface | ||||
|             $ranges   = $this->getRanges($bill, $start, $end); | ||||
|             $paidBill = '0'; | ||||
|             foreach ($ranges as $range) { | ||||
|                 $paid     = $bill->transactionjournals() | ||||
|                                  ->before($range['end']) | ||||
|                                  ->after($range['start']) | ||||
|                                  ->leftJoin( | ||||
|                                      'transactions', function (JoinClause $join) { | ||||
|                                      $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0); | ||||
|                                  } | ||||
|                                  ) | ||||
|                                  ->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]); | ||||
|                 $paidBill = bcadd($paid->sum_amount, $paidBill); | ||||
|                 $paid      = $bill->transactionjournals() | ||||
|                                   ->before($range['end']) | ||||
|                                   ->after($range['start']) | ||||
|                                   ->leftJoin( | ||||
|                                       'transactions', function (JoinClause $join) { | ||||
|                                       $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0); | ||||
|                                   } | ||||
|                                   ) | ||||
|                                   ->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]); | ||||
|                 $sumAmount = $paid->sum_amount ?? '0'; | ||||
|                 $paidBill  = bcadd($sumAmount, $paidBill); | ||||
|             } | ||||
|             if ($paidBill == 0) { | ||||
|                 $amount = bcadd($amount, $bill->expectedAmount); | ||||
|   | ||||
| @@ -37,7 +37,7 @@ class ComponentRepository | ||||
|                          ->whereIn('accounts.id', $ids) | ||||
|                          ->after($start) | ||||
|                          ->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]); | ||||
|         $amount = $entry->journalAmount; | ||||
|         $amount = $entry->journalAmount ?? '0'; | ||||
|  | ||||
|         return $amount; | ||||
|     } | ||||
|   | ||||
| @@ -23,7 +23,7 @@ class Steam | ||||
|      * @param \Carbon\Carbon             $date | ||||
|      * @param bool                       $ignoreVirtualBalance | ||||
|      * | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function balance(Account $account, Carbon $date, $ignoreVirtualBalance = false) | ||||
|     { | ||||
| @@ -45,11 +45,11 @@ class Steam | ||||
|         )->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount'); | ||||
|  | ||||
|         if (!$ignoreVirtualBalance) { | ||||
|             $balance = bcadd($balance, $account->virtual_balance); | ||||
|             $balance = bcadd(strval($balance), $account->virtual_balance); | ||||
|         } | ||||
|         $cache->store(round($balance, 2)); | ||||
|         $cache->store($balance); | ||||
|  | ||||
|         return round($balance, 2); | ||||
|         return $balance; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -177,14 +177,14 @@ class Steam | ||||
|  | ||||
|         if (!(strpos($string, 'k') === false)) { | ||||
|             // has a K in it, remove the K and multiply by 1024. | ||||
|             $bytes = bcmul(rtrim($string, 'k'), 1024); | ||||
|             $bytes = bcmul(rtrim($string, 'k'), '1024'); | ||||
|  | ||||
|             return intval($bytes); | ||||
|         } | ||||
|  | ||||
|         if (!(strpos($string, 'm') === false)) { | ||||
|             // has a M in it, remove the M and multiply by 1048576. | ||||
|             $bytes = bcmul(rtrim($string, 'm'), 1048576); | ||||
|             $bytes = bcmul(rtrim($string, 'm'),'1048576'); | ||||
|  | ||||
|             return intval($bytes); | ||||
|         } | ||||
|   | ||||
| @@ -16,6 +16,7 @@ use Twig_SimpleFunction; | ||||
|  * @codeCoverageIgnore | ||||
|  * | ||||
|  * Class TwigSupport | ||||
|  * @todo    these functions should be parameterized. | ||||
|  * | ||||
|  * @package FireflyIII\Support | ||||
|  */ | ||||
| @@ -164,13 +165,14 @@ class General extends Twig_Extension | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @return Twig_SimpleFilter | ||||
|      */ | ||||
|     protected function formatAmount() | ||||
|     { | ||||
|         return new Twig_SimpleFilter( | ||||
|             'formatAmount', function ($string) { | ||||
|             $value = is_null($string) ? '0' : $string; | ||||
|             $value = is_null($string) ? '0' : strval($string); | ||||
|  | ||||
|             return app('amount')->format($value); | ||||
|         }, ['is_safe' => ['html']] | ||||
| @@ -184,7 +186,9 @@ class General extends Twig_Extension | ||||
|     { | ||||
|         return new Twig_SimpleFilter( | ||||
|             'formatAmountPlain', function ($string) { | ||||
|             return app('amount')->format($string, false); | ||||
|             $value = is_null($string) ? '0' : strval($string); | ||||
|  | ||||
|             return app('amount')->format($value, false); | ||||
|         }, ['is_safe' => ['html']] | ||||
|         ); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user