Fix cycle end calculation for misaligned cycle_start dates
Make cycle generation idempotent by skipping existing cycles
This commit is contained in:
parent
e3d615acb8
commit
3241dd7d96
2 changed files with 43 additions and 9 deletions
|
|
@ -299,11 +299,15 @@ defmodule Mv.MembershipFees.CalendarCycles do
|
|||
end
|
||||
|
||||
defp quarterly_cycle_end(cycle_start) do
|
||||
case cycle_start.month do
|
||||
1 -> Date.new!(cycle_start.year, 3, 31)
|
||||
4 -> Date.new!(cycle_start.year, 6, 30)
|
||||
7 -> Date.new!(cycle_start.year, 9, 30)
|
||||
10 -> Date.new!(cycle_start.year, 12, 31)
|
||||
# Ensure cycle_start is aligned to quarter boundary
|
||||
# This handles cases where cycle_start might not be at the correct quarter start (e.g., month 12)
|
||||
aligned_start = quarterly_cycle_start(cycle_start)
|
||||
|
||||
case aligned_start.month do
|
||||
1 -> Date.new!(aligned_start.year, 3, 31)
|
||||
4 -> Date.new!(aligned_start.year, 6, 30)
|
||||
7 -> Date.new!(aligned_start.year, 9, 30)
|
||||
10 -> Date.new!(aligned_start.year, 12, 31)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -313,9 +317,13 @@ defmodule Mv.MembershipFees.CalendarCycles do
|
|||
end
|
||||
|
||||
defp half_yearly_cycle_end(cycle_start) do
|
||||
case cycle_start.month do
|
||||
1 -> Date.new!(cycle_start.year, 6, 30)
|
||||
7 -> Date.new!(cycle_start.year, 12, 31)
|
||||
# Ensure cycle_start is aligned to half-year boundary
|
||||
# This handles cases where cycle_start might not be at the correct half-year start (e.g., month 10)
|
||||
aligned_start = half_yearly_cycle_start(cycle_start)
|
||||
|
||||
case aligned_start.month do
|
||||
1 -> Date.new!(aligned_start.year, 6, 30)
|
||||
7 -> Date.new!(aligned_start.year, 12, 31)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue