<?php
include('../db/cn.php');
ob_start();

$orderId = $_GET["order_id"];


$t = mysqli_query($connection,"select * from log_user_sales where order_id = '$orderId'");
$r = mysqli_fetch_array($t);

ob_end_flush();
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Invoice - Fine & Fair</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body {
      font-family: Arial, sans-serif;
      font-size: 14px;
    }
    .invoice-box {
      padding: 20px;
      max-width: 1000px;
      margin: auto;
      border: 1px solid #eee;
      background: #fff;
    }
    .fw-600 { font-weight: 600; }
    .table th, .table td { vertical-align: middle; }
    @media print {
      .no-print { display: none; }
    }
  </style>
</head>
<body>
<div class="invoice-box">
  <div class="text-center mb-3">
    <h3 class="fw-bold">Fine & Fair</h3>
    <div>Einzel und Großhandel<br>Indisches Lebensmittel Geschäft<br>Balinger Str. 1, 70567, Stuttgart<br>Mobile: 015215481967 Ph. 0711 69988947</div>
  </div>
<div style="border:1px solid #000;">
  <div class="row mb-2">
    <div class="col-sm-6">
      <table class="table table-sm border">
        <tr><td>Rechnung Nr.: <strong>FF-0525-2504165</strong></td><td>Datum: <strong><?php  echo $r["date_time"];?></strong></td></tr>
        <tr><td>Liefer Datum: <strong><?php  echo $r["date_time"];?></strong></td></tr>
        <tr><td>Lieferschein Nr.: <strong>0425-0144</strong></td></tr>
      </table>
    </div>
    <div class="col-sm-6">
        <td>VAT Nr.: <strong>DE359845492</strong></td>
        <BR>
            <BR>
                <BR>
      <strong>Bank Details:</strong> 
      <div>Name des Begünstigten: <strong> Saima Jabeen</strong></div>
      <div>Name der Bank:<strong> BW-Bank</strong> </div>
      <div>BIC (SWIFT):<strong>SOLADEST</strong> </div>
      <div>IBAN: <strong> DE52 6005 0101 0405 6456 51</strong></div>
    </div>
  </div>

  <div class="mb-3">
    <strong>Kunde:</strong><br>
    GENO-Haus Stuttgart GmbH & Co. KG,<br>
    Heilbronner Str. 41,<br>
    70191 Stuttgart<br>
    Deutschland.
  </div>
</div>
<br>
  <table class="table table-bordered text-center align-middle table-sm">
    <thead class="table-dark">
      <tr>
        <th>POS</th>
      
        <th>ARTIKEL</th>
        <th>MENGE</th>
        <th>EINZEL<br>PREIS EUR</th>
        <th>MwSt.<br>%</th>
        <th>GESAMT<br>EUR</th>
      </tr>
    </thead>
    <tbody>
   
   <?php
     $sr = 1;
     $p = mysqli_query($connection,"select * from log_user_sales where order_id = '$orderId'");
     while($row = mysqli_fetch_array($p)){
   ?>
   <tr>
     <td><?php  echo $sr++ ;?></td> 
     <td><?php  echo $row["product_name"] ;?></td> 
     <td><?php  echo $row["product_quantity"] ;?></td> 
     <td><?php  echo $row["product_price"] ;?></td>
     <td><?php  echo $row["wh_percentage"].'%' ;?></td>
     <td><?php  echo $row["product_total"] ;?></td>
   </tr>
   <?php
     }
   ?>
    </tbody>
    <?php 
$s7 = mysqli_query($connection, "SELECT * FROM log_user_sales WHERE order_id = '$orderId' AND wh_percentage = '7'");
$total7 = 0;
while ($r7 = mysqli_fetch_array($s7)) {
    $total7 += $r7["net_amount"];
}
$tax7 = $total7 * 0.07;
$net7 = $total7 - $tax7;

$s19 = mysqli_query($connection, "SELECT * FROM log_user_sales WHERE order_id = '$orderId' AND wh_percentage = '19'");
$total19 = 0;
while ($r19 = mysqli_fetch_array($s19)) {
    $total19 += $r19["net_amount"];
}
$tax19 = $total19 * 0.19;
$net19 = $total19 - $tax19;
?>
    <tfoot>
      <tr>
        <td colspan="5" class="text-end"><strong>Gesamt Netto</strong></td>
        <td><strong><?php  echo $r["discount_amount"];?></strong></td>
      </tr>
      <tr>
        <td colspan="5" class="text-end">MwSt. 7%</td>
        <td><?php  echo $tax7;?></td>
      </tr>
       <tr>
        <td colspan="5" class="text-end">MwSt. 19%</td>
        <td><?php  echo $tax19 ;?></td>
      </tr>
      <tr>
        <td colspan="5" class="text-end fw-bold">Rechnungsbetrag (TOTAL AMOUNT)</td>
        <td class="fw-bold"><?php  echo $r["discount_amount"] ;?></td>
      </tr>
    </tfoot>
  </table>
  
  <br><br>
  <center>
  <a href="mainpos.php" class="btn btn-dark no-print">Back</a>
  </center>
</div>
</body>
</html>
