<?php
session_start();
header('Content-Type: application/json');
include_once('../includes/config.php');

if (!isset($_SESSION['uid'])) {
    echo json_encode(['success' => false, 'message' => 'Unauthorized']);
    exit();
}

$query = "SELECT ID, SalesType, InvoicePrefix, Description FROM tblsales_type_config WHERE IsActive = 1 ORDER BY SalesType";
$result = mysqli_query($con, $query);

$salesTypes = [];
if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        $salesTypes[] = $row;
    }
}

echo json_encode([
    'success' => true,
    'data' => $salesTypes
]);
?>
