Fixed all problems related to strict types.

This commit is contained in:
James Cole 2016-02-05 13:09:18 +01:00
parent aa1193a9eb
commit df918e8529
18 changed files with 58 additions and 52 deletions

View File

@ -39,7 +39,7 @@ class ChartJsBillChartGenerator implements BillChartGeneratorInterface
'label' => trans('firefly.unpaid'),
],
[
'value' => round($paid * -1, 2), // paid is negative, must be positive.
'value' => round(bcmul($paid, '-1'), 2), // paid is negative, must be positive.
'color' => 'rgba(0, 141, 76, 0.7)',
'highlight' => 'rgba(0, 141, 76, 0.9)',
'label' => trans('firefly.paid'),
@ -57,6 +57,7 @@ class ChartJsBillChartGenerator implements BillChartGeneratorInterface
*/
public function single(Bill $bill, Collection $entries)
{
bcscale(2);
$format = (string)trans('config.month');
$data = [
'count' => 3,
@ -74,7 +75,7 @@ class ChartJsBillChartGenerator implements BillChartGeneratorInterface
/*
* journalAmount has been collected in BillRepository::getJournals
*/
$actualAmount[] = round(($entry->journalAmount * -1), 2);
$actualAmount[] = round(bcmul($entry->journalAmount, '-1'), 2);
}
$data['datasets'][] = [

View File

@ -68,6 +68,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
*/
public function frontpage(Collection $entries)
{
bcscale(2);
$data = [
'count' => 0,
'labels' => [],
@ -84,8 +85,8 @@ class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
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
$spent[] = round(bcmul($entry[2],'-1'), 2); // spent is coming in negative, must be positive
$overspent[] = round(bcmul($entry[3],'-1'), 2); // same
}
$data['datasets'][] = [

View File

@ -39,11 +39,11 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
foreach ($entries as $entry) {
$data['labels'][] = $entry[1];
$spent = round($entry[2], 2);
$earned = round($entry[3], 2);
$spent = $entry[2];
$earned = $entry[3];
$data['datasets'][0]['data'][] = $spent == 0 ? null : $spent * -1;
$data['datasets'][1]['data'][] = $earned == 0 ? null : $earned;
$data['datasets'][0]['data'][] = bccomp($spent, '0') === 0 ? null : bcmul($spent, '-1');
$data['datasets'][1]['data'][] = bccomp($earned, '0') === 0 ? null : $earned;
}
return $data;
@ -89,6 +89,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
*/
public function frontpage(Collection $entries)
{
bcscale(2);
$data = [
'count' => 1,
'labels' => [],
@ -102,7 +103,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
foreach ($entries as $entry) {
if ($entry->spent != 0) {
$data['labels'][] = $entry->name;
$data['datasets'][0]['data'][] = round(($entry->spent * -1), 2);
$data['datasets'][0]['data'][] = round(bcmul($entry->spent, '-1'), 2);
}
}

View File

@ -40,6 +40,7 @@ class ConnectJournalToPiggyBank
/** @var TransactionJournal $journal */
$journal = $event->journal;
$piggyBankId = $event->piggyBankId;
bcscale(2);
/** @var PiggyBank $piggyBank */
$piggyBank = Auth::user()->piggybanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
@ -57,7 +58,7 @@ class ConnectJournalToPiggyBank
$amount = $journal->amount_positive;
// if piggy account matches source account, the amount is positive
if ($piggyBank->account_id == $journal->source_account->id) {
$amount = $amount * -1;
$amount = bcmul($amount,'-1');
}

View File

@ -142,7 +142,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
return $model->account_id == $account->id && is_null($model->budget_id);
}
);
$spent = 0;
$spent = '0';
if (!is_null($entry->first())) {
$spent = $entry->first()->spent;
}
@ -151,7 +151,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
return $tag->account_id == $account->id;
}
);
$left = 0;
$left = '0';
if (!is_null($leftEntry->first())) {
$left = $leftEntry->first()->sum;
}
@ -185,7 +185,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
return $model->account_id == $account->id && is_null($model->budget_id);
}
);
$spent = 0;
$spent = '0';
if (!is_null($entry->first())) {
$spent = $entry->first()->spent;
}
@ -221,7 +221,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
return $tag->account_id == $account->id;
}
);
$left = 0;
$left = '0';
if (!is_null($leftEntry->first())) {
$left = $leftEntry->first()->sum;
}

View File

@ -285,7 +285,7 @@ class AccountController extends Controller
return $array[$entryId];
}
return null;
return '';
}
}

View File

