<?php
     session_start();
      include 'database/shikanisha.kts.php';
        if(!($_SESSION['type'] == 'Manager' || $_SESSION['type'] == 'Cashier'|| $_SESSION['type'] == 'Waiter')){
            header("location:logout.php");
}


?>

							
<!DOCTYPE html>
<html lang="en">

<head>
  <style>
    
        body {
            margin: 0;
            padding: 0;
            font-family: 'PT Sans', sans-serif;
        }

        @page {
            size: 2.5in 11in;
            margin-top: 0cm;
            margin-left: 0cm;
            margin-right: 0cm;
        }

        table {
            width: 100%;
        }

        tr {
            width: 100%;

        }

        h1 {
            text-align: center;
            vertical-align: middle;
        }

        #logo {
            width: 60%;
            text-align: center;
            -webkit-align-content: center;
            align-content: center;
            padding: 5px;
            margin: 2px;
            display: block;
            margin: 0 auto;
        }

        header {
            width: 100%;
            text-align: center;
            -webkit-align-content: center;
            align-content: center;
            vertical-align: middle;
        }

        .items thead {
            text-align: center;
        }

        .center-align {
            text-align: center;
        }

        .bill-details td {
            font-size: 12px;
        }

        .receipt {
            font-size: medium;
        }

        .items .heading {
            font-size: 12.5px;
            text-transform: uppercase;
            border-top:1px solid black;
            margin-bottom: 4px;
            border-bottom: 1px solid black;
            vertical-align: middle;
        }

        .items thead tr th:first-child,
        .items tbody tr td:first-child {
            width: 47%;
            min-width: 47%;
            max-width: 47%;
            word-break: ;
            text-align: left;
        }

        .items td {
            font-size: 12px;
            text-align: right;
            vertical-align: bottom;
        }

        .price::before {
             content: "\Ksh:";
            font-family: Arial;
            text-align: right;
        }

        .sum-up {
            text-align: right !important;
        }
        .total {
            font-size: 13px;
            border-top:1px dashed black !important;
            border-bottom:1px dashed black !important;
        }
        .total.text, .total.price {
            text-align: right;
        }
        .total.price::before {
            content: "Ksh:"; 
        }
        .line {
            border-top:1px solid black !important;
        }
        .heading.rate {
            width: 20%;
        }
        .heading.amount {
            width: 25%;
        }
        .heading.qty {
            width: 5%
        }
        p {
            padding: 1px;
            margin: 0;
        }
        section, footer {
            font-size: 10px;
        }
    
    
    
    </style>
   </head>

 <div id="div_print">
<body >
    <header>
        <div id="logo" class="media" data-src="logo.png" src="./logo.png"></div>

    </header>
   
   
    <p class="center-align">MACHAKOS COTTAGE INN</p>
    <p class="center-align">Your Dinner Of Choice!</p>
    <table class="bill-details">
        <tbody>
            <tr>
                <td><span>Tel:0722891657</span></td>
              <td><span>Till:193362</span></td>
		
            </tr>
           
            <tr>
                <th class="center-align" colspan="2"><span class="receipt">Customer Receipt</span></th>
            </tr>
             <tr>
                 <td><span>Receipt ID:#<?php
$letters = range('A', 'Z');
shuffle($letters);
$random_string = implode(array_slice($letters, 0, 6));
echo $random_string;
?>
</span></td>
            </tr>
        </tbody>
    </table>
   
    
    <table class="items">
        <thead>
            <tr>
                <th class="heading name">Item</th>
                <th class="heading qty">Price</th>
                <th class="heading rate">Qty</th>
                <th class="heading amount">Subtotal</th>
            </tr>
        </thead>
       
        <tbody>
           <?php
                            
 if (!empty($_SESSION['cart'])){
                                   
                                   foreach($_SESSION['cart'] as $key =>  $value){
                                       $quantity= $value['qty'];
                                       $productid= $value['id'];
                               
                                       ?>
                                         
            <tr>
                <td class=""><p><?php echo $value['name'];?></p></td>
                <td class="price"><?php echo number_format($value['price']);?></td>
                <td ><?php echo $value['qty'];?></td>
                <td class="price"><?php echo number_format($value['price'] * $value['qty']);}?></td>
            </tr>
            <?php
                                  
                                     $total=0;
                                       foreach($_SESSION['cart'] as $value){
                                     $total +=  $value['qty'] * $value['price'];   
                                       
                                       }}
                                     
     ?>
            <tr>
                <td colspan="3" class="sum-up line">Total:</td>
                <td class="line price"> <strong><?php echo  $_SESSION['total'];?></strong></td>
            </tr>
             <?php
                            
 if (!empty($_SESSION['transaction'])){
                                   
                                   foreach($_SESSION['transaction'] as $key =>  $value){
                               
                                $balance=0;
                                $balance= $total - $value['amount_paid'];
                                $phone=  $value['phone'];
                            ?>
            <tr>
                <td colspan="3" class="sum-up">Paid:</td>
                <td class="price"> <strong><?php echo  $value['amount_paid'];}}?></strong></td>
            </tr>
           
            
        </tbody>
    </table>
    <section>
      
     
       <?php
                
                //  include_once('database/shikanisha.kts.php');
                        
      //            $sql = "SELECT customer_name,customers.phone_number, (coalesce(x.amount, 0) + coalesce(x.total, 0))balances from(select phone_number, sum(total) total, -sum(amount_paid)amount from customer_sales where customer_sales.phone_number=$phone)x inner join customers on x.phone_number=customers.phone_number ";
                                      
        //          $result=mysqli_query($conn,$sql);
                   
          //           while($row=mysqli_fetch_assoc($result))
            //          {
                       
	?> 
      -->
       <p>
          
           ACC Balance: <span><?php //echo $row['balances']; }
           ?></span>
        </p>  
        <p style="text-align:center">
          
           Served by : <span><?php echo $_SESSION['user'];?></span>
        </p>
        <p style="text-align:center">
            THANK YOU, WELCOME AGAIN! <?php
date_default_timezone_set('Africa/Nairobi');
$current_datetime = date('Y-m-d H:i:s');
echo $current_datetime;
?>

        </p>
	
    </section>
    <footer style="text-align:center">
        <p>Goods once sold are not returnable</p>
        <p>developed by 0715585188</p>
    </footer>
   
</body>
   </div>
   
   
    <button type="submit" onclick="printdiv('div_print');window.location.href='database/endbill.kts.php'" value="print" name="close" >PRINT</button>
    
     <script type="text/javascript">
        function printdiv(printpage) {
            var headstr ="<html><head><title>Machakos Cottage Inn</title><head><body>";
            var footstr="</body>";
            var newstr=document.all.item(printpage).innerHTML;
            var oldstr=document.body.innerHTML;
            document.body.innerHTML = headstr + newstr + footstr;
            window.print();
           
           
            return false;
        }
    </script>
</html>