// List<Expenditure> list = new ArrayList<Expenditure>(map.values());
// SortComparator comparator = new SortComparator();
// Collections.sort(list, comparator);
Map<String, Expenditure> map = (Map<String, Expenditure>) system.query(new GetExpenditures());
List<Expenditure> list = new ArrayList<Expenditure>();
GDDate date;
for (Expenditure expenditure : map.values()) {
if (expenditure.isActive()) {
date = new GDDate(expenditure.getNextPaymentDate());
int frequency = expenditure.getFrequency();
if (expenditure.getNumberOfOcurrencies() > 0) {
int i = 1;
while (i <= expenditure.getNumberOfOcurrencies()) {
if ( date.afterOrEqualsDay(fromDate) && date.beforeOrEqualsDay(toDate) ){
// Expenditure myBill = new Expenditure(expenditure.getId(), expenditure.getDescription(), new GDDate(date), expenditure.getFrequency(), expenditure.getNumberOfOcurrencies(), expenditure.getValue(), expenditure.isFixedValue(), expenditure.getCategoryId(), expenditure.getObservation());
Expenditure myBill = new Expenditure(expenditure.getId(), expenditure.getDescription(), new GDDate(date), expenditure.getFrequency(), expenditure.getNumberOfOcurrencies(), expenditure.getValue(), expenditure.isFixedValue(), expenditure.getCategoryId(), expenditure.getObservation(),expenditure.getFirstPaymentDate(),expenditure.getLastPaymentDate());
list.add(myBill);
}
date = skip(date, frequency);
if (date == null) {
break;
}
i++;
}
}else{
while (date.beforeOrEqualsDay(toDate)){
if ( date.afterOrEqualsDay(fromDate) && date.beforeOrEqualsDay(toDate) ){
Expenditure myBill = new Expenditure(expenditure.getId(), expenditure.getDescription(), new GDDate(date), expenditure.getFrequency(), expenditure.getNumberOfOcurrencies(), expenditure.getValue(), expenditure.isFixedValue(), expenditure.getCategoryId(), expenditure.getObservation(),expenditure.getFirstPaymentDate(),expenditure.getLastPaymentDate());
list.add(myBill);
}
date = skip(date, frequency);
if (date == null) {
break;
}
}
}
}
}
SortComparator comparator = new SortComparator();
Collections.sort(list, comparator);
int bgColorControl = 0;
for (Expenditure expenditure : list) {
if (expenditure.isActive()) {
TableItem item = new TableItem(expenditureTable, SWT.NONE | SWT.MULTI | SWT.WRAP);
if (bgColorControl == 1) {
item.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
bgColorControl = 0;
} else {
bgColorControl = 1;
}
GDDate todayPlusOneWeek = new GDDate();
todayPlusOneWeek.addDays(7);
GDDate nextPaymentDate = expenditure.getNextPaymentDate();
GDDate today = new GDDate();
Expenditure expenditureToCompare = (Expenditure) system.query(new GetExpenditures(expenditure.getId()));
GDDate paymentDayBill = expenditureToCompare.getNextPaymentDate();
if (paymentDayBill.beforeDay(nextPaymentDate) && paymentDayBill.beforeDay(today)) {
item.setImage(new Image(null, "img/icoExpiradNotPayed.png"));
} else if (nextPaymentDate.beforeOrEqualsDay(todayPlusOneWeek) && nextPaymentDate.afterOrEqualsDay(today)) {