File: /var/www/html/fieldsblaze-heroku/app/Library/UserLib.php
<?php
namespace App\Library;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use App\Models\User;
use DB;
class UserLib
{
public function tokenGenrator() {
$length = 100;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ=.';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
//create user id
public function useridGenrator() {
$length = 37;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
//create otp
public function otpGenrator() {
$length = 6;
$characters = '0123456789';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
//tokenChecker
public function tokenChecker($request)
{
$access_token = $request->header('AuthToken');
$UserId = $request->header('UserId');
$auth = DB::table('tbl_user_auth')->where('UserId', $UserId)->where('AuthToken',$access_token)->get();
if ($auth->count() > 0)
{ //token is exist
return TRUE;
}
else
{
//token is not exist
return FALSE;
}
}
//tokenCheckerAdmin
public function tokenCheckerAdmin($request)
{
$access_token = $request->header('AuthToken');
$UserId = $request->header('UserId');
$auth = DB::table('tbl_admin_auth')->where('admin_id', $UserId)->where('AuthToken',$access_token)->get();
if ($auth->count() > 0)
{ //token is exist
return TRUE;
}
else
{
//token is not exist
return FALSE;
}
}
public function generateID($length = 8)
{
$random = "";
srand((double) microtime() * 1000000);
$data = "123456123456789071234567890890";
// $data .= "aBCdefghijklmn123opq45rs67tuv89wxyz"; // if you need alphabatic also
for ($i = 0; $i < $length; $i++) {
$random .= substr($data, (rand() % (strlen($data))), 1);
}
return $random;
}
public function amountInWords(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].' '.$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 . '' : '') . $get_paise;
}
}