Skip to content

Commit

Permalink
print reports
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Apr 7, 2018
1 parent fcc6107 commit 7ecf691
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 184 deletions.
13 changes: 11 additions & 2 deletions app/Http/Controllers/Reports/ExpenseSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,28 @@ public function index()
$this->setAmount($expenses_graph, $totals, $expenses, $payments, 'payment', 'paid_at');
}

// Check if it's a print or normal request
if (request('print')) {
$chart_template = 'vendor.consoletvs.charts.chartjs.multi.line_print';
$view_template = 'reports.expense_summary.print';
} else {
$chart_template = 'vendor.consoletvs.charts.chartjs.multi.line';
$view_template = 'reports.expense_summary.index';
}

// Expenses chart
$chart = Charts::multi('line', 'chartjs')
->dimensions(0, 300)
->colors(['#F56954'])
->dataset(trans_choice('general.expenses', 1), $expenses_graph)
->labels($dates)
->credits(false)
->view('vendor.consoletvs.charts.chartjs.multi.line');
->view($chart_template);

// Expenses Graph
$expenses_graph = json_encode($expenses_graph);

return view('reports.expense_summary.index', compact('chart', 'dates', 'categories', 'expenses', 'totals'));
return view($view_template, compact('chart', 'dates', 'categories', 'expenses', 'totals'));
}

private function setAmount(&$graph, &$totals, &$expenses, $items, $type, $date_field)
Expand Down
13 changes: 11 additions & 2 deletions app/Http/Controllers/Reports/IncomeExpenseSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,25 @@ public function index()
$this->setAmount($profit_graph, $totals, $compares, $payments, 'payment', 'paid_at');
}

// Check if it's a print or normal request
if (request('print')) {
$chart_template = 'vendor.consoletvs.charts.chartjs.multi.line_print';
$view_template = 'reports.income_expense_summary.print';
} else {
$chart_template = 'vendor.consoletvs.charts.chartjs.multi.line';
$view_template = 'reports.income_expense_summary.index';
}

// Profit chart
$chart = Charts::multi('line', 'chartjs')
->dimensions(0, 300)
->colors(['#6da252'])
->dataset(trans_choice('general.profits', 1), $profit_graph)
->labels($dates)
->credits(false)
->view('vendor.consoletvs.charts.chartjs.multi.line');
->view($chart_template);

return view('reports.income_expense_summary.index', compact('chart', 'dates', 'income_categories', 'expense_categories', 'compares', 'totals'));
return view($view_template, compact('chart', 'dates', 'income_categories', 'expense_categories', 'compares', 'totals'));
}

private function setAmount(&$graph, &$totals, &$compares, $items, $type, $date_field)
Expand Down
13 changes: 11 additions & 2 deletions app/Http/Controllers/Reports/IncomeSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,25 @@ public function index()
$this->setAmount($incomes_graph, $totals, $incomes, $revenues, 'revenue', 'paid_at');
}

// Check if it's a print or normal request
if (request('print')) {
$chart_template = 'vendor.consoletvs.charts.chartjs.multi.line_print';
$view_template = 'reports.income_summary.print';
} else {
$chart_template = 'vendor.consoletvs.charts.chartjs.multi.line';
$view_template = 'reports.income_summary.index';
}

// Incomes chart
$chart = Charts::multi('line', 'chartjs')
->dimensions(0, 300)
->colors(['#00c0ef'])
->dataset(trans_choice('general.incomes', 1), $incomes_graph)
->labels($dates)
->credits(false)
->view('vendor.consoletvs.charts.chartjs.multi.line');
->view($chart_template);

return view('reports.income_summary.index', compact('chart', 'dates', 'categories', 'incomes', 'totals'));
return view($view_template, compact('chart', 'dates', 'categories', 'incomes', 'totals'));
}

private function setAmount(&$graph, &$totals, &$incomes, $items, $type, $date_field)
Expand Down
4 changes: 4 additions & 0 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ ul.add-new.nav.navbar-nav.pull-left {
opacity: 0.4;
}

.print-width {
max-width: 1500px;
}

