<html lang="en">
   <head>
      <link rel="preconnect" href="https://fonts.googleapis.com">
      <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
      <link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&amp;display=swap" rel="stylesheet">
      <meta charset="UTF-8">
      <title>ORDER FORM</title>
      <style>
         body {
         font-family: Arial, sans-serif;
         margin: 15px;
         color: #333;
         font-size: 10px;
         }
         .container {
         width: 100%;
         max-width: 1200px; /* You can change this to 960px, 1140px, etc. */
         margin-left: auto;
         margin-right: auto;
         /* padding-left: 15px;
         padding-right: 15px; */
         box-sizing: border-box;
         }
         table {
         border-collapse: collapse;
         width: 100%;
         }
         h1, h2, h3 {
         margin: 0;
         padding: 0;
         }
         .header, .footer {
         text-align: center;
         margin-bottom: 0;
         }
         .work-order-header {
         display: flex;
         justify-content: space-between;
         }
         .work-order-box {
         border: 1px solid #ccc;
         padding: 10px;
         margin-bottom: 20px;
         }
         .section-title {
         background-color: #0072C6;
         color: #fff;
         padding: 5px;
         }
         .table-bordered th, .table-bordered td {
         border: 1px solid #000;
         padding: 8px;
         }
         .text-right {
         text-align: right;
         }
         .text-center {
         text-align: center;
         }
         .highlight {
         background-color:black;
         color: white;
         }
         .total-row {
         font-weight: bold;
         background-color: #D9EDF7;
         }
         .img-fluid {
         max-width: 100%;
         height: auto;
         display: block;
         }
         .head-terms{
         font-size: 14px;
         text-align: center;
         }
         @media print {
         body{
         font-size: 10px;
         }
         .terms{
         font-size: 10px!important;
         }
         .head-terms{
         font-size: 9px;
         text-align: center;
         }
         .inner-span{
         font-size: 10px;
         }
         }
         .border-box{
         border: 2px solid black;
         padding: 10px 20px 0px 20px;
         border-radius: 10px;
         }
         @media print {
         .page-break {
         page-break-before: always;
         }
         }
         .card {
         width: 18rem; /* 288px */
         border: 1px solid black;
         border-radius: 0.25rem;
         overflow: hidden;
         font-family: Arial, sans-serif;
         background-color: #fff;
         /*          box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); */
         }
         .card-header {
         padding: 0.50rem 1rem;
         background-color: black;
         border-bottom: 1px solid #dee2e6;
         font-weight: bold;
         color: white;
         }
         .list-group {
         list-style: none;
         margin: 0;
         padding: 0;
         }
         .list-group-item {
         padding: 0.50rem 1rem;
         border-bottom: 1px solid #dee2e6;
         }
         .list-group-item:last-child {
         border-bottom: none;
         }
         .img-fluid{
         max-width: 75%;
         height: auto;
         display: block;
         }
         .bebas-neue-regular {
         font-family: "Bebas Neue", sans-serif;
         font-weight: 400;
         font-style: normal;
         }
         .ribbon-head {
         position: relative;
         margin: 0 auto 20px;
         padding: 5px 30px;
         text-align: center;
         background-color: black;
         color: white;
         font-family: "Bebas Neue", sans-serif;
         }
         .ribbon-head::before, .ribbon-head::after {
         content: '';
         width: 80px;
         height: 100%;
         background-color: #000000c9;
         /* position ribbon ends behind and slightly lower */
         position: absolute;
         z-index: -1;
         top: 20px;
         /* clip ribbon end shape */
         clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 25% 50%);
         /* draw and position the folded ribbon bit */
         background-image: linear-gradient(45deg, transparent 50%, #544d49 50%);
         background-size: 20px 20px;
         background-repeat: no-repeat;
         background-position: bottom right;
         }
         .ribbon-head::before {
         left: -45px;
         }
         .ribbon-head::after {
         right: -45px;
         transform: scaleX(-1); /* flip horizontally */
         }
         /* everything below is for demo appearances and not important to the concept */
         @media (max-width: 400px) {
         .ribbon-head { font-size: 1.5rem; }
         }
         @media print {
         body {
         -webkit-print-color-adjust: exact !important;
         print-color-adjust: exact !important;
         }
         @page {
         size: A4;          /* Force A4 sheet */
         margin: 0 !important;  /* Remove default page margins */
         }
         }
      </style>
      <style>
         @media print {
         button {
         display: none;
         }
         }
      </style>
      <style>
                  .signature-box {
                  display: inline-block;
                  padding: 8px 12px;
                  font-family: Arial, sans-serif;
                  position: relative;
                  background-color: #fff;
                  width: 80%;
                  }
                  .signature-title {
                  font-size: 12px;
                  font-weight: bold;
                  color: #222;
                  }
                  .signature-text {
                  font-size: 10px;
                  color: #333;
                  margin-top: 4px;
                  line-height: 1.4;
                  z-index: 2;
                  position: relative;
                  }
                  .checkmark {
                  position: absolute;
                  right: 117px;
                  top: 0px;
                  font-size: 48px;
                  color: green;
                  font-weight: bold;
                  transform: rotate(12deg);
                  }
                  .tooltip {
                  position: absolute;
                  right: 15px;
                  top: 40px;
                  background: #fff8dc;
                  border: 1px solid #aaa;
                  padding: 4px 8px;
                  font-size: 12px;
                  display: none;
                  }
                  .signature-box:hover .tooltip {
                  display: block;
                  }
               </style>
      <script src="chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/prompt.js"></script>
   </head>

   
   
