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'));
|
$page = intval(Input::get('page'));
|
||||||
$set = $repository->getJournals($category, $page);
|
$set = $repository->getJournals($category, $page);
|
||||||
$count = $repository->countJournals($category);
|
$count = $repository->countJournals($category);
|
||||||
|
$totalSum = $repository->journalsSum($category);
|
||||||
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
||||||
$journals->setPath('categories/show/' . $category->id);
|
$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 whereUserId($value)
|
||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereEncrypted($value)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereEncrypted($value)
|
||||||
* @property-read float $spent
|
* @property-read float $spent
|
||||||
* @property-read \Carbon\Carbon $lastActivity
|
* @property \Carbon\Carbon $lastActivity
|
||||||
*/
|
*/
|
||||||
class Category extends Model
|
class Category extends Model
|
||||||
{
|
{
|
||||||
|
@@ -57,6 +57,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
|||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
@@ -64,7 +65,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getCategoriesAndExpensesCorrected($start, $end)
|
public function getCategoriesAndExpensesCorrected(Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
$set = Auth::user()->transactionjournals()
|
$set = Auth::user()->transactionjournals()
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
@@ -233,4 +234,32 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
|||||||
|
|
||||||
return $category;
|
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
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getCategoriesAndExpensesCorrected($start, $end);
|
public function getCategoriesAndExpensesCorrected(Carbon $start, Carbon $end);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Category $category
|
* @param Category $category
|
||||||
@@ -57,6 +57,18 @@ interface CategoryRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getJournals(Category $category, $page);
|
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
|
* @param Category $category
|
||||||
*
|
*
|
||||||
|
@@ -15,6 +15,7 @@ return [
|
|||||||
'cancel' => 'Cancel',
|
'cancel' => 'Cancel',
|
||||||
'from' => 'From',
|
'from' => 'From',
|
||||||
'to' => 'To',
|
'to' => 'To',
|
||||||
|
'total_sum' => 'Total sum',
|
||||||
'showEverything' => 'Show everything',
|
'showEverything' => 'Show everything',
|
||||||
'never' => 'Never',
|
'never' => 'Never',
|
||||||
'search_results_for' => 'Search results for ":query"',
|
'search_results_for' => 'Search results for ":query"',
|
||||||
|
@@ -15,6 +15,7 @@ return [
|
|||||||
'cancel' => 'Annuleren',
|
'cancel' => 'Annuleren',
|
||||||
'from' => 'Van',
|
'from' => 'Van',
|
||||||
'to' => 'Tot',
|
'to' => 'Tot',
|
||||||
|
'total_sum' => 'Totale som',
|
||||||
'showEverything' => 'Laat alles zien',
|
'showEverything' => 'Laat alles zien',
|
||||||
'never' => 'Nooit',
|
'never' => 'Nooit',
|
||||||
'search_results_for' => 'Zoekresultaten voor ":query"',
|
'search_results_for' => 'Zoekresultaten voor ":query"',
|
||||||
|
@@ -45,7 +45,7 @@
|
|||||||
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
|
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body no-padding">
|
<div class="box-body no-padding">
|
||||||
{% include 'list/journals' %}
|
{% include 'list/journals' with {showPageSum: true,showTotalSum: true} %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
{{ journals.render|raw }}
|
{{ journals.render|raw }}
|
||||||
|
|
||||||
<table class="table table-hover sortable sortable-table">
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
<tr class="ignore">
|
<tr class="ignore">
|
||||||
<th class="hidden-xs" colspan="2"> </th>
|
<th class="hidden-xs" colspan="2"> </th>
|
||||||
<th>{{ trans('list.description') }}</th>
|
<th>{{ trans('list.description') }}</th>
|
||||||
@@ -23,6 +24,9 @@
|
|||||||
<th class="hidden-xs"><i class="fa fa-fw fa-rotate-right" title="{{ trans('list.bill') }}"></i></th>
|
<th class="hidden-xs"><i class="fa fa-fw fa-rotate-right" title="{{ trans('list.bill') }}"></i></th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% set _sum = 0 %}
|
||||||
{% for journal in journals %}
|
{% for journal in journals %}
|
||||||
{% if invalidJournal(journal) %}
|
{% if invalidJournal(journal) %}
|
||||||
<tr class="ignore">
|
<tr class="ignore">
|
||||||
@@ -36,6 +40,7 @@
|
|||||||
<td colspan="7"><em>Invalid journal: Found {{ journal.transactions|length }} transaction(s)</em></td>
|
<td colspan="7"><em>Invalid journal: Found {{ journal.transactions|length }} transaction(s)</em></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
{% set _sum = _sum + journal.correct_amount %}
|
||||||
<tr class="drag" data-date="{{ journal.date.format('Y-m-d') }}" data-id="{{ journal.id }}">
|
<tr class="drag" data-date="{{ journal.date.format('Y-m-d') }}" data-id="{{ journal.id }}">
|
||||||
<td class="hidden-xs">
|
<td class="hidden-xs">
|
||||||
<div class="btn-group btn-group-xs">
|
<div class="btn-group btn-group-xs">
|
||||||
@@ -111,8 +116,23 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
{% if showPageSum %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="3" style="text-align: right;"><em>{{ 'sum'|_ }}</em></td>
|
||||||
|
<td colspan="2">{{ _sum|formatAmount }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% if showTotalSum %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="3" style="text-align: right;"><em>{{ 'total_sum'|_ }}</em></td>
|
||||||
|
<td colspan="2">{{ totalSum|formatAmount }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{{ journals.render|raw }}
|
{{ journals.render|raw }}
|
||||||
|
Reference in New Issue
Block a user