<?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));

            $branch =                  htmlspecialchars ( $_POST['branch']);
            $name =                  htmlspecialchars ( $_POST['name']);
            // $code =                  htmlspecialchars ( $_POST['code']);
            $descriptions =           htmlspecialchars ( $_POST['description']);
            $uom =                   htmlspecialchars ( $_POST['uom']);
            // $type =    2 ;               htmlspecialchars ( $_POST['itemtype']);
            // $coagroup =              htmlspecialchars ( $_POST['coagroup']);
            $category_id =              htmlspecialchars ( $_POST['category']);
            $price =                 htmlspecialchars ( $_POST['price']);
            $stock =                 htmlspecialchars ( $_POST['stock']);
            $photo =                 htmlspecialchars ( $_POST['photo']);
            $status =                 htmlspecialchars ( $_POST['status']);
            // $subcategory =           htmlspecialchars ( $_POST['subcategory']);
            // $rlevel =                htmlspecialchars ( $_POST['reorderlevel']);
            // $warehouse =             htmlspecialchars ( $_POST['warehouse']);
            // $brand =                 htmlspecialchars ( $_POST['brand']);
            // $variant =               htmlspecialchars ( $_POST['variantstatus']);
           // $itemstatus =            htmlspecialchars ( $_POST['itemstatus']);
              
    
            $sql = 'INSERT INTO products(name,descriptions,category_id,price,stock) 
                               VALUES(:name,:descriptions,:category_id,:price,:stock )';
            $conn->prepare($sql)->execute(['name'=>$name,'descriptions'=>$descriptions,'category_id'=>$category_id,
                                             'price'=>$price,'stock'=>$stock   ]);

            header("location:allproduct");

        } 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-barcode" ></i> Add Products   </h1>

          <ol class="breadcrumb">          
          <li> <a href="allproduct" > <button class="btn  btn-sm btn-default " > <i class="fa fa-bars "></i> VIEW ALL PRODUCTS </button>    </a></li>
                   
        </ol>
        </section>


<!-- Main content -->

  <section class="content container-fluid" style="padding-bottom:0px;" > 
        <div class="box box-success box-xs">
            <div class="box-body">
                <div class="row">
                    <form class="form-horizontal "  action="" method="post"  >
                        <div class="">    
                                       
                            <!-- <div class="col-sm-2"> 
                                <label > Date </label>  
                                <input type="text"   autocomplete="off" class="form-control datepicker" name="date"   required=""   > 
                            </div>                                              -->
                            <div class="col-sm-8"> 
                                <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-md-4">
                                <label > Description  </label>                          
                                <input type="text" class="form-control" name="description" required="" autocomplete="off" >
                            </div>    
                                                                    
                           
                             
                            <div class="col-sm-3"> 
                                <label > Category </label>  
                                    <select class="form-control js-example-basic-single   "  required="" name="category" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM categories  ");
                                        $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-3">
                                <label >Price    </label>                          
                                <input type="text" class="form-control" name="price" required="" autocomplete="off" >
                            </div>  

                            <div class="col-md-2">
                                <label > Stock Quantity   </label>                          
                                <input type="text" class="form-control" name="stock" required="" autocomplete="off" >
                            </div> 
                             <div class="col-md-4">
                                <label > Photo    </label>                          
                                <input type="file" class="form-control" name="photo"  autocomplete="off" >
                            </div> 
                            <div class="col-sm-3"> 
                                <label > Status </label>  
                                    <select class="form-control  js-example-basic-single "  required="" name="status" style="width:100%" >
                                        <option value=1 > Active </option>
                                        <option value=2 > In Actice </option>
                                    </select>                                         
                            </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-success col-md-3">  <i class="fa fa-cubes"></i>  Add Products  </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>