def availableAmount()

in src/main/scala/com/gu/invoicing/refund/Impl.scala [89:98]


  def availableAmount(invoiceItem: InvoiceItem, adjustments: List[InvoiceItemAdjustment]): Option[BigDecimal] = {
    netAdjustmentsByInvoiceItemId(adjustments).get(invoiceItem.Id) match {
      case Some(netAdjustment) =>
        val availableRefundableAmount = invoiceItem.amountWithTax - netAdjustment
        if (availableRefundableAmount <= 0) None else Some(availableRefundableAmount)

      case None => // this items has not been adjusted therefore the original full item amount is available
        if (invoiceItem.amountWithTax <= 0) None else Some(invoiceItem.amountWithTax)
    }
  }