<!doctype html>
<?php 
include("../connection.php");
include("../user.php");
$cur_date=date('Y-m-d H:i:s');
$user=$_SESSION['user'];
$branch_id=$_SESSION['branch_id'];
$ho_access=$_SESSION['ha'];
		$stock_verify=mysqli_query($con,"select transaction_id from stock_inward order by id desc limit 0,1");
		$stock_count=mysqli_num_rows($stock_verify);
	if($stock_count=='')
	{
		$transaction_inc_id='1';
	}
	else
	{   $id_gen=mysqli_fetch_array($stock_verify);
		$transaction_ids=$id_gen['transaction_id'];
		$transaction_inc_id=$transaction_ids+1;
	}
	$sid=$_REQUEST['id'];
$stock_in=mysqli_fetch_array(mysqli_query($con,"SELECT st.*,st.transaction_id,st.date,st.from_location,lmm.location as to_location,st.flag,lm.location as from_location,st.to_division as division,sid.fa_serial_no FROM stock_transfer st left join location_master lm on st.from_location=lm.id left join location_master lmm on st.to_location=lmm.id join stock_item_detail sid on st.transaction_id=sid.transaction_id where st.transaction_id='$sid'"));
	$branch_idss=$stock_in['from_location'];  $to_locations=$stock_in['to_location']; $dates=date('d-m-Y',strtotime($stock_in['date']));
$location_name=mysqli_fetch_array(mysqli_query($con,"Select id from location_master where location='$branch_idss'"));
?>
 <html class="no-js" lang=""> 
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?php echo TITLE;?></title>
    <meta name="description" content="Ela Admin - HTML5 Admin Template">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="apple-touch-icon" href="../images/bluebase.png">
    <link rel="shortcut icon" href="../images/bluebase.png">
    <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> -->

	<style>
	input
	{
	text-transform:uppercase;	
	}
	textarea
	{
	text-transform:uppercase;	
	}
	select
	{
	text-transform:uppercase;	
	}
	 .select2-results__option {
            text-transform: uppercase;
        }
    </style>
    <script>
        $(document).ready(function() {
            $('.select-search').select2({
                placeholder: "-- SELECT --",
                allowClear: true,
                templateResult: function (data) {
                    if (!data.id) return data.text;
                    return data.text.toUpperCase();
                },
                templateSelection: function (data) {
                    if (!data.id) return data.text;
                    return data.text.toUpperCase();
                }
            });
        });
    </script>
