From 9b5a06451f820683a282df8e25a4583858d9d267 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Mon, 10 Nov 2025 04:11:47 +0000 Subject: [PATCH] SInarKasih --- _export_sales_report.php | 71 ++++ _get_best_selling_products.php | 27 ++ _get_sale_items.php | 22 ++ _get_sales_data.php | 42 +++ _handle_add_product.php | 32 ++ _handle_checkout.php | 67 ++++ _handle_delete_product.php | 30 ++ _handle_edit_product.php | 39 +++ _handle_login.php | 40 +++ _handle_register.php | 48 +++ assets/css/custom.css | 58 ++++ catalog.php | 41 +++ db/config.php | 40 ++- db/migrations/001_create_products_table.sql | 9 + db/migrations/002_create_sales_tables.sql | 17 + db/migrations/003_create_users_table.sql | 8 + includes/auth.php | 16 + includes/footer.php | 8 + includes/header.php | 79 +++++ index.php | 351 ++++++++++++-------- login.php | 55 +++ logout.php | 7 + pos.php | 196 +++++++++++ product_add.php | 41 +++ product_edit.php | 63 ++++ products.php | 70 ++++ receipt.php | 134 ++++++++ register.php | 70 ++++ reports.php | 192 +++++++++++ 29 files changed, 1723 insertions(+), 150 deletions(-) create mode 100644 _export_sales_report.php create mode 100644 _get_best_selling_products.php create mode 100644 _get_sale_items.php create mode 100644 _get_sales_data.php create mode 100644 _handle_add_product.php create mode 100644 _handle_checkout.php create mode 100644 _handle_delete_product.php create mode 100644 _handle_edit_product.php create mode 100644 _handle_login.php create mode 100644 _handle_register.php create mode 100644 assets/css/custom.css create mode 100644 catalog.php create mode 100644 db/migrations/001_create_products_table.sql create mode 100644 db/migrations/002_create_sales_tables.sql create mode 100644 db/migrations/003_create_users_table.sql create mode 100644 includes/auth.php create mode 100644 includes/footer.php create mode 100644 includes/header.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 pos.php create mode 100644 product_add.php create mode 100644 product_edit.php create mode 100644 products.php create mode 100644 receipt.php create mode 100644 register.php create mode 100644 reports.php diff --git a/_export_sales_report.php b/_export_sales_report.php new file mode 100644 index 0000000..f59af43 --- /dev/null +++ b/_export_sales_report.php @@ -0,0 +1,71 @@ += ?"; + $params[] = $start_date . ' 00:00:00'; +} +if ($end_date) { + $conditions[] = "s.sale_date <= ?"; + $params[] = $end_date . ' 23:59:59'; +} +if ($payment_method) { + $conditions[] = "s.payment_method = ?"; + $params[] = $payment_method; +} + +if (count($conditions) > 0) { + $sql .= " WHERE " . implode(' AND ', $conditions); +} + +$sql .= " GROUP BY s.id ORDER BY s.sale_date DESC"; + +$stmt = $pdo->prepare($sql); +$stmt->execute($params); +$sales = $stmt->fetchAll(PDO::FETCH_ASSOC); + +// CSV generation +$filename = "sales_report_" . date('Y-m-d') . ".csv"; + +header('Content-Type: text/csv'); +header('Content-Disposition: attachment; filename="' . $filename . '"'); + +$output = fopen('php://output', 'w'); + +// Add BOM to support UTF-8 in Excel +fputs($output, "\xEF\xBB\xBF"); + +// Header row +fputcsv($output, ['Sale ID', 'Date', 'Total Amount', 'Payment Method', 'Items']); + +// Data rows +foreach ($sales as $sale) { + fputcsv($output, [ + $sale['id'], + $sale['sale_date'], + number_format($sale['total_amount'], 2), + $sale['payment_method'], + $sale['items'] + ]); +} + +fclose($output); +exit; diff --git a/_get_best_selling_products.php b/_get_best_selling_products.php new file mode 100644 index 0000000..359c17b --- /dev/null +++ b/_get_best_selling_products.php @@ -0,0 +1,27 @@ +query(" + SELECT + p.name, + SUM(si.quantity) as total_quantity + FROM sale_items si + JOIN products p ON si.product_id = p.id + GROUP BY p.name + ORDER BY total_quantity DESC + LIMIT 5 + "); + + $best_selling_products = $stmt->fetchAll(PDO::FETCH_ASSOC); + + header('Content-Type: application/json'); + echo json_encode($best_selling_products); + +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['error' => 'Database error: ' . $e->getMessage()]); +} +?> \ No newline at end of file diff --git a/_get_sale_items.php b/_get_sale_items.php new file mode 100644 index 0000000..2ec0245 --- /dev/null +++ b/_get_sale_items.php @@ -0,0 +1,22 @@ + 'Sale ID not provided.']); + exit; +} + +$sale_id = $_GET['sale_id']; +$pdo = db(); + +$stmt = $pdo->prepare(" + SELECT si.quantity, si.price, p.name as product_name + FROM sale_items si + JOIN products p ON si.product_id = p.id + WHERE si.sale_id = ? +"); +$stmt->execute([$sale_id]); +$items = $stmt->fetchAll(PDO::FETCH_ASSOC); + +echo json_encode($items); diff --git a/_get_sales_data.php b/_get_sales_data.php new file mode 100644 index 0000000..c69e682 --- /dev/null +++ b/_get_sales_data.php @@ -0,0 +1,42 @@ +prepare($sql); +$stmt->bindParam(':start_date', $p_start_date, PDO::PARAM_STR); +$stmt->bindParam(':end_date', $p_end_date, PDO::PARAM_STR); +$stmt->execute(); + +$sales_data = $stmt->fetchAll(PDO::FETCH_ASSOC); + +$labels = []; +$data = []; + +foreach ($sales_data as $row) { + $labels[] = date('M d', strtotime($row['sale_date'])); + $data[] = $row['daily_total']; +} + +echo json_encode(['labels' => $labels, 'data' => $data]); diff --git a/_handle_add_product.php b/_handle_add_product.php new file mode 100644 index 0000000..3cbee73 --- /dev/null +++ b/_handle_add_product.php @@ -0,0 +1,32 @@ +prepare("INSERT INTO products (name, sku, category, price, stock) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$name, $sku, $category, $price, $stock]); + + // Redirect to product list on success + header('Location: products.php?success=Product+added'); + exit; + } catch (PDOException $e) { + // Handle error, e.g., duplicate SKU + // For now, we'll just redirect with a generic error + error_log($e->getMessage()); + header('Location: product_add.php?error=Could+not+add+product'); + exit; + } +} diff --git a/_handle_checkout.php b/_handle_checkout.php new file mode 100644 index 0000000..7e6f437 --- /dev/null +++ b/_handle_checkout.php @@ -0,0 +1,67 @@ + false, 'message' => 'An unknown error occurred.']; + +if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + http_response_code(405); + $response['message'] = 'Invalid request method.'; + echo json_encode($response); + exit; +} + +$data = json_decode(file_get_contents('php://input'), true); +$cart = $data['cart'] ?? []; +$paymentMethod = $data['payment_method'] ?? 'Cash'; + +if (empty($cart)) { + http_response_code(400); + $response['message'] = 'Cart is empty.'; + echo json_encode($response); + exit; +} + +$pdo = db(); +try { + $pdo->beginTransaction(); + + $totalAmount = 0; + foreach ($cart as $item) { + $totalAmount += $item['price'] * $item['quantity']; + } + + $transactionId = 'TXN-' . strtoupper(uniqid()); + $stmt = $pdo->prepare("INSERT INTO sales (transaction_id, total_amount, payment_method) VALUES (?, ?, ?)"); + $stmt->execute([$transactionId, $totalAmount, $paymentMethod]); + $saleId = $pdo->lastInsertId(); + + $itemStmt = $pdo->prepare("INSERT INTO sale_items (sale_id, product_id, quantity, price) VALUES (?, ?, ?, ?)"); + $stockStmt = $pdo->prepare("UPDATE products SET stock = stock - ? WHERE id = ?"); + + foreach ($cart as $item) { + $productId = $item['id']; + $quantity = $item['quantity']; + $price = $item['price']; + + $itemStmt->execute([$saleId, $productId, $quantity, $price]); + $stockStmt->execute([$quantity, $productId]); + } + + $pdo->commit(); + + $response['success'] = true; + $response['message'] = 'Checkout successful!'; + $response['transaction_id'] = $transactionId; + http_response_code(200); + +} catch (Exception $e) { + if ($pdo->inTransaction()) { + $pdo->rollBack(); + } + http_response_code(500); + $response['message'] = 'Checkout failed: ' . $e->getMessage(); +} + +echo json_encode($response); diff --git a/_handle_delete_product.php b/_handle_delete_product.php new file mode 100644 index 0000000..90e3f0b --- /dev/null +++ b/_handle_delete_product.php @@ -0,0 +1,30 @@ +prepare('DELETE FROM products WHERE id = ?'); + $stmt->execute([$id]); + + // Check if any row was deleted + if ($stmt->rowCount() > 0) { + header('Location: products.php?status=deleted'); + } else { + header('Location: products.php?error=not_found'); + } + exit; +} catch (PDOException $e) { + // Handle DB error + // error_log($e->getMessage()); + header('Location: products.php?error=db'); + exit; +} diff --git a/_handle_edit_product.php b/_handle_edit_product.php new file mode 100644 index 0000000..7c0ac14 --- /dev/null +++ b/_handle_edit_product.php @@ -0,0 +1,39 @@ +prepare( + 'UPDATE products SET name = ?, sku = ?, category = ?, price = ?, stock = ? WHERE id = ?' + ); + $stmt->execute([$name, $sku, $category, $price, $stock, $id]); + + // Redirect to products list on success + header('Location: products.php?status=updated'); + exit; + } catch (PDOException $e) { + // Handle DB error, e.g., log error and redirect + // For development, you might want to see the error + // error_log($e->getMessage()); + header('Location: product_edit.php?id=' . $id . '&error=db'); + exit; + } +} + +// Redirect if accessed directly +header('Location: products.php'); +exit; diff --git a/_handle_login.php b/_handle_login.php new file mode 100644 index 0000000..0e34386 --- /dev/null +++ b/_handle_login.php @@ -0,0 +1,40 @@ + false, 'message' => 'Invalid username or password.']; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $username = $_POST['username'] ?? ''; + $password = $_POST['password'] ?? ''; + + if (empty($username) || empty($password)) { + $response['message'] = 'Username and password are required.'; + echo json_encode($response); + exit; + } + + try { + $pdo = db(); + + $stmt = $pdo->prepare("SELECT id, username, password FROM users WHERE username = ?"); + $stmt->execute([$username]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + $response['success'] = true; + $response['message'] = 'Login successful.'; + } else { + $response['message'] = 'Invalid username or password.'; + } + } catch (PDOException $e) { + $response['message'] = 'Database error: ' . $e->getMessage(); + } + + echo json_encode($response); +} +?> \ No newline at end of file diff --git a/_handle_register.php b/_handle_register.php new file mode 100644 index 0000000..5ef740f --- /dev/null +++ b/_handle_register.php @@ -0,0 +1,48 @@ + false, 'message' => 'An error occurred.']; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $username = $_POST['username'] ?? ''; + $password = $_POST['password'] ?? ''; + + if (empty($username) || empty($password)) { + $response['message'] = 'Username and password are required.'; + echo json_encode($response); + exit; + } + + try { + $pdo = db(); + + // Check if username already exists + $stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?"); + $stmt->execute([$username]); + if ($stmt->fetch()) { + $response['message'] = 'Username already taken.'; + echo json_encode($response); + exit; + } + + // Hash the password + $password_hash = password_hash($password, PASSWORD_DEFAULT); + + // Insert the new user + $stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (?, ?)"); + if ($stmt->execute([$username, $password_hash])) { + $response['success'] = true; + $response['message'] = 'Registration successful. You can now log in.'; + } else { + $response['message'] = 'Failed to register user.'; + } + } catch (PDOException $e) { + // In a real application, you would log this error. + $response['message'] = 'Database error: ' . $e->getMessage(); + } + + echo json_encode($response); +} +?> \ No newline at end of file diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..f0850e0 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,58 @@ +/* +SinarKasihMart Custom Styles +Primary: #0d6efd (Blue) +Secondary: #198754 (Green) +*/ + +body { + background-color: #f8f9fa; +} + +.navbar { + margin-bottom: 1.5rem; +} + +.card { + border-radius: 0.375rem; + box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); +} + +.btn-primary { + background-color: #0d6efd; + border-color: #0d6efd; +} + +.btn-success { + background-color: #198754; + border-color: #198754; +} + +.nav-link.active { + font-weight: 500; +} + +.product-card { + transition: transform .2s ease-in-out, box-shadow .2s ease-in-out; +} + +.product-card:hover { + transform: translateY(-5px); + box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); +} + +#saleItemsModal .modal-body { + max-height: 400px; + overflow-y: auto; +} + +#salesChart { + max-height: 320px; +} + +#bestSellingChart { + max-height: 320px; +} + +.chart-container { + height: 400px; /* Adjust as needed */ +} diff --git a/catalog.php b/catalog.php new file mode 100644 index 0000000..f82a4fa --- /dev/null +++ b/catalog.php @@ -0,0 +1,41 @@ +query('SELECT * FROM products WHERE stock > 0 ORDER BY created_at DESC'); +$products = $stmt->fetchAll(); + +?> + +
+

