450 lines
17 KiB
PHP
450 lines
17 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
use App\Models\{Kuesioner, Pertanyaan, Summary, Temp, Dimension, Answer, Kritik};
|
|
|
|
use Carbon\Carbon;
|
|
use DataTables;
|
|
|
|
class KuesionerController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = Kuesioner::select('*');
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('is_status', function($row){
|
|
if ($row->status == 1) {
|
|
return '<span class="mb-1 badge font-medium bg-primary text-white py-2 px-3 fs-7">Aktif</span>';
|
|
} else {
|
|
return '<span class="mb-1 badge font-medium bg-light text-dark py-2 px-3 fs-7">Tidak</span>';
|
|
}
|
|
})
|
|
->addColumn('publish', function($row){
|
|
if ($row->is_publish == 1) {
|
|
return '<span class="mb-1 badge font-medium bg-primary text-white py-2 px-3 fs-7">Publish</span>';
|
|
} else {
|
|
return '<span class="mb-1 badge font-medium bg-light text-dark py-2 px-3 fs-7">Draft</span>';
|
|
}
|
|
})
|
|
->rawColumns(['is_status', 'publish'])
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Kuesioner',
|
|
'button' => true,
|
|
'module' => [
|
|
'url' => route('kuesioner.create'),
|
|
'name' => 'Tambah baru'
|
|
]
|
|
];
|
|
|
|
return view('admin.app.content.kuesioner.index', compact('data'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$data = [
|
|
'subtitle' => 'Tambah baru',
|
|
];
|
|
|
|
return view('admin.app.content.kuesioner.add', compact('data'));
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'start_periode' => 'required',
|
|
'end_periode' => 'required',
|
|
'status' => 'required',
|
|
'is_publish' => 'required',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return redirect()->back()->with('error', 'Unexpected error, please try again')->withInput();
|
|
}
|
|
|
|
$input = $request->all();
|
|
|
|
$post = new Kuesioner([
|
|
'start_periode' => $input['start_periode'],
|
|
'end_periode' => $input['end_periode'],
|
|
'status' => $input['status'],
|
|
'is_publish' => $input['is_publish'],
|
|
]);
|
|
|
|
$check = Kuesioner::where('start_periode', $input['start_periode'])->where('end_periode', $input['end_periode'])->count();
|
|
if ($check == 0) {
|
|
if ($post->save()) {
|
|
return redirect()->route('kuesioner')->with('success', 'You have successfully added data');
|
|
} else {
|
|
return redirect()->route('kuesioner')->with('error', 'Unexpected error, please try again');
|
|
}
|
|
} else {
|
|
return redirect()->route('kuesioner')->with('error', 'Data already exists');
|
|
}
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$data = [
|
|
'subtitle' => 'Edit Kuesioner',
|
|
];
|
|
$kuesioner = Kuesioner::FindOrFail($id);
|
|
|
|
return view('admin.app.content.kuesioner.edit', compact('data','kuesioner', 'id'));
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
// Validasi input sebelum memperbarui data
|
|
$validator = Validator::make($request->all(), [
|
|
'start_periode' => 'required',
|
|
'end_periode' => 'required',
|
|
'status' => 'required',
|
|
'is_publish' => 'required',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return redirect()->back()->withInput()->with('error', 'Unexpected error, please try again');
|
|
}
|
|
|
|
// Cari data berdasarkan ID
|
|
$post = Kuesioner::find($id);
|
|
|
|
// Jika data ditemukan
|
|
if ($post) {
|
|
|
|
// Update data dengan data baru dari form yang telah dibersihkan
|
|
$post->update($request->all());
|
|
// Simpan perubahan pada database
|
|
$post->save();
|
|
return redirect()->route('kuesioner')->with('success', 'You are successfully modify data');
|
|
} else {
|
|
return redirect()->route('kuesioner')->with('error', 'Data not found');
|
|
}
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
// Cari data berdasarkan ID
|
|
$post = Kuesioner::find($id);
|
|
// Jika data ditemukan
|
|
if ($post) {
|
|
// Hapus data dari database
|
|
$post->delete();
|
|
return redirect()->route('kuesioner')->with('success', 'You are successfully deleted records');
|
|
} else {
|
|
return redirect()->route('kuesioner')->with('error', 'Data not found');
|
|
}
|
|
}
|
|
|
|
public function pertanyaan(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = Pertanyaan::select('*');
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('dimension', function($row){
|
|
return $row->dimension->title;
|
|
})
|
|
->rawColumns(['dimension'])
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Pertanyaan',
|
|
'button' => true,
|
|
'module' => [
|
|
'url' => route('pertanyaan.create'),
|
|
'name' => 'Tambah baru'
|
|
]
|
|
];
|
|
|
|
return view('admin.app.content.pertanyaan.index', compact('data'));
|
|
}
|
|
|
|
public function createPertanyaan()
|
|
{
|
|
$data = [
|
|
'subtitle' => 'Tambah baru',
|
|
];
|
|
|
|
return view('admin.app.content.pertanyaan.add', compact('data'));
|
|
}
|
|
|
|
public function storePertanyaan(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'question' => 'required',
|
|
'dimension_id' => 'required',
|
|
'questionnaire_id' => 'required',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return redirect()->back()->with('error', 'Unexpected error, please try again')->withInput();
|
|
}
|
|
|
|
$input = $request->all();
|
|
|
|
$post = new Pertanyaan([
|
|
'question' => $input['question'],
|
|
'dimension_id' => $input['dimension_id'],
|
|
'questionnaire_id' => $input['questionnaire_id'],
|
|
]);
|
|
|
|
$check = Pertanyaan::where('question', $input['question'])->where('dimension_id', $input['dimension_id'])->where('questionnaire_id', $input['questionnaire_id'])->count();
|
|
if ($check == 0) {
|
|
if ($post->save()) {
|
|
return redirect()->route('pertanyaan')->with('success', 'You have successfully added data');
|
|
} else {
|
|
return redirect()->route('pertanyaan')->with('error', 'Unexpected error, please try again');
|
|
}
|
|
} else {
|
|
return redirect()->route('pertanyaan')->with('error', 'Data already exists');
|
|
}
|
|
}
|
|
|
|
public function editPertanyaan($id)
|
|
{
|
|
$data = [
|
|
'subtitle' => 'Edit Pertanyaan',
|
|
];
|
|
$detail = Pertanyaan::FindOrFail($id);
|
|
|
|
return view('admin.app.content.pertanyaan.edit', compact('data','detail', 'id'));
|
|
}
|
|
|
|
public function updatePertanyaan(Request $request, $id)
|
|
{
|
|
// Validasi input sebelum memperbarui data
|
|
$validator = Validator::make($request->all(), [
|
|
'question' => 'required',
|
|
'dimension_id' => 'required',
|
|
'questionnaire_id' => 'required',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return redirect()->back()->withInput()->with('error', 'Unexpected error, please try again');
|
|
}
|
|
|
|
// Cari data berdasarkan ID
|
|
$post = Pertanyaan::find($id);
|
|
|
|
// Jika data ditemukan
|
|
if ($post) {
|
|
|
|
// Update data dengan data baru dari form yang telah dibersihkan
|
|
$post->update($request->all());
|
|
// Simpan perubahan pada database
|
|
$post->save();
|
|
return redirect()->route('pertanyaan')->with('success', 'You are successfully modify data');
|
|
} else {
|
|
return redirect()->route('pertanyaan')->with('error', 'Data not found');
|
|
}
|
|
}
|
|
|
|
public function destroyPertanyaan($id)
|
|
{
|
|
// Cari data berdasarkan ID
|
|
$post = Pertanyaan::find($id);
|
|
// Jika data ditemukan
|
|
if ($post) {
|
|
// Hapus data dari database
|
|
$post->delete();
|
|
return redirect()->route('pertanyaan')->with('success', 'You are successfully deleted records');
|
|
} else {
|
|
return redirect()->route('pertanyaan')->with('error', 'Data not found');
|
|
}
|
|
}
|
|
|
|
public function detail(Request $request, $id)
|
|
{
|
|
$kuesioner = Kuesioner::find($id);
|
|
if($kuesioner) {
|
|
if ($request->ajax()) {
|
|
$data = Pertanyaan::where('questionnaire_id', $id)->get();
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('dimension', function($row){
|
|
return $row->dimension->title;
|
|
})
|
|
->rawColumns(['dimension'])
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Detail Kuesioner'
|
|
];
|
|
|
|
$datas = Temp::where('questionnaire_id', $kuesioner->id)->get();
|
|
$puas = 0;
|
|
$sangatPuas = 0;
|
|
$tidakPuas = 0;
|
|
if (!empty($datas)) {
|
|
foreach ($datas as $value) {
|
|
$expectation_average = round(($value->sum_total_answerer > 0 ? ($value->sum_expectation_answer/$value->sum_total_answerer) : 0), 2);
|
|
$reality_average = round(($value->sum_total_answerer > 0 ? ($value->sum_reality_answer/$value->sum_total_answerer) : 0), 2);
|
|
$gap5 = $value->sum_total_answerer > 0 ? $reality_average-$expectation_average : 0;
|
|
$rating = '';
|
|
if($gap5 == 0) {
|
|
$rating = 'Puas terhadap layanan';
|
|
$puas += 1;
|
|
} elseif($gap5 > 0) {
|
|
$rating = 'Sangat puas terhadap layanan (diskrepansi)';
|
|
$sangatPuas += 1;
|
|
} elseif($gap5 < 0) {
|
|
$rating = 'Kurang puas terhadap layanan';
|
|
$tidakPuas += 1;
|
|
}
|
|
}
|
|
} else {
|
|
$puas = 0;
|
|
$sangatPuas = 0;
|
|
$tidakPuas = 0;
|
|
}
|
|
|
|
return view('admin.app.content.kuesioner.detail', compact('data', 'kuesioner', 'id', 'puas', 'sangatPuas', 'tidakPuas'));
|
|
} else {
|
|
return redirect()->back()->with('error', 'Data kuesioner not found');
|
|
}
|
|
}
|
|
|
|
public function answer(Request $request)
|
|
{
|
|
$kuesioner = $request->get('kuesioner');
|
|
$pertanyaan = Pertanyaan::where('question', $kuesioner)->first();
|
|
if($pertanyaan) {
|
|
$get_data = Summary::where('question_id', $pertanyaan->id);
|
|
|
|
if($get_data->count() > 0) {
|
|
$fetch_data = $get_data->get();
|
|
|
|
$total_answere = 0;
|
|
$total_expectation_point = 0;
|
|
$total_reality_point = 0;
|
|
$temp_expectation = [];
|
|
$temp_reality = [];
|
|
foreach($fetch_data as $value) {
|
|
if($value->type == 'expectation') {
|
|
array_push($temp_expectation, $value);
|
|
$total_expectation_point = $total_expectation_point + $value->sum_total_point;
|
|
}else if($value->type == 'reality') {
|
|
array_push($temp_reality, $value);
|
|
$total_reality_point = $total_reality_point + $value->sum_total_point;
|
|
$total_answere = $total_answere + $value->sum_total_answerer;
|
|
}
|
|
}
|
|
|
|
$temp_gap_expectation[1] = 0;
|
|
$temp_gap_expectation[2] = 0;
|
|
$temp_gap_expectation[3] = 0;
|
|
$temp_gap_expectation[4] = 0;
|
|
$temp_gap_expectation[5] = 0;
|
|
|
|
$temp_gap_reality[1] = 0;
|
|
$temp_gap_reality[2] = 0;
|
|
$temp_gap_reality[3] = 0;
|
|
$temp_gap_reality[4] = 0;
|
|
$temp_gap_reality[5] = 0;
|
|
|
|
foreach($temp_expectation as $value) {
|
|
$temp_gap_expectation[$value->gap] = $temp_gap_expectation[$value->gap] + $value->sum_total_answerer;
|
|
}
|
|
|
|
foreach($temp_reality as $value) {
|
|
$temp_gap_reality[$value->gap] = $temp_gap_reality[$value->gap] + $value->sum_total_answerer;
|
|
}
|
|
|
|
$data = [
|
|
'expectation' => $temp_gap_expectation,
|
|
'reality' => $temp_gap_reality,
|
|
'total_expectation_point' => $total_expectation_point,
|
|
'total_reality_point' => $total_reality_point,
|
|
'total_answere' => $total_answere
|
|
];
|
|
|
|
$bobot_harapan = "(1x{$data['expectation'][1]}) + (2x{$data['expectation'][2]}) + (3x{$data['expectation'][3]}) + (4x{$data['expectation'][4]}) + (5x{$data['expectation'][5]}) = {$data['total_expectation_point']}";
|
|
$bobot_kenyataan = "(1x{$data['reality'][1]}) + (2x{$data['reality'][2]}) + (3x{$data['reality'][3]}) + (4x{$data['reality'][4]}) + (5x{$data['reality'][5]}) = {$data['total_reality_point']}";
|
|
$rerata_kenyataan = $data['total_reality_point'] / $data['total_answere'] . " = " . $data['total_reality_point']/$data['total_answere'];
|
|
$nilai_gap = $data['total_reality_point'] / $data['total_answere'] - $data['total_expectation_point'] / $data['total_answere'] . " = " . ($data['total_reality_point'] / $data['total_answere']) - ($data['total_expectation_point'] / $data['total_answere']);
|
|
$rerata_harapan = $data['total_expectation_point'] / $data['total_answere'] . " = " . ($data['total_expectation_point'] / $data['total_answere']);
|
|
|
|
return "
|
|
<table class='table table-bordered'>
|
|
<tr class='bg-info text-center text-white'>
|
|
<th>Pertanyaan</th>
|
|
</tr>
|
|
<tr class='text-center'>
|
|
<th><i>{$pertanyaan->question}</i></th>
|
|
</tr>
|
|
<tr class='bg-primary text-center text-white'>
|
|
<th>Detail Perhitungan</th>
|
|
</tr>
|
|
<tr>
|
|
<td>Bobot Harapan = $bobot_harapan</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Rerata Harapan = $rerata_harapan</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Bobot Kenyataan = $bobot_kenyataan</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Rerata Kenyataan = $rerata_kenyataan</td>
|
|
</tr>
|
|
<tr>
|
|
<td class='bg-dark text-white'><b>Nilai GAP 5 = $nilai_gap</b></td>
|
|
</tr>
|
|
";
|
|
} else {
|
|
return '<div class="alert alert-danger text-center">Detail not found</div>';
|
|
}
|
|
} else {
|
|
return '<div class="alert alert-danger text-center">Question not found</div>';
|
|
}
|
|
}
|
|
|
|
public function kritik(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = Kritik::select('*');
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('created', function($row){
|
|
return Carbon::parse($row->created_at)->format('j F Y, H:i');
|
|
})
|
|
->addColumn('sender', function($row){
|
|
return \App\Models\User::where('id', $row->id_user)->first()->name;
|
|
})
|
|
->rawColumns(['created', 'sender'])
|
|
->filter(function ($query) use ($request) {
|
|
if ($request->has('search')) {
|
|
$search = $request->get('search')['value'];
|
|
if(!empty($search)) {
|
|
$query->where('description', 'LIKE', "%$search%");
|
|
} else {
|
|
$query->get();
|
|
}
|
|
}
|
|
})
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Kritik & Saran'
|
|
];
|
|
|
|
return view('admin.app.content.kuesioner.kritik', compact('data'));
|
|
}
|
|
}
|