Skip to content

Commit

Permalink
Add category filter on summary report
Browse files Browse the repository at this point in the history
  • Loading branch information
nafiesl committed Jun 16, 2020
1 parent 1f5b4f8 commit f9cd995
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/Http/Controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public function index(Request $request)
{
$partnerId = $request->get('partner_id');
$partners = $this->getPartnerList();
$categoryId = $request->get('category_id');
$categories = $this->getCategoryList();
$year = $this->getYearQuery($request->get('year'));
$data = $this->getYearlyTransactionSummary($year, auth()->id(), $partnerId);
$data = $this->getYearlyTransactionSummary($year, auth()->id(), $partnerId, $categoryId);

return view('reports.index', compact('year', 'data', 'partners', 'partnerId'));
return view('reports.index', compact('year', 'data', 'partners', 'partnerId', 'categories', 'categoryId'));
}

/**
Expand All @@ -42,7 +44,7 @@ private function getYearQuery($yearQuery)
* @param int|null $partnerId
* @return \Illuminate\Support\Collection
*/
private function getYearlyTransactionSummary($year, $userId, $partnerId = null)
private function getYearlyTransactionSummary($year, $userId, $partnerId = null, $categoryId = null)
{
$rawQuery = 'MONTH(date) as month';
$rawQuery .= ', YEAR(date) as year';
Expand All @@ -58,6 +60,10 @@ private function getYearlyTransactionSummary($year, $userId, $partnerId = null)
$reportQuery->where('partner_id', $partnerId);
}

if ($categoryId) {
$reportQuery->where('category_id', $categoryId);
}

$reportsData = $reportQuery->orderBy('year', 'ASC')
->orderBy('month', 'ASC')
->groupBy(DB::raw('YEAR(date)'))
Expand Down
1 change: 1 addition & 0 deletions resources/views/reports/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{{ Form::label('year', __('report.view_yearly_label'), ['class' => 'control-label']) }}
{{ Form::select('year', get_years(), $year, ['class' => 'form-control']) }}
{{ Form::select('partner_id', $partners, $partnerId, ['class' => 'form-control', 'placeholder' => '-- '.__('partner.all').' --']) }}
{{ Form::select('category_id', $categories, $categoryId, ['class' => 'form-control', 'placeholder' => '-- '.__('category.all').' --']) }}
{{ Form::submit(__('report.view_report'), ['class' => 'btn btn-info btn-sm']) }}
{{ link_to_route('reports.index', __('report.this_year'), [], ['class' => 'btn btn-default btn-sm']) }}
{{ Form::close() }}
Expand Down

0 comments on commit f9cd995

Please sign in to comment.