first commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Remenurasi;
|
||||
|
||||
use App\Models\Verifikator\Periode;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use App\Services\PerhitunganKegiatanService;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class HitungRemunerasiCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:hitung-remunerasi-command {nip?*}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Hitung Remunerasi';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$nips = $this->argument('nip');
|
||||
|
||||
if (! $nips || count($nips) === 0) {
|
||||
$pegawais = Pegawai::query();
|
||||
$nips = $pegawais->pluck('nip')->toArray();
|
||||
}
|
||||
|
||||
$periode = Periode::where('status', true)->first()->id_periode;
|
||||
$perhitunganKegiatanService = new PerhitunganKegiatanService;
|
||||
|
||||
if ($periode % 2 === 1) {
|
||||
$bulan = [1, 2, 3, 4, 5, 6];
|
||||
} else {
|
||||
$bulan = [7, 8, 9, 10, 11, 12];
|
||||
}
|
||||
|
||||
$num = 1;
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
foreach ($nips as $nip) {
|
||||
try {
|
||||
$nama = Pegawai::where('nip', $nip)->value('nama') ?? '-';
|
||||
$nama = Str::limit($nama, 37);
|
||||
$kegiatans = collect($perhitunganKegiatanService->listKegiatan($nip, $periode, $bulan, null, true));
|
||||
$p2 = $kegiatans->sum(fn ($bulan) => $bulan['p2']['total']['bruto'] ?? 0);
|
||||
$p2Formatted = number_format($p2, 2, ',', '.');
|
||||
$this->info(sprintf(
|
||||
'%3d. %-20s %-40s %20s %s',
|
||||
$num,
|
||||
$nip,
|
||||
$nama,
|
||||
$p2Formatted,
|
||||
now()
|
||||
));
|
||||
$num++;
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return 0;
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user