chnage count cycle function as per account type

This commit is contained in:
ns77@siliconpin.com
2025-08-30 08:55:30 +00:00
parent 565705ce7b
commit dba162bab6
3 changed files with 461 additions and 53 deletions

View File

@@ -19,6 +19,80 @@
</div>
<?php
function countCycles($cycle, $createDate, $totalInstallment, $accountType) {
$today = new DateTime();
$startDate = new DateTime($createDate);
$cycle = strtoupper(trim($cycle));
if ($cycle === "D") {
// দৈনিক চক্র: ক্রিয়েশন ডেট থেকেই শুরু
if($accountType === 'Recurring'){
$firstPaymentDate = clone $startDate; // সেই দিনই শুরু
} elseif($accountType === 'Loan') {
$firstPaymentDate = (clone $startDate)->modify('+1 day'); // পরের দিন থেকে
}
if ($firstPaymentDate > $today) {
$count = 0;
} else {
$diff = $firstPaymentDate->diff($today);
$count = $diff->days + 1; // +1 because diff->days doesn't include start day
}
} elseif ($cycle === "W") {
if($accountType === 'Recurring'){
$firstPaymentDate = clone $startDate;
}elseif($accountType === 'Loan'){
// সাপ্তাহিক চক্র: দিন পরে প্রথম EMI
$firstPaymentDate = (clone $startDate)->modify('+7 days');
}
if ($firstPaymentDate > $today) {
$count = 0;
} else {
$diff = $firstPaymentDate->diff($today);
$count = floor($diff->days / 7) + 1;
}
} elseif ($cycle === "M") {
if($accountType === 'Recurring'){
$firstPaymentDate = clone $startDate;
}elseif($accountType === 'Loan'){
// মাসিক চক্র: পরের মাসের同一天 প্রথম EMI
$firstPaymentDate = (clone $startDate)->modify('+1 month');
}
// যদি পরের মাসে同一天 না থাকে (যেমন 31st Jan থেকে 28/29th Feb)
if ($firstPaymentDate->format('d') != $startDate->format('d')) {
$firstPaymentDate->modify('last day of this month');
}
if ($firstPaymentDate > $today) {
$count = 0;
} else {
$count = 1; // প্রথম EMI already due
$nextPaymentDate = clone $firstPaymentDate;
// পরের মাসগুলির জন্য গণনা
while ($nextPaymentDate <= $today) {
$nextPaymentDate->modify('+1 month');
// তারিখ adjust করাが必要 হলে
if ($nextPaymentDate->format('d') != $firstPaymentDate->format('d')) {
$nextPaymentDate->modify('last day of this month');
}
if ($nextPaymentDate <= $today) {
$count++;
}
}
}
} else {
$count = 0;
}
return min($count, $totalInstallment);
}
function view_list_ac($type) {
echo '
<div class="container" style="margin-top: 70px;">
@@ -29,27 +103,40 @@ function view_list_ac($type) {
<tr>
<th>SL</th>
<th>Type</th>';
if ($_SESSION['type'] === 'admin') {
echo '<th>Agent</th>';
}
if ($_SESSION['type'] === 'admin') {
echo '<th>Agent</th>';
}
if(isset($_GET['Type']) && $_GET['Type']=="Recurring" || $_GET['Type']=="Matured-Recurring"){
echo '
<th>AC No</th>
<th>Name</th>
<th>Account Creation Date</th>
<th>Maturity Amount</th>
<th>PHONE</th>
<th>Balance</th>
<th>Total Installment</th>
<th>Paid Installment</th>
<th>Deu Installment Till Date</th>
<th>Installment Amount</th>
<th>Due Amount</th>
</tr>';
}elseif(isset($_GET['Type']) && $_GET['Type']=="Loan" || $_GET['Type']=="Closed-Acc"){
echo '
<th>AC No</th>
<th>Name</th>
<th>Account Creation Date</th>
<th>Loan Amount</th>
<th>PHONE</th>
<th>Balance</th>
<th>Total EMI</th>
<th>Paid EMI</th>
<th>Deu EMI Till Date</th>
<th>EMI Amount</th>
<th>Due Amount</th>
</tr>';
}
echo '
<th>AC No</th>
<th>Name</th>
<th>Account Creation Date</th>
<th>Loan Amount</th>
<th>PHONE</th>
<th>Balance</th>
<th>Total No Of Installment to be paid</th>
<th>No Of Paid Installment</th>
<th>No of Expected Installment till today</th>
<th>Installment Amount</th>
<th>Due Installment</th>
<th>Due Amount</th>
<th>Due after Fine</th>
</tr>';
// <th>Due after Fine</th>
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
@@ -97,7 +184,7 @@ function view_list_ac($type) {
$date1 = date_create($row["AA_DATE"]);
$date2 = date_create(date("Y/m/d"));
$diff = date_diff($date1, $date2);
if($type === 'Loan') {
$no_paid_inst = ($row["AA_MATURE_VALUE"] + $row["AA_BAL"]) / $row["AA_INSTALLMENT"];
} else {
@@ -114,6 +201,34 @@ function view_list_ac($type) {
$due_i = $diff - $no_paid_inst;
}
if($row['AA_TYPE'] === 'Loan'){
$paidInstallment = ($row['AA_MATURE_VALUE'] + $row['AA_BAL']) / $row['AA_INSTALLMENT'];
$paidInstallment = number_format($paidInstallment, 2, '.', '');
$deuEMITillDate = countCycles($row['AA_ACTYPE'], $row['AA_DATE'], $row['AA_NO_OF_PAYMENT'], $row['AA_TYPE']) - $paidInstallment;
// $deuEMITillDate = abs($deuEMITillDate);
$deuEMITillDate = number_format($deuEMITillDate, 2, '.', '');
$totalDEUEMI = $row['AA_BAL'] / $row['AA_INSTALLMENT'];
$totalDEUEMI = number_format($totalDEUEMI, 2, '.', '');
}elseif($row['AA_TYPE'] === 'Recurring'){
$paidInstallment = $row['AA_BAL'] / $row['AA_INSTALLMENT'];
$paidInstallment = number_format($paidInstallment, 2, '.', '');
$deuEMITillDate = countCycles($row['AA_ACTYPE'], $row['AA_DATE'], $row['AA_NO_OF_PAYMENT'], $row['AA_TYPE']) - $paidInstallment;
// $deuEMITillDate = abs($deuEMITillDate);
$deuEMITillDate = number_format($deuEMITillDate, 2, '.', '');
// $totalDEUEMI = ($row["AA_MATURE_VALUE"] - $row['AA_BAL']) / $row['AA_INSTALLMENT'];
$totalDEUEMI = $row["AA_NO_OF_PAYMENT"] - $paidInstallment;
$totalDEUEMI = number_format($totalDEUEMI, 2, '.', '');
}
$totalDeuAmount = $totalDEUEMI * $row["AA_INSTALLMENT"];
echo "<tr>
<td>".$tt."</td>
<td>".$row["AA_ACTYPE"].",".$row["AA_TYPE"]."</td>";
@@ -122,39 +237,45 @@ function view_list_ac($type) {
echo "<td>".$row["AA_AGENT"]."</td>";
}
echo "<td><a href='./Details?no=".$row["AA_ACNO"]."&type=".$row["AA_TYPE"]."'>".$row["AA_ACNO"]."</a> &nbsp;&nbsp;
<a href='./Trans_New?no=".$row["AA_ACNO"]."&type=".$row["AA_TYPE"]."'>Transact</a></td>
<td>".$row["AA_NAME"]."</td>
<td>".$row["AA_DATE"]."</td>
<td>".$row["AA_MATURE_VALUE"]."</td>
<td>".$row["AA_PHONE"]."</td>
<td>".$row["AA_BAL"]. "</td>
<td>".$row["AA_NO_OF_PAYMENT"]."</td>
<td>".$no_paid_inst."</td>
<td>".$diff."</td>
<td>".$row["AA_INSTALLMENT"]."</td>
<td>".$due_i."</td>";
if ($due_i > 0) {
$due_amount = $due_i * $row["AA_INSTALLMENT"];
echo "<td class='alert danger text-danger'>".$due_amount."</td>";
} else {
$due_amount = 'All Clear';
echo "<td class='alert success text-success'>".$due_amount."</td>";
echo "<td><a href='./Details?no=".$row["AA_ACNO"]."&type=".$row["AA_TYPE"]."'>".$row["AA_ACNO"]."</a> &nbsp;&nbsp; <a href='./Trans_New?no=".$row["AA_ACNO"]."&type=".$row["AA_TYPE"]."'>Transact</a></td>
<td>".$row["AA_NAME"]."</td>
<td>".$row["AA_DATE"]."</td>
<td>".$row["AA_MATURE_VALUE"]."</td>
<td>".$row["AA_PHONE"]."</td>
<td>".$row["AA_BAL"]. "</td>
<td>".$row["AA_NO_OF_PAYMENT"]."</td>
<td>".$paidInstallment."</td>
<td>".$deuEMITillDate."</td>
<td>".$row["AA_INSTALLMENT"]."</td>";
if($row["AA_TYPE"] === 'Recurring'){
echo "<td class='".($totalDeuAmount > 0 ? "alert danger text-danger" : "alert success text-success")."'>".($totalDeuAmount > 0 ? $totalDeuAmount : "All Clear")."</td>";
}elseif($row["AA_TYPE"] === 'Loan'){
echo "<td class='".($totalDeuAmount >= 0 ? "alert success text-success" : "alert danger text-danger")."'>".($totalDeuAmount < 0 ? $totalDeuAmount : "All Clear")."</td>";
}
// $totalDeuAmount
if ($due_i > 0 && $type == "Recurring") {
$due_amount = $due_i * $row["AA_INSTALLMENT"];
$due_amount = (($due_amount) * 20)/100;
echo "<td class='alert danger text-danger'>".$due_amount."</td>";
} elseif ($due_i > 0 && $type == "Loan") {
$due_amount = $due_i * $row["AA_INSTALLMENT"];
$due_amount = (($due_amount) * 40)/100;
echo "<td class='alert danger text-danger'>".$due_amount."</td>";
} else {
$due_amount = 'Up to Date!!';
echo "<td class='alert success text-success'>".$due_amount."</td>";
}
// if ($due_i > 0) {
// $due_amount = $due_i * $row["AA_INSTALLMENT"];
// echo "<td class='alert danger text-danger'>".$due_amount."</td>";
// } else {
// $due_amount = 'All Clear';
// echo "<td class='alert success text-success'>".$due_amount."</td>";
// }
// if ($due_i > 0 && $type == "Recurring") {
// $due_amount = $due_i * $row["AA_INSTALLMENT"];
// $due_amount = (($due_amount) * 20)/100;
// echo "<td class='alert danger text-danger'>".$due_amount."</td>";
// } elseif ($due_i > 0 && $type == "Loan") {
// $due_amount = $due_i * $row["AA_INSTALLMENT"];
// $due_amount = (($due_amount) * 40)/100;
// echo "<td class='alert danger text-danger'>".$due_amount."</td>";
// } else {
// $due_amount = 'Up to Date!!';
// echo "<td class='alert success text-success'>".$due_amount."</td>";
// }
echo "</tr>";
}