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 '
VIEW CUSTOMERS

'; if ($_SESSION['type'] === 'admin') { echo ''; } if(isset($_GET['Type']) && $_GET['Type']=="Recurring" || $_GET['Type']=="Matured-Recurring"){ echo ' '; }elseif(isset($_GET['Type']) && $_GET['Type']=="Loan" || $_GET['Type']=="Closed-Acc"){ echo ' '; } // $conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Build SQL query based on user type and account type if($_SESSION['type'] === 'agent') { if($type === 'Closed-Acc') { // Only Closed Loan $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='Loan' AND `STATUS`='closed' AND `AA_AGENT`='".$_SESSION['user_id']."' ORDER BY `AA_ID` DESC"; } elseif($type === 'Matured-Recurring') { // Only Matured Recurring $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='Recurring' AND `STATUS`='matured' AND `AA_AGENT`='".$_SESSION['user_id']."' ORDER BY `AA_ID` DESC"; } elseif($type === 'Loan') { // Loan except Closed (include NULL) $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='Loan' AND (`STATUS` IS NULL OR `STATUS`!='closed') AND `AA_AGENT`='".$_SESSION['user_id']."' ORDER BY `AA_ID` DESC"; } elseif($type === 'Recurring') { // Recurring except Matured (include NULL) $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='Recurring' AND (`STATUS` IS NULL OR `STATUS`!='matured') AND `AA_AGENT`='".$_SESSION['user_id']."' ORDER BY `AA_ID` DESC"; } else { $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='".$type."' AND `AA_AGENT`='".$_SESSION['user_id']."' ORDER BY `AA_ID` DESC"; } } elseif($_SESSION['type'] === 'admin' || $_SESSION['type'] === 'bm') { if($type === 'Closed-Acc') { $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='Loan' AND `STATUS`='closed' ORDER BY `AA_ID` DESC"; } elseif($type === 'Matured-Recurring') { $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='Recurring' AND `STATUS`='matured' ORDER BY `AA_ID` DESC"; } elseif($type === 'Loan') { // Loan except Closed (include NULL) $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='Loan' AND (`STATUS` IS NULL OR `STATUS`!='closed') ORDER BY `AA_ID` DESC"; } elseif($type === 'Recurring') { // Recurring except Matured (include NULL) $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='Recurring' AND (`STATUS` IS NULL OR `STATUS`!='matured') ORDER BY `AA_ID` DESC"; } else { $sql = "SELECT * FROM `".$GLOBALS['arif_ac']."` WHERE `AA_TYPE`='".$type."' ORDER BY `AA_ID` DESC"; } } $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $tt = $row["AA_ID"] - 10; $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 { $no_paid_inst = $row["AA_BAL"] / $row["AA_INSTALLMENT"]; } if ($row["AA_ACTYPE"] == 'D') { $diff = $diff->format("%a"); $diff = (int)$diff; $due_i = $diff - $no_paid_inst; } else { $diff = $diff->format("%m"); $diff = (int)$diff; $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 ""; if ($_SESSION['type'] === 'admin') { echo ""; } echo ""; if($row["AA_TYPE"] === 'Recurring'){ echo ""; }elseif($row["AA_TYPE"] === 'Loan'){ echo ""; } // $totalDeuAmount // if ($due_i > 0) { // $due_amount = $due_i * $row["AA_INSTALLMENT"]; // echo ""; // } else { // $due_amount = 'All Clear'; // echo ""; // } // if ($due_i > 0 && $type == "Recurring") { // $due_amount = $due_i * $row["AA_INSTALLMENT"]; // $due_amount = (($due_amount) * 20)/100; // echo ""; // } elseif ($due_i > 0 && $type == "Loan") { // $due_amount = $due_i * $row["AA_INSTALLMENT"]; // $due_amount = (($due_amount) * 40)/100; // echo ""; // } else { // $due_amount = 'Up to Date!!'; // echo ""; // } echo ""; } } else { echo ""; } $conn->close(); echo '
SL TypeAgentAC No Name Account Creation Date Maturity Amount PHONE Balance Total Installment Paid Installment Deu Installment Till Date Installment Amount Due Amount
AC No Name Account Creation Date Loan Amount PHONE Balance Total EMI Paid EMI Deu EMI Till Date EMI Amount Due Amount
Due after Fine
".$tt." ".$row["AA_ACTYPE"].",".$row["AA_TYPE"]."".$row["AA_AGENT"]."".$row["AA_ACNO"]."    Transact ".$row["AA_NAME"]." ".$row["AA_DATE"]." ".$row["AA_MATURE_VALUE"]." ".$row["AA_PHONE"]." ".$row["AA_BAL"]. " ".$row["AA_NO_OF_PAYMENT"]." ".$paidInstallment." ".$deuEMITillDate." ".$row["AA_INSTALLMENT"]."".($totalDeuAmount > 0 ? $totalDeuAmount : "All Clear")."".($totalDeuAmount < 0 ? $totalDeuAmount : "All Clear")."".$due_amount."".$due_amount."".$due_amount."".$due_amount."".$due_amount."
0 results
'; } if(isset($_GET['Type'])) { switch($_GET['Type']) { case "Loan": view_list_ac('Loan'); break; case "Recurring": view_list_ac('Recurring'); break; case "Matured-Recurring": view_list_ac('Matured-Recurring'); break; case "FD": view_list_ac('FD'); break; case "Closed-Acc": view_list_ac('Closed-Acc'); break; } } ?>