<?php session_start();?>
<?php include'includes/header.php'; ?>
<?php include'includes/sidebar.php';?>
<?php include'includes/functions.php';?>
<?php include'includes/navbar.php'; ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<style>

.invoice-container {
  max-width: 500px;
  margin: auto;
  background: #fff;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.invoice-header {
  text-align: center;
  border-bottom: 2px solid #eee;
  margin-bottom: 20px;
}

.invoice-header h2 {
  margin: 0;
  color: #333;
}

.invoice-details {
  margin-top: 20px;
}

.invoice-details p {
  margin: 5px 0;
  font-size: 16px;
}

.summary {
  background-color: #f1f1f1;
  padding: 15px;
  margin-top: 20px;
  border-radius: 8px;
}

.summary h3 {
  margin-bottom: 10px;
  color: #444;
}

.summary p {
  margin: 5px 0;
}

.btns {
  margin-top: 30px;
  text-align: center;
}

.btns button {
  margin: 10px;
  padding: 10px 20px;
  font-size: 15px;
  cursor: pointer;
  border: none;
  border-radius: 5px;
  background-color: #1976d2;
  color: white;
  transition: background 0.3s;
}

.btns button:hover {
  background-color: #004ba0;
}

@media print {
  body * {
    visibility: hidden;
    font-size: 11px!important;
    background: #fff!important;
  }

  .invoice-container {
      /*box-shadow: none !important;
      border: none !important;
      max-width: 100% !important;*/
    }
    .invoice-container h4, .invoice-container p, .invoice-container span {
      font-size: 11px !important;
      line-height: 1.2 !important;
    }

  #invoiceArea, #invoiceArea * {
    visibility: visible;
  }

  #invoiceArea {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }

  .btns {
    display: none !important;
  }

  .logo-area img {
    width: 50px !important;
    height: auto !important;
    object-fit: contain !important;
    display: block !important;
    margin: 0 !important;
  }

  .icon-bg{
    
    width: 55px;
    height: 55px;
    background: #E3F3EE!important;

  }
  .icon-bg i{
    font-size: 28px!important;
  }
}

.invoice-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo-area img{
  max-width: 50px;
    height: auto;
    /*border: 2px solid #ccc;*/
    border-radius: 5px;
    display: block;
}
.invoice-title{
  text-align: right;
}
.invoice-title h4{
  font-size: 18px;
  font-weight: bold;
  font-family: sans-serif;
  color: #261756;
  margin: 0;
}
.invoice-title small {
  font-size: 12px;
  color: #777;
}
.invoice-title span{
  font-size: 18px;
  font-weight: bold;
  font-family: sans-serif;
}
.invoice-cust{
  padding-top: 20px;
}
.invoice-cust h4{
  font-size: 17px;
}
.invoice-cust span{
  font-size: 16px;
  font-weight: bold;
}
.total h4{
  text-align: right;
  font-size: 14px;
  font-weight: bold;
}
.summary h4{
  font-weight: 18px;
  font-size: 18px;
}
.summary span{
  font-size: 15px;
  font-family: sans-serif;
  font-weight: bold;
}
.middle-icon{
  width: 100%;
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap:10px;
}
.icon-bg{
  /*padding: 15px;*/
  width: 55px;
  height: 55px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 50%;
  background: #E3F3EE;

}
.icon-bg i{
  font-size: 28px;
}
.middle-icon h4{
  font-size: 18px;
  font-weight: bold;
}

.reciept-block{
  width: 100%;
}
.reciept-block p {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin: 4px 0;
}
.span-left{
  font-size: 12px;
  color: #888;
}
.span-right{
  font-weight: bold;
  font-size: 12px
}

.items-list {
  margin-top: 15px;
}
.items-list h5 {
  font-size: 14px;
  color: #555;
  margin-bottom: 5px;
}
.items-list ul {
  padding-left: 20px;
  margin: 0;
  list-style: disc;
  font-size: 13px;
}
.items-list li {
  margin: 2px 0;
  word-wrap: break-word;
}

</style>
</head>
<body>
  <?php
  if (isset($_SESSION['customer'])) {
    $customer = $_SESSION['customer'];
  }
 
  $product_name = "Bicycle";
  $created = date('Y-m-d H:i:s');
  ?>
  <div class="invoice-container" id="invoiceArea">
    <div class="invoice-top">
      <div class="logo-area">
        <img src="logo/goodness.jpg" alt="logo" class="logo-print">
      </div>
      <div class="invoice-title">
        <h4>DE-GOODNESS ACADEMY</h4>
        <small>Official Payment Receipt</small>
      </div>
    </div>

    <div class="middle-icon">
      <div class="icon-bg">
        <i class="fa fa-check-circle text-success"></i>
      </div>
      <h4>Payment Successful!</h4>
    </div>
    
    <hr style="border:1px dashed black">
    
    <div class="reciept-block">
      <p><span class="span-left">Name</span><span class="span-right">Taiwo Tosin Amos</span></p>
      <p><span class="span-left">Admission No</span><span class="span-right">000713</span></p>
      <p><span class="span-left">Class</span><span class="span-right">JSS3</span></p>
      <p><span class="span-left">Session</span><span class="span-right">2025/2026</span></p>
      <p><span class="span-left">Payment Method</span><span class="span-right">Bank Transfer</span></p>
      <p><span class="span-left">Date</span><span class="span-right">27 Aug 2025</span></p>
    </div>

     <div class="items-list">
       <h5>Items Paid For</h5>
       <ul>
         <li>Tuition</li>
         <li>Uniform</li>
         <li>Sportwears</li>
         <li>Report Card</li>
         <li>Library Fee</li>
       </ul>
     </div>

    
    <hr style="border:1px dashed black">
      
    

    <div class="total">
      <h4>TOTAL AMOUNT: ₦800</h4>
    </div>

  </div>
  <div class="btns">
    <button onclick="printInvoice()">🖨️ Print Invoice</button>
    <button onclick="downloadPDF()">⬇️ Download PDF</button>
  </div>


  <script>
    function printInvoice() {   
      window.print();
      
    }
    // printInvoice();
    // setInterval(printInvoice, 10000);

    // function downloadPDF() {
    //   const element = document.getElementById('invoiceArea');
    //   html2pdf().from(element).save('invoice.pdf');
    // }

    function downloadPDF() {
      const element = document.getElementById('invoiceArea');
      const opt = {
        margin: 0.2,
        filename: 'receipt.pdf',
        image: { type: 'jpeg', quality: 0.98 },
        html2canvas: { scale: 2 },
        jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' },
        pagebreak: { mode: ['avoid-all'] }
      };
      html2pdf().set(opt).from(element).save();
    }

  </script>
<?php include'includes/footer.php';?>