@ -185,26 +185,26 @@ class BudgetController extends Controller
$currentStart = clone $start;
$currentEnd = clone $end;
$expenses = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
$amount = 0;
$left = 0;
$amount = '0';
$left = '0';
$spent = $expenses;
$overspent = 0;
$overspent = '0';
} else {
$currentStart = clone $budget->startdate;
$currentEnd = clone $budget->enddate;
$expenses = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
$amount = $budget->amount;
// smaller than 1 means spent MORE than budget allows.
$left = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? 0 : bcadd($budget->amount, $expenses);
$spent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? ($amount * -1) : $expenses;
$overspent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? bcadd($budget->amount, $expenses) : 0;
$left = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? '0' : bcadd($budget->amount, $expenses);
$spent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? bcmul($amount, '-1') : $expenses;
$overspent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? bcadd($budget->amount, $expenses) : '0';
}
$allEntries->push([$name, $left, $spent, $overspent, $amount, $expenses]);
}
$noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end);
$allEntries->push([trans('firefly.noBudget'), 0, 0, $noBudgetExpenses, 0, 0]);
$allEntries->push([trans('firefly.noBudget'), '0', '0', $noBudgetExpenses, '0', '0']);
$data = $this->generator->frontpage($allEntries);
$cache->store($data);

View File

@ -406,8 +406,8 @@ class CategoryController extends Controller
while ($start <= $end) {
$str = $start->format('Y-m-d');
$spent = $spentArray[$str] ?? 0;
$earned = $earnedArray[$str] ?? 0;
$spent = $spentArray[$str] ?? '0';
$earned = $earnedArray[$str] ?? '0';
$date = Navigation::periodShow($start, '1D');
$entries->push([clone $start, $date, $spent, $earned]);
$start->addDay();

View File

@ -66,7 +66,7 @@ class JsonController extends Controller
if ($creditCardDue >= 0) {
$amount = bcadd($amount, $creditCardDue);
}
$amount = $amount * -1;
$amount = bcmul($amount,'-1');
$data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];

View File

@ -166,6 +166,7 @@ class PiggyBankController extends Controller
{
/** @var Collection $piggyBanks */
$piggyBanks = $piggyRepository->getPiggyBanks();
/** @var Carbon $end */
$end = session('end', Carbon::now()->endOfMonth());
bcscale(2);

View File

@ -247,7 +247,7 @@ class TagController extends Controller
$data = [
'tag' => $request->get('tag'),
'date' => strlen($date) > 0 ? new Carbon($date) : null,
'description' => strlen($request->get('description')) > 0 ? $request->get('description') : '',
'description' => $request->get('description') ?? '',
'latitude' => $latitude,
'longitude' => $longitude,
'zoomLevel' => $zoomLevel,
@ -290,11 +290,10 @@ class TagController extends Controller
}
$date = $request->get('date') ?? '';
$data = [
'tag' => $request->get('tag'),
'date' => strlen($date) > 0 ? new Carbon($date) : null,
'description' => strlen($request->get('description')) > 0 ? $request->get('description') : '',
'description' => $request->get('description') ?? '',
'latitude' => $latitude,
'longitude' => $longitude,
'zoomLevel' => $zoomLevel,

View File

@ -38,14 +38,14 @@ class JournalFormRequest extends Request
'account_id' => intval($this->get('account_id')),
'account_from_id' => intval($this->get('account_from_id')),
'account_to_id' => intval($this->get('account_to_id')),
'expense_account' => $this->get('expense_account'),
'revenue_account' => $this->get('revenue_account'),
'expense_account' => $this->get('expense_account') ?? '',
'revenue_account' => $this->get('revenue_account') ?? '',
'amount' => round($this->get('amount'), 2),
'user' => Auth::user()->id,
'amount_currency_id_amount' => intval($this->get('amount_currency_id_amount')),
'date' => new Carbon($this->get('date')),
'budget_id' => intval($this->get('budget_id')),
'category' => $this->get('category'),
'category' => $this->get('category') ?? '',
'tags' => explode(',', $tags),
];
}

View File

@ -330,7 +330,7 @@ class AccountRepository implements AccountRepositoryInterface
$balance = Steam::balance($account, $date, true);
/** @var PiggyBank $p */
foreach ($account->piggybanks()->get() as $p) {
$balance -= $p->currentRelevantRep()->currentamount;
$balance = bcsub($p->currentRelevantRep()->currentamount, $balance);
}
return $balance;

View File

