
<?php 
$PageSecurity = 2;
$title = _('Process Material 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']);
?>	

<style>
#slidingDiv 
{
    display: none;
	height:auto;
	background-color: transparent;
	padding:0px;
}
</style>

<script type="text/javascript">
function showSlidingDiv(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 700 });
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
  <?php if($_REQUEST['action']==''){?>
  <h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></h1>
<p align="left">
<?php if($_SESSION['frmAdd']=='1') {?>
<a href="index.php?route=Inventory/transation/Issue_slip_add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewIssue=yes"><input type="button" class="search" value="Add New Issue Slip" /></a>
<a href="#" onClick="showSlidingDiv(); return false;"><input type="button" class="search" value="SEARCH" /></a>

<a href="index.php?route=Inventory/transation/process_Issue_slip_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewIssue=yes"><input type="button" class="search" value="Process Issue Slip" /></a>

<!--<a href="index.php?route=Inventory/transation/service_Issue_slip_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewIssue=yes"><input type="button" class="search" value="Services Issue Slip" /></a>-->

<?php }?>
</p>
<div id="slidingDiv" class="centre">
<form method="post">
<table width="100%" border="0" style="border-collapse:collapse;" cellspacing="0" cellpadding="3" align="center">
  <tr class="row1">
	<td width="13%"><strong>Site</strong></td>
    <td width="20%">
	<?php
	//echo  $_SESSION['AssignedBranch'];
	if($_SESSION['AssignedBranch']!='')
	  {	  	
 		 $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }?>
	 <select name="site" onchange="showmrn(this.value);getContratorList(this.value)"> 
    <option  value="000">Select Site</option>
	<?php 	
		while ($myrow=DB_fetch_array($site_sql)){
 			?>
 				<option Value="<?php echo $myrow['loccode'];  ?>" <?php echo ($myrow['loccode']==$_REQUEST['site']?"selected":""); ?>><?php echo $myrow['locationname']; ?></option>
 		<?php
 		}
	?> </select></td>
	<td width="13%"><strong>Issue Number</strong></td>
    <td width="20%">
	<div id="mrnno1">
     <select name="issueno" id="issueno">
	 <option value="000">Select</option>
	<?php 
		$sql = "SELECT  * FROM addissue where site in('".$_SESSION['AssignedBranch']."')";
		$resultStkLocs = DB_query($sql,$db);
		while ($myrow=DB_fetch_array($resultStkLocs)){
 				?>
 					<option Value="<?php echo $myrow['id'] ?>" <?php echo ($myrow['id']==$_REQUEST['issueno']?"selected":""); ?>><?php echo $myrow['issue_slipno'] ?></option>
 				<?php 		
       }
	?></select>
	</div>	
	</td>
	 <td width="13%"><strong>Employee</strong></td>	
    <td>	  
		<select name="employee" id="employee">
		<option value="000">---Select---</option>-->
		<?php 
		$vendor_sql=DB_query("Select id,emp_code,emp_name from empmaster where emp_site in('".$_SESSION['AssignedBranch']."') order by emp_name ASC",$db);
		while($vendor_res=DB_fetch_array($vendor_sql))
		{?>
		<option value="<?php echo $vendor_res['id'];?>" <?php echo ($vendor_res['id']==$_REQUEST['employee']?"selected":""); ?>><?php echo $vendor_res['emp_name'];?></option>
		<?php } ?>
		</select>		
	</td>
	</tr>
    <tr class="row1">
	<td style="display:none;"><strong>Contactor</strong></td>
	<td style="display:none;">
	<select name="contactor" id="contactor">
		<option value="000">---Select---</option>-->
		<?php 
		if(isset($_REQUEST['site']))
		{
	$vendor_sql=DB_query("Select id,c_name from clientmaster where Site='".$_REQUEST['site']."' and client_type='C' order by c_name ASC",$db);
		while($vendor_res=DB_fetch_array($vendor_sql))
		{?>		
		<option value="<?php echo $vendor_res['id'];?>" <?php echo ($vendor_res['id']==$_REQUEST['contactor']?"selected":""); ?>><?php echo  $vendor_res['c_name']; ?></option>
		<?php } 
	}
		?>
		</select>	
		</td>
	<td><strong>From Date</strong></td>
	<td><input type="text" name="fromdate" id="fromdate" class="datepicker" value="<?php echo ($_REQUEST['fromdate']!="")?$_REQUEST['fromdate']:ConvertSQLDate($_SESSION['financialYrStart']);?>" onchange="javascript:checkdate(this.value)" /></td>
	<td><strong>To Date</strong></td>
	<td><input type="text" name="todate" class="datepicker"  size="12"  id="todate" value="<?php echo ($_REQUEST['todate']!="")?$_REQUEST['todate']:ConvertSQLDate($_SESSION['financialYrEnd']);?>"  onchange="javascript:checkdate(this.value)" >
		<input type="hidden" value="<?php echo ConvertSQLDate($_SESSION['financialYrStart']);?>" id='from'>
	<input type="hidden" value="<?php echo ConvertSQLDate($_SESSION['financialYrEnd']);?>" id='to'>
	</td>
	<td colspan="2"></td>
	</tr>
	<tr class="row1">
	<td colspan="6" style="text-align:center"><input name="Search" type="submit" value="Search" class="Search" /></td>
	</tr>
  </table>  
  </form>
  
</div>

<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid;">
	<tr>
    <th width="10%" rowspan="2">Issue Slip No.</th>
    <th width="6%" rowspan="2">Issue Date</th>
    <th rowspan="2">Branch</th>
    <th width="20%" rowspan="2">Godown</th>
	<th width="20%" rowspan="2">Issue To</th>
	<th colspan="5" style="text-align:center;">Action</th>
</tr>
 <tr>
    <th width="4%" style="text-align:center;">View</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>
	<th width="4%" style="text-align:center;">Cancel</th>
 </tr>
  <?php
     if(isset($_POST['Search']))
	 {
	 
     	 $issuenumber=$_REQUEST['issueno'];
		$site=$_REQUEST['site'];
		$emp=$_REQUEST['employee'];
		$cont=$_REQUEST['contactor'];
		$fromdate=ConvertSQLDate($_POST['fromdate']);
	    $todate=ConvertSQLDate($_POST['todate']); 
	    $filter=array();
		if($fromdate!='//' ||$todate!='//')
		{
		$filter[]="issuedate BETWEEN '".$fromdate."' AND '".$todate."'";
		}
		if($site!='000')
		{
		$filter[]="site='".$site."'";
		}
		if($issuenumber!='000')
		{
		$filter[]="id ='".$issuenumber."'";
		}
		if($cont!='000')
		{
		$filter[]="issueto='".$cont."'";
		}
		if($emp!='000')
		{
		$filter[]="received_by='".$emp."'";
		}
		
  
  
      if(isset($filter))
		{
			 if(count($filter)>0)
		 	{
				$filter1=implode(" and ",$filter);
				$SQL ="SELECT * FROM addissue where $filter1 order by id DESC";
			}
			else
			{
				$SQL ="SELECT * FROM addissue where site in('".$_SESSION['AssignedBranch']."')  order by id DESC";
	        }
			
		}
	}	
	else 
	{   
			
		$SQL = "SELECT * FROM addissue where site in ('".$_SESSION['AssignedBranch']."') and issuedate between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' order by id DESC";
		
		 
	}  

  
  $sql=DB_query($SQL,$db);
 
  $i=0;
  if(DB_num_rows($sql)>0)
  {
  while($myrow=DB_fetch_array($sql))
  {
  //echo '<pre>'; print_r($myrow);
   $check=$s->getField('material_return','issue_slipno',$myrow['id'],'id');
   $cancelissue=$s->getField('addissue','id',$myrow['id'],'cancel_issue');
  ?>
  <tr bgcolor="#FFFFFF">
    <td><?php echo $myrow['issue_slipno'];?></td>
    <td><?php echo ConvertSQLDate($myrow['issuedate']);?></td>
    <td><?php  
	echo	$sitename=$s->getField('locations','loccode',$myrow['site'],'locationname');
	 ?></td>
    <td><?php 	echo $storename=$s->getField('storetype','id',$myrow['mst_storeid'],'StoreName');	 ?></td>
	<td><?php 
	if($myrow['issueto']!='')
	{
	$productionFloor=$s->getField('contractor_master','id',$myrow['issueto'],'contractor_name');
	echo $productionFloor; } else {
		
	$productionFloor=$s->getField('empmaster','id',$myrow['received_by'],'emp_name');
	echo $productionFloor;	
		
	}?></td>
	<?php

		//if($myrow['type']=='Process')
		//{
			?>
			<!--<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td> -->
		<?php 
		//}
		//else
	{
	 ?>
	<td style="text-align:center;"><?php if($_SESSION['frmView']=='1' ){?>
	<a href="index.php?route=Inventory/transation/Issue_slip_view&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=view&id=<?php echo $myrow['id']; ?>" ><img src="images/search.gif" height="15" width="15" title="View" /></a><?php }else { ?><img src="images/search.gif" height="15" width="15" title="No Permission" style="opacity:0.5;" /><?php } ?></td>
	<td style="text-align:center;">
	<?php 
	$checkEdit= checkEdit($myrow['id']);
	 if($checkEdit!=0)
	 {
		if($_SESSION['frmEdit']=='1' &&  $check=='' && $cancelissue==0){?>
	<a href="index.php?route=Inventory/transation/Issue_slip_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="No Permission" style="opacity:0.5;" />
	<?php }
	}
	else{echo "ISSUE SLIP USED";}?>
	</td>
	<td style="text-align:center;">
	<?php 
	 if($checkEdit!=0)
	 {
		if($_SESSION['frmDelete']=='1' &&  $check=='' && $cancelissue==0){?>	
	<a href=""onclick="javascript:delete_reason('<?php echo $_REQUEST['modid'] ?>','<?php echo $_REQUEST['frmid'] ?>','<?php echo $myrow['id'] ?>','<?php echo $myrow['site'] ?>','<?php echo $myrow['mst_storeid']?>','<?php echo $myrow['issuedate'] ?>')">
	<img src="images/Icon_Delete.png" height="15" width="15" title="Delete" /></a><?php 
		}
		else
		{ ?>
			<img src="images/Icon_Delete.png" height="15" width="15" title="No Permission" style="opacity:0.5;" />
		<?php }
	}
		else{echo "ISSUE SLIP USED";}?>
	</td>

	<td style="text-align:center;">	
	<?php if($_SESSION['modid']!=""){?>
		<a target="_blank"  href="material_issue_page.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Report&id=<?php echo $myrow['id']; ?>">
	<img src="images/icon_print.jpg" height="18" width="18" title="Print" />
	</a>
	
	<?php }else{ ?><img src="images/icon_print.jpg" height="18" width="18" title="No Permission" style="opacity:0.5;" /><?php }?>
	</td>
	<td style="text-align:center;">
	<?php 	
	if($_SESSION['frmDelete']=='1')
	{
		if($cancelissue==1) 
		{ 
		?>
			 <input type="button" name="reason"  value="Cancelled" onclick="javascript:popup('ditectpo_cancel_reason.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>',200,220)">
			 <? } 	else {
			 		 if($checkEdit!=0)
	 				{
			 	 ?>
			 		<a onclick="popup('AddIssueCancel.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>',600,200)" href="#" ><img src="images/icon_cancel.png" height="15" width="15" title="Cancel" /></a>
			 	<?php }
			 		  else
			 		  {
			 		  	echo "ISSUE SLIP USED";
			 		  }
			 	} }else { ?><img src="images/icon_cancel.png" height="15" width="15" title="No Permission" style="opacity:0.5;" /><?php } ?></td>
    <?php } ?>
  </tr>
  <?php $i++;
	} 
	}
  else
  {?>
  <tr>
  <td colspan="12"><strong>No Record Found</strong></td>
  </tr>
  <?php 	
  }
  ?>
</table>
</form>
<?php }  ?>
</div></div> 
<?php
function checkEdit($id)
  {
    global $db;
    $query="SELECT id FROM stock_valuation_tbl WHERE against_tra_id in( SELECT id FROM stock_valuation_tbl WHERE TYPE='Issue' AND against_voucher_main_id='".$id."') ";
    $result=Db_query($query,$db);
   
    if(DB_num_rows($result)>0)
      return 0;
    else
      return 1;
  }

