<?php 
    include("../connection.php");
    include("../user.php");
    $cur_date=date('Y-m-d H:i:s');
    $user=$_SESSION['user'];
    $id=$_REQUEST['id'];
    $editcat=mysqli_fetch_array(mysqli_query($con,"select  * from category_master cm where cm.id='$id'"));	
?>
<!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">
    <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> -->
	<style>
	input,
	textarea
	{
	    text-transform:uppercase;	
	}
	</style>
</head>
<body>
	<div class="col-lg-8">
	    <div class="card">
		    <div class="card-header">
		        <strong>Edit Stock</strong>
		        <a href="category_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="category_update.php">
	                <div class="row form-group">
                        <div class="col col-md-3">
                            <label for="text-input" class="form-control-label">Stock ID</label>
                            
                        </div>
                        <div class="col-12 col-md-9">
                            <input type="text" id="category_id" name="category_id" placeholder="Enter Stock ID" class="form-control" value="<?php echo $editcat['category_id'];?>" autocomplete="off" required>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col col-md-3">
                            <label for="measurement-type" class="form-control-label">Department</label>
                        </div>
                        <div class="col-12 col-md-9">
                            <select id="dept" name="dept" class="form-control select-search" required>
                                <option value="">Select Department</option>
                                <?php
            					$brn = mysqli_query($con, "SELECT id,type FROM type_master where  status='0'");
            					while ($brc = mysqli_fetch_array($brn)) {
            					?>
        						<option value="<?php echo $brc['id']; ?>" <?php echo ($editcat['department'] == $brc['id']) ? 'selected' : ''; ?>><?php echo strtoupper($brc['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">Stock Name</label><span style="color:red;">*</span></div>
		                <div class="col-12 col-md-9"><input type="text" id="category" name="category" placeholder="Enter Stock Name" class="form-control" value="<?php echo $editcat['category_type'];?>" autocomplete="off" required></div>
		            </div>
					 <div class="row form-group">
                        <div class="col col-md-3">
                            <label for="text-input" class="form-control-label">Stock Availability</label><span style="color:red;">*</span>
                            
                        </div>
                        <div class="col-12 col-md-9">
                            <input type="number" id="availability" name="availability" placeholder="Enter Availability" class="form-control" value="<?php echo $editcat['availability'];?>" oninput="changeQuantity(this.value)" autocomplete="off" required>
                        </div>
                    </div>
		            <div class="row form-group">
		                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Stock Brand</label></div>
		                <div class="col-12 col-md-9"><input type="text" id="cat_brand" name="cat_brand" placeholder="Enter Stock Brand" class="form-control" value="<?php echo $editcat['category_brand'];?>" autocomplete="off"></div>
		            </div>
	                <div class="row form-group">
		                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Stock Description</label></div>
		                <div class="col-12 col-md-9"><input type="text" id="cat_dec" name="cat_dec" placeholder="Enter Stock Description" class="form-control" value="<?php echo $editcat['category_description'];?>" autocomplete="off"></div>
		            </div>
		            <div class="row form-group">
                        <div class="col col-md-3">
                            <label for="measurement-type" class="form-control-label">Stock Measurement</label>
                        </div>
                        <div class="col-12 col-md-9">
                            <select id="measurement-type" name="measurement_type" class="form-control select-search">
                                <option value="">Select Measurement Type</option>
                                <?php
            					$brn = mysqli_query($con, "SELECT id,name FROM measurement_master where  status='0'");
            					while ($brc = mysqli_fetch_array($brn)) {
            					?>
        						<option value="<?php echo $brc['id']; ?>" <?php echo ($editcat['measurement'] == $brc['id']) ? 'selected' : ''; ?>><?php echo strtoupper($brc['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">Price</label>
                            
                        </div>
                        <div class="col-12 col-md-9">
                            <input type="number" id="price" name="price" placeholder="Enter Price" class="form-control" autocomplete="off" value="<?php echo $editcat['amount'];?>" oninput="changePrice(this.value)" step="0.0001">
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col col-md-3">
                            <label for="text-input" class="form-control-label">Total Amount</label>
                            
                        </div>
                        <div class="col-12 col-md-9">
                            <input type="number" id="tol_amount" name="tol_amount" value="<?php echo $editcat['total_amount'];?>" placeholder="Total Amount" class="form-control" autocomplete="off" readonly step="0.0001">
                        </div>
                    </div>
					<input type="hidden" id="id" name="id" value="<?php echo $editcat['id'];?>">
		            <div style="">
	                    <button type="submit" name="submit" class="btn btn-success" ><i class="fa fa-dot-circle-o"></i>Update</button>
		            </div>
	            </form>
	        </div>
	    </div>
        <div class="clearfix"></div>
        <footer class="site-footer"></footer>
    </div><!-- /#right-panel -->
<script>
    $(document).ready(function() {
        $('.select-search').select2({
            placeholder: "-- SELECT --",
            allowClear: true
        });
    });
    function changeQuantity(value) {
        var price = parseFloat($("#price").val()) || 0;
        var total_amount = price * value;
        $('#tol_amount').val(total_amount.toFixed(2)); 
	}
	function changePrice(price){
	    var value = parseFloat($("#availability").val()) || 0;
        var total_amount = price * value;
        $('#tol_amount').val(total_amount.toFixed(2)); 
	}
</script>
</body>
</html>


