<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
$inno=$_REQUEST['invno'];
?>
<html>
<head>
<script type="text/javascript" src="number_to_word.js"></script>
<? 
$qry=mysqli_query($db,"select * from salesretn where invno='$inno' and brcode='$brcode'");
if(mysqli_num_rows($qry)<=0)
{
 print"<script>alert('invalid invoice number');document.location='slsrtn_printinv1.php';</script>";
} 
else
{
 print "<script>window.print();</script>";
}
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Sahad Sohar</title>
<style>

body{
  -webkit-print-color-adjust:exact;
}
.printable{ 
      page-break-before: always;

      margin-top:30px;
    }
.tbl
{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
text-transform:uppercase;
}
.tbl td
{
border: 0px solid black;
}
#tbl
{
border: 1px solid black;

}
.tble 
{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
border-collapse:collapse;
text-transform:uppercase;

}
.tble  td{
height:15px;
margin-left:10px;
margin-right:10px;
padding-left:10px;
padding-right:10px;
}

.tble th
{
border:1px solid black;
}
.tbl1{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
border-collapse:collapse;
text-align:right;
text-transform:uppercase;
}
.tbl1 td{
border-bottom:1px solid black;
height:10px;
}

#add_td{
font-size:12px;
height:15px;
}
#add_td br{
margin:0px;
padding:0px;
}
.tot_td{
border-bottom:0px solid black;
}
.tot_td1{
border-top:0px solid black;
}
#tot_tbl td{
border:1px solid black;
border-collapse:collapse;
}
body
 {font-family:Arial;
   }

p{
 margin:0px;
 padding:0px;
 }


  @media print
        {
            #head
            {
                background-color:grey;
            }
        }

</style>
</head>
  <body style='margin-top:70px;'>
<center>
    <div style="height: 50%;  ">
  <br>
 <?
$qry=mysqli_query($db,"select * from salesretn where invno='$inno' and brcode='$brcode'");
$row=mysqli_fetch_array($qry);
$q_count1=mysqli_query($db,"select count(*) from salesretn where invno='$inno' and brcode='$brcode'");
 $cnt1=mysqli_fetch_array($q_count1); 
$count=$cnt1[0];      
$date = $row[1];
$newDate = date("d-m-Y", strtotime($date));
if(strlen($count)<=0)
 {
  $count=0;
 }
 $limit=23;
 
 $pg_no=floor($count/$limit);
 $i=1;
	$ptot=0;
	$pdisctot=0;
	$ltot=0;
	$subtot=0;
	$ldis=0;
$res=mysqli_query($db,"select * from salesretn  where invno='$inno' and brcode='$brcode'");
	 while($res1=mysqli_fetch_array($res))
	 { 
              $slno[$i]=$i;
              $code[$i]=$res1['item_code'];
              $item[$i]=$res1['item'];
              $qty[$i] =$res1['qty'];
		$rte[$i]=$res1['unitprice'];
              $amt[$i]=$res1['unitprice']*$res1['qty'];
		$ptot+=$res1['unitprice']*$res1['qty'];
		$pdisctot+=$res1['dis'];
		$i++;
             
	}

$gtot=$ptot;
$ntot1=$gtot-$pdisctot;
$ntot=$ntot1;






$tot_fill=0;

 for($p=0;$p<=$pg_no;$p++)
 {
   if($p==$pg_no)
      {
       $tot_fill=1;
      }
               /* to fill total amt in last table if it is last print page */
   $lower_lmt=($p*$limit)+1;

    $upper_lmt=($p+1)*$limit;
?>                                    

<table border='1' width='100%' style='border-collapse:collapse;'><tr>
<th  align='center'  width='100%' style='border:0px solid white;height:20px;font-size:18px;' id='head'>INVOICE&nbsp;&nbsp;(<? echo $row[pmode]; ?>)</th></tr></table>


<table width=100% class='tbl' >

<tr><td align='left' style="width:80px;"><b>Customer</b></td><td ><b>:</b></td><td align='left' colspan='2' style="min-width:50%;" ><? echo $row[customer]?></td><td align='left'><b>Doc. No. </b></td><td><b> :</b></td><td align='left'><? echo $row[0]?></td></tr>
<tr><td align='left'><b>Cash Customer</b></td><td ><b>:</b></td><td align='left' colspan='2'><? echo $row[2]; ?></td><td align='left'><b>Date </b></td><td><b> :</b></td><td align='left'><? echo $newDate; ?></td></tr>
<tr><td align='left'><b>Account No:</b></td><td ><b>:</b></td><td align='left' colspan='2'>01-02-0001</td><td align='left'><b>Page No. </b></td><td><b> :</b></td><td align='left'>1</td></tr>
</table>

<table width=100% class='tble'  border='1' FRAME=BOX BORDER=1 CELLPADDING=0 CELLSPACING=0 RULES=COLS>


<tr><th>No.<th>Part Number<th colspan='2'>Description<th >Qty <th> Rate<th> Amount</tr>

<?
//$k=0;
//$i=1;
//$s_ntot=0;
//$l_ntot=0;
//$s_tot=0;
//$l_tot=0;

  for($k=$lower_lmt;$k<=$upper_lmt;$k++)
	{

             print "<tr><td width='4%' >".$slno[$k]."</td><td >".$code[$k]."</td><td colspan=2>".$item[$k]."</td><td align='right' >".$qty[$k] ."</td><td align='right' width='75'>".putcoma($rte[$k])."</td><td align='right' width='75'>".putcoma($amt[$k])."</td></tr>";
	}



?>
</table>
<table  width=100% class='tbl1' id='tbl'  style='height:50px;'>



<tr><td style="font-size:12px;" align=right>G. Amount:     <? echo number_format($gtot,3,".","") ?> </td></tr>
<tr><td style="font-size:12px;" align=right>Discount:     <? echo number_format($pdisctot,3,".",""); ?></td></tr>
</table>

<table  width=100% class='tbl1' id='tbl'  style='height:30px;'>
<tr><td align='right' class='tot_td' style='font-size:12px'><b>

<? print "<b>Total: OMR <script>document.write(toWords($ntot));</script> only";?>
                   
              

                  </td><td class='tot_td' style='font-size:12px'><b> <?echo number_format($ntot,3,".",""); ?></b>

                 </td></tr></table>
                      


<table  width=100% class='tbl1' id='tbl'  style='height:70px;'>
<tr>
<td width='33%' align='left'><b>Cashier</b></td><td width='33%' ></td><td width='33%' align='right'><b>Signature</b></td></tr></table>


   
  
  





<table border='1' width='100%' style='border-collapse:collapse;margin-top:10px;font-size:10px;'>
	<td align='right'  width='100%' style='border:0px solid white;height:12px;'><? echo 'Page:'.($p+1).'/'.($pg_no+1);?></td></tr></table>
<?
 }//close for loop

?>
  

</center>
  </body>
</html>


