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

   $storeID =  $_SESSION['storeid'] ;


if (filter_has_var(INPUT_POST, "submit")) 
try{    
      $date =            htmlspecialchars (strtoupper($_POST['date']));
      $date =            date("Y-m-d", strtotime($date));

      $type =                htmlspecialchars ( strtoupper($_POST['type']));          
      $cgroup =                htmlspecialchars ( strtoupper($_POST['customergroup']));          
      $entity =               htmlspecialchars ( strtoupper($_POST['entity']));          
      $name =                htmlspecialchars ( $_POST['name']);          
      $regno =               htmlspecialchars ( strtoupper($_POST['regno']));
      $currency =               htmlspecialchars ( strtoupper($_POST['currency']));
      $phone =               htmlspecialchars ( strtoupper($_POST['phone']));
      $email =               htmlspecialchars ( $_POST['email']);
      $pin =                 htmlspecialchars  ( strtoupper($_POST['krapin']));
      $zrb=                  htmlspecialchars  ( strtoupper($_POST['zrb']));
      $branch =              htmlspecialchars  ( $_POST['branch']);
      $website =             htmlspecialchars  ( $_POST['website']);
      $address =             htmlspecialchars ( $_POST['address']);
      $location =            htmlspecialchars ( $_POST['location']);
      $country =             htmlspecialchars ( strtoupper($_POST['country']));
                   
      $sql = 'INSERT INTO bppartner (type,pgroup,date,entity,name,regno,currency,phone,email,pin,zrb,branch,website,address,location,country,uid,storeID )  
                                 VALUES (:type,:pgroup,:date,:entity,:name,:regno,:currency,:phone,:email,:pin,:zrb,:branch,:website,:add,:loc,:country,:uid,:storeID )';
      $stmt = $conn->prepare($sql)->execute([ 'type' => $type,'pgroup' => $cgroup,'date' => $date,'entity' => $entity,  'name' => $name, 'regno' => $regno,'currency' => $currency,'phone' => $phone, 
                                              'email' => $email, 'pin' => $pin,'zrb' => $zrb,'branch'=>$branch, 'website' => $website,'add' => $address,
                                              'loc' => $location,'country' => $country, 'uid'=>$uid,'storeID'=>$storeID  ]);

                                              $inserted = $conn->lastInsertId(); 
                                              
                                              if($inserted>0)
                                                 {
                                                    $msg = true;
                                                  // $Lerror='<div class="alert alert-success alert-dismissable" style="margin-top:5px;"><i class="fa fa-key"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><b> Customer added Succefully  </b></div>';  
                                                   
                                                  }else
                                                   {
                                                     header("location:customer.php");
                                                  }
     

       
             if(isset($msg))
            {
             
                $_SESSION['message'] = "Successfully Added";
                header('Location:customer.php');
                exit(0);
            }
            else
            {
                $_SESSION['message'] = "Not Imported";
                header('Location:customer.php');
                exit(0);
            }

  
  } 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 CUSTOMER </p>
     
         <ol class="breadcrumb">
          
          <li> <a href="customers" > <button class="btn  btn-sm btn-default " > <i class="fa fa-bars "></i> VIEW ALL CUSTOMERS </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>
                         <?php
                         if(isset($_SESSION['message']))
                         { 
                         ?>

                         <div class="alert alert-success alert-dismissible">                         
                              <h4><i class="icon fa fa-check"></i> <?php echo $_SESSION['message'];  unset($_SESSION['message']);  ?>  </h4>
                                   
                         </div>

                       <?php }  ?>
                    </div>

                        <form class="form-horizontal "  action="" method="post"  >
                                <div class="">
                                                                                                        
                                            <div class="col-sm-2">
                                                <label> Partner Type   </label>
                                                <select class="form-control js-example-basic-single   "  required=""  name="type"  >
                                                  <?php $stmt = $conn->prepare("SELECT * FROM bppartnertype where id=1   ");
                                                  $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> Customer Group   </label>
                                                <select class="form-control js-example-basic-single   "  required=""  name="customergroup"  >
                                                  <?php $stmt = $conn->prepare("SELECT * FROM bppartnergroup   ");
                                                  $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> Date    </label>
                                                <input type="text" class="form-control datepicker" name="date"   autocomplete="off">
                                            </div>                  
                                            <div class="col-sm-2">
                                                <label> Entity Type   </label>
                                                <select class="form-control js-example-basic-single   "  required=""  name="entity"  >
                                                  <?php $stmt = $conn->prepare("SELECT * FROM bppartnerentity  ");
                                                  $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-4">
                                                <label> Full  Name    </label>
                                                <input type="text" class="form-control " name="name"   autocomplete="off">
                                            </div>                    

                                            <div class="col-sm-2">
                                                <label> Regno /ID number </label>
                                                <input type="text" class="form-control " name="regno"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-2">
                                                <label> Currency </label>
                                                <select class="form-control js-example-basic-single   "  required=""  name="currency"  >
                                              <?php $stmt = $conn->prepare("SELECT * FROM acccurrency where status=1  ");
                                                  $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> Phone number </label>
                                                <input type="text" class="form-control " name="phone"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-3">
                                                <label> Email Address </label>
                                                <input type="text" class="form-control " name="email"  autocomplete="off">   
                                            </div>
                                            
                                            <div class="col-sm-3">
                                                <label> PIN/Tin Number  </label>
                                                <input type="text" class="form-control " name="krapin"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-2">
                                                <label> GST/VAT Number  </label>
                                                <input type="text" class="form-control " name="zrb"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-2">
                                                <label> Branch </label>
                                             
                                                <select class="form-control js-example-basic-single   "  required=""  name="branch"  >
                                                     <option value=0> All branches  </option>
                                              <?php $stmt = $conn->prepare("SELECT * FROM admbranch where  id='$storeID'  ");
                                                  $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> Website </label>
                                                <input type="text" class="form-control " name="website"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-3">
                                                <label> Address  </label>
                                                <input type="text" class="form-control " name="address"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-3">
                                                <label> Location  </label>
                                                <input type="text" class="form-control " name="location"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-2">
                                                <label> Country </label>
                                                
                                                <select class="form-control js-example-basic-single   "  required=""  name="country"  >
                                              <?php $stmt = $conn->prepare("SELECT * FROM adcountry   ");
                                                  $stmt->execute(); foreach ($stmt as $row) {?>
                                                       <option> </option>
                                                     <option value="<?php echo $row['id']; ?>"><?php
                                                        echo $row['name']; ?></option> <?php } ?>
                                                </select>    
                                            </div>
                                        
                                </div>
                        <!-- submit button -->
                                <div class="form-group">                              
                                    <div class="col-sm-offset-4 col-sm-10" style="padding:2rem;">
                                            <button type="submit"  name="submit" class="btn btn-success col-md-3 subbtn">  <i class="fa fa-user-plus"></i>  Add Business Partner  </button> </div>
                                </div> 
                        </form>
                </div>
            </div>

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


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

</body>
</html>

<script>
  
  setInterval(function(){ $(".alert").fadeOut(); }, 1000);


</script>