Fixed some math.

This commit is contained in:
James Cole 2015-05-24 08:00:40 +02:00
parent 724db6c34c
commit 288546c2b9
12 changed files with 64 additions and 218 deletions

View File

@ -15,14 +15,14 @@ class Budget
{
/** @var Collection */
protected $budgetLines;
/** @var float */
protected $budgeted = 0;
/** @var float */
protected $left = 0;
/** @var float */
protected $overspent = 0;
/** @var float */
protected $spent = 0;
/** @var string */
protected $budgeted = '0';
/** @var string */
protected $left = '0';
/** @var string */
protected $overspent = '0';
/** @var string */
protected $spent = '0';
/**
*
@ -45,7 +45,9 @@ class Budget
*/
public function addBudgeted($add)
{
$this->budgeted += floatval($add);
$add = strval(round($add, 2));
bcscale(2);
$this->budgeted = bcadd($this->budgeted, $add);
}
/**
@ -53,7 +55,9 @@ class Budget
*/
public function addLeft($add)
{
$this->left += floatval($add);
$add = strval(round($add, 2));
bcscale(2);
$this->left = bcadd($this->left, $add);
}
/**
@ -61,7 +65,9 @@ class Budget
*/
public function addOverspent($add)
{
$this->overspent += floatval($add);
$add = strval(round($add, 2));
bcscale(2);
$this->overspent = bcadd($this->overspent, $add);
}
/**
@ -69,7 +75,9 @@ class Budget
*/
public function addSpent($add)
{
$this->spent += floatval($add);
$add = strval(round($add, 2));
bcscale(2);
$this->spent = bcadd($this->spent, $add);
}
/**
@ -81,7 +89,7 @@ class Budget
}
/**
* @return float
* @return string
*/
public function getBudgeted()
{
@ -89,7 +97,7 @@ class Budget
}
/**
* @param float $budgeted
* @param string $budgeted
*/
public function setBudgeted($budgeted)
{
@ -97,7 +105,7 @@ class Budget
}
/**
* @return float
* @return string
*/
public function getLeft()
{
@ -105,7 +113,7 @@ class Budget
}
/**
* @param float $left
* @param string $left
*/
public function setLeft($left)
{
@ -113,7 +121,7 @@ class Budget
}
/**
* @return float
* @return string
*/
public function getOverspent()
{
@ -121,15 +129,15 @@ class Budget
}
/**
* @param float $overspent
* @param string $overspent
*/
public function setOverspent($overspent)
{
$this->overspent = $overspent;
$this->overspent = strval(round($overspent, 2));
}
/**
* @return float
* @return string
*/
public function getSpent()
{
@ -137,11 +145,11 @@ class Budget
}
/**
* @param float $spent
* @param string $spent
*/
public function setSpent($spent)
{
$this->spent = $spent;
$this->spent = strval(round($spent, 2));
}

View File

@ -24,8 +24,8 @@ class Category
/** @var Collection */
protected $categories;
/** @var float */
protected $total = 0;
/** @var string */
protected $total = '0';
/**
*
@ -50,7 +50,9 @@ class Category
*/
public function addTotal($add)
{
$this->total += floatval($add);
$add = strval(round($add, 2));
bcscale(2);
$this->total = bcadd($this->total, $add);
}
/**
@ -69,11 +71,11 @@ class Category
}
/**
* @return float
* @return string
*/
public function getTotal()
{
return $this->total;
return strval(round($this->total, 2));
}

View File

@ -17,8 +17,8 @@ class Expense
{
/** @var Collection */
protected $expenses;
/** @var float */
protected $total;
/** @var string */
protected $total = '0';
/**
*
@ -37,14 +37,15 @@ class Expense
$accountId = $entry->account_id;
if (!$this->expenses->has($accountId)) {
$newObject = new stdClass;
$newObject->amount = floatval($entry->amount);
$newObject->amount = strval(round($entry->amount, 2));
$newObject->name = $entry->name;
$newObject->count = 1;
$newObject->id = $accountId;
$this->expenses->put($accountId, $newObject);
} else {
$existing = $this->expenses->get($accountId);
$existing->amount += floatval($entry->amount);
bcscale(2);
$existing = $this->expenses->get($accountId);
$existing->amount = bcadd($existing->amount, $entry->amount);
$existing->count++;
$this->expenses->put($accountId, $existing);
}
@ -55,7 +56,9 @@ class Expense
*/
public function addToTotal($add)
{
$this->total += floatval($add);
$add = strval(round($add, 2));
bcscale(2);
$this->total = bcadd($this->total, $add);
}
/**
@ -73,10 +76,10 @@ class Expense
}
/**
* @return float
* @return string
*/
public function getTotal()
{
return $this->total;
return strval(round($this->total, 2));
}
}

View File

@ -38,14 +38,15 @@ class Income
$accountId = $entry->account_id;
if (!$this->incomes->has($accountId)) {
$newObject = new stdClass;
$newObject->amount = floatval($entry->amount);
$newObject->amount = strval(round($entry->amount, 2));
$newObject->name = $entry->name;
$newObject->count = 1;
$newObject->id = $accountId;
$this->incomes->put($accountId, $newObject);
} else {
bcscale(2);
$existing = $this->incomes->get($accountId);
$existing->amount += floatval($entry->amount);
$existing->amount = bcadd($existing->amount, $entry->amount);
$existing->count++;
$this->incomes->put($accountId, $existing);
}
@ -56,7 +57,9 @@ class Income
*/
public function addToTotal($add)
{
$this->total += floatval($add);
$add = strval(round($add, 2));
bcscale(2);
$this->total = bcadd($this->total, $add);
}
/**
@ -78,7 +81,7 @@ class Income
*/
public function getTotal()
{
return $this->total;
return strval(round($this->total, 2));
}

View File

@ -151,24 +151,6 @@ class Account extends Model
return $value;
}
/**
* @param $value
*
* @codeCoverageIgnore
* @return float|int
*/
public function getVirtualBalanceAttribute($value)
{
// if (is_null($this->virtual_balance_encrypted)) {
// return $value;
// }
// $value = intval(Crypt::decrypt($this->virtual_balance_encrypted));
// $value = $value / 100;
return $value;
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
@ -229,10 +211,7 @@ class Account extends Model
*/
public function setVirtualBalanceAttribute($value)
{
// $value = intval($value * 100);
// $this->attributes['virtual_balance_encrypted'] = Crypt::encrypt($value);
// $this->attributes['virtual_balance'] = ($value / 100);
$this->attributes['virtual_balance'] = round($value, 2);
$this->attributes['virtual_balance'] = strval(round($value, 2));
}
/**

View File

@ -17,39 +17,6 @@ class Bill extends Model
protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted'];
/**
* @param $value
*
* @return float|int
*/
public function getAmountMaxAttribute($value)
{
// if (is_null($this->amount_max_encrypted)) {
// return $value;
// }
// $value = intval(Crypt::decrypt($this->amount_max_encrypted));
// $value = $value / 100;
return $value;
}
/**
*
* @param $value
*
* @return float|int
*/
public function getAmountMinAttribute($value)
{
// if (is_null($this->amount_min_encrypted)) {
// return $value;
// }
// $value = intval(Crypt::decrypt($this->amount_min_encrypted));
// $value = $value / 100;
return $value;
}
/**
* @return array
*/
@ -93,11 +60,7 @@ class Bill extends Model
*/
public function setAmountMaxAttribute($value)
{
// save in cents:
// $value = intval($value * 100);
// $this->attributes['amount_max_encrypted'] = Crypt::encrypt($value);
// $this->attributes['amount_max'] = ($value / 100);
$this->attributes['amount_max'] = round($value, 2);
$this->attributes['amount_max'] = strval(round($value, 2));
}
/**
@ -105,11 +68,7 @@ class Bill extends Model
*/
public function setAmountMinAttribute($value)
{
// save in cents:
// $value = intval($value * 100);
// $this->attributes['amount_min_encrypted'] = Crypt::encrypt($value);
// $this->attributes['amount_min'] = ($value / 100);
$this->attributes['amount_min'] = round($value, 2);
$this->attributes['amount_min'] = strval(round($value, 2));
}
/**

View File

@ -21,22 +21,6 @@ class BudgetLimit extends Model
return $this->belongsTo('FireflyIII\Models\Budget');
}
/**
* @param $value
*
* @return float|int
*/
public function getAmountAttribute($value)
{
// if (is_null($this->amount_encrypted)) {
// return $value;
// }
// $value = intval(Crypt::decrypt($this->amount_encrypted));
// $value = $value / 100;
return $value;
}
/**
* @return array
*/
@ -58,11 +42,7 @@ class BudgetLimit extends Model
*/
public function setAmountAttribute($value)
{
// save in cents:
// $value = intval($value * 100);
// $this->attributes['amount_encrypted'] = Crypt::encrypt($value);
// $this->attributes['amount'] = ($value / 100);
$this->attributes['amount'] = round($value, 2);
$this->attributes['amount'] = strval(round($value, 2));
}
}

