customers.add(preferredCustomer);
}else{
customers = getAllCustomers();
}
for(Customer customer : customers){
OutstandingBalanceInfoBean balanceBean = new OutstandingBalanceInfoBean();
balanceBean.setCustomerName(customer.getName());
Invoice invoice = getLastInvoice(customer);
if(invoice!=null){
balanceBean.setCarriedForward(invoice.getCarriedForward().toString());
balanceBean.setLastInvoiceDate(invoice.getDate());
List<Subscription> subscriptions = getInvoiceSubscriptions(invoice.getId());
if(subscriptions!=null && subscriptions.size()>0){
balanceBean.setSubscription(subscriptions.get(0).getSubscriptionPlan());
}
}else{ //if we dont have an invoice we have to look for the active subscription to get the subscription plan
Subscription subscription = getActiveSubscriptionOfCustomer(customer.getId());
if(subscription!=null){
balanceBean.setSubscription(subscription.getSubscriptionPlan());
}else{
balanceBean.setSubscription("Not Available");
}
}
Payment payment = getLastPayment(customer);
if(payment!=null){
balanceBean.setLastPaidAmount(payment.getAmount().toString());
balanceBean.setLastPaymentDate(payment.getDate());
}
outstandingBalances.add(balanceBean);
}
return outstandingBalances;
}