/*
.tooltip > .tooltip-inner {
background-color: #6da252;
Expand Down
7 changes: 7 additions & 0 deletions resources/views/layouts/print.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
@include('partials.admin.head')

<body onload="window.print();" class="print-width">
@yield('content')
</body>
</html>
48 changes: 48 additions & 0 deletions resources/views/reports/expense_summary/body.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="box-body">
{!! $chart->render() !!}

<hr>

<div class="table table-responsive">
<table class="table table-bordered table-striped table-hover" id="tbl-report-expenses">
<thead>
<tr>
<th>{{ trans_choice('general.categories', 1) }}</th>
@foreach($dates as $date)
<th class="text-right">{{ $date }}</th>
@endforeach
</tr>
</thead>
<tbody>
@if ($expenses)
@foreach($expenses as $category_id => $category)
<tr>
<td>{{ $categories[$category_id] }}</td>
@foreach($category as $item)
<td class="text-right">@money($item['amount'], $item['currency_code'], true)</td>
@endforeach
</tr>
@endforeach
@else
<tr>
<td colspan="4">
<h5 class="text-center">{{ trans('general.no_records') }}</h5>
</td>
</tr>
@endif
</tbody>
<tfoot>
<tr>
<th>{{ trans_choice('general.totals', 1) }}</th>
@foreach($totals as $total)
<th class="text-right">@money($total['amount'], $total['currency_code'], true)</th>
@endforeach
</tr>
</tfoot>
</table>
</div>
</div>

@push('js')
{!! Charts::assets() !!}
@endpush
53 changes: 5 additions & 48 deletions resources/views/reports/expense_summary/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

@section('title', trans('reports.summary.expense'))

@section('new_button')
<span class="new-button"><a href="{{ url('reports/expense-summary') }}?print=1&status={{ request('status') }}&year={{ request('year', $this_year) }}" target="_blank" class="btn btn-success btn-sm"><span class="fa fa-print"></span> &nbsp;{{ trans('general.print') }}</a></span>
@endsection

@section('content')
<!-- Default box -->
<div class="box box-success">
Expand All @@ -17,55 +21,8 @@
</div>
{!! Form::close() !!}
</div>
<div class="box-body">
{!! $chart->render() !!}

<hr>

<div class="table table-responsive">
<table class="table table-bordered table-striped table-hover" id="tbl-report-expenses">
<thead>
<tr>
<th>{{ trans_choice('general.categories', 1) }}</th>
@foreach($dates as $date)
<th class="text-right">{{ $date }}</th>
@endforeach
</tr>
</thead>
<tbody>
@if ($expenses)
@foreach($expenses as $category_id => $category)
<tr>
<td>{{ $categories[$category_id] }}</td>
@foreach($category as $item)
<td class="text-right">@money($item['amount'], $item['currency_code'], true)</td>
@endforeach
</tr>
@endforeach
@else
<tr>
<td colspan="4">
<h5 class="text-center">{{ trans('general.no_records') }}</h5>
</td>
</tr>
@endif
</tbody>
<tfoot>
<tr>
<th>{{ trans_choice('general.totals', 1) }}</th>
@foreach($totals as $total)
<th class="text-right">@money($total['amount'], $total['currency_code'], true)</th>
@endforeach
</tr>
</tfoot>
</table>
</div>
</div>
<!-- /.box-body -->
@include('reports.expense_summary.body')
</div>
<!-- /.box -->
@endsection

@push('js')
{!! Charts::assets() !!}
@endpush
7 changes: 7 additions & 0 deletions resources/views/reports/expense_summary/print.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@extends('layouts.print')

@section('title', trans('reports.summary.expense'))

@section('content')
@include('reports.expense_summary.body')
@endsection
66 changes: 66 additions & 0 deletions resources/views/reports/income_expense_summary/body.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<div class="box-body">
{!! $chart->render() !!}

<hr>

<div class="table table-responsive">
<table class="table table-bordered table-striped table-hover" id="tbl-payments">
<thead>
<tr>
<th>{{ trans_choice('general.categories', 1) }}</th>
@foreach($dates as $date)
<th class="text-right">{{ $date }}</th>
@endforeach
</tr>
</thead>
<tbody>
@if ($compares)
@foreach($compares as $type => $categories)
@foreach($categories as $category_id => $category)
<tr>
@if($type == 'income')
<td>{{ $income_categories[$category_id] }}</td>
@else
<td>{{ $expense_categories[$category_id] }}</td>
@endif
@foreach($category as $item)
@if($type == 'income')
<td class="text-right">@money($item['amount'], $item['currency_code'], true)</td>
@else
<td class="text-right">@money(-$item['amount'], $item['currency_code'], true)</td>
@endif
@endforeach
</tr>
@endforeach
@endforeach
@else
<tr>
<td colspan="13">
<h5 class="text-center">{{ trans('general.no_records') }}</h5>
</td>
</tr>
@endif
</tbody>
<tfoot>
<tr>
<th>{{ trans_choice('general.totals', 1) }}</th>
@foreach($totals as $total)
<th class="text-right">
@if($total['amount'] == 0)
<span>@money($total['amount'], $total['currency_code'], true)</span>
@elseif($total['amount'] > 0)
<span class="text-green">@money($total['amount'], $total['currency_code'], true)</span>
@else
<span class="text-red">@money($total['amount'], $total['currency_code'], true)</span>
@endif
</th>
@endforeach
</tr>
</tfoot>
</table>
</div>
</div>

@push('js')
{!! Charts::assets() !!}
@endpush
73 changes: 6 additions & 67 deletions resources/views/reports/income_expense_summary/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@extends('layouts.admin')

@section('title', trans_choice('reports.summary.income_expense', 1))
@section('title', trans('reports.summary.income_expense'))

@section('new_button')
<span class="new-button"><a href="{{ url('reports/income-expense-summary') }}?print=1&status={{ request('status') }}&year={{ request('year', $this_year) }}" target="_blank" class="btn btn-success btn-sm"><span class="fa fa-print"></span> &nbsp;{{ trans('general.print') }}</a></span>
@endsection

@section('content')
<!-- Default box -->
Expand All @@ -17,73 +21,8 @@
</div>
{!! Form::close() !!}
</div>
<div class="box-body">
{!! $chart->render() !!}

<hr>

<div class="table table-responsive">
<table class="table table-bordered table-striped table-hover" id="tbl-payments">
<thead>
<tr>
<th>{{ trans_choice('general.categories', 1) }}</th>
@foreach($dates as $date)
<th class="text-right">{{ $date }}</th>
@endforeach
</tr>
</thead>
<tbody>
@if ($compares)
@foreach($compares as $type => $categories)
@foreach($categories as $category_id => $category)
<tr>
@if($type == 'income')
<td>{{ $income_categories[$category_id] }}</td>
@else
<td>{{ $expense_categories[$category_id] }}</td>
@endif
@foreach($category as $item)
@if($type == 'income')
<td class="text-right">@money($item['amount'], $item['currency_code'], true)</td>
@else
<td class="text-right">@money(-$item['amount'], $item['currency_code'], true)</td>
@endif
@endforeach
</tr>
@endforeach
@endforeach
@else
<tr>
<td colspan="13">
<h5 class="text-center">{{ trans('general.no_records') }}</h5>
</td>
</tr>
@endif
</tbody>
<tfoot>
<tr>
<th>{{ trans_choice('general.totals', 1) }}</th>
@foreach($totals as $total)
<th class="text-right">
@if($total['amount'] == 0)
<span>@money($total['amount'], $total['currency_code'], true)</span>
@elseif($total['amount'] > 0)
<span class="text-green">@money($total['amount'], $total['currency_code'], true)</span>
@else
<span class="text-red">@money($total['amount'], $total['currency_code'], true)</span>
@endif
</th>
@endforeach
</tr>
</tfoot>
</table>
</div>
</div>
<!-- /.box-body -->
@include('reports.income_expense_summary.body')
</div>
<!-- /.box -->
@endsection

@push('js')
{!! Charts::assets() !!}
@endpush
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@extends('layouts.print')

@section('title', trans('reports.summary.income_expense'))

@section('content')
@include('reports.income_expense_summary.body')
@endsection

0 comments on commit 7ecf691

Please sign in to comment.