perbaikan team activity di so
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Modules\Lpj\Http\Controllers;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Modules\Lpj\Models\Permohonan;
|
use Modules\Lpj\Models\Permohonan;
|
||||||
@@ -47,38 +48,97 @@ class ActivityController extends Controller
|
|||||||
|
|
||||||
$teamsActivity = TeamsUsers::with(['user', 'team', 'team.regions', 'user.roles'])
|
$teamsActivity = TeamsUsers::with(['user', 'team', 'team.regions', 'user.roles'])
|
||||||
->whereHas('team', function ($q) use ($regionId, $teamId) {
|
->whereHas('team', function ($q) use ($regionId, $teamId) {
|
||||||
$q->when($regionId, fn($q) => $q->where('regions_id', $regionId))
|
$q->when($regionId, fn ($q) => $q->where('regions_id', $regionId))
|
||||||
->when($teamId, fn($q) => $q->where('id', $teamId));
|
->when($teamId, fn ($q) => $q->where('id', $teamId));
|
||||||
})
|
})
|
||||||
->where('user_id', '!=', $user->id)
|
->where('user_id', '!=', $user->id)
|
||||||
->whereHas('user.roles', fn($q) => $q->whereIn('name', ['surveyor', 'surveyor-penilai']))
|
->whereHas('user.roles', fn ($q) => $q->whereIn('name', ['surveyor', 'surveyor-penilai']))
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return view('lpj::activity.progres_activity.index', compact('teamsActivity'));
|
return view('lpj::activity.progres_activity.index', compact('teamsActivity'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateTeamAssingment(Request $request) {
|
public function updateTeamAssingment(Request $request)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$id = $request->input('id');
|
// Validasi input
|
||||||
$user = PenilaianTeam::where('penilaian_id', $id)->get();
|
$request->validate([
|
||||||
if ($user) {
|
'id' => 'required|integer', // penilaian_id
|
||||||
foreach ($user as $item) {
|
'team_member_id' => 'required|integer',
|
||||||
if($item->role == 'surveyor') {
|
'permohonan_id' => 'required|integer',
|
||||||
$item->update(['user_id' => $request->surveyor_id]);
|
'user_id' => 'required|integer',
|
||||||
}
|
]);
|
||||||
}
|
|
||||||
return redirect()->route('activity.progres.index')->with('success', 'Surveyor berhasil diganti');
|
$penilaianId = $request->input('id');
|
||||||
|
$teamMemberId = $request->input('team_member_id');
|
||||||
|
$permohonanId = $request->input('permohonan_id');
|
||||||
|
$user_id = $request->input('user_id');
|
||||||
|
|
||||||
|
// Cek apakah permohonan ada
|
||||||
|
$permohonan = Permohonan::findOrFail($permohonanId);
|
||||||
|
|
||||||
|
// Validasi status permohonan
|
||||||
|
if ($permohonan->status != 'assign') {
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Tidak bisa ganti tim, permohonan ini sudah mengatur jadwal.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ambil tim berdasarkan penilaian_id dan user_id
|
||||||
|
$teams = PenilaianTeam::where('penilaian_id', $penilaianId)
|
||||||
|
->where('user_id', $user_id)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
// Cek apakah tim ditemukan
|
||||||
|
if ($teams->isEmpty()) {
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Data tim tidak ditemukan.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flag untuk mendeteksi perubahan
|
||||||
|
$updated = false;
|
||||||
|
|
||||||
|
// Proses update berdasarkan role
|
||||||
|
foreach ($teams as $team) {
|
||||||
|
if ($team->role == 'surveyor') {
|
||||||
|
// Jika role-nya surveyor, update user_id menjadi teamMemberId
|
||||||
|
$team->user_id = $teamMemberId;
|
||||||
|
$team->save();
|
||||||
|
$updated = true;
|
||||||
|
} elseif ($team->role == 'penilai') {
|
||||||
|
// Jika role-nya penilai, update user_id menjadi teamMemberId
|
||||||
|
$team->user_id = $teamMemberId;
|
||||||
|
$team->save();
|
||||||
|
$updated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($updated) {
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Data tim berhasil diperbarui.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Tidak ada perubahan yang dilakukan.',
|
||||||
|
]);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return redirect()->route('activity.progres.index')->with('success', $th->getMessage());
|
return response()->json([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => $th->getMessage(),
|
||||||
|
], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function senior()
|
public function senior()
|
||||||
{
|
{
|
||||||
return view('lpj::activity.senior_officer.index');
|
return view('lpj::activity.senior_officer.index');
|
||||||
@@ -246,7 +306,9 @@ class ActivityController extends Controller
|
|||||||
'permohonan.debiture',
|
'permohonan.debiture',
|
||||||
'permohonan.tujuanPenilaian',
|
'permohonan.tujuanPenilaian',
|
||||||
'permohonan.debiture.documents.jenisJaminan',
|
'permohonan.debiture.documents.jenisJaminan',
|
||||||
'userPenilai',
|
'userPenilai' => function ($query) use ($id) {
|
||||||
|
$query->where('user_id', $id);
|
||||||
|
},
|
||||||
'permohonan.penilai',
|
'permohonan.penilai',
|
||||||
'permohonan.approveEo',
|
'permohonan.approveEo',
|
||||||
'permohonan.approveDd',
|
'permohonan.approveDd',
|
||||||
@@ -288,6 +350,73 @@ class ActivityController extends Controller
|
|||||||
|
|
||||||
// Ambil data dengan pagination
|
// Ambil data dengan pagination
|
||||||
$data = $query->skip($offset)->take($size)->get();
|
$data = $query->skip($offset)->take($size)->get();
|
||||||
|
|
||||||
|
$data = $data->map(function ($item) {
|
||||||
|
$jeniAsset = null;
|
||||||
|
$statusPembayaran = trim(strtolower($item->permohonan->status_bayar ?? ''));
|
||||||
|
$tujuanPenilaian = $item->permohonan->tujuanPenilaian->name ?? null;
|
||||||
|
$now = Carbon::now();
|
||||||
|
|
||||||
|
// $plafond = $item->permohonan->nilaiPlafond->name ?? null;
|
||||||
|
// $type_report = $item->permohonan->penilai->type_penilai;
|
||||||
|
|
||||||
|
// $hari = 0;
|
||||||
|
// if ($plafond == '< 1M') {
|
||||||
|
// $item->paparan = 'Tidak Ada';
|
||||||
|
// }else if($plafond == '2 M - 5 M'){
|
||||||
|
// $hari = 2;
|
||||||
|
// }else if($plafond == '5 M - 10 M'){
|
||||||
|
// $hari = 3;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
if ($item->permohonan && $item->permohonan->debiture) {
|
||||||
|
$jeniAsset = $item->permohonan->debiture->documents->first() ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hariTambahan = 0;
|
||||||
|
|
||||||
|
if ($tujuanPenilaian == 'RAP') {
|
||||||
|
$hariTambahan = 2;
|
||||||
|
} else {
|
||||||
|
if ($statusPembayaran == 'sudah_bayar') {
|
||||||
|
$hariTambahan = 1; // H+1 untuk yang sudah bayar
|
||||||
|
} else {
|
||||||
|
$hariTambahan = 2; // H+2 untuk yang belum bayar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$tanggalMulai = $item->waktu_penilaian;
|
||||||
|
|
||||||
|
if ($tanggalMulai) {
|
||||||
|
// Konversi string tanggal ke objek Carbon jika belum
|
||||||
|
if (!$tanggalMulai instanceof Carbon) {
|
||||||
|
$tanggalMulai = Carbon::parse($tanggalMulai);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hitung tanggal selesai berdasarkan hari tambahan
|
||||||
|
$tanggalSelesai = $tanggalMulai->copy()->addDays($hariTambahan);
|
||||||
|
|
||||||
|
// Hitung hari kerja
|
||||||
|
$hariKerja = hitungHariKerja($tanggalMulai->toDateString(), $tanggalSelesai->toDateString());
|
||||||
|
|
||||||
|
// Set due date SLA
|
||||||
|
$dueDateSla = $tanggalMulai->copy()->addDays($hariKerja);
|
||||||
|
|
||||||
|
// Cek apakah sudah melewati due date
|
||||||
|
if ($now->greaterThan($dueDateSla)) {
|
||||||
|
$item->due_date_sla = null;
|
||||||
|
} else {
|
||||||
|
$item->due_date_sla = $dueDateSla->toDateString();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$item->due_date_sla = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
|
||||||
$filteredRecords = $data->count();
|
$filteredRecords = $data->count();
|
||||||
$pageCount = ceil($totalRecords / $size);
|
$pageCount = ceil($totalRecords / $size);
|
||||||
|
|
||||||
|
|||||||
@@ -709,6 +709,7 @@ class PenilaiController extends Controller
|
|||||||
'asuransi_luas_bangunan' => $request->input('asuransi_luas_bangunan'),
|
'asuransi_luas_bangunan' => $request->input('asuransi_luas_bangunan'),
|
||||||
'asuransi_nilai_1' => $request->input('asuransi_nilai_1'),
|
'asuransi_nilai_1' => $request->input('asuransi_nilai_1'),
|
||||||
'asuransi_nilai_2' => $request->input('asuransi_nilai_2'),
|
'asuransi_nilai_2' => $request->input('asuransi_nilai_2'),
|
||||||
|
'keterangan_penilai' => $request->input('keterangan_penilai') ?? [],
|
||||||
];
|
];
|
||||||
|
|
||||||
$npwData = [];
|
$npwData = [];
|
||||||
|
|||||||
@@ -1972,7 +1972,8 @@ class SurveyorController extends Controller
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->whereRaw('LOWER(status) = ?', ['assign']);
|
$query->whereRaw('LOWER(status) IN (?, ?)', ['assign', 'survey']);
|
||||||
|
|
||||||
|
|
||||||
if (!Auth::user()->hasRole('administrator')) {
|
if (!Auth::user()->hasRole('administrator')) {
|
||||||
$query->whereHas('penilaian.userPenilai', function ($q) {
|
$query->whereHas('penilaian.userPenilai', function ($q) {
|
||||||
|
|||||||
@@ -102,6 +102,7 @@
|
|||||||
<th class="min-w-[100px]">Tujuan Penilaian</th>
|
<th class="min-w-[100px]">Tujuan Penilaian</th>
|
||||||
<th class="min-w-[100px]">Status Bayar</th>
|
<th class="min-w-[100px]">Status Bayar</th>
|
||||||
<th class="min-w-[100px]">Jenis Asset</th>
|
<th class="min-w-[100px]">Jenis Asset</th>
|
||||||
|
<th class="min-w-[100px]">Penugasan</th>
|
||||||
<th class="min-w-[100px]">Jenis Report</th>
|
<th class="min-w-[100px]">Jenis Report</th>
|
||||||
<th class="min-w-[100px]">Tgl Register</th>
|
<th class="min-w-[100px]">Tgl Register</th>
|
||||||
<th class="min-w-[100px]">Tgl Assign</th>
|
<th class="min-w-[100px]">Tgl Assign</th>
|
||||||
@@ -182,9 +183,11 @@
|
|||||||
status_bayar: {
|
status_bayar: {
|
||||||
title: 'Status Bayar',
|
title: 'Status Bayar',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
const status = data.permohonan.status_bayar.replace(/_/g,
|
const status = data.permohonan.status_bayar.replace(
|
||||||
|
/_/g,
|
||||||
' ');
|
' ');
|
||||||
const statusClass = data.permohonan.status_bayar === 'belum_bayar' ? 'text-red-600' :
|
const statusClass = data.permohonan.status_bayar ===
|
||||||
|
'belum_bayar' ? 'text-red-600' :
|
||||||
'text-green-600';
|
'text-green-600';
|
||||||
return `<span class="badge badge-sm badge-default font-bold ${statusClass} uppercase">
|
return `<span class="badge badge-sm badge-default font-bold ${statusClass} uppercase">
|
||||||
${status}
|
${status}
|
||||||
@@ -196,6 +199,15 @@
|
|||||||
render: (item, data) =>
|
render: (item, data) =>
|
||||||
`${data.permohonan.debiture?.documents?.map(d => d.jenis_jaminan.name) || ''}`,
|
`${data.permohonan.debiture?.documents?.map(d => d.jenis_jaminan.name) || ''}`,
|
||||||
},
|
},
|
||||||
|
penugasan: {
|
||||||
|
title: 'Penugasan',
|
||||||
|
render: (item, data) => {
|
||||||
|
|
||||||
|
const roles = data.user_penilai?.map(d => d.role).join(
|
||||||
|
'<br>') || '-';
|
||||||
|
return roles;
|
||||||
|
},
|
||||||
|
},
|
||||||
jenis_report: {
|
jenis_report: {
|
||||||
title: 'Jenis Report',
|
title: 'Jenis Report',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
@@ -228,16 +240,21 @@
|
|||||||
due_date: {
|
due_date: {
|
||||||
title: 'Due Date',
|
title: 'Due Date',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
const jenis_asset = data.permohonan.debiture?.documents
|
if (!data.due_date_sla) {
|
||||||
?.map(d => d.jenis_jaminan.name);
|
return `<span class="badge badge-sm badge-danger uppercase flex justify-center">Sudah melewati batas</span>`;
|
||||||
|
}
|
||||||
return `${calculateDateSLA(jenis_asset, data.tanggal_kunjungan)}`;
|
return `${window.formatTanggalIndonesia(data.due_date_sla)}`;
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
paparan: {
|
paparan: {
|
||||||
title: 'Paparan',
|
title: 'Paparan',
|
||||||
render: (item, data) => `${data.paparan || ''}`,
|
render: (item, data) => {
|
||||||
|
if (!data.due_date_sla) {
|
||||||
|
return `<span class="badge badge-sm badge-danger uppercase flex justify-center">Sudah melewati batas</span>`;
|
||||||
|
}
|
||||||
|
return `${window.formatTanggalIndonesia(data.due_date_sla)}`;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
approve: {
|
approve: {
|
||||||
title: 'Approve',
|
title: 'Approve',
|
||||||
@@ -262,8 +279,8 @@
|
|||||||
actions: {
|
actions: {
|
||||||
title: 'Action',
|
title: 'Action',
|
||||||
render: (item, data) => `
|
render: (item, data) => `
|
||||||
<a class="btn btn-sm btn-icon btn-clear btn-primary" data-modal-toggle="#modal_jadwal" onclick="jadwal(${data.user_penilai[0].penilaian_id})">
|
<a class="btn btn-sm btn-icon btn-clear btn-primary" onclick="updateTeam(${data.user_penilai[0].penilaian_id}, ${data.permohonan.id}, ${data.user_penilai[0].user_id})" title="Ganti Team">
|
||||||
<i class="ki-filled ki-calendar-edit"></i>
|
<i class="ki-filled ki-user-edit"></i>
|
||||||
</a>`,
|
</a>`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -293,47 +310,69 @@
|
|||||||
return $jenis, $date;
|
return $jenis, $date;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function updateTeam(penilaaniId, permohonanId, userId) {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Pilih Tim',
|
||||||
|
input: 'select',
|
||||||
|
inputOptions: {
|
||||||
|
@foreach ($teamsActivity as $item)
|
||||||
|
{{ $item->user->id }}: '{{ $item->user->name }}',
|
||||||
|
@endforeach
|
||||||
|
},
|
||||||
|
inputPlaceholder: 'Pilih anggota tim',
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Ya',
|
||||||
|
cancelButtonText: 'Batal',
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
if (!result.value) {
|
||||||
|
// Tampilkan pesan error jika tidak ada pilihan
|
||||||
|
Swal.fire('Error!', 'Anda harus memilih anggota tim sebelum melanjutkan.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define variables
|
||||||
|
let token = "{{ csrf_token() }}";
|
||||||
|
let useURL = "{{ URL::to('/activity/update-team') }}";
|
||||||
|
|
||||||
|
// Prepare input data
|
||||||
|
let input_data = {
|
||||||
|
_token: token,
|
||||||
|
id: penilaaniId,
|
||||||
|
team_member_id: result.value,
|
||||||
|
permohonan_id: permohonanId,
|
||||||
|
user_id: userId,
|
||||||
|
};
|
||||||
|
|
||||||
|
// AJAX request
|
||||||
|
$.ajax({
|
||||||
|
url: useURL,
|
||||||
|
type: "PUT",
|
||||||
|
cache: false,
|
||||||
|
data: input_data,
|
||||||
|
dataType: "json",
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status === 'success') {
|
||||||
|
Swal.fire('Sukses!', response.message, 'success').then(() => {
|
||||||
|
location.reload(true);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Swal.fire('Error!', response.message, 'error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
console.error(xhr);
|
||||||
|
Swal.fire('Error!', 'Terjadi kesalahan saat memproses permintaan.',
|
||||||
|
'error');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
|
|
||||||
<div class="modal" data-modal="true" id="modal_jadwal">
|
|
||||||
<div class="modal-content max-w-[600px] top-[10%]">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h3 class="modal-title">Pilih</h3>
|
|
||||||
<button class="btn btn-xs btn-icon btn-light" data-modal-dismiss="true">
|
|
||||||
<i class="ki-outline ki-cross"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<form action="{{ route('activity.update-team') }}" method="POST" enctype="multipart/form-data"
|
|
||||||
id="revisiForm">
|
|
||||||
@method('put')
|
|
||||||
@csrf
|
|
||||||
<input id="ids" type="hidden" name="id">
|
|
||||||
<div class="pl-1 grid gap-2.5">
|
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
|
||||||
<label class="form-label max-w-56">Pilih Team</label>
|
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
|
||||||
<div class="input-group w-full">
|
|
||||||
<select id="surveyor_id" name="surveyor_id" class="input tomselect">
|
|
||||||
<option value="">Pilih Team</option>
|
|
||||||
@foreach ($teamsActivity as $item)
|
|
||||||
<option value="{{ $item->user->id }}">{{ $item->user->name }}</option>
|
|
||||||
@endforeach
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<em id="error-surveyor_id" class="alert text-danger text-sm"></em>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="modal-footer justify-end mt-2">
|
|
||||||
<div class="flex gap-4">
|
|
||||||
<button type="button" class="btn btn-light" data-modal-dismiss="true">Cancel</button>
|
|
||||||
<button id="btnSubmit" type="submit" class="btn btn-primary">Submit</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|||||||
@@ -278,7 +278,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@include('lpj::penilai.components.foto-lampiran')
|
{{-- @include('lpj::penilai.components.foto-lampiran') --}}
|
||||||
|
|
||||||
<div class="flex card-footer justify-end gap-5">
|
<div class="flex card-footer justify-end gap-5">
|
||||||
<a class="btn btn-success" onclick="saveMemo()">
|
<a class="btn btn-success" onclick="saveMemo()">
|
||||||
|
|||||||
@@ -352,8 +352,6 @@
|
|||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@include('lpj::penilai.components.foto-lampiran')
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user