in src/main/scala/com/gu/invoicing/preview/Impl.scala [275:296]
def pricePerPublication(invoiceItem: InvoiceItem): Double = {
def round2Places(d: Double): Double = BigDecimal(d).setScale(2, RoundingMode.UP).toDouble
def roundedWeeks(weeks: Long): Long = weeks match {
case 12 | 13 => 13 // Quarter
case 51 | 52 => 52 // Annual
case 25 | 26 => 26 // Semi_annual
case 3 | 4 => 4 // Month
case 5 | 6 => 6 // 6 for 6
case 7 =>
6 // 6 for 6 (7 weeks billing period might happen during Christmas time when have to extend to account for missing issue)
case v =>
log(invoiceItem, s"WARN: Check publication price for unusual billing period of $weeks"); v
}
val approxBillingPeriodInWeeks = roundedWeeks(
WEEKS.between( // plus one because between is exclusive on right bound but serviceEndDate is inclusive
invoiceItem.serviceStartDate,
invoiceItem.serviceEndDate.plusDays(1),
),
)
round2Places(invoiceItem.chargeAmount / approxBillingPeriodInWeeks)
}