100 lines
3.4 KiB
PHP
100 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use App\Models\Karyawan;
|
|
use App\Models\KaryawanLuar;
|
|
|
|
class KaryawanController extends Controller
|
|
{
|
|
public function listData(Request $request){
|
|
$search = trim($request->input('search'));
|
|
$limit = (int) $request->input('limit', 50);
|
|
if ($limit < 1) $limit = 50;
|
|
if ($limit > 100) $limit = 100;
|
|
|
|
$validator = Validator::make(
|
|
['search' => $search, 'limit' => $limit],
|
|
['search' => 'required|min:2', 'limit' => 'integer|min:1|max:100']
|
|
);
|
|
|
|
if ($validator->fails()) {
|
|
return response()->json(['error' => 0, 'data' => []]);
|
|
}
|
|
|
|
$rows = DB::connection('pgsql')
|
|
->table('public.pegawai_m as pg')
|
|
->leftJoin('public.mappegawaijabatantounitkerja_m as mp', function ($join) {
|
|
$join->on('mp.objectpegawaifk', '=', 'pg.id')
|
|
->where('mp.statusenabled', true)
|
|
->where('mp.isprimary', true);
|
|
})
|
|
->leftJoin('public.unitkerjapegawai_m as ukp', function ($join) {
|
|
$join->on('ukp.id', '=', 'mp.objectunitkerjapegawaifk')
|
|
->where('ukp.statusenabled', true);
|
|
})
|
|
->where('pg.statusenabled', true)
|
|
->where('pg.kedudukanfk', 1)
|
|
->where(function ($q) use ($search) {
|
|
$q->where('pg.namalengkap', 'ILIKE', "%$search%")
|
|
->orWhere('pg.nip_pns', 'ILIKE', "%$search%");
|
|
})
|
|
->whereNotIn('pg.kategorypegawai', ['11'])
|
|
->select([
|
|
'pg.id',
|
|
DB::raw("coalesce(pg.namalengkap, '-') as namalengkap"),
|
|
DB::raw("coalesce(pg.nip_pns, '-') as nip_pns"),
|
|
DB::raw("coalesce(ukp.name, '-') as unit_name"),
|
|
])
|
|
->orderBy('pg.namalengkap')
|
|
->limit($limit)
|
|
->get();
|
|
|
|
return response()->json([
|
|
'error' => 0,
|
|
'data' => $rows,
|
|
]);
|
|
}
|
|
|
|
public function listDataKaryawanLuar(Request $request)
|
|
{
|
|
$search = trim((string) $request->input('search'));
|
|
$limit = (int) $request->input('limit', 50);
|
|
if ($limit < 1) $limit = 50;
|
|
if ($limit > 100) $limit = 100;
|
|
|
|
$validator = Validator::make(
|
|
['search' => $search, 'limit' => $limit],
|
|
['search' => 'required|min:2', 'limit' => 'integer|min:1|max:100']
|
|
);
|
|
|
|
if ($validator->fails()) {
|
|
return response()->json(['error' => 0, 'data' => []]);
|
|
}
|
|
|
|
$data = KaryawanLuar::query()
|
|
->from('public.pegawai_luar_pl as pl')
|
|
->where(function($q) use($search){
|
|
$q->where('pl.nama', 'ILIKE', "%$search%")
|
|
->orWhere('pl.nik', 'ILIKE', "%$search%");
|
|
})
|
|
->select([
|
|
'pl.id as id',
|
|
DB::raw("coalesce(pl.nama, '-') as namalengkap"),
|
|
DB::raw("coalesce(pl.nik, '-') as nip_pns"),
|
|
DB::raw("coalesce(nullif(pl.tipe, ''), '-') as unit_name"),
|
|
])
|
|
->orderBy('pl.nama')
|
|
->limit($limit)
|
|
->get();
|
|
return response()->json([
|
|
'error' => 0,
|
|
'data' => $data
|
|
]);
|
|
|
|
}
|
|
}
|