<?php 
error_reporting(0);
session_start(); 
include('config.php');   

 $lastinvoice_id = $_GET['lastinvoice_id']; 
 $lastinvoice_detail_id=$_SESSION['lastinvoice_detail_id'];
 $invoice_format = $_GET['invoice_format'];
 
// $finalamount1 =(round($finalamount)); 
 //$grandtotal = $_SESSION['grandtotal'];
 // $invoice_type = $_SESSION['invoice_type'];

  $sql11="SELECT * FROM  tbl_generate_invoice_mst WHERE invoice_id = '$lastinvoice_id'";
  $result11 = mysql_query($sql11);
  $row11 = mysql_fetch_array($result11);
  $invoice_no=$row11['invoice_no'];
  $invoice_date=$row11['invoice_date'];
  $customername=$row11['customername'];
  $invoice_cust_name=$row11['invoice_cust_name'];
  $address	=$row11['address'];
  $mobile =  $row11['mobile']; 
  $email =  $row11['email']; 
  $adv_amount =  $row11['adv_amount'];
  
//  $acc_no = $_GET['acc_no']; 
// exit();
   $sql1="SELECT * FROM  tbl_vattax";
	$result1 = mysql_query($sql1);
	$row1 = mysql_fetch_array($result1);
   $servicetax =  $row1['servicetax'];
//	$invoice_type =  $row1['invoice_type'];
//	$invoicedate =  $row1['invoicedate'];
 //   $customerid =  $row1['customerid'];
  //  $customername =  $row1['customername'];
//	$customername =  $row1['customername'];
//	$tax_number	 =  $row1['tax_number'];
	
//	 $add_tax = $_SESSION['add_tax_session']; 
 //    $vat1 = $_SESSION['vat1_session']; 
  //   $vat2 = $_SESSION['vat2_session']; 
//	 $add_tax15 = $_SESSION['add_tax15_session']; 
//     $vat125 = $_SESSION['vat125_session']; 
 //    $vat25 = $_SESSION['vat25_session']; 
 ?>
<!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">
<title>Print Invoice</title>
<head>
<style type="text/css">
@media print {
input#printButton {
	display: none;
}
}
</style>
</head>
<body>
<center>
  <?php 
  if(isset($_REQUEST['back']))
				{
				?>
  <script language="javascript">window.location.href="invoice.php?lastid=<?php echo $lastid ?>";</script>
  <?php
					  		}
  if(isset($_REQUEST['cancel']))
				{				 
					unset($_SESSION['lastinvoice_id']);
					unset($_SESSION['lastinvoice_detail_id']);
				?>
  <script language="javascript">window.location.href="generate_invoice_list.php";</script>
  <?php
		  		}
 				if(isset($_REQUEST['up_status']))
				{
				?>
  <script language="javascript">window.location.href="generate_invoice_list.php";</script>
  <?php
					  	//	}
   							?>
  <?php } else { ?>
  <form name="form" method="post" >
    <input type="submit" id="printButton" onclick="window.print();" value="Print Invoice" name="print" />
  </form>
  <?php } 
if(isset($_REQUEST['print'])) 
{    
			unset($_SESSION['lastinvoice_id']);
			unset($_SESSION['lastinvoice_detail_id']);
?>
  <script language="javascript">window.location.href="generate_invoice_list.php";</script>
  <?php
} 
 ?>