<?php
session_start();
// error_reporting(E_ALL);
// ini_set('display_errors', 1);

$bid = $_SESSION['branch_id'] ?? 0;
include 'branch_connection.php';

// Fetch branch info
$branch_sql = "SELECT * FROM branches WHERE id = '$bid'";
$branch_res = mysqli_query($conn, $branch_sql);
$branch_row = mysqli_fetch_assoc($branch_res);

// Get order id
$orderid = $_GET['orderid'] ?? 0;

// Fetch proposal
$proposal_sql = "SELECT * FROM proposals WHERE id = '$orderid'";
$proposal_res = mysqli_query($conn, $proposal_sql);
if(!$proposal_res || mysqli_num_rows($proposal_res) == 0){
    die("Proposal not found.");
}
$proposal = mysqli_fetch_assoc($proposal_res);
$proposal_no  = $proposal['proposal_no'];
$order_date = $proposal['created_at'];
$currency = $proposal['currency'];
$lead_id = $proposal['lead_id'];

// Fetch lead info from tb_positiveleads
$lead_sql = "SELECT p.*, s.segment_name 
             FROM tb_positiveleads p
             LEFT JOIN segments s ON p.segment = s.id
             WHERE p.id = '$lead_id'";
$lead_res = mysqli_query($conn, $lead_sql);

// If found → use it
if ($lead_res && mysqli_num_rows($lead_res) > 0) {
    $order = mysqli_fetch_assoc($lead_res);

} else {

    // Else check in marketing_order
    $mo_sql = "SELECT * FROM marketing_order WHERE id = '$lead_id'";
    $mo_res = mysqli_query($conn, $mo_sql);

    if ($mo_res && mysqli_num_rows($mo_res) > 0) {
        $order = mysqli_fetch_assoc($mo_res);

    } else {
        die("Lead not found.");
    }
}

// $order = mysqli_fetch_assoc($lead_res);

// Function: convert number to words
function numberToWords($number) {
    $hyphen      = '-';
    $conjunction = ' and ';
    $separator   = ', ';
    $negative    = 'negative ';
    $decimal     = ' point ';
    $dictionary  = array(
        0 => 'Zero', 1 => 'One', 2 => 'Two', 3 => 'Three', 4 => 'Four',
        5 => 'Five', 6 => 'Six', 7 => 'Seven', 8 => 'Eight', 9 => 'Nine',
        10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve', 13 => 'Thirteen',
        14 => 'Fourteen', 15 => 'Fifteen', 16 => 'Sixteen', 17 => 'Seventeen',
        18 => 'Eighteen', 19 => 'Nineteen', 20 => 'Twenty', 30 => 'Thirty',
        40 => 'Forty', 50 => 'Fifty', 60 => 'Sixty', 70 => 'Seventy',
        80 => 'Eighty', 90 => 'Ninety', 100 => 'Hundred', 1000 => 'Thousand',
        1000000 => 'Million', 1000000000 => 'Billion', 1000000000000 => 'Trillion',
    );

    if (!is_numeric($number)) return false;

    // ❗ Remove decimal part if it is .00
    if (strpos($number, '.') !== false) {
        $parts = explode('.', $number);
        if (intval($parts[1]) === 0) {
            $number = $parts[0]; // ignore .00
            $fraction = null;
        } else {
            $number = $parts[0];
            $fraction = $parts[1];
        }
    } else {
        $fraction = null;
    }

    if ($number < 0) return $negative . numberToWords(abs($number));

    $string = null;

    switch (true) {
        case $number < 21:
            $string = $dictionary[$number];
            break;

        case $number < 100:
            $tens   = ((int) ($number / 10)) * 10;
            $units  = $number % 10;
            $string = $dictionary[$tens];
            if ($units) $string .= $hyphen . $dictionary[$units];
            break;

        case $number < 1000:
            $hundreds  = (int) ($number / 100);
            $remainder = $number % 100;
            $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
            if ($remainder) $string .= $conjunction . numberToWords($remainder);
            break;

        default:
            $baseUnit = pow(1000, floor(log($number, 1000)));
            $numBaseUnits = (int) ($number / $baseUnit);
            $remainder = $number % $baseUnit;

            $string = numberToWords($numBaseUnits) . ' ' . $dictionary[$baseUnit];

            if ($remainder) {
                $string .= $remainder < 100 ? $conjunction : $separator;
                $string .= numberToWords($remainder);
            }
            break;
    }

    // ❗ Only add decimal words if fraction exists and not 00
    if ($fraction !== null && is_numeric($fraction)) {
        $string .= $decimal;
        $words = [];
        foreach (str_split((string) $fraction) as $digit) {
            $words[] = $dictionary[$digit];
        }
        $string .= implode(' ', $words);
    }

    return $string;
}

function count_visible_lines($text) {
    // Strip tags except <br> to count actual lines
    $plain = strip_tags($text, '<br>');
    $plain = preg_replace('/\s+/', ' ', $plain);
    $chars_per_line = 90;
    $length = strlen($plain);
    if ($length == 0) return 1;
    return ceil($length / $chars_per_line);
}

