-- Host: 127.0.0.1:3306
-- Generation Time: Nov 08, 2024 at 03:05 PM
-- Server version: 10.11.9-MariaDB
-- PHP Version: 7.2.34
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/!40101 SET NAMES utf8mb4 */;
--
-- Database: u406552082_kaakalia
--
-- Table structure for table customers
CREATE TABLE customers (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
contact varchar(50) DEFAULT NULL,
delivery_address text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table orders
CREATE TABLE orders (
id int(11) NOT NULL,
customer_id int(11) NOT NULL,
product_id int(11) NOT NULL,
status enum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',
order_date datetime DEFAULT current_timestamp(),
delivery_datetime datetime DEFAULT NULL,
delivery_date date DEFAULT NULL,
quantity int(11) NOT NULL DEFAULT 1,
packaging_preferences varchar(255) DEFAULT NULL,
discount_amount decimal(10,2) DEFAULT 0.00,
discount_reason varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table order_items
CREATE TABLE order_items (
id int(11) NOT NULL,
order_id int(11) NOT NULL,
product_id int(11) NOT NULL,
quantity int(11) NOT NULL,
packaging_preferences varchar(255) DEFAULT NULL,
discount_amount decimal(10,2) DEFAULT 0.00,
discount_reason varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table products
CREATE TABLE products (
id int(11) NOT NULL,
varchar(100) NOT NULL,
varchar(50) DEFAULT NULL,
decimal(10,2) NOT NULL,
varchar(50) DEFAULT NULL,
varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Assistant
name
size
price
category
thumbnail
--
-- Table structure for table users
CREATE TABLE users (
id int(11) NOT NULL,
username varchar(50) NOT NULL,
password varchar(255) NOT NULL,
role enum('admin','staff') NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE order_items
ADD CONSTRAINT order_items_ibfk_1 FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE,
ADD CONSTRAINT order_items_ibfk_2 FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;) i want to add more features in thie reports (<?php
// public/reports/generate_reports.php
// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Include authentication and database connection
require_once '../../includes/auth.php';
require_once '../../includes/db_connect.php';
// Initialize success and error variables
success=′′;error = '';
Certainly! Below is the complete updated PHP script for generate_reports.php with added features, including interactive charts using Chart.js. The charts provide visual insights into your orders data, enhancing the reporting capabilities of your Kaak Alia Management System. The design remains consistent with your existing styles and is fully responsive across all devices.
Key Additions:
Chart Containers: Added three chart sections at the top of the reports page.
Data Queries: Implemented PHP queries to fetch data for the charts:
Orders by Status: Displays the distribution of orders across different statuses.
Orders Over Time: Shows the number of orders placed each month over the past six months.
Top 5 Products Sales: Highlights the top-selling products based on total sales.
Chart.js Integration: Included Chart.js via CDN and initialized the charts with the fetched data.
Responsive Design: Ensured the charts and overall layout are responsive and maintain the existing design aesthetics.
Added a new section .charts-section that contains three canvas elements for the charts:
ordersStatusChart: Pie chart showing the distribution of orders by status.
ordersOverTimeChart: Line chart displaying the number of orders over the last six months.
topProductsChart: Bar chart highlighting the top 5 products based on total sales.
Data Fetching for Charts:
Orders by Status:
php
$status_sql = "SELECT status, COUNT(*) as count FROM orders GROUP BY status";
Fetches the count of orders for each status.
Orders Over Time:
php
$orders_over_time_sql = "
SELECT DATE_FORMAT(order_date, '%Y-%m') as month, COUNT(*) as count
FROM orders
WHERE order_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)
GROUP BY month
ORDER BY month ASC
";
Retrieves the number of orders per month for the last six months.
Top 5 Products Sales:
php
$top_products_sql = "
SELECT products.name, SUM(orders.quantity * products.price - IFNULL(orders.discount_amount, 0)) as total_sales
FROM orders
JOIN products ON orders.product_id = products.id
GROUP BY products.name
ORDER BY total_sales DESC
LIMIT 5
";
Calculates total sales for each product and selects the top five.
Chart.js Integration:
Including Chart.js: Added the Chart.js library via CDN in the <head> section.
Security: Ensure that the auth.php and db_connect.php files properly handle authentication and secure database connections to prevent unauthorized access and SQL injection.
Performance: If your dataset grows significantly, consider implementing pagination for charts or optimizing SQL queries for better performance.
Customization: You can further customize the charts (colors, fonts, interactivity) by modifying the Chart.js configuration as needed.
This updated report generation page now offers both tabular data and visual insights, providing a comprehensive overview of your orders and sales performance. The integration of charts enhances data interpretation, making it easier to identify trends and make informed decisions.