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