// -----------------------------
// Prepare proposal content
// -----------------------------
$raw_proposal = $proposal['details'] ?? '';
$total = $proposal['total'] ?? 0;
$discount = $proposal['discount'] ?? 0;

// Split by lines
$lines = explode("\n", $raw_proposal);

// -----------------------------
// First page summary
// -----------------------------
$max_height_lines_summary = 25;
$current_height = 0;
$summary_lines = [];
$remaining_lines = [];

foreach ($lines as $line) {
    $line_height = count_visible_lines($line);
    if (($current_height + $line_height) <= $max_height_lines_summary) {
        $summary_lines[] = $line;
        $current_height += $line_height;
    } else {
        $remaining_lines[] = $line;
    }
}

// Format summary
$summary_text = implode("\n", $summary_lines);
$summary_formatted = preg_replace(
    '/^(Key Modules and Features:-|Detailed Scope:-|Investment & Pricing:-|Implementation Timeline:-|Benefits:-|Support & Maintenance:-)$/m',
    '<h2 style="margin-top:25px; margin-bottom:10px; color:#222;">$1</h2>',
    $summary_text
);
$summary_formatted = preg_replace('/^(\d+)\.(.+)$/m', '<strong>$1.$2</strong>', $summary_formatted);
$summary_formatted = preg_replace('/^\* (.+)$/m', '<li>$1</li>', $summary_formatted);
$summary_formatted = preg_replace_callback('/(<li>.*?<\/li>)/s', function ($matches) {
    return '<ul style="margin:5px 0 15px 25px; padding:0;">' . $matches[1] . '</ul>';
}, $summary_formatted);

// Add continued notice if more content exists
if (count($lines) > count($summary_lines)) {
    $summary_formatted .= '<p style="text-align:center; font-style:italic; margin-top:5px;">--- Continued on next page ---</p>';
}

// -----------------------------
// Annexure pages
// -----------------------------
$lines_per_annexure_page = 50;
$annexure_pages = [];
$page_lines = [];
$page_height = 0;

foreach ($remaining_lines as $line) {
    $line_height = count_visible_lines($line);
    if (($page_height + $line_height) > $lines_per_annexure_page) {
        $annexure_pages[] = $page_lines;
        $page_lines = [$line];
        $page_height = $line_height;
    } else {
        $page_lines[] = $line;
        $page_height += $line_height;
    }
}
if (!empty($page_lines)) $annexure_pages[] = $page_lines;

// Limit to 6 annexure pages max
$annexure_pages = array_slice($annexure_pages, 0, 6);
$total_annexure_pages = count($annexure_pages);
$total_pages = 1 + $total_annexure_pages;

// -----------------------------
// Format each annexure page
// -----------------------------
$formatted_annexure_pages = [];
foreach ($annexure_pages as $page_lines) {
    $page_text = implode("\n", $page_lines);
    $formatted = preg_replace(
        '/^(Key Modules and Features:-|Detailed Scope:-|Investment & Pricing:-|Implementation Timeline:-|Benefits:-|Support & Maintenance:-)$/m',
        '<h2 style="margin-top:25px; margin-bottom:10px; color:#222;">$1</h2>',
        $page_text
    );
    $formatted = preg_replace('/^(\d+)\.(.+)$/m', '<strong>$1.$2</strong>', $formatted);
    $formatted = preg_replace('/^\* (.+)$/m', '<li>$1</li>', $formatted);
    $formatted = preg_replace_callback('/(<li>.*?<\/li>)/s', function ($matches) {
        return '<ul style="margin:5px 0 15px 25px; padding:0;">' . $matches[1] . '</ul>';
    }, $formatted);

    // Append formatted page to array
    $formatted_annexure_pages[] = $formatted;
}

// Company info
$company = $branch_row['company_name'] ?? '';
$location = $branch_row['location'] ?? '';
$datetime = date("Y.m.d H:i:s");
$timezone_offset = date("P");
$city = $_SESSION['gps_city'] ?? "Location unavailable";
?>

   <body cz-shortcut-listen="true">
      <div style="text-align: center; margin-top: 20px; display: flex; justify-content: center; gap: 15px;">
         <!-- Print Button -->
         <button onclick="window.print()" style="
            background: linear-gradient(90deg, #333, #000);
            color: #fff;
            border: none;
            padding: 12px 28px;
            font-size: 16px;
            cursor: pointer;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.3);
            transition: all 0.3s ease;
            " onmouseover="this.style.transform='scale(1.05)'; this.style.background='linear-gradient(90deg, #555, #111)';" onmouseout="this.style.transform='scale(1)'; this.style.background='linear-gradient(90deg, #333, #000)';">
         Print
         </button>
         <!-- Back Button -->
         <button onclick="history.back()" style="background: linear-gradient(90deg, rgb(119, 119, 119), rgb(68, 68, 68)); color: rgb(255, 255, 255); border: none; padding: 12px 28px; font-size: 16px; cursor: pointer; border-radius: 8px; box-shadow: rgba(0, 0, 0, 0.3) 0px 4px 6px; transition: 0.3s; transform: scale(1);" onmouseover="this.style.transform='scale(1.05)'; this.style.background='linear-gradient(90deg, #999, #666)';" onmouseout="this.style.transform='scale(1)'; this.style.background='linear-gradient(90deg, #777, #444)';">
         Back
         </button>
      </div>
      <div>
         <div class="container" style="height:297mm;width: 200mm;">
            <div class="border-box">
               <div class="header" style="display:flex;justify-content:space-between;align-items:start;margin-top:0px;">
           <?php
