<?php
require_once("../includes/config.php");
if(isset($_REQUEST['location'])){$selloc=$_REQUEST['location'];}else{$selloc="";}
if(isset($_REQUEST['stock_type'])){$selstoktyp=$_REQUEST['stock_type'];}else{$selstoktyp="";}
if(isset($_REQUEST['daterange'])){$date_range=$_REQUEST['daterange'];}else{$date_range="";}
/////////check approval is applicable or not
$apply_app = getAnyDetails(base64_decode($_REQUEST['pid']),"apply_approval","tabid","tab_master",$link1);

$get_opr_rgts = getOprRights($_SESSION['userid'],$_REQUEST['pid'],$link1);
///// get access location details
$access_loc = getAccessLocation($_SESSION['userid'],$link1);
?>
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="shortcut icon" href="../images/titleimg.png" type="image/png">
 <script src="../js/jquery.js"></script>
 <?php 
 include("../includes/fontawesome.html");
 include("../includes/main_css.html"); 
 include("../includes/bootstrap.html");
 include("../includes/datatables.html");
 ?>
 <script type="text/javascript" language="javascript" >
$(document).ready(function() {
	var dataTable = $('#emp-grid').DataTable( {
		"processing": true,
		"serverSide": true,
		"order": [[ 0, "asc" ]],
		"ajax":{
			url :"../pagination/stock_conversion-grid-data.php", // json datasource
			data: { "pid": "<?=$_REQUEST['pid']?>", "hid": "<?=$_REQUEST['hid']?>", "icn": "<?=$_REQUEST['icn']?>", "location": "<?=$selloc?>", "stock_type": "<?=$selstoktyp?>", "daterange": "<?=$date_range?>"},
			type: "post",  // method  , by default get
			error: function(){  // error handling
				$(".emp-grid-error").html("");
				$("#emp-grid").append('<tbody class="emp-grid-error"><tr><th colspan="<?php if($apply_app=="Y"){echo "9";}else{ echo "8";}?>">No data found in the server</th></tr></tbody>');
				$("#emp-grid_processing").css("display","none");
				
			}
		}
	} );
} );
$(document).ready(function(){
	$('input[name="daterange"]').daterangepicker({
		locale: {
			format: 'YYYY-MM-DD'
		},
		startDate: "<?=date("Y-m-01")?>"
	});
});
</script>
 <!-- Include Date Range Picker -->
  <script type="text/javascript" src="../js/moment.js"></script>
 <script type="text/javascript" src="../js/daterangepicker.js"></script>
 <link rel="stylesheet" type="text/css" href="../css/daterangepicker.css"/>
