Go back"); } // Check permissions $user_role = $_SESSION['role']; $user_id = $_SESSION['user_id']; if ($user_role === 'supplier' && $supply['supplier_id'] != $user_id) { die("You can only edit your own supplies. Go back"); } // Get fish types $fish_types = fetchAll("SELECT fish_id, fish_name_english, fish_name_tamil FROM fish_types WHERE status = 'active' ORDER BY fish_name_english"); // Get suppliers (for admin/manager) $suppliers = []; if (hasRole(['admin', 'manager'])) { $suppliers = fetchAll("SELECT user_id, full_name, role FROM users WHERE (role = 'supplier' OR role = 'manager') AND status = 'active' ORDER BY full_name"); } // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $supply_date = $_POST['supply_date']; $supplier_id = hasRole(['admin', 'manager']) ? intval($_POST['supplier_id']) : $user_id; $fish_id = intval($_POST['fish_id']); $weight_kg = floatval($_POST['weight_kg']); $rate_per_kg = floatval($_POST['rate_per_kg']); $manual_total = isset($_POST['manual_total']) && $_POST['manual_total'] === '1'; if ($manual_total) { $total_amount = floatval($_POST['total_amount']); } else { $total_amount = $weight_kg * $rate_per_kg; } $notes = trim($_POST['notes']); // Validation if (empty($supply_date) || $fish_id <= 0 || $weight_kg <= 0 || $rate_per_kg <= 0 || $total_amount <= 0) { $error = "Please fill all required fields with valid values"; } else { // Update supply $sql = "UPDATE supply SET supply_date = ?, supplier_id = ?, fish_id = ?, weight_kg = ?, rate_per_kg = ?, total_amount = ?, notes = ? WHERE supply_id = ?"; if (executeQuery($sql, "siidddsi", [$supply_date, $supplier_id, $fish_id, $weight_kg, $rate_per_kg, $total_amount, $notes, $supply_id])) { logActivity($_SESSION['user_id'], 'UPDATE', 'supply', "Edited supply #$supply_id"); $success = "Supply entry updated successfully!"; // Reload supply data $supply = fetchSingle(" SELECT s.*, u.full_name, u.role, f.fish_name_english, f.fish_name_tamil FROM supply s JOIN users u ON s.supplier_id = u.user_id JOIN fish_types f ON s.fish_id = f.fish_id WHERE s.supply_id = ? ", "i", [$supply_id]); } else { $error = "Failed to update supply entry"; } } } $page_title = 'Edit Supply'; require_once __DIR__ . '/../includes/header.php'; ?>

Edit Supply Entry #

Current Details

Manager
kg
/kg

Edit Supply Entry

Cancel 🗑️ Delete Entry