<?php
namespace App\Helpers;
use App\Models\Setting;
use App\Models\UserLog;
class Helper {
public static function getController($controller) {
return 'App\Http\Controllers\\' . $controller;
}
public static function countPembayaranTransferPending() {
return \App\Models\Pembayaran::has('siswa')->where('metode_pembayaran','transfer')->where('status_pembayaran', 'pending')->count();
}
//add active css class
public static function setActive($route) {
return request()->is($route) ? 'active' : '';
}
public static function addUserLog($activity) {
$ip_address = request()->ip();
$log = new UserLog;
$log->user_id = auth()->user()->id;
$log->activity = $activity;
$log->ip_address = $ip_address;
$log->save();
}
public static function sendWa($number, $message,$file=null)
{
//jika nomor kosong
if ($number === "" || $number === null || strlen($number) < 4) {
return "nomor hp kosong";
}
$ptn = "/^0/"; // Regex
$rpltxt = "+62"; // Replacement string
$number = preg_replace($ptn, $rpltxt, "$number");
// if still doesnt have +62
if (strpos($number, '+62') === false) {
$number = '+62' . $number;
}
$key = Setting::get('woo_wa_key');
$url = 'http://116.203.191.58/api/async_send_message';
$data = array(
"phone_no" => $number,
"key" => $key,
"message" => $message,
// "url" =>$img_url,
);
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 360);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
)
);
$res = curl_exec($ch);
curl_close($ch);
// Log::info("WA : ".$res);
if($file){
$url = 'http://116.203.191.58/api/async_send_file_url';
$data = array(
"phone_no" => $number,
"key" => $key,
"url" => $file,
// "url" =>$img_url,
);
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 360);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
)
);
$res = curl_exec($ch);
curl_close($ch);
}
return $res;
}
public static function bulanIndo($bulan){
$bulan = (int) $bulan;
$arrBulan = [
1 => 'Januari',
2 => 'Februari',
3 => 'Maret',
4 => 'April',
5 => 'Mei',
6 => 'Juni',
7 => 'Juli',
8 => 'Agustus',
9 => 'September',
10 => 'Oktober',
11 => 'November',
12 => 'Desember',
];
return $arrBulan[$bulan];
}
public static function terbilang($nominal){
$angka = [
'',
'Satu',
'Dua',
'Tiga',
'Empat',
'Lima',
'Enam',
'Tujuh',
'Delapan',
'Sembilan',
'Sepuluh',
'Sebelas'
];
if ($nominal < 12) {
return $angka[$nominal];
} elseif ($nominal < 20) {
return self::terbilang($nominal - 10) . ' Belas';
} elseif ($nominal < 100) {
return self::terbilang($nominal / 10) . ' Puluh ' . self::terbilang($nominal % 10);
} elseif ($nominal < 200) {
return 'Seratus ' . self::terbilang($nominal - 100);
} elseif ($nominal < 1000) {
return self::terbilang($nominal / 100) . ' Ratus ' . self::terbilang($nominal % 100);
} elseif ($nominal < 2000) {
return 'Seribu ' . self::terbilang($nominal - 1000);
} elseif ($nominal < 1000000) {
return self::terbilang($nominal / 1000) . ' Ribu ' . self::terbilang($nominal % 1000);
} elseif ($nominal < 1000000000) {
return self::terbilang($nominal / 1000000) . ' Juta ' . self::terbilang($nominal % 1000000);
} elseif ($nominal < 1000000000000) {
return self::terbilang($nominal / 1000000000) . ' Milyar ' . self::terbilang($nominal % 1000000000);
} elseif ($nominal < 1000000000000000) {
return self::terbilang($nominal / 1000000000000) . ' Trilyun ' . self::terbilang($nominal % 1000000000000);
}
}
//$day is monday, tuesday, etc
public static function hariIndo($day){
$day = strtolower($day);
$arrDay = [
'monday' => 'Senin',
'tuesday' => 'Selasa',
'wednesday' => 'Rabu',
'thursday' => 'Kamis',
'friday' => 'Jumat',
'saturday' => 'Sabtu',
'sunday' => 'Minggu',
];
return $arrDay[$day];
}
public static function setting($key){
return Setting::get($key);
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]