update kertas kerja dan column name table inspeksi
This commit is contained in:
@@ -7,7 +7,8 @@ use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Exports\KertasKerjaExport;
|
||||
class PenilaiController extends Controller
|
||||
{
|
||||
public $user;
|
||||
@@ -89,83 +90,209 @@ class PenilaiController extends Controller
|
||||
}
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('penilai.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('penilai.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query();
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query();
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$columns = ['nomor_registrasi', 'debiture.name', 'branch.name', 'user.name', 'tujuanPenilaian.name', 'jenisfasilitasKredit.name'];
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$columns = ['nomor_registrasi', 'debiture.name', 'branch.name', 'user.name', 'tujuanPenilaian.name', 'jenisfasilitasKredit.name'];
|
||||
|
||||
$query->where(function ($q) use ($search, $columns) {
|
||||
foreach ($columns as $column) {
|
||||
$q->orWhereRelation(explode('.', $column)[0], explode('.', $column)[1], 'LIKE', '%' . $search . '%');
|
||||
}
|
||||
$query->where(function ($q) use ($search, $columns) {
|
||||
foreach ($columns as $column) {
|
||||
$q->orWhereRelation(explode('.', $column)[0], explode('.', $column)[1], 'LIKE', '%' . $search . '%');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Apply whereHas to check penilai_id, role, and user_id specifically for 'penilai' role
|
||||
$query->whereHas('penilaian.userPenilai', function ($q) {
|
||||
$q->where('role', 'penilai') // Ensure the role is 'penilai'
|
||||
->where('user_id', 12); // Ganti dengan Auth::user()->id jika dinamis
|
||||
});
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size;
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->with([
|
||||
'user',
|
||||
'debiture',
|
||||
'branch',
|
||||
'tujuanPenilaian',
|
||||
'jenisfasilitasKredit',
|
||||
'penilaian.userPenilai' // Ensure this relation is included
|
||||
])->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page', 1);
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
// Apply whereHas to check penilai_id, role, and user_id specifically for 'penilai' role
|
||||
$query->whereHas('penilaian.userPenilai', function ($q) {
|
||||
$q->where('role', 'penilai') // Ensure the role is 'penilai'
|
||||
->where('user_id', 12); // Ganti dengan Auth::user()->id jika dinamis
|
||||
});
|
||||
public function kertas_kerja()
|
||||
{
|
||||
$data = [
|
||||
[
|
||||
'Pendekatan pasar',
|
||||
'Nama Pemilik Aset',
|
||||
'',
|
||||
],
|
||||
[
|
||||
'Metode Perbandingan Data Pasar',
|
||||
'Nama Pemberi Tugas: ',
|
||||
'',
|
||||
'',
|
||||
],
|
||||
[
|
||||
'Tanggal Penilaian: ',
|
||||
'Lokasi: ',
|
||||
'',
|
||||
'',
|
||||
],
|
||||
[
|
||||
'No.',
|
||||
'Objek Penilaian',
|
||||
'Data Pembanding 1',
|
||||
'Data Pembanding 2',
|
||||
'Data Pembanding 3'
|
||||
],[
|
||||
'1',
|
||||
'Jenis Aset',
|
||||
'Pembanding 1',
|
||||
'Pembanding 1',
|
||||
'Pembanding 1'
|
||||
],
|
||||
[
|
||||
'2',
|
||||
'Luas Tanah',
|
||||
'Pembanding 2',
|
||||
'Pembanding 2',
|
||||
'Pembanding 2'
|
||||
],
|
||||
[
|
||||
'3',
|
||||
'Penawaran/Transaksi',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'4',
|
||||
'Harga penawaran/Transaksi',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],[
|
||||
'5',
|
||||
'Nomor Telepon',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'6',
|
||||
'Estimasi Harga Transaksi',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'7',
|
||||
'Nama Nara sumber',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'8',
|
||||
'Status Nara sumber',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'9',
|
||||
'Waktu Penawaran/Transaksi',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'10',
|
||||
'Titik GPS',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
],
|
||||
[
|
||||
'11',
|
||||
'Alamat',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'12',
|
||||
'Jarak Pembanding dengan Objek (m)',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'13',
|
||||
'Estimasi Rangking Tanah',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
],
|
||||
[
|
||||
'14',
|
||||
'Estimasi Rangking Bangunan',
|
||||
'',
|
||||
'Pembanding 3',
|
||||
'Pembanding 3'
|
||||
]
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
];
|
||||
return Excel::download(new KertasKerjaExport($data), 'kertas-kerja.xlsx');
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size;
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->with([
|
||||
'user',
|
||||
'debiture',
|
||||
'branch',
|
||||
'tujuanPenilaian',
|
||||
'jenisfasilitasKredit',
|
||||
'penilaian.userPenilai' // Ensure this relation is included
|
||||
])->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page', 1);
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user