Merge pull request #153 from cuneytsenturk/master
Customer panel dashboard add chart
This commit is contained in:
commit
3c3bb9f733
@ -4,10 +4,11 @@ namespace App\Http\Controllers\Customers;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Income\Invoice;
|
use App\Models\Income\Invoice;
|
||||||
|
use Charts;
|
||||||
|
use Date;
|
||||||
|
|
||||||
class Dashboard extends Controller
|
class Dashboard extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* 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();
|
$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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
public/css/app.css
vendored
13
public/css/app.css
vendored
@ -522,3 +522,16 @@ ul.add-new.nav.navbar-nav.pull-left {
|
|||||||
right: 0;
|
right: 0;
|
||||||
z-index: 999;
|
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;
|
||||||
|
}
|
@ -93,6 +93,11 @@ return [
|
|||||||
'id' => 'ID',
|
'id' => 'ID',
|
||||||
'more_actions' => 'More Actions',
|
'more_actions' => 'More Actions',
|
||||||
'duplicate' => 'Duplicate',
|
'duplicate' => 'Duplicate',
|
||||||
|
'unpaid' => 'Unpaid',
|
||||||
|
'paid' => 'Paid',
|
||||||
|
'overdue' => 'Overdue',
|
||||||
|
'partially' => 'Partially',
|
||||||
|
'partially_paid' => 'Partially Paid',
|
||||||
|
|
||||||
'title' => [
|
'title' => [
|
||||||
'new' => 'New :type',
|
'new' => 'New :type',
|
||||||
|
@ -4,90 +4,63 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<!---Income, Expense and Profit Line Chart-->
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<!-- Invoices List-->
|
|
||||||
<div class="box box-success">
|
<div class="box box-success">
|
||||||
<div class="box-header with-border">
|
<div class="box-body" id="chart">
|
||||||
<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>
|
|
||||||
</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
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-3">
|
||||||
<!-- Revenues List-->
|
<div class="customer-content">
|
||||||
<div class="box box-success">
|
<div class="pull-left">{{ trans('general.unpaid') }}</div>
|
||||||
<div class="box-header with-border">
|
<div class="pull-right">{{ $progress['total'] }} / {{ $progress['unpaid'] }}</div>
|
||||||
<h3 class="box-title">{{ trans_choice('general.payments', 2) }}</h3>
|
<div class="progress">
|
||||||
<div class="box-tools pull-right">
|
<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' }}%">
|
||||||
<button type="button" class="btn btn-box-tool" data-widget="collapse">
|
{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['unpaid'] : '0' }} %
|
||||||
<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>
|
</div>
|
||||||
<div class="box-body">
|
</div>
|
||||||
@if ($customer->revenues->count())
|
</div>
|
||||||
<table class="table table-striped">
|
<div class="col-md-3">
|
||||||
<thead>
|
<div class="customer-content">
|
||||||
<tr>
|
<div class="pull-left">{{ trans('general.paid') }}</div>
|
||||||
<th>{{ trans('general.date') }}</th>
|
<div class="pull-right">{{ $progress['total'] }} / {{ $progress['paid'] }}</div>
|
||||||
<th>{{ trans('general.amount') }}</th>
|
<div class="progress">
|
||||||
<th>{{ trans_choice('general.categories', 1) }}</th>
|
<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' }}%">
|
||||||
<th>{{ trans_choice('general.accounts', 1) }}</th>
|
{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['paid'] : '0' }}%
|
||||||
</tr>
|
</div>
|
||||||
</thead>
|
</div>
|
||||||
<tbody>
|
</div>
|
||||||
@foreach($customer->revenues as $item)
|
</div>
|
||||||
<tr>
|
<div class="col-md-3">
|
||||||
<td><a href="{{ url('customers/payments/' . $item->id . '') }}">{{ Date::parse($item->paid_at)->format($date_format) }}</a></td>
|
<div class="customer-content">
|
||||||
<td>@money($item->amount, $item->currency_code, true)</td>
|
<div class="pull-left">{{ trans('general.overdue') }}</div>
|
||||||
<td>{{ $item->category->name }}</td>
|
<div class="pull-right">{{ $progress['total'] }} / {{ $progress['overdue'] }}</div>
|
||||||
<td>{{ $item->account->name }}</td>
|
<div class="progress">
|
||||||
</tr>
|
<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' }}%">
|
||||||
@endforeach
|
{{ !empty($progress['total']) ? (100 / $progress['total']) * $progress['overdue'] : '0' }}%
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
</div>
|
||||||
@else
|
</div>
|
||||||
<h5 class="text-center">{{ trans('general.no_records') }}</h5>
|
</div>
|
||||||
@endif
|
<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>
|
||||||
|
<hr>
|
||||||
|
{!! $chart->render() !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
@push('js')
|
||||||
|
{!! Charts::assets() !!}
|
||||||
|
@endpush
|
Loading…
x
Reference in New Issue
Block a user