<?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 (strtoupper($_POST['account']));
      $group =              htmlspecialchars (strtoupper($_POST['group']));
      $subgroup =              htmlspecialchars (strtoupper($_POST['subgroup']));
      $name =               htmlspecialchars (strtoupper($_POST['name']));
      $description =        htmlspecialchars ( strtoupper($_POST['description']));

      $sql = 'INSERT INTO coa( date,type,cgroup,subgroup,name,description) VALUES(:date,:type,:group,:subgroup,:name,:desc )';
      $conn->prepare($sql)->execute (['date'=> $date,'type'=>$type,'group'=>$group,'subgroup'=>$subgroup,'name'=>$name,'desc' =>$description]);

      header("location:coa.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"  >
         <p class="listheader" > <i class="fa fa-file-o" ></i> ADD CHART OF ACCOUNTS  </p>
         
            <ol class="breadcrumb">
            
            <li> <a href="coas" > <button class="btn  btn-sm btn-default " > <i class="fa fa-bars "></i> VIEW ALL COA </button>    </a></li>
                    
            </ol>
        </section>


    <section class="content container-fluid" style="padding-top:0px;" >           
        <div class="box box-default box-xs">
            <div class="box-body">
            
                <div class="row">
                    <form class="form-horizontal"  action="" method="post" >
                        <div class="col-md-12 ">
                           
                            <div class="col-sm-2">
                                <label>  Date  </label>
                                <input type="text" class="form-control datepicker " name="date"   autocomplete="off">
                            </div>  

                            <div class="col-sm-3">
                                <label>  Select Coa Type   </label>                               
                                <select class="form-control  js-example-basic-single   "  required="" name="account" style="width:100%" >
                                    <?php $stmt = $conn->prepare("SELECT * FROM coa_accounts  ");
                                    $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-sm-2">
                                <label>  Select Coa Group   </label>                               
                                <select class="form-control  js-example-basic-single   "  required="" name="group" style="width:100%" >
                                    <?php $stmt = $conn->prepare("SELECT * FROM coa_group  ");
                                    $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-sm-2">
                                <label>  Select Subgroup   </label>                               
                                <select class="form-control  js-example-basic-single   "  required="" name="subgroup" style="width:100%" >
                                    <?php $stmt = $conn->prepare("SELECT * FROM coa_group_sub  ");
                                    $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-sm-3">
                                <label>  Chart of account  name    </label>
                                <input type="text" class="form-control " name="name"   autocomplete="off">
                            </div>  
                            <div class="col-sm-12">
                                 <label>  Description  </label>
                                <input type="text" class="form-control " name="description"   autocomplete="off">
                            </div>  
                     
                          
                     
                        </div>                         

                        <div class="col-md-12">
                           <div class="form-group">                              
                            <div class="col-sm-offset-4 col-sm-10" style="padding-top:0.4rem;">
                                    <button type="submit"  name="submit" class="btn btn-default col-md-3 subbtn">  <i class="fa fa-plus"></i>  Add Coa </button> </div>
                            </div> 
                        </div>              
                     
                    </form>
                </div>
            </div>
        </div>
                                
    </section>
</div>



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


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


</body>



</html>