<?php  include "header.php"; ?>
<?php
if(isset($_POST['update'])){
    try{
         
         $statement = $pdo->prepare("UPDATE `tbl_config` SET `status`=?,`value`=? WHERE id=?");
    	 $result = $statement->execute(array($_POST['gst_status'],$_POST['value'],$_POST['ids']));
        
        if($result){    
            header("location: gst-update.php");
        } 
        else{
            echo "<script>alert('Update Error')</script>";
        }
         
    }catch(PDOException $e){
        echo "<script>alert('Update Error')</script>";
    }   
}

?>

<?php
$statement = $pdo->prepare("SELECT * FROM `tbl_config` c WHERE c.id=1");
$statement->execute();
$Datas = $statement->fetchAll(PDO::FETCH_ASSOC);
$totalData = $statement->rowCount();

?>

<div class="content-wrapper" style="background:white;">
        <div class="col-lg-12 alerts">
            <div id="custom-alerts" style="display:none;">
                <div class="alert alert-dismissable">
                    <div class="custom-msg"></div>
                </div>
            </div>
            <?php if ($error)  { ?>
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-ban"></i> Error</h4>
                <?= $error; ?>
            </div>
            <?php $error=0;} if ($warning) { ?>
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-warning"></i> warning</h4>
                <?= $warning; ?>
            </div>
            <?php  $warning=0;} if ($message) { ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?= $message; ?>
            </div>
            <?php $message=0; } ?>
        </div>
        <div class="clearfix"></div>







<section class="content">
    
    
    <div class="row" style="">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div style="list-style: none; padding-inline-start: 0px; padding: 5px 0px 5px 0px;">
                <?php include "header/sub_header.php"; ?>
             </div>
        </div>
    </div>
    
    
    
    <div class="row">
        <div class="col-xs-12">
            <div>
                <div class="box-header">
                    <h3 class="box-title"><b>Update GST (%) : </b></h3>
                </div>
                <div class="box-body">
                    
                    <div class="col-lg-12">

                        <form action=""  enctype="multipart/form-data" method="post" id="add_form" accept-charset="utf-8">
                            
                            <input type="hidden" name="ids" value="<?=$Datas[0]['id']?>"?>
                            <div class="row">
                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="control-label required" for="gst_status">GST Status</label>
                                        <select name="gst_status" class="form-control select2 " style="width:100%" id="gst_status" required="required">
                                        <option value="1" <?php if($Datas[0]['status']==1){echo "selected";}?>>ON</option>
                                        <option value="0" <?php if($Datas[0]['status']==0){echo "selected";}?>>OFF</option>
                                        </select>
                                    </div>
                                </div>
                                
                                <div class="col-sm-3"  id="gst_values" style="display: none;">
                                    <div class="form-group">
                                        <label class="control-label required" for="value">GST (%)</label>
                                        <select name="value" class="form-control select2 " style="width:100%" id="value" required="required">
                                        <option value="5" <?php if($Datas[0]['value']==5){echo "selected";}?>>5%</option>
                                        <option value="12" <?php if($Datas[0]['value']==12){echo "selected";}?>>12%</option>
                                        <option value="18" <?php if($Datas[0]['value']==18){echo "selected";}?>>18%</option>
                                        <option value="24" <?php if($Datas[0]['value']==24){echo "selected";}?>>24%</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            
                            <br>
                            
                            <div class="form-group" style="text-align:center;">
                                <input type="submit" name="update" id="update" value="Update"  class="btn btn-success" />
                            </div>
                            
                            
                        
                        </form>
                        
                        
                        
                    </div>
                         
                         
                    <br><br><br><br>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</section>


<script>
$(document).ready(function(){
    get_status();
});
$("#gst_status").change(function () {
    get_status();
});
function get_status(){
    var gst_status = $("#gst_status").val();
        
        if(gst_status==1){
            $("#gst_values").show();
        }else{
            $("#gst_values").hide();
        }
   
}
</script>




<?php include "footer.php";?>
<style>
    .seat{
        width: 55px;
        font-size: 20px;
        font-weight: 700;
        text-align: center;
    }
</style>