<?php
require_once __DIR__ . "/includes/db.php";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $sender = $_POST['sender_name'];
    $phone  = $_POST['phone'];
    $amount = $_POST['amount'];
    $bank   = $_POST['bank_account_id'];

    $slipName = time() . "_" . $_FILES['slip']['name'];
    move_uploaded_file($_FILES['slip']['tmp_name'], __DIR__ . "/assets/uploads/" . $slipName);

    $stmt = $pdo->prepare("INSERT INTO orders (sender_name, phone, amount, bank_account_id, slip, status) VALUES (?, ?, ?, ?, ?, 'بانتظار')");
    $stmt->execute([$sender, $phone, $amount, $bank, $slipName]);

    header("Location: /user/dashboard.php?msg=تم رفع طلبك بنجاح وسيتم مراجعته");
    exit;
}
