<?php   include_once('../config/db.php');   include_once('../config/check.php');  

if (filter_has_var(INPUT_POST, "submit")) 
    try{
            
           $date =            htmlspecialchars (strtoupper($_POST['date']));
           $date =            date("Y-m-d", strtotime($date));

            $type =            htmlspecialchars ( $_POST['type']);
            $coa =            htmlspecialchars ( $_POST['coa']);
            $name =           htmlspecialchars ( $_POST['name']);
            $value =           htmlspecialchars ( $_POST['rate']);
            $status =           1 ;
            $sql = 'INSERT INTO adtaxrate (date,type,coa,name,value,r_status,uid) VALUES(:date,:type,:coa,:name,:value,:status,:uid )';
            $conn->prepare($sql)->execute(['date'=>$date,'type'=>$type,'coa'=>$coa,'name'=>$name,'value'=>$value,'status'=>$status,'uid' => $uid    ]);
            header("location:taxrate.php");

        } catch(Exception $e) { echo 'Message: ' .$e->getMessage();}

?>

<!DOCTYPE html>
<html>
<head>
<?php include_once('../inc/slink.php');   ?>  
</head>
<body <?php include_once('../inc/snav.php');  ?>
<div class="wrapper">

  <!-- Main Header -->
    <header class="main-header">

    <!-- Logo -->
       <?php include_once('../inc/sbrand.php');   ?>

    <!-- Header Navbar -->
    <?php include_once('../inc/snavbar.php');   ?>

  </header>
 
  <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">

    <!-- sidebar: style can be found in sidebar.less -->
     <?php include_once('../inc/smenu.php');   ?>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
      <section class="content-header">
          <h1>   <i class="fa fa-balance-scale"></i> Add Tax Rate  </h1>
            <ol class="breadcrumb">
            
            <li><a href="taxrates.php" >  <button class="btn btn-default btn-sm"> <i class="fa fa-arrow-left"></i> View all Tax Rates   </button> </a></li>  
            <!-- <li><a href="adcoa.php" >  <button class="btn btn-default btn-sm">  <i class="fa fa-plus"></i> Add Chart of accounts  <i class="fa fa-arrow-right"></i>  </button> </a></li>   -->
            </ol>
      </section> 


<!-- Main content -->

  <section class="content container-fluid"> 
        <div class="box box-default box-xs">
            <div class="box-body">
                <div class="row">
                    <form class="form-horizontal add_form "  action="" method="post"  >
                        <div class="">                       

                            <div class="col-sm-3"> 
                                <label >  Date Added </label>  
                                <input type="text"   class=" form-control datepicker" name="date"   required=""   > 
                            </div>   

                            <div class="col-sm-2"> 
                                <label > Tax Type  </label>  
                                  <select name="type" class="form-control">
                                     <option value=1> Input Vat</option>
                                    <option  value=2 >  Output vat </option>

                                  </select>
                                    
                                    
                            </div> 

                            <div class="col-sm-3"> 
                                <label > Select Taxrate COA  </label>  
                                    <select class="form-control  js-example-basic-single   "  required="" name="coa" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM coa  ");
                                        $stmt->execute(); foreach ($stmt as $row) {?>
                                                <option></option>
                                                <option value="<?php echo $row['id']; ?>"><?php
                                                echo $row['name']; ?></option> <?php } ?>
                                    </select>
                                   
                            </div> 
                                                                                    
                            <div class="col-md-4">
                                <label > Tax Rate Name </label>                          
                                <input type="text" class="form-control" name="name" required="" autocomplete="off" >
                            </div>                                             
                            <div class="col-md-3">
                                <label > Tax rate Value  </label>                          
                                <input type="text" class="form-control" name="rate" required="" autocomplete="off" >
                            </div>                                             
                                                                         
                        </div>                           
                   
                        
                        <!-- submit button -->
                        <div class="form-group">                              
                            <div class="col-sm-offset-4 col-sm-10" style="padding-top:0.5rem;">
                                    <button type="submit"  name="submit" class="btn btn-success  subbtn  col-md-3">  <i class="fa fa-dollar"></i>  Add Tax Rate  </button> </div>
                        </div> 
                    </form>               
                </div>
            </div>
        </div>
                                
    </section>

</div>
  <!-- /.content-wrapper -->
  
  <!-- Main Footer -->
  <footer class="main-footer">
    <?php  include_once('../inc/sfooter.php'); ?>
  </footer>
  
</div>
                         
<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->
<?php include_once('../inc/slinkjs.php') ?>

</body>
</html>