if($_REQUEST['id']!='' && $_REQUEST['action']=='Delete') 
{ 
//$del=DB_query("delete from addissue where id='".$_REQUEST['id']."'",$db);
//$del1=DB_query("delete from issueqty where issue_id='".$_REQUEST['id']."'",$db);
//$del_stocktable=DB_query("delete from stock_valuation_tbl where against_voucher_main_id='".$_REQUEST['id']."' and type='Issue' ",$db);

header("location:index.php?route=Inventory/transation/Issue_slip_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."");
	
}	?>
<?php 
include('includes/footer.inc');

 if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
?>
<script>
function showmrn(str)
{
	$.post('showissueno.php',{'site':str},function(data){
		$('#issueno').html(data);
	});

		


}
function checkdate(date)
{
	var from =document.getElementById('from').value;
	var to =document.getElementById('to').value;
	
		var cdate=date.split("/");
		var sdate=from.split("/");
		var edate=to.split("/");

		cdate[1]=cdate[1]-1;
		sdate[1]=sdate[1]-1;
		edate[1]=edate[1]-1;
			 
		var dateC = new Date(cdate[2], cdate[1], cdate[0]); //Year, Month, Date 
		var dateS = new Date(sdate[2], sdate[1], sdate[0]); //Year, Month, Date
	    var dateE = new Date(edate[2], edate[1], edate[0]); //Year, Month, Date

	    if (dateS > dateE) {
	        alert("Start Date is not greather then Date End.");
	        document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	        
	    }

	    if (dateC > dateE) {
	        alert("Date Not greather than "+to);
	       document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	       
	    }

	    if (dateC < dateS) {
	        alert(" Date Not less than "+from);
	        document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	       
	    }	
	
	
}
function delete_reason(mod,frm,id,site,store,date1)
{
//alert(date1);
window.open("delete_reason_issue.php?modid="+mod+"&frmid="+frm+"&action=Delete&id="+id+"&sitecode="+site+"&store="+store+"&date="+date1,"profiles_popup_window","height=425,width=800,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}
function getContratorList(SiteId){
	$.ajax({
		url:"GetContractor.php",
		type:"POST",
		data:{"SiteId":SiteId},
		success:function(result){
			$("#contactor").html(result);
		}
	});
}
</script>	