<?php
session_start();
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../classes/Database.php';
require_once __DIR__ . '/../../classes/sales.php';


$database = new Database();
$conn = $database->getConnection();
$auth = new Auth($conn);

if (!isset($_SESSION['user_id'])) {
    header('Location: /IMS/login.php');
    exit();
}

$database = new Database();
$conn = $database->getConnection();
$sales = new Sales($conn);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $branchId = $_SESSION['branch_id'];
    $depositDate = $_POST['deposit_date'];
    $depositAmount = $_POST['deposit_amount'];


    $result = $sales->addDeposit($branchId, $depositDate, $depositAmount);

    if ($result) {
        $_SESSION['success_message'] = "Deposit added successfully.";
    } else {
        $_SESSION['error_message'] = "Failed to add deposit.";
    }


    header('Location: weekly_report.php');
    exit();
}
?>