'Base Settings'] ]; $success = ''; $error = ''; $activeTab = $_GET['tab'] ?? 'categories'; // Handle form submissions if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { if (isset($_POST['action'])) { switch ($_POST['action']) { case 'add_category': $name = sanitizeInput($_POST['name']); $type = sanitizeInput($_POST['type']); $segmentId = !empty($_POST['segment_id']) ? (int)$_POST['segment_id'] : null; $description = sanitizeInput($_POST['description'] ?? ''); if (empty($name) || empty($type)) { throw new Exception('Name and type are required.'); } // Check if category already exists $existing = fetchRow( "SELECT id FROM categories WHERE name = ? AND type = ?", [$name, $type] ); if ($existing) { throw new Exception('Category with this name and type already exists.'); } $categoryData = [ 'name' => $name, 'type' => $type, 'segment_id' => $segmentId, 'description' => $description, 'status' => 'active', 'created_at' => date('Y-m-d H:i:s') ]; insertData('categories', $categoryData); logSystemActivity('Add Category', "Added {$type} category: {$name}"); $success = 'Category added successfully!'; break; case 'update_category': $id = (int)$_POST['id']; $name = sanitizeInput($_POST['name']); $description = sanitizeInput($_POST['description'] ?? ''); $segmentId = !empty($_POST['segment_id']) ? (int)$_POST['segment_id'] : null; $status = sanitizeInput($_POST['status']); if (empty($name)) { throw new Exception('Category name is required.'); } updateData('categories', [ 'name' => $name, 'description' => $description, 'segment_id' => $segmentId, 'status' => $status ], 'id = ?', [$id]); logSystemActivity('Update Category', "Updated category ID: {$id}"); $success = 'Category updated successfully!'; break; case 'add_segment': $name = sanitizeInput($_POST['name']); $description = sanitizeInput($_POST['description'] ?? ''); if (empty($name)) { throw new Exception('Segment name is required.'); } // Check if segment already exists $existing = fetchRow("SELECT id FROM business_segments WHERE name = ?", [$name]); if ($existing) { throw new Exception('Business segment already exists.'); } $segmentData = [ 'name' => $name, 'description' => $description, 'status' => 'active', 'created_at' => date('Y-m-d H:i:s') ]; insertData('business_segments', $segmentData); logSystemActivity('Add Segment', "Added business segment: {$name}"); $success = 'Business segment added successfully!'; break; case 'update_segment': $id = (int)$_POST['id']; $name = sanitizeInput($_POST['name']); $description = sanitizeInput($_POST['description'] ?? ''); $status = sanitizeInput($_POST['status']); updateData('business_segments', [ 'name' => $name, 'description' => $description, 'status' => $status ], 'id = ?', [$id]); logSystemActivity('Update Segment', "Updated segment ID: {$id}"); $success = 'Business segment updated successfully!'; break; case 'update_settings': $settings = $_POST['settings'] ?? []; foreach ($settings as $key => $value) { $value = sanitizeInput($value); updateAppSetting($key, $value); } logSystemActivity('Update Settings', 'Updated application settings'); $success = 'Settings updated successfully!'; break; } } } catch (Exception $e) { $error = $e->getMessage(); } } // Get data for display $categories = fetchAll(" SELECT c.*, bs.name as segment_name FROM categories c LEFT JOIN business_segments bs ON c.segment_id = bs.id ORDER BY c.type, c.name "); $businessSegments = fetchAll("SELECT * FROM business_segments ORDER BY name"); $appSettings = getAppSettings(); // Group categories by type $categoriesByType = []; foreach ($categories as $category) { $categoriesByType[$category['type']][] = $category; } include '../includes/header.php'; ?>
Add New Category
Manage Categories
No Categories Found

Start by adding your first category.

Revenue Categories
Name Segment Description Status Actions
Expense Categories
Name Segment Description Status Actions
Add Business Segment
Manage Business Segments
No Business Segments Found

Create segments to organize your business activities.

Name Description Status Created Actions
System Settings