@ -65,9 +65,10 @@ class JournalRepository implements JournalRepositoryInterface
->where('transaction_journals.order', '>=', $journal->order)
->where('transaction_journals.id', '!=', $journal->id)
->get(['transactions.*']);
$sum = 0;
bcscale(2);
$sum = '0';
foreach ($set as $entry) {
$sum += $entry->amount;
$sum = bcadd($entry->amount, $sum);
}
return $sum;

View File

@ -194,7 +194,7 @@ class TestData
* @param $name
* @param $amount
*/
public static function createBudgetLimit(User $user, Carbon $current, $name, $amount)
public static function createBudgetLimit(User $user, Carbon $current, string $name, string $amount)
{
$start = clone $current;
$end = clone $current;
@ -474,7 +474,7 @@ class TestData
*
* @return Account|null
*/
public static function findAccount(User $user, $name)
public static function findAccount(User $user, string $name)
{
/** @var Account $account */
foreach ($user->accounts()->get() as $account) {
@ -495,7 +495,7 @@ class TestData
*
* @return Budget|null
*/
public static function findBudget(User $user, $name)
public static function findBudget(User $user, string $name)
{
/** @var Budget $budget */
foreach (Budget::get() as $budget) {

View File

@ -7,6 +7,7 @@ use Carbon\Carbon;
use Config;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Route;
use Twig_Extension;
use Twig_SimpleFilter;
@ -158,7 +159,7 @@ class General extends Twig_Extension
protected function env()
{
return new Twig_SimpleFunction(
'env', function ($name, $default) {
'env', function (string $name, string $default) {
return env($name, $default);
}
);
@ -171,10 +172,9 @@ class General extends Twig_Extension
protected function formatAmount()
{
return new Twig_SimpleFilter(
'formatAmount', function ($string) {
$value = is_null($string) ? '0' : strval($string);
'formatAmount', function (string $string) {
return app('amount')->format($value);
return app('amount')->format($string);
}, ['is_safe' => ['html']]
);
}
@ -185,10 +185,9 @@ class General extends Twig_Extension
protected function formatAmountPlain()
{
return new Twig_SimpleFilter(
'formatAmountPlain', function ($string) {
$value = is_null($string) ? '0' : strval($string);
'formatAmountPlain', function (string $string) {
return app('amount')->format($value, false);
return app('amount')->format($string, false);
}, ['is_safe' => ['html']]
);
}
@ -199,8 +198,7 @@ class General extends Twig_Extension
protected function formatFilesize()
{
return new Twig_SimpleFilter(
'filesize', function ($size) {
$size = intval($size);
'filesize', function (int $size) {
// less than one GB, more than one MB
if ($size < (1024 * 1024 * 2014) && $size >= (1024 * 1024)) {
@ -223,7 +221,7 @@ class General extends Twig_Extension
protected function formatJournal()
{
return new Twig_SimpleFilter(
'formatJournal', function ($journal) {
'formatJournal', function (TransactionJournal $journal) {
return app('amount')->formatJournal($journal);
}, ['is_safe' => ['html']]
);
@ -247,7 +245,7 @@ class General extends Twig_Extension
protected function getAccountRole()
{
return new Twig_SimpleFilter(
'getAccountRole', function ($name) {
'getAccountRole', function (string $name) {
return Config::get('firefly.accountRoles.' . $name);
}
);
@ -283,7 +281,7 @@ class General extends Twig_Extension
protected function mimeIcon()
{
return new Twig_SimpleFilter(
'mimeIcon', function ($string) {
'mimeIcon', function (string $string) {
switch ($string) {
default:
return 'fa-file-o';
@ -303,7 +301,7 @@ class General extends Twig_Extension
protected function phpdate()
{
return new Twig_SimpleFunction(
'phpdate', function ($str) {
'phpdate', function (string $str) {
return date($str);
}
);

View File

@ -41,7 +41,7 @@
</tr>
<tr>
<td>{{ 'target_amount'|_ }}</td>
<td>{{ piggyBank.targetAmount|formatAmount }}</td>
<td>{{ piggyBank.targetamount|formatAmount }}</td>
</tr>
<tr>
<td>{{ 'saved_so_far'|_ }}</td>

View File

@ -26,7 +26,10 @@
<td>
<a href="{{ route('budgets.show',balanceLine.getBudget.id) }}">{{ balanceLine.getTitle }}</a>
</td>
<td>{{ balanceLine.getRepetition.amount|formatAmount }}</td>
<td>
[source]
<!-- { { balanceLine.getRepetition.amount|formatAmount } } -->
</td>
{% else %}
<td colspan="2">{{ balanceLine.getTitle }}</td>
{% endif %}