change namespace to Webapp\

This commit is contained in:
2026-08-26 14:01:47 +07:00
parent 81ff3bc60c
commit 64e9c02c38
26 changed files with 179 additions and 181 deletions
+91 -90
View File
@@ -16,20 +16,20 @@ declare(strict_types=1);
/*************************** FORMAT ANGKA / CURRENCY *****************************/
if (!function_exists('rupiah')) {//oke
function rupiah(string|float $angka = 0, int $desi = 0): string {
return number_format((float)$angka, $desi, ",", ".");
if (!function_exists('rupiah')) {
function rupiah(mixed $angka = 0, int $desi = 0): string {
return number_format((float) $angka, $desi, ",", ".");
}
}
if (!function_exists('rupiah2')) {//oke
function rupiah2($angka = 0): string {
if (!function_exists('rupiah2')) {
function rupiah2(mixed $angka = 0): string {
return rupiah($angka, 2);
}
}
//todo: deprecated
/*if (!function_exists('rupiah30')) {
/* todo: deprecated
if (!function_exists('rupiah30')) {
function rupiah30($angka = 0): string {
$nilai = explode(".", $angka);
$hasil = (intval($nilai[1])==0) ? rupiah($angka, 0) : rupiah($angka, 3);
@@ -38,77 +38,78 @@ if (!function_exists('rupiah2')) {//oke
}*/
if (!function_exists('kurung_rup')) {
function kurung_rup($angka = 0, $desi = 0) {
$thasil = rupiah(abs($angka), $desi);
if ($angka<0) return "(".$thasil.")";
function kurung_rup(mixed $angka = 0, int $desi = 0): string {
$thasil = rupiah(abs((float) $angka), $desi);
if ((float) $angka < 0) return "(".$thasil.")";
return $thasil." ";
}
}
if (!function_exists('kurung')) {
function kurung($angka = 0, $desi = 0) {
$thasil = uang(abs($angka), $desi);
if ($angka<0) return "(".$thasil.")";
function kurung(mixed $angka = 0, int $desi = 0): string {
$thasil = uang(abs((float) $angka), $desi);
if ((float) $angka < 0) return "(".$thasil.")";
return $thasil." ";
}
}
if (!function_exists('kurung2')) {
function kurung2($angka = 0) {
function kurung2(mixed $angka = 0): string {
return kurung($angka, 2);
}
}
if (!function_exists('uang')) {//oke
function uang(string|float $angka = '0', int $desi = 0) {
$angka = str_replace(",", "", (string)$angka);
return number_format((float)$angka, $desi);
if (!function_exists('uang')) {
function uang(mixed $angka = 0, int $desi = 0): string {
$angka = str_replace(",", "", (string) $angka);
return number_format((float) $angka, $desi);
}
}
if (!function_exists('uang2')) {
function uang2($angka = 0) {
function uang2(mixed $angka = 0): string {
return uang($angka, 2);
}
}
/* todo: deprecated
if (!function_exists('koma30')) {
function koma30($angka = 0) {
$nilai = explode(".", $angka);
$hasil = (intval($nilai[1])==0) ? uang($angka, 0) : uang($angka, 3);
return $hasil;
}
}
}*/
if (!function_exists('items')) {
function items($item = 0) {
function items(mixed $item = 0): string {
return rupiah($item)." Items";
}
}
if (!function_exists('records')) {
function records($item = 0) {
function records(mixed $item = 0): string {
return rupiah($item)." Records";
}
}
if (!function_exists('baris')) {
function baris($item = 0) {
function baris(mixed $item = 0): string {
return rupiah($item)." Baris";
}
}
if (!function_exists('npwp')) {
function npwp($nomor = "000000000000000") {
function npwp(string $nomor = "000000000000000"): string {
return substr($nomor,0,2).".".substr($nomor,2,3).".".substr($nomor,5,3).".".substr($nomor,8,1)."-".substr($nomor,9,3).".".substr($nomor,12,3);
}
}
if (!function_exists('romawi')) {
function romawi($n) {
function romawi(int $n): string {
$hasil = "";
$iromawi = array("","I","II","III","IV","V","VI","VII","VIII","IX","X",20=>"XX",30=>"XXX",40=>"XL",50=>"L",60=>"LX",70=>"LXX",80=>"LXXX",90=>"XC",100=>"C",200=>"CC",300=>"CCC",400=>"CD",500=>"D",600=>"DC",700=>"DCC",800=>"DCCC",900=>"CM",1000=>"M",2000=>"MM",3000=>"MMM");
if (array_key_exists($n,$iromawi)) {
$iromawi = ["","I","II","III","IV","V","VI","VII","VIII","IX","X",20=>"XX",30=>"XXX",40=>"XL",50=>"L",60=>"LX",70=>"LXX",80=>"LXXX",90=>"XC",100=>"C",200=>"CC",300=>"CCC",400=>"CD",500=>"D",600=>"DC",700=>"DCC",800=>"DCCC",900=>"CM",1000=>"M",2000=>"MM",3000=>"MMM"];
if (array_key_exists($n, $iromawi)) {
$hasil = $iromawi[$n];
} else if ($n >= 11 && $n <= 99) {
$i = $n % 10;
@@ -125,7 +126,7 @@ if (!function_exists('romawi')) {
}
if (!function_exists('abjad')) {
function abjad($n) {
function abjad(int $n): string {
$_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return substr($_str, ($n-1), 1);
}
@@ -134,8 +135,8 @@ if (!function_exists('abjad')) {
/*************************** FORM CONTROL *****************************/
if (!function_exists('checkbox')) {
function checkbox($nilai = 0) {
$thasil = ((is_string($nilai) && ($nilai=="N" || $nilai=="0")) or (is_numeric($nilai) && $nilai==0) or (is_bool($nilai) && $nilai==false)) ? "circle text-secondary" : "check-circle text-info";
function checkbox(mixed $nilai): string {
$thasil = (empty($nilai) or (is_string($nilai) && ($nilai=="N" || $nilai=="0")) or (is_numeric($nilai) && $nilai==0) or (is_bool($nilai) && $nilai==false)) ? "circle text-secondary" : "check-circle text-info";
return '<i class="fs-6 bi-'.$thasil.'"></i>';
}
}
@@ -143,34 +144,34 @@ if (!function_exists('checkbox')) {
/*************************** FORMAT TANGGAL / KALENDER *****************************/
if (!function_exists('sqltgl')) {
function sqltgl($waktu = "0") {
function sqltgl(string $waktu): string {
return tgl_sql2str($waktu);
}
}
if (!function_exists('sqltgls')) {
function sqltgls($waktu = "0") {
function sqltgls(string $waktu): string {
return tgl_sql2str($waktu, false, true);
}
}
if (!function_exists('sqljam')) {
function sqljam($waktu = "0") {
function sqljam(string $waktu): string {
return tgl_sql2str($waktu, true);
}
}
if (!function_exists('sqljams')) {
function sqljams($waktu = "0") {
function sqljams(string $waktu): string {
return tgl_sql2str($waktu, true, true);
}
}
if (!function_exists('tgl_sql2str')) {
function tgl_sql2str($waktu = "0", $jam = false, $short = false) {
if ($waktu=="0" || $waktu=="") return;
function tgl_sql2str(string $waktu, bool $jam = false, bool $short = false): string {
if (empty($waktu)) return '';
$atgl = explode(" ", $waktu);
$sjam = ($jam) ? ((empty($atgl[1]))?date("H:i:s"):$atgl[1]) : "";
$sjam = ($jam) ? ((empty($atgl[1])) ? date("H:i:s") : $atgl[1]) : "";
$atgl = explode("-", $atgl[0]);
$stgl = $atgl[2]."-".$atgl[1]."-".$atgl[0];
if ($short) $stgl = $atgl[2].".".$atgl[1].".".substr($atgl[0],2);
@@ -179,66 +180,66 @@ if (!function_exists('tgl_sql2str')) {
}
if (!function_exists('tgl_ymd')) {
function tgl_ymd($jam = false) {
function tgl_ymd(bool $jam = false): string {
return (($jam) ? date("Y-m-d H:i:s") : date("Y-m-d"));
}
}
if (!function_exists('tgl_dmy')) {
function tgl_dmy($jam = false) {
function tgl_dmy(bool $jam = false): string {
return (($jam) ? date("d-m-Y H:i:s") : date("d-m-Y"));
}
}
if (!function_exists('tgl_operasi')) {
function tgl_operasi($dtgl = "", $nhari = 0, $nbln = 0, $nthn = 0) {
$atgl = explode("-", $dtgl);
return date("d-m-Y", mktime(0,0,0, $atgl[1]+$nbln, $atgl[0]+$nhari, $atgl[2]+$nthn));
function tgl_operasi(string $tgl, int $hari = 0, int $bln = 0, int $thn = 0): string {
$atgl = explode("-", $tgl);
return date("d-m-Y", mktime(0,0,0, (int) $atgl[1]+$bln, (int) $atgl[0]+$hari, (int) $atgl[2]+$thn));
}
}
if (!function_exists('tgl_range_hari')) {
function tgl_range_hari($dftgl="", $dttgl="", $bhitung_awal=false) {
$_start = strtotime(tgl_sql2str($dftgl));
$_end = strtotime(tgl_sql2str($dttgl));
return ceil(abs($_end - $_start) / 86400) + (($bhitung_awal==true)?1:0);
function tgl_range_hari(string $tgl_from, string $tgl_to, bool $hitung_awal = false): float {
if (empty($tgl_to) or empty($tgl_from)) return 0;
$_start = strtotime(tgl_sql2str($tgl_from));
$_end = strtotime(tgl_sql2str($tgl_to));
return ceil(abs($_end - $_start) / 86400) + (($hitung_awal)?1:0);
}
}
if (!function_exists('tgl_akhbln')) {
function tgl_akhbln($tgl) {
function tgl_akhbln(string $tgl): string {
if (empty($tgl)) return '';
$atgl = explode("-", $tgl);
$ablna = array(31,28,31,30,31,30,31,31,30,31,30,31);
$ablna = ['31','28','31','30','31','30','31','31','30','31','30','31'];
// jika tahun masehi dan bulan 2
if ( (round($atgl[2]/4)==($atgl[2]/4)) && intval($atgl[1])==2 ) return "29-02-".$atgl[2];
return $ablna[(intval($atgl[1])-1)]."-".isi_nol($atgl[1],2)."-".$atgl[2];
if ((round((int) $atgl[2]/4) === ((int) $atgl[2]/4)) && (int) $atgl[1] === 2) return "29-02-".$atgl[2];
return $ablna[(int) $atgl[1]-1]."-".isi_nol($atgl[1],2)."-".$atgl[2];
}
}
if (!function_exists('tgl_panjang')) {
function tgl_panjang($dtgl = "") {
if (trim($dtgl)=="") $dtgl = tgl_dmy();
$atgl = explode("-", $dtgl);
function tgl_panjang(string $tgl): string {
if (empty($tgl)) $tgl = tgl_dmy();
$atgl = explode("-", $tgl);
$abulan = bulan_array();
return $atgl[0]." ".$abulan[intval($atgl[1])]." ".$atgl[2];
return $atgl[0]." ".$abulan[$atgl[1]]." ".$atgl[2];
}
}
if (!function_exists('tgl_hari')) {
function tgl_hari($dtgl = "") {
function tgl_hari(string $tgl): string {
$nhari = date("w");
if (trim($dtgl)!="") {
//$atgl = getdate($dtgl);
//$nhari = $atgl[wday];
$nhari = date("w", strtotime(tgl_sql2str($dtgl)));
if (!empty($tgl)) {
$nhari = date("w", strtotime(tgl_sql2str($tgl)));
}
$ahari = array("0"=>"Minggu","1"=>"Senin","2"=>"Selasa","3"=>"Rabu","4"=>"Kamis","5"=>"Jum'at","6"=>"Sabtu");
$ahari = ["0"=>"Minggu","1"=>"Senin","2"=>"Selasa","3"=>"Rabu","4"=>"Kamis","5"=>"Jum'at","6"=>"Sabtu"];
return $ahari[$nhari];
}
}
if (!function_exists('tgl_triwulan')) {
function tgl_triwulan($dtgl = "") {
if ($dtgl == "") {
function tgl_triwulan(string $tgl): int {
if (empty($tgl)) {
$dtgl = date("m");
} else {
$atgl = explode("-", $tgl);
@@ -254,13 +255,13 @@ if (!function_exists('tgl_triwulan')) {
}
if (!function_exists('bulan_array')) {
function bulan_array() {
return array("1"=>"Januari","2"=>"Februari","3"=>"Maret","4"=>"April","5"=>"Mei","6"=>"Juni","7"=>"Juli","8"=>"Agustus","9"=>"September","10"=>"Oktober","11"=>"November","12"=>"Desember");
function bulan_array(): array {
return ["1"=>"Januari","2"=>"Februari","3"=>"Maret","4"=>"April","5"=>"Mei","6"=>"Juni","7"=>"Juli","8"=>"Agustus","9"=>"September","10"=>"Oktober","11"=>"November","12"=>"Desember"];
}
}
if (!function_exists('triwulan_array')) {
function triwulan_array() {
function triwulan_array(): array {
return ["1"=>"Triwulan 1","2"=>"Triwulan 2","3"=>"Triwulan 3","4"=>"Triwulan 4"];
}
}
@@ -268,24 +269,25 @@ if (!function_exists('triwulan_array')) {
/*************************** FORMAT TAMPILAN & ERROR *****************************/
if (!function_exists('subjudul')) {
function subjudul($tjudul) {
return '<table border="0" align="center" valign="middle" width="100%" height="26px"><tr><td width="50%"><hr /></td><td>&nbsp;&nbsp;<span style="text-align:center;font-weight:bold;white-space:nowrap;">'.$tjudul.'</span>&nbsp;&nbsp;</td><td width="50%"><hr /></td></tr></table>';
function subjudul(string $judul): string {
return '<table border="0" align="center" valign="middle" width="100%" height="26px"><tr><td width="50%"><hr /></td><td>&nbsp;&nbsp;<span style="text-align:center;font-weight:bold;white-space:nowrap;">'.$judul.'</span>&nbsp;&nbsp;</td><td width="50%"><hr /></td></tr></table>';
}
}
/* todo: deprecated
if (!function_exists('showerror')) {
function showerror($terror) {
echo '<input type="hidden" id="_Error" class="error" value="'.$terror.'!" />';
function showerror(string $error): void {
echo '<input type="hidden" id="_Error" class="error" value="'.$error.'!" />';
}
}
}*/
if (!function_exists('br2nl')) {
function br2nl($string) {
function br2nl(string $string): string {
return preg_replace('/\<br(\s*)?\/?\>/i', "\n\r", $string);
}
}
if (!function_exists('isi_nol')) {//oke
if (!function_exists('isi_nol')) {
function isi_nol(string|int $nilai = 0, int $panjang = 1): string {
$nilai = (string)$nilai;
return ($panjang>strlen($nilai) ? str_repeat("0", $panjang-strlen($nilai)):'').$nilai;
@@ -293,7 +295,7 @@ if (!function_exists('isi_nol')) {//oke
}
if (!function_exists('isMobile')) {
function isMobile() {
function isMobile(): bool {
$agen = $_SERVER['HTTP_USER_AGENT'];
$amobile = ['Android', 'webOS', 'iPhone', 'iPad', 'iPod', 'BlackBerry', 'Windows Phone', 'Mobile'];
foreach ($amobile as $keyword) {
@@ -304,46 +306,47 @@ if (!function_exists('isMobile')) {
}
if (!function_exists('isLinux')) {
function isLinux() {
function isLinux(): bool {
$agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen,'linux') !== false) return true;
if (stripos($agen, 'linux') !== false) return true;
return false;
}
}
if (!function_exists('isIE')) {
function isIE() {
function isIE(): bool {
$agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen,'msie') !== false) return true;
if (stripos($agen, 'msie') !== false) return true;
return false;
}
}
if (!function_exists('isChrome')) {
function isChrome() {
function isChrome(): bool {
$agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen,'chrome') !== false) return true;
if (stripos($agen, 'chrome') !== false) return true;
return false;
}
}
if (!function_exists('isFirefox')) {
function isFirefox() {
function isFirefox(): bool {
$agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen,'firefox') !== false) return true;
if (stripos($agen, 'firefox') !== false) return true;
return false;
}
}
/* todo: deprecated
if (!function_exists('potong')) {
function potong($nilai) {//utk rkpd
return substr($nilai, 0, 60);
}
}
}*/
if (!function_exists('format_bytes')) {
function format_bytes($bytes) {
if ($bytes < 1024) return $bytes.' B';
function format_bytes(int $bytes): string {
if ($bytes < 1024) return (string) $bytes.' B';
elseif ($bytes < 1048576) return uang2($bytes / 1024).' KB';
elseif ($bytes < 1073741824) return uang2($bytes / 1048576).' MB';
elseif ($bytes < 1099511627776) return uang2($bytes / 1073741824).' GB';
@@ -352,12 +355,10 @@ if (!function_exists('format_bytes')) {
}
if (!function_exists('random_color')) {
function random_color($trans = "0.6") {
$col_r = mt_rand( 0, 255 );
$col_g = mt_rand( 0, 255 );
$col_b = mt_rand( 0, 255 );
function random_color(string $trans = "0.6"): string {
$col_r = (string) mt_rand( 0, 255 );
$col_g = (string) mt_rand( 0, 255 );
$col_b = (string) mt_rand( 0, 255 );
return "rgba(".$col_r.",".$col_g.",".$col_b.",".$trans.")";
}
}
?>