<?php 

require_once("config/configDB.php");

//header('Content-disposition: attachment; ');
//header('Content-type: application/pdf');


?>
<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Invoice-<?php echo $_GET['saleID']; ?></title>

<script type="text/javascript">

 function printin(el,cpy,c,amd,valam)
{
 var restore =  document.body.innerHTML;
 var pricn = document.getElementById(el).innerHTML;
 document.body.innerHTML=pricn;
 document.getElementById(amd).innerHTML = valam;
 if(c=='o')
 {
   document.getElementById(cpy).innerHTML = "Original Copy";
 }
 else
 {
  document.getElementById(cpy).innerHTML = "Duplicate Copy";
 }
 document.getElementById("btno").style.display = "none";
 document.getElementById("btnd").style.display = "none";
 window.print();
 document.body.innerHTML=restore;
 

}



</script>
</head>
<body onload="btnd.click(" >
<div id="p1">

<?php


function convertNumberToWord($number = false)
{
  
   $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;
	    $plural =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] : '';
  //echo $result . "Rupees  " . $points . " Paise";
    return  $result;
}


  $invoice_id  = $_GET['saleID'];
  
$re = mysqli_query($conn,"select * from customer_payment_header where id='".$invoice_id."' "); 
//$re=mysqli_query($sql);
 if($row = mysqli_fetch_array($re))
 {
    $invoice_no= $row['cashno'];
	
	
	
   $tamount = round($row['received_amount']);
   $discount=$row['discount'];
   $customer_code = $row['customerID'];
   $date1 = $row['collectiondate'];
    $date = date("d-m-Y", strtotime($date1)); 
	
	$date1 = $row['collectiondate'];
	
	 $pending_amount=$row['pending'];
	  $collection_amount=$row['received_amount'];
	   $discount=$row['discount'];
	   
	   if($discount=='0.00')
	   {
		   
		   $display="style=display:none";
		   
	   }
	   
	  else
	   {
		   
		   $display="";
		   
	   }
	   
	   
	    
   
  
  // $status = $row[6]; 
   // $others = $row[5];
//	$others_amount = $row[6];

   //$sql2="select * from customer_master where id='".$customer_code."' ";
   $re2 = mysqli_query($conn,"select * from customer_master where id='".$customer_code."' "); 
   //$re2=mysqli_query($sql2);
   if($row2 = mysqli_fetch_array($re2))
    {

	   $client_name= $row2['cname_tamil'];
	   $address= $row2['caddress'];
  	   $address2= $row2['area_tamil'];
	   $pincode= $row2['pincode'];
	   $area= $row2['area'];
   	  $area_tamil= $row2['area_tamil'];
   	  $mobile=$row2['mobile'];
	   
    }
    
   //$sql3="SELECT sii.*,pro.code,pro.name,pro.    FROM `saleiteminfo` as sii left join product as pro ON pro.id = sii.product_id  where invoice_id='$invoice_id'";

    
   
            
 }
?>
<button onClick="printin('p1','cpy','o','amd','<?php echo number_format((float)$tamount, 2, '.', '');?>')" id="btno">O print</button>
<button onClick="printin('p1','cpy','d','amd','<?php echo number_format((float)$tamount, 2, '.', '');?>')" id="btnd">D print</button>
<center>
    <table width="690">
    <tr><td><div align="left" id="cpy">Original Copy</div></td><td align="right"><b> Amount :</b><b  id="amd"></b></td></tr>
    </table>
   <table border='3' width="760"  cellpadding="5" style="border-collapse:collapse;">
     
     
     
       <tr style="border-bottom:2pt solid black;"><td style="border-right:2pt solid black;" colspan="10"  >
       <center>
       
  <table width="100%" >
  <tr>
       <td width="21%" align="right" >
       <!--<img src="images/logo.png" width="150" height="100"  />-->       </td>
       <td width="61%" align="left"> <center><B><font size="6dp"> RK Fruits</font></B>
       <br /><u><strong>பழ கமிஷன் மண்டி</strong></u>
            <br><font style="font-size: 14px;"><strong>காய்கறி  மார்க்கெட் பிள்ளையார் கோவில் எதிரில் , <br>கள்ளக்குறிச்சி  -606202.</strong></font></center>
        <br>      </td>
      <td width="18%" align="center" >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       </td> 
      </tr>
