s1
This commit is contained in:
@@ -36,6 +36,7 @@ function calculateAmount() {
|
||||
</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>
|
||||
@@ -60,7 +61,7 @@ function calculateAmount() {
|
||||
$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"];
|
||||
//$ID=$row["GC_ID"];
|
||||
echo "
|
||||
<tr>
|
||||
<td>".$row["AA_NAME"]."</td>
|
||||
@@ -150,6 +151,7 @@ function calculateAmount() {
|
||||
$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>
|
||||
@@ -212,6 +214,141 @@ function calculateAmount() {
|
||||
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';\">×</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 = "Deducted ₹$loanEMIAmount from recurring balance to pay Loan Account No: $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 = "Credited ₹$loanEMIAmount to Loan Account No: $paidToLoanAccountNumber EMI from recurring balance";
|
||||
$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';\">×</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">
|
||||
@@ -265,6 +402,39 @@ if(isset($_GET["no"])){
|
||||
?>
|
||||
|
||||
<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();
|
||||
@@ -287,4 +457,13 @@ function sendData(event) {
|
||||
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 -->
|
||||
Reference in New Issue
Block a user