sparqapi/api/application/helpers/myutil_helper.php
2019-03-27 23:17:32 +05:30

127 lines
3.6 KiB
PHP

<?php
class MYUTIL
{
public static function numtowords($number)
{
$no = round($number);
$point = round($number - $no, 2) * 100;
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$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');
$digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
while ($i < $digits_1) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += ($divider == 10) ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? 's' : null;
$hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
$str [] = ($number < 21) ? $words[$number] .
" " . $digits[$counter] . $plural . " " . $hundred
:
$words[floor($number / 10) * 10]
. " " . $words[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else $str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ?
"." . $words[$point / 10] . " " .
$words[$point = $point % 10] : '';
$res = $result . "Rupees " ;
if($points != "")
{
$res.=$points . " Paise";
}
return $res;
}
public static function findCompanyName($array,$companyid,$type)
{
if($array != null && $type==1)
{
foreach($array as $key => $value)
{
if($companyid == $value['company_order_id'])
{
return $value['company_name'];
}
}
}
if($array != null && $type==2)
{
foreach($array as $key => $value)
{
//print_r($value);die();
// echo date("d-m-Y", strtotime($value['business_date_object']) );
// die();
if($companyid == $value['company_order_id'])
{
$getSentense = $value['company_name'];
$getSentense .=' is a ';
$getSentense .=$value['business_entity_type']==1 ? $value['business_entity_type_other'] : $value['business_entity_type_master'];
$getSentense .=' formed on ';
$year_and_month = $value['business_years'] . ' Years';
$year_and_month .= isset($value['business_month']) ? $value['business_month'] . ' months ago': ' ago';
$getSentense .=$value['business_date_object'] ? date("d-m-Y", strtotime($value['business_date_object'])) : $year_and_month;
$getSentense .='.';
return $getSentense;
//return $value['company_name'].' is a '.$value['business_entity_type']==1 ? $value['business_entity_type_other'] : $value['business_entity_type_master'] .' formed on '.date("d-m-Y", strtotime($value['business_date_object']));
}
}
}
else
{
return 'Company Not Found';
}
}
public static function findQuestionByKey($array,$qkey)
{
foreach($array as $key => $value)
{
//echo $value['key'].'--'.$qkey;
if(!strcmp(trim($value['key']),trim($qkey)))
{
// echo "\n";
// echo 'IF'.$value['key'].'--'.$qkey;
return $value['question'];
}
}
}
public static function customIndianNumberFormat($value)
{
$indian_num_format = numfmt_create( 'en_IN', NumberFormatter::CURRENCY );
//echo numfmt_format_currency($indian_num_format,$value, "INR");
return numfmt_format_currency($indian_num_format,$value, "INR");
}
}
?>