</table>
    <table border="0" width="100%">
      <tr>
      <td align="left"><b>Phone No : 98948 17332 & 73588 75353</b></td><td align="left"  valign="center" width="255"><B></B></td>
      </tr>
      </table>
      </center> 
      
       </td></tr>
      <tr >
      <td colspan="6" rowspan="4" style="border-right:2pt solid black; border-bottom:2pt solid black;" valign="top" >
      <font size="3"><U><B>Buyer Name & Address</B></U>
      <br><?php echo $client_name; ?>
      <br><?php echo nl2br($address); ?>
      <br><?php echo $pincode; ?>  
      
       <br>Mobile:<?php echo $mobile; ?>      </font>
      <br></td>
      <td colspan="4" style="border-right:2pt solid black;"><center><b>  Collection Receipt</b></center></td></tr>
         <td colspan="2">Invoice No.</td><td colspan="2" style="border-right:2pt solid black;">: <?php echo $invoice_no; ?> </td> </tr>
         <!--<td colspan="2"><b>Bill Amount</b></td><td colspan="2" style="border-right:2pt solid black;">: <b  id="amd"></b> </td> </tr>-->    
        <tr><td colspan="2">Date.</td><td colspan="2"  style="border-right:2pt solid black;">: <?php echo $date;  ?></td> </tr>
        <tr><td colspan="2">Area</td><td colspan="2" style="border-right:2pt solid black;">:  <?php echo $area; ?>/     (<?php echo $area_tamil;?>)</td> </tr>
        

    <tr style="border-bottom:2pt solid black; border-top:2pt solid black;">
    <td width="5%" style="border-right:2pt solid black;" ><center><b>Sno.</b></center></td>
    <td width="50%" style="border-right:2pt solid black;" colspan="8"><center><b>Description </b></center></td>
    
    
    
    <!--<td width="1%" style="border-right:2pt solid black;"><center><b>Amount</b></center></td>
    <td width="12%"   style="border-right:2pt solid black;"><center><b>CGST</b></center></td>
    <td width="12%" style="border-right:2pt solid black;"><center><b>SGST</b></center></td>
    <td width="12%"  style="border-right:2pt solid black;"><center><b>IGST</b></center></td>-->
    <td width="1%" style="border-right:2pt solid black;"><center><b>Total</b></center></td></tr>
    
    
     
     <tr style="border-bottom:0pt solid white;"> 

      <td  align="center" style="font-size:20px;" >1</td>
      <td colspan="8" style="font-size:20px;">Received&nbsp;Amount</td>
     
    
      
      <td style="border-right:2pt solid black;font-size:20px;" align="right"><?php echo number_format((float)$tamount, 2, '.', ''); ?></td></tr>
  
<?php
    
    
	for($ii = 0 ;$ii<9 ; $ii++)
	{
	?>
       <tr style="border-bottom:0pt solid white;" height="30">
       <td  align="center" ></td>
       <td  colspan="8"></td>
      
       <td style="border-right:2pt solid black;" align="right"></td></tr>
  <?php
	}





?>
    
    
  
    <tr style="border-top:2pt solid black; border-bottom:2pt solid black;">
    <td colspan="6" align="left" valign="top" style="border-top:2pt solid black;">
    <b>Total Amount in words : </b> <br>   
    <?php echo ucfirst(convertNumberToWord($tamount)).'rupees only'; ?></td>
    <td colspan="3" rowspan="2" style="border-bottom:2pt solid black;font-size:20px;" ><b>Total  Amount </b></td><td rowspan="2" align="right" style="border-right:2pt solid black;border-bottom:2pt solid black;font-size:20px;"><strong><?php echo number_format((float)$tamount, 2, '.', '');  ?></strong></td></tr>
    

    <tr> 
    <td colspan="6" rowspan="5" align="left" valign="top" style="border-top:2pt solid black;">&nbsp;     </td>
    </tr>
    
    <tr style="border-bottom:2pt solid black;"> 
    <td colspan="3" align="right" style="font-size:20px;"><strong>முன் பாக்கி :</strong></td>
    <td align="right" style="font-size:20px;"> <strong><?php echo number_format($pending_amount,2,'.','');?></strong> </td>
    </tr>
    
    <tr style="border-bottom:2pt solid black;">
      <td colspan="3" align="right" style="font-size:20px;"><strong>வரவு :</strong></td>
      <td align="right" style="font-size:20px;"> <strong> <?php echo number_format($collection_amount,2,'.','');?></strong></td>
    </tr>
    <tr style="border-bottom:2pt solid black;">
      <td colspan="3" align="right" style="font-size:20px;"><strong><span <?php echo $display;?> >Discount Amt:</span></strong></td>
      <td align="right" style="font-size:20px;"> <strong> <span <?php echo $display;?> ><?php echo number_format($discount,2,'.','');?></span></strong></td>
    </tr>
    <tr style="border-bottom:2pt solid black;">
      <td colspan="3" align="right" style="font-size:20px;"><strong>மொத்த பாக்கி:</strong></td>
      <td align="right" style="font-size:20px;">  <strong><?php echo number_format((($pending_amount)-($collection_amount+$discount)),2,'.','');?></strong></td>
    </tr>
     <tr style="border-bottom:2pt solid black;border-top:2pt solid black; ">
     <td colspan="5" style="font-size: 13px;" >
     
    
    Customer Signature<br />     </td> 
     <td style="border-right:2pt solid black;" colspan="5" align="right"  valign="top"><b><font size="3">For RK Fruits</font> </b><br />
  <img src="        "  />
<br />
<br>Authorized signatory</td>
   </table>
   <table width="700">
    <tr><td><center> This is Computer Generated Invoice</center></td></tr>
    </table>
</center>   
</div>
<!--<button onClick="printin('p1','cpy','o','amd','<?php echo number_format((float)$roundtotal, 2, '.', '');?>')" id="btno">O print</button>
<button onClick="printin('p1','cpy','d','amd','<?php echo number_format((float)$roundtotal, 2, '.', '');?>')" id="btnd">D print</button>-->

<?php

//echo "<a href='salebill.php?saleID=$invoice_id'  target='_blank' class='btn btn-primary'>Generate PDF</a>";
?>



</body>
</html>