private static BigDecimal computeInvoiceAmountAdjustedForAccountCredit ( final Currency currency , final Iterable < InvoiceItem > invoiceItems ) { BigDecimal amountAdjusted = BigDecimal . ZERO ; if ( invoiceItems == null || ! invoiceItems . iterator ( ) . hasNext ( ) ) { return KillBillMoney . of ( amountAdjusted , currency ) ; } for ( final InvoiceItem invoiceItem : invoiceItems ) { final Iterable < InvoiceItem > otherInvoiceItems = Iterables . filter ( invoiceItems , new Predicate < InvoiceItem > ( ) { @ Override public boolean apply ( final InvoiceItem input ) { return ! input . getId ( ) . equals ( invoiceItem . getId ( ) ) ; } } ) ; if ( InvoiceItemType . CREDIT_ADJ . equals ( invoiceItem . getInvoiceItemType ( ) ) && ( Iterables . size ( otherInvoiceItems ) == 1 && InvoiceItemType . CBA_ADJ . equals ( otherInvoiceItems . iterator ( ) . next ( ) . getInvoiceItemType ( ) ) && otherInvoiceItems . iterator ( ) . next ( ) . getInvoiceId ( ) . equals ( invoiceItem . getInvoiceId ( ) ) && otherInvoiceItems . iterator ( ) . next ( ) . getAmount ( ) . compareTo ( invoiceItem . getAmount ( ) . negate ( ) ) == 0 ) ) { amountAdjusted = amountAdjusted . add ( invoiceItem . getAmount ( ) ) ; } } return KillBillMoney . of ( amountAdjusted , currency ) ; }
Snowflake for the CREDIT_ADJ on its own invoice