<?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'];
    $location=$_SESSION['location'];
    $branch=$_SESSION['division_name'];
	$stock_verify=mysqli_query($con,"select max(transaction_id) AS transaction_id from stock_transfer 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= (int)$transaction_ids + 1;
	}
?>
<!doctype html>
<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">
   	<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 Transfer</strong>
	            <a href="stock_transfer_master.php"><button class="btn btn-primary" style="width:50px;margin-left:400px;"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="stocktransfer_submit.php">
		            <input type="hidden" id="transaction_id" name="transaction_id" value="<?php echo $transaction_inc_id; ?>">
	                <?php if($ho_access=="yes")	{ //Admin login	?>  
	                <div class="row form-group">
		                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Location</label><span style="color:red;">*</span></div>
		                <div class="col-12 col-md-9">
			                <select id="from_location" name="from_location" placeholder="select location" class="form-control select-search" autocomplete="off" required>
				                <option value="" selected disabled>Select Location</option>
				                <?php	$brn=mysqli_query($con,"SELECT * FROM location_master where  status='0' order by id asc");
					            while($brc=mysqli_fetch_array($brn))
					            { ?>
					            <option value="<?php echo $brc['id']; ?>"><?php echo strtoupper($brc['location']); ?></option>
					            <?php }	?>
			                </select>
		                </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">
				            <select id="fdivision" name="fdivision" placeholder="select division" class="form-control select-search"autocomplete="off" required>
					            <option value="" selected disabled>Select division</option>
        						<?php $brn1=mysqli_query($con,"SELECT * FROM branch_master where status='0' order by id asc");
        						while($brc1=mysqli_fetch_array($brn1))
        						{ 	?>
							    <option value="<?php echo $brc1['branch_name']; ?>"><?php echo strtoupper($brc1['branch_name']); ?></option>
								<?php }	?>
				            </select>
			            </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">
            				<select id="division" name="division" placeholder="select division" class="form-control select-search"autocomplete="off" required>
            					<option value="" selected disabled>Select division</option>
            						<?php $brn1=mysqli_query($con,"SELECT * FROM branch_master where status='0' order by id asc");
            						while($brc1=mysqli_fetch_array($brn1))
            							{ 	?>
								 <option value="<?php echo $brc1['branch_name']; ?>"><?php echo strtoupper($brc1['branch_name']); ?></option>
									<?php }	?>
				            </select>
            			</div>
            		</div>
            		<div class="row form-group">
            			<div class="col col-md-3"><label for="text-input" class=" form-control-label">Category</label><span style="color:red;">*</span></div>
            			<div class="col-12 col-md-9">
            				<select name="item_search" id="item_search" placeholder="select Item" class="form-control select-search" autocomplete="off" required>
            					<option value="" selected disabled>Select Item</option>
            					<?php  $ctg=mysqli_query($con,"SELECT id,category_type,category_description FROM category_master where  status='0' order by id");
            						while($ctgr=mysqli_fetch_array($ctg)) { ?>
            							<option value="<?php echo $ctgr['id']; ?>"><?php echo strtoupper($ctgr['category_type']."-".$ctgr['category_description']); ?></option>
            						 <?php  } ?>
            				</select>
            			</div>
            		</div>
		            <div id="replaces_div">
		            </div>
	    	        <div class="row form-group">
			            <div class="col col-md-3"><label for="text-input" class="form-control-label">Quantity</label><span style="color:red;">*</span></div>
			            <div class="col-12 col-md-9"><input type="number" name="quantity" id="quantity" onchange="yes_quant(this.value)" placeholder="Enter Quantity" 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">Fa Serial No.</label></div>
			            <div class="col-12 col-md-9"><input type="text" name="fa_serial_no" id="fa_serial_no" placeholder="Enter Fa Serial Number" 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">Remarks</label></div>
            			<div class="col-12 col-md-9"><input type="text" id="remarks" name="remarks" placeholder="Enter Remarks" class="form-control"  autocomplete="off" required></div>
            		</div>
	                <?php	}  else {	//User login branchs?>
	                <input type="hidden" name="from_location" id="from_location" value="<?php echo $location; ?>">
            		<div class="row form-group">
            			<div class="col col-md-3"><label for="text-input" class=" form-control-label">Location</label><span style="color:red;">*</span></div>
            			<div class="col-12 col-md-9">
            				<select id="to_location" name="to_location" placeholder="select location" class="form-control select-search"autocomplete="off" required>
            					<option value="" selected disabled>Select Location</option>
        						<?php $brn=mysqli_query($con,"SELECT * FROM location_master where status='0' order by id asc");
        						while($brc=mysqli_fetch_array($brn))
        							{ 	?>
							    <option value="<?php echo $brc['id']; ?>"><?php echo strtoupper($brc['location']); ?></option>
									<?php }	?>
				            </select>
			            </div>
		            </div>
            		<div class="row form-group">
            			<div class="col col-md-3"><label for="text-input" class=" form-control-label">Division</label><span style="color:red;">*</span></div>
            			<div class="col-12 col-md-9">
            				<select id="division" name="division" placeholder="select division" class="form-control select-search"autocomplete="off" required>
            					<option value="" selected disabled>Select division</option>
            						<?php $brn1=mysqli_query($con,"SELECT * FROM branch_master where status='0' and branch_name!='$branch' order by id asc");
            						while($brc1=mysqli_fetch_array($brn1))
            							{ 	?>
            								  <option value="<?php echo $brc1['branch_name']; ?>"><?php echo strtoupper($brc1['branch_name']); ?></option>
									<?php }	?>
            				</select>
            			</div>
	                </div>
            		<div class="row form-group">
            			<div class="col col-md-3"><label for="text-input" class=" form-control-label">Category</label><span style="color:red;">*</span></div>
            			<div class="col-12 col-md-9">
            				<select name="item_search" id="item_search" placeholder="select Item" class="form-control select-search" autocomplete="off" required>
            					<option value="" selected disabled>Select Item</option>
            					<?php  $ctg=mysqli_query($con,"SELECT id,category_type,category_description FROM category_master where  status='0' order by id");
            						while($ctgr=mysqli_fetch_array($ctg)) { ?>
            							<option value="<?php echo $ctgr['id']; ?>"><?php echo strtoupper($ctgr['category_type']."-".$ctgr['category_description']); ?></option>
            						 <?php  } ?>
            				</select>
            			</div>
            		</div>
            		<div class="row form-group">
            			<div class="col col-md-3"><label for="text-input" class="form-control-label">Quantity</label><span style="color:red;">*</span></div>
            			<div class="col-12 col-md-9"><input type="number" name="quantity" id="quantity" onchange="quan(this.value)" placeholder="Enter Quantity" 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">Fa Serial No.</label>></div>
			            <div class="col-12 col-md-9"><input type="text" name="fa_serial_no" id="fa_serial_no" placeholder="Enter Fa Serial Number" 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">Remarks</label></div>
            			<div class="col-12 col-md-9"><input type="text" id="remarks" name="remarks" placeholder="Enter Remarks" class="form-control"  autocomplete="off" required></div>
            		</div>
            	    <?php }	?>	
            		<div style="">
            			<button type="submit" name="submit" class="btn btn-success" ><i class="fa fa-retweet"></i>Stock Transfer</button>
            		</div>
	            </form>
	        </div>
	    </div>
        <div class="clearfix"></div>
        <footer class="site-footer"></footer>
    </div><!-- /#right-panel-->
</body>
</html>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

