implemented admin or bm approval functionality

This commit is contained in:
ns77@siliconpin.com
2025-09-10 13:57:41 +00:00
parent 4a1128066d
commit 5a12de1c64
8 changed files with 2293 additions and 65 deletions

View File

@@ -2,6 +2,47 @@
include(__DIR__ . '/auth.php');
require_login();
date_default_timezone_set('Asia/Kolkata');
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$pendingCount = 0; // Default value
try {
$table = 'fund_trans';
// Check user type and prepare appropriate query
if ($_SESSION['type'] === 'admin') {
// Admin can only see BM requests
$countStmt = $conn->prepare("SELECT COUNT(*) AS pending_count FROM `$table` WHERE status = 0 AND request_usr_type = 'bm'");
} elseif ($_SESSION['type'] === 'bm') {
// BM can only see Admin requests
$countStmt = $conn->prepare("SELECT COUNT(*) AS pending_count FROM `$table` WHERE status = 0 AND request_usr_type = 'admin'");
} else {
// Other user types see nothing
$countStmt = false;
$pendingCount = 0;
}
if ($countStmt) {
$countStmt->execute();
$countResult = $countStmt->get_result();
if ($countResult) {
$row = $countResult->fetch_assoc();
$pendingCount = $row['pending_count'] ?? 0;
}
$countStmt->close();
}
} catch (Exception $e) {
// Log error instead of showing to user
error_log("Error getting pending count: " . $e->getMessage());
}
$conn->close();
?>
<style>
.logo {
@@ -19,6 +60,14 @@ date_default_timezone_set('Asia/Kolkata');
align-items: center;
}
/* Dropdown menu styling */
.dropdown-menu > li > a {
padding: 10px 20px;
}
.navbar-nav > li > .dropdown-menu {
border-top: 2px solid #337ab7;
}
/* Mobile-specific styles */
@media (max-width: 767px) {
.mobile-welcome,
@@ -30,6 +79,21 @@ date_default_timezone_set('Asia/Kolkata');
.navbar-right {
display: none !important; /* hide right side in mobile */
}
/* Adjust dropdown for mobile */
.navbar-nav .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
box-shadow: none;
}
.navbar-nav .open .dropdown-menu > li > a {
padding: 10px 15px 10px 35px;
color: #777;
}
}
/* Desktop styles */
@@ -56,9 +120,6 @@ date_default_timezone_set('Asia/Kolkata');
</button>
<!-- Mobile profile + welcome -->
<img class="mobile-profile"
src="<?php echo $imagePath; ?>"
width="40" height="40"
@@ -72,39 +133,45 @@ date_default_timezone_set('Asia/Kolkata');
<?php
$userType = $_SESSION['type'] ?? '';
if ($userType === 'admin') {
if ($userType === 'admin' || $userType === 'bm') {
?>
<li><a href="/Admin/Create_AC_Recurring">New Recurring</a></li>
<li><a href="/Admin/Create_AC_FD">New FD</a></li>
<li><a href="/Admin/Create_AC_Loan">New Loan</a></li>
<li><a href="/Admin/Add_group">Add New Group</a></li>
<li><a href="/Admin/Trans_New">Transaction</a></li>
<!-- Create New Dropdown Menu -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Create New <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="/Admin/Create_AC_Recurring">New Recurring</a></li>
<li><a href="/Admin/Create_AC_FD">New FD</a></li>
<li><a href="/Admin/Create_AC_Loan">New Loan</a></li>
<li role="separator" class="divider"></li>
<li><a href="/Admin/Add_group">Add New Group</a></li>
</ul>
</li>
<li><a href="/Admin/View_AC?Type=Recurring">View A/C</a></li>
<!-- Other menu items -->
<li><a href="/Admin/Trans_New">Transaction</a></li>
<?php if ($userType === 'admin') { ?>
<li><a href="/Admin/agent-targets">Agent Targets</a></li>
<li><a href="/Admin/agent_View_report">Commission</a></li>
<?php } ?>
<li><a href="/Admin/agent_View_report">Commission</a></li>
<?php if ($userType === 'admin') { ?>
<li><a href="/Admin/View_AC?Type=Recurring">View A/C</a></li>
<li><a href="/Admin/upcoming-maturity">Upcoming Maturity</a></li>
<?php } ?>
<li><a href="/Admin/upcoming-maturity">Upcoming Maturity</a></li>
<?php if ($userType === 'admin') { ?>
<li><a href="/Admin/Report">Report</a></li>
<li><a href="/Admin/Due">Deemand Sheet</a></li>
<li><a href="/Admin/Settings_Agent">Agent Settings</a></li>
<?php
} elseif ($userType === 'bm') {
?>
<li><a href="/Admin/Create_AC_Recurring">New Recurring</a></li>
<li><a href="/Admin/Create_AC_FD">New FD</a></li>
<li><a href="/Admin/Create_AC_Loan">New Loan</a></li>
<li><a href="/Admin/Add_group">Add New Group</a></li>
<li><a href="/Admin/upcoming-maturity">Upcoming Maturity</a></li>
<li><a href="/Admin/Trans_New">Transaction</a></li>
<li><a href="/Admin/agent-targets">Agent Targets</a></li>
<li><a href="/Admin/agent_View_report">Commission</a></li>
<?php
<?php } ?>
<?php
} elseif ($userType === 'agent') {
?>
<li><a href="/Admin/View_AC?Type=Recurring">View A/C</a></li>
<li><a href="/Admin/Due">Deemand Sheet</a></li>
<li><a href="/Admin/Report">Report</a></li>
<li><a href="/Admin/agent_View_report">Commission</a></li>
<?php
?>
<li><a href="/Admin/View_AC?Type=Recurring">View A/C</a></li>
<li><a href="/Admin/Due">Deemand Sheet</a></li>
<li><a href="/Admin/Report">Report</a></li>
<li><a href="/Admin/agent_View_report">Commission</a></li>
<?php
}
?>
</ul>
@@ -136,7 +203,22 @@ date_default_timezone_set('Asia/Kolkata');
?>
</li>
<li><a href="/Admin/Signout">Signout</a></li>
<li>
<a href="/Admin/notification" style="position: relative; display: inline-block; padding: 8px;">
<?php if($pendingCount > 0) { ?>
<div style="width: 18px; height: 18px; border-radius: 50%; background-color: #ff4444; position: absolute; top: 2px; right: 2px; z-index: 10; box-shadow: 0 0 0 2px rgba(255,255,255,0.8); font-size: 11px; font-weight: bold; color: white; text-align: center; line-height: 18px;">
<?= $pendingCount > 99 ? '99+' : $pendingCount ?>
</div>
<?php } ?>
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 64 64" fill="#4a5568" style="filter: drop-shadow(0 2px 2px rgba(0,0,0,0.2));">
<g>
<path fill="currentColor" d="M56,44c-1.832,0-4-2.168-4-4V20C52,8.973,43.027,0,32,0S12,8.973,12,20v20c0,1.793-2.207,4-4,4 c-2.211,0-4,1.789-4,4s1.789,4,4,4h48c2.211,0,4-1.789,4-4S58.211,44,56,44z"></path>
<path fill="currentColor" d="M32,64c4.418,0,8-3.582,8-8H24C24,60.418,27.582,64,32,64z"></path>
</g>
</svg>
</a>
</li>
</ul>
</div>
</div>
</nav>
</nav>

View File

@@ -215,14 +215,10 @@ function calculateAmount() {
}
?>
<?php
if ($_SESSION['type'] === 'admin' && isset($_GET["no"]) && isset($_GET["type"]) && $_GET["type"] == "Recurring") {
if (
$_SERVER['REQUEST_METHOD'] === 'POST'
&& isset($_POST['PAY_LOAN_EMI_FROM_RECURRING'], $_POST['PAY_LOAN_EMI_FROM_RECURRING_ID'], $_POST['DEDUCT_LOAN_AMOUNT'])
&& $_POST['PAY_LOAN_EMI_FROM_RECURRING_ID'] === 'axakassaoxnnxsaoij34866'
) {
if ($_SESSION['type'] === 'admin' || $_SESSION['type'] === 'bm' && isset($_GET["no"]) && isset($_GET["type"]) && $_GET["type"] == "Recurring") {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['PAY_LOAN_EMI_FROM_RECURRING'], $_POST['PAY_LOAN_EMI_FROM_RECURRING_ID'], $_POST['DEDUCT_LOAN_AMOUNT']) && $_POST['PAY_LOAN_EMI_FROM_RECURRING_ID'] === 'axakassaoxnnxsaoij34866') {
$loanEMIAmount = floatval($_POST['DEDUCT_LOAN_AMOUNT']);
$deductAmount = -$loanEMIAmount; // negative for recurring deduction
$deductAmount = $loanEMIAmount; // negative for recurring deduction
$paidToLoanAccountNumber = $_POST['LOAN_AC_NUMBER'];
$accountId = $_GET['no'];
@@ -259,35 +255,20 @@ if ($_SESSION['type'] === 'admin' && isset($_GET["no"]) && isset($_GET["type"])
$conn->begin_transaction();
try {
$table = $GLOBALS['arif_tran'] ?? 'arif_tran';
$userType = 'admin';
// $table = $GLOBALS['arif_tran'] ?? 'arif_tran';
$table = 'fund_trans';
$requestBy = $_SESSION['user_id'];
$requestUSRType = $_SESSION['type'];
$recACNumber = $accountId;
$loanACNumber = $paidToLoanAccountNumber;
$transferAmount = $deductAmount;
// Entry 1: Deduction from recurring
$remarksText1 = "₹$loanEMIAmount deducted from Recurring for Loan A/c $paidToLoanAccountNumber EMI";
$stmt = $conn->prepare("INSERT INTO `$table` (AT_ADMIN, AT_ACID, AT_AMOUNT, REMARKS) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssds", $userType, $accountId, $deductAmount, $remarksText1);
$stmt->execute();
$stmt->close();
// Entry 2: Credit to loan account
$remarksText2 = "₹$loanEMIAmount credited to Loan A/c $paidToLoanAccountNumber EMI (from Recurring $accountId)";
$stmt = $conn->prepare("INSERT INTO `$table` (AT_ADMIN, AT_ACID, AT_AMOUNT, REMARKS) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssds", $userType, $paidToLoanAccountNumber, $loanEMIAmount, $remarksText2);
$stmt->execute();
$stmt->close();
// Update Loan Account
$ins_no = 1;
$sql = "UPDATE `" . $GLOBALS['arif_ac'] . "` SET `AA_BAL` = `AA_BAL` + ?, `AA_NO_OF_PAYPAID` = `AA_NO_OF_PAYPAID` + ? WHERE `AA_ACNO` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("dis", $loanEMIAmount, $ins_no, $paidToLoanAccountNumber);
$stmt->execute();
$stmt->close();
// Update Recurring Account
$sql = "UPDATE `" . $GLOBALS['arif_ac'] . "` SET `AA_BAL` = `AA_BAL` - ? WHERE `AA_ACNO` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ds", $loanEMIAmount, $accountId);
// $remarksText1 = "₹$loanEMIAmount deducted from Recurring for Loan A/c $paidToLoanAccountNumber EMI";
$stmt = $conn->prepare("INSERT INTO `$table` (request_by, request_usr_type, rec_ac_number, loan_ac_number, transfer_amount) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $requestBy, $requestUSRType, $recACNumber, $loanACNumber, $transferAmount);
$stmt->execute();
$stmt->close();
@@ -310,7 +291,7 @@ if ($_SESSION['type'] === 'admin' && isset($_GET["no"]) && isset($_GET["type"])
}
?>
<?php if ($_SESSION['type'] === 'admin' && isset($_GET["no"]) && isset($_GET["type"]) && $_GET["type"] == "Recurring") { ?>
<?php if ($_SESSION['type'] === 'admin' || $_SESSION['type'] === 'bm' && isset($_GET["no"]) && isset($_GET["type"]) && $_GET["type"] == "Recurring") { ?>
<div class="container">
<h4>Pay Loan EMI from Recurring balance</h4>
<div style="display: flex; gap: 20px; flex-direction: row; max-width: 60%;">

View File

@@ -0,0 +1,502 @@
<?php
session_start();
date_default_timezone_set('Asia/Kolkata');
if (!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])) {
echo "<script>window.location.href = '/Agent/agent-login'</script>";
exit;
}
// Database connection
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Process status update if form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) {
$id = $conn->real_escape_string($_POST['id']);
$status = $conn->real_escape_string($_POST['status']);
$approved_by = $_SESSION['user_id'];
$remarks = $conn->real_escape_string($_POST['remarks'] ?? '');
try {
$conn->begin_transaction();
// First get the transaction details
$getStmt = $conn->prepare("SELECT * FROM fund_trans WHERE id = ?");
$getStmt->bind_param("i", $id);
$getStmt->execute();
$transaction = $getStmt->get_result()->fetch_assoc();
$getStmt->close();
if ($transaction) {
// Check if the current user has permission to approve this request
$can_approve = false;
// Admin can approve BM requests
if ($_SESSION['type'] === 'admin' && $transaction['request_usr_type'] === 'bm') {
$can_approve = true;
}
// BM can approve Admin requests
elseif ($_SESSION['type'] === 'bm' && $transaction['request_usr_type'] === 'admin') {
$can_approve = true;
}
if (!$can_approve) {
throw new Exception("You don't have permission to approve this request.");
}
$updateStmt = $conn->prepare("UPDATE fund_trans SET status = ?, approved_by = ?, approved_usr_type = ?, remarks = ? WHERE id = ?");
$updateStmt->bind_param("ssssi", $status, $approved_by, $_SESSION['type'], $remarks, $id);
$updateStmt->execute();
// If approved, process the fund transfer
if ($status == 1) {
$transfer_amount = abs($transaction['transfer_amount']); // Make it positive
$rec_ac_number = $transaction['rec_ac_number']; // Recurring Account Number
$loan_ac_number = $transaction['loan_ac_number']; // Loan Account Number
// Check if Recurring Account has sufficient balance
$balanceCheck = $conn->prepare("SELECT AA_BAL FROM `" . $GLOBALS['arif_ac'] . "` WHERE AA_ACNO = ?");
$balanceCheck->bind_param("s", $rec_ac_number);
$balanceCheck->execute();
$balanceCheck->bind_result($current_balance);
$balanceCheck->fetch();
$balanceCheck->close();
if ($current_balance < $transfer_amount) {
throw new Exception("Insufficient balance in Recurring Account.");
}
// Deduct from Recurring Account
$deductStmt = $conn->prepare("UPDATE `" . $GLOBALS['arif_ac'] . "` SET AA_BAL = AA_BAL - ? WHERE AA_ACNO = ?");
$deductStmt->bind_param("ds", $transfer_amount, $rec_ac_number);
$deductStmt->execute();
$deductStmt->close();
// Add to Loan Account
$addStmt = $conn->prepare("UPDATE `" . $GLOBALS['arif_ac'] . "` SET AA_BAL = AA_BAL + ? WHERE AA_ACNO = ?");
$addStmt->bind_param("ds", $transfer_amount, $loan_ac_number);
$addStmt->execute();
$addStmt->close();
// Create transaction records
$userType = $_SESSION['type'];
$table = $GLOBALS['arif_tran'] ?? 'arif_tran';
// Deduction from Recurring Account
$remarksText1 = "$transfer_amount transferred to Loan A/c $loan_ac_number";
$stmt1 = $conn->prepare("INSERT INTO `$table` (AT_ADMIN, AT_ACID, AT_AMOUNT, REMARKS) VALUES (?, ?, ?, ?)");
$negative_amount = -$transfer_amount;
$stmt1->bind_param("ssds", $userType, $rec_ac_number, $negative_amount, $remarksText1);
$stmt1->execute();
$stmt1->close();
// Credit to Loan Account
$remarksText2 = "$transfer_amount received from Recurring A/c $rec_ac_number";
$stmt2 = $conn->prepare("INSERT INTO `$table` (AT_ADMIN, AT_ACID, AT_AMOUNT, REMARKS) VALUES (?, ?, ?, ?)");
$stmt2->bind_param("ssds", $userType, $loan_ac_number, $transfer_amount, $remarksText2);
$stmt2->execute();
$stmt2->close();
}
if ($updateStmt->affected_rows > 0) {
$conn->commit();
$success_message = "Status updated successfully!";
} else {
throw new Exception("No rows affected. Update failed.");
}
$updateStmt->close();
} else {
throw new Exception("Transaction not found.");
}
} catch (Exception $e) {
$conn->rollback();
$error_message = "Error updating status: " . $e->getMessage();
}
}
// Get all pending items where status = 0
$countResult = [];
try {
$table = 'fund_trans';
// Only show requests that the current user can approve
if ($_SESSION['type'] === 'admin') {
$countStmt = $conn->prepare("SELECT * FROM `$table` WHERE status = 0 AND request_usr_type = 'bm' ORDER BY created DESC");
} elseif ($_SESSION['type'] === 'bm') {
$countStmt = $conn->prepare("SELECT * FROM `$table` WHERE status = 0 AND request_usr_type = 'admin' ORDER BY created DESC");
} else {
// For other user types, show nothing
$countStmt = $conn->prepare("SELECT * FROM `$table` WHERE status = 0 AND 1=0 ORDER BY created DESC");
}
$countStmt->execute();
$result = $countStmt->get_result();
while ($row = $result->fetch_assoc()) {
$countResult[] = $row;
}
$countStmt->close();
} catch (Exception $e) {
$error_message = "Error: " . $e->getMessage();
}
// Get approval history
$historyResult = [];
try {
if ($_SESSION['type'] === 'admin' || $_SESSION['type'] === 'bm') {
$historyStmt = $conn->prepare("SELECT * FROM `fund_trans` WHERE status != 0 ORDER BY created DESC LIMIT 20");
$historyStmt->execute();
$history = $historyStmt->get_result();
while ($row = $history->fetch_assoc()) {
$historyResult[] = $row;
}
$historyStmt->close();
}
} catch (Exception $e) {
$history_error = "Error loading history: " . $e->getMessage();
}
$conn->close();
?>
<!-- Notification Section -->
<div class="container mt-4">
<?php if (isset($success_message)): ?>
<div class="alert alert-success alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<strong>Success!</strong> <?php echo $success_message; ?>
</div>
<?php endif; ?>
<?php if (isset($error_message)): ?>
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<strong>Error!</strong> <?php echo $error_message; ?>
</div>
<?php endif; ?>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<h4 class="pull-left">Pending Fund Transfer Requests</h4>
<span class="badge pull-right"><?php echo count($countResult); ?> Pending</span>
<div class="clearfix"></div>
</div>
</div>
<div class="panel-body">
<?php if (count($countResult) > 0): ?>
<div class="table-responsive">
<table class="table table-bordered table-hover" id="notificationTable" style="font-size: 14px;">
<thead>
<tr>
<th>ID</th>
<th>Requested By</th>
<th>Req. User Type</th>
<th>Recurring Account</th>
<th>Loan Account</th>
<th>Amount</th>
<th>Req. On</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($countResult as $row): ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['request_by']; ?></td>
<td><span class="label label-<?php echo $row['request_usr_type'] === 'admin' ? 'primary' : 'info'; ?>"><?php echo strtoupper($row['request_usr_type']); ?></span></td>
<td><?php echo $row['rec_ac_number']; ?></td>
<td><?php echo $row['loan_ac_number']; ?></td>
<td class="text-danger"><strong><?php echo $row['transfer_amount']; ?></strong></td>
<td><?php echo date("d M Y, h:i A", strtotime($row['created'])); ?></td>
<td>
<div class="btn-group btn-group-sm">
<button class="btn btn-success" onclick="openStatusModal(<?php echo $row['id']; ?>, 1)">
<i class="glyphicon glyphicon-ok"></i> Approve
</button>
<button class="btn btn-danger" onclick="openStatusModal(<?php echo $row['id']; ?>, 2)">
<i class="glyphicon glyphicon-remove"></i> Reject
</button>
<button class="btn btn-info" onclick="viewDetails(<?php echo $row['id']; ?>)">
<i class="glyphicon glyphicon-eye-open"></i> View
</button>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="alert alert-info text-center">
<i class="glyphicon glyphicon-info-sign" style="font-size: 24px;"></i>
<h4>No pending fund transfer requests</h4>
<p>All requests have been processed or you don't have any requests to approve.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- Approval History Section -->
<div class="container mt-4">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Approval History</h4>
</div>
<div class="panel-body">
<?php if (isset($history_error)): ?>
<div class="alert alert-warning">
<?php echo $history_error; ?>
</div>
<?php elseif (count($historyResult) > 0): ?>
<div class="table-responsive">
<table class="table table-bordered table-hover" id="historyTable" style="font-size: 14px;">
<thead>
<tr>
<th>ID</th>
<th>Requested By</th>
<th>Requested User Type</th>
<th>Approved By</th>
<th>Approved User Type</th>
<th>Recurring Account</th>
<th>Loan Account</th>
<th>Amount</th>
<th>Status</th>
<th>Requested On</th>
<th>Approved On</th>
</tr>
</thead>
<tbody>
<?php foreach ($historyResult as $row): ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['request_by']; ?></td>
<td><span class="label label-<?php echo $row['request_usr_type'] === 'admin' ? 'primary' : 'info'; ?>"><?php echo strtoupper($row['request_usr_type']); ?></span></td>
<td><?php echo $row['approved_by'] ?? 'N/A'; ?></td>
<td>
<?php if ($row['approved_usr_type']): ?>
<span class="label label-<?php echo $row['approved_usr_type'] === 'admin' ? 'primary' : 'info'; ?>"><?php echo strtoupper($row['approved_usr_type']); ?></span>
<?php else: ?>
N/A
<?php endif; ?>
</td>
<td><?php echo $row['rec_ac_number']; ?></td>
<td><?php echo $row['loan_ac_number']; ?></td>
<td class="<?php echo $row['status'] == 1 ? 'text-success' : 'text-danger'; ?>">
<strong><?php echo $row['transfer_amount']; ?></strong>
</td>
<td>
<?php if ($row['status'] == 1): ?>
<span class="label label-success">Approved</span>
<?php elseif ($row['status'] == 2): ?>
<span class="label label-danger">Rejected</span>
<?php else: ?>
<span class="label label-warning">Pending</span>
<?php endif; ?>
</td>
<td><?php echo date("d M Y, h:i A", strtotime($row['created'])); ?></td>
<td>
<?php if ($row['status'] != 0): ?>
<?php echo date("d M Y, h:i A", strtotime($row['created'])); ?>
<?php else: ?>
N/A
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="alert alert-info text-center">
<i class="glyphicon glyphicon-info-sign" style="font-size: 24px;"></i>
<h4>No approval history found</h4>
<p>There are no approved or rejected requests in the history.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- View Details Modal -->
<div class="modal fade" id="viewModal" tabindex="-1" role="dialog" aria-labelledby="viewModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="viewModalLabel">Transaction Details</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<p><strong>ID:</strong> <span id="detail-id"></span></p>
<p><strong>Requested By:</strong> <span id="detail-request-by"></span></p>
<p><strong>User Type:</strong> <span id="detail-usr-type"></span></p>
</div>
<div class="col-md-6">
<p><strong>Recurring Account:</strong> <span id="detail-rec-account"></span></p>
<p><strong>Loan Account:</strong> <span id="detail-loan-account"></span></p>
<p><strong>Amount:</strong> <span id="detail-amount" class="text-danger"><strong></strong></span></p>
</div>
</div>
<div class="row mt-3">
<div class="col-12">
<p><strong>Requested On:</strong> <span id="detail-created"></span></p>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Status Update Modal -->
<div class="modal fade" id="statusModal" tabindex="-1" role="dialog" aria-labelledby="statusModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form method="post" action="">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="statusModalLabel">Update Transaction Status</h4>
</div>
<div class="modal-body">
<input type="hidden" name="id" id="status-id">
<input type="hidden" name="update_status" value="1">
<div class="form-group">
<label for="status" class="control-label">Status</label>
<select class="form-control" id="status" name="status" required>
<option value="1">Approve</option>
<option value="2">Reject</option>
</select>
</div>
<div class="form-group">
<label for="remarks" class="control-label">Remarks (Optional)</label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Update Status</button>
</div>
</form>
</div>
</div>
</div>
<script>
// View transaction details
function viewDetails(id) {
<?php foreach ($countResult as $row): ?>
if (<?php echo $row['id']; ?> === id) {
document.getElementById('detail-id').textContent = <?php echo $row['id']; ?>;
document.getElementById('detail-request-by').textContent = "<?php echo $row['request_by']; ?>";
document.getElementById('detail-usr-type').textContent = "<?php echo $row['request_usr_type']; ?>";
document.getElementById('detail-rec-account').textContent = "<?php echo $row['rec_ac_number']; ?>";
document.getElementById('detail-loan-account').textContent = "<?php echo $row['loan_ac_number']; ?>";
document.getElementById('detail-amount').textContent = "<?php echo $row['transfer_amount']; ?>";
document.getElementById('detail-created').textContent = "<?php echo date("d M Y, h:i A", strtotime($row['created'])); ?>";
}
<?php endforeach; ?>
// Use Bootstrap 3 modal method
$('#viewModal').modal('show');
}
// Open status update modal
function openStatusModal(id, status) {
document.getElementById('status-id').value = id;
document.getElementById('status').value = status;
// Use Bootstrap 3 modal method
$('#statusModal').modal('show');
}
// Initialize DataTable if we have records (if DataTable is available)
document.addEventListener('DOMContentLoaded', function() {
// Check if DataTable is available (if you're using it)
if (typeof $.fn.DataTable !== 'undefined') {
<?php if (count($countResult) > 0): ?>
$('#notificationTable').DataTable({
"pageLength": 10,
"order": [[6, "desc"]],
"language": {
"search": "Search transactions:",
"lengthMenu": "Show _MENU_ entries",
"info": "Showing _START_ to _END_ of _TOTAL_ entries",
"paginate": {
"previous": "Previous",
"next": "Next"
}
}
});
<?php endif; ?>
<?php if (count($historyResult) > 0): ?>
$('#historyTable').DataTable({
"pageLength": 10,
"order": [[9, "desc"]],
"language": {
"search": "Search history:",
"lengthMenu": "Show _MENU_ entries",
"info": "Showing _START_ to _END_ of _TOTAL_ entries",
"paginate": {
"previous": "Previous",
"next": "Next"
}
}
});
<?php endif; ?>
}
});
</script>
<style>
.panel {
border-radius: 4px;
box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.table th {
font-weight: 600;
background-color: #f5f5f5;
}
.btn-group-sm > .btn {
padding: 5px 10px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
.badge {
background-color: #d9534f;
font-size: 14px;
padding: 5px 10px;
margin-top: 5px;
}
.label {
font-size: 85%;
padding: 0.2em 0.6em 0.3em;
}
</style>

View File

@@ -0,0 +1,468 @@
<script>
function calculateFine() {
var due_amount = document.getElementById('due_amount'),
inst_no = document.getElementById('inst_no').value,
inst_amount = document.getElementById('inst_amount').value,
total_rec = document.getElementById('total_rec').value,
// rec_amount = document.getElementById('rec_amount'),
fine = document.getElementById('fine');
due_amount = parseInt(due_amount.value);
fine = parseInt(fine.value);
// document.getElementById('due_amount').value = due_amount;
// document.getElementById('rec_amount').value = due_amount + fine;
document.getElementById('total_amount').value = inst_amount * inst_no + fine;
document.getElementById('hidden_total_rec').value = inst_amount * inst_no;
document.getElementById('total_rec').value = inst_amount * inst_no;
}
function calculateAmount() {
var inst_amount = document.getElementById('inst_amount').value,
// rec_amount = document.getElementById('rec_amount').value,
inst_no = document.getElementById('inst_no').value;
show_amount = document.getElementById('show_amount').value;
// document.getElementById('rec_amount').value = inst_amount * inst_no;
// document.getElementById('show_amount').value = inst_amount * inst_no;
document.getElementById('total_amount').value = inst_amount * inst_no;
document.getElementById('hidden_total_amount').value = inst_amount * inst_no;
}
</script>
<div class="container" style="margin-top: 20px;margin-bottom:20px;">
<form method="get" action="Trans_New">
<div class="form-group">
<input class="form-control" type="text" placeholder="input A/C no and enter" name="no">
</div>
</form>
</div>
<?php
$CURRENT_RECURRING_BALANCE = 0;
if(isset($_GET["no"]) && isset($_GET["type"])&&$_GET["type"]=="Loan"){
echo '
<div class="container" style="margin-top: 20px;"> <h5>New Transaction : '.$GLOBALS['post_info'].' </h5><hr></div>
<div class="container">
<table class="table table-striped table-bordered table-hover table-responsive">
<tr>
<th>Name</th>
<th>Phone</th>
<th>AC No</th>
<th>Remaining Amount</th>
<th>Installment</th>
</tr>';
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_ACNO` = '".$_GET["no"]."' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$date1 = date_create($row["AA_DATE"]);
$date2 = date_create(date("Y/m/d"));
$diff = date_diff($date1, $date2);
if ($row["AA_ACTYPE"] == 'D'){$diff = $diff->format("%a"); $diff=(int)$diff;$due_i=$diff-$row["AA_NO_OF_PAYPAID"];} else {$diff=$diff->format("%m"); $diff=(int)$diff;$due_i=$diff-$row["AA_NO_OF_PAYPAID"];}
//$ID=$row["GC_ID"];
echo "
<tr>
<td>".$row["AA_NAME"]."</td>
<td>".$row["AA_PHONE"]."</td>
<td>".$row["AA_ACNO"]."</td>
<td>".$row["AA_BAL"]. '</td>
<td>
<form method="post" enctype="multipart/form-data" id="submitInstallment">
<input type="hidden" name="FORM_NAME" value="add_installment">';
if ($due_i > 0 && $_GET['type'] == "Loan") {
$due_amount = $due_i * $row["AA_INSTALLMENT"];
$due_amount = intval($due_amount);
$fine_amount = ($due_amount * 40) / 100;
$total_amount = $row["AA_INSTALLMENT"] + $fine_amount;
$total_rec = $row["AA_INSTALLMENT"] * 1;
echo '
<table class="table table-bordered">
<tr>
<td>
<input type="hidden" name="AA_ACNO" value="'.$row['AA_ACNO'].'">
<input type="hidden" name="ins_no" value="'.$due_i. '">
<small>Due Amount:</small>
<input type="text" id="due_amount" value="'.$due_amount. '" disabled style="width:50px;border:1px solid red">
<small>Installment Amount:</small>
<input type="text" id="inst_amount" value="' . $row['AA_INSTALLMENT'] . '" style="width:50px;">
<small>No:</small>
<input type="number" id="inst_no" value="1" min="1" style="width:50px;" onchange="calculateFine()">
<small>Total received:</small>
<input type="number" id="total_rec" value="'.$total_rec.'" style="width:50px;" onchange="calculateFine()" disabled>
</td>
</tr>
<tr>
<td>
<input type="hidden" id="hidden_total_rec" value="'.$total_rec.'" name="add_i" style="width:50px;" onchange="calculateFine()">
<small>Fine:</small>
<input type="number" id="fine" name="fine_amount" value="'.$fine_amount.'" min="0" style="width:50px;border:1px solid red" onchange="calculateFine()">
<small>Total:</small>
<input type="text" id="total_amount" value="'.$total_amount. '" disabled style="width:50px;border:1px solid red">
<input type="submit" class="btn-info" value="Receive" onclick="sendData(event)">
</td>
</tr>
</table>';
} else
echo'
<input type="hidden" id="inst_amount" value="'.$row['AA_INSTALLMENT']. '">
<small>Amount:</small>
<input type="text" id="show_amount" value="'.$row['AA_INSTALLMENT']. '" disabled style="width:50px;">
<small>No:</small>
<input type="number" id="inst_no" value="1" min="1" style="width:50px;" onchange="calculateAmount()">
<input type="hidden" name="AA_ACNO" value="'.$row['AA_ACNO']. '">
<small>Total:</small>
<input type="text" id="total_amount" value="'.$row['AA_INSTALLMENT'].'" disabled style="width:50px;">
<input type="hidden" id="hidden_total_amount" name="add_i" value="'.$row['AA_INSTALLMENT'].'">
<input type="submit" class="btn-info" value="Receive" onclick="sendData(event)">';
echo '</form></td></tr>';
}
} else {echo "Check A/C no.";};
$conn->close();
echo '</table></div>';
}
if(isset($_GET["no"]) && isset($_GET["type"])&&$_GET["type"]=="Recurring"){
echo '
<div class="container" style="margin-top: 10px;"> <h5>New Transaction : '.$GLOBALS['post_info'].' </h5><hr></div>
<div class="container table-responsive">
<table class="table table-striped table-bordered table-hover">
<tr>
<th>Name</th>
<th>Phone</th>
<th>AC No</th>
<th>Total Deposit</th>
<th>Installment</th>
<th>Receive Amount</th>
</tr>';
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_ACNO` = '".$_GET["no"]."' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$date1 = date_create($row["AA_DATE"]);
$date2 = date_create(date("Y/m/d"));
$diff = date_diff($date1, $date2);
if ($row["AA_ACTYPE"] == 'D'){$diff = $diff->format("%a"); $diff=(int)$diff;$due_i=$diff-$row["AA_NO_OF_PAYPAID"];} else {$diff=$diff->format("%m"); $diff=(int)$diff;$due_i=$diff-$row["AA_NO_OF_PAYPAID"];}
//$ID=$row["GC_ID"];
$CURRENT_RECURRING_BALANCE = $row["AA_BAL"];
echo "
<tr>
<td>".$row["AA_NAME"]. "</td>
<td>".$row["AA_PHONE"]. "</td>
<td>".$row["AA_ACNO"]."</td>
<td>".$row["AA_BAL"]. "</td>
<td>".$row["AA_INSTALLMENT"]. '</td>
<td>
<form method="post" enctype="multipart/form-data" id="submitInstallment">
<input type="hidden" name="FORM_NAME" value="add_installment">';
if ($due_i > 0 && $_GET['type'] == "Recurring") {
$due_amount = $due_i * $row["AA_INSTALLMENT"];
$due_amount = intval($due_amount);
$fine_amount = ($due_amount * 20) / 100;
$total_amount = $row["AA_INSTALLMENT"] + $fine_amount;
$total_rec = $row["AA_INSTALLMENT"] * 1;
echo '
<table class="table table-bordered">
<tr>
<td>
<input type="hidden" name="AA_ACNO" value="'.$row['AA_ACNO'].'">
<input type="hidden" name="ins_no" value="'.$due_i. '">
<small>Due Amount:</small>
<input type="text" id="due_amount" value="'.$due_amount. '" disabled style="width:50px;border:1px solid red">
<small>Installment Amount:</small>
<input type="text" id="inst_amount" value="' . $row['AA_INSTALLMENT'] . '" style="width:50px;">
<small>No:</small>
<input type="number" id="inst_no" value="1" min="1" style="width:50px;" onchange="calculateFine()">
<small>Total received:</small>
<input type="number" id="total_rec" value="'.$total_rec.'" style="width:50px;" onchange="calculateFine()" disabled>
</td>
</tr>
<tr>
<td>
<input type="hidden" id="hidden_total_rec" value="'.$total_rec.'" name="add_i" style="width:50px;" onchange="calculateFine()">
<small>Fine:</small>
<input type="number" id="fine" name="fine_amount" value="'.$fine_amount.'" min="0" style="width:50px;border:1px solid red" onchange="calculateFine()">
<small>Total:</small>
<input type="text" id="total_amount" value="'.$total_amount. '" disabled style="width:50px;border:1px solid red">
<input type="submit" class="btn-info" value="Receive" onclick="sendData(event)">
</td>
</tr>
</table>';
} else
echo '
<input type="hidden" id="inst_amount" value="'.$row['AA_INSTALLMENT']. '">
<small>Amount:</small>
<input type="text" id="show_amount" value="'.$row['AA_INSTALLMENT'].'" disabled style="width:50px;">
<small>No:</small>
<input type="number" id="inst_no" value="1" min="1" style="width:50px;" onchange="calculateAmount()">
<input type="hidden" name="AA_ACNO" value="'.$row['AA_ACNO']. '">
<small>Total:</small>
<input type="text" id="total_amount" value="'.$row['AA_INSTALLMENT'].'" disabled style="width:50px;">
<input type="hidden" id="hidden_total_amount" name="add_i" value="'.$row['AA_INSTALLMENT'].'">
<input type="submit" class="btn-info" value="Receive" onclick="sendData(event)">';
echo '</form></td></tr>';
}
} else {echo "Check A/C no.";};
$conn->close();
echo '</table></div>';
}
?>
<?php
if ($_SESSION['type'] === 'admin' && isset($_GET["no"]) && isset($_GET["type"]) && $_GET["type"] == "Recurring") {
if (
$_SERVER['REQUEST_METHOD'] === 'POST'
&& isset($_POST['PAY_LOAN_EMI_FROM_RECURRING'], $_POST['PAY_LOAN_EMI_FROM_RECURRING_ID'], $_POST['DEDUCT_LOAN_AMOUNT'])
&& $_POST['PAY_LOAN_EMI_FROM_RECURRING_ID'] === 'axakassaoxnnxsaoij34866'
) {
$loanEMIAmount = floatval($_POST['DEDUCT_LOAN_AMOUNT']);
$deductAmount = -$loanEMIAmount; // negative for recurring deduction
$paidToLoanAccountNumber = $_POST['LOAN_AC_NUMBER'];
$accountId = $_GET['no'];
if (!$accountId) {
echo "Account number missing";
exit;
}
// ✅ DB connection
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// ✅ Check recurring balance first
$sql = "SELECT AA_BAL FROM `" . $GLOBALS['arif_ac'] . "` WHERE `AA_ACNO` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $accountId);
$stmt->execute();
$stmt->bind_result($CURRENT_RECURRING_BALANCE);
$stmt->fetch();
$stmt->close();
if ($loanEMIAmount > $CURRENT_RECURRING_BALANCE) {
echo "<div class='container' style=' background-color: #f8d7da; color: #721c24; padding: 12px 20px; border: 1px solid #f5c6cb; border-radius: 5px; font-family: Arial, sans-serif; font-size: 15px; margin: 10px auto; position: relative;'>
<strong>Error!</strong> Insufficient balance in Recurring account.
<span style=\" position: absolute; top: 8px; right: 12px; color: #721c24; font-weight: bold; cursor: pointer; \" onclick=\"this.parentElement.style.display='none';\">&times;</span>
</div>";
exit;
}
// ✅ Begin transaction for atomicity
$conn->begin_transaction();
try {
$table = $GLOBALS['arif_tran'] ?? 'arif_tran';
$userType = 'admin';
// Entry 1: Deduction from recurring
$remarksText1 = "₹$loanEMIAmount deducted from Recurring for Loan A/c $paidToLoanAccountNumber EMI";
$stmt = $conn->prepare("INSERT INTO `$table` (AT_ADMIN, AT_ACID, AT_AMOUNT, REMARKS) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssds", $userType, $accountId, $deductAmount, $remarksText1);
$stmt->execute();
$stmt->close();
// Entry 2: Credit to loan account
$remarksText2 = "₹$loanEMIAmount credited to Loan A/c $paidToLoanAccountNumber EMI (from Recurring $accountId)";
$stmt = $conn->prepare("INSERT INTO `$table` (AT_ADMIN, AT_ACID, AT_AMOUNT, REMARKS) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssds", $userType, $paidToLoanAccountNumber, $loanEMIAmount, $remarksText2);
$stmt->execute();
$stmt->close();
// Update Loan Account
$ins_no = 1;
$sql = "UPDATE `" . $GLOBALS['arif_ac'] . "` SET `AA_BAL` = `AA_BAL` + ?, `AA_NO_OF_PAYPAID` = `AA_NO_OF_PAYPAID` + ? WHERE `AA_ACNO` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("dis", $loanEMIAmount, $ins_no, $paidToLoanAccountNumber);
$stmt->execute();
$stmt->close();
// Update Recurring Account
$sql = "UPDATE `" . $GLOBALS['arif_ac'] . "` SET `AA_BAL` = `AA_BAL` - ? WHERE `AA_ACNO` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ds", $loanEMIAmount, $accountId);
$stmt->execute();
$stmt->close();
// ✅ Commit if everything ok
$conn->commit();
echo "<div class='container' style=' background-color: #d4edda; color: #155724; padding: 12px 20px; border: 1px solid #c3e6cb; border-radius: 5px; font-family: Arial, sans-serif; font-size: 15px; margin: 10px auto; position: relative;'>
<strong>Success!</strong> Loan EMI paid successfully!
<span style=\" position: absolute; top: 8px; right: 12px; color: #155724; font-weight: bold; cursor: pointer; \" onclick=\"this.parentElement.style.display='none';\">&times;</span>
</div>";
} catch (Exception $e) {
$conn->rollback();
echo "Error processing EMI payment: " . $e->getMessage();
}
$conn->close();
}
}
?>
<?php if ($_SESSION['type'] === 'admin' && isset($_GET["no"]) && isset($_GET["type"]) && $_GET["type"] == "Recurring") { ?>
<div class="container">
<h4>Pay Loan EMI from Recurring balance</h4>
<div style="display: flex; gap: 20px; flex-direction: row; max-width: 60%;">
<input class="form-control" type="text" id="acno" placeholder="Enter Account No" />
<button class="btn btn-primary" onclick="getAccountDetails()">Get Details</button>
</div>
<form id="PAY_LOAN_RECURRING_FORM" method="post" style="display: none; gap: 20px; flex-direction: column; max-width: 60%; margin-top: 30px;">
<input type="hidden" name="PAY_LOAN_EMI_FROM_RECURRING" value="1">
<input type="hidden" name="PAY_LOAN_EMI_FROM_RECURRING_ID" value="axakassaoxnnxsaoij34866">
<div>
<label for="ACCOUNT_HOLDER_NAME">Account holder Name:</label>
<input class="form-control" id="ACCOUNT_HOLDER_NAME" name="ACCOUNT_HOLDER_NAME" type="text" readOnly />
</div>
<div>
<label for="ACCOUNT_HOLDER_NAME">Recurring Balance:</label>
<input class="form-control" id="ACCOUNT_HOLDER_NAME" name="ACCOUNT_HOLDER_NAME" type="text" value="<?= $CURRENT_RECURRING_BALANCE ?>" readOnly />
</div>
<div>
<label for="LOAN_AC_NUMBER">Loan Account Number:</label>
<input class="form-control" id="LOAN_AC_NUMBER" name="LOAN_AC_NUMBER" type="text" required readOnly />
</div>
<div>
<label for="DEDUCT_LOAN_AMOUNT">Deduct Loan Amount:</label>
<input class="form-control" id="DEDUCT_LOAN_AMOUNT" name="DEDUCT_LOAN_AMOUNT" type="number" required />
</div>
<div style="">
<input class="btn btn-success" type="submit" value="Deduct & Pay Now" />
</div>
</form>
</div>
<?php } ?>
<div class="container" style="margin-top: 70px;">
<div class="row">
<div class="col-md-2">
<h5>Past Transactions::::</h5>
</div>
<div class="col-md-2">
<button class="btn btn-success" onclick="window.location.reload()">Refresh</button>
</div>
</div><hr>
</div>
<?php
if(isset($_GET["no"])){
echo '
<div class="container table-responsive">
<table class="table table-striped table-bordered table-hover">
<tr>
<th>SL</th>
<th>Tr No</th>
<th>TimeStamp</th>
<th>User</th>
<th>A/C No</th>
<th>Amount</th>
</tr>';
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
// $sql = "SELECT * FROM `".$GLOBALS['arif_tran']."` WHERE `AT_ACID` = '".$_GET['no']."'";
$sql = "SELECT * FROM `".$GLOBALS['arif_tran']."` WHERE `AT_ACID` = '".$_GET['no']."' ORDER BY `".$GLOBALS['arif_tran']."`.`AT_ID` DESC";
$result = $conn->query($sql);
$rowcount=mysqli_num_rows($result);//$rowcount++;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
//$ID=$row["GC_ID"];
$kolkataTime = date("d M Y, h:i A", strtotime($row["AT_TIMESTAMP"] . " +5 hours 30 minutes"));
echo "
<tr>
<td>".$rowcount. "</td>
<td>".$row["AT_ID"]. "</td>
<td>".$kolkataTime. "</td>
<td>".$row["AT_ADMIN"]. "</td>
<td>".$row["AT_ACID"]. "</td>
<td>".$row["AT_AMOUNT"]. "</td>
</tr>";
$rowcount--;
}
} else echo "No Past record Found";
mysqli_free_result($result);$conn->close();
echo '</table></div>';
}
?>
<script>
function getAccountDetails() {
let acno = document.getElementById("acno").value;
fetch("/exe/get-loan-details/", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: "AA_ACNO=" + encodeURIComponent(acno)
})
.then(res => res.json())
.then(data => {
document.getElementById('PAY_LOAN_RECURRING_FORM').style.display = 'flex';
console.log(data.data[0].AA_ACNO);
document.getElementById('LOAN_AC_NUMBER').value = data.data[0].AA_ACNO;
document.getElementById('DEDUCT_LOAN_AMOUNT').value = data.data[0].AA_INSTALLMENT;
document.getElementById('ACCOUNT_HOLDER_NAME').value = data.data[0].AA_NAME;
document.getElementById('INSTALLMENT_NUMBER').value = data.data[0].AA_BAL / data.data[0].AA_INSTALLMENT;
if(data.status === "Success"){
// Example: show first record
console.log("Account Holder: " + data.data[0].AA_NAME + "\nBalance: " + data.data[0].AA_BAL);
} else {
alert(data.statusmsg);
}
})
.catch(err => console.error("Error:", err));
}
var submitInstallment = document.getElementById("submitInstallment");
function sendData(event) {
event.preventDefault();
var XHR = new XMLHttpRequest();
var FD = new FormData(submitInstallment);
XHR.addEventListener("load", function (event) {
var obj = JSON.parse(event.target.responseText);
// console.log(obj);
alert(obj.statusmsg);
// window.location.reload(true);
window.history.back();
});
XHR.addEventListener("error", function () {
alert('Error', 'Ooops!! Something went wrong.');
});
console.log(FD);
XHR.open("POST", "/exe/receive_amount/");
XHR.send(FD);
}
function addACNumberToField(){
document.getElementById('LOAN_ACC_NUMBER').value = document.getElementById('LOAN_AC_NUMBER').value;
}
</script>
<!-- GVD20210607R519 -->

