@extends(backpack_view('blank'))
@php
function formatDate($data) {
$date = date_create($data);
return date_format($date,"d M Y");
}
$lead = \App\Models\Lead::whereBetween('created_at', [$date_from, $date_to])->get();
$leadCount = $lead->count();
if (backpack_user()->hasRole('ADMIN') || backpack_user()->hasRole('MARKETING') || backpack_user()->hasRole('MANAGEMENT')){
// Year to date sales
Widget::add([
'type' => 'view',
'view' => 'backpack::chart.year_to_date',
'date_from' => formatDate($date_from),
'date_to' => formatDate($date_to),
]);
// Backlog Sales
Widget::add([
'type' => 'view',
'view' => 'backpack::chart.sales_backlog',
'date_from' => formatDate($date_from),
'date_to' => formatDate($date_to),
]);
// Lead Paperline and Lead Source
Widget::add([
'type' => 'div',
'class' => 'row mb-4 chart-dashboard',
'content' => [
[
'type' => 'chart',
'wrapper' => ['class' =>'widget-view col-md-6'],
'controller' => \App\Http\Controllers\Admin\Charts\StatusLeadsChartController::class,
'content' => [
'body' => '
Leads Pipeline
'. formatDate($date_from).' - '. formatDate($date_to).'
Total Leads: '.$leadCount.'
',
]
],
[
'type' => 'chart',
'wrapper' => ['class' =>'widget-view col-md-6'],
'controller' => \App\Http\Controllers\Admin\Charts\LeadSourceChartController::class,
'content' => [
'body' => '
Leads Source
'. formatDate($date_from).' - '. formatDate($date_to).'
',
]
],
],
]);
// Opportunity stuck
Widget::add([
'type' => 'div',
'class' => 'row mb-4 chart-dashboard',
'content' => [
[
'type' => 'chart',
'wrapper' => ['class' =>'col-md-6 widget-view'],
'controller' => \App\Http\Controllers\Admin\Charts\OppStuckChartController::class,
'content' => [
'body' => '
Opportunity stuck > 180 days
'. formatDate($date_from).' - '. formatDate($date_to).'
',
]
]
],
]);
} else {
// Target Chart
$format = '$ -';
$target = \App\Models\SalesTarget::where('user_id', backpack_auth()->id())->where('year',date('Y'))->first();
if($target != null){
$fmt = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
$format = $fmt->formatCurrency($target->target, 'USD');
}
$backYear = now()->format('Y') - 1;
$backlog = \App\Models\VariationOrder::with('agreement.quotation.lead.salesman.user')
->whereYear('created_at', date($backYear))
// ->where('payment_status', 'unpayment')
->get();
$backlogSales = array();
$backlogTotal = array();
foreach ($backlog as $back){
if($back->agreement != null) {
if ($back->agreement->quotation->lead->salesman->user->id == backpack_user()->getAuthIdentifier()) {
$backlogSales[] = [
'client' => $back->agreement->quotation->client_name,
'remain' => 10000
];
$backlogTotal[] = 10000;
}
}
}
$data = [
'backlog' => $backlogSales,
'total' => array_sum($backlogTotal),
'year' => $backYear
];
if (backpack_user()->hasRole('TEAM LEAD')) {
Widget::add([
'type' => 'dashboard-title',
'wrapper' => ['class' => 'col-sm-12'],
'content' => 'Team Lead
',
]);
Widget::add([
'type' => 'div',
'class' => 'row chart-dashboard',
'content' => [
[
'type' => 'chart',
'wrapper' => ['class' =>'widget-view col-md-7'],
'controller' => \App\Http\Controllers\Admin\Charts\SalesTargetChartController::class,
'content' => [
'body' => '
Sales Target vs Actual
'.formatDate($date_from).' - '.formatDate($date_today).'
'
]
],
[
'type' => 'view',
'view' => 'backpack::chart.backlog_reminder',
'date_from' => formatDate($date_from),
'date_to' => formatDate($date_today),
'data' => $data,
]
],
]);
Widget::add([
'type' => 'dashboard-title',
'wrapper' => ['class' => 'col-sm-12'],
'content' => 'Individual
',
]);
}
//Sales Target vs Actual and Backlog Reminder
Widget::add([
'type' => 'div',
'class' => 'row chart-dashboard',
'content' => [
[
'type' => 'chart',
'wrapper' => ['class' =>'widget-view col-md-7'],
'controller' => \App\Http\Controllers\Admin\Charts\SalesTargetChartController::class,
'content' => [
'body' => '
Sales Target vs Actual
'.formatDate($date_from).' - '.formatDate($date_today).'
'
]
],
[
'type' => 'view',
'view' => 'backpack::chart.backlog_reminder',
'date_from' => formatDate($date_from),
'date_to' => formatDate($date_today),
'data' => $data,
]
],
]);
}
@endphp
@section('content')
@endsection
@section('before_styles')
@endsection