Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 80c7c0c46f | |||
| 64bbd3ef16 | |||
| 32342a299d | |||
| 2ed50051a5 | |||
| 32482cdf8b | |||
| 42362fd143 | |||
| fabda9eaa4 | |||
| 03df3096eb | |||
| 9057ab3643 | |||
| e4e19fa419 | |||
| 8aa3da65ce | |||
| 56c512e0ed | |||
| ffcfdd3579 | |||
| 88d27ef207 | |||
| e42892a32b | |||
| b2e9ebc2dc |
@@ -35,6 +35,13 @@ DB_DATABASE_SISKA=siska_386
|
|||||||
DB_USERNAME_SISKA=siska
|
DB_USERNAME_SISKA=siska
|
||||||
DB_PASSWORD_SISKA=UntanMulia-2020
|
DB_PASSWORD_SISKA=UntanMulia-2020
|
||||||
|
|
||||||
|
DB_CONNECTION_SIDIA=pgsql
|
||||||
|
DB_HOST_SIDIA=172.16.40.128
|
||||||
|
DB_PORT_SIDIA=5432
|
||||||
|
DB_DATABASE_SIDIA=sidia
|
||||||
|
DB_USERNAME_SIDIA=arbi
|
||||||
|
DB_PASSWORD_SIDIA="K~3V6%#£9w;:/Q]Gi4:or[8N"
|
||||||
|
|
||||||
SESSION_DRIVER=database
|
SESSION_DRIVER=database
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
SESSION_ENCRYPT=false
|
SESSION_ENCRYPT=false
|
||||||
@@ -75,7 +82,14 @@ VITE_APP_NAME="${APP_NAME}"
|
|||||||
# CONFIG
|
# CONFIG
|
||||||
PERIODE_VERIFIKATOR=395
|
PERIODE_VERIFIKATOR=395
|
||||||
|
|
||||||
|
VERIFIKATOR_WEBHOOK_URL=http://172.16.50.94:8087/webhook/verifikator
|
||||||
|
VERIFIKATOR_WEBHOOK_KEY=
|
||||||
|
|
||||||
|
VERIFIKASI_ABSEN_WA_URL=http://verifikasi-presensi-whatsapp.test
|
||||||
|
|
||||||
|
GOOGLE_DRIVE_FOLDER_ID=0AJQK-NMrB4b_Uk9PVA
|
||||||
|
|
||||||
# LOGIN MODE
|
# LOGIN MODE
|
||||||
# 1 = Login biasa (NIP/Password + Google OAuth)
|
# 1 = Login biasa (NIP/Password + Google OAuth)
|
||||||
# 2 = Login SSO Portal Untan (khusus domain *.untan.ac.id)
|
# 2 = Login SSO Portal Untan (khusus domain *.untan.ac.id)
|
||||||
LOGIN_MODE=1
|
LOGIN_MODE=2
|
||||||
|
|||||||
@@ -35,6 +35,13 @@ DB_DATABASE_SISKA=siska_386
|
|||||||
DB_USERNAME_SISKA=siska
|
DB_USERNAME_SISKA=siska
|
||||||
DB_PASSWORD_SISKA=UntanMulia-2020
|
DB_PASSWORD_SISKA=UntanMulia-2020
|
||||||
|
|
||||||
|
DB_CONNECTION_SIDIA=pgsql
|
||||||
|
DB_HOST_SIDIA=172.16.40.128
|
||||||
|
DB_PORT_SIDIA=5432
|
||||||
|
DB_DATABASE_SIDIA=sidia
|
||||||
|
DB_USERNAME_SIDIA=arbi
|
||||||
|
DB_PASSWORD_SIDIA="K~3V6%#£9w;:/Q]Gi4:or[8N"
|
||||||
|
|
||||||
SESSION_DRIVER=database
|
SESSION_DRIVER=database
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
SESSION_ENCRYPT=false
|
SESSION_ENCRYPT=false
|
||||||
@@ -75,6 +82,13 @@ VITE_APP_NAME="${APP_NAME}"
|
|||||||
# CONFIG
|
# CONFIG
|
||||||
PERIODE_VERIFIKATOR=395
|
PERIODE_VERIFIKATOR=395
|
||||||
|
|
||||||
|
VERIFIKATOR_WEBHOOK_URL=http://172.16.50.94:8087/webhook/verifikator
|
||||||
|
VERIFIKATOR_WEBHOOK_KEY=
|
||||||
|
|
||||||
|
VERIFIKASI_ABSEN_WA_URL=http://verifikasi-presensi-whatsapp.test
|
||||||
|
|
||||||
|
GOOGLE_DRIVE_FOLDER_ID=
|
||||||
|
|
||||||
# LOGIN MODE
|
# LOGIN MODE
|
||||||
# 1 = Login Biasa (NIP/Password + Google OAuth)
|
# 1 = Login Biasa (NIP/Password + Google OAuth)
|
||||||
# 2 = Login SSO Portal Untan (khusus domain *.untan.ac.id)
|
# 2 = Login SSO Portal Untan (khusus domain *.untan.ac.id)
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/.phpunit.cache
|
||||||
|
/node_modules
|
||||||
|
/public/build
|
||||||
|
/public/hot
|
||||||
|
/public/storage
|
||||||
|
/storage/*.key
|
||||||
|
/storage/pail
|
||||||
|
/vendor
|
||||||
|
.env
|
||||||
|
.env.backup
|
||||||
|
.env.production
|
||||||
|
.phpactor.json
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
auth.json
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
/.fleet
|
||||||
|
/.idea
|
||||||
|
/.nova
|
||||||
|
/.vscode
|
||||||
|
/.zed
|
||||||
@@ -264,8 +264,6 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
*/
|
*/
|
||||||
private function updatePegawai(array $newDosen, array $newTendik, DawaiService $dawaiService): void
|
private function updatePegawai(array $newDosen, array $newTendik, DawaiService $dawaiService): void
|
||||||
{
|
{
|
||||||
DB::beginTransaction();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$insertedDosen = 0;
|
$insertedDosen = 0;
|
||||||
$updatedDosen = 0;
|
$updatedDosen = 0;
|
||||||
@@ -296,7 +294,7 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
|
|
||||||
foreach ($newDosen as $dosen) {
|
foreach ($newDosen as $dosen) {
|
||||||
try {
|
try {
|
||||||
$result = $this->insertDosen($dosen, $dawaiService, $periode, $dosenMap, $tendikMap, $dosenByIdDawai);
|
$result = DB::transaction(fn () => $this->insertDosen($dosen, $dawaiService, $periode, $dosenMap, $tendikMap, $dosenByIdDawai));
|
||||||
|
|
||||||
match ($result) {
|
match ($result) {
|
||||||
'inserted' => $insertedDosen++,
|
'inserted' => $insertedDosen++,
|
||||||
@@ -335,7 +333,7 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
|
|
||||||
foreach ($newTendik as $tendik) {
|
foreach ($newTendik as $tendik) {
|
||||||
try {
|
try {
|
||||||
$result = $this->insertTendik($tendik, $dawaiService, $periode, $dosenMap, $tendikMap, $tendikByIdDawai);
|
$result = DB::transaction(fn () => $this->insertTendik($tendik, $dawaiService, $periode, $dosenMap, $tendikMap, $tendikByIdDawai));
|
||||||
|
|
||||||
match ($result) {
|
match ($result) {
|
||||||
'inserted' => $insertedTendik++,
|
'inserted' => $insertedTendik++,
|
||||||
@@ -366,8 +364,6 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DB::commit();
|
|
||||||
|
|
||||||
$this->newLine();
|
$this->newLine();
|
||||||
$this->info('========== HASIL PROSES ==========');
|
$this->info('========== HASIL PROSES ==========');
|
||||||
$this->info("Total dosen baru ditambahkan: {$insertedDosen}");
|
$this->info("Total dosen baru ditambahkan: {$insertedDosen}");
|
||||||
@@ -387,7 +383,6 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
}
|
}
|
||||||
$this->info('Proses selesai!');
|
$this->info('Proses selesai!');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
DB::rollBack();
|
|
||||||
$this->error('Terjadi error saat proses: '.$e->getMessage());
|
$this->error('Terjadi error saat proses: '.$e->getMessage());
|
||||||
Log::error('Error saat proses pegawai', [
|
Log::error('Error saat proses pegawai', [
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
@@ -615,6 +610,7 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
'tubel_kembali' => ($dosen['detail']['status'] ?? '') === 'tubel' ? $validateDate($dosen['detail']['tst'] ?? null) : null,
|
'tubel_kembali' => ($dosen['detail']['status'] ?? '') === 'tubel' ? $validateDate($dosen['detail']['tst'] ?? null) : null,
|
||||||
'npwp' => $dosen['npwp'] ?? $existing->npwp,
|
'npwp' => $dosen['npwp'] ?? $existing->npwp,
|
||||||
'nomor_rekening' => $dosen['nomor_rekening'] ?? $existing->nomor_rekening,
|
'nomor_rekening' => $dosen['nomor_rekening'] ?? $existing->nomor_rekening,
|
||||||
|
'no_hp' => $dosen['privasi']['no_hp'] ?? $existing->no_hp,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $nipChanged ? 'nip_changed' : 'updated';
|
return $nipChanged ? 'nip_changed' : 'updated';
|
||||||
@@ -653,6 +649,7 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
'wafat' => ($dosen['detail']['status'] ?? '') === 'wafat' ? now()->format('Y-m-d') : null,
|
'wafat' => ($dosen['detail']['status'] ?? '') === 'wafat' ? now()->format('Y-m-d') : null,
|
||||||
'npwp' => $dosen['npwp'] ?? null,
|
'npwp' => $dosen['npwp'] ?? null,
|
||||||
'nomor_rekening' => $dosen['nomor_rekening'] ?? null,
|
'nomor_rekening' => $dosen['nomor_rekening'] ?? null,
|
||||||
|
'no_hp' => $dosen['privasi']['no_hp'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $changedType ? 'changed_type' : 'inserted';
|
return $changedType ? 'changed_type' : 'inserted';
|
||||||
@@ -732,6 +729,7 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
'tubel_kembali' => ($tendik['detail']['status'] ?? '') === 'tubel' ? $validateDate($tendik['detail']['tst'] ?? null) : null,
|
'tubel_kembali' => ($tendik['detail']['status'] ?? '') === 'tubel' ? $validateDate($tendik['detail']['tst'] ?? null) : null,
|
||||||
'npwp' => $tendik['npwp'] ?? $existing->npwp,
|
'npwp' => $tendik['npwp'] ?? $existing->npwp,
|
||||||
'nomor_rekening' => $tendik['nomor_rekening'] ?? $existing->nomor_rekening,
|
'nomor_rekening' => $tendik['nomor_rekening'] ?? $existing->nomor_rekening,
|
||||||
|
'no_hp' => $tendik['privasi']['no_hp'] ?? $existing->no_hp,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $nipChanged ? 'nip_changed' : 'updated';
|
return $nipChanged ? 'nip_changed' : 'updated';
|
||||||
@@ -770,6 +768,7 @@ class CheckPegawaiBaruCommand extends Command
|
|||||||
'wafat' => ($tendik['detail']['status'] ?? '') === 'wafat' ? now()->format('Y-m-d') : null,
|
'wafat' => ($tendik['detail']['status'] ?? '') === 'wafat' ? now()->format('Y-m-d') : null,
|
||||||
'npwp' => $tendik['npwp'] ?? null,
|
'npwp' => $tendik['npwp'] ?? null,
|
||||||
'nomor_rekening' => $tendik['nomor_rekening'] ?? null,
|
'nomor_rekening' => $tendik['nomor_rekening'] ?? null,
|
||||||
|
'no_hp' => $tendik['privasi']['no_hp'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $changedType ? 'changed_type' : 'inserted';
|
return $changedType ? 'changed_type' : 'inserted';
|
||||||
|
|||||||
@@ -0,0 +1,337 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use App\Models\Rekapitulasi\P1;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||||
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
||||||
|
class P1PerbandinganExport implements WithMultipleSheets
|
||||||
|
{
|
||||||
|
protected $jenisPegawai;
|
||||||
|
|
||||||
|
protected $tahun;
|
||||||
|
|
||||||
|
protected $bulan;
|
||||||
|
|
||||||
|
protected $unit;
|
||||||
|
|
||||||
|
protected $arah;
|
||||||
|
|
||||||
|
public function __construct($jenisPegawai, $tahun, $bulan, $unit, $arah = '')
|
||||||
|
{
|
||||||
|
$this->jenisPegawai = $jenisPegawai;
|
||||||
|
$this->tahun = $tahun;
|
||||||
|
$this->bulan = $bulan;
|
||||||
|
$this->unit = $unit;
|
||||||
|
$this->arah = $arah;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
$sheets = [];
|
||||||
|
$months = $this->bulan === null ? range(1, Carbon::now()->month) : [$this->bulan];
|
||||||
|
|
||||||
|
foreach ($months as $month) {
|
||||||
|
$sheets[] = new P1PerbandinganMonthlySheet($this->jenisPegawai, $this->tahun, $month, $this->unit, $this->arah);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sheets;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class P1PerbandinganMonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles, WithTitle
|
||||||
|
{
|
||||||
|
protected $jenisPegawai;
|
||||||
|
|
||||||
|
protected $tahun;
|
||||||
|
|
||||||
|
protected $bulan;
|
||||||
|
|
||||||
|
protected $unit;
|
||||||
|
|
||||||
|
protected $arah;
|
||||||
|
|
||||||
|
private $cachedCollection;
|
||||||
|
|
||||||
|
private array $totals = [];
|
||||||
|
|
||||||
|
protected $bulanNames = [
|
||||||
|
1 => 'Januari',
|
||||||
|
2 => 'Februari',
|
||||||
|
3 => 'Maret',
|
||||||
|
4 => 'April',
|
||||||
|
5 => 'Mei',
|
||||||
|
6 => 'Juni',
|
||||||
|
7 => 'Juli',
|
||||||
|
8 => 'Agustus',
|
||||||
|
9 => 'September',
|
||||||
|
10 => 'Oktober',
|
||||||
|
11 => 'November',
|
||||||
|
12 => 'Desember',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct($jenisPegawai, $tahun, $bulan, $unit, $arah = '')
|
||||||
|
{
|
||||||
|
$this->jenisPegawai = $jenisPegawai;
|
||||||
|
$this->tahun = $tahun;
|
||||||
|
$this->bulan = $bulan;
|
||||||
|
$this->unit = $unit;
|
||||||
|
$this->arah = $arah;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function title(): string
|
||||||
|
{
|
||||||
|
return $this->bulanNames[$this->bulan];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
if ($this->cachedCollection !== null) {
|
||||||
|
return $this->cachedCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cachedCollection = $this->buildCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function baseQuery(int $queryYear, int $queryMonth)
|
||||||
|
{
|
||||||
|
return P1::query()
|
||||||
|
->where('tahun', $queryYear)
|
||||||
|
->where('bulan', $queryMonth)
|
||||||
|
->when($this->unit !== null && $this->unit !== '', fn ($query) => $query->where('id_unit_kerja', $this->unit))
|
||||||
|
->when($this->jenisPegawai === 'dosen' || $this->jenisPegawai === 'tendik', fn ($query) => $query->whereRaw('LOWER(jenis_pegawai) = ?', [$this->jenisPegawai]))
|
||||||
|
->get()
|
||||||
|
->keyBy('nip');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function keteranganLabel(float $selisihNetto): string
|
||||||
|
{
|
||||||
|
return match (true) {
|
||||||
|
$selisihNetto > 0 => 'Naik',
|
||||||
|
$selisihNetto < 0 => 'Turun',
|
||||||
|
default => 'Tetap',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildCollection()
|
||||||
|
{
|
||||||
|
$previousMonth = $this->bulan === 1 ? 12 : $this->bulan - 1;
|
||||||
|
$previousYear = $this->bulan === 1 ? $this->tahun - 1 : $this->tahun;
|
||||||
|
|
||||||
|
$current = $this->baseQuery($this->tahun, $this->bulan);
|
||||||
|
$previous = $this->baseQuery($previousYear, $previousMonth);
|
||||||
|
$nips = $current->keys()->merge($previous->keys())->unique();
|
||||||
|
|
||||||
|
$comparison = $nips->map(function ($nip) use ($current, $previous) {
|
||||||
|
$currentRow = $current->get($nip);
|
||||||
|
$previousRow = $previous->get($nip);
|
||||||
|
|
||||||
|
$currentBruto = (float) ($currentRow->gaji_yang_dibayarkan ?? 0);
|
||||||
|
$previousBruto = (float) ($previousRow->gaji_yang_dibayarkan ?? 0);
|
||||||
|
$currentPajak = (float) ($currentRow->pph21 ?? 0);
|
||||||
|
$previousPajak = (float) ($previousRow->pph21 ?? 0);
|
||||||
|
$currentNetto = (float) ($currentRow->gaji_bersih ?? 0);
|
||||||
|
$previousNetto = (float) ($previousRow->gaji_bersih ?? 0);
|
||||||
|
|
||||||
|
$selisihBruto = $currentBruto - $previousBruto;
|
||||||
|
$selisihPajak = $currentPajak - $previousPajak;
|
||||||
|
$selisihNetto = $currentNetto - $previousNetto;
|
||||||
|
|
||||||
|
$acuan = $currentRow ?? $previousRow;
|
||||||
|
$cleanNip = ltrim((string) $nip, "'");
|
||||||
|
|
||||||
|
return (object) [
|
||||||
|
'no' => 0,
|
||||||
|
'nip' => "'".$cleanNip,
|
||||||
|
'nama_lengkap' => $acuan->nama ?? '-',
|
||||||
|
'pangkat' => $acuan->pangkat ?? '-',
|
||||||
|
'golongan' => $acuan->golongan ?? '-',
|
||||||
|
'nama_jafung' => $acuan->nama_jabatan_fungsional ?? '-',
|
||||||
|
'grade_jafung' => $acuan->grade_jabatan_fungsional ?? '-',
|
||||||
|
'harga_jafung' => $acuan->gaji_jabatan_fungsional ?? 0,
|
||||||
|
'nama_jtt' => $acuan->nama_jabatan_tugas_tambahan ?: '-',
|
||||||
|
'grade_jtt' => $acuan->grade_jabatan_tugas_tambahan ?? '-',
|
||||||
|
'harga_jtt' => $acuan->gaji_jabatan_tugas_tambahan ?? 0,
|
||||||
|
'jenis_pegawai' => strtolower((string) ($acuan->jenis_pegawai ?? '')),
|
||||||
|
'selisih_bruto' => $selisihBruto,
|
||||||
|
'selisih_pajak' => $selisihPajak,
|
||||||
|
'selisih_netto' => $selisihNetto,
|
||||||
|
'keterangan' => $this->keteranganLabel($selisihNetto),
|
||||||
|
'npwp' => $acuan->npwp ? "'".str_replace(['-', '.'], '', $acuan->npwp) : '',
|
||||||
|
'nomor_rekening' => $acuan->nomor_rekening ? "'".$acuan->nomor_rekening : '',
|
||||||
|
'nama_unit' => $acuan->nama_unit_kerja ?? '-',
|
||||||
|
];
|
||||||
|
})->filter(function ($row) {
|
||||||
|
$values = [$row->selisih_bruto, $row->selisih_pajak, $row->selisih_netto];
|
||||||
|
|
||||||
|
return match ($this->arah) {
|
||||||
|
'diatas' => collect($values)->contains(fn ($value) => $value > 0),
|
||||||
|
'dibawah' => collect($values)->contains(fn ($value) => $value < 0),
|
||||||
|
default => collect($values)->contains(fn ($value) => $value != 0),
|
||||||
|
};
|
||||||
|
})->values();
|
||||||
|
|
||||||
|
$sortedData = $comparison->sortBy('nama_lengkap')->values();
|
||||||
|
|
||||||
|
$sortedData = $sortedData->map(function ($item, $index) {
|
||||||
|
$item->no = $index + 1;
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->totals = [
|
||||||
|
'total_kenaikan_netto' => $sortedData->filter(fn ($row) => $row->selisih_netto > 0)->sum('selisih_netto'),
|
||||||
|
'total_penurunan_netto' => $sortedData->filter(fn ($row) => $row->selisih_netto < 0)->sum('selisih_netto'),
|
||||||
|
'total_kenaikan_bruto' => $sortedData->filter(fn ($row) => $row->selisih_bruto > 0)->sum('selisih_bruto'),
|
||||||
|
'total_penurunan_bruto' => $sortedData->filter(fn ($row) => $row->selisih_bruto < 0)->sum('selisih_bruto'),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($sortedData->count() > 0) {
|
||||||
|
for ($spacer = 0; $spacer < 3; $spacer++) {
|
||||||
|
$sortedData->push((object) ['is_spacer' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$summary = [
|
||||||
|
'Total Kenaikan P1' => 'total_kenaikan_bruto',
|
||||||
|
'Total Penurunan P1' => 'total_penurunan_bruto',
|
||||||
|
'Total Kenaikan P1 Setelah Pajak' => 'total_kenaikan_netto',
|
||||||
|
'Total Penurunan P1 Setelah Pajak' => 'total_penurunan_netto',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($summary as $label => $key) {
|
||||||
|
$sortedData->push((object) [
|
||||||
|
'is_summary' => true,
|
||||||
|
'nama_lengkap' => $label,
|
||||||
|
'summary_value' => $this->totals[$key] ?? 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sortedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function headings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'No.',
|
||||||
|
'Nama',
|
||||||
|
'NIP',
|
||||||
|
'Pangkat',
|
||||||
|
'Golongan',
|
||||||
|
'Jabatan Fungsional',
|
||||||
|
'Grade Jabatan Fungsional',
|
||||||
|
'Harga Jabatan Fungsional',
|
||||||
|
'Jabatan Tugas Tambahan',
|
||||||
|
'Grade Jabatan Tugas Tambahan',
|
||||||
|
'Harga Jabatan Tugas Tambahan',
|
||||||
|
'Jenis Pegawai',
|
||||||
|
'Selisih Bruto',
|
||||||
|
'Selisih Pajak',
|
||||||
|
'Selisih Netto',
|
||||||
|
'Keterangan',
|
||||||
|
'NPWP',
|
||||||
|
'Nomor Rekening',
|
||||||
|
'Unit Kerja',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($row): array
|
||||||
|
{
|
||||||
|
if ($row->is_spacer ?? false) {
|
||||||
|
return array_fill(0, 19, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row->is_summary ?? false) {
|
||||||
|
return [
|
||||||
|
'',
|
||||||
|
$row->nama_lengkap.':',
|
||||||
|
$row->summary_value,
|
||||||
|
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
$row->no,
|
||||||
|
$row->nama_lengkap,
|
||||||
|
$row->nip,
|
||||||
|
$row->pangkat,
|
||||||
|
$row->golongan,
|
||||||
|
$row->nama_jafung,
|
||||||
|
$row->grade_jafung,
|
||||||
|
$row->harga_jafung,
|
||||||
|
$row->nama_jtt,
|
||||||
|
$row->grade_jtt,
|
||||||
|
$row->harga_jtt,
|
||||||
|
$row->jenis_pegawai == 'dosen' ? 'Dosen' : ($row->jenis_pegawai == 'tendik' ? 'Tendik' : '-'),
|
||||||
|
$row->selisih_bruto ?: 0,
|
||||||
|
$row->selisih_pajak ?: 0,
|
||||||
|
$row->selisih_netto ?: 0,
|
||||||
|
$row->keterangan ?: '-',
|
||||||
|
$row->npwp,
|
||||||
|
$row->nomor_rekening,
|
||||||
|
$row->nama_unit,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function columnFormats(): array
|
||||||
|
{
|
||||||
|
$accountingFormat = '_("Rp"\ * #,##0.00_);_("Rp"\ * \-#,##0.00_);_("Rp"\ * "-"??_);_(@_)';
|
||||||
|
|
||||||
|
return [
|
||||||
|
'C' => '@', // NIP as text
|
||||||
|
'H' => $accountingFormat, // Harga Jabatan Fungsional
|
||||||
|
'K' => $accountingFormat, // Harga Jabatan Tugas Tambahan
|
||||||
|
'M' => $accountingFormat, // Selisih Bruto
|
||||||
|
'N' => $accountingFormat, // Selisih Pajak
|
||||||
|
'O' => $accountingFormat, // Selisih Netto
|
||||||
|
'Q' => '@', // NPWP as text
|
||||||
|
'R' => '@', // Nomor Rekening as text
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function styles(Worksheet $sheet)
|
||||||
|
{
|
||||||
|
$dataCount = $this->collection()->count();
|
||||||
|
$summaryStartRow = $dataCount - 2;
|
||||||
|
$accountingFormat = '_("Rp"\ * #,##0.00_);_("Rp"\ * \-#,##0.00_);_("Rp"\ * "-"??_);_(@_)';
|
||||||
|
|
||||||
|
$styles = [
|
||||||
|
1 => [
|
||||||
|
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
|
||||||
|
'fill' => [
|
||||||
|
'fillType' => Fill::FILL_SOLID,
|
||||||
|
'startColor' => ['rgb' => '4472C4'],
|
||||||
|
],
|
||||||
|
'alignment' => [
|
||||||
|
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||||
|
'vertical' => Alignment::VERTICAL_CENTER,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($dataCount > 0) {
|
||||||
|
for ($rowNumber = $summaryStartRow; $rowNumber <= $summaryStartRow + 3; $rowNumber++) {
|
||||||
|
$styles['B'.$rowNumber] = [
|
||||||
|
'font' => ['bold' => true],
|
||||||
|
];
|
||||||
|
$styles['C'.$rowNumber] = [
|
||||||
|
'font' => ['bold' => true],
|
||||||
|
'numberFormat' => ['formatCode' => $accountingFormat],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $styles;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Exports;
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use App\Helpers\JenjangPendidikanHelper;
|
||||||
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
||||||
use App\Models\Verifikator\JabatanPegawai;
|
use App\Models\Verifikator\JabatanPegawai;
|
||||||
use App\Models\Verifikator\JabatanTugasTambahanRiwayat;
|
use App\Models\Verifikator\JabatanTugasTambahanRiwayat;
|
||||||
@@ -26,6 +27,7 @@ class P2Export implements FromCollection, ShouldAutoSize, WithColumnFormatting,
|
|||||||
private readonly ?int $periode,
|
private readonly ?int $periode,
|
||||||
private readonly mixed $unitKerjaId,
|
private readonly mixed $unitKerjaId,
|
||||||
private readonly ?string $jenisPegawai,
|
private readonly ?string $jenisPegawai,
|
||||||
|
private readonly ?string $jenjangPendidikan = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function title(): string
|
public function title(): string
|
||||||
@@ -65,6 +67,10 @@ class P2Export implements FromCollection, ShouldAutoSize, WithColumnFormatting,
|
|||||||
$query->where('jpd.jenis_pegawai', $this->jenisPegawai);
|
$query->where('jpd.jenis_pegawai', $this->jenisPegawai);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->jenjangPendidikan !== null && $this->jenjangPendidikan !== '') {
|
||||||
|
JenjangPendidikanHelper::applyQueryFilter($query, 'verifikator.pegawais.pendidikan_terakhir', $this->jenjangPendidikan);
|
||||||
|
}
|
||||||
|
|
||||||
$data = $query->get();
|
$data = $query->get();
|
||||||
|
|
||||||
if ($data->isEmpty()) {
|
if ($data->isEmpty()) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Exports;
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use App\Helpers\JenjangPendidikanHelper;
|
||||||
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
||||||
use App\Models\Verifikator\JabatanPegawaiDetail;
|
use App\Models\Verifikator\JabatanPegawaiDetail;
|
||||||
use App\Models\Verifikator\JabatanTugasTambahanRiwayat;
|
use App\Models\Verifikator\JabatanTugasTambahanRiwayat;
|
||||||
@@ -53,11 +54,12 @@ class SimulasiJabatanExport implements WithMultipleSheets
|
|||||||
private readonly ?string $jenis = null,
|
private readonly ?string $jenis = null,
|
||||||
private readonly int|string|null $unitKerjaId = null,
|
private readonly int|string|null $unitKerjaId = null,
|
||||||
private readonly bool $grade12 = false,
|
private readonly bool $grade12 = false,
|
||||||
|
private readonly ?string $jenjangPendidikan = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function sheets(): array
|
public function sheets(): array
|
||||||
{
|
{
|
||||||
$rows = SimulasiJabatanSheet::rows($this->periode, $this->bulan, $this->unitKerjaId, $this->jenis, false, $this->grade12);
|
$rows = SimulasiJabatanSheet::rows($this->periode, $this->bulan, $this->unitKerjaId, $this->jenis, false, $this->grade12, false, $this->jenjangPendidikan);
|
||||||
$sheets = [new SimulasiJabatanSheet('All', $rows)];
|
$sheets = [new SimulasiJabatanSheet('All', $rows)];
|
||||||
foreach ($rows->groupBy(fn ($row) => $row['unit_kerja'] ?: 'Tanpa Unit Kerja') as $unit => $unitRows) {
|
foreach ($rows->groupBy(fn ($row) => $row['unit_kerja'] ?: 'Tanpa Unit Kerja') as $unit => $unitRows) {
|
||||||
$sheets[] = new SimulasiJabatanSheet($unit, $unitRows->values());
|
$sheets[] = new SimulasiJabatanSheet($unit, $unitRows->values());
|
||||||
@@ -70,12 +72,13 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
|||||||
{
|
{
|
||||||
public function __construct(private readonly string $sheetTitle, private readonly Collection $items) {}
|
public function __construct(private readonly string $sheetTitle, private readonly Collection $items) {}
|
||||||
|
|
||||||
public static function rows(int $periode, ?int $bulan = null, int|string|null $unitKerjaId = null, ?string $jenis = null, bool $raw = false, bool $grade12 = false, bool $splitUnit = false): Collection
|
public static function rows(int $periode, ?int $bulan = null, int|string|null $unitKerjaId = null, ?string $jenis = null, bool $raw = false, bool $grade12 = false, bool $splitUnit = false, ?string $jenjangPendidikan = null): Collection
|
||||||
{
|
{
|
||||||
$q = JabatanPegawaiDetailPoin::query()->select([
|
$q = JabatanPegawaiDetailPoin::query()->select([
|
||||||
'verifikator.jabatan_pegawais.nip', 'verifikator.poin_per_bulans.jabatan_pegawai_detail_id',
|
'verifikator.jabatan_pegawais.nip', 'verifikator.poin_per_bulans.jabatan_pegawai_detail_id',
|
||||||
'verifikator.pegawais.nama as nama_pegawai', 'verifikator.jabatan_pegawai_details.jenis_pegawai',
|
'verifikator.pegawais.nama as nama_pegawai', 'verifikator.jabatan_pegawai_details.jenis_pegawai',
|
||||||
'verifikator.pegawais.unit_kerja_nama as unit_kerja', 'verifikator.pegawais.unit_kerja_id',
|
'verifikator.pegawais.unit_kerja_nama as unit_kerja', 'verifikator.pegawais.unit_kerja_id',
|
||||||
|
'verifikator.pegawais.pendidikan_terakhir',
|
||||||
'verifikator.poin_per_bulans.poin_kegiatan',
|
'verifikator.poin_per_bulans.poin_kegiatan',
|
||||||
'verifikator.poin_per_bulans.poin_absen', 'verifikator.poin_per_bulans.poin_skp',
|
'verifikator.poin_per_bulans.poin_absen', 'verifikator.poin_per_bulans.poin_skp',
|
||||||
'verifikator.poin_per_bulans.poin_grade_14_17', 'verifikator.poin_per_bulans.detail_p2',
|
'verifikator.poin_per_bulans.poin_grade_14_17', 'verifikator.poin_per_bulans.detail_p2',
|
||||||
@@ -113,6 +116,7 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
|||||||
$q->where('verifikator.pegawais.unit_kerja_id', (int) $unitKerjaId);
|
$q->where('verifikator.pegawais.unit_kerja_id', (int) $unitKerjaId);
|
||||||
}
|
}
|
||||||
if ($jenis) $q->where('verifikator.jabatan_pegawai_details.jenis_pegawai', $jenis);
|
if ($jenis) $q->where('verifikator.jabatan_pegawai_details.jenis_pegawai', $jenis);
|
||||||
|
if ($jenjangPendidikan) JenjangPendidikanHelper::applyQueryFilter($q, 'verifikator.pegawais.pendidikan_terakhir', $jenjangPendidikan);
|
||||||
$excel = collect(json_decode(file_get_contents(public_path('data-jabatan-excel.json')), true) ?: [])->keyBy(fn ($x) => mb_strtolower(trim($x['nama_jabatan'] ?? '')));
|
$excel = collect(json_decode(file_get_contents(public_path('data-jabatan-excel.json')), true) ?: [])->keyBy(fn ($x) => mb_strtolower(trim($x['nama_jabatan'] ?? '')));
|
||||||
$source = $q->get();
|
$source = $q->get();
|
||||||
$details = JabatanPegawaiDetail::with(['fungsional','tambahan'])->whereIn('id', $source->pluck('jabatan_pegawai_detail_id'))->get()->keyBy('id');
|
$details = JabatanPegawaiDetail::with(['fungsional','tambahan'])->whereIn('id', $source->pluck('jabatan_pegawai_detail_id'))->get()->keyBy('id');
|
||||||
@@ -297,6 +301,7 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles,
|
|||||||
$out['raw_p2_final_374_g12'] = $final374g12;
|
$out['raw_p2_final_374_g12'] = $final374g12;
|
||||||
$out['raw_p2_final_377_g12'] = $final377g12;
|
$out['raw_p2_final_377_g12'] = $final377g12;
|
||||||
$out['raw_p2_final_excel_g12'] = $finalExcelg12;
|
$out['raw_p2_final_excel_g12'] = $finalExcelg12;
|
||||||
|
$out['raw_pendidikan_terakhir'] = (string) ($r->pendidikan_terakhir ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mode gabung (default): satu baris per pegawai — total seluruh unit bayar.
|
// Mode gabung (default): satu baris per pegawai — total seluruh unit bayar.
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||||
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rekap Excel "Total" untuk menu Simulasi Jabatan: satu baris per pegawai
|
||||||
|
* (atau per unit pembayaran bila mode pecah aktif) berisi Total P2 (2022),
|
||||||
|
* P2 (2023), dan P2 (Excel), ditutup satu baris TOTAL keseluruhan.
|
||||||
|
*
|
||||||
|
* Nilai sudah dihitung di controller (dari dataset yang sama dengan tabel &
|
||||||
|
* kartu ringkasan) dan diterima di sini sebagai angka mentah.
|
||||||
|
*
|
||||||
|
* @param Collection<int, array{nama_pegawai:string, nip:string, jenis_pegawai:string, unit_kerja:string, unit_pembayaran?:string, p2_2022:float, p2_2023:float, p2_excel:float, keterangan:string}> $items
|
||||||
|
*/
|
||||||
|
class SimulasiJabatanTotalExport implements FromCollection, WithHeadings, WithStyles, ShouldAutoSize, WithColumnFormatting, WithTitle
|
||||||
|
{
|
||||||
|
private const RUPIAH_FORMAT = '_([$Rp-421]* #,##0.00_);_([$Rp-421]* (#,##0.00);_([$Rp-421]* "-"??_);_(@_)';
|
||||||
|
|
||||||
|
public function __construct(private readonly Collection $items, private readonly bool $splitUnit = false) {}
|
||||||
|
|
||||||
|
public function collection(): Collection
|
||||||
|
{
|
||||||
|
$rows = $this->items->map(fn ($r) => array_values($r));
|
||||||
|
|
||||||
|
$total = collect(['p2_2022', 'p2_2023', 'p2_excel'])
|
||||||
|
->mapWithKeys(fn ($key) => [$key => $this->items->sum(fn ($r) => (float) ($r[$key] ?? 0))]);
|
||||||
|
|
||||||
|
// Kolom teks sebelum angka: Nama, NIP, Jenis Pegawai, Unit Kerja (+ Unit Pembayaran).
|
||||||
|
$lead = array_fill(0, $this->splitUnit ? 5 : 4, '');
|
||||||
|
$lead[0] = 'TOTAL';
|
||||||
|
|
||||||
|
return $rows->push(array_merge($lead, [$total['p2_2022'], $total['p2_2023'], $total['p2_excel'], '']));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function headings(): array
|
||||||
|
{
|
||||||
|
$head = ['Nama Pegawai', 'NIP', 'Jenis Pegawai', 'Unit Kerja'];
|
||||||
|
if ($this->splitUnit) {
|
||||||
|
$head[] = 'Unit Pembayaran';
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_merge($head, ['Total P2 (2022)', 'Total P2 (2023)', 'Total P2 (Excel)', 'Keterangan']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function columnFormats(): array
|
||||||
|
{
|
||||||
|
$cols = $this->splitUnit ? ['F', 'G', 'H'] : ['E', 'F', 'G'];
|
||||||
|
|
||||||
|
return array_fill_keys($cols, self::RUPIAH_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function title(): string
|
||||||
|
{
|
||||||
|
return 'Total P2';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function styles(Worksheet $sheet): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
1 => ['font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']], 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => '20C997']]],
|
||||||
|
$sheet->getHighestRow() => ['font' => ['bold' => true]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\Verifikator\PengajuanPresensi;
|
||||||
|
use App\Models\Verifikator\View\Pegawai;
|
||||||
|
use App\Services\DawaiService;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
class BawahanHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* TTL cache daftar bawahan (menit).
|
||||||
|
*/
|
||||||
|
private const CACHE_TTL = 30;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daftar NIP bawahan pegawai (dari DAWAI) untuk NIP atasan tertentu.
|
||||||
|
* Default: user yang sedang login. Hasil di-cache 30 menit.
|
||||||
|
*/
|
||||||
|
public static function nips(?string $userNip = null): array
|
||||||
|
{
|
||||||
|
$userNip = $userNip ?: (Auth::user()->nip ?? null);
|
||||||
|
|
||||||
|
if (! $userNip) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Cache::remember("bawahan_nips:{$userNip}", now()->addMinutes(self::CACHE_TTL), function () use ($userNip) {
|
||||||
|
$pegawai = Pegawai::withoutGlobalScopes()
|
||||||
|
->where('nip', $userNip)
|
||||||
|
->orWhere('nip_siakad', $userNip)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $pegawai) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$dawai = app(DawaiService::class);
|
||||||
|
|
||||||
|
$bawahan = $dawai->getListBawahan($pegawai->nip)['data']['bawahan'] ?? [];
|
||||||
|
|
||||||
|
if (empty($bawahan) && $pegawai->nip !== $pegawai->nip_siakad && $pegawai->nip_siakad) {
|
||||||
|
$bawahan = $dawai->getListBawahan($pegawai->nip_siakad)['data']['bawahan'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_unique(array_filter(array_column($bawahan, 'nip'))));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apakah user (default: login) punya minimal satu bawahan pegawai.
|
||||||
|
*/
|
||||||
|
public static function has(?string $userNip = null): bool
|
||||||
|
{
|
||||||
|
return count(self::nips($userNip)) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apakah NIP tertentu termasuk bawahan user yang sedang login.
|
||||||
|
*/
|
||||||
|
public static function contains(string $nip): bool
|
||||||
|
{
|
||||||
|
return in_array($nip, self::nips(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isSuperuser(): bool
|
||||||
|
{
|
||||||
|
return Auth::check() && Auth::user()->hasRole('Superuser');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pastikan user boleh mengakses data pegawai dengan NIP tsb (Superuser selalu boleh).
|
||||||
|
*/
|
||||||
|
public static function authorizeNip(?string $nip): void
|
||||||
|
{
|
||||||
|
abort_unless(self::isSuperuser() || ($nip && self::contains($nip)), 403, 'Pegawai ini bukan bawahan Anda.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pastikan semua pengajuan (by id) milik bawahan user (Superuser selalu boleh).
|
||||||
|
*
|
||||||
|
* @param array<int|string>|int|string $ids
|
||||||
|
*/
|
||||||
|
public static function authorizePengajuan($ids): void
|
||||||
|
{
|
||||||
|
if (self::isSuperuser()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = array_filter((array) $ids);
|
||||||
|
$nips = PengajuanPresensi::whereIn('id', $ids)->pluck('nip')->unique();
|
||||||
|
|
||||||
|
abort_unless(
|
||||||
|
$nips->isNotEmpty() && $nips->every(fn ($nip) => self::contains($nip)),
|
||||||
|
403,
|
||||||
|
'Pengajuan ini bukan milik bawahan Anda.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function forget(?string $userNip = null): void
|
||||||
|
{
|
||||||
|
$userNip = $userNip ?: (Auth::user()->nip ?? null);
|
||||||
|
|
||||||
|
if ($userNip) {
|
||||||
|
Cache::forget("bawahan_nips:{$userNip}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\Verifikator\View\Pegawai;
|
||||||
|
|
||||||
|
class JenjangPendidikanHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Nilai sentinel untuk kategori "belum diisi" (pendidikan_terakhir NULL/kosong).
|
||||||
|
* Tanpa ini, pegawai yang datanya kosong tidak akan pernah muncul di filter
|
||||||
|
* manapun sehingga jumlah per kategori bisa lebih kecil dari total keseluruhan.
|
||||||
|
*/
|
||||||
|
public const KOSONG = '__KOSONG__';
|
||||||
|
|
||||||
|
public const KOSONG_LABEL = '(Belum Diisi)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daftar jenjang pendidikan unik (sudah dinormalisasi) untuk dropdown filter.
|
||||||
|
*/
|
||||||
|
public static function options(): array
|
||||||
|
{
|
||||||
|
$raw = Pegawai::withoutGlobalScopes()
|
||||||
|
->whereNotNull('pendidikan_terakhir')
|
||||||
|
->distinct()
|
||||||
|
->pluck('pendidikan_terakhir');
|
||||||
|
|
||||||
|
$options = $raw->map(fn ($value) => self::normalize($value))
|
||||||
|
->unique()
|
||||||
|
->sort()
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
|
||||||
|
$options[] = self::KOSONG;
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Angka diploma -> angka romawi setara, dipakai untuk gabungkan "DIII" ke "D3", dst. */
|
||||||
|
private const DIPLOMA_ROMAN = ['2' => 'ii', '3' => 'iii', '4' => 'iv'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gabungkan varian penulisan (mis. "S-1 Adm Publik", "S-1" -> "S1";
|
||||||
|
* "SMA / sederajat", "SMA/SMK" -> "SMA"; "DIII" -> "D3";
|
||||||
|
* "Profesi", "Sp-1" -> "S1") jadi satu kategori.
|
||||||
|
*/
|
||||||
|
public static function normalize(string $value): string
|
||||||
|
{
|
||||||
|
$trimmed = trim($value);
|
||||||
|
|
||||||
|
if (preg_match('/^(Profesi|Sp-?1)\b/i', $trimmed)) {
|
||||||
|
return 'S1';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^S-?([123])\b/i', $trimmed, $matches)) {
|
||||||
|
return 'S'.$matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^SMA\b/i', $trimmed)) {
|
||||||
|
return 'SMA';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^D-?(2|II|3|III|4|IV)\b/i', $trimmed, $matches)) {
|
||||||
|
$digit = array_search(strtolower($matches[1]), self::DIPLOMA_ROMAN, true) ?: $matches[1];
|
||||||
|
|
||||||
|
return 'D'.$digit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $trimmed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terapkan filter jenjang pendidikan ke query builder, mencocokkan seluruh
|
||||||
|
* varian penulisan yang tergabung dalam satu kategori (S1/S2/S3/SMA/D2/D3/D4).
|
||||||
|
*/
|
||||||
|
public static function applyQueryFilter($query, string $column, string $jenjangPendidikan): void
|
||||||
|
{
|
||||||
|
if ($jenjangPendidikan === self::KOSONG) {
|
||||||
|
$query->whereNull($column);
|
||||||
|
} elseif ($jenjangPendidikan === 'S1') {
|
||||||
|
$query->whereRaw("{$column} ~* ?", ['^(s-?1|profesi|sp-?1)']);
|
||||||
|
} elseif (preg_match('/^S([23])$/', $jenjangPendidikan, $matches)) {
|
||||||
|
$query->whereRaw("{$column} ~* ?", ['^s-?'.$matches[1]]);
|
||||||
|
} elseif ($jenjangPendidikan === 'SMA') {
|
||||||
|
$query->whereRaw("{$column} ~* ?", ['^sma']);
|
||||||
|
} elseif (preg_match('/^D([234])$/', $jenjangPendidikan, $matches)) {
|
||||||
|
$roman = self::DIPLOMA_ROMAN[$matches[1]];
|
||||||
|
$query->whereRaw("{$column} ~* ?", ['^d-?('.$matches[1].'|'.$roman.')\y']);
|
||||||
|
} else {
|
||||||
|
$query->where($column, $jenjangPendidikan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terapkan filter jenjang pendidikan ke collection di memori (dataset yang
|
||||||
|
* sudah di-cache), dengan nilai per baris yang sudah dinormalisasi lebih dulu.
|
||||||
|
*/
|
||||||
|
public static function applyCollectionFilter(\Illuminate\Support\Collection $rows, string $column, string $jenjangPendidikan): \Illuminate\Support\Collection
|
||||||
|
{
|
||||||
|
$target = $jenjangPendidikan === self::KOSONG ? '' : $jenjangPendidikan;
|
||||||
|
|
||||||
|
return $rows->where($column, $target);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,11 +10,14 @@ use App\Models\Verifikator\Honorer;
|
|||||||
use App\Models\Verifikator\PengajuanPresensi;
|
use App\Models\Verifikator\PengajuanPresensi;
|
||||||
use App\Models\Verifikator\Tendik;
|
use App\Models\Verifikator\Tendik;
|
||||||
use App\Services\DawaiService;
|
use App\Services\DawaiService;
|
||||||
|
use App\Services\VerifikasiAbsenLinkService;
|
||||||
|
use App\Services\WhatsAppService;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class PengajuanAbsenController extends Controller
|
class PengajuanAbsenController extends Controller
|
||||||
{
|
{
|
||||||
@@ -83,14 +86,14 @@ class PengajuanAbsenController extends Controller
|
|||||||
|
|
||||||
public function store(AbsenRequest $request)
|
public function store(AbsenRequest $request)
|
||||||
{
|
{
|
||||||
// if (! in_array($request->nip, ['19980513202401011', '19970812202101011'])) {
|
if (! in_array($request->nip, ['19980513202401011', '19970812202101011'])) {
|
||||||
// return response()->json([
|
return response()->json([
|
||||||
// 'code' => 400,
|
'code' => 400,
|
||||||
// 'status' => 'failed',
|
'status' => 'failed',
|
||||||
// 'message' => 'Sedang proses Remunerasi, Tidak dapat mengajukan absen untuk saat ini',
|
'message' => 'Sedang proses Remunerasi, Tidak dapat mengajukan absen untuk saat ini',
|
||||||
// // 'message' => 'Sedang proses Maintenance, Tidak dapat mengajukan absen untuk saat ini',
|
// 'message' => 'Sedang proses Maintenance, Tidak dapat mengajukan absen untuk saat ini',
|
||||||
// ], 400);
|
], 400);
|
||||||
// }
|
}
|
||||||
|
|
||||||
$batasBulanPengajuan = (int) date('m');
|
$batasBulanPengajuan = (int) date('m');
|
||||||
if (date('j') < 2) {
|
if (date('j') < 2) {
|
||||||
@@ -109,6 +112,12 @@ class PengajuanAbsenController extends Controller
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$dawaiService = new DawaiService;
|
$dawaiService = new DawaiService;
|
||||||
|
|
||||||
|
// Keterangan diisi otomatis dari nama kategori/tipe absen (DAWAI listStatusPresensi).
|
||||||
|
$statusPresensiList = collect($dawaiService->listStatusPresensi());
|
||||||
|
$namaKategori = $statusPresensiList->firstWhere('id', (int) $request->kategori)['nama'] ?? null;
|
||||||
|
$request->merge(['keterangan' => $namaKategori]);
|
||||||
|
|
||||||
$tahun = explode('-', $request->tanggal)[0];
|
$tahun = explode('-', $request->tanggal)[0];
|
||||||
$bulan = explode('-', $request->tanggal)[1];
|
$bulan = explode('-', $request->tanggal)[1];
|
||||||
$tanggal = explode('-', $request->tanggal)[2];
|
$tanggal = explode('-', $request->tanggal)[2];
|
||||||
@@ -290,7 +299,8 @@ class PengajuanAbsenController extends Controller
|
|||||||
$absen['file'] = $namaFile;
|
$absen['file'] = $namaFile;
|
||||||
|
|
||||||
// Simpan file ke storage/app/public/absen/presensi/{periode}
|
// Simpan file ke storage/app/public/absen/presensi/{periode}
|
||||||
$filePath = $request->file('bukti')->storeAs("absen/presensi/$periode", $namaFile, 'public');
|
$buktiFile = $request->file('file_surat') ?? $request->file('bukti');
|
||||||
|
$filePath = $buktiFile->storeAs("absen/presensi/$periode", $namaFile, 'public');
|
||||||
|
|
||||||
if (! $filePath) {
|
if (! $filePath) {
|
||||||
Log::error("Gagal menyimpan file: $namaFile");
|
Log::error("Gagal menyimpan file: $namaFile");
|
||||||
@@ -302,8 +312,29 @@ class PengajuanAbsenController extends Controller
|
|||||||
], 500);
|
], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->hasFile('file_lampiran')) {
|
||||||
|
$namaFileLampiran = uniqid().'-'.$pegawai->nip.'-lampiran.pdf';
|
||||||
|
$filePathLampiran = $request->file('file_lampiran')->storeAs("absen/presensi/$periode", $namaFileLampiran, 'public');
|
||||||
|
|
||||||
|
if (! $filePathLampiran) {
|
||||||
|
Log::error("Gagal menyimpan file lampiran: $namaFileLampiran");
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'code' => 500,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Gagal menyimpan file lampiran',
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
$absen['file_lampiran'] = $namaFileLampiran;
|
||||||
|
} else {
|
||||||
|
unset($absen['file_lampiran']);
|
||||||
|
}
|
||||||
|
|
||||||
$pengajuan = PengajuanPresensi::create($absen);
|
$pengajuan = PengajuanPresensi::create($absen);
|
||||||
|
|
||||||
|
$this->notifikasiAtasanWhatsApp($pengajuan, $pegawai, $dawaiService);
|
||||||
|
|
||||||
// Ambil nama kategori dari Dawai Service
|
// Ambil nama kategori dari Dawai Service
|
||||||
$statusPresensi = collect($dawaiService->listStatusPresensi());
|
$statusPresensi = collect($dawaiService->listStatusPresensi());
|
||||||
$kategoriStatus = $statusPresensi->firstWhere('id', (int) $request->kategori);
|
$kategoriStatus = $statusPresensi->firstWhere('id', (int) $request->kategori);
|
||||||
@@ -549,4 +580,43 @@ class PengajuanAbsenController extends Controller
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kirim notifikasi WhatsApp ke atasan berisi link verifikasi (terima/tolak) pengajuan absen.
|
||||||
|
* Kegagalan di sini tidak menggagalkan pengajuan (dicatat ke log saja).
|
||||||
|
*/
|
||||||
|
private function notifikasiAtasanWhatsApp(PengajuanPresensi $pengajuan, $pegawai, DawaiService $dawaiService): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$atasan = $dawaiService->getListBawahan($pengajuan->nip)['data']['atasan'][0] ?? null;
|
||||||
|
|
||||||
|
if (! $atasan || empty($atasan['nip'])) {
|
||||||
|
Log::error("Notifikasi WhatsApp Pengajuan Absen: atasan tidak ditemukan untuk NIP $pengajuan->nip");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = (new VerifikasiAbsenLinkService())->generate($pengajuan->id, $atasan['nip']);
|
||||||
|
|
||||||
|
$tanggalMulai = Carbon::parse($pengajuan->tanggal_mulai);
|
||||||
|
$tanggalSelesai = Carbon::parse($pengajuan->tanggal_selesai ?? $pengajuan->tanggal_mulai);
|
||||||
|
|
||||||
|
// TODO: nomor WA atasan masih manual/sementara, belum ada sumber data resminya.
|
||||||
|
$nomorTujuan = '6289698424476';
|
||||||
|
|
||||||
|
(new WhatsAppService())->sendPengajuanAbsenNotification(
|
||||||
|
$nomorTujuan,
|
||||||
|
$atasan['nama_lengkap'] ?? $atasan['nama'],
|
||||||
|
$pegawai->nama,
|
||||||
|
$pengajuan->nip,
|
||||||
|
max($tanggalMulai->diffInDays($tanggalSelesai), 1),
|
||||||
|
$tanggalMulai->format('d-m-Y'),
|
||||||
|
$tanggalSelesai->format('d-m-Y'),
|
||||||
|
$pengajuan->keterangan ?: '-',
|
||||||
|
$link['button_param']
|
||||||
|
);
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
Log::error('Notifikasi WhatsApp Pengajuan Absen : '.$th->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api\VerifikasiAbsen;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Verifikator\PengajuanPresensi;
|
||||||
|
use App\Services\DawaiService;
|
||||||
|
use App\Services\VerifikasiAbsenLinkService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class LinkController extends Controller
|
||||||
|
{
|
||||||
|
private DawaiService $dawaiService;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected VerifikasiAbsenLinkService $linkService,
|
||||||
|
) {
|
||||||
|
$this->dawaiService = new DawaiService('http://172.16.40.128/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generate(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'pengajuan_id' => 'required|integer',
|
||||||
|
'nip' => 'required|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$pengajuan = PengajuanPresensi::find($request->pengajuan_id);
|
||||||
|
|
||||||
|
if (! $pengajuan) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Pengajuan tidak ditemukan.',
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->dawaiService->isAtasanDari($request->nip, $pengajuan->nip)) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'NIP tersebut bukan atasan dari pemohon pengajuan ini.',
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = $this->linkService->generate($pengajuan->id, $request->nip);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'data' => $link,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,302 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api\VerifikasiAbsen;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Verifikator\PengajuanPresensi;
|
||||||
|
use App\Models\Verifikator\View\Pegawai;
|
||||||
|
use App\Services\DawaiService;
|
||||||
|
use App\Services\GoogleDriveService;
|
||||||
|
use App\Services\TteService;
|
||||||
|
use App\Services\VerifikasiAbsenLinkService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class VerifikasiAbsenController extends Controller
|
||||||
|
{
|
||||||
|
const BATAS_HARI_VERIFIKASI = 5;
|
||||||
|
|
||||||
|
private DawaiService $dawaiService;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected TteService $tteService,
|
||||||
|
protected GoogleDriveService $googleDriveService,
|
||||||
|
protected VerifikasiAbsenLinkService $linkService,
|
||||||
|
) {
|
||||||
|
$this->dawaiService = new DawaiService('http://172.16.40.128/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(Request $request, int $id): JsonResponse
|
||||||
|
{
|
||||||
|
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||||
|
|
||||||
|
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||||
|
|
||||||
|
if ($nipAtasan === false) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'state' => 'unauthorized',
|
||||||
|
'message' => 'Tautan ini tidak valid, sudah kedaluwarsa, atau Anda bukan atasan dari pegawai pemohon.',
|
||||||
|
], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'state' => $this->resolveState($pengajuan),
|
||||||
|
'data' => $this->formatPengajuan($pengajuan),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setujui(Request $request, int $id): JsonResponse
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'nik' => 'required|string',
|
||||||
|
'passphrase' => 'required|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||||
|
|
||||||
|
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||||
|
|
||||||
|
if ($nipAtasan === false) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Anda tidak berwenang memverifikasi pengajuan ini.',
|
||||||
|
], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
|
||||||
|
return $gagal;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dokumenTertandatangani = $this->tteService->signDokumenUser(
|
||||||
|
$request->nik,
|
||||||
|
$request->passphrase,
|
||||||
|
$pengajuan->file,
|
||||||
|
$this->linkService->url($pengajuan->id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($dokumenTertandatangani === false) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Gagal menandatangani dokumen. Periksa kembali NIK dan Passphrase Anda.',
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->googleDriveService->uploadPdf(
|
||||||
|
$dokumenTertandatangani,
|
||||||
|
$pengajuan->nip,
|
||||||
|
$pengajuan->pegawai?->nama ?? $pengajuan->nip,
|
||||||
|
$pengajuan->tanggal_mulai,
|
||||||
|
$pengajuan->kategori
|
||||||
|
)) {
|
||||||
|
Log::error("Gagal mengunggah dokumen tertandatangani ke Google Drive untuk pengajuan #$id");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->proses($pengajuan, 'Diterima', null, $nipAtasan)) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Gagal menyetujui pengajuan absen. Silakan coba lagi.',
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Pengajuan absen berhasil disetujui.',
|
||||||
|
'state' => $this->resolveState($pengajuan),
|
||||||
|
'data' => $this->formatPengajuan($pengajuan),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tolak(Request $request, int $id): JsonResponse
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'catatan' => 'required|string|max:500',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||||
|
|
||||||
|
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||||
|
|
||||||
|
if ($nipAtasan === false) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Anda tidak berwenang memverifikasi pengajuan ini.',
|
||||||
|
], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
|
||||||
|
return $gagal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->proses($pengajuan, 'Ditolak', $request->catatan, $nipAtasan)) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Gagal menolak pengajuan absen. Silakan coba lagi.',
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Pengajuan absen berhasil ditolak.',
|
||||||
|
'state' => $this->resolveState($pengajuan),
|
||||||
|
'data' => $this->formatPengajuan($pengajuan),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function cekBisaDiproses(PengajuanPresensi $pengajuan): ?JsonResponse
|
||||||
|
{
|
||||||
|
if ($pengajuan->status !== 'Diajukan') {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Pengajuan ini sudah diproses sebelumnya.',
|
||||||
|
'state' => 'already_processed',
|
||||||
|
'data' => $this->formatPengajuan($pengajuan),
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isExpired($pengajuan)) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Pengajuan ini sudah kadaluarsa dan tidak dapat diverifikasi lagi.',
|
||||||
|
'state' => 'expired',
|
||||||
|
'data' => $this->formatPengajuan($pengajuan),
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveState(PengajuanPresensi $pengajuan): string
|
||||||
|
{
|
||||||
|
if ($pengajuan->status !== 'Diajukan') {
|
||||||
|
return 'already_processed';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isExpired($pengajuan)) {
|
||||||
|
return 'expired';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'pending';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatPengajuan(PengajuanPresensi $pengajuan): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $pengajuan->id,
|
||||||
|
'nip' => $pengajuan->nip,
|
||||||
|
'nama' => $pengajuan->pegawai?->nama,
|
||||||
|
'tanggal' => $pengajuan->tanggal_mulai,
|
||||||
|
'kategori' => $pengajuan->kategori,
|
||||||
|
'keterangan' => $pengajuan->keterangan,
|
||||||
|
'file' => $pengajuan->file,
|
||||||
|
'status' => $pengajuan->status,
|
||||||
|
'alasan' => $pengajuan->notes?->last()?->message,
|
||||||
|
'created_at' => $pengajuan->created_at,
|
||||||
|
'batas_hari_verifikasi' => self::BATAS_HARI_VERIFIKASI,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isExpired(PengajuanPresensi $pengajuan): bool
|
||||||
|
{
|
||||||
|
return $pengajuan->created_at?->copy()->addDays(self::BATAS_HARI_VERIFIKASI)->isPast() ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan): string|false
|
||||||
|
{
|
||||||
|
$nip = $request->input('nip');
|
||||||
|
$expires = $request->input('expires');
|
||||||
|
$signature = $request->input('signature');
|
||||||
|
|
||||||
|
if (! $this->linkService->verify($pengajuan->id, $nip, $expires, $signature)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->dawaiService->isAtasanDari($nip, $pengajuan->nip)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nip;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function proses(PengajuanPresensi $pengajuan, string $status, ?string $catatan, string $nipAtasan): bool
|
||||||
|
{
|
||||||
|
$atasan = Pegawai::withoutGlobalScopes()->where('nip', $nipAtasan)->first();
|
||||||
|
$verifikatorRole = 'Atasan (via WhatsApp)';
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$pengajuan->update(['status' => $status]);
|
||||||
|
|
||||||
|
$pengajuan->logs()->create([
|
||||||
|
'user_id' => null,
|
||||||
|
'method' => 'POST',
|
||||||
|
'employee_id' => $nipAtasan,
|
||||||
|
'employee_name' => $atasan?->nama ?? $pengajuan->pegawai?->nama,
|
||||||
|
'employee_role' => $verifikatorRole,
|
||||||
|
'message' => 'Pengajuan Presensi Berhasil '.strtolower($status).' via WhatsApp',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($status === 'Ditolak') {
|
||||||
|
$pengajuan->notes()->create([
|
||||||
|
'type' => 'Catatan',
|
||||||
|
'user_id' => null,
|
||||||
|
'employee_id' => $nipAtasan,
|
||||||
|
'employee_name' => $atasan?->nama ?? $pengajuan->pegawai?->nama,
|
||||||
|
'employee_role' => $verifikatorRole,
|
||||||
|
'message' => $catatan,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$pengajuan->refresh()->load('notes');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$webhookResponse = Http::timeout(5)
|
||||||
|
->withHeaders(['X-API-Key' => config('services.verifikator_webhook.key')])
|
||||||
|
->post(config('services.verifikator_webhook.url'), [
|
||||||
|
'jenis' => 'izin',
|
||||||
|
'nip' => $pengajuan->nip,
|
||||||
|
'tanggal' => $pengajuan->tanggal_mulai,
|
||||||
|
'kategori' => $this->mapKategoriSlug($pengajuan->getRawOriginal('kategori')),
|
||||||
|
'status' => $status === 'Diterima' ? 'approved' : 'rejected',
|
||||||
|
'alasan' => $catatan ?? '',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($webhookResponse->successful()) {
|
||||||
|
Log::info("Webhook Verifikator via WhatsApp berhasil: {$pengajuan->nip} ($status)");
|
||||||
|
} else {
|
||||||
|
Log::warning("Webhook Verifikator via WhatsApp gagal: {$pengajuan->nip} ($status) - HTTP {$webhookResponse->status()}");
|
||||||
|
}
|
||||||
|
} catch (Throwable $webhookException) {
|
||||||
|
Log::error("Webhook Verifikator via WhatsApp error: {$pengajuan->nip} ($status) - ".$webhookException->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
DB::rollBack();
|
||||||
|
Log::error("Verifikasi Absen via WhatsApp ($status): ".$th->getMessage());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function mapKategoriSlug(mixed $kategoriId): ?string
|
||||||
|
{
|
||||||
|
return match ((int) $kategoriId) {
|
||||||
|
2 => 'dinas',
|
||||||
|
3 => 'terlambat',
|
||||||
|
20 => 'lupa_absen',
|
||||||
|
21 => 'cepat_pulang',
|
||||||
|
24 => 'lupa_absen_masuk',
|
||||||
|
25 => 'lupa_absen_pulang',
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,8 +27,13 @@ class LoginController extends Controller
|
|||||||
return redirect('dashboard');
|
return redirect('dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config('app.login_mode') === 2) {
|
return view('auth.login-sso');
|
||||||
return view('auth.login-sso');
|
}
|
||||||
|
|
||||||
|
function ariyutta()
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
return redirect('dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('auth.login');
|
return view('auth.login');
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Lainnya\SimulasiJabatan;
|
namespace App\Http\Controllers\Lainnya\SimulasiJabatan;
|
||||||
|
|
||||||
|
use App\Helpers\JenjangPendidikanHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Verifikator\JabatanPegawaiDetailPoin;
|
use App\Models\Verifikator\JabatanPegawaiDetailPoin;
|
||||||
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
||||||
@@ -14,6 +15,7 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use App\Exports\SimulasiJabatanExport;
|
use App\Exports\SimulasiJabatanExport;
|
||||||
|
use App\Exports\SimulasiJabatanTotalExport;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
|
||||||
class SimulasiJabatanController extends Controller
|
class SimulasiJabatanController extends Controller
|
||||||
@@ -23,8 +25,9 @@ class SimulasiJabatanController extends Controller
|
|||||||
$title = 'Simulasi Jabatan';
|
$title = 'Simulasi Jabatan';
|
||||||
$periodes = Periode::orderByDesc('id_periode')->get();
|
$periodes = Periode::orderByDesc('id_periode')->get();
|
||||||
$periodeNow = optional(Periode::where('status', true)->first())->id_periode;
|
$periodeNow = optional(Periode::where('status', true)->first())->id_periode;
|
||||||
|
$jenjangPendidikanList = JenjangPendidikanHelper::options();
|
||||||
|
|
||||||
return view('lainnya.simulasi-jabatan.index', compact('title', 'periodes', 'periodeNow'));
|
return view('lainnya.simulasi-jabatan.index', compact('title', 'periodes', 'periodeNow', 'jenjangPendidikanList'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,6 +48,10 @@ class SimulasiJabatanController extends Controller
|
|||||||
$rows = $rows->where('jenis_pegawai', $request->input('jenis_pegawai'));
|
$rows = $rows->where('jenis_pegawai', $request->input('jenis_pegawai'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->filled('jenjang_pendidikan')) {
|
||||||
|
$rows = JenjangPendidikanHelper::applyCollectionFilter($rows, 'jenjang_pendidikan', $request->input('jenjang_pendidikan'));
|
||||||
|
}
|
||||||
|
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +150,9 @@ class SimulasiJabatanController extends Controller
|
|||||||
if ($request->filled('jenis_pegawai')) {
|
if ($request->filled('jenis_pegawai')) {
|
||||||
$rows = $rows->where('jenis_pegawai', $request->input('jenis_pegawai'));
|
$rows = $rows->where('jenis_pegawai', $request->input('jenis_pegawai'));
|
||||||
}
|
}
|
||||||
|
if ($request->filled('jenjang_pendidikan')) {
|
||||||
|
$rows = JenjangPendidikanHelper::applyCollectionFilter($rows, 'jenjang_pendidikan', $request->input('jenjang_pendidikan'));
|
||||||
|
}
|
||||||
|
|
||||||
$parse = fn ($value) => (float) str_replace(',', '.', str_replace('.', '', (string) $value));
|
$parse = fn ($value) => (float) str_replace(',', '.', str_replace('.', '', (string) $value));
|
||||||
|
|
||||||
@@ -198,7 +208,9 @@ class SimulasiJabatanController extends Controller
|
|||||||
*/
|
*/
|
||||||
public static function datasetCacheKey(int $periode, bool $splitUnit = false): string
|
public static function datasetCacheKey(int $periode, bool $splitUnit = false): string
|
||||||
{
|
{
|
||||||
return "simulasi-jabatan:dataset:{$periode}".($splitUnit ? ':split-unit' : '');
|
// v3: aturan normalisasi jenjang_pendidikan berubah (mis. Profesi/Sp-1 -> S1,
|
||||||
|
// DIII -> D3) — versi dinaikkan supaya cache lama tidak dipakai ulang.
|
||||||
|
return "simulasi-jabatan:dataset:v3:{$periode}".($splitUnit ? ':split-unit' : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -280,6 +292,7 @@ class SimulasiJabatanController extends Controller
|
|||||||
'nip' => $nip,
|
'nip' => $nip,
|
||||||
'nama_pegawai' => $row['nama_pegawai'],
|
'nama_pegawai' => $row['nama_pegawai'],
|
||||||
'jenis_pegawai' => mb_strtolower((string) $row['jenis_pegawai']),
|
'jenis_pegawai' => mb_strtolower((string) $row['jenis_pegawai']),
|
||||||
|
'jenjang_pendidikan' => JenjangPendidikanHelper::normalize((string) ($row['raw_pendidikan_terakhir'] ?? '')),
|
||||||
'unit_kerja' => $row['unit_kerja'] === 'Tanpa Unit Kerja' ? '' : $row['unit_kerja'],
|
'unit_kerja' => $row['unit_kerja'] === 'Tanpa Unit Kerja' ? '' : $row['unit_kerja'],
|
||||||
'unit_kerja_id' => (int) $row['raw_unit_kerja_id'],
|
'unit_kerja_id' => (int) $row['raw_unit_kerja_id'],
|
||||||
'unit_pembayaran' => $row['unit_pembayaran'] ?? null,
|
'unit_pembayaran' => $row['unit_pembayaran'] ?? null,
|
||||||
@@ -311,9 +324,61 @@ class SimulasiJabatanController extends Controller
|
|||||||
$periode = (int) ($request->input('periode') ?: optional(Periode::where('status', true)->first())->id_periode);
|
$periode = (int) ($request->input('periode') ?: optional(Periode::where('status', true)->first())->id_periode);
|
||||||
$jenis = $request->input('jenis_pegawai') ?: null;
|
$jenis = $request->input('jenis_pegawai') ?: null;
|
||||||
$unitKerjaId = $request->input('unit_kerja_id') ?: null;
|
$unitKerjaId = $request->input('unit_kerja_id') ?: null;
|
||||||
|
$jenjangPendidikan = $request->input('jenjang_pendidikan') ?: null;
|
||||||
$grade12 = $request->boolean('grade12');
|
$grade12 = $request->boolean('grade12');
|
||||||
$suffix = ($unitKerjaId ? '-unit'.$unitKerjaId : '').($grade12 ? '-grade12' : '');
|
$suffix = ($unitKerjaId ? '-unit'.$unitKerjaId : '').($grade12 ? '-grade12' : '');
|
||||||
return Excel::download(new SimulasiJabatanExport($periode, null, $jenis, $unitKerjaId, $grade12), 'simulasi-jabatan-'.$periode.$suffix.'.xlsx');
|
return Excel::download(new SimulasiJabatanExport($periode, null, $jenis, $unitKerjaId, $grade12, $jenjangPendidikan), 'simulasi-jabatan-'.$periode.$suffix.'.xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rekap Excel "Total": ringkas — satu baris per pegawai (atau per unit
|
||||||
|
* pembayaran bila mode pecah aktif) berisi Total P2 (2022), P2 (2023),
|
||||||
|
* P2 (Excel), plus satu baris TOTAL keseluruhan. Sumber angka sama dengan
|
||||||
|
* tabel & kartu ringkasan (dataset ter-cache), menghormati filter periode,
|
||||||
|
* unit kerja, jenis pegawai, simulasi +12 poin grade, dan unit pembayaran.
|
||||||
|
*/
|
||||||
|
public function exportTotal(Request $request)
|
||||||
|
{
|
||||||
|
@set_time_limit(300);
|
||||||
|
@ini_set('max_execution_time', '300');
|
||||||
|
|
||||||
|
$periode = (int) ($request->input('periode') ?: optional(Periode::where('status', true)->first())->id_periode);
|
||||||
|
$splitUnit = $request->boolean('split_unit');
|
||||||
|
$grade12 = $request->boolean('grade12');
|
||||||
|
$unitKerjaId = $request->input('unit_kerja_id') ?: null;
|
||||||
|
|
||||||
|
$key = $grade12 ? '_g12' : '';
|
||||||
|
$parse = fn ($value) => (float) str_replace(',', '.', str_replace('.', '', (string) $value));
|
||||||
|
|
||||||
|
$rows = $this->applyUnitJenisFilter($this->dataset($periode, $splitUnit), $request)
|
||||||
|
->values()
|
||||||
|
->map(function ($row) use ($parse, $key, $splitUnit) {
|
||||||
|
$out = [
|
||||||
|
'nama_pegawai' => $row['nama_pegawai'],
|
||||||
|
'nip' => "'".$row['nip'],
|
||||||
|
'jenis_pegawai' => strtoupper((string) $row['jenis_pegawai']),
|
||||||
|
'unit_kerja' => $row['unit_kerja'] ?: 'Tanpa Unit Kerja',
|
||||||
|
];
|
||||||
|
if ($splitUnit) {
|
||||||
|
$out['unit_pembayaran'] = $row['unit_pembayaran'] ?: '-';
|
||||||
|
}
|
||||||
|
$out['p2_2022'] = $parse($row['p2_total_374'.$key]);
|
||||||
|
$out['p2_2023'] = $parse($row['p2_total_377'.$key]);
|
||||||
|
$out['p2_excel'] = $parse($row['p2_total_excel'.$key]);
|
||||||
|
// Poin P2 baru terbentuk bila Total Poin melewati ambang 12
|
||||||
|
// (rumus P2 memakai ...-12). Bila di bawah itu, atau ketiga versi
|
||||||
|
// P2 nol, tandai supaya mudah difilter di Excel.
|
||||||
|
$out['keterangan'] = ($parse($row['total_poin']) < 12
|
||||||
|
|| ($out['p2_2022'] == 0.0 && $out['p2_2023'] == 0.0 && $out['p2_excel'] == 0.0))
|
||||||
|
? 'Poin P2 tidak mencukupi 12 Poin'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
});
|
||||||
|
|
||||||
|
$suffix = ($unitKerjaId ? '-unit'.$unitKerjaId : '').($grade12 ? '-grade12' : '').($splitUnit ? '-unit-pembayaran' : '');
|
||||||
|
|
||||||
|
return Excel::download(new SimulasiJabatanTotalExport($rows, $splitUnit), 'simulasi-jabatan-total-'.$periode.$suffix.'.xlsx');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,186 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Lainnya\VerifikasiAbsen;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Models\Verifikator\PengajuanPresensi;
|
|
||||||
use App\Services\DawaiService;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\View\View;
|
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
class VerifikasiAbsenController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct(protected DawaiService $dawaiService) {}
|
|
||||||
|
|
||||||
public function showSetujui(int $id): View|RedirectResponse
|
|
||||||
{
|
|
||||||
$pengajuan = PengajuanPresensi::with('pegawai')->findOrFail($id);
|
|
||||||
|
|
||||||
if ($pengajuan->status !== 'Diajukan') {
|
|
||||||
return redirect()->route('verifikasi-absen.sudah-diproses', $id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = 'Setujui Pengajuan Absen';
|
|
||||||
|
|
||||||
return view('lainnya.verifikasi-absen.setujui', compact('title', 'pengajuan'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setujui(Request $request, int $id): RedirectResponse
|
|
||||||
{
|
|
||||||
$pengajuan = PengajuanPresensi::findOrFail($id);
|
|
||||||
|
|
||||||
if ($pengajuan->status !== 'Diajukan') {
|
|
||||||
return redirect()->route('verifikasi-absen.sudah-diproses', $id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$success = $this->proses([$id], 'Diterima', null);
|
|
||||||
|
|
||||||
if ($success) {
|
|
||||||
return redirect()->route('verifikasi-absen.berhasil-disetujui', $id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return back()->with('error', 'Gagal menyetujui pengajuan absen. Silakan coba lagi.');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function berhasilDisetujui(int $id): View
|
|
||||||
{
|
|
||||||
$pengajuan = PengajuanPresensi::with('pegawai')->findOrFail($id);
|
|
||||||
$title = 'Berhasil Menyetujui Pengajuan Absen';
|
|
||||||
|
|
||||||
return view('lainnya.verifikasi-absen.berhasil-disetujui', compact('title', 'pengajuan'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function showTolak(int $id): View|RedirectResponse
|
|
||||||
{
|
|
||||||
$pengajuan = PengajuanPresensi::with('pegawai')->findOrFail($id);
|
|
||||||
|
|
||||||
if ($pengajuan->status !== 'Diajukan') {
|
|
||||||
return redirect()->route('verifikasi-absen.sudah-diproses', $id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = 'Tolak Pengajuan Absen';
|
|
||||||
|
|
||||||
return view('lainnya.verifikasi-absen.tolak', compact('title', 'pengajuan'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tolak(Request $request, int $id): JsonResponse
|
|
||||||
{
|
|
||||||
$request->validate([
|
|
||||||
'catatan' => 'required|string|max:500',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$pengajuan = PengajuanPresensi::findOrFail($id);
|
|
||||||
|
|
||||||
if ($pengajuan->status !== 'Diajukan') {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Pengajuan ini sudah diproses sebelumnya.',
|
|
||||||
], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
$success = $this->proses([$id], 'Ditolak', $request->catatan);
|
|
||||||
|
|
||||||
if ($success) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Pengajuan absen berhasil ditolak.',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Gagal menolak pengajuan absen. Silakan coba lagi.',
|
|
||||||
], 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sudahDiproses(int $id): View
|
|
||||||
{
|
|
||||||
$pengajuan = PengajuanPresensi::with('pegawai')->findOrFail($id);
|
|
||||||
$title = 'Pengajuan Sudah Diproses';
|
|
||||||
|
|
||||||
return view('lainnya.verifikasi-absen.sudah-diproses', compact('title', 'pengajuan'));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function proses(array $ids, string $status, ?string $catatan): bool
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$pengajuans = PengajuanPresensi::whereIn('id', $ids)->get();
|
|
||||||
|
|
||||||
foreach ($pengajuans as $pengajuan) {
|
|
||||||
DB::beginTransaction();
|
|
||||||
|
|
||||||
$pengajuan->update(['status' => $status]);
|
|
||||||
|
|
||||||
$pengajuan->logs()->create([
|
|
||||||
'user_id' => Auth::id(),
|
|
||||||
'method' => 'POST',
|
|
||||||
'employee_id' => Auth::user()->nip,
|
|
||||||
'employee_name' => Auth::user()->name,
|
|
||||||
'employee_role' => 'Verifikator',
|
|
||||||
'message' => 'Pengajuan Presensi Berhasil ' . strtolower($status) . ' via WhatsApp',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($status === 'Ditolak') {
|
|
||||||
$pengajuan->notes()->create([
|
|
||||||
'type' => 'Catatan',
|
|
||||||
'user_id' => Auth::id(),
|
|
||||||
'employee_id' => Auth::user()->nip,
|
|
||||||
'employee_name' => Auth::user()->name,
|
|
||||||
'employee_role' => 'Verifikator',
|
|
||||||
'message' => $catatan,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dawai = $this->dawaiService->verifikasiUsulanPresensi(
|
|
||||||
$pengajuan->nip,
|
|
||||||
[$pengajuan->tanggal_mulai],
|
|
||||||
$this->mapStatus($status),
|
|
||||||
$pengajuan->getRawOriginal('kategori')
|
|
||||||
);
|
|
||||||
|
|
||||||
if (! $dawai) {
|
|
||||||
Log::error("Presensi DAWAI via WhatsApp: $pengajuan->nip ($status)");
|
|
||||||
throw new Exception('Presensi: DAWAI ERROR');
|
|
||||||
}
|
|
||||||
|
|
||||||
DB::commit();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Http::timeout(5)->asMultipart()->post('http://172.16.50.94:8084/webhook/presensi', [
|
|
||||||
['name' => 'nip', 'contents' => $pengajuan->nip],
|
|
||||||
['name' => 'tanggal[]', 'contents' => $pengajuan->tanggal_mulai],
|
|
||||||
['name' => 'kategori', 'contents' => (string) $pengajuan->getRawOriginal('kategori')],
|
|
||||||
['name' => 'username', 'contents' => Auth::user()->nip],
|
|
||||||
['name' => 'name', 'contents' => Auth::user()->name],
|
|
||||||
]);
|
|
||||||
} catch (Throwable $webhookException) {
|
|
||||||
Log::error("Webhook Presensi via WhatsApp error: {$pengajuan->nip} ($status) - " . $webhookException->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Throwable $th) {
|
|
||||||
DB::rollBack();
|
|
||||||
Log::error("Verifikasi Absen via WhatsApp ($status): " . $th->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function mapStatus(string $status): ?bool
|
|
||||||
{
|
|
||||||
return match ($status) {
|
|
||||||
'Diterima' => true,
|
|
||||||
'Ditolak' => false,
|
|
||||||
default => null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Manajemen;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Sidia\Pegawai;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
|
|
||||||
|
class PegawaiController extends Controller
|
||||||
|
{
|
||||||
|
public function index(): View
|
||||||
|
{
|
||||||
|
abort_if(! auth()->user()->can('Baca Pegawai'), 403);
|
||||||
|
|
||||||
|
$title = 'Pegawai';
|
||||||
|
|
||||||
|
$unitKerjaOptions = Pegawai::select('nama_unit_kerja')
|
||||||
|
->whereNotNull('nama_unit_kerja')
|
||||||
|
->distinct()
|
||||||
|
->orderBy('nama_unit_kerja')
|
||||||
|
->pluck('nama_unit_kerja');
|
||||||
|
|
||||||
|
$statusPegawaiOptions = Pegawai::select('status_pegawai')
|
||||||
|
->whereNotNull('status_pegawai')
|
||||||
|
->distinct()
|
||||||
|
->orderBy('status_pegawai')
|
||||||
|
->pluck('status_pegawai');
|
||||||
|
|
||||||
|
$statusOptions = Pegawai::select('status')
|
||||||
|
->whereNotNull('status')
|
||||||
|
->distinct()
|
||||||
|
->orderBy('status')
|
||||||
|
->pluck('status');
|
||||||
|
|
||||||
|
return view('manajemen.pegawai.index', compact('title', 'unitKerjaOptions', 'statusPegawaiOptions', 'statusOptions'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function data(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
abort_if(! auth()->user()->can('Baca Pegawai'), 403);
|
||||||
|
|
||||||
|
$pegawais = Pegawai::select([
|
||||||
|
'id', 'nip', 'nama', 'jenis_pegawai',
|
||||||
|
'nama_unit_kerja', 'nama_jabatan_fungsional',
|
||||||
|
'nama_jabatan_tugas_tambahan', 'nama_jabatan_kontrak',
|
||||||
|
])
|
||||||
|
->when($request->unit_kerja, fn ($query, $value) => $query->where('nama_unit_kerja', $value))
|
||||||
|
->when($request->jenis_pegawai, fn ($query, $value) => $query->where('jenis_pegawai', $value))
|
||||||
|
->when($request->status_pegawai, fn ($query, $value) => $query->where('status_pegawai', $value))
|
||||||
|
->when($request->status, fn ($query, $value) => $query->where('status', $value))
|
||||||
|
->orderBy('nama');
|
||||||
|
|
||||||
|
return DataTables::of($pegawais)->make(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id): JsonResponse
|
||||||
|
{
|
||||||
|
abort_if(! auth()->user()->can('Baca Pegawai'), 403);
|
||||||
|
|
||||||
|
$pegawai = Pegawai::findOrFail($id);
|
||||||
|
|
||||||
|
return response()->json($pegawai);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Perhitungan\Remunerasi;
|
namespace App\Http\Controllers\Perhitungan\Remunerasi;
|
||||||
|
|
||||||
use App\Exports\P1Export;
|
use App\Exports\P1Export;
|
||||||
|
use App\Exports\P1PerbandinganExport;
|
||||||
use App\Exports\P1SelisihExport;
|
use App\Exports\P1SelisihExport;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Rekapitulasi\P1;
|
use App\Models\Rekapitulasi\P1;
|
||||||
@@ -536,6 +537,58 @@ class P1Controller extends Controller
|
|||||||
return Excel::download(new P1SelisihExport($jenisPegawai, $tahun, $bulan, $unit, $includePppk2025), $filename);
|
return Excel::download(new P1SelisihExport($jenisPegawai, $tahun, $bulan, $unit, $includePppk2025), $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function exportPerbandingan(Request $request): BinaryFileResponse
|
||||||
|
{
|
||||||
|
set_time_limit(300);
|
||||||
|
|
||||||
|
$datenow = Carbon::now();
|
||||||
|
$bulanNow = $datenow->format('m');
|
||||||
|
$tahunNow = $datenow->format('Y');
|
||||||
|
$team = Team::find(session('team_id'));
|
||||||
|
|
||||||
|
if ($request->has('unit_kerja') && $request->unit_kerja !== null) {
|
||||||
|
$unit = $request->unit_kerja;
|
||||||
|
} elseif ($team && $team->unit_kerja_id !== null && $team->unit_kerja_id !== 0) {
|
||||||
|
$unit = $team->unit_kerja_id;
|
||||||
|
} else {
|
||||||
|
$unit = $request->unit_kerja;
|
||||||
|
}
|
||||||
|
|
||||||
|
$jenisPegawai = $request->jenis_pegawai ?? '';
|
||||||
|
$tahun = (int) ($request->tahun ?? $tahunNow);
|
||||||
|
$bulan = $request->bulan ?? null;
|
||||||
|
$arah = $request->arah ?? '';
|
||||||
|
|
||||||
|
$unitIdForModel = ($unit == 99) ? 0 : $unit;
|
||||||
|
|
||||||
|
$bulanNames = [
|
||||||
|
1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni',
|
||||||
|
7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember',
|
||||||
|
];
|
||||||
|
|
||||||
|
$unitName = '';
|
||||||
|
if ($unit) {
|
||||||
|
$unitKerja = UnitKerja::find($unitIdForModel);
|
||||||
|
if ($unitKerja) {
|
||||||
|
$unitName = '_'.str_replace(['/', ' ', '.'], '_', $unitKerja->nama);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$unitName = '_Semua_Unit_Kerja';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $bulan) {
|
||||||
|
$namaBulanSekarang = $bulanNames[(int) $bulanNow];
|
||||||
|
$filename = "P1_Perbandingan_Januari_sampai_{$namaBulanSekarang}_{$tahun}{$unitName}.xlsx";
|
||||||
|
|
||||||
|
return Excel::download(new P1PerbandinganExport($jenisPegawai, $tahun, null, $unitIdForModel, $arah), $filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
$bulanName = $bulanNames[(int) $bulan];
|
||||||
|
$filename = "P1_Perbandingan_{$bulanName}_{$tahun}{$unitName}.xlsx";
|
||||||
|
|
||||||
|
return Excel::download(new P1PerbandinganExport($jenisPegawai, $tahun, (int) $bulan, $unitIdForModel, $arah), $filename);
|
||||||
|
}
|
||||||
|
|
||||||
public function logs(Request $request): JsonResponse
|
public function logs(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
Log::info('Export P1 Log:', $request->all());
|
Log::info('Export P1 Log:', $request->all());
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Perhitungan\Remunerasi;
|
|||||||
|
|
||||||
use App\Exports\P2Export;
|
use App\Exports\P2Export;
|
||||||
use App\Helpers\JabatanPegawaiTambahanHelper;
|
use App\Helpers\JabatanPegawaiTambahanHelper;
|
||||||
|
use App\Helpers\JenjangPendidikanHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Controllers\Perhitungan\PlenoPenunjang\RasioP2Controller;
|
use App\Http\Controllers\Perhitungan\PlenoPenunjang\RasioP2Controller;
|
||||||
use App\Models\Verifikator\Periode;
|
use App\Models\Verifikator\Periode;
|
||||||
@@ -39,8 +40,9 @@ class P2Controller extends Controller
|
|||||||
$team = Team::find(session('team_id'));
|
$team = Team::find(session('team_id'));
|
||||||
$periodes = Periode::orderBy('id_periode', 'desc')->get();
|
$periodes = Periode::orderBy('id_periode', 'desc')->get();
|
||||||
$periodeNow = Periode::where('status', true)->first()?->id_periode;
|
$periodeNow = Periode::where('status', true)->first()?->id_periode;
|
||||||
|
$jenjangPendidikanList = JenjangPendidikanHelper::options();
|
||||||
|
|
||||||
return view('perhitungan.remunerasi.p2.index', compact('title', 'team', 'periodes', 'periodeNow'));
|
return view('perhitungan.remunerasi.p2.index', compact('title', 'team', 'periodes', 'periodeNow', 'jenjangPendidikanList'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function data(Request $request): JsonResponse
|
public function data(Request $request): JsonResponse
|
||||||
@@ -53,9 +55,9 @@ class P2Controller extends Controller
|
|||||||
return DataTables::of(collect([]))->make();
|
return DataTables::of(collect([]))->make();
|
||||||
}
|
}
|
||||||
|
|
||||||
[$unitKerjaId, $jenisPegawai, $periode] = $this->resolveFilters($request, $team);
|
[$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan] = $this->resolveFilters($request, $team);
|
||||||
|
|
||||||
$query = $this->buildQuery($periode, $unitKerjaId, $jenisPegawai);
|
$query = $this->buildQuery($periode, $unitKerjaId, $jenisPegawai, $jenjangPendidikan);
|
||||||
|
|
||||||
return DataTables::of($query)
|
return DataTables::of($query)
|
||||||
->editColumn('nip', fn ($row) => ltrim($row->nip ?? '', "'"))
|
->editColumn('nip', fn ($row) => ltrim($row->nip ?? '', "'"))
|
||||||
@@ -75,7 +77,7 @@ class P2Controller extends Controller
|
|||||||
|
|
||||||
$team = Team::find(session('team_id'));
|
$team = Team::find(session('team_id'));
|
||||||
|
|
||||||
[$unitKerjaId, $jenisPegawai, $periode] = $this->resolveFilters($request, $team);
|
[$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan] = $this->resolveFilters($request, $team);
|
||||||
|
|
||||||
$periodeNama = Periode::where('id_periode', $periode)->first()?->nama ?? $periode;
|
$periodeNama = Periode::where('id_periode', $periode)->first()?->nama ?? $periode;
|
||||||
$unitNama = $unitKerjaId !== null && $unitKerjaId !== '' ? (UnitKerja::find($unitKerjaId)?->nama ?? 'Semua Unit') : 'Semua Unit';
|
$unitNama = $unitKerjaId !== null && $unitKerjaId !== '' ? (UnitKerja::find($unitKerjaId)?->nama ?? 'Semua Unit') : 'Semua Unit';
|
||||||
@@ -85,7 +87,7 @@ class P2Controller extends Controller
|
|||||||
.'_'.str_replace(['/', ' ', '.'], '_', $unitNama)
|
.'_'.str_replace(['/', ' ', '.'], '_', $unitNama)
|
||||||
.$jenisPegawaiNama.'.xlsx';
|
.$jenisPegawaiNama.'.xlsx';
|
||||||
|
|
||||||
return Excel::download(new P2Export($periode, $unitKerjaId, $jenisPegawai), $filename);
|
return Excel::download(new P2Export($periode, $unitKerjaId, $jenisPegawai, $jenjangPendidikan), $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detail(Request $request, string $nip): View
|
public function detail(Request $request, string $nip): View
|
||||||
@@ -117,11 +119,12 @@ class P2Controller extends Controller
|
|||||||
$periodeNow = Periode::where('status', true)->first()?->id_periode;
|
$periodeNow = Periode::where('status', true)->first()?->id_periode;
|
||||||
$periode = $request->periode ?? $periodeNow;
|
$periode = $request->periode ?? $periodeNow;
|
||||||
$jenisPegawai = $request->jenis_pegawai ?: null;
|
$jenisPegawai = $request->jenis_pegawai ?: null;
|
||||||
|
$jenjangPendidikan = $request->jenjang_pendidikan ?: null;
|
||||||
|
|
||||||
return [$unitKerjaId, $jenisPegawai, $periode];
|
return [$unitKerjaId, $jenisPegawai, $periode, $jenjangPendidikan];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildQuery(mixed $periode, mixed $unitKerjaId, ?string $jenisPegawai)
|
private function buildQuery(mixed $periode, mixed $unitKerjaId, ?string $jenisPegawai, ?string $jenjangPendidikan = null)
|
||||||
{
|
{
|
||||||
$fakultasIds = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
$fakultasIds = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||||
|
|
||||||
@@ -133,6 +136,7 @@ class P2Controller extends Controller
|
|||||||
->select(['verifikator.pegawais.nip', 'verifikator.pegawais.nama'])
|
->select(['verifikator.pegawais.nip', 'verifikator.pegawais.nama'])
|
||||||
->selectRaw('MAX(ukp.nama) as nama_unit')
|
->selectRaw('MAX(ukp.nama) as nama_unit')
|
||||||
->selectRaw('MAX(jpd.jenis_pegawai) as jenis_pegawai')
|
->selectRaw('MAX(jpd.jenis_pegawai) as jenis_pegawai')
|
||||||
|
->selectRaw('MAX(verifikator.pegawais.pendidikan_terakhir) as jenjang_pendidikan')
|
||||||
->selectRaw('SUM(rpb.p2_bruto) as total_p2_bruto')
|
->selectRaw('SUM(rpb.p2_bruto) as total_p2_bruto')
|
||||||
->selectRaw('SUM(rpb.p2_bruto) - SUM(rpb.p2_netto) as total_p2_pajak')
|
->selectRaw('SUM(rpb.p2_bruto) - SUM(rpb.p2_netto) as total_p2_pajak')
|
||||||
->selectRaw('SUM(rpb.p2_netto) as total_p2_netto')
|
->selectRaw('SUM(rpb.p2_netto) as total_p2_netto')
|
||||||
@@ -151,6 +155,10 @@ class P2Controller extends Controller
|
|||||||
$query->where('jpd.jenis_pegawai', $jenisPegawai);
|
$query->where('jpd.jenis_pegawai', $jenisPegawai);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($jenjangPendidikan !== null && $jenjangPendidikan !== '') {
|
||||||
|
JenjangPendidikanHelper::applyQueryFilter($query, 'verifikator.pegawais.pendidikan_terakhir', $jenjangPendidikan);
|
||||||
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Verifikasi\PengajuanPresensi;
|
namespace App\Http\Controllers\Verifikasi\PengajuanPresensi;
|
||||||
|
|
||||||
|
use App\Helpers\BawahanHelper;
|
||||||
use App\Helpers\BeritaAcaraHelper;
|
use App\Helpers\BeritaAcaraHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Verifikator\Honorer;
|
use App\Models\Verifikator\Honorer;
|
||||||
@@ -258,6 +259,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function detail(Request $request, $id)
|
public function detail(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizeNip($id);
|
||||||
|
|
||||||
// Cek periode verifikasi Presensi terlebih dahulu
|
// Cek periode verifikasi Presensi terlebih dahulu
|
||||||
$periode = Periode::where('status', true)->first();
|
$periode = Periode::where('status', true)->first();
|
||||||
if ($periode && ! $periode->canVerifyPresensi() && Auth::user()->id != 1) {
|
if ($periode && ! $periode->canVerifyPresensi() && Auth::user()->id != 1) {
|
||||||
@@ -269,7 +272,7 @@ class HonorerController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('pengajuan-presensi.honorer.index')
|
return redirect()->route('pengajuan-presensi.index')
|
||||||
->with('info', $errorMessage ?: 'Periode Verifikasi Presensi telah Selesai.');
|
->with('info', $errorMessage ?: 'Periode Verifikasi Presensi telah Selesai.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,8 +291,10 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
$team = Team::find(session('team_id'));
|
$team = Team::find(session('team_id'));
|
||||||
|
|
||||||
// Ambil bulan dari query parameter
|
// Ambil bulan, tahun & periode dari query parameter
|
||||||
$bulan = $request->query('bulan');
|
$bulan = $request->query('bulan');
|
||||||
|
$tahun = $request->query('tahun');
|
||||||
|
$periodeFilter = $request->query('periode');
|
||||||
|
|
||||||
$title = 'Detail Pengajuan Presensi - '.$pegawai->nama;
|
$title = 'Detail Pengajuan Presensi - '.$pegawai->nama;
|
||||||
|
|
||||||
@@ -297,17 +302,24 @@ class HonorerController extends Controller
|
|||||||
$beritaAcaraUploaded = $beritaAcaraCheck['uploaded'];
|
$beritaAcaraUploaded = $beritaAcaraCheck['uploaded'];
|
||||||
$beritaAcaraMessage = $beritaAcaraCheck['message'];
|
$beritaAcaraMessage = $beritaAcaraCheck['message'];
|
||||||
|
|
||||||
return view('verifikasi.pengajuan-presensi.honorer.detail', compact('title', 'pegawai', 'id', 'team', 'bulan', 'validasiWaktu', 'beritaAcaraUploaded', 'beritaAcaraMessage'));
|
return view('verifikasi.pengajuan-presensi.honorer.detail', compact('title', 'pegawai', 'id', 'team', 'bulan', 'tahun', 'periodeFilter', 'validasiWaktu', 'beritaAcaraUploaded', 'beritaAcaraMessage'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataDetail(Request $request, $id)
|
public function dataDetail(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizeNip($id);
|
||||||
|
|
||||||
|
$periodeId = $request->periode ?: Periode::where('status', true)->first()->id_periode;
|
||||||
|
|
||||||
$presensis = PengajuanPresensi::where('nip', $id)
|
$presensis = PengajuanPresensi::where('nip', $id)
|
||||||
->where('periode', Periode::where('status', true)->first()->id_periode)
|
->where('periode', $periodeId)
|
||||||
->where('tipe', 'absen')
|
->where('tipe', 'absen')
|
||||||
->when($request->bulan, function ($query) use ($request) {
|
->when($request->bulan, function ($query) use ($request) {
|
||||||
return $query->whereMonth('tanggal_mulai', $request->bulan);
|
return $query->whereMonth('tanggal_mulai', $request->bulan);
|
||||||
})
|
})
|
||||||
|
->when($request->tahun, function ($query) use ($request) {
|
||||||
|
return $query->whereYear('tanggal_mulai', $request->tahun);
|
||||||
|
})
|
||||||
->orderBy('tanggal_mulai');
|
->orderBy('tanggal_mulai');
|
||||||
|
|
||||||
return DataTables::of($presensis)
|
return DataTables::of($presensis)
|
||||||
@@ -393,6 +405,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function approve(Request $request, $id)
|
public function approve(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($id);
|
||||||
|
|
||||||
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
||||||
if (! $validasiWaktu['status']) {
|
if (! $validasiWaktu['status']) {
|
||||||
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
||||||
@@ -415,6 +429,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function reject(Request $request, $id)
|
public function reject(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($id);
|
||||||
|
|
||||||
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
||||||
if (! $validasiWaktu['status']) {
|
if (! $validasiWaktu['status']) {
|
||||||
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
||||||
@@ -441,6 +457,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function cancel($id)
|
public function cancel($id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($id);
|
||||||
|
|
||||||
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
||||||
if (! $validasiWaktu['status']) {
|
if (! $validasiWaktu['status']) {
|
||||||
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
||||||
@@ -463,6 +481,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function delete($id)
|
public function delete($id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($id);
|
||||||
|
|
||||||
// Hanya Superuser yang dapat menghapus
|
// Hanya Superuser yang dapat menghapus
|
||||||
if (! Auth::user()->hasRole('Superuser')) {
|
if (! Auth::user()->hasRole('Superuser')) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -503,6 +523,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function deleteSelected(Request $request)
|
public function deleteSelected(Request $request)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($request->input('ids', []));
|
||||||
|
|
||||||
// Hanya Superuser yang dapat menghapus
|
// Hanya Superuser yang dapat menghapus
|
||||||
if (! Auth::user()->hasRole('Superuser')) {
|
if (! Auth::user()->hasRole('Superuser')) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -561,6 +583,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function verifikasiSemua($nip)
|
public function verifikasiSemua($nip)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizeNip($nip);
|
||||||
|
|
||||||
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
||||||
if (! $validasiWaktu['status']) {
|
if (! $validasiWaktu['status']) {
|
||||||
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
||||||
@@ -601,6 +625,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function verifikasiSelected(Request $request)
|
public function verifikasiSelected(Request $request)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($request->input('ids', []));
|
||||||
|
|
||||||
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
||||||
if (! $validasiWaktu['status']) {
|
if (! $validasiWaktu['status']) {
|
||||||
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
return response()->json(['success' => false, 'message' => $validasiWaktu['message']], 403);
|
||||||
@@ -639,6 +665,8 @@ class HonorerController extends Controller
|
|||||||
|
|
||||||
public function batalkanSelected(Request $request): JsonResponse
|
public function batalkanSelected(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($request->input('ids', []));
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'ids' => 'required|array',
|
'ids' => 'required|array',
|
||||||
'ids.*' => 'integer',
|
'ids.*' => 'integer',
|
||||||
|
|||||||
@@ -0,0 +1,386 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Verifikasi\PengajuanPresensi;
|
||||||
|
|
||||||
|
use App\Helpers\BawahanHelper;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Verifikator\Honorer;
|
||||||
|
use App\Models\Verifikator\Periode;
|
||||||
|
use App\Models\Verifikator\Team;
|
||||||
|
use App\Models\Verifikator\Tendik;
|
||||||
|
use App\Models\Verifikator\UnitKerjaPegawai;
|
||||||
|
use App\Services\DawaiService;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
|
|
||||||
|
class PengajuanPresensiController extends Controller
|
||||||
|
{
|
||||||
|
protected $dawaiService;
|
||||||
|
|
||||||
|
protected $periodeAktif;
|
||||||
|
|
||||||
|
public function __construct(DawaiService $dawaiService)
|
||||||
|
{
|
||||||
|
$this->dawaiService = $dawaiService;
|
||||||
|
$this->periodeAktif = Periode::where('status', true)->first()->id_periode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
// Ditampilkan sebagai banner peringatan (hanya relevan untuk Non ASN).
|
||||||
|
// Tidak memblokir halaman: verifikasi tetap digating per-aksi di controller detail.
|
||||||
|
$validasiWaktu = $this->validasiWaktuVerifikasi();
|
||||||
|
|
||||||
|
$title = 'Pengajuan Presensi';
|
||||||
|
$showFilterBulan = $this->showFilterBulan();
|
||||||
|
$canHonorer = $this->canHonorer();
|
||||||
|
$canTendik = $this->canTendik();
|
||||||
|
$periodes = Periode::orderBy('id_periode', 'desc')->get();
|
||||||
|
$periodeAktif = $this->periodeAktif;
|
||||||
|
|
||||||
|
return view('verifikasi.pengajuan-presensi.index', compact(
|
||||||
|
'title',
|
||||||
|
'showFilterBulan',
|
||||||
|
'validasiWaktu',
|
||||||
|
'canHonorer',
|
||||||
|
'canTendik',
|
||||||
|
'periodes',
|
||||||
|
'periodeAktif'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function data(Request $request)
|
||||||
|
{
|
||||||
|
$canHonorer = $this->canHonorer();
|
||||||
|
$canTendik = $this->canTendik();
|
||||||
|
|
||||||
|
// Resolusi jenis pegawai: '' = semua, 'non_asn' = Honorer, 'asn' = Tendik
|
||||||
|
$jenis = $request->input('jenis', '');
|
||||||
|
if (! $canHonorer) {
|
||||||
|
$jenis = 'asn';
|
||||||
|
} elseif (! $canTendik) {
|
||||||
|
$jenis = 'non_asn';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Superuser: lihat semua (filter unit kerja per team seperti sebelumnya).
|
||||||
|
// Selain itu: dibatasi ke NIP bawahan pegawai (dari DAWAI).
|
||||||
|
$isSuperuser = Auth::user()->hasRole('Superuser');
|
||||||
|
$bawahanNips = $isSuperuser ? null : BawahanHelper::nips();
|
||||||
|
|
||||||
|
$team = Team::find(session('team_id'));
|
||||||
|
$showFilterBulan = $this->showFilterBulan();
|
||||||
|
|
||||||
|
// Tentukan bulan verifikasi berdasarkan tanggal
|
||||||
|
$tanggalSekarang = (int) date('j');
|
||||||
|
$bulanVerifikasi = (int) date('m');
|
||||||
|
|
||||||
|
// Tanggal 1-5: Tampilkan bulan lalu (N-1)
|
||||||
|
if ($tanggalSekarang <= 5) {
|
||||||
|
$bulanVerifikasi--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $showFilterBulan) {
|
||||||
|
$bulan = $bulanVerifikasi;
|
||||||
|
} else {
|
||||||
|
$bulan = $request->input('bulan', $bulanVerifikasi);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter unit kerja
|
||||||
|
if (! $isSuperuser) {
|
||||||
|
// Mode bawahan: tidak dipaksa unit kerja team, hanya ikut dropdown.
|
||||||
|
$unit = $request->unit;
|
||||||
|
} elseif ($team && $team->id == 1) {
|
||||||
|
$unit = $request->unit;
|
||||||
|
} elseif ($team && $team->unit_kerja_id == 0) {
|
||||||
|
$unit = 'exclude_1_9';
|
||||||
|
} else {
|
||||||
|
$unit = ($team->unit_kerja_id ?? null) ?: $request->unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = $request->status ?? 0;
|
||||||
|
$periode = (int) ($request->input('periode') ?: $this->periodeAktif);
|
||||||
|
$tahun = $this->tahunPeriode($periode);
|
||||||
|
|
||||||
|
$queryDetail = '?bulan='.str_pad($bulan, 2, '0', STR_PAD_LEFT).'&tahun='.$tahun.'&periode='.$periode;
|
||||||
|
|
||||||
|
$merged = collect();
|
||||||
|
|
||||||
|
if ($canHonorer && $jenis !== 'asn') {
|
||||||
|
$honorer = $this->getPengajuanHonorer($status, $unit, $periode, $bulan)
|
||||||
|
->map(function ($row) use ($queryDetail) {
|
||||||
|
return [
|
||||||
|
'nip' => $row->nip,
|
||||||
|
'nama' => $row->nama,
|
||||||
|
'unit_nama' => $row->unit->nama ?? '-',
|
||||||
|
'absen_count' => $row->absen_count,
|
||||||
|
'jenis' => 'non_asn',
|
||||||
|
'jenis_label' => 'Non ASN',
|
||||||
|
'jenis_pegawai' => strtolower($row->jenis_pegawai) === 'dosen' ? 'dosen' : 'tendik',
|
||||||
|
'detail_url' => route('pengajuan-presensi.honorer.detail', $row->nip).$queryDetail,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
$merged = $merged->concat($honorer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($canTendik && $jenis !== 'non_asn') {
|
||||||
|
$tendik = $this->getPengajuanTendik($status, $unit, $periode, $bulan)
|
||||||
|
->map(function ($row) use ($queryDetail) {
|
||||||
|
return [
|
||||||
|
'nip' => $row->nip,
|
||||||
|
'nama' => $row->nama,
|
||||||
|
'unit_nama' => $row->unit_kerja_nama ?? '-',
|
||||||
|
'absen_count' => $row->absen_count,
|
||||||
|
'jenis' => 'asn',
|
||||||
|
'jenis_label' => 'ASN',
|
||||||
|
'jenis_pegawai' => 'tendik',
|
||||||
|
'detail_url' => route('pengajuan-presensi.tendik.detail', $row->nip).$queryDetail,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
$merged = $merged->concat($tendik);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mode bawahan: batasi hanya ke NIP bawahan pegawai
|
||||||
|
if ($bawahanNips !== null) {
|
||||||
|
$merged = $merged->whereIn('nip', $bawahanNips);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter jenis pegawai (dosen/tendik)
|
||||||
|
$jenisPegawai = $request->input('jenis_pegawai', '');
|
||||||
|
if (in_array($jenisPegawai, ['dosen', 'tendik'], true)) {
|
||||||
|
$merged = $merged->where('jenis_pegawai', $jenisPegawai);
|
||||||
|
}
|
||||||
|
|
||||||
|
$merged = $merged->sortBy('nama')->values();
|
||||||
|
|
||||||
|
return DataTables::of($merged)
|
||||||
|
->addIndexColumn()
|
||||||
|
->addColumn('action', function ($row) {
|
||||||
|
return '
|
||||||
|
<div class="dropdown">
|
||||||
|
<span id="dropdownMenuButton" data-bs-toggle="dropdown" style="cursor: pointer;">
|
||||||
|
<i class="uil-ellipsis-v"></i>
|
||||||
|
</span>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li>
|
||||||
|
<a href="javascript:void(0)" class="dropdown-item detail-btn" data-id="'.$row['nip'].'" data-url="'.$row['detail_url'].'">
|
||||||
|
<i class="fas fa-eye" style="margin-right: 5px"></i> Detail
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>';
|
||||||
|
})
|
||||||
|
->rawColumns(['action', 'detail_url'])
|
||||||
|
->make(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unitKerja()
|
||||||
|
{
|
||||||
|
// Mode bawahan: daftar unit kerja diturunkan dari bawahan pegawai
|
||||||
|
if (! Auth::user()->hasRole('Superuser')) {
|
||||||
|
$nips = BawahanHelper::nips();
|
||||||
|
|
||||||
|
$unitIds = collect()
|
||||||
|
->merge(Honorer::whereIn('nip', $nips)->pluck('unit_id'))
|
||||||
|
->merge(Tendik::whereIn('nip', $nips)->pluck('unit_kerja_id'))
|
||||||
|
->filter()
|
||||||
|
->unique()
|
||||||
|
->values();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'units' => UnitKerjaPegawai::whereIn('id', $unitIds)->orderBy('nama')->get(),
|
||||||
|
'selected' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$team = Team::find(session('team_id'));
|
||||||
|
|
||||||
|
if ($team->id == 1) {
|
||||||
|
$units = UnitKerjaPegawai::all();
|
||||||
|
} elseif ($team->unit_kerja_id == 0) {
|
||||||
|
$units = UnitKerjaPegawai::whereNotIn('id', [1, 2, 3, 4, 5, 6, 7, 8, 9])->get();
|
||||||
|
} elseif ($team->unit_kerja_id !== null) {
|
||||||
|
$units = UnitKerjaPegawai::where('id', $team->unit_kerja_id)->get();
|
||||||
|
} else {
|
||||||
|
$units = UnitKerjaPegawai::all();
|
||||||
|
}
|
||||||
|
|
||||||
|
$selectedUnitKerja = null;
|
||||||
|
if ($team->unit_kerja_id !== null && $team->unit_kerja_id != 0) {
|
||||||
|
$selectedUnitKerja = $team->unit_kerja_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'units' => $units,
|
||||||
|
'selected' => $selectedUnitKerja,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bulanList(Request $request)
|
||||||
|
{
|
||||||
|
$periodeId = $request->input('periode');
|
||||||
|
$periode = $periodeId
|
||||||
|
? Periode::where('id_periode', $periodeId)->first()
|
||||||
|
: null;
|
||||||
|
$periode = $periode ?: Periode::where('status', true)->first();
|
||||||
|
|
||||||
|
if ($periode->id_periode % 2 === 1) {
|
||||||
|
$bulanList = [
|
||||||
|
['value' => '01', 'label' => 'Januari'],
|
||||||
|
['value' => '02', 'label' => 'Februari'],
|
||||||
|
['value' => '03', 'label' => 'Maret'],
|
||||||
|
['value' => '04', 'label' => 'April'],
|
||||||
|
['value' => '05', 'label' => 'Mei'],
|
||||||
|
['value' => '06', 'label' => 'Juni'],
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$bulanList = [
|
||||||
|
['value' => '07', 'label' => 'Juli'],
|
||||||
|
['value' => '08', 'label' => 'Agustus'],
|
||||||
|
['value' => '09', 'label' => 'September'],
|
||||||
|
['value' => '10', 'label' => 'Oktober'],
|
||||||
|
['value' => '11', 'label' => 'November'],
|
||||||
|
['value' => '12', 'label' => 'Desember'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'bulanList' => $bulanList,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getPengajuanHonorer($selesai, $unit = null, $periode = null, $bulan = null)
|
||||||
|
{
|
||||||
|
$periode = $periode ?? Periode::where('status', true)->first()->id_periode;
|
||||||
|
|
||||||
|
return Honorer::with('unit')
|
||||||
|
->withCount(['absen' => function ($query) use ($bulan, $periode, $selesai) {
|
||||||
|
$query->where('periode', $periode)
|
||||||
|
->when($selesai == 0, function ($query) {
|
||||||
|
return $query->where('status', 'Diajukan');
|
||||||
|
})
|
||||||
|
->when($bulan !== null, function ($query) use ($bulan) {
|
||||||
|
return $query->whereMonth('tanggal_mulai', $bulan);
|
||||||
|
});
|
||||||
|
}])
|
||||||
|
->when($selesai == 1, function ($query) use ($periode, $bulan) {
|
||||||
|
$query->whereDoesntHave('absen', function ($subquery) use ($bulan) {
|
||||||
|
$subquery->where('status', 'Diajukan')
|
||||||
|
->when($bulan !== null, function ($query) use ($bulan) {
|
||||||
|
return $query->whereMonth('tanggal_mulai', $bulan);
|
||||||
|
});
|
||||||
|
})->whereHas('absen', function ($subquery) use ($periode, $bulan) {
|
||||||
|
$subquery->where('periode', $periode)
|
||||||
|
->when($bulan !== null, function ($query) use ($bulan) {
|
||||||
|
return $query->whereMonth('tanggal_mulai', $bulan);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, function ($query) use ($periode, $bulan) {
|
||||||
|
$query->whereHas('absen', function ($subquery) use ($periode, $bulan) {
|
||||||
|
$subquery->where('status', 'Diajukan')
|
||||||
|
->whereMonth('tanggal_mulai', $bulan)
|
||||||
|
->where('periode', $periode);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->has('absen')
|
||||||
|
->when($unit !== null, function ($query) use ($unit) {
|
||||||
|
if ($unit === 'exclude_1_9') {
|
||||||
|
$query->whereNotIn('unit_id', [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||||
|
} else {
|
||||||
|
$query->where('unit_id', $unit);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getPengajuanTendik($selesai, $unit = null, $periode = null, $bulan = null)
|
||||||
|
{
|
||||||
|
$periode = $periode ?? Periode::where('status', true)->first()->id_periode;
|
||||||
|
|
||||||
|
return Tendik::withCount(['absen' => function ($query) use ($bulan, $periode, $selesai) {
|
||||||
|
$query->where('periode', $periode)
|
||||||
|
->when($selesai == 0, function ($query) {
|
||||||
|
return $query->where('status', 'Diajukan');
|
||||||
|
})
|
||||||
|
->when($bulan !== null, function ($query) use ($bulan) {
|
||||||
|
return $query->whereMonth('tanggal_mulai', $bulan);
|
||||||
|
});
|
||||||
|
}])
|
||||||
|
->when($selesai == 1, function ($query) use ($periode, $bulan) {
|
||||||
|
$query->whereDoesntHave('absen', function ($subquery) use ($bulan) {
|
||||||
|
$subquery->where('status', 'Diajukan')
|
||||||
|
->when($bulan !== null, function ($query) use ($bulan) {
|
||||||
|
return $query->whereMonth('tanggal_mulai', $bulan);
|
||||||
|
});
|
||||||
|
})->whereHas('absen', function ($subquery) use ($periode, $bulan) {
|
||||||
|
$subquery->where('periode', $periode)
|
||||||
|
->when($bulan !== null, function ($query) use ($bulan) {
|
||||||
|
return $query->whereMonth('tanggal_mulai', $bulan);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, function ($query) use ($periode, $bulan) {
|
||||||
|
$query->whereHas('absen', function ($subquery) use ($periode, $bulan) {
|
||||||
|
$subquery->where('status', 'Diajukan')
|
||||||
|
->whereMonth('tanggal_mulai', $bulan)
|
||||||
|
->where('periode', $periode);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->has('absen')
|
||||||
|
->when($unit !== null, function ($query) use ($unit) {
|
||||||
|
if ($unit === 'exclude_1_9') {
|
||||||
|
$query->whereNotIn('unit_kerja_id', [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||||
|
} else {
|
||||||
|
$query->where('unit_kerja_id', $unit);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Akses menu digating middleware `bawahan.presensi` (Superuser atau punya bawahan).
|
||||||
|
// Yang lolos boleh melihat kedua jenis pegawai (Non ASN & ASN) dari bawahannya.
|
||||||
|
protected function canHonorer(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function canTendik(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tahunPeriode($periodeId = null)
|
||||||
|
{
|
||||||
|
$periodeId = $periodeId ?: $this->periodeAktif;
|
||||||
|
|
||||||
|
// Ambil tahun dari nama periode, mis. "(401) 2026 Semester 1"
|
||||||
|
$nama = (string) (Periode::where('id_periode', $periodeId)->value('nama') ?? '');
|
||||||
|
|
||||||
|
return preg_match('/(\d{4})/', $nama, $m) ? (int) $m[1] : (int) now()->year;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function showFilterBulan(): bool
|
||||||
|
{
|
||||||
|
// Akses menu sudah dibatasi ke Superuser atau verifikator yang punya bawahan
|
||||||
|
// (middleware bawahan.presensi), jadi filter bulan selalu tersedia di sini.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function validasiWaktuVerifikasi()
|
||||||
|
{
|
||||||
|
$tanggalSekarang = (int) date('j');
|
||||||
|
|
||||||
|
if (Auth::user()->hasRole('Superuser')) {
|
||||||
|
return ['status' => true];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tanggal 5-19: Masa verifikasi sudah selesai (tidak bisa verifikasi)
|
||||||
|
if ($tanggalSekarang > 4 && $tanggalSekarang < 20) {
|
||||||
|
return [
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Masa Verifikasi Presensi Pegawai Non ASN sudah selesai',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['status' => true];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Verifikasi\PengajuanPresensi;
|
namespace App\Http\Controllers\Verifikasi\PengajuanPresensi;
|
||||||
|
|
||||||
|
use App\Helpers\BawahanHelper;
|
||||||
use App\Helpers\BeritaAcaraHelper;
|
use App\Helpers\BeritaAcaraHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Verifikator\PengajuanPresensi;
|
use App\Models\Verifikator\PengajuanPresensi;
|
||||||
@@ -251,6 +252,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function detail(Request $request, $id)
|
public function detail(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizeNip($id);
|
||||||
|
|
||||||
// Cek periode verifikasi Presensi terlebih dahulu
|
// Cek periode verifikasi Presensi terlebih dahulu
|
||||||
$periode = Periode::where('status', true)->first();
|
$periode = Periode::where('status', true)->first();
|
||||||
if ($periode && ! $periode->canVerifyPresensi() && Auth::user()->id != 1) {
|
if ($periode && ! $periode->canVerifyPresensi() && Auth::user()->id != 1) {
|
||||||
@@ -262,7 +265,7 @@ class TendikController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('pengajuan-presensi.tendik.index')->with('info', $errorMessage ?: 'Periode Verifikasi Presensi telah Selesai.');
|
return redirect()->route('pengajuan-presensi.index')->with('info', $errorMessage ?: 'Periode Verifikasi Presensi telah Selesai.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$pegawai = Tendik::where('nip', $id)->first();
|
$pegawai = Tendik::where('nip', $id)->first();
|
||||||
@@ -273,8 +276,10 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
$team = Team::find(session('team_id'));
|
$team = Team::find(session('team_id'));
|
||||||
|
|
||||||
// Ambil bulan dari query parameter
|
// Ambil bulan, tahun & periode dari query parameter
|
||||||
$bulan = $request->query('bulan');
|
$bulan = $request->query('bulan');
|
||||||
|
$tahun = $request->query('tahun');
|
||||||
|
$periodeFilter = $request->query('periode');
|
||||||
|
|
||||||
$title = 'Detail Pengajuan Presensi - '.$pegawai->nama;
|
$title = 'Detail Pengajuan Presensi - '.$pegawai->nama;
|
||||||
|
|
||||||
@@ -282,17 +287,24 @@ class TendikController extends Controller
|
|||||||
$beritaAcaraUploaded = $beritaAcaraCheck['uploaded'];
|
$beritaAcaraUploaded = $beritaAcaraCheck['uploaded'];
|
||||||
$beritaAcaraMessage = $beritaAcaraCheck['message'];
|
$beritaAcaraMessage = $beritaAcaraCheck['message'];
|
||||||
|
|
||||||
return view('verifikasi.pengajuan-presensi.tendik.detail', compact('title', 'pegawai', 'id', 'team', 'bulan', 'beritaAcaraUploaded', 'beritaAcaraMessage'));
|
return view('verifikasi.pengajuan-presensi.tendik.detail', compact('title', 'pegawai', 'id', 'team', 'bulan', 'tahun', 'periodeFilter', 'beritaAcaraUploaded', 'beritaAcaraMessage'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataDetail(Request $request, $id)
|
public function dataDetail(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizeNip($id);
|
||||||
|
|
||||||
|
$periodeId = $request->periode ?: Periode::where('status', true)->first()->id_periode;
|
||||||
|
|
||||||
$presensis = PengajuanPresensi::where('nip', $id)
|
$presensis = PengajuanPresensi::where('nip', $id)
|
||||||
->where('periode', Periode::where('status', true)->first()->id_periode)
|
->where('periode', $periodeId)
|
||||||
->where('tipe', 'absen')
|
->where('tipe', 'absen')
|
||||||
->when($request->bulan, function ($query) use ($request) {
|
->when($request->bulan, function ($query) use ($request) {
|
||||||
return $query->whereMonth('tanggal_mulai', $request->bulan);
|
return $query->whereMonth('tanggal_mulai', $request->bulan);
|
||||||
})
|
})
|
||||||
|
->when($request->tahun, function ($query) use ($request) {
|
||||||
|
return $query->whereYear('tanggal_mulai', $request->tahun);
|
||||||
|
})
|
||||||
->orderBy('tanggal_mulai');
|
->orderBy('tanggal_mulai');
|
||||||
|
|
||||||
return DataTables::of($presensis)
|
return DataTables::of($presensis)
|
||||||
@@ -375,6 +387,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function approve(Request $request, $id)
|
public function approve(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($id);
|
||||||
|
|
||||||
$success = $this->sekretariat([$id], 'Diterima', $request->catatan);
|
$success = $this->sekretariat([$id], 'Diterima', $request->catatan);
|
||||||
|
|
||||||
if ($success !== null) {
|
if ($success !== null) {
|
||||||
@@ -392,6 +406,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function reject(Request $request, $id)
|
public function reject(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($id);
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'catatan' => 'required|string|max:500',
|
'catatan' => 'required|string|max:500',
|
||||||
]);
|
]);
|
||||||
@@ -413,6 +429,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function cancel($id)
|
public function cancel($id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($id);
|
||||||
|
|
||||||
$success = $this->sekretariat([$id], 'Diajukan', null);
|
$success = $this->sekretariat([$id], 'Diajukan', null);
|
||||||
|
|
||||||
if ($success !== null) {
|
if ($success !== null) {
|
||||||
@@ -430,6 +448,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function delete($id)
|
public function delete($id)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($id);
|
||||||
|
|
||||||
// Hanya Superuser yang dapat menghapus
|
// Hanya Superuser yang dapat menghapus
|
||||||
if (! Auth::user()->hasRole('Superuser')) {
|
if (! Auth::user()->hasRole('Superuser')) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -470,6 +490,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function deleteSelected(Request $request)
|
public function deleteSelected(Request $request)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($request->input('ids', []));
|
||||||
|
|
||||||
// Hanya Superuser yang dapat menghapus
|
// Hanya Superuser yang dapat menghapus
|
||||||
if (! Auth::user()->hasRole('Superuser')) {
|
if (! Auth::user()->hasRole('Superuser')) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -528,6 +550,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function verifikasiSemua($nip)
|
public function verifikasiSemua($nip)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizeNip($nip);
|
||||||
|
|
||||||
$tanggalSekarang = (int) date('j');
|
$tanggalSekarang = (int) date('j');
|
||||||
$bulanVerifikasi = (int) date('m');
|
$bulanVerifikasi = (int) date('m');
|
||||||
|
|
||||||
@@ -563,6 +587,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function verifikasiSelected(Request $request)
|
public function verifikasiSelected(Request $request)
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($request->input('ids', []));
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'ids' => 'required|array',
|
'ids' => 'required|array',
|
||||||
'ids.*' => 'integer',
|
'ids.*' => 'integer',
|
||||||
@@ -596,6 +622,8 @@ class TendikController extends Controller
|
|||||||
|
|
||||||
public function batalkanSelected(Request $request): JsonResponse
|
public function batalkanSelected(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
|
BawahanHelper::authorizePengajuan($request->input('ids', []));
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'ids' => 'required|array',
|
'ids' => 'required|array',
|
||||||
'ids.*' => 'integer',
|
'ids.*' => 'integer',
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Helpers\BawahanHelper;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class EnsureBawahanPresensi
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Akses menu Pengajuan Presensi:
|
||||||
|
* - Superuser: selalu boleh.
|
||||||
|
* - Selain itu: hanya bila punya bawahan pegawai (dari DAWAI).
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next): Response
|
||||||
|
{
|
||||||
|
if (! Auth::check()) {
|
||||||
|
return redirect()->route('login');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Auth::user()->hasRole('Superuser')) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! BawahanHelper::has()) {
|
||||||
|
if ($request->ajax() || $request->wantsJson()) {
|
||||||
|
abort(403, 'Anda tidak memiliki bawahan pegawai untuk verifikasi presensi.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('dashboard.index')
|
||||||
|
->with('error', 'Anda tidak memiliki bawahan pegawai untuk verifikasi presensi.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,19 +16,61 @@ class AbsenRequest extends FormRequest
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Samakan nama field dengan kontrak SISKA (/api/v2/siremun/absen/usulan):
|
||||||
|
* tipe_absen -> kategori. Nama lama tetap diterima.
|
||||||
|
*/
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
if ($this->missing('kategori') && $this->filled('tipe_absen')) {
|
||||||
|
$this->merge(['kategori' => $this->input('tipe_absen')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the validation rules that apply to the request.
|
* Get the validation rules that apply to the request.
|
||||||
*
|
*
|
||||||
|
* File bukti diterima lewat `file_surat` (SISKA) atau `bukti` (nama lama).
|
||||||
|
* `keterangan` tidak divalidasi; diisi otomatis dari nama kategori absen.
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'nip' => 'required|string',
|
'nip' => 'required|string',
|
||||||
'bukti' => 'required|file|mimes:pdf|max:1024',
|
'file_surat' => 'required_without:bukti|file|mimes:pdf|max:1024',
|
||||||
'keterangan' => 'required|string',
|
'bukti' => 'required_without:file_surat|file|mimes:pdf|max:1024',
|
||||||
'kategori' => 'required|integer',
|
'kategori' => 'required|integer',
|
||||||
'tanggal' => 'required|date|date_format:Y-m-d|before_or_equal:' . date('Y-m-d'),
|
'tanggal' => 'required|date|date_format:Y-m-d|before_or_equal:'.date('Y-m-d'),
|
||||||
|
'file_lampiran' => 'nullable|required_if:kategori,2|file|mimes:pdf|max:1024',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pesan error dalam Bahasa Indonesia (locale app belum punya file terjemahan).
|
||||||
|
*/
|
||||||
|
public function messages()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'nip.required' => 'NIP wajib diisi.',
|
||||||
|
'file_surat.required_without' => 'File surat (file_surat) wajib diunggah.',
|
||||||
|
'file_surat.file' => 'File surat tidak valid.',
|
||||||
|
'file_surat.mimes' => 'File surat harus berformat PDF.',
|
||||||
|
'file_surat.max' => 'Ukuran file surat maksimal 1 MB.',
|
||||||
|
'bukti.required_without' => 'File surat (file_surat) wajib diunggah.',
|
||||||
|
'bukti.file' => 'File surat tidak valid.',
|
||||||
|
'bukti.mimes' => 'File surat harus berformat PDF.',
|
||||||
|
'bukti.max' => 'Ukuran file surat maksimal 1 MB.',
|
||||||
|
'kategori.required' => 'Tipe absen (tipe_absen) wajib diisi.',
|
||||||
|
'kategori.integer' => 'Tipe absen (tipe_absen) harus berupa angka.',
|
||||||
|
'tanggal.required' => 'Tanggal wajib diisi.',
|
||||||
|
'tanggal.date_format' => 'Format tanggal harus YYYY-MM-DD.',
|
||||||
|
'tanggal.before_or_equal' => 'Tanggal tidak boleh melebihi hari ini.',
|
||||||
|
'file_lampiran.required_if' => 'File lampiran wajib diunggah untuk kategori Tugas Dinas.',
|
||||||
|
'file_lampiran.file' => 'File lampiran tidak valid.',
|
||||||
|
'file_lampiran.mimes' => 'File lampiran harus berformat PDF.',
|
||||||
|
'file_lampiran.max' => 'Ukuran file lampiran maksimal 1 MB.',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class AbsenResource extends JsonResource
|
|||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'alasan' => $this->notes?->last()?->message,
|
'alasan' => $this->notes?->last()?->message,
|
||||||
'bukti' => $this->file,
|
'bukti' => $this->file,
|
||||||
|
'file_lampiran' => $this->file_lampiran,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Sidia;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Pegawai extends Model
|
||||||
|
{
|
||||||
|
protected $connection = 'sidia';
|
||||||
|
|
||||||
|
protected $table = 'view_data_pegawai';
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'nip',
|
||||||
|
'nip_siakad',
|
||||||
|
'nip_honorer',
|
||||||
|
'nidn',
|
||||||
|
'foto',
|
||||||
|
'nama',
|
||||||
|
'email',
|
||||||
|
'jenis_pegawai',
|
||||||
|
'status_pegawai',
|
||||||
|
'unit_kerja_id',
|
||||||
|
'nama_unit_kerja',
|
||||||
|
'prodi_id',
|
||||||
|
'nama_prodi',
|
||||||
|
'golongan',
|
||||||
|
'pangkat',
|
||||||
|
'pendidikan_terakhir',
|
||||||
|
'status',
|
||||||
|
'tmt_status',
|
||||||
|
'tst_status',
|
||||||
|
'jabatan_fungsional_id',
|
||||||
|
'nama_jabatan_fungsional',
|
||||||
|
'grade_jabatan_fungsional',
|
||||||
|
'sk_jabatan_fungsional',
|
||||||
|
'jabatan_tugas_tambahan_id',
|
||||||
|
'nama_jabatan_tugas_tambahan',
|
||||||
|
'grade_jabatan_tugas_tambahan',
|
||||||
|
'sk_jabatan_tugas_tambahan',
|
||||||
|
'tmt_jabatan_tugas_tambahan',
|
||||||
|
'tst_jabatan_tugas_tambahan',
|
||||||
|
'jabatan_kontrak_id',
|
||||||
|
'nama_jabatan_kontrak',
|
||||||
|
'no_hp',
|
||||||
|
'npwp',
|
||||||
|
'no_rekening',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ class Dosen extends Model
|
|||||||
'wafat',
|
'wafat',
|
||||||
'npwp',
|
'npwp',
|
||||||
'nomor_rekening',
|
'nomor_rekening',
|
||||||
|
'no_hp',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function kegiatanPenunjangs()
|
public function kegiatanPenunjangs()
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class PengajuanPresensi extends Model
|
|||||||
'kategori',
|
'kategori',
|
||||||
'keterangan',
|
'keterangan',
|
||||||
'file',
|
'file',
|
||||||
|
'file_lampiran',
|
||||||
'status',
|
'status',
|
||||||
'status_id',
|
'status_id',
|
||||||
];
|
];
|
||||||
@@ -45,6 +46,31 @@ class PengajuanPresensi extends Model
|
|||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setFileLampiranAttribute($value): void
|
||||||
|
{
|
||||||
|
if ($value === null) {
|
||||||
|
$this->attributes['file_lampiran'] = null;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = explode('/', $value);
|
||||||
|
$this->attributes['file_lampiran'] = end($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileLampiranAttribute($value): ?string
|
||||||
|
{
|
||||||
|
if ($value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->bdr_id === null) {
|
||||||
|
return asset("storage/$this->tipe/presensi/$this->periode/$value");
|
||||||
|
}
|
||||||
|
|
||||||
|
return config('baseUri.presensi') . "storage/izin/" . $value;
|
||||||
|
}
|
||||||
|
|
||||||
function getKategoriAttribute($value): string
|
function getKategoriAttribute($value): string
|
||||||
{
|
{
|
||||||
if ($this->periode < Periode::where('status', true)->first()->id_periode) {
|
if ($this->periode < Periode::where('status', true)->first()->id_periode) {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class Tendik extends Model
|
|||||||
'wafat',
|
'wafat',
|
||||||
'npwp',
|
'npwp',
|
||||||
'nomor_rekening',
|
'nomor_rekening',
|
||||||
|
'no_hp',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function kegiatanPenunjangs()
|
public function kegiatanPenunjangs()
|
||||||
|
|||||||
@@ -56,6 +56,13 @@ class DawaiService
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isAtasanDari(string $nipAtasan, string $nipBawahan): bool
|
||||||
|
{
|
||||||
|
$bawahan = $this->getListBawahan($nipAtasan)['data']['bawahan'] ?? [];
|
||||||
|
|
||||||
|
return in_array($nipBawahan, array_column($bawahan, 'nip'), true);
|
||||||
|
}
|
||||||
|
|
||||||
public function isVerifikatorTriDharma(string $nip)
|
public function isVerifikatorTriDharma(string $nip)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -88,7 +95,7 @@ class DawaiService
|
|||||||
public function listPegawai(string $nip = '', string $jenisPegawai = '', string $email = ''): array
|
public function listPegawai(string $nip = '', string $jenisPegawai = '', string $email = ''): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->client->get("api/v1/pegawai?jenis_pegawai=$jenisPegawai&nip=$nip&email=$email&asn=true&pensiun=0&wafat=0&mutkel=0&nonaktif=0");
|
$response = $this->client->get("api/v1/pegawai?jenis_pegawai=$jenisPegawai&nip=$nip&email=$email&asn=true&pensiun=0&wafat=0&mutkel=0&nonaktif=0&privasi=true");
|
||||||
$data = json_decode($response->getBody()->getContents(), true);
|
$data = json_decode($response->getBody()->getContents(), true);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Google\Client;
|
||||||
|
use Google\Service\Drive;
|
||||||
|
use Google\Service\Drive\DriveFile;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class GoogleDriveService
|
||||||
|
{
|
||||||
|
private string $credentialsPath;
|
||||||
|
|
||||||
|
private string $rootFolderId;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->credentialsPath = (string) config('services.google_drive.credentials_path');
|
||||||
|
$this->rootFolderId = (string) config('services.google_drive.folder_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function uploadPdf(string $content, string $nip, string $namaPegawai, string $tanggal, string $namaKategori): string|false
|
||||||
|
{
|
||||||
|
if (! $this->credentialsPath || ! file_exists($this->credentialsPath) || ! $this->rootFolderId) {
|
||||||
|
Log::error('GoogleDriveService: belum dikonfigurasi, upload dilewati.');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$client = new Client();
|
||||||
|
$client->setAuthConfig($this->credentialsPath);
|
||||||
|
$client->addScope(Drive::DRIVE);
|
||||||
|
|
||||||
|
$service = new Drive($client);
|
||||||
|
|
||||||
|
$pengajuanPresensiFolderId = $this->findOrCreateFolder($service, 'Pengajuan Presensi', $this->rootFolderId);
|
||||||
|
$pegawaiFolderId = $this->findOrCreateFolder($service, $this->sanitize("$nip - $namaPegawai"), $pengajuanPresensiFolderId);
|
||||||
|
$bulanFolderId = $this->findOrCreateFolder($service, Carbon::parse($tanggal)->translatedFormat('F Y'), $pegawaiFolderId);
|
||||||
|
|
||||||
|
$fileName = Carbon::parse($tanggal)->format('Y-m-d').'_'.$this->sanitize($namaKategori).'.pdf';
|
||||||
|
|
||||||
|
$fileMetadata = new DriveFile([
|
||||||
|
'name' => $fileName,
|
||||||
|
'parents' => [$bulanFolderId],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$uploaded = $service->files->create($fileMetadata, [
|
||||||
|
'data' => $content,
|
||||||
|
'mimeType' => 'application/pdf',
|
||||||
|
'uploadType' => 'multipart',
|
||||||
|
'fields' => 'id, webViewLink',
|
||||||
|
'supportsAllDrives' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $uploaded->getWebViewLink() ?: $uploaded->getId();
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
Log::error('GoogleDriveService uploadPdf : '.$th->getMessage());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function findOrCreateFolder(Drive $service, string $name, string $parentId): string
|
||||||
|
{
|
||||||
|
$escapedName = str_replace("'", "\\'", $name);
|
||||||
|
|
||||||
|
$result = $service->files->listFiles([
|
||||||
|
'q' => "name='$escapedName' and '$parentId' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false",
|
||||||
|
'fields' => 'files(id)',
|
||||||
|
'supportsAllDrives' => true,
|
||||||
|
'includeItemsFromAllDrives' => true,
|
||||||
|
'corpora' => 'allDrives',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$existing = $result->getFiles();
|
||||||
|
|
||||||
|
if (count($existing) > 0) {
|
||||||
|
return $existing[0]->getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
$folder = new DriveFile([
|
||||||
|
'name' => $name,
|
||||||
|
'mimeType' => 'application/vnd.google-apps.folder',
|
||||||
|
'parents' => [$parentId],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$created = $service->files->create($folder, [
|
||||||
|
'fields' => 'id',
|
||||||
|
'supportsAllDrives' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $created->getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sanitize(string $value): string
|
||||||
|
{
|
||||||
|
return trim(str_replace(['/', '\\'], '-', $value));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class TteService
|
||||||
|
{
|
||||||
|
private string $baseUrl = 'http://118.98.229.146';
|
||||||
|
|
||||||
|
private string $username = '9702946';
|
||||||
|
|
||||||
|
private string $password = 'DsC1-G0cP-Pbk8-qYxE';
|
||||||
|
|
||||||
|
public function signDokumenUser(string $nik, string $passphrase, string $filePath, string $linkQr): string|false
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$query = http_build_query([
|
||||||
|
'nik' => $nik,
|
||||||
|
'passphrase' => $passphrase,
|
||||||
|
'tampilan' => 'invisible',
|
||||||
|
'halaman' => 'terakhir',
|
||||||
|
'image' => 'false',
|
||||||
|
'xAxis' => 43.63,
|
||||||
|
'yAxis' => 28.71,
|
||||||
|
'width' => 550.78,
|
||||||
|
'height' => 130.88,
|
||||||
|
'reason' => 'Dokumen ditandatangani secara elektronik Universitas Tanjungpura',
|
||||||
|
'location' => 'Universitas Tanjungpura',
|
||||||
|
'linkQR' => $linkQr,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = Http::withBasicAuth($this->username, $this->password)
|
||||||
|
->timeout(60)
|
||||||
|
->attach('file', file_get_contents($filePath), basename($filePath))
|
||||||
|
->post("{$this->baseUrl}/api/sign/pdf?{$query}");
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
Log::error('TTE signDokumenUser : '.$th->getMessage());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
Log::error("TTE signDokumenUser gagal: HTTP {$response->status()} - {$response->body()}");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response->body();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
class VerifikasiAbsenLinkService
|
||||||
|
{
|
||||||
|
const TTL_MENIT_DEFAULT = 7200;
|
||||||
|
|
||||||
|
public function generate(int $pengajuanId, string $nip, int $ttlMenit = self::TTL_MENIT_DEFAULT): array
|
||||||
|
{
|
||||||
|
$expires = now()->addMinutes($ttlMenit)->timestamp;
|
||||||
|
$signature = $this->hash($pengajuanId, $nip, $expires);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'nip' => $nip,
|
||||||
|
'expires' => $expires,
|
||||||
|
'signature' => $signature,
|
||||||
|
'url' => $this->url($pengajuanId, $nip, $expires, $signature),
|
||||||
|
'button_param' => "{$pengajuanId}?nip={$nip}&expires={$expires}&signature={$signature}",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function url(int $pengajuanId, ?string $nip = null, ?int $expires = null, ?string $signature = null): string
|
||||||
|
{
|
||||||
|
$base = rtrim(config('services.verifikasi_absen_wa.url'), '/')."/{$pengajuanId}";
|
||||||
|
|
||||||
|
if (! $nip || ! $expires || ! $signature) {
|
||||||
|
return $base;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $base.'?'.http_build_query(compact('nip', 'expires', 'signature'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verify(int $pengajuanId, ?string $nip, mixed $expires, ?string $signature): bool
|
||||||
|
{
|
||||||
|
if (! $nip || ! $expires || ! $signature) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((int) $expires < now()->timestamp) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$expected = $this->hash($pengajuanId, $nip, (int) $expires);
|
||||||
|
|
||||||
|
return hash_equals($expected, $signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function hash(int $pengajuanId, string $nip, int $expires): string
|
||||||
|
{
|
||||||
|
return hash_hmac('sha256', "{$pengajuanId}|{$nip}|{$expires}", config('app.key'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class WhatsAppService
|
||||||
|
{
|
||||||
|
private string $baseUrl = 'https://chat.api.co.id';
|
||||||
|
|
||||||
|
private string $token = 'apicoid_live_7J0vmW5Sbk2dBBAEIEDtdc4tG4fOswy3Seblz_nKZqk';
|
||||||
|
|
||||||
|
public function sendPengajuanAbsenNotification(
|
||||||
|
string $nomorTujuan,
|
||||||
|
string $namaAtasan,
|
||||||
|
string $namaPemohon,
|
||||||
|
string $nipPemohon,
|
||||||
|
int $jumlahHari,
|
||||||
|
string $tanggalMulai,
|
||||||
|
string $tanggalSelesai,
|
||||||
|
string $keterangan,
|
||||||
|
string $link
|
||||||
|
): bool {
|
||||||
|
try {
|
||||||
|
$response = Http::withToken($this->token)
|
||||||
|
->post("{$this->baseUrl}/api/v1/public/messages/send", [
|
||||||
|
'phone_number' => $nomorTujuan,
|
||||||
|
'channel' => 'whatsapp',
|
||||||
|
'message_type' => 'template',
|
||||||
|
'template' => [
|
||||||
|
'name' => 'pengajuan_absen',
|
||||||
|
'language' => ['code' => 'id'],
|
||||||
|
'components' => [
|
||||||
|
[
|
||||||
|
'type' => 'body',
|
||||||
|
'parameters' => [
|
||||||
|
['type' => 'text', 'text' => $namaAtasan],
|
||||||
|
['type' => 'text', 'text' => $namaPemohon],
|
||||||
|
['type' => 'text', 'text' => $nipPemohon],
|
||||||
|
['type' => 'text', 'text' => (string) $jumlahHari],
|
||||||
|
['type' => 'text', 'text' => $tanggalMulai],
|
||||||
|
['type' => 'text', 'text' => $tanggalSelesai],
|
||||||
|
['type' => 'text', 'text' => $keterangan],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'type' => 'button',
|
||||||
|
'sub_type' => 'url',
|
||||||
|
'index' => '0',
|
||||||
|
'parameters' => [
|
||||||
|
['type' => 'text', 'text' => $link],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
Log::error('WhatsApp sendPengajuanAbsenNotification : '.$th->getMessage());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
Log::error("WhatsApp sendPengajuanAbsenNotification gagal: HTTP {$response->status()} - {$response->body()}");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
-4
@@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Middleware\CheckPermission;
|
||||||
|
use App\Http\Middleware\EnsureBawahanPresensi;
|
||||||
|
use App\Http\Middleware\SetPermissionsTeamId;
|
||||||
|
use App\Http\Middleware\UntanSSO;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Foundation\Configuration\Exceptions;
|
use Illuminate\Foundation\Configuration\Exceptions;
|
||||||
use Illuminate\Foundation\Configuration\Middleware;
|
use Illuminate\Foundation\Configuration\Middleware;
|
||||||
@@ -17,7 +21,8 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$middleware->alias([
|
$middleware->alias([
|
||||||
'permission' => \App\Http\Middleware\CheckPermission::class,
|
'permission' => CheckPermission::class,
|
||||||
|
'bawahan.presensi' => EnsureBawahanPresensi::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Trust proxies for HTTPS forwarding
|
// Trust proxies for HTTPS forwarding
|
||||||
@@ -25,10 +30,13 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
|
|
||||||
// Add SetPermissionsTeamId middleware to web group
|
// Add SetPermissionsTeamId middleware to web group
|
||||||
$middleware->web(append: [
|
$middleware->web(append: [
|
||||||
\App\Http\Middleware\SetPermissionsTeamId::class,
|
SetPermissionsTeamId::class,
|
||||||
\App\Http\Middleware\UntanSSO::class,
|
UntanSSO::class,
|
||||||
]);
|
]);
|
||||||
})
|
})
|
||||||
->withExceptions(function (Exceptions $exceptions): void {
|
->withExceptions(function (Exceptions $exceptions): void {
|
||||||
//
|
// Route API selalu balas JSON (mis. error validasi 422), bukan redirect ke login.
|
||||||
|
$exceptions->shouldRenderJsonWhen(
|
||||||
|
fn ($request, $e) => $request->is('api/*') || $request->expectsJson()
|
||||||
|
);
|
||||||
})->create();
|
})->create();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
|
"google/apiclient": "^2.19",
|
||||||
"laravel/framework": "^12.0",
|
"laravel/framework": "^12.0",
|
||||||
"laravel/socialite": "^5.23",
|
"laravel/socialite": "^5.23",
|
||||||
"laravel/tinker": "^2.10.1",
|
"laravel/tinker": "^2.10.1",
|
||||||
|
|||||||
Generated
+236
-1
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "e35c9d807d4c3b727d8b29698aada6ae",
|
"content-hash": "ff4de989ae1021516a8c7e527a1faed3",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
@@ -860,6 +860,192 @@
|
|||||||
],
|
],
|
||||||
"time": "2025-12-03T09:33:47+00:00"
|
"time": "2025-12-03T09:33:47+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "google/apiclient",
|
||||||
|
"version": "v2.19.4",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/googleapis/google-api-php-client.git",
|
||||||
|
"reference": "f745b310113d556c19d5e54ccc48b5821d1e2622"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/f745b310113d556c19d5e54ccc48b5821d1e2622",
|
||||||
|
"reference": "f745b310113d556c19d5e54ccc48b5821d1e2622",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"firebase/php-jwt": "^6.0||^7.0",
|
||||||
|
"google/apiclient-services": "~0.350",
|
||||||
|
"google/auth": "^1.37",
|
||||||
|
"guzzlehttp/guzzle": "^7.4.5",
|
||||||
|
"guzzlehttp/psr7": "^2.6",
|
||||||
|
"monolog/monolog": "^2.9||^3.0",
|
||||||
|
"php": "^8.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"cache/filesystem-adapter": "^1.1",
|
||||||
|
"composer/composer": "^2.9",
|
||||||
|
"phpcompatibility/php-compatibility": "^9.2",
|
||||||
|
"phpspec/prophecy-phpunit": "^2.1",
|
||||||
|
"phpunit/phpunit": "^9.6",
|
||||||
|
"squizlabs/php_codesniffer": "^3.8",
|
||||||
|
"symfony/css-selector": "^5.4",
|
||||||
|
"symfony/dom-crawler": "^5.4"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"component": {
|
||||||
|
"entry": "src/Client.php"
|
||||||
|
},
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "2.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"src/aliases.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Google\\": "src/"
|
||||||
|
},
|
||||||
|
"classmap": [
|
||||||
|
"src/aliases.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"Apache-2.0"
|
||||||
|
],
|
||||||
|
"description": "Client library for Google APIs",
|
||||||
|
"homepage": "http://developers.google.com/api-client-library/php",
|
||||||
|
"keywords": [
|
||||||
|
"google"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/googleapis/google-api-php-client/issues",
|
||||||
|
"source": "https://github.com/googleapis/google-api-php-client/tree/v2.19.4"
|
||||||
|
},
|
||||||
|
"time": "2026-06-29T08:12:37+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "google/apiclient-services",
|
||||||
|
"version": "v0.459.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/googleapis/google-api-php-client-services.git",
|
||||||
|
"reference": "3b45be50c8420dea56b6f2326ff745175c3cafb8"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/3b45be50c8420dea56b6f2326ff745175c3cafb8",
|
||||||
|
"reference": "3b45be50c8420dea56b6f2326ff745175c3cafb8",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^8.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^9.6"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"autoload.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Google\\Service\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"Apache-2.0"
|
||||||
|
],
|
||||||
|
"description": "Client library for Google APIs",
|
||||||
|
"homepage": "http://developers.google.com/api-client-library/php",
|
||||||
|
"keywords": [
|
||||||
|
"google"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/googleapis/google-api-php-client-services/issues",
|
||||||
|
"source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.459.0"
|
||||||
|
},
|
||||||
|
"time": "2026-09-14T01:22:23+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "google/auth",
|
||||||
|
"version": "v1.54.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/googleapis/google-auth-library-php.git",
|
||||||
|
"reference": "a9e3aedd93f01997e935556adbd1866fec576968"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/a9e3aedd93f01997e935556adbd1866fec576968",
|
||||||
|
"reference": "a9e3aedd93f01997e935556adbd1866fec576968",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"firebase/php-jwt": "^6.0||^7.0",
|
||||||
|
"guzzlehttp/guzzle": "^7.8.2||^8.0",
|
||||||
|
"guzzlehttp/psr7": "^2.6.3||^3.0",
|
||||||
|
"php": "^8.1",
|
||||||
|
"psr/cache": "^2.0||^3.0",
|
||||||
|
"psr/http-client": "^1.0",
|
||||||
|
"psr/http-message": "^1.1||^2.0",
|
||||||
|
"psr/log": "^2.0||^3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"guzzlehttp/promises": "^2.0.3||^3.0",
|
||||||
|
"kelvinmo/simplejwt": "^1.1.0",
|
||||||
|
"phpseclib/phpseclib": "^3.0.35",
|
||||||
|
"phpspec/prophecy-phpunit": "^2.1",
|
||||||
|
"phpunit/phpunit": "^9.6",
|
||||||
|
"sebastian/comparator": ">=1.2.3",
|
||||||
|
"squizlabs/php_codesniffer": "^4.0",
|
||||||
|
"symfony/filesystem": "^6.3||^7.3",
|
||||||
|
"symfony/process": "^6.0||^7.0",
|
||||||
|
"webmozart/assert": "^1.11||^2.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"phpseclib/phpseclib": "May be used in place of OpenSSL for signing strings or for token management. Please require version ^2."
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"component": {
|
||||||
|
"id": "auth",
|
||||||
|
"path": "Auth",
|
||||||
|
"entry": "README.md",
|
||||||
|
"target": "googleapis/google-auth-library-php.git"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Google\\Auth\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"Apache-2.0"
|
||||||
|
],
|
||||||
|
"description": "Google Auth Library for PHP",
|
||||||
|
"homepage": "https://github.com/googleapis/google-auth-library-php",
|
||||||
|
"keywords": [
|
||||||
|
"Authentication",
|
||||||
|
"google",
|
||||||
|
"oauth2"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"docs": "https://cloud.google.com/php/docs/reference/auth/latest",
|
||||||
|
"issues": "https://github.com/googleapis/google-auth-library-php/issues",
|
||||||
|
"source": "https://github.com/googleapis/google-auth-library-php/tree/v1.54.0"
|
||||||
|
},
|
||||||
|
"time": "2026-09-14T18:27:51+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "graham-campbell/result-type",
|
"name": "graham-campbell/result-type",
|
||||||
"version": "v1.1.4",
|
"version": "v1.1.4",
|
||||||
@@ -3855,6 +4041,55 @@
|
|||||||
],
|
],
|
||||||
"time": "2026-04-10T01:33:53+00:00"
|
"time": "2026-04-10T01:33:53+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "psr/cache",
|
||||||
|
"version": "3.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-fig/cache.git",
|
||||||
|
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
|
||||||
|
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.0.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.0.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Psr\\Cache\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "PHP-FIG",
|
||||||
|
"homepage": "https://www.php-fig.org/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Common interface for caching libraries",
|
||||||
|
"keywords": [
|
||||||
|
"cache",
|
||||||
|
"psr",
|
||||||
|
"psr-6"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/php-fig/cache/tree/3.0.0"
|
||||||
|
},
|
||||||
|
"time": "2021-02-03T23:26:27+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "psr/clock",
|
"name": "psr/clock",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'paths' => ['api/*'],
|
||||||
|
|
||||||
|
'allowed_methods' => ['*'],
|
||||||
|
|
||||||
|
'allowed_origins' => array_filter([
|
||||||
|
env('VERIFIKASI_ABSEN_WA_URL'),
|
||||||
|
]),
|
||||||
|
|
||||||
|
'allowed_origins_patterns' => [],
|
||||||
|
|
||||||
|
'allowed_headers' => ['*'],
|
||||||
|
|
||||||
|
'exposed_headers' => [],
|
||||||
|
|
||||||
|
'max_age' => 0,
|
||||||
|
|
||||||
|
'supports_credentials' => false,
|
||||||
|
|
||||||
|
];
|
||||||
@@ -130,6 +130,21 @@ return [
|
|||||||
]) : [],
|
]) : [],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'sidia' => [
|
||||||
|
'driver' => 'pgsql',
|
||||||
|
'url' => env('DATABASE_URL_SIDIA'),
|
||||||
|
'host' => env('DB_HOST_SIDIA', '127.0.0.1'),
|
||||||
|
'port' => env('DB_PORT_SIDIA', '5432'),
|
||||||
|
'database' => env('DB_DATABASE_SIDIA', 'forge'),
|
||||||
|
'username' => env('DB_USERNAME_SIDIA', 'forge'),
|
||||||
|
'password' => env('DB_PASSWORD_SIDIA', ''),
|
||||||
|
'charset' => env('DB_CHARSET', 'utf8'),
|
||||||
|
'prefix' => '',
|
||||||
|
'prefix_indexes' => true,
|
||||||
|
'search_path' => 'public',
|
||||||
|
'sslmode' => 'prefer',
|
||||||
|
],
|
||||||
|
|
||||||
'rekapitulasi' => [
|
'rekapitulasi' => [
|
||||||
'driver' => 'pgsql',
|
'driver' => 'pgsql',
|
||||||
'url' => env('DATABASE_URL'),
|
'url' => env('DATABASE_URL'),
|
||||||
|
|||||||
@@ -41,4 +41,18 @@ return [
|
|||||||
'redirect' => env('GOOGLE_REDIRECT_URL', env('APP_URL') . '/auth/google/callback'),
|
'redirect' => env('GOOGLE_REDIRECT_URL', env('APP_URL') . '/auth/google/callback'),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'verifikator_webhook' => [
|
||||||
|
'url' => env('VERIFIKATOR_WEBHOOK_URL', 'http://172.16.50.94:8087/webhook/verifikator'),
|
||||||
|
'key' => env('VERIFIKATOR_WEBHOOK_KEY'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'verifikasi_absen_wa' => [
|
||||||
|
'url' => env('VERIFIKASI_ABSEN_WA_URL', 'http://verifikasi-presensi-whatsapp.test'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'google_drive' => [
|
||||||
|
'credentials_path' => env('GOOGLE_DRIVE_CREDENTIALS_PATH', storage_path('app/private/google-drive-service-account.json')),
|
||||||
|
'folder_id' => env('GOOGLE_DRIVE_FOLDER_ID'),
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Definisi view verifikator.pegawais (union dosens + tendiks) yang bergantung
|
||||||
|
* pada kolom no_hp, sehingga harus di-drop sebelum ALTER dan dibuat ulang setelahnya.
|
||||||
|
*/
|
||||||
|
private string $viewDefinition = <<<'SQL'
|
||||||
|
CREATE VIEW verifikator.pegawais AS
|
||||||
|
SELECT dosens.id,
|
||||||
|
dosens.nip,
|
||||||
|
dosens.nip_siakad,
|
||||||
|
dosens.nip_sk,
|
||||||
|
dosens.sk,
|
||||||
|
dosens.status_nip,
|
||||||
|
dosens.nama,
|
||||||
|
'dosen'::text AS jenis_pegawai,
|
||||||
|
dosens.no_hp,
|
||||||
|
dosens.unit_kerja_id,
|
||||||
|
dosens.unit_kerja_nama,
|
||||||
|
dosens.pendidikan_terakhir,
|
||||||
|
dosens.prodi_id,
|
||||||
|
dosens.tubel_berangkat,
|
||||||
|
dosens.tubel_kembali,
|
||||||
|
dosens.pensiun,
|
||||||
|
dosens.wafat,
|
||||||
|
dosens.jabatan_fungsional_id,
|
||||||
|
dosens.jabatan_fungsional_nama,
|
||||||
|
dosens.jabatan_dtt_id,
|
||||||
|
dosens.jabatan_dtt_nama,
|
||||||
|
dosens.jabatan_dtt_tanggal_berlaku,
|
||||||
|
dosens.jabatan_dtt_tanggal_berakhir,
|
||||||
|
dosens.npwp,
|
||||||
|
dosens.nomor_rekening
|
||||||
|
FROM verifikator.dosens
|
||||||
|
UNION
|
||||||
|
SELECT tendiks.id,
|
||||||
|
tendiks.nip,
|
||||||
|
tendiks.nip_siakad,
|
||||||
|
tendiks.nip_sk,
|
||||||
|
tendiks.sk,
|
||||||
|
tendiks.status_nip,
|
||||||
|
tendiks.nama,
|
||||||
|
'tendik'::text AS jenis_pegawai,
|
||||||
|
tendiks.no_hp,
|
||||||
|
tendiks.unit_kerja_id,
|
||||||
|
tendiks.unit_kerja_nama,
|
||||||
|
tendiks.pendidikan_terakhir,
|
||||||
|
NULL::bigint AS prodi_id,
|
||||||
|
tendiks.tubel_berangkat,
|
||||||
|
tendiks.tubel_kembali,
|
||||||
|
tendiks.pensiun,
|
||||||
|
tendiks.wafat,
|
||||||
|
tendiks.jabatan_fungsional_id,
|
||||||
|
tendiks.jabatan_fungsional_nama,
|
||||||
|
tendiks.jabatan_dtt_id,
|
||||||
|
tendiks.jabatan_dtt_nama,
|
||||||
|
tendiks.jabatan_dtt_tanggal_berlaku,
|
||||||
|
tendiks.jabatan_dtt_tanggal_berakhir,
|
||||||
|
tendiks.npwp,
|
||||||
|
tendiks.nomor_rekening
|
||||||
|
FROM verifikator.tendiks
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
DB::statement('DROP VIEW IF EXISTS verifikator.pegawais');
|
||||||
|
|
||||||
|
Schema::table('verifikator.dosens', function (Blueprint $table) {
|
||||||
|
$table->string('no_hp', 20)->nullable()->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('verifikator.tendiks', function (Blueprint $table) {
|
||||||
|
$table->string('no_hp', 20)->nullable()->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement($this->viewDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
DB::statement('DROP VIEW IF EXISTS verifikator.pegawais');
|
||||||
|
|
||||||
|
Schema::table('verifikator.dosens', function (Blueprint $table) {
|
||||||
|
$table->string('no_hp', 13)->nullable()->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('verifikator.tendiks', function (Blueprint $table) {
|
||||||
|
$table->string('no_hp', 13)->nullable()->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement($this->viewDefinition);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Definisi view verifikator.pegawais (union dosens + tendiks) yang bergantung
|
||||||
|
* pada kolom no_hp, sehingga harus di-drop sebelum ALTER dan dibuat ulang setelahnya.
|
||||||
|
*/
|
||||||
|
private string $viewDefinition = <<<'SQL'
|
||||||
|
CREATE VIEW verifikator.pegawais AS
|
||||||
|
SELECT dosens.id,
|
||||||
|
dosens.nip,
|
||||||
|
dosens.nip_siakad,
|
||||||
|
dosens.nip_sk,
|
||||||
|
dosens.sk,
|
||||||
|
dosens.status_nip,
|
||||||
|
dosens.nama,
|
||||||
|
'dosen'::text AS jenis_pegawai,
|
||||||
|
dosens.no_hp,
|
||||||
|
dosens.unit_kerja_id,
|
||||||
|
dosens.unit_kerja_nama,
|
||||||
|
dosens.pendidikan_terakhir,
|
||||||
|
dosens.prodi_id,
|
||||||
|
dosens.tubel_berangkat,
|
||||||
|
dosens.tubel_kembali,
|
||||||
|
dosens.pensiun,
|
||||||
|
dosens.wafat,
|
||||||
|
dosens.jabatan_fungsional_id,
|
||||||
|
dosens.jabatan_fungsional_nama,
|
||||||
|
dosens.jabatan_dtt_id,
|
||||||
|
dosens.jabatan_dtt_nama,
|
||||||
|
dosens.jabatan_dtt_tanggal_berlaku,
|
||||||
|
dosens.jabatan_dtt_tanggal_berakhir,
|
||||||
|
dosens.npwp,
|
||||||
|
dosens.nomor_rekening
|
||||||
|
FROM verifikator.dosens
|
||||||
|
UNION
|
||||||
|
SELECT tendiks.id,
|
||||||
|
tendiks.nip,
|
||||||
|
tendiks.nip_siakad,
|
||||||
|
tendiks.nip_sk,
|
||||||
|
tendiks.sk,
|
||||||
|
tendiks.status_nip,
|
||||||
|
tendiks.nama,
|
||||||
|
'tendik'::text AS jenis_pegawai,
|
||||||
|
tendiks.no_hp,
|
||||||
|
tendiks.unit_kerja_id,
|
||||||
|
tendiks.unit_kerja_nama,
|
||||||
|
tendiks.pendidikan_terakhir,
|
||||||
|
NULL::bigint AS prodi_id,
|
||||||
|
tendiks.tubel_berangkat,
|
||||||
|
tendiks.tubel_kembali,
|
||||||
|
tendiks.pensiun,
|
||||||
|
tendiks.wafat,
|
||||||
|
tendiks.jabatan_fungsional_id,
|
||||||
|
tendiks.jabatan_fungsional_nama,
|
||||||
|
tendiks.jabatan_dtt_id,
|
||||||
|
tendiks.jabatan_dtt_nama,
|
||||||
|
tendiks.jabatan_dtt_tanggal_berlaku,
|
||||||
|
tendiks.jabatan_dtt_tanggal_berakhir,
|
||||||
|
tendiks.npwp,
|
||||||
|
tendiks.nomor_rekening
|
||||||
|
FROM verifikator.tendiks
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
DB::statement('DROP VIEW IF EXISTS verifikator.pegawais');
|
||||||
|
|
||||||
|
Schema::table('verifikator.dosens', function (Blueprint $table) {
|
||||||
|
$table->string('no_hp', 100)->nullable()->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('verifikator.tendiks', function (Blueprint $table) {
|
||||||
|
$table->string('no_hp', 100)->nullable()->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement($this->viewDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
DB::statement('DROP VIEW IF EXISTS verifikator.pegawais');
|
||||||
|
|
||||||
|
Schema::table('verifikator.dosens', function (Blueprint $table) {
|
||||||
|
$table->string('no_hp', 20)->nullable()->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('verifikator.tendiks', function (Blueprint $table) {
|
||||||
|
$table->string('no_hp', 20)->nullable()->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement($this->viewDefinition);
|
||||||
|
}
|
||||||
|
};
|
||||||
+7
-6
@@ -90,15 +90,16 @@ Verifikasi laporan kegiatan non-mengajar, terbagi tiga kategori:
|
|||||||
|
|
||||||
### Pengajuan Presensi
|
### Pengajuan Presensi
|
||||||
|
|
||||||
Verifikasi pengajuan presensi/absensi manual, dipisah berdasarkan jenis pegawai:
|
Verifikasi pengajuan presensi/absensi manual dalam satu halaman gabungan, dengan filter **Jenis Pegawai**:
|
||||||
|
|
||||||
- **Honorer**
|
- **Non ASN** (sebelumnya menu Honorer)
|
||||||
- **Tendik** (Tenaga Kependidikan)
|
- **ASN** (sebelumnya menu Tendik / Tenaga Kependidikan)
|
||||||
|
- **Semua** — gabungan keduanya (tampilan default)
|
||||||
|
|
||||||
Setiap tab punya sub-status **Belum Selesai** dan **Selesai**, serta filter per Unit Kerja dan Bulan.
|
Halaman punya sub-status **Belum Selesai** dan **Selesai**, serta filter per Unit Kerja dan Bulan.
|
||||||
|
Setiap baris menampilkan badge jenis pegawai; klik baris membuka halaman detail pengajuan pegawai tersebut.
|
||||||
|
|
||||||

|

|
||||||

|
|
||||||
|
|
||||||
### SKP
|
### SKP
|
||||||
|
|
||||||
|
|||||||
@@ -1755,5 +1755,82 @@
|
|||||||
"grade": 14,
|
"grade": 14,
|
||||||
"harga_bruto": 11776000,
|
"harga_bruto": 11776000,
|
||||||
"harga_jabatan": 1766400
|
"harga_jabatan": 1766400
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 178,
|
||||||
|
"nama_jabatan": "Pengelola Data dan Informasi",
|
||||||
|
"grade": 6,
|
||||||
|
"harga_bruto": 2661000,
|
||||||
|
"harga_jabatan": 399150
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 54,
|
||||||
|
"nama_jabatan": "Pranata Laboratorium Pendidikan Pertama",
|
||||||
|
"grade": 8,
|
||||||
|
"harga_bruto": 3308000,
|
||||||
|
"harga_jabatan": 496200
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 108,
|
||||||
|
"nama_jabatan": "Arsiparis Pertama",
|
||||||
|
"grade": 8,
|
||||||
|
"harga_bruto": 3308000,
|
||||||
|
"harga_jabatan": 496200
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 56,
|
||||||
|
"nama_jabatan": "Pranata Komputer Pertama",
|
||||||
|
"grade": 8,
|
||||||
|
"harga_bruto": 3308000,
|
||||||
|
"harga_jabatan": 496200
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 157,
|
||||||
|
"nama_jabatan": "Bidan Mahir",
|
||||||
|
"grade": 7,
|
||||||
|
"harga_bruto": 0,
|
||||||
|
"harga_jabatan": 622800
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 45,
|
||||||
|
"nama_jabatan": "Pranata Laboratorium Pendidikan Muda",
|
||||||
|
"grade": 9,
|
||||||
|
"harga_bruto": 4221000,
|
||||||
|
"harga_jabatan": 633150
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 227,
|
||||||
|
"nama_jabatan": "Fisioterapis Mahir",
|
||||||
|
"grade": 6,
|
||||||
|
"harga_bruto": 0,
|
||||||
|
"harga_jabatan": 644850
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 46,
|
||||||
|
"nama_jabatan": "Pustakawan Muda",
|
||||||
|
"grade": 9,
|
||||||
|
"harga_bruto": 4221000,
|
||||||
|
"harga_jabatan": 633150
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 55,
|
||||||
|
"nama_jabatan": "Pustakawan Pertama",
|
||||||
|
"grade": 8,
|
||||||
|
"harga_bruto": 3308000,
|
||||||
|
"harga_jabatan": 496200
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 29,
|
||||||
|
"nama_jabatan": "Kepala Bagian Umum",
|
||||||
|
"grade": 12,
|
||||||
|
"harga_bruto": 8637000,
|
||||||
|
"harga_jabatan": 1295550
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no": 228,
|
||||||
|
"nama_jabatan": "Nutrisionis Terampil",
|
||||||
|
"grade": 6,
|
||||||
|
"harga_bruto": 0,
|
||||||
|
"harga_jabatan": 580950
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -145,18 +145,24 @@
|
|||||||
'actionButton' =>
|
'actionButton' =>
|
||||||
'<div class="d-flex flex-wrap gap-2">'
|
'<div class="d-flex flex-wrap gap-2">'
|
||||||
. '<button type="button" id="warm-cache-btn" class="btn btn-outline-primary"><i class="mdi mdi-database-refresh-outline me-1"></i> Perbarui Data</button>'
|
. '<button type="button" id="warm-cache-btn" class="btn btn-outline-primary"><i class="mdi mdi-database-refresh-outline me-1"></i> Perbarui Data</button>'
|
||||||
. '<a id="export-excel" class="btn btn-success" href="' . route('lainnya.simulasi-jabatan.export') . '"><i class="mdi mdi-file-excel me-1"></i> Rekap Excel</a>'
|
. '<div class="btn-group">'
|
||||||
|
. '<button type="button" class="btn btn-success dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-file-excel me-1"></i> Rekap Excel</button>'
|
||||||
|
. '<ul class="dropdown-menu dropdown-menu-end">'
|
||||||
|
. '<li><a class="dropdown-item" id="export-excel-detail" href="' . route('lainnya.simulasi-jabatan.export') . '"><i class="mdi mdi-format-list-bulleted me-1"></i> Detail</a></li>'
|
||||||
|
. '<li><a class="dropdown-item" id="export-excel-total" href="' . route('lainnya.simulasi-jabatan.export-total') . '"><i class="mdi mdi-sigma me-1"></i> Total</a></li>'
|
||||||
|
. '</ul>'
|
||||||
|
. '</div>'
|
||||||
. '</div>',
|
. '</div>',
|
||||||
])
|
])
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-md-4"><label class="form-label">Periode</label><select id="periode"
|
<div class="col-md-3"><label class="form-label">Periode</label><select id="periode"
|
||||||
class="form-select select2" data-placeholder="Pilih Periode">
|
class="form-select select2" data-placeholder="Pilih Periode">
|
||||||
@foreach ($periodes as $periode)
|
@foreach ($periodes as $periode)
|
||||||
<option value="{{ $periode->id_periode }}"
|
<option value="{{ $periode->id_periode }}"
|
||||||
{{ $periode->id_periode == $periodeNow ? 'selected' : '' }}>{{ $periode->nama }}</option>
|
{{ $periode->id_periode == $periodeNow ? 'selected' : '' }}>{{ $periode->nama }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select></div>
|
</select></div>
|
||||||
<div class="col-md-4"><label class="form-label">Unit Kerja</label><select id="unit_kerja_id"
|
<div class="col-md-3"><label class="form-label">Unit Kerja</label><select id="unit_kerja_id"
|
||||||
class="form-select select2" data-placeholder="Pilih Unit Kerja">
|
class="form-select select2" data-placeholder="Pilih Unit Kerja">
|
||||||
<option value="">Semua Unit Kerja</option>
|
<option value="">Semua Unit Kerja</option>
|
||||||
<option value="99">Universitas</option>
|
<option value="99">Universitas</option>
|
||||||
@@ -175,12 +181,19 @@
|
|||||||
<label class="form-check-label" for="split_unit">Unit Pembayaran</label>
|
<label class="form-check-label" for="split_unit">Unit Pembayaran</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4"><label class="form-label">Jenis Pegawai</label><select id="jenis_pegawai"
|
<div class="col-md-3"><label class="form-label">Jenis Pegawai</label><select id="jenis_pegawai"
|
||||||
class="form-select select2" data-placeholder="Pilih Jenis Pegawai">
|
class="form-select select2" data-placeholder="Pilih Jenis Pegawai">
|
||||||
<option value="">Semua Jenis Pegawai</option>
|
<option value="">Semua Jenis Pegawai</option>
|
||||||
<option value="dosen">Dosen</option>
|
<option value="dosen">Dosen</option>
|
||||||
<option value="tendik">Tendik</option>
|
<option value="tendik">Tendik</option>
|
||||||
</select></div>
|
</select></div>
|
||||||
|
<div class="col-md-3"><label class="form-label">Jenjang Pendidikan</label><select
|
||||||
|
id="jenjang_pendidikan" class="form-select select2" data-placeholder="Pilih Jenjang Pendidikan">
|
||||||
|
<option value="">Semua Jenjang Pendidikan</option>
|
||||||
|
@foreach ($jenjangPendidikanList as $jp)
|
||||||
|
<option value="{{ $jp }}">{{ $jp === \App\Helpers\JenjangPendidikanHelper::KOSONG ? \App\Helpers\JenjangPendidikanHelper::KOSONG_LABEL : $jp }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check form-switch mb-3">
|
<div class="form-check form-switch mb-3">
|
||||||
<input class="form-check-input" type="checkbox" role="switch" id="grade12">
|
<input class="form-check-input" type="checkbox" role="switch" id="grade12">
|
||||||
@@ -317,6 +330,7 @@
|
|||||||
d.periode = $('#periode').val();
|
d.periode = $('#periode').val();
|
||||||
d.unit_kerja_id = $('#unit_kerja_id').val();
|
d.unit_kerja_id = $('#unit_kerja_id').val();
|
||||||
d.jenis_pegawai = $('#jenis_pegawai').val();
|
d.jenis_pegawai = $('#jenis_pegawai').val();
|
||||||
|
d.jenjang_pendidikan = $('#jenjang_pendidikan').val();
|
||||||
d.grade12 = $('#grade12').is(':checked') ? 1 : 0;
|
d.grade12 = $('#grade12').is(':checked') ? 1 : 0;
|
||||||
d.split_unit = $('#split_unit').is(':checked') ? 1 : 0;
|
d.split_unit = $('#split_unit').is(':checked') ? 1 : 0;
|
||||||
}
|
}
|
||||||
@@ -368,24 +382,26 @@
|
|||||||
|
|
||||||
function refreshSummary() {
|
function refreshSummary() {
|
||||||
$('#summary-p2-2022, #summary-p2-2023, #summary-p2-excel').text('...');
|
$('#summary-p2-2022, #summary-p2-2023, #summary-p2-excel').text('...');
|
||||||
$.get('{{ route('lainnya.simulasi-jabatan.summary') }}', { periode: $('#periode').val(), unit_kerja_id: $('#unit_kerja_id').val(), jenis_pegawai: $('#jenis_pegawai').val(), search: table.search(), grade12: grade12On(), split_unit: splitUnitOn() }, function(res) {
|
$.get('{{ route('lainnya.simulasi-jabatan.summary') }}', { periode: $('#periode').val(), unit_kerja_id: $('#unit_kerja_id').val(), jenis_pegawai: $('#jenis_pegawai').val(), jenjang_pendidikan: $('#jenjang_pendidikan').val(), search: table.search(), grade12: grade12On(), split_unit: splitUnitOn() }, function(res) {
|
||||||
$('#summary-p2-2022').text(res.p2_total_374 || '0,00'); $('#summary-p2-2023').text(res.p2_total_377 || '0,00'); $('#summary-p2-excel').text(res.p2_total_excel || '0,00');
|
$('#summary-p2-2022').text(res.p2_total_374 || '0,00'); $('#summary-p2-2023').text(res.p2_total_377 || '0,00'); $('#summary-p2-excel').text(res.p2_total_excel || '0,00');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateExportUrl() {
|
function updateExportUrl() {
|
||||||
const params = new URLSearchParams({ periode: $('#periode').val(), jenis_pegawai: $('#jenis_pegawai').val() || '', unit_kerja_id: $('#unit_kerja_id').val() || '', grade12: grade12On() });
|
const params = new URLSearchParams({ periode: $('#periode').val(), jenis_pegawai: $('#jenis_pegawai').val() || '', unit_kerja_id: $('#unit_kerja_id').val() || '', jenjang_pendidikan: $('#jenjang_pendidikan').val() || '', grade12: grade12On() });
|
||||||
$('#export-excel').attr('href', '{{ route('lainnya.simulasi-jabatan.export') }}?' + params.toString());
|
$('#export-excel-detail').attr('href', '{{ route('lainnya.simulasi-jabatan.export') }}?' + params.toString());
|
||||||
|
params.set('split_unit', splitUnitOn());
|
||||||
|
$('#export-excel-total').attr('href', '{{ route('lainnya.simulasi-jabatan.export-total') }}?' + params.toString());
|
||||||
}
|
}
|
||||||
// Kembalikan pilihan checkbox dari sesi sebelumnya.
|
// Kembalikan pilihan checkbox dari sesi sebelumnya.
|
||||||
try {
|
try {
|
||||||
if (localStorage.getItem('simulasi-jabatan:grade12') === '1') $('#grade12').prop('checked', true);
|
if (localStorage.getItem('simulasi-jabatan:grade12') === '1') $('#grade12').prop('checked', true);
|
||||||
if (localStorage.getItem('simulasi-jabatan:split_unit') === '1') $('#split_unit').prop('checked', true);
|
if (localStorage.getItem('simulasi-jabatan:split_unit') === '1') $('#split_unit').prop('checked', true);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
$('#periode, #jenis_pegawai, #unit_kerja_id, #grade12').on('change', updateExportUrl);
|
$('#periode, #jenis_pegawai, #jenjang_pendidikan, #unit_kerja_id, #grade12, #split_unit').on('change', updateExportUrl);
|
||||||
updateExportUrl();
|
updateExportUrl();
|
||||||
$('#unit_kerja_id, #jenis_pegawai, #periode').on('change', () => table.ajax.reload());
|
$('#unit_kerja_id, #jenis_pegawai, #jenjang_pendidikan, #periode').on('change', () => table.ajax.reload());
|
||||||
$('#unit_kerja_id, #jenis_pegawai, #periode').on('change', refreshSummary);
|
$('#unit_kerja_id, #jenis_pegawai, #jenjang_pendidikan, #periode').on('change', refreshSummary);
|
||||||
$('#grade12').on('change', function() {
|
$('#grade12').on('change', function() {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem('simulasi-jabatan:grade12', this.checked ? '1' : '0');
|
localStorage.setItem('simulasi-jabatan:grade12', this.checked ? '1' : '0');
|
||||||
@@ -445,7 +461,8 @@
|
|||||||
function loadCharts() {
|
function loadCharts() {
|
||||||
$.get('{{ route('lainnya.simulasi-jabatan.chart') }}', {
|
$.get('{{ route('lainnya.simulasi-jabatan.chart') }}', {
|
||||||
periode: $('#periode').val(),
|
periode: $('#periode').val(),
|
||||||
jenis_pegawai: $('#jenis_pegawai').val()
|
jenis_pegawai: $('#jenis_pegawai').val(),
|
||||||
|
jenjang_pendidikan: $('#jenjang_pendidikan').val()
|
||||||
}, function(res) {
|
}, function(res) {
|
||||||
var cats = res.map(function(r) { return r.unit_kerja_short; });
|
var cats = res.map(function(r) { return r.unit_kerja_short; });
|
||||||
shortToFull = {};
|
shortToFull = {};
|
||||||
@@ -466,7 +483,7 @@
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$('#periode, #jenis_pegawai').on('change', loadCharts);
|
$('#periode, #jenis_pegawai, #jenjang_pendidikan').on('change', loadCharts);
|
||||||
loadCharts();
|
loadCharts();
|
||||||
|
|
||||||
$('#warm-cache-btn').on('click', function() {
|
$('#warm-cache-btn').on('click', function() {
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
@extends('layouts.action')
|
|
||||||
|
|
||||||
@section('content')
|
|
||||||
<div class="card border shadow-sm">
|
|
||||||
<div class="card-body p-4 text-center">
|
|
||||||
<div class="avatar-lg mx-auto mb-3">
|
|
||||||
<span class="avatar-title rounded-circle bg-success text-white display-5">
|
|
||||||
<i class="uil-check"></i>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<h4 class="text-success mb-1">Berhasil Disetujui!</h4>
|
|
||||||
<p class="text-muted mb-4">Pengajuan absen telah berhasil disetujui.</p>
|
|
||||||
|
|
||||||
<div class="table-responsive text-start mb-4">
|
|
||||||
<table class="table table-sm table-bordered">
|
|
||||||
<tr>
|
|
||||||
<th width="140" class="bg-light">NIP</th>
|
|
||||||
<td>{{ $pengajuan->nip }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Nama</th>
|
|
||||||
<td>{{ $pengajuan->pegawai?->nama ?? '-' }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Tanggal</th>
|
|
||||||
<td>{{ \Carbon\Carbon::parse($pengajuan->tanggal_mulai)->translatedFormat('d F Y') }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Kategori</th>
|
|
||||||
<td>{{ $pengajuan->kategori }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Status</th>
|
|
||||||
<td><span class="badge bg-success rounded-pill fs-6 px-2 py-1">Diterima</span></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="text-muted small">Anda dapat menutup halaman ini.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endsection
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
@extends('layouts.action')
|
|
||||||
|
|
||||||
@section('content')
|
|
||||||
<div class="card border shadow-sm">
|
|
||||||
<div class="card-body p-4">
|
|
||||||
<div class="text-center mb-4">
|
|
||||||
<div class="avatar-lg mx-auto mb-3">
|
|
||||||
<span class="avatar-title rounded-circle bg-success-subtle text-success display-5">
|
|
||||||
<i class="uil-check-circle"></i>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<h4 class="mb-1">Setujui Pengajuan Absen</h4>
|
|
||||||
<p class="text-muted mb-0">Pastikan data di bawah sudah benar sebelum menyetujui.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="table-responsive mb-4">
|
|
||||||
<table class="table table-sm table-bordered">
|
|
||||||
<tr>
|
|
||||||
<th width="140" class="bg-light">NIP</th>
|
|
||||||
<td>{{ $pengajuan->nip }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Nama</th>
|
|
||||||
<td>{{ $pengajuan->pegawai?->nama ?? '-' }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Tanggal</th>
|
|
||||||
<td>{{ \Carbon\Carbon::parse($pengajuan->tanggal_mulai)->translatedFormat('d F Y') }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Kategori</th>
|
|
||||||
<td>{{ $pengajuan->kategori }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Keterangan</th>
|
|
||||||
<td>{{ $pengajuan->keterangan ?: '-' }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Bukti</th>
|
|
||||||
<td>
|
|
||||||
<a href="{{ $pengajuan->file }}" target="_blank" class="btn btn-sm btn-outline-primary">
|
|
||||||
<i class="uil-file-alt me-1"></i> Lihat PDF
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form action="{{ route('verifikasi-absen.setujui', $pengajuan->id) }}" method="POST">
|
|
||||||
@csrf
|
|
||||||
<div class="d-grid gap-2">
|
|
||||||
<button type="submit" class="btn btn-success btn-lg" id="btn-setujui">
|
|
||||||
<i class="uil-check me-1"></i> Setujui Pengajuan
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endsection
|
|
||||||
|
|
||||||
@section('js')
|
|
||||||
<script>
|
|
||||||
document.getElementById('btn-setujui').addEventListener('click', function(e) {
|
|
||||||
if (!confirm('Apakah Anda yakin ingin menyetujui pengajuan absen ini?')) {
|
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.disabled = true;
|
|
||||||
this.innerHTML = '<span class="spinner-border spinner-border-sm me-1"></span> Memproses...';
|
|
||||||
this.closest('form').submit();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@endsection
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
@extends('layouts.action')
|
|
||||||
|
|
||||||
@section('content')
|
|
||||||
<div class="card border shadow-sm">
|
|
||||||
<div class="card-body p-4 text-center">
|
|
||||||
<div class="avatar-lg mx-auto mb-3">
|
|
||||||
<span class="avatar-title rounded-circle bg-warning-subtle text-warning display-5">
|
|
||||||
<i class="uil-info-circle"></i>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<h4 class="mb-1">Pengajuan Sudah Diproses</h4>
|
|
||||||
<p class="text-muted mb-4">Pengajuan absen ini sudah diproses sebelumnya.</p>
|
|
||||||
|
|
||||||
<div class="table-responsive text-start mb-4">
|
|
||||||
<table class="table table-sm table-bordered">
|
|
||||||
<tr>
|
|
||||||
<th width="140" class="bg-light">NIP</th>
|
|
||||||
<td>{{ $pengajuan->nip }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Nama</th>
|
|
||||||
<td>{{ $pengajuan->pegawai?->nama ?? '-' }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Tanggal</th>
|
|
||||||
<td>{{ \Carbon\Carbon::parse($pengajuan->tanggal_mulai)->translatedFormat('d F Y') }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Kategori</th>
|
|
||||||
<td>{{ $pengajuan->kategori }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Status</th>
|
|
||||||
<td>
|
|
||||||
@if ($pengajuan->status === 'Diterima')
|
|
||||||
<span class="badge bg-success rounded-pill fs-6 px-2 py-1">Diterima</span>
|
|
||||||
@elseif ($pengajuan->status === 'Ditolak')
|
|
||||||
<span class="badge bg-danger rounded-pill fs-6 px-2 py-1">Ditolak</span>
|
|
||||||
@else
|
|
||||||
<span class="badge bg-secondary rounded-pill fs-6 px-2 py-1">{{ $pengajuan->status }}</span>
|
|
||||||
@endif
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="text-muted small">Anda dapat menutup halaman ini.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endsection
|
|
||||||
@@ -1,224 +0,0 @@
|
|||||||
@extends('layouts.action')
|
|
||||||
|
|
||||||
@section('content')
|
|
||||||
<!-- Tampilan PDF Bukti -->
|
|
||||||
<div class="card border shadow-sm mb-3">
|
|
||||||
<div class="card-header bg-light">
|
|
||||||
<h6 class="mb-0"><i class="uil-file-alt me-1"></i> Bukti Pengajuan</h6>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-0">
|
|
||||||
<iframe
|
|
||||||
src="{{ $pengajuan->file }}"
|
|
||||||
style="width: 100%; height: 420px; border: none; display: block;"
|
|
||||||
title="Bukti Pengajuan">
|
|
||||||
</iframe>
|
|
||||||
</div>
|
|
||||||
<div class="card-footer bg-light text-end py-2">
|
|
||||||
<a href="{{ $pengajuan->file }}" target="_blank" class="btn btn-sm btn-outline-primary">
|
|
||||||
<i class="uil-external-link-alt me-1"></i> Buka di Tab Baru
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Detail Pengajuan -->
|
|
||||||
<div class="card border shadow-sm mb-3">
|
|
||||||
<div class="card-header bg-light">
|
|
||||||
<h6 class="mb-0"><i class="uil-info-circle me-1"></i> Detail Pengajuan</h6>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-3">
|
|
||||||
<div class="table-responsive">
|
|
||||||
<table class="table table-sm table-bordered mb-0">
|
|
||||||
<tr>
|
|
||||||
<th width="140" class="bg-light">NIP</th>
|
|
||||||
<td>{{ $pengajuan->nip }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Nama</th>
|
|
||||||
<td>{{ $pengajuan->pegawai?->nama ?? '-' }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Tanggal</th>
|
|
||||||
<td>{{ \Carbon\Carbon::parse($pengajuan->tanggal_mulai)->translatedFormat('d F Y') }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Kategori</th>
|
|
||||||
<td>{{ $pengajuan->kategori }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-light">Keterangan</th>
|
|
||||||
<td>{{ $pengajuan->keterangan ?: '-' }}</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Form Penolakan -->
|
|
||||||
<div class="card border shadow-sm">
|
|
||||||
<div class="card-header bg-light">
|
|
||||||
<h6 class="mb-0 text-danger"><i class="uil-times-circle me-1"></i> Form Penolakan</h6>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-4">
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="catatan" class="form-label fw-semibold">
|
|
||||||
Alasan Penolakan <span class="text-danger">*</span>
|
|
||||||
</label>
|
|
||||||
<textarea
|
|
||||||
id="catatan"
|
|
||||||
class="form-control"
|
|
||||||
rows="4"
|
|
||||||
maxlength="500"
|
|
||||||
placeholder="Tuliskan alasan penolakan pengajuan absen ini..."
|
|
||||||
></textarea>
|
|
||||||
<div class="d-flex justify-content-between mt-1">
|
|
||||||
<div id="catatan-error" class="text-danger small" style="display: none !important;">
|
|
||||||
Alasan penolakan wajib diisi.
|
|
||||||
</div>
|
|
||||||
<small class="text-muted ms-auto"><span id="char-count">0</span>/500</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-flex gap-2">
|
|
||||||
<button type="button" class="btn btn-danger flex-fill" id="btn-tolak">
|
|
||||||
<i class="uil-times me-1"></i> Tolak
|
|
||||||
</button>
|
|
||||||
<button type="button" class="btn btn-secondary" id="btn-batal" onclick="window.close()">
|
|
||||||
Batal
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Modal Konfirmasi Tolak -->
|
|
||||||
<div class="modal fade" id="modal-konfirmasi" tabindex="-1" aria-hidden="true">
|
|
||||||
<div class="modal-dialog modal-dialog-centered">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title text-danger">
|
|
||||||
<i class="uil-exclamation-triangle me-1"></i> Konfirmasi Penolakan
|
|
||||||
</h5>
|
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<p class="mb-1">Apakah Anda yakin ingin <strong>menolak</strong> pengajuan absen ini?</p>
|
|
||||||
<p class="text-muted small mb-0">Alasan: <span id="preview-catatan" class="fst-italic"></span></p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tidak</button>
|
|
||||||
<button type="button" class="btn btn-danger" id="btn-konfirmasi-tolak">
|
|
||||||
<i class="uil-check me-1"></i> Ya, Tolak
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endsection
|
|
||||||
|
|
||||||
@section('js')
|
|
||||||
<script>
|
|
||||||
const pengajuanId = {{ $pengajuan->id }};
|
|
||||||
const catatanInput = document.getElementById('catatan');
|
|
||||||
const charCount = document.getElementById('char-count');
|
|
||||||
const catatanError = document.getElementById('catatan-error');
|
|
||||||
const modalKonfirmasi = new bootstrap.Modal(document.getElementById('modal-konfirmasi'));
|
|
||||||
|
|
||||||
catatanInput.addEventListener('input', function() {
|
|
||||||
charCount.textContent = this.value.length;
|
|
||||||
if (this.value.trim()) {
|
|
||||||
catatanError.style.setProperty('display', 'none', 'important');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('btn-tolak').addEventListener('click', function() {
|
|
||||||
const catatan = catatanInput.value.trim();
|
|
||||||
|
|
||||||
if (!catatan) {
|
|
||||||
catatanError.style.removeProperty('display');
|
|
||||||
catatanInput.focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('preview-catatan').textContent = catatan;
|
|
||||||
modalKonfirmasi.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('btn-konfirmasi-tolak').addEventListener('click', function() {
|
|
||||||
const catatan = catatanInput.value.trim();
|
|
||||||
const btn = this;
|
|
||||||
|
|
||||||
btn.disabled = true;
|
|
||||||
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-1"></span> Memproses...';
|
|
||||||
|
|
||||||
fetch('{{ route('verifikasi-absen.tolak', $pengajuan->id) }}', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
|
|
||||||
'Accept': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
catatan: catatan
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(data => {
|
|
||||||
modalKonfirmasi.hide();
|
|
||||||
|
|
||||||
if (data.success) {
|
|
||||||
btn.disabled = false;
|
|
||||||
btn.innerHTML = '<i class="uil-check me-1"></i> Ya, Tolak';
|
|
||||||
|
|
||||||
showSuccessAlert();
|
|
||||||
} else {
|
|
||||||
alert(data.message || 'Terjadi kesalahan. Silakan coba lagi.');
|
|
||||||
btn.disabled = false;
|
|
||||||
btn.innerHTML = '<i class="uil-check me-1"></i> Ya, Tolak';
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
modalKonfirmasi.hide();
|
|
||||||
alert('Terjadi kesalahan koneksi. Silakan coba lagi.');
|
|
||||||
btn.disabled = false;
|
|
||||||
btn.innerHTML = '<i class="uil-check me-1"></i> Ya, Tolak';
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function showSuccessAlert() {
|
|
||||||
const overlay = document.createElement('div');
|
|
||||||
overlay.style.cssText = `
|
|
||||||
position: fixed; inset: 0; background: rgba(0,0,0,0.5);
|
|
||||||
display: flex; align-items: center; justify-content: center;
|
|
||||||
z-index: 9999;
|
|
||||||
`;
|
|
||||||
overlay.innerHTML = `
|
|
||||||
<div style="background: #fff; border-radius: 12px; padding: 32px 40px; text-align: center; max-width: 360px; width: 90%;">
|
|
||||||
<div style="width: 64px; height: 64px; background: #dcfce7; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;">
|
|
||||||
<svg width="32" height="32" fill="none" viewBox="0 0 24 24">
|
|
||||||
<path stroke="#16a34a" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<h5 style="color: #16a34a; margin-bottom: 8px;">Berhasil Ditolak!</h5>
|
|
||||||
<p style="color: #6b7280; margin-bottom: 16px; font-size: 0.9rem;">Pengajuan absen telah berhasil ditolak.</p>
|
|
||||||
<p style="color: #9ca3af; font-size: 0.8rem;" id="countdown-text">Halaman akan ditutup dalam <strong id="countdown">3</strong> detik...</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
document.body.appendChild(overlay);
|
|
||||||
|
|
||||||
let seconds = 3;
|
|
||||||
const timer = setInterval(() => {
|
|
||||||
seconds--;
|
|
||||||
const el = document.getElementById('countdown');
|
|
||||||
if (el) { el.textContent = seconds; }
|
|
||||||
|
|
||||||
if (seconds <= 0) {
|
|
||||||
clearInterval(timer);
|
|
||||||
window.close();
|
|
||||||
// Fallback jika window.close() diblokir browser
|
|
||||||
setTimeout(() => {
|
|
||||||
overlay.querySelector('p[id="countdown-text"]').textContent = 'Silakan tutup tab ini secara manual.';
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@endsection
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="id">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>{{ $title }} | {{ config('app.name') }}</title>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
||||||
<link rel="shortcut icon" href="{{ asset('assets/images/logo-untan.png') }}">
|
|
||||||
<link href="{{ asset('assets/css/icons.min.css') }}" rel="stylesheet" type="text/css" />
|
|
||||||
<link href="{{ asset('assets/css/app.min.css') }}" rel="stylesheet" type="text/css" />
|
|
||||||
@yield('css')
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: "Inter", sans-serif;
|
|
||||||
background-color: #f4f6f9;
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-wrapper {
|
|
||||||
min-height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-header {
|
|
||||||
background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #1d4ed8 100%);
|
|
||||||
padding: 16px 24px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-header img {
|
|
||||||
height: 40px;
|
|
||||||
width: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-header .app-name {
|
|
||||||
color: #fff;
|
|
||||||
font-size: 1rem;
|
|
||||||
font-weight: 600;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-content {
|
|
||||||
flex: 1;
|
|
||||||
padding: 24px 16px;
|
|
||||||
max-width: 720px;
|
|
||||||
margin: 0 auto;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-footer {
|
|
||||||
text-align: center;
|
|
||||||
padding: 16px;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
color: #8a9ab0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="action-wrapper">
|
|
||||||
<div class="action-header">
|
|
||||||
<img src="{{ asset('assets/images/logo-untan.png') }}" alt="Logo">
|
|
||||||
<p class="app-name">{{ config('app.name') }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="action-content">
|
|
||||||
@if (session('error'))
|
|
||||||
<div class="alert alert-danger alert-dismissible fade show mb-3" role="alert">
|
|
||||||
{{ session('error') }}
|
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
@yield('content')
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="action-footer">
|
|
||||||
© {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="{{ asset('assets/js/vendor.min.js') }}"></script>
|
|
||||||
<script src="{{ asset('assets/js/app.min.js') }}"></script>
|
|
||||||
@yield('js')
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -369,37 +369,14 @@
|
|||||||
</li>
|
</li>
|
||||||
@endcanany
|
@endcanany
|
||||||
|
|
||||||
@canany(['Baca Presensi', 'Baca Presensi Honorer'])
|
@if (auth()->user()->hasRole('Superuser') || \App\Helpers\BawahanHelper::has())
|
||||||
<li class="side-nav-item si-pengajuan-presensi">
|
<li class="side-nav-item si-pengajuan-presensi">
|
||||||
<a data-bs-toggle="collapse" href="#sidebarPengajuanPresensi" aria-expanded="false"
|
<a href="{{ route('pengajuan-presensi.index') }}" class="side-nav-link ni-pengajuan-presensi">
|
||||||
aria-controls="sidebarPengajuanPresensi" class="side-nav-link ni-pengajuan-presensi">
|
|
||||||
<i class="uil-books"></i>
|
<i class="uil-books"></i>
|
||||||
<span> Pengajuan Presensi </span>
|
<span> Pengajuan Presensi </span>
|
||||||
<span class="menu-arrow"></span>
|
|
||||||
</a>
|
</a>
|
||||||
<div class="collapse li-pengajuan-presensi" id="sidebarPengajuanPresensi">
|
|
||||||
<ul class="side-nav-second-level">
|
|
||||||
@canany(['Baca Presensi Honorer', 'Verifikasi Presensi Honorer'])
|
|
||||||
<li class="li-pengajuan-presensi-honorer">
|
|
||||||
<a href="{{ route('pengajuan-presensi.honorer.index') }}">
|
|
||||||
<i class="uil-file-bookmark-alt" style="margin-right: 3px; font-size:18px"></i>
|
|
||||||
<span> Honorer </span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
@endcanany
|
|
||||||
|
|
||||||
@canany(['Baca Presensi', 'Verifikasi Presensi'])
|
|
||||||
<li class="li-pengajuan-presensi-tendik">
|
|
||||||
<a href="{{ route('pengajuan-presensi.tendik.index') }}">
|
|
||||||
<i class="uil-file-upload-alt" style="margin-right: 3px; font-size:18px"></i>
|
|
||||||
<span> Tendik </span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
@endcanany
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
@endcanany
|
@endif
|
||||||
|
|
||||||
{{-- @canany(['Baca Pengajuan Aktivitas'])
|
{{-- @canany(['Baca Pengajuan Aktivitas'])
|
||||||
<li class="side-nav-item si-pengajuan-aktivitas">
|
<li class="side-nav-item si-pengajuan-aktivitas">
|
||||||
@@ -618,7 +595,7 @@
|
|||||||
</li>
|
</li>
|
||||||
@endcan
|
@endcan
|
||||||
|
|
||||||
@canany(['Baca User', 'Baca Rubrik', 'Baca Team', 'Baca Team Anggota', 'Baca Periode', 'Baca Permission', 'Baca Rubrik Kategori', 'Baca Rubrik Syarat', 'Baca Limit Mengajar', 'Baca Limit Penunjang'])
|
@canany(['Baca User', 'Baca Pegawai', 'Baca Rubrik', 'Baca Team', 'Baca Team Anggota', 'Baca Periode', 'Baca Permission', 'Baca Rubrik Kategori', 'Baca Rubrik Syarat', 'Baca Limit Mengajar', 'Baca Limit Penunjang'])
|
||||||
<li class="side-nav-title side-nav-item">Manajemen</li>
|
<li class="side-nav-title side-nav-item">Manajemen</li>
|
||||||
@endcanany
|
@endcanany
|
||||||
|
|
||||||
@@ -631,6 +608,15 @@
|
|||||||
</li>
|
</li>
|
||||||
@endcan
|
@endcan
|
||||||
|
|
||||||
|
@can('Baca Pegawai')
|
||||||
|
<li class="side-nav-item si-pegawai">
|
||||||
|
<a href="{{ route('manajemen.pegawai.index') }}" class="side-nav-link ni-pegawai">
|
||||||
|
<i class="uil-user-square"></i>
|
||||||
|
<span> Pegawai </span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
@endcan
|
||||||
|
|
||||||
@canany(['Baca Team', 'Baca Team Anggota'])
|
@canany(['Baca Team', 'Baca Team Anggota'])
|
||||||
<li class="side-nav-item si-team">
|
<li class="side-nav-item si-team">
|
||||||
<a href="{{ route('manajemen.team.index') }}" class="side-nav-link ni-team">
|
<a href="{{ route('manajemen.team.index') }}" class="side-nav-link ni-team">
|
||||||
|
|||||||
@@ -0,0 +1,425 @@
|
|||||||
|
@extends('layouts.main')
|
||||||
|
|
||||||
|
@section('css')
|
||||||
|
<style>
|
||||||
|
#pegawaiTable thead th {
|
||||||
|
background: linear-gradient(135deg, #2080f5 0%, #0166d2 100%) !important;
|
||||||
|
color: #fff !important;
|
||||||
|
border-color: #0166d2 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiTable tbody tr {
|
||||||
|
transition: background-color 0.15s ease-in-out;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiTable tbody tr:hover > * {
|
||||||
|
background-color: rgba(13, 110, 253, 0.08) !important;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiTable tbody td.nama-col .text-truncate {
|
||||||
|
max-width: 260px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiTable tbody td.nama-col > div {
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiTable tbody td {
|
||||||
|
padding-top: 0.5rem;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiTable tbody td .clamp-2 {
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiDetailModal .table-bordered {
|
||||||
|
border-color: #adb5bd;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiDetailModal .table-bordered th,
|
||||||
|
#pegawaiDetailModal .table-bordered td {
|
||||||
|
border-color: #adb5bd;
|
||||||
|
padding: 0.4rem 0.6rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiDetailModal .table-bordered th {
|
||||||
|
background-color: #eaf2fe;
|
||||||
|
color: #0166d2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiDetailModal h6 {
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pegawaiDetailModal .table-sm {
|
||||||
|
margin-bottom: 0.85rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('breadcrumb')
|
||||||
|
<ol class="breadcrumb m-0">
|
||||||
|
<li class="breadcrumb-item"><a href="javascript:void(0);">Manajemen</a></li>
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">{{ $title }}</li>
|
||||||
|
</ol>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card border">
|
||||||
|
<div class="card-body">
|
||||||
|
@include('components.datatable-header', [
|
||||||
|
'title' => 'Daftar Pegawai',
|
||||||
|
'description' => 'Berikut adalah daftar pegawai yang bersumber dari SIDIA',
|
||||||
|
'actionButton' => ''
|
||||||
|
])
|
||||||
|
|
||||||
|
<div class="row g-2 mb-3">
|
||||||
|
<div class="col-6 col-md-3">
|
||||||
|
<label for="unit_kerja" class="form-label">Unit Kerja</label>
|
||||||
|
<select name="unit_kerja" id="unit_kerja" class="form-select select2"
|
||||||
|
data-placeholder="Pilih Unit Kerja">
|
||||||
|
<option value=""></option>
|
||||||
|
@foreach ($unitKerjaOptions as $unitKerja)
|
||||||
|
<option value="{{ $unitKerja }}">{{ $unitKerja }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-6 col-md-3">
|
||||||
|
<label for="jenis_pegawai" class="form-label">Jenis Pegawai</label>
|
||||||
|
<select name="jenis_pegawai" id="jenis_pegawai" class="form-select select2"
|
||||||
|
data-placeholder="Pilih Jenis Pegawai">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="dosen">Dosen</option>
|
||||||
|
<option value="tendik">Tendik</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-6 col-md-3">
|
||||||
|
<label for="status_pegawai" class="form-label">Status Pegawai</label>
|
||||||
|
<select name="status_pegawai" id="status_pegawai" class="form-select select2"
|
||||||
|
data-placeholder="Pilih Status Pegawai">
|
||||||
|
<option value=""></option>
|
||||||
|
@foreach ($statusPegawaiOptions as $statusPegawai)
|
||||||
|
<option value="{{ $statusPegawai }}">{{ $statusPegawai }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-6 col-md-3">
|
||||||
|
<label for="status" class="form-label">Status Aktif</label>
|
||||||
|
<select name="status" id="status" class="form-select select2"
|
||||||
|
data-placeholder="Pilih Status Aktif">
|
||||||
|
<option value=""></option>
|
||||||
|
@foreach ($statusOptions as $status)
|
||||||
|
<option value="{{ $status }}">{{ ucfirst($status) }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered w-100" id="pegawaiTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Pegawai</th>
|
||||||
|
<th>Unit Kerja</th>
|
||||||
|
<th>Jabatan Fungsional</th>
|
||||||
|
<th>Jabatan Tugas Tambahan</th>
|
||||||
|
<th>Jabatan Kontrak</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Detail Modal -->
|
||||||
|
<div class="modal fade" id="pegawaiDetailModal" tabindex="-1" role="dialog" aria-labelledby="pegawaiDetailModalLabel" aria-hidden="true" data-bs-backdrop="static">
|
||||||
|
<div class="modal-dialog modal-xl modal-dialog-scrollable" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header bg-primary text-white">
|
||||||
|
<h5 class="modal-title" id="pegawaiDetailModalLabel">Detail Pegawai</h5>
|
||||||
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div id="pegawaiDetailLoading" class="text-center py-4">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="pegawaiDetailContent" style="display:none;">
|
||||||
|
<div class="d-flex align-items-center gap-3 mb-2 pb-2 border-bottom">
|
||||||
|
<img id="d-foto" src="" alt="Foto" class="rounded-circle border" style="width:72px;height:72px;object-fit:cover;">
|
||||||
|
<div>
|
||||||
|
<h5 class="mb-1" id="d-nama">-</h5>
|
||||||
|
<div class="text-muted small font-monospace" id="d-nip-header">-</div>
|
||||||
|
<div class="mt-1" id="d-jenis-badge"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h6 class="fw-bold mb-2">Identitas</h6>
|
||||||
|
<table class="table table-sm table-bordered mb-3">
|
||||||
|
<tbody>
|
||||||
|
<tr><th width="40%">NIP</th><td id="d-nip">-</td></tr>
|
||||||
|
<tr><th>NIP Siakad</th><td id="d-nip-siakad">-</td></tr>
|
||||||
|
<tr><th>NIP Honorer</th><td id="d-nip-honorer">-</td></tr>
|
||||||
|
<tr><th>NIDN</th><td id="d-nidn">-</td></tr>
|
||||||
|
<tr><th>Email</th><td id="d-email">-</td></tr>
|
||||||
|
<tr><th>No HP</th><td id="d-no-hp">-</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h6 class="fw-bold mb-2">Kepegawaian</h6>
|
||||||
|
<table class="table table-sm table-bordered mb-3">
|
||||||
|
<tbody>
|
||||||
|
<tr><th width="40%">Jenis Pegawai</th><td id="d-jenis-pegawai">-</td></tr>
|
||||||
|
<tr><th>Status Pegawai</th><td id="d-status-pegawai">-</td></tr>
|
||||||
|
<tr><th>Status</th><td id="d-status">-</td></tr>
|
||||||
|
<tr><th>TMT Status</th><td id="d-tmt-status">-</td></tr>
|
||||||
|
<tr><th>TST Status</th><td id="d-tst-status">-</td></tr>
|
||||||
|
<tr><th>Golongan</th><td id="d-golongan">-</td></tr>
|
||||||
|
<tr><th>Pangkat</th><td id="d-pangkat">-</td></tr>
|
||||||
|
<tr><th>Pendidikan Terakhir</th><td id="d-pendidikan">-</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h6 class="fw-bold mb-2">Data Keuangan</h6>
|
||||||
|
<table class="table table-sm table-bordered mb-0">
|
||||||
|
<tbody>
|
||||||
|
<tr><th width="40%">NPWP</th><td id="d-npwp">-</td></tr>
|
||||||
|
<tr><th>No Rekening</th><td id="d-no-rekening">-</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h6 class="fw-bold mb-2">Unit Kerja & Prodi</h6>
|
||||||
|
<table class="table table-sm table-bordered mb-3">
|
||||||
|
<tbody>
|
||||||
|
<tr><th width="40%">Unit Kerja</th><td id="d-unit-kerja">-</td></tr>
|
||||||
|
<tr><th>Prodi</th><td id="d-prodi">-</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h6 class="fw-bold mb-2">Jabatan Fungsional</h6>
|
||||||
|
<table class="table table-sm table-bordered mb-3">
|
||||||
|
<tbody>
|
||||||
|
<tr><th width="40%">Nama Jabatan</th><td id="d-jafung-nama">-</td></tr>
|
||||||
|
<tr><th>Grade</th><td id="d-jafung-grade">-</td></tr>
|
||||||
|
<tr><th>SK</th><td id="d-jafung-sk">-</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h6 class="fw-bold mb-2">Jabatan Tugas Tambahan</h6>
|
||||||
|
<table class="table table-sm table-bordered mb-3">
|
||||||
|
<tbody>
|
||||||
|
<tr><th width="40%">Nama Jabatan</th><td id="d-jtt-nama">-</td></tr>
|
||||||
|
<tr><th>Grade</th><td id="d-jtt-grade">-</td></tr>
|
||||||
|
<tr><th>TMT</th><td id="d-jtt-tmt">-</td></tr>
|
||||||
|
<tr><th>TST</th><td id="d-jtt-tst">-</td></tr>
|
||||||
|
<tr><th>SK</th><td id="d-jtt-sk">-</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h6 class="fw-bold mb-2">Jabatan Kontrak</h6>
|
||||||
|
<table class="table table-sm table-bordered mb-0">
|
||||||
|
<tbody>
|
||||||
|
<tr><th width="40%">Nama Jabatan</th><td id="d-jk-nama">-</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="pegawaiDetailError" class="text-center text-danger py-4" style="display:none;">
|
||||||
|
Gagal memuat detail pegawai
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('js')
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
function renderJenisPegawaiTag(jenis) {
|
||||||
|
var config = {
|
||||||
|
'dosen': { color: 'var(--ct-primary)', rgb: 'var(--ct-primary-rgb)', icon: 'uil-user-graduate' },
|
||||||
|
'tendik': { color: '#fd7e14', rgb: '253, 126, 20', icon: 'uil-briefcase-alt' }
|
||||||
|
};
|
||||||
|
var normalizedJenis = (jenis || '').toString().toLowerCase();
|
||||||
|
var c = config[normalizedJenis];
|
||||||
|
if (!c) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return '<small class="d-inline-block fw-bold" style="padding: 1px 18px 1px 6px; color: ' +
|
||||||
|
c.color + '; background: linear-gradient(to right, rgba(' + c.rgb + ', 0.25), rgba(' + c.rgb +
|
||||||
|
', 0)); clip-path: polygon(0 0, 100% 0, calc(100% - 20px) 100%, 0 100%);"><i class="' + c.icon +
|
||||||
|
'"></i> ' + normalizedJenis.toUpperCase() + '</small>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderClampedText(data) {
|
||||||
|
var text = data || '-';
|
||||||
|
return '<span class="clamp-2" title="' + text.replace(/"/g, '"') + '">' + text + '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
let table = $('#pegawaiTable').DataTable({
|
||||||
|
processing: true,
|
||||||
|
serverSide: true,
|
||||||
|
ajax: {
|
||||||
|
url: "{{ route('manajemen.pegawai.data') }}",
|
||||||
|
data: function(d) {
|
||||||
|
d.unit_kerja = $('#unit_kerja').val();
|
||||||
|
d.jenis_pegawai = $('#jenis_pegawai').val();
|
||||||
|
d.status_pegawai = $('#status_pegawai').val();
|
||||||
|
d.status = $('#status').val();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
data: 'nama', name: 'nama', className: 'nama-col', width: '25%',
|
||||||
|
render: function(data, type, row) {
|
||||||
|
if (type !== 'display') { return data; }
|
||||||
|
var nama = data || '-';
|
||||||
|
var nip = row.nip || '-';
|
||||||
|
return '<div>' +
|
||||||
|
'<div class="fw-semibold text-truncate" title="' + nama + '">' + nama + '</div>' +
|
||||||
|
'<div class="text-muted small font-monospace">' + nip + '</div>' +
|
||||||
|
'<div class="mt-1">' + renderJenisPegawaiTag(row.jenis_pegawai) + '</div>' +
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'nama_unit_kerja', name: 'nama_unit_kerja',
|
||||||
|
render: function(data, type) {
|
||||||
|
if (type !== 'display') { return data; }
|
||||||
|
return renderClampedText(data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'nama_jabatan_fungsional', name: 'nama_jabatan_fungsional', width: '18%',
|
||||||
|
render: function(data, type) {
|
||||||
|
if (type !== 'display') { return data; }
|
||||||
|
return renderClampedText(data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'nama_jabatan_tugas_tambahan', name: 'nama_jabatan_tugas_tambahan', width: '18%',
|
||||||
|
render: function(data, type) {
|
||||||
|
if (type !== 'display') { return data; }
|
||||||
|
return renderClampedText(data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'nama_jabatan_kontrak', name: 'nama_jabatan_kontrak', width: '18%',
|
||||||
|
render: function(data, type) {
|
||||||
|
if (type !== 'display') { return data; }
|
||||||
|
return renderClampedText(data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
language: {
|
||||||
|
processing: "<div class='spinner'></div> Sedang Memuat...",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#unit_kerja, #jenis_pegawai, #status_pegawai, #status').on('change', function() {
|
||||||
|
table.ajax.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
function setText(id, value) {
|
||||||
|
$(id).text(value || '-');
|
||||||
|
}
|
||||||
|
|
||||||
|
function setLink(id, url, label) {
|
||||||
|
if (url) {
|
||||||
|
$(id).html('<a href="' + url + '" target="_blank" rel="noopener"><i class="uil-file-alt"></i> ' + (label || 'Lihat Dokumen') + '</a>');
|
||||||
|
} else {
|
||||||
|
$(id).text('-');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#pegawaiTable tbody').on('click', 'tr', function() {
|
||||||
|
let row = table.row(this).data();
|
||||||
|
if (!row) { return; }
|
||||||
|
let id = row.id;
|
||||||
|
|
||||||
|
$('#pegawaiDetailContent').hide();
|
||||||
|
$('#pegawaiDetailError').hide();
|
||||||
|
$('#pegawaiDetailLoading').show();
|
||||||
|
let modal = new bootstrap.Modal(document.getElementById('pegawaiDetailModal'));
|
||||||
|
modal.show();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "{{ route('manajemen.pegawai.show', ':id') }}".replace(':id', id),
|
||||||
|
type: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
$('#d-foto').attr('src', data.foto);
|
||||||
|
setText('#d-nama', data.nama);
|
||||||
|
setText('#d-nip-header', data.nip);
|
||||||
|
$('#d-jenis-badge').html(renderJenisPegawaiTag(data.jenis_pegawai));
|
||||||
|
|
||||||
|
setText('#d-nip', data.nip);
|
||||||
|
setText('#d-nip-siakad', data.nip_siakad);
|
||||||
|
setText('#d-nip-honorer', data.nip_honorer);
|
||||||
|
setText('#d-nidn', data.nidn);
|
||||||
|
setText('#d-email', data.email);
|
||||||
|
setText('#d-no-hp', data.no_hp);
|
||||||
|
|
||||||
|
setText('#d-jenis-pegawai', data.jenis_pegawai);
|
||||||
|
setText('#d-status-pegawai', data.status_pegawai);
|
||||||
|
setText('#d-status', data.status);
|
||||||
|
setText('#d-tmt-status', data.tmt_status);
|
||||||
|
setText('#d-tst-status', data.tst_status);
|
||||||
|
setText('#d-golongan', data.golongan);
|
||||||
|
setText('#d-pangkat', data.pangkat);
|
||||||
|
setText('#d-pendidikan', data.pendidikan_terakhir);
|
||||||
|
|
||||||
|
setText('#d-npwp', data.npwp);
|
||||||
|
setText('#d-no-rekening', data.no_rekening);
|
||||||
|
|
||||||
|
setText('#d-unit-kerja', data.nama_unit_kerja);
|
||||||
|
setText('#d-prodi', data.nama_prodi);
|
||||||
|
|
||||||
|
setText('#d-jafung-nama', data.nama_jabatan_fungsional);
|
||||||
|
setText('#d-jafung-grade', data.grade_jabatan_fungsional);
|
||||||
|
setLink('#d-jafung-sk', data.sk_jabatan_fungsional, 'Lihat SK');
|
||||||
|
|
||||||
|
setText('#d-jtt-nama', data.nama_jabatan_tugas_tambahan);
|
||||||
|
setText('#d-jtt-grade', data.grade_jabatan_tugas_tambahan);
|
||||||
|
setText('#d-jtt-tmt', data.tmt_jabatan_tugas_tambahan);
|
||||||
|
setText('#d-jtt-tst', data.tst_jabatan_tugas_tambahan);
|
||||||
|
setLink('#d-jtt-sk', data.sk_jabatan_tugas_tambahan, 'Lihat SK');
|
||||||
|
|
||||||
|
setText('#d-jk-nama', data.nama_jabatan_kontrak);
|
||||||
|
|
||||||
|
$('#pegawaiDetailLoading').hide();
|
||||||
|
$('#pegawaiDetailContent').show();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
$('#pegawaiDetailLoading').hide();
|
||||||
|
$('#pegawaiDetailError').show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endsection
|
||||||
@@ -148,6 +148,7 @@
|
|||||||
'actionButton' => '
|
'actionButton' => '
|
||||||
<a href="#" class="btn btn-sm btn-outline-success export"><i class="uil-file-download-alt"></i> Export Excel</a>
|
<a href="#" class="btn btn-sm btn-outline-success export"><i class="uil-file-download-alt"></i> Export Excel</a>
|
||||||
<a href="#" class="btn btn-sm btn-outline-success export-selisih"><i class="uil-file-download-alt"></i> Export Excel</a>
|
<a href="#" class="btn btn-sm btn-outline-success export-selisih"><i class="uil-file-download-alt"></i> Export Excel</a>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-success export-perbandingan"><i class="uil-file-download-alt"></i> Export Excel</a>
|
||||||
'
|
'
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -240,6 +241,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Pegawai</th>
|
<th>Pegawai</th>
|
||||||
<th>Unit Kerja</th>
|
<th>Unit Kerja</th>
|
||||||
|
<th class="d-none">NIP</th>
|
||||||
<th>Jabatan Fungsional</th>
|
<th>Jabatan Fungsional</th>
|
||||||
<th>Jabatan Tugas Tambahan</th>
|
<th>Jabatan Tugas Tambahan</th>
|
||||||
<th class="text-center">Bruto</th>
|
<th class="text-center">Bruto</th>
|
||||||
@@ -267,6 +269,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Pegawai</th>
|
<th>Pegawai</th>
|
||||||
<th>Unit Kerja</th>
|
<th>Unit Kerja</th>
|
||||||
|
<th class="d-none">NIP</th>
|
||||||
<th>Keterangan</th>
|
<th>Keterangan</th>
|
||||||
<th class="text-center">Selisih Bruto</th>
|
<th class="text-center">Selisih Bruto</th>
|
||||||
<th class="text-center">Selisih Pajak</th>
|
<th class="text-center">Selisih Pajak</th>
|
||||||
@@ -293,6 +296,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Pegawai</th>
|
<th>Pegawai</th>
|
||||||
<th>Unit Kerja</th>
|
<th>Unit Kerja</th>
|
||||||
|
<th class="d-none">NIP</th>
|
||||||
<th class="text-center">Selisih Bruto</th>
|
<th class="text-center">Selisih Bruto</th>
|
||||||
<th class="text-center">Selisih Pajak</th>
|
<th class="text-center">Selisih Pajak</th>
|
||||||
<th class="text-center">Selisih Netto</th>
|
<th class="text-center">Selisih Netto</th>
|
||||||
@@ -417,8 +421,9 @@
|
|||||||
var table, tableSelisih, tablePerbandingan;
|
var table, tableSelisih, tablePerbandingan;
|
||||||
var hideUnitKerja = {{ ($team && isset($team->unit_kerja_id) && $team->unit_kerja_id >= 1 && $team->unit_kerja_id <= 9) ? 'true' : 'false' }};
|
var hideUnitKerja = {{ ($team && isset($team->unit_kerja_id) && $team->unit_kerja_id >= 1 && $team->unit_kerja_id <= 9) ? 'true' : 'false' }};
|
||||||
|
|
||||||
// Tab Main aktif secara default, jadi sembunyikan tombol export Selisih di awal
|
// Tab Main aktif secara default, jadi sembunyikan tombol export Selisih & Perbandingan di awal
|
||||||
$('a.export-selisih').hide();
|
$('a.export-selisih').hide();
|
||||||
|
$('a.export-perbandingan').hide();
|
||||||
|
|
||||||
function renderRupiah(data, differs) {
|
function renderRupiah(data, differs) {
|
||||||
var diffClass = differs ? ' nominal-diff' : '';
|
var diffClass = differs ? ' nominal-diff' : '';
|
||||||
@@ -475,6 +480,7 @@
|
|||||||
var isMain = tabId === 'main-tab';
|
var isMain = tabId === 'main-tab';
|
||||||
$('a.export').toggle(isMain);
|
$('a.export').toggle(isMain);
|
||||||
$('a.export-selisih').toggle(tabId === 'selisih-tab');
|
$('a.export-selisih').toggle(tabId === 'selisih-tab');
|
||||||
|
$('a.export-perbandingan').toggle(tabId === 'perbandingan-tab');
|
||||||
if (isMain && table) { table.columns.adjust().draw(); }
|
if (isMain && table) { table.columns.adjust().draw(); }
|
||||||
if (tabId === 'selisih-tab' && tableSelisih) { tableSelisih.columns.adjust().draw(); }
|
if (tabId === 'selisih-tab' && tableSelisih) { tableSelisih.columns.adjust().draw(); }
|
||||||
if (tabId === 'perbandingan-tab' && tablePerbandingan) { tablePerbandingan.columns.adjust().draw(); }
|
if (tabId === 'perbandingan-tab' && tablePerbandingan) { tablePerbandingan.columns.adjust().draw(); }
|
||||||
@@ -516,6 +522,7 @@
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{ data: 'nip', name: 'nip', orderable: false, visible: false },
|
||||||
{ data: 'nama_jafung', name: 'nama_jafung', orderable: false, searchable: false, visible: false },
|
{ data: 'nama_jafung', name: 'nama_jafung', orderable: false, searchable: false, visible: false },
|
||||||
{ data: 'nama_jtt', name: 'nama_jtt', orderable: false, searchable: false, visible: false },
|
{ data: 'nama_jtt', name: 'nama_jtt', orderable: false, searchable: false, visible: false },
|
||||||
{
|
{
|
||||||
@@ -664,6 +671,7 @@
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{ data: 'nip', name: 'nip', orderable: false, visible: false },
|
||||||
{
|
{
|
||||||
data: 'jenis_selisih', name: 'jenis_selisih', orderable: false, searchable: false, width: '18%',
|
data: 'jenis_selisih', name: 'jenis_selisih', orderable: false, searchable: false, width: '18%',
|
||||||
render: function(data, type, row) {
|
render: function(data, type, row) {
|
||||||
@@ -724,6 +732,7 @@
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{ data: 'nip', name: 'nip', orderable: false, visible: false },
|
||||||
{ data: 'selisih_bruto', name: 'selisih_bruto', orderable: false, searchable: false, width: '14%', render: function(data) { return renderRupiah(data); } },
|
{ data: 'selisih_bruto', name: 'selisih_bruto', orderable: false, searchable: false, width: '14%', render: function(data) { return renderRupiah(data); } },
|
||||||
{ data: 'selisih_pajak', name: 'selisih_pajak', orderable: false, searchable: false, width: '14%', render: function(data) { return renderRupiah(data); } },
|
{ data: 'selisih_pajak', name: 'selisih_pajak', orderable: false, searchable: false, width: '14%', render: function(data) { return renderRupiah(data); } },
|
||||||
{ data: 'selisih_netto', name: 'selisih_netto', orderable: false, searchable: false, width: '14%', render: function(data) { return renderRupiah(data); } }
|
{ data: 'selisih_netto', name: 'selisih_netto', orderable: false, searchable: false, width: '14%', render: function(data) { return renderRupiah(data); } }
|
||||||
@@ -964,6 +973,69 @@
|
|||||||
showError('Gagal', 'Terjadi kesalahan saat export Excel');
|
showError('Gagal', 'Terjadi kesalahan saat export Excel');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('a.export-perbandingan').on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var button = $(this);
|
||||||
|
var originalHtml = button.html();
|
||||||
|
var tahun = $('select#tahun').val();
|
||||||
|
var bulan = $('select#bulan').val();
|
||||||
|
var jenisPegawai = $('select#jenis_pegawai').val();
|
||||||
|
var arah = $('#arah_perbandingan').val();
|
||||||
|
@if (!$team || !isset($team->unit_kerja_id) || $team->unit_kerja_id === null || $team->unit_kerja_id === 0)
|
||||||
|
var unitKerja = $('select#unit_kerja').val();
|
||||||
|
@else
|
||||||
|
var unitKerja = '{{ $team->unit_kerja_id ?? "" }}';
|
||||||
|
@endif
|
||||||
|
|
||||||
|
if (!tahun) { showWarning('Perhatian', 'Silakan pilih tahun terlebih dahulu.'); return; }
|
||||||
|
|
||||||
|
button.addClass('disabled').html('<span class="spinner-border spinner-border-sm me-1"></span> Exporting...');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "{{ route('remunerasi.p1.logs') }}",
|
||||||
|
method: 'POST',
|
||||||
|
data: { _token: '{{ csrf_token() }}', nip: $('#userId').val(), nama: $('#username').val(), tahun: tahun, bulan: bulan, jenis_pegawai: jenisPegawai, unit_kerja: unitKerja, status: 'success', message: 'Export Excel Perbandingan berhasil' },
|
||||||
|
});
|
||||||
|
|
||||||
|
var exportUrl = "{{ route('remunerasi.p1.export-perbandingan') }}"
|
||||||
|
+ '?tahun=' + encodeURIComponent(tahun)
|
||||||
|
+ '&bulan=' + encodeURIComponent(bulan)
|
||||||
|
+ '&jenis_pegawai=' + encodeURIComponent(jenisPegawai)
|
||||||
|
+ '&unit_kerja=' + encodeURIComponent(unitKerja)
|
||||||
|
+ '&arah=' + encodeURIComponent(arah);
|
||||||
|
|
||||||
|
fetch(exportUrl)
|
||||||
|
.then(function(response) {
|
||||||
|
if (!response.ok) { throw new Error('gagal'); }
|
||||||
|
var filename = 'p1_perbandingan_export.xlsx';
|
||||||
|
var disposition = response.headers.get('Content-Disposition');
|
||||||
|
if (disposition) {
|
||||||
|
var match = disposition.match(/filename[^;=\n]*=['"]?([^'"\n]+)['"]?/);
|
||||||
|
if (match) { filename = match[1]; }
|
||||||
|
}
|
||||||
|
return response.blob().then(function(blob) {
|
||||||
|
return { blob: blob, filename: filename };
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(function(data) {
|
||||||
|
var url = URL.createObjectURL(data.blob);
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = data.filename;
|
||||||
|
a.style.display = 'none';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
button.removeClass('disabled').html(originalHtml);
|
||||||
|
showSuccess('Berhasil!', 'File Excel berhasil didownload');
|
||||||
|
})
|
||||||
|
.catch(function() {
|
||||||
|
button.removeClass('disabled').html(originalHtml);
|
||||||
|
showError('Gagal', 'Terjadi kesalahan saat export Excel');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@@ -87,6 +87,13 @@
|
|||||||
</option>
|
</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select name="jenjang_pendidikan" id="jenjang_pendidikan" class="form-select select2" data-placeholder="Pilih Jenjang Pendidikan">
|
||||||
|
<option value=""></option>
|
||||||
|
@foreach ($jenjangPendidikanList as $jp)
|
||||||
|
<option value="{{ $jp }}">{{ $jp === \App\Helpers\JenjangPendidikanHelper::KOSONG ? \App\Helpers\JenjangPendidikanHelper::KOSONG_LABEL : $jp }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
@@ -148,6 +155,7 @@
|
|||||||
d.unit_kerja_id = $('select#unit_kerja_id').val();
|
d.unit_kerja_id = $('select#unit_kerja_id').val();
|
||||||
@endif
|
@endif
|
||||||
d.jenis_pegawai = $('select#jenis_pegawai').val();
|
d.jenis_pegawai = $('select#jenis_pegawai').val();
|
||||||
|
d.jenjang_pendidikan = $('select#jenjang_pendidikan').val();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
columns: [
|
columns: [
|
||||||
@@ -204,7 +212,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('select#periode, select#unit_kerja_id, select#jenis_pegawai').on('change', function() {
|
$('select#periode, select#unit_kerja_id, select#jenis_pegawai, select#jenjang_pendidikan').on('change', function() {
|
||||||
table.ajax.reload();
|
table.ajax.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -238,6 +246,7 @@
|
|||||||
var exportUrl = "{{ route('remunerasi.p2.export') }}"
|
var exportUrl = "{{ route('remunerasi.p2.export') }}"
|
||||||
+ '?periode=' + encodeURIComponent(periode)
|
+ '?periode=' + encodeURIComponent(periode)
|
||||||
+ '&jenis_pegawai=' + encodeURIComponent($('select#jenis_pegawai').val())
|
+ '&jenis_pegawai=' + encodeURIComponent($('select#jenis_pegawai').val())
|
||||||
|
+ '&jenjang_pendidikan=' + encodeURIComponent($('select#jenjang_pendidikan').val())
|
||||||
@if (!$team || !isset($team->unit_kerja_id) || $team->unit_kerja_id === null || $team->unit_kerja_id === 0)
|
@if (!$team || !isset($team->unit_kerja_id) || $team->unit_kerja_id === null || $team->unit_kerja_id === 0)
|
||||||
+ '&unit_kerja_id=' + encodeURIComponent($('select#unit_kerja_id').val())
|
+ '&unit_kerja_id=' + encodeURIComponent($('select#unit_kerja_id').val())
|
||||||
@else
|
@else
|
||||||
|
|||||||
@@ -62,8 +62,8 @@
|
|||||||
@section('breadcrumb')
|
@section('breadcrumb')
|
||||||
<ol class="breadcrumb m-0">
|
<ol class="breadcrumb m-0">
|
||||||
<li class="breadcrumb-item"><a href="javascript:void(0);">Verifikasi</a></li>
|
<li class="breadcrumb-item"><a href="javascript:void(0);">Verifikasi</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{{ route('pengajuan-presensi.honorer.index') }}">Pengajuan Presensi</a></li>
|
<li class="breadcrumb-item"><a href="{{ route('pengajuan-presensi.index') }}">Pengajuan Presensi</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{{ route('pengajuan-presensi.honorer.index') }}">Honorer</a></li>
|
<li class="breadcrumb-item">Non ASN</li>
|
||||||
<li class="breadcrumb-item active" aria-current="page">{{ $pegawai->nama }}</li>
|
<li class="breadcrumb-item active" aria-current="page">{{ $pegawai->nama }}</li>
|
||||||
</ol>
|
</ol>
|
||||||
@endsection
|
@endsection
|
||||||
@@ -360,8 +360,6 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Aktifkan menu sidebar
|
// Aktifkan menu sidebar
|
||||||
$('.si-pengajuan-presensi').addClass('menuitem-active');
|
$('.si-pengajuan-presensi').addClass('menuitem-active');
|
||||||
$('.li-pengajuan-presensi').addClass('show');
|
|
||||||
$('.li-pengajuan-presensi-honorer').addClass('active badge-primary-lighten');
|
|
||||||
|
|
||||||
@if (isset($bulan) && $bulan)
|
@if (isset($bulan) && $bulan)
|
||||||
// Set label bulan
|
// Set label bulan
|
||||||
@@ -391,6 +389,12 @@
|
|||||||
@if (isset($bulan) && $bulan)
|
@if (isset($bulan) && $bulan)
|
||||||
d.bulan = "{{ $bulan }}";
|
d.bulan = "{{ $bulan }}";
|
||||||
@endif
|
@endif
|
||||||
|
@if (isset($tahun) && $tahun)
|
||||||
|
d.tahun = "{{ $tahun }}";
|
||||||
|
@endif
|
||||||
|
@if (isset($periodeFilter) && $periodeFilter)
|
||||||
|
d.periode = "{{ $periodeFilter }}";
|
||||||
|
@endif
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
columns: [{
|
columns: [{
|
||||||
|
|||||||
@@ -0,0 +1,524 @@
|
|||||||
|
@extends('layouts.main')
|
||||||
|
|
||||||
|
@section('css')
|
||||||
|
<style>
|
||||||
|
#table-belum-selesai td, #table-belum-selesai th,
|
||||||
|
#table-selesai td, #table-selesai th {
|
||||||
|
border-color: #ced4da !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-belum-selesai thead th,
|
||||||
|
#table-selesai thead th {
|
||||||
|
background: linear-gradient(135deg, #2080f5 0%, #0166d2 100%) !important;
|
||||||
|
color: #fff !important;
|
||||||
|
border-color: #0166d2 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-belum-selesai tbody tr,
|
||||||
|
#table-selesai tbody tr {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-belum-selesai tbody tr:hover > *,
|
||||||
|
#table-selesai tbody tr:hover > * {
|
||||||
|
background-color: rgba(13, 110, 253, 0.08) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-belum-selesai thead th,
|
||||||
|
#table-selesai thead th {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-belum-selesai td.unit-col,
|
||||||
|
#table-selesai td.unit-col {
|
||||||
|
max-width: 200px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-belum-selesai tbody td.nama-col > div,
|
||||||
|
#table-selesai tbody td.nama-col > div {
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-belum-selesai tbody td.nama-col .text-truncate,
|
||||||
|
#table-selesai tbody td.nama-col .text-truncate {
|
||||||
|
max-width: 240px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-belum-selesai tbody td,
|
||||||
|
#table-selesai tbody td {
|
||||||
|
padding-top: 0.5rem;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('breadcrumb')
|
||||||
|
<ol class="breadcrumb m-0">
|
||||||
|
<li class="breadcrumb-item"><a href="javascript:void(0);">Verifikasi</a></li>
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">Pengajuan Presensi</li>
|
||||||
|
</ol>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<!-- Alert Batas Verifikasi -->
|
||||||
|
@if (!$validasiWaktu['status'])
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="alert alert-warning alert-dismissible fade show" role="alert">
|
||||||
|
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||||
|
<strong>Perhatian!</strong> {{ $validasiWaktu['message'] }}
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card border">
|
||||||
|
<div class="card-body">
|
||||||
|
@include('components.datatable-header', [
|
||||||
|
'title' => 'Daftar Pengajuan Presensi',
|
||||||
|
'description' =>
|
||||||
|
'Berikut adalah daftar pengajuan presensi pegawai yang perlu diverifikasi',
|
||||||
|
])
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
@if ($canHonorer && $canTendik)
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label for="filter_jenis" class="form-label">Status Pegawai</label>
|
||||||
|
<select class="form-select select2" id="filter_jenis" name="filter_jenis"
|
||||||
|
data-placeholder="Pilih Status Pegawai">
|
||||||
|
<option value="">Semua</option>
|
||||||
|
<option value="non_asn">Non ASN</option>
|
||||||
|
<option value="asn">ASN</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<input type="hidden" id="filter_jenis" value="{{ $canHonorer ? 'non_asn' : 'asn' }}">
|
||||||
|
@endif
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label for="filter_jenis_pegawai" class="form-label">Jenis Pegawai</label>
|
||||||
|
<select class="form-select select2" id="filter_jenis_pegawai" name="filter_jenis_pegawai"
|
||||||
|
data-placeholder="Pilih Jenis Pegawai">
|
||||||
|
<option value="">Semua</option>
|
||||||
|
<option value="dosen">Dosen</option>
|
||||||
|
<option value="tendik">Tendik</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<label for="filter_unit" class="form-label">Unit Kerja</label>
|
||||||
|
<select class="form-select select2" id="filter_unit" name="filter_unit"
|
||||||
|
data-placeholder="Pilih Unit Kerja">
|
||||||
|
<option value=""></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<label for="filter_periode" class="form-label">Periode</label>
|
||||||
|
<select class="form-select select2" id="filter_periode" data-placeholder="Pilih Periode">
|
||||||
|
@foreach ($periodes as $periode)
|
||||||
|
<option value="{{ $periode->id_periode }}"
|
||||||
|
{{ $periode->id_periode == $periodeAktif ? 'selected' : '' }}>
|
||||||
|
{{ $periode->nama }}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
@if ($showFilterBulan)
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label for="filter_bulan" class="form-label">Bulan</label>
|
||||||
|
<select class="form-control select2" id="filter_bulan" data-placeholder="Pilih Bulan">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="nav nav-pills bg-nav-pills nav-justified mb-3" id="statusTab" role="tablist">
|
||||||
|
<li class="nav-item" role="presentation">
|
||||||
|
<button class="nav-link rounded-0 active" id="belum-selesai-tab" data-bs-toggle="tab"
|
||||||
|
data-bs-target="#belum-selesai" type="button" role="tab" aria-expanded="true">
|
||||||
|
<i class="uil-clock d-md-none d-block"></i>
|
||||||
|
<span class="d-none d-md-block">Belum Selesai</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item" role="presentation">
|
||||||
|
<button class="nav-link rounded-0" id="selesai-tab" data-bs-toggle="tab"
|
||||||
|
data-bs-target="#selesai" type="button" role="tab" aria-expanded="false">
|
||||||
|
<i class="uil-check-circle d-md-none d-block"></i>
|
||||||
|
<span class="d-none d-md-block">Selesai</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane show active" id="belum-selesai" role="tabpanel">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered w-100" id="table-belum-selesai">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Pegawai</th>
|
||||||
|
<th>Unit Kerja</th>
|
||||||
|
<th>Jumlah Pengajuan</th>
|
||||||
|
<th>NIP</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane" id="selesai" role="tabpanel">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered w-100" id="table-selesai">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Pegawai</th>
|
||||||
|
<th>Unit Kerja</th>
|
||||||
|
<th>Jumlah Pengajuan</th>
|
||||||
|
<th>NIP</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('js')
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
let tableBelumSelesai, tableSelesai;
|
||||||
|
|
||||||
|
// Restore tab aktif dari sessionStorage
|
||||||
|
var savedTab = sessionStorage.getItem('presensiGabungan_activeTab');
|
||||||
|
sessionStorage.removeItem('presensiGabungan_activeTab');
|
||||||
|
if (savedTab) {
|
||||||
|
var tabEl = document.getElementById(savedTab);
|
||||||
|
if (tabEl) { new bootstrap.Tab(tabEl).show(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore jenis dari sessionStorage
|
||||||
|
var savedJenis = sessionStorage.getItem('presensiGabungan_filterJenis');
|
||||||
|
sessionStorage.removeItem('presensiGabungan_filterJenis');
|
||||||
|
if (savedJenis !== null && $('#filter_jenis').is('select')) {
|
||||||
|
$('#filter_jenis').val(savedJenis);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore jenis pegawai dari sessionStorage
|
||||||
|
var savedJenisPegawai = sessionStorage.getItem('presensiGabungan_filterJenisPegawai');
|
||||||
|
sessionStorage.removeItem('presensiGabungan_filterJenisPegawai');
|
||||||
|
if (savedJenisPegawai !== null) {
|
||||||
|
$('#filter_jenis_pegawai').val(savedJenisPegawai);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore periode dari sessionStorage
|
||||||
|
var savedPeriode = sessionStorage.getItem('presensiGabungan_filterPeriode');
|
||||||
|
sessionStorage.removeItem('presensiGabungan_filterPeriode');
|
||||||
|
if (savedPeriode !== null && $('#filter_periode').find('option[value="' + savedPeriode + '"]').length) {
|
||||||
|
$('#filter_periode').val(savedPeriode);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderJenisPegawaiTag(jenis) {
|
||||||
|
var config = {
|
||||||
|
'dosen': { color: 'var(--ct-primary)', rgb: 'var(--ct-primary-rgb)', icon: 'uil-user-graduate' },
|
||||||
|
'tendik': { color: '#fd7e14', rgb: '253, 126, 20', icon: 'uil-briefcase-alt' }
|
||||||
|
};
|
||||||
|
var normalizedJenis = (jenis || '').toString().toLowerCase();
|
||||||
|
var c = config[normalizedJenis];
|
||||||
|
if (!c) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return '<small class="d-inline-block fw-bold" style="padding: 1px 18px 1px 6px; color: ' +
|
||||||
|
c.color + '; background: linear-gradient(to right, rgba(' + c.rgb + ', 0.25), rgba(' + c.rgb +
|
||||||
|
', 0)); clip-path: polygon(0 0, 100% 0, calc(100% - 20px) 100%, 0 100%);"><i class="' + c.icon +
|
||||||
|
'"></i> ' + normalizedJenis.toUpperCase() + '</small>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderStatusPegawaiTag(status, label) {
|
||||||
|
var config = {
|
||||||
|
'asn': { color: '#0a91a8', rgb: '13, 202, 240', icon: 'uil-shield-check' },
|
||||||
|
'non_asn': { color: '#6c757d', rgb: '108, 117, 125', icon: 'uil-user' }
|
||||||
|
};
|
||||||
|
var c = config[(status || '').toString().toLowerCase()];
|
||||||
|
if (!c) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return '<small class="d-inline-block fw-bold" style="padding: 1px 18px 1px 6px; color: ' +
|
||||||
|
c.color + '; background: linear-gradient(to right, rgba(' + c.rgb + ', 0.25), rgba(' + c.rgb +
|
||||||
|
', 0)); clip-path: polygon(0 0, 100% 0, calc(100% - 20px) 100%, 0 100%);"><i class="' + c.icon +
|
||||||
|
'"></i> ' + (label || '').toUpperCase() + '</small>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function initDataTable(tableId, status) {
|
||||||
|
return $(tableId).DataTable({
|
||||||
|
processing: true,
|
||||||
|
serverSide: true,
|
||||||
|
autoWidth: false,
|
||||||
|
ajax: {
|
||||||
|
url: "{{ route('pengajuan-presensi.data') }}",
|
||||||
|
data: function(d) {
|
||||||
|
d.status = status;
|
||||||
|
d.jenis = $('#filter_jenis').val();
|
||||||
|
d.jenis_pegawai = $('#filter_jenis_pegawai').val();
|
||||||
|
d.unit = $('#filter_unit').val();
|
||||||
|
d.periode = $('#filter_periode').val();
|
||||||
|
@if ($showFilterBulan)
|
||||||
|
d.bulan = $('#filter_bulan').val();
|
||||||
|
@endif
|
||||||
|
}
|
||||||
|
},
|
||||||
|
columns: [{
|
||||||
|
data: 'nama',
|
||||||
|
name: 'nama',
|
||||||
|
className: 'nama-col',
|
||||||
|
render: function(data, type, row) {
|
||||||
|
if (type !== 'display') {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
var nama = data || '-';
|
||||||
|
var nip = row.nip || '-';
|
||||||
|
return '<div>' +
|
||||||
|
'<div class="fw-semibold text-truncate" title="' + nama + '">' + nama + '</div>' +
|
||||||
|
'<div class="text-muted small font-monospace">' + nip + '</div>' +
|
||||||
|
'<div class="d-flex flex-wrap align-items-center gap-1 mt-1">' +
|
||||||
|
renderJenisPegawaiTag(row.jenis_pegawai) +
|
||||||
|
renderStatusPegawaiTag(row.jenis, row.jenis_label) +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'unit_nama',
|
||||||
|
name: 'unit_nama',
|
||||||
|
orderable: false,
|
||||||
|
className: 'unit-col',
|
||||||
|
render: function(data, type, row) {
|
||||||
|
if (type === 'display') {
|
||||||
|
return '<span title="' + (data || '') + '">' + (data || '') + '</span>';
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'absen_count',
|
||||||
|
name: 'absen_count',
|
||||||
|
orderable: false,
|
||||||
|
searchable: false,
|
||||||
|
className: 'text-center',
|
||||||
|
width: '120px',
|
||||||
|
render: function(data, type) {
|
||||||
|
if (type !== 'display') {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
return (data || 0) + ' Hari';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'nip',
|
||||||
|
name: 'nip',
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
createdRow: function(row, data) {
|
||||||
|
if (data.nip) {
|
||||||
|
$(row).attr('data-nip', data.nip)
|
||||||
|
.attr('data-url', data.detail_url)
|
||||||
|
.attr('data-bs-toggle', 'tooltip')
|
||||||
|
.attr('data-bs-placement', 'top')
|
||||||
|
.attr('title', 'Klik untuk melihat detail');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
drawCallback: function() {
|
||||||
|
document.querySelectorAll('body > .tooltip').forEach(function(el) { el.remove(); });
|
||||||
|
document.querySelectorAll(tableId + ' tbody tr[data-bs-toggle="tooltip"]').forEach(function(el) {
|
||||||
|
bootstrap.Tooltip.getOrCreateInstance(el);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
order: [[0, 'asc']],
|
||||||
|
language: {
|
||||||
|
processing: "<div class='spinner'></div> Sedang Memuat...",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
tableBelumSelesai = initDataTable('#table-belum-selesai', 0);
|
||||||
|
tableSelesai = initDataTable('#table-selesai', 1);
|
||||||
|
|
||||||
|
function saveFilterState() {
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterJenis', $('#filter_jenis').val() || '');
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterJenisPegawai', $('#filter_jenis_pegawai').val() || '');
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterUnit', $('#filter_unit').val() || '');
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterPeriode', $('#filter_periode').val() || '');
|
||||||
|
sessionStorage.setItem('presensiGabungan_activeTab', $('button[data-bs-toggle="tab"].active').attr('id') || '');
|
||||||
|
@if ($showFilterBulan)
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterBulan', $('#filter_bulan').val() || '');
|
||||||
|
@endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Row click navigation
|
||||||
|
$('#table-belum-selesai, #table-selesai').on('click', 'tbody tr', function(e) {
|
||||||
|
if ($(e.target).closest('.btn, .btn-group, .dropdown, .dropdown-menu, a, button').length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var url = $(this).data('url');
|
||||||
|
if (url) {
|
||||||
|
saveFilterState();
|
||||||
|
$('body').css('cursor', 'wait');
|
||||||
|
$(this).css('cursor', 'wait');
|
||||||
|
window.location.href = url;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
loadUnitKerja();
|
||||||
|
|
||||||
|
@if ($showFilterBulan)
|
||||||
|
loadBulanList();
|
||||||
|
@endif
|
||||||
|
|
||||||
|
$('#filter_jenis').on('change', function() {
|
||||||
|
tableBelumSelesai.draw();
|
||||||
|
tableSelesai.draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#filter_jenis_pegawai').on('change', function() {
|
||||||
|
tableBelumSelesai.draw();
|
||||||
|
tableSelesai.draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#filter_unit').on('change', function() {
|
||||||
|
tableBelumSelesai.draw();
|
||||||
|
tableSelesai.draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#filter_periode').on('change', function() {
|
||||||
|
@if ($showFilterBulan)
|
||||||
|
// List bulan mengikuti periode yang dipilih; draw dipicu oleh perubahan bulan.
|
||||||
|
loadBulanList();
|
||||||
|
@else
|
||||||
|
tableBelumSelesai.draw();
|
||||||
|
tableSelesai.draw();
|
||||||
|
@endif
|
||||||
|
});
|
||||||
|
|
||||||
|
@if ($showFilterBulan)
|
||||||
|
$('#filter_bulan').on('change', function() {
|
||||||
|
tableBelumSelesai.draw();
|
||||||
|
tableSelesai.draw();
|
||||||
|
});
|
||||||
|
@endif
|
||||||
|
|
||||||
|
$('button[data-bs-toggle="tab"]').on('shown.bs.tab', function(e) {
|
||||||
|
if (e.target.id === 'belum-selesai-tab') {
|
||||||
|
tableBelumSelesai.columns.adjust().responsive.recalc();
|
||||||
|
} else if (e.target.id === 'selesai-tab') {
|
||||||
|
tableSelesai.columns.adjust().responsive.recalc();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function loadUnitKerja() {
|
||||||
|
var savedUnit = sessionStorage.getItem('presensiGabungan_filterUnit');
|
||||||
|
sessionStorage.removeItem('presensiGabungan_filterUnit');
|
||||||
|
|
||||||
|
$.get("{{ route('pengajuan-presensi.unit-kerja') }}", function(response) {
|
||||||
|
$('#filter_unit').empty().append('<option value="">Semua Unit Kerja</option>');
|
||||||
|
$.each(response.units, function(key, value) {
|
||||||
|
$('#filter_unit').append('<option value="' + value.id + '">' + value.nama +
|
||||||
|
'</option>');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (savedUnit !== null) {
|
||||||
|
$('#filter_unit').val(savedUnit).trigger('change');
|
||||||
|
} else if (response.selected) {
|
||||||
|
$('#filter_unit').val(response.selected).trigger('change');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@if ($showFilterBulan)
|
||||||
|
function loadBulanList() {
|
||||||
|
var savedBulan = sessionStorage.getItem('presensiGabungan_filterBulan');
|
||||||
|
sessionStorage.removeItem('presensiGabungan_filterBulan');
|
||||||
|
|
||||||
|
$.get("{{ route('pengajuan-presensi.bulan-list') }}", { periode: $('#filter_periode').val() }, function(response) {
|
||||||
|
$('#filter_bulan').empty();
|
||||||
|
$.each(response.bulanList, function(key, value) {
|
||||||
|
$('#filter_bulan').append('<option value="' + value.value + '">' + value
|
||||||
|
.label +
|
||||||
|
'</option>');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set bulan default berdasarkan logika tanggal
|
||||||
|
var tanggalSekarang = new Date().getDate();
|
||||||
|
var sekarang = new Date();
|
||||||
|
var bulanSekarang = sekarang.getMonth() + 1; // 1-12
|
||||||
|
|
||||||
|
var bulanDefault = bulanSekarang;
|
||||||
|
|
||||||
|
if (tanggalSekarang <= 5) {
|
||||||
|
bulanDefault = bulanSekarang - 1;
|
||||||
|
if (bulanDefault < 1) {
|
||||||
|
bulanDefault = 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var bulanDefaultStr = ('0' + bulanDefault).slice(-2);
|
||||||
|
var bulanSekarangStr = ('0' + bulanSekarang).slice(-2);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
var selectElement = $('#filter_bulan');
|
||||||
|
var availableOptions = selectElement.find('option').map(function() {
|
||||||
|
return $(this).val();
|
||||||
|
}).get();
|
||||||
|
|
||||||
|
if (savedBulan !== null && availableOptions.includes(savedBulan)) {
|
||||||
|
selectElement.val(savedBulan).trigger('change');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (availableOptions.includes(bulanDefaultStr)) {
|
||||||
|
selectElement.val(bulanDefaultStr);
|
||||||
|
} else if (availableOptions.includes(bulanSekarangStr)) {
|
||||||
|
selectElement.val(bulanSekarangStr);
|
||||||
|
} else if (availableOptions.length > 0) {
|
||||||
|
selectElement.val(availableOptions[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectElement.trigger('change');
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@endif
|
||||||
|
});
|
||||||
|
|
||||||
|
// Event handler untuk tombol detail
|
||||||
|
$(document).on('click', '.detail-btn', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
var button = $(this);
|
||||||
|
var url = button.data('url');
|
||||||
|
if (!url) { return; }
|
||||||
|
|
||||||
|
// Simpan state filter
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterJenis', $('#filter_jenis').val() || '');
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterJenisPegawai', $('#filter_jenis_pegawai').val() || '');
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterUnit', $('#filter_unit').val() || '');
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterPeriode', $('#filter_periode').val() || '');
|
||||||
|
sessionStorage.setItem('presensiGabungan_activeTab', $('button[data-bs-toggle="tab"].active').attr('id') || '');
|
||||||
|
@if ($showFilterBulan)
|
||||||
|
sessionStorage.setItem('presensiGabungan_filterBulan', $('#filter_bulan').val() || '');
|
||||||
|
@endif
|
||||||
|
|
||||||
|
button.prop('disabled', true);
|
||||||
|
button.html('<i class="fas fa-spinner fa-spin" style="margin-right: 5px"></i> Loading...');
|
||||||
|
|
||||||
|
window.location.href = url;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endsection
|
||||||
@@ -62,8 +62,8 @@
|
|||||||
@section('breadcrumb')
|
@section('breadcrumb')
|
||||||
<ol class="breadcrumb m-0">
|
<ol class="breadcrumb m-0">
|
||||||
<li class="breadcrumb-item"><a href="javascript:void(0);">Verifikasi</a></li>
|
<li class="breadcrumb-item"><a href="javascript:void(0);">Verifikasi</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{{ route('pengajuan-presensi.tendik.index') }}">Pengajuan Presensi</a></li>
|
<li class="breadcrumb-item"><a href="{{ route('pengajuan-presensi.index') }}">Pengajuan Presensi</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{{ route('pengajuan-presensi.tendik.index') }}">Tendik</a></li>
|
<li class="breadcrumb-item">ASN</li>
|
||||||
<li class="breadcrumb-item active" aria-current="page">{{ $pegawai->nama }}</li>
|
<li class="breadcrumb-item active" aria-current="page">{{ $pegawai->nama }}</li>
|
||||||
</ol>
|
</ol>
|
||||||
@endsection
|
@endsection
|
||||||
@@ -342,8 +342,6 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Aktifkan menu sidebar
|
// Aktifkan menu sidebar
|
||||||
$('.si-pengajuan-presensi').addClass('menuitem-active');
|
$('.si-pengajuan-presensi').addClass('menuitem-active');
|
||||||
$('.li-pengajuan-presensi').addClass('show');
|
|
||||||
$('.li-pengajuan-presensi-tendik').addClass('active badge-primary-lighten');
|
|
||||||
|
|
||||||
// Set nama bulan jika ada filter bulan
|
// Set nama bulan jika ada filter bulan
|
||||||
@if(isset($bulan) && $bulan)
|
@if(isset($bulan) && $bulan)
|
||||||
@@ -365,6 +363,12 @@
|
|||||||
@if(isset($bulan) && $bulan)
|
@if(isset($bulan) && $bulan)
|
||||||
d.bulan = "{{ $bulan }}";
|
d.bulan = "{{ $bulan }}";
|
||||||
@endif
|
@endif
|
||||||
|
@if(isset($tahun) && $tahun)
|
||||||
|
d.tahun = "{{ $tahun }}";
|
||||||
|
@endif
|
||||||
|
@if(isset($periodeFilter) && $periodeFilter)
|
||||||
|
d.periode = "{{ $periodeFilter }}";
|
||||||
|
@endif
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
columns: [{
|
columns: [{
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ use App\Http\Controllers\Api\Remunerasi\PoinController as RemunerasiPoinControll
|
|||||||
use App\Http\Controllers\Api\Remunerasi\RemunerasiController;
|
use App\Http\Controllers\Api\Remunerasi\RemunerasiController;
|
||||||
use App\Http\Controllers\Api\Remunerasi\SKPController;
|
use App\Http\Controllers\Api\Remunerasi\SKPController;
|
||||||
use App\Http\Controllers\Api\RubrikController;
|
use App\Http\Controllers\Api\RubrikController;
|
||||||
|
use App\Http\Controllers\Api\VerifikasiAbsen\LinkController as VerifikasiAbsenLinkController;
|
||||||
|
use App\Http\Controllers\Api\VerifikasiAbsen\VerifikasiAbsenController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -110,4 +112,11 @@ Route::prefix('v1')->group(function () {
|
|||||||
Route::get('/poin', [RemunerasiPoinController::class, 'index']);
|
Route::get('/poin', [RemunerasiPoinController::class, 'index']);
|
||||||
Route::get('/skp', [SKPController::class, 'index']);
|
Route::get('/skp', [SKPController::class, 'index']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::prefix('/verifikasi-absen')->name('verifikasi-absen.')->group(function () {
|
||||||
|
Route::post('/link', [VerifikasiAbsenLinkController::class, 'generate'])->name('link');
|
||||||
|
Route::get('/{id}', [VerifikasiAbsenController::class, 'show'])->name('show');
|
||||||
|
Route::post('/{id}/setujui', [VerifikasiAbsenController::class, 'setujui'])->name('setujui');
|
||||||
|
Route::post('/{id}/tolak', [VerifikasiAbsenController::class, 'tolak'])->name('tolak');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ Route::prefix('/lainnya')->name('lainnya.')->group(function () {
|
|||||||
Route::get('/summary', [SimulasiJabatanController::class, 'summary'])->name('summary');
|
Route::get('/summary', [SimulasiJabatanController::class, 'summary'])->name('summary');
|
||||||
Route::get('/chart', [SimulasiJabatanController::class, 'chart'])->name('chart');
|
Route::get('/chart', [SimulasiJabatanController::class, 'chart'])->name('chart');
|
||||||
Route::get('/export', [SimulasiJabatanController::class, 'export'])->name('export');
|
Route::get('/export', [SimulasiJabatanController::class, 'export'])->name('export');
|
||||||
|
Route::get('/export-total', [SimulasiJabatanController::class, 'exportTotal'])->name('export-total');
|
||||||
Route::post('/warm-cache', [SimulasiJabatanController::class, 'warmCache'])->name('warm-cache');
|
Route::post('/warm-cache', [SimulasiJabatanController::class, 'warmCache'])->name('warm-cache');
|
||||||
Route::get('/detail/{nip}', [SimulasiJabatanController::class, 'detail'])->name('detail');
|
Route::get('/detail/{nip}', [SimulasiJabatanController::class, 'detail'])->name('detail');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use App\Http\Controllers\Auth\LoginController;
|
|||||||
use App\Http\Controllers\Manajemen\Limit\MengajarController;
|
use App\Http\Controllers\Manajemen\Limit\MengajarController;
|
||||||
use App\Http\Controllers\Manajemen\Limit\PenunjangController;
|
use App\Http\Controllers\Manajemen\Limit\PenunjangController;
|
||||||
use App\Http\Controllers\Manajemen\MemberController;
|
use App\Http\Controllers\Manajemen\MemberController;
|
||||||
|
use App\Http\Controllers\Manajemen\PegawaiController;
|
||||||
use App\Http\Controllers\Manajemen\PeriodeController;
|
use App\Http\Controllers\Manajemen\PeriodeController;
|
||||||
use App\Http\Controllers\Manajemen\PermissionController;
|
use App\Http\Controllers\Manajemen\PermissionController;
|
||||||
use App\Http\Controllers\Manajemen\Rubrik\DaftarListController;
|
use App\Http\Controllers\Manajemen\Rubrik\DaftarListController;
|
||||||
@@ -113,6 +114,14 @@ Route::middleware('permission:Baca Periode,Tambah Periode,Ubah Periode,Hapus Per
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::middleware('permission:Baca Pegawai')->prefix('/manajemen')->name('manajemen.')->group(function () {
|
||||||
|
Route::prefix('/pegawai')->name('pegawai.')->group(function () {
|
||||||
|
Route::get('/', [PegawaiController::class, 'index'])->name('index');
|
||||||
|
Route::get('/data', [PegawaiController::class, 'data'])->name('data');
|
||||||
|
Route::get('/{id}', [PegawaiController::class, 'show'])->name('show');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Route::middleware('permission:Baca Team,Baca Team Anggota,Tambah Team,Ubah Team,Hapus Team,Tambah Team Anggota,Ubah Team Anggota,Hapus Team Anggota')->prefix('/manajemen')->name('manajemen.')->group(function () {
|
Route::middleware('permission:Baca Team,Baca Team Anggota,Tambah Team,Ubah Team,Hapus Team,Tambah Team Anggota,Ubah Team Anggota,Hapus Team Anggota')->prefix('/manajemen')->name('manajemen.')->group(function () {
|
||||||
Route::prefix('/team')->name('team.')->group(function () {
|
Route::prefix('/team')->name('team.')->group(function () {
|
||||||
Route::get('/', [TeamController::class, 'index'])->name('index');
|
Route::get('/', [TeamController::class, 'index'])->name('index');
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\Verifikasi\PengajuanPresensi\HonorerController;
|
use App\Http\Controllers\Verifikasi\PengajuanPresensi\HonorerController;
|
||||||
|
use App\Http\Controllers\Verifikasi\PengajuanPresensi\PengajuanPresensiController;
|
||||||
use App\Http\Controllers\Verifikasi\PengajuanPresensi\TendikController;
|
use App\Http\Controllers\Verifikasi\PengajuanPresensi\TendikController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::middleware('permission:Baca Presensi,Baca Presensi Honorer,Verifikasi Presensi,Verifikasi Presensi Honorer')->prefix('/pengajuan-presensi')->name('pengajuan-presensi.')->group(function () {
|
// Akses ditentukan kepemilikan bawahan pegawai (DAWAI); Superuser selalu boleh.
|
||||||
Route::middleware('permission:Baca Presensi Honorer,Verifikasi Presensi Honorer')->prefix('/honorer')->name('honorer.')->group(function () {
|
// Otorisasi per-NIP untuk detail/aksi dilakukan di controller lewat BawahanHelper.
|
||||||
|
Route::middleware('bawahan.presensi')->prefix('/pengajuan-presensi')->name('pengajuan-presensi.')->group(function () {
|
||||||
|
// Halaman gabungan (Non ASN + ASN) dengan filter Jenis Pegawai
|
||||||
|
Route::get('/', [PengajuanPresensiController::class, 'index'])->name('index');
|
||||||
|
Route::get('/data', [PengajuanPresensiController::class, 'data'])->name('data');
|
||||||
|
Route::get('/unit-kerja', [PengajuanPresensiController::class, 'unitKerja'])->name('unit-kerja');
|
||||||
|
Route::get('/bulan-list', [PengajuanPresensiController::class, 'bulanList'])->name('bulan-list');
|
||||||
|
|
||||||
|
// Path URL memakai "non-asn"; nama route tetap "honorer.*" (dipakai di banyak view/controller).
|
||||||
|
Route::prefix('/non-asn')->name('honorer.')->group(function () {
|
||||||
Route::get('/', [HonorerController::class, 'index'])->name('index');
|
Route::get('/', [HonorerController::class, 'index'])->name('index');
|
||||||
Route::get('/data', [HonorerController::class, 'data'])->name('data');
|
Route::get('/data', [HonorerController::class, 'data'])->name('data');
|
||||||
Route::get('/unit-kerja', [HonorerController::class, 'unitKerja'])->name('unit-kerja');
|
Route::get('/unit-kerja', [HonorerController::class, 'unitKerja'])->name('unit-kerja');
|
||||||
@@ -22,7 +32,8 @@ Route::middleware('permission:Baca Presensi,Baca Presensi Honorer,Verifikasi Pre
|
|||||||
Route::post('/batalkan-selected', [HonorerController::class, 'batalkanSelected'])->name('batalkan-selected');
|
Route::post('/batalkan-selected', [HonorerController::class, 'batalkanSelected'])->name('batalkan-selected');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::middleware('permission:Baca Presensi,Verifikasi Presensi')->prefix('/tendik')->name('tendik.')->group(function () {
|
// Path URL memakai "asn"; nama route tetap "tendik.*" (dipakai di banyak view/controller).
|
||||||
|
Route::prefix('/asn')->name('tendik.')->group(function () {
|
||||||
Route::get('/', [TendikController::class, 'index'])->name('index');
|
Route::get('/', [TendikController::class, 'index'])->name('index');
|
||||||
Route::get('/data', [TendikController::class, 'data'])->name('data');
|
Route::get('/data', [TendikController::class, 'data'])->name('data');
|
||||||
Route::get('/unit-kerja', [TendikController::class, 'unitKerja'])->name('unit-kerja');
|
Route::get('/unit-kerja', [TendikController::class, 'unitKerja'])->name('unit-kerja');
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ Route::middleware('permission:Baca Pembayaran')->prefix('/remunerasi')->name('re
|
|||||||
Route::get('/data-perbandingan', [P1Controller::class, 'dataPerbandingan'])->name('data-perbandingan');
|
Route::get('/data-perbandingan', [P1Controller::class, 'dataPerbandingan'])->name('data-perbandingan');
|
||||||
Route::get('/export', [P1Controller::class, 'export'])->name('export');
|
Route::get('/export', [P1Controller::class, 'export'])->name('export');
|
||||||
Route::get('/export-selisih', [P1Controller::class, 'exportSelisih'])->name('export-selisih');
|
Route::get('/export-selisih', [P1Controller::class, 'exportSelisih'])->name('export-selisih');
|
||||||
|
Route::get('/export-perbandingan', [P1Controller::class, 'exportPerbandingan'])->name('export-perbandingan');
|
||||||
Route::post('/logs', [P1Controller::class, 'logs'])->name('logs');
|
Route::post('/logs', [P1Controller::class, 'logs'])->name('logs');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use App\Http\Controllers\Lainnya\VerifikasiAbsen\VerifikasiAbsenController;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
|
||||||
|
|
||||||
Route::prefix('/verifikasi-absen')->name('verifikasi-absen.')->group(function () {
|
|
||||||
Route::get('/setujui/{id}', [VerifikasiAbsenController::class, 'showSetujui'])->name('show-setujui');
|
|
||||||
Route::post('/setujui/{id}', [VerifikasiAbsenController::class, 'setujui'])->name('setujui');
|
|
||||||
Route::get('/berhasil-disetujui/{id}', [VerifikasiAbsenController::class, 'berhasilDisetujui'])->name('berhasil-disetujui');
|
|
||||||
Route::get('/tolak/{id}', [VerifikasiAbsenController::class, 'showTolak'])->name('show-tolak');
|
|
||||||
Route::post('/tolak/{id}', [VerifikasiAbsenController::class, 'tolak'])->name('tolak');
|
|
||||||
Route::get('/sudah-diproses/{id}', [VerifikasiAbsenController::class, 'sudahDiproses'])->name('sudah-diproses');
|
|
||||||
});
|
|
||||||
+1
-1
@@ -12,6 +12,7 @@ Route::get('/', function () {
|
|||||||
|
|
||||||
// Authentication Routes
|
// Authentication Routes
|
||||||
Route::get('/login', [LoginController::class, 'index'])->name('login');
|
Route::get('/login', [LoginController::class, 'index'])->name('login');
|
||||||
|
Route::get('/login/ariyutta', [LoginController::class, 'ariyutta'])->name('login.ariyutta');
|
||||||
Route::post('/authenticated', [LoginController::class, 'authenticated'])->name('authenticated');
|
Route::post('/authenticated', [LoginController::class, 'authenticated'])->name('authenticated');
|
||||||
Route::get('/logout', [LoginController::class, 'logout'])->name('logout');
|
Route::get('/logout', [LoginController::class, 'logout'])->name('logout');
|
||||||
|
|
||||||
@@ -26,7 +27,6 @@ Route::get('/auth/google/callback', [OauthController::class, 'callback'])->name(
|
|||||||
Route::get('/jurnal', [JurnalController::class, 'index']);
|
Route::get('/jurnal', [JurnalController::class, 'index']);
|
||||||
|
|
||||||
Route::middleware('auth')->group(function () {
|
Route::middleware('auth')->group(function () {
|
||||||
include __DIR__.'/prefix/verifikasi-absen.php';
|
|
||||||
include __DIR__.'/prefix/profil.php';
|
include __DIR__.'/prefix/profil.php';
|
||||||
include __DIR__.'/prefix/dashboard.php';
|
include __DIR__.'/prefix/dashboard.php';
|
||||||
include __DIR__.'/prefix/pagu.php';
|
include __DIR__.'/prefix/pagu.php';
|
||||||
|
|||||||
Vendored
-22
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// autoload.php @generated by Composer
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 50600) {
|
|
||||||
if (!headers_sent()) {
|
|
||||||
header('HTTP/1.1 500 Internal Server Error');
|
|
||||||
}
|
|
||||||
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
|
||||||
if (!ini_get('display_errors')) {
|
|
||||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
|
||||||
fwrite(STDERR, $err);
|
|
||||||
} elseif (!headers_sent()) {
|
|
||||||
echo $err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new RuntimeException($err);
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once __DIR__ . '/composer/autoload_real.php';
|
|
||||||
|
|
||||||
return ComposerAutoloaderInite35c9d807d4c3b727d8b29698aada6ae::getLoader();
|
|
||||||
Vendored
-119
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../nesbot/carbon/bin/carbon)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = $this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/nesbot/carbon/bin/carbon');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/nesbot/carbon/bin/carbon';
|
|
||||||
Vendored
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/carbon
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
php "%BIN_TARGET%" %*
|
|
||||||
Vendored
-119
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../symfony/error-handler/Resources/bin/patch-type-declarations)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = $this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/symfony/error-handler/Resources/bin/patch-type-declarations');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/symfony/error-handler/Resources/bin/patch-type-declarations';
|
|
||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/patch-type-declarations
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
php "%BIN_TARGET%" %*
|
|
||||||
Vendored
-119
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../nikic/php-parser/bin/php-parse)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = $this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/nikic/php-parser/bin/php-parse');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/nikic/php-parser/bin/php-parse';
|
|
||||||
Vendored
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/php-parse
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
php "%BIN_TARGET%" %*
|
|
||||||
Vendored
-122
@@ -1,122 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../phpunit/phpunit/phpunit)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
$GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST'] = $GLOBALS['__PHPUNIT_ISOLATION_BLACKLIST'] = array(realpath(__DIR__ . '/..'.'/phpunit/phpunit/phpunit'));
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = 'phpvfscomposer://'.$this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
$data = str_replace('__DIR__', var_export(dirname($this->realpath), true), $data);
|
|
||||||
$data = str_replace('__FILE__', var_export($this->realpath, true), $data);
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/phpunit/phpunit/phpunit');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/phpunit/phpunit/phpunit';
|
|
||||||
Vendored
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/phpunit
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
php "%BIN_TARGET%" %*
|
|
||||||
Vendored
-119
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../laravel/pint/builds/pint)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = $this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/laravel/pint/builds/pint');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/laravel/pint/builds/pint';
|
|
||||||
Vendored
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/pint
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
php "%BIN_TARGET%" %*
|
|
||||||
Vendored
-119
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../psy/psysh/bin/psysh)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = $this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/psy/psysh/bin/psysh');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/psy/psysh/bin/psysh';
|
|
||||||
Vendored
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/psysh
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
php "%BIN_TARGET%" %*
|
|
||||||
Vendored
-37
@@ -1,37 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
# Support bash to support `source` with fallback on $0 if this does not run with bash
|
|
||||||
# https://stackoverflow.com/a/35006505/6512
|
|
||||||
selfArg="$BASH_SOURCE"
|
|
||||||
if [ -z "$selfArg" ]; then
|
|
||||||
selfArg="$0"
|
|
||||||
fi
|
|
||||||
|
|
||||||
self=$(realpath "$selfArg" 2> /dev/null)
|
|
||||||
if [ -z "$self" ]; then
|
|
||||||
self="$selfArg"
|
|
||||||
fi
|
|
||||||
|
|
||||||
dir=$(cd "${self%[/\\]*}" > /dev/null; cd ../laravel/sail/bin && pwd)
|
|
||||||
|
|
||||||
if [ -d /proc/cygdrive ]; then
|
|
||||||
case $(which php) in
|
|
||||||
$(readlink -n /proc/cygdrive)/*)
|
|
||||||
# We are in Cygwin using Windows php, so the path must be translated
|
|
||||||
dir=$(cygpath -m "$dir");
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
export COMPOSER_RUNTIME_BIN_DIR="$(cd "${self%[/\\]*}" > /dev/null; pwd)"
|
|
||||||
|
|
||||||
# If bash is sourcing this file, we have to source the target as well
|
|
||||||
bashSource="$BASH_SOURCE"
|
|
||||||
if [ -n "$bashSource" ]; then
|
|
||||||
if [ "$bashSource" != "$0" ]; then
|
|
||||||
source "${dir}/sail" "$@"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec "${dir}/sail" "$@"
|
|
||||||
Vendored
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/../laravel/sail/bin/sail
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
bash "%BIN_TARGET%" %*
|
|
||||||
Vendored
-119
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../symfony/var-dumper/Resources/bin/var-dump-server)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = $this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/symfony/var-dumper/Resources/bin/var-dump-server');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/symfony/var-dumper/Resources/bin/var-dump-server';
|
|
||||||
Vendored
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/var-dump-server
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
php "%BIN_TARGET%" %*
|
|
||||||
Vendored
-119
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../symfony/yaml/Resources/bin/yaml-lint)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = $this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/symfony/yaml/Resources/bin/yaml-lint');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/symfony/yaml/Resources/bin/yaml-lint';
|
|
||||||
Vendored
-5
@@ -1,5 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
setlocal DISABLEDELAYEDEXPANSION
|
|
||||||
SET BIN_TARGET=%~dp0/yaml-lint
|
|
||||||
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
|
|
||||||
php "%BIN_TARGET%" %*
|
|
||||||
Vendored
-634
@@ -1,634 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
|
||||||
|
|
||||||
## [0.14.8](https://github.com/brick/math/releases/tag/0.14.8) - 2026-02-10
|
|
||||||
|
|
||||||
🗑️ **Deprecations**
|
|
||||||
|
|
||||||
- Method `BigInteger::testBit()` is deprecated, use `isBitSet()` instead
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- New method: `BigInteger::isBitSet()` (replaces `testBit()`)
|
|
||||||
- New method: `BigNumber::toString()` (alias of magic method `__toString()`)
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- Performance optimization of `BigRational` comparison methods
|
|
||||||
- More exceptions have been documented with `@throws` annotations
|
|
||||||
|
|
||||||
## [0.14.7](https://github.com/brick/math/releases/tag/0.14.7) - 2026-02-07
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `clamp()` is now available on the base `BigNumber` class
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- Improved `@throws` exception documentation
|
|
||||||
|
|
||||||
## [0.14.6](https://github.com/brick/math/releases/tag/0.14.6) - 2026-02-05
|
|
||||||
|
|
||||||
🗑️ **Deprecations**
|
|
||||||
|
|
||||||
- Not passing a `$scale` to `BigDecimal::dividedBy()` is deprecated; **`$scale` will be required in 0.15**
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- `BigRational::toFloat()` never returns `NAN` anymore
|
|
||||||
|
|
||||||
## [0.14.5](https://github.com/brick/math/releases/tag/0.14.5) - 2026-02-03
|
|
||||||
|
|
||||||
🗑️ **Deprecations**
|
|
||||||
|
|
||||||
- Not passing a rounding mode to `BigInteger::sqrt()` and `BigDecimal::sqrt()` triggers a deprecation notice: **the default rounding mode will change from `Down` to `Unnecessary` in 0.15**
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigInteger::sqrt()` and `BigDecimal::sqrt()` now support rounding
|
|
||||||
- `abs()` and `negated()` methods are now available on the base `BigNumber` class
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- Alphabet is now checked for duplicate characters in `BigInteger::(from|to)ArbitraryBase()`
|
|
||||||
- `BigNumber::ofNullable()` is now marked as `@pure`
|
|
||||||
|
|
||||||
## [0.14.4](https://github.com/brick/math/releases/tag/0.14.4) - 2026-02-02
|
|
||||||
|
|
||||||
🗑️ **Deprecations**
|
|
||||||
|
|
||||||
- Passing a negative modulus to `BigInteger::mod()` is deprecated to align with Euclidean modulo semantics; it will throw `NegativeNumberException` in 0.15
|
|
||||||
- Method `BigDecimal::stripTrailingZeros()` is deprecated, use `strippedOfTrailingZeros()` instead
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigInteger::modPow()` now accepts negative bases
|
|
||||||
- New method: `BigDecimal::strippedOfTrailingZeros()` (replaces `stripTrailingZeros()`)
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- `clamp()` methods are now marked as `@pure`
|
|
||||||
|
|
||||||
## [0.14.3](https://github.com/brick/math/releases/tag/0.14.3) - 2026-02-01
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- New method: `BigInteger::lcm()`
|
|
||||||
- New method: `BigInteger::lcmAll()`
|
|
||||||
- New method: `BigRational::toRepeatingDecimalString()`
|
|
||||||
|
|
||||||
🐛 **Bug fixes**
|
|
||||||
|
|
||||||
- `BigInteger::gcdAll()` / `gcdMultiple()` could return a negative result when used with a single negative number
|
|
||||||
|
|
||||||
## [0.14.2](https://github.com/brick/math/releases/tag/0.14.2) - 2026-01-30
|
|
||||||
|
|
||||||
🗑️ **Deprecations**
|
|
||||||
|
|
||||||
- **Passing `float` values to `of()` or arithmetic methods is deprecated** and will be removed in 0.15; cast to string explicitly to preserve the previous behaviour (#105)
|
|
||||||
- **Accessing `RoundingMode` enum cases through upper snake case (e.g. `HALF_UP`) is deprecated**, use the pascal case version (e.g. `HalfUp`) instead
|
|
||||||
- Method `BigInteger::gcdMultiple()` is deprecated, use `gcdAll()` instead
|
|
||||||
- Method `BigDecimal::exactlyDividedBy()` is deprecated, use `dividedByExact()` instead
|
|
||||||
- Method `BigDecimal::getIntegralPart()` is deprecated (will be removed in 0.15, and re-introduced as returning `BigInteger` in 0.16)
|
|
||||||
- Method `BigDecimal::getFractionalPart()` is deprecated (will be removed in 0.15, and re-introduced as returning `BigDecimal` with a different meaning in 0.16)
|
|
||||||
- Method `BigRational::nd()` is deprecated, use `ofFraction()` instead
|
|
||||||
- Method `BigRational::quotient()` is deprecated, use `getIntegralPart()` instead
|
|
||||||
- Method `BigRational::remainder()` is deprecated, use `$number->getNumerator()->remainder($number->getDenominator())` instead
|
|
||||||
- Method `BigRational::quotientAndRemainder()` is deprecated, use `$number->getNumerator()->quotientAndRemainder($number->getDenominator())` instead
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- New method: `BigInteger::gcdAll()` (replaces `gcdMultiple()`)
|
|
||||||
- New method: `BigRational::clamp()`
|
|
||||||
- New method: `BigRational::ofFraction()` (replaces `nd()`)
|
|
||||||
- New method: `BigRational::getIntegralPart()` (replaces `quotient()`)
|
|
||||||
- New method: `BigRational::getFractionalPart()`
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- `BigInteger::modInverse()` now accepts `BigNumber|int|float|string` instead of just `BigInteger`
|
|
||||||
- `BigInteger::gcdMultiple()` now accepts `BigNumber|int|float|string` instead of just `BigInteger`
|
|
||||||
|
|
||||||
🐛 **Bug fixes**
|
|
||||||
|
|
||||||
- `BigInteger::clamp()` and `BigDecimal::clamp()` now throw an exception on inverted bounds, instead of returning an incorrect result
|
|
||||||
|
|
||||||
## [0.14.1](https://github.com/brick/math/releases/tag/0.14.1) - 2025-11-24
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- New method: `BigNumber::ofNullable()` (#94 by @mrkh995)
|
|
||||||
|
|
||||||
✨ **Compatibility fixes**
|
|
||||||
|
|
||||||
- Fixed warnings on PHP 8.5 (#101 and #102 by @julien-boudry)
|
|
||||||
|
|
||||||
## [0.14.0](https://github.com/brick/math/releases/tag/0.14.0) - 2025-08-29
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- New methods: `BigInteger::clamp()` and `BigDecimal::clamp()` (#96 by @JesterIruka)
|
|
||||||
|
|
||||||
✨ **Improvements**
|
|
||||||
|
|
||||||
- All pure methods in `BigNumber` classes are now marked as `@pure` for better static analysis
|
|
||||||
|
|
||||||
💥 **Breaking changes**
|
|
||||||
|
|
||||||
- Minimum PHP version is now 8.2
|
|
||||||
- `BigNumber` classes are now `readonly`
|
|
||||||
- `BigNumber` is now marked as sealed: it must not be extended outside of this package
|
|
||||||
- Exception classes are now `final`
|
|
||||||
|
|
||||||
## [0.13.1](https://github.com/brick/math/releases/tag/0.13.1) - 2025-03-29
|
|
||||||
|
|
||||||
✨ **Improvements**
|
|
||||||
|
|
||||||
- `__toString()` methods of `BigInteger` and `BigDecimal` are now type-hinted as returning `numeric-string` instead of `string` (#90 by @vudaltsov)
|
|
||||||
|
|
||||||
## [0.13.0](https://github.com/brick/math/releases/tag/0.13.0) - 2025-03-03
|
|
||||||
|
|
||||||
💥 **Breaking changes**
|
|
||||||
|
|
||||||
- `BigDecimal::ofUnscaledValue()` no longer throws an exception if the scale is negative
|
|
||||||
- `MathException` now extends `RuntimeException` instead of `Exception`; this reverts the change introduced in version `0.11.0` (#82)
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigDecimal::ofUnscaledValue()` allows a negative scale (and converts the values to create a zero scale number)
|
|
||||||
|
|
||||||
## [0.12.3](https://github.com/brick/math/releases/tag/0.12.3) - 2025-02-28
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigDecimal::getPrecision()` Returns the number of significant digits in a decimal number
|
|
||||||
|
|
||||||
## [0.12.2](https://github.com/brick/math/releases/tag/0.12.2) - 2025-02-26
|
|
||||||
|
|
||||||
⚡️ **Performance improvements**
|
|
||||||
|
|
||||||
- Division in `NativeCalculator` is now faster for small divisors, thanks to [@Izumi-kun](https://github.com/Izumi-kun) in [#87](https://github.com/brick/math/pull/87).
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- Add missing `RoundingNecessaryException` to the `@throws` annotation of `BigNumber::of()`
|
|
||||||
|
|
||||||
## [0.12.1](https://github.com/brick/math/releases/tag/0.12.1) - 2023-11-29
|
|
||||||
|
|
||||||
⚡️ **Performance improvements**
|
|
||||||
|
|
||||||
- `BigNumber::of()` is now faster, thanks to [@SebastienDug](https://github.com/SebastienDug) in [#77](https://github.com/brick/math/pull/77).
|
|
||||||
|
|
||||||
## [0.12.0](https://github.com/brick/math/releases/tag/0.12.0) - 2023-11-26
|
|
||||||
|
|
||||||
💥 **Breaking changes**
|
|
||||||
|
|
||||||
- Minimum PHP version is now 8.1
|
|
||||||
- `RoundingMode` is now an `enum`; if you're type-hinting rounding modes, you need to type-hint against `RoundingMode` instead of `int` now
|
|
||||||
- `BigNumber` classes do not implement the `Serializable` interface anymore (they use the [new custom object serialization mechanism](https://wiki.php.net/rfc/custom_object_serialization))
|
|
||||||
- The following breaking changes only affect you if you're creating your own `BigNumber` subclasses:
|
|
||||||
- the return type of `BigNumber::of()` is now `static`
|
|
||||||
- `BigNumber` has a new abstract method `from()`
|
|
||||||
- all `public` and `protected` functions of `BigNumber` are now `final`
|
|
||||||
|
|
||||||
## [0.11.0](https://github.com/brick/math/releases/tag/0.11.0) - 2023-01-16
|
|
||||||
|
|
||||||
💥 **Breaking changes**
|
|
||||||
|
|
||||||
- Minimum PHP version is now 8.0
|
|
||||||
- Methods accepting a union of types are now strongly typed<sup>*</sup>
|
|
||||||
- `MathException` now extends `Exception` instead of `RuntimeException`
|
|
||||||
|
|
||||||
<sup>* You may now run into type errors if you were passing `Stringable` objects to `of()` or any of the methods
|
|
||||||
internally calling `of()`, with `strict_types` enabled. You can fix this by casting `Stringable` objects to `string`
|
|
||||||
first.</sup>
|
|
||||||
|
|
||||||
## [0.10.2](https://github.com/brick/math/releases/tag/0.10.2) - 2022-08-11
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- `BigRational::toFloat()` now simplifies the fraction before performing division (#73) thanks to @olsavmic
|
|
||||||
|
|
||||||
## [0.10.1](https://github.com/brick/math/releases/tag/0.10.1) - 2022-08-02
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigInteger::gcdMultiple()` returns the GCD of multiple `BigInteger` numbers
|
|
||||||
|
|
||||||
## [0.10.0](https://github.com/brick/math/releases/tag/0.10.0) - 2022-06-18
|
|
||||||
|
|
||||||
💥 **Breaking changes**
|
|
||||||
|
|
||||||
- Minimum PHP version is now 7.4
|
|
||||||
|
|
||||||
## [0.9.3](https://github.com/brick/math/releases/tag/0.9.3) - 2021-08-15
|
|
||||||
|
|
||||||
🚀 **Compatibility with PHP 8.1**
|
|
||||||
|
|
||||||
- Support for custom object serialization; this removes a warning on PHP 8.1 due to the `Serializable` interface being deprecated (#60) thanks @TRowbotham
|
|
||||||
|
|
||||||
## [0.9.2](https://github.com/brick/math/releases/tag/0.9.2) - 2021-01-20
|
|
||||||
|
|
||||||
🐛 **Bug fix**
|
|
||||||
|
|
||||||
- Incorrect results could be returned when using the BCMath calculator, with a default scale set with `bcscale()`, on PHP >= 7.2 (#55).
|
|
||||||
|
|
||||||
## [0.9.1](https://github.com/brick/math/releases/tag/0.9.1) - 2020-08-19
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigInteger::not()` returns the bitwise `NOT` value
|
|
||||||
|
|
||||||
🐛 **Bug fixes**
|
|
||||||
|
|
||||||
- `BigInteger::toBytes()` could return an incorrect binary representation for some numbers
|
|
||||||
- The bitwise operations `and()`, `or()`, `xor()` on `BigInteger` could return an incorrect result when the GMP extension is not available
|
|
||||||
|
|
||||||
## [0.9.0](https://github.com/brick/math/releases/tag/0.9.0) - 2020-08-18
|
|
||||||
|
|
||||||
👌 **Improvements**
|
|
||||||
|
|
||||||
- `BigNumber::of()` now accepts `.123` and `123.` formats, both of which return a `BigDecimal`
|
|
||||||
|
|
||||||
💥 **Breaking changes**
|
|
||||||
|
|
||||||
- Deprecated method `BigInteger::powerMod()` has been removed - use `modPow()` instead
|
|
||||||
- Deprecated method `BigInteger::parse()` has been removed - use `fromBase()` instead
|
|
||||||
|
|
||||||
## [0.8.17](https://github.com/brick/math/releases/tag/0.8.17) - 2020-08-19
|
|
||||||
|
|
||||||
🐛 **Bug fix**
|
|
||||||
|
|
||||||
- `BigInteger::toBytes()` could return an incorrect binary representation for some numbers
|
|
||||||
- The bitwise operations `and()`, `or()`, `xor()` on `BigInteger` could return an incorrect result when the GMP extension is not available
|
|
||||||
|
|
||||||
## [0.8.16](https://github.com/brick/math/releases/tag/0.8.16) - 2020-08-18
|
|
||||||
|
|
||||||
🚑 **Critical fix**
|
|
||||||
|
|
||||||
- This version reintroduces the deprecated `BigInteger::parse()` method, that has been removed by mistake in version `0.8.9` and should have lasted for the whole `0.8` release cycle.
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigInteger::modInverse()` calculates a modular multiplicative inverse
|
|
||||||
- `BigInteger::fromBytes()` creates a `BigInteger` from a byte string
|
|
||||||
- `BigInteger::toBytes()` converts a `BigInteger` to a byte string
|
|
||||||
- `BigInteger::randomBits()` creates a pseudo-random `BigInteger` of a given bit length
|
|
||||||
- `BigInteger::randomRange()` creates a pseudo-random `BigInteger` between two bounds
|
|
||||||
|
|
||||||
💩 **Deprecations**
|
|
||||||
|
|
||||||
- `BigInteger::powerMod()` is now deprecated in favour of `modPow()`
|
|
||||||
|
|
||||||
## [0.8.15](https://github.com/brick/math/releases/tag/0.8.15) - 2020-04-15
|
|
||||||
|
|
||||||
🐛 **Fixes**
|
|
||||||
|
|
||||||
- added missing `ext-json` requirement, due to `BigNumber` implementing `JsonSerializable`
|
|
||||||
|
|
||||||
⚡️ **Optimizations**
|
|
||||||
|
|
||||||
- additional optimization in `BigInteger::remainder()`
|
|
||||||
|
|
||||||
## [0.8.14](https://github.com/brick/math/releases/tag/0.8.14) - 2020-02-18
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigInteger::getLowestSetBit()` returns the index of the rightmost one bit
|
|
||||||
|
|
||||||
## [0.8.13](https://github.com/brick/math/releases/tag/0.8.13) - 2020-02-16
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigInteger::isEven()` tests whether the number is even
|
|
||||||
- `BigInteger::isOdd()` tests whether the number is odd
|
|
||||||
- `BigInteger::testBit()` tests if a bit is set
|
|
||||||
- `BigInteger::getBitLength()` returns the number of bits in the minimal representation of the number
|
|
||||||
|
|
||||||
## [0.8.12](https://github.com/brick/math/releases/tag/0.8.12) - 2020-02-03
|
|
||||||
|
|
||||||
🛠️ **Maintenance release**
|
|
||||||
|
|
||||||
Classes are now annotated for better static analysis with [psalm](https://psalm.dev/).
|
|
||||||
|
|
||||||
This is a maintenance release: no bug fixes, no new features, no breaking changes.
|
|
||||||
|
|
||||||
## [0.8.11](https://github.com/brick/math/releases/tag/0.8.11) - 2020-01-23
|
|
||||||
|
|
||||||
✨ **New feature**
|
|
||||||
|
|
||||||
`BigInteger::powerMod()` performs a power-with-modulo operation. Useful for crypto.
|
|
||||||
|
|
||||||
## [0.8.10](https://github.com/brick/math/releases/tag/0.8.10) - 2020-01-21
|
|
||||||
|
|
||||||
✨ **New feature**
|
|
||||||
|
|
||||||
`BigInteger::mod()` returns the **modulo** of two numbers. The *modulo* differs from the *remainder* when the signs of the operands are different.
|
|
||||||
|
|
||||||
## [0.8.9](https://github.com/brick/math/releases/tag/0.8.9) - 2020-01-08
|
|
||||||
|
|
||||||
⚡️ **Performance improvements**
|
|
||||||
|
|
||||||
A few additional optimizations in `BigInteger` and `BigDecimal` when one of the operands can be returned as is. Thanks to @tomtomsen in #24.
|
|
||||||
|
|
||||||
## [0.8.8](https://github.com/brick/math/releases/tag/0.8.8) - 2019-04-25
|
|
||||||
|
|
||||||
🐛 **Bug fixes**
|
|
||||||
|
|
||||||
- `BigInteger::toBase()` could return an empty string for zero values (BCMath & Native calculators only, GMP calculator unaffected)
|
|
||||||
|
|
||||||
✨ **New features**
|
|
||||||
|
|
||||||
- `BigInteger::toArbitraryBase()` converts a number to an arbitrary base, using a custom alphabet
|
|
||||||
- `BigInteger::fromArbitraryBase()` converts a string in an arbitrary base, using a custom alphabet, back to a number
|
|
||||||
|
|
||||||
These methods can be used as the foundation to convert strings between different bases/alphabets, using BigInteger as an intermediate representation.
|
|
||||||
|
|
||||||
💩 **Deprecations**
|
|
||||||
|
|
||||||
- `BigInteger::parse()` is now deprecated in favour of `fromBase()`
|
|
||||||
|
|
||||||
`BigInteger::fromBase()` works the same way as `parse()`, with 2 minor differences:
|
|
||||||
|
|
||||||
- the `$base` parameter is required, it does not default to `10`
|
|
||||||
- it throws a `NumberFormatException` instead of an `InvalidArgumentException` when the number is malformed
|
|
||||||
|
|
||||||
## [0.8.7](https://github.com/brick/math/releases/tag/0.8.7) - 2019-04-20
|
|
||||||
|
|
||||||
**Improvements**
|
|
||||||
|
|
||||||
- Safer conversion from `float` when using custom locales
|
|
||||||
- **Much faster** `NativeCalculator` implementation 🚀
|
|
||||||
|
|
||||||
You can expect **at least a 3x performance improvement** for common arithmetic operations when using the library on systems without GMP or BCMath; it gets exponentially faster on multiplications with a high number of digits. This is due to calculations now being performed on whole blocks of digits (the block size depending on the platform, 32-bit or 64-bit) instead of digit-by-digit as before.
|
|
||||||
|
|
||||||
## [0.8.6](https://github.com/brick/math/releases/tag/0.8.6) - 2019-04-11
|
|
||||||
|
|
||||||
**New method**
|
|
||||||
|
|
||||||
`BigNumber::sum()` returns the sum of one or more numbers.
|
|
||||||
|
|
||||||
## [0.8.5](https://github.com/brick/math/releases/tag/0.8.5) - 2019-02-12
|
|
||||||
|
|
||||||
**Bug fix**: `of()` factory methods could fail when passing a `float` in environments using a `LC_NUMERIC` locale with a decimal separator other than `'.'` (#20).
|
|
||||||
|
|
||||||
Thanks @manowark 👍
|
|
||||||
|
|
||||||
## [0.8.4](https://github.com/brick/math/releases/tag/0.8.4) - 2018-12-07
|
|
||||||
|
|
||||||
**New method**
|
|
||||||
|
|
||||||
`BigDecimal::sqrt()` calculates the square root of a decimal number, to a given scale.
|
|
||||||
|
|
||||||
## [0.8.3](https://github.com/brick/math/releases/tag/0.8.3) - 2018-12-06
|
|
||||||
|
|
||||||
**New method**
|
|
||||||
|
|
||||||
`BigInteger::sqrt()` calculates the square root of a number (thanks @peter279k).
|
|
||||||
|
|
||||||
**New exception**
|
|
||||||
|
|
||||||
`NegativeNumberException` is thrown when calling `sqrt()` on a negative number.
|
|
||||||
|
|
||||||
## [0.8.2](https://github.com/brick/math/releases/tag/0.8.2) - 2018-11-08
|
|
||||||
|
|
||||||
**Performance update**
|
|
||||||
|
|
||||||
- Further improvement of `toInt()` performance
|
|
||||||
- `NativeCalculator` can now perform some multiplications more efficiently
|
|
||||||
|
|
||||||
## [0.8.1](https://github.com/brick/math/releases/tag/0.8.1) - 2018-11-07
|
|
||||||
|
|
||||||
Performance optimization of `toInt()` methods.
|
|
||||||
|
|
||||||
## [0.8.0](https://github.com/brick/math/releases/tag/0.8.0) - 2018-10-13
|
|
||||||
|
|
||||||
**Breaking changes**
|
|
||||||
|
|
||||||
The following deprecated methods have been removed. Use the new method name instead:
|
|
||||||
|
|
||||||
| Method removed | Replacement method |
|
|
||||||
| --- | --- |
|
|
||||||
| `BigDecimal::getIntegral()` | `BigDecimal::getIntegralPart()` |
|
|
||||||
| `BigDecimal::getFraction()` | `BigDecimal::getFractionalPart()` |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**New features**
|
|
||||||
|
|
||||||
`BigInteger` has been augmented with 5 new methods for bitwise operations:
|
|
||||||
|
|
||||||
| New method | Description |
|
|
||||||
| --- | --- |
|
|
||||||
| `and()` | performs a bitwise `AND` operation on two numbers |
|
|
||||||
| `or()` | performs a bitwise `OR` operation on two numbers |
|
|
||||||
| `xor()` | performs a bitwise `XOR` operation on two numbers |
|
|
||||||
| `shiftedLeft()` | returns the number shifted left by a number of bits |
|
|
||||||
| `shiftedRight()` | returns the number shifted right by a number of bits |
|
|
||||||
|
|
||||||
Thanks to @DASPRiD 👍
|
|
||||||
|
|
||||||
## [0.7.3](https://github.com/brick/math/releases/tag/0.7.3) - 2018-08-20
|
|
||||||
|
|
||||||
**New method:** `BigDecimal::hasNonZeroFractionalPart()`
|
|
||||||
|
|
||||||
**Renamed/deprecated methods:**
|
|
||||||
|
|
||||||
- `BigDecimal::getIntegral()` has been renamed to `getIntegralPart()` and is now deprecated
|
|
||||||
- `BigDecimal::getFraction()` has been renamed to `getFractionalPart()` and is now deprecated
|
|
||||||
|
|
||||||
## [0.7.2](https://github.com/brick/math/releases/tag/0.7.2) - 2018-07-21
|
|
||||||
|
|
||||||
**Performance update**
|
|
||||||
|
|
||||||
`BigInteger::parse()` and `toBase()` now use GMP's built-in base conversion features when available.
|
|
||||||
|
|
||||||
## [0.7.1](https://github.com/brick/math/releases/tag/0.7.1) - 2018-03-01
|
|
||||||
|
|
||||||
This is a maintenance release, no code has been changed.
|
|
||||||
|
|
||||||
- When installed with `--no-dev`, the autoloader does not autoload tests anymore
|
|
||||||
- Tests and other files unnecessary for production are excluded from the dist package
|
|
||||||
|
|
||||||
This will help make installations more compact.
|
|
||||||
|
|
||||||
## [0.7.0](https://github.com/brick/math/releases/tag/0.7.0) - 2017-10-02
|
|
||||||
|
|
||||||
Methods renamed:
|
|
||||||
|
|
||||||
- `BigNumber:sign()` has been renamed to `getSign()`
|
|
||||||
- `BigDecimal::unscaledValue()` has been renamed to `getUnscaledValue()`
|
|
||||||
- `BigDecimal::scale()` has been renamed to `getScale()`
|
|
||||||
- `BigDecimal::integral()` has been renamed to `getIntegral()`
|
|
||||||
- `BigDecimal::fraction()` has been renamed to `getFraction()`
|
|
||||||
- `BigRational::numerator()` has been renamed to `getNumerator()`
|
|
||||||
- `BigRational::denominator()` has been renamed to `getDenominator()`
|
|
||||||
|
|
||||||
Classes renamed:
|
|
||||||
|
|
||||||
- `ArithmeticException` has been renamed to `MathException`
|
|
||||||
|
|
||||||
## [0.6.2](https://github.com/brick/math/releases/tag/0.6.2) - 2017-10-02
|
|
||||||
|
|
||||||
The base class for all exceptions is now `MathException`.
|
|
||||||
`ArithmeticException` has been deprecated, and will be removed in 0.7.0.
|
|
||||||
|
|
||||||
## [0.6.1](https://github.com/brick/math/releases/tag/0.6.1) - 2017-10-02
|
|
||||||
|
|
||||||
A number of methods have been renamed:
|
|
||||||
|
|
||||||
- `BigNumber:sign()` is deprecated; use `getSign()` instead
|
|
||||||
- `BigDecimal::unscaledValue()` is deprecated; use `getUnscaledValue()` instead
|
|
||||||
- `BigDecimal::scale()` is deprecated; use `getScale()` instead
|
|
||||||
- `BigDecimal::integral()` is deprecated; use `getIntegral()` instead
|
|
||||||
- `BigDecimal::fraction()` is deprecated; use `getFraction()` instead
|
|
||||||
- `BigRational::numerator()` is deprecated; use `getNumerator()` instead
|
|
||||||
- `BigRational::denominator()` is deprecated; use `getDenominator()` instead
|
|
||||||
|
|
||||||
The old methods will be removed in version 0.7.0.
|
|
||||||
|
|
||||||
## [0.6.0](https://github.com/brick/math/releases/tag/0.6.0) - 2017-08-25
|
|
||||||
|
|
||||||
- Minimum PHP version is now [7.1](https://gophp71.org/); for PHP 5.6 and PHP 7.0 support, use version `0.5`
|
|
||||||
- Deprecated method `BigDecimal::withScale()` has been removed; use `toScale()` instead
|
|
||||||
- Method `BigNumber::toInteger()` has been renamed to `toInt()`
|
|
||||||
|
|
||||||
## [0.5.4](https://github.com/brick/math/releases/tag/0.5.4) - 2016-10-17
|
|
||||||
|
|
||||||
`BigNumber` classes now implement [JsonSerializable](http://php.net/manual/en/class.jsonserializable.php).
|
|
||||||
The JSON output is always a string.
|
|
||||||
|
|
||||||
## [0.5.3](https://github.com/brick/math/releases/tag/0.5.3) - 2016-03-31
|
|
||||||
|
|
||||||
This is a bugfix release. Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.
|
|
||||||
|
|
||||||
## [0.5.2](https://github.com/brick/math/releases/tag/0.5.2) - 2015-08-06
|
|
||||||
|
|
||||||
The `$scale` parameter of `BigDecimal::dividedBy()` is now optional again.
|
|
||||||
|
|
||||||
## [0.5.1](https://github.com/brick/math/releases/tag/0.5.1) - 2015-07-05
|
|
||||||
|
|
||||||
**New method: `BigNumber::toScale()`**
|
|
||||||
|
|
||||||
This allows to convert any `BigNumber` to a `BigDecimal` with a given scale, using rounding if necessary.
|
|
||||||
|
|
||||||
## [0.5.0](https://github.com/brick/math/releases/tag/0.5.0) - 2015-07-04
|
|
||||||
|
|
||||||
**New features**
|
|
||||||
- Common `BigNumber` interface for all classes, with the following methods:
|
|
||||||
- `sign()` and derived methods (`isZero()`, `isPositive()`, ...)
|
|
||||||
- `compareTo()` and derived methods (`isEqualTo()`, `isGreaterThan()`, ...) that work across different `BigNumber` types
|
|
||||||
- `toBigInteger()`, `toBigDecimal()`, `toBigRational`() conversion methods
|
|
||||||
- `toInteger()` and `toFloat()` conversion methods to native types
|
|
||||||
- Unified `of()` behaviour: every class now accepts any type of number, provided that it can be safely converted to the current type
|
|
||||||
- New method: `BigDecimal::exactlyDividedBy()`; this method automatically computes the scale of the result, provided that the division yields a finite number of digits
|
|
||||||
- New methods: `BigRational::quotient()` and `remainder()`
|
|
||||||
- Fine-grained exceptions: `DivisionByZeroException`, `RoundingNecessaryException`, `NumberFormatException`
|
|
||||||
- Factory methods `zero()`, `one()` and `ten()` available in all classes
|
|
||||||
- Rounding mode reintroduced in `BigInteger::dividedBy()`
|
|
||||||
|
|
||||||
This release also comes with many performance improvements.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Breaking changes**
|
|
||||||
- `BigInteger`:
|
|
||||||
- `getSign()` is renamed to `sign()`
|
|
||||||
- `toString()` is renamed to `toBase()`
|
|
||||||
- `BigInteger::dividedBy()` now throws an exception by default if the remainder is not zero; use `quotient()` to get the previous behaviour
|
|
||||||
- `BigDecimal`:
|
|
||||||
- `getSign()` is renamed to `sign()`
|
|
||||||
- `getUnscaledValue()` is renamed to `unscaledValue()`
|
|
||||||
- `getScale()` is renamed to `scale()`
|
|
||||||
- `getIntegral()` is renamed to `integral()`
|
|
||||||
- `getFraction()` is renamed to `fraction()`
|
|
||||||
- `divideAndRemainder()` is renamed to `quotientAndRemainder()`
|
|
||||||
- `dividedBy()` now takes a **mandatory** `$scale` parameter **before** the rounding mode
|
|
||||||
- `toBigInteger()` does not accept a `$roundingMode` parameter anymore
|
|
||||||
- `toBigRational()` does not simplify the fraction anymore; explicitly add `->simplified()` to get the previous behaviour
|
|
||||||
- `BigRational`:
|
|
||||||
- `getSign()` is renamed to `sign()`
|
|
||||||
- `getNumerator()` is renamed to `numerator()`
|
|
||||||
- `getDenominator()` is renamed to `denominator()`
|
|
||||||
- `of()` is renamed to `nd()`, while `parse()` is renamed to `of()`
|
|
||||||
- Miscellaneous:
|
|
||||||
- `ArithmeticException` is moved to an `Exception\` sub-namespace
|
|
||||||
- `of()` factory methods now throw `NumberFormatException` instead of `InvalidArgumentException`
|
|
||||||
|
|
||||||
## [0.4.3](https://github.com/brick/math/releases/tag/0.4.3) - 2016-03-31
|
|
||||||
|
|
||||||
Backport of two bug fixes from the 0.5 branch:
|
|
||||||
- `BigInteger::parse()` did not always throw `InvalidArgumentException` as expected
|
|
||||||
- Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.
|
|
||||||
|
|
||||||
## [0.4.2](https://github.com/brick/math/releases/tag/0.4.2) - 2015-06-16
|
|
||||||
|
|
||||||
New method: `BigDecimal::stripTrailingZeros()`
|
|
||||||
|
|
||||||
## [0.4.1](https://github.com/brick/math/releases/tag/0.4.1) - 2015-06-12
|
|
||||||
|
|
||||||
Introducing a `BigRational` class, to perform calculations on fractions of any size.
|
|
||||||
|
|
||||||
## [0.4.0](https://github.com/brick/math/releases/tag/0.4.0) - 2015-06-12
|
|
||||||
|
|
||||||
Rounding modes have been removed from `BigInteger`, and are now a concept specific to `BigDecimal`.
|
|
||||||
|
|
||||||
`BigInteger::dividedBy()` now always returns the quotient of the division.
|
|
||||||
|
|
||||||
## [0.3.5](https://github.com/brick/math/releases/tag/0.3.5) - 2016-03-31
|
|
||||||
|
|
||||||
Backport of two bug fixes from the 0.5 branch:
|
|
||||||
|
|
||||||
- `BigInteger::parse()` did not always throw `InvalidArgumentException` as expected
|
|
||||||
- Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.
|
|
||||||
|
|
||||||
## [0.3.4](https://github.com/brick/math/releases/tag/0.3.4) - 2015-06-11
|
|
||||||
|
|
||||||
New methods:
|
|
||||||
- `BigInteger::remainder()` returns the remainder of a division only
|
|
||||||
- `BigInteger::gcd()` returns the greatest common divisor of two numbers
|
|
||||||
|
|
||||||
## [0.3.3](https://github.com/brick/math/releases/tag/0.3.3) - 2015-06-07
|
|
||||||
|
|
||||||
Fix `toString()` not handling negative numbers.
|
|
||||||
|
|
||||||
## [0.3.2](https://github.com/brick/math/releases/tag/0.3.2) - 2015-06-07
|
|
||||||
|
|
||||||
`BigInteger` and `BigDecimal` now have a `getSign()` method that returns:
|
|
||||||
- `-1` if the number is negative
|
|
||||||
- `0` if the number is zero
|
|
||||||
- `1` if the number is positive
|
|
||||||
|
|
||||||
## [0.3.1](https://github.com/brick/math/releases/tag/0.3.1) - 2015-06-05
|
|
||||||
|
|
||||||
Minor performance improvements
|
|
||||||
|
|
||||||
## [0.3.0](https://github.com/brick/math/releases/tag/0.3.0) - 2015-06-04
|
|
||||||
|
|
||||||
The `$roundingMode` and `$scale` parameters have been swapped in `BigDecimal::dividedBy()`.
|
|
||||||
|
|
||||||
## [0.2.2](https://github.com/brick/math/releases/tag/0.2.2) - 2015-06-04
|
|
||||||
|
|
||||||
Stronger immutability guarantee for `BigInteger` and `BigDecimal`.
|
|
||||||
|
|
||||||
So far, it would have been possible to break immutability of these classes by calling the `unserialize()` internal function. This release fixes that.
|
|
||||||
|
|
||||||
## [0.2.1](https://github.com/brick/math/releases/tag/0.2.1) - 2015-06-02
|
|
||||||
|
|
||||||
Added `BigDecimal::divideAndRemainder()`
|
|
||||||
|
|
||||||
## [0.2.0](https://github.com/brick/math/releases/tag/0.2.0) - 2015-05-22
|
|
||||||
|
|
||||||
- `min()` and `max()` do not accept an `array` anymore, but a variable number of parameters
|
|
||||||
- **minimum PHP version is now 5.6**
|
|
||||||
- continuous integration with PHP 7
|
|
||||||
|
|
||||||
## [0.1.1](https://github.com/brick/math/releases/tag/0.1.1) - 2014-09-01
|
|
||||||
|
|
||||||
- Added `BigInteger::power()`
|
|
||||||
- Added HHVM support
|
|
||||||
|
|
||||||
## [0.1.0](https://github.com/brick/math/releases/tag/0.1.0) - 2014-08-31
|
|
||||||
|
|
||||||
First beta release.
|
|
||||||
Vendored
-20
@@ -1,20 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013-present Benjamin Morel
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
Vendored
-39
@@ -1,39 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "brick/math",
|
|
||||||
"description": "Arbitrary-precision arithmetic library",
|
|
||||||
"type": "library",
|
|
||||||
"keywords": [
|
|
||||||
"Brick",
|
|
||||||
"Math",
|
|
||||||
"Mathematics",
|
|
||||||
"Arbitrary-precision",
|
|
||||||
"Arithmetic",
|
|
||||||
"BigInteger",
|
|
||||||
"BigDecimal",
|
|
||||||
"BigRational",
|
|
||||||
"BigNumber",
|
|
||||||
"Bignum",
|
|
||||||
"Decimal",
|
|
||||||
"Rational",
|
|
||||||
"Integer"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"require": {
|
|
||||||
"php": "^8.2"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpunit/phpunit": "^11.5",
|
|
||||||
"php-coveralls/php-coveralls": "^2.2",
|
|
||||||
"phpstan/phpstan": "2.1.22"
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Brick\\Math\\": "src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload-dev": {
|
|
||||||
"psr-4": {
|
|
||||||
"Brick\\Math\\Tests\\": "tests/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Vendored
-975
@@ -1,975 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math;
|
|
||||||
|
|
||||||
use Brick\Math\Exception\DivisionByZeroException;
|
|
||||||
use Brick\Math\Exception\MathException;
|
|
||||||
use Brick\Math\Exception\NegativeNumberException;
|
|
||||||
use Brick\Math\Exception\RoundingNecessaryException;
|
|
||||||
use Brick\Math\Internal\Calculator;
|
|
||||||
use Brick\Math\Internal\CalculatorRegistry;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use LogicException;
|
|
||||||
use Override;
|
|
||||||
|
|
||||||
use function func_num_args;
|
|
||||||
use function in_array;
|
|
||||||
use function intdiv;
|
|
||||||
use function max;
|
|
||||||
use function rtrim;
|
|
||||||
use function sprintf;
|
|
||||||
use function str_pad;
|
|
||||||
use function str_repeat;
|
|
||||||
use function strlen;
|
|
||||||
use function substr;
|
|
||||||
use function trigger_error;
|
|
||||||
|
|
||||||
use const E_USER_DEPRECATED;
|
|
||||||
use const STR_PAD_LEFT;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An arbitrarily large decimal number.
|
|
||||||
*
|
|
||||||
* This class is immutable.
|
|
||||||
*
|
|
||||||
* The scale of the number is the number of digits after the decimal point. It is always positive or zero.
|
|
||||||
*/
|
|
||||||
final readonly class BigDecimal extends BigNumber
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The unscaled value of this decimal number.
|
|
||||||
*
|
|
||||||
* This is a string of digits with an optional leading minus sign.
|
|
||||||
* No leading zero must be present.
|
|
||||||
* No leading minus sign must be present if the value is 0.
|
|
||||||
*/
|
|
||||||
private string $value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The scale (number of digits after the decimal point) of this decimal number.
|
|
||||||
*
|
|
||||||
* This must be zero or more.
|
|
||||||
*/
|
|
||||||
private int $scale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Protected constructor. Use a factory method to obtain an instance.
|
|
||||||
*
|
|
||||||
* @param string $value The unscaled value, validated.
|
|
||||||
* @param int $scale The scale, validated.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
protected function __construct(string $value, int $scale = 0)
|
|
||||||
{
|
|
||||||
$this->value = $value;
|
|
||||||
$this->scale = $scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a BigDecimal from an unscaled value and a scale.
|
|
||||||
*
|
|
||||||
* Example: `(12345, 3)` will result in the BigDecimal `12.345`.
|
|
||||||
*
|
|
||||||
* A negative scale is normalized to zero by appending zeros to the unscaled value.
|
|
||||||
*
|
|
||||||
* Example: `(12345, -3)` will result in the BigDecimal `12345000`.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $value The unscaled value. Must be convertible to a BigInteger.
|
|
||||||
* @param int $scale The scale of the number. If negative, the scale will be set to zero
|
|
||||||
* and the unscaled value will be adjusted accordingly.
|
|
||||||
*
|
|
||||||
* @throws MathException If the value is not valid, or is not convertible to a BigInteger.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function ofUnscaledValue(BigNumber|int|float|string $value, int $scale = 0): BigDecimal
|
|
||||||
{
|
|
||||||
$value = BigInteger::of($value)->toString();
|
|
||||||
|
|
||||||
if ($scale < 0) {
|
|
||||||
if ($value !== '0') {
|
|
||||||
$value .= str_repeat('0', -$scale);
|
|
||||||
}
|
|
||||||
$scale = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BigDecimal($value, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a BigDecimal representing zero, with a scale of zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function zero(): BigDecimal
|
|
||||||
{
|
|
||||||
/** @var BigDecimal|null $zero */
|
|
||||||
static $zero;
|
|
||||||
|
|
||||||
if ($zero === null) {
|
|
||||||
$zero = new BigDecimal('0');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a BigDecimal representing one, with a scale of zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function one(): BigDecimal
|
|
||||||
{
|
|
||||||
/** @var BigDecimal|null $one */
|
|
||||||
static $one;
|
|
||||||
|
|
||||||
if ($one === null) {
|
|
||||||
$one = new BigDecimal('1');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $one;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a BigDecimal representing ten, with a scale of zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function ten(): BigDecimal
|
|
||||||
{
|
|
||||||
/** @var BigDecimal|null $ten */
|
|
||||||
static $ten;
|
|
||||||
|
|
||||||
if ($ten === null) {
|
|
||||||
$ten = new BigDecimal('10');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ten;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sum of this number and the given one.
|
|
||||||
*
|
|
||||||
* The result has a scale of `max($this->scale, $that->scale)`.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The number to add. Must be convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @throws MathException If the number is not valid, or is not convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function plus(BigNumber|int|float|string $that): BigDecimal
|
|
||||||
{
|
|
||||||
$that = BigDecimal::of($that);
|
|
||||||
|
|
||||||
if ($that->value === '0' && $that->scale <= $this->scale) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->value === '0' && $this->scale <= $that->scale) {
|
|
||||||
return $that;
|
|
||||||
}
|
|
||||||
|
|
||||||
[$a, $b] = $this->scaleValues($this, $that);
|
|
||||||
|
|
||||||
$value = CalculatorRegistry::get()->add($a, $b);
|
|
||||||
$scale = max($this->scale, $that->scale);
|
|
||||||
|
|
||||||
return new BigDecimal($value, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the difference of this number and the given one.
|
|
||||||
*
|
|
||||||
* The result has a scale of `max($this->scale, $that->scale)`.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The number to subtract. Must be convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @throws MathException If the number is not valid, or is not convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function minus(BigNumber|int|float|string $that): BigDecimal
|
|
||||||
{
|
|
||||||
$that = BigDecimal::of($that);
|
|
||||||
|
|
||||||
if ($that->value === '0' && $that->scale <= $this->scale) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
[$a, $b] = $this->scaleValues($this, $that);
|
|
||||||
|
|
||||||
$value = CalculatorRegistry::get()->sub($a, $b);
|
|
||||||
$scale = max($this->scale, $that->scale);
|
|
||||||
|
|
||||||
return new BigDecimal($value, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the product of this number and the given one.
|
|
||||||
*
|
|
||||||
* The result has a scale of `$this->scale + $that->scale`.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The multiplier. Must be convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @throws MathException If the multiplier is not valid, or is not convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function multipliedBy(BigNumber|int|float|string $that): BigDecimal
|
|
||||||
{
|
|
||||||
$that = BigDecimal::of($that);
|
|
||||||
|
|
||||||
if ($that->value === '1' && $that->scale === 0) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->value === '1' && $this->scale === 0) {
|
|
||||||
return $that;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = CalculatorRegistry::get()->mul($this->value, $that->value);
|
|
||||||
$scale = $this->scale + $that->scale;
|
|
||||||
|
|
||||||
return new BigDecimal($value, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the result of the division of this number by the given one, at the given scale.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
|
|
||||||
* @param int|null $scale The desired scale. Omitting this parameter is deprecated; it will be required in 0.15.
|
|
||||||
* @param RoundingMode $roundingMode An optional rounding mode, defaults to Unnecessary.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If the scale is negative.
|
|
||||||
* @throws MathException If the divisor is not valid, or is not convertible to a BigDecimal.
|
|
||||||
* @throws DivisionByZeroException If the divisor is zero.
|
|
||||||
* @throws RoundingNecessaryException If RoundingMode::Unnecessary is used and the result cannot be represented
|
|
||||||
* exactly at the given scale.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function dividedBy(BigNumber|int|float|string $that, ?int $scale = null, RoundingMode $roundingMode = RoundingMode::Unnecessary): BigDecimal
|
|
||||||
{
|
|
||||||
$that = BigDecimal::of($that);
|
|
||||||
|
|
||||||
if ($that->isZero()) {
|
|
||||||
throw DivisionByZeroException::divisionByZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($scale === null) {
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
trigger_error(
|
|
||||||
'Not passing a $scale to BigDecimal::dividedBy() is deprecated. ' .
|
|
||||||
'Use $a->dividedBy($b, $a->getScale(), $roundingMode) to retain current behavior.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
$scale = $this->scale;
|
|
||||||
} elseif ($scale < 0) {
|
|
||||||
throw new InvalidArgumentException('Scale must not be negative.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($that->value === '1' && $that->scale === 0 && $scale === $this->scale) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
$p = $this->valueWithMinScale($that->scale + $scale);
|
|
||||||
$q = $that->valueWithMinScale($this->scale - $scale);
|
|
||||||
|
|
||||||
$result = CalculatorRegistry::get()->divRound($p, $q, $roundingMode);
|
|
||||||
|
|
||||||
return new BigDecimal($result, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the exact result of the division of this number by the given one.
|
|
||||||
*
|
|
||||||
* The scale of the result is automatically calculated to fit all the fraction digits.
|
|
||||||
*
|
|
||||||
* @deprecated Will be removed in 0.15. Use dividedByExact() instead.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @throws MathException If the divisor is not a valid number, is not convertible to a BigDecimal, is zero,
|
|
||||||
* or the result yields an infinite number of digits.
|
|
||||||
*/
|
|
||||||
public function exactlyDividedBy(BigNumber|int|float|string $that): BigDecimal
|
|
||||||
{
|
|
||||||
trigger_error(
|
|
||||||
'BigDecimal::exactlyDividedBy() is deprecated and will be removed in 0.15. Use dividedByExact() instead.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->dividedByExact($that);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the exact result of the division of this number by the given one.
|
|
||||||
*
|
|
||||||
* The scale of the result is automatically calculated to fit all the fraction digits.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @throws MathException If the divisor is not valid, or is not convertible to a BigDecimal.
|
|
||||||
* @throws DivisionByZeroException If the divisor is zero.
|
|
||||||
* @throws RoundingNecessaryException If the result yields an infinite number of digits.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function dividedByExact(BigNumber|int|float|string $that): BigDecimal
|
|
||||||
{
|
|
||||||
$that = BigDecimal::of($that);
|
|
||||||
|
|
||||||
if ($that->value === '0') {
|
|
||||||
throw DivisionByZeroException::divisionByZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
[, $b] = $this->scaleValues($this, $that);
|
|
||||||
|
|
||||||
$d = rtrim($b, '0');
|
|
||||||
$scale = strlen($b) - strlen($d);
|
|
||||||
|
|
||||||
$calculator = CalculatorRegistry::get();
|
|
||||||
|
|
||||||
foreach ([5, 2] as $prime) {
|
|
||||||
for (; ;) {
|
|
||||||
$lastDigit = (int) $d[-1];
|
|
||||||
|
|
||||||
if ($lastDigit % $prime !== 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$d = $calculator->divQ($d, (string) $prime);
|
|
||||||
$scale++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->dividedBy($that, $scale)->strippedOfTrailingZeros();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns this number exponentiated to the given value.
|
|
||||||
*
|
|
||||||
* The result has a scale of `$this->scale * $exponent`.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function power(int $exponent): BigDecimal
|
|
||||||
{
|
|
||||||
if ($exponent === 0) {
|
|
||||||
return BigDecimal::one();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($exponent === 1) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($exponent < 0 || $exponent > Calculator::MAX_POWER) {
|
|
||||||
throw new InvalidArgumentException(sprintf(
|
|
||||||
'The exponent %d is not in the range 0 to %d.',
|
|
||||||
$exponent,
|
|
||||||
Calculator::MAX_POWER,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BigDecimal(CalculatorRegistry::get()->pow($this->value, $exponent), $this->scale * $exponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the quotient of the division of this number by the given one.
|
|
||||||
*
|
|
||||||
* The quotient has a scale of `0`.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* - `7.5` quotient `3` returns `2`
|
|
||||||
* - `7.5` quotient `-3` returns `-2`
|
|
||||||
* - `-7.5` quotient `3` returns `-2`
|
|
||||||
* - `-7.5` quotient `-3` returns `2`
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @throws MathException If the divisor is not valid, or is not convertible to a BigDecimal.
|
|
||||||
* @throws DivisionByZeroException If the divisor is zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function quotient(BigNumber|int|float|string $that): BigDecimal
|
|
||||||
{
|
|
||||||
$that = BigDecimal::of($that);
|
|
||||||
|
|
||||||
if ($that->isZero()) {
|
|
||||||
throw DivisionByZeroException::divisionByZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
$p = $this->valueWithMinScale($that->scale);
|
|
||||||
$q = $that->valueWithMinScale($this->scale);
|
|
||||||
|
|
||||||
$quotient = CalculatorRegistry::get()->divQ($p, $q);
|
|
||||||
|
|
||||||
return new BigDecimal($quotient, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the remainder of the division of this number by the given one.
|
|
||||||
*
|
|
||||||
* The remainder has a scale of `max($this->scale, $that->scale)`.
|
|
||||||
* The remainder, when non-zero, has the same sign as the dividend.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* - `7.5` remainder `3` returns `1.5`
|
|
||||||
* - `7.5` remainder `-3` returns `1.5`
|
|
||||||
* - `-7.5` remainder `3` returns `-1.5`
|
|
||||||
* - `-7.5` remainder `-3` returns `-1.5`
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @throws MathException If the divisor is not valid, or is not convertible to a BigDecimal.
|
|
||||||
* @throws DivisionByZeroException If the divisor is zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function remainder(BigNumber|int|float|string $that): BigDecimal
|
|
||||||
{
|
|
||||||
$that = BigDecimal::of($that);
|
|
||||||
|
|
||||||
if ($that->isZero()) {
|
|
||||||
throw DivisionByZeroException::divisionByZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
$p = $this->valueWithMinScale($that->scale);
|
|
||||||
$q = $that->valueWithMinScale($this->scale);
|
|
||||||
|
|
||||||
$remainder = CalculatorRegistry::get()->divR($p, $q);
|
|
||||||
|
|
||||||
$scale = max($this->scale, $that->scale);
|
|
||||||
|
|
||||||
return new BigDecimal($remainder, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the quotient and remainder of the division of this number by the given one.
|
|
||||||
*
|
|
||||||
* The quotient has a scale of `0`, and the remainder has a scale of `max($this->scale, $that->scale)`.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* - `7.5` quotientAndRemainder `3` returns [`2`, `1.5`]
|
|
||||||
* - `7.5` quotientAndRemainder `-3` returns [`-2`, `1.5`]
|
|
||||||
* - `-7.5` quotientAndRemainder `3` returns [`-2`, `-1.5`]
|
|
||||||
* - `-7.5` quotientAndRemainder `-3` returns [`2`, `-1.5`]
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @return array{BigDecimal, BigDecimal} An array containing the quotient and the remainder.
|
|
||||||
*
|
|
||||||
* @throws MathException If the divisor is not valid, or is not convertible to a BigDecimal.
|
|
||||||
* @throws DivisionByZeroException If the divisor is zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function quotientAndRemainder(BigNumber|int|float|string $that): array
|
|
||||||
{
|
|
||||||
$that = BigDecimal::of($that);
|
|
||||||
|
|
||||||
if ($that->isZero()) {
|
|
||||||
throw DivisionByZeroException::divisionByZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
$p = $this->valueWithMinScale($that->scale);
|
|
||||||
$q = $that->valueWithMinScale($this->scale);
|
|
||||||
|
|
||||||
[$quotient, $remainder] = CalculatorRegistry::get()->divQR($p, $q);
|
|
||||||
|
|
||||||
$scale = max($this->scale, $that->scale);
|
|
||||||
|
|
||||||
$quotient = new BigDecimal($quotient, 0);
|
|
||||||
$remainder = new BigDecimal($remainder, $scale);
|
|
||||||
|
|
||||||
return [$quotient, $remainder];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the square root of this number, rounded to the given scale according to the given rounding mode.
|
|
||||||
*
|
|
||||||
* @param int $scale The target scale. Must be non-negative.
|
|
||||||
* @param RoundingMode $roundingMode The rounding mode to use, defaults to Down.
|
|
||||||
* ⚠️ WARNING: the default rounding mode was kept as Down for backward
|
|
||||||
* compatibility, but will change to Unnecessary in version 0.15. Pass a rounding
|
|
||||||
* mode explicitly to avoid this upcoming breaking change.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If the scale is negative.
|
|
||||||
* @throws NegativeNumberException If this number is negative.
|
|
||||||
* @throws RoundingNecessaryException If RoundingMode::Unnecessary is used and the result cannot be represented
|
|
||||||
* exactly at the given scale.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function sqrt(int $scale, RoundingMode $roundingMode = RoundingMode::Down): BigDecimal
|
|
||||||
{
|
|
||||||
if (func_num_args() === 1) {
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
trigger_error(
|
|
||||||
'The default rounding mode of BigDecimal::sqrt() will change from Down to Unnecessary in version 0.15. ' .
|
|
||||||
'Pass a rounding mode explicitly to avoid this breaking change.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($scale < 0) {
|
|
||||||
throw new InvalidArgumentException('Scale must not be negative.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->value === '0') {
|
|
||||||
return new BigDecimal('0', $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->value[0] === '-') {
|
|
||||||
throw new NegativeNumberException('Cannot calculate the square root of a negative number.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->value;
|
|
||||||
$inputScale = $this->scale;
|
|
||||||
|
|
||||||
if ($inputScale % 2 !== 0) {
|
|
||||||
$value .= '0';
|
|
||||||
$inputScale++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$calculator = CalculatorRegistry::get();
|
|
||||||
|
|
||||||
// Keep one extra digit for rounding.
|
|
||||||
$intermediateScale = max($scale, intdiv($inputScale, 2)) + 1;
|
|
||||||
$value .= str_repeat('0', 2 * $intermediateScale - $inputScale);
|
|
||||||
|
|
||||||
$sqrt = $calculator->sqrt($value);
|
|
||||||
$isExact = $calculator->mul($sqrt, $sqrt) === $value;
|
|
||||||
|
|
||||||
if (! $isExact) {
|
|
||||||
if ($roundingMode === RoundingMode::Unnecessary) {
|
|
||||||
throw RoundingNecessaryException::roundingNecessary();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Non-perfect-square sqrt is irrational, so the true value is strictly above this sqrt floor.
|
|
||||||
// Add one at the intermediate scale to guarantee Up/Ceiling round up at the target scale.
|
|
||||||
if (in_array($roundingMode, [RoundingMode::Up, RoundingMode::Ceiling], true)) {
|
|
||||||
$sqrt = $calculator->add($sqrt, '1');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Irrational sqrt cannot land exactly on a midpoint; treat tie-to-down modes as HalfUp.
|
|
||||||
elseif (in_array($roundingMode, [RoundingMode::HalfDown, RoundingMode::HalfEven, RoundingMode::HalfFloor], true)) {
|
|
||||||
$roundingMode = RoundingMode::HalfUp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (new BigDecimal($sqrt, $intermediateScale))->toScale($scale, $roundingMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a copy of this BigDecimal with the decimal point moved to the left by the given number of places.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function withPointMovedLeft(int $n): BigDecimal
|
|
||||||
{
|
|
||||||
if ($n === 0) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($n < 0) {
|
|
||||||
return $this->withPointMovedRight(-$n);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BigDecimal($this->value, $this->scale + $n);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a copy of this BigDecimal with the decimal point moved to the right by the given number of places.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function withPointMovedRight(int $n): BigDecimal
|
|
||||||
{
|
|
||||||
if ($n === 0) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($n < 0) {
|
|
||||||
return $this->withPointMovedLeft(-$n);
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->value;
|
|
||||||
$scale = $this->scale - $n;
|
|
||||||
|
|
||||||
if ($scale < 0) {
|
|
||||||
if ($value !== '0') {
|
|
||||||
$value .= str_repeat('0', -$scale);
|
|
||||||
}
|
|
||||||
$scale = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BigDecimal($value, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a copy of this BigDecimal with any trailing zeros removed from the fractional part.
|
|
||||||
*
|
|
||||||
* @deprecated Use strippedOfTrailingZeros() instead.
|
|
||||||
*/
|
|
||||||
public function stripTrailingZeros(): BigDecimal
|
|
||||||
{
|
|
||||||
trigger_error(
|
|
||||||
'BigDecimal::stripTrailingZeros() is deprecated, use strippedOfTrailingZeros() instead.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->strippedOfTrailingZeros();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a copy of this BigDecimal with any trailing zeros removed from the fractional part.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function strippedOfTrailingZeros(): BigDecimal
|
|
||||||
{
|
|
||||||
if ($this->scale === 0) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
$trimmedValue = rtrim($this->value, '0');
|
|
||||||
|
|
||||||
if ($trimmedValue === '') {
|
|
||||||
return BigDecimal::zero();
|
|
||||||
}
|
|
||||||
|
|
||||||
$trimmableZeros = strlen($this->value) - strlen($trimmedValue);
|
|
||||||
|
|
||||||
if ($trimmableZeros === 0) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($trimmableZeros > $this->scale) {
|
|
||||||
$trimmableZeros = $this->scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = substr($this->value, 0, -$trimmableZeros);
|
|
||||||
$scale = $this->scale - $trimmableZeros;
|
|
||||||
|
|
||||||
return new BigDecimal($value, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function negated(): static
|
|
||||||
{
|
|
||||||
return new BigDecimal(CalculatorRegistry::get()->neg($this->value), $this->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function compareTo(BigNumber|int|float|string $that): int
|
|
||||||
{
|
|
||||||
$that = BigNumber::of($that);
|
|
||||||
|
|
||||||
if ($that instanceof BigInteger) {
|
|
||||||
$that = $that->toBigDecimal();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($that instanceof BigDecimal) {
|
|
||||||
[$a, $b] = $this->scaleValues($this, $that);
|
|
||||||
|
|
||||||
return CalculatorRegistry::get()->cmp($a, $b);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -$that->compareTo($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function getSign(): int
|
|
||||||
{
|
|
||||||
return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function getUnscaledValue(): BigInteger
|
|
||||||
{
|
|
||||||
return self::newBigInteger($this->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function getScale(): int
|
|
||||||
{
|
|
||||||
return $this->scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of significant digits in the number.
|
|
||||||
*
|
|
||||||
* This is the number of digits to both sides of the decimal point, stripped of leading zeros.
|
|
||||||
* The sign has no impact on the result.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
* 0 => 0
|
|
||||||
* 0.0 => 0
|
|
||||||
* 123 => 3
|
|
||||||
* 123.456 => 6
|
|
||||||
* 0.00123 => 3
|
|
||||||
* 0.0012300 => 5
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function getPrecision(): int
|
|
||||||
{
|
|
||||||
$value = $this->value;
|
|
||||||
|
|
||||||
if ($value === '0') {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$length = strlen($value);
|
|
||||||
|
|
||||||
return ($value[0] === '-') ? $length - 1 : $length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representing the integral part of this decimal number.
|
|
||||||
*
|
|
||||||
* Example: `-123.456` => `-123`.
|
|
||||||
*
|
|
||||||
* @deprecated Will be removed in 0.15 and re-introduced as returning BigInteger in 0.16.
|
|
||||||
*/
|
|
||||||
public function getIntegralPart(): string
|
|
||||||
{
|
|
||||||
trigger_error(
|
|
||||||
'BigDecimal::getIntegralPart() is deprecated and will be removed in 0.15. It will be re-introduced as returning BigInteger in 0.16.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($this->scale === 0) {
|
|
||||||
return $this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->getUnscaledValueWithLeadingZeros();
|
|
||||||
|
|
||||||
return substr($value, 0, -$this->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representing the fractional part of this decimal number.
|
|
||||||
*
|
|
||||||
* If the scale is zero, an empty string is returned.
|
|
||||||
*
|
|
||||||
* Examples: `-123.456` => '456', `123` => ''.
|
|
||||||
*
|
|
||||||
* @deprecated Will be removed in 0.15 and re-introduced as returning BigDecimal with a different meaning in 0.16.
|
|
||||||
*/
|
|
||||||
public function getFractionalPart(): string
|
|
||||||
{
|
|
||||||
trigger_error(
|
|
||||||
'BigDecimal::getFractionalPart() is deprecated and will be removed in 0.15. It will be re-introduced as returning BigDecimal with a different meaning in 0.16.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($this->scale === 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->getUnscaledValueWithLeadingZeros();
|
|
||||||
|
|
||||||
return substr($value, -$this->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether this decimal number has a non-zero fractional part.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function hasNonZeroFractionalPart(): bool
|
|
||||||
{
|
|
||||||
if ($this->scale === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->getUnscaledValueWithLeadingZeros();
|
|
||||||
|
|
||||||
return substr($value, -$this->scale) !== str_repeat('0', $this->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toBigInteger(): BigInteger
|
|
||||||
{
|
|
||||||
$zeroScaleDecimal = $this->scale === 0 ? $this : $this->dividedBy(1, 0);
|
|
||||||
|
|
||||||
return self::newBigInteger($zeroScaleDecimal->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toBigDecimal(): BigDecimal
|
|
||||||
{
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toBigRational(): BigRational
|
|
||||||
{
|
|
||||||
$numerator = self::newBigInteger($this->value);
|
|
||||||
$denominator = self::newBigInteger('1' . str_repeat('0', $this->scale));
|
|
||||||
|
|
||||||
return self::newBigRational($numerator, $denominator, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::Unnecessary): BigDecimal
|
|
||||||
{
|
|
||||||
if ($scale === $this->scale) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->dividedBy(BigDecimal::one(), $scale, $roundingMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toInt(): int
|
|
||||||
{
|
|
||||||
return $this->toBigInteger()->toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toFloat(): float
|
|
||||||
{
|
|
||||||
return (float) $this->toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return numeric-string
|
|
||||||
*/
|
|
||||||
#[Override]
|
|
||||||
public function toString(): string
|
|
||||||
{
|
|
||||||
if ($this->scale === 0) {
|
|
||||||
/** @var numeric-string */
|
|
||||||
return $this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->getUnscaledValueWithLeadingZeros();
|
|
||||||
|
|
||||||
/** @phpstan-ignore return.type */
|
|
||||||
return substr($value, 0, -$this->scale) . '.' . substr($value, -$this->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is required for serializing the object and SHOULD NOT be accessed directly.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @return array{value: string, scale: int}
|
|
||||||
*/
|
|
||||||
public function __serialize(): array
|
|
||||||
{
|
|
||||||
return ['value' => $this->value, 'scale' => $this->scale];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is only here to allow unserializing the object and cannot be accessed directly.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @param array{value: string, scale: int} $data
|
|
||||||
*
|
|
||||||
* @throws LogicException
|
|
||||||
*/
|
|
||||||
public function __unserialize(array $data): void
|
|
||||||
{
|
|
||||||
/** @phpstan-ignore isset.initializedProperty */
|
|
||||||
if (isset($this->value)) {
|
|
||||||
throw new LogicException('__unserialize() is an internal function, it must not be called directly.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @phpstan-ignore deadCode.unreachable */
|
|
||||||
$this->value = $data['value'];
|
|
||||||
$this->scale = $data['scale'];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
protected static function from(BigNumber $number): static
|
|
||||||
{
|
|
||||||
return $number->toBigDecimal();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Puts the internal values of the given decimal numbers on the same scale.
|
|
||||||
*
|
|
||||||
* @return array{string, string} The scaled integer values of $x and $y.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function scaleValues(BigDecimal $x, BigDecimal $y): array
|
|
||||||
{
|
|
||||||
$a = $x->value;
|
|
||||||
$b = $y->value;
|
|
||||||
|
|
||||||
if ($b !== '0' && $x->scale > $y->scale) {
|
|
||||||
$b .= str_repeat('0', $x->scale - $y->scale);
|
|
||||||
} elseif ($a !== '0' && $x->scale < $y->scale) {
|
|
||||||
$a .= str_repeat('0', $y->scale - $x->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [$a, $b];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function valueWithMinScale(int $scale): string
|
|
||||||
{
|
|
||||||
$value = $this->value;
|
|
||||||
|
|
||||||
if ($this->value !== '0' && $scale > $this->scale) {
|
|
||||||
$value .= str_repeat('0', $scale - $this->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds leading zeros if necessary to the unscaled value to represent the full decimal number.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function getUnscaledValueWithLeadingZeros(): string
|
|
||||||
{
|
|
||||||
$value = $this->value;
|
|
||||||
$targetLength = $this->scale + 1;
|
|
||||||
$negative = ($value[0] === '-');
|
|
||||||
$length = strlen($value);
|
|
||||||
|
|
||||||
if ($negative) {
|
|
||||||
$length--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($length >= $targetLength) {
|
|
||||||
return $this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($negative) {
|
|
||||||
$value = substr($value, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = str_pad($value, $targetLength, '0', STR_PAD_LEFT);
|
|
||||||
|
|
||||||
if ($negative) {
|
|
||||||
$value = '-' . $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Vendored
-1351
File diff suppressed because it is too large
Load Diff
Vendored
-712
@@ -1,712 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math;
|
|
||||||
|
|
||||||
use Brick\Math\Exception\DivisionByZeroException;
|
|
||||||
use Brick\Math\Exception\MathException;
|
|
||||||
use Brick\Math\Exception\NumberFormatException;
|
|
||||||
use Brick\Math\Exception\RoundingNecessaryException;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use JsonSerializable;
|
|
||||||
use Override;
|
|
||||||
use Stringable;
|
|
||||||
|
|
||||||
use function array_shift;
|
|
||||||
use function assert;
|
|
||||||
use function filter_var;
|
|
||||||
use function is_float;
|
|
||||||
use function is_int;
|
|
||||||
use function is_nan;
|
|
||||||
use function is_null;
|
|
||||||
use function ltrim;
|
|
||||||
use function preg_match;
|
|
||||||
use function str_contains;
|
|
||||||
use function str_repeat;
|
|
||||||
use function strlen;
|
|
||||||
use function substr;
|
|
||||||
use function trigger_error;
|
|
||||||
|
|
||||||
use const E_USER_DEPRECATED;
|
|
||||||
use const FILTER_VALIDATE_INT;
|
|
||||||
use const PREG_UNMATCHED_AS_NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for arbitrary-precision numbers.
|
|
||||||
*
|
|
||||||
* This class is sealed: it is part of the public API but should not be subclassed in userland.
|
|
||||||
* Protected methods may change in any version.
|
|
||||||
*
|
|
||||||
* @phpstan-sealed BigInteger|BigDecimal|BigRational
|
|
||||||
*/
|
|
||||||
abstract readonly class BigNumber implements JsonSerializable, Stringable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The regular expression used to parse integer or decimal numbers.
|
|
||||||
*/
|
|
||||||
private const PARSE_REGEXP_NUMERICAL =
|
|
||||||
'/^' .
|
|
||||||
'(?<sign>[\-\+])?' .
|
|
||||||
'(?<integral>[0-9]+)?' .
|
|
||||||
'(?<point>\.)?' .
|
|
||||||
'(?<fractional>[0-9]+)?' .
|
|
||||||
'(?:[eE](?<exponent>[\-\+]?[0-9]+))?' .
|
|
||||||
'$/';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The regular expression used to parse rational numbers.
|
|
||||||
*/
|
|
||||||
private const PARSE_REGEXP_RATIONAL =
|
|
||||||
'/^' .
|
|
||||||
'(?<sign>[\-\+])?' .
|
|
||||||
'(?<numerator>[0-9]+)' .
|
|
||||||
'\/' .
|
|
||||||
'(?<denominator>[0-9]+)' .
|
|
||||||
'$/';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a BigNumber of the given value.
|
|
||||||
*
|
|
||||||
* When of() is called on BigNumber, the concrete return type is dependent on the given value, with the following
|
|
||||||
* rules:
|
|
||||||
*
|
|
||||||
* - BigNumber instances are returned as is
|
|
||||||
* - integer numbers are returned as BigInteger
|
|
||||||
* - floating point numbers are converted to a string then parsed as such (deprecated, will be removed in 0.15)
|
|
||||||
* - strings containing a `/` character are returned as BigRational
|
|
||||||
* - strings containing a `.` character or using an exponential notation are returned as BigDecimal
|
|
||||||
* - strings containing only digits with an optional leading `+` or `-` sign are returned as BigInteger
|
|
||||||
*
|
|
||||||
* When of() is called on BigInteger, BigDecimal, or BigRational, the resulting number is converted to an instance
|
|
||||||
* of the subclass when possible; otherwise a RoundingNecessaryException exception is thrown.
|
|
||||||
*
|
|
||||||
* @throws NumberFormatException If the format of the number is not valid.
|
|
||||||
* @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
|
|
||||||
* @throws RoundingNecessaryException If the value cannot be converted to an instance of the subclass without rounding.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public static function of(BigNumber|int|float|string $value): static
|
|
||||||
{
|
|
||||||
$value = self::_of($value);
|
|
||||||
|
|
||||||
if (static::class === BigNumber::class) {
|
|
||||||
assert($value instanceof static);
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::from($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a BigNumber of the given value, or returns null if the input is null.
|
|
||||||
*
|
|
||||||
* Behaves like of() for non-null values.
|
|
||||||
*
|
|
||||||
* @see BigNumber::of()
|
|
||||||
*
|
|
||||||
* @throws NumberFormatException If the format of the number is not valid.
|
|
||||||
* @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
|
|
||||||
* @throws RoundingNecessaryException If the value cannot be converted to an instance of the subclass without rounding.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public static function ofNullable(BigNumber|int|float|string|null $value): ?static
|
|
||||||
{
|
|
||||||
if (is_null($value)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::of($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the minimum of the given values.
|
|
||||||
*
|
|
||||||
* If several values are equal and minimal, the first one is returned.
|
|
||||||
* This can affect the concrete return type when calling this method on BigNumber.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string ...$values The numbers to compare. All the numbers must be convertible to an
|
|
||||||
* instance of the class this method is called on.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If no values are given.
|
|
||||||
* @throws MathException If a number is not valid, or is not convertible to an instance of the class
|
|
||||||
* this method is called on.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public static function min(BigNumber|int|float|string ...$values): static
|
|
||||||
{
|
|
||||||
$min = null;
|
|
||||||
|
|
||||||
foreach ($values as $value) {
|
|
||||||
$value = static::of($value);
|
|
||||||
|
|
||||||
if ($min === null || $value->isLessThan($min)) {
|
|
||||||
$min = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($min === null) {
|
|
||||||
throw new InvalidArgumentException(__METHOD__ . '() expects at least one value.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $min;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the maximum of the given values.
|
|
||||||
*
|
|
||||||
* If several values are equal and maximal, the first one is returned.
|
|
||||||
* This can affect the concrete return type when calling this method on BigNumber.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string ...$values The numbers to compare. All the numbers must be convertible to an
|
|
||||||
* instance of the class this method is called on.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If no values are given.
|
|
||||||
* @throws MathException If a number is not valid, or is not convertible to an instance of the class
|
|
||||||
* this method is called on.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public static function max(BigNumber|int|float|string ...$values): static
|
|
||||||
{
|
|
||||||
$max = null;
|
|
||||||
|
|
||||||
foreach ($values as $value) {
|
|
||||||
$value = static::of($value);
|
|
||||||
|
|
||||||
if ($max === null || $value->isGreaterThan($max)) {
|
|
||||||
$max = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($max === null) {
|
|
||||||
throw new InvalidArgumentException(__METHOD__ . '() expects at least one value.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $max;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sum of the given values.
|
|
||||||
*
|
|
||||||
* When called on BigNumber, sum() accepts any supported type and returns a result whose type is the widest among
|
|
||||||
* the given values (BigInteger < BigDecimal < BigRational).
|
|
||||||
*
|
|
||||||
* When called on BigInteger, BigDecimal, or BigRational, sum() requires that all values can be converted to that
|
|
||||||
* specific subclass, and returns a result of the same type.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string ...$values The numbers to add. All the numbers must be convertible to an
|
|
||||||
* instance of the class this method is called on.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If no values are given.
|
|
||||||
* @throws MathException If a number is not valid, or is not convertible to an instance of the class
|
|
||||||
* this method is called on.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public static function sum(BigNumber|int|float|string ...$values): static
|
|
||||||
{
|
|
||||||
$first = array_shift($values);
|
|
||||||
|
|
||||||
if ($first === null) {
|
|
||||||
throw new InvalidArgumentException(__METHOD__ . '() expects at least one value.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$sum = static::of($first);
|
|
||||||
|
|
||||||
foreach ($values as $value) {
|
|
||||||
$sum = self::add($sum, static::of($value));
|
|
||||||
}
|
|
||||||
|
|
||||||
assert($sum instanceof static);
|
|
||||||
|
|
||||||
return $sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is equal to the given one.
|
|
||||||
*
|
|
||||||
* @throws MathException If the given number is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isEqualTo(BigNumber|int|float|string $that): bool
|
|
||||||
{
|
|
||||||
return $this->compareTo($that) === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is strictly less than the given one.
|
|
||||||
*
|
|
||||||
* @throws MathException If the given number is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isLessThan(BigNumber|int|float|string $that): bool
|
|
||||||
{
|
|
||||||
return $this->compareTo($that) < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is less than or equal to the given one.
|
|
||||||
*
|
|
||||||
* @throws MathException If the given number is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isLessThanOrEqualTo(BigNumber|int|float|string $that): bool
|
|
||||||
{
|
|
||||||
return $this->compareTo($that) <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is strictly greater than the given one.
|
|
||||||
*
|
|
||||||
* @throws MathException If the given number is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isGreaterThan(BigNumber|int|float|string $that): bool
|
|
||||||
{
|
|
||||||
return $this->compareTo($that) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is greater than or equal to the given one.
|
|
||||||
*
|
|
||||||
* @throws MathException If the given number is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isGreaterThanOrEqualTo(BigNumber|int|float|string $that): bool
|
|
||||||
{
|
|
||||||
return $this->compareTo($that) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number equals zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isZero(): bool
|
|
||||||
{
|
|
||||||
return $this->getSign() === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is strictly negative.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isNegative(): bool
|
|
||||||
{
|
|
||||||
return $this->getSign() < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is negative or zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isNegativeOrZero(): bool
|
|
||||||
{
|
|
||||||
return $this->getSign() <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is strictly positive.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isPositive(): bool
|
|
||||||
{
|
|
||||||
return $this->getSign() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this number is positive or zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function isPositiveOrZero(): bool
|
|
||||||
{
|
|
||||||
return $this->getSign() >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the absolute value of this number.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function abs(): static
|
|
||||||
{
|
|
||||||
return $this->isNegative() ? $this->negated() : $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the negated value of this number.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function negated(): static;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sign of this number.
|
|
||||||
*
|
|
||||||
* Returns -1 if the number is negative, 0 if zero, 1 if positive.
|
|
||||||
*
|
|
||||||
* @return -1|0|1
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function getSign(): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compares this number to the given one.
|
|
||||||
*
|
|
||||||
* Returns -1 if `$this` is lower than, 0 if equal to, 1 if greater than `$that`.
|
|
||||||
*
|
|
||||||
* @return -1|0|1
|
|
||||||
*
|
|
||||||
* @throws MathException If the number is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function compareTo(BigNumber|int|float|string $that): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Limits (clamps) this number between the given minimum and maximum values.
|
|
||||||
*
|
|
||||||
* If the number is lower than $min, returns $min.
|
|
||||||
* If the number is greater than $max, returns $max.
|
|
||||||
* Otherwise, returns this number unchanged.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $min The minimum. Must be convertible to an instance of the class this method is called on.
|
|
||||||
* @param BigNumber|int|float|string $max The maximum. Must be convertible to an instance of the class this method is called on.
|
|
||||||
*
|
|
||||||
* @throws MathException If min/max are not convertible to an instance of the class this method is called on.
|
|
||||||
* @throws InvalidArgumentException If min is greater than max.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function clamp(BigNumber|int|float|string $min, BigNumber|int|float|string $max): static
|
|
||||||
{
|
|
||||||
$min = static::of($min);
|
|
||||||
$max = static::of($max);
|
|
||||||
|
|
||||||
if ($min->isGreaterThan($max)) {
|
|
||||||
throw new InvalidArgumentException('Minimum value must be less than or equal to maximum value.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isLessThan($min)) {
|
|
||||||
return $min;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isGreaterThan($max)) {
|
|
||||||
return $max;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts this number to a BigInteger.
|
|
||||||
*
|
|
||||||
* @throws RoundingNecessaryException If this number cannot be converted to a BigInteger without rounding.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function toBigInteger(): BigInteger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts this number to a BigDecimal.
|
|
||||||
*
|
|
||||||
* @throws RoundingNecessaryException If this number cannot be converted to a BigDecimal without rounding.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function toBigDecimal(): BigDecimal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts this number to a BigRational.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function toBigRational(): BigRational;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts this number to a BigDecimal with the given scale, using rounding if necessary.
|
|
||||||
*
|
|
||||||
* @param int $scale The scale of the resulting `BigDecimal`. Must be non-negative.
|
|
||||||
* @param RoundingMode $roundingMode An optional rounding mode, defaults to Unnecessary.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If the scale is negative.
|
|
||||||
* @throws RoundingNecessaryException If RoundingMode::Unnecessary is used, and this number cannot be converted to
|
|
||||||
* the given scale without rounding.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::Unnecessary): BigDecimal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the exact value of this number as a native integer.
|
|
||||||
*
|
|
||||||
* If this number cannot be converted to a native integer without losing precision, an exception is thrown.
|
|
||||||
* Note that the acceptable range for an integer depends on the platform and differs for 32-bit and 64-bit.
|
|
||||||
*
|
|
||||||
* @throws MathException If this number cannot be exactly converted to a native integer.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function toInt(): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an approximation of this number as a floating-point value.
|
|
||||||
*
|
|
||||||
* Note that this method can discard information as the precision of a floating-point value
|
|
||||||
* is inherently limited.
|
|
||||||
*
|
|
||||||
* If the number is greater than the largest representable floating point number, positive infinity is returned.
|
|
||||||
* If the number is less than the smallest representable floating point number, negative infinity is returned.
|
|
||||||
* This method never returns NaN.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function toFloat(): float;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of this number.
|
|
||||||
*
|
|
||||||
* The output of this method can be parsed by the `of()` factory method; this will yield an object equal to this
|
|
||||||
* one, but possibly of a different type if instantiated through `BigNumber::of()`.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function toString(): string;
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
final public function jsonSerialize(): string
|
|
||||||
{
|
|
||||||
return $this->toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function __toString(): string
|
|
||||||
{
|
|
||||||
return $this->toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overridden by subclasses to convert a BigNumber to an instance of the subclass.
|
|
||||||
*
|
|
||||||
* @throws RoundingNecessaryException If the value cannot be converted.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract protected static function from(BigNumber $number): static;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy method to access BigInteger's protected constructor from sibling classes.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final protected function newBigInteger(string $value): BigInteger
|
|
||||||
{
|
|
||||||
return new BigInteger($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy method to access BigDecimal's protected constructor from sibling classes.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final protected function newBigDecimal(string $value, int $scale = 0): BigDecimal
|
|
||||||
{
|
|
||||||
return new BigDecimal($value, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy method to access BigRational's protected constructor from sibling classes.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final protected function newBigRational(BigInteger $numerator, BigInteger $denominator, bool $checkDenominator): BigRational
|
|
||||||
{
|
|
||||||
return new BigRational($numerator, $denominator, $checkDenominator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws NumberFormatException If the format of the number is not valid.
|
|
||||||
* @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private static function _of(BigNumber|int|float|string $value): BigNumber
|
|
||||||
{
|
|
||||||
if ($value instanceof BigNumber) {
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_int($value)) {
|
|
||||||
return new BigInteger((string) $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_float($value)) {
|
|
||||||
// @phpstan-ignore-next-line
|
|
||||||
trigger_error(
|
|
||||||
'Passing floats to BigNumber::of() and arithmetic methods is deprecated and will be removed in 0.15. ' .
|
|
||||||
'Cast the float to string explicitly to preserve the previous behaviour.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (is_nan($value)) {
|
|
||||||
$value = 'NAN';
|
|
||||||
} else {
|
|
||||||
$value = (string) $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str_contains($value, '/')) {
|
|
||||||
// Rational number
|
|
||||||
if (preg_match(self::PARSE_REGEXP_RATIONAL, $value, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
|
|
||||||
throw NumberFormatException::invalidFormat($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sign = $matches['sign'];
|
|
||||||
$numerator = $matches['numerator'];
|
|
||||||
$denominator = $matches['denominator'];
|
|
||||||
|
|
||||||
$numerator = self::cleanUp($sign, $numerator);
|
|
||||||
$denominator = self::cleanUp(null, $denominator);
|
|
||||||
|
|
||||||
if ($denominator === '0') {
|
|
||||||
throw DivisionByZeroException::denominatorMustNotBeZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BigRational(
|
|
||||||
new BigInteger($numerator),
|
|
||||||
new BigInteger($denominator),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// Integer or decimal number
|
|
||||||
if (preg_match(self::PARSE_REGEXP_NUMERICAL, $value, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
|
|
||||||
throw NumberFormatException::invalidFormat($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sign = $matches['sign'];
|
|
||||||
$point = $matches['point'];
|
|
||||||
$integral = $matches['integral'];
|
|
||||||
$fractional = $matches['fractional'];
|
|
||||||
$exponent = $matches['exponent'];
|
|
||||||
|
|
||||||
if ($integral === null && $fractional === null) {
|
|
||||||
throw NumberFormatException::invalidFormat($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($integral === null) {
|
|
||||||
$integral = '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($point !== null || $exponent !== null) {
|
|
||||||
$fractional ??= '';
|
|
||||||
|
|
||||||
if ($exponent !== null) {
|
|
||||||
if ($exponent[0] === '-') {
|
|
||||||
$exponent = ltrim(substr($exponent, 1), '0') ?: '0';
|
|
||||||
$exponent = filter_var($exponent, FILTER_VALIDATE_INT);
|
|
||||||
if ($exponent !== false) {
|
|
||||||
$exponent = -$exponent;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($exponent[0] === '+') {
|
|
||||||
$exponent = substr($exponent, 1);
|
|
||||||
}
|
|
||||||
$exponent = ltrim($exponent, '0') ?: '0';
|
|
||||||
$exponent = filter_var($exponent, FILTER_VALIDATE_INT);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$exponent = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($exponent === false) {
|
|
||||||
throw new NumberFormatException('Exponent too large.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$unscaledValue = self::cleanUp($sign, $integral . $fractional);
|
|
||||||
|
|
||||||
$scale = strlen($fractional) - $exponent;
|
|
||||||
|
|
||||||
if ($scale < 0) {
|
|
||||||
if ($unscaledValue !== '0') {
|
|
||||||
$unscaledValue .= str_repeat('0', -$scale);
|
|
||||||
}
|
|
||||||
$scale = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BigDecimal($unscaledValue, $scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
$integral = self::cleanUp($sign, $integral);
|
|
||||||
|
|
||||||
return new BigInteger($integral);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes optional leading zeros and applies sign.
|
|
||||||
*
|
|
||||||
* @param string|null $sign The sign, '+' or '-', optional. Null is allowed for convenience and treated as '+'.
|
|
||||||
* @param string $number The number, validated as a string of digits.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private static function cleanUp(string|null $sign, string $number): string
|
|
||||||
{
|
|
||||||
$number = ltrim($number, '0');
|
|
||||||
|
|
||||||
if ($number === '') {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sign === '-' ? '-' . $number : $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds two BigNumber instances in the correct order to avoid a RoundingNecessaryException.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private static function add(BigNumber $a, BigNumber $b): BigNumber
|
|
||||||
{
|
|
||||||
if ($a instanceof BigRational) {
|
|
||||||
return $a->plus($b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b instanceof BigRational) {
|
|
||||||
return $b->plus($a);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($a instanceof BigDecimal) {
|
|
||||||
return $a->plus($b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b instanceof BigDecimal) {
|
|
||||||
return $b->plus($a);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $a->plus($b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-606
@@ -1,606 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math;
|
|
||||||
|
|
||||||
use Brick\Math\Exception\DivisionByZeroException;
|
|
||||||
use Brick\Math\Exception\MathException;
|
|
||||||
use Brick\Math\Exception\NumberFormatException;
|
|
||||||
use Brick\Math\Exception\RoundingNecessaryException;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use LogicException;
|
|
||||||
use Override;
|
|
||||||
|
|
||||||
use function is_finite;
|
|
||||||
use function max;
|
|
||||||
use function min;
|
|
||||||
use function strlen;
|
|
||||||
use function substr;
|
|
||||||
use function trigger_error;
|
|
||||||
|
|
||||||
use const E_USER_DEPRECATED;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An arbitrarily large rational number.
|
|
||||||
*
|
|
||||||
* This class is immutable.
|
|
||||||
*
|
|
||||||
* Fractions are automatically simplified to lowest terms. For example, `2/4` becomes `1/2`.
|
|
||||||
* The denominator is always strictly positive; the sign is carried by the numerator.
|
|
||||||
*/
|
|
||||||
final readonly class BigRational extends BigNumber
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The numerator.
|
|
||||||
*/
|
|
||||||
private BigInteger $numerator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The denominator. Always strictly positive.
|
|
||||||
*/
|
|
||||||
private BigInteger $denominator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Protected constructor. Use a factory method to obtain an instance.
|
|
||||||
*
|
|
||||||
* @param BigInteger $numerator The numerator.
|
|
||||||
* @param BigInteger $denominator The denominator.
|
|
||||||
* @param bool $checkDenominator Whether to check the denominator for negative and zero.
|
|
||||||
*
|
|
||||||
* @throws DivisionByZeroException If the denominator is zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
protected function __construct(BigInteger $numerator, BigInteger $denominator, bool $checkDenominator)
|
|
||||||
{
|
|
||||||
if ($checkDenominator) {
|
|
||||||
if ($denominator->isZero()) {
|
|
||||||
throw DivisionByZeroException::denominatorMustNotBeZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($denominator->isNegative()) {
|
|
||||||
$numerator = $numerator->negated();
|
|
||||||
$denominator = $denominator->negated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->numerator = $numerator;
|
|
||||||
$this->denominator = $denominator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a BigRational out of a numerator and a denominator.
|
|
||||||
*
|
|
||||||
* If the denominator is negative, the signs of both the numerator and the denominator
|
|
||||||
* will be inverted to ensure that the denominator is always positive.
|
|
||||||
*
|
|
||||||
* @deprecated Use ofFraction() instead.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $numerator The numerator. Must be convertible to a BigInteger.
|
|
||||||
* @param BigNumber|int|float|string $denominator The denominator. Must be convertible to a BigInteger.
|
|
||||||
*
|
|
||||||
* @throws NumberFormatException If an argument does not represent a valid number.
|
|
||||||
* @throws RoundingNecessaryException If an argument represents a non-integer number.
|
|
||||||
* @throws DivisionByZeroException If the denominator is zero.
|
|
||||||
*/
|
|
||||||
public static function nd(
|
|
||||||
BigNumber|int|float|string $numerator,
|
|
||||||
BigNumber|int|float|string $denominator,
|
|
||||||
): BigRational {
|
|
||||||
trigger_error(
|
|
||||||
'The BigRational::nd() method is deprecated, use BigRational::ofFraction() instead.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
return self::ofFraction($numerator, $denominator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a BigRational out of a numerator and a denominator.
|
|
||||||
*
|
|
||||||
* If the denominator is negative, the signs of both the numerator and the denominator
|
|
||||||
* will be inverted to ensure that the denominator is always positive.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $numerator The numerator. Must be convertible to a BigInteger.
|
|
||||||
* @param BigNumber|int|float|string $denominator The denominator. Must be convertible to a BigInteger.
|
|
||||||
*
|
|
||||||
* @throws MathException If an argument is not valid, or is not convertible to a BigInteger.
|
|
||||||
* @throws DivisionByZeroException If the denominator is zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function ofFraction(
|
|
||||||
BigNumber|int|float|string $numerator,
|
|
||||||
BigNumber|int|float|string $denominator,
|
|
||||||
): BigRational {
|
|
||||||
$numerator = BigInteger::of($numerator);
|
|
||||||
$denominator = BigInteger::of($denominator);
|
|
||||||
|
|
||||||
return new BigRational($numerator, $denominator, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a BigRational representing zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function zero(): BigRational
|
|
||||||
{
|
|
||||||
/** @var BigRational|null $zero */
|
|
||||||
static $zero;
|
|
||||||
|
|
||||||
if ($zero === null) {
|
|
||||||
$zero = new BigRational(BigInteger::zero(), BigInteger::one(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a BigRational representing one.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function one(): BigRational
|
|
||||||
{
|
|
||||||
/** @var BigRational|null $one */
|
|
||||||
static $one;
|
|
||||||
|
|
||||||
if ($one === null) {
|
|
||||||
$one = new BigRational(BigInteger::one(), BigInteger::one(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $one;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a BigRational representing ten.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function ten(): BigRational
|
|
||||||
{
|
|
||||||
/** @var BigRational|null $ten */
|
|
||||||
static $ten;
|
|
||||||
|
|
||||||
if ($ten === null) {
|
|
||||||
$ten = new BigRational(BigInteger::ten(), BigInteger::one(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ten;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function getNumerator(): BigInteger
|
|
||||||
{
|
|
||||||
return $this->numerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function getDenominator(): BigInteger
|
|
||||||
{
|
|
||||||
return $this->denominator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the quotient of the division of the numerator by the denominator.
|
|
||||||
*
|
|
||||||
* @deprecated Will be removed in 0.15. Use getIntegralPart() instead.
|
|
||||||
*/
|
|
||||||
public function quotient(): BigInteger
|
|
||||||
{
|
|
||||||
trigger_error(
|
|
||||||
'BigRational::quotient() is deprecated and will be removed in 0.15. Use getIntegralPart() instead.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->numerator->quotient($this->denominator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the remainder of the division of the numerator by the denominator.
|
|
||||||
*
|
|
||||||
* @deprecated Will be removed in 0.15. Use `$number->getNumerator()->remainder($number->getDenominator())` instead.
|
|
||||||
*/
|
|
||||||
public function remainder(): BigInteger
|
|
||||||
{
|
|
||||||
trigger_error(
|
|
||||||
'BigRational::remainder() is deprecated and will be removed in 0.15. Use `$number->getNumerator()->remainder($number->getDenominator())` instead.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->numerator->remainder($this->denominator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the quotient and remainder of the division of the numerator by the denominator.
|
|
||||||
*
|
|
||||||
* @deprecated Will be removed in 0.15. Use `$number->getNumerator()->quotientAndRemainder($number->getDenominator())` instead.
|
|
||||||
*
|
|
||||||
* @return array{BigInteger, BigInteger}
|
|
||||||
*/
|
|
||||||
public function quotientAndRemainder(): array
|
|
||||||
{
|
|
||||||
trigger_error(
|
|
||||||
'BigRational::quotientAndRemainder() is deprecated and will be removed in 0.15. Use `$number->getNumerator()->quotientAndRemainder($number->getDenominator())` instead.',
|
|
||||||
E_USER_DEPRECATED,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->numerator->quotientAndRemainder($this->denominator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the integral part of this rational number.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* - `7/3` returns `2` (since 7/3 = 2 + 1/3)
|
|
||||||
* - `-7/3` returns `-2` (since -7/3 = -2 + (-1/3))
|
|
||||||
*
|
|
||||||
* The following identity holds: `$r->isEqualTo($r->getFractionalPart()->plus($r->getIntegralPart()))`.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function getIntegralPart(): BigInteger
|
|
||||||
{
|
|
||||||
return $this->numerator->quotient($this->denominator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the fractional part of this rational number.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* - `7/3` returns `1/3` (since 7/3 = 2 + 1/3)
|
|
||||||
* - `-7/3` returns `-1/3` (since -7/3 = -2 + (-1/3))
|
|
||||||
*
|
|
||||||
* The following identity holds: `$r->isEqualTo($r->getFractionalPart()->plus($r->getIntegralPart()))`.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function getFractionalPart(): BigRational
|
|
||||||
{
|
|
||||||
return new BigRational($this->numerator->remainder($this->denominator), $this->denominator, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sum of this number and the given one.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The number to add.
|
|
||||||
*
|
|
||||||
* @throws MathException If the number is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function plus(BigNumber|int|float|string $that): BigRational
|
|
||||||
{
|
|
||||||
$that = BigRational::of($that);
|
|
||||||
|
|
||||||
$numerator = $this->numerator->multipliedBy($that->denominator);
|
|
||||||
$numerator = $numerator->plus($that->numerator->multipliedBy($this->denominator));
|
|
||||||
$denominator = $this->denominator->multipliedBy($that->denominator);
|
|
||||||
|
|
||||||
return new BigRational($numerator, $denominator, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the difference of this number and the given one.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The number to subtract.
|
|
||||||
*
|
|
||||||
* @throws MathException If the number is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function minus(BigNumber|int|float|string $that): BigRational
|
|
||||||
{
|
|
||||||
$that = BigRational::of($that);
|
|
||||||
|
|
||||||
$numerator = $this->numerator->multipliedBy($that->denominator);
|
|
||||||
$numerator = $numerator->minus($that->numerator->multipliedBy($this->denominator));
|
|
||||||
$denominator = $this->denominator->multipliedBy($that->denominator);
|
|
||||||
|
|
||||||
return new BigRational($numerator, $denominator, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the product of this number and the given one.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The multiplier.
|
|
||||||
*
|
|
||||||
* @throws MathException If the multiplier is not valid.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function multipliedBy(BigNumber|int|float|string $that): BigRational
|
|
||||||
{
|
|
||||||
$that = BigRational::of($that);
|
|
||||||
|
|
||||||
$numerator = $this->numerator->multipliedBy($that->numerator);
|
|
||||||
$denominator = $this->denominator->multipliedBy($that->denominator);
|
|
||||||
|
|
||||||
return new BigRational($numerator, $denominator, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the result of the division of this number by the given one.
|
|
||||||
*
|
|
||||||
* @param BigNumber|int|float|string $that The divisor.
|
|
||||||
*
|
|
||||||
* @throws MathException If the divisor is not valid.
|
|
||||||
* @throws DivisionByZeroException If the divisor is zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function dividedBy(BigNumber|int|float|string $that): BigRational
|
|
||||||
{
|
|
||||||
$that = BigRational::of($that);
|
|
||||||
|
|
||||||
if ($that->isZero()) {
|
|
||||||
throw DivisionByZeroException::divisionByZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
$numerator = $this->numerator->multipliedBy($that->denominator);
|
|
||||||
$denominator = $this->denominator->multipliedBy($that->numerator);
|
|
||||||
|
|
||||||
return new BigRational($numerator, $denominator, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns this number exponentiated to the given value.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function power(int $exponent): BigRational
|
|
||||||
{
|
|
||||||
if ($exponent === 0) {
|
|
||||||
return BigRational::one();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($exponent === 1) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BigRational(
|
|
||||||
$this->numerator->power($exponent),
|
|
||||||
$this->denominator->power($exponent),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the reciprocal of this BigRational.
|
|
||||||
*
|
|
||||||
* The reciprocal has the numerator and denominator swapped.
|
|
||||||
*
|
|
||||||
* @throws DivisionByZeroException If the numerator is zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function reciprocal(): BigRational
|
|
||||||
{
|
|
||||||
return new BigRational($this->denominator, $this->numerator, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function negated(): static
|
|
||||||
{
|
|
||||||
return new BigRational($this->numerator->negated(), $this->denominator, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the simplified value of this BigRational.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function simplified(): BigRational
|
|
||||||
{
|
|
||||||
$gcd = $this->numerator->gcd($this->denominator);
|
|
||||||
|
|
||||||
$numerator = $this->numerator->quotient($gcd);
|
|
||||||
$denominator = $this->denominator->quotient($gcd);
|
|
||||||
|
|
||||||
return new BigRational($numerator, $denominator, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function compareTo(BigNumber|int|float|string $that): int
|
|
||||||
{
|
|
||||||
$that = BigRational::of($that);
|
|
||||||
|
|
||||||
if ($this->denominator->isEqualTo($that->denominator)) {
|
|
||||||
return $this->numerator->compareTo($that->numerator);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->numerator
|
|
||||||
->multipliedBy($that->denominator)
|
|
||||||
->compareTo($that->numerator->multipliedBy($this->denominator));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function getSign(): int
|
|
||||||
{
|
|
||||||
return $this->numerator->getSign();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toBigInteger(): BigInteger
|
|
||||||
{
|
|
||||||
$simplified = $this->simplified();
|
|
||||||
|
|
||||||
if (! $simplified->denominator->isEqualTo(1)) {
|
|
||||||
throw new RoundingNecessaryException('This rational number cannot be represented as an integer value without rounding.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $simplified->numerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toBigDecimal(): BigDecimal
|
|
||||||
{
|
|
||||||
return $this->numerator->toBigDecimal()->dividedByExact($this->denominator);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toBigRational(): BigRational
|
|
||||||
{
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::Unnecessary): BigDecimal
|
|
||||||
{
|
|
||||||
return $this->numerator->toBigDecimal()->dividedBy($this->denominator, $scale, $roundingMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toInt(): int
|
|
||||||
{
|
|
||||||
return $this->toBigInteger()->toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toFloat(): float
|
|
||||||
{
|
|
||||||
$simplified = $this->simplified();
|
|
||||||
$numeratorFloat = $simplified->numerator->toFloat();
|
|
||||||
$denominatorFloat = $simplified->denominator->toFloat();
|
|
||||||
|
|
||||||
if (is_finite($numeratorFloat) && is_finite($denominatorFloat)) {
|
|
||||||
return $numeratorFloat / $denominatorFloat;
|
|
||||||
}
|
|
||||||
|
|
||||||
// At least one side overflows to INF; use a decimal approximation instead.
|
|
||||||
// We need ~17 significant digits for double precision (we use 20 for some margin). Since $scale controls
|
|
||||||
// decimal places (not significant digits), we subtract the estimated order of magnitude so that large results
|
|
||||||
// use fewer decimal places and small results use more (to look past leading zeros). Clamped to [0, 350] as
|
|
||||||
// doubles range from e-324 to e308 (350 ≈ 324 + 20 significant digits + margin).
|
|
||||||
$magnitude = strlen($simplified->numerator->abs()->toString()) - strlen($simplified->denominator->toString());
|
|
||||||
$scale = min(350, max(0, 20 - $magnitude));
|
|
||||||
|
|
||||||
return $simplified->numerator
|
|
||||||
->toBigDecimal()
|
|
||||||
->dividedBy($simplified->denominator, $scale, RoundingMode::HalfEven)
|
|
||||||
->toFloat();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toString(): string
|
|
||||||
{
|
|
||||||
$numerator = $this->numerator->toString();
|
|
||||||
$denominator = $this->denominator->toString();
|
|
||||||
|
|
||||||
if ($denominator === '1') {
|
|
||||||
return $numerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $numerator . '/' . $denominator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the decimal representation of this rational number, with repeating decimals in parentheses.
|
|
||||||
*
|
|
||||||
* WARNING: This method is unbounded.
|
|
||||||
* The length of the repeating decimal period can be as large as `denominator - 1`.
|
|
||||||
* For fractions with large denominators, this method can use excessive memory and CPU time.
|
|
||||||
* For example, `1/100019` has a repeating period of 100,018 digits.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* - `10/3` returns `3.(3)`
|
|
||||||
* - `171/70` returns `2.4(428571)`
|
|
||||||
* - `1/2` returns `0.5`
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function toRepeatingDecimalString(): string
|
|
||||||
{
|
|
||||||
if ($this->numerator->isZero()) {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
$sign = $this->numerator->isNegative() ? '-' : '';
|
|
||||||
$numerator = $this->numerator->abs();
|
|
||||||
$denominator = $this->denominator;
|
|
||||||
|
|
||||||
$integral = $numerator->quotient($denominator);
|
|
||||||
$remainder = $numerator->remainder($denominator);
|
|
||||||
|
|
||||||
$integralString = $integral->toString();
|
|
||||||
|
|
||||||
if ($remainder->isZero()) {
|
|
||||||
return $sign . $integralString;
|
|
||||||
}
|
|
||||||
|
|
||||||
$digits = '';
|
|
||||||
$remainderPositions = [];
|
|
||||||
$index = 0;
|
|
||||||
|
|
||||||
while (! $remainder->isZero()) {
|
|
||||||
$remainderString = $remainder->toString();
|
|
||||||
|
|
||||||
if (isset($remainderPositions[$remainderString])) {
|
|
||||||
$repeatIndex = $remainderPositions[$remainderString];
|
|
||||||
$nonRepeating = substr($digits, 0, $repeatIndex);
|
|
||||||
$repeating = substr($digits, $repeatIndex);
|
|
||||||
|
|
||||||
return $sign . $integralString . '.' . $nonRepeating . '(' . $repeating . ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
$remainderPositions[$remainderString] = $index;
|
|
||||||
$remainder = $remainder->multipliedBy(10);
|
|
||||||
|
|
||||||
$digits .= $remainder->quotient($denominator)->toString();
|
|
||||||
$remainder = $remainder->remainder($denominator);
|
|
||||||
$index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sign . $integralString . '.' . $digits;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is required for serializing the object and SHOULD NOT be accessed directly.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @return array{numerator: BigInteger, denominator: BigInteger}
|
|
||||||
*/
|
|
||||||
public function __serialize(): array
|
|
||||||
{
|
|
||||||
return ['numerator' => $this->numerator, 'denominator' => $this->denominator];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is only here to allow unserializing the object and cannot be accessed directly.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @param array{numerator: BigInteger, denominator: BigInteger} $data
|
|
||||||
*
|
|
||||||
* @throws LogicException
|
|
||||||
*/
|
|
||||||
public function __unserialize(array $data): void
|
|
||||||
{
|
|
||||||
/** @phpstan-ignore isset.initializedProperty */
|
|
||||||
if (isset($this->numerator)) {
|
|
||||||
throw new LogicException('__unserialize() is an internal function, it must not be called directly.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @phpstan-ignore deadCode.unreachable */
|
|
||||||
$this->numerator = $data['numerator'];
|
|
||||||
$this->denominator = $data['denominator'];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
protected static function from(BigNumber $number): static
|
|
||||||
{
|
|
||||||
return $number->toBigRational();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown when a division by zero occurs.
|
|
||||||
*/
|
|
||||||
final class DivisionByZeroException extends MathException
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function divisionByZero(): DivisionByZeroException
|
|
||||||
{
|
|
||||||
return new self('Division by zero.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function modulusMustNotBeZero(): DivisionByZeroException
|
|
||||||
{
|
|
||||||
return new self('The modulus must not be zero.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function denominatorMustNotBeZero(): DivisionByZeroException
|
|
||||||
{
|
|
||||||
return new self('The denominator of a rational number cannot be zero.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Exception;
|
|
||||||
|
|
||||||
use Brick\Math\BigInteger;
|
|
||||||
|
|
||||||
use function sprintf;
|
|
||||||
|
|
||||||
use const PHP_INT_MAX;
|
|
||||||
use const PHP_INT_MIN;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown when an integer overflow occurs.
|
|
||||||
*/
|
|
||||||
final class IntegerOverflowException extends MathException
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function toIntOverflow(BigInteger $value): IntegerOverflowException
|
|
||||||
{
|
|
||||||
$message = '%s is out of range %d to %d and cannot be represented as an integer.';
|
|
||||||
|
|
||||||
return new self(sprintf($message, $value->toString(), PHP_INT_MIN, PHP_INT_MAX));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Exception;
|
|
||||||
|
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for all math exceptions.
|
|
||||||
*/
|
|
||||||
class MathException extends RuntimeException
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown when attempting to perform an unsupported operation, such as a square root, on a negative number.
|
|
||||||
*/
|
|
||||||
final class NegativeNumberException extends MathException
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Exception;
|
|
||||||
|
|
||||||
use function dechex;
|
|
||||||
use function ord;
|
|
||||||
use function sprintf;
|
|
||||||
use function strtoupper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown when attempting to create a number from a string with an invalid format.
|
|
||||||
*/
|
|
||||||
final class NumberFormatException extends MathException
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function invalidFormat(string $value): self
|
|
||||||
{
|
|
||||||
return new self(sprintf(
|
|
||||||
'The given value "%s" does not represent a valid number.',
|
|
||||||
$value,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $char The failing character.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function charNotInAlphabet(string $char): self
|
|
||||||
{
|
|
||||||
return new self(sprintf(
|
|
||||||
'Character %s is not valid in the given alphabet.',
|
|
||||||
self::charToString($char),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private static function charToString(string $char): string
|
|
||||||
{
|
|
||||||
$ord = ord($char);
|
|
||||||
|
|
||||||
if ($ord < 32 || $ord > 126) {
|
|
||||||
$char = strtoupper(dechex($ord));
|
|
||||||
|
|
||||||
if ($ord < 16) {
|
|
||||||
$char = '0' . $char;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '0x' . $char;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '"' . $char . '"';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown when a number cannot be represented at the requested scale without rounding.
|
|
||||||
*/
|
|
||||||
final class RoundingNecessaryException extends MathException
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public static function roundingNecessary(): RoundingNecessaryException
|
|
||||||
{
|
|
||||||
return new self('Rounding is necessary to represent the result of the operation at this scale.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-704
@@ -1,704 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Internal;
|
|
||||||
|
|
||||||
use Brick\Math\Exception\RoundingNecessaryException;
|
|
||||||
use Brick\Math\RoundingMode;
|
|
||||||
|
|
||||||
use function chr;
|
|
||||||
use function ltrim;
|
|
||||||
use function ord;
|
|
||||||
use function str_repeat;
|
|
||||||
use function strlen;
|
|
||||||
use function strpos;
|
|
||||||
use function strrev;
|
|
||||||
use function strtolower;
|
|
||||||
use function substr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs basic operations on arbitrary size integers.
|
|
||||||
*
|
|
||||||
* Unless otherwise specified, all parameters must be validated as non-empty strings of digits,
|
|
||||||
* without leading zero, and with an optional leading minus sign if the number is not zero.
|
|
||||||
*
|
|
||||||
* Any other parameter format will lead to undefined behaviour.
|
|
||||||
* All methods must return strings respecting this format, unless specified otherwise.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
abstract readonly class Calculator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The maximum exponent value allowed for the pow() method.
|
|
||||||
*/
|
|
||||||
public const MAX_POWER = 1_000_000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The alphabet for converting from and to base 2 to 36, lowercase.
|
|
||||||
*/
|
|
||||||
public const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the absolute value of a number.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function abs(string $n): string
|
|
||||||
{
|
|
||||||
return ($n[0] === '-') ? substr($n, 1) : $n;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Negates a number.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function neg(string $n): string
|
|
||||||
{
|
|
||||||
if ($n === '0') {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($n[0] === '-') {
|
|
||||||
return substr($n, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return '-' . $n;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compares two numbers.
|
|
||||||
*
|
|
||||||
* Returns -1 if the first number is less than, 0 if equal to, 1 if greater than the second number.
|
|
||||||
*
|
|
||||||
* @return -1|0|1
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function cmp(string $a, string $b): int
|
|
||||||
{
|
|
||||||
[$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b);
|
|
||||||
|
|
||||||
if ($aNeg && ! $bNeg) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($bNeg && ! $aNeg) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$aLen = strlen($aDig);
|
|
||||||
$bLen = strlen($bDig);
|
|
||||||
|
|
||||||
if ($aLen < $bLen) {
|
|
||||||
$result = -1;
|
|
||||||
} elseif ($aLen > $bLen) {
|
|
||||||
$result = 1;
|
|
||||||
} else {
|
|
||||||
$result = $aDig <=> $bDig;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $aNeg ? -$result : $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds two numbers.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function add(string $a, string $b): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subtracts two numbers.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function sub(string $a, string $b): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Multiplies two numbers.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function mul(string $a, string $b): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the quotient of the division of two numbers.
|
|
||||||
*
|
|
||||||
* @param string $a The dividend.
|
|
||||||
* @param string $b The divisor, must not be zero.
|
|
||||||
*
|
|
||||||
* @return string The quotient.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function divQ(string $a, string $b): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the remainder of the division of two numbers.
|
|
||||||
*
|
|
||||||
* @param string $a The dividend.
|
|
||||||
* @param string $b The divisor, must not be zero.
|
|
||||||
*
|
|
||||||
* @return string The remainder.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function divR(string $a, string $b): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the quotient and remainder of the division of two numbers.
|
|
||||||
*
|
|
||||||
* @param string $a The dividend.
|
|
||||||
* @param string $b The divisor, must not be zero.
|
|
||||||
*
|
|
||||||
* @return array{string, string} An array containing the quotient and remainder.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function divQR(string $a, string $b): array;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exponentiates a number.
|
|
||||||
*
|
|
||||||
* @param string $a The base number.
|
|
||||||
* @param int $e The exponent, validated as an integer between 0 and MAX_POWER.
|
|
||||||
*
|
|
||||||
* @return string The power.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function pow(string $a, int $e): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $b The modulus; must not be zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function mod(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return $this->divR($this->add($this->divR($a, $b), $b), $b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the modular multiplicative inverse of $x modulo $m.
|
|
||||||
*
|
|
||||||
* If $x has no multiplicative inverse mod m, this method must return null.
|
|
||||||
*
|
|
||||||
* This method can be overridden by the concrete implementation if the underlying library has built-in support.
|
|
||||||
*
|
|
||||||
* @param string $m The modulus; must not be negative or zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function modInverse(string $x, string $m): ?string
|
|
||||||
{
|
|
||||||
if ($m === '1') {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
$modVal = $x;
|
|
||||||
|
|
||||||
if ($x[0] === '-' || ($this->cmp($this->abs($x), $m) >= 0)) {
|
|
||||||
$modVal = $this->mod($x, $m);
|
|
||||||
}
|
|
||||||
|
|
||||||
[$g, $x] = $this->gcdExtended($modVal, $m);
|
|
||||||
|
|
||||||
if ($g !== '1') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->mod($this->add($this->mod($x, $m), $m), $m);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Raises a number into power with modulo.
|
|
||||||
*
|
|
||||||
* @param string $base The base number.
|
|
||||||
* @param string $exp The exponent; must be positive or zero.
|
|
||||||
* @param string $mod The modulus; must be strictly positive.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function modPow(string $base, string $exp, string $mod): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the greatest common divisor of the two numbers.
|
|
||||||
*
|
|
||||||
* This method can be overridden by the concrete implementation if the underlying library
|
|
||||||
* has built-in support for GCD calculations.
|
|
||||||
*
|
|
||||||
* @return string The GCD, always positive, or zero if both arguments are zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function gcd(string $a, string $b): string
|
|
||||||
{
|
|
||||||
if ($a === '0') {
|
|
||||||
return $this->abs($b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b === '0') {
|
|
||||||
return $this->abs($a);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->gcd($b, $this->divR($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the least common multiple of the two numbers.
|
|
||||||
*
|
|
||||||
* This method can be overridden by the concrete implementation if the underlying library
|
|
||||||
* has built-in support for LCM calculations.
|
|
||||||
*
|
|
||||||
* @return string The LCM, always positive, or zero if at least one argument is zero.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function lcm(string $a, string $b): string
|
|
||||||
{
|
|
||||||
if ($a === '0' || $b === '0') {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->divQ($this->abs($this->mul($a, $b)), $this->gcd($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the square root of the given number, rounded down.
|
|
||||||
*
|
|
||||||
* The result is the largest x such that x² ≤ n.
|
|
||||||
* The input MUST NOT be negative.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
abstract public function sqrt(string $n): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a number from an arbitrary base.
|
|
||||||
*
|
|
||||||
* This method can be overridden by the concrete implementation if the underlying library
|
|
||||||
* has built-in support for base conversion.
|
|
||||||
*
|
|
||||||
* @param string $number The number, positive or zero, non-empty, case-insensitively validated for the given base.
|
|
||||||
* @param int $base The base of the number, validated from 2 to 36.
|
|
||||||
*
|
|
||||||
* @return string The converted number, following the Calculator conventions.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function fromBase(string $number, int $base): string
|
|
||||||
{
|
|
||||||
return $this->fromArbitraryBase(strtolower($number), self::ALPHABET, $base);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a number to an arbitrary base.
|
|
||||||
*
|
|
||||||
* This method can be overridden by the concrete implementation if the underlying library
|
|
||||||
* has built-in support for base conversion.
|
|
||||||
*
|
|
||||||
* @param string $number The number to convert, following the Calculator conventions.
|
|
||||||
* @param int $base The base to convert to, validated from 2 to 36.
|
|
||||||
*
|
|
||||||
* @return string The converted number, lowercase.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function toBase(string $number, int $base): string
|
|
||||||
{
|
|
||||||
$negative = ($number[0] === '-');
|
|
||||||
|
|
||||||
if ($negative) {
|
|
||||||
$number = substr($number, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$number = $this->toArbitraryBase($number, self::ALPHABET, $base);
|
|
||||||
|
|
||||||
if ($negative) {
|
|
||||||
return '-' . $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a non-negative number in an arbitrary base using a custom alphabet, to base 10.
|
|
||||||
*
|
|
||||||
* @param string $number The number to convert, validated as a non-empty string,
|
|
||||||
* containing only chars in the given alphabet/base.
|
|
||||||
* @param string $alphabet The alphabet that contains every digit, validated as 2 chars minimum.
|
|
||||||
* @param int $base The base of the number, validated from 2 to alphabet length.
|
|
||||||
*
|
|
||||||
* @return string The number in base 10, following the Calculator conventions.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function fromArbitraryBase(string $number, string $alphabet, int $base): string
|
|
||||||
{
|
|
||||||
// remove leading "zeros"
|
|
||||||
$number = ltrim($number, $alphabet[0]);
|
|
||||||
|
|
||||||
if ($number === '') {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// optimize for "one"
|
|
||||||
if ($number === $alphabet[1]) {
|
|
||||||
return '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = '0';
|
|
||||||
$power = '1';
|
|
||||||
|
|
||||||
$base = (string) $base;
|
|
||||||
|
|
||||||
for ($i = strlen($number) - 1; $i >= 0; $i--) {
|
|
||||||
$index = strpos($alphabet, $number[$i]);
|
|
||||||
|
|
||||||
if ($index !== 0) {
|
|
||||||
$result = $this->add(
|
|
||||||
$result,
|
|
||||||
($index === 1) ? $power : $this->mul($power, (string) $index),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($i !== 0) {
|
|
||||||
$power = $this->mul($power, $base);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a non-negative number to an arbitrary base using a custom alphabet.
|
|
||||||
*
|
|
||||||
* @param string $number The number to convert, positive or zero, following the Calculator conventions.
|
|
||||||
* @param string $alphabet The alphabet that contains every digit, validated as 2 chars minimum.
|
|
||||||
* @param int $base The base to convert to, validated from 2 to alphabet length.
|
|
||||||
*
|
|
||||||
* @return string The converted number in the given alphabet.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function toArbitraryBase(string $number, string $alphabet, int $base): string
|
|
||||||
{
|
|
||||||
if ($number === '0') {
|
|
||||||
return $alphabet[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$base = (string) $base;
|
|
||||||
$result = '';
|
|
||||||
|
|
||||||
while ($number !== '0') {
|
|
||||||
[$number, $remainder] = $this->divQR($number, $base);
|
|
||||||
$remainder = (int) $remainder;
|
|
||||||
|
|
||||||
$result .= $alphabet[$remainder];
|
|
||||||
}
|
|
||||||
|
|
||||||
return strrev($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a rounded division.
|
|
||||||
*
|
|
||||||
* Rounding is performed when the remainder of the division is not zero.
|
|
||||||
*
|
|
||||||
* @param string $a The dividend.
|
|
||||||
* @param string $b The divisor, must not be zero.
|
|
||||||
* @param RoundingMode $roundingMode The rounding mode.
|
|
||||||
*
|
|
||||||
* @throws RoundingNecessaryException If RoundingMode::Unnecessary is provided but rounding is necessary.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final public function divRound(string $a, string $b, RoundingMode $roundingMode): string
|
|
||||||
{
|
|
||||||
[$quotient, $remainder] = $this->divQR($a, $b);
|
|
||||||
|
|
||||||
$hasDiscardedFraction = ($remainder !== '0');
|
|
||||||
$isPositiveOrZero = ($a[0] === '-') === ($b[0] === '-');
|
|
||||||
|
|
||||||
$discardedFractionSign = function () use ($remainder, $b): int {
|
|
||||||
$r = $this->abs($this->mul($remainder, '2'));
|
|
||||||
$b = $this->abs($b);
|
|
||||||
|
|
||||||
return $this->cmp($r, $b);
|
|
||||||
};
|
|
||||||
|
|
||||||
$increment = false;
|
|
||||||
|
|
||||||
switch ($roundingMode) {
|
|
||||||
case RoundingMode::Unnecessary:
|
|
||||||
if ($hasDiscardedFraction) {
|
|
||||||
throw RoundingNecessaryException::roundingNecessary();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::Up:
|
|
||||||
$increment = $hasDiscardedFraction;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::Down:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::Ceiling:
|
|
||||||
$increment = $hasDiscardedFraction && $isPositiveOrZero;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::Floor:
|
|
||||||
$increment = $hasDiscardedFraction && ! $isPositiveOrZero;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::HalfUp:
|
|
||||||
$increment = $discardedFractionSign() >= 0;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::HalfDown:
|
|
||||||
$increment = $discardedFractionSign() > 0;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::HalfCeiling:
|
|
||||||
$increment = $isPositiveOrZero ? $discardedFractionSign() >= 0 : $discardedFractionSign() > 0;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::HalfFloor:
|
|
||||||
$increment = $isPositiveOrZero ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoundingMode::HalfEven:
|
|
||||||
$lastDigit = (int) $quotient[-1];
|
|
||||||
$lastDigitIsEven = ($lastDigit % 2 === 0);
|
|
||||||
$increment = $lastDigitIsEven ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($increment) {
|
|
||||||
return $this->add($quotient, $isPositiveOrZero ? '1' : '-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $quotient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates bitwise AND of two numbers.
|
|
||||||
*
|
|
||||||
* This method can be overridden by the concrete implementation if the underlying library
|
|
||||||
* has built-in support for bitwise operations.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function and(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return $this->bitwise('and', $a, $b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates bitwise OR of two numbers.
|
|
||||||
*
|
|
||||||
* This method can be overridden by the concrete implementation if the underlying library
|
|
||||||
* has built-in support for bitwise operations.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function or(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return $this->bitwise('or', $a, $b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates bitwise XOR of two numbers.
|
|
||||||
*
|
|
||||||
* This method can be overridden by the concrete implementation if the underlying library
|
|
||||||
* has built-in support for bitwise operations.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
public function xor(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return $this->bitwise('xor', $a, $b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts the sign & digits of the operands.
|
|
||||||
*
|
|
||||||
* @return array{bool, bool, string, string} Whether $a and $b are negative, followed by their digits.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
final protected function init(string $a, string $b): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
$aNeg = ($a[0] === '-'),
|
|
||||||
$bNeg = ($b[0] === '-'),
|
|
||||||
|
|
||||||
$aNeg ? substr($a, 1) : $a,
|
|
||||||
$bNeg ? substr($b, 1) : $b,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array{string, string, string} GCD, X, Y
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function gcdExtended(string $a, string $b): array
|
|
||||||
{
|
|
||||||
if ($a === '0') {
|
|
||||||
return [$b, '0', '1'];
|
|
||||||
}
|
|
||||||
|
|
||||||
[$gcd, $x1, $y1] = $this->gcdExtended($this->mod($b, $a), $a);
|
|
||||||
|
|
||||||
$x = $this->sub($y1, $this->mul($this->divQ($b, $a), $x1));
|
|
||||||
$y = $x1;
|
|
||||||
|
|
||||||
return [$gcd, $x, $y];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a bitwise operation on a decimal number.
|
|
||||||
*
|
|
||||||
* @param 'and'|'or'|'xor' $operator The operator to use.
|
|
||||||
* @param string $a The left operand.
|
|
||||||
* @param string $b The right operand.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function bitwise(string $operator, string $a, string $b): string
|
|
||||||
{
|
|
||||||
[$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b);
|
|
||||||
|
|
||||||
$aBin = $this->toBinary($aDig);
|
|
||||||
$bBin = $this->toBinary($bDig);
|
|
||||||
|
|
||||||
$aLen = strlen($aBin);
|
|
||||||
$bLen = strlen($bBin);
|
|
||||||
|
|
||||||
if ($aLen > $bLen) {
|
|
||||||
$bBin = str_repeat("\x00", $aLen - $bLen) . $bBin;
|
|
||||||
} elseif ($bLen > $aLen) {
|
|
||||||
$aBin = str_repeat("\x00", $bLen - $aLen) . $aBin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($aNeg) {
|
|
||||||
$aBin = $this->twosComplement($aBin);
|
|
||||||
}
|
|
||||||
if ($bNeg) {
|
|
||||||
$bBin = $this->twosComplement($bBin);
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = match ($operator) {
|
|
||||||
'and' => $aBin & $bBin,
|
|
||||||
'or' => $aBin | $bBin,
|
|
||||||
'xor' => $aBin ^ $bBin,
|
|
||||||
};
|
|
||||||
|
|
||||||
$negative = match ($operator) {
|
|
||||||
'and' => $aNeg and $bNeg,
|
|
||||||
'or' => $aNeg or $bNeg,
|
|
||||||
'xor' => $aNeg xor $bNeg,
|
|
||||||
};
|
|
||||||
|
|
||||||
if ($negative) {
|
|
||||||
$value = $this->twosComplement($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->toDecimal($value);
|
|
||||||
|
|
||||||
return $negative ? $this->neg($result) : $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $number A positive, binary number.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function twosComplement(string $number): string
|
|
||||||
{
|
|
||||||
$xor = str_repeat("\xff", strlen($number));
|
|
||||||
|
|
||||||
$number ^= $xor;
|
|
||||||
|
|
||||||
for ($i = strlen($number) - 1; $i >= 0; $i--) {
|
|
||||||
$byte = ord($number[$i]);
|
|
||||||
|
|
||||||
if (++$byte !== 256) {
|
|
||||||
$number[$i] = chr($byte);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$number[$i] = "\x00";
|
|
||||||
|
|
||||||
if ($i === 0) {
|
|
||||||
$number = "\x01" . $number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a decimal number to a binary string.
|
|
||||||
*
|
|
||||||
* @param string $number The number to convert, positive or zero, only digits.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function toBinary(string $number): string
|
|
||||||
{
|
|
||||||
$result = '';
|
|
||||||
|
|
||||||
while ($number !== '0') {
|
|
||||||
[$number, $remainder] = $this->divQR($number, '256');
|
|
||||||
$result .= chr((int) $remainder);
|
|
||||||
}
|
|
||||||
|
|
||||||
return strrev($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the positive decimal representation of a binary number.
|
|
||||||
*
|
|
||||||
* @param string $bytes The bytes representing the number.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function toDecimal(string $bytes): string
|
|
||||||
{
|
|
||||||
$result = '0';
|
|
||||||
$power = '1';
|
|
||||||
|
|
||||||
for ($i = strlen($bytes) - 1; $i >= 0; $i--) {
|
|
||||||
$index = ord($bytes[$i]);
|
|
||||||
|
|
||||||
if ($index !== 0) {
|
|
||||||
$result = $this->add(
|
|
||||||
$result,
|
|
||||||
($index === 1) ? $power : $this->mul($power, (string) $index),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($i !== 0) {
|
|
||||||
$power = $this->mul($power, '256');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Internal\Calculator;
|
|
||||||
|
|
||||||
use Brick\Math\Internal\Calculator;
|
|
||||||
use Override;
|
|
||||||
|
|
||||||
use function bcadd;
|
|
||||||
use function bcdiv;
|
|
||||||
use function bcmod;
|
|
||||||
use function bcmul;
|
|
||||||
use function bcpow;
|
|
||||||
use function bcpowmod;
|
|
||||||
use function bcsqrt;
|
|
||||||
use function bcsub;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculator implementation built around the bcmath library.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final readonly class BcMathCalculator extends Calculator
|
|
||||||
{
|
|
||||||
#[Override]
|
|
||||||
public function add(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return bcadd($a, $b, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function sub(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return bcsub($a, $b, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function mul(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return bcmul($a, $b, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divQ(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return bcdiv($a, $b, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divR(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return bcmod($a, $b, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divQR(string $a, string $b): array
|
|
||||||
{
|
|
||||||
$q = bcdiv($a, $b, 0);
|
|
||||||
$r = bcmod($a, $b, 0);
|
|
||||||
|
|
||||||
return [$q, $r];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function pow(string $a, int $e): string
|
|
||||||
{
|
|
||||||
return bcpow($a, (string) $e, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function modPow(string $base, string $exp, string $mod): string
|
|
||||||
{
|
|
||||||
// normalize to Euclidean representative so modPow() stays consistent with mod()
|
|
||||||
$base = $this->mod($base, $mod);
|
|
||||||
|
|
||||||
return bcpowmod($base, $exp, $mod, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function sqrt(string $n): string
|
|
||||||
{
|
|
||||||
return bcsqrt($n, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Internal\Calculator;
|
|
||||||
|
|
||||||
use Brick\Math\Internal\Calculator;
|
|
||||||
use GMP;
|
|
||||||
use Override;
|
|
||||||
|
|
||||||
use function gmp_add;
|
|
||||||
use function gmp_and;
|
|
||||||
use function gmp_div_q;
|
|
||||||
use function gmp_div_qr;
|
|
||||||
use function gmp_div_r;
|
|
||||||
use function gmp_gcd;
|
|
||||||
use function gmp_init;
|
|
||||||
use function gmp_invert;
|
|
||||||
use function gmp_lcm;
|
|
||||||
use function gmp_mul;
|
|
||||||
use function gmp_or;
|
|
||||||
use function gmp_pow;
|
|
||||||
use function gmp_powm;
|
|
||||||
use function gmp_sqrt;
|
|
||||||
use function gmp_strval;
|
|
||||||
use function gmp_sub;
|
|
||||||
use function gmp_xor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculator implementation built around the GMP library.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final readonly class GmpCalculator extends Calculator
|
|
||||||
{
|
|
||||||
#[Override]
|
|
||||||
public function add(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_add($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function sub(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_sub($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function mul(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_mul($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divQ(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_div_q($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divR(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_div_r($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divQR(string $a, string $b): array
|
|
||||||
{
|
|
||||||
[$q, $r] = gmp_div_qr($a, $b);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var GMP $q
|
|
||||||
* @var GMP $r
|
|
||||||
*/
|
|
||||||
return [
|
|
||||||
gmp_strval($q),
|
|
||||||
gmp_strval($r),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function pow(string $a, int $e): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_pow($a, $e));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function modInverse(string $x, string $m): ?string
|
|
||||||
{
|
|
||||||
$result = gmp_invert($x, $m);
|
|
||||||
|
|
||||||
if ($result === false) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gmp_strval($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function modPow(string $base, string $exp, string $mod): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_powm($base, $exp, $mod));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function gcd(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_gcd($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function lcm(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_lcm($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function fromBase(string $number, int $base): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_init($number, $base));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function toBase(string $number, int $base): string
|
|
||||||
{
|
|
||||||
return gmp_strval($number, $base);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function and(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_and($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function or(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_or($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function xor(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_xor($a, $b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function sqrt(string $n): string
|
|
||||||
{
|
|
||||||
return gmp_strval(gmp_sqrt($n));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,616 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Brick\Math\Internal\Calculator;
|
|
||||||
|
|
||||||
use Brick\Math\Internal\Calculator;
|
|
||||||
use Override;
|
|
||||||
|
|
||||||
use function assert;
|
|
||||||
use function in_array;
|
|
||||||
use function intdiv;
|
|
||||||
use function is_int;
|
|
||||||
use function ltrim;
|
|
||||||
use function str_pad;
|
|
||||||
use function str_repeat;
|
|
||||||
use function strcmp;
|
|
||||||
use function strlen;
|
|
||||||
use function substr;
|
|
||||||
|
|
||||||
use const PHP_INT_SIZE;
|
|
||||||
use const STR_PAD_LEFT;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculator implementation using only native PHP code.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final readonly class NativeCalculator extends Calculator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The max number of digits the platform can natively add, subtract, multiply or divide without overflow.
|
|
||||||
* For multiplication, this represents the max sum of the lengths of both operands.
|
|
||||||
*
|
|
||||||
* In addition, it is assumed that an extra digit can hold a carry (1) without overflowing.
|
|
||||||
* Example: 32-bit: max number 1,999,999,999 (9 digits + carry)
|
|
||||||
* 64-bit: max number 1,999,999,999,999,999,999 (18 digits + carry)
|
|
||||||
*/
|
|
||||||
private int $maxDigits;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @pure
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->maxDigits = match (PHP_INT_SIZE) {
|
|
||||||
4 => 9,
|
|
||||||
8 => 18,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function add(string $a, string $b): string
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var numeric-string $a
|
|
||||||
* @var numeric-string $b
|
|
||||||
*/
|
|
||||||
$result = $a + $b;
|
|
||||||
|
|
||||||
if (is_int($result)) {
|
|
||||||
return (string) $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($a === '0') {
|
|
||||||
return $b;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b === '0') {
|
|
||||||
return $a;
|
|
||||||
}
|
|
||||||
|
|
||||||
[$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b);
|
|
||||||
|
|
||||||
$result = $aNeg === $bNeg ? $this->doAdd($aDig, $bDig) : $this->doSub($aDig, $bDig);
|
|
||||||
|
|
||||||
if ($aNeg) {
|
|
||||||
$result = $this->neg($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function sub(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return $this->add($a, $this->neg($b));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function mul(string $a, string $b): string
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var numeric-string $a
|
|
||||||
* @var numeric-string $b
|
|
||||||
*/
|
|
||||||
$result = $a * $b;
|
|
||||||
|
|
||||||
if (is_int($result)) {
|
|
||||||
return (string) $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($a === '0' || $b === '0') {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($a === '1') {
|
|
||||||
return $b;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b === '1') {
|
|
||||||
return $a;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($a === '-1') {
|
|
||||||
return $this->neg($b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b === '-1') {
|
|
||||||
return $this->neg($a);
|
|
||||||
}
|
|
||||||
|
|
||||||
[$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b);
|
|
||||||
|
|
||||||
$result = $this->doMul($aDig, $bDig);
|
|
||||||
|
|
||||||
if ($aNeg !== $bNeg) {
|
|
||||||
$result = $this->neg($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divQ(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return $this->divQR($a, $b)[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divR(string $a, string $b): string
|
|
||||||
{
|
|
||||||
return $this->divQR($a, $b)[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function divQR(string $a, string $b): array
|
|
||||||
{
|
|
||||||
if ($a === '0') {
|
|
||||||
return ['0', '0'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($a === $b) {
|
|
||||||
return ['1', '0'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b === '1') {
|
|
||||||
return [$a, '0'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b === '-1') {
|
|
||||||
return [$this->neg($a), '0'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var numeric-string $a */
|
|
||||||
$na = $a * 1; // cast to number
|
|
||||||
|
|
||||||
if (is_int($na)) {
|
|
||||||
/** @var numeric-string $b */
|
|
||||||
$nb = $b * 1;
|
|
||||||
|
|
||||||
if (is_int($nb)) {
|
|
||||||
// the only division that may overflow is PHP_INT_MIN / -1,
|
|
||||||
// which cannot happen here as we've already handled a divisor of -1 above.
|
|
||||||
$q = intdiv($na, $nb);
|
|
||||||
$r = $na % $nb;
|
|
||||||
|
|
||||||
return [
|
|
||||||
(string) $q,
|
|
||||||
(string) $r,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b);
|
|
||||||
|
|
||||||
[$q, $r] = $this->doDiv($aDig, $bDig);
|
|
||||||
|
|
||||||
if ($aNeg !== $bNeg) {
|
|
||||||
$q = $this->neg($q);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($aNeg) {
|
|
||||||
$r = $this->neg($r);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [$q, $r];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function pow(string $a, int $e): string
|
|
||||||
{
|
|
||||||
if ($e === 0) {
|
|
||||||
return '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($e === 1) {
|
|
||||||
return $a;
|
|
||||||
}
|
|
||||||
|
|
||||||
$odd = $e % 2;
|
|
||||||
$e -= $odd;
|
|
||||||
|
|
||||||
$aa = $this->mul($a, $a);
|
|
||||||
|
|
||||||
$result = $this->pow($aa, $e / 2);
|
|
||||||
|
|
||||||
if ($odd === 1) {
|
|
||||||
$result = $this->mul($result, $a);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Algorithm from: https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/.
|
|
||||||
*/
|
|
||||||
#[Override]
|
|
||||||
public function modPow(string $base, string $exp, string $mod): string
|
|
||||||
{
|
|
||||||
// normalize to Euclidean representative so modPow() stays consistent with mod()
|
|
||||||
$base = $this->mod($base, $mod);
|
|
||||||
|
|
||||||
// special case: the algorithm below fails with power 0 mod 1 (returns 1 instead of 0)
|
|
||||||
if ($exp === '0' && $mod === '1') {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
$x = $base;
|
|
||||||
|
|
||||||
$res = '1';
|
|
||||||
|
|
||||||
// numbers are positive, so we can use remainder instead of modulo
|
|
||||||
$x = $this->divR($x, $mod);
|
|
||||||
|
|
||||||
while ($exp !== '0') {
|
|
||||||
if (in_array($exp[-1], ['1', '3', '5', '7', '9'])) { // odd
|
|
||||||
$res = $this->divR($this->mul($res, $x), $mod);
|
|
||||||
}
|
|
||||||
|
|
||||||
$exp = $this->divQ($exp, '2');
|
|
||||||
$x = $this->divR($this->mul($x, $x), $mod);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adapted from https://cp-algorithms.com/num_methods/roots_newton.html.
|
|
||||||
*/
|
|
||||||
#[Override]
|
|
||||||
public function sqrt(string $n): string
|
|
||||||
{
|
|
||||||
if ($n === '0') {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// initial approximation
|
|
||||||
$x = str_repeat('9', intdiv(strlen($n), 2) ?: 1);
|
|
||||||
|
|
||||||
$decreased = false;
|
|
||||||
|
|
||||||
for (; ;) {
|
|
||||||
$nx = $this->divQ($this->add($x, $this->divQ($n, $x)), '2');
|
|
||||||
|
|
||||||
if ($x === $nx || $this->cmp($nx, $x) > 0 && $decreased) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$decreased = $this->cmp($nx, $x) < 0;
|
|
||||||
$x = $nx;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the addition of two non-signed large integers.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function doAdd(string $a, string $b): string
|
|
||||||
{
|
|
||||||
[$a, $b, $length] = $this->pad($a, $b);
|
|
||||||
|
|
||||||
$carry = 0;
|
|
||||||
$result = '';
|
|
||||||
|
|
||||||
for ($i = $length - $this->maxDigits; ; $i -= $this->maxDigits) {
|
|
||||||
$blockLength = $this->maxDigits;
|
|
||||||
|
|
||||||
if ($i < 0) {
|
|
||||||
$blockLength += $i;
|
|
||||||
$i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var numeric-string $blockA */
|
|
||||||
$blockA = substr($a, $i, $blockLength);
|
|
||||||
|
|
||||||
/** @var numeric-string $blockB */
|
|
||||||
$blockB = substr($b, $i, $blockLength);
|
|
||||||
|
|
||||||
$sum = (string) ($blockA + $blockB + $carry);
|
|
||||||
$sumLength = strlen($sum);
|
|
||||||
|
|
||||||
if ($sumLength > $blockLength) {
|
|
||||||
$sum = substr($sum, 1);
|
|
||||||
$carry = 1;
|
|
||||||
} else {
|
|
||||||
if ($sumLength < $blockLength) {
|
|
||||||
$sum = str_repeat('0', $blockLength - $sumLength) . $sum;
|
|
||||||
}
|
|
||||||
$carry = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $sum . $result;
|
|
||||||
|
|
||||||
if ($i === 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($carry === 1) {
|
|
||||||
$result = '1' . $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the subtraction of two non-signed large integers.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function doSub(string $a, string $b): string
|
|
||||||
{
|
|
||||||
if ($a === $b) {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that we always subtract to a positive result: biggest minus smallest.
|
|
||||||
$cmp = $this->doCmp($a, $b);
|
|
||||||
|
|
||||||
$invert = ($cmp === -1);
|
|
||||||
|
|
||||||
if ($invert) {
|
|
||||||
$c = $a;
|
|
||||||
$a = $b;
|
|
||||||
$b = $c;
|
|
||||||
}
|
|
||||||
|
|
||||||
[$a, $b, $length] = $this->pad($a, $b);
|
|
||||||
|
|
||||||
$carry = 0;
|
|
||||||
$result = '';
|
|
||||||
|
|
||||||
$complement = 10 ** $this->maxDigits;
|
|
||||||
|
|
||||||
for ($i = $length - $this->maxDigits; ; $i -= $this->maxDigits) {
|
|
||||||
$blockLength = $this->maxDigits;
|
|
||||||
|
|
||||||
if ($i < 0) {
|
|
||||||
$blockLength += $i;
|
|
||||||
$i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var numeric-string $blockA */
|
|
||||||
$blockA = substr($a, $i, $blockLength);
|
|
||||||
|
|
||||||
/** @var numeric-string $blockB */
|
|
||||||
$blockB = substr($b, $i, $blockLength);
|
|
||||||
|
|
||||||
$sum = $blockA - $blockB - $carry;
|
|
||||||
|
|
||||||
if ($sum < 0) {
|
|
||||||
$sum += $complement;
|
|
||||||
$carry = 1;
|
|
||||||
} else {
|
|
||||||
$carry = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sum = (string) $sum;
|
|
||||||
$sumLength = strlen($sum);
|
|
||||||
|
|
||||||
if ($sumLength < $blockLength) {
|
|
||||||
$sum = str_repeat('0', $blockLength - $sumLength) . $sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $sum . $result;
|
|
||||||
|
|
||||||
if ($i === 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carry cannot be 1 when the loop ends, as a > b
|
|
||||||
assert($carry === 0);
|
|
||||||
|
|
||||||
$result = ltrim($result, '0');
|
|
||||||
|
|
||||||
if ($invert) {
|
|
||||||
$result = $this->neg($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the multiplication of two non-signed large integers.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function doMul(string $a, string $b): string
|
|
||||||
{
|
|
||||||
$x = strlen($a);
|
|
||||||
$y = strlen($b);
|
|
||||||
|
|
||||||
$maxDigits = intdiv($this->maxDigits, 2);
|
|
||||||
$complement = 10 ** $maxDigits;
|
|
||||||
|
|
||||||
$result = '0';
|
|
||||||
|
|
||||||
for ($i = $x - $maxDigits; ; $i -= $maxDigits) {
|
|
||||||
$blockALength = $maxDigits;
|
|
||||||
|
|
||||||
if ($i < 0) {
|
|
||||||
$blockALength += $i;
|
|
||||||
$i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$blockA = (int) substr($a, $i, $blockALength);
|
|
||||||
|
|
||||||
$line = '';
|
|
||||||
$carry = 0;
|
|
||||||
|
|
||||||
for ($j = $y - $maxDigits; ; $j -= $maxDigits) {
|
|
||||||
$blockBLength = $maxDigits;
|
|
||||||
|
|
||||||
if ($j < 0) {
|
|
||||||
$blockBLength += $j;
|
|
||||||
$j = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$blockB = (int) substr($b, $j, $blockBLength);
|
|
||||||
|
|
||||||
$mul = $blockA * $blockB + $carry;
|
|
||||||
$value = $mul % $complement;
|
|
||||||
$carry = ($mul - $value) / $complement;
|
|
||||||
|
|
||||||
$value = (string) $value;
|
|
||||||
$value = str_pad($value, $maxDigits, '0', STR_PAD_LEFT);
|
|
||||||
|
|
||||||
$line = $value . $line;
|
|
||||||
|
|
||||||
if ($j === 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($carry !== 0) {
|
|
||||||
$line = $carry . $line;
|
|
||||||
}
|
|
||||||
|
|
||||||
$line = ltrim($line, '0');
|
|
||||||
|
|
||||||
if ($line !== '') {
|
|
||||||
$line .= str_repeat('0', $x - $blockALength - $i);
|
|
||||||
$result = $this->add($result, $line);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($i === 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the division of two non-signed large integers.
|
|
||||||
*
|
|
||||||
* @return string[] The quotient and remainder.
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function doDiv(string $a, string $b): array
|
|
||||||
{
|
|
||||||
$cmp = $this->doCmp($a, $b);
|
|
||||||
|
|
||||||
if ($cmp === -1) {
|
|
||||||
return ['0', $a];
|
|
||||||
}
|
|
||||||
|
|
||||||
$x = strlen($a);
|
|
||||||
$y = strlen($b);
|
|
||||||
|
|
||||||
// we now know that a >= b && x >= y
|
|
||||||
|
|
||||||
$q = '0'; // quotient
|
|
||||||
$r = $a; // remainder
|
|
||||||
$z = $y; // focus length, always $y or $y+1
|
|
||||||
|
|
||||||
/** @var numeric-string $b */
|
|
||||||
$nb = $b * 1; // cast to number
|
|
||||||
// performance optimization in cases where the remainder will never cause int overflow
|
|
||||||
if (is_int(($nb - 1) * 10 + 9)) {
|
|
||||||
$r = (int) substr($a, 0, $z - 1);
|
|
||||||
|
|
||||||
for ($i = $z - 1; $i < $x; $i++) {
|
|
||||||
$n = $r * 10 + (int) $a[$i];
|
|
||||||
/** @var int $nb */
|
|
||||||
$q .= intdiv($n, $nb);
|
|
||||||
$r = $n % $nb;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [ltrim($q, '0') ?: '0', (string) $r];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; ;) {
|
|
||||||
$focus = substr($a, 0, $z);
|
|
||||||
|
|
||||||
$cmp = $this->doCmp($focus, $b);
|
|
||||||
|
|
||||||
if ($cmp === -1) {
|
|
||||||
if ($z === $x) { // remainder < dividend
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$z++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$zeros = str_repeat('0', $x - $z);
|
|
||||||
|
|
||||||
$q = $this->add($q, '1' . $zeros);
|
|
||||||
$a = $this->sub($a, $b . $zeros);
|
|
||||||
|
|
||||||
$r = $a;
|
|
||||||
|
|
||||||
if ($r === '0') { // remainder == 0
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$x = strlen($a);
|
|
||||||
|
|
||||||
if ($x < $y) { // remainder < dividend
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$z = $y;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [$q, $r];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compares two non-signed large numbers.
|
|
||||||
*
|
|
||||||
* @return -1|0|1
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function doCmp(string $a, string $b): int
|
|
||||||
{
|
|
||||||
$x = strlen($a);
|
|
||||||
$y = strlen($b);
|
|
||||||
|
|
||||||
$cmp = $x <=> $y;
|
|
||||||
|
|
||||||
if ($cmp !== 0) {
|
|
||||||
return $cmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return strcmp($a, $b) <=> 0; // enforce -1|0|1
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pads the left of one of the given numbers with zeros if necessary to make both numbers the same length.
|
|
||||||
*
|
|
||||||
* The numbers must only consist of digits, without leading minus sign.
|
|
||||||
*
|
|
||||||
* @return array{string, string, int}
|
|
||||||
*
|
|
||||||
* @pure
|
|
||||||
*/
|
|
||||||
private function pad(string $a, string $b): array
|
|
||||||
{
|
|
||||||
$x = strlen($a);
|
|
||||||
$y = strlen($b);
|
|
||||||
|
|
||||||
if ($x > $y) {
|
|
||||||
$b = str_repeat('0', $x - $y) . $b;
|
|
||||||
|
|
||||||
return [$a, $b, $x];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($x < $y) {
|
|
||||||
$a = str_repeat('0', $y - $x) . $a;
|
|
||||||
|
|
||||||
return [$a, $b, $y];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [$a, $b, $x];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user