38682-vm/includes/functions.php
2026-02-22 10:13:38 +00:00

35 lines
1.1 KiB
PHP

<?php
// Function to fetch company settings from DB
function get_company_settings() {
static $settings = null;
if ($settings === null) {
$pdo = db();
try {
$stmt = $pdo->query("SELECT * FROM company_settings LIMIT 1");
$settings = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (Exception $e) {
// Log error or ignore if table doesn't exist yet
}
// Default values if no settings found
if (!$settings) {
$settings = [
'company_name' => 'My Restaurant',
'address' => '123 Food Street',
'phone' => '555-0199',
'email' => 'info@restaurant.com',
'vat_rate' => 0.00,
'currency_symbol' => '$',
'currency_decimals' => 2
];
}
}
return $settings;
}
// Function to format currency using settings
function format_currency($amount) {
$settings = get_company_settings();
return $settings['currency_symbol'] . number_format((float)$amount, (int)$settings['currency_decimals']);
}