</center>
<?php 
function convertNumber($num)
{
list($num, $dec) = explode(".", $num);
$output = "";
if($num{0} == "-")
{
$output = "negative ";
$num = ltrim($num, "-");
}
else if($num{0} == "+")
{
$output = "positive ";
$num = ltrim($num, "+");
}
if($num{0} == "0")
{
$output .= "zero";
}
else
{
$num = str_pad($num, 36, "0", STR_PAD_LEFT);
$group = rtrim(chunk_split($num, 3, " "), " ");
$groups = explode(" ", $group);
$groups2 = array();
foreach($groups as $g) $groups2[] = convertThreeDigit($g{0}, $g{1}, $g{2});
for($z = 0; $z < count($groups2); $z++)
{
if($groups2[$z] != "")
{
$output .= $groups2[$z].convertGroup(11 - $z).($z < 11 && !array_search('', array_slice($groups2, $z + 1, -1))
&& $groups2[11] != '' && $groups[11]{0} == '0' ? " and " : ", ");
}
}
$output = rtrim($output, ", ");
}
if($dec > 0)
{
$output .= " point";
for($i = 0; $i < strlen($dec); $i++) $output .= " ".convertDigit($dec{$i});
}
return $output;
}
function convertGroup($index)
{
switch($index)
{
case 11: return " decillion";
case 10: return " nonillion";
case 9: return " octillion";
case 8: return " septillion";
case 7: return " sextillion";
case 6: return " quintrillion";
case 5: return " quadrillion";
case 4: return " trillion";
case 3: return " billion";
case 2: return " million";
case 1: return " thousand";
case 0: return "";
}
}
function convertThreeDigit($dig1, $dig2, $dig3)
{
$output = "";
if($dig1 == "0" && $dig2 == "0" && $dig3 == "0") return "";
if($dig1 != "0")
{
$output .= convertDigit($dig1)." hundred";
if($dig2 != "0" || $dig3 != "0") $output .= " and ";
}
if($dig2 != "0") $output .= convertTwoDigit($dig2, $dig3);
else if($dig3 != "0") $output .= convertDigit($dig3);
return $output;
}
function convertTwoDigit($dig1, $dig2)
{
if($dig2 == "0")
{
switch($dig1)
{
case "1": return "ten";
case "2": return "twenty";
case "3": return "thirty";
case "4": return "forty";
case "5": return "fifty";
case "6": return "sixty";
case "7": return "seventy";
case "8": return "eighty";
case "9": return "ninety";
}
}
else if($dig1 == "1")
{
switch($dig2)
{
case "1": return "eleven";
case "2": return "twelve";
case "3": return "thirteen";
case "4": return "fourteen";
case "5": return "fifteen";
case "6": return "sixteen";
case "7": return "seventeen";
case "8": return "eighteen";
case "9": return "nineteen";
}
}
else
{
$temp = convertDigit($dig2);
switch($dig1)
{
case "2": return "twenty-$temp";
case "3": return "thirty-$temp";
case "4": return "forty-$temp";
case "5": return "fifty-$temp";
case "6": return "sixty-$temp";
case "7": return "seventy-$temp";
case "8": return "eighty-$temp";
case "9": return "ninety-$temp";
}
}
}
function convertDigit($digit)
{
switch($digit)
{
case "0": return "zero";
case "1": return "one";
case "2": return "two";
case "3": return "three";
case "4": return "four";
case "5": return "five";
case "6": return "six";
case "7": return "seven";
case "8": return "eight";
case "9": return "nine";
}
}
		 ?>