View File

@@ -0,0 +1,95 @@
<?php
if ($_SESSION['type'] === 'admin' && isset($_GET["no"]) && isset($_GET["type"]) && $_GET["type"] == "Recurring") {
if (
$_SERVER['REQUEST_METHOD'] === 'POST'
&& isset($_POST['PAY_LOAN_EMI_FROM_RECURRING'], $_POST['PAY_LOAN_EMI_FROM_RECURRING_ID'], $_POST['DEDUCT_LOAN_AMOUNT'])
&& $_POST['PAY_LOAN_EMI_FROM_RECURRING_ID'] === 'axakassaoxnnxsaoij34866'
) {
$loanEMIAmount = floatval($_POST['DEDUCT_LOAN_AMOUNT']);
$deductAmount = -$loanEMIAmount; // negative for recurring deduction
$paidToLoanAccountNumber = $_POST['LOAN_AC_NUMBER'];
$accountId = $_GET['no'];
if (!$accountId) {
echo "Account number missing";
exit;
}
// ✅ DB connection
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// ✅ Check recurring balance first
$sql = "SELECT AA_BAL FROM `" . $GLOBALS['arif_ac'] . "` WHERE `AA_ACNO` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $accountId);
$stmt->execute();
$stmt->bind_result($CURRENT_RECURRING_BALANCE);
$stmt->fetch();
$stmt->close();
if ($loanEMIAmount > $CURRENT_RECURRING_BALANCE) {
echo "<div class='container' style=' background-color: #f8d7da; color: #721c24; padding: 12px 20px; border: 1px solid #f5c6cb; border-radius: 5px; font-family: Arial, sans-serif; font-size: 15px; margin: 10px auto; position: relative;'>
<strong>Error!</strong> Insufficient balance in Recurring account.
<span style=\" position: absolute; top: 8px; right: 12px; color: #721c24; font-weight: bold; cursor: pointer; \" onclick=\"this.parentElement.style.display='none';\">&times;</span>
</div>";
exit;
}
// ✅ Begin transaction for atomicity
$conn->begin_transaction();
try {
$table = $GLOBALS['arif_tran'] ?? 'arif_tran';
$userType = 'admin';
// Entry 1: Deduction from recurring
$remarksText1 = "$loanEMIAmount deducted from Recurring for Loan A/c $paidToLoanAccountNumber EMI";
$stmt = $conn->prepare("INSERT INTO `$table` (AT_ADMIN, AT_ACID, AT_AMOUNT, REMARKS) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssds", $userType, $accountId, $deductAmount, $remarksText1);
$stmt->execute();
$stmt->close();
// Entry 2: Credit to loan account
$remarksText2 = "$loanEMIAmount credited to Loan A/c $paidToLoanAccountNumber EMI (from Recurring $accountId)";
$stmt = $conn->prepare("INSERT INTO `$table` (AT_ADMIN, AT_ACID, AT_AMOUNT, REMARKS) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssds", $userType, $paidToLoanAccountNumber, $loanEMIAmount, $remarksText2);
$stmt->execute();
$stmt->close();
// Update Loan Account
$ins_no = 1;
$sql = "UPDATE `" . $GLOBALS['arif_ac'] . "` SET `AA_BAL` = `AA_BAL` + ?, `AA_NO_OF_PAYPAID` = `AA_NO_OF_PAYPAID` + ? WHERE `AA_ACNO` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("dis", $loanEMIAmount, $ins_no, $paidToLoanAccountNumber);
$stmt->execute();
$stmt->close();
// Update Recurring Account
$sql = "UPDATE `" . $GLOBALS['arif_ac'] . "` SET `AA_BAL` = `AA_BAL` - ? WHERE `AA_ACNO` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ds", $loanEMIAmount, $accountId);
$stmt->execute();
$stmt->close();
// ✅ Commit if everything ok
$conn->commit();
echo "<div class='container' style=' background-color: #d4edda; color: #155724; padding: 12px 20px; border: 1px solid #c3e6cb; border-radius: 5px; font-family: Arial, sans-serif; font-size: 15px; margin: 10px auto; position: relative;'>
<strong>Success!</strong> Loan EMI paid successfully!
<span style=\" position: absolute; top: 8px; right: 12px; color: #155724; font-weight: bold; cursor: pointer; \" onclick=\"this.parentElement.style.display='none';\">&times;</span>
</div>";
} catch (Exception $e) {
$conn->rollback();
echo "Error processing EMI payment: " . $e->getMessage();
}
$conn->close();
}
}
?>