Merge pull request #153 from cuneytsenturk/master

Customer panel dashboard add chart
This commit is contained in:
Cüneyt Şentürk 2017-12-18 20:09:45 +03:00 committed by GitHub
commit 3c3bb9f733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 175 additions and 83 deletions

View File

@ -4,10 +4,11 @@ namespace App\Http\Controllers\Customers;
use App\Http\Controllers\Controller;
use App\Models\Income\Invoice;
use Charts;
use Date;
class Dashboard extends Controller
{
/**
* Display a listing of the resource.
*
@ -19,6 +20,106 @@ class Dashboard extends Controller
$invoices = Invoice::with('status')->accrued()->where('customer_id', $customer->id)->get();
return view('customers.dashboard.index', compact('customer', 'invoices'));
$start = Date::parse(request('start', Date::today()->startOfYear()->format('Y-m-d')));
$end = Date::parse(request('end', Date::today()->endOfYear()->format('Y-m-d')));
$start_month = $start->month;
$end_month = $end->month;
// Monthly
$labels = [];
$s = clone $start;
for ($j = $end_month; $j >= $start_month; $j--) {
$labels[$end_month - $j] = $s->format('M Y');
$s->addMonth();
}
$unpaid = $paid = $overdue = $partial_paid = [];
foreach ($invoices as $invoice) {
switch ($invoice->invoice_status_code) {
case 'paid':
$paid[] = $invoice;
break;
case 'partial':
$partial_paid[] = $invoice;
break;
case 'sent':
default:
if (Date::today()->format('Y-m-d') > $invoice->due_at->format('Y-m-d')) {
$overdue[] = $invoice;
} else {
$unpaid[] = $invoice;
}
}
}
$total = count($unpaid) + count($paid) + count($partial_paid) + count($overdue);
$progress = [
'unpaid' => count($unpaid),
'paid' => count($paid),
'overdue' => count($overdue),
'partially_paid' => count($partial_paid),
'total' => $total,
];
$unpaid = $this->calculateTotals($unpaid, $start, $end, 'unpaid');
$paid = $this->calculateTotals($paid, $start, $end, 'paid');
$partial_paid = $this->calculateTotals($partial_paid, $start, $end, 'partial');
$overdue = $this->calculateTotals($overdue, $start, $end, 'overdue');
$chart = Charts::multi('line', 'chartjs')
->dimensions(0, 300)
->colors(['#dd4b39', '#6da252', '#f39c12', '#00c0ef'])
->dataset(trans('general.unpaid'), $unpaid)
->dataset(trans('general.paid'), $paid)
->dataset(trans('general.overdue'), $overdue)
->dataset(trans('general.partially_paid'), $partial_paid)
->labels($labels)
->credits(false)
->view('vendor.consoletvs.charts.chartjs.multi.line');
return view('customers.dashboard.index', compact('customer', 'invoices', 'progress', 'chart'));
}
private function calculateTotals($items, $start, $end, $type)
{
$totals = [];
$date_format = 'Y-m';
$n = 1;
$start_date = $start->format($date_format);
$end_date = $end->format($date_format);
$next_date = $start_date;
$s = clone $start;
while ($next_date <= $end_date) {
$totals[$next_date] = 0;
$next_date = $s->addMonths($n)->format($date_format);
}
$this->setTotals($totals, $items, $date_format, $type);
return $totals;
}
private function setTotals(&$totals, $items, $date_format, $type)
{
foreach ($items as $item) {
if ($type == 'partial') {
$item->amount = $item->payments()->paid();
}
$i = Date::parse($item->paid_at)->format($date_format);
$totals[$i] += $item->getConvertedAmount();
}
}
}

15
public/css/app.css vendored
View File

@ -521,4 +521,17 @@ ul.add-new.nav.navbar-nav.pull-left {
position: fixed;
right: 0;
z-index: 999;
}*/
}*/
.progress-bar-green, .progress-bar-success {
background-color: #6da252;
}
#chart .row {
margin-top: 10px;
}
#chart .row .col-md-3 .customer-content .progress {
clear: both;
margin-top: 25px;
margin-bottom: 10px;
}

View File

