<?php 
session_start();
include "../../../config/database.php";
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
include "../../../config/function.php";
$take_action1   = new actionDo();


$MAIN_sql			= mysql_query(" SELECT * FROM `client_logo` ")or die(mysql_error());
$MAIN_data			= mysql_fetch_array($MAIN_sql);


ini_set('max_input_vars',10000);
ini_set('max_post_vars',10000);
ini_set('max_request_vars',10000);

function get_word($val)
{
    $number = $val;
	$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) ? ' ' : 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] : '';
	if(!empty($points))
	{   return $result . "Rupees  " . $points . " Paise";	}
	else
	{	return $result . "   "; }
} 
function makecomma($input)
{
    // This function is written by some anonymous person - I got it from Google
    if(strlen($input)<=2)
    { return $input; }
    $length=substr($input,0,strlen($input)-2);
    $formatted_input = makecomma($length).",".substr($input,-2);
    return $formatted_input;
}

function formatInIndianStyle($num)
{
    // This is my function
    $pos = strpos((string)$num, ".");
    if ($pos === false) { $decimalpart="00";}
    else { $decimalpart= substr($num, $pos+1, 2); $num = substr($num,0,$pos); }

    if(strlen($num)>3 & strlen($num) <= 12){
                $last3digits = substr($num, -3 );
                $numexceptlastdigits = substr($num, 0, -3 );
                $formatted = makecomma($numexceptlastdigits);
                $stringtoreturn = $formatted.",".$last3digits.".".$decimalpart ;
    }elseif(strlen($num)<=3){
                $stringtoreturn = $num.".".$decimalpart ;
    }elseif(strlen($num)>12){
                $stringtoreturn = number_format($num, 2);
    }

    if(substr($stringtoreturn,0,2)=="-,"){$stringtoreturn = "-".substr($stringtoreturn,2 );}

    return $stringtoreturn;
}

//// Check Bill Exists or Not
$invoice_no		 = $_GET['invoice_no'];
$invoice_prefix	 = $_GET['invoice_prefix'];
$pre_qry		 = "";
if(!empty($invoice_prefix))
{
	$pre_qry	 = " and `invoice_prefix`='$invoice_prefix' ";
}

$sql_no			 = mysql_query("select * from `tbl_invoice` where `invoice_no`='$invoice_no' $pre_qry ")or die(mysql_error());
$data_no		 = mysql_fetch_array($sql_no);
$monthName  	 = date('F', mktime(0, 0, 0, $data_no['month'], 10));
$month			 = $data_no['month'];
$year			 = $data_no['year'];
$total			 = $data_no['amt'];	
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $MAIN_data['website_title'];?>11</title>
<link rel="icon" href="../../../upload/<?php echo $MAIN_data['home_image'];?>" type="image/gif" sizes="16x16">
<meta name="Keywords" content="<?php echo $MAIN_data['web_keywords'];?>"/>
<meta name="description" content="<?php echo $MAIN_data['web_meta_desc'];?>">
<link rel="stylesheet" href="normalize.css">
<link rel="stylesheet" href="paper.css">
<style>
body{ margin:0 auto !important;}

