# KAYALAQUA2025_29 OCT 2025 - REPOSITORY
================================================================================
Project Name: kayalaqua2025_29 Oct 2025
Created: 2025-10-29 02:12:09
Last Updated: 2025-10-29 02:13:26
Source ZIP: public_html.zip
Total Files: 31
Total Folders: 0
================================================================================
## FILE STRUCTURE
================================================================================
kayalaqua2025_29 Oct 2025/
├── base.php
├── dashboard.php
├── database_setup.sql
├── db_connection.php
├── default.php
├── delete_buyer.php
├── delete_expense.php
├── delete_expense_category.php
├── delete_expense_head.php
├── delete_payment.php
├── delete_sale.php
├── edit_buyer.php
├── edit_expense.php
├── edit_expense_head.php
├── edit_payment.php
├── edit_sale.php
├── expenses.php
├── export_buyers.php
├── export_dashboard.php
├── export_expenses.php
├── export_payments.php
├── export_sales.php
├── get_buyer_rates.php
├── get_expense_heads.php
├── index.php
├── login.php
├── logout.php
├── main_layout.php
├── payments.php
├── sales.php
└── styles.css
================================================================================
## FILE CONTENTS
================================================================================
### FILE 1: base.php
- Type: PHP
- Size: 13.49 KB
- Path: .
- Name: base.php
------------------------------------------------------------
1800)) {
header("Location: logout.php");
exit();
}
$_SESSION['last_activity'] = time();
require_once 'db_connection.php';
$pageTitle = "Base Setup";
// Handle form submissions
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
// Add Buyer
if (isset($_POST['add_buyer'])) {
$stmt = $conn->prepare("INSERT INTO buyers (name, phone, rate_tilapia, rate_small_fish, rate_big_fish, delivery_rate, harvesting_fee_tilapia, harvesting_fee_small_fish, harvesting_fee_big_fish) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssddddddd",
$_POST['name'],
$_POST['phone'],
$_POST['rate_tilapia'],
$_POST['rate_small_fish'],
$_POST['rate_big_fish'],
$_POST['delivery_rate'],
$_POST['harvesting_fee_tilapia'],
$_POST['harvesting_fee_small_fish'],
$_POST['harvesting_fee_big_fish']
);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Buyer added successfully!";
header("Location: base.php");
exit();
}
// Add Expense Category
if (isset($_POST['add_expense_category'])) {
$stmt = $conn->prepare("INSERT INTO expense_categories (name) VALUES (?)");
$stmt->bind_param("s", $_POST['category_name']);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Expense category added successfully!";
header("Location: base.php");
exit();
}
// Add Expense Head
if (isset($_POST['add_expense_head'])) {
$stmt = $conn->prepare("INSERT INTO expense_heads (name, category_id) VALUES (?, ?)");
$stmt->bind_param("si", $_POST['head_name'], $_POST['category_id']);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Expense head added successfully!";
header("Location: base.php");
exit();
}
// Update Initial Values
if (isset($_POST['update_initial_values'])) {
// Check if initial values exist
$checkQuery = "SELECT COUNT(*) as count FROM initial_values";
$result = $conn->query($checkQuery);
$count = $result->fetch_assoc()['count'];
if ($count > 0) {
$stmt = $conn->prepare("UPDATE initial_values SET cash_in_hand = ?, madhu_balance = ?, rathna_balance = ?, jambukkutti_balance = ? WHERE id = 1");
} else {
$stmt = $conn->prepare("INSERT INTO initial_values (cash_in_hand, madhu_balance, rathna_balance, jambukkutti_balance) VALUES (?, ?, ?, ?)");
}
$stmt->bind_param("dddd",
$_POST['cash_in_hand'],
$_POST['madhu_balance'],
$_POST['rathna_balance'],
$_POST['jambukkutti_balance']
);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Initial values updated successfully!";
header("Location: base.php");
exit();
}
} catch (Exception $e) {
$_SESSION['error'] = "An error occurred. Please try again.";
error_log("Base.php error: " . $e->getMessage());
}
}
// Fetch all buyers
$buyersQuery = "SELECT * FROM buyers ORDER BY name";
$buyers = $conn->query($buyersQuery)->fetch_all(MYSQLI_ASSOC);
// Fetch all expense categories with their heads
$categoriesQuery = "SELECT * FROM expense_categories ORDER BY name";
$categories = $conn->query($categoriesQuery)->fetch_all(MYSQLI_ASSOC);
// Fetch initial values
$initialQuery = "SELECT * FROM initial_values LIMIT 1";
$initialResult = $conn->query($initialQuery);
$initialValues = $initialResult->fetch_assoc();
if (!$initialValues) {
$initialValues = [
'cash_in_hand' => 0,
'madhu_balance' => 0,
'rathna_balance' => 0,
'jambukkutti_balance' => 0
];
}
// Generate buyer rows
$buyerRows = '';
foreach ($buyers as $buyer) {
$buyerRows .= "
" . htmlspecialchars($buyer['name']) . "
" . htmlspecialchars($buyer['phone']) . "
₹" . number_format($buyer['rate_tilapia'], 2) . "
₹" . number_format($buyer['rate_small_fish'], 2) . "
₹" . number_format($buyer['rate_big_fish'], 2) . "
";
}
// Generate expense categories and heads
$expenseCategoriesHtml = '';
foreach ($categories as $category) {
$headsQuery = "SELECT * FROM expense_heads WHERE category_id = " . $category['id'] . " ORDER BY name";
$heads = $conn->query($headsQuery)->fetch_all(MYSQLI_ASSOC);
$headsHtml = '';
foreach ($heads as $head) {
$headsHtml .= "
{$head['name']}
";
}
$expenseCategoriesHtml .= "
";
}
$content = <<
Name
Phone
Tilapia Rate
Small Fish Rate
Big Fish Rate
Actions
$buyerRows
Expense Categories & Heads
$expenseCategoriesHtml
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 2: dashboard.php
- Type: PHP
- Size: 11.87 KB
- Path: .
- Name: dashboard.php
------------------------------------------------------------
1800)) {
header("Location: logout.php");
exit();
}
$_SESSION['last_activity'] = time();
require_once 'db_connection.php';
$pageTitle = "Dashboard";
// Helper function to safely format currency
function formatCurrency($value) {
if (is_numeric($value)) {
return '₹' . number_format((float)$value, 2, '.', ',');
}
return '₹0.00';
}
// Function to safely execute SQL queries
function executeQuery($conn, $query) {
$result = $conn->query($query);
if ($result === false) {
error_log("Query failed: " . $conn->error);
throw new Exception("Database query failed.");
}
return $result;
}
try {
// Get total sales value
$result = executeQuery($conn, "SELECT SUM(final_amount) as total FROM sales");
$totalSales = $result->fetch_assoc()['total'] ?? 0;
// Get total expense value
$result = executeQuery($conn, "SELECT SUM(amount) as total FROM expenses");
$totalExpenses = $result->fetch_assoc()['total'] ?? 0;
// Get total payments value
$result = executeQuery($conn, "SELECT SUM(amount_paid) as total FROM payments");
$totalPayments = $result->fetch_assoc()['total'] ?? 0;
// Get total weight harvested
$result = executeQuery($conn, "SELECT SUM(weight_tilapia + weight_small_fish + weight_big_fish) as total FROM sales");
$totalWeightHarvested = $result->fetch_assoc()['total'] ?? 0;
// Get average rate per kg
$result = executeQuery($conn, "SELECT SUM(final_amount) / NULLIF(SUM(weight_tilapia + weight_small_fish + weight_big_fish), 0) as avg_rate FROM sales");
$averageRatePerKg = $result->fetch_assoc()['avg_rate'] ?? 0;
// Get initial values
$result = executeQuery($conn, "SELECT * FROM initial_values LIMIT 1");
$initialValues = $result->fetch_assoc();
$initialCash = $initialValues['cash_in_hand'] ?? 0;
// Calculate cash in hand
$cashInHand = $initialCash + $totalPayments - $totalExpenses;
// Format values for display
$formattedTotalSales = formatCurrency($totalSales);
$formattedTotalExpenses = formatCurrency($totalExpenses);
$formattedTotalPayments = formatCurrency($totalPayments);
$formattedCashInHand = formatCurrency($cashInHand);
$formattedTotalWeightHarvested = number_format($totalWeightHarvested, 2);
$formattedAverageRatePerKg = formatCurrency($averageRatePerKg);
// Generate Fortnightly Harvest Charges rows
$fortnightlyRows = '';
$query = "SELECT
DATE_FORMAT(date, '%Y-%m') as month_year,
CASE
WHEN DAY(date) <= 15 THEN 'First Half'
ELSE 'Second Half'
END as half_month,
MIN(date) as start_date,
MAX(date) as end_date,
SUM(weight_tilapia) as total_tilapia,
SUM(weight_small_fish) as total_small_fish,
SUM(weight_big_fish) as total_big_fish,
SUM(harvesting_charges) as total_charges
FROM sales
WHERE date BETWEEN '2024-10-01' AND '2025-09-30'
GROUP BY
month_year,
half_month
HAVING total_charges > 0
ORDER BY start_date";
$result = executeQuery($conn, $query);
while ($row = $result->fetch_assoc()) {
$startDate = date('Y-m-d', strtotime($row['start_date']));
$endDate = date('Y-m-d', strtotime($row['end_date']));
if ($row['half_month'] == 'First Half') {
$fortnightName = date('M d', strtotime($startDate)) . " - " . date('M d', strtotime($row['month_year'] . '-15'));
} else {
$fortnightName = date('M d', strtotime($row['month_year'] . '-16')) . " - " . date('M d', strtotime($endDate));
}
$fortnightlyRows .= "
" . htmlspecialchars($fortnightName) . "
" . number_format($row['total_tilapia'], 2) . "
" . number_format($row['total_small_fish'], 2) . "
" . number_format($row['total_big_fish'], 2) . "
" . formatCurrency($row['total_charges']) . "
";
}
// Generate Buyer Data rows
$buyerRows = '';
$madhuBalance = $initialValues['madhu_balance'] ?? 0;
$rathnaBalance = $initialValues['rathna_balance'] ?? 0;
$jambukkuttiBalance = $initialValues['jambukkutti_balance'] ?? 0;
$query = "SELECT
b.name as buyer_name,
COALESCE(SUM(s.final_amount), 0) as total_sales,
COALESCE((SELECT SUM(amount_paid) FROM payments p WHERE p.buyer_id = b.id), 0) as total_payments,
CASE
WHEN b.name = 'Madhu' THEN COALESCE(SUM(s.final_amount), 0) - COALESCE((SELECT SUM(amount_paid) FROM payments p WHERE p.buyer_id = b.id), 0) + $madhuBalance
WHEN b.name = 'Rathna' THEN COALESCE(SUM(s.final_amount), 0) - COALESCE((SELECT SUM(amount_paid) FROM payments p WHERE p.buyer_id = b.id), 0) + $rathnaBalance
WHEN b.name = 'Jambukkutti' THEN COALESCE(SUM(s.final_amount), 0) - COALESCE((SELECT SUM(amount_paid) FROM payments p WHERE p.buyer_id = b.id), 0) + $jambukkuttiBalance
ELSE COALESCE(SUM(s.final_amount), 0) - COALESCE((SELECT SUM(amount_paid) FROM payments p WHERE p.buyer_id = b.id), 0)
END as balance
FROM buyers b
LEFT JOIN sales s ON b.id = s.buyer_id
GROUP BY b.id
ORDER BY b.name";
$result = executeQuery($conn, $query);
while ($row = $result->fetch_assoc()) {
$buyerRows .= "
" . htmlspecialchars($row['buyer_name']) . "
" . formatCurrency($row['total_sales']) . "
" . formatCurrency($row['total_payments']) . "
" . formatCurrency($row['balance']) . "
";
}
// Get monthly data for the table
$query = "SELECT
DATE_FORMAT(s.date, '%Y-%m') as month,
SUM(s.final_amount) as sales_value,
(SELECT SUM(amount) FROM expenses e WHERE DATE_FORMAT(e.date, '%Y-%m') = DATE_FORMAT(s.date, '%Y-%m')) as expense_value,
(SELECT SUM(amount_paid) FROM payments p WHERE DATE_FORMAT(p.date, '%Y-%m') = DATE_FORMAT(s.date, '%Y-%m')) as payments_value,
SUM(s.weight_tilapia + s.weight_small_fish + s.weight_big_fish) as harvested_weight,
SUM(s.final_amount) / NULLIF(SUM(s.weight_tilapia + s.weight_small_fish + s.weight_big_fish), 0) as rate_per_kg
FROM sales s
WHERE s.date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 MONTH) AND CURDATE()
GROUP BY DATE_FORMAT(s.date, '%Y-%m')
ORDER BY s.date DESC";
$monthlyData = executeQuery($conn, $query);
// Generate monthly report rows
$monthlyRows = '';
while ($row = $monthlyData->fetch_assoc()) {
$monthlyRows .= "
" . date('M Y', strtotime($row['month'] . '-01')) . "
" . formatCurrency($row['sales_value']) . "
" . formatCurrency($row['expense_value']) . "
" . formatCurrency($row['payments_value']) . "
" . number_format($row['harvested_weight'], 2) . " kg
" . formatCurrency($row['rate_per_kg']) . "
";
}
$content = <<
$formattedTotalWeightHarvested kg
$formattedAverageRatePerKg
Fortnight
Tilapia (kg)
Small Fish (kg)
Big Fish (kg)
Harvest Charges
$fortnightlyRows
Buyer
Total Sales
Total Payments
Balance
$buyerRows
Month
Sales Value
Expenses
Payments
Harvested Weight
Rate/Kg
$monthlyRows
HTML;
} catch (Exception $e) {
$content = " An error occurred while loading dashboard data.
";
error_log("Dashboard error: " . $e->getMessage());
}
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 3: database_setup.sql
- Type: SQL
- Size: 6.91 KB
- Path: .
- Name: database_setup.sql
------------------------------------------------------------
-- Kayal Aqua 2025 - Database Setup
-- Generated on: 2025-10-28
-- Use this file to set up the database
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
-- --------------------------------------------------------
-- Table structure for table `buyers`
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `buyers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`phone` varchar(20) DEFAULT NULL,
`rate_tilapia` decimal(10,2) DEFAULT NULL,
`rate_small_fish` decimal(10,2) DEFAULT NULL,
`rate_big_fish` decimal(10,2) DEFAULT NULL,
`delivery_rate` decimal(10,2) DEFAULT NULL,
`harvesting_fee_tilapia` decimal(10,2) DEFAULT NULL,
`harvesting_fee_small_fish` decimal(10,2) DEFAULT NULL,
`harvesting_fee_big_fish` decimal(10,2) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
-- Table structure for table `expenses`
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `expenses` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL,
`buyer_id` int(11) DEFAULT NULL,
`category_id` int(11) DEFAULT NULL,
`head_id` int(11) DEFAULT NULL,
`amount` decimal(10,2) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `buyer_id` (`buyer_id`),
KEY `category_id` (`category_id`),
KEY `head_id` (`head_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
-- Table structure for table `expense_categories`
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `expense_categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
-- Table structure for table `expense_heads`
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `expense_heads` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) DEFAULT NULL,
`name` varchar(100) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `category_id` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
-- Table structure for table `initial_values`
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `initial_values` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cash_in_hand` decimal(10,2) NOT NULL DEFAULT 0.00,
`madhu_balance` decimal(10,2) NOT NULL DEFAULT 0.00,
`rathna_balance` decimal(10,2) NOT NULL DEFAULT 0.00,
`jambukkutti_balance` decimal(10,2) NOT NULL DEFAULT 0.00,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Insert default initial values
INSERT INTO `initial_values` (`id`, `cash_in_hand`, `madhu_balance`, `rathna_balance`, `jambukkutti_balance`) VALUES
(1, 0.00, 0.00, 0.00, 0.00);
-- --------------------------------------------------------
-- Table structure for table `payments`
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `payments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL,
`buyer_id` int(11) DEFAULT NULL,
`amount_paid` decimal(10,2) DEFAULT NULL,
`balance` decimal(10,2) DEFAULT NULL,
`balance_override` decimal(10,2) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `buyer_id` (`buyer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
-- Table structure for table `sales`
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `sales` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL,
`buyer_id` int(11) DEFAULT NULL,
`weight_tilapia` decimal(10,2) DEFAULT NULL,
`weight_small_fish` decimal(10,2) DEFAULT NULL,
`weight_big_fish` decimal(10,2) DEFAULT NULL,
`include_delivery` tinyint(1) DEFAULT 0,
`final_amount` decimal(10,2) DEFAULT NULL,
`final_amount_override` decimal(10,2) DEFAULT NULL,
`harvesting_charges` decimal(10,2) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `buyer_id` (`buyer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
-- Table structure for table `users`
-- --------------------------------------------------------
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` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Insert default admin user (username: admin, password: admin123)
INSERT INTO `users` (`username`, `password`) VALUES
('admin', '$2y$10$vWJYH9MCqNzKGzEqKLmXOe4jYZVQGZj5uyxqVZ7h.wjCKxJjr7Bfi');
-- --------------------------------------------------------
-- Add Foreign Keys
-- --------------------------------------------------------
ALTER TABLE `expenses`
ADD CONSTRAINT `expenses_ibfk_1` FOREIGN KEY (`buyer_id`) REFERENCES `buyers` (`id`) ON DELETE SET NULL,
ADD CONSTRAINT `expenses_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `expense_categories` (`id`) ON DELETE SET NULL,
ADD CONSTRAINT `expenses_ibfk_3` FOREIGN KEY (`head_id`) REFERENCES `expense_heads` (`id`) ON DELETE SET NULL;
ALTER TABLE `expense_heads`
ADD CONSTRAINT `expense_heads_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `expense_categories` (`id`) ON DELETE CASCADE;
ALTER TABLE `payments`
ADD CONSTRAINT `payments_ibfk_1` FOREIGN KEY (`buyer_id`) REFERENCES `buyers` (`id`) ON DELETE SET NULL;
ALTER TABLE `sales`
ADD CONSTRAINT `sales_ibfk_1` FOREIGN KEY (`buyer_id`) REFERENCES `buyers` (`id`) ON DELETE SET NULL;
COMMIT;
-------------------- END OF FILE --------------------
### FILE 4: db_connection.php
- Type: PHP
- Size: 728 B
- Path: .
- Name: db_connection.php
------------------------------------------------------------
connect_error) {
error_log("Database connection failed: " . $conn->connect_error);
die("Connection failed. Please contact administrator.");
}
// Set charset to utf8mb4 for better character support
$conn->set_charset("utf8mb4");
} catch (Exception $e) {
error_log("Database error: " . $e->getMessage());
die("Database error. Please contact administrator.");
}
?>
-------------------- END OF FILE --------------------
### FILE 5: default.php
- Type: PHP
- Size: 15.99 KB
- Path: .
- Name: default.php
------------------------------------------------------------
Default page
You Are All Set to Go!
All you have to do now is upload your website files and start your journey. Check out how to do that below:
-------------------- END OF FILE --------------------
### FILE 6: delete_buyer.php
- Type: PHP
- Size: 729 B
- Path: .
- Name: delete_buyer.php
------------------------------------------------------------
prepare("DELETE FROM buyers WHERE id = ?");
$stmt->bind_param("i", $buyerId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Buyer deleted successfully!";
} catch (Exception $e) {
$_SESSION['error'] = "Cannot delete buyer. It may be referenced in sales or payments.";
error_log("Delete buyer error: " . $e->getMessage());
}
header("Location: base.php");
exit();
?>
-------------------- END OF FILE --------------------
### FILE 7: delete_expense_category.php
- Type: PHP
- Size: 763 B
- Path: .
- Name: delete_expense_category.php
------------------------------------------------------------
prepare("DELETE FROM expense_categories WHERE id = ?");
$stmt->bind_param("i", $categoryId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Expense category deleted successfully!";
} catch (Exception $e) {
$_SESSION['error'] = "Cannot delete category. It may have expense heads or expenses.";
error_log("Delete category error: " . $e->getMessage());
}
header("Location: base.php");
exit();
?>
-------------------- END OF FILE --------------------
### FILE 8: delete_expense_head.php
- Type: PHP
- Size: 753 B
- Path: .
- Name: delete_expense_head.php
------------------------------------------------------------
prepare("DELETE FROM expense_heads WHERE id = ?");
$stmt->bind_param("i", $headId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Expense head deleted successfully!";
} catch (Exception $e) {
$_SESSION['error'] = "Cannot delete expense head. It may be referenced in expenses.";
error_log("Delete expense head error: " . $e->getMessage());
}
header("Location: base.php");
exit();
?>
-------------------- END OF FILE --------------------
### FILE 9: delete_expense.php
- Type: PHP
- Size: 709 B
- Path: .
- Name: delete_expense.php
------------------------------------------------------------
prepare("DELETE FROM expenses WHERE id = ?");
$stmt->bind_param("i", $expenseId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Expense deleted successfully!";
} catch (Exception $e) {
$_SESSION['error'] = "Error deleting expense.";
error_log("Delete expense error: " . $e->getMessage());
}
header("Location: expenses.php");
exit();
?>
-------------------- END OF FILE --------------------
### FILE 10: delete_payment.php
- Type: PHP
- Size: 709 B
- Path: .
- Name: delete_payment.php
------------------------------------------------------------
prepare("DELETE FROM payments WHERE id = ?");
$stmt->bind_param("i", $paymentId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Payment deleted successfully!";
} catch (Exception $e) {
$_SESSION['error'] = "Error deleting payment.";
error_log("Delete payment error: " . $e->getMessage());
}
header("Location: payments.php");
exit();
?>
-------------------- END OF FILE --------------------
### FILE 11: delete_sale.php
- Type: PHP
- Size: 682 B
- Path: .
- Name: delete_sale.php
------------------------------------------------------------
prepare("DELETE FROM sales WHERE id = ?");
$stmt->bind_param("i", $saleId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Sale deleted successfully!";
} catch (Exception $e) {
$_SESSION['error'] = "Error deleting sale.";
error_log("Delete sale error: " . $e->getMessage());
}
header("Location: sales.php");
exit();
?>
-------------------- END OF FILE --------------------
### FILE 12: edit_buyer.php
- Type: PHP
- Size: 5.01 KB
- Path: .
- Name: edit_buyer.php
------------------------------------------------------------
1800)) {
header("Location: logout.php");
exit();
}
$_SESSION['last_activity'] = time();
require_once 'db_connection.php';
$pageTitle = "Edit Buyer";
if (!isset($_GET['id'])) {
$_SESSION['error'] = "Buyer ID is required.";
header("Location: base.php");
exit();
}
$buyerId = intval($_GET['id']);
// Fetch buyer data
$stmt = $conn->prepare("SELECT * FROM buyers WHERE id = ?");
$stmt->bind_param("i", $buyerId);
$stmt->execute();
$result = $stmt->get_result();
$buyer = $result->fetch_assoc();
$stmt->close();
if (!$buyer) {
$_SESSION['error'] = "Buyer not found.";
header("Location: base.php");
exit();
}
// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$stmt = $conn->prepare("UPDATE buyers SET name = ?, phone = ?, rate_tilapia = ?, rate_small_fish = ?, rate_big_fish = ?, delivery_rate = ?, harvesting_fee_tilapia = ?, harvesting_fee_small_fish = ?, harvesting_fee_big_fish = ? WHERE id = ?");
$stmt->bind_param("ssddddddi",
$_POST['name'],
$_POST['phone'],
$_POST['rate_tilapia'],
$_POST['rate_small_fish'],
$_POST['rate_big_fish'],
$_POST['delivery_rate'],
$_POST['harvesting_fee_tilapia'],
$_POST['harvesting_fee_small_fish'],
$_POST['harvesting_fee_big_fish'],
$buyerId
);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Buyer updated successfully!";
header("Location: base.php");
exit();
} catch (Exception $e) {
$_SESSION['error'] = "An error occurred while updating buyer.";
error_log("Edit buyer error: " . $e->getMessage());
}
}
$content = <<
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 13: edit_expense_head.php
- Type: PHP
- Size: 2.71 KB
- Path: .
- Name: edit_expense_head.php
------------------------------------------------------------
prepare("SELECT * FROM expense_heads WHERE id = ?");
$stmt->bind_param("i", $headId);
$stmt->execute();
$result = $stmt->get_result();
$head = $result->fetch_assoc();
$stmt->close();
if (!$head) {
$_SESSION['error'] = "Expense head not found.";
header("Location: base.php");
exit();
}
$categoriesQuery = "SELECT id, name FROM expense_categories ORDER BY name";
$categories = $conn->query($categoriesQuery)->fetch_all(MYSQLI_ASSOC);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$stmt = $conn->prepare("UPDATE expense_heads SET name = ?, category_id = ? WHERE id = ?");
$stmt->bind_param("sii", $_POST['name'], $_POST['category_id'], $headId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Expense head updated successfully!";
header("Location: base.php");
exit();
} catch (Exception $e) {
$_SESSION['error'] = "An error occurred while updating expense head.";
error_log("Edit expense head error: " . $e->getMessage());
}
}
$categoryOptions = '';
foreach ($categories as $category) {
$selected = $category['id'] == $head['category_id'] ? 'selected' : '';
$categoryOptions .= "{$category['name']} ";
}
$content = <<
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 14: edit_expense.php
- Type: PHP
- Size: 5.64 KB
- Path: .
- Name: edit_expense.php
------------------------------------------------------------
prepare("SELECT * FROM expenses WHERE id = ?");
$stmt->bind_param("i", $expenseId);
$stmt->execute();
$result = $stmt->get_result();
$expense = $result->fetch_assoc();
$stmt->close();
if (!$expense) {
$_SESSION['error'] = "Expense not found.";
header("Location: expenses.php");
exit();
}
$buyersQuery = "SELECT id, name FROM buyers ORDER BY name";
$buyers = $conn->query($buyersQuery)->fetch_all(MYSQLI_ASSOC);
$categoriesQuery = "SELECT id, name FROM expense_categories ORDER BY name";
$categories = $conn->query($categoriesQuery)->fetch_all(MYSQLI_ASSOC);
$headsQuery = "SELECT id, name FROM expense_heads WHERE category_id = " . $expense['category_id'] . " ORDER BY name";
$heads = $conn->query($headsQuery)->fetch_all(MYSQLI_ASSOC);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$buyer_id = !empty($_POST['buyer_id']) ? intval($_POST['buyer_id']) : NULL;
$stmt = $conn->prepare("UPDATE expenses SET date = ?, buyer_id = ?, category_id = ?, head_id = ?, amount = ? WHERE id = ?");
$stmt->bind_param("siiidi", $_POST['date'], $buyer_id, $_POST['category_id'], $_POST['head_id'], $_POST['amount'], $expenseId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Expense updated successfully!";
header("Location: expenses.php");
exit();
} catch (Exception $e) {
$_SESSION['error'] = "Error updating expense.";
error_log("Edit expense error: " . $e->getMessage());
}
}
$buyerOptions = 'None ';
foreach ($buyers as $buyer) {
$selected = $buyer['id'] == $expense['buyer_id'] ? 'selected' : '';
$buyerOptions .= "{$buyer['name']} ";
}
$categoryOptions = '';
foreach ($categories as $category) {
$selected = $category['id'] == $expense['category_id'] ? 'selected' : '';
$categoryOptions .= "{$category['name']} ";
}
$headOptions = '';
foreach ($heads as $head) {
$selected = $head['id'] == $expense['head_id'] ? 'selected' : '';
$headOptions .= "{$head['name']} ";
}
$content = <<
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 15: edit_payment.php
- Type: PHP
- Size: 2.92 KB
- Path: .
- Name: edit_payment.php
------------------------------------------------------------
prepare("SELECT * FROM payments WHERE id = ?");
$stmt->bind_param("i", $paymentId);
$stmt->execute();
$result = $stmt->get_result();
$payment = $result->fetch_assoc();
$stmt->close();
if (!$payment) {
$_SESSION['error'] = "Payment not found.";
header("Location: payments.php");
exit();
}
$buyersQuery = "SELECT id, name FROM buyers ORDER BY name";
$buyers = $conn->query($buyersQuery)->fetch_all(MYSQLI_ASSOC);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$stmt = $conn->prepare("UPDATE payments SET date = ?, buyer_id = ?, amount_paid = ? WHERE id = ?");
$stmt->bind_param("sidi", $_POST['date'], $_POST['buyer_id'], $_POST['amount_paid'], $paymentId);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Payment updated successfully!";
header("Location: payments.php");
exit();
} catch (Exception $e) {
$_SESSION['error'] = "Error updating payment.";
error_log("Edit payment error: " . $e->getMessage());
}
}
$buyerOptions = '';
foreach ($buyers as $buyer) {
$selected = $buyer['id'] == $payment['buyer_id'] ? 'selected' : '';
$buyerOptions .= "{$buyer['name']} ";
}
$content = <<
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 16: edit_sale.php
- Type: PHP
- Size: 4.78 KB
- Path: .
- Name: edit_sale.php
------------------------------------------------------------
prepare("SELECT * FROM sales WHERE id = ?");
$stmt->bind_param("i", $saleId);
$stmt->execute();
$result = $stmt->get_result();
$sale = $result->fetch_assoc();
$stmt->close();
if (!$sale) {
$_SESSION['error'] = "Sale not found.";
header("Location: sales.php");
exit();
}
$buyersQuery = "SELECT id, name FROM buyers ORDER BY name";
$buyers = $conn->query($buyersQuery)->fetch_all(MYSQLI_ASSOC);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$stmt = $conn->prepare("UPDATE sales SET date = ?, buyer_id = ?, weight_tilapia = ?, weight_small_fish = ?, weight_big_fish = ?, include_delivery = ?, final_amount = ?, harvesting_charges = ? WHERE id = ?");
$stmt->bind_param("sidddiddi",
$_POST['date'],
$_POST['buyer_id'],
$_POST['weight_tilapia'],
$_POST['weight_small_fish'],
$_POST['weight_big_fish'],
isset($_POST['include_delivery']) ? 1 : 0,
$_POST['final_amount'],
$_POST['harvesting_charges'],
$saleId
);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Sale updated successfully!";
header("Location: sales.php");
exit();
} catch (Exception $e) {
$_SESSION['error'] = "Error updating sale.";
error_log("Edit sale error: " . $e->getMessage());
}
}
$buyerOptions = '';
foreach ($buyers as $buyer) {
$selected = $buyer['id'] == $sale['buyer_id'] ? 'selected' : '';
$buyerOptions .= "{$buyer['name']} ";
}
$includeDeliveryChecked = $sale['include_delivery'] ? 'checked' : '';
$content = <<
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 17: expenses.php
- Type: PHP
- Size: 6.79 KB
- Path: .
- Name: expenses.php
------------------------------------------------------------
1800)) {
header("Location: logout.php");
exit();
}
$_SESSION['last_activity'] = time();
require_once 'db_connection.php';
$pageTitle = "Expenses";
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_expense'])) {
try {
$buyer_id = !empty($_POST['buyer_id']) ? intval($_POST['buyer_id']) : NULL;
$stmt = $conn->prepare("INSERT INTO expenses (date, buyer_id, category_id, head_id, amount) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("siiii", $_POST['date'], $buyer_id, $_POST['category_id'], $_POST['head_id'], $_POST['amount']);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Expense added successfully!";
header("Location: expenses.php");
exit();
} catch (Exception $e) {
$_SESSION['error'] = "Error adding expense.";
error_log("Expenses error: " . $e->getMessage());
}
}
$buyersQuery = "SELECT id, name FROM buyers ORDER BY name";
$buyers = $conn->query($buyersQuery)->fetch_all(MYSQLI_ASSOC);
$categoriesQuery = "SELECT id, name FROM expense_categories ORDER BY name";
$categories = $conn->query($categoriesQuery)->fetch_all(MYSQLI_ASSOC);
$expensesQuery = "SELECT e.*, b.name as buyer_name, ec.name as category_name, eh.name as head_name
FROM expenses e
LEFT JOIN buyers b ON e.buyer_id = b.id
JOIN expense_categories ec ON e.category_id = ec.id
JOIN expense_heads eh ON e.head_id = eh.id
ORDER BY e.date DESC";
$expenses = $conn->query($expensesQuery)->fetch_all(MYSQLI_ASSOC);
$buyerOptions = 'None ';
foreach ($buyers as $buyer) {
$buyerOptions .= "{$buyer['name']} ";
}
$categoryOptions = '';
foreach ($categories as $category) {
$categoryOptions .= "{$category['name']} ";
}
$expenseRows = '';
foreach ($expenses as $expense) {
$buyerName = $expense['buyer_name'] ? $expense['buyer_name'] : 'N/A';
$expenseRows .= "
{$expense['date']}
$buyerName
{$expense['category_name']}
{$expense['head_name']}
₹" . number_format($expense['amount'], 2) . "
";
}
$content = <<
Date
Buyer
Category
Head
Amount
Actions
$expenseRows
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 18: export_buyers.php
- Type: PHP
- Size: 1.59 KB
- Path: .
- Name: export_buyers.php
------------------------------------------------------------
query($query);
while ($row = $result->fetch_assoc()) {
fputcsv($output, array(
$row['name'],
$row['phone'],
number_format($row['rate_tilapia'], 2),
number_format($row['rate_small_fish'], 2),
number_format($row['rate_big_fish'], 2),
number_format($row['delivery_rate'], 2),
number_format($row['harvesting_fee_tilapia'], 2),
number_format($row['harvesting_fee_small_fish'], 2),
number_format($row['harvesting_fee_big_fish'], 2)
));
}
fclose($output);
$conn->close();
} catch (Exception $e) {
header('Content-Type: text/plain');
echo "An error occurred while exporting data.";
error_log("Buyer export error: " . $e->getMessage());
}
exit();
?>
-------------------- END OF FILE --------------------
### FILE 19: export_dashboard.php
- Type: PHP
- Size: 4.75 KB
- Path: .
- Name: export_dashboard.php
------------------------------------------------------------
query($query);
if ($result === false) {
error_log("Query failed: " . $conn->error);
throw new Exception("Database query failed.");
}
return $result;
}
try {
// Set headers for CSV download
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="dashboard_report_' . date('Y-m-d') . '.csv"');
// Create output stream
$output = fopen('php://output', 'w');
// Add BOM for Excel UTF-8 support
fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF));
// Summary section
fputcsv($output, array('DASHBOARD SUMMARY - Generated on ' . date('Y-m-d H:i:s')));
fputcsv($output, array(''));
// Get total sales value
$result = executeQuery($conn, "SELECT SUM(final_amount) as total FROM sales");
$totalSales = $result->fetch_assoc()['total'] ?? 0;
fputcsv($output, array('Total Sales Value', formatCurrency($totalSales)));
// Get total expense value
$result = executeQuery($conn, "SELECT SUM(amount) as total FROM expenses");
$totalExpenses = $result->fetch_assoc()['total'] ?? 0;
fputcsv($output, array('Total Expenses', formatCurrency($totalExpenses)));
// Get total payments value
$result = executeQuery($conn, "SELECT SUM(amount_paid) as total FROM payments");
$totalPayments = $result->fetch_assoc()['total'] ?? 0;
fputcsv($output, array('Total Payments Received', formatCurrency($totalPayments)));
// Get initial values
$result = executeQuery($conn, "SELECT * FROM initial_values LIMIT 1");
$initialValues = $result->fetch_assoc();
$initialCash = $initialValues['cash_in_hand'] ?? 0;
$cashInHand = $initialCash + $totalPayments - $totalExpenses;
fputcsv($output, array('Cash in Hand', formatCurrency($cashInHand)));
// Get total weight harvested
$result = executeQuery($conn, "SELECT SUM(weight_tilapia + weight_small_fish + weight_big_fish) as total FROM sales");
$totalWeightHarvested = $result->fetch_assoc()['total'] ?? 0;
fputcsv($output, array('Total Weight Harvested (kg)', number_format($totalWeightHarvested, 2)));
// Get average rate per kg
$result = executeQuery($conn, "SELECT SUM(final_amount) / NULLIF(SUM(weight_tilapia + weight_small_fish + weight_big_fish), 0) as avg_rate FROM sales");
$averageRatePerKg = $result->fetch_assoc()['avg_rate'] ?? 0;
fputcsv($output, array('Average Rate per Kg', formatCurrency($averageRatePerKg)));
fputcsv($output, array(''));
fputcsv($output, array(''));
// Monthly Report Header
fputcsv($output, array('MONTHLY REPORT (LAST 12 MONTHS)'));
fputcsv($output, array('Month', 'Sales Value', 'Expenses', 'Payments', 'Harvested Weight (kg)', 'Rate per Kg'));
// Monthly data
$query = "SELECT
DATE_FORMAT(s.date, '%Y-%m') as month,
SUM(s.final_amount) as sales_value,
(SELECT SUM(amount) FROM expenses e WHERE DATE_FORMAT(e.date, '%Y-%m') = DATE_FORMAT(s.date, '%Y-%m')) as expense_value,
(SELECT SUM(amount_paid) FROM payments p WHERE DATE_FORMAT(p.date, '%Y-%m') = DATE_FORMAT(s.date, '%Y-%m')) as payments_value,
SUM(s.weight_tilapia + s.weight_small_fish + s.weight_big_fish) as harvested_weight,
SUM(s.final_amount) / NULLIF(SUM(s.weight_tilapia + s.weight_small_fish + s.weight_big_fish), 0) as rate_per_kg
FROM sales s
WHERE s.date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 MONTH) AND CURDATE()
GROUP BY DATE_FORMAT(s.date, '%Y-%m')
ORDER BY s.date DESC";
$result = executeQuery($conn, $query);
while ($row = $result->fetch_assoc()) {
fputcsv($output, array(
date('M Y', strtotime($row['month'] . '-01')),
formatCurrency($row['sales_value']),
formatCurrency($row['expense_value']),
formatCurrency($row['payments_value']),
number_format($row['harvested_weight'], 2),
formatCurrency($row['rate_per_kg'])
));
}
fclose($output);
$conn->close();
} catch (Exception $e) {
// In case of error, output error message
header('Content-Type: text/plain');
echo "An error occurred while exporting data. Please try again.";
error_log("Dashboard export error: " . $e->getMessage());
}
exit();
?>
-------------------- END OF FILE --------------------
### FILE 20: export_expenses.php
- Type: PHP
- Size: 1.33 KB
- Path: .
- Name: export_expenses.php
------------------------------------------------------------
query($query);
while ($row = $result->fetch_assoc()) {
fputcsv($output, array(
$row['date'],
$row['buyer_name'] ? $row['buyer_name'] : 'N/A',
$row['category_name'],
$row['head_name'],
number_format($row['amount'], 2)
));
}
fclose($output);
$conn->close();
} catch (Exception $e) {
header('Content-Type: text/plain');
echo "Export error";
error_log("Expenses export error: " . $e->getMessage());
}
exit();
?>
-------------------- END OF FILE --------------------
### FILE 21: export_payments.php
- Type: PHP
- Size: 1.01 KB
- Path: .
- Name: export_payments.php
------------------------------------------------------------
query($query);
while ($row = $result->fetch_assoc()) {
fputcsv($output, array(
$row['date'],
$row['buyer_name'],
number_format($row['amount_paid'], 2)
));
}
fclose($output);
$conn->close();
} catch (Exception $e) {
header('Content-Type: text/plain');
echo "Export error";
error_log("Payments export error: " . $e->getMessage());
}
exit();
?>
-------------------- END OF FILE --------------------
### FILE 22: export_sales.php
- Type: PHP
- Size: 1.39 KB
- Path: .
- Name: export_sales.php
------------------------------------------------------------
query($query);
while ($row = $result->fetch_assoc()) {
fputcsv($output, array(
$row['date'],
$row['buyer_name'],
number_format($row['weight_tilapia'], 2),
number_format($row['weight_small_fish'], 2),
number_format($row['weight_big_fish'], 2),
$row['include_delivery'] ? 'Yes' : 'No',
number_format($row['harvesting_charges'], 2),
number_format($row['final_amount'], 2)
));
}
fclose($output);
$conn->close();
} catch (Exception $e) {
header('Content-Type: text/plain');
echo "Export error";
error_log("Sales export error: " . $e->getMessage());
}
exit();
?>
-------------------- END OF FILE --------------------
### FILE 23: get_buyer_rates.php
- Type: PHP
- Size: 967 B
- Path: .
- Name: get_buyer_rates.php
------------------------------------------------------------
'Buyer ID is required']);
exit();
}
$buyerId = intval($_GET['id']);
try {
$stmt = $conn->prepare("SELECT rate_tilapia, rate_small_fish, rate_big_fish, delivery_rate, harvesting_fee_tilapia, harvesting_fee_small_fish, harvesting_fee_big_fish FROM buyers WHERE id = ?");
$stmt->bind_param("i", $buyerId);
$stmt->execute();
$result = $stmt->get_result();
$buyer = $result->fetch_assoc();
$stmt->close();
if ($buyer) {
echo json_encode($buyer);
} else {
echo json_encode(['error' => 'Buyer not found']);
}
} catch (Exception $e) {
echo json_encode(['error' => 'Database error']);
error_log("Get buyer rates error: " . $e->getMessage());
}
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 24: get_expense_heads.php
- Type: PHP
- Size: 810 B
- Path: .
- Name: get_expense_heads.php
------------------------------------------------------------
'Category ID is required']);
exit();
}
$categoryId = intval($_GET['category_id']);
try {
$stmt = $conn->prepare("SELECT id, name FROM expense_heads WHERE category_id = ? ORDER BY name");
$stmt->bind_param("i", $categoryId);
$stmt->execute();
$result = $stmt->get_result();
$heads = $result->fetch_all(MYSQLI_ASSOC);
$stmt->close();
echo json_encode($heads);
} catch (Exception $e) {
echo json_encode(['error' => 'Database error']);
error_log("Get expense heads error: " . $e->getMessage());
}
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 25: index.php
- Type: PHP
- Size: 73 B
- Path: .
- Name: index.php
------------------------------------------------------------
-------------------- END OF FILE --------------------
### FILE 26: login.php
- Type: PHP
- Size: 4.67 KB
- Path: .
- Name: login.php
------------------------------------------------------------
prepare($query);
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 1) {
$user = $result->fetch_assoc();
// Verify password
if (password_verify($password, $user['password'])) {
// Regenerate session ID to prevent session fixation
session_regenerate_id(true);
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['last_activity'] = time();
header("Location: dashboard.php");
exit();
} else {
$error = "Invalid username or password.";
// Log failed attempt
error_log("Failed login attempt for user: " . $username);
}
} else {
$error = "Invalid username or password.";
}
$stmt->close();
}
}
}
// Generate CSRF token
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
?>
Login - Kayal Aqua 2025
close(); ?>
-------------------- END OF FILE --------------------
### FILE 27: logout.php
- Type: PHP
- Size: 295 B
- Path: .
- Name: logout.php
------------------------------------------------------------
-------------------- END OF FILE --------------------
### FILE 28: main_layout.php
- Type: PHP
- Size: 5.78 KB
- Path: .
- Name: main_layout.php
------------------------------------------------------------
Kayal Aqua 2025
-------------------- END OF FILE --------------------
### FILE 29: payments.php
- Type: PHP
- Size: 4.03 KB
- Path: .
- Name: payments.php
------------------------------------------------------------
1800)) {
header("Location: logout.php");
exit();
}
$_SESSION['last_activity'] = time();
require_once 'db_connection.php';
$pageTitle = "Payments";
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_payment'])) {
try {
$stmt = $conn->prepare("INSERT INTO payments (date, buyer_id, amount_paid, balance) VALUES (?, ?, ?, 0)");
$stmt->bind_param("sid", $_POST['date'], $_POST['buyer_id'], $_POST['amount_paid']);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Payment added successfully!";
header("Location: payments.php");
exit();
} catch (Exception $e) {
$_SESSION['error'] = "Error adding payment.";
error_log("Payments error: " . $e->getMessage());
}
}
$buyersQuery = "SELECT id, name FROM buyers ORDER BY name";
$buyers = $conn->query($buyersQuery)->fetch_all(MYSQLI_ASSOC);
$paymentsQuery = "SELECT p.*, b.name as buyer_name FROM payments p JOIN buyers b ON p.buyer_id = b.id ORDER BY p.date DESC";
$payments = $conn->query($paymentsQuery)->fetch_all(MYSQLI_ASSOC);
$buyerOptions = '';
foreach ($buyers as $buyer) {
$buyerOptions .= "{$buyer['name']} ";
}
$paymentRows = '';
foreach ($payments as $payment) {
$paymentRows .= "
{$payment['date']}
{$payment['buyer_name']}
₹" . number_format($payment['amount_paid'], 2) . "
";
}
$content = <<
Date
Buyer
Amount Paid
Actions
$paymentRows
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 30: sales.php
- Type: PHP
- Size: 9.67 KB
- Path: .
- Name: sales.php
------------------------------------------------------------
1800)) {
header("Location: logout.php");
exit();
}
$_SESSION['last_activity'] = time();
require_once 'db_connection.php';
$pageTitle = "Sales";
// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_sale'])) {
try {
$date = $_POST['date'];
$buyer_id = intval($_POST['buyer_id']);
$weight_tilapia = floatval($_POST['weight_tilapia']);
$weight_small_fish = floatval($_POST['weight_small_fish']);
$weight_big_fish = floatval($_POST['weight_big_fish']);
$include_delivery = isset($_POST['include_delivery']) ? 1 : 0;
$final_amount = floatval($_POST['final_amount']);
$harvesting_charges = floatval($_POST['harvesting_charges']);
$stmt = $conn->prepare("INSERT INTO sales (date, buyer_id, weight_tilapia, weight_small_fish, weight_big_fish, include_delivery, final_amount, harvesting_charges) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sidddidi", $date, $buyer_id, $weight_tilapia, $weight_small_fish, $weight_big_fish, $include_delivery, $final_amount, $harvesting_charges);
$stmt->execute();
$stmt->close();
$_SESSION['success'] = "Sale added successfully!";
header("Location: sales.php");
exit();
} catch (Exception $e) {
$_SESSION['error'] = "Error adding sale.";
error_log("Sales error: " . $e->getMessage());
}
}
// Get buyers
$buyersQuery = "SELECT id, name FROM buyers ORDER BY name";
$buyers = $conn->query($buyersQuery)->fetch_all(MYSQLI_ASSOC);
// Pagination
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$per_page = 20;
$offset = ($page - 1) * $per_page;
// Get total sales count
$totalQuery = "SELECT COUNT(*) as total FROM sales";
$totalResult = $conn->query($totalQuery);
$totalSales = $totalResult->fetch_assoc()['total'];
$totalPages = ceil($totalSales / $per_page);
// Get sales
$salesQuery = "SELECT s.*, b.name as buyer_name FROM sales s JOIN buyers b ON s.buyer_id = b.id ORDER BY s.date DESC LIMIT $offset, $per_page";
$sales = $conn->query($salesQuery)->fetch_all(MYSQLI_ASSOC);
// Generate buyer options
$buyerOptions = '';
foreach ($buyers as $buyer) {
$buyerOptions .= "{$buyer['name']} ";
}
// Generate sales rows
$salesRows = '';
foreach ($sales as $sale) {
$salesRows .= "
{$sale['date']}
{$sale['buyer_name']}
" . number_format($sale['weight_tilapia'], 2) . " kg
" . number_format($sale['weight_small_fish'], 2) . " kg
" . number_format($sale['weight_big_fish'], 2) . " kg
" . ($sale['include_delivery'] ? 'Yes' : 'No') . "
₹" . number_format($sale['final_amount'], 2) . "
";
}
// Generate pagination
$pagination = '';
if ($totalPages > 1) {
$pagination = '';
}
$content = <<
Date
Buyer
Tilapia
Small Fish
Big Fish
Delivery
Amount
Actions
$salesRows
$pagination
HTML;
include 'main_layout.php';
$conn->close();
?>
-------------------- END OF FILE --------------------
### FILE 31: styles.css
- Type: CSS
- Size: 14.02 KB
- Path: .
- Name: styles.css
------------------------------------------------------------
/* Kayal Aqua 2025 - Modern Professional Stylesheet */
/* Import Professional Font - Inter */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
:root {
/* Professional Color Palette - Ocean Theme */
--primary-color: #0f4c81;
--primary-dark: #0a3359;
--primary-light: #1a6bb3;
--accent-color: #f8f9fa;
--secondary-color: #64b5f6;
/* Background Colors */
--bg-main: #f5f7fa;
--bg-card: #ffffff;
--bg-hover: #f0f2f5;
/* Text Colors */
--text-primary: #2c3e50;
--text-secondary: #6c757d;
--text-light: #95a5a6;
/* Border & Shadow */
--border-color: #e1e8ed;
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
--shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.12);
/* Status Colors */
--success: #27ae60;
--warning: #f39c12;
--danger: #e74c3c;
--info: #3498db;
/* Spacing */
--spacing-xs: 0.5rem;
--spacing-sm: 1rem;
--spacing-md: 1.5rem;
--spacing-lg: 2rem;
--spacing-xl: 3rem;
/* Border Radius */
--radius-sm: 4px;
--radius-md: 8px;
--radius-lg: 12px;
--radius-full: 50px;
}
/* Reset & Base Styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: var(--bg-main);
color: var(--text-primary);
line-height: 1.6;
font-size: 15px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* Container */
.container {
width: 100%;
max-width: 1400px;
margin: 0 auto;
padding: 0 var(--spacing-md);
}
/* Header */
.header {
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
color: var(--accent-color);
padding: 0;
box-shadow: var(--shadow-md);
position: sticky;
top: 0;
z-index: 1000;
}
.header-content {
display: flex;
justify-content: space-between;
align-items: center;
padding: var(--spacing-sm) var(--spacing-md);
}
.logo-container {
display: flex;
align-items: center;
gap: var(--spacing-sm);
}
.logo-icon {
font-size: 2rem;
}
.logo-text {
font-size: 1.5rem;
font-weight: 700;
letter-spacing: -0.5px;
}
.logo-subtitle {
font-size: 0.75rem;
opacity: 0.9;
display: block;
margin-top: -4px;
font-weight: 400;
}
/* Navigation */
.nav-toggle {
display: none;
background: transparent;
border: none;
color: var(--accent-color);
font-size: 1.5rem;
cursor: pointer;
padding: var(--spacing-xs);
}
.main-nav {
display: flex;
}
.main-nav ul {
display: flex;
list-style: none;
gap: var(--spacing-xs);
}
.main-nav a {
color: var(--accent-color);
text-decoration: none;
padding: var(--spacing-sm) var(--spacing-md);
border-radius: var(--radius-md);
font-weight: 500;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: var(--spacing-xs);
}
.main-nav a:hover,
.main-nav a.active {
background: rgba(255, 255, 255, 0.15);
transform: translateY(-2px);
}
.main-nav i {
font-size: 1.1rem;
}
/* Cards */
.card {
background: var(--bg-card);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-sm);
margin-bottom: var(--spacing-lg);
overflow: hidden;
transition: box-shadow 0.3s ease;
}
.card:hover {
box-shadow: var(--shadow-md);
}
.card-header {
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
color: var(--accent-color);
padding: var(--spacing-md);
display: flex;
justify-content: space-between;
align-items: center;
}
.card-header h2 {
font-size: 1.25rem;
font-weight: 600;
display: flex;
align-items: center;
gap: var(--spacing-sm);
}
.card-body {
padding: var(--spacing-lg);
}
/* Forms */
.form-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: var(--spacing-md);
margin-bottom: var(--spacing-md);
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group label {
font-weight: 500;
margin-bottom: var(--spacing-xs);
color: var(--text-primary);
font-size: 0.9rem;
}
.form-control,
input[type="text"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="password"],
input[type="email"],
select,
textarea {
width: 100%;
padding: 0.75rem var(--spacing-sm);
border: 2px solid var(--border-color);
border-radius: var(--radius-md);
font-size: 0.95rem;
font-family: inherit;
transition: all 0.3s ease;
background: var(--bg-card);
}
.form-control:focus,
input:focus,
select:focus,
textarea:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.1);
}
.checkbox-group {
display: flex;
align-items: center;
gap: var(--spacing-sm);
padding: var(--spacing-sm) 0;
}
.checkbox-group input[type="checkbox"] {
width: 20px;
height: 20px;
cursor: pointer;
}
/* Buttons */
.btn {
padding: 0.75rem 1.5rem;
border: none;
border-radius: var(--radius-md);
font-size: 0.95rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: var(--spacing-xs);
text-decoration: none;
font-family: inherit;
}
.btn-primary {
background: var(--primary-color);
color: var(--accent-color);
}
.btn-primary:hover {
background: var(--primary-dark);
transform: translateY(-2px);
box-shadow: var(--shadow-md);
}
.btn-success {
background: var(--success);
color: white;
}
.btn-success:hover {
background: #229954;
transform: translateY(-2px);
}
.btn-secondary {
background: var(--text-secondary);
color: white;
}
.btn-secondary:hover {
background: #5a6268;
}
.btn-sm {
padding: 0.5rem 1rem;
font-size: 0.85rem;
}
.btn-export {
background: var(--secondary-color);
color: white;
}
.btn-export:hover {
background: #42a5f5;
}
/* Tables */
.table-responsive {
overflow-x: auto;
-webkit-overflow-scrolling: touch;
border-radius: var(--radius-md);
}
.data-table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
}
.data-table thead {
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
color: var(--accent-color);
}
.data-table th {
padding: 1rem;
text-align: left;
font-weight: 600;
white-space: nowrap;
}
.data-table td {
padding: 1rem;
border-bottom: 1px solid var(--border-color);
}
.data-table tbody tr {
transition: background-color 0.2s ease;
}
.data-table tbody tr:hover {
background-color: var(--bg-hover);
}
.data-table tbody tr:last-child td {
border-bottom: none;
}
/* Action Buttons in Tables */
.action-btns {
display: flex;
gap: var(--spacing-xs);
}
.btn-edit,
.btn-delete {
padding: 0.5rem 0.75rem;
border-radius: var(--radius-sm);
color: white;
text-decoration: none;
font-size: 0.85rem;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 0.25rem;
}
.btn-edit {
background: var(--info);
}
.btn-edit:hover {
background: #2980b9;
transform: scale(1.05);
}
.btn-delete {
background: var(--danger);
}
.btn-delete:hover {
background: #c0392b;
transform: scale(1.05);
}
/* Dashboard Stats */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: var(--spacing-md);
margin-bottom: var(--spacing-lg);
}
.stat-card {
background: var(--bg-card);
padding: var(--spacing-lg);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-sm);
border-left: 4px solid var(--primary-color);
transition: all 0.3s ease;
}
.stat-card:hover {
transform: translateY(-4px);
box-shadow: var(--shadow-md);
}
.stat-header {
display: flex;
align-items: center;
gap: var(--spacing-sm);
margin-bottom: var(--spacing-sm);
color: var(--text-secondary);
font-size: 0.9rem;
font-weight: 500;
}
.stat-icon {
font-size: 1.5rem;
color: var(--primary-color);
}
.stat-value {
font-size: 2rem;
font-weight: 700;
color: var(--text-primary);
}
/* Alerts/Flash Messages */
.alert {
padding: var(--spacing-md);
border-radius: var(--radius-md);
margin-bottom: var(--spacing-md);
display: flex;
align-items: center;
gap: var(--spacing-sm);
}
.alert-success {
background: #d4edda;
color: #155724;
border-left: 4px solid var(--success);
}
.alert-error {
background: #f8d7da;
color: #721c24;
border-left: 4px solid var(--danger);
}
.alert-info {
background: #d1ecf1;
color: #0c5460;
border-left: 4px solid var(--info);
}
/* Pagination */
.pagination {
display: flex;
justify-content: center;
align-items: center;
gap: var(--spacing-xs);
margin-top: var(--spacing-lg);
flex-wrap: wrap;
}
.pagination a {
padding: 0.5rem 0.75rem;
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
color: var(--text-primary);
text-decoration: none;
transition: all 0.3s ease;
min-width: 40px;
text-align: center;
}
.pagination a:hover {
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
}
.pagination a.active {
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
}
.pagination-ellipsis {
padding: 0.5rem;
color: var(--text-secondary);
}
/* Login Page */
.login-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: var(--spacing-md);
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}
.login-card {
background: var(--bg-card);
padding: var(--spacing-xl);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-lg);
width: 100%;
max-width: 400px;
}
.login-header {
text-align: center;
margin-bottom: var(--spacing-lg);
}
.login-logo {
font-size: 3rem;
color: var(--primary-color);
margin-bottom: var(--spacing-sm);
}
.login-title {
font-size: 1.75rem;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 0.25rem;
}
.login-subtitle {
color: var(--text-secondary);
font-size: 0.9rem;
}
/* Mobile Responsive Design */
@media screen and (max-width: 768px) {
.container {
padding: 0 var(--spacing-sm);
}
.header-content {
padding: var(--spacing-sm);
}
.logo-text {
font-size: 1.25rem;
}
.logo-subtitle {
font-size: 0.7rem;
}
.nav-toggle {
display: block;
}
.main-nav {
position: fixed;
top: 60px;
left: -100%;
width: 80%;
max-width: 300px;
height: calc(100vh - 60px);
background: var(--primary-dark);
transition: left 0.3s ease;
box-shadow: var(--shadow-lg);
overflow-y: auto;
}
.main-nav.active {
left: 0;
}
.main-nav ul {
flex-direction: column;
padding: var(--spacing-md);
}
.main-nav li {
width: 100%;
}
.main-nav a {
width: 100%;
justify-content: flex-start;
padding: var(--spacing-md);
}
/* Mobile Table Optimization */
.data-table {
font-size: 0.85rem;
}
.data-table thead {
display: none;
}
.data-table tbody tr {
display: block;
margin-bottom: var(--spacing-md);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
overflow: hidden;
}
.data-table td {
display: flex;
justify-content: space-between;
align-items: center;
padding: var(--spacing-sm);
border: none;
border-bottom: 1px solid var(--border-color);
}
.data-table td:last-child {
border-bottom: none;
}
.data-table td::before {
content: attr(data-label);
font-weight: 600;
color: var(--text-secondary);
}
/* Mobile Form Grid */
.form-grid {
grid-template-columns: 1fr;
}
/* Mobile Stats Grid */
.stats-grid {
grid-template-columns: 1fr;
}
.stat-value {
font-size: 1.75rem;
}
/* Mobile Cards */
.card-body {
padding: var(--spacing-md);
}
/* Mobile Buttons */
.btn {
width: 100%;
justify-content: center;
}
.action-btns {
width: 100%;
justify-content: flex-end;
}
.action-btns .btn-edit,
.action-btns .btn-delete {
width: auto;
}
}
@media screen and (max-width: 480px) {
.logo-text {
font-size: 1.1rem;
}
.logo-subtitle {
display: none;
}
.card-header h2 {
font-size: 1.1rem;
}
.stat-value {
font-size: 1.5rem;
}
}
/* Utility Classes */
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
.mt-1 { margin-top: var(--spacing-xs); }
.mt-2 { margin-top: var(--spacing-sm); }
.mt-3 { margin-top: var(--spacing-md); }
.mt-4 { margin-top: var(--spacing-lg); }
.mb-1 { margin-bottom: var(--spacing-xs); }
.mb-2 { margin-bottom: var(--spacing-sm); }
.mb-3 { margin-bottom: var(--spacing-md); }
.mb-4 { margin-bottom: var(--spacing-lg); }
.hidden {
display: none;
}
/* Loading Spinner */
.spinner {
border: 3px solid var(--border-color);
border-top: 3px solid var(--primary-color);
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: var(--spacing-lg) auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Print Styles */
@media print {
.header,
.nav-toggle,
.main-nav,
.btn,
.action-btns {
display: none !important;
}
.card {
box-shadow: none;
page-break-inside: avoid;
}
}
-------------------- END OF FILE --------------------
================================================================================
## SUMMARY
================================================================================
Repository contains 31 files total.
All file contents have been extracted and are shown above.
This repository snapshot was generated on: 2026-02-04 22:11:31
================================================================================
## END OF REPOSITORY
================================================================================