public function table(Request $request)
{
$order = $request->input('columns');
$tahun_st = date('Y');
if($order[9]['search']['value']){
$tahun_st = $order[9]['search']['value'];
}
if($tahun_st == null || $tahun_st == ''){
$tahun_st = date('Y');
}
$data = DB::table('pegawais')->select('pegawais.*')
->selectRAW('SUM(surat_tugas_nominatifs.jml_hari) as jumlah_hari')
->selectRAW('SUM(surat_tugas_nominatifs.tiket + surat_tugas_nominatifs.taksi_tujuan + surat_tugas_nominatifs.taksi_awal + surat_tugas_nominatifs.trans_short_dist + surat_tugas_nominatifs.transport_lokal :: DOUBLE PRECISION) AS transport')
->selectRAW('sum(COALESCE(surat_tugas_nominatifs.lama_inap * surat_tugas_nominatifs.cost_inap)) as penginapan')
->selectRAW('SUM (CASE WHEN surat_tugass.jenis_st_id = 5 THEN COALESCE (surat_tugas_nominatifs.uang_rapat * (( 100 - surat_tugas_nominatifs.pajak ) / 100 :: DOUBLE PRECISION )) WHEN surat_tugass.jenis_st_id = 2 THEN COALESCE ((surat_tugas_nominatifs.fb + surat_tugas_nominatifs.fd ) * (( 100 - surat_tugas_nominatifs.pajak ) / 100 :: DOUBLE PRECISION )) WHEN surat_tugass.jenis_st_id = 3 THEN surat_tugas_nominatifs.fb_luar_kota ELSE surat_tugas_nominatifs.jml_hari * surat_tugas_nominatifs.harian END) AS harian')
->leftjoin('surat_tugas_pesertas','surat_tugas_pesertas.pegawai_id', 'pegawais.id')
->leftJoin('surat_tugas_nominatifs', function($join) {$join->on('surat_tugas_nominatifs.peserta_id', 'surat_tugas_pesertas.id')->where('surat_tugas_nominatifs.jml_hari', '!=' , 0);})
->leftJoin('surat_tugass','surat_tugas_pesertas.surat_tugas_id', 'surat_tugass.id')
->leftJoin('view_latest_jabatan_pegawai', 'view_latest_jabatan_pegawai.pegawai_id', 'pegawais.id')
->whereRAW("date_part('year', surat_tugass.tgl_awal) = ". $tahun_st)
->where('surat_tugass.cetak_stat', true)
->where('surat_tugass.jenis_st_id', '!=', 10)//jika bukan narasumberr
->groupBy('pegawais.id');
//dd($data->toSql());
if(!auth()->user()->can('rekap surat tugas all')){
$unit_kerja_org = DB::table('ktus')->select('*')->where('pegawai_id', auth()->user()->pegawai_id)->first();
// dd($unit_kerja_org);
$data = $data->where('view_latest_jabatan_pegawai.org_unit_kerja_id', $unit_kerja_org->organisasi_id);
}
$action = [];
$dataTable = Datatable::create($data)
->setId('pegawais.id')
->editColumn('action', function ($data) use($request, $tahun_st) {
//$dump = '<a title="" href="'. route($this->route.'.rekap', ['id' => $data->pegawai_id, 'tahun' => (isset($request->tahun))?$request->tahun:date('Y')]) .'" class="btn btn-icon-only shoot blue tooltips" data-original-title="Detail Uraian"><i class="fa fa-calculator"></i></a>';
//return $dump;
//return $tahun_st;
return '<a title="Manage" href="'.route($this->route_list.'.list', ['id' => $data->id, 'tahun' => $tahun_st]).'" class="btn shoot btn-icon-only blue tooltips">
<i class="fa fa-tasks"></i>
</a>';
})
->editColumn('pegawai_nama', function ($data) use($request) {
return $data->nama;
})
// ->filterColumn('nip', function ($query, $key) {
// return $query->where("pegawais.nip", "ilike", '%'.$key.'%');
// })
->filterColumn('tahun', function ($query, $key) {
return $query->whereRAW("date_part('year', surat_tugass.tgl_awal) = ".$key);
})
->editColumn('tahun', function ($data) use($request) {
// return null;
})
->editColumn('transport', function ($data) use($request) {
if(Helper::convert_number($data->transport)){
return Helper::convert_number($data->transport);
}else{
return '-';
}
})
->editColumn('uk', function ($data) use($request) {
// return $data->organisasi_id;
})
->editColumn('penginapan', function ($data) use($request) {
if(Helper::convert_number($data->penginapan)){
return Helper::convert_number($data->penginapan);
}else{
return '-';
}
})
->editColumn('harian', function ($data) use($request) {
if(Helper::convert_rupiah($data->harian)){
return Helper::convert_number($data->harian);
}else{
return '-';
}
})
->editColumn('jml_hari', function ($data) use($request) {
if($data->jumlah_hari){
$jumlah_hari = $data->jumlah_hari;
}else{
$jumlah_hari = 0;
}
return $jumlah_hari.'hari';
})
->editColumn('total', function ($data) use($request) {
$total = 0;
$total = $data->penginapan + $data->harian + $data->transport;
if($total != 0 ){
return Helper::convert_number($total);
}else{
return '-';
}
})
->defaultAction($action, ['route' => $this->route, 'title' => $this->title, 'param-model' => 'vendor']);
if ($request->has('dateFilter')) {
$date = Carbon::createFromTimestamp($request->input('dateFilter'));
} else {
$date = Carbon::now();
}
$response = $dataTable->make(true);
return response()->json($response);
}
Когда я добавлю surat_tugas_nominatifs.jml_hari
в groupby
, на нем будет отображаться имя двойного сотрудника
Как можно вычислить сумму penginapan+transport+harian
? На самом деле уже есть общий расчет, и числа появляются, но они не могут фильтроваться как c и des c. Я пытался написать -
selectRaw('Count(surat_tugas_nominatifs.transport_lokal+ surat_tugas_nominatifs.cost_inap + surat_tugas_nominatifs.harian) AS Total')
Это не выдает ошибку, но все еще не может фильтровать как c и des c.