chnage count cycle function as per account type

This commit is contained in:
ns77@siliconpin.com
2025-08-28 13:18:44 +00:00
parent d2c2833064
commit 527b982e84
6 changed files with 133 additions and 63 deletions

View File

@@ -0,0 +1,8 @@
<?php
echo "<h3>Add New Agent</h3>";
// Your form to add new agent
echo "<form method='POST' action='?action=save'>
<input type='text' name='agent_name' placeholder='Agent Name'>
<button type='submit'>Save Agent</button>
</form>";
?>

View File

@@ -0,0 +1,8 @@
<div class="container mx-auto">
<form action="">
<div>
<label for="ACCOUNT_NUMBER">Account Number</label>
<input class="form-control" type="text" name="ACCOUNT_NUMBER" id="ACCOUNT_NUMBER" />
</div>
</form>
</div>

View File

@@ -0,0 +1,27 @@
<?php
// Get the absolute path to Admin directory
$admin_dir = dirname(__DIR__);
// Include admin files with absolute paths
include($admin_dir . "/ADMIN_HEADER.php");
include($admin_dir . "/ADMIN_nav.php");
// Use the $lnk variable that comes from main engine.php
// $lnk already contains 'deemand' for /Admin/Agent/deemand
if ($lnk == "") {
include("list_agents.php");
}
// Check if the requested file exists
elseif (file_exists(__DIR__ . "/" . $lnk . ".php")) {
include($lnk . ".php");
}
// If file doesn't exist, show list or 404
else {
include("list_agents.php");
// or include("404.php");
}
include($admin_dir . "/ADMIN_FOOTER.php");
?>

View File

@@ -0,0 +1,6 @@
<?php
echo "<h3>Agent List</h3>";
// Your code to display list of agents
echo "<p>This will show a list of all agents</p>";
echo "<a href='?action=add' class='btn btn-primary'>Add New Agent</a>";
?>

View File

@@ -69,63 +69,95 @@
// // Ensure count doesn't exceed total installments
// return min($count, $totalInstallment);
// }
function countCycles($cycle, $createDate, $totalInstallment) {
function countCycles($cycle, $createDate, $totalInstallment, $accountType) {
$today = new DateTime();
$startDate = new DateTime($createDate);
$cycle = strtoupper(trim($cycle));
$accountType = strtoupper(trim($accountType));
if ($cycle === "D") {
// দৈনিক চক্র: ক্রিয়েশন ডেট থেকেই শুরু
$firstPaymentDate = clone $startDate; // পরের দিন নয়, সেই দিনই
if ($accountType === "Recurring") {
// Recurring account: creation date ই first EMI date
$firstPaymentDate = clone $startDate;
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") {
// সাপ্তাহিক চক্র: দিন পরে প্রথম 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") {
// মাসিক চক্র: পরের মাসের同一天 প্রথম 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');
if ($cycle === "D") {
$diff = $firstPaymentDate->diff($today);
$count = $diff->days + 1;
} elseif ($cycle === "W") {
$diff = $firstPaymentDate->diff($today);
$count = floor($diff->days / 7) + 1;
} elseif ($cycle === "M") {
$count = 1; // প্রথম EMI already due
$nextPaymentDate = clone $firstPaymentDate;
// তারিখ adjust করাが必要 হলে
if ($nextPaymentDate->format('d') != $firstPaymentDate->format('d')) {
$nextPaymentDate->modify('last day of this month');
}
if ($nextPaymentDate <= $today) {
$count++;
while ($nextPaymentDate <= $today) {
$nextPaymentDate->modify('+1 month');
if ($nextPaymentDate->format('d') != $firstPaymentDate->format('d')) {
$nextPaymentDate->modify('last day of this month');
}
if ($nextPaymentDate <= $today) {
$count++;
}
}
} else {
$count = 0;
}
}
} elseif ($accountType === "Loan") {
// Loan account: cycle অনুযায়ী first EMI later
if ($cycle === "D") {
$firstPaymentDate = (clone $startDate)->modify('+1 day');
if ($firstPaymentDate > $today) {
$count = 0;
} else {
$diff = $firstPaymentDate->diff($today);
$count = $diff->days + 1;
}
} elseif ($cycle === "W") {
$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") {
$firstPaymentDate = (clone $startDate)->modify('+1 month');
if ($firstPaymentDate->format('d') != $startDate->format('d')) {
$firstPaymentDate->modify('last day of this month');
}
if ($firstPaymentDate > $today) {
$count = 0;
} else {
$count = 1;
$nextPaymentDate = clone $firstPaymentDate;
while ($nextPaymentDate <= $today) {
$nextPaymentDate->modify('+1 month');
if ($nextPaymentDate->format('d') != $firstPaymentDate->format('d')) {
$nextPaymentDate->modify('last day of this month');
}
if ($nextPaymentDate <= $today) {
$count++;
}
}
}
} else {
$count = 0;
}
} else {
$count = 0;
$count = 0; // Unknown account type
}
return min($count, $totalInstallment);
@@ -183,7 +215,7 @@ foreach($types as $type){
$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']) - $paidInstallment;
$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, '.', '');
@@ -191,7 +223,7 @@ foreach($types as $type){
$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']) - $paidInstallment;
$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, '.', '');

View File

@@ -1,24 +1,13 @@
<?php
$lnk2 = explode('?', $lnk);
include("ADMIN_HEADER.php");
//if(isset($_SESSION['EMAIL']) && ($_SESSION['EMAIL'] =="sarkar.suvankar@gmail.com" || $_SESSION['EMAIL']=="samiran.in@gmail.com" || $_SESSION['EMAIL']=="arif.kanyashree@gmail.com") ) {
// if($_SESSION['EMAIL'] =="sarkar.suvankar@gmail.com" || $_SESSION['EMAIL']=="samiran.in@gmail.com" || $_SESSION['EMAIL']=="arif.kanyashree@gmail.com") {
// if(isset($_SESSION['EMAIL']) && ($_SESSION['EMAIL'] =="sarkar.suvankar@gmail.com" || $_SESSION['EMAIL']=="samiran.in@gmail.com" || $_SESSION['EMAIL']=="arif.kanyashree@gmail.com") ) {
include("ADMIN_nav.php");
echo "<br>";
if($lnk=="") include("home.php");
elseif(file_exists(__DIR__."/".$lnk.".php")) include($lnk.".php");
elseif(isset($lnk2[1]) && file_exists(__DIR__."/".$lnk2[0].".php") ) include($lnk2[0].".php");
else include("404.php");
/*}
elseif(get_user() == true){
include("AGENT_nav.php");
echo "<br>";
if($lnk=="") include("home.php");
elseif(file_exists(__DIR__."/agent_".$lnk.".php")) include("agent_".$lnk.".php");
elseif(isset($lnk2[1]) && file_exists(__DIR__."/agent_".$lnk2[0].".php") ) include("agent_".$lnk2[0].".php");
else include("404.php");
} else echo '<center><h2>Provide Details to login</h2> <a href="https://siliconpin.com/id/auth"><button class="btn btn-default">Login</button></a></center>'; */
include("ADMIN_nav.php");
echo "<br>";
if($lnk=="") include("home.php");
elseif(file_exists(__DIR__."/".$lnk.".php")) include($lnk.".php");
elseif(isset($lnk2[1]) && file_exists(__DIR__."/".$lnk2[0].".php") ) include($lnk2[0].".php");
else include("404.php");
include("ADMIN_FOOTER.php");
?>