Added a sum of the current page and the sum of the entire category, in reference to issue #99.

This commit is contained in:
James Cole
2015-08-09 16:56:38 +02:00
parent 8d109a3cfe
commit 51e30aed66
8 changed files with 71 additions and 7 deletions

View File

@@ -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'));
}
/**

View File

@@ -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
{

View File

@@ -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');
}
}

View File

@@ -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
*