</head>
<body>
  <div class="col-lg-8">
		<div class="card">
		<div class="card-header">
			<strong>Stock Inward</strong>
			<a href="stock_inward_master.php">
			<button class="btn btn-primary" style="width:50px;margin-left:600px;"onclick=""><i class="fa fa-backward"></i></button></a>			
		</div>
	<div class="card-body card-block">
	<form  method="post" enctype="multipart/form-data" class="form-horizontal" action="stock_inward_submit.php">
	
	<input type="hidden" id="transaction_id" name="transaction_id" value="<?php echo $stock_in['transaction_id']; ?>">
	<?php 
	if($ho_access=="yes")
	{
	?> 
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">Date</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
			<input type="text" id="date" name="date" value="<?php echo $dates; ?>"  class="form-control" autocomplete="off" required readonly>
		</div>
	</div>	
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">From Location</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
		<input type="text" value="<?php echo $branch_idss;?>" id="from_location" name="from_location" placeholder="select location" class="form-control"autocomplete="off" required readonly></div>
	</div>
		<input type="hidden" id="to_location" name="to_location" value="<?php echo $to_locations;?>" placeholder="select location" class="form-control" autocomplete="off" required readonly>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">From Division</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
		<input type="text" value="<?php echo $stock_in['from_division'];?>" id="fdivision" name="fdivision" placeholder="FROM DIVISION" class="form-control"autocomplete="off" required readonly></div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">To Division</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
		<input type="text" value="<?php echo $stock_in['to_division'];?>" id="division" name="division" placeholder="TO DIVISION" class="form-control"autocomplete="off" required readonly></div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">DEPARTMENT</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
		 <select class="form-control select-search" name="department" id="department" required="true">
		 <?php 
		 $department=mysqli_query($con,"SELECT * FROM type_master where status='0'");
		 ?>
		 <option value="">CHOOSE DEPARTMENT</option>
		 <?php
		 while($department_det=mysqli_fetch_array($department))
		 { ?>
			<option value="<?php echo $department_det['id']; ?>"><?php echo strtoupper($department_det['type']); ?></option>
		<?php	}	?>
		</select>
		</div>
	</div>
	<div class="row form-group">
			<div class="col col-md-3"><label for="text-input" class=" form-control-label">FA S.NO</label><span style="color:red;">*</span></div>
			<div class="col-12 col-md-9"><input type="text" value="<?php echo $stock_in['fa_serial_no']; ?>" id="fa" name="fa" class="form-control" autocomplete="off" placeholder="Enter FA Serial Number" required></div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">DEPRECIATION VALUE</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9"><input type="number" id="dep_value" name="dep_value" class="form-control" autocomplete="off" Placeholder="DEPRECIATION PERCENTAGES"></div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">DEPRECIATION AMOUNT</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9"><input type="number" id="dep_amount" name="dep_amount" class="form-control" autocomplete="off" Placeholder="DEPRECIATION AMOUNT"></div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">Remarks</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
			<input type="textarea" id="remarks" name="remarks" placeholder="Enter REMARKS" class="form-control" autocomplete="off" required>
		</div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">AMC/INS.NO Date</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
			<input type="date" id="expiry_dates" name="expiry_dates" placeholder="CHOOSE EXPIRY DATE" class="form-control" autocomplete="off">
		</div>
	</div>
			
		<div id="conf">
		<table id="upload" class="table table-striped" style="text-transform:upper;" >
			<thead>
				<tr>
					<th>Category</th>
					<th>Category Description</th>
					<th>Item NO.</th>
					<th>Value</th>
					<th>Amount</th>
				</tr>
			</thead>
		<?php 
		
		$categ_det=mysqli_query($con,"SELECT sit.transaction_id as trans_id,sit.value as value,sit.amount as amount,sit.transaction_id,sit.quantity as quantity,sit.category as cat_name,sit.category_description as category_description FROM stock_item_detail sit where flag=1 and transaction_id='$sid'");
		while($cate_peu=mysqli_fetch_array($categ_det))
		{ ?>
		<tbody>
				<tr id="rw_1" class="row_1">
				<td>
				<input type="hidden" class="form-control" name="cat_id" value="<?php echo $cate_peu['trans_id']; ?>">
				<input  class="form-control" type="text" id="cat_name"  name="cat_name" value="<?php echo $cate_peu['cat_name']; ?>" autocomplete="off" readonly="TRUE">
				</td>
				<td>
				<input  class="form-control" type="text" id="cat_desc"  name="cat_desc" value="<?php echo $cate_peu['category_description']; ?>" autocomplete="off" readonly="TRUE">
				</td>
				<td><input  class="form-control" type="text" id="item"  name="item" value="<?php echo $cate_peu['quantity']; ?>" autocomplete="off" readonly="TRUE"></td>
				<td><input  class="form-control" type="text" id="value"  name="value" value="<?php echo $cate_peu['value']; ?>" autocomplete="off" readonly="TRUE"></td>
				<td><input  class="form-control" type="text" id="amount"  name="amount" value="<?php echo $cate_peu['amount']; ?>" autocomplete="off" readonly="TRUE"></td>	
			</tr>
		</tbody>
		<?php  } ?>
		</table>
		</div>
	<?php
	}
