prepare("SELECT COUNT(*) FROM orders " . $pending_orders_where_clause); $stmt->execute($params); $pending_orders_count = $stmt->fetchColumn(); // Pending Replies Count (Orders with status 'Query' or 'Query Replied') $pending_replies_conditions_arr = $base_conditions_arr; $pending_replies_conditions_arr[] = "(status = 'Query' OR status = 'Query Replied')"; $pending_replies_where_clause = ''; if (!empty($pending_replies_conditions_arr)) { $pending_replies_where_clause = " WHERE " . implode(" AND ", $pending_replies_conditions_arr); } $stmt = $pdo->prepare("SELECT COUNT(*) FROM orders " . $pending_replies_where_clause); $stmt->execute($params); $pending_replies_count = $stmt->fetchColumn(); // Shipped Orders This Month Count $current_month_start = date('Y-m-01 00:00:00'); $current_month_end = date('Y-m-t 23:59:59'); $shipped_conditions_arr = $base_conditions_arr; $shipped_conditions_arr[] = "status = 'Shipped'"; $shipped_conditions_arr[] = "created_at >= :start_date"; $shipped_conditions_arr[] = "created_at <= :end_date"; $shipped_where_clause = ''; $shipped_params = $params; $shipped_params[':start_date'] = $current_month_start; $shipped_params[':end_date'] = $current_month_end; if (!empty($shipped_conditions_arr)) { $shipped_where_clause = " WHERE " . implode(" AND ", $shipped_conditions_arr); } $stmt = $pdo->prepare("SELECT COUNT(*) FROM orders " . $shipped_where_clause); $stmt->execute($shipped_params); $shipped_orders_month_count = $stmt->fetchColumn(); // --- Fetch Order List --- $orders = []; $sql = "SELECT o.id, o.order_number, o.order_date, o.order_text, o.status, o.sales_rep_id, u.name as sales_rep_name FROM orders o JOIN users u ON o.sales_rep_id = u.id"; if ($user_role === 'Sales Rep') { $sql .= " WHERE o.sales_rep_id = :user_id"; $stmt = $pdo->prepare($sql); $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); } else { // Dispatch and Admin can see all orders $stmt = $pdo->prepare($sql); } $stmt->execute(); $orders = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { error_log("Database error fetching dashboard data or orders: " . $e->getMessage()); echo ''; } ?>
Pending Orders

Pending Replies

Shipped This Month

Welcome, !

Your current role:

Order List

No orders found.

Order Number Date Sales Rep Text Status Actions
... View Edit