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



if (filter_has_var(INPUT_POST, "submit")) 
    try{


           $startdate =            htmlspecialchars (strtoupper($_POST['startdate']));
           $startdate =            date("Y-m-d", strtotime($startdate));

            $enddate =              htmlspecialchars (strtoupper($_POST['enddate']));
            $enddate =              date("Y-m-d", strtotime($enddate));

            $client =                   htmlspecialchars ( $_POST['client']);
            $hostingtype =            htmlspecialchars ( $_POST['hostingtype']);
            $guest =                  htmlspecialchars ( $_POST['guest']);

            $price        =           htmlspecialchars ( $_POST['price']);
            $paymentmode  =           htmlspecialchars ( $_POST['paymode']);
          //   $payments     =           htmlspecialchars ( $_POST['payments']);
            $amountpaid   =           htmlspecialchars ( $_POST['amountpaid']);
            $transactions  =           htmlspecialchars ( $_POST['transaction']);
            
            // $description =           htmlspecialchars ( $_POST['description']);
          //  $sales =           htmlspecialchars ( $_POST['sales']);
         //   $cogs =           htmlspecialchars ( $_POST['cogs']);

            // $sql = 'INSERT INTO itemcategory ( type,name,code,description  ) VALUES(:type,:name,:code,:desc )';
            // $conn->prepare($sql)->execute ([ 'type'=>$type,'name'=>$name,'code'=>$code, 'desc'=>$desc    ]);

            $sql = 'INSERT INTO roomsbooking ( client,hostingtype,guest,price,startdate,enddate,
                                              paymentmode,amountpaid,transactions,uid  )
                                      VALUES ( :client,:hostingtype,:guest,:price,:startdate,:enddate,
                                               :paymentmode,:amountpaid,:transactions,:uid  )';
            $conn->prepare($sql)->execute([ 'client'=>$client,'hostingtype'=>$hostingtype,'guest'=>$guest,
            'price'=>$price,'startdate'=>$startdate,'enddate'=>$enddate,'paymentmode'=>$paymentmode,
            'amountpaid'=>$amountpaid,'transactions'=>$transactions,'uid'=>$uid
            
             ]);


            header("location:booking.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" style="padding-bottom:0px;">
            <p class="listheader" > <i class="fa fa-plus-circle" ></i>  New booking  </p>
                
         
        </section>


<!-- Main content -->

  <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 add_form "  action="" method="post"  >
                        <div class="">    
                                   
                               <div class="col-sm-3"> 
                                <label > Select a visitor  </label>  
                                    <select class="form-control  js-example-basic-single "  required="" name="client" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM clients  ");
                                        $stmt->execute(); foreach ($stmt as $row) {?>
                                                <option></option>
                                                <option value="<?php echo $row['id']; ?>"><?php
                                                    echo $row['fname'].' '.$row['mname'].''.$row['lname']; ?></option> <?php } ?>
                                    </select>                                         
                               </div>

                               <div class="col-sm-3"> 
                                <label > Select a booking type  </label>  
                                    <select class="form-control  js-example-basic-single "  required="" name="hostingtype" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM rooms  ");
                                        $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 > Select number of guest  </label>  
                                    <select class="form-control  js-example-basic-single "  required="" name="guest" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM roomsrate  ");
                                        $stmt->execute(); foreach ($stmt as $row) {?>
                                                <option></option>
                                                <option value="<?php echo $row['id']; ?>"><?php
                                                    echo $row['capacity']; ?></option> <?php } ?>
                                    </select>                                         
                               </div>

                               <div class="col-sm-3"> 
                                 <label> Payments  </label>  
                                 <input type="" class="form-control" name="price">                                    
                               </div>

                               <div class="col-sm-3">
                                   <label> Start date  </label>
                                   <input type="text"   autocomplete="off" class="form-control datepicker" name="startdate"   required=""   >
                               </div>
                               <div class="col-sm-3">
                                   <label> End date  </label>
                                   <input type="text"   autocomplete="off" class="form-control datepicker" name="enddate"   required=""   >
                               </div>

                               <div class="col-sm-3"> 
                                 <label> Payment option </label>  
                                   <select class="form-control  js-example-basic-single "  required="" name="paymode" style="width:100%" >
                                        <?php $stmt = $conn->prepare("SELECT * FROM paymentsmode  ");
                                        $stmt->execute(); foreach ($stmt as $row) {?>
                                                <option></option>
                                                <option value="<?php echo $row['id']; ?>"><?php
                                                    echo $row['name'].' '.$row['account']; ?></option> <?php } ?>
                                   </select>                                         
                               </div>

                               <div class="col-sm-3">
                                   <label> Amount Paid  </label>
                                   <input type="text"   autocomplete="off" class="form-control " name="amountpaid"   required=""   >
                               </div>
                               
                               <div class="col-sm-12">
                                   <label> Transaction Code  </label>
                                   <textarea type="text" class="form-control" name="transaction" ></textarea>
                                   <!-- <input type="text"   autocomplete="off" class="form-control " name="date"   required=""   > -->
                               </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 btn-success col-md-3 subbtn ">  <i class="fa fa-plus"></i> Add new booking  </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>