<style type="text/css">
#apDiv1 {
	position:absolute;
	width:51px;
	height:318px;
	z-index:1;
	left: 9px;
	top: 287px;
	border-right:solid 1px #000000;
}
#apDiv2 {
	position:absolute;
	width:410px;
	height:318px;
	z-index:1;
	left:-11px;
	top: 287px;
	border-right:solid 1px #000000;

}
#apDiv3 {
	position:absolute;
	width:118px;
	height:318px;
	z-index:1;
	left: 372px;
	top: 287px;
	border-right:solid 1px #000000;
}
#apDiv4 {
	position:absolute;
	width:196px;
	height:318px;
	z-index:1;
	left: 396px;
	top: 287px;
	border-right:solid 1px #000000;

}
/*#apDiv5 {
	position:absolute;
	width:146px;
	height:471px;
	z-index:1;
	left: 580px;
	top: 330px;
	border-right:solid 1px #000000;
	
}*/
#apDiv6 {
	position:absolute;
	width:209px;
	height:318px;
	z-index:1;
	left: 660px;
	top: 983px;
	border-left:solid 1px #000000;
	border-bottom:solid 1px #000000;

	

}
</style>
<div id="apDiv1"></div>
<div id="apDiv2"></div>
<div id="apDiv3"></div>
<div id="apDiv4"></div>
<div id="apDiv5"></div>
<!--<div id="apDiv6"></div>-->
<?php
  if($invoice_format == '1')
    {
  ?>
<table width="692" height="357%"  border="1" cellpadding="0" cellspacing="0" style="line-height:1">
  <tr height="100">
    <td height="79" colspan="3"><img src="img/suc_header1.jpg" width="695" style="margin-left:5px;"/> </td>
  <tr>
    <td  height="23" colspan="6"><center>
      <div align="center"><strong><font size="+2.5" face="Calibri"> Invoice</font></strong> </div>
      <center></td>
  </tr>
  <tr>
    <td width="680" rowspan="3" valign="top" headers="" ><table  border="0">
        <tr style="height:20px;">
          <td colspan="2"><font face="Calibri"><strong>To,</strong></font></td>
        </tr>
        <tr style="height:20px;">
          <td colspan="2"><font face="Calibri">
            <?php  echo   $customername;?>
            </font><!--<font face="Calibri">
            <?php  //echo   $address; ?>
            </font>--></td>
        </tr>
        
        <tr style="height:20px;">
          <td><font face="Calibri"><strong>Mobele:</strong></font><font face="Calibri">
            <?php  echo $mobile; ?>
            </font><!--<font face="Calibri"><strong>Email:</strong></font><font face="Calibri">
            <?php // echo $email; ?>
            </font>--></td>
        </tr>
        
    </table></td>
  </tr>
  <tr>
    <td width="269"  height="40" headers=""><strong>&nbsp;&nbsp;<font face="Calibri">Invoice No.:-</font></strong> &nbsp; <font face="Calibri">
      <?php 
echo $invoice_no;
	?>
      </font></td>
  </tr>
  <tr>
    <td height="34" headers=""><font face="Calibri"></font> &nbsp;&nbsp;<font face="Calibri"><strong>Invoice Date:-</strong>
      <?php  echo  $invoice_date11=date("d-m-Y", strtotime($invoice_date)); ?>
      </font> </td>
  </tr>
  <tr>
    <td colspan="3"><table  border="0" cellpadding="0" style="line-height:1.5; text-align:center;" cellspacing="0">
        <tr>
          <td colspan="5"><div style="width:705px; float:left; height:340px;">
              <div style="width:708px; float:left; min-height:18px;">
                <div style="width:50px; float:left; border-right:solid 1px #000000; border-bottom:solid 1px #000000;" align="center" ><strong><font face="Calibri">Sr. No.</font></strong></div>
                <div style="width:338px; float:left;  border-right:solid 1px #000000; border-bottom:solid 1px #000000;" align="center"><strong><font face="Calibri">Description</font></strong></div>
                <div style="width:90px; float:left;  border-right:solid 1px #000000; border-bottom:solid 1px #000000; " align="center"><strong><font face="Calibri">Qty. (Unit.)</font></strong></div>
                <div style="width:101px; float:left;  border-right:solid 1px #000000; border-bottom:solid 1px #000000; " align="center"><strong><font face="Calibri">Rate</font></strong></div>
                <div style="width:123px; float:left;  border-right:solid 1px #000000; border-bottom:solid 1px #000000; " align="center"><strong><font face="Calibri">Total</font></strong></div>
              </div>
              <?php
	$ure= mysql_query("select * from tbl_generate_invoice_detail where invoice_id='$lastinvoice_id'");
		while($rows=mysql_fetch_array($ure)) {
		 $id==0;
		?>
              <div style="width:708px; float:left; height:20px;">
                <div style="width:50px; float:left;  min-height:388px;  ">
                  <div style="min-width:60px; float:left;" align="center">
                    <?php  echo $numbrer= 1 + $id++; ?>
                    . </div>
                </div>
                <div style="min-width:335px; float:left;"  align="left">
                  <div style="min-width:335px; float:left;  height:20px;  margin-left:5px;"><font face="Calibri"><?php echo $rows['title']; ?></font></div>
                </div>
                <div style="min-width:85px; float:left; " align="center" >
                  <div style="min-width:85px; float:left; height:20px;    margin-left:5px;" align="center"><font face="Calibri"> <?php echo $qty = $rows['qty']; ?> </font></div>
                </div>
                <div style="min-width:100px; float:left;">
                  <div style="min-width:100px; float:left;   height:20px; padding-right:3px;" align="center"><font face="Calibri"> &nbsp;<?php echo $price= $rows['price']; ?> </font></div>
                </div>
                <div style="min-width:115px; float:left;  height:20px;" align="right"  >
                  <div style="min-width:115px; float:left;  margin-left:5px;">
                    <div align="right"><font face="Calibri"><?php echo $total= $qty * $price; ?>.00&nbsp;</font></div>
                  </div>
                </div>
              </div>
              <?php } ?>
            </div></td>
        </tr>
        <tr>
          <td colspan="2" width="298" style="border-top:solid 1px #000000;  border-right:solid 1px #000000">&nbsp;</td>
          <td colspan="1" style="border-top:solid 1px #000000;  "><div align="right" ><strong><font face="Calibri">Total</font></strong>&nbsp;&nbsp;</div></td>
          <td width="100" colspan="1" align="center" abbr="" style="border-top:solid 1px #000000; border-left:solid 1px #000000;"><div align="right" style="padding-right:5px;"><strong>
              <?php 
			 $sql3="SELECT SUM(total_amount) from  tbl_generate_invoice_detail where invoice_id='$lastinvoice_id'";
		     $exe3=mysql_query($sql3);
			 $rowitem13 = mysql_fetch_array($exe3);
			echo  $total_amount= $rowitem13['SUM(total_amount)']; ?>.00</strong> </div></td>
        </tr>
		
        
		
		
	<?php /*?>	<tr>
          <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td height="26" colspan="1" style="border-top:solid 1px #000000;" align="right"><strong><font face="Calibri">Service Tax @ <?php echo $servicetax; ?> %</font></strong>&nbsp;&nbsp;</td>
          <td width="122" align="center" abbr="" style="border-top:solid 1px #000000; border-left:solid 1px #000000;"><div align="right"><strong>
             <?php  
		 echo $service_tax = $total_amount * $servicetax/100;
		   ?>&nbsp;&nbsp;</td>
        </tr>
		<?php */?>
		
		
		
		<?php /*?><tr>
          <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td height="26" colspan="1" style="border-top:solid 1px #000000; border-bottom:solid 1px #000000;"><div align="right"><strong ><font face="Calibri">Sub Total</font></strong>&nbsp;&nbsp;</div></td>
          <td width="122" align="center" abbr="" style="border-top:solid 1px #000000; border-bottom:solid 1px #000000; border-left:solid 1px #000000;"><div align="right"><strong>
              <?php 
		 $finalamount1 = $total_amount + $service_tax;
		  echo $total_amount111 =(round($finalamount1));
		   ?>.00</strong>&nbsp;&nbsp;</div></td>
        </tr><?php */?>
        <!--<tr>
          <td colspan="3" ></td>
          <td colspan="2" style="border-left:solid 1px #000000;"></td>
        </tr>-->
		
        <tr>
          <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td colspan="1" ><div align="right" style="border-top:solid 1px #000000"><font face="Calibri"><strong>Advance &nbsp;</strong></font></div></td>
          <td colspan="2" style="border-left:solid 1px #000000; border-top:solid 1px #000000;"><div align="right"><strong><?php echo $adv_amount; ?>.00</strong>&nbsp;&nbsp;</div></td>
          <strong></strong></tr>
        <?php /*?><tr>
          <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td colspan="1" ><div align="right"><font face="Calibri"><strong>Adjustment &nbsp;</strong></font></div></td>
          <td colspan="2" style="border-left:solid 1px #000000;"><div align="right"><strong>
              <?php //echo $adv_amount; ?>
              .00</strong>&nbsp;&nbsp;</div></td>
        </tr><?php */?>
  		
  	<?php if($total_amount == $adv_amount){?>
        <tr>
		  <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td height="26" colspan="1" style="border-top:solid 1px #000000;"><div align="right"><strong style="font-size:18px"><font face="Calibri">Final Amount</font></strong>&nbsp;&nbsp;</div></td>
          <td width="122" align="center" abbr="" style="border-top:solid 1px #000000; border-left:solid 1px #000000;"><div align="right" style="padding-right:5px;"><strong>
              <?php 
		  echo $finalamount1 = $total_amount - $adv_amount;
		   ?>.00</strong>&nbsp; </div></td>
        </tr>
        <?php } else {?>
		 <tr>
		  <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td height="26" colspan="1" style="border-top:solid 1px #000000;"><div align="right"><strong style="font-size:18px"><font face="Calibri">Final Amount</font></strong>&nbsp;&nbsp;</div></td>
          <td width="122" align="center" abbr="" style="border-top:solid 1px #000000; border-left:solid 1px #000000;"><div align="right" style="padding-right:5px;"><strong>
              <?php 
		  echo $finalamount1 = $total_amount - $adv_amount;
		   ?>.00</strong>&nbsp; </div></td>
        </tr>
        <?php }?>
      </table></td>
  </tr>
  
  
  <tr>
    <td height="25" colspan="3" style="line-height:20px;">&nbsp;<strong><font face="Calibri">Amount in Word:</font></strong>&nbsp;&nbsp; <font face="Calibri">
      <?php  echo ucwords(convertNumber($total_amount111));?>
      &nbsp;Only.</font></td>
  </tr>
  <tr >
    <td height="101" colspan="3" valign="top"><table width="705" height="238" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td height="105" colspan="8" ><ul>
              <li><font face="Calibri">Payment to be made by A/c. Payee's Cheque / Draft in favour of <strong>"Shop Name"</strong> payable at Ahmedabad only</font></li>
              <li><font face="Calibri">Payment should be made as per terms of payment stipulated in this invoice, otherwise interest @24% will be charged.</font></li>
              <li><font face="Calibri">Subject to Ahmedabad Jurisdiction.</font></li>
            </ul></td>
        </tr>
        <tr >
          <td colspan="8" align="right" style="padding-right:10px; font-family:Calibri;"> For, <strong>Shop Name</strong></td>
        </tr>
        <tr>
          <td colspan="8" ><br />
          </td>
        </tr>
        <tr>
          <td colspan="8" ><br />
          </td>
        </tr>
        <tr>
          <td colspan="8" ><br />
          </td>
        </tr>
        <tr>
          <td colspan="8" align="right" style="padding-right:10px;  font-family:Calibri">Authorised Signatury</td>
        </tr>
        <tr>
          <td colspan="8" ><br />
          </td>
        </tr>
        <tr>
          <td colspan="8" ><br />
          </td>
        </tr>
      </table></td>
  </tr>
</table>

<?php
}
else
{
?>
<table width="692" height="350%"  border="1" cellpadding="0" cellspacing="0" style="line-height:1; border-top:none; border-right:none; border-left:none;" >
  <tr height="80" style="border:none">
    <td height="79" colspan="3" style="border:none"><img src="img/si_Blank_header.png" width="695" height="80" style="margin-left:5px;"/> </td>
  
  <tr style="border-bottom:none; border-right:solid 1px #000000;">
    <td  height="23" colspan="6"><center>
      <div align="center"><strong><font size="+2.5" face="Calibri"> Invoice</font></strong> </div>
      <center></td>
  </tr>
  
  
  <tr style="border-bottom:none">
    <td width="680" rowspan="3" valign="top" headers="" >
	<table  width="500">
        <tr style="height:20px;">
          <td colspan="2"><font face="Calibri"><strong>To,</strong></font></td>
        </tr>
        <tr style="height:20px;">
          <td colspan="2"><font face="Calibri">
            <?php  echo   $customername;?>
            </font><!--<font face="Calibri">
            <?php  //echo   $address; ?>
            </font>--></td>
        </tr>
        
        <tr style="height:20px;">
          <td><font face="Calibri"><strong>Mobile:</strong></font><font face="Calibri">
            <?php  echo $mobile; ?>
            </font><!--<font face="Calibri"><strong>Email:</strong></font><font face="Calibri">
            <?php  //echo $email; ?>
            </font>--></td>
        </tr>
      </table></td>
  </tr>
  <tr style="border-right:solid 1px #000000; border-bottom:none">
    <td width="269"  height="40"><strong>&nbsp;&nbsp;<font face="Calibri">Invoice No.:-</font></strong> &nbsp; <font face="Calibri">
      <?php 
echo $invoice_no;
	?>
      </font></td>
  </tr>
  <tr style="border-right:solid 1px #000000; border-bottom:none;">
    <td height="33" headers=""><font face="Calibri"></font> &nbsp;&nbsp;<font face="Calibri"><strong>Invoice Date:-</strong>
      <?php  echo  $invoice_date11=date("d-m-Y", strtotime($invoice_date)); ?>
      </font> </td>
  </tr>
  
  <tr>
    <td colspan="3"><table cellpadding="0" style="line-height:1.5; text-align:center; border-right:solid 1px #000000;" cellspacing="0">
        <tr >
          <td colspan="4"><div style="width:705px; float:left; height:360px;">
              <div style="width:708px; float:left; min-height:18px;">
                <div style="width:51px; float:left; border-right:solid 1px #000000; border-bottom:solid 1px #000000;" align="center" ><strong><font face="Calibri">Sr. No.</font></strong></div>
                <div style="width:338px; float:left;  border-right:solid 1px #000000; border-bottom:solid 1px #000000;" align="center"><strong><font face="Calibri">Description</font></strong></div>
                <div style="width:90px; float:left;  border-right:solid 1px #000000; border-bottom:solid 1px #000000; " align="center"><strong><font face="Calibri">Qty. (Unit.)</font></strong></div>
                <div style="width:101px; float:left;  border-right:solid 1px #000000; border-bottom:solid 1px #000000; " align="center"><strong><font face="Calibri">Rate</font></strong></div>
                <div style="width:121px; float:left;  border-right:solid 1px #000000; border-bottom:solid 1px #000000; " align="center"><strong><font face="Calibri">Total</font></strong></div>
              </div>
              <?php
		$ure11=mysql_query("select * from tbl_generate_invoice_detail where invoice_id='$lastinvoice_id'");
		while($rows11=mysql_fetch_array($ure11)) {
		 $id==0;
		?>
              <div style="width:708px; float:left; height:20px;">
                <div style="width:50px; float:left;  min-height:388px;  ">
                  <div style="min-width:60px; float:left;" align="center">
                    <?php  echo $numbrer= 1 + $id++; ?>
                    . </div>
                </div>
                <div style="min-width:335px; float:left;"  align="left">
                  <div style="min-width:335px; float:left;  height:20px;  margin-left:5px;"><font face="Calibri"><?php echo $rows11['title']; ?></font></div>
                </div>
                <div style="min-width:85px; float:left; " align="center" >
                  <div style="min-width:85px; float:left; height:20px;    margin-left:5px;" align="center"><font face="Calibri"> <?php echo $qty = $rows11['qty']; ?> </font></div>
                </div>
                <div style="min-width:100px; float:left;">
                  <div style="min-width:100px; float:left;   height:20px; padding-right:3px;" align="center"><font face="Calibri"> &nbsp;<?php echo $price= $rows11['price']; ?> </font></div>
                </div>
                <div style="min-width:115px; float:left;  height:20px;" align="right"  >
                  <div style="min-width:115px; float:left;  margin-left:5px;">
                    <div align="right"><font face="Calibri">&nbsp;<?php echo $total= $qty * $price; ?>.00&nbsp;</font></div>
                  </div>
                </div>
              </div>
              <?php } ?>
            </div></td>
        </tr>
		
        
		<tr>
          <td colspan="2" width="298" style="border-top:solid 1px #000000;  border-right:solid 1px #000000">&nbsp;</td>
          <td colspan="1" style="border-top:solid 1px #000000;  "><div align="right" ><strong><font face="Calibri">Total</font></strong>&nbsp;&nbsp;</div></td>
          <td width="100" colspan="1" align="center" abbr="" style="border-top:solid 1px #000000; border-left:solid 1px #000000;"><div align="right" style="padding-right:5px;"><strong><?php 
			 $sql3="SELECT SUM(total_amount) from  tbl_generate_invoice_detail where invoice_id='$lastinvoice_id'";
		     $exe3=mysql_query($sql3);
			 $rowitem13 = mysql_fetch_array($exe3);
			echo  $total_amount= $rowitem13['SUM(total_amount)'];?>.00</strong></div></td>
        </tr>
		
        
		
		
		<?php /*?><tr>
          <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td height="26" colspan="1" style="border-top:solid 1px #000000;" align="right"><strong><font face="Calibri">Service Tax @ <?php echo $servicetax; ?> %</font></strong>&nbsp;&nbsp;</td>
          <td width="122" align="center" abbr="" style="border-top:solid 1px #000000; border-left:solid 1px #000000;"><div align="right"><strong>
             <?php  
		 echo $service_tax = $total_amount * $servicetax/100;
		   ?>&nbsp;&nbsp;</td>
        </tr>
		<?php */?>
		
		
		
		<?php /*?><tr>
          <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td height="26" colspan="1" style="border-top:solid 1px #000000; border-bottom:solid 1px #000000;"><div align="right"><strong ><font face="Calibri">Sub Total</font></strong>&nbsp;&nbsp;</div></td>
          <td width="122" align="center" abbr="" style="border-top:solid 1px #000000; border-bottom:solid 1px #000000; border-left:solid 1px #000000;"><div align="right"><strong>
              <?php 
		 $finalamount1 = $total_amount + $service_tax;
		  echo $total_amount111 =(round($finalamount1));
		   ?>.00</strong>&nbsp;&nbsp;</div></td>
        </tr><?php */?>
       <!-- <tr>
          <td colspan="3" ></td>
          <td colspan="2" style="border-left:solid 1px #000000;"></td>
        </tr>-->
		
        <tr>
          <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td colspan="1" ><div align="right" style="border-top:solid 1px #000000;"><font face="Calibri"><strong>Advance &nbsp;</strong></font></div></td>
          <td colspan="2" style="border-left:solid 1px #000000; border-top:solid 1px #000000;"><div align="right"><strong><?php echo $adv_amount; ?>.00</strong>&nbsp;&nbsp;</div></td>
          <strong></strong></tr>
        <?php /*?><tr>
          <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td colspan="1" ><div align="right"><font face="Calibri"><strong>Adjustment &nbsp;</strong></font></div></td>
          <td colspan="2" style="border-left:solid 1px #000000;"><div align="right"><strong>
              <?php //echo $adv_amount; ?>
              .00</strong>&nbsp;&nbsp;</div></td>
        </tr><?php */?>
  
  
      <?php if($total_amount == $adv_amount){?>
        <tr>
		  <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td height="26" colspan="1" style="border-top:solid 1px #000000;"><div align="right"><strong style="font-size:18px"><font face="Calibri">Final Amount</font></strong>&nbsp;&nbsp;</div></td>
          <td width="122" align="center" abbr="" style="border-top:solid 1px #000000; border-left:solid 1px #000000;"><div align="right" style="padding-right:5px;"><strong>
              <?php 
		  echo $finalamount1 = $total_amount - $adv_amount;
		   ?>.00</strong>&nbsp; </div></td>
        </tr>
        <?php } else {?>
		 <tr>
		  <td colspan="2" width="298" style="border-right:solid 1px #000000">&nbsp;</td>
          <td height="26" colspan="1" style="border-top:solid 1px #000000;"><div align="right"><strong style="font-size:18px"><font face="Calibri">Final Amount</font></strong>&nbsp;&nbsp;</div></td>
          <td width="122" align="center" abbr="" style="border-top:solid 1px #000000; border-left:solid 1px #000000;"><div align="right" style="padding-right:5px;"><strong>
              <?php 
		  echo $finalamount1 = $total_amount - $adv_amount;
		   ?>.00</strong>&nbsp; </div></td>
        </tr>
        <?php }?>
		
		
		
		
      </table></td>
  </tr>
  <tr>
    <td height="25" colspan="3" style="line-height:20px; border-bottom:none; border-top:none; border-right: solid 1px #000000;">&nbsp;<strong><font face="Calibri">Amount in Word:</font></strong>&nbsp;&nbsp; <font face="Calibri">
      <?php  echo ucwords(convertNumber($total_amount111));?>
      &nbsp;Only.</font></td>
  </tr>
  <tr style="border-right:solid 1px #000000; border-bottom:none;">
    <td height="101" colspan="3" valign="top"><table width="705" height="200" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td height="105" colspan="8" ><ul>
              <li><font face="Calibri">Payment to be made by A/c. Payee's Cheque / Draft in favour of <strong>"Shop Name"</strong> payable at Ahmedabad only</font></li>
              <li><font face="Calibri">Payment should be made as per terms of payment stipulated in this invoice, otherwise interest @24% will be charged.</font></li>
              <li><font face="Calibri">Subject to Ahmedabad Jurisdiction.</font></li>
            </ul></td>
        </tr>
        <tr >
          <td colspan="8" align="right" style="padding-right:10px; font-family:Calibri;"> For, <strong>Shop Name</strong></td>
        </tr>
        <!--<tr>
          <td colspan="8" ><br />
          </td>
        </tr>-->
       <!-- <tr>
          <td colspan="8" ><br />
          </td>
        </tr>-->
        <tr>
          <td colspan="8" align="right" style="padding-right:10px;  font-family:Calibri">Authorised Signatury</td>
        </tr>
        
<?php /*?>        <tr>
          <td colspan="8" ><br />
          </td>
        </tr><?php */?>
      </table></td>
  </tr>
  <table> <tr>
          <td colspan="8" ><br />
          </td>
        </tr>
		<tr>
          <td colspan="8" ><br />
          </td>
        </tr>
		</table>
  
  
</table>
<?php
}
?>

</body>
</html>
