e29a5891c8
Reviewed-on: #5 Co-authored-by: ISMAIL MASSERAN <ismail@koppkb.com> Co-committed-by: ISMAIL MASSERAN <ismail@koppkb.com>
723 lines
31 KiB
PHP
723 lines
31 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Cawangan;
|
|
use App\Models\CawanganKpi;
|
|
use App\Models\DataKpi;
|
|
use App\Models\Jawatan;
|
|
use App\Models\Tetapan;
|
|
use App\Models\UserKaunter;
|
|
use App\Services\RingkasanHarianServices;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use PDF;
|
|
|
|
class KpiController extends Controller
|
|
{
|
|
//
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
public function janaekpi()
|
|
{
|
|
$currentDate = Carbon::now();
|
|
$currentDate = $currentDate->toDateString();
|
|
$caw = Cawangan::all();
|
|
// $bulan = Bulan::all();
|
|
// $tahun = Tahun::all();
|
|
$years = [];
|
|
for ($year = 2023; $year <= 2024; $year++) {
|
|
$years[$year] = $year;
|
|
}
|
|
$jawatan = Jawatan::all();
|
|
// dd($bulan);
|
|
$tetapan = Tetapan::where('id', '=', 1)->first();
|
|
|
|
return view('kpi.janakpi', compact('caw', 'tetapan', 'currentDate', 'years', 'jawatan'));
|
|
}
|
|
|
|
public function senaraitempkpi(Request $request)
|
|
{
|
|
$bulan = $request->month;
|
|
$tahun = $request->year;
|
|
$jawatan = $request->jawatan[0];
|
|
$mula = date('Y-m-d', strtotime("$tahun-$bulan-01")); // 2023-01-01
|
|
$hingga = date('Y-m-t', strtotime("$tahun-$bulan-01")); // 2023-01-31
|
|
|
|
if ($jawatan == 'pc') {
|
|
$cawangan_all = Cawangan::orderBy('caw_name')->get();
|
|
$nama_jawatan = Jawatan::where('idjawatan', $jawatan)->first();
|
|
$senarai = [];
|
|
foreach ($cawangan_all as $cawangan) {
|
|
|
|
$getnamapc = UserKaunter::where('cawangan', $cawangan->caw_code)
|
|
->where('role_asal', $jawatan)
|
|
->first();
|
|
$toarray = $getnamapc->toArray();
|
|
// dd($toarray['name']);
|
|
$checkExisting = CawanganKpi::where('namastaff', '=', $toarray['name'])
|
|
->where('tahun_kpi', '=', date('Y'))
|
|
->where('tahun', '=', $tahun)
|
|
->where('bulan', '=', $bulan)
|
|
->get();
|
|
// dd($checkExisting);
|
|
if ($checkExisting->isEmpty()) {
|
|
|
|
$kodcaw = $cawangan->caw_code;
|
|
// $ringkasan = new RingkasanHarianServices();
|
|
// $laporan_ringkasan = $ringkasan->getRingkasanHarian($mula,$hingga,$kodcaw);
|
|
$laporan_ringkasan = Http::get(config('app.api_url').'get/ringkasanharian/', [
|
|
'mula' => $mula,
|
|
'hingga' => $hingga,
|
|
'kodcaw' => $kodcaw,
|
|
])->json();
|
|
|
|
$data = [
|
|
'nama_staff' => $getnamapc['name'],
|
|
'nokpstaff' => $getnamapc['no_kp'],
|
|
'kodcaw' => $cawangan->caw_code,
|
|
'caw_name' => $cawangan->caw_name,
|
|
'namajawatan' => $nama_jawatan->namajawatan,
|
|
'laporan_ringkasan' => $laporan_ringkasan ? $laporan_ringkasan : '',
|
|
];
|
|
|
|
array_push($senarai, $data);
|
|
}
|
|
// dump($data);
|
|
}
|
|
} elseif ($jawatan == 'ppc') {
|
|
$cawangan_all = Cawangan::orderBy('caw_name')->get();
|
|
$nama_jawatan = Jawatan::where('idjawatan', $jawatan)->first();
|
|
$senarai = [];
|
|
foreach ($cawangan_all as $cawangan) {
|
|
$getnamapc = UserKaunter::where('cawangan', $cawangan->caw_code)
|
|
->where('role_asal', $jawatan)
|
|
->first();
|
|
$toarray = $getnamapc->toArray();
|
|
$checkExisting = CawanganKpi::where('namastaff', '=', $toarray['name'])
|
|
->where('tahun_kpi', '=', date('Y'))
|
|
->where('tahun', '=', $tahun)
|
|
->where('bulan', '=', $bulan)
|
|
->get();
|
|
// dd($checkExisting);
|
|
if ($checkExisting->isEmpty()) {
|
|
$kodcaw = $cawangan->caw_code;
|
|
// $ringkasan = new RingkasanHarianServices();
|
|
// $laporan_ringkasan = $ringkasan->getRingkasanHarian($mula,$hingga,$kodcaw);
|
|
$laporan_ringkasan = Http::get(config('app.api_url').'get/ringkasanharian/', [
|
|
'mula' => $mula,
|
|
'hingga' => $hingga,
|
|
'kodcaw' => $kodcaw,
|
|
])->json();
|
|
|
|
$aging = Http::get(config('app.api_url').'laporan/aging', [
|
|
'kodcaw' => $kodcaw,
|
|
'tahun' => $tahun,
|
|
'bulan' => $bulan,
|
|
])->json();
|
|
|
|
$data = [
|
|
// 'cawid'=>$getnamapc['name'],
|
|
'nama_staff' => $getnamapc['name'],
|
|
'nokpstaff' => $getnamapc['no_kp'],
|
|
'kodcaw' => $cawangan->caw_code,
|
|
'caw_name' => $cawangan->caw_name,
|
|
'namajawatan' => $nama_jawatan->namajawatan,
|
|
'laporan_ringkasan' => $laporan_ringkasan ? $laporan_ringkasan : '',
|
|
'aging' => $aging ? $aging : '',
|
|
];
|
|
|
|
array_push($senarai, $data);
|
|
}
|
|
}
|
|
} elseif ($jawatan == 'teller') {
|
|
$cawangan_all = Cawangan::orderBy('caw_name')->get();
|
|
$nama_jawatan = Jawatan::where('idjawatan', $jawatan)->first();
|
|
$senarai = [];
|
|
// dd($cawangan_all);
|
|
foreach ($cawangan_all as $cawangan) {
|
|
|
|
// dd($getnamapc);
|
|
|
|
$kodcaw = $cawangan->caw_code;
|
|
// $ringkasan = new RingkasanHarianServices();
|
|
// $laporan_ringkasan = $ringkasan->getRingkasanHarian($mula,$hingga,$kodcaw);
|
|
$laporan_ringkasan = Http::get(config('app.api_url').'get/ringkasanharian/', [
|
|
'mula' => $mula,
|
|
'hingga' => $hingga,
|
|
'kodcaw' => $kodcaw,
|
|
])->json();
|
|
|
|
$getnamateller = UserKaunter::where('cawangan', $cawangan->caw_code)
|
|
->where('role_asal', $jawatan)
|
|
->whereNotIn('name', ['LELONG'])
|
|
->orderBy('name', 'desc')
|
|
->get();
|
|
// dd($getnamateller);
|
|
$pluckteller = $getnamateller->pluck('name')->toArray();
|
|
$nokpstaff = $getnamateller->keyBy('no_kp')->toArray();
|
|
// dd($plucktellernokp);
|
|
$gadai = Http::get(config('app.api_url').'getLaporanGadaiRangeDatebyTeller/'.$kodcaw, [
|
|
'mula' => $mula,
|
|
'akhir' => $hingga,
|
|
'teller' => $pluckteller,
|
|
])->json();
|
|
foreach ($gadai as $index => $datateller) {
|
|
$getnokpteller = UserKaunter::where('cawangan', $cawangan->caw_code)
|
|
->where('name', $datateller['teller'])
|
|
->first();
|
|
|
|
$gadai[$index]['nokpstaff'] = $getnokpteller['no_kp'];
|
|
|
|
}
|
|
$toarray = $getnokpteller->toArray();
|
|
$checkExisting = CawanganKpi::where('namastaff', '=', $toarray['name'])
|
|
->where('tahun_kpi', '=', date('Y'))
|
|
->where('tahun', '=', $tahun)
|
|
->where('bulan', '=', $bulan)
|
|
->where('jawatan', '=', 'teller')
|
|
->get();
|
|
// dd($checkExisting);
|
|
if ($checkExisting->isEmpty()) {
|
|
$tebus = Http::get(config('app.api_url').'getLaporanTebusRangeDatebyTeller/'.$kodcaw, [
|
|
'mula' => $mula,
|
|
'akhir' => $hingga,
|
|
'teller' => $pluckteller,
|
|
])->json();
|
|
|
|
$data = [
|
|
'nokpstaff' => $nokpstaff,
|
|
'kodcaw' => $cawangan->caw_code,
|
|
'caw_name' => $cawangan->caw_name,
|
|
'namajawatan' => $nama_jawatan->namajawatan,
|
|
'laporan_ringkasan' => $laporan_ringkasan ? $laporan_ringkasan : '',
|
|
'gadai' => $gadai ? $gadai : '',
|
|
'tebus' => $tebus ? $tebus : '',
|
|
];
|
|
|
|
array_push($senarai, $data);
|
|
}
|
|
}
|
|
} elseif ($jawatan == 'penilai') {
|
|
$cawangan_all = Cawangan::orderBy('caw_name')->get();
|
|
$nama_jawatan = Jawatan::where('idjawatan', $jawatan)->first();
|
|
$senarai = [];
|
|
foreach ($cawangan_all as $cawangan) {
|
|
$kodcaw = $cawangan->caw_code;
|
|
$laporan_ringkasan = Http::get(config('app.api_url').'get/ringkasanharian/', [
|
|
'mula' => $mula,
|
|
'hingga' => $hingga,
|
|
'kodcaw' => $kodcaw,
|
|
])->json();
|
|
|
|
$gadaipenilai = Http::get(config('app.api_url').'getLaporanGadaiRangeDatebyPenilai/'.$kodcaw, [
|
|
'mula' => $mula,
|
|
'akhir' => $hingga,
|
|
])->json();
|
|
foreach ($gadaipenilai as $index => $datapenilai) {
|
|
$getnokppenilai = UserKaunter::where('cawangan', $cawangan->caw_code)
|
|
->where('name', $datapenilai['penilai'])
|
|
->first();
|
|
$gadaipenilai[$index]['nokpstaff'] = $getnokppenilai['no_kp'] ? $getnokppenilai['no_kp'] : '';
|
|
}
|
|
$toarray = $getnokppenilai->toArray();
|
|
$checkExisting = CawanganKpi::where('namastaff', '=', $toarray['name'])
|
|
->where('tahun_kpi', '=', date('Y'))
|
|
->where('tahun', '=', $tahun)
|
|
->where('bulan', '=', $bulan)
|
|
->where('jawatan', '=', 'penilai')
|
|
->get();
|
|
// dd($checkExisting);
|
|
if ($checkExisting->isEmpty()) {
|
|
$data = [
|
|
'kodcaw' => $cawangan->caw_code,
|
|
'caw_name' => $cawangan->caw_name,
|
|
'namajawatan' => $nama_jawatan->namajawatan,
|
|
'laporan_ringkasan' => $laporan_ringkasan ? $laporan_ringkasan : '',
|
|
'gadaipenilai' => $gadaipenilai ? $gadaipenilai : '',
|
|
];
|
|
|
|
array_push($senarai, $data);
|
|
}
|
|
// dd($data);
|
|
}
|
|
}
|
|
// dd($data);
|
|
|
|
// if($total_bil_lelong == 0)
|
|
// {
|
|
// return redirect()->route('notisperingatan.jananotisperingatan')
|
|
// ->with('failed','Tiada surat untuk di dijana');
|
|
// }
|
|
|
|
// dd($data);
|
|
return view('kpi.senaraitempkpi', compact(
|
|
// 'getsurat',
|
|
'senarai',
|
|
'nama_jawatan',
|
|
'tahun',
|
|
'bulan',
|
|
'jawatan'
|
|
|
|
));
|
|
}
|
|
|
|
public function savedatakpi(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
$jawatan = $request->jawatan;
|
|
$bulan = $request->bulan;
|
|
$tahun = $request->tahun;
|
|
$mula = date('Y-m-d', strtotime("$tahun-$bulan-01")); // 2023-01-01
|
|
$hingga = date('Y-m-t', strtotime("$tahun-$bulan-01")); // 2023-01-31
|
|
$current = Carbon::now();
|
|
$current = new Carbon;
|
|
$currentNow = Carbon::now();
|
|
$tarikh_savekpi = $current->toDateString();
|
|
$selected_caw = $request->kodcaw;
|
|
// dd($request->caw);
|
|
// if(!empty($selected_caw))
|
|
$cawangan_all = Cawangan::whereIn('caw_code', $selected_caw)->get();
|
|
// dd($caws);
|
|
$bil_surat = 0;
|
|
$senarai = [];
|
|
if ($jawatan == 'pc') {
|
|
$datakpi_temp_arr = [];
|
|
foreach ($request->nama_staff as $key => $datastaff) {
|
|
|
|
$checkExisting = CawanganKpi::where('namastaff', '=', $request->nama_staff[$key])
|
|
->where('tahun_kpi', '=', date('Y'))
|
|
->where('tahun', '=', $request->tahun)
|
|
->where('bulan', '=', $request->bulan)
|
|
->get();
|
|
if ($checkExisting->isEmpty()) {
|
|
$cawangan = Cawangan::where('caw_code', $request->kodcaw[$key])->first();
|
|
$caw_kpi = new CawanganKpi;
|
|
$caw_kpi->caw_id = $cawangan->id;
|
|
$caw_kpi->kodcaw = $request->kodcaw[$key];
|
|
$caw_kpi->tahun_kpi = date('Y');
|
|
$caw_kpi->tahun = $request->tahun;
|
|
$caw_kpi->bulan = $request->bulan;
|
|
$caw_kpi->jawatan = $request->jawatan;
|
|
$caw_kpi->namastaff = $request->nama_staff[$key];
|
|
$caw_kpi->nokpstaff = $request->nokpstaff[$key];
|
|
$caw_kpi->status_jana = 1;
|
|
$caw_kpi->save();
|
|
|
|
$datakpi_to_be_inserted = [
|
|
'idcawkpi' => $caw_kpi->id,
|
|
'caw_id' => $cawangan->id,
|
|
'kodcaw' => $request->kodcaw[$key],
|
|
'tahun_kpi' => date('Y'),
|
|
'tahun' => $request->tahun,
|
|
'bulan' => $request->bulan,
|
|
'jawatan' => $request->jawatan,
|
|
'namastaff' => $request->nama_staff[$key],
|
|
'nokpstaff' => $request->nokpstaff[$key],
|
|
'pc_bilpembiayaan' => $request->bilangan_gadai[$key],
|
|
'pc_pembiayaan' => $request->total_gadai[$key],
|
|
'pc_pendapatan' => $request->pendapatan[$key],
|
|
'pc_pelangganbaru' => $request->bilangan_customer_baru[$key],
|
|
'created_at' => $currentNow,
|
|
'updated_at' => $currentNow,
|
|
];
|
|
|
|
array_push($datakpi_temp_arr, $datakpi_to_be_inserted);
|
|
} else {
|
|
return redirect()
|
|
->route('janakpi.janaekpi')
|
|
->with('failed', 'Maaf, Bulan dan Tahun KPI bagi nama staff ini telah wujud dalam db.');
|
|
}
|
|
|
|
}
|
|
DataKpi::insert($datakpi_temp_arr);
|
|
|
|
} elseif ($jawatan == 'ppc') {
|
|
$datakpi_temp_arr = [];
|
|
foreach ($request->nama_staff as $key => $datastaff) {
|
|
$checkExisting = CawanganKpi::where('namastaff', '=', $request->nama_staff[$key])
|
|
->where('tahun_kpi', '=', date('Y'))
|
|
->where('tahun', '=', $request->tahun)
|
|
->where('bulan', '=', $request->bulan)
|
|
->get();
|
|
if ($checkExisting->isEmpty()) {
|
|
$cawangan = Cawangan::where('caw_code', $request->kodcaw[$key])->first();
|
|
// dd($cawangan);
|
|
$caw_kpi = new CawanganKpi;
|
|
$caw_kpi->caw_id = $cawangan->id;
|
|
$caw_kpi->kodcaw = $request->kodcaw[$key];
|
|
$caw_kpi->tahun_kpi = date('Y');
|
|
$caw_kpi->tahun = $request->tahun;
|
|
$caw_kpi->bulan = $request->bulan;
|
|
$caw_kpi->jawatan = $request->jawatan;
|
|
$caw_kpi->namastaff = $request->nama_staff[$key];
|
|
$caw_kpi->nokpstaff = $request->nokpstaff[$key];
|
|
$caw_kpi->status_jana = 1;
|
|
$caw_kpi->save();
|
|
|
|
$datakpi_to_be_inserted = [
|
|
'idcawkpi' => $caw_kpi->id,
|
|
'caw_id' => $cawangan->id,
|
|
'kodcaw' => $request->kodcaw[$key],
|
|
'tahun_kpi' => date('Y'),
|
|
'tahun' => $request->tahun,
|
|
'bulan' => $request->bulan,
|
|
'jawatan' => $request->jawatan,
|
|
'namastaff' => $request->nama_staff[$key],
|
|
'nokpstaff' => $request->nokpstaff[$key],
|
|
'ppc_aging1' => $request->aging1[$key],
|
|
'ppc_aging2' => $request->aging2[$key],
|
|
'ppc_aging3' => $request->aging3[$key],
|
|
'ppc_penebusan' => $request->total_tebus[$key],
|
|
'created_at' => $currentNow,
|
|
'updated_at' => $currentNow,
|
|
];
|
|
|
|
array_push($datakpi_temp_arr, $datakpi_to_be_inserted);
|
|
|
|
} else {
|
|
return redirect()
|
|
->route('janakpi.janaekpi')
|
|
->with('failed', 'Maaf, Bulan dan Tahun KPI bagi nama staff ini telah wujud dalam db.');
|
|
}
|
|
}
|
|
DataKpi::insert($datakpi_temp_arr);
|
|
} elseif ($jawatan == 'teller') {
|
|
// dd($request->all());
|
|
$datakpi_temp_arr = [];
|
|
foreach ($request->nama_staff as $key => $datastaff) {
|
|
$checkExisting = CawanganKpi::where('namastaff', '=', $request->nama_staff[$key])
|
|
->where('tahun_kpi', '=', date('Y'))
|
|
->where('tahun', '=', $request->tahun)
|
|
->where('bulan', '=', $request->bulan)
|
|
->where('jawatan', '=', $request->jawatan)
|
|
->get();
|
|
if ($checkExisting->isEmpty()) {
|
|
$cawangan = Cawangan::where('caw_code', $request->kodcaw[$key])->first();
|
|
$caw_kpi = new CawanganKpi;
|
|
$caw_kpi->caw_id = $cawangan->id;
|
|
$caw_kpi->kodcaw = $request->kodcaw[$key];
|
|
$caw_kpi->tahun_kpi = date('Y');
|
|
$caw_kpi->tahun = $request->tahun;
|
|
$caw_kpi->bulan = $request->bulan;
|
|
$caw_kpi->jawatan = $request->jawatan;
|
|
$caw_kpi->namastaff = $request->nama_staff[$key];
|
|
$caw_kpi->nokpstaff = $request->nokpstaff[$key];
|
|
$caw_kpi->status_jana = 1;
|
|
$caw_kpi->save();
|
|
|
|
$datakpi_to_be_inserted = [
|
|
'idcawkpi' => $caw_kpi->id,
|
|
'caw_id' => $cawangan->id,
|
|
'kodcaw' => $request->kodcaw[$key],
|
|
'tahun_kpi' => date('Y'),
|
|
'tahun' => $request->tahun,
|
|
'bulan' => $request->bulan,
|
|
'jawatan' => $request->jawatan,
|
|
'namastaff' => $request->nama_staff[$key],
|
|
'nokpstaff' => $request->nokpstaff[$key],
|
|
'teller_bilgadai' => $request->total_gadai[$key],
|
|
'teller_pembiayaan' => $request->total_pembiayaan[$key],
|
|
'teller_biltebus' => $request->total_tebus[$key],
|
|
'teller_tebuspembiayaan' => $request->total_penebusan[$key],
|
|
'created_at' => $currentNow,
|
|
'updated_at' => $currentNow,
|
|
];
|
|
|
|
array_push($datakpi_temp_arr, $datakpi_to_be_inserted);
|
|
|
|
} else {
|
|
return redirect()
|
|
->route('janakpi.janaekpi')
|
|
->with('failed', 'Maaf, Bulan dan Tahun KPI bagi nama staff ini telah wujud dalam db.');
|
|
}
|
|
}
|
|
DataKpi::insert($datakpi_temp_arr);
|
|
} elseif ($jawatan == 'penilai') {
|
|
// dd($request->all());
|
|
$datakpi_temp_arr = [];
|
|
foreach ($request->nama_staff as $key => $datastaff) {
|
|
$checkExisting = CawanganKpi::where('namastaff', '=', $request->nama_staff[$key])
|
|
->where('tahun_kpi', '=', date('Y'))
|
|
->where('tahun', '=', $request->tahun)
|
|
->where('bulan', '=', $request->bulan)
|
|
->where('jawatan', '=', $request->jawatan)
|
|
->get();
|
|
if ($checkExisting->isEmpty()) {
|
|
$cawangan = Cawangan::where('caw_code', $request->kodcaw[$key])->first();
|
|
$caw_kpi = new CawanganKpi;
|
|
$caw_kpi->caw_id = $cawangan->id;
|
|
$caw_kpi->kodcaw = $request->kodcaw[$key];
|
|
$caw_kpi->tahun_kpi = date('Y');
|
|
$caw_kpi->tahun = $request->tahun;
|
|
$caw_kpi->bulan = $request->bulan;
|
|
$caw_kpi->jawatan = $request->jawatan;
|
|
$caw_kpi->namastaff = $request->nama_staff[$key];
|
|
$caw_kpi->nokpstaff = $request->nokpstaff[$key];
|
|
$caw_kpi->status_jana = 1;
|
|
$caw_kpi->save();
|
|
|
|
$datakpi_to_be_inserted = [
|
|
'idcawkpi' => $caw_kpi->id,
|
|
'caw_id' => $cawangan->id,
|
|
'kodcaw' => $request->kodcaw[$key],
|
|
'tahun_kpi' => date('Y'),
|
|
'tahun' => $request->tahun,
|
|
'bulan' => $request->bulan,
|
|
'jawatan' => $request->jawatan,
|
|
'namastaff' => $request->nama_staff[$key],
|
|
'nokpstaff' => $request->nokpstaff[$key],
|
|
'penilai_bilgadai' => $request->total_gadai[$key],
|
|
'penilai_pembiayaan' => $request->total_pembiayaan[$key],
|
|
'created_at' => $currentNow,
|
|
'updated_at' => $currentNow,
|
|
];
|
|
|
|
array_push($datakpi_temp_arr, $datakpi_to_be_inserted);
|
|
|
|
} else {
|
|
return redirect()
|
|
->route('janakpi.janaekpi')
|
|
->with('failed', 'Maaf, Bulan dan Tahun KPI bagi nama staff ini telah wujud dalam db.');
|
|
}
|
|
}
|
|
DataKpi::insert($datakpi_temp_arr);
|
|
}
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// return redirect()->route('janakpi.janaekpi')->with('failed','Tiada surat untuk di jana');
|
|
// }
|
|
|
|
return redirect()->route('janakpi.janaekpi')
|
|
->with('success', 'Berjaya Daftar KPI '.$jawatan.' ('.$bulan.'/'.$tahun.')');
|
|
// return redirect()->route('analisa.senaraisimulasi')->with('success',"Success daftar simulasi!");
|
|
|
|
}
|
|
|
|
public function listdatakpi()
|
|
{
|
|
$tahunkpi = date('Y');
|
|
$senarai = [];
|
|
$cawangan_all = Cawangan::with(['cawanganKpi'])
|
|
->withCount(['cawanganKpi' => function ($query) use ($tahunkpi) {
|
|
$query->where('tahun_kpi', $tahunkpi);
|
|
}])
|
|
->orderBy('caw_name', 'ASC')
|
|
->get();
|
|
foreach ($cawangan_all as $index3 => $cawangan) {
|
|
|
|
$getnamastaff = CawanganKpi::where('kodcaw', $cawangan->caw_code)
|
|
->groupBy('nokpstaff')
|
|
->get();
|
|
$kodcaw = $cawangan->caw_code;
|
|
|
|
$data = [
|
|
'namastaff' => $getnamastaff->toArray(),
|
|
'nokpstaff' => $getnamastaff->toArray(),
|
|
];
|
|
|
|
array_push($senarai, $data);
|
|
// dd($data);
|
|
|
|
$cawangan_all_groupby_caw = $cawangan->groupBy('caw_code');
|
|
|
|
$cawangan_all[$index3]['cawangan_info'] = $cawangan;
|
|
$cawangan_all[$index3]['namastaff'] = $getnamastaff;
|
|
}
|
|
|
|
return view('kpi.datakpibycaw', compact('cawangan_all', 'senarai'));
|
|
}
|
|
|
|
public function listdatakpidetail($nokpstaff, $kodcaw, Request $request)
|
|
{
|
|
$getnamastaff = CawanganKpi::where('kodcaw', $kodcaw)
|
|
->where('nokpstaff', $nokpstaff)
|
|
->first();
|
|
// dd($getnamastaff);
|
|
$jawatan = Jawatan::where('idjawatan', $getnamastaff->jawatan)
|
|
->get();
|
|
$bycaw_all = CawanganKpi::with(['cawangan', 'dataKpi' => function ($query) use ($jawatan) {
|
|
$query->where('jawatan', $jawatan[0]['idjawatan'])
|
|
->orderByRaw('CONVERT(bulan, SIGNED) asc')
|
|
->orderByRaw('CONVERT(tahun, SIGNED) asc');
|
|
}])
|
|
->where('nokpstaff', $nokpstaff)
|
|
->where('kodcaw', $kodcaw)
|
|
->where('jawatan', $jawatan[0]['idjawatan'])
|
|
->get();
|
|
|
|
foreach ($bycaw_all as $index3 => $listbatch) {
|
|
$bycaw_all_groupby_caw = $listbatch->groupBy('lelong_id');
|
|
$bycaw_all[$index3]['datakpi_info'] = $listbatch->dataKpi;
|
|
$bycaw_all[$index3]['nama_caw'] = $listbatch->cawangan->caw_name;
|
|
}
|
|
|
|
return view('kpi.datakpibycawdetail', compact('getnamastaff', 'bycaw_all', 'jawatan', 'kodcaw'));
|
|
|
|
}
|
|
|
|
public function checkpenilai($nokpstaff, $jawatan)
|
|
{
|
|
|
|
$getnamastaff = CawanganKpi::where('nokpstaff', $nokpstaff)
|
|
->where('jawatan', $jawatan)
|
|
->first();
|
|
// dd($getnamastaff);
|
|
$jawatan = Jawatan::where('idjawatan', $jawatan)
|
|
->get();
|
|
// dd($jawatan);
|
|
$kodcaw = $getnamastaff['kodcaw'];
|
|
$bycaw_all = CawanganKpi::with(['cawangan', 'dataKpi' => function ($query) use ($jawatan) {
|
|
$query->where('jawatan', $jawatan[0]['idjawatan']);
|
|
}])
|
|
->where('nokpstaff', $nokpstaff)
|
|
->where('kodcaw', $kodcaw)
|
|
->where('jawatan', $jawatan[0]['idjawatan'])
|
|
->get();
|
|
// dd($bycaw_all);
|
|
foreach ($bycaw_all as $index3 => $listbatch) {
|
|
// dd($listbatch->toArray());
|
|
$bycaw_all_groupby_caw = $listbatch->groupBy('lelong_id');
|
|
$bycaw_all[$index3]['datakpi_info'] = $listbatch->dataKpi;
|
|
$bycaw_all[$index3]['nama_caw'] = $listbatch->cawangan->caw_name;
|
|
// $bycaw_all[$index3]["nama_caw"] = $listbatch->cawangan;
|
|
}
|
|
|
|
// dd($bycaw_all);
|
|
return view('kpi.datakpibycawdetail', compact('getnamastaff', 'bycaw_all', 'jawatan'));
|
|
|
|
}
|
|
|
|
public function listdatakpidetail2($nokpstaff, $kodcaw, Request $request)
|
|
{
|
|
$namacaw = Cawangan::where('caw_code', $kodcaw)->first();
|
|
$getnamastaff = CawanganKpi::where('kodcaw', $kodcaw)
|
|
->where('nokpstaff', $nokpstaff)
|
|
->first();
|
|
// dd($getnamastaff);
|
|
$jawatan1 = Jawatan::where('idjawatan', $request->jawatan)
|
|
->get();
|
|
$jawatan = $request->jawatan;
|
|
// dd($jawatan[0]);
|
|
|
|
$bycaw_all = CawanganKpi::with(['cawangan', 'dataKpi' => function ($query) use ($jawatan) {
|
|
$query->where('jawatan', $jawatan);
|
|
}])
|
|
->where('nokpstaff', $nokpstaff)
|
|
->where('kodcaw', $kodcaw)
|
|
->where('jawatan', $request->jawatan)
|
|
->get();
|
|
// dd($bycaw_all);
|
|
|
|
foreach ($bycaw_all as $index3 => $listbatch) {
|
|
// dd($listbatch->toArray());
|
|
$bycaw_all_groupby_caw = $listbatch->groupBy('lelong_id');
|
|
$bycaw_all[$index3]['datakpi_info'] = $listbatch->dataKpi;
|
|
$bycaw_all[$index3]['nama_caw'] = $listbatch->cawangan->caw_name;
|
|
$bycaw_all[$index3]['jawatan1'] = $jawatan1;
|
|
// $bycaw_all[$index3]["nama_caw"] = $listbatch->cawangan;
|
|
}
|
|
if ($request->type == 'excel') {
|
|
|
|
return view('kpi.datakpibycawdetail_excel', compact('getnamastaff', 'bycaw_all', 'jawatan', 'kodcaw', 'jawatan1'));
|
|
|
|
} else {
|
|
$pdf = PDF::loadView('kpi.datakpibycawdetail_pdf', compact('getnamastaff', 'bycaw_all', 'jawatan', 'kodcaw', 'jawatan1', 'namacaw'))
|
|
->setPaper('a4', 'potrait');
|
|
|
|
return $pdf->download('Data KPI '.$getnamastaff->namastaff.'.pdf');
|
|
}
|
|
}
|
|
|
|
public function listdatakpidetailall($kodcaw, Request $request)
|
|
{
|
|
$kodcaw = $kodcaw;
|
|
$getnamastaff = CawanganKpi::where('kodcaw', $kodcaw)
|
|
->groupBy('jawatan', 'nokpstaff')
|
|
->orderBy('namastaff')
|
|
->get();
|
|
$getdatakpi = DataKpi::where('kodcaw', $kodcaw)
|
|
// ->groupBy('jawatan','nokpstaff')
|
|
->orderByRaw('CONVERT(bulan, SIGNED) asc')
|
|
->orderByRaw('CONVERT(tahun, SIGNED) asc')
|
|
// ->select('namastaff','jawatan','bulan')
|
|
->get();
|
|
$groupby_nama = $getdatakpi->groupby('namastaff');
|
|
$collection_datakpi = Collect();
|
|
foreach ($groupby_nama as $index => $nama) {
|
|
$groupby_jawatan = $nama->groupBy('jawatan');
|
|
$collection_datakpi->push($groupby_jawatan);
|
|
$groupby_nama[$index]['jawatan'] = $groupby_jawatan;
|
|
}
|
|
|
|
return view('kpi.datakpibycawdetailall', compact('collection_datakpi', 'kodcaw'));
|
|
}
|
|
|
|
public function listdatakpidetailall2($kodcaw, Request $request)
|
|
{
|
|
$namacaw = Cawangan::where('caw_code', $kodcaw)->first();
|
|
$getnamastaff = CawanganKpi::where('kodcaw', $kodcaw)
|
|
->groupBy('jawatan', 'nokpstaff')
|
|
->orderBy('namastaff')
|
|
->get();
|
|
$getdatakpi = DataKpi::where('kodcaw', $kodcaw)
|
|
->orderByRaw('CONVERT(bulan, SIGNED) asc')
|
|
->orderByRaw('CONVERT(tahun, SIGNED) asc')
|
|
->get();
|
|
$groupby_nama = $getdatakpi->groupby('namastaff');
|
|
$collection_datakpi = Collect();
|
|
foreach ($groupby_nama as $index => $nama) {
|
|
$groupby_jawatan = $nama->groupBy('jawatan');
|
|
$collection_datakpi->push($groupby_jawatan);
|
|
$groupby_nama[$index]['jawatan'] = $groupby_jawatan;
|
|
}
|
|
|
|
if ($request->type == 'excel') {
|
|
|
|
return view('kpi.datakpibycawdetailall_excel', compact('collection_datakpi', 'kodcaw'));
|
|
|
|
} else {
|
|
$pdf = PDF::loadView('kpi.datakpibycawdetailall_pdf', compact('collection_datakpi', 'kodcaw', 'namacaw'))
|
|
->setPaper('a4', 'potrait');
|
|
|
|
return $pdf->download('Data KPI Keseluruhan'.$kodcaw.'.pdf');
|
|
}
|
|
|
|
return view('kpi.datakpibycawdetailall', compact('collection_datakpi'));
|
|
|
|
}
|
|
|
|
public function hapusdatakpi($recno)
|
|
{
|
|
$datastaff = DataKpi::where('id', '=', $recno)
|
|
->get();
|
|
$datastafftoarray = $datastaff->toArray();
|
|
$nokpstaff = $datastafftoarray[0]['nokpstaff'];
|
|
$kodcaw = $datastafftoarray[0]['kodcaw'];
|
|
$idcawkpi = $datastafftoarray[0]['idcawkpi'];
|
|
// dd($idcawkpi);
|
|
|
|
$caw = DataKpi::where('id', '=', $recno);
|
|
$caw->delete();
|
|
$caw1 = CawanganKpi::where('id', '=', $idcawkpi);
|
|
$caw1->delete();
|
|
$checkExisting = CawanganKpi::where('nokpstaff', '=', $nokpstaff)
|
|
->where('kodcaw', '=', $kodcaw)
|
|
->get();
|
|
// dd($checkExisting);
|
|
if ($checkExisting->isEmpty()) {
|
|
return redirect()->route('janakpi.listdatakpi')
|
|
->with('success', 'Data '.$kodcaw.' Berjaya Dihapuskan');
|
|
} else {
|
|
return redirect()->route('janakpi.listdatakpidetail', ['nokpstaff' => $nokpstaff, 'kodcaw' => $kodcaw])
|
|
->with('success', 'Data '.$kodcaw.' Berjaya Dihapuskan');
|
|
}
|
|
}
|
|
}
|