<?php
require_once "labClass.php";
$con = new labClass();

if (isset($_POST['submit'])) {
    $category = trim($_POST['category']);
    $source = trim($_POST['source']);
    $amount = trim($_POST['amount']);
    $sdate = trim($_POST['sdate']);
    $description = trim($_POST['description']);
    $user = $_POST['user']; // you can replace with $_SESSION['user'] if available

    if ($category != "" && $source != "" && $amount > 0) {
        try {
            $con->cashEx($category,$source,$amount,$description,$sdate,$user);
            echo "<div class='alert alert-success p-2'>Record saved successfully.</div>";
        } catch (PDOException $e) {
            echo "<div class='alert alert-danger p-2'>Error saving record: " . $e->getMessage() . "</div>";
        }
    } else {
        echo "<div class='alert alert-warning p-2'>All required fields must be filled correctly.</div>";
    }
}
?>
