mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 10:16:49 +00:00
More stuff.
This commit is contained in:
@@ -21,6 +21,9 @@ class BalanceEntry
|
||||
/** @var float */
|
||||
protected $spent = 0.0;
|
||||
|
||||
/** @var float */
|
||||
protected $left = 0.0;
|
||||
|
||||
|
||||
/**
|
||||
* @return AccountModel
|
||||
@@ -54,5 +57,23 @@ class BalanceEntry
|
||||
$this->spent = $spent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $left
|
||||
*/
|
||||
public function setLeft($left)
|
||||
{
|
||||
$this->left = $left;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -3,6 +3,7 @@
|
||||
namespace FireflyIII\Helpers\Collection;
|
||||
|
||||
use FireflyIII\Models\Budget as BudgetModel;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
@@ -15,14 +16,20 @@ use Illuminate\Support\Collection;
|
||||
class BalanceLine
|
||||
{
|
||||
|
||||
const ROLE_DEFAULTROLE = 1;
|
||||
const ROLE_TAGROLE = 2;
|
||||
const ROLE_DIFFROLE = 3;
|
||||
|
||||
/** @var Collection */
|
||||
protected $balanceEntries;
|
||||
|
||||
/** @var BudgetModel */
|
||||
protected $budget;
|
||||
|
||||
/** @var float */
|
||||
protected $budgetAmount = 0.0;
|
||||
/** @var LimitRepetition */
|
||||
protected $repetition;
|
||||
|
||||
protected $role = self::ROLE_DEFAULTROLE;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -40,6 +47,25 @@ class BalanceLine
|
||||
$this->balanceEntries->push($balanceEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if ($this->getBudget() instanceof BudgetModel) {
|
||||
return $this->getBudget()->name;
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_DEFAULTROLE) {
|
||||
return trans('firefly.noBudget');
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_TAGROLE) {
|
||||
return trans('firefly.coveredWithTags');
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_DIFFROLE) {
|
||||
return trans('firefly.leftUnbalanced');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BudgetModel
|
||||
*/
|
||||
@@ -57,11 +83,32 @@ class BalanceLine
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRole()
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $role
|
||||
*/
|
||||
public function setRole($role)
|
||||
{
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a BalanceLine has a budget/repetition, each BalanceEntry in this BalanceLine
|
||||
* should have a "spent" value, which is the amount of money that has been spent
|
||||
* on the given budget/repetition. If you subtract all those amounts from the budget/repetition's
|
||||
* total amount, this is returned:
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function left()
|
||||
public function leftOfRepetition()
|
||||
{
|
||||
$start = $this->getBudgetAmount();
|
||||
$start = $this->getRepetition() ? $this->getRepetition()->amount : 0;
|
||||
/** @var BalanceEntry $balanceEntry */
|
||||
foreach ($this->getBalanceEntries() as $balanceEntry) {
|
||||
$start += $balanceEntry->getSpent();
|
||||
@@ -71,19 +118,19 @@ class BalanceLine
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
* @return LimitRepetition
|
||||
*/
|
||||
public function getBudgetAmount()
|
||||
public function getRepetition()
|
||||
{
|
||||
return $this->budgetAmount;
|
||||
return $this->repetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $budgetAmount
|
||||
* @param LimitRepetition $repetition
|
||||
*/
|
||||
public function setBudgetAmount($budgetAmount)
|
||||
public function setRepetition($repetition)
|
||||
{
|
||||
$this->budgetAmount = $budgetAmount;
|
||||
$this->repetition = $repetition;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,5 +149,22 @@ class BalanceLine
|
||||
$this->balanceEntries = $balanceEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the BalanceEntries for a BalanceLine have a "left" value, the amount
|
||||
* of money left in the entire BalanceLine is returned here:
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function sumOfLeft()
|
||||
{
|
||||
$sum = 0.0;
|
||||
/** @var BalanceEntry $balanceEntry */
|
||||
foreach ($this->getBalanceEntries() as $balanceEntry) {
|
||||
$sum += $balanceEntry->getLeft();
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user