if (firstTime || collectionSheetFlatData.getClientId().equals(prevClientId)) {
if (collectionSheetFlatData.getLoanId() != null) {
loansDueData.add(collectionSheetFlatData.getLoanDueData());
}
} else {
final JLGClientData clientData = prevCollectioSheetFlatData.getClientData();
clientData.setLoans(loansDueData);
clientsData.add(clientData);
loansDueData = new ArrayList<>();
if (collectionSheetFlatData.getLoanId() != null) {
loansDueData.add(collectionSheetFlatData.getLoanDueData());
}
}
} else {
final JLGClientData clientData = prevCollectioSheetFlatData.getClientData();
clientData.setLoans(loansDueData);
clientsData.add(clientData);
final JLGGroupData jlgGroupData = prevCollectioSheetFlatData.getJLGGroupData();
jlgGroupData.setClients(clientsData);
jlgGroupsData.add(jlgGroupData);
loansDueData = new ArrayList<>();
clientsData = new ArrayList<>();
if (collectionSheetFlatData.getLoanId() != null) {
loansDueData.add(collectionSheetFlatData.getLoanDueData());
}
}
prevClientId = collectionSheetFlatData.getClientId();
prevGroupId = collectionSheetFlatData.getGroupId();
prevCollectioSheetFlatData = collectionSheetFlatData;
firstTime = false;
}
// FIXME Need to check last loan is added under previous
// client/group or new client / previous group or new client / new
// group
if (corrCollectioSheetFlatData != null) {
final JLGClientData lastClientData = corrCollectioSheetFlatData.getClientData();
lastClientData.setLoans(loansDueData);
clientsData.add(lastClientData);
final JLGGroupData jlgGroupData = corrCollectioSheetFlatData.getJLGGroupData();
jlgGroupData.setClients(clientsData);
jlgGroupsData.add(jlgGroupData);