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

if (filter_has_var(INPUT_POST, "submit")) 
    try{
            
        $type =                  htmlspecialchars ( $_POST['type']);
        $name =                  htmlspecialchars ( $_POST['name']);
        $code =                     htmlspecialchars ( $_POST['code']);
        $stock =                    htmlspecialchars ( $_POST['stockcoa']);
        $sale =                  htmlspecialchars ( $_POST['salecoa']);
        $cogs =                     htmlspecialchars ( $_POST['cogscoa']);
        $status =                     htmlspecialchars ( $_POST['status']);
                        

        $sql = 'INSERT INTO coaitem (type,name,code,stockcoa,salecoa,cogscoa,status,uid)  VALUES(:type,:name,:code,:stock,:sale,:cogs,:status,:uid )';
        $conn->prepare($sql)->execute([ 'type' =>$type,'name' => $name,'code' =>$code,'stock'=> $stock,'sale'=> $sale,
                                         'cogs' => $cogs,'status'=> $status,'uid'=>$uid  
                                        ]);

        header("location:coaitem");

        } 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 class="listheader">   <i class="fa fa-cog" ></i> Items Chart of account Setups   </h1>
            <!-- <ol class="breadcrumb"> -->
            <!-- <li><a href="#"><i class="fa fa-dashboard"></i> </a></li>
            <li><a href="#"> </a></li>
            <li class="active"> </li> -->
            <!-- <li><a href="products.php" class="btn btn-default btn-md"> <i class="fa fa-cubes"></i> View All Listed Products   </a></li> -->
            <!-- </ol> -->
        </section>


<!-- Main content -->

  <section class="content container-fluid" style="padding-bottom:0px;" > 
        <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 > Item Type </label>  
                                    <select class="form-control js-example-basic-single   "  required="" name="type" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM invgroup  ");
                                        $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-6"> 
                                <label > Name </label>  
                                    <input type="text"  name="name" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div>                                                  
                            <div class="col-md-3">
                                <label > Code  </label>                          
                                <input type="text" class="form-control" name="code" required="" autocomplete="off" >
                            </div>    
                            
                                  
                            <div class="col-sm-3"> 
                                <label > Stock Chart of account  </label>  
                                    <select class="form-control js-example-basic-single   "  required="" name="stockcoa" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM coa where cgroup=2   ");
                                        $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 > Sales/Revenue Chart of account  </label>  
                                    <select class="form-control js-example-basic-single   "  required="" name="salecoa" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM coa where type=5   ");
                                        $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 > COGS Chart of account  </label>  
                                    <select class="form-control js-example-basic-single   "  required="" name="cogscoa" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM coa where type=9   ");
                                        $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 >  Status   </label>  
                                    <select class="form-control   "  required="" name="status" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM pitemactive  ");
                                        $stmt->execute(); foreach ($stmt as $row) {?>
                                                
                                                <option value="<?php echo $row['id']; ?>"><?php
                                                    echo $row['name']; ?></option> <?php } ?>
                                    </select>                                         
                            </div>  
                           
                            <!-- <div class="col-md-3">
                                <label >Selling Price   </label>                          
                                <input type="text" class="form-control" name="cost" required="" autocomplete="off" >
                            </div> 
                                                                -->
                                                                                                          
                        </div>                           
                      
                       
                        
                        
                        <!-- submit button -->
                        <div class="form-group">                              
                            <div class="col-sm-offset-4 col-sm-10" style="padding:0.5rem;">
                                    <button type="submit"  name="submit" class="btn subbtn btn-default col-md-3">  <i class="fa fa-cubes"></i>  ADD COA ITEM  </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>