<?php 
session_start();
ob_start(); ?>
<?php include "header.php"?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
input{ border:#CCCCCC solid 1px; border-radius:5px; height:22px; width:200px; padding-left:5px;}
select{ border:#CCCCCC solid 1px; border-radius:5px; height:27px; width:200px;}
.table_bg{ border:#CCCCCC solid 1px; border-radius:5px; height:auto; width:auto; padding:20px; margin-bottom:10px;}
.text_style{ font-family:Arial, Helvetica, sans-serif; font-size:12px;}
.text_style1{ font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px;}
.style14 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	font-weight: bold;
}
.style141 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 16px;
	font-weight: bold;
.style15 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style16 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 24px;
	font-weight: bold;
}

-->
</style>
</head>

<?php
if(isset($_GET["uid"]))
{
$uid=$_GET["uid"];

			
			$whr1="md5(id)='$uid' and session_login_id = '".$_SESSION['login_id']."'";
$get=$objIms->getRows('view_sales_master',$whr1);
$salesmas_id=$get["id"];
$sale_no=$get["sale_no"];
$sales_type=$get["sales_type"];
$client_name=$get["client_name"];
$client_address=$get["client_address"];
$client_tin=$get["tin_no"];
$saledt=$objIms->IntToDate($get["stampdate"]);

$whr="mas_id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
$getPatientInfo=$objIms->getRows('tbl_account',$whr);

			$invoice_no=$getPatientInfo["invoice_no"];
			$trans_date=$objIms->IntToDate($getPatientInfo["trans_date"]);
			$actual_amt=$getPatientInfo["actual_amt"];			
			
			$discount=$getPatientInfo["discount"];
$Paid_Amount=$objIms->getSumValue('tbl_account','Dr_Amt','mas_id="'.$salesmas_id.'" and sales_type="Sales" and session_login_id = "'.$_SESSION['login_id'].'"');
	}
?>

<script type="text/javascript">
 
function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

</script>
<body>

<div class="panel" style="width:95%; margin:10px auto">
<br />

<div align="center" class="style16"></div>
<br />
<div id="printableArea">
<div style="width:210mm; height:auto; margin:auto; text-align:center">
  <table width="100%" border="1">
    <tr>
      <td  colspan="8"><table width="100%" border="1">
          <tr>
            <td height="102" colspan="2" align="center" ><span class="style14" style="background:#666666; color:#FFFFFF">SWASTIK SALES </span><br />
                <span class="style141">Gola Chowk,Badam Bazaar</span><br />
                <span class="style141">Dist-Hazaribhag (Jharkhand)</span><br />
				 <?php if($sales_type=="Tax Invoice"){?><span class="style141">Tin No: <?=$client_tin?></span><?php }?></td>
            <td width="19%" align="left" valign="top"><span class="text_style1" style="float:right; margin-right:15px;">Contact No</span><br />
                <span class="text_style1" style="float:right;margin-right:10px;">Ph. No.: 06546-227422</span><br />
                <span class="text_style1" style="float:right;margin-right:10px;">Mobile: 9430322212</span><br />
                <span class="text_style1" style="float:right;margin-right:10px;">8877030008</span><br />            </td>
          </tr>
          <tr>
            <td width="14%"  align="left" valign="top"><span class="text_style1">No: </span></td>
            <td width="67%" align="left"><span class="text_style1">
              <?=$sale_no?>
            </span></td>
            <td width="19%" align="left" valign="top"><span class="text_style1"> Date : </span>
                <?=$saledt?></td>
          </tr>
          <tr>
            <td align="left"><span class="text_style1">Client Name  : </span> </td>
            <td align="left"><?=$client_name?></td>
            <td align="left"><!--Tin No:
              <?=$client_tin?>-->&nbsp;</td>
          </tr>
          <tr>
            <td align="left"><span class="text_style1">Client Address :  &nbsp;</span> </td>
            <td align="left"><?=$client_address?></td>
            <td>&nbsp;</td>
          </tr>
      </table></td>
    </tr>
    <?php
  $sql_viewtmp="select *  from view_sales_detail where session_login_id = '".$_SESSION['login_id']."' and  salesmas_id=$salesmas_id";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					$sum=0;
  ?>
    <tr>
      <td width="4%" height="28"><span class="text_style1">Si No</span></td>
      <td width="20%"><span class="text_style1">Item Name</span></td>
      <td width="11%"><span class="text_style1">Unit Name</span></td>
      <td width="11%"><span class="text_style1">Order Qty</span></td>
      <td width="11%"><span class="text_style1">Price(Pc)</span></td>
      <td width="11%">Total</td>
      <td width="16%">Discount</td>
      <td width="16%"><span class="text_style1">Total Price</span></td>
    </tr>
    <?php
  while($rows=mysql_fetch_assoc($res_viewtmp))
					{
  ?>
    <tr>
      <td height="27"><span class="text_style">
        <?=$i++?>
      </span></td>
      <td><span class="text_style">
        <?=$rows["item_name"]?>
      </span></td>
      <td><span class="text_style">
        <?=$rows["unit_name"]?>
      </span></td>
      <td><span class="text_style">
        <?=$rows["qty"]?>
      </span></td>
      <td><span class="text_style">
        <?=$rows["unit_price"]?>
      </span></td>
      <td><?php echo $totsum=($rows["unit_price"]*$rows["qty"]);?></td>
      <td><?php echo $discount=$totsum*($rows["discount"]/100);?></td>
      <td class="text_style1"><?php echo $totprice=($totsum-$discount);?></td>
    </tr>
    <?php $sum=$sum+$totprice;}}?>
    <tr>
      <td height="27" colspan="7" align="right" class="text_style1"> Sum Total : </td>
      <td class="text_style1"><?php echo number_format($sum,2);?></td>
    </tr>
    <?php  
  
  $sqltax="select * from tbl_sales_tax where session_login_id = '".$_SESSION['login_id']."' and salesmas_id=$salesmas_id order by id asc";
	$exetax=mysql_query($sqltax);
	$sumtax=0;
	if(mysql_num_rows($exetax)>0){while($rstax=mysql_fetch_array($exetax)){
	
	$sqltax1="select * from tbl_tax_mstr where session_login_id = '".$_SESSION['login_id']."' and id=".$rstax["taxmas_id"];
	$exetax1=mysql_query($sqltax1);	
	$rstax1=mysql_fetch_array($exetax1);
	?>
    <tr>
      <td height="27" colspan="7" align="right" class="text_style1"><?=$rstax1["tax_name"]?></td>
      <td class="text_style1"><?php $tax=($rstax1["tax_percent"]/100)*$sum; echo $tax;?></td>
    </tr>
    <?php $sumtax=$sumtax+$tax;}}?>
    <tr>
      <td height="27" colspan="7" align="right" class="text_style1">Grand Total: </td>
      <td class="text_style1"><?php  $gtol=$sum+$sumtax;; echo number_format($gtol,2);$gtol=round($gtol);?></td>
    </tr>
    <tr>
      <td height="27" colspan="7" align="right" class="text_style1"><span style="float:left;">Paid Amt :
        <?=$Paid_Amount?>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Due :
        <?php $pt=$gtol-$Paid_Amount; echo number_format($pt,2);?>
      </span>Round Off:</td>
      <td class="text_style1"><?php  echo $gtol;?></td>
    </tr>
    <tr>
      <td colspan="8" align="left"><table width="100%" border="0">
          <tr>
            <td width="58%" height="93" class="text_style">&nbsp;</td>
            <td width="21%">&nbsp;</td>
            <td width="21%" align="left" valign="top"><br />
                <br />
                <br />
                <br />
                <span style="font-size:12px;"> For: <strong>SWASTIK SALES</strong></span></td>
          </tr>
      </table></td>
    </tr>
  </table>
</div>
</div>
<br />

<div align="center"><span class="btn btn-info" onClick="printDiv('printableArea')">Print</span></div>
</div>
  

</body>
</html>
