Skip to content

Commit

Permalink
feat: also show previous payments on the calendar for the current month
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite committed Jun 26, 2024
1 parent b429399 commit 28c4716
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,17 @@ class="fa-solid fa-chevron-right"></i></button>
default:
$incrementString = "+{$frequency} months"; // Default case, if needed
}

// Calculate the start of the month
$startOfMonth = strtotime($calendarYear . '-' . str_pad($calendarMonth, 2, '0', STR_PAD_LEFT) . '-01');

// Find the first payment date of the month by moving backwards
$startDate = $nextPaymentDate;
while ($startDate > $startOfMonth) {
$startDate = strtotime("-" . $incrementString, $startDate);
}

for ($date = $nextPaymentDate; $date <= $endDate; $date = strtotime($incrementString, $date)) {
for ($date = $startDate; $date <= $endDate; $date = strtotime($incrementString, $date)) {
if (date('Y-m', $date) == $calendarYear . '-' . str_pad($calendarMonth, 2, '0', STR_PAD_LEFT)) {
if (date('d', $date) == $day) {
?>
Expand Down Expand Up @@ -195,7 +204,16 @@ class="fa-solid fa-chevron-right"></i></button>
$incrementString = "+{$frequency} months"; // Default case, if needed
}

for ($date = $nextPaymentDate; $date <= $endDate; $date = strtotime($incrementString, $date)) {
// Calculate the start of the month
$startOfMonth = strtotime($calendarYear . '-' . str_pad($calendarMonth, 2, '0', STR_PAD_LEFT) . '-01');

// Find the first payment date of the month by moving backwards
$startDate = $nextPaymentDate;
while ($startDate > $startOfMonth) {
$startDate = strtotime("-" . $incrementString, $startDate);
}

for ($date = $startDate; $date <= $endDate; $date = strtotime($incrementString, $date)) {
if (date('Y-m', $date) == $calendarYear . '-' . str_pad($calendarMonth, 2, '0', STR_PAD_LEFT)) {
if (date('d', $date) == $day) {
?>
Expand Down

0 comments on commit 28c4716

Please sign in to comment.