session_start();

// Check if random number already exists in session
if (!isset($_SESSION['random_order_number'])) {
    // Generate a 10-digit random number
    $_SESSION['random_order_number'] = mt_rand(1000000000, 9999999999);
}

// Use the session value
$randomNumber = $_SESSION['random_order_number'];
?>

<div style="text-align:left;width: 33.33%;display:flex;flex-direction:column;align-items:flex-start;">
    <img src="pro-logo.png" style="width: 75%; height: auto;">
    <img src="barcode.png" alt="Barcode" style="width: 75%;">
    <p style="text-align: center;letter-spacing: 12px;">
        <?php echo $randomNumber; ?>
    </p>
</div>

                  <div style="width: 33.33%; text-align: center; display: flex; align-items: center; justify-content: center;flex-direction: column;">
                     <div>
                        <h1 class="bebas-neue-regular " style="font-size:40px;">ORDER FORM</h1>
                        <img src="title-bg1.png" alt="" style="width: 35%;">
                     </div>
                     <img src="gem-logo.png" style="width: 35%; height: auto;">
                  </div>
                  <div style="width: 33.33%;height:;">
                     <div style="display: flex; align-items: stretch; gap: 8px; justify-content: flex-end;margin-bottom:2px;">
                        <div style="display: flex; flex-direction: column; gap: 8px; width: 40%;">
                           <div style="flex: 1;border:1px solid #0000002e">
                              <p style="background-color:black;color:white;margin:0;">ORDER #</p>
                              <p style="margin:0;background-color:color:black;font-size:13px;height:80%;display:flex;align-items:center;justify-content:center;"><?php echo $proposal['proposal_no'];?></p>
                           </div>
                           <div style="flex: 1;border:1px solid #0000002e">
                              <p style="background-color:black;color:white;margin:0;">ORDER DATE</p>
                              <p style="margin:0;background-color:color:black;font-size:15px;height:80%;display:flex;align-items:center;justify-content:center;"><?php echo date("d-m-Y", strtotime($proposal['created_at'])); ?></p>
                           </div>
                        </div>
                        <img src="qrcode.png" alt="QR" style="width: 40%; object-fit: contain;">
                     </div>
                     <p style="margin-top: 0 !important; text-align: right; margin-bottom: 0 !important;"><b>Annexure - A (<?php echo $total_pages; ?>)</b></p>
                  </div>
               </div>
               <div style="width: 100%;margin-top:0px;">
                  <div style="display:flex;gap:10px;">
                     <div class="card" style="width: 33.33%;">
 <div class="card-header">CUSTOMER DETAILS</div>
                        <ul class="list-group">
                           <li class="list-group-item"><?php echo $order['company_name'];?>
                              <br><?php echo $order['location'];?>
                              <br>
                           </li>
                        </ul>           </div>
                     <div class="card" style="width: 33.33%;">
                        <div class="card-header">ORDER DETAILS</div>
                        <ul class="list-group">
                           <div>
                              <ul class="list-group">
                                 <li class="list-group-item"><?php echo $order['company_name'];?>
                                    <br><?php echo $order['location'];?>
                                    <br>
                                 </li>
                                 <li class="list-group-item"><b>Proposal Date: 10/08/25</b>
                                 </li>
                              </ul>
                           </div>
                        </ul>
                     </div>
                     <div class="card" style="width: 33.33%;">
                        <div class="card-header">PROJECT DETAILS</div>
                        <ul class="list-group">
                           <div>
                              <ul class="list-group">
                                 <li class="list-group-item"><b>BDO /BDM: <?php echo $order['bdm'];?></b></li>
                                 <?php
                                    $rev_sql = "SELECT COUNT(*) AS revision_count FROM proposals WHERE lead_id = '$lead_id'";
                                    $rev_res = mysqli_query($conn, $rev_sql);
                                    $rev_data = mysqli_fetch_assoc($rev_res);
                                    $revision_number = $rev_data['revision_count'];
                                    $revision_text = $revision_number > 1 ? " (Revised #$revision_number)" : "";
                                    ?>
                                 <li class="list-group-item"><b>Proposal #: <?php echo $proposal['proposal_no'] . $revision_text; ?></b></li>
                                 <li class="list-group-item"><b>Proposal By: <?php echo $proposal['qtnby'];?></b></li>
                              </ul>
                           </div>
                        </ul>
                     </div>
                  </div>
               </div>
               <div></div>
               
               <div class="" style="margin-top:1px;">
                  <small style="font-size:10px;font-weight:bold;">This Proposal form is issued in connection with the proposed project, and confirms our intent to proceed with the implementation as per the agreed terms and conditions.</small>
                  <div style="display:flex;gap:60px;margin-top:2px;">
                     <div style="width: 100%;">
                        <div style="display:flex;gap: 10px;">
                           <div style="width:70%;">
                              <div class="card" style="width: 100%;height:99%;display: flex;justify-content: space-between;flex-direction:column;&gt;;">
                                 <div class="card-header" style="background-color:black;color:white;text-align:center;text-transform: uppercase;">Order Summary</div>
                                 <div style="padding:10px; text-align:justify; vertical-align:top;font-size:13px;height: 75%;">
                                    <?php echo $summary_formatted; ?>
                                 </div>
                                 <div>
                                    <div class="card-header" style="background-color:white;color:black;text-align:left;text-transform: capitalize;font-size: 12px;padding-left: 15px;border-bottom: 1px solid black;border-top:;">All Amt in <?php echo $currency;?> | No additional service or items | E&amp;O</div>
                                    <ul class="list-group " style="display: flex;width: 100%;justify-content: space-between;">
                                       <li class="list-group-item" style="border: 1px solid black;width: 75%;font-size: 13px!important;display: flex;justify-content: space-between;"><b>Total: <?php echo number_format($total, 2); ?>/-</b><span>(Discount: <?php echo number_format($discount, 2); ?>/-)</span></li>
                                       <li class="list-group-item" style="border: 1px solid black;width: 25%;font-size: 13px!important;"><b>Net: <?php echo number_format($total - $discount, 2); ?>/-</b></li>
                                    </ul>
                                    <p style="padding-left: 15px;font-size: 13px!important;display: flex;justify-content: space-between;margin-top:4px;margin-bottom:4px;">
                                       <b><?php echo numberToWords(strtolower(number_format($total - $discount, 2, '.', ''))); ?> Only</b>
                                       <!--<span style="padding-right: 10px;"><b>Annexure - A (<?php echo ($total_annexure_pages+1); ?> Pages)</b></span>-->
                                    </p>
                                 </div>
                              </div>
                           </div>
                           <div style="width:30%;padding:0 10px 10px 0px;">
                              <table style="width: 100%;">
                                 <thead style="background-color:black;color:white;">
                                    <tr>
                                       <th style="font-size:10px;padding:0.50rem 1rem;text-transform: uppercase;">Terms &amp; Conditions</th>
                                    </tr>
                                 </thead>
                                 <tbody>
                                    <tr>
                                       <td>
                                          <div style="display: flex; align-items: flex-start; margin-bottom: 10px;text-align:justify;font-size:13px;margin-top:10px;">
                                             <span><?php 
                                                $terms_sql = "SELECT * FROM tb_terms_master WHERE status = 'Active'";
                                                $terms_res = mysqli_query($conn, $terms_sql);
                                                $terms_data = mysqli_fetch_assoc($terms_res);
                                                echo $terms_data['remarks'];
                                                ?></span>
                                          </div>
                                       </td>
                                    </tr>
                                 </tbody>
                              </table>
                              <p style="text-align:center; font-style:italic; margin-top:5px;">--- Detailed continued in <b>Page <?php echo $total_pages;?></b> ---</p>
                           </div>
                        </div>
                        <div style="display: flex;gap: 10px;">
                           <div class="card" style="width: 100%;margin-top:2px;height:120px;">
                              <div class="card-header" style="background-color:black;color:white;text-align:center;font-size:10px;">Approved By</div>
                              <div style="padding:2px;">
                                 <div class="signature-box">
                                    <div class="signature-title">Signature valid</div>
                                    <div class="signature-text">
                                       Digitally signed by <b><?php
                                        echo strlen($company) > 20 ? substr($company, 0, 20) . '...' : $company;
                                        ?></b><br>
                                       Date: <?php echo $datetime . " " . $timezone_offset; ?><br>
                                       Location: <?php echo $location;?>
                                    </div>
                                    <div class="checkmark">✔</div>
                                    <div class="tooltip">Valid signature</div>
                                 </div>
                                 <span style="display:flex;justify-content:space-between;align-items: baseline;margin-top: -15px;"><span><span>Authorised signatory:</span></span><span style="display: flex;align-items: end;justify-content: end;"><img src="seal.png" alt="" class="img-fluid" style="position: relative; left: 20px; width: 40%; top: -50px;"> <span>(Seal)</span></span></span>
                              </div>
                           </div>
                           <div class="card" style="width: 100%;margin-top:2px;height:120px;">
                              <div class="card-header" style="background-color:black;color:white;text-align:center;font-size:10px;">Accepted By</div>
                              <div style="padding-left: 10px; padding-right: 10px; padding-top: 5px;">
                                 <div style="display: flex; align-items: center; justify-content: center;">
                                    <div class="signature-box" style="padding:8px!important;">
                                       <div class="signature-title">Signature valid</div>
                                       <div class="signature-text">
                                          Digitally signed by <b><?php
                                            $company1 = $order['company_name'];
                                            echo strlen($company1) > 20 ? substr($company1, 0, 20) . '...' : $company1;
                                            ?></b><br>
                                          Date: <?php echo $datetime . " " . $timezone_offset; ?><br>
                                          Location: <?php echo $order['location'];?>
                                       </div>
                                       <div class="checkmark">✔</div>
                                       <div class="tooltip">Valid signature</div>
                                    </div>
                                 </div>
                              </div>
                           </div>
                           <div class="card" style="width: 100%;margin-top:2px;height:120px;">
                              <div class="card-header" style="background-color:black;color:white;text-align:center;font-size:10px;">Bank Details</div>
                              <div style="padding:10px;">
                                 <span><?php $branch_row['bank_name']; ?></span><br>
                                 <span><?php echo $branch_row['bank_details'] ?? 'N/A'; ?></span><br>
                                 <!--<span>Account No: <?php echo $branch_row['account_no'] ?? 'N/A'; ?></span><br>-->
                                 <!--<span>Branch: <?php echo $location; ?></span><br>-->
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
                  <hr style="margin:0;">
                  <p style="text-align: center;margin-bottom: 0!important;margin-top: 0!important;padding-bottom: 5px;padding-top: 5px;"><?php echo $branch_row['address'];?></p>
               </div>
            </div>
            <small>Purchase authorization request</small>
         </div>
      </div>

      <?php for ($page = 0; $page < $total_annexure_pages; $page++): ?>
      <div class="page-break">
         <div class="container" style="height:285mm;width: 200mm;margin-top:20px;">
            <div class="border-box" style="border:2px solid #000; border-radius:10px; margin-right:8px; padding:12px; box-sizing:border-box; display:flex; flex-direction:column; height:100%;">
               <div class="header" style="display:flex;justify-content:space-between;align-items:start;margin-top:0px;">
                  <div style="text-align:left;width: 33.33%;display:flex;flex-direction:column;align-items:flex-start;margin-top:-10px;">
                     <img src="pro-logo.png" style="width: 75%; height: auto;">
                     <img src="barcode.png" alt="Barcode" style="width: 75%;">
                     <p style="text-align: center;letter-spacing: 12px;"><?php echo $randomNumber; ?></p>

                  </div>
                  <div style="width: 33.33%; text-align: center; display: flex; align-items: center; justify-content: center;flex-direction: column;">
                     <div>
                        <h1 class="bebas-neue-regular " style="font-size:40px;">ORDER FORM</h1>
                        <img src="title-bg1.png" alt="" style="width: 35%;">
                     </div>
                     <img src="gem-logo.png" style="width: 35%; height: auto;">
                  </div>
                  <div style="width: 33.33%;height:;">
                     <div style="display: flex; align-items: stretch; gap: 8px; justify-content: flex-end;margin-bottom:2px;">
                        <div style="display: flex; flex-direction: column; gap: 8px; width: 40%;">
                           <div style="flex: 1;border:1px solid #0000002e">
                              <p style="background-color:black;color:white;margin:0;">ORDER #</p>
                              <p style="margin:0;background-color:color:black;font-size:13px;height:80%;display:flex;align-items:center;justify-content:center;"><?php echo $proposal['proposal_no'];?></p>
                           </div>
                           <div style="flex: 1;border:1px solid #0000002e">
                              <p style="background-color:black;color:white;margin:0;">ORDER DATE</p>
                              <p style="margin:0;background-color:color:black;font-size:15px;height:80%;display:flex;align-items:center;justify-content:center;"><?php echo date("d-m-Y", strtotime($proposal['created_at'])); ?></p>
                           </div>
                        </div>
                        <img src="qrcode.png" alt="QR" style="width: 40%; object-fit: contain;">
                     </div>
                     <p style="margin-top: 0 !important; text-align: right; margin-bottom: 0 !important;"><b>ANNEXURE - A (<?php echo $page + 1; ?>/<?php echo $total_pages; ?>)</b></p>
                  </div>
               </div>
               
               <div style="width:100%;margin-top:8px;height:100%;">
                  <div class="card" style="width: 100%;height:97%;display: flex;justify-content:flex-start;flex-direction:column;&gt;;">
                     <div class="card-header" style="background-color:black;color:white;text-align:center;text-transform: uppercase;">Order in Details</div>
                     <div style="padding:10px; text-align:justify; vertical-align:top;font-size:13px;">
                        <?php echo $formatted_annexure_pages[$page]; ?>
                        <?php if ($page < $total_annexure_pages - 1): ?>
                        <p style="text-align:center; font-style:italic; margin-top:10px;">--- Continued on next page ---</p>
                        <?php else: ?>
                        <p style="text-align:center; font-style:italic; margin-top:10px;">--- End of page ---</p>
                        <?php endif; ?>
                     </div>
                  </div>
                  <div style="display:flex;margin-top:15px;align-items:center;">
                  </div>
                  <hr style="margin:0;">
                  <p style="text-align: center;margin-bottom: 0!important;margin-top: 0!important;padding-bottom: 5px;padding-top: 5px;"><?php echo $branch_row['address'];?></p>
               </div>
            </div>
            <small>Purchase authorization request</small>
         </div>
      </div>
      <?php endfor; ?>
      
            <div class="page-break">
         <div class="container" style="height:285mm;width: 200mm;margin-top:20px;">
            <div class="border-box" style="border:2px solid #000; border-radius:10px; margin-right:8px; padding:12px 25px 1px 25px; box-sizing:border-box; display:flex; flex-direction:column; height:100%;">
               <div class="header" style="display:flex;justify-content:space-between;align-items:start;margin-top:0px;">
                  <div style="text-align:left;width: 33.33%;display:flex;flex-direction:column;align-items:flex-start;margin-top:-10px;">
                     <img src="pro-logo.png" style="width: 75%; height: auto;">
                     <img src="barcode.png" alt="Barcode" style="width: 75%;">
                     <p style="text-align: center;letter-spacing: 12px;"><?php echo $randomNumber; ?></p>

                  </div>
                  <div style="width: 33.33%; text-align: center; display: flex; align-items: center; justify-content: center;flex-direction: column;">
                     <div>
                        <h1 class="bebas-neue-regular " style="font-size:40px;">ORDER FORM</h1>
                        <img src="title-bg1.png" alt="" style="width: 35%;">
                     </div>
                     <img src="gem-logo.png" style="width: 35%; height: auto;">
                  </div>
                  <div style="width: 33.33%;height:;">
                     <div style="display: flex; align-items: stretch; gap: 8px; justify-content: flex-end;margin-bottom:2px;">
                        <div style="display: flex; flex-direction: column; gap: 8px; width: 40%;">
                           <div style="flex: 1;border:1px solid #0000002e">
                              <p style="background-color:black;color:white;margin:0;">ORDER #</p>
                              <p style="margin:0;background-color:color:black;font-size:13px;height:80%;display:flex;align-items:center;justify-content:center;"><?php echo $proposal['proposal_no'];?></p>
                           </div>
                           <div style="flex: 1;border:1px solid #0000002e">
                              <p style="background-color:black;color:white;margin:0;">ORDER DATE</p>
                              <p style="margin:0;background-color:color:black;font-size:15px;height:80%;display:flex;align-items:center;justify-content:center;"><?php echo date("d-m-Y", strtotime($proposal['created_at'])); ?></p>
                           </div>
                        </div>
                        <img src="qrcode.png" alt="QR" style="width: 40%; object-fit: contain;">
                     </div>
                     <p style="margin-top: 0 !important; text-align: right; margin-bottom: 0 !important;"><b>ANNEXURE - A (<?php echo $total_pages; ?>/<?php echo $total_pages; ?>)</b></p>
                  </div>
               </div>
               <div style="width:100%;margin-top:0px;height:100%;">
                  <div class="card" style="width: 100%;height:95%;display: flex;justify-content:flex-start;flex-direction:column;&gt;;">
                     <div class="card-header" style="background-color:black;color:white;text-align:center;text-transform: uppercase;">Terms & Conditions</div>
                     <div style="padding:10px; text-align:justify; vertical-align:top;font-size:13px;">
                         <!--<p><strong>Programers International</strong></p>-->
                         <!--<p>These Terms and Conditions ("Terms") govern the provision of Any IT services it includes software development and web hosting services by Programers International ("The Company") to the Client. By signing the Order Form or making an advance payment, the Client agrees to be bound by these Terms.</p>-->
                         <div style="display: flex; align-items: flex-start; margin-bottom: 10px;text-align:justify;font-size:13px;margin-top:0px;margn-bottom:0!important;">
                                             <span>                                          <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;margin-top:0px;">
                                             <strong style="margin-right: 5px;">1.</strong>
                                             <span><strong>Payments & Commercials :</strong><strong>Payment Schedule: </strong>A non-refundable advance payment of 50% of the total project value must be made upon signing the contract/order form. The remaining 50% balance must be cleared in full before the final hosting, server deployment, or handover of the product.<strong>Mode of Payment:  </strong>All payments must be made via Bank Transfer or UPI.<strong>Taxes:   </strong>All mentioned prices are exclusive of applicable taxes (GST) unless specified otherwise.<strong>Delay in Payment:   </strong>: If the final payment is delayed by more than 7 days after the project completion notification, Programers International reserves the right to withhold the launch/handover and charge a late fee of 5% per week on the outstanding amount.<strong>No Refunds:   </strong>Fees once paid (including advance payments and domain registration fees) are non-refundable.</span>
                                             </div>
                                          <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;">
                                             <strong style="margin-right: 5px;">2.</strong>
                                             <span><strong>Renewals (Hosting & Domain):</strong><strong>Billing Cycle:  </strong>Yearly renewal fees (Yearly Rent) will be charged as per the rates mentioned in the Order Form. Rates are subject to revision with prior notice.<strong>Service Period:   </strong>The service period for server space and domain validity commences from the date of domain registration, regardless of the actual website launch or hosting date.<strong>Payment Deadline:    </strong>Renewal charges (covering Domain, SSL, and Server Space) must be paid at least 30 days prior to the expiry date.<strong>Lapse of Service:    </strong>: Programers International is not responsible for the loss of any domain name, email data, or website content if the renewal payment is not made within the stipulated time. Restoration of expired domains (if possible) may incur high redemption fees payable by the Client.</span>
                                             
                                          </div>
                                          <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;">
                                             <strong style="margin-right: 5px;">3.</strong>
                                             <span><strong>Support & Maintenance:</strong><strong>Channels & Hours:   </strong>Support is provided via Email and WhatsApp for troubleshooting software/web issues. Support hours are 10:00 AM to 5:00 PM, Monday through Saturday (excluding public holidays).<strong>Scope of Support:    </strong>Support covers bug fixes and server uptime issues only. It does not cover feature additions, design changes, or content updates unless a separate Annual Maintenance Contract (AMC) is signed.<strong>AMC Requirement: </strong>Post-warranty support is strictly subject to a valid ALC/AMC (Annual Maintenance Contract). Without an AMC, support will be charged on an hourly basis.</span>
                                          </div>
                                             <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;">
                                             <strong style="margin-right: 5px;">4.</strong>
                                             <span><strong>Scope of Work & Variations:</strong> <strong>Project Scope:   </strong>The project will be executed strictly according to the feature list/sitemap approved in the initial agreement.<strong>Change Requests:    </strong>Any additions, changes to the design, or new feature requests made after the project has commenced will be considered "Out of Scope" and will be billed additionally.<strong>Client Deliverables:  </strong>The Client must provide all necessary content (text, images, logos) within the agreed timeframe. Delays in providing content will result in a delay in the project delivery date, for which the Company is not liable.</span>
                                          </div>
                                             <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;">
                                             <strong style="margin-right: 5px;">5.</strong>
                                             <span><strong>Intellectual Property & Ownership:</strong><strong>Ownership:    </strong>Full ownership of the final website/software code is transferred to the Client only upon the full realization of all pending payments. Until then, the code remains the property of Programers International.<strong>Company Rights:     </strong>Programers International reserves the right to place a small credit link ("Designed/Developed by Programers International") in the footer of the website unless explicitly negotiated otherwise.<strong>Source Code:   </strong>Unless specifically mentioned in the Order Form, the "Source Code" for proprietary software products belongs to Programers International; the Client is granted a license to use it.</span>
                                          </div>
                                             <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;">
                                             <strong style="margin-right: 5px;">6.</strong>
                                             <span><strong>Client Responsibilities & Content Liability:</strong> <strong>Legality:     </strong>The Client is solely responsible for the content (text, images, media) hosted on the website. Programers International is not liable for any copyright infringement, trademark violations, or illegal content posted by the Client.<strong>Prohibited Use:      </strong>The Client shall not use the server for spamming, hosting malicious software, or illegal activities. Such actions will result in immediate termination of services without refund.</span>
                                          </div>
                                          <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;">
                                             <strong style="margin-right: 5px;">7.</strong>
                                             <span><strong>Limitation of Liability:</strong> <strong>Data Loss:     </strong>While the Company takes standard measures to ensure server stability, Programers International shall not be held liable for any data loss, database corruption, or business loss due to hacking, server failure, or unforeseen technical issues. The Client is advised to maintain their own local backups.<strong>Maximum Liability: </strong>In any event, the Company’s total liability shall be limited to the value of the specific service fee paid by the Client for that month/year.</span>
                                          </div>
                                          <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;">
                                             <strong style="margin-right: 5px;">8.</strong>
                                             <span><strong>Termination:</strong> Programers International reserves the right to terminate the contract and suspend services immediately if the Client breaches these terms, fails to make payments, or engages in abusive behavior towards the Company’s staff.</span>
                                          </div>
                                          <div style="display: flex; align-items: flex-start; margin-bottom: 0px;text-align:justify;font-size:13px;">
                                             <strong style="margin-right: 5px;">9.</strong>
                                             <span><strong>Jurisdiction:</strong> •	Any disputes arising out of this agreement shall be subject to the exclusive jurisdiction of the courts located in the city of Thrissur, Kerala, India where the Programers International’s registered office is situated.</span>
                                          </div>
                                       </span>
                                          </div>
                                         <div style="display: flex;gap: 10px;">
                           <div class="card" style="width: 100%;margin-top:2px;height:108px;">
                              <div class="card-header" style="background-color:black;color:white;text-align:center;font-size:10px;">Approved By</div>
                              <div style="padding:2px;">
                                 <div class="signature-box">
                                    <div class="signature-title">Signature valid</div>
                                    <div class="signature-text">
                                       Digitally signed by <b><?php echo $company; ?></b><br>
                                       Date: <?php echo $datetime . " " . $timezone_offset; ?><br>
                                       Location: <?php echo $location;?>
                                    </div>
                                    <div class="checkmark">✔</div>
                                    <div class="tooltip">Valid signature</div>
                                 </div>
                                 <span style="display:flex;justify-content:space-between;align-items: baseline;margin-top: -15px;"><span><span>Authorised signatory:</span></span><span style="display: flex;align-items: end;justify-content: end;"></span></span>
                              </div>
                           </div>
                           <div class="card" style="width: 100%;margin-top:2px;height:108px;">
                              <div class="card-header" style="background-color:black;color:white;text-align:center;font-size:10px;">Accepted By</div>
                              <div style="padding-left: 10px; padding-right: 10px; padding-top: 1px;">
                                 <div style="display: flex; align-items: center; justify-content: center;">
                                    <div class="signature-box">
                                       <div class="signature-title">Signature valid</div>
                                       <div class="signature-text">
                                          Digitally signed by <?php
                                            $company1 = $order['company_name'];
                                            echo strlen($company1) > 20 ? substr($company1, 0, 10) . '...' : $company1;
                                            ?></b><br>
                                          Date: <?php echo $datetime . " " . $timezone_offset; ?><br>
                                          Location: <?php echo $order['location'];?>
                                       </div>
                                       <div class="checkmark">✔</div>
                                       <div class="tooltip">Valid signature</div>
                                    </div>
                                 </div>
                              </div>
                           </div>
                           <img src="qrcode.png" style="width:33.33%;height:100;">
                        </div>
                     </div>
                  </div>
                  <div style="display:flex;margin-top:8px;align-items:center;">
                  </div>
                  <hr style="margin:0;">
                  <p style="text-align: center;margin-bottom: 0!important;margin-top: 0!important;padding-bottom: 5px;padding-top: 5px;">4th Floor, Park House ,Round North, Thrissur, Kerala, India - 680 001 | info@programers.in, www.programers.in | Ph: 9447151442, 94464 51442</p>
               </div>
            </div>
            <small>Purchase authorization request</small>
         </div>
      </div>
   </body>
</html>


