<link rel="stylesheet" href="css/new_mxerp.css">
 <script type="text/javascript">
    $(document).ready(function(){
        $('input[name="to"]').click(function(){
            if($(this).val()=="received")
            {
                $(".issue").css('display','none');
                $(".received").css('display','block');
                $("#issue_to").attr('disabled','disabled');
                $("#received_by").removeAttr('disabled');
            }
            if($(this).val()=="issue")
            {
                $(".issue").css('display','block');
                $(".received").css('display','none');
                $("#received_by").attr('disabled','disabled');
                $("#issue_to").removeAttr('disabled');
            }
           });
        $('#search_form').submit(function(){
        	
        	if($('#project').val()=='0')
        	{
        		alert("Please Select Site")
        		return false;
        	}
        });

    });

</script>

<style type="text/css">
#amc-tab{}
  #amc-tab table{border:none; border-collapse:collapse; }
  #amc-tab table tr td{border-right:#808080 1px solid; border-bottom:#808080 1px solid;}
  #amc-tab table tr td:last-child{border-right:none;}
  #amc-tab table tr:last-child td{border-bottom:none;}
  #amc-tab table tr td > table tr td{border-right:#808080 1px solid; border-bottom:#808080 1px solid;}
  #amc-tab table tr td > table tr td:last-child{border-right:none;}
  #amc-tab table tr td > table tr:last-child td{border-bottom:none;}
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Asset Issue Register</h1>
<form name="" id="search_form" method="POST">
<fieldset class="bggreen">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr class="row3" style="height:5px"><td colspan="6"></td></tr>
<tr class="row3">
	<td width="13%" align="right"><strong>Branch:</strong></td>         
    <td width="20%">
    	<select name="project" id="project" class="detailedViewTextBox" style="width:98%;">
          <option value="0">Select Branch</option>
          <?php
		    $query4=DB_query("Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($row4=DB_fetch_array($query4))
				{
					$s1='';
					if($_REQUEST['project']==$row4['loccode'])
					$s1="selected";
					?>
					<option value=<?php echo $row4['loccode'];?> <?php echo $s1;?>><?php echo $row4['locationname'];?></option>
		  <?php } ?>
        </select> 
    </td>
    <td width="13%" style="text-align:right;"><strong>Employee:</strong>
      <!--  <label><input type="radio" name="to" <?php  if($_REQUEST['to']=="received") echo "checked"; else echo "checked";  ?> value="received"><strong>Employeer</strong></label>
        <label><input type="radio" name="to" <?php  if($_REQUEST['to']=="issue") echo "checked";  ?> value="issue"><strong>Contractor</strong></label> -->
    </td>
    <?php
	//$g1="style='display:block'";
	//$g2=" style='display:none'";
	 ?>
	<td width="20%" class="received" >
    	<select name="received_by" id="received_by" style="width:98%;">
          <option value="">Select Employee</option>
          <?php
		  $query2=DB_query("Select * from empmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($row2=DB_fetch_array($query2))
				{?>
					<option value="<?php echo $row2['id'];?>" <?php if($_REQUEST['received_by']==$row2['id']){ echo 'selected="selected"'; } ?>><?php echo $row2['emp_name'];?></option>
		  <?php } ?>
        </select>
    </td>
    <!-- <td width="20%" class="issue" <?php if($_REQUEST['to']=='issue'){ ?>style='display:block' <?php } else { ?> style='display:none'<?php } ?>>
    	<select name="issue_to" id="issue_to" <?php if($_REQUEST['to']!='issue'){ ?>disabled=""<?php } ?> style="width:98%;">
          <option value="">Select Contractor</option>
          <?php
		  $query2=DB_query("Select * from suppliers  where CompanyId='".$_SESSION['ACGCompanyId']."' and vendorgroup='C' ",$db);
			while($row2=DB_fetch_array($query2))
				{ ?>
					<option value="<?php echo $row2['id'];?>" <?php if($_REQUEST['issue_to']==$row2['id']){ echo 'selected="selected"'; }?>><?php echo $row2['vendor_name'];?></option>
		  <?php } ?>
        </select> </td> -->
    <td width="13%" align="right"><strong>Asset:</strong></td>
    <td>
    	<select name="asset_name"  id="asset_name" class="detailedViewTextBox" style="width:98%;">
          <option value="0">All</option>
          <?php $SQLMachine=db_query("SELECT * FROM machine_center where CompanyId='".$_SESSION['ACGCompanyId']."'",$db );
		 while($MachineNa=db_fetch_array($SQLMachine))
		   { ?>
		 	<option value="<?php echo $MachineNa['id']?>" <?php if($MachineNa['id']==$_REQUEST['asset_name']){ echo 'selected="selected"'; } ?>><?php echo $MachineNa['name']; ?></option>
	 <?php } ?>
        </select>
    </td>
</tr>
<tr class="row3">
	<td align="right"><strong>From Date:</strong></td>
    <td><input type="text" name="frmdate" id="frmdate" style="width:98%;" class="datepicker" value="<?php echo $_REQUEST['frmdate'] ?>"/></td>
    <td align="right"><strong>To Date:</strong></td>
    <td><input type="text" name="todate" id="todate" style="width:98%;" value="<?php echo $_REQUEST['todate'] ?>" class="datepicker" /></td>
    <td align="right"><strong>Issue No.:</strong></td>
    <td><input type="text" name="issueno" list="issue" id="issueno" style="width:98%;" value=""/>
    	<datalist id="issue">
    		<?php 
    		$issue_query=DB_query("select * from asset_issue",$db); 
    		while($issue_result=DB_fetch_assoc($issue_query)) {
    		?>
    		<option value="<?php echo $issue_result['issue_slipno'] ?>"></option>
    		<?php } ?>
    	</datalist>
    </td>
</tr>
<tr class="row3">
	<td colspan="6" style="text-align:center;">
	<input type="submit" name="Search" class="search" value="Search" />
	<?php if(isset($_REQUEST['Search'])){?> <a href="asset_isssue_stock_print.php?asset_name=<?php echo $_REQUEST['asset_name'] ?>" target="_blank"><input type="button" name="print" value="Print" class="search"></a><?php } ?></td>
</tr>
<tr class="row3" style="height:5px"><td colspan="6"></td></tr>
</table>
</fieldset>
<br>
	<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid; border-collapse:collapse;">
  	<tr>
  		<th width="4%">S. No.</th>
  		<th width="7%">Issue Date</th>
  		<th width="10%">Issue No.</th>
  		<th width="12%">Issue To</th>
	  	<th width="100">Asset Code</th>
	    <th width="300">Asset Name</th>
	   	<th width="60">Unit</th>
	   	<th width="90">Return Date</th>
	   	<th>Remarks</th>
   </tr>
<?php
      if(isset($_REQUEST['Search']))
        {
        $fordate   = $_POST['frmdate'];		
	    $todate    = $_POST['todate'];		
	    $fromdate  = explode("/", $fordate);
		$daydate   = $fromdate['0'];
		$Monthdate = $fromdate['1'];
		$yeardate  = $fromdate['2'];
		$fdate     = $yeardate."-".$Monthdate."-".$daydate;							   
		$tredate   = explode("/", $todate);
		$dayda     = $tredate['0'];
		$Monthda   = $tredate['1'];
		$yearda    = $tredate['2'];
		$toyrdate  = $yearda."-".$Monthda."-".$dayda;	
	    $filter    = array();

	if($_REQUEST['project']!= '0')	
		$filter[]="a.site='".$_REQUEST['project']."'";
    if($_REQUEST['received_by']!='')
    { 
    	$filter[]="a.received_by='".$_REQUEST['received_by']."'";
     } 
     //elseif ($_REQUEST['issue_to']!='') { 
       //$filter[]="a.issueto='".$_REQUEST['issue_to']."'";
     //}

	if($_REQUEST['asset_name']!= '0')	
		$filter[]="b.mst_itemid='".$_REQUEST['asset_name']."'";
	
	if($_REQUEST['todate']!='' && $_REQUEST['frmdate']!= '') 
		$filter[]="a.issuedate  between '".$fdate."' and '".$toyrdate."'";
   
    if($_REQUEST['issueno']!='')	
		$filter[]="a.issue_slipno like '%".$_REQUEST['issueno']."%'";

	if($filter!='')
	{			
	$filter1 = implode(" and ",$filter);
       //print_r($filter);	
	}
	//echo $filter1;
	if($filter1!='')
	{
	 $search_query="SELECT a.* FROM asset_issue a, asset_issue_details b WHERE a.id=b.issue_id and $filter1"." group by a.id";
	}
	else
	{
		 $search_query="SELECT a.* FROM asset_issue a, asset_issue_details b WHERE a.id=b.issue_id"." group by a.id";
	}

	$_SESSION['isseue_report_sql'] = $search_query;
 
$sql=DB_query($search_query,$db);
$i=1;
$num=DB_num_rows($sql);
if($num>0)
{
while($row=DB_fetch_array($sql))
	{ ?>
<tr bgcolor="#fff">
	    <td><?php echo $i; ?></td>
	    <td><?php echo ConvertSQLDate($row['issuedate']) ?></td>
	    <td><?php echo $row['issue_slipno'] ?></td>
	    <td><?php if($row['issueto']==''){ echo $a=$s->getField('empmaster','id',$row['received_by'],'emp_name'); } 
	    //else{ echo $b= $s->getField('suppliers','id',$row['issueto'],'vendor_name'); } ?></td>
	    <td colspan="5" style="padding:0px;" valign="top">
	     <div id="amc-tab">
	    	<table cellpadding="3" cellspacing="0" border="0" width="100%">
	    		<?php 
	    		if($_REQUEST['asset_name']!='0'){
	    		$detail_que=DB_query("select * from asset_issue_details where issue_id='".$row['id']."' and mst_itemid='".$_REQUEST['asset_name']."'",$db);
	    		}
	    		elseif($_REQUEST['asset_name']=='0'){
	    		$detail_que=DB_query("select * from asset_issue_details where issue_id='".$row['id']."'",$db);
	    		}	    			
	    		while($detail_res=DB_fetch_assoc($detail_que))
	    		{
	    		$asset_detail=DB_fetch_assoc(DB_query("select * from machine_center where id='".$detail_res['mst_itemid']."'",$db));
	    		$unit=DB_fetch_assoc(DB_query("select * from unitsofmeasure where unitid='".$asset_detail['unit']."'",$db));
	    		
	    		 ?>
	    		<tr>
	    			<td width="100"><?php echo $asset_detail['code'] ?></td>
	    			<td width="300"><?php echo $asset_detail['name'] ?></td>
	    			<td width="60"><?php echo $unit['unitname']; ?></td>
	    			<td width="90"><?php echo ConvertSQLDate($detail_res['return_date']) ?></td>
	    			<td><?php echo $detail_res['remarks'] ?></td>
	    		</tr>
	    		<?php } ?>
	    	</table>
	     </div>
	    </td>
</tr>

<?php $i++; }} else { ?>
<tr bgcolor="#fff">
  <td colspan="11" style="text-align: center;"><font color="#FF0000" style="font-weight:bold;"><?php echo "No Records Found"; ?></font></td>
</tr>	 
	<?php } }?> 
</table>
</form>
</div></div>
<script type="text/javascript">
	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
</script>