<?php
     session_start();
      include 'database/shikanisha.kts.php';
        if(!($_SESSION['type'] == 'Manager' || $_SESSION['type'] == 'Cashier' || $_SESSION['type'] == 'Receptionist')){
            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"><span id="shopname"></span></p>
    <p class="center-align"> <span id="location"></span></p>
    <p class="center-align"><span id="address"></span></p>
 
    <table class="bill-details">
        <tbody>
            <tr>
                <td><span id="street"></span></td>
              <td><span id="contact1"></span></td>
		
            </tr>
            <tr>
                <td><span>#</span></td>
              <td><span id="pin"></span></td>
		
            </tr>
           
           
            <tr>
                <th class="center-align" colspan="2"><span class="receipt">Accomodation Details</span></th>
            </tr>
             <tr>
                 <th class="center-align" colspan="2"><span class="receipt">Booking ID:#<?php if (!empty($_SESSION['transactionc'])){
      foreach($_SESSION['transactionc'] as $key =>  $value){
                          ?><strong><?php echo  $value['book'];}}?></strong>        
           
</span></th>
        </tbody>
    </table>
    
    <table class="items">
        <thead>
            <tr>
                <th class="heading name">Room_Name</th>
                <th class="heading qty">Price</th>
                <th class="heading rate">Days</th>
                <th class="heading amount">Subtotal</th>
            </tr>
        </thead>
       
        <tbody>
           <?php
                            
 if (!empty($_SESSION['cartc'])){
                                   
                                   foreach($_SESSION['cartc'] as $key =>  $value){
                                       $quantity= $value['qty'];
                               
                                       ?>
                                         
            <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['cartc'] as $value){
                                     $total +=  $value['qty'] * $value['price'];   
                                       
                                       }}
                                     
     ?>
              <?php
                            
 if (!empty($_SESSION['transactionc'])){
      foreach($_SESSION['transactionc'] as $key =>  $value){
                                   ?>
            <tr>
                <td colspan="3" class="sum-up line">Total:</td>
                <td class="line price"> <strong><?php echo  $value['total'];?></strong></td>
            </tr>
          
            <tr>
                <td colspan="3" class="sum-up">Balance:</td>
                <td class="price"> <strong><?php echo  $value['balance'];}}?></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 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></p>
        <p>Developed by 0715585188</p>
    </footer>
   
</body>
   </div>
   
   
     <script>
    function fetchBusinessDetails() {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', './database/fetch_business.kts.php', true);
        xhr.onload = function() {
            if (this.status === 200) {
                var data = JSON.parse(this.responseText);

                // Check if no error
                if (!data.error) {
                    // Update the span elements with the fetched data
                    document.getElementById('shopname').innerText = data.shop_name || '';
                    document.getElementById('location').innerText = data.location || '';
                    document.getElementById('quote').innerText = data.quote || '';
                    document.getElementById('street').innerText = data.street || '';
                    document.getElementById('address').innerText = data.address || '';
                    document.getElementById('pin').innerText = data.pin || '';
                    document.getElementById('contact1').innerText = data.contact1 || '';
                    document.getElementById('contact2').innerText = data.contact2 || ''; // This should populate contact2
                } else {
                    console.error("Error: " + data.error);
                }
            } else {
                console.error("Failed to fetch data");
            }
        };
        xhr.send();
    }

  
    window.onload = function() {
        fetchBusinessDetails();
    };
</script>
    <button type="submit" onclick="printdiv('div_print');window.location.href='database/accobill.kts.php'" value="print" name="close" >PRINT</button>
    
     <script type="text/javascript">
        function printdiv(printpage) {
            var headstr ="<html><head><title>Kakashi Tech Solutions</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>