Product Catalog

+ +
+ +
+

No products are currently available.

+
+ + +
+
+
+
+

+

Rp

+
+ +
+
+ + +
+
+ + diff --git a/db/config.php b/db/config.php index 742ca86..1b03b22 100644 --- a/db/config.php +++ b/db/config.php @@ -8,10 +8,42 @@ define('DB_PASS', '6ba26df8-c17d-4aa6-b713-e17374a6fbd9'); function db() { static $pdo; if (!$pdo) { - $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [ - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); + try { + $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ]); + } catch (PDOException $e) { + // If database doesn't exist, create it + if ($e->getCode() == 1049) { + try { + $tempPdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS); + $tempPdo->exec('CREATE DATABASE IF NOT EXISTS '.DB_NAME.' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci'); + $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ]); + } catch (PDOException $e2) { + die('DB ERROR: Could not create database. ' . $e2->getMessage()); + } + } else { + die('DB ERROR: ' . $e->getMessage()); + } + } } return $pdo; } + +function run_migrations() { + $pdo = db(); + $migration_files = glob(__DIR__ . '/migrations/*.sql'); + foreach ($migration_files as $file) { + $sql = file_get_contents($file); + try { + $pdo->exec($sql); + } catch (PDOException $e) { + // You might want to log this error instead of dying + error_log('Migration failed for file ' . basename($file) . ': ' . $e->getMessage()); + } + } +} diff --git a/db/migrations/001_create_products_table.sql b/db/migrations/001_create_products_table.sql new file mode 100644 index 0000000..79b7af7 --- /dev/null +++ b/db/migrations/001_create_products_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS products ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + sku VARCHAR(100) UNIQUE, + category VARCHAR(100), + price DECIMAL(10, 2) NOT NULL, + stock INT NOT NULL DEFAULT 0, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/migrations/002_create_sales_tables.sql b/db/migrations/002_create_sales_tables.sql new file mode 100644 index 0000000..202afcb --- /dev/null +++ b/db/migrations/002_create_sales_tables.sql @@ -0,0 +1,17 @@ +CREATE TABLE IF NOT EXISTS sales ( + id INT AUTO_INCREMENT PRIMARY KEY, + transaction_id VARCHAR(255) NOT NULL UNIQUE, + total_amount DECIMAL(10, 2) NOT NULL, + payment_method VARCHAR(50) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS sale_items ( + id INT AUTO_INCREMENT PRIMARY KEY, + sale_id INT NOT NULL, + product_id INT NOT NULL, + quantity INT NOT NULL, + price DECIMAL(10, 2) NOT NULL, + FOREIGN KEY (sale_id) REFERENCES sales(id) ON DELETE CASCADE, + FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE SET NULL +); diff --git a/db/migrations/003_create_users_table.sql b/db/migrations/003_create_users_table.sql new file mode 100644 index 0000000..55f9b3a --- /dev/null +++ b/db/migrations/003_create_users_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(50) NOT NULL, + `password` varchar(255) NOT NULL, + `created_at` datetime DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; diff --git a/includes/auth.php b/includes/auth.php new file mode 100644 index 0000000..994e4e5 --- /dev/null +++ b/includes/auth.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..a94e9bf --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..6363b5c --- /dev/null +++ b/includes/header.php @@ -0,0 +1,79 @@ + + + + + + + SinarKasihMart + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/index.php b/index.php index 7205f3d..363aebb 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,209 @@ query('SELECT COUNT(*) FROM products')->fetchColumn(); + +// Today's Sales +$today = date('Y-m-d'); +$stmt_today = db()->prepare("SELECT COUNT(*) as num_transactions, SUM(total_amount) as total_sales FROM sales WHERE DATE(sale_date) = ?"); +$stmt_today->execute([$today]); +$today_sales = $stmt_today->fetch(PDO::FETCH_ASSOC); + +// All-Time Sales +$stmt_all_time = db()->query("SELECT COUNT(*) as num_transactions, SUM(total_amount) as total_sales FROM sales"); +$all_time_sales = $stmt_all_time->fetch(PDO::FETCH_ASSOC); + + +// Low Stock +$low_stock_threshold = 5; +$stmt_low_stock = db()->prepare('SELECT COUNT(*) FROM products WHERE stock <= ?'); +$stmt_low_stock->execute([$low_stock_threshold]); +$low_stock_count = $stmt_low_stock->fetchColumn(); -$phpVersion = PHP_VERSION; -$now = date('Y-m-d H:i:s'); ?> - - - - - - New Style - - - - - - - - - - - - - - - - - - - - - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
+

Dashboard

+
+ +
+
+
+
Total Products
+
+
+

items in inventory.

+ View details → +
+
-
-
- Page updated: (UTC) -
- - +
+
+
Today's Sales
+
+
Rp
+

from transactions.

+ View details → +
+
+
+
+
+
All-Time Sales
+
+
Rp
+

from transactions.

+ View details → +
+
+
+
+
+
Low Stock Alerts
+
+
+

items need restocking.

+ View details → +
+
+
+
+ +
+
+
+
+ Sales Trend (Last 7 Days) +
+
+ +
+
+
+
+
+
+ Best-Selling Products +
+
+ +
+
+
+
+ + + + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..91350fa --- /dev/null +++ b/login.php @@ -0,0 +1,55 @@ + + +
+
+
+
+
+

Login

+
+
+
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+ + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..4e97304 --- /dev/null +++ b/logout.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/pos.php b/pos.php new file mode 100644 index 0000000..2620ad2 --- /dev/null +++ b/pos.php @@ -0,0 +1,196 @@ +query("SELECT id, name, price, stock FROM products ORDER BY name ASC"); + $products = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + die("Error fetching products: " . $e->getMessage()); +} +?> + +
+
+ +
+
+
+
Products
+
+
+
+ +
+
No products found. Please add a product first.
+
+ + +
+
+
+
+