else 
{ 
$convert_date_format=date('d-m-Y',strtotime($stock_in['date']));
	?>
		<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">Date</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
			<input type="text" id="dates" name="dates" value="<?php echo $convert_date_format; ?>" placeholder="" class="form-control" autocomplete="off" disabled>
			<input type="hidden" id="date" name="date" value="<?php echo $stock_in['date']; ?>" placeholder="" class="form-control" autocomplete="off" >
		</div>
		</div>
		<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">From Location</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
			<input type="hidden" id="to_location" name="to_location" value="<?php echo $to_locations; ?>" placeholder="" class="form-control">
			<input type="hidden" id="from_location" name="from_location" value="<?php echo $branch_idss; ?>" placeholder="" class="form-control">
			<input type="text" name="from_loc" value="<?php echo $branch_idss; ?>" class="form-control" autocomplete="off" disabled ></div>
		</div>
		<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">From Division</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
		<input type="text" value="<?php echo $stock_in['from_division'];?>" id="fdivision" name="fdivision" placeholder="FROM DIVISION" class="form-control"autocomplete="off" required readonly></div>
	</div>
		
			<input type="hidden" id="division" name="division" value="<?php echo $stock_in['division']; ?>"  class="form-control" autocomplete="off" readonly>
		
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">DEPARTMENT</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
		 <select class="form-control select-search" name="department" id="department" required="true">
		 <?php 
		 $department=mysqli_query($con,"SELECT * FROM type_master where status='0'");
		 ?>
		 <option value="">CHOOSE DEPARTMENT</option>
		 <?php
		 while($department_det=mysqli_fetch_array($department))
		 { ?>
			<option value="<?php echo $department_det['id']; ?>"><?php echo strtoupper($department_det['type']); ?></option>
		<?php	}	?>
		</select>
		</div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">FA</label><span style="color:red;">*</span></div>
			<div class="col-12 col-md-9">
				<input type="text" id="fa" name="fa" value="<?php echo $stock_in['fa_serial_no']; ?>" placeholder="Enter FA SERIAL NUMBER" class="form-control" autocomplete="off" required>
			</div>
	</div>	
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">DEPRECIATION VALUE</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9"><input type="number" id="dep_value" name="dep_value" class="form-control" autocomplete="off" Placeholder="DEPRECIATION PERCENTAGES"></div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">DEPRECIATION AMOUNT</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9"><input type="number" id="dep_amount" name="dep_amount" class="form-control" autocomplete="off" Placeholder="DEPRECIATION AMOUNT"></div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">Remarks</label><span style="color:red;">*</span></div>
			<div class="col-12 col-md-9">
				<input type="textarea" id="remarks" name="remarks" placeholder="Enter REMARKS" class="form-control" autocomplete="off" required>
			</div>
	</div>
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">AMC/INS.NO Date</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9">
			<input type="date" id="expiry_dates" name="expiry_dates" placeholder="CHOOSE EXPIRY DATE" class="form-control" autocomplete="off">
		</div>
	</div>
			
	<div id="conf">
		<table id="upload" class="table table-striped" style="text-transform:upper;" >
			<thead>
				<tr>
					<th>Category</th>
					<th>Category Description</th>
					<th>Item NO.</th>
					<th>Value</th>
					<th>Amount</th>
				</tr>
			</thead>
		<?php $categ_det=mysqli_query($con,"SELECT sit.transaction_id as trans_id,sit.value as value,sit.amount as amount,sit.transaction_id,sit.quantity as quantity,sit.category as cat_name,sit.category_description as category_description FROM stock_item_detail sit where flag=1 and transaction_id='$sid'");
			while($cate_peu=mysqli_fetch_array($categ_det))
		{ ?>
		<tbody>
				<tr id="rw_1" class="row_1">
				<td>
				<input type="hidden" class="form-control" name="cat_id" value="<?php echo $cate_peu['trans_id']; ?>">
				<input  class="form-control" type="text" id="cat_name"  name="cat_name" value="<?php echo $cate_peu['cat_name']; ?>" autocomplete="off" readonly="TRUE">
				</td>
				<td>
				<input  class="form-control" type="text" id="cat_desc"  name="cat_desc" value="<?php echo $cate_peu['category_description']; ?>" autocomplete="off" readonly="TRUE">
				</td>
				</td>
				<td><input  class="form-control" type="text" id="item"  name="item" value="<?php echo $cate_peu['quantity']; ?>" autocomplete="off" readonly="TRUE"></td>
				<td><input  class="form-control" type="text" id="value"  name="value" value="<?php echo $cate_peu['value']; ?>" autocomplete="off" readonly="TRUE"></td>
				<td><input  class="form-control" type="text" id="amount"  name="amount" value="<?php echo $cate_peu['amount']; ?>" autocomplete="off" readonly="TRUE"></td>				
				</tr>
		</tbody>
			<?php  } ?>
		</table>
		</div>
	<?php }	?>	
		<div style="">
			<button type="submit" name="submit" class="btn btn-success" ><i class="fa fa-inbox"></i>Receive Stock</button>
		</div>
	</form>
	</div>
	</div>
  

    <div class="clearfix"></div>

    <footer class="site-footer">
        
    </footer>

</div><!-- /#right-panel-->
</body>
</html>

<script language="javascript">
	   $('.add_new').click(function(){
	var len=$('#upload tr').length;
	//alert(len);
	//len=len+1;



	//$('#upload').append('<tr id="rw_'+len+'" class="row_'+len+'"><td><?php $cat=mysqli_query($con,"select * from category_master where status=0");?><select  id="category_'+len+'"  class="form-control" name="category[]"><option selected disabled>Select Category</option><?php while($category=mysqli_fetch_array($cat)){ ?><option value="<?php echo $category['id']; ?>"><?php echo $category['category']; ?></option><?php } ?></select></td><td><input type="text" class="form-control" id="item_'+len+'" name="item[]"></td><td><input type="button" value="Delete" class="btn btn-danger" onclick="deleteRow(this)"/></td> </tr>');
 

	/* $('.table-striped').append('<tr class="row_'+len+'"><td>Type Filename</td><td><input type="text" id="type_name_'+len+'" name="type_name[]"></td><td><input type="file" name="userFile'+len+'" id="userFile'+len+'"></td></tr>'); */
	
	//alert("test");
	});
		
	$('.delete').click(function()

{
	$('input:checkbox:checked.chk').map(function(){
	
	var id=$(this).val();
	var rw=$('#rw_ tr').length;
	if(rw==1)
	{
		alert("You Can't Delete All the Rows");
		//alert(rs);
	}
	else
	{
		//alert(rs);
		$('.row_'+id).remove();
	}
	
	});
}); 
	
	</script>

	<script>
function deleteRow(btn) {
	  var row = btn.parentNode.parentNode;
	  row.parentNode.removeChild(row);
	}
</script>