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));
}