2015-05-16 06:53:08 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FireflyIII\Helpers\Collection;
|
|
|
|
|
2015-05-16 07:51:23 -05:00
|
|
|
use FireflyIII\Models\Category as CategoryModel;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-05-16 12:08:54 -05:00
|
|
|
* @codeCoverageIgnore
|
|
|
|
*
|
2015-05-16 07:51:23 -05:00
|
|
|
* Class Category
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Helpers\Collection
|
|
|
|
*/
|
|
|
|
class Category
|
|
|
|
{
|
|
|
|
|
|
|
|
/** @var Collection */
|
|
|
|
protected $categories;
|
2015-05-24 01:00:40 -05:00
|
|
|
/** @var string */
|
|
|
|
protected $total = '0';
|
2015-05-16 07:51:23 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->categories = new Collection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param CategoryModel $category
|
|
|
|
*/
|
|
|
|
public function addCategory(CategoryModel $category)
|
|
|
|
{
|
|
|
|
if ($category->spent > 0) {
|
|
|
|
$this->categories->push($category);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float $add
|
|
|
|
*/
|
|
|
|
public function addTotal($add)
|
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$add = strval(round($add, 2));
|
|
|
|
bcscale(2);
|
|
|
|
$this->total = bcadd($this->total, $add);
|
2015-05-16 07:51:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getCategories()
|
|
|
|
{
|
|
|
|
$this->categories->sortByDesc(
|
2015-06-06 16:09:12 -05:00
|
|
|
function (CategoryModel $category) {
|
2015-05-16 07:51:23 -05:00
|
|
|
return $category->spent;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-24 01:00:40 -05:00
|
|
|
* @return string
|
2015-05-16 07:51:23 -05:00
|
|
|
*/
|
|
|
|
public function getTotal()
|
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
return strval(round($this->total, 2));
|
2015-05-16 07:51:23 -05:00
|
|
|
}
|
2015-05-16 06:53:08 -05:00
|
|
|
|
|
|
|
|
2015-05-20 12:56:14 -05:00
|
|
|
}
|