body{ font-family:"Times New Roman", Times, serif;font-size:16px; line-height:24px;}
.wrapper{ margin:0 auto; width:900px;}
.wrapper h4{ margin:0; text-align:center; font-weight:bold; font-size:15px; padding:10px 0}
.wrapper h1{ margin:0; text-align:center; font-weight:bold; font-size:40px; padding:10px 0}
.wrapper h3{ margin:0; text-align:center; font-weight:normal;padding:10px 0;}
.dot_br{ border-bottom:#000 double ; border-top:#000 solid 1px; padding:10px 0;}
table td{ padding:5px !important;}
.top_br{ border-top:#fff solid 1px !important;}
.but_br{ border-bottom:#fff solid 1px !important;}
@page { size: A4 }
</style>
</head>
<body class="A4">
<div class="wrapper">
	<section class="sheet padding-10mm">
<article>
       
<h4>Invoice</h4>
<h1>Rudraansh Holdings LLP</h1>
<h3>Apartment No. C 1st, Chittora Apartments, A-4, Tilak Marg, C-Scheme, Jaipur - 302 001</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="dot_br">
  <tr>
    <td width="7%">PAN</td>
    <td width="33%"><strong>AATFR9757Q</strong></td>
    <td width="29%">&nbsp;</td>
    <td width="9%">GSTN</td>
    <td width="22%"><strong>08AATFR9757Q1ZP</strong></td>
  </tr>
</table><br />

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="15%"><strong>Invoice No.:</strong></td>
   <?php
	if(!empty($invoice_prefix)){
	?>
    <td width="50%"><?php echo $invoice_prefix.$invoice_no;?></td>
    <?php }	else {?>
    <td width="50%"><?php echo date('Y')."/".$invoice_no;?></td>
    <?php }	?>
    <td width="30%" align="right"><strong>Dated :</strong></td>
    <td width="5%" align="left"><?php echo date("d-M-Y",strtotime($data_no['date']));?></td>
  </tr>   
  	<tr>
    <td colspan="2">To<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Ryka Home Store</strong><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SCO-288, Sector 20, Urban Estate, Panchkula-134116</td>
    <td align="right" class="top_br"><strong>GSTN :</strong></td>
    <td align="right"><strong>06AATFR9757Q1ZT</strong></td>
    </tr> 
</table>
<br />

<table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="5%"><strong>S. No.</strong></td>
    <td width="40%" align="center"><strong>Particulars</strong></td>
    <td width="5%"><strong>HSN/SAC</strong></td>
    <td width="7%" align="center"><strong>Qty</strong></td>
    <td width="14%" align="center"><strong>Rate</strong></td>
    <td width="9%" align="center"><strong>GST Rate</strong></td>
    <td width="20%" align="center"><strong>Amount</strong></td>
  </tr>
	<?php 
    $menu 		     =  mysql_query("SELECT * FROM `tbl_sale` WHERE `bill_no` = '$invoice_no' order by `id` ASC ")or die(mysql_error());
    $i				 = 1;
	$grand_total	 = 0.0; 
    while($modify    =  mysql_fetch_array($menu))
    {
		$grand_total = $grand_total+$modify['product_total'];
	?>
          <tr>
            <td style="text-align:center;"><?php echo $i;?></td>
            <td><?php echo product($modify['product_id']);?></td>
            <td><?php echo product_code($modify['product_id']);?></td>
            <td align="center" valign="top"><?php echo $modify['product_qty'];?></td>
            <td align="center" valign="top">&#8377; <?php echo $modify['product_rate'];?></td>
            <td align="center" valign="top"><?php echo $modify['gst_rate'];?>%</td>
            <td align="right" valign="top">&#8377; <?php echo $modify['product_total'];?></td>
          </tr>  
  <?php $i++;} ?>
  <tr>
    <td colspan="6" style="text-align:right;">Rounding-off figure</td>    
    <td align="right">&#8377; <?php $second = round($grand_total,2);
	echo formatInIndianStyle(round($grand_total)-$second);?></td>
  </tr>
  <tr>
    <td colspan="6" style="text-align:center;"><strong>Total</strong></td>
    <td align="right">&#8377; <?php echo formatInIndianStyle(round($grand_total));?></td>
  </tr>
  
  <tr>
    <td colspan="7">RUPEES <strong><?php echo ucfirst(strtolower(get_word(round($grand_total))));?> ONLY</strong></td>
    
  </tr>
</table>
<br /><br />
<p><strong>For Rudraansh Holdings LLP</strong></p><br />
<br />

<p>Partner / Authorised Signatory</p>
</article>
</section>
</div>

</body>
</html>
