<?php
    session_start();
    
    $thisPage = "lotAdmin.php";
    $thisPageName = "Lot Admin";

	include "includes/common.php"; // your connection file
    //include "includes/mysql-555.php"; // your db connection file

	date_default_timezone_set('America/New_York');
    error_reporting(E_ALL);		// Report all errors
    error_reporting(0);			// Turn off error reporting

    $DEBUG = "Yo";
    //$DEBUG = "Ydb";
	//$DEBUG = "Y";

    if (($DEBUG == "Y") || ($DEBUG == "Ydb"))
    {
        foreach ($_POST as $key => $value) 
        {
            printf("\n<br>(9) key=%s, value=%s",$key,$value);
        } 
    	printf("\n<br>");
    	if ($DEBUG == "Ydb")
    	{
    	    printf("\n<br>dbuser=%s",$dbuser);
    	    printf("\n<br>dbdatabase=%s",$dbdatabase);
    	}
    	printf("\n<br>");    	
    }


?>
<!doctype html>
<html lang="en">
  <!--begin::Head-->
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo $SITENAME; ?> | <?php echo $thisPageName; ?> </title>
    <!--begin::Accessibility Meta Tags-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <meta name="color-scheme" content="light dark" />
    <meta name="theme-color" content="#007bff" media="(prefers-color-scheme: light)" />
    <meta name="theme-color" content="#1a1a1a" media="(prefers-color-scheme: dark)" />
    <!--end::Accessibility Meta Tags-->
    <!--begin::Primary Meta Tags-->
    <meta name="title" content="<?php echo $SITENAME; ?> | <?php echo $thisPageName; ?> " />
    <meta name="author" content="ColorlibHQ" />
    <meta
      name="<?php echo $SITENAME; ?> "
      //content="AdminLTE is a Free Bootstrap 5 Admin Dashboard, 30 example pages using Vanilla JS. Fully accessible with WCAG 2.1 AA compliance."
      keywords="<?php echo $KEYWORDS; ?>"
    />
    <meta
      name="keywords"       content="<?php echo $KEYWORDS; ?>  />
    <!--end::Primary Meta Tags-->
    <!--begin::Accessibility Features-->
    <!-- Skip links will be dynamically added by accessibility.js -->
    <meta name="supported-color-schemes" content="light dark" />
    <link rel="preload" href="./css/adminlte.css" as="style" />
    <!--end::Accessibility Features-->
    <!--begin::Fonts-->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@fontsource/source-sans-3@5.0.12/index.css"
      integrity="sha256-tXJfXfp6Ewt1ilPzLDtQnJV4hclT9XuaZUKyUvmyr+Q="
      crossorigin="anonymous"
      media="print"
      onload="this.media='all'"
    />
    <!--end::Fonts-->
    <!--begin::Third Party Plugin(OverlayScrollbars)-->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.11.0/styles/overlayscrollbars.min.css"
      crossorigin="anonymous"
    />
    <!--end::Third Party Plugin(OverlayScrollbars)-->
    <!--begin::Third Party Plugin(Bootstrap Icons)-->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css"
      crossorigin="anonymous"
    />
    <!--end::Third Party Plugin(Bootstrap Icons)-->
    <!--begin::Required Plugin(AdminLTE)-->
    <link rel="stylesheet" href="./css/adminlte.css" />
    <!--end::Required Plugin(AdminLTE)-->
    <!-- apexcharts -->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/apexcharts@3.37.1/dist/apexcharts.css"
      integrity="sha256-4MX+61mt9NVvvuPjUWdUdyfZfxSB1/Rf9WtqRHgG5S0="
      crossorigin="anonymous"
    />
    <!-- jsvectormap -->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/jsvectormap@1.5.3/dist/css/jsvectormap.min.css"
      integrity="sha256-+uGLJmmTKOqBr+2E6KDYs/NRsHxSkONXFHUL0fy2O/4="
      crossorigin="anonymous"
    />

    <!-- here is the color boxes w/icons -->
    <?php include "css/dashboard.css"; ?>

  </head>
  <!--end::Head-->
  <!--begin::Body-->
  <body class="layout-fixed sidebar-expand-lg sidebar-open bg-body-tertiary">
    <!--begin::App Wrapper-->
    <div class="app-wrapper">
      <!--begin::Header-->
      <nav class="app-header navbar navbar-expand bg-body">
        <!--begin::Container-->
        <div class="container-fluid">



          <!--begin::Start Navbar Links-->
          <ul class="navbar-nav">
            <li class="nav-item">
              <a class="nav-link" data-lte-toggle="sidebar" href="#" role="button">
                <i class="bi bi-list"></i>
              </a>
            </li>
            <li class="nav-item d-none d-md-block"><a href="dashboard.php" class="nav-link">Home</a></li>
            <li class="nav-item d-none d-md-block"><a href="#" class="nav-link"><?php echo $thisPageName; ?> </a></li>
          </ul>
          <!--end::Start Navbar Links-->
          <!--begin::End Navbar Links-->
          <ul class="navbar-nav ms-auto">
            <!--begin::Navbar Search-->
            <li class="nav-item">
              <a class="nav-link" data-widget="navbar-search" href="#" role="button">
                <i class="bi bi-search"></i>
              </a>
            </li>
            <!--end::Navbar Search-->
            <!--begin::Messages Dropdown Menu-->
            <li class="nav-item dropdown">
              <a class="nav-link" data-bs-toggle="dropdown" href="#">   <!-- [REVISIT]  messageCenter.php link and lookup required maybe SESSION var too -->
                <i class="bi bi-chat-text"></i>
                <span class="navbar-badge badge text-bg-danger">3</span>
              </a>
              <div class="dropdown-menu dropdown-menu-lg dropdown-menu-end">
                <a href="#" class="dropdown-item">
                  <!--begin::Message-->
                  <div class="d-flex">
                    <div class="flex-shrink-0">
                      <img
                        src="./assets/img/user1-128x128.jpg"
                        alt="User Avatar"
                        class="img-size-50 rounded-circle me-3"
                      />
                    </div>
                    <div class="flex-grow-1">                 <!-- [REVISIT] messageCenter lookup or just remove this option? -->
                      <h3 class="dropdown-item-title">
                        Brad Diesel
                        <span class="float-end fs-7 text-danger"
                          ><i class="bi bi-star-fill"></i
                        ></span>
                      </h3>
                      <p class="fs-7">Call me whenever you can...</p>
                      <p class="fs-7 text-secondary">
                        <i class="bi bi-clock-fill me-1"></i> 4 Hours Ago   <!-- [REVISIT] messageCenter linke probably (lookup or SESSION var required? or just remove this option -->
                      </p>
                    </div>
                  </div>
                  <!--end::Message-->
                </a>
                <div class="dropdown-divider"></div>
                <a href="#" class="dropdown-item">
                  <!--begin::Message-->
                  <div class="d-flex">
                    <div class="flex-shrink-0">
                      <img
                        src="./assets/img/user8-128x128.jpg"
                        alt="User Avatar"
                        class="img-size-50 rounded-circle me-3"
                      />
                    </div>
                    <div class="flex-grow-1">
                      <h3 class="dropdown-item-title">
                        John Pierce
                        <span class="float-end fs-7 text-secondary">
                          <i class="bi bi-star-fill"></i>
                        </span>
                      </h3>
                      <p class="fs-7">I got your message bro</p>
                      <p class="fs-7 text-secondary">
                        <i class="bi bi-clock-fill me-1"></i> 4 Hours Ago
                      </p>
                    </div>
                  </div>
                  <!--end::Message-->
                </a>
                <div class="dropdown-divider"></div>
                <a href="#" class="dropdown-item">
                  <!--begin::Message-->
                  <div class="d-flex">
                    <div class="flex-shrink-0">
                      <img
                        src="./assets/img/user3-128x128.jpg"
                        alt="User Avatar"
                        class="img-size-50 rounded-circle me-3"
                      />
                    </div>
                    <div class="flex-grow-1">
                      <h3 class="dropdown-item-title">
                        Nora Silvester
                        <span class="float-end fs-7 text-warning">
                          <i class="bi bi-star-fill"></i>
                        </span>
                      </h3>
                      <p class="fs-7">The subject goes here (214)</p>
                      <p class="fs-7 text-secondary">
                        <i class="bi bi-clock-fill me-1"></i> 4 Hours Ago
                      </p>
                    </div>
                  </div>
                  <!--end::Message-->
                </a>
                <div class="dropdown-divider"></div>
                <a href="#" class="dropdown-item dropdown-footer">See All Messages</a>  <!-- [REVISIT] link to messageCenter.php -->
              </div>
            </li>
            <!--end::Messages Dropdown Menu-->
            <!--begin::Notifications Dropdown Menu-->
            <li class="nav-item dropdown">
              <a class="nav-link" data-bs-toggle="dropdown" href="#">
                <i class="bi bi-bell-fill"></i>
                <span class="navbar-badge badge text-bg-warning">15</span>
              </a>
              <div class="dropdown-menu dropdown-menu-lg dropdown-menu-end">
                <span class="dropdown-item dropdown-header">15 Notifications</span>   <!-- [REVISIT] needs a lookup or SESSION var -->
                <div class="dropdown-divider"></div>
                <a href="#" class="dropdown-item">
                  <i class="bi bi-envelope me-2"></i> 4 new messages
                  <span class="float-end text-secondary fs-7">3 mins</span>
                </a>
                <div class="dropdown-divider"></div>
                <a href="#" class="dropdown-item">
                  <i class="bi bi-people-fill me-2"></i> 8 friend requests
                  <span class="float-end text-secondary fs-7">12 hours</span>
                </a>
                <div class="dropdown-divider"></div>
                <a href="#" class="dropdown-item">
                  <i class="bi bi-file-earmark-fill me-2"></i> 3 new reports   <!--  [REVISIT] SESSION var or something else ?  -->
                  <span class="float-end text-secondary fs-7">2 days</span>
                </a>
                <div class="dropdown-divider"></div>
                <a href="#" class="dropdown-item dropdown-footer"> See All Notifications </a>
              </div>
            </li>
            <!--end::Notifications Dropdown Menu-->
            <!--begin::Fullscreen Toggle-->
            <li class="nav-item">
              <a class="nav-link" href="#" data-lte-toggle="fullscreen">
                <i data-lte-icon="maximize" class="bi bi-arrows-fullscreen"></i>
                <i data-lte-icon="minimize" class="bi bi-fullscreen-exit" style="display: none"></i>
              </a>
            </li>
            <!--end::Fullscreen Toggle-->
            <!--begin::User Menu Dropdown-->
            <li class="nav-item dropdown user-menu">
              <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                <img
                  src="./assets/img/user2-160x160.jpg"
                  class="user-image rounded-circle shadow"
                  alt="User Image"
                />
                <span class="d-none d-md-inline">Alexander Pierce</span>  <!-- [REVISIT] SESSION var username -->
              </a>
              <ul class="dropdown-menu dropdown-menu-lg dropdown-menu-end">
                <!--begin::User Image-->
                <li class="user-header text-bg-primary">
                  <img
                    src="./assets/img/user2-160x160.jpg"
                    class="rounded-circle shadow"
                    alt="User Image"
                  />
                  <p>
                    Alexander Pierce - Web Developer  <!-- [REVISIT] SESSION var user info -->
                    <small>Member since Nov. 2023</small>
                  </p>
                </li>
                <!--end::User Image-->
                <!--begin::Menu Body-->
                <li class="user-body">
                  <!--begin::Row-->
                  <div class="row">
                    <div class="col-4 text-center"><a href="#">Followers</a></div>   <!-- [REVISIT] lookup details SESSION var? -->
                    <div class="col-4 text-center"><a href="#">Sales</a></div>
                    <div class="col-4 text-center"><a href="#">Friends</a></div>
                  </div>
                  <!--end::Row-->
                </li>
                <!--end::Menu Body-->
                <!--begin::Menu Footer-->
                <li class="user-footer">
                  <a href="#" class="btn btn-default btn-flat">Profile</a>
                  <a href="logout.php" class="btn btn-default btn-flat float-end">Sign out</a>  <!-- [REVISIT]  logout.php needed -->
                </li>
                <!--end::Menu Footer-->
              </ul>
            </li>
            <!--end::User Menu Dropdown-->
          </ul>
          <!--end::End Navbar Links-->
        </div>
        <!--end::Container-->
      </nav>
      <!--end::Header-->



      <!--begin::Sidebar-->
        <?php include "includes/navSide.php"; ?>
      <!--end::Sidebar-->



      <!--begin::App Main-->
      <main class="app-main">
        <!--begin::App Content Header-->
        <div class="app-content-header">
          <!--begin::Container-->
          <div class="container-fluid">
            <!--begin::Row-->
            <div class="row">
              <div class="col-sm-6"><h3 class="mb-0"><?php echo $thisPageName; ?> </h3></div>
              <div class="col-sm-6">
                <ol class="breadcrumb float-sm-end">
                  <li class="breadcrumb-item"><a href="#">Home</a></li>
                  <li class="breadcrumb-item active" aria-current="page">My Profile</li>
                </ol>
              </div>
            </div>
            <!--end::Row-->
          </div>
          <!--end::Container-->
        </div>
        <!--end::App Content Header-->

    <!-- here is the color boxes w/icons -->
    <?php include "css/dashboard3.css"; ?>


        <!--begin::App Content-->                                     <!--  [REVISIT]  start of first 4 cards -->
        <div class="app-content">
          <!--begin::Container-->
          <div class="container-fluid">

            <!--begin::Row-->
            <div class="row">
              <!--begin::Col-->



            <!--begin::Row-->
            <!--begin::Row-->
            <!--begin::Row-->









<?php
// lotsList.php
// AdminLTE lot listing page with search + desktop table + mobile stacked cards
// Procedural PHP / MySQLi

ini_set('display_errors', 1);
error_reporting(E_ALL);

/*
|--------------------------------------------------------------------------
| CONFIG
|--------------------------------------------------------------------------
*/
$USE_DB = false;   // change to true when ready to use MySQL
$db_host = "localhost";
$db_user = "YOUR_DB_USER";
$db_pass = "YOUR_DB_PASS";
$db_name = "YOUR_DB_NAME";

/*
|--------------------------------------------------------------------------
| INPUTS
|--------------------------------------------------------------------------
*/
$search_lot_id             = isset($_GET['lot_id']) ? trim($_GET['lot_id']) : '';
$search_lot_owner          = isset($_GET['lot_owner']) ? trim($_GET['lot_owner']) : '';
$search_in_transit         = isset($_GET['in_transit']) ? trim($_GET['in_transit']) : '';
$search_ready_for_transport= isset($_GET['ready_for_transport']) ? trim($_GET['ready_for_transport']) : '';

// NOTE: contract_id is not in the current lots table spec.
// Keeping this here for future expansion only.
$search_contract_id = isset($_GET['contract_id']) ? trim($_GET['contract_id']) : '';

$rows = [];
$db_error = '';

/*
|--------------------------------------------------------------------------
| DATA LOAD
|--------------------------------------------------------------------------
*/
if ($USE_DB) {

    $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

    if (!$conn) {
        $db_error = "Database connection failed: " . mysqli_connect_error();
    } else {

        mysqli_set_charset($conn, "utf8mb4");

        $sql = "SELECT
                    lkey,
                    lot_id,
                    start_date,
                    lot_status,
                    lot_owner,
                    lot_contract_price,
                    lot_consigner,
                    lot_interim_payts,
                    lot_current_location,
                    ready_for_transport,
                    in_transit,
                    animal_count,
                    animal_weight
                FROM lots
                WHERE 1=1";

        if ($search_lot_id !== '') {
            $lot_id_esc = mysqli_real_escape_string($conn, $search_lot_id);
            $sql .= " AND lot_id LIKE '%{$lot_id_esc}%'";
        }

        if ($search_lot_owner !== '') {
            $lot_owner_esc = mysqli_real_escape_string($conn, $search_lot_owner);
            $sql .= " AND lot_owner LIKE '%{$lot_owner_esc}%'";
        }

        if ($search_in_transit !== '') {
            $in_transit_esc = mysqli_real_escape_string($conn, $search_in_transit);
            $sql .= " AND in_transit = '{$in_transit_esc}'";
        }

        if ($search_ready_for_transport !== '') {
            $ready_esc = mysqli_real_escape_string($conn, $search_ready_for_transport);
            $sql .= " AND ready_for_transport = '{$ready_esc}'";
        }

        // FUTURE: if you add lot_contract_id to the table, uncomment this:
        /*
        if ($search_contract_id !== '') {
            $contract_id_esc = mysqli_real_escape_string($conn, $search_contract_id);
            $sql .= " AND lot_contract_id LIKE '%{$contract_id_esc}%'";
        }
        */

        $sql .= " ORDER BY lkey DESC";

        $result = mysqli_query($conn, $sql);

        if (!$result) {
            $db_error = "Query failed: " . mysqli_error($conn);
        } else {
            while ($row = mysqli_fetch_assoc($result)) {
                $rows[] = $row;
            }
            mysqli_free_result($result);
        }

        mysqli_close($conn);
    }

} else {
    /*
    |--------------------------------------------------------------------------
    | TEST DATA
    |--------------------------------------------------------------------------
    */
    $rows = [
        [
            'lkey' => 101,
            'lot_id' => 'LOT-1001',
            'start_date' => '2026-03-01',
            'lot_status' => 'A',
            'lot_owner' => 'Blue Sky Ranch',
            'lot_contract_price' => '18500.00',
            'lot_consigner' => 'North Valley Consignment',
            'lot_interim_payts' => 'Y',
            'lot_current_location' => 'Yard 1',
            'ready_for_transport' => 'Y',
            'in_transit' => 'N',
            'animal_count' => 45,
            'animal_weight' => '24875.50',
        ],
        [
            'lkey' => 102,
            'lot_id' => 'LOT-1002',
            'start_date' => '2026-03-02',
            'lot_status' => 'A',
            'lot_owner' => 'Triple Oak Farms',
            'lot_contract_price' => '9200.00',
            'lot_consigner' => 'South Route Livestock',
            'lot_interim_payts' => 'N',
            'lot_current_location' => 'Holding Pen B',
            'ready_for_transport' => 'N',
            'in_transit' => 'Y',
            'animal_count' => 22,
            'animal_weight' => '11640.00',
        ],
        [
            'lkey' => 103,
            'lot_id' => 'LOT-1003',
            'start_date' => '2026-03-04',
            'lot_status' => 'I',
            'lot_owner' => 'Rolling Meadow Beef',
            'lot_contract_price' => '14325.00',
            'lot_consigner' => 'Central Cattle Group',
            'lot_interim_payts' => 'Y',
            'lot_current_location' => 'Pasture 4',
            'ready_for_transport' => 'N',
            'in_transit' => 'N',
            'animal_count' => 31,
            'animal_weight' => '17220.75',
        ],
    ];

    // simple filter against test data
    $filtered = [];

    foreach ($rows as $r) {
        $keep = true;

        if ($search_lot_id !== '' && stripos($r['lot_id'], $search_lot_id) === false) {
            $keep = false;
        }

        if ($search_lot_owner !== '' && stripos($r['lot_owner'], $search_lot_owner) === false) {
            $keep = false;
        }

        if ($search_in_transit !== '' && $r['in_transit'] !== $search_in_transit) {
            $keep = false;
        }

        if ($search_ready_for_transport !== '' && $r['ready_for_transport'] !== $search_ready_for_transport) {
            $keep = false;
        }

        $filtered[] = $keep ? $r : null;
    }

    $rows = array_values(array_filter($filtered));
}

function h($v) {
    return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
}

function ynBadge($v) {
    if ($v === 'Y') {
        return '<span class="badge text-bg-success">Yes</span>';
    }
    if ($v === 'N') {
        return '<span class="badge text-bg-secondary">No</span>';
    }
    return '<span class="badge text-bg-light">-</span>';
}

function statusBadge($v) {
    if ($v === 'A') {
        return '<span class="badge text-bg-primary">Active</span>';
    }
    if ($v === 'I') {
        return '<span class="badge text-bg-warning">Inactive</span>';
    }
    if ($v === 'D') {
        return '<span class="badge text-bg-danger">Deleted</span>';
    }
    return '<span class="badge text-bg-light">' . h($v) . '</span>';
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Lots List</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- AdminLTE / Bootstrap -->
    <link rel="stylesheet" href="./css/adminlte.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">

    <style>
        .mobile-lot-card {
            border: 1px solid rgba(0,0,0,.125);
            border-radius: .75rem;
            background: #fff;
            box-shadow: 0 .125rem .25rem rgba(0,0,0,.075);
            margin-bottom: 1rem;
            overflow: hidden;
        }

        .mobile-lot-card .card-header-lite {
            background: #f8f9fa;
            padding: .85rem 1rem;
            border-bottom: 1px solid rgba(0,0,0,.08);
        }

        .mobile-lot-card .card-body-lite {
            padding: .75rem 1rem;
        }

        .mobile-lot-row {
            display: flex;
            justify-content: space-between;
            gap: 1rem;
            padding: .45rem 0;
            border-bottom: 1px solid rgba(0,0,0,.06);
        }

        .mobile-lot-row:last-child {
            border-bottom: 0;
        }

        .mobile-lot-label {
            flex: 0 0 48%;
            font-weight: 600;
            color: #495057;
        }

        .mobile-lot-value {
            flex: 0 0 52%;
            text-align: right;
            word-break: break-word;
        }

        .search-note {
            font-size: .9rem;
            color: #6c757d;
        }

        @media (max-width: 767.98px) {
            .desktop-table-wrap {
                display: none;
            }
        }

        @media (min-width: 768px) {
            .mobile-card-wrap {
                display: none;
            }
        }
    </style>
</head>
<body class="layout-fixed sidebar-expand-lg bg-body-tertiary">

<div class="app-wrapper">

    <main class="app-main">
        <div class="app-content-header">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-6">
                        <h3 class="mb-0">Lot Listing</h3>
                    </div>
                    <div class="col-sm-6 text-sm-end">
                        <a href="lotForm.php" class="btn btn-primary btn-sm">
                            <i class="bi bi-plus-circle"></i> Add Lot
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="app-content">
            <div class="container-fluid">

                <!-- Search Card -->
                <div class="card card-primary card-outline mb-4">
                    <div class="card-header">
                        <h3 class="card-title">Search Lots</h3>
                    </div>

                    <form method="get" action="lotsList.php">
                        <div class="card-body">
                            <div class="row g-3">
                                <div class="col-md-3">
                                    <label class="form-label">Lot ID</label>
                                    <input type="text" class="form-control" name="lot_id" value="<?php echo h($search_lot_id); ?>">
                                </div>

                                <div class="col-md-3">
                                    <label class="form-label">Owner</label>
                                    <input type="text" class="form-control" name="lot_owner" value="<?php echo h($search_lot_owner); ?>">
                                </div>

                                <div class="col-md-3">
                                    <label class="form-label">Contract ID</label>
                                    <input type="text" class="form-control" name="contract_id" value="<?php echo h($search_contract_id); ?>">
                                    <div class="search-note">Placeholder only until a contract ID column exists.</div>
                                </div>

                                <div class="col-md-3">
                                    <label class="form-label">In Transit</label>
                                    <select class="form-select" name="in_transit">
                                        <option value="">All</option>
                                        <option value="Y" <?php echo ($search_in_transit === 'Y') ? 'selected' : ''; ?>>Yes</option>
                                        <option value="N" <?php echo ($search_in_transit === 'N') ? 'selected' : ''; ?>>No</option>
                                    </select>
                                </div>

                                <div class="col-md-3">
                                    <label class="form-label">Ready for Transport</label>
                                    <select class="form-select" name="ready_for_transport">
                                        <option value="">All</option>
                                        <option value="Y" <?php echo ($search_ready_for_transport === 'Y') ? 'selected' : ''; ?>>Yes</option>
                                        <option value="N" <?php echo ($search_ready_for_transport === 'N') ? 'selected' : ''; ?>>No</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="card-footer">
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-search"></i> Search
                            </button>
                            <a href="lotsList.php" class="btn btn-secondary">
                                <i class="bi bi-arrow-clockwise"></i> Clear
                            </a>
                        </div>
                    </form>
                </div>

                <?php if ($db_error !== ''): ?>
                    <div class="alert alert-danger">
                        <?php echo h($db_error); ?>
                    </div>
                <?php endif; ?>

                <!-- Desktop Table -->
                <div class="card desktop-table-wrap">
                    <div class="card-header">
                        <h3 class="card-title">Lot Results</h3>
                        <div class="card-tools">
                            <span class="badge text-bg-primary"><?php echo count($rows); ?> record(s)</span>
                        </div>
                    </div>

                    <div class="card-body table-responsive p-0">
                        <table class="table table-striped table-hover align-middle mb-0">
                            <thead>
                                <tr>
                                    <th>LKey</th>
                                    <th>Lot ID</th>
                                    <th>Start Date</th>
                                    <th>Status</th>
                                    <th>Owner</th>
                                    <th>Contract Price</th>
                                    <th>Consigner</th>
                                    <th>Interim Payts</th>
                                    <th>Current Location</th>
                                    <th>Ready</th>
                                    <th>In Transit</th>
                                    <th>Animal Count</th>
                                    <th>Animal Weight</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php if (count($rows) > 0): ?>
                                <?php foreach ($rows as $row): ?>
                                    <tr>
                                        <td><a href="lotAdmin.php"><?php echo h($row['lkey']); ?> </a></td>
                                        <td><?php echo h($row['lot_id']); ?></td>
                                        <td><?php echo h($row['start_date']); ?></td>
                                        <td><?php echo statusBadge($row['lot_status']); ?></td>
                                        <td><?php echo h($row['lot_owner']); ?></td>
                                        <td><?php echo h(number_format((float)$row['lot_contract_price'], 2)); ?></td>
                                        <td><?php echo h($row['lot_consigner']); ?></td>
                                        <td><?php echo ynBadge($row['lot_interim_payts']); ?></td>
                                        <td><?php echo h($row['lot_current_location']); ?></td>
                                        <td><?php echo ynBadge($row['ready_for_transport']); ?></td>
                                        <td><?php echo ynBadge($row['in_transit']); ?></td>
                                        <td><?php echo h($row['animal_count']); ?></td>
                                        <td><?php echo h(number_format((float)$row['animal_weight'], 2)); ?></td>
                                    </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr>
                                    <td colspan="13" class="text-center py-4">No lots found.</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>

                <!-- Mobile Stacked Cards -->
                <div class="mobile-card-wrap">
                    <div class="mb-3">
                        <span class="badge text-bg-primary"><?php echo count($rows); ?> record(s)</span>
                    </div>

                    <?php if (count($rows) > 0): ?>
                        <?php foreach ($rows as $row): ?>
                            <div class="mobile-lot-card">
                                <div class="card-header-lite">
                                    <strong><a href="lotAdmin.php"><?php echo h($row['lot_id']); ?> </a></strong>
                                </div>

                                <div class="card-body-lite">

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">LKey</div>
                                        <div class="mobile-lot-value"><?php echo h($row['lkey']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Start Date</div>
                                        <div class="mobile-lot-value"><?php echo h($row['start_date']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Status</div>
                                        <div class="mobile-lot-value"><?php echo statusBadge($row['lot_status']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Owner</div>
                                        <div class="mobile-lot-value"><?php echo h($row['lot_owner']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Contract Price</div>
                                        <div class="mobile-lot-value"><?php echo h(number_format((float)$row['lot_contract_price'], 2)); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Consigner</div>
                                        <div class="mobile-lot-value"><?php echo h($row['lot_consigner']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Interim Payts</div>
                                        <div class="mobile-lot-value"><?php echo ynBadge($row['lot_interim_payts']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Current Location</div>
                                        <div class="mobile-lot-value"><?php echo h($row['lot_current_location']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Ready for Transport</div>
                                        <div class="mobile-lot-value"><?php echo ynBadge($row['ready_for_transport']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">In Transit</div>
                                        <div class="mobile-lot-value"><?php echo ynBadge($row['in_transit']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Animal Count</div>
                                        <div class="mobile-lot-value"><?php echo h($row['animal_count']); ?></div>
                                    </div>

                                    <div class="mobile-lot-row">
                                        <div class="mobile-lot-label">Animal Weight</div>
                                        <div class="mobile-lot-value"><?php echo h(number_format((float)$row['animal_weight'], 2)); ?></div>
                                    </div>

                                </div>
                            </div>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <div class="alert alert-info">No lots found.</div>
                    <?php endif; ?>
                </div>

            </div>
        </div>
    </main>

</div>

<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.min.js"></script>
<script src="./js/adminlte.js"></script>


















            <!--end::Row-->
            <!--end::Row-->
            <!--end::Row-->



            </div>
            <!--end::Row-->

    </div>
    <center><b>Profile (620)</b></center>
</div>


<hr><hr>

        <div class="app-content">
          <!--begin::Container-->
          <div class="container-fluid">
            <!--begin::Row-->
            <div class="row">
              <div class="col-lg-6">

this is another row

              </div>
            <!-- /.row (main row) -->
          </div>
          <!--end::Container-->
        </div>
        <!--end::App Content-->
      </main>
      <!--end::App Main-->

      <!--begin::Footer-->
        <?php include "includes/footer.php"; ?>
      <!--end::Footer-->





    </div>
    <!--end::App Wrapper-->
    <!--begin::Script-->
    <!--begin::Third Party Plugin(OverlayScrollbars)-->
    <script
      src="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.11.0/browser/overlayscrollbars.browser.es6.min.js"
      crossorigin="anonymous"
    ></script>
    <!--end::Third Party Plugin(OverlayScrollbars)--><!--begin::Required Plugin(popperjs for Bootstrap 5)-->
    <script
      src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"
      crossorigin="anonymous"
    ></script>
    <!--end::Required Plugin(popperjs for Bootstrap 5)--><!--begin::Required Plugin(Bootstrap 5)-->
    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.min.js"
      crossorigin="anonymous"
    ></script>
    <!--end::Required Plugin(Bootstrap 5)--><!--begin::Required Plugin(AdminLTE)-->
    <script src="./js/adminlte.js"></script>
    <!--end::Required Plugin(AdminLTE)--><!--begin::OverlayScrollbars Configure-->
    <script>
      const SELECTOR_SIDEBAR_WRAPPER = '.sidebar-wrapper';
      const Default = {
        scrollbarTheme: 'os-theme-light',
        scrollbarAutoHide: 'leave',
        scrollbarClickScroll: true,
      };
      document.addEventListener('DOMContentLoaded', function () {
        const sidebarWrapper = document.querySelector(SELECTOR_SIDEBAR_WRAPPER);
        if (sidebarWrapper && OverlayScrollbarsGlobal?.OverlayScrollbars !== undefined) {
          OverlayScrollbarsGlobal.OverlayScrollbars(sidebarWrapper, {
            scrollbars: {
              theme: Default.scrollbarTheme,
              autoHide: Default.scrollbarAutoHide,
              clickScroll: Default.scrollbarClickScroll,
            },
          });
        }
      });
    </script>
    <!--end::OverlayScrollbars Configure-->
    <!-- OPTIONAL SCRIPTS -->
    <!-- sortablejs -->
    <script
      src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"
      crossorigin="anonymous"
    ></script>
    <!-- sortablejs -->
    <script>
      new Sortable(document.querySelector('.connectedSortable'), {
        group: 'shared',
        handle: '.card-header',
      });

      const cardHeaders = document.querySelectorAll('.connectedSortable .card-header');
      cardHeaders.forEach((cardHeader) => {
        cardHeader.style.cursor = 'move';
      });
    </script>
    <!-- apexcharts -->
    <script
      src="https://cdn.jsdelivr.net/npm/apexcharts@3.37.1/dist/apexcharts.min.js"
      integrity="sha256-+vh8GkaU7C9/wbSLIcwq82tQ2wTf44aOHA8HlBMwRI8="
      crossorigin="anonymous"
    ></script>
    <!-- ChartJS -->
    <script>
      // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
      // IT'S ALL JUST JUNK FOR DEMO
      // ++++++++++++++++++++++++++++++++++++++++++

      const sales_chart_options = {
        series: [
          {
            name: 'Digital Goods',
            data: [28, 48, 40, 19, 86, 27, 90],
          },
          {
            name: 'Electronics',
            data: [65, 59, 80, 81, 56, 55, 40],
          },
        ],
        chart: {
          height: 300,
          type: 'area',
          toolbar: {
            show: false,
          },
        },
        legend: {
          show: false,
        },
        colors: ['#0d6efd', '#20c997'],
        dataLabels: {
          enabled: false,
        },
        stroke: {
          curve: 'smooth',
        },
        xaxis: {
          type: 'datetime',
          categories: [
            '2023-01-01',
            '2023-02-01',
            '2023-03-01',
            '2023-04-01',
            '2023-05-01',
            '2023-06-01',
            '2023-07-01',
          ],
        },
        tooltip: {
          x: {
            format: 'MMMM yyyy',
          },
        },
      };

      const sales_chart = new ApexCharts(
        document.querySelector('#revenue-chart'),
        sales_chart_options,
      );
      sales_chart.render();
    </script>
    <!-- jsvectormap -->
    <script
      src="https://cdn.jsdelivr.net/npm/jsvectormap@1.5.3/dist/js/jsvectormap.min.js"
      integrity="sha256-/t1nN2956BT869E6H4V1dnt0X5pAQHPytli+1nTZm2Y="
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdn.jsdelivr.net/npm/jsvectormap@1.5.3/dist/maps/world.js"
      integrity="sha256-XPpPaZlU8S/HWf7FZLAncLg2SAkP8ScUTII89x9D3lY="
      crossorigin="anonymous"
    ></script>
    <!-- jsvectormap -->
    <script>
      // World map by jsVectorMap
      new jsVectorMap({
        selector: '#world-map',
        map: 'world',
      });

      // Sparkline charts
      const option_sparkline1 = {
        series: [
          {
            data: [1000, 1200, 920, 927, 931, 1027, 819, 930, 1021],
          },
        ],
        chart: {
          type: 'area',
          height: 50,
          sparkline: {
            enabled: true,
          },
        },
        stroke: {
          curve: 'straight',
        },
        fill: {
          opacity: 0.3,
        },
        yaxis: {
          min: 0,
        },
        colors: ['#DCE6EC'],
      };

      const sparkline1 = new ApexCharts(document.querySelector('#sparkline-1'), option_sparkline1);
      sparkline1.render();

      const option_sparkline2 = {
        series: [
          {
            data: [515, 519, 520, 522, 652, 810, 370, 627, 319, 630, 921],
          },
        ],
        chart: {
          type: 'area',
          height: 50,
          sparkline: {
            enabled: true,
          },
        },
        stroke: {
          curve: 'straight',
        },
        fill: {
          opacity: 0.3,
        },
        yaxis: {
          min: 0,
        },
        colors: ['#DCE6EC'],
      };

      const sparkline2 = new ApexCharts(document.querySelector('#sparkline-2'), option_sparkline2);
      sparkline2.render();

      const option_sparkline3 = {
        series: [
          {
            data: [15, 19, 20, 22, 33, 27, 31, 27, 19, 30, 21],
          },
        ],
        chart: {
          type: 'area',
          height: 50,
          sparkline: {
            enabled: true,
          },
        },
        stroke: {
          curve: 'straight',
        },
        fill: {
          opacity: 0.3,
        },
        yaxis: {
          min: 0,
        },
        colors: ['#DCE6EC'],
      };

      const sparkline3 = new ApexCharts(document.querySelector('#sparkline-3'), option_sparkline3);
      sparkline3.render();
    </script>
    <!--end::Script-->
  </body>
  <!--end::Body-->
</html>
