<?php
include("../../classes/manager.class.php");
$m = new Manager();

$cat_type = $_REQUEST['cat_type']; // Get the cat_type (All, Wholesaler, Local Mart)

// Category Filter Logic Based on Cat Type
$categoryFilter = " JOIN customer_setup ON customer_category.id = customer_setup.category_id 
                    WHERE customer_setup.status = 'active' ";

// Filter for cat_type
if ($cat_type == '0') {
    $categoryFilter .= " AND customer_setup.is_mart = 0 "; // Wholesaler
} elseif ($cat_type == '1') {
    $categoryFilter .= " AND customer_setup.is_mart = 1 "; // Local Mart
}

// Group by Category and Order by Category Name
$categoryFilter .= " GROUP BY customer_category.id ORDER BY customer_category.name";

$categories = CustomerCategorySetup::GetCustomerCategorySetupList($categoryFilter);

if ($categories) {
    echo '<option value="All">All</option>';
    $count = 1; // Initialize counter for numbering
    foreach ($categories as $categoriesRow) {
        echo '<option value="' . $categoriesRow->catid . '">' . $categoriesRow->catname . ' (' . $count . ')</option>';
        $count++; // Increment counter
    }
} else {
    echo '<option>No Categories Found</option>';
}
?>
