Skip to content
Browse files

Merge pull request #235 from roostr/master

Fixed #234 Clicking month bar shows report that's off by one month
  • Loading branch information...
2 parents 73ba06d + c7c1cea commit 246409c1b887c39260b0d60c9a267532e6cc515e @omz committed
Showing with 8 additions and 11 deletions.
  1. +8 −11 Classes/SalesViewController.m
View
19 Classes/SalesViewController.m
@@ -239,21 +239,18 @@ - (void)reloadData
for (Report *dailyReport in sortedDailyReports) {
NSDateComponents *dateComponents = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit fromDate:dailyReport.startDate];
if (!prevDateComponents || (dateComponents.month != prevDateComponents.month || dateComponents.year != prevDateComponents.year)) {
- if (reportsInCurrentMonth) {
- ReportCollection *monthCollection = [[[ReportCollection alloc] initWithReports:reportsInCurrentMonth] autorelease];
- monthCollection.title = [monthFormatter stringFromDate:dailyReport.startDate];
- [sortedCalendarMonthReports addObject:monthCollection];
- }
+ // New month discovered. Make a new ReportCollection to gather all the daily reports in this month.
reportsInCurrentMonth = [NSMutableArray array];
+ [reportsInCurrentMonth addObject:dailyReport];
+ ReportCollection *monthCollection = [[[ReportCollection alloc] initWithReports:reportsInCurrentMonth] autorelease];
+ monthCollection.title = [monthFormatter stringFromDate:dailyReport.startDate];
+ [sortedCalendarMonthReports addObject:monthCollection];
+ } else {
+ // This report is from the same month as the previous report. Append the daily report to the existing collection.
+ [reportsInCurrentMonth addObject:dailyReport];
}
- [reportsInCurrentMonth addObject:dailyReport];
prevDateComponents = dateComponents;
}
- if ([reportsInCurrentMonth count] > 0) {
- ReportCollection *monthCollection = [[[ReportCollection alloc] initWithReports:reportsInCurrentMonth] autorelease];
- monthCollection.title = [monthFormatter stringFromDate:[monthCollection firstReport].startDate];
- [sortedCalendarMonthReports addObject:monthCollection];
- }
// Group daily reports by fiscal month:
[sortedFiscalMonthReports removeAllObjects];

0 comments on commit 246409c

Please sign in to comment.
Something went wrong with that request. Please try again.