|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/liminfinity.edukrypt.in/app/Helpers/ |
Upload File : |
<?php
namespace App\Helpers;
use Illuminate\Support\Facades\DB;
use App\Models\Otpsession;
use App\Models\Email_log;
use Illuminate\Support\Facades\Request;
use carbon\carbon;
use Postal;
class Frontend
{
// Web OTP
public static function send_otp($mobile)
{
// dd($mobile);
$KEY = "JIqYbkePhdgYBbz8";
$TMPID = "1207162141508403142";
$OTP = rand(111111, 999999);
$MSG = urlencode("Dear Student, use OTP code $OTP to verify your account, Edukrypt APP");
//$mobile = $number;
$url = "https://www.hellotext.live/vb/apikey.php?apikey=$KEY&senderid=EDUKYT&templateid=$TMPID&number=$mobile&message=$MSG";
$opts = array('http' => array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$output = file_get_contents($url, false, $context);
$header = json_decode($output);
// dd($header);
if (empty($header) && $header->status != "Success") {
return array();
}
//dd($header);
$data = array(
'message_id' => $header->data->messageid,
'phone' => $mobile,
'otp' => $OTP
);
$otp = Otpsession::create($data);
if ($otp) {
$return_data = array(
'phone' => $mobile,
"message_id" => $header->data->messageid
);
return $return_data;
}
return array();
}
public static function sendMailPostal($to, $subject, $html)
{
$client = new Postal\Client('https://postal.balancepost.in', 'vOJW2d6wG1Cm4qkxitdjziYv');
// Create a new message
$message = new Postal\SendMessage($client);
// Add some recipients
$message->to($to);
//$message->to('mail@globalexcell.co.in');
//$message->cc('vishal@globalexcell.co.in');
//$message->bcc('secret@awesomeapp.com');
$message->from('noreply@edukrypt.in');
// Set the subject
$message->subject($subject);
// Set the content for the e-mail
//$message->plainBody('Hello world!');
$message->htmlBody($html);
// Add any custom headers
//$message->header('X-PHP-Test', 'value');
// Attach any files
//$message->attach('textmessage.txt', 'text/plain', 'Hello world!');
// Send the message and get the result
$result = $message->send();
// dd($result);
if ($result) {
$log_data = array(
'email' => $to
);
Email_log::create($log_data);
}
return $result;
}
public static function makeCartEmpty()
{
// Make Cart Empty
$carts = session()->get('cart');
foreach ($carts as $cart) {
unset($carts[$cart['productId']]);
}
Session()->put('cart', $carts);
}
public static function PushNotification($registation_ids, $title, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$registration_ids = $registation_ids;
$title = htmlspecialchars($title, ENT_COMPAT);
$message = htmlspecialchars($message, ENT_COMPAT);
$icon = htmlspecialchars('icon', ENT_COMPAT);
// Push Datas
$fields = array(
"registration_ids" => $registration_ids,
"notification" => array(
"title" => "{$title}",
"body" => "{$message}",
"icon" => "{$icon}"
),
"data" => array(
"title" => "{$title}",
"body" => "{$message}",
"icon" => "{$icon}"
)
);
$headers = array(
'Authorization: key=' . env('FB_MESSAGE_TOKEN'),
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === false) {
exit('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
public static function getCurrentFinancialYear()
{
$_billing_year = "";
if (date('m') <= 3) {
$_billing_year = (date('Y') - 1) . '-' . date('Y');
} else {
$_billing_year = date('Y') . '-' . (date('Y') + 1);
}
return $_billing_year;
}
public static function numberTowords(float $amount)
{
$amount_after_decimal = round($amount - ($num = floor($amount)), 2) * 100;
// Check if there is any number after decimal
$amt_hundred = null;
$count_length = strlen($num);
$x = 0;
$string = array();
$change_words = array(
0 => '', 1 => 'One', 2 => 'Two',
3 => 'Three', 4 => 'Four', 5 => 'Five', 6 => 'Six',
7 => 'Seven', 8 => 'Eight', 9 => 'Nine',
10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve',
13 => 'Thirteen', 14 => 'Fourteen', 15 => 'Fifteen',
16 => 'Sixteen', 17 => 'Seventeen', 18 => 'Eighteen',
19 => 'Nineteen', 20 => 'Twenty', 30 => 'Thirty',
40 => 'Forty', 50 => 'Fifty', 60 => 'Sixty',
70 => 'Seventy', 80 => 'Eighty', 90 => 'Ninety'
);
$here_digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
while ($x < $count_length) {
$get_divider = ($x == 2) ? 10 : 100;
$amount = floor($num % $get_divider);
$num = floor($num / $get_divider);
$x += $get_divider == 10 ? 1 : 2;
if ($amount) {
$add_plural = (($counter = count($string)) && $amount > 9) ? 's' : null;
$amt_hundred = ($counter == 1 && $string[0]) ? ' and ' : null;
$string[] = ($amount < 21) ? $change_words[$amount] . ' ' . $here_digits[$counter] . $add_plural . '
' . $amt_hundred : $change_words[floor($amount / 10) * 10] . ' ' . $change_words[$amount % 10] . '
' . $here_digits[$counter] . $add_plural . ' ' . $amt_hundred;
} else $string[] = null;
}
$implode_to_Rupees = implode('', array_reverse($string));
$get_paise = ($amount_after_decimal > 0) ? "And " . ($change_words[$amount_after_decimal / 10] . "
" . $change_words[$amount_after_decimal % 10]) . ' Paise' : '';
return ($implode_to_Rupees ? $implode_to_Rupees . 'Rupees ' : '') . $get_paise;
}
public static function getInvoiceSerialNo($admin_id)
{
$_billing = DB::table('billings')->where(['admin_id' => $admin_id, 'payment_status' => 'Credit', 'order_type' => 'paid'])->get()->last();
if (empty($_billing)) {
$serialNo = 1;
} else {
$serialNo = $_billing->serial_no + 1;
}
return $serialNo;
}
public static function getWebsiteInfo($admin_id)
{
$website_info = DB::table('website_info')->where(['admin_id' => $admin_id])->get()->last();
return $website_info;
}
public static function discountCalculation()
{
}
public static function getProductPrice($product_id, $mode)
{
$prices = DB::table('prices')
->where('product_id', $product_id)
->where('mode', $mode)
->first();
return $prices;
// return "hello";
}
// Course List Page
public static function getProductPrice_In_List($product_id)
{
$prices = DB::table('prices')
->where('product_id', $product_id)
->first();
return $prices;
}
public static function getGlobalSetting()
{
$global_settings = DB::table('global_settings')->first();
return $global_settings;
// return "hello";
}
public static function getTeacher($teacher_id)
{
$teacher = DB::table('admin_users')
->where('id', $teacher_id)
->first();
return $teacher;
}
public static function getTotalProduct($admin_id = 2)
{
$products = DB::table('products as P')
->join('main_categories as MC', 'MC.id', '=', 'P.cat_id')
->where(['P.admin_id' => $admin_id, 'P.status' => '1'])
->select('P.*', 'MC.name as category')
->orderBy('sort_order', 'ASC')
->get()->count();
return $products;
}
public static function getChapter($product_id)
{
$catetories = DB::table('categories')->where(['product_id' => $product_id])->get();
return $catetories;
}
// CSV 2 Array
public static function csvToArray($filename = '', $delimiter = ',')
{
if (!file_exists($filename) || !is_readable($filename))
return false;
$header = null;
$data = array();
if (($handle = fopen($filename, 'r')) !== false) {
while (($row = fgetcsv($handle, 1000, $delimiter)) !== false) {
if (!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
}