work on deemand sheet page
This commit is contained in:
@@ -22,6 +22,53 @@
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
// function countCycles($cycle, $createDate, $totalInstallment) {
|
||||
// $today = new DateTime();
|
||||
// $startDate = new DateTime($createDate);
|
||||
|
||||
// $cycle = strtoupper(trim($cycle)); // normalize input (W/M/D)
|
||||
|
||||
// if ($cycle === "D") {
|
||||
// // For daily cycles, count starts from the next day
|
||||
// $startDate->modify('+1 day');
|
||||
// if ($startDate > $today) {
|
||||
// $count = 0;
|
||||
// } else {
|
||||
// $diff = $startDate->diff($today);
|
||||
// $count = $diff->days;
|
||||
// }
|
||||
// } elseif ($cycle === "W") {
|
||||
// // For weekly cycles, first payment is next week
|
||||
// $startDate->modify('next monday'); // or use '+1 week' if you want exactly 7 days later
|
||||
|
||||
// if ($startDate > $today) {
|
||||
// $count = 0;
|
||||
// } else {
|
||||
// $diff = $startDate->diff($today);
|
||||
// $count = floor($diff->days / 7);
|
||||
// }
|
||||
// } elseif ($cycle === "M") {
|
||||
// // For monthly cycles, first payment is next month
|
||||
// $startDate->modify('first day of next month');
|
||||
|
||||
// if ($startDate > $today) {
|
||||
// $count = 0;
|
||||
// } else {
|
||||
// $diff = $startDate->diff($today);
|
||||
// $count = ($diff->y * 12) + $diff->m;
|
||||
|
||||
// // If we're in the same month but after the start date, add one
|
||||
// if ($diff->y == 0 && $diff->m == 0 && $diff->d > 0) {
|
||||
// $count++;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// $count = 0; // unknown cycle
|
||||
// }
|
||||
|
||||
// // Ensure count doesn't exceed total installments
|
||||
// return min($count, $totalInstallment);
|
||||
// }
|
||||
function countCycles($cycle, $createDate, $totalInstallment) {
|
||||
$today = new DateTime();
|
||||
$startDate = new DateTime($createDate);
|
||||
@@ -29,8 +76,8 @@
|
||||
$cycle = strtoupper(trim($cycle));
|
||||
|
||||
if ($cycle === "D") {
|
||||
// দৈনিক চক্র: পরের দিন থেকে শুরু
|
||||
$firstPaymentDate = (clone $startDate)->modify('+1 day');
|
||||
// দৈনিক চক্র: ক্রিয়েশন ডেট থেকেই শুরু
|
||||
$firstPaymentDate = clone $startDate; // পরের দিন নয়, সেই দিনই
|
||||
|
||||
if ($firstPaymentDate > $today) {
|
||||
$count = 0;
|
||||
@@ -132,12 +179,22 @@ foreach($types as $type){
|
||||
$paidInst = 0; // বা অন্য লজিক
|
||||
$remainInst = 0;
|
||||
}
|
||||
$paidInstallment = ($row['AA_MATURE_VALUE'] + $row['AA_BAL']) / $row['AA_INSTALLMENT'];
|
||||
$paidInstallment = number_format($paidInstallment, 2, '.', '');
|
||||
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']) - $paidInstallment;
|
||||
$deuEMITillDate = abs($deuEMITillDate);
|
||||
$deuEMITillDate = number_format($deuEMITillDate, 2, '.', '');
|
||||
$deuEMITillDate = countCycles($row['AA_ACTYPE'], $row['AA_DATE'], $row['AA_NO_OF_PAYMENT']) - $paidInstallment;
|
||||
$deuEMITillDate = abs($deuEMITillDate);
|
||||
$deuEMITillDate = number_format($deuEMITillDate, 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']) - $paidInstallment;
|
||||
$deuEMITillDate = abs($deuEMITillDate);
|
||||
$deuEMITillDate = number_format($deuEMITillDate, 2, '.', '');
|
||||
|
||||
}
|
||||
// HTML table row
|
||||
echo "<tr>
|
||||
<td>".$sl."</td>
|
||||
@@ -177,8 +234,8 @@ foreach($types as $type){
|
||||
|
||||
// Update grand total
|
||||
$grandTotal['accounts']++;
|
||||
$grandTotal['paidInstallments'] += $paidInst;
|
||||
$grandTotal['dueInstallments'] += $remainInst;
|
||||
$grandTotal['paidInstallments'] += $paidInstallment;
|
||||
$grandTotal['dueInstallments'] += $deuEMITillDate;
|
||||
$grandTotal['dueAmount'] += $totalDueAmt;
|
||||
|
||||
$sl++;
|
||||
|
||||
Reference in New Issue
Block a user