| Server IP : 198.54.126.135 / Your IP : 216.73.216.217 Web Server : Apache System : Linux host11.registrar-servers.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : linearpo ( 12988) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/linearpo/app.linear-pos.com/ |
Upload File : |
<?php
// transactions.php - Handle Deposits and Withdrawals
require_once 'config.php';
checkAuth();
$success = '';
$error = '';
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$customer_name = $conn->real_escape_string($_POST['customer_name']);
$customer_phone = $conn->real_escape_string($_POST['customer_phone']);
$transaction_type = $conn->real_escape_string($_POST['transaction_type']);
$amount = floatval($_POST['amount']);
$reference_number = $conn->real_escape_string($_POST['reference_number'] ?? '');
$notes = $conn->real_escape_string($_POST['notes'] ?? '');
// Validate float availability
$float = getCurrentFloat($conn, $_SESSION['user_id']);
if ($transaction_type == 'withdrawal' && $float['cash_balance'] < $amount) {
$error = 'Insufficient cash float for this withdrawal';
} elseif ($transaction_type == 'deposit' && $float['digital_balance'] < $amount) {
$error = 'Insufficient digital float for this deposit';
} else {
$sql = "INSERT INTO transactions (user_id, customer_name, customer_phone, transaction_type, amount, reference_number, notes)
VALUES ({$_SESSION['user_id']}, '$customer_name', '$customer_phone', '$transaction_type', $amount, '$reference_number', '$notes')";
if ($conn->query($sql)) {
$success = ucfirst($transaction_type) . ' of KES ' . number_format($amount, 2) . ' recorded successfully!';
} else {
$error = 'Error recording transaction: ' . $conn->error;
}
}
}
$default_type = $_GET['type'] ?? 'deposit';
$page_title = "New Transaction";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $page_title; ?> - M-Pesa Agent System</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
<style>
:root { --mpesa-green: #00a650; }
body { background-color: #f8f9fa; }
.navbar { background: linear-gradient(135deg, var(--mpesa-green) 0%, #008f43 100%); }
.sidebar { min-height: calc(100vh - 56px); background: white; box-shadow: 2px 0 10px rgba(0,0,0,0.1); }
.sidebar .nav-link { color: #333; padding: 15px 20px; }
.sidebar .nav-link:hover, .sidebar .nav-link.active { background-color: rgba(0, 166, 80, 0.1); color: var(--mpesa-green); border-right: 3px solid var(--mpesa-green); }
.sidebar .nav-link i { margin-right: 10px; width: 20px; }
.transaction-card { background: white; border-radius: 15px; box-shadow: 0 5px 15px rgba(0,0,0,0.08); }
.type-selector { cursor: pointer; transition: all 0.3s; }
.type-selector.active { border-color: var(--mpesa-green) !important; background-color: rgba(0, 166, 80, 0.05); }
.type-selector.deposit.active { border-color: #00a650 !important; background-color: rgba(0, 166, 80, 0.05); }
.type-selector.withdrawal.active { border-color: #dc3545 !important; background-color: rgba(220, 53, 69, 0.05); }
.btn-submit { background: var(--mpesa-green); border: none; }
.btn-submit:hover { background: #008f43; }
.float-warning { background: #fff3cd; border-left: 4px solid #ffc107; }
</style>
</head>
<body>
<nav class="navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="dashboard.php"><i class="bi bi-phone-fill me-2"></i><strong>M-Pesa Agent</strong> System</a>
<div class="d-flex align-items-center text-white">
<span class="me-3"><i class="bi bi-person-circle me-1"></i> <?php echo $_SESSION['full_name']; ?></span>
<a href="logout.php" class="btn btn-outline-light btn-sm"><i class="bi bi-box-arrow-right"></i> Logout</a>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-2 sidebar p-0">
<nav class="nav flex-column">
<a class="nav-link" href="dashboard.php"><i class="bi bi-speedometer2"></i> Dashboard</a>
<a class="nav-link active" href="transactions.php"><i class="bi bi-cash-coin"></i> Transactions</a>
<a class="nav-link" href="float_management.php"><i class="bi bi-wallet2"></i> Float Management</a>
<a class="nav-link" href="reports.php"><i class="bi bi-graph-up"></i> Reports</a>
<?php if ($_SESSION['role'] == 'admin'): ?>
<a class="nav-link" href="users.php"><i class="bi bi-people"></i> User Management</a>
<?php endif; ?>
<a class="nav-link" href="change_password.php"><i class="bi bi-key"></i> Change Password</a>
</nav>
</div>
<div class="col-md-10 p-4">
<h2 class="mb-4"><i class="bi bi-cash-coin me-2"></i>New Transaction</h2>
<?php
$float = getCurrentFloat($conn, $_SESSION['user_id']);
?>
<div class="row mb-4">
<div class="col-md-6">
<div class="float-warning p-3 rounded">
<h6 class="mb-2"><i class="bi bi-info-circle me-2"></i>Current Float Status</h6>
<div class="row">
<div class="col-6">
<small class="text-muted">Cash Available</small>
<div class="fw-bold text-warning">KES <?php echo number_format($float['cash_balance'], 2); ?></div>
</div>
<div class="col-6">
<small class="text-muted">Digital Available</small>
<div class="fw-bold text-info">KES <?php echo number_format($float['digital_balance'], 2); ?></div>
</div>
</div>
</div>
</div>
</div>
<?php if ($success): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="bi bi-check-circle-fill me-2"></i><?php echo $success; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="bi bi-exclamation-triangle-fill me-2"></i><?php echo $error; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="transaction-card p-4">
<form method="POST" action="" id="transactionForm">
<!-- Transaction Type Selector -->
<div class="row mb-4">
<div class="col-md-6 mx-auto">
<div class="row g-3">
<div class="col-6">
<div class="type-selector deposit border rounded p-3 text-center <?php echo $default_type == 'deposit' ? 'active' : ''; ?>" onclick="selectType('deposit')">
<i class="bi bi-arrow-down-circle text-success fs-2"></i>
<div class="mt-2 fw-bold">Deposit</div>
<small class="text-muted">Customer puts in cash</small>
</div>
</div>
<div class="col-6">
<div class="type-selector withdrawal border rounded p-3 text-center <?php echo $default_type == 'withdrawal' ? 'active' : ''; ?>" onclick="selectType('withdrawal')">
<i class="bi bi-arrow-up-circle text-danger fs-2"></i>
<div class="mt-2 fw-bold">Withdrawal</div>
<small class="text-muted">Customer takes cash</small>
</div>
</div>
</div>
<input type="hidden" name="transaction_type" id="transaction_type" value="<?php echo $default_type; ?>">
</div>
</div>
<div class="row g-3">
<div class="col-md-6">
<label class="form-label fw-bold">Customer Name *</label>
<div class="input-group">
<span class="input-group-text"><i class="bi bi-person"></i></span>
<input type="text" class="form-control form-control-lg" name="customer_name" required placeholder="Enter customer full name">
</div>
</div>
<div class="col-md-6">
<label class="form-label fw-bold">Customer Phone *</label>
<div class="input-group">
<span class="input-group-text"><i class="bi bi-phone"></i></span>
<input type="tel" class="form-control form-control-lg" name="customer_phone" required placeholder="07XX XXX XXX" pattern="[0-9]{10,12}">
</div>
</div>
<div class="col-md-6">
<label class="form-label fw-bold">Amount (KES) *</label>
<div class="input-group">
<span class="input-group-text">KES</span>
<input type="number" class="form-control form-control-lg" name="amount" required min="1" step="0.01" placeholder="0.00">
</div>
<div class="form-text" id="amountHelp">Minimum transaction: KES 1</div>
</div>
<div class="col-md-6">
<label class="form-label fw-bold">Reference Number</label>
<div class="input-group">
<span class="input-group-text"><i class="bi bi-hash"></i></span>
<input type="text" class="form-control form-control-lg" name="reference_number" placeholder="M-Pesa confirmation code (optional)">
</div>
</div>
<div class="col-12">
<label class="form-label fw-bold">Notes</label>
<textarea class="form-control" name="notes" rows="2" placeholder="Any additional information..."></textarea>
</div>
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end mt-4">
<button type="reset" class="btn btn-outline-secondary btn-lg px-4">Clear</button>
<button type="submit" class="btn btn-submit btn-lg text-white px-5">
<i class="bi bi-check-circle me-2"></i>Complete Transaction
</button>
</div>
</form>
</div>
<!-- Today's Transactions List -->
<h4 class="mt-5 mb-3"><i class="bi bi-list-check me-2"></i>Today's Transactions</h4>
<div class="transaction-card p-0 overflow-hidden">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th>Time</th>
<th>Customer</th>
<th>Type</th>
<th>Amount</th>
<th>Reference</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php
$today_trans = $conn->query("SELECT * FROM transactions
WHERE user_id = {$_SESSION['user_id']} AND DATE(created_at) = CURDATE()
ORDER BY created_at DESC");
if ($today_trans->num_rows > 0) {
while ($row = $today_trans->fetch_assoc()) {
$badge = $row['transaction_type'] == 'deposit'
? '<span class="badge bg-success"><i class="bi bi-arrow-down me-1"></i>Deposit</span>'
: '<span class="badge bg-danger"><i class="bi bi-arrow-up me-1"></i>Withdrawal</span>';
echo "<tr>";
echo "<td>" . date('H:i:s', strtotime($row['created_at'])) . "</td>";
echo "<td>" . htmlspecialchars($row['customer_name']) . "<br><small class='text-muted'>" . $row['customer_phone'] . "</small></td>";
echo "<td>{$badge}</td>";
echo "<td class='fw-bold'>KES " . number_format($row['amount'], 2) . "</td>";
echo "<td>" . ($row['reference_number'] ? '<code>' . $row['reference_number'] . '</code>' : '-') . "</td>";
echo "<td><small class='text-muted'>" . htmlspecialchars($row['notes'] ?: '-') . "</small></td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='6' class='text-center text-muted py-4'>No transactions recorded today</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
function selectType(type) {
document.querySelectorAll('.type-selector').forEach(el => el.classList.remove('active'));
document.querySelector('.type-selector.' + type).classList.add('active');
document.getElementById('transaction_type').value = type;
// Update help text
const helpText = type === 'deposit'
? 'Cash you receive from customer (max: your digital float)'
: 'Cash you give to customer (max: your cash float)';
document.getElementById('amountHelp').textContent = helpText;
}
</script>
</body>
</html>