Updated various files for #506

This commit is contained in:
James Cole 2016-12-30 13:45:02 +01:00
parent 9ec3febbfa
commit ac86e75233
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
22 changed files with 63 additions and 70 deletions

View File

@ -58,7 +58,7 @@ class ChartJsGenerator implements GeneratorInterface
{
reset($data);
$first = current($data);
$labels = array_keys($first['entries']);
$labels = is_array($first['entries']) ? array_keys($first['entries']) : [];
$chartData = [
'count' => count($data),

View File

@ -35,27 +35,10 @@ class BalanceLine
/** @var BudgetModel */
protected $budget;
/** @var int */
protected $role = self::ROLE_DEFAULTROLE;
/** @var BudgetLimit */
protected $budgetLimit;
/**
* @return BudgetLimit
*/
public function getBudgetLimit(): BudgetLimit
{
return $this->budgetLimit;
}
/**
* @param BudgetLimit $budgetLimit
*/
public function setBudgetLimit(BudgetLimit $budgetLimit)
{
$this->budgetLimit = $budgetLimit;
}
/** @var int */
protected $role = self::ROLE_DEFAULTROLE;
/**
*
@ -106,6 +89,22 @@ class BalanceLine
$this->budget = $budget;
}
/**
* @return BudgetLimit
*/
public function getBudgetLimit(): BudgetLimit
{
return $this->budgetLimit;
}
/**
* @param BudgetLimit $budgetLimit
*/
public function setBudgetLimit(BudgetLimit $budgetLimit)
{
$this->budgetLimit = $budgetLimit;
}
/**
* @return Carbon
*/

View File

@ -60,7 +60,6 @@ class Budget
*/
public function addBudgeted(string $add): Budget
{
$add = strval(round($add, 2));
$this->budgeted = bcadd($this->budgeted, $add);
return $this;
@ -73,7 +72,6 @@ class Budget
*/
public function addLeft(string $add): Budget
{
$add = strval(round($add, 2));
$this->left = bcadd($this->left, $add);
return $this;
@ -86,7 +84,6 @@ class Budget
*/
public function addOverspent(string $add): Budget
{
$add = strval(round($add, 2));
$this->overspent = bcadd($this->overspent, $add);
return $this;
@ -99,7 +96,6 @@ class Budget
*/
public function addSpent(string $add): Budget
{
$add = strval(round($add, 2));
$this->spent = bcadd($this->spent, $add);
return $this;
@ -168,7 +164,7 @@ class Budget
*/
public function setOverspent(string $overspent): Budget
{
$this->overspent = strval(round($overspent, 2));
$this->overspent = $overspent;
return $this;
}
@ -188,7 +184,7 @@ class Budget
*/
public function setSpent(string $spent): Budget
{
$this->spent = strval(round($spent, 2));
$this->spent = $spent;
return $this;
}

View File

@ -55,7 +55,6 @@ class Category
*/
public function addTotal(string $add)
{
$add = strval(round($add, 2));
$this->total = bcadd($this->total, $add);
}
@ -79,7 +78,7 @@ class Category
*/
public function getTotal(): string
{
return strval(round($this->total, 2));
return $this->total;
}

View File

@ -128,7 +128,7 @@ class AccountController extends Controller
$endBalance = $endBalances[$id] ?? '0';
$diff = bcsub($endBalance, $startBalance);
if (bccomp($diff, '0') !== 0) {
$chartData[$account->name] = round($diff, 2);
$chartData[$account->name] = $diff;
}
}
arsort($chartData);
@ -391,7 +391,7 @@ class AccountController extends Controller
$diff = bcsub($endBalance, $startBalance);
$diff = bcmul($diff, '-1');
if (bccomp($diff, '0') !== 0) {
$chartData[$account->name] = round($diff, 2);
$chartData[$account->name] = $diff;
}
}
@ -475,11 +475,11 @@ class AccountController extends Controller
];
$currentStart = clone $start;
$range = Steam::balanceInRange($account, $start, clone $end);
$previous = round(array_values($range)[0], 2);
$previous = array_values($range)[0];
while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d');
$label = $currentStart->formatLocalized(strval(trans('config.month_and_day')));
$balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
$balance = isset($range[$format]) ? round($range[$format], 12) : $previous;
$previous = $balance;
$currentStart->addDay();
$currentSet['entries'][$label] = $balance;

View File

@ -231,9 +231,9 @@ class BudgetController extends Controller
$current = clone $start;
while ($current < $end) {
$currentStart = Navigation::startOfPeriod($current, $range);
$currentEnd = Navigation::endOfPeriod($current, $range);
$budgetLimits = $repository->getBudgetLimits($budget, $currentStart, $currentEnd);
$currentStart = Navigation::startOfPeriod($current, $range);
$currentEnd = Navigation::endOfPeriod($current, $range);
$budgetLimits = $repository->getBudgetLimits($budget, $currentStart, $currentEnd);
$index = $currentStart->format($key);
$budgeted[$index] = $budgetLimits->sum('amount');
$currentEnd->addDay();
@ -258,7 +258,7 @@ class BudgetController extends Controller
$label = $periods[$period];
$spent = isset($entries[$budget->id]['entries'][$period]) ? $entries[$budget->id]['entries'][$period] : '0';
$limit = isset($budgeted[$period]) ? $budgeted[$period] : 0;
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 2);
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
$chartData[1]['entries'][$label] = $limit;
}

View File

@ -245,8 +245,8 @@ class BudgetReportController extends Controller
$currentExpenses = $expenses[$budget->id] ?? '0';
$sumOfExpenses[$budget->id] = $sumOfExpenses[$budget->id] ?? '0';
$sumOfExpenses[$budget->id] = bcadd($currentExpenses, $sumOfExpenses[$budget->id]);
$chartData[$budget->id]['entries'][$label] = round(bcmul($currentExpenses, '-1'), 2);
$chartData[$budget->id . '-sum']['entries'][$label] = round(bcmul($sumOfExpenses[$budget->id], '-1'), 2);
$chartData[$budget->id]['entries'][$label] = bcmul($currentExpenses, '-1');
$chartData[$budget->id . '-sum']['entries'][$label] = bcmul($sumOfExpenses[$budget->id], '-1');
if (count($budgetLimits) > 0) {
$budgetLimitId = $budgetLimits->first()->id;

View File

@ -117,7 +117,7 @@ class NewUserController extends Controller
'virtualBalance' => 0,
'active' => true,
'accountRole' => 'defaultAsset',
'openingBalance' => round($request->input('bank_balance'), 2),
'openingBalance' => round($request->input('bank_balance'), 12),
'openingBalanceDate' => new Carbon,
'openingBalanceCurrency' => intval($request->input('amount_currency_id_bank_balance')),
];
@ -142,7 +142,7 @@ class NewUserController extends Controller
'virtualBalance' => 0,
'active' => true,
'accountRole' => 'savingAsset',
'openingBalance' => round($request->input('savings_balance'), 2),
'openingBalance' => round($request->input('savings_balance'), 12),
'openingBalanceDate' => new Carbon,
'openingBalanceCurrency' => intval($request->input('amount_currency_id_savings_balance')),
];
@ -163,7 +163,7 @@ class NewUserController extends Controller
'name' => 'Credit card',
'iban' => null,
'accountType' => 'asset',
'virtualBalance' => round($request->get('credit_card_limit'), 2),
'virtualBalance' => round($request->get('credit_card_limit'), 12),
'active' => true,
'accountRole' => 'ccAsset',
'openingBalance' => null,

View File

@ -219,7 +219,7 @@ class PiggyBankController extends Controller
$accounts = [];
/** @var PiggyBank $piggyBank */
foreach ($piggyBanks as $piggyBank) {
$piggyBank->savedSoFar = round($piggyBank->currentRelevantRep()->currentamount, 2);
$piggyBank->savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
$piggyBank->percentage = $piggyBank->savedSoFar != 0 ? intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100) : 0;
$piggyBank->leftToSave = bcsub($piggyBank->targetamount, strval($piggyBank->savedSoFar));
$piggyBank->percentage = $piggyBank->percentage > 100 ? 100 : $piggyBank->percentage;
@ -234,7 +234,7 @@ class PiggyBankController extends Controller
'balance' => Steam::balanceIgnoreVirtual($account, $end),
'leftForPiggyBanks' => $piggyBank->leftOnAccount($end),
'sumOfSaved' => strval($piggyBank->savedSoFar),
'sumOfTargets' => strval(round($piggyBank->targetamount, 2)),
'sumOfTargets' => $piggyBank->targetamount,
'leftToSave' => $piggyBank->leftToSave,
];
} else {
@ -279,15 +279,15 @@ class PiggyBankController extends Controller
*/
public function postAdd(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
{
$amount = strval(round($request->get('amount'), 2));
$amount = $request->get('amount');
/** @var Carbon $date */
$date = session('end', Carbon::now()->endOfMonth());
$leftOnAccount = $piggyBank->leftOnAccount($date);
$savedSoFar = strval($piggyBank->currentRelevantRep()->currentamount);
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = round(min($leftOnAccount, $leftToSave), 2);
$maxAmount = strval(min(round($leftOnAccount, 12), round($leftToSave, 12)));
if ($amount <= $maxAmount) {
if (bccomp($amount, $maxAmount) === -1) {
$repetition = $piggyBank->currentRelevantRep();
$currentAmount = $repetition->currentamount ?? '0';
$repetition->currentamount = bcadd($currentAmount, $amount);
@ -319,11 +319,11 @@ class PiggyBankController extends Controller
*/
public function postRemove(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
{
$amount = strval(round($request->get('amount'), 2));
$amount = strval(round($request->get('amount'), 12));
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
if ($amount <= $savedSoFar) {
if (bccomp($amount, $savedSoFar) === -1) {
$repetition = $piggyBank->currentRelevantRep();
$repetition->currentamount = bcsub($repetition->currentamount, $amount);
$repetition->save();

View File

@ -214,7 +214,7 @@ class MassController extends Controller
'source_account_name' => $sourceAccountName,
'destination_account_id' => intval($destAccountId),
'destination_account_name' => $destAccountName,
'amount' => round($request->get('amount')[$journal->id], 4),
'amount' => round($request->get('amount')[$journal->id], 12),
'currency_id' => intval($request->get('amount_currency_id_amount_' . $journal->id)),
'date' => new Carbon($request->get('date')[$journal->id]),
'interest_date' => $journal->interest_date,

View File

@ -138,7 +138,7 @@ class SplitController extends Controller
$data = $this->arrayFromInput($request);
$journal = $repository->updateSplitJournal($journal, $data);
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
// save attachments:
$this->attachments->saveAttachmentsForModel($journal, $files);
@ -257,7 +257,7 @@ class SplitController extends Controller
'source_account_name' => $transaction['source_account_name'],
'destination_account_id' => $transaction['destination_account_id'],
'destination_account_name' => $transaction['destination_account_name'],
'amount' => round($transaction['destination_amount'], 2),
'amount' => round($transaction['destination_amount'], 12),
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
'category' => $transaction['category'],
];
@ -292,7 +292,7 @@ class SplitController extends Controller
'source_account_name' => $transaction['source_account_name'] ?? '',
'destination_account_id' => $transaction['destination_account_id'] ?? 0,
'destination_account_name' => $transaction['destination_account_name'] ?? '',
'amount' => round($transaction['amount'] ?? 0, 2),
'amount' => round($transaction['amount'] ?? 0, 12),
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
'category' => $transaction['category'] ?? '',
];

View File

@ -43,13 +43,13 @@ class AccountFormRequest extends Request
'active' => intval($this->input('active')) === 1,
'accountType' => $this->input('what'),
'currency_id' => intval($this->input('currency_id')),
'virtualBalance' => round($this->input('virtualBalance'), 2),
'virtualBalance' => round($this->input('virtualBalance'), 12),
'virtualBalanceCurrency' => intval($this->input('amount_currency_id_virtualBalance')),
'iban' => trim(strval($this->input('iban'))),
'BIC' => trim(strval($this->input('BIC'))),
'accountNumber' => trim(strval($this->input('accountNumber'))),
'accountRole' => $this->input('accountRole'),
'openingBalance' => round($this->input('openingBalance'), 2),
'openingBalance' => round($this->input('openingBalance'), 12),
'openingBalanceDate' => new Carbon((string)$this->input('openingBalanceDate')),
'openingBalanceCurrency' => intval($this->input('amount_currency_id_openingBalance')),
'ccType' => $this->input('ccType'),

View File

@ -40,10 +40,10 @@ class BillFormRequest extends Request
return [
'name' => $this->get('name'),
'match' => $this->get('match'),
'amount_min' => round($this->get('amount_min'), 2),
'amount_min' => round($this->get('amount_min'), 12),
'amount_currency_id_amount_min' => intval($this->get('amount_currency_id_amount_min')),
'amount_currency_id_amount_max' => intval($this->get('amount_currency_id_amount_max')),
'amount_max' => round($this->get('amount_max'), 2),
'amount_max' => round($this->get('amount_max'), 12),
'date' => new Carbon($this->get('date')),
'repeat_freq' => $this->get('repeat_freq'),
'skip' => intval($this->get('skip')),

View File

@ -59,7 +59,7 @@ class JournalFormRequest extends Request
// transaction / journal data:
'description' => $this->getFieldOrEmptyString('description'),
'amount' => round($this->get('amount'), 2),
'amount' => round($this->get('amount'), 12),
'budget_id' => intval($this->get('budget_id')),
'category' => $this->getFieldOrEmptyString('category'),
'source_account_id' => intval($this->get('source_account_id')),

View File

@ -41,7 +41,7 @@ class PiggyBankFormRequest extends Request
'name' => trim($this->get('name')),
'startdate' => new Carbon,
'account_id' => intval($this->get('account_id')),
'targetamount' => round($this->get('targetamount'), 2),
'targetamount' => round($this->get('targetamount'), 12),
'targetdate' => strlen(strval($this->get('targetdate'))) > 0 ? new Carbon($this->get('targetdate')) : null,
'note' => trim(strval($this->get('note'))),
];

View File

@ -93,7 +93,7 @@ class SplitJournalFormRequest extends Request
$category = $this->get('category')[$index] ?? '';
$transaction = [
'description' => $description,
'amount' => round($this->get('amount')[$index], 2),
'amount' => round($this->get('amount')[$index], 12),
'budget_id' => $this->get('budget_id')[$index] ? intval($this->get('budget_id')[$index]) : 0,
'category' => trim($category),
'source_account_id' => isset($this->get('source_account_id')[$index])

View File

@ -62,7 +62,7 @@ class Amount extends BasicConverter implements ConverterInterface
$this->setCertainty(90);
return round(floatval($value), 4);
return round(floatval($value), 12);
}
}

View File

@ -318,7 +318,7 @@ class Account extends Model
*/
public function setVirtualBalanceAttribute($value)
{
$this->attributes['virtual_balance'] = strval(round($value, 2));
$this->attributes['virtual_balance'] = strval(round($value, 12));
}
/**

View File

@ -29,9 +29,6 @@ class Bill extends Model
{
use ValidatingTrait;
/** @var array */
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/**
* The attributes that should be casted to native types.
*
@ -49,6 +46,8 @@ class Bill extends Model
'name_encrypted' => 'boolean',
'match_encrypted' => 'boolean',
];
/** @var array */
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip',
'automatch', 'active',];
@ -105,7 +104,7 @@ class Bill extends Model
*/
public function setAmountMaxAttribute($value)
{
$this->attributes['amount_max'] = strval(round($value, 2));
$this->attributes['amount_max'] = strval(round($value, 12));
}
/**
@ -113,7 +112,7 @@ class Bill extends Model
*/
public function setAmountMinAttribute($value)
{
$this->attributes['amount_min'] = strval(round($value, 2));
$this->attributes['amount_min'] = strval(round($value, 12));
}
/**

View File

@ -81,7 +81,7 @@ class BudgetLimit extends Model
*/
public function setAmountAttribute($value)
{
$this->attributes['amount'] = strval(round($value, 2));
$this->attributes['amount'] = strval(round($value, 12));
}
}

View File

@ -35,7 +35,7 @@ class PiggyBank extends Model
* @var array
*/
protected $casts
= [
= [
'created_at' => 'date',
'updated_at' => 'date',
'deleted_at' => 'date',
@ -168,6 +168,6 @@ class PiggyBank extends Model
*/
public function setTargetamountAttribute($value)
{
$this->attributes['targetamount'] = strval(round($value, 2));
$this->attributes['targetamount'] = strval(round($value, 12));
}
}

View File

@ -506,7 +506,7 @@ class ExpandedForm
// make sure value is formatted nicely:
if (!is_null($value) && $value !== '') {
$value = round($value, 2);
$value = round($value, $defaultCurrency->decimal_places);
}