<title><?=siteTitle?></title>
</head>
<body>
<div class="container-fluid">
  <div class="row content">
	<?php 
    include("../includes/leftnav_admin.php");
    ?>
    <div class="<?=$screenwidth?> tab-pane fade in active" id="home">
      <h2 align="center"><i class="fa <?=$fa_icon?>"></i> Stock Conversion List</h2>
      <?php if(isset($_REQUEST['msg'])){?>
        <div class="alert alert-<?php echo $_REQUEST['chkflag'];?> alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            <strong><?php echo $_REQUEST['chkmsg'];?>!</strong>&nbsp;&nbsp;<?=$_REQUEST['msg']?>.
        </div>
      <?php }?>
	  <form class="form-horizontal" role="form" name="form1" action="" method="get">
	   <div class="form-group">         
		  <div class="col-md-6"><label class="col-md-5 control-label">Location</label>
			<div class="col-md-6" align="left">
			   <select name="location" id="location" class="form-control custom-select">
                    <option value=''>All</option>
					<?php
					$res_maploc = mysqli_query($link1,"select location_code,locationname from location_master where statusid='1' and location_code in (".$access_loc.") order by locationname "); 
					while($row_maploc = mysqli_fetch_assoc($res_maploc)){
						?>
					<option value="<?=$row_maploc['location_code']?>" <?php if($selloc == $row_maploc['location_code']) { echo 'selected'; }?>><?=$row_maploc['locationname']." (".$row_maploc['location_code'].")"?></option>
					<?php } ?>
               </select>
            </div>
          </div>
               <div class="col-md-6"><label class="col-md-5 control-label"> Conversion Type </label>	  
			<div class="col-md-6" align="left">
			   <select name="stock_type" id="stock_type" class="form-control custom-select">
                    <option value=''>All</option>               	    
                    <option value="Fresh To Damage" <?php if($selstoktyp == "Fresh To Damage") { echo 'selected'; }?>>Fresh To Damage</option>    
                    <option value="Damage To Fresh" <?php if($selstoktyp == "Damage To Fresh") { echo 'selected'; }?>>Damage To Fresh</option>                    
               </select>
            </div>
          </div>
	    </div><!--close form group-->		
	    <div class="form-group" style="margin-top:30px;">
		  	<div class="col-md-6" align="left"><label class="col-md-5 control-label"> Date Range </label>
			<div class="col-md-6" align="left">	
                            <input type="text" name="daterange" id="date_rng" class="form-control" value="<?=$seldaterng?>" />
            </div>
                        </div>
		  <div class="col-md-4"><label class="col-md-5 control-label"></label>
			<div class="col-md-5" align="left">
	       <input name="pid" id="pid" type="hidden" value="<?=$_REQUEST['pid']?>"/>
               <input name="hid" id="hid" type="hidden" value="<?=$_REQUEST['hid']?>"/>
               <input name="icn" id="icn" type="hidden" value="<?=$_REQUEST['icn']?>"/>
               <input style="float:left;" name="Submit" type="submit" class="btn<?=$btncolor?>" value="GO"  title="Go!">
			   
			   <?php
			    ////// check this user have right to export the excel report
			    	if($get_opr_rgts['excel']=="Y"){
			   ?>
               <a style="float:right;" href="../excelReports/stock_conversion_list_excel.php?daterange=<?=$seldaterng;?>&location=<?=base64_encode($selloc);?>&stock_type=<?=base64_encode($selstoktyp);?>" title="Export Stock Ledger details in excel"><i class="fa fa-file-excel-o fa-2x faicon excelicon" title="Export Stock Ledger details in excel"></i></a>
               <?php
			}
				?>
			   
            </div>
          </div>
	    </div><!--close form group-->
	  </form>
      <form class="form-horizontal" role="form">
      <?php
      if($get_opr_rgts['add']=="Y"){
      ?>
        <button title="Add Stock Conversion" type="button" class="btn<?=$btncolor?>" style="float:right;" onClick="window.location.href='stock_conversion_add.php?op=add<?=$pagenav?>'"><i class="fa fa-plus-circle fa-lg"></i>&nbsp;&nbsp;Add Stock Conversion</button>&nbsp;&nbsp;
        <?php } ?> 
        <div class="form-group"  id="page-wrap" style="margin-left:10px;"><br/>
      <!--<div class="form-group table-responsive"  id="page-wrap" style="margin-left:10px;"><br/><br/>-->
       <table  width="100%" id="emp-grid" class="display" align="center" cellpadding="4" cellspacing="0" border="1">
          <thead>
            <tr class="<?=$tableheadcolor?>">
              <th>S.No</th>
              <th>Location</th>
              <th>System Ref. No.</th>
              <th>Entry Date</th>
              <th>Conversion Type</th>
              <th>Status</th>
              <?php if($apply_app=="Y"){?>
              <th>Approval</th>
              <?php }?>
              <th>View</th>
              <th>Print</th>
            </tr>
            </tr>
          </thead>
          </table>
          </div>
      <!--</div>-->
      </form>
    </div>
    
  </div>
</div>
<?php
include("../includes/footer.php");
include("../includes/connection_close.php");
?>
</body>
</html>
