Perbaikan Pengajuan Absen
This commit is contained in:
@@ -14,7 +14,6 @@ use App\Services\DawaiService;
|
||||
use App\Services\VerifikatorWebhookService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -457,37 +456,6 @@ class HonorerController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancel($id)
|
||||
{
|
||||
BawahanHelper::authorizePengajuan($id);
|
||||
|
||||
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
||||
if (! $validasiWaktu['status']) {
|
||||
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
||||
}
|
||||
|
||||
if (PengajuanPresensi::where('id', $id)->where('status', 'Diterima')->exists()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan yang sudah diterima tidak dapat dibatalkan',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$success = $this->sekretariat([$id], 'Diajukan', null);
|
||||
|
||||
if ($success !== null) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "Berhasil membatalkan status $success pengajuan",
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal membatalkan status pengajuan',
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
BawahanHelper::authorizePengajuan($id);
|
||||
@@ -677,45 +645,6 @@ class HonorerController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function batalkanSelected(Request $request): JsonResponse
|
||||
{
|
||||
BawahanHelper::authorizePengajuan($request->input('ids', []));
|
||||
|
||||
$request->validate([
|
||||
'ids' => 'required|array',
|
||||
'ids.*' => 'integer',
|
||||
]);
|
||||
|
||||
$validCount = PengajuanPresensi::whereIn('id', $request->ids)->count();
|
||||
if ($validCount !== count($request->ids)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Beberapa pengajuan tidak ditemukan',
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (PengajuanPresensi::whereIn('id', $request->ids)->where('status', 'Diterima')->exists()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan yang sudah diterima tidak dapat dibatalkan',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$success = $this->sekretariat($request->ids, 'Diajukan', null);
|
||||
|
||||
if ($success !== null) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "Berhasil membatalkan status $success pengajuan",
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal membatalkan status pengajuan',
|
||||
]);
|
||||
}
|
||||
|
||||
public function sekretariat($id, $status, $catatan)
|
||||
{
|
||||
try {
|
||||
@@ -723,8 +652,8 @@ class HonorerController extends Controller
|
||||
$pengajuans = PengajuanPresensi::whereIn('id', $id)->get();
|
||||
foreach ($pengajuans as $pengajuan) {
|
||||
DB::beginTransaction();
|
||||
if ($status === 'Diterima' && $pengajuan->getRawOriginal('kategori') == 3) {
|
||||
$limit = $this->checkLimit($pengajuan->nip, $pengajuan->tanggal_mulai);
|
||||
if ($status === 'Diterima' && in_array((int) $pengajuan->getRawOriginal('kategori'), [3, 21, 24, 25])) {
|
||||
$limit = $this->checkLimit($pengajuan->nip, $pengajuan->tanggal_mulai, (int) $pengajuan->getRawOriginal('kategori'));
|
||||
if ($limit) {
|
||||
continue;
|
||||
}
|
||||
@@ -809,12 +738,12 @@ class HonorerController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function checkLimit($nip, $tanggal)
|
||||
public function checkLimit($nip, $tanggal, int $kategori = 3)
|
||||
{
|
||||
$pengajuans = PengajuanPresensi::where('nip', $nip)
|
||||
->whereIn('status', ['Diterima'])
|
||||
->where('tipe', 'absen')
|
||||
->where('kategori', 3)
|
||||
->where('kategori', $kategori)
|
||||
->whereYear('tanggal_mulai', explode('-', $tanggal)[0])
|
||||
->whereMonth('tanggal_mulai', explode('-', $tanggal)[1])
|
||||
->count();
|
||||
|
||||
Reference in New Issue
Block a user