mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Added a sum of the current page and the sum of the entire category, in reference to issue #99.
This commit is contained in:
@@ -151,10 +151,11 @@ class CategoryController extends Controller
|
||||
$page = intval(Input::get('page'));
|
||||
$set = $repository->getJournals($category, $page);
|
||||
$count = $repository->countJournals($category);
|
||||
$totalSum = $repository->journalsSum($category);
|
||||
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
||||
$journals->setPath('categories/show/' . $category->id);
|
||||
|
||||
return view('categories.show', compact('category', 'journals', 'hideCategory'));
|
||||
return view('categories.show', compact('category', 'journals', 'hideCategory', 'totalSum'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereUserId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereEncrypted($value)
|
||||
* @property-read float $spent
|
||||
* @property-read \Carbon\Carbon $lastActivity
|
||||
* @property \Carbon\Carbon $lastActivity
|
||||
*/
|
||||
class Category extends Model
|
||||
{
|
||||
|
@@ -57,6 +57,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Carbon $start
|
||||
@@ -64,7 +65,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoriesAndExpensesCorrected($start, $end)
|
||||
public function getCategoriesAndExpensesCorrected(Carbon $start, Carbon $end)
|
||||
{
|
||||
$set = Auth::user()->transactionjournals()
|
||||
->leftJoin(
|
||||
@@ -233,4 +234,32 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the sum of the journals in the category, optionally
|
||||
* limited by a start or end date.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function journalsSum(Category $category, Carbon $start = null, Carbon $end = null)
|
||||
{
|
||||
$query = $category->transactionJournals()
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
if (!is_null($start)) {
|
||||
$query->after($start);
|
||||
}
|
||||
|
||||
if (!is_null($end)) {
|
||||
$query->before($end);
|
||||
}
|
||||
|
||||
return $query->get(['transaction_journals.*'])->sum('correct_amount');
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoriesAndExpensesCorrected($start, $end);
|
||||
public function getCategoriesAndExpensesCorrected(Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
@@ -57,6 +57,18 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function getJournals(Category $category, $page);
|
||||
|
||||
/**
|
||||
* This method returns the sum of the journals in the category, optionally
|
||||
* limited by a start or end date.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function journalsSum(Category $category, Carbon $start = null, Carbon $end = null);
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
|
Reference in New Issue
Block a user