diff --git a/CONTENT/ROOT_URI/Admin/Due.php b/CONTENT/ROOT_URI/Admin/Due.php index 0e622a1..a6eea70 100644 --- a/CONTENT/ROOT_URI/Admin/Due.php +++ b/CONTENT/ROOT_URI/Admin/Due.php @@ -210,7 +210,8 @@ foreach($types as $type){ } // HTML table row - echo " + if($deuEMITillDate > 0){ + echo " ".$sl." ".$row['AA_ACTYPE'].", ".$row['AA_TYPE']." ".$row['AA_ACNO']." @@ -226,6 +227,8 @@ foreach($types as $type){ ".$totalDueAmt." "; + } + // ".$remainInst." ".$row['AA_NO_OF_PAYMENT']." // PDF simplified row // "SL","NAME ","MOBILE NO", "CYCLE", "ACCOUNT NO","EMI PAID","EMI DUE", "EMI AMOUNT", "CUSTOMER. SIGN" diff --git a/CONTENT/ROOT_URI/Admin/View_AC copy.php b/CONTENT/ROOT_URI/Admin/View_AC copy.php new file mode 100644 index 0000000..75d73bd --- /dev/null +++ b/CONTENT/ROOT_URI/Admin/View_AC copy.php @@ -0,0 +1,284 @@ +
+ +
+ +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 ''; + } + + 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') { + 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']; + + }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; + + } + + echo " + + "; + + if ($_SESSION['type'] === 'admin') { + echo ""; + } + + echo " + + + + + + + + + + "; + + 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 '
SLTypeAgentAC NoNameAccount Creation DateLoan AmountPHONEBalanceTotal EMIPaid EMIDue EMIDeu EMI Till DateEMI AmountDue AmountDue 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."".$totalDEUEMI."".$deuEMITillDate."".$due_i."".$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; + } +} +?> diff --git a/CONTENT/ROOT_URI/Admin/View_AC.php b/CONTENT/ROOT_URI/Admin/View_AC.php index 1108574..ebf0a6e 100644 --- a/CONTENT/ROOT_URI/Admin/View_AC.php +++ b/CONTENT/ROOT_URI/Admin/View_AC.php @@ -19,6 +19,80 @@ 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 '
@@ -29,27 +103,40 @@ function view_list_ac($type) { SL Type'; - - if ($_SESSION['type'] === 'admin') { - echo 'Agent'; - } + if ($_SESSION['type'] === 'admin') { + echo 'Agent'; + } + if(isset($_GET['Type']) && $_GET['Type']=="Recurring" || $_GET['Type']=="Matured-Recurring"){ + echo ' + AC No + Name + Account Creation Date + Maturity Amount + PHONE + Balance + Total Installment + Paid Installment + Deu Installment Till Date + Installment Amount + Due Amount + '; + }elseif(isset($_GET['Type']) && $_GET['Type']=="Loan" || $_GET['Type']=="Closed-Acc"){ + echo ' + AC No + Name + Account Creation Date + Loan Amount + PHONE + Balance + Total EMI + Paid EMI + Deu EMI Till Date + EMI Amount + Due Amount + '; + } - echo ' - AC No - Name - Account Creation Date - Loan Amount - PHONE - Balance - Total No Of Installment to be paid - No Of Paid Installment - No of Expected Installment till today - Installment Amount - Due Installment - Due Amount - Due after Fine - '; - + // Due after Fine $conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); @@ -97,7 +184,7 @@ function view_list_ac($type) { $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 { @@ -114,6 +201,34 @@ function view_list_ac($type) { $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 " ".$tt." ".$row["AA_ACTYPE"].",".$row["AA_TYPE"].""; @@ -122,39 +237,45 @@ function view_list_ac($type) { echo "".$row["AA_AGENT"].""; } - echo "".$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"]." - ".$no_paid_inst." - ".$diff." - ".$row["AA_INSTALLMENT"]." - ".$due_i.""; - - if ($due_i > 0) { - $due_amount = $due_i * $row["AA_INSTALLMENT"]; - echo "".$due_amount.""; - } else { - $due_amount = 'All Clear'; - echo "".$due_amount.""; + echo "".$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"].""; + if($row["AA_TYPE"] === 'Recurring'){ + echo "".($totalDeuAmount > 0 ? $totalDeuAmount : "All Clear").""; + }elseif($row["AA_TYPE"] === 'Loan'){ + echo "".($totalDeuAmount < 0 ? $totalDeuAmount : "All Clear").""; } + + + // $totalDeuAmount - if ($due_i > 0 && $type == "Recurring") { - $due_amount = $due_i * $row["AA_INSTALLMENT"]; - $due_amount = (($due_amount) * 20)/100; - echo "".$due_amount.""; - } elseif ($due_i > 0 && $type == "Loan") { - $due_amount = $due_i * $row["AA_INSTALLMENT"]; - $due_amount = (($due_amount) * 40)/100; - echo "".$due_amount.""; - } else { - $due_amount = 'Up to Date!!'; - echo "".$due_amount.""; - } + // if ($due_i > 0) { + // $due_amount = $due_i * $row["AA_INSTALLMENT"]; + // echo "".$due_amount.""; + // } else { + // $due_amount = 'All Clear'; + // echo "".$due_amount.""; + // } + + // if ($due_i > 0 && $type == "Recurring") { + // $due_amount = $due_i * $row["AA_INSTALLMENT"]; + // $due_amount = (($due_amount) * 20)/100; + // echo "".$due_amount.""; + // } elseif ($due_i > 0 && $type == "Loan") { + // $due_amount = $due_i * $row["AA_INSTALLMENT"]; + // $due_amount = (($due_amount) * 40)/100; + // echo "".$due_amount.""; + // } else { + // $due_amount = 'Up to Date!!'; + // echo "".$due_amount.""; + // } echo ""; }