@ -93,6 +93,11 @@ return [
'id' => 'ID',
'more_actions' => 'More Actions',
'duplicate' => 'Duplicate',
'unpaid' => 'Unpaid',
'paid' => 'Paid',
'overdue' => 'Overdue',
'partially' => 'Partially',
'partially_paid' => 'Partially Paid',
'title' => [
'new' => 'New :type',

View File

@ -4,90 +4,63 @@
@section('content')
<div class="row">
<!---Income, Expense and Profit Line Chart-->
<div class="col-md-12">
<!-- Invoices List-->
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">{{ trans_choice('general.invoices', 2) }}</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse">
<i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
<div class="box-body" id="chart">
<div class="row">
<div class="col-md-3">
<div class="customer-content">
<div class="pull-left">{{ trans('general.unpaid') }}</div>
<div class="pull-right">{{ $progress['total'] }} / {{ $progress['unpaid'] }}</div>
<div class="progress">
<div class="progress-bar progress-bar-red" role="progressbar" aria-valuenow="{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['unpaid'] : '0' }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['unpaid'] : '0' }}%">
{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['unpaid'] : '0' }} %
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="customer-content">
<div class="pull-left">{{ trans('general.paid') }}</div>
<div class="pull-right">{{ $progress['total'] }} / {{ $progress['paid'] }}</div>
<div class="progress">
<div class="progress-bar progress-bar-green" role="progressbar" aria-valuenow="{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['paid'] : '0' }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['paid'] : '0' }}%">
{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['paid'] : '0' }}%
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="customer-content">
<div class="pull-left">{{ trans('general.overdue') }}</div>
<div class="pull-right">{{ $progress['total'] }} / {{ $progress['overdue'] }}</div>
<div class="progress">
<div class="progress-bar progress-bar-yellow" role="progressbar" aria-valuenow="{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['overdue'] : '0' }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['overdue'] : '0' }}%">
{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['overdue'] : '0' }}%
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="customer-content">
<div class="pull-left">{{ trans('general.partially_paid') }}</div>
<div class="pull-right">{{ $progress['total'] }} / {{ $progress['partially_paid'] }}</div>
<div class="progress">
<div class="progress-bar progress-bar-light-blue" role="progressbar" aria-valuenow="{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['partially_paid'] : '0' }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['partially_paid'] : '0' }}%">
{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['partially_paid'] : '0' }}%
</div>
</div>
</div>
</div>
</div>
</div>
<div class="box-body">
@if ($invoices->count())
<table class="table table-striped">
<thead>
<tr>
<th class="col-md-2">{{ trans('invoices.invoice_number') }}</th>
<th class="col-md-2 text-right">{{ trans('general.amount') }}</th>
<th class="col-md-3 text-right">{{ trans('invoices.invoice_date') }}</th>
<th class="col-md-3 text-right">{{ trans('invoices.due_date') }}</th>
<th class="col-md-2 text-center">{{ trans_choice('general.statuses', 1) }}</th>
</tr>
</thead>
<tbody>
@foreach($invoices as $item)
<tr>
<td><a href="{{ url('customers/invoices/' . $item->id) }}">{{ $item->invoice_number }}</a></td>
<td class="text-right">@money($item->amount, $item->currency_code, true)</td>
<td class="text-right">{{ Date::parse($item->invoiced_at)->format($date_format) }}</td>
<td class="text-right">{{ Date::parse($item->due_at)->format($date_format) }}</td>
<td class="text-center"><span class="label {{ $item->status->label }}">{{ $item->status->name }}</span></td>
</tr>
@endforeach
</tbody>
</table>
@else
<h5 class="text-center">{{ trans('general.no_records') }}</h5>
@endif
<hr>
{!! $chart->render() !!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<!-- Revenues List-->
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">{{ trans_choice('general.payments', 2) }}</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse">
<i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
@if ($customer->revenues->count())
<table class="table table-striped">
<thead>
<tr>
<th>{{ trans('general.date') }}</th>
<th>{{ trans('general.amount') }}</th>
<th>{{ trans_choice('general.categories', 1) }}</th>
<th>{{ trans_choice('general.accounts', 1) }}</th>
</tr>
</thead>
<tbody>
@foreach($customer->revenues as $item)
<tr>
<td><a href="{{ url('customers/payments/' . $item->id . '') }}">{{ Date::parse($item->paid_at)->format($date_format) }}</a></td>
<td>@money($item->amount, $item->currency_code, true)</td>
<td>{{ $item->category->name }}</td>
<td>{{ $item->account->name }}</td>
</tr>
@endforeach
</tbody>
</table>
@else
<h5 class="text-center">{{ trans('general.no_records') }}</h5>
@endif
</div>
</div>
</div>
</div>
@endsection
@endsection
@push('js')
{!! Charts::assets() !!}
@endpush