mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 07:08:19 +00:00
Fixed a bug where the category list in a monthly report would be empty.
This commit is contained in:
@@ -34,7 +34,8 @@ class Category
|
|||||||
*/
|
*/
|
||||||
public function addCategory(CategoryModel $category)
|
public function addCategory(CategoryModel $category)
|
||||||
{
|
{
|
||||||
if ($category->spent > 0) {
|
// spent is minus zero for an expense report:
|
||||||
|
if ($category->spent < 0) {
|
||||||
$this->categories->push($category);
|
$this->categories->push($category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
|
|
||||||
// no repetition(s) for this budget:
|
// no repetition(s) for this budget:
|
||||||
if ($repetitions->count() == 0) {
|
if ($repetitions->count() == 0) {
|
||||||
$spent = $repository->spentInPeriodCorrected($budget, $start, $end, $shared);
|
$spent = $repository->balanceInPeriod($budget, $start, $end, $shared);
|
||||||
$budgetLine = new BudgetLine;
|
$budgetLine = new BudgetLine;
|
||||||
$budgetLine->setBudget($budget);
|
$budgetLine->setBudget($budget);
|
||||||
$budgetLine->setOverspent($spent);
|
$budgetLine->setOverspent($spent);
|
||||||
@@ -278,7 +278,7 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
$budgetLine = new BudgetLine;
|
$budgetLine = new BudgetLine;
|
||||||
$budgetLine->setBudget($budget);
|
$budgetLine->setBudget($budget);
|
||||||
$budgetLine->setRepetition($repetition);
|
$budgetLine->setRepetition($repetition);
|
||||||
$expenses = $repository->spentInPeriodCorrected($budget, $repetition->startdate, $repetition->enddate, $shared);
|
$expenses = $repository->balanceInPeriod($budget, $repetition->startdate, $repetition->enddate, $shared);
|
||||||
$left = $expenses < $repetition->amount ? bcsub($repetition->amount, $expenses) : 0;
|
$left = $expenses < $repetition->amount ? bcsub($repetition->amount, $expenses) : 0;
|
||||||
$spent = $expenses > $repetition->amount ? 0 : $expenses;
|
$spent = $expenses > $repetition->amount ? 0 : $expenses;
|
||||||
$overspent = $expenses > $repetition->amount ? bcsub($expenses, $repetition->amount) : 0;
|
$overspent = $expenses > $repetition->amount ? bcsub($expenses, $repetition->amount) : 0;
|
||||||
@@ -327,7 +327,7 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
||||||
$set = $repository->getCategories();
|
$set = $repository->getCategories();
|
||||||
foreach ($set as $category) {
|
foreach ($set as $category) {
|
||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $end, $shared);
|
$spent = $repository->balanceInPeriod($category, $start, $end, $shared);
|
||||||
$category->spent = $spent;
|
$category->spent = $spent;
|
||||||
$object->addCategory($category);
|
$object->addCategory($category);
|
||||||
$object->addTotal($spent);
|
$object->addTotal($spent);
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ class BudgetController extends Controller
|
|||||||
foreach ($budgets as $budget) {
|
foreach ($budgets as $budget) {
|
||||||
$date = Session::get('start', Carbon::now()->startOfMonth());
|
$date = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
$budget->spent = $repository->spentInPeriodCorrected($budget, $date, $end);
|
$budget->spent = $repository->balanceInPeriod($budget, $date, $end);
|
||||||
$budget->currentRep = $repository->getCurrentRepetition($budget, $date);
|
$budget->currentRep = $repository->getCurrentRepetition($budget, $date);
|
||||||
if ($budget->currentRep) {
|
if ($budget->currentRep) {
|
||||||
$budgeted = bcadd($budgeted, $budget->currentRep->amount);
|
$budgeted = bcadd($budgeted, $budget->currentRep->amount);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class BudgetController extends Controller
|
|||||||
$end->subDay();
|
$end->subDay();
|
||||||
$chartDate = clone $end;
|
$chartDate = clone $end;
|
||||||
$chartDate->startOfMonth();
|
$chartDate->startOfMonth();
|
||||||
$spent = $repository->spentInPeriodCorrected($budget, $first, $end);
|
$spent = $repository->balanceInPeriod($budget, $first, $end);
|
||||||
$entries->push([$chartDate, $spent]);
|
$entries->push([$chartDate, $spent]);
|
||||||
$first = Navigation::addPeriod($first, $range, 0);
|
$first = Navigation::addPeriod($first, $range, 0);
|
||||||
}
|
}
|
||||||
@@ -156,13 +156,13 @@ class BudgetController extends Controller
|
|||||||
foreach ($budgets as $budget) {
|
foreach ($budgets as $budget) {
|
||||||
$repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end);
|
$repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end);
|
||||||
if ($repetitions->count() == 0) {
|
if ($repetitions->count() == 0) {
|
||||||
$expenses = $repository->spentInPeriodCorrected($budget, $start, $end, true);
|
$expenses = $repository->balanceInPeriod($budget, $start, $end, true);
|
||||||
$allEntries->push([$budget->name, 0, 0, $expenses, 0, 0]);
|
$allEntries->push([$budget->name, 0, 0, $expenses, 0, 0]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/** @var LimitRepetition $repetition */
|
/** @var LimitRepetition $repetition */
|
||||||
foreach ($repetitions as $repetition) {
|
foreach ($repetitions as $repetition) {
|
||||||
$expenses = $repository->spentInPeriodCorrected($budget, $repetition->startdate, $repetition->enddate, true);
|
$expenses = $repository->balanceInPeriod($budget, $repetition->startdate, $repetition->enddate, true);
|
||||||
// $left can be less than zero.
|
// $left can be less than zero.
|
||||||
// $overspent can be more than zero ( = overspending)
|
// $overspent can be more than zero ( = overspending)
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ class BudgetController extends Controller
|
|||||||
// filter empty budgets:
|
// filter empty budgets:
|
||||||
|
|
||||||
foreach ($allBudgets as $budget) {
|
foreach ($allBudgets as $budget) {
|
||||||
$spent = $repository->spentInPeriodCorrected($budget, $start, $end, $shared);
|
$spent = $repository->balanceInPeriod($budget, $start, $end, $shared);
|
||||||
if ($spent != 0) {
|
if ($spent != 0) {
|
||||||
$budgets->push($budget);
|
$budgets->push($budget);
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
// each budget, fill the row:
|
// each budget, fill the row:
|
||||||
foreach ($budgets as $budget) {
|
foreach ($budgets as $budget) {
|
||||||
$spent = $repository->spentInPeriodCorrected($budget, $start, $month, $shared);
|
$spent = $repository->balanceInPeriod($budget, $start, $month, $shared);
|
||||||
$row[] = $spent * -1;
|
$row[] = $spent * -1;
|
||||||
}
|
}
|
||||||
$entries->push($row);
|
$entries->push($row);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
while ($start <= $end) {
|
while ($start <= $end) {
|
||||||
$currentEnd = Navigation::endOfPeriod($start, $range);
|
$currentEnd = Navigation::endOfPeriod($start, $range);
|
||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $currentEnd);
|
$spent = $repository->balanceInPeriod($category, $start, $currentEnd);
|
||||||
$entries->push([clone $start, $spent]);
|
$entries->push([clone $start, $spent]);
|
||||||
$start = Navigation::addPeriod($start, $range, 0);
|
$start = Navigation::addPeriod($start, $range, 0);
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ class CategoryController extends Controller
|
|||||||
$entries = new Collection;
|
$entries = new Collection;
|
||||||
$categories = $allCategories->filter(
|
$categories = $allCategories->filter(
|
||||||
function (Category $category) use ($repository, $start, $end, $shared) {
|
function (Category $category) use ($repository, $start, $end, $shared) {
|
||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $end, $shared);
|
$spent = $repository->balanceInPeriod($category, $start, $end, $shared);
|
||||||
if ($spent < 0) {
|
if ($spent < 0) {
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ class CategoryController extends Controller
|
|||||||
$row = [clone $start]; // make a row:
|
$row = [clone $start]; // make a row:
|
||||||
|
|
||||||
foreach ($categories as $category) { // each budget, fill the row
|
foreach ($categories as $category) { // each budget, fill the row
|
||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $month, $shared);
|
$spent = $repository->balanceInPeriod($category, $start, $month, $shared);
|
||||||
if ($spent < 0) {
|
if ($spent < 0) {
|
||||||
$row[] = $spent * -1;
|
$row[] = $spent * -1;
|
||||||
} else {
|
} else {
|
||||||
@@ -247,7 +247,7 @@ class CategoryController extends Controller
|
|||||||
$allEntries = new Collection;
|
$allEntries = new Collection;
|
||||||
$categories = $allCategories->filter(
|
$categories = $allCategories->filter(
|
||||||
function (Category $category) use ($repository, $start, $end, $shared) {
|
function (Category $category) use ($repository, $start, $end, $shared) {
|
||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $end, $shared);
|
$spent = $repository->balanceInPeriod($category, $start, $end, $shared);
|
||||||
if ($spent > 0) {
|
if ($spent > 0) {
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ class CategoryController extends Controller
|
|||||||
$row = [clone $start]; // make a row:
|
$row = [clone $start]; // make a row:
|
||||||
|
|
||||||
foreach ($categories as $category) { // each budget, fill the row
|
foreach ($categories as $category) { // each budget, fill the row
|
||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $month, $shared);
|
$spent = $repository->balanceInPeriod($category, $start, $month, $shared);
|
||||||
if ($spent > 0) {
|
if ($spent > 0) {
|
||||||
$row[] = $spent;
|
$row[] = $spent;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -313,9 +313,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function spentInPeriodCorrected(Budget $budget, Carbon $start, Carbon $end, $shared = true)
|
public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true)
|
||||||
{
|
{
|
||||||
return $this->balanceInPeriod($budget, $start, $end, $shared);
|
return $this->commonBalanceInPeriod($budget, $start, $end, $shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ interface BudgetRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function spentInPeriodCorrected(Budget $budget, Carbon $start, Carbon $end, $shared = true);
|
public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
|||||||
@@ -183,9 +183,9 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function spentInPeriodCorrected(Category $category, Carbon $start, Carbon $end, $shared = false)
|
public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false)
|
||||||
{
|
{
|
||||||
return $this->balanceInPeriod($category, $start, $end, $shared);
|
return $this->commonBalanceInPeriod($category, $start, $end, $shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ interface CategoryRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function spentInPeriodCorrected(Category $category, Carbon $start, Carbon $end, $shared = false);
|
public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class ComponentRepository
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function balanceInPeriod($object, Carbon $start, Carbon $end, $shared = false)
|
protected function commonBalanceInPeriod($object, Carbon $start, Carbon $end, $shared = false)
|
||||||
{
|
{
|
||||||
$cache = new CacheProperties; // we must cache this.
|
$cache = new CacheProperties; // we must cache this.
|
||||||
$cache->addProperty($object->id);
|
$cache->addProperty($object->id);
|
||||||
@@ -32,7 +32,7 @@ class ComponentRepository
|
|||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty($shared);
|
$cache->addProperty($shared);
|
||||||
$cache->addProperty('spentInPeriod');
|
$cache->addProperty('balanceInPeriod');
|
||||||
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
|
|||||||
Reference in New Issue
Block a user