Rapport-Laravel/resources/views/metricreport/appreport.blade.php

654 lines
35 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
@include('layouts.shared/title-meta', ['title' => "Report"])
@include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? ''])
<link href="{{asset('assets/libs/flatpickr/flatpickr.min.css')}}" rel="stylesheet" type="text/css" />
<link href="{{asset('assets/libs/bootstrap-datepicker/bootstrap-datepicker.min.css')}}" rel="stylesheet" type="text/css" />
</head>
<body class="loading" style="background:#fff">
<div class="loader text-white">
<i class="mdi mdi-loading mdi-spin mdi-48px" aria-hidden="true"></i><br />Loading
</div>
<div class="card p-2" id="graph-wrapper">
<div class="card-body p-0">
<div class="row">
<div class="col-12 pt-1">
<h4 class="header-title">{{$graph->name}}</h4>
</div>
<div class="col-6 pt-1">
<p class="text-muted"> {!!$graph->agg_type == 'team' ? '<i class="mdi mdi-account-group" aria-hidden="true"></i>' : '<i class="mdi mdi-account" aria-hidden="true"></i>' !!} {{ucwords($graph->agg_type)}} Report</p>
</div>
<div class="col-6 pt-1">
<p class="text-end" text-muted><i class="mdi mdi-chart-box-plus-outline" aria-hidden="true"></i> {{ucwords($graph->type)}} Metric</p>
</div>
<!-- <div class="col-8">
<p class="text-muted"><i class="mdi mdi-calendar" aria-hidden="true"></i> Report Validity: {{$graph->valid_from}} to {{$graph->valid_till}}</p>
</div> -->
<div class="col-12">
<p class="text-muted"><i class="mdi mdi-calendar" aria-hidden="true"></i> Date Range Selected: {{$graph->first_day}} to {{$graph->last_day}}</p>
</div>
<div class="col-12 text-end">
@if((in_array($post['type'], ['trend','leaderboard']) && !in_array($post['chart'], ['line', 'bar']) ) || ($post['type'] == 'graphical' && $graph->type == 'grouped') || ($post['type'] == 'details' && $graph->chart == 'tabular') || ($post['type'] == 'contacts' && $graph->chart == 'contacts') || ($post['type'] == 'scoreboard' && $graph->chart == 'leaderboard') )
<button class="btn btn-dark btn-xs" id="export">Download</button>
<button class="btn btn-warning btn-xs" id="email-export">Send me Email</button>
@endif
<button type="button" class="btn btn-success btn-xs" data-bs-toggle="modal" data-bs-target="#metric-filter-modal"><i class="mdi mdi-filter"></i></button>
<div class="modal fade" id="metric-filter-modal" tabindex="-1" aria-labelledby="mySmallModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="mySmallModalLabel">Filter out Metrics</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body text-start">
@foreach($graph->metrics as $val)
<div class="form-check mb-2 form-check-primary">
<input class="form-check-input" type="checkbox" name="metric-filter[]" value="{{$val->metric}}" id="filter-{{$val->metric}}" {{isset($post['metrics']) ? (in_array($val->metric,$post['metrics']) ? 'checked' : '' ): 'checked' }}>
<label class="form-check-label ps-2" for="filter-{{$val->metric}}">{{$val->display}}</label>
</div>
@endforeach
<button type="button" class="btn btn-success btn-xs" id="apply-metric-filter">Apply Filter</button>
<button type="button" class="btn btn-info btn-xs" id="clear-metric-filter">Clear Filter</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
</div>
<div class="col-12 pt-1">
<div class="button-list">
@foreach($charts as $chart)
@if(sizeof($chart->charts)>0)
<!-- <a href="/form/metricreport?id={{$graph->id}}&type={{$chart->type}}&chart={{$chart->charts[0]}}&period={{$periods[0]->value}}" class="btn btn-{{$chart->type == $post['type'] ? '':'outline-' }}khaki btn-rounded btn-xs font-14">{{$chart->name}}</a> -->
<button charttype="{{$chart->type}}" type="button" chart="{{$chart->charts[0]}}" class="btn btn-{{$chart->type == $post['type'] ? '':'outline-' }}khaki btn-rounded btn-xs font-14 charttypebtn m-0">{{$chart->name}}</button>
@endif
@endforeach
</div>
</div>
<div class="col-7 pt-3">
<p class="text-end">Select Period</p>
</div>
<div class="col-5 pt-3">
<select class="form-control" id="period" name="period" style="padding: 2px 0 2px 8px;">
@foreach($periods as $v)
<option value="{{$v->value}}" {{$post['period'] == $v->value ? "selected":""}}>{{$v->label}}</option>
@endforeach
</select>
</div>
</div>
<div class="row">
@foreach($charts as $chart)
@if($chart->type == $post['type'] && sizeof($chart->charts) > 1)
@foreach($chart->charts as $ch)
<div class="col-auto">
<a href="/form/metricreport?id={{$graph->id}}&type={{$chart->type}}&chart={{$ch}}&period={{$periods[0]->value}}" class="text-dark font-14 {{$ch == $graph->chart ? 'underline':'' }}"><i class="mdi {{$ch == 'tabular' ? 'mdi-table':'mdi-chart-'.$ch}}" aria-hidden="true"></i> {{ucwords($ch)}} chart</a>
</div>
@endforeach
@endif
@endforeach
</div>
<div class="widget-chart text-center" dir="ltr">
@switch(true)
@case($graph->chart == 'leaderboard')
<div id="cardCollpase4" class="collapse pt-1 show">
@if(sizeof($breadcrumbs) == 0)
<div class="row">
<div class="col-6">
<div class="btn-group mb-2 float-start">
<button type="button" class="btn btn-info btn-xs leaderboard-prev" {{$graph->current_level==$graph->level?'disabled':''}}><i class="mdi mdi-play mdi-rotate-180 mdi-18px"></i></button>
<button type="button" class="btn btn-info btn-xs">Level {{$graph->current_level}}</button>
<button type="button" class="btn btn-info btn-xs leaderboard-next" {{$graph->current_level==1?'disabled':''}}><i class="mdi mdi-play mdi-18px"></i></button>
</div>
</div>
<div class="col-6">
<div class="btn-group mb-2 float-end">
<button type="button" class="btn btn-warning dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> Select Level <i class="mdi mdi-chevron-down"></i> </button>
<div class="dropdown-menu" style="">
@php
$level = $graph->level;
@endphp
@while($level > 0)
<a class="dropdown-item leaderboard-dd-level" level="{{$level}}" href="/form/metricreport?{!! http_build_query(request()->except("level"))!!}&level={{$level}}">Level {{$level}}</a>
@php
$level--;
@endphp
@endwhile
</div>
</div>
</div>
</div>
@else
<ol class="breadcrumb m-2">
<li class="breadcrumb-item"><a href="{{url()->current().'?'.http_build_query(request()->except("username", "hid","level"))}}">Your Team</a></li>
@foreach($breadcrumbs as $bc)
<li class="breadcrumb-item"><a href="{{request()->fullUrlWithQuery($bc)}}">{{$bc['username']}}</a></li>
@endforeach
</ol>
@endif
<div class="table-responsive">
<table class="table table-centered table-nowrap table-borderless mb-0" id="leaderboard-table">
<thead class="table-light">
<tr>
<th>Rank</th>
<th>User</th>
<th>Units</th>
@foreach($graph->metrics as $val)
<th>{{$val->display}}</th>
@endforeach
</tr>
</thead>
<tbody>
@php
$leader_id = '';
@endphp
@foreach($graph->values as $i => $val)
@if($leader_id != $val->user->id)
<tr hid="{{isset($val->hierarchy)?$val->hierarchy:''}}" username="{{$val->user->name}}">
<td><img src="https://ui-avatars.com/api/?background={{$i>3?$colors[4]:$colors[$i]}}&name={{$val->rank}}" class="avatar-md"></td>
<td style="text-align:left;">{{$val->user->name}} <br />{{$val->user->designation}}</td>
@if($graph->type == 'verses')
<td>{{isset($val->actual)?$val->actual:0}} / {{isset($val->target)?$val->target:0}}<br />{{round($val->score, 2)}}%</td>
@else
<td>{{round($val->score, 2)}}<br />{{$graph->values[0]->rank != 0 ? ($graph->values[0]->rank == 1 ? ($graph->values[0]->score ? ceil(($val->score/$graph->values[0]->score)*100) : 0) : ($graph->values[1]->score ? ceil(($val->score/$graph->values[1]->score)*100) : 0 ) ) : 0 }}%</td>
@endif
@foreach($graph->metrics as $m)
<td>{{ isset($val->stats->{$m->metric}) ? $val->stats->{$m->metric} : '-' }}</th>
@endforeach
</tr>
@endif
@php
$leader_id = $val->user->id;
@endphp
@endforeach
</tbody>
</table>
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($graph->type == 'simple' && $post['type'] == 'trend' && $graph->chart == 'tabular')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th>Periods</th>
<th>{{$graph->label}}</th>
</tr>
</thead>
<tbody>
@foreach($graph->values as $i => $val)
<tr>
<td>{{$val->x}}</td>
<td>{{$val->y}}</td>
</tr>
@endforeach
</tbody>
</table>
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($graph->type == 'grouped' && $post['type'] == 'trend' && $graph->chart == 'tabular')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th>Periods</th>
@foreach($graph->values as $met)
<th>{{$met->metric}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($graph->values[0]->stats as $i => $stat)
<tr>
<td>{{$stat->x}}</td>
@foreach($graph->values as $met)
<td>{{isset($met->stats[$i])?$met->stats[$i]->y:0}}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($post['type'] == 'details' && $graph->chart == 'tabular')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
@if(isset($graph->values->metrics))
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th colspan="2">User</th>
<th>Employee Code</th>
<th>Zone</th>
<th>Region</th>
<th>Area</th>
<th>Territory</th>
@foreach($graph->values->metrics as $metric)
<th>{{$metric->metric}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($graph->values->users as $user)
<tr>
<td><img src="{{isset($user->avatar) ? $user->avatar : ''}}" class="avatar-sm rounded-circle"></td>
<td>{{ $user->name }} <br/>{{$user->designation}}</td>
<td>{{ isset($user->employee_code) ? $user->employee_code:''}}</td>
<td>{{ isset($user->positions->Zone) ? $user->positions->Zone : '-' }}</td>
<td>{{ isset($user->positions->Region) ? $user->positions->Region : '-' }}</td>
<td>{{ isset($user->positions->Area) ? $user->positions->Area : '-' }}</td>
<td>{{ isset($user->positions->Territory) ? $user->positions->Territory : '-' }}</td>
@foreach($graph->values->metrics as $metric)
<td>{{ isset($metric->stats->{$user->id}) ? $metric->stats->{$user->id} : '-' }}</th>
@endforeach
</tr>
@endforeach
</tbody>
</table>
@endif
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($post['type'] == 'contacts' && $graph->chart == 'contacts')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
@if(isset($graph->values->metrics))
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th>Doctor</th>
<th>MSL Code</th>
<th>User</th>
<th>Employee Code</th>
<th>Zone</th>
<th>Region</th>
<th>Area</th>
<th>Territory</th>
@foreach($graph->values->metrics as $metric)
<th>{{$metric->metric}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($graph->values->contacts as $contact)
<tr>
<td>{{ $contact->name }}</td>
<td>{{ $contact->msl_code }}</td>
@php
if(!isset($graph->values->users->{$contact->id})) {
continue;
}
$user = $graph->values->users->{$contact->id};
@endphp
<td>{{ $user->name }} <br/>{{$user->designation}}</td>
<td>{{ isset($user->employee_code) ? $user->employee_code:''}}</td>
<td>{{ isset($user->positions->Zone) ? $user->positions->Zone : '-' }}</td>
<td>{{ isset($user->positions->Region) ? $user->positions->Region : '-' }}</td>
<td>{{ isset($user->positions->Area) ? $user->positions->Area : '-' }}</td>
<td>{{ isset($user->positions->Territory) ? $user->positions->Territory : '-' }}</td>
@foreach($graph->values->metrics as $metric)
<td>{{ isset($metric->stats->{$contact->id}) ? $metric->stats->{$contact->id} : '-' }}</th>
@endforeach
</tr>
@endforeach
</tbody>
</table>
@endif
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@default
<div id="chart-{{$graph->id}}" class="mt-0" data-colors="#f1556c"></div>
@if($post['type'] == 'value' || ($post['type'] == 'graphical' && $graph->chart = 'percentile' && $graph->type == 'simple' ))
<h5 class="text-muted mt-0">{{ $graph->type == 'simple' ? $graph->label : 'Total ' . $graph->name }}</h5>
<h2>{{$graph->value}}</h2>
@endif
@break
@endswitch
</div>
</div>
</div> <!-- end card -->
<style type="text/css">
.btn-xs {border-radius: 6px!important;}
.underline {border-bottom: 2px solid #B9B970;}
.loader{
position: absolute;
height: 100vh;
width: 100vw;
z-index: 999;
background-color: rgba(0,0,0,0.5);
padding-top: calc(50vh - 24px);
padding-left: calc(50vw - 24px);
}
</style>
<!-- end container -->
@include('layouts.shared/footer-script')
<!-- third party js -->
<script src="{{asset('assets/libs/flatpickr/flatpickr.min.js')}}"></script>
<script src="{{asset('assets/libs/apexcharts/apexcharts.min.js')}}"></script>
<!-- third party js ends -->
<script type="text/javascript">
jQuery(document).ready(function($){
$('.charttypebtn').click(function(){
$('.loader').show()
let href = new URL(window.location.href);
href.searchParams.delete('type')
href.searchParams.delete('chart')
href.searchParams.set('type', $(this).attr('charttype') );
href.searchParams.set('chart', $(this).attr('chart') );
window.location.href = href.toString()
})
$('#apply-metric-filter').click(function(){
$('.loader').show()
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
var searchIDs = $("#metric-filter-modal input:checkbox:checked").map(function(){
return $(this).val();
}).get();
href.searchParams.set('metrics', searchIDs.join(',') );
window.location.href = href.toString()
})
$('#clear-metric-filter').click(function(){
$('.loader').show()
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.delete('metrics')
window.location.href = href.toString()
})
$('.loader').hide()
$('#period').change(function(){
let href = new URL(window.location.href);
href.searchParams.set('period', $(this).val() );
$('.loader').show()
window.location.href = href.toString()
});
$('#graph-wrapper a').click(function(event) {
event.preventDefault();
$('.loader').show()
console.log($(this).attr('href'))
let href = new URL(document.location.origin + $(this).attr('href'));
href.searchParams.set('period', $('#period').val() );
window.location.href = href.toString()
});
$('.leaderboard-next').click(function(){
let href = new URL(window.location.href);
href.searchParams.set('level', {{$graph->current_level}}-1 );
window.location.href = href.toString()
})
$('.leaderboard-prev').click(function(){
let href = new URL(window.location.href);
href.searchParams.set('level', {{$graph->current_level}}+1 );
window.location.href = href.toString()
})
$('.leaderboard-dd-level').click(function(){
event.preventDefault();
$('.loader').show()
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.set('level', $(this).attr('level') );
window.location.href = href.toString()
})
$('#export').click(function(){
let href = new URL(window.location.href);
$('.loader').show()
href.searchParams.set('period', $('#period').val() );
$.get( href.origin + '/form/metricreport' + href.search + '&download=1&s3=1', function( data ) {
console.log(data)
$('.loader').hide()
$('#graph-wrapper').prepend('<div class="button-list pe-xl-4 d-grid"><a href="'+data.filename+'" download class="btn btn-primary waves-effect waves-light mt-3">Download Report</a></div>');
});
})
$('#email-export').click(function(){
let href = new URL(window.location.href);
$('.loader').show()
href.searchParams.set('period', $('#period').val() );
$.get( href.origin + '/form/metricreport' + href.search + '&download=1&email=1', function( data ) {
$('.loader').hide()
$('#graph-wrapper').prepend('<div class="alert alert-success mt-3">Email send Successfully!</div>');
});
})
@if($post['type'] == 'leaderboard')
$('.leaderboardrow').click(function(){
console.log( $(this).attr('hid') )
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.set('level', {{$graph->current_level}}-1 );
href.searchParams.set('hid', $(this).attr('hid') );
href.searchParams.set('username', $(this).attr('username') );
window.location.href = href.toString()
})
@endif
let colors = {!!json_encode($colors)!!};
colors = colors.map(c => '#'+c)
let options = {}
let chart = {}
let values = []
colors.shift()
@if($graph->type == 'grouped')
@switch($post['type'])
@case('graphical')
values = {!!json_encode($graph->values)!!}
@if($post['chart'] == 'pie')
options = {
series: values.map(a => a.value),
chart: {
width: 500,
type: 'pie',
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
labels: values.map(a => a.label),
responsive: [{
breakpoint: 480,
options: {
chart: {
width: 380
},
legend: {
position: 'bottom'
}
}
}]
};
@elseif($post['chart'] == 'bar')
options = {
series: [{
name: "{{$graph->label}}",
data: values.map(a => a.value)
}],
chart: {
height: 350,
type: '{{$post['chart']}}',
zoom: {
enabled: false
},
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
grid: {
row: {
colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
opacity: 0.5
},
},
xaxis: {
categories: values.map(a => a.label),
}
};
@endif
@break
@case('trend')
values = {!!json_encode($graph->values)!!}
options = {
series: values.map(m => {
return {
name: m.metric,
data: m.stats.map(a => a.y)
}
}),
// series: [{
// name: "{{$graph->label}}",
// data: values.map(a => a.y)
// }],
chart: {
height: 350,
type: '{{$post['chart']}}',
zoom: {
enabled: false
},
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
grid: {
row: {
colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
opacity: 0.5
},
},
xaxis: {
categories: values[0].stats.map(a => a.x),
}
};
console.log(options)
@break
@endswitch
@elseif($graph->type == 'simple')
@switch($post['type'])
@case('graphical')
options = {
series: [{{ $graph->max > 0 ? ceil(($graph->value/$graph->max)*100) : 0 }}],
chart: {
height: 250,
type: 'radialBar',
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
plotOptions: {
radialBar: {
startAngle: -90,
endAngle: 270,
hollow: {
size: '58%',
}
},
},
fill: {
type: 'gradient',
gradient: {
shade: 'dark',
shadeIntensity: 0.15,
inverseColors: false,
opacityFrom: 1,
opacityTo: 1,
stops: [0, 50, 65, 91]
},
},
stroke: {
dashArray: 7
},
colors: colors,
labels: ['{{$graph->label}}'],
};
@break
@case('trend')
values = {!!json_encode($graph->values)!!}
options = {
series: [{
name: "{{$graph->label}}",
data: values.map(a => a.y)
}],
chart: {
height: 350,
type: '{{$post['chart']}}',
zoom: {
enabled: false
},
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
grid: {
row: {
colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
opacity: 0.5
},
},
xaxis: {
categories: values.map(a => a.x),
}
};
@break
@endswitch
@endif
chart = new ApexCharts(document.querySelector("#chart-{{$graph->id}}"), options);
chart.render();
});
</script>
</body>
</html>