<!DOCTYPE html>
<html>
<head>
  <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="product_accept.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 = $_POST['voucher_no'];

               

                $voucher = $connection->real_escape_string($voucher);

                $sql = "SELECT * FROM ".$cargo."";
                $result = $connection->query($sql);
                if ($result->num_rows > 0) {
                    $row = $result->fetch_assoc(); // Fetch the row here
                    $cargo_data = $row["cargo_name"];
                
                    // Replace 'id' with the actual column name to sort by
                    $sql = "SELECT * FROM ".$cargo_data."_trans WHERE voucher = '$voucher' 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['shop_name']."</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: " . mysqli_error($connection);
                    }
                }


                
                
              
              ?>
          
          </td>
      </tr>
      <tr>

        <td colspan="2" class="voucher-content">
            <table><br>
                <tr>
                  <th>ပစ္စည်းအမည်</th>
                  <th>အမျိုးစား</th>
                  <th>အရေအတွက်</th>
                </tr>
                    <?php

                        $voucher = $connection->real_escape_string($voucher);

$sql = "SELECT * FROM ".$cargo."";
$result = $connection->query($sql);
if ($result->num_rows > 0) {
    $row = $result->fetch_assoc(); // Fetch the row here
    $cargo_data = $row["cargo_name"];

    // Properly construct the query with quotes if needed
    $sql = "SELECT * FROM ".$cargo_data."_trans WHERE voucher='$voucher'";
    $result = mysqli_query($connection, $sql);

    if ($result && mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            echo '  
            <tr>  
                <td contenteditable="true">' . htmlspecialchars($row['product_name']) . '</td>   
                <td contenteditable="true">' . htmlspecialchars($row['type']) . '</td>   
                <td contenteditable="true">' . htmlspecialchars($row['qty']) . '</td>                         
            </tr>';
        }
    } else {
        // Handle the case where no results are found
        // echo "No data found for voucher: " . htmlspecialchars($voucher);
    }
} else {
    // Handle the case where no cargo data is found
    // echo "No cargo data found for browser_id: " . htmlspecialchars($b_id);
}

                        

      
                  ?>

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

      <tr>
        <?php
        $today = date("Y-m-d");
          echo'
          <td class="voucher-footer" colspan="2">Date: '.$today.'<br>
            <label>Manager Sign</label><br><br><br>
            <label>------------------</label>
        </td>
          ';
        ?>
        
        
      </tr>
    </table>
  </div>
</body>
</html>

