<?php 
extract($_ENV);

extract($_GET);

extract($_POST);

extract($_COOKIE);

extract($_SERVER); 

mysql_connect("localhost","wilmacin_vinod","vinod69*")or
die("could not connect");
mysql_select_db("wilmacin_wilson")or
die("could not select database");


$brcode='10';
$branch='COIMBATORE';
$company='Wilson Press Tools';

$aresult = mysql_query("select distinct compcode,account_year,name from company") or die(mysql_error());
$arow = mysql_fetch_row($aresult);
$account_year = $arow[1];

function british($indate)
{
	$outdate = substr($indate,8,2).'-'.substr($indate,5,2).'-'.substr($indate,0,4);
	return $outdate;
}

function us($indate)
{
	$outdate = substr($indate,6,4).'-'.substr($indate,3,2).'-'.substr($indate,0,2);
	return $outdate;
}

function british_blank($indate)
{
	if($indate=='00-00-0000')
	{
		$retin = '';
	}
	else
	{
		$retin= $indate;
	}
	return $retin;
}


function us_blank($indate)
{
	if($indate=='0000-00-00')
	{
		$retin = '';
	}
	else
	{
		$retin= $indate;
	}
	return $retin;
}

function datediff($endDate, $beginDate)
{
$dformat ='/';

$beginDate = substr($beginDate ,5,2).'/'.substr($beginDate ,8,2).'/'.substr($beginDate ,0,4);
$endDate = substr($endDate,5,2).'/'.substr($endDate,8,2).'/'.substr($endDate,0,4);		


$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
$mn= $end_date - $start_date;
return $mn;
}

function previous_month($sdt,$endt)
{
$date5 = $sdt;
$curr_month = substr($date5,5,2);
$prev_month = substr($date5,5,2);
while( $prev_month== $curr_month)
{ 
	$sec = mysql_query("select '$date5' -  interval 1 day ");
	$secondday = mysql_fetch_row($sec);
	$nextday = substr($secondday[0],0,4).'-'.substr($secondday[0],5,2).'-'.substr($secondday[0],8,2);
	$prev_month=substr($secondday[0],5,2);
	$date5= $nextday;
}

return $date5;

}

function current_month($sdt)
{
$date5 = $sdt;
$curr_month = substr($date5,5,2);
$next_month = substr($date5,5,2);
while( $next_month== $curr_month)
{ 
	$sec = mysql_query("select '$date5' +  interval 1 day ");
	$secondday = mysql_fetch_row($sec);
	$nextday = substr($secondday[0],0,4).'-'.substr($secondday[0],5,2).'-'.substr($secondday[0],8,2);
	$curr_month=substr($secondday[0],5,2);
	$date5= $nextday;
	//echo("DAT5 : $date5<br>");
}

return $date5;

}


function lastyear($dt)
{
	$sec = mysql_query("select '$dt' -  interval 365 day ");
	$secondday = mysql_fetch_row($sec);
	$nextday = substr($secondday[0],0,4).'-'.substr($secondday[0],5,2).'-'.substr($secondday[0],8,2);	
	return $nextday;
}


function no_of_month($sdt,$endt)
{
$date5 = $sdt;
$first_month = substr($sdt,5,2);
$last_month = substr($endt,5,2);
$count_month =0;
while($date5 < $endt)
{ 
	$sec = mysql_query("select '$date5' +  interval 1 day ");
	$secondday = mysql_fetch_row($sec);
	$nextday = substr($secondday[0],0,4).'-'.substr($secondday[0],5,2).'-'.substr($secondday[0],8,2);
	$curr_month=substr($secondday[0],5,2);
	if($first_month != $curr_month)
	{
		$count_month++;
		$first_month = $curr_month;
	}
	$date5= $nextday;
}

return $count_month;

}



 function connum($num) 
{

$ones = array( "", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine", " Ten",  " Eleven", " Twelve", " Thirteen", " Fourteen", " Fifteen", " Sixteen", " Seventeen", " Eighteen", " Nineteen");


$tensr = array( "","", " Twenty", " Thirty", " Forty", " Fifty", " Sixty", " Seventy", " Eighty", " Ninety");

$triplets = array( "", " thousand",  " million", " billion", " trillion", " quadrillion", " quintillion", " sextillion", " septillion", " octillion", " nonillion");


 // global $ones, $tensr, $triplets;

 
  $number = intval($num);
  $lakhs = (int) ($number/100000);
  $reminder = (int) ($number%100000);
  $thousand = (int) ($reminder / 1000);
  $reminder = (int) ($reminder % 1000);
  $hundred =  (int) ($reminder / 100);
  $reminder = (int) ($reminder % 100);
  $tens = intval($reminder);
  $paise     = round(($num - $number) * 100,0);

  $str = "";

if ($lakhs > 0 && $lakhs < 20)
 	 {
  	 $str .= $ones[$lakhs]." lakhs ";
   	 }
	 elseif($lakhs >=20)
  	 {
	   $str .= $tensr[(int) ($lakhs / 10)] . $ones[$lakhs % 10]." lakhs";
	 }




  if ($thousand > 0 and $thousand < 20)
  	{
	$str .= $ones[$thousand]." thousand ";
   	}
  	elseif($thousand >=20)
  	{
   	$str .= $tensr[(int) ($thousand / 10)] . $ones[$thousand % 10]." thousand";
  	}


if ($hundred > 0)
  	{
   	$str.= $ones[$hundred] . " hundred";
  	}
  
  
if ($tens >0 and $tens < 20)
   	$str .= $ones[$tens];
else
 	$str .= $tensr[(int) ($tens / 10)] . $ones[$tens % 10];


if($paise > 0)
{
if ($paise < 20)
   	$str .= ' and ' .$ones[$paise] . ' paise';
else
   	$str .= ' and '.$tensr[(int) ($paise / 10)] . $ones[$paise % 10] . ' paise';
}
if($num > 0)
	{
	return($str);
	}
else
	{
	return(" ");
	}
}

?>
<script language="JavaScript">
function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}
</script>

