<?php 
$PageSecurity = 2;
$title=$s->GetFieldValue('modules_form',"id='".$_REQUEST['frmid']."'",'frm_name');
$title = _($title);
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$url="&modid=".$modid."&frmid=".$frmid;
$targetpage="index.php?route=".$_REQUEST['route'].$url;
$_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']);
 
                   function openingBalance($function_filter,$item)
					    		{
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];								
								if($site!='')
								$filter[]="site = '".$site."'";
								if($store!='')
								$filter[]="store = '".$store."'";
								if($from!='--' && $to!='--')
								$filter[]="reveive_date <= '".$from."'";
								if($item!='')
								$filter[]="itemcode = '".$item."'";
								
								$filter=implode(' and ',$filter);
								 $sql1="Select stock, rate from opening_stockitemwise where $filter";
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								return $myrow1['stock'];
							}
                      
					   
					   

						////1. MRN/////
                     function receivedMRN($function_filter,$item)
						{
							global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							if($site!='')
							$filter[]="addmrn.site = '".$site."'";
							if($store!='')
							$filter[]="addmrn.StoreCode = '".$store."'";
							if($item!='')
							$filter[]="addmrnqty.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
							 $sql1="Select SUM(addmrnqty.reciveqty) from addmrn left join addmrnqty 
							       on(addmrn.id=addmrnqty.issue_id) where Cancel_Status='N' and $filter ";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(addmrnqty.reciveqty)'];
						}
						

							////1. Issue Slip/////
                         function issueSlip($function_filter,$item)
							{
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];
								if($site!='')
								$filter[]="addissue.site = '".$site."'";
								if($store!='')
								$filter[]="addissue.mst_storeid = '".$store."'";
								if($item!='')
								$filter[]="issueqty.mst_itemid = '".$item."'";
								
								
								$filter=implode(' and ',$filter);
							
								 $sql1="Select SUM(issueqty.issueqty) from addissue left join 
								 issueqty on(addissue.id=issueqty.issue_id) where $filter";
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								
								return $myrow1['SUM(issueqty.issueqty)'];
							}

                                ////2. Material return/////
						function receivedReturn($function_filter,$item)
						{
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];
								$to=$function_filter[3];							
								if($site!='')
								$filter[]="material_return.site = '".$site."'";
								if($store!='')
								$filter[]="material_return.store = '".$store."'";
								if($from!='--' && $to!='--')
								$filter[]="material_return.returndate <='".$from."'";
								if($item!='')
								$filter[]="material_return_details.itemid = '".$item."'";								
								$filter=implode(' and ',$filter);
								$sql1="Select SUM(material_return_details.receiveqty) 
								from material_return left join material_return_details 
								on(material_return.id=material_return_details.parentId) where $filter";							
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								return $myrow1['SUM(material_return_details.receiveqty)'];
							}
						
						
						       ////////////site to site receive//////
						function receivedSiteToSite($function_filter,$item)
						{
							global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[3];
							if($site!='')
							$filter[]="transfer_receipt.Received_to = '".$site."'";
							if($store!='')
							$filter[]="transfer_receipt.Received_store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="transfer_receipt.MRNDate <='".$from."'";
							if($item!='')
							$filter[]="transfer_receipt_details.itemid = '".$item."'";
							$filter=implode(' and ',$filter);
							$sql1="Select SUM(transfer_receipt_details.reciveqty) 
							from transfer_receipt left join transfer_receipt_details 
							on(transfer_receipt.id=transfer_receipt_details.transfer_receipt_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(transfer_receipt_details.reciveqty)'];
						}
						
						
						////2. Site to site transfer issue/////
						function issueSiteToSite($function_filter,$item)
						{
							global $db;
						 	$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[3];
							if($site!='')
							$filter[]="transfer_issue.sitecode = '".$site."'";
							if($store!='')
							$filter[]="transfer_issue.fromstore = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="transfer_issue.issuedate <='".$from."' ";
							if($item!='')
							$filter[]="transfer_issue_details.itemid = '".$item."'";
							$filter=implode(' and ',$filter);
						    $sql1="Select SUM(transfer_issue_details.issueqty) 
							from transfer_issue left join transfer_issue_details 
							on(transfer_issue.id=transfer_issue_details.transfer_issue_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							$return_array=$myrow1['SUM(transfer_issue_details.issueqty)'];
							//$avg_rate=$myrow1['SUM(transfer_issue_details.rate)'];
							//$return_array[]=$avg_rate;
							return $return_array;
						 }
						////3. Material return to vendor///
						function issueMatarialReturn($function_filter,$item)
						{
							global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[3];
							if($site!='')
							$filter[]="inv_material_return.sitecode = '".$site."'";
							if($store!='')
							$filter[]="inv_material_return.storecode = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="inv_material_return.Reqdate <='".$from."'";
							if($item!='')
							$filter[]="inv_material_return_details.itemid = '".$item."'";
							$filter=implode(' and ',$filter);
						    $sql1="Select SUM(inv_material_return_details.ReturnQty) 
						    from inv_material_return left join inv_material_return_details 
						    on(inv_material_return.id=inv_material_return_details.parentId) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(inv_material_return_details.ReturnQty)'];
						}
						
						
						function Rgpchallan($function_filter,$item)
					     {
					  
					        global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[2];
							if($site!='')
							$filter[]="rgp_tab.branch = '".$site."'";
							if($store!='')
							$filter[]="rgp_tab.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="rgp_tab.date <= '".$from."'";
							if($item!='')
							$filter[]="rgp_tab_details.mst_itemid = '".$item."'";
							$filter=implode(' and ',$filter);
							$sql1="Select SUM(rgp_tab_details.qty) 
							from rgp_tab left join rgp_tab_details 
							on(rgp_tab.id=rgp_tab_details.parent_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(rgp_tab_details.qty)'];
					    		
					     }	
					   function Rgpreturn($function_filter,$item)
					    {
					  
					        global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[2];
						    if($site!='')
							$filter[]="rgp_return.branch = '".$site."'";
							if($store!='')
							$filter[]="rgp_return.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="rgp_return.return_date <= '".$from."' ";
							if($item!='')
							$filter[]="rgp_return_details.item_id = '".$item."'";
							$filter=implode(' and ',$filter);
							$sql1="Select SUM(rgp_return_details.qty) 
							from rgp_return left join rgp_return_details 
							on(rgp_return.id=rgp_return_details.parent_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(rgp_return_details.qty)'];
					  				  		
					    }	
					  
					  function Nrgp($function_filter,$item)
					    {					  
					        global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[2];							
							if($site!='')
							$filter[]="nrgp_challan.branch = '".$site."'";
							if($store!='')
							$filter[]="nrgp_challan.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="nrgp_challan.date <= '".$from."' ";
							if($item!='')
							$filter[]="nrgp_challan_details.item_code = '".$item."'";							
							$filter=implode(' and ',$filter);
							$sql1="Select SUM(nrgp_challan_details.qty) 
							from nrgp_challan left join nrgp_challan_details 
							on(nrgp_challan.id=nrgp_challan_details.parant_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(nrgp_challan_details.qty)'];
					  			  		
					  }	
						
						 function FinishedMR($function_filter,$item)
					    {					  
					        global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
														
							if($site!='')
							$filter[]="finished_recieved.site = '".$site."'";
							if($store!='')
							$filter[]="finished_recieved.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="finished_recieved.recieved_date <= '".$from."' ";
							if($item!='')
							$filter[]="finished_recieved_details.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							   $sql1="Select SUM(finished_recieved_details.reciveqty) 
							  from finished_recieved left join finished_recieved_details 
							  on(finished_recieved.id=finished_recieved_details.finished_recieved_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(finished_recieved_details.reciveqty)'];
					  
					  
					  		
					  }	
					  
					   
					  function invoice($function_filter,$item)
					  {
					   global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
														
							if($site!='')
							$filter[]="invoice.branch_name = '".$site."'";
							if($store!='')
							$filter[]="invoice_details.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="invoice.invoiceDate <= '".$from."' ";
							if($item!='')
							$filter[]="invoice_details.ItemCode = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							    $sql1="Select SUM(invoice_details.Quantity)  from 
							  invoice_details INNER JOIN invoice 
								ON invoice.invoice_id=invoice_details.invoiceid 
								where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(invoice_details.Quantity)'];
					  
					  
					  
					  }
					  
					  function disptch($function_filter,$item)
					  {
					   global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
														
							if($site!='')
							$filter[]="dispatch.site = '".$site."'";
							if($store!='')
							$filter[]="dispatch.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="dispatch.dispatchDate <= '".$from."' ";
							if($item!='')
							$filter[]="dispatch_details.item = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							
							
							
							     $sql1="Select SUM(dispatch_details.dispatchQty)  from 
							  dispatch_details INNER JOIN dispatch 
								ON dispatch.id=dispatch_details.parentId 
								where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(dispatch_details.dispatchQty)'];
					  
					  
					  
					  }
if($_REQUEST['action']=='close'){
   
$sql=DB_query("UPDATE dms_doc_type SET status='1' WHERE id='".$_REQUEST['id']."'",$db);
 $s->pageLocation("index.php?route=DMS/doc_type_index".$rurl);
}

if($_REQUEST['action'] == 'Delete')
{
	$del_query = "DELETE FROM dms_doc_type WHERE id='".$_REQUEST['id']."'";
	$del_query_res = DB_query($del_query,$db) or die(DB_error());
	$del=DB_query("DELETE from dms_doc_type_dtls WHERE parent_id='".$_REQUEST['id']."'",$db);

	if(DB_affected_rows($del_query_res)>0)
	{
	echo "<script>alert('Successfully Deleted')</script>";
	}
}					  
 
?>	

<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<script type="text/javascript">
function showSlidingDiv(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 700 });
}
</script>
<div class="body_contain">
<div class="tab_div">
<?php 
echo '<form action="' . $_SERVER['PHP_SELF'] . '?' . 'route=Inventory/transation/Issue_slip_index&modid='.$_REQUEST['modid'].'&frmid=' .$_REQUEST['frmid'].'" method=post>'; ?>
<?php if($_REQUEST['action']==''){?>
<h3 align="center"><strong>Pending Document Type</strong></h3>
<br />
<div align="left"><!--<a href="#" onClick="showSlidingDiv(); return false;"><input type="button" class="search" value="Show Search" style="width:140px;cursor:pointer;"/></a>--></div>
<div id="slidingDiv" class="centre" >
<table width="100%" border="1" cellspacing="1" cellpadding="2" align="center">
  <tr class="row1">
	<td class="tabledata1" ><strong>Site</strong></td>
    <td class="tabledata1">
	<?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);"> 
    <option  value="000">Select Site</option>
	<?php 
	
		while ($myrow=DB_fetch_array($site_sql)){
 				echo '<option Value="' . $myrow['loccode'] . '">' . $myrow['locationname'].'</option>';
 		}
      

	?> </select></td>
	<td class="tabledata1" ><strong>Issue Number</strong></td>
     <td class="tabledata1">
	<div id="mrnno1">
     <select  name="issueno">
	 <option  value="000">Select</option>
	<?php 
		$sql = "SELECT  * FROM addissue";
		$resultStkLocs = DB_query($sql,$db);
		while ($myrow=DB_fetch_array($resultStkLocs)){
 				echo '<option Value="'.$myrow['id'].'">' . $myrow['issue_slipno'].'</option>';
 		
       }

	?> </select>
	</div>
	
	</td></tr>
    <tr class="row1">
   <td class="tabledata1" ><strong>Employee</strong></td>	
     <td class="tabledata1">	  
		<select name="employee" id="employee" >
		<option value="000">---Select---</option>-->
		<?php 
		$vendor_sql=DB_query("Select id,emp_name from empmaster where CompanyId='".$_SESSION['ACGCompanyId']."' AND 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['emp_name'];?></option>
		<?php } ?>
		</select>
		
	</td>
	<td class="tabledata1" ><strong>Contactor</strong></td>
	<td class="tabledata1"><select name="contactor" id="contactor" >
		<option value="000">---Select---</option>-->
		<?php 
	$vendor_sql=DB_query("Select id,contractor_name from contractor_master order by contractor_name ASC",$db);
		while($vendor_res=DB_fetch_array($vendor_sql))
		{?>		
		<option value="<?php echo $vendor_res['id'];?>"><?php echo  $vendor_res['contractor_name']; ?></option>
		<?php } ?>
		</select></td>
  
    </tr>	
	<tr class="row1">
	<td class="tabledata1" ><strong>From Date</strong></td>
	<td class="tabledata1" ><input type="text" name="fromdate" class="datepicker"  size="12" /></td>
	<td class="tabledata1"><strong>To Date</strong></td>
	<td class="tabledata1" ><input type="text" name="todate" class="datepicker"  size="12"  /></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1" colspan="4" align="center" style="text-align:center;" ><input name="Search" type="submit" value="Search" class="search" /></td>
	</tr>
  </table>

</div>
<br/>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;" align="center">
  <tr>
    <td class="tabledata"><strong>Sr No.</strong></td>
    <td class="tabledata"><strong>Branch </strong></td>
    <td class="tabledata"><strong>Document No.</strong></td>
    <td class="tabledata"><strong>Document Date</strong></td>
    <td class="tabledata"><strong>Document From/To</strong></td>
    <td class="tabledata"><strong>Name</strong></td>
    <td class="tabledata"><strong>Movement</strong></td>
    <td class="tabledata"><strong>Subject</strong></td>
    <td class="tabledata"><strong>View</strong></td>
    <td class="tabledata"><strong>Edit</strong></td>
    <td class="tabledata"><strong>Delete</strong></td>
    <td class="tabledata" colspan='2' style='text-align:center;'><strong>Action</strong></td>
  </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 
{   
if($_SESSION['AssignedBranch']!='')
{	
$SQL="SELECT a.id as mainId, a.* FROM dms_doc_type a  where a.CompanyId='".$_SESSION['ACGCompanyId']."' 
and a.branch in ('".$_SESSION['AssignedBranch']."') and a.status='0' order by a.id DESC";
}
else
{
$SQL="SELECT  a.id as mainId, a.* FROM dms_doc_type a 
where a.CompanyId='".$_SESSION['ACGCompanyId']."' and a.status='0' order by a.id DESC";
}  
}  
  //echo $SQL;
  $sql=DB_query($SQL,$db);
 
  $i=0;
  if(DB_num_rows($sql)>0)
  {
  while($myrow=DB_fetch_array($sql))
  {
   if($myrow['doc']=='I')
   { 
       $userArray=explode(',', $myrow['to_name']);
       if(in_array($_SESSION['UserID'], $userArray) || $myrow['createdBy']==$_SESSION['UserID'] || $_SESSION['UserType']=='SuperAdmin')
       {
  ?>
  <tr bgcolor="#FFFFFF">
    <td><?php echo ($i+1).'.'; ?></td>
     <td><?php  
	echo $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
	 ?></td>
      <td><?php  
	echo $myrow['doc_no'];
	 ?></td>
    <td><?php echo ConvertSQLDate($myrow['doc_date']);?></td>
    <td><?php 
    if($myrow['doc_Type']=='V') { $type='Vendor'; } elseif($myrow['doc_Type']=='C'){ $type='Client'; } elseif($myrow['doc_Type']=='G'){ $type='General'; } elseif($myrow['doc_Type']=='O'){ $type='Other'; } elseif($myrow['doc_Type']=='B'){ $type='Branch'; }
	echo	$type;
	 ?></td>
    
    <td><?php 
    if($myrow['doc_Type']=='V') { $name=$s->getField('suppliers','id',$myrow['doc_id'],'vendor_name'); } 
    elseif($myrow['doc_Type']=='C'){ $name=$s->getField('clientmaster','id',$myrow['doc_id'],'c_name'); }
    elseif($myrow['doc_Type']=='G'){ $name=$myrow['doc_id']; }
    elseif($myrow['doc_Type']=='O'){ $type=$myrow['doc_id']; }
    elseif($myrow['doc_Type']=='B'){ $name=$s->getField('locations','loccode',$myrow['doc_id'],'locationname'); }
	echo $name;
	 ?></td>
    
     <td><?php 
    if($myrow['doc']=='I') { $docName='Incoming'; } elseif($myrow['doc']=='O'){ $docName='Outgoing'; } 
    echo $docName;
	 ?></td>
     
     <td><?php 
    $detailsSql="select * from dms_doc_type_dtls where parent_id='".$myrow['mainId']."'";
    $detailsSqlExec=DB_query($detailsSql,$db);
    while($row=DB_fetch_array($detailsSqlExec))
  { 
        echo $row['doc_name'].'<br/>';
 } ?></td>
     <td style="text-align: center;"><?php if($_SESSION['frmView']=='1' ){?>
	<a href="index.php?route=DMS/dmsTransaction_EDIT&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=View&id=<?php echo $myrow['mainId']; ?>" ><img src="images/search.gif" height="15" width="15"></a><?php }else{echo "No Permission";}?></td>
	<td style="text-align: center;">
	<?php if($_SESSION['frmEdit']=='1'){?>
	<a href="index.php?route=DMS/dmsTransaction_EDIT&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Edit&id=<?php echo $myrow['mainId']; ?>" ><img src="images/icon-edit.png" height="15" width="15"></a><?php }else{echo "No Permission";}?>
	</td>
	<td style="text-align: center;">
	<?php if($_SESSION['frmDelete']=='1' &&  $check=='' ){?>
	<a href="index.php?route=DMS/doc_type_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Delete&id=<?php echo $myrow['mainId']; ?>&sitecode=<?php echo $myrow['site']; ?>&store=<?php echo $myrow['mst_storeid'];?>&date=<?php echo $myrow['issuedate']; ?>"onclick="return confirm('Are you sure you want to delete?')"> <img src="images/Icon_Delete.png" height="15" width="15"></a>
        
            <?php }else{echo "No Permission";}?>
	</td>
    	<td style="text-align: center;">
       <a href="index.php?route=DMS/dmsFollowup&id=<?php  echo $myrow['id'].$rurl;?>"><input type="button" name="Create" value="Follow Up" class="search" /></a>
       <?php if(($myrow['createdBy']==$_SESSION['UserID']) || ($_SESSION['UserType']=='SuperAdmin')){ ?><a href="<?php echo $targetpage?>&action=close&id=<?php echo $myrow['mainId']; ?>"><input type="button" name="close" value="Close" class="search" onclick="return confirm('Are you sure to close?')"/></a><?php }else{?><input type="button" name="close" value="Close" class="search" style="opacity: 0.3;"/><?php }?>
        </td>
  </tr>
   <?php $i++;}
  }
  else { 
  $userArray2=explode(',', $myrow['from_name']);
       if(in_array($_SESSION['UserID'], $userArray2) || $myrow['createdBy']==$_SESSION['UserID'] || $_SESSION['UserType']=='SuperAdmin')
       {
  ?>
  <tr bgcolor="#FFFFFF">
    <td><?php echo ($i+1).'.'; ?></td>
     <td><?php  
	echo $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
	 ?></td>
      <td><?php  
	echo $myrow['doc_no'];
	 ?></td>
    <td><?php echo ConvertSQLDate($myrow['doc_date']);?></td>
    <td><?php 
    if($myrow['doc_Type']=='V') { $type='Vendor'; } elseif($myrow['doc_Type']=='C'){ $type='Client'; } elseif($myrow['doc_Type']=='G'){ $type='General'; } elseif($myrow['doc_Type']=='O'){ $type='Other'; } elseif($myrow['doc_Type']=='B'){ $type='Branch'; }
	echo	$type;
	 ?></td>
    
    <td><?php 
    if($myrow['doc_Type']=='V') { $name=$s->getField('suppliers','id',$myrow['doc_id'],'vendor_name'); } 
    elseif($myrow['doc_Type']=='C'){ $name=$s->getField('clientmaster','id',$myrow['doc_id'],'c_name'); }
    elseif($myrow['doc_Type']=='G'){ $name=$myrow['doc_id']; }
    elseif($myrow['doc_Type']=='O'){ $type=$myrow['doc_id']; }
    elseif($myrow['doc_Type']=='B'){ $name=$s->getField('locations','loccode',$myrow['doc_id'],'locationname'); }
	echo $name;
	 ?></td>
    
     <td><?php 
    if($myrow['doc']=='I') { $docName='Incoming'; } elseif($myrow['doc']=='O'){ $docName='Outgoing'; } 
    echo $docName;
	 ?></td>
     
     <td><?php 
   $detailsSql="select * from dms_doc_type_dtls where parent_id='".$myrow['mainId']."'";
    $detailsSqlExec=DB_query($detailsSql,$db);
    while($row=DB_fetch_array($detailsSqlExec))
  { 
        echo $row['doc_name'].'<br/>';
  } ?></td>
     <td style="text-align: center;"><?php if($_SESSION['frmView']=='1' ){?>
	<a href="index.php?route=DMS/dmsTransaction_EDIT&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=View&id=<?php echo $myrow['mainId']; ?>" ><img src="images/search.gif" height="15" width="15"></a><?php }else{echo "No Permission";}?></td>
	<td style="text-align: center;">
	<?php if($_SESSION['frmEdit']=='1'){?>
	<a href="index.php?route=DMS/dmsTransaction_EDIT&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Edit&id=<?php echo $myrow['mainId']; ?>" ><img src="images/icon-edit.png" height="15" width="15"></a><?php }else{echo "No Permission";}?>
	</td>
	<td style="text-align: center;">
	<?php if($_SESSION['frmDelete']=='1' &&  $check=='' ){?>
	<a href="index.php?route=DMS/doc_type_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Delete&id=<?php echo $myrow['mainId']; ?>&sitecode=<?php echo $myrow['site']; ?>&store=<?php echo $myrow['mst_storeid'];?>&date=<?php echo $myrow['issuedate']; ?>" onclick="return confirm('Are you sure you want to delete?')"><img src="images/Icon_Delete.png" height="15" width="15"></a><?php }else{echo "No Permission";}?>
	</td>
    	<td style="text-align: center;">
       <a href="index.php?route=DMS/dmsFollowup&id=<?php  echo $myrow['id'].$rurl;?>"><input type="button" name="Create" value="Follow Up" class="search" /></a>
       <?php if(($myrow['createdBy']==$_SESSION['UserID']) || ($_SESSION['UserType']=='SuperAdmin')){ ?><a href="<?php echo $targetpage?>&action=close&id=<?php echo $myrow['mainId']; ?>"><input type="button" name="close" value="Close" class="search" onclick="return confirm('Are you sure to close?')"/></a><?php }else{?><input type="button" name="close" value="Close" class="search" style="opacity: 0.3;"/><?php } ?>
       </td></tr>
   <?php $i++;}
 }
  } }
  else
  {?>
  <tr>
  <td colspan="12" style="color:red;"><strong>No Record Found</strong></td>
  </tr>
  <?php 	
  }
  ?>
</table>
</form>
<?php } 
if($_REQUEST['id']!='' && $_REQUEST['action']=='view') 
{ 
	$sql="SELECT * FROM addissue where id='".$_REQUEST['id']."'";
	$result=DB_query($sql,$db);
	$myrow1=DB_fetch_array($result);
	
	$function_filter[]=$myrow1['site'];
	$function_filter[]=$myrow1['mst_storeid'];
	$function_filter[]=date('Y-m-d'); 
	$function_filter[]=date('Y-m-d'); 
	?>
	<h3 align="center"><strong>Material</strong> Issue <strong>Slip</strong></h3>
    <div align="center">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;" align="center">
<tr class="row1">
    <td class="tabledata1"><strong>Branch</strong></td>
    <td class="tabledata1">
	 <?php echo  $sitename=$s->getField('locations','loccode',$myrow1['site'],'locationname');?> </td>
    <td class="tabledata1"><strong>Godown</strong></td>
    <td class="tabledata1"><?php echo $storename=$s->getField('storetype','StoreCode',$myrow1['store'],'StoreName');?></td>
</tr>
  <tr class="row1">
    <td class="tabledata1"><strong>Issue Slip No.</strong></td>
    <td class="tabledata1"><?php echo $myrow1['issue_slipno']; ?></td>
    <td class="tabledata1"><strong>Issue Date </strong></td>
    <td class="tabledata1"><?php echo ConvertSQLDate($myrow1['issuedate']); ?></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1"><strong>Department</strong></td>
    <td  class="tabledata1">	
	<?php  echo $s->getField('deptmaster','id',$myrow1['department'],'deptname'); ?>	    </td>
        <td class="tabledata1"><strong>Employee Name</strong></td>
    <td class="tabledata1"><?php echo $s->getField('empmaster','id',$myrow1['received_by'],'emp_name'); ?></td>
</tr>  
  <tr class="row1">
    <td class="tabledata1"><strong>Issue To Floor</strong></td>
	<?php $floor_id = $s->getField('addissue','id',$_REQUEST['id'],'issue_floor');?>
	
    <td class="tabledata1"><?php echo strtoupper($s->getField('floor_master','id',$floor_id,'floorName'));  ?></td>
	<td class="tabledata1"><strong>Finished Item Detail</strong></td>
	
  	<td class="tabledata1"><?php echo $myrow1['finished_item_detail']; ?></td> </tr>
    <tr class="row1">
	<td class="tabledata1"><strong>Issue Reference No.</strong></td>
  	<td><?php echo $myrow1['issue_reg_no']; ?></td>
  	<td class="tabledata1"><strong>Cost Center </strong></th>
  	<td class="tabledata1"><?php echo $myrow1['cost_center']; ?></td>
  </tr>
  <tr><td>&nbsp;</td></tr>
</table>
</div>
<br/>
<div align="center">
<table width="100%" align="center">
<tr class="row1">
<td  class="tabledata1" >
<table width="100%" border="" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;" 
align="center">
  <tr class="row1">
    <td class="tabledata1"><strong>Item Code</strong></td>
    <td class="tabledata1"><strong>Description</strong></td>
     <td class="tabledata1"><strong>UOM</strong></td>
    
   
    <td class="tabledata1"><strong>Current Balance </strong></td>
	  <td class="tabledata1"><strong>Req Qty </strong></td>
	  <td class="tabledata1"><strong>Issue Qty </strong></td>	
      </tr>
  <tbody id="dataTable">
  	<?php 
   	$sql = "SELECT * FROM issueqty where issue_id ='".$_REQUEST['id']."'";
	  $resultStkLocs1 = DB_query($sql,$db);
	  $i=0;
	  while ($myrow2=DB_fetch_array($resultStkLocs1))
	  {
	  
							 $op=openingBalance($function_filter,$myrow2['mst_itemid']);
							//echo "openingBalance"."<br>";
							 $in_1=receivedMRN($function_filter,$myrow2['mst_itemid']);
							//echo "receivedMRN"."<br>";
							 $out_1=issueSlip($function_filter,$myrow2['mst_itemid']);
							//echo "issueSlip"."<br>";
							 $out_2=issueSiteToSite($function_filter,$myrow2['mst_itemid']);		
							//echo "issuesitetosite"."<br>";
							 $in_2=receivedSiteToSite($function_filter,$myrow2['mst_itemid']);
							//echo " receivesitetosite"."<br>";
							 $out_3=issueMatarialReturn($function_filter,$myrow2['mst_itemid']);
							//echo "issuematerialreturn"."<br>";
							 $in_3=receivedReturn($function_filter,$myrow2['mst_itemid']);	
							//echo "receivedReturn"."<br>";
							 $out_4=Rgpchallan($function_filter,$myrow2['mst_itemid']);
							//echo "Rgpchallan"."<br>";
							 $out_5=Nrgp($function_filter,$myrow2['mst_itemid']);
							//echo "Nrgp"."<br>";
							//echo $out_6=invoice($function_filter,$myrow2['mst_itemid']);
							//echo "invoice"."<br>";
							 $out_7=disptch($function_filter,$myrow2['mst_itemid']);
							//echo "disptch"."<br>";
							 $in_4=Rgpreturn($function_filter,$myrow2['mst_itemid']);
							//echo "Rgpreturn"."<br>";	 
							 $in_5=FinishedMR($function_filter,$myrow2['mst_itemid']);
							//echo "FinishedMR"."<br>";	
							//$in_4=return_rejection($function_filter,$myrow2['id']);
							$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5);
							$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_7);
							$tot=$invalue-$outvalue;
							//$total_current=$op ;	
							$stockbalance=$tot;	
	  
	  
						$item_name= $s->GetFieldValue('item_master'," id='".$myrow2['mst_itemid']."'" ,'item_name');
						$item_code= $s->GetFieldValue('item_master'," id='".$myrow2['mst_itemid']."'" ,'StockID');
						$unit= $s->GetFieldValue('item_master'," id='".$myrow2['mst_itemid']."'" ,'mst_unitid');
						$item_desc= $s->GetFieldValue('item_master'," id='".$myrow2['mst_itemid']."'" ,'item_desc');
						$Stockbalance= $myrow2['current_stock'];
						$issueqty= $myrow2['issueqty'];
						$primary_issueqty= $myrow2['primary_issueqty'];
						$req_qty=$myrow2['req_qty'];
			
	  		?>			
<tr bgcolor="#FFFFFF">
<td><?php echo $item_code;?></td>
<td><?php echo $item_name;?></td>
<td><?php  echo $s->GetFieldValue('unitsofmeasure',"unitid='". $unit."'",'unitname');?></td>           
<td><?php echo $stockbalance;?></td>
<td> <?php  echo $req_qty;	?></td>
<td><?php echo $issueqty?></td>
</tr> 
  
  <?php $i++;} ?>
</tbody>
</table>
</td>
</tr>
</table>
</div>
</div>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;" align="center">
<tr class="row1">
<td class="tabledata1"><strong>Remarks </strong></td>
<td class="tabledata1" colspan="3"><textarea name="remarks"  style="width:100%" id="remark" readonly=""><?php echo $myrow1['remarks']; ?></textarea></td>
</tr>
<tr class="row1">
<td class="tabledata1"><strong>Material Recd by</strong></td>
<td class="tabledata1"><?php echo $myrow1['material_received_by']; ?></td>
<td class="tabledata1"><strong>Material Issued by</strong></td>
<td class="tabledata1"><?php echo $myrow1['material_issue_by']; ?></td>
</tr>
</table>


<p align="center">
<a href="index.php?route=Inventory/transation/Issue_slip_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes" style="text-decoration:none;"><input type="button" value="Cancel" name="Back" class="search" style="cursor:pointer;"/></a></p>
<?php } ?>
 </div></div>
<?php











if($_REQUEST['id']!='' && $_REQUEST['action']=='Delete') 
{ 

$del="delete from dms_doc_type where id='".$_REQUEST['id']."'";
$query=DB_query($del,$db);

$fetchFiles="select * from dms_doc_type_dtls where parent_id='".$_REQUEST['id']."'";
$fetchFilesExec=DB_query($fetchFiles,$db);
 while ($rowfiles=DB_fetch_array($fetchFilesExec))
	  {
     $name=$rowfiles['doc_file_name'];
     if($name!='')
     {
        $path="uploaded_docs/".$name;
        if(unlink($path))
        {
            $del1="delete from dms_doc_type_dtls where parent_id='".$_REQUEST['id']."'";
           $query1=DB_query($del1,$db);
        }
    }
 }
 

$s->pageLocation("index.php?route=DMS/doc_type_index".$rurl);

}	?>
<?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)
{

if (str.length==0)
  		{
  			document.getElementById("mrnno1").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("mrnno1").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","issueno.php?site="+str,true);
		xmlhttp.send();


}

</script>	