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

 //  $mycurrentpage ='sellreceipt';
     $receiptno =           $_POST['approve'];

     $rdata = $conn->query(" SELECT a.*,a.id aid,b.name bname,c.name cname,c.chairperson_phone,d.fname dfname,
                                    d.lname dlname,e.name ename,g.name gname,
                                    h.name hname,i.fname ifname ,i.lname ilname    FROM orders a
                             LEFT JOIN clients b ON a.client_id=b.id
                             LEFT JOIN groups c ON a.group_id=c.id
                             LEFT JOIN sys_user d ON a.uid=d.id
                             LEFT JOIN orderstatus e ON a.status=e.id 
                             LEFT JOIN branches g on a.branch_id=g.id
                             LEFT JOIN ordersdeliverymethod h on a.delivery_method=h.id
                             LEFT JOIN sys_user  i on a.uid=i.id
                              WHERE a.id='$receiptno' 
                          ")->fetch(); 


    $items = $conn->prepare(" SELECT a.* ,b.name bname   FROM order_products a 
                              JOIN products b ON a.product_id = b.id 
                             
                                                     where trans_id='$receiptno' ");
     $items->execute();
  
//      $t3 = $conn->query(" SELECT  itemtotal total FROM acctransactionsdetails a WHERE a.transmove=3 and transid='$receiptno'  ")->fetch();
//      $t4 = $conn->query(" SELECT  total FROM acctransactionsdetails a WHERE a.transmove=4 and transid='$receiptno'  ")->fetch();
//      $t5 = $conn->query(" SELECT  total FROM acctransactionsdetails a WHERE a.transmove=5 and transid='$receiptno'  ")->fetch();
                          

 if (filter_has_var(INPUT_POST, "submit")) 
  try{  
      
          // $rid =                 htmlspecialchars ( $_POST['rid']);
          // $raction =             htmlspecialchars ( $_POST['raction']);
          // $remarks =             htmlspecialchars ( $_POST['remarks']);
         

          //  $sql = 'INSERT INTO orderhistory(rorder,raction,remarks,uid)
          //                         VALUES  (:rorder,:raction,:remarks,:uid )';
          //  $conn->prepare($sql)->execute (['rorder'=>$rid,'raction'=>$raction,'remarks'=>$remarks,'uid'=>$uid  ]);

          //  $sql = "UPDATE orders SET status=:status   WHERE id=:id "; 
          //  $conn->prepare($sql)->execute(['status'=>$raction,'id'=>$rid  ]); 


          // header("location:apporders.php");
 
   } catch(Exception $e) { echo 'Message: ' .$e->getMessage();}
       
       
?>

<!DOCTYPE html>
<html>
<head>
<?php include_once('../inc/slink.php');   ?>  
</head>
<!-- <body   class="hold-transition skin-black  sidebar-mini" > -->

<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">
   

          <!-- Main content -->
         <div class="row">
          <div class="col-xs-1"></div>
          <div class="col-xs-10">
           <section class="invoice" style="border:solid;border-radius:5px;border-color:green;" >

               <!-- info row -->
               <div class="row invoice-info " style="background-color:whitesmoke;padding-top:0px;" >
                    

                    <div class="col-sm-4 invoice-col with-border ">               
                         <h3>
                            ORDER OVERVIEW
                         </h3>
                         Created At #       :<?php  echo $rdata["created_at"]; ?></br>
                         ORDER STATUS       :</b> <?php  echo $rdata["ename"]; ?><br>
                         TOTAL AMOUNT       :</b> <?php  echo $rdata["total_price"]; ?><br>
                         DELIVERY METHOD    :</b> <?php  echo $rdata["hname"]; ?><br>
                         CREDIT_OFFICER     :</b> <?php  echo $rdata["ifname"].' '. $rdata["ilname"] ; ?><br>
                    </div>
                    
               
                    <div class="col-sm-4 invoice-col ">
                         <h3>
                            GROUP DETAILS
                         </h3>
                         GROUP NAME               :</b> <?php  echo $rdata["cname"]; ?><br>
                         GROUP LOAN BALANCE       :</b> <?php  echo $rdata["group_loan_balance"]; ?><br>
                         GROUP ARREARS            :</b> <?php  echo $rdata["group_arrears"]; ?><br>
                         CHAIRPERSON_PHONE        :</b> <?php  echo $rdata["chairperson_phone"]; ?><br>
                         BRANCH_NAME        :</b> <?php  echo $rdata["gname"]; ?><br>
                         
                    </div>

                    <div class="col-sm-4 invoice-col ">
                         <h3>
                            CLIENT DETAILS
                         </h3>
                         CLIENT NAME              :<?php  echo $rdata["bname"]; ?></br>
                         CLIENT LOAN BALANACE     :</b> <?php  echo $rdata["client_loan_balance"]; ?><br>
                         CLIENT SYSTEM SAVINGS    :</b> <?php  echo $rdata["client_system_savings"]; ?><br>
                         LOAN TERMS               :</b> <?php  echo $rdata["loan_term"]; ?><br>
                            
                    </div>
                    <!-- <div class="col-sm-4 invoice-col with-border ">  
                         <h2 class="page-header"> <i class="fa fa-print"></i> PROFOMA </h2> 
                         
                         <a href="sales"  class="btn btn-default"><i class="fa fa-print"></i> Print </a>
                        
                    </div> -->
               
               
               </div>
               

               <!-- Table row -->
               <div class="row">
               <div class="col-xs-11 table-responsive">
                    <table class="table table-striped">
                    <thead class="bg-purple">

                    
                    <tr>
                    
                    <th>Product</th>
                    <th>Qty</th>
                    <th>Price #</th>
                    <!-- <th>Tax</th> -->
                    <th>Total</th>
                    </tr>
                    </thead>
                    <tbody>
                         <?php foreach($items as $item) 
                              { ?>
                                   <tr>
                                   
                                   <td> <?php echo $item['bname'];  ?> </td>
                                   <td> <?php echo $item['quantity'];  ?> </td>
                                   <td> <?php echo $item['price'];  ?>  </td>
                                   <!-- <td> <?php echo $item['ccode'];  ?>  </td> -->
                                   <td> <?php echo $item['total'];  ?>  </td>
                                   </tr>
                         <?php } ?>
                    
                    
                    </tbody>
                    </table>
               </div>
               <div class="col-xs-2"></div>
               <!-- /.col -->
               </div>
               <!-- /.row -->

               <div class="row">
               <div class="col-xs-12">
                    <!-- <p class="lead">TOTALS </p> -->
                    <!-- 
                    <div class="table-responsive">
                     <table class="table ">
                     <tr>
                         <td></td>
                         <td></td>
                         <td></td>
                         <td>Subtotal:</td>
                         <td> <?php // echo $t3["total"]; ?> </td>
                    </tr> 
                    <tr>
                         <td></td>
                         <td></td>
                         <td></td>
                         <td>Tax </td>
                         <td> <?php // echo $t4["total"]; ?> </td>
                    </tr> 
                    <tr>
                         <td></td>
                         <td></td>
                         <td></td>
                         <td>Total:</td>
                         <td > <?php  echo $rdata["total_price"]; ?> </td>
                    </tr>
                    </table> 
                    </div> -->
               </div>
             
               </div>
               <!-- /.row -->

               <!-- this row will not appear when printing -->
               <div class="row no-print">
                    <a href="ordersmy.php"  class="btn btn-block bg-purple "><i class="fa fa-arrow-left"></i> GO BACK TO ALL ORDERS  </a>

                <form class=" "  action="" method="post"  >  
                 <!-- <div class="col-md-12">
                    <div class="col-md-2">
                         <label> Close </label>
                        <a href="apporders"  class="btn btn-block btn-default"><i class="fa fa-arrow-left"></i> Close  </a>
                    </div>
                     <div class="col-md-6">
                         <label> REMARKS </label>
                         <input  type="hidden" name="rid" value="<?php echo $rdata["id"]; ?>" >
                         <textarea class="form-control" name="remarks" ></textarea>
                     </div>
                     <div class="col-md-2">
                         <label> ACTION </label>
                         <select class="form-control  js-example-basic-single "  required="" name="raction"  >
                              <?php $stmt = $conn->prepare(" SELECT a.id,a.name FROM orderstatus a 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-md-2">
                         <label>.</label>
                          <button type="submit"  name="submit" class="btn btn-success btn-block  ">  <i class="fa fa-save"></i>  Submit  </button>
                     </div>
                 </div> -->
                </form> 
               </div>
          </section>

    </div>
    <div class="col-xs-1"></div>
    </div>
    <!-- /.content -->

  <!-- Main content -->
  
</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>
