<?php 
if($_REQUEST['action']=="Delete" && $_REQUEST['id']!='')
{
   $child_release_sql=DB_query("select * from asset_issue_details where issue_id='".$_REQUEST['id']."'",$db);
            while($child_release_res=DB_fetch_assoc($child_release_sql))
            {
              DB_query("update machine_center set availability_status='0' where id='".$child_release_res['mst_itemid']."'",$db);
            }
  DB_query("delete from asset_issue where id='".$_REQUEST['id']."'",$db);
  echo "<script>location.href='index.php?route=asset_issue_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<?php 
	$PageSecurity = 2;
	$title = _('Asset Issue Slip');
	$_SESSION['modid']=$_REQUEST['modid'];
	$_SESSION['frmid']=$_REQUEST['frmid'];
	$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
	$_SESSION['frmAdd']=$frmpermission[0];
	$_SESSION['frmEdit']=$frmpermission[1];
	$_SESSION['frmDelete']=$frmpermission[2];
	$_SESSION['frmView']=$frmpermission[3];
	unset($_SESSION['ACGRequisition-ItemList_1']);	
	unset($_SESSION['ACGRequisition-ItemList']);
?>
<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php if($_REQUEST['action']==''){?>
<h1>Asset Issue Slip</h1>
<?php if($_SESSION['frmAdd']=='1') {?>
<p align="left"><a href="index.php?route=add_asset_issue_slip&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" class="search" value="Add New Issue Slip"></a><!--<a href="PO_Order_Print.php?qtid=<?php echo $_REQUEST['VQuotesId'];?>">Print</a>--></p>
<?php }?>

<table border="0" cellpadding="3" cellspacing="0" width="100%" class="thborder">
  <tr>
  <th>Branch</th>
  <th width="7%">Issue Date</th>
  <th width="10%">Issue Slip No.</th>
  <th width="14%">Issue To</th>
	<th width="14%">Issue By</th>
  <th width="4%" style="text-align:center;">Edit</th>
  <th width="4%" style="text-align:center;">Delete</th>
  <th width="4%" style="text-align:center;">Print</th>
  </tr>
  <?php
  $sql=DB_query("select * from asset_issue where CompanyId='".$_SESSION['ACGCompanyId']."' and issuedate BETWEEN '".$_SESSION['financialYrStart']."'   AND '".$_SESSION['financialYrEnd']."' order by id desc ",$db);
  $i=0;
  if(DB_num_rows($sql)>0)
  {
  while($myrow=DB_fetch_array($sql))
  {
    $datacheck=$s->getField('material_return','issue_slipno',$myrow['id'],'id');	
    $cancelissue=$s->getField('addissue','id',$myrow['id'],'cancel_issue');
  ?>
  <tr onmouseover="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onmouseout="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
   <td><?php echo  $sitename=$s->getField('locations','loccode',$myrow['site'],'locationname'); ?></td>    
    <td><?php echo ConvertSQLDate($myrow['issuedate']);?></td>
    <td><?php echo $myrow['issue_slipno'];?></td>
    <td><?php 
          if($myrow['issueto']!='')
          {
          $productionFloor=$s->getField('suppliers','id',$myrow['issueto'],'vendor_name');
          echo $productionFloor;
          }
           else
            {
             $productionFloor=$s->getField('empmaster','id',$myrow['received_by'],'emp_name');
             echo $productionFloor;	
            }
          ?></td>
	<td><?php echo $set = $s->getField('www_users','id',$myrow['createdby'],'realname') ?></td>
  <td style="text-align:center;"><?php 
    $cnt=DB_num_rows(DB_query("select * from asset_issue_details where issue_id='".$myrow['id']."' and returning_status='1'",$db));
    if($cnt=='0'){ ?>
    <a href="index.php?route=asset_issue_edit&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=edit&id=<?php echo $myrow['id'] ?>" ><img src="images/icon-edit.png" height="15" width="15" title="Edit" /></a>
    <?php } else {?>
    <img src="images/icon-edit.png" height="15" width="15" title="Not allowed" style="opacity:0.5;" />
    <?php } ?></td>
  <td style="text-align:center;"><?php 
    $cnt=DB_num_rows(DB_query("select * from asset_return where asset_issue_no='".$myrow['id']."'",$db));
   // echo $cnt;
    if($cnt=='0'){ ?><a href="index.php?route=asset_issue_index&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=Delete&id=<?php echo $myrow['id'] ?>" onclick="return confirm('Are you sure you want to delete?')" ><img title="Delete" src="images/Icon_Delete.png" height="15" width="15" /></a>
    <?php } else{ ?><img title="No Permission" src="images/Icon_Delete.png" style="opacity:0.5;" height="15" width="15"/><?php } ?></td>
  <td style="text-align:center;"><a href="print_asset_issue_slip.php?rid=<?php echo $myrow['id'] ?>&send=<?php echo $set; ?>" target="_blank"><img title="Print" src="images/icon_print.jpg" height="18" width="18"/><!--<input type="button" class="search" name="print" value="Print" style="cursor: pointer;">--></a></td>
  </tr>
  <?php $i++;} }
  else
  {?>
  <tr>
  <td colspan="12" align="center"><strong>No Record Found</strong></td>
  </tr>
  <?php 	
  }
  ?>
</table>
<?php } ?>
</div>
</div>

