Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...top-processor/src/main/scala/com/gu/holidaystopprocessor/NextBillingPeriodStartDate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gu.holidaystopprocessor | ||
|
||
import java.time.LocalDate | ||
|
||
/** | ||
* Holiday credit is applied to the next invoice on the first day of the next billing period. | ||
* | ||
* 'Invoiced period' or `billing period that has already been invoiced` is defined as | ||
* [processedThroughDate, chargedThroughDate) meaning | ||
* - from processedThroughDate inclusive | ||
* - to chargedThroughDate exclusive | ||
* | ||
* Hence chargedThroughDate represents the first day of the next billing period. For quarterly | ||
* billing period this would be the first day of the next quarter, whilst for annual this would be | ||
* the first day of the next year. | ||
* | ||
* Note chargedThroughDate is an API concept. The UI and the actual invoice use the term 'Service Period' | ||
* where from and to dates are both inclusive. | ||
* | ||
* Note nextBillingPeriodStartDate represents a specific date yyyy-mm-dd unlike billingPeriod (quarterly) | ||
* or billingPeriodStartDay (1st of month). | ||
*/ | ||
object NextBillingPeriodStartDate { | ||
def apply(subscription: Subscription): Either[HolidayStopFailure, LocalDate] = { | ||
subscription | ||
.originalRatePlanCharge | ||
.flatMap(_.chargedThroughDate) | ||
.toRight(HolidayStopFailure("Original rate plan charge has no charged through date. A bill run is needed to fix this.")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters