first commit
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Remunerasi;
|
||||
|
||||
use App\Models\DokSiremun\Kegiatan;
|
||||
use App\Models\Verifikator\JabatanPegawaiDetailSyarat;
|
||||
use App\Models\Verifikator\KategoriRubrik;
|
||||
use App\Models\Verifikator\Periode;
|
||||
use App\Services\RemunerasiService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class HitungRemunerasi implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $id, $ratio, $user, $id_kategori, $count;
|
||||
|
||||
public $timeout = 1200;
|
||||
|
||||
public $skps = [
|
||||
'17' => 25,
|
||||
'16' => 25,
|
||||
'15' => 22,
|
||||
'14' => 22,
|
||||
'13' => 19,
|
||||
'12' => 19,
|
||||
'11' => 16,
|
||||
'10' => 16,
|
||||
];
|
||||
|
||||
public function __construct($id, $ratio, $user, $id_kategori = null, $count = false)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->ratio = $ratio;
|
||||
$this->user = $user;
|
||||
$this->id_kategori = $id_kategori;
|
||||
$this->count = $count;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$id = $this->id;
|
||||
$ratio = $this->ratio;
|
||||
$user = $this->user;
|
||||
$periode = Periode::where('status', true)->first()->id_periode;
|
||||
$kategori = $this->id_kategori;
|
||||
$remunerasiService = new RemunerasiService();
|
||||
|
||||
$kategoriRubrik = KategoriRubrik::where('nama', 'ILIKE', '%Kegiatan Penunjang%')
|
||||
->when($kategori, function ($query) use ($kategori) {
|
||||
$query->where('id', $kategori);
|
||||
})->get();
|
||||
|
||||
$kegiatan = Kegiatan::with(['syarats' => function ($query) use ($kategoriRubrik) {
|
||||
$query
|
||||
->whereIn('status_verifikasi_id', [6, 7])
|
||||
->whereIn('id_kategori', $kategoriRubrik->pluck('id')->toArray());
|
||||
}, 'syarats.pegawai.jabatans' => function ($query) use ($periode) {
|
||||
$query->where('periode', $periode)
|
||||
->where('active', true)
|
||||
->with(['detail' => function ($query) {
|
||||
$query->where('p2_jf', true)
|
||||
->where('p2_jtt', true);
|
||||
}]);
|
||||
}])
|
||||
->whereHas('syarats', function ($query) {
|
||||
$query->whereIn('status_verifikasi_id', [6, 7]);
|
||||
})
|
||||
->whereNotIn('uploader', ['Api Praktisi', 'Api Spada', 'API LMS', 'API Permatasari'])
|
||||
->where('id', $id)
|
||||
->whereNull('feeder')
|
||||
->first();
|
||||
|
||||
try {
|
||||
$kegiatan->update(['status_processing' => 'PROCESSING']);
|
||||
DB::beginTransaction();
|
||||
|
||||
$rasio = $ratio / 100;
|
||||
foreach ($kegiatan->syarats as $anggota) {
|
||||
$oldRatio = $anggota->rasio * 100;
|
||||
if ($oldRatio != $this->ratio) {
|
||||
if ($this->user?->id) {
|
||||
$anggota->update([
|
||||
'rasio' => $rasio,
|
||||
]);
|
||||
}
|
||||
|
||||
$anggota->logs()->create([
|
||||
'user_id' => $user->id,
|
||||
'employee_id' => $user->nip,
|
||||
'employee_name' => $user->name,
|
||||
'employee_role' => 'Verifikator',
|
||||
'message' => "Rasio poin diubah dari {$oldRatio}% menjadi $ratio%",
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->count || ($oldRatio != $this->ratio)) {
|
||||
if ($anggota->status_verifikasi_id < 6) continue;
|
||||
foreach ($anggota->pegawai->jabatans ?? [] as $jabatan) {
|
||||
$poin = $anggota->poin_total;
|
||||
$id_rubrik = $anggota->id_rubrik;
|
||||
$cost = $remunerasiService->biaya($poin, $jabatan->detail, $rasio, $anggota->pegawai->jenis_pegawai, $id_rubrik);
|
||||
|
||||
foreach ($jabatan->detail as $detail) {
|
||||
JabatanPegawaiDetailSyarat::updateOrCreate(
|
||||
[
|
||||
'syarat_id' => $anggota->id,
|
||||
'jabatan_pegawai_detail_id' => $detail->id,
|
||||
],
|
||||
[
|
||||
'poin' => round($cost[$detail->id]['poin'], 2),
|
||||
'biaya' => $cost[$detail->id]['bruto'],
|
||||
'biaya_rasio' => $cost[$detail->id]['ratio'],
|
||||
'tax' => $cost[$detail->id]['tax'],
|
||||
'biaya_netto' => $cost[$detail->id]['netto'],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
DB::beginTransaction();
|
||||
$nips = $kegiatan->syarats->pluck('id_pelaksana')->toArray();
|
||||
Artisan::call('app:hitung-remunerasi-command ' . implode(' ', $nips));
|
||||
$kegiatan->update(['status_processing' => 'SUCCESS']);
|
||||
DB::commit();
|
||||
Log::info("Count Remunerasi for kegiatan {$kegiatan->id} with ratio {$this->ratio}% completed successfully. ");
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
$kegiatan->update(['status_processing' => 'FAILED']);
|
||||
Log::error($th);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user