2015-05-16 06:53:08 -05:00
|
|
|
<?php
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2015-05-16 07:14:22 -05:00
|
|
|
namespace FireflyIII\Helpers\Collection;
|
2015-05-20 12:55:53 -05:00
|
|
|
|
2015-05-16 07:14:22 -05:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
2015-05-16 06:53:08 -05:00
|
|
|
/**
|
2015-05-16 12:08:54 -05:00
|
|
|
* @codeCoverageIgnore
|
|
|
|
*
|
2015-05-16 07:14:22 -05:00
|
|
|
* Class Budget
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Helpers\Collection
|
2015-05-16 06:53:08 -05:00
|
|
|
*/
|
2015-05-16 07:14:22 -05:00
|
|
|
class Budget
|
|
|
|
{
|
|
|
|
/** @var Collection */
|
|
|
|
protected $budgetLines;
|
2015-05-24 01:00:40 -05:00
|
|
|
/** @var string */
|
|
|
|
protected $budgeted = '0';
|
|
|
|
/** @var string */
|
|
|
|
protected $left = '0';
|
|
|
|
/** @var string */
|
|
|
|
protected $overspent = '0';
|
|
|
|
/** @var string */
|
|
|
|
protected $spent = '0';
|
2015-05-16 07:14:22 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->budgetLines = new Collection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param BudgetLine $budgetLine
|
|
|
|
*/
|
|
|
|
public function addBudgetLine(BudgetLine $budgetLine)
|
|
|
|
{
|
|
|
|
$this->budgetLines->push($budgetLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-02-05 02:25:15 -06:00
|
|
|
* @param string $add
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
2016-02-05 02:25:15 -06:00
|
|
|
public function addBudgeted(string $add)
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$add = strval(round($add, 2));
|
|
|
|
bcscale(2);
|
|
|
|
$this->budgeted = bcadd($this->budgeted, $add);
|
2015-05-16 07:14:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-02-05 02:25:15 -06:00
|
|
|
* @param string $add
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
2016-02-05 02:25:15 -06:00
|
|
|
public function addLeft(string $add)
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$add = strval(round($add, 2));
|
|
|
|
bcscale(2);
|
|
|
|
$this->left = bcadd($this->left, $add);
|
2015-05-16 07:14:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-02-05 02:25:15 -06:00
|
|
|
* @param string $add
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
2016-02-05 02:25:15 -06:00
|
|
|
public function addOverspent(string $add)
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$add = strval(round($add, 2));
|
|
|
|
bcscale(2);
|
|
|
|
$this->overspent = bcadd($this->overspent, $add);
|
2015-05-16 07:14:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-02-05 02:25:15 -06:00
|
|
|
* @param string $add
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
2016-02-05 02:25:15 -06:00
|
|
|
public function addSpent(string $add)
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$add = strval(round($add, 2));
|
|
|
|
bcscale(2);
|
|
|
|
$this->spent = bcadd($this->spent, $add);
|
2015-05-16 07:14:22 -05:00
|
|
|
}
|
|
|
|
|
2015-05-20 12:55:53 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Support\Collection
|
|
|
|
*/
|
|
|
|
public function getBudgetLines()
|
|
|
|
{
|
|
|
|
return $this->budgetLines;
|
|
|
|
}
|
|
|
|
|
2015-05-16 07:14:22 -05:00
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @return string
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
|
|
|
public function getBudgeted()
|
|
|
|
{
|
|
|
|
return $this->budgeted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @param string $budgeted
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
2016-02-05 02:25:15 -06:00
|
|
|
public function setBudgeted(string $budgeted)
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
|
|
|
$this->budgeted = $budgeted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @return string
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
|
|
|
public function getLeft()
|
|
|
|
{
|
|
|
|
return $this->left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @param string $left
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
2016-02-05 02:25:15 -06:00
|
|
|
public function setLeft(string $left)
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
|
|
|
$this->left = $left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @return string
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
|
|
|
public function getOverspent()
|
|
|
|
{
|
|
|
|
return $this->overspent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @param string $overspent
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
2016-02-05 02:25:15 -06:00
|
|
|
public function setOverspent(string $overspent)
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$this->overspent = strval(round($overspent, 2));
|
2015-05-16 07:14:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @return string
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
|
|
|
public function getSpent()
|
|
|
|
{
|
|
|
|
return $this->spent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @param string $spent
|
2015-05-16 07:14:22 -05:00
|
|
|
*/
|
2016-02-05 02:25:15 -06:00
|
|
|
public function setSpent(string $spent)
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$this->spent = strval(round($spent, 2));
|
2015-05-16 07:14:22 -05:00
|
|
|
}
|
|
|
|
|
2015-05-16 06:53:08 -05:00
|
|
|
|
2015-05-20 12:56:14 -05:00
|
|
|
}
|