<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();
?>




<!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>
			select.error { background-color:#ffa8a8; border: 1px dotted red;  }
			input.error{ background-color:#ffa8a8;   }
			textarea.error{ background-color:#ffa8a8; border: 1px dotted red;  }
         </style>
		 
        


<style type="text/css">
<!--
.table_bg{ border:#CCCCCC solid 1px; border-radius:5px; height:auto; width:auto; padding:20px; margin-bottom:10px;}


-->
</style>
</head>
<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>
<script type="text/javascript">
	$(document).ready(function() {                
	$("#form1").validate({
	rules: {
	
	client_name: "required",
	
	
	},
	messages: {
	
	client_name:"",
	
	},
	});                
	});
	</script>
<body>

<div class="span11" style=" width:83%;">



<div class="12" style=" margin-left:0px; ">



<br />
<br />
<br />

<div class="12" style=" margin-left:0px;">

<div class="panel" style="border:<?php echo THEMECOLOR?> solid 1px; border-radius:0px;">
<div class="entry-head" >
<h4>View Sales Report
</div>
<p>&nbsp;</p>
<form name="form1" id="form1" method="post">
  <table width="100%" border="0" align="center">
    <tr>
      <td width="6%" height="49" nowrap="nowrap"><strong>From Date </strong></td>
      <td width="1%"><strong>:</strong></td>
      <td width="15%"><input name="s_date" type="text" class="tcal" id="s_date" readonly=""  value="<?php if($_POST["s_date"]<>''){echo $_POST["s_date"];}else{echo date('d-m-Y');}?>"/></td>
      <td width="7%"><strong>To Date </strong></td>
      <td width="1%"><strong>:</strong></td>
      <td width="23%"><input name="end_date" type="text" class="tcal" id="end_date" readonly=""  value="<?php if($_POST["end_date"]<>''){echo $_POST["end_date"];}else{echo date('d-m-Y');}?>" /></td>
      <td width="11%"><strong>Client Name </strong></td>
      <td width="1%"><strong>:</strong></td>
      <td width="12%"><select name="client_name" id="client_name" style="width:200px;"  class="required">
      <option value="">---Please Select---</option>
      <?php 
							$sqlc="select * from tbl_client where session_login_id = '".$_SESSION['login_id']."' order by client_name";
							//echo $sqlc;
							$c=mysql_query($sqlc);
							if(mysql_num_rows($c)>0){
							while($cs=mysql_fetch_array($c))
							{?>
      <option value="<?=$cs["id"];?>" <?php if(($cs["id"])==$_POST["client_name"]){ ?> selected="selected" <?php }?>>
      <?=$cs["client_name"];?>
      </option>
      <?php }}?>
    </select></td>
      <td width="1%">&nbsp;</td>
      <td width="22%"><input type="submit" name="Search" value="Search" class="btn btn-info" /></td>
      </tr>
  </table>
</form>
<br />

<?php 
if(isset($_POST["Search"]))
{
$s_date=$objIms->DateToInt($_POST["s_date"]);
$end_date=$objIms->DateToInt($_POST["end_date"]);
$client_name=$_POST["client_name"];
$whr1="id='$client_name' and session_login_id = '".$_SESSION['login_id']."'";
$get=$objIms->getRows('tbl_client',$whr1);
?>
 <div class="panel-heading">Sales To 
					  <strong>
					  <?=$get["client_name"]?>
					  </strong>					  From <?php echo $_POST["s_date"];?> To <?php echo $_POST["end_date"];?></div>
					<p>&nbsp;</p>  
 <div id="printableArea"> <div class="panel">
					 
          <table width="100%" border="0">
		  <tr>
		    <td colspan="2"><div align="center"><h2 style="color:#000000">M/S TIRUPATI BALAJI TEXTILE</h2></div></td>
		    </tr>
		  <tr>
		    <td colspan="2"><?=$get["client_name"]?><br />
			<?=$get["address"]?><span style="float:right"> Date : <?=date("d-m-Y")?></span></td>
		    </tr>
		  <tr><td colspan="2"><div align="center">OUTSTANDING BILLS </div></td></tr>
  <tr>
    <td valign="top">
<table width="100%" >
                     <tr height="32" align="left">
            <th nowrap="nowrap" width="15%">Date </th>
            <th nowrap="nowrap" width="15%">Particulars</th>            
            <th nowrap="nowrap" width="14%"><div align="right">Debit &nbsp;&nbsp;</div></th>
                     </tr>
            <?php
			$sql_viewtmp="select * from view_sales_master where session_login_id = '".$_SESSION['login_id']."' and cancel_status=0 and client_id='$client_name' and  stampdate>='$s_date' and stampdate<='$end_date'";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					$sums=0;?>
					 <tr height="32">
              <td colspan="3" nowrap="nowrap"><hr /></td>
              </tr>
			  <?php
				while($rows=mysql_fetch_assoc($res_viewtmp))
					{
						
					$sqlsum="select sum(actual_amt) as totactual_amt, sum(Dr_Amt) as totDr_Amt from tbl_account where session_login_id = '".$_SESSION['login_id']."' and mas_id='".$rows["id"]."' and sales_type='Sales' and cancel_status=0";
					$exesum=mysql_query($sqlsum);	
					$rssum=mysql_fetch_array($exesum);	
					$totactual_amt=	$rssum["totactual_amt"];
					$totDr_Amt=	$rssum["totDr_Amt"];		
					$restamt=$totactual_amt-$totDr_Amt;
					$sums+=$restamt;
			?>
           
           
            <tr height="32">
            <td nowrap="nowrap" width="15%"><?php echo $objIms->IntToDate($rows["stampdate"]);?></td>
		    <td nowrap="nowrap" width="15%"><?php echo $rows["sale_no"];?></td>		   
            <td nowrap="nowrap" width="14%"><div align="right"><?php echo number_format($restamt,2);?>&nbsp;&nbsp;</div></td>
            </tr>   <?php }}?>
          </table>    </td>
    <td valign="top">
					
                     <table width="100%" >
                     <tr height="32" align="left">
            <th nowrap="nowrap" width="15%">Date </th>
            <th nowrap="nowrap" width="15%">Particulars</th>            
            <th nowrap="nowrap" width="14%"><div align="right">Credit</div></th>
                     </tr>
            <?php
			  $sql_viewtmpre="select * from view_salesreturn where session_login_id = '".$_SESSION['login_id']."' and client_id='$client_name' and  stampdate>='$s_date' and stampdate<='$end_date'";
				$res_viewtmpre=mysql_query($sql_viewtmpre);
				if(mysql_num_rows($res_viewtmpre)>0)
				{ 
					$ii=1;
					$sumsre=0;
					?>
					  <tr height="32">
              <td colspan="3" nowrap="nowrap"><hr /></td>
              </tr>
			  <?php
			  
				while($rowsre=mysql_fetch_assoc($res_viewtmpre))
					{
						
					$sqlsumre="select sum(Dr_Amt) as totDr_Amt from tbl_account where session_login_id = '".$_SESSION['login_id']."' and mas_id='".$rowsre["id"]."' and sales_type='Sales Return' and cancel_status=0";
					$exesumre=mysql_query($sqlsumre);	
					$rssumre=mysql_fetch_array($exesumre);	
					$totactual_amtre=$rssumre["totactual_amt"];
					$totDr_Amtre=$rssumre["totDr_Amt"];		
					$restamtre=$totDr_Amtre;
					$sumsre+=$restamtre;
			?>
           
          
            <tr height="32">
            <td nowrap="nowrap" width="15%"><?php echo $objIms->IntToDate($rowsre["return_date"]);?></td>
		    <td nowrap="nowrap" width="15%"><?php echo $rowsre["salereturn_no"];?></td>		   
            <td nowrap="nowrap" width="14%"><div align="right"><?php echo number_format($restamtre,2);?></div></td>
            </tr>   <?php }}?>
          </table>    </td>
  </tr>
  <tr>
    <td  valign="top"><hr /></td>
	<td  valign="top"><hr /></td>
    </tr>
  <tr>
    <td valign="top"><div align="right"><?=number_format($sums,2)?>&nbsp;&nbsp;</div></td>
    <td valign="top"><div align="right"><?=number_format($sumsre,2)?></div></td>
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td valign="top">DEBIT BALANCE... <span style="float:right"><?=number_format(($sums-$sumsre),2)?></span></td>
  </tr>
   <tr>
    <td valign="top"><hr></td>
	<td valign="top"><hr></td>
    </tr> 
	 <tr>
    <td colspan="2" ><div align="center">DEPOSIT CHQ/CASH AT SBI:- 3704511441 IFCS:-SBIN0012815 <br />
Please inform us at 7033875044 whenever you deposite in bank<br />

<span style="float:right">Reciver Sign</span></div></td>
	</tr> 
</table>
  
	</div></div><br />

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

   
<p></p>
		<br />
        


</div>

</body>
</html>
