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

if (filter_has_var(INPUT_POST, "submit")) 
    try{
                $date_posted =             $_POST['date_posted'];
                $date_posted =             date("Y-m-d", strtotime($date_posted));
         
                $branch_id                 =     htmlspecialchars ( $_POST['branch_id']);
                $receipt_no                =     htmlspecialchars ($_POST['receiptnumber']);
                // $postedby               =     htmlspecialchars ( $_POST['postedby']);
                $posted_by_id              =     htmlspecialchars ( $_POST['postedby']);

               // $dateposted                =     htmlspecialchars ( $_POST['dateposted']);
                $group_name                =     htmlspecialchars ( $_POST['groupname']);
                $group_account_number      =     htmlspecialchars ( $_POST['groupaccountnumber']);
                $treasurer_phone_number    =     htmlspecialchars ( $_POST['treasurerphonenumber']);
                $credit_officer            =     htmlspecialchars ( $_POST['creditofficer']);
                $transaction_code          =     htmlspecialchars ( $_POST['transactioncode']);
                $receipt_amount            =     htmlspecialchars ( $_POST['receiptamount']);
                $banked_amount             =     htmlspecialchars ( $_POST['bankedamount']);
                $debit_amount              =     htmlspecialchars ( $_POST['debitamount']);
                $remarks                   =     htmlspecialchars ( $_POST['remarks']);


                     $sql = 'INSERT INTO receipt_records( receipt_no,credit_officer,group_name,group_account_number,
                                                          treasurer_phone_number,receipt_amount,banked_amount,debit_amount,
                                                          transaction_code,remarks,date_posted,posted_by_id,branch_id )
                             values(
                                              :receipt_no,:credit_officer,:group_name,:group_account_number,
                                              :treasurer_phone_number,:receipt_amount,:banked_amount,
                                              :debit_amount,:transaction_code,:remarks,:date_posted,
                                              :posted_by_id,:branch_id  )';

                     $conn->prepare($sql)->execute (['receipt_no'=>$receipt_no,'credit_officer'=>$credit_officer,
                                             'group_name'=>$group_name,'group_account_number'=>$group_account_number,
                                             'treasurer_phone_number'=>$treasurer_phone_number,'receipt_amount'=>$receipt_amount,
                                             'banked_amount'=>$banked_amount,'debit_amount'=>$debit_amount,
                                             'debit_amount'=>$debit_amount,'transaction_code'=>$transaction_code,
                                             'transaction_code'=>$transaction_code,'remarks'=>$remarks,
                                             'date_posted'=>$date_posted,'posted_by_id'=>$posted_by_id,
                                             'branch_id'=>$branch_id ]);

                     header("location:allreceipt");

        } 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 style="color:green; font-size:20px; font-weight:bold; " > <i class="fa fa-file " ></i> Create New Receipt  </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="col-sm-4"> 
                                <label > Date  </label>  
                                <input type="text"   autocomplete="off" class="form-control datepicker" name="date"   required=""   > 
                            </div>                                            -->
                            
                            <div class="col-md-3">
                              <label > SELECT BRANCH </label>
                                <select class=" js-example-basic-single " name="branch_id" required=""   style="width:100%" >
                                
                                            <?php
                                            $stmt = $conn->prepare("SELECT * FROM branches");
                                            $stmt->execute();
                                            while($data=$stmt->fetch(PDO::FETCH_ASSOC))
                                                {?>
                                    <option> </option>
                                    <option value="<?php echo $data['id']; ?>"><?php echo $data['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="col-sm-3"> 
                                <label > Receipt Number*  </label>  
                                    <input type="text"  name="receiptnumber" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div> 

                            <div class="col-sm-3"> 
                                <label> Posted By  </label>  
                                    <select class=" js-example-basic-single  " name="postedby" required=""  id="branch" style="width:100%" >
                                    
                                                <?php
                                                $stmt = $conn->prepare("SELECT * FROM user ");
                                                $stmt->execute();
                                                while($data=$stmt->fetch(PDO::FETCH_ASSOC))
                                                    {?>
                                        <option> </option>
                                        <option value="<?php echo $data['id']; ?>"><?php echo $data['name']; ?></option>
                                        <?php } ?>
                                    </select>
                                    <!-- <input type="text"  name="postedby" value="" autocomplete="off" class="form-control"   required=""   >  -->
                            </div> 
                            <div class="col-sm-3"> 
                                <label> Date Posted  </label>  
                                    <input type="date"  name="date_posted" value="" autocomplete="off" class="form-control"  > 
                            </div> 
                             
                            <div class="col-sm-3"> 
                                <label> Group Name  </label>  
                                    <input type="text"  name="groupname" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div>
                            <div class="col-sm-3"> 
                                <label> Group Account Number  </label>  
                                    <input type="text"  name="groupaccountnumber" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div>
                            
                            <div class="col-sm-3"> 
                                <label> Credit Officer  </label>  
                                    <select class=" js-example-basic-single  " name="creditofficer" required=""   style="width:100%" >
                                    
                                                <?php
                                                $stmt = $conn->prepare("SELECT * FROM user ");
                                                $stmt->execute();
                                                while($data=$stmt->fetch(PDO::FETCH_ASSOC))
                                                    {?>
                                        <option> </option>
                                        <option value="<?php echo $data['id']; ?>"><?php echo $data['name']; ?></option>
                                        <?php } ?>
                                    </select>
                                    <!-- <input type="text"  name="creditofficer" value="" autocomplete="off" class="form-control"   required=""   >  -->
                            </div>
                            <div class="col-sm-3"> 
                                <label> Treasurer Phone Number  </label>  
                                    <input type="text"  name="treasurerphonenumber" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div>
                            <div class="col-sm-3"> 
                                <label> Transaction Code*  </label>  
                                    <input type="text"  name="transactioncode" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div>
                            <div class="col-sm-3"> 
                                <label> Receipt Amount**  </label>  
                                    <input type="text"  name="receiptamount" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div>
                            <div class="col-sm-3"> 
                                <label> Banked Amount**  </label>  
                                    <input type="text"  name="bankedamount" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div>
                            <div class="col-sm-3"> 
                                <label> Deficit Amount**  </label>  
                                    <input type="text"  name="debitamount" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div>
                            <div class="col-sm-12"> 
                                <label> Remarks**  </label>  
                                    <textarea  type="text" name="remarks" class="form-control"></textarea>
                                    <!-- <input type="text"  name="activemembers" value="" autocomplete="off" class="form-control"   required=""   >  -->
                            </div>
                            <!-- <div class="col-sm-3"> 
                                <label > Code </label>  
                                    <input type="text"  name="code" value="" autocomplete="off" class="form-control"   required=""   > 
                            </div> 
                            <div class="col-sm-12"> 
                                <label > Description  </label>  
                                    <input type="text"  name="description"  autocomplete="off" class="form-control"   required=""   > 
                            </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>  Create New Receipt </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>