<?
include('opendb.php');
date_default_timezone_set("Asia/Calcutta"); 
function getbrname($code,$db)
{
 $rew=mysqli_query($db,"select brname from branch where brcode='$code'");
 $rerow=mysqli_fetch_row($rew);
  return $rerow[0];
}

function getacname($code,$db)
{
 $rew=mysqli_query($db,"select acname from custmaster where brcode='$code' ");
 $rerow=mysqli_fetch_row($rew);
  return $rerow[0];
}



function getrep1($code,$db)
{
 $rew=mysqli_query($db,"select repname from rep_master where code='$code'");
 $rerow=mysqli_fetch_row($rew);
  return $rerow[0];
}

function getphead($exec,$maname,$db)
{
 $rew=mysqli_query($db,"select dgm from saletarget where exec='$exec' and maname='$maname'");
 $rerow=mysqli_fetch_row($rew);
  return $rerow[0];
}

function getdhead($exec,$maname,$db)
{
 $rew=mysqli_query($db,"select dhd from saletarget where exec='$exec' and maname='$maname'");
 $rerow=mysqli_fetch_row($rew);
  return $rerow[0];
}

function GetRegno($ch,$db)
{
 $rew=mysqli_query($db,"select vehicle_no from psnindia_gen4psnauto_psn_psndms.vehlis where chassis_no='$ch'");
 $rerow=mysqli_fetch_row($rew);
  return $rerow[0];
}
function GetJcno($ch,$db)
{
 $rew=mysqli_query($db,"select job_no from psnindia_gen4psnauto_psn_psndms.vehlis where chassis_no='$ch'");
 $rerow=mysqli_fetch_row($rew);
  return $rerow[0];
}
function GetJcdate($ch,$db)
{
 $rew=mysqli_query($db,"select job_date from psnindia_gen4psnauto_psn_psndms.vehlis where chassis_no='$ch'");
 $rerow=mysqli_fetch_row($rew);
  return $rerow[0];
}
function GetJcbr($ch,$db)
{
 $rew=mysqli_query($db,"select brcode from psnindia_gen4psnauto_psn_psndms.vehlis where chassis_no='$ch'");
 $rerow=mysqli_fetch_row($rew);

 $rew1=mysqli_query($db,"select brname from psnindia_gen4psnauto_psn_psndms.branch where brcode='$rerow[0]'");
 $rerow1=mysqli_fetch_row($rew1);

  return $rerow1[0];
}

$regno=GetRegno($row['chasis'],$db);
$jcno=GetJcno($row['chasis'],$db);
$jcdate=GetJcdate($row['chasis'],$db);
$jcbr=GetJcbr($row['chasis'],$db);


date_default_timezone_set("Asia/Kolkata");

function log_entry($brcode,$user,$ip,$act,$db)
{
 $dt=date("Y-m-d H:i:s");
 $sql="insert into log values('$brcode','$user','$ip','$dt','$act')";
 mysqli_query($db,$sql) or die(mysqli_error());
}

function log_entry1($brcode,$user,$ip,$act,$port,$host,$db)
{
 $dt=date("Y-m-d H:i");
 $sql="insert into lognew values('$brcode','$user','$ip','$dt','$act','$port','$host')";
 mysqli_query($db,$sql) or die(mysqli_error());
}

function parseDate($d)
{
 if(strlen($d)<=0)
  return; 
 $ar=explode("-",$d);
 $var=$var.$ar[2]."-".$ar[1]."-".$ar[0];
 return $var;
}
function datetoHtml($d)
{
 $ar=explode("-",$d);
 $var=$ar[2]."-".$ar[1]."-".$ar[0];
 return $var;
}

function expired($d)
{
 $ar=explode("-",$d);
 $dt=mktime(0,0,0,$ar[1],$ar[2],$ar[0]);
 if($dt<time())
  return true;
 else
  return false;
} 

