diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 45556136ab..c28194764c 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -147,7 +147,7 @@ class CategoryController extends Controller while ($start <= $end) { $spent = $repository->spentOnDaySumCorrected($category, $start); - $earned = 0; + $earned = $repository->earnedOnDaySumCorrected($category, $start); if ($spent < 0) { $earned = $spent * -1; $spent = 0; diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index c0e838c50d..3212a5121a 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -200,7 +200,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito */ public function spentOnDaySumCorrected(Category $category, Carbon $date) { - return $category->transactionjournals()->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount'); + return $category->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount'); } /** @@ -355,4 +355,18 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito { return $category->transactionJournals()->before($end)->after($start)->count(); } + + /** + * + * Corrected for tags. + * + * @param Category $category + * @param Carbon $date + * + * @return float + */ + public function earnedOnDaySumCorrected(Category $category, Carbon $date) + { + return $category->transactionjournals()->transactionTypes(['Deposit'])->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount'); + } } diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php index 06e40064a0..e424927fc8 100644 --- a/app/Repositories/Category/CategoryRepositoryInterface.php +++ b/app/Repositories/Category/CategoryRepositoryInterface.php @@ -145,6 +145,17 @@ interface CategoryRepositoryInterface */ public function spentOnDaySumCorrected(Category $category, Carbon $date); + /** + * + * Corrected for tags. + * + * @param Category $category + * @param Carbon $date + * + * @return float + */ + public function earnedOnDaySumCorrected(Category $category, Carbon $date); + /** * @param array $data *