<link rel="stylesheet" href="css/new_mxerp.css">

<?php
$PageSecurity = 11;
?>
<script language="javascript" type="text/javascript">

function get_itemsubgroup(str)
{
	if(str=="")
  {
  document.getElementById("sub_id").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("sub_id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","item_subcategory.php?main="+str,true);
xmlhttp.send();
}
function get_item(str)
{
if(str=="")
  {
  document.getElementById("itemid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Get_itemcode.php?sub="+str,true);
xmlhttp.send();
}
</script>


<div class="body_contain">
<div class="tab_div">


<h1>Purchase Register Detail Wise</h1>


<form action="" method="post">
  		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  	  <tr class="row1">
  	    <td class="tabledata1" align="left">Branch</td>
  	    
  	    <td><select name="site" style="width:98%;">
  	      <option value="0">Select</option>
  	      <?php
			$sql = "SELECT locationname,loccode FROM locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
	    	  $resultStkLocs = DB_query($sql,$db);
				while($myrow=DB_fetch_array($resultStkLocs))
				{
				?>
				<option value="<?php echo $myrow['loccode']; ?>" <?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $myrow['locationname']; ?></option>
  	    <?php 
				}
				 ?>
	      </select></td>
  	    <td class="tabledata1" align="left">Period Wise</td>
  	    <td>
  	    	<?php 
	if($_REQUEST['fromDate']!=''){$fromDate=$_REQUEST['fromDate'];}
	if($_REQUEST['toDate']!=''){$toDate=$_REQUEST['toDate'];}
	?>
      <input name="fromDate" type="text" size="12" class="datepicker" value="<?php echo $fromDate;?>"/>
      To 
      <input name="toDate" type="text" size="12" class="datepicker" value="<?php echo $toDate;?>"/></td></tr>
  	  <tr class="row1">
  	    <td class="tabledata1" align="left">Party wise</td>
  	    <td><select name="vendor" style="width:98%;">
	   <option value="0">Select</option>
	  <?php 
	  $v_sql=DB_query("Select vendor_code,vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	  while($v_row=DB_fetch_array($v_sql)) {
	  ?>
	  <option value="<?php echo $v_row['vendor_code'];?>"<?php echo ($_REQUEST['vendor']==$v_row['vendor_code']?'selected':'')?>><?php echo $v_row['vendor_name'];?></option>
	  <?php } ?>
      </select> </td>
  	    <td class="tabledata1" align="left">Item Wise</td>
  	    <td><select name="itemCode" style="width:88%">
  	      <option value="0">Select</option>
	<?php 
	$name_sql=DB_query("Select distinct item_name from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($name_row=DB_fetch_array($name_sql)) {
	?>
	<option value="<?php echo $name_row['item_name'];?>"<?php echo ($_REQUEST['itemName']==$name_row['item_name']?'selected':'')?>><?php echo $name_row['item_name'];?></option>
	<?php } ?>
	      </select></td>
  	    </tr>
  	  <tr class="row1">
  	    <td class="tabledata1" align="left">Tax Wise</td>
  	    <td><select name="select2" style="width:98%">
  	      <option value="0">Select</option>
	      </select></td>
  	    <td class="tabledata1" align="left">&nbsp;</td>
  	    <?php 
				$salesmanname=$s->getField('suppliers','vendor_code',$master_row['Transporter'],'vendor_name');
				?>
  	    <td>&nbsp;</td>
  	    </tr>
  	 <tr class="row1">
  	    <td colspan="4">&nbsp;</td>
	    </tr>
         <tr class="row1">
  	    <td colspan="4" style="text-align:center;" align="center"><input type="submit" name="Proceed" id="button" value="Proceed" /></td>
	    </tr>
  	  <tr class="row1">
  	    <td colspan="4">&nbsp;</td>
	    </tr>
    </table>
    </form>
	

<div style="width:810px; margin-left:auto; margin-right:auto; overflow:auto;">
   

<table width="100%" border="0" cellspacing="0" cellpadding="5">
    	        <tr class="row1">
    	          <td class="tabledata1">Company Name</td>
    	          <td class="tabledata1">RATNAMANI BIO-CHEMICALS & PHARMACEUTICA</td>
    	          <td class="tabledata1" style="text-align:right;">Date From</td>
    	          <td><?php echo $_REQUEST['fromDate']; ?>  To <?php echo  $_REQUEST['toDate'];  ?></td>
                </tr>
  	        </table>
</div>

<div style="overflow:auto; width:810px; height:200px;">
<table width="1000" border="1" cellspacing="0" cellpadding="3">
    	        <tr>
    	          <td class="tabledata">Document</td>
    	          <td class="tabledata">MRN No.</td>
    	          <td class="tabledata">MRN Date</td>
    	          <td class="tabledata">Invoice No.</td>
    	          <td class="tabledata">Invoice Date</td>
    	          <td class="tabledata">Party name</td>
    	          <td class="tabledata">Gross Bill Amt</td>
    	          <td class="tabledata">Basic Amt.</td>
    	          <td class="tabledata">Excise Duty</td>
    	          <td class="tabledata">E Cess</td>
    	          <td class="tabledata">SAH E Cess</td>
    	          <td class="tabledata">Tax Type</td>
    	          <td class="tabledata">Tax Amt</td>
    	          <td class="tabledata">Freight </td>
    	          <td class="tabledata">Pkg Charges</td>
    	          <td class="tabledata">Round Off</td>
    	          <td class="tabledata">Other Amt</td>
    	          <td class="tabledata">Discount</td>
   	            </tr>
   	          <?php 
	if(isset($_POST['Proceed']))
	{
		$filter=array();		
		$fromDate=$_REQUEST['fromDate'];																						
		$fromDateBrk=explode("/",$fromDate);
		$fromDate=$fromDateBrk[0];
		$fromMonth=$fromDateBrk[1];
		$fromYear=$fromDateBrk[2];
		$From=$fromYear."-".$fromMonth."-".$fromDate;
		$toDate=$_REQUEST['toDate'];
		$toDateBrk=explode("/",$toDate);
		$toDate=$toDateBrk[0];
		$toMonth=$toDateBrk[1];
		$toYear=$toDateBrk[2];
		$To=$toYear."-".$toMonth."-".$toDate;
		if($_REQUEST['site']!='0')
		$filter[]="A.site='".$_REQUEST['site']."'";
		if($_REQUEST['vendor']!='0')
		$filter[]="A.vendor='".$_REQUEST['vendor']."'";
		if($_REQUEST['itemCode']!='0')
		$filter[]="B.item_code ='".$_REQUEST['itemCode']."'";
		if($_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
		$filter[]="A.bill_date between '".$From."' and '".$To."'";
		
		if($filter!='')
		{
			if($_REQUEST['site']!='0'){$filter2=implode(" and ",$filter)." ";}
			else
			$filter2=implode(" and ",$filter);
		}
		
		if(count($filter)>0)
		{
	     $sql="Select A.*, B.*  from  purchase_billbook A ,purchase_bill_details B where A.id=B.purch_billbookid and $filter2";
		}
		else{
		$sql="Select A.*, B.* from  purchase_billbook A ,purchase_bill_details B where A.id=B.purch_billbookid "; }
		
		//echo $sql;
		
	    	
		$result=DB_query($sql,$db);
	
		$i=1;
		if(DB_num_rows($result)>0)
		{
			while($myrow=DB_fetch_array($result))
			{
				
		?>
<tr bgcolor="#c1c1c1">
    	          <td><?php 
    	           $mrnno1=$s->getField('addmrn','id',$myrow['mrn_no'],'DocumentType');
    	             echo $mrnno1; ?></td>
    	          <td><?php 
    	           $mrnno=$s->getField('addmrn','id',$myrow['mrn_no'],'MRNNo');
    	             echo $mrnno; ?></td>
    	          <td><?php 
    	           $mrndate=$s->getField('addmrn','id',$myrow['mrn_no'],'MRNDate');
    	             echo $mrndate; ?></td>
    	          <td><?php 
    	           $mrnno2=$s->getField('addmrn','id',$myrow['mrn_no'],'BillNo');
    	             echo $mrnno2; ?></td>
    	         
    	          <td><?php 
    	           $mrnno3=$s->getField('addmrn','id',$myrow['mrn_no'],'BillDate');
    	             echo $mrnno3; ?></td>
    	          <td><?php 
	  $vendorname=$s->getField('suppliers','vendor_code',$myrow['vendor'],'vendor_name');
	  echo $vendorname;?></td>
    	          <td><?php echo $myrow['sum(grand_total)'] ?></td>
    	          <td><?php echo $myrow['basic_amount'] ?></td>
    	          <td><?php echo $myrow['Excise_Duty'] ?></td>
    	          <td><?php echo $myrow['Edu_Cess_perc'] ?></td>
    	          <td>&nbsp;</td>
    	          <td><?php   $tax=$s->getField('taxgroups','taxgroupid',$myrow['taxname'],'taxgroupdescription');
	  echo $tax;?></td>
    	          <td><?php echo $myrow['taxable_amt']; ?></td>
    	          <td>&nbsp;</td>
    	          <td>&nbsp;</td>
    	          <td>&nbsp;</td>
    	          <td>&nbsp;</td>
    	          <td>&nbsp;</td>
   	            </tr>
   	            <?php } } 
else { ?>
	 <tr bgcolor="#FFFFFF"><td colspan="19"><font color="#FF0000">No Record Found</font></td></tr>
	
	<?php }
}?>
             
  	        </table>
</div>



</div></div>