chnage count cycle function as per account type

This commit is contained in:
ns77@siliconpin.com
2025-08-28 13:39:06 +00:00
parent ce54b72e0e
commit 565705ce7b

View File

@@ -69,7 +69,7 @@
// // Ensure count doesn't exceed total installments // // Ensure count doesn't exceed total installments
// return min($count, $totalInstallment); // return min($count, $totalInstallment);
// } // }
function countCycles($cycle, $createDate, $totalInstallment) { function countCycles($cycle, $createDate, $totalInstallment, $accountType) {
$today = new DateTime(); $today = new DateTime();
$startDate = new DateTime($createDate); $startDate = new DateTime($createDate);
@@ -77,7 +77,11 @@
if ($cycle === "D") { if ($cycle === "D") {
// দৈনিক চক্র: ক্রিয়েশন ডেট থেকেই শুরু // দৈনিক চক্র: ক্রিয়েশন ডেট থেকেই শুরু
$firstPaymentDate = clone $startDate; // পরের দিন নয়, সেই দিনই if($accountType === 'Recurring'){
$firstPaymentDate = clone $startDate; // সেই দিনই শুরু
} elseif($accountType === 'Loan') {
$firstPaymentDate = (clone $startDate)->modify('+1 day'); // পরের দিন থেকে
}
if ($firstPaymentDate > $today) { if ($firstPaymentDate > $today) {
$count = 0; $count = 0;
@@ -86,8 +90,12 @@
$count = $diff->days + 1; // +1 because diff->days doesn't include start day $count = $diff->days + 1; // +1 because diff->days doesn't include start day
} }
} elseif ($cycle === "W") { } elseif ($cycle === "W") {
if($accountType === 'Recurring'){
$firstPaymentDate = clone $startDate;
}elseif($accountType === 'Loan'){
// সাপ্তাহিক চক্র: দিন পরে প্রথম EMI // সাপ্তাহিক চক্র: দিন পরে প্রথম EMI
$firstPaymentDate = (clone $startDate)->modify('+7 days'); $firstPaymentDate = (clone $startDate)->modify('+7 days');
}
if ($firstPaymentDate > $today) { if ($firstPaymentDate > $today) {
$count = 0; $count = 0;
@@ -96,8 +104,13 @@
$count = floor($diff->days / 7) + 1; $count = floor($diff->days / 7) + 1;
} }
} elseif ($cycle === "M") { } elseif ($cycle === "M") {
if($accountType === 'Recurring'){
$firstPaymentDate = clone $startDate;
}elseif($accountType === 'Loan'){
// মাসিক চক্র: পরের মাসের同一天 প্রথম EMI // মাসিক চক্র: পরের মাসের同一天 প্রথম EMI
$firstPaymentDate = (clone $startDate)->modify('+1 month'); $firstPaymentDate = (clone $startDate)->modify('+1 month');
}
// যদি পরের মাসে同一天 না থাকে (যেমন 31st Jan থেকে 28/29th Feb) // যদি পরের মাসে同一天 না থাকে (যেমন 31st Jan থেকে 28/29th Feb)
if ($firstPaymentDate->format('d') != $startDate->format('d')) { if ($firstPaymentDate->format('d') != $startDate->format('d')) {
@@ -183,7 +196,7 @@ foreach($types as $type){
$paidInstallment = ($row['AA_MATURE_VALUE'] + $row['AA_BAL']) / $row['AA_INSTALLMENT']; $paidInstallment = ($row['AA_MATURE_VALUE'] + $row['AA_BAL']) / $row['AA_INSTALLMENT'];
$paidInstallment = number_format($paidInstallment, 2, '.', ''); $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 = abs($deuEMITillDate);
$deuEMITillDate = number_format($deuEMITillDate, 2, '.', ''); $deuEMITillDate = number_format($deuEMITillDate, 2, '.', '');
@@ -191,7 +204,7 @@ foreach($types as $type){
$paidInstallment = $row['AA_BAL'] / $row['AA_INSTALLMENT']; $paidInstallment = $row['AA_BAL'] / $row['AA_INSTALLMENT'];
$paidInstallment = number_format($paidInstallment, 2, '.', ''); $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 = abs($deuEMITillDate);
$deuEMITillDate = number_format($deuEMITillDate, 2, '.', ''); $deuEMITillDate = number_format($deuEMITillDate, 2, '.', '');