-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyBookingsController.mm
473 lines (362 loc) · 13 KB
/
MyBookingsController.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
//
// MyBookingsController.m
// iOdyssey
//
// Created by Michael Holm on 6/27/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "MyBookingsController.h"
#import "MyBookingCell.h"
#import "EmptyBookingCell.h"
#import "DateViewController.h"
#import "iOdysseyAppDelegate.h"
#import "CustomCellBackgroundView.h"
@implementation MyBookingsController
@synthesize table, bookingDetailController, ResourceName, preferencesController, aboutController, DisplayScopeLabel, UpdatedDateLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
// DLog(@"initWithNibName");
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
// DLog(@"initWithNibName return");
return self;
}
- (void)didReceiveMemoryWarning
{
DLog(@"didReceiveMemoryWarning");
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (void)viewDidLoad
{
// AppDelegate does not exist yet, so kep our own timezone
NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
DateAndTimeFormatter = [[NSDateFormatter alloc] init];
[DateAndTimeFormatter setDateFormat:@"dd/MM-yyyy HH:mm"];
[DateAndTimeFormatter setTimeZone:timeZone];
TimeFormatter = [[NSDateFormatter alloc] init];
[TimeFormatter setDateFormat:@"HH:mm"];
[TimeFormatter setTimeZone:timeZone];
ShortDateTimeFormatter = [[NSDateFormatter alloc] init];
[ShortDateTimeFormatter setDateFormat:@"ddMMMyy"];
[ShortDateTimeFormatter setTimeZone:timeZone];
DayNameFormatter = [[NSDateFormatter alloc] init];
[DayNameFormatter setDateFormat:@"cccc"];
[DayNameFormatter setTimeZone:timeZone];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
*/
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
switch (toInterfaceOrientation)
{
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
[self RefreshView];
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
[self dismissModalViewControllerAnimated:YES];
break;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// DLog(@"indexPath.colum:%d indexPath.row:%d ", indexPath.section, indexPath.row);
if(AppDelegate.IsIpad)
return 75;
int myResourceKey = AppDelegate.loginData.Login.RE_KEY;
for(Resource *res in AppDelegate->viewData.Resources)
if(res.RE_KEY == myResourceKey)
{
if([res.bookings count] == 0)
return 430;
else
return 75;
}
return 75; // quiet compiler
}
-(void) RefreshView
{
cout << "MyBookingsController :: RefreshView" << endl;
int myResourceKey = AppDelegate.loginData.Login.RE_KEY;
NSDate *a=[NSDate date];
Date today(a);
today=today.LocalTime();
[UpdatedDateLabel setText:today.FormatForUpdatedLabel()];
[ResourceName setText:AppDelegate.loginData.Login.FULL_NAME];
// Sort entries by date
for(Resource* res in AppDelegate->viewData.Resources)
if(res.RE_KEY == myResourceKey)
{
[res sortBookingsByStartDate];
break;
}
[DisplayScopeLabel setText:[NSString stringWithFormat:@"%@ - %@", AppDelegate.dataScopeStart.FormatForDataScopeView(), AppDelegate.dataScopeEnd.FormatForDataScopeView()]];
[table performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
// Find the selected booking in the my bookings controller
for(Resource* res in AppDelegate->viewData.Resources)
for(Booking* b in res.bookings)
if(b.BO_KEY == AppDelegate.selected_BO_KEY)
{
BookingDetailController *cnt=AppDelegate.MyBookingsAndDrillDown.myBookingsController->bookingDetailController;
cnt.book = b;
[cnt.table performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
return;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
Date start = AppDelegate.displayStart.DaysBefore(AppDelegate.DataScopeBack);
Date end = AppDelegate.displayEnd.DaysAfter(AppDelegate.DataScopeForward);
int nDays = 0;
while(!start.IsSameDayAs(end))
{
nDays++;
start = start.DaysAfter(1);
}
return nDays;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
Date start = AppDelegate.dataScopeStart;
int nDays = 0;
while(nDays<section)
{
start = start.DaysAfter(1);
nDays++;
}
return start.FormatForMyBookings();
return @"ERROR 0x2343243";
}
-(void) RecalcBookingsPrDayTable
{
Date start = AppDelegate.dataScopeStart;
Date end = AppDelegate.dataScopeEnd;
BookingsPrDay.clear();
BookingsPrDay.resize(start.daysBetweenDate(end));
int myResourceKey = AppDelegate.loginData.Login.RE_KEY;
for(Resource* res in AppDelegate->viewData.Resources)
{
if(res.RE_KEY == myResourceKey)
{
// How many of the bookings are today?
for(Booking* b in res.bookings)
{
int DayNr = AppDelegate.dataScopeStart.daysBetweenDate(b.FROM_TIME);
BookingsPrDay[DayNr]++;
}
}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
[self RecalcBookingsPrDayTable];
if(BookingsPrDay.size() > section)
return BookingsPrDay[section];
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyBookingCell *cell = (MyBookingCell *)[table dequeueReusableCellWithIdentifier: nil]; //@"MyBookingCell"
if (cell == nil)
{
NSString *nibName;
if(AppDelegate.IsIpad)
nibName = @"MyBookingCell_ipad";
else
nibName = @"MyBookingCell_iphone";
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (MyBookingCell *)currentObject;
break;
}
}
}
int myResourceKey = AppDelegate.loginData.Login.RE_KEY;
for(Resource* res in AppDelegate->viewData.Resources)
{
if(res.RE_KEY == myResourceKey)
{
if([res.bookings count] == 0) // we have no bookings, inform about this
{
EmptyBookingCell *cell = (EmptyBookingCell *)[table dequeueReusableCellWithIdentifier:@"EmptyBookingCell"];
if (cell == nil)
{
NSString *nibName;
if(AppDelegate.IsIpad)
nibName = @"EmptyBookingCell_ipad";
else
nibName = @"EmptyBookingCell_iphone";
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (EmptyBookingCell *)currentObject;
break;
}
}
}
return cell;
}
// Find the right booking for the section
int BookingNr=0;
int d;
for(d=0;d<indexPath.section;d++)
BookingNr+= BookingsPrDay[d];
BookingNr+= indexPath.row;
Booking* b = (Booking*)[res.bookings objectAtIndex:BookingNr];
[[cell StartTime] setText:[TimeFormatter stringFromDate:b.FROM_TIME.nsdate()]];
[[cell EndTime] setText:[TimeFormatter stringFromDate:b.TO_TIME.nsdate()]];
[[cell Component] setText:[NSString stringWithFormat:@"%@ / %@", b.ACTIVITY, b.Folder_name ]];
// DLog(@" indexPath.section : %d Bookings for day %d: %d\n", indexPath.section, indexPath.section, BookingsPrDay[indexPath.section]);
CustomCellBackgroundView *bgView = [[CustomCellBackgroundView alloc] initWithFrame:CGRectZero];
[bgView setBorderColor:[UIColor blackColor]];
[bgView setFillColor:[UIColor whiteColor]];
[bgView setProgressColor:[UIColor colorWithRed:0.7 green:0.9 blue:0.7 alpha:1.0]];
[bgView setPassedBookingsColor:[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0]];
[bgView setOpenPassedBookingsColor:[UIColor colorWithRed:1 green:0.6 blue:0.6 alpha:1.0]];
[bgView setBook:b];
PCODE pc = b.pcode;
if(pc == P_FINISHED || pc == P_INVOICED || pc == P_APPROVED)
{
[cell.signedOffImage setHidden:NO];//setImage:[UIImage imageNamed:@"signedOff.png"]];
}
else
{
[cell.signedOffImage setHidden:YES];//setImage:nil];
}
if(BookingsPrDay[indexPath.section] == 1)
{
bgView.position = CustomCellBackgroundViewPositionSingle;
}
else if (indexPath.row == 0)
{
bgView.position = CustomCellBackgroundViewPositionTop;
}
else if (indexPath.row == BookingsPrDay[indexPath.section]-1)
{
bgView.position = CustomCellBackgroundViewPositionBottom;
}
else
{
bgView.position = CustomCellBackgroundViewPositionMiddle;
}
// Progress
NSDate* a = [NSDate date];
Date now(a);
float t = (now-b.FROM_TIME).nstimeInterval()/(b.TO_TIME.nstimeInterval() - b.FROM_TIME.nstimeInterval());
bgView.progress = t;
cell.backgroundView = bgView;
[[cell Client] setText:b.CL_NAME ];
/*
enum CStatus{ROS, BKS, BK, A16, A35, HL1, HL2, IO, CNI, CND, P01, NA, MET, TRA, SIP, GRATIS, INVOICED, UNKNOWN, ERROR};
enum PCODE{P_UNKNOWN, P_OPEN, P_FINISHED, P_APPROVED, P_PRECALC, P_PROFORMA, P_INVOICED, P_LOGGEDOUT, P_ERROR};
*/
NSString* status;
switch(b.STATUS)
{
case ROS: status=@"ROS"; break;
case BKS: status=@"BKS"; break;
case BK: status=@"BK"; break;
case A16: status=@"A16"; break;
case A35: status=@"A35"; break;
case HL1: status=@"HL1"; break;
case HL2: status=@"HL2"; break;
case IO: status=@"IO"; break;
case CNI: status=@"CNI"; break;
case CND: status=@"CND"; break;
case P01: status=@"P01"; break;
case NA: status=@"NA"; break;
case MET: status=@"MET"; break;
case TRA: status=@"TRA"; break;
case SIP: status=@"SIP"; break;
case GRATIS: status=@"GRATIS"; break;
case INVOICED: status=@"INVOICED"; break;
case UNKNOWN: status=@"UNKNOWN"; break;
case ERROR: status=@"ERROR"; break;
}
NSString* pcode;
switch(b.pcode)
{
case P_UNKNOWN: pcode=@"UNKNOWN"; break;
case P_OPEN: pcode=@"OPEN"; break;
case P_FINISHED: pcode=@"FINISHED"; break;
case P_APPROVED: pcode=@"APPROVED"; break;
case P_PRECALC: pcode=@"PRECALC"; break;
case P_PROFORMA: pcode=@"PROFORMA"; break;
case P_INVOICED: pcode=@"INVOICED"; break;
case P_LOGGEDOUT: pcode=@"LOGGEDOUT"; break;
case P_GRATIS: pcode=@"GRATIS"; break;
default:
case P_ERROR: pcode=@"ERROR"; break;
}
[[cell Activity] setText: [NSString stringWithFormat:@"%@ / %@ / %d / %@", status, pcode, b.BO_KEY , b.NAME]];
// [[cell DayLabel] setText:[DayNameFormatter stringFromDate:AppDelegate->viewData.Resources[i].bookings[BookingNr].FROM_TIME.nsdate()]];
// [[cell DateLabel] setText:[ShortDateTimeFormatter stringFromDate:AppDelegate->viewData.Resources[i].bookings[BookingNr].FROM_TIME.nsdate()]];
cell.STATUS = b.STATUS;
cell.book = b;
return cell;
}
}
return cell;
}
- (void) tableView: (UITableView *) tableView accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *) indexPath
{
MyBookingCell *cell = (MyBookingCell*)[tableView cellForRowAtIndexPath:indexPath];
bookingDetailController.book = cell.book;
[bookingDetailController.table reloadData];
AppDelegate.selected_BO_KEY = cell.book.BO_KEY;
[self.navigationController pushViewController:bookingDetailController animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyBookingCell *cell = (MyBookingCell*)[tableView cellForRowAtIndexPath:indexPath];
[cell setNeedsDisplay];
bookingDetailController.book = cell.book;
[bookingDetailController.table reloadData];
AppDelegate.selected_BO_KEY = cell.book.BO_KEY;
[self.navigationController pushViewController:bookingDetailController animated:YES];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyBookingCell *cell = (MyBookingCell*)[tableView cellForRowAtIndexPath:indexPath];
[cell setNeedsDisplay];
}
-(void) ShowPreferences
{
[self.navigationController pushViewController:preferencesController animated:YES];
}
-(void) ShowAbout
{
// [self.navigationController pushViewController:aboutController animated:YES];
[UIView beginAnimations:@"animation" context:nil];
[self.navigationController pushViewController:aboutController animated:NO];
[UIView setAnimationDuration:2];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
}
@end