function day($d)
{
 $ar=explode("-",$d);
 if($ar[0]>3000)
  return "Invalid Year";
 if($ar[1]>12)
  return "Invalid Month";
 if($ar[2]>31)
  return "Invalid Date";
 
 $dt=mktime(0,0,0,$ar[1],$ar[2],$ar[0]);
 return date("l",$dt); 
}
function nDays($date)
{
 $d=explode("-",$date);
 $m=$d[1];
 $y=$d[0];
 $dt2=mktime(0,0,0,$m,1,$y);
  $dd=date("M/j/Y",$dt2); 
$leap= date("L",$dt2);

 if($m==1)
  return 31;
 else if($m==2)
  {
      if($leap==0)
         return 28;
      else
          return 29;
  }
 else if($m==3)
  return 31;
 else if($m==4)
  return 30;
 else if($m==5)
  return 31;
 else if($m==6)
  return 30;
 else if($m==7)
  return 31;
 else if($m==8)
  return 31;
 else if($m==9)
  return 30;
 else if($m==10)
  return 31;
 else if($m==11)
  return 30;
 else if($m==12)
  return 31;
}

function fortextarea($val)
{
 $x=str_replace("<br>","&#10;",$val);
 $y=str_replace("<hr>","&#10;&#45;&#45;&#10;",$x);
 return $y;
}

function htmlValidate($a)
{
 return nl2br(str_replace("--","-----",$a));
}
//***************** number to words
function word_new($x)
{
$x=str_replace(".","-",$x);
$num=explode('-',$x); 

if($num[1]>0)
{
 $m="".ConvertToWords($num[0])." and ".ConvertToWords($num[1])." paise";
 return $m;
}
else
{ $m= "".ConvertToWords($num[0]);
 return $m;
}
}

function word($x)
{
$x=str_replace(".","-",$x);
$num=explode('-',$x); 

if($num[1]>0)
{
 $m="Rupees ".ConvertToWords($num[0])." and ".ConvertToWords($num[1])." paise";
 return $m;
}
else
{ $m= "Rupees ".ConvertToWords($num[0]);
 return $m;
}

}
 function ConvertToWords($n, $followup='')  
 {  
     if($n==0)  
     {  
         if($followup=='no')  
         {  
             return "";  
             exit();  
         }  
        else  
         {  
             return "zero";  
             exit();  
         }  
     }  
     switch($n)  
    {  
         case 1: return "one"; break;  
         case 2: return "two"; break;  
         case 3: return "three"; break;  
         case 4: return "four"; break;  
         case 5: return "five"; break;  
         case 6: return "six"; break;  
         case 7: return "seven"; break;  
         case 8: return "eight"; break;  
         case 9: return "nine"; break;  
         case 10: return "ten"; break;  
         case 11: return "eleven"; break;  
         case 12: return "twelve"; break;  
         case 13: return "thirteen"; break;  
         case 14: return "fourteen"; break;  
         case 15: return "fifteen"; break;  
         case 16: return "sixteen"; break;  
         case 17: return "seventeen"; break;  
         case 18: return "eighteen"; break;  
         case 19: return "nineteen"; break;  
        case 20: return "twenty"; break;  
         case 30: return "thirty"; break;  
         case 40: return "forty"; break;  
         case 50: return "fifty"; break;  
         case 60: return "sixty"; break;  
         case 70: return "seventy"; break;  
         case 80: return "eighty"; break;  
         case 90: return "ninety"; break;  
         case 100: return "one hundred"; break;  
         case 1000: return "one thousand"; break;  
         case 100000: return "one lakh"; break;  
         default:  
         {  
             if($n<100)  
             {  
                 return ConvertToWords(floor($n/10)*10, 'no')."-".ConvertToWords($n%10, 'no'); break;  
             }  
             elseif($n<1000)  
             {  
                 return ConvertToWords(floor($n/100), 'no')." hundred ".ConvertToWords($n%100, 'no'); break;  
             }  
             elseif($n<100000)  
             {  
                 return ConvertToWords(floor($n/1000), 'no')." thousand ".ConvertToWords($n%1000, 'no'); break;  
             }  
             elseif($n<10000000)  
             {  
                 return ConvertToWords(floor($n/100000), 'no')." lakh ".ConvertToWords($n%100000, 'no'); break;  
             }  
             else  
             {  
                 return "Something else"; break;  
             }  
         }  
     }  
 }  

/*****************************************************************************/
function word1($x)
{
$x=str_replace(".","-",$x);
$num=explode('-',$x); 
/*
if(substr($num[0],0,1)==0)
{ $val.=' ';
 $x=substr($num[0],1);
 $val.=word($x);
}
*/
 if($num[0]<=20)
 {
   switch($num[0])
   {
    case 0:
     $val.=" ";
     break;
     case 1:
      $val="one";
      break;
     case 2:
      $val="two";
      break;
     case 3:
      $val="three";
      break;
     case 4:
      $val="four";
      break;
     case 5:
      $val="five";
      break;
     case 6:
      $val="six";
      break;
     case 7:
      $val="seven";
      break;
     case 8:
      $val="eight";
      break;
     case 9:
      $val="nine";
      break;
     case 10:
      $val="ten";
      break;
     case 11:
      $val="eleven";
      break;
     case 12:
      $val="twelve";
      break;
     case 13:
      $val="thirteen";
      break;
     case 14:
      $val="fourteen";
      break;
     case 15:
      $val="fifteen";
      break;
     case 16:
      $val="sixteen";
      break;
     case 17:
      $val="seventeen";
      break;
     case 18:
      $val="eighteen";
      break;
     case 19:
      $val="nineteen";
      break;
     case 20:
      $val="twenty";
      break;
}
} //end if
else if($num[0]>20 && $num[0]<30)
{
 $val=" twenty ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=30 && $num[0]<40)
{
 $val=" thirty ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=40 && $num[0]<50)
{
 $val=" fourty ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=50 && $num[0]<60)
{
 $val=" fifty ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=60 && $num[0]<70)
{
 $val=" sixty ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=70 && $num[0]<80)
{
 $val=" seventy ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=80 && $num[0]<90)
{
 $val=" eighty ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=90 && $num[0]<100)
{
 $val=" ninety ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=100 && $num[0]<200)
{
 $val="one hundred ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=200 && $num[0]<300)
{
 $val=" two hundred ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=300 && $num[0]<400)
{
 $val=" three hundred ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=400 && $num[0]<500)
{
 $val="four hundred ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=500 && $num[0]<600)
{
 $val=" five hundred ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=600 && $num[0]<700)
{
 $val=" six hundred ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=700 && $num[0]<800)
{
 $val=" seven hundred ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=800 && $num[0]<900)
{
 $val=" eight hundred ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=900 && $num[0]<1000)
{
 $val="nine hundred and ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=1000 && $num[0]<10000)
{
 $x=substr($num[0],0,1); 
 $val.=word($x)." thousand ";
 $x=substr($num[0],1);
 $val.=word($x);
}
else if($num[0]>=10000 && $num[0]<100000)
{
 $x=substr($num[0],0,2); 
 $val.=word($x)." thousand ";
 $x=substr($num[0],2);
 $val.=word($x);
}
else if($num[0]>=100000 && $num[0]<1000000)
{
 $x=substr($num[0],0,1); 
 $val.=word($x)." Lakh ";
 $x=substr($num[0],1,2);
 if($x>0)
  $val.=word($x)." thousand ";
  $x=substr($num[0],3,3);
 $val.=word($x);
 //$x=substr($num[0],4);print $x;
// $val.=word($x);
}
else if($num[0]>=1000000 && $num[0]<10000000)
{
 $x=substr($num[0],0,2); 
 $val.=word($x)." Lakh ";
 $x=substr($num[0],2,2);
 if($x>0)
 $val.=word($x)." thousand ";
 $x=substr($num[0],4,1);
 if($x>0)
 $val.=word($x)." hundred ";
 $x=substr($num[0],5,2);
 if($x>0)
 $val.=word($x); 

}
//***********************************************************************

if($num[1]>0)
{
 $val.= " And ";
 if($num[1]<=20)
 {
   switch($num[1])
   {
    case 0:
     $val.=" ";
     break;
     case 1:
      $val.="one";
      break;
     case 2:
      $val.="two";
      break;
     case 3:
      $val.="three";
      break;
     case 4:
      $val.="four";
      break;
     case 5:
      $val.="five";
      break;
     case 6:
      $val.="six";
      break;
     case 7:
      $val.="seven";
      break;
     case 8:
      $val.="eight";
      break;
     case 9:
      $val.="nine";
      break;
     case 10:
      $val.="ten";
      break;
     case 11:
      $val.="eleven";
      break;
     case 12:
      $val.="twelve";
      break;
     case 13:
      $val.="thirteen";
      break;
     case 14:
      $val.="fourteen";
      break;
     case 15:
      $val.="fifteen";
      break;
     case 16:
      $val.="sixteen";
      break;
     case 17:
      $val.="seventeen";
      break;
     case 18:
      $val.="eighteen";
      break;
     case 19:
      $val.="nineteen";
      break;
     case 20:
      $val.="twenty";
      break;
}
} //endif
else if($num[1]>20 && $num[1]<30)
{
 $val.="twenty ";
 $x=substr($num[1],1);
 $val.=word($x);
}
else if($num[1]>=30 && $num[1]<40)
{
 $val.="thirty ";
 $x=substr($num[1],1);
 $val.=word($x);
}
else if($num[1]>=40 && $num[1]<50)
{
 $val.="fourty ";
 $x=substr($num[1],1);
 $val.=word($x);
}
else if($num[1]>=50 && $num[1]<60)
{
 $val.="fifty ";
 $x=substr($num[1],1);
 $val.=word($x);
}
else if($num[1]>=60 && $num[1]<70)
{
 $val.="sixty ";
 $x=substr($num[1],1);
 $val.=word($x);
}
else if($num[1]>=70 && $num[1]<80)
{
 $val.="seventy ";
 $x=substr($num[1],1);
 $val.=word($x);
}
else if($num[1]>=80 && $num[1]<90)
{
 $val.="eighty ";
 $x=substr($num[1],1);
 $val.=word($x);
}
else if($num[1]>=90 && $num[1]<100)
{
 $val.="ninety ";
 $x=substr($num[1],1);
 $val.=word($x);
}
$val.=" paise";
}
 
return strtoupper($val);
}
//*******************************
function putComa($num)
{
 if(strlen($num)==0)
  return;
 
 if(strlen(strstr($num,"."))<=0)
  { 
    $v=$num.".00";
  }
  else $v=$num;
 $a='';
    $a=explode(".",$v);
 if(strlen($a[1])==1)
  $v.="0";
//print $v;
 if(strlen($a[0])>8)
 {
  $v=substr($v,0,2).",".substr($v,2,2).",".substr($v,4,2).",".substr($v,6);
 }
 else if(strlen($a[0])>7)
 {
  $v=substr($v,0,1).",".substr($v,1,2).",".substr($v,3,2).",".substr($v,5);
 }
 else if(strlen($a[0])>6)
 {
  $v=substr($v,0,2).",".substr($v,2,2).",".substr($v,4);
 }
 else if(strlen($a[0])>5)
 {
  $v=substr($v,0,1).",".substr($v,1,2).",".substr($v,3);
 }
 else if(strlen($a[0])>4)
 {
  $v=substr($v,0,2).",".substr($v,2,6);
 }
 else if(strlen($a[0])>3)
 {
  $v=substr($v,0,1).",".substr($v,1);
 }
 return $v;
}

function nozero($x)
{
 if($x==0)
   return ' ';
 else
   return $x;
}

?>
