2015-05-16 06:53:08 -05:00
|
|
|
<?php
|
2016-05-20 05:27:31 -05:00
|
|
|
/**
|
|
|
|
* Budget.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
*
|
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
|
|
|
{
|
2016-03-19 10:51:52 -05:00
|
|
|
$add = strval(round($add, 2));
|
2015-05-24 01:00:40 -05:00
|
|
|
$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
|
|
|
{
|
2016-03-19 10:51:52 -05:00
|
|
|
$add = strval(round($add, 2));
|
2015-05-24 01:00:40 -05:00
|
|
|
$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
|
|
|
{
|
2016-03-19 10:51:52 -05:00
|
|
|
$add = strval(round($add, 2));
|
2015-05-24 01:00:40 -05:00
|
|
|
$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
|
|
|
{
|
2016-03-19 10:51:52 -05:00
|
|
|
$add = strval(round($add, 2));
|
2015-05-24 01:00:40 -05:00
|
|
|
$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
|
|
|
|
*/
|
2016-02-18 03:04:26 -06:00
|
|
|
public function getBudgetLines(): Collection
|
2015-05-20 12:55:53 -05:00
|
|
|
{
|
|
|
|
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
|
|
|
*/
|
2016-02-18 03:04:26 -06:00
|
|
|
public function getBudgeted(): string
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
|
|
|
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
|
|
|
*/
|
2016-02-18 03:04:26 -06:00
|
|
|
public function getLeft(): string
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
|
|
|
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
|
|
|
*/
|
2016-02-18 03:04:26 -06:00
|
|
|
public function getOverspent(): string
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
|
|
|
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
|
|
|
*/
|
2016-02-18 03:04:26 -06:00
|
|
|
public function getSpent(): string
|
2015-05-16 07:14:22 -05:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|