<?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));
            $name =                  htmlspecialchars ( $_POST['name']);
            $code =                  htmlspecialchars ( $_POST['code']);
            $description =           htmlspecialchars ( $_POST['description']);
            $uom =                   htmlspecialchars ( $_POST['uom']);
            $type =                   htmlspecialchars ( $_POST['itemtype']);
            $category =              htmlspecialchars ( $_POST['category']);
            $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 item (date,name,code,description,uom,type,category,subcategory,reorderlevel,
                                       warehouse,brand,variant,status,uid) 
                               VALUES(:date,:name,:code,:description,:uom,:type,:category,:subcategory,:rlevel,
                                       :warehouse,:brand,:variant,:status,:uid )';
            $conn->prepare($sql)->execute(['date' =>$date,'name' => $name,'code' =>$code,'description'=> $description,'uom' => $uom,
                                           'type' => $type,'category'=>$category,'subcategory'=>$subcategory,'rlevel'=>$rlevel,
                                           'warehouse' =>$warehouse,'brand'=>$brand,'variant'=>$variant,'status'=>$status,'uid'=>$uid  
                                         ]);

            header("location:asset");

        } 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-car" ></i> ADD ASSETS   </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-2"> 
                                <label > Date </label>  
                                <input type="text"   autocomplete="off" class="form-control datepicker" name="date"   required=""   > 
                            </div>                                             
                            <div class="col-sm-4"> 
                                <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-3">
                                <label > Description  </label>                          
                                <input type="text" class="form-control" name="description" required="" autocomplete="off" >
                            </div>    
                            <div class="col-sm-2"> 
                                <label > Uom </label>  
                                    <select class="form-control  js-example-basic-single "  required="" name="uom" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM aduom  ");
                                        $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 > Type </label>  
                                    <select class="form-control js-example-basic-single   "  required="" name="itemtype" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM itemgroup  ");
                                        $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 > Category </label>  
                                    <select class="form-control js-example-basic-single   "  required="" name="category" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM itemcategory ");
                                        $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 > SubCategory </label>  
                                    <select class="form-control js-example-basic-single   "  required="" name="subcategory" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM  itemcategorysub ");
                                        $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 > Reorder level    </label>                          
                                <input type="text" class="form-control" name="reorderlevel" required="" autocomplete="off" >
                            </div>  
                            
                               
                            <div class="col-sm-2"> 
                                <label > Warehouse stored  </label>  
                                    <select class="form-control js-example-basic-single  "  required="" name="warehouse" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM admbranch where type=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-2"> 
                                <label > Brand  </label>  
                                    <select class="form-control js-example-basic-single  "  required="" name="brand" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM itembrand  ");
                                        $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 > Variant Status  </label>  
                                    <select class="form-control   "  required="" name="variantstatus" style="width:100%" >                                       
                                                 <option selected value=0> NO VARIANT </option>
                                                 <option  value=1> HAS VARIANT </option>                                                
                                    </select>                                         
                            </div>
                            <div class="col-sm-3"> 
                                <label > Item Status   </label>  
                                    <select class="form-control   "  required="" name="itemstatus"  >
                                        <?php $stmt = $conn->prepare("SELECT * FROM itemstatus  ");
                                        $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 ASSET  </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>