View File

@ -22,22 +22,6 @@ class LimitRepetition extends Model
return $this->belongsTo('FireflyIII\Models\BudgetLimit');
}
/**
* @param $value
*
* @return float|int
*/
public function getAmountAttribute($value)
{
// if (is_null($this->amount_encrypted)) {
// return $value;
// }
// $value = intval(Crypt::decrypt($this->amount_encrypted));
// $value = $value / 100;
return $value;
}
/**
* @return array
*/
@ -51,11 +35,7 @@ class LimitRepetition extends Model
*/
public function setAmountAttribute($value)
{
// save in cents:
// $value = intval($value * 100);
// $this->attributes['amount_encrypted'] = Crypt::encrypt($value);
// $this->attributes['amount'] = ($value / 100);
$this->attributes['amount'] = round($value, 2);
$this->attributes['amount'] = strval(round($value, 2));
}
}

View File

@ -89,22 +89,6 @@ class PiggyBank extends Model
return intval($value) == 1;
}
/**
* @param $value
*
* @return float|int
*/
public function getTargetamountAttribute($value)
{
// if (is_null($this->targetamount_encrypted)) {
// return $value;
// }
// $value = intval(Crypt::decrypt($this->targetamount_encrypted));
// $value = $value / 100;
return $value;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
@ -136,10 +120,6 @@ class PiggyBank extends Model
*/
public function setTargetamountAttribute($value)
{
// save in cents:
// $value = intval($value * 100);
// $this->attributes['targetamount_encrypted'] = Crypt::encrypt($value);
// $this->attributes['targetamount'] = ($value / 100);
$this->attributes['targetamount'] = round($value, 2);
$this->attributes['targetamount'] = strval(round($value, 2));
}
}

View File

@ -15,22 +15,6 @@ class PiggyBankEvent extends Model
protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'amount'];
protected $hidden = ['amount_encrypted'];
/**
* @param $value
*
* @return float|int
*/
public function getAmountAttribute($value)
{
// if (is_null($this->amount_encrypted)) {
// return $value;
// }
// $value = intval(Crypt::decrypt($this->amount_encrypted));
// $value = $value / 100;
return $value;
}
/**
* @return array
*/
@ -52,11 +36,7 @@ class PiggyBankEvent extends Model
*/
public function setAmountAttribute($value)
{
// save in cents:
// $value = intval($value * 100);
// $this->attributes['amount_encrypted'] = Crypt::encrypt($value);
// $this->attributes['amount'] = ($value / 100);
$this->attributes['amount'] = round($value, 2);
$this->attributes['amount'] = strval(round($value, 2));
}
/**

View File

@ -16,22 +16,6 @@ class PiggyBankRepetition extends Model
protected $fillable = ['piggy_bank_id', 'startdate', 'targetdate', 'currentamount'];
protected $hidden = ['currentamount_encrypted'];
/**
* @param $value
*
* @return float|int
*/
public function getCurrentamountAttribute($value)
{
// if (is_null($this->currentamount_encrypted)) {
// return $value;
// }
// $value = intval(Crypt::decrypt($this->currentamount_encrypted));
// $value = $value / 100;
return $value;
}
/**
* @return array
*/
@ -88,11 +72,7 @@ class PiggyBankRepetition extends Model
*/
public function setCurrentamountAttribute($value)
{
// save in cents:
// $value = intval($value * 100);
// $this->attributes['currentamount_encrypted'] = Crypt::encrypt($value);
// $this->attributes['currentamount'] = ($value / 100);
$this->attributes['currentamount'] = round($value, 2);
$this->attributes['currentamount'] = strval(round($value, 2));
}
}

View File

@ -42,12 +42,6 @@ class Transaction extends Model
public function getAmountAttribute($value)
{
return $value;
// if (is_null($this->amount_encrypted)) {
// return $value;
// }
// $value = floatval(Crypt::decrypt($this->amount_encrypted));
//
// return $value;
}
/**
@ -85,9 +79,7 @@ class Transaction extends Model
*/
public function setAmountAttribute($value)
{
// save in cents:
// $this->attributes['amount_encrypted'] = Crypt::encrypt($value);
$this->attributes['amount'] = round($value, 2);
$this->attributes['amount'] = strval(round($value, 2));
}
/**