try {
List<Billet> billets = new ArrayList<Billet>();
int parcelId = 1;
String text = "";
Billet billet = null;
if(oneStudents.getSelection()){
List<Parcel> parcels = selectedRegistration.getParcels();
MergeSortAlgorithm sort = new MergeSortAlgorithm();
sort.sortParcelByDate(parcels);
for (Parcel parcel : parcels) {
if(parcelIsSelected(parcelId, getSelectedParcels())) {
billet = new Billet(String.valueOf(parcelId), parcel, selectedRegistration, selectedRegistration.getStudent(), getNamePrint(selectedRegistration));
billets.add(billet);
}
parcelId++;
text = " do aluno " + ((billet != null)?billet.getPerson().getName():" ");
}
} else {
GDDate begin = new GDDate(initialDateText.getText());
GDDate end = new GDDate(endDateText.getText());
Map<String, Registration> registrationMap = (Map<String, Registration>) system.query(new GetRegistration());
for (Registration registration : registrationMap.values()) {
parcelId = 1;
for (Parcel parcel : registration.getParcels()) {
GDDate parcelDate = new GDDate(parcel.getDate());
if(begin.beforeOrEqualsDay(parcelDate) && end.afterOrEqualsDay(parcelDate) && !parcel.isPayed()){
billet = new Billet(String.valueOf(parcelId), parcel, registration, registration.getStudent(), getNamePrint(registration));
billets.add(billet);
parcelId++;
}
}
}