<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="image/logo.png" type="image/png">
  <title>A4 Voucher</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
    }

    .voucher-container {
      width: 210mm; /* A4 paper width */
      height: 297mm; /* A4 paper height */
      background-color: #f2f2f2;
      padding: 5mm;
      box-sizing: border-box;
    }

    table {
      width: 100%;
      border-collapse: collapse;
    }

    th, td {
      padding: 10px;
      border: 1px solid #ccc;
    }

    .voucher-header {
      text-align: center;
      font-size: 24px;
      margin-bottom: 10px;
    }

    .voucher-content {
      font-size: 13px;
    }

    .voucher-footer {
      margin-top: 10px;
      text-align: right;
    }

    @media print {
      body {
        width: 210mm;
        height: 297mm;
      }
    }
  </style>
</head>
<body>
<a href="customer_payment.php"><--Back</a>
  <div class="voucher-container">
    <table>
      <tr>
        <td colspan="2" class="voucher-header">
            <img src="image/logo.png" style="width: 80px; margin-bottom: -50px;">
            <br><br>
            </img>
            
            <?php
              include 'database/database.php';
              include 'database/data.php';

              session_start();
  
              // Check if the browser ID is already stored in the session
              if (isset($_SESSION['browser_id'])) {
                  $browserId = $_SESSION['browser_id'];
              } else {
                  // Generate a new browser ID
                  $browserId = generateUniqueBrowserId();
                  // Store the browser ID in the session for future use
                  $_SESSION['browser_id'] = $browserId;
              }
              $b_id = $browserId;
  
              $sql = "Select * from ".$shop_name."";
              $result = mysqli_query($connection, $sql);
              if ($result) {
                  while ($row = mysqli_fetch_assoc($result)) {
  
                      echo "
                          <div class='title' style='margin-top:30px'><b>".$row['name']."</b></div>
                          <address style='text-align: left;font-size: 15px;'> ".$row['address']."<br> ".$row['ph_1']."-".$row['ph_2']."</address>
                      ";
                  }
                }

                $voucher_data = $_POST['voucher_no'];


                
                // Replace 'id' with the actual column name to sort by
                $sql = "SELECT * FROM ".$sell_data." where voucher = ".$voucher_data." ORDER BY id LIMIT 1"; 
                $result = mysqli_query($connection, $sql);
                
                if ($result) {
                    while ($row = mysqli_fetch_assoc($result)) {
                        echo "<div style='text-align:left; line-height:20px;'>
                            <b style='text-align: left; font-size: 15px;'> ဝယ်ယူသူအမည် - ".$row['customer']."</b><br>
                            <b style='text-align: left; font-size: 15px;'> voucher no - ".$row['voucher']."</b>
                            </div>
                        ";
                    }
                } else {
                    // Handle the error if the query fails
                    // echo "Error: " . $connection->error;
                }
              
              ?>
          
          </td>
      </tr>
      <tr>
        <td colspan="2" class="voucher-content">
            <table><br>
                <tr>
                  <th>ပစ္စည်းအမည်</th>
                  <th>အမျိုးစား</th>
                  <th>အရေအတွက်</th>
                  <th>ဈေးနှုန်း</th>
                  <th>လျော့ဈေး</th>
                  <th>စုစုပေါင်းလျော့ဈေး</th>
                  <th>ကျသင့်ငွေ</th>
                </tr>
                    <?php

                    $sql = "SELECT * FROM ".$sell_data." where voucher = ".$voucher_data.""; 
                    $result = mysqli_query($connection, $sql);
                    if ($result) {
                        while ($row = mysqli_fetch_assoc($result)) {
                            echo '  
                            <tr>  
                            <td contenteditable="true">' . ($row['product_name']) . '</td>   
                            <td contenteditable="true">' . ($row['type']) . '</td>   
                            <td contenteditable="true">' . ($row['qty']) . '</td>   
                            <td contenteditable="true">' . number_format($row['price']/$row['rate']) . '</td>
                            <td contenteditable="true">' . number_format($row['discount']/$row['rate']) . '</td>     
                            <td contenteditable="true">' . number_format(($row['discount']/$row['rate'])*$row['qty']) . '</td>   
                            <td contenteditable="true">' .number_format($row['total']/$row['rate']) . '</td>                         
                            </tr>';
                        }
                    }



                    $sql = "
                      SELECT v.total, v.discount, v.voucher_no, c.currency
                      FROM ".$voucher." v
                      INNER JOIN ".$customer." c ON v.customer_name = c.name
                      WHERE v.voucher_no = '".$voucher_data."'
                  ";

                  $result = mysqli_query($connection, $sql);
                  if ($result) {
                      while ($row = mysqli_fetch_assoc($result)) {
                        echo '  
                        <tr>  
                        <td colspan="5" style="text-align:center;">Total '.$row['currency'].'</td>       
                        <td><b>' .number_format($row['discount']) . '</b></td>   
                        <td><b>' .number_format($row['total']) . '</b></td>                           
                        </tr>';
                      }
                  }

                  $sql = "Select * FROM ".$voucher." where voucher_no = ".$voucher_data."";
                    $result = mysqli_query($connection, $sql);
                    if ($result) {
                        while ($row = mysqli_fetch_assoc($result)) {

                          echo '  
                          <tr>  
                          <td colspan=7></td>          
                          </tr>';

                          echo '  
                          <tr>  
                          <td>အမည်</td>       
                          <td>ပေါင်ချာနံပါတ်</td>       
                          <td>စုစုပေါင်း</td>       
                          <td>လျော့ဈေး</td>       
                          <td>ပေးပြီး</td>       
                          <td colspan=2>ပေးရန်ကျန်ငွေ</td>       
          
                          </tr>';


                            echo '  
                            <tr>      
                            <td><b>' .($row['customer_name']) . '</b></td>                         
                            <td><b>' .($row['voucher_no']) . '</b></td>                         
                            <td><b>' .number_format($row['total']) . '</b></td>                         
                            <td><b>' .number_format($row['discount']) . '</b></td>                         
                            <td><b>' .number_format($row['pay']) . '</b></td>                         
                            <td colspan=2><b>' .number_format($row['payable']) . '</b></td>                         
                            </tr>';
                        }
                    }
                                  
                       

      
                  ?>

            </table>
        </td>
      </tr>

      <tr>
        <?php
        $today = date("Y-m-d");
          echo'
          <td class="voucher-footer" colspan="2">Date: '.$today.'<br>
            <label>ဝယ်မှုအတွက် အထူးကျေးဇူးတင်ရှိပါသည်</label><br>
            <label>Manager Sign</label><br><br><br>
            <label>------------------</label>
        </td>
          ';
        ?>
        
        
      </tr>
    </table>
  </div>
</body>
</html>

