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") { // সাপ্তাহিক চক্র: ৭ দিন পরে প্রথম 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'); // তারিখ 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); } $conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $agent_id = $_SESSION['user_id']; $types = ['Loan', 'Recurring']; $pdfData = []; $sl = 1; // Grand total for PDF $grandTotal = [ 'accounts' => 0, 'paidInstallments' => 0, 'dueInstallments' => 0, 'dueAmount' => 0 ]; foreach($types as $type){ $typeLike = "%$type%"; if($_SESSION['type']==='admin'){ $sql = "SELECT * FROM `" . $GLOBALS['arif_ac'] . "` WHERE `AA_TYPE` LIKE ? AND (`STATUS` IS NULL OR (`STATUS`!='closed' AND `STATUS`!='matured')) ORDER BY `AA_ID` DESC"; $stmt = $conn->prepare($sql); $stmt->bind_param("s", $typeLike); } elseif($_SESSION['type']==='agent'){ $sql = "SELECT * FROM `" . $GLOBALS['arif_ac'] . "` WHERE `AA_TYPE` LIKE ? AND (`STATUS` IS NULL OR (`STATUS`!='closed' AND `STATUS`!='matured')) AND `AA_AGENT`=? ORDER BY `AA_ID` DESC"; $stmt = $conn->prepare($sql); $stmt->bind_param("ss", $typeLike, $agent_id); } $stmt->execute(); $result = $stmt->get_result(); if($result->num_rows>0){ echo ""; while($row = $result->fetch_assoc()){ $totalDueAmt = $row['AA_BAL']; if ($row['AA_INSTALLMENT'] > 0) { $paidInst = ($row['AA_MATURE_VALUE'] + $row['AA_BAL']) / $row['AA_INSTALLMENT']; $paidInst = number_format($paidInst, 2); $remainInst = abs($row['AA_BAL']) / $row['AA_INSTALLMENT']; $remainInst = number_format($remainInst, 2); } else { $paidInst = 0; // বা অন্য লজিক $remainInst = 0; } $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, '.', ''); // HTML table row echo ""; // // PDF simplified row // "SL","NAME ","MOBILE NO", "CYCLE", "ACCOUNT NO","EMI PAID","EMI DUE", "EMI AMOUNT", "CUSTOMER. SIGN" if($deuEMITillDate != 0){ $pdfData[] = [ $type, $sl, $row['AA_NAME'], // NAME OF ACCOUNT HOLDER $row['AA_PHONE'], // MOBILE NO (blank) $row['AA_ACTYPE'], // EMI Cycle $row['AA_ACNO'], // ACCOUNT NO $paidInstallment, // NO OF INSTALLMENT PAID $deuEMITillDate, // NO OF INSTALLMENT DUE $row['AA_INSTALLMENT'], // EMI AMOUNT // $totalDueAmt, // TOTAL DUE AMOUNT "" // CUSTOMER SIGNATURE ]; } // Update grand total $grandTotal['accounts']++; $grandTotal['paidInstallments'] += $paidInst; $grandTotal['dueInstallments'] += $remainInst; $grandTotal['dueAmount'] += $totalDueAmt; $sl++; // echo $dueInst . '
'; } } } $conn->close(); ?>
SL Type AC No Name Mobile Account Create Date Maturity Value Balance Total EMI Total Paid EMI Deu EMI Till Date EMI Amount Total Due Amount
$type Demand
".$sl." ".$row['AA_ACTYPE'].", ".$row['AA_TYPE']." ".$row['AA_ACNO']." ".$row['AA_NAME']." ".$row['AA_PHONE']." ".$row['AA_DATE']." ".$row['AA_MATURE_VALUE']." ".$row['AA_BAL']." ".$row['AA_NO_OF_PAYMENT']." ".$paidInstallment." ".$deuEMITillDate." ".$row['AA_INSTALLMENT']." ".$totalDueAmt."
".$remainInst." ".$row['AA_NO_OF_PAYMENT']."