<? include("../../include/dbconnect.php"); 

function recalc()
{
	$result= mysql_query("select distinct prodcode from stktrans order by prodcode") or die(mysql_error());
	while($row=mysql_fetch_row($result))
	{
		$fchk='F';
		$qtysel = mysql_query("select opbal,prqty,selqty,record from stktrans where prodcode = '$row[0]'  order by prodcode,date,selqty,prqty") or die(mysql_error());
		while($qrow=mysql_fetch_row($qtysel))
		{
			if($fchk=="F")
			{
				$opbal=$qrow[0];
				$fchk="T";
			}
			$prqty=$qrow[1];
			$selqty=$qrow[2];
			$record=$qrow[3];
			$clbal = $opbal+$prqty-$selqty;
			$query="update stktrans set opbal = '$opbal',clbal='$clbal' where record ='$record' ";
			mysql_query($query) or die(mysql_error());
			if($fchk=='T')
			{
				$opbal=$clbal;
			}
		}	
	}

}


 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(" ");
	}
}
?>