IDR

+
+
+
+ + +
+
+
+
+ + +
+
+
+
Cart
+
+
+
+

Cart is empty

+
+
+
+
Subtotal
+
IDR 0.00
+
+
+
Total
+
IDR 0.00
+
+
+ + +
+
+ +
+
+
+
+
+
+ + + + diff --git a/product_add.php b/product_add.php new file mode 100644 index 0000000..f08bc33 --- /dev/null +++ b/product_add.php @@ -0,0 +1,41 @@ + + +
+

Add New Product

+
+ +
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + Cancel +
+ + diff --git a/product_edit.php b/product_edit.php new file mode 100644 index 0000000..8c9d372 --- /dev/null +++ b/product_edit.php @@ -0,0 +1,63 @@ +prepare('SELECT * FROM products WHERE id = ?'); +$stmt->execute([$id]); +$product = $stmt->fetch(); + +if (!$product) { + // Redirect or show an error + header('Location: products.php'); + exit; +} +?> + +
+

Edit Product

+
+ +
+ +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + Cancel +
+ + diff --git a/products.php b/products.php new file mode 100644 index 0000000..b690596 --- /dev/null +++ b/products.php @@ -0,0 +1,70 @@ +query($query); +$products = $stmt->fetchAll(); + +?> + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SKUNameCategoryPriceStockActions
No products found. Add one!
Rp + + +
+
+ + diff --git a/receipt.php b/receipt.php new file mode 100644 index 0000000..3673352 --- /dev/null +++ b/receipt.php @@ -0,0 +1,134 @@ +prepare("SELECT * FROM sales WHERE id = ?"); +$sale_stmt->execute([$sale_id]); +$sale = $sale_stmt->fetch(PDO::FETCH_ASSOC); + +if (!$sale) { + die('Sale not found.'); +} + +// Get sale items +$items_stmt = $pdo->prepare( + "SELECT si.*, p.name as product_name + FROM sale_items si + JOIN products p ON si.product_id = p.id + WHERE si.sale_id = ?" +); +$items_stmt->execute([$sale_id]); +$items = $items_stmt->fetchAll(PDO::FETCH_ASSOC); + +?> + + + + + + Receipt - Sale #<?php echo htmlspecialchars($sale['id']); ?> + + + + +
+
+

Your Store Name

+

123 Main Street, Anytown, USA

+

Date:

+

Receipt #:

+
+ +
+
+ Item + Price +
+ +
+ +
+ ( @ $) +
+ $ +
+ +
+ + + +
+

Thank you for your business!

+
+ +
+ + New Sale +
+
+ + diff --git a/register.php b/register.php new file mode 100644 index 0000000..1b8b78f --- /dev/null +++ b/register.php @@ -0,0 +1,70 @@ + + +
+
+
+
+
+

Register

+
+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+ + + + diff --git a/reports.php b/reports.php new file mode 100644 index 0000000..adfc7eb --- /dev/null +++ b/reports.php @@ -0,0 +1,192 @@ +query("SELECT DISTINCT payment_method FROM sales ORDER BY payment_method"); +$payment_methods = $payment_methods_stmt->fetchAll(PDO::FETCH_COLUMN); + +// Filter logic +$start_date = $_GET['start_date'] ?? ''; +$end_date = $_GET['end_date'] ?? ''; +$payment_method = $_GET['payment_method'] ?? ''; + +$sql = "SELECT * FROM sales"; +$conditions = []; +$params = []; + +if ($start_date) { + $conditions[] = "sale_date >= ?"; + $params[] = $start_date . ' 00:00:00'; +} +if ($end_date) { + $conditions[] = "sale_date <= ?"; + $params[] = $end_date . ' 23:59:59'; +} +if ($payment_method) { + $conditions[] = "payment_method = ?"; + $params[] = $payment_method; +} + +if (count($conditions) > 0) { + $sql .= " WHERE " . implode(' AND ', $conditions); +} + +$sql .= " ORDER BY sale_date DESC"; + +$sales_stmt = $pdo->prepare($sql); +$sales_stmt->execute($params); +$sales = $sales_stmt->fetchAll(PDO::FETCH_ASSOC); +?> + +
+

Sales Reports

+ +
+
+ + Filter Sales +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + Clear + Export to CSV +
+
+
+
+ +
+
+ + Filtered Sales +
+
+ + + + + + + + + + + + 0): ?> + + + + + + + + + + + + + + + +
IDDateTotal AmountPayment MethodActions
$ + + + Receipt + +
No sales found matching your criteria.
+
+
+
+ + + + + + + \ No newline at end of file