-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaff-script.js
More file actions
2791 lines (2448 loc) · 129 KB
/
staff-script.js
File metadata and controls
2791 lines (2448 loc) · 129 KB
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Staff Booking System JavaScript
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('staff-booking-form');
const departDateInput = document.getElementById('staff-depart-date');
const returnDateInput = document.getElementById('staff-return-date');
// Set minimum date to today and auto-populate departure date
const today = new Date().toISOString().split('T')[0];
departDateInput.setAttribute('min', today);
returnDateInput.setAttribute('min', today);
departDateInput.value = today;
// Initialize staff form interactions
setupStaffFormInteractions();
setupStaffCustomerLookup();
setupStaffKeyboardShortcuts();
// Initialize custom time pickers directly
setTimeout(() => {
console.log('Initializing custom time pickers for staff page...');
initializeStaffTimePickers();
initializeLocationAutocomplete();
}, 100);
function setupStaffFormInteractions() {
// Trip type change handler
const tripTypeSelect = document.getElementById('staff-trip-type');
const returnRow = document.getElementById('staff-return-row');
const returnDateInput = document.getElementById('staff-return-date');
const returnTimeInput = document.querySelector('[data-name="returnTime"] .time-value');
tripTypeSelect.addEventListener('change', function() {
const multiTransferSection = document.getElementById('staff-multi-transfer-section');
if (this.value === 'return') {
returnRow.style.display = 'grid';
returnDateInput.setAttribute('required', 'required');
// For custom time picker, set required on the display input
const returnTimeDisplay = document.querySelector('[data-name="returnTime"] .time-display');
if (returnTimeDisplay) {
returnTimeDisplay.setAttribute('required', 'required');
}
multiTransferSection.style.display = 'none';
// Show the original pickup/dropoff/date/time rows for return trip
const originalLocationRow = document.querySelector('.form-row-staff:has(#staff-pickup)');
const originalDateTimeRow = document.querySelector('.form-row-staff:has(#staff-depart-date)');
if (originalLocationRow) originalLocationRow.style.display = 'grid';
if (originalDateTimeRow) originalDateTimeRow.style.display = 'grid';
} else if (this.value === 'multi-transfer') {
returnRow.style.display = 'none';
returnDateInput.removeAttribute('required');
// Clear return time inputs
const returnTimeDisplay = document.querySelector('[data-name="returnTime"] .time-display');
const returnTimeValue = document.querySelector('[data-name="returnTime"] .time-value');
if (returnTimeDisplay) {
returnTimeDisplay.removeAttribute('required');
returnTimeDisplay.value = '';
}
if (returnTimeValue) {
returnTimeValue.value = '';
}
returnDateInput.value = '';
// Hide the original pickup/dropoff/date/time row for multi-transfer
const originalLocationRow = document.querySelector('.form-row-staff:has(#staff-pickup)');
const originalDateTimeRow = document.querySelector('.form-row-staff:has(#staff-depart-date)');
if (originalLocationRow) originalLocationRow.style.display = 'none';
if (originalDateTimeRow) originalDateTimeRow.style.display = 'none';
multiTransferSection.style.display = 'block';
// Initialize with 2 transfers if none exist
if (document.querySelectorAll('.transfer-leg').length === 0) {
addTransferLeg();
addTransferLeg();
}
} else {
returnRow.style.display = 'none';
returnDateInput.removeAttribute('required');
// For custom time picker, remove required from display input and clear values
const returnTimeDisplay = document.querySelector('[data-name="returnTime"] .time-display');
const returnTimeValue = document.querySelector('[data-name="returnTime"] .time-value');
if (returnTimeDisplay) {
returnTimeDisplay.removeAttribute('required');
returnTimeDisplay.value = '';
}
if (returnTimeValue) {
returnTimeValue.value = '';
}
returnDateInput.value = '';
multiTransferSection.style.display = 'none';
// Show the original pickup/dropoff/date/time rows for one-way
const originalLocationRow = document.querySelector('.form-row-staff:has(#staff-pickup)');
const originalDateTimeRow = document.querySelector('.form-row-staff:has(#staff-depart-date)');
if (originalLocationRow) originalLocationRow.style.display = 'grid';
if (originalDateTimeRow) originalDateTimeRow.style.display = 'grid';
}
calculatePrice();
});
// Customer type change handler
const customerTypeSelect = document.getElementById('staff-customer-type');
const agentRow = document.getElementById('staff-agent-row');
customerTypeSelect.addEventListener('change', function() {
if (this.value === 'agent') {
agentRow.style.display = 'grid';
} else {
agentRow.style.display = 'none';
}
calculatePrice();
updateAllTransferPricing();
});
// Passenger count change handler
const passengersSelect = document.getElementById('staff-passengers');
const travellersGroup = document.getElementById('staff-travellers-group');
passengersSelect.addEventListener('change', function() {
const passengerCount = parseInt(this.value);
if (passengerCount > 2) {
travellersGroup.style.display = 'block';
} else {
travellersGroup.style.display = 'none';
document.getElementById('staff-travellers').value = '';
}
calculatePrice();
updateAllTransferPricing();
});
// Departure date change handler
const departDateInput = document.getElementById('staff-depart-date');
departDateInput.addEventListener('change', function() {
const departDate = this.value;
returnDateInput.setAttribute('min', departDate);
if (returnDateInput.value && returnDateInput.value < departDate) {
returnDateInput.value = '';
}
calculatePrice();
});
// Location and service type change handlers for price calculation
const pickupSelect = document.getElementById('staff-pickup');
const dropoffSelect = document.getElementById('staff-dropoff');
const serviceTypeSelect = document.getElementById('staff-service-type');
pickupSelect.addEventListener('change', function() {
console.log('Pickup changed to:', this.value);
updateAddressFields();
calculatePrice();
});
dropoffSelect.addEventListener('change', function() {
console.log('Dropoff changed to:', this.value);
updateAddressFields();
calculatePrice();
});
serviceTypeSelect.addEventListener('change', function() {
console.log('Service type changed to:', this.value);
calculatePrice();
updateAllTransferPricing();
});
// Accommodation dropdown change handlers
const pickupAccommodationSelect = document.getElementById('staff-pickup-accommodation');
const dropoffAccommodationSelect = document.getElementById('staff-dropoff-accommodation');
if (pickupAccommodationSelect) {
pickupAccommodationSelect.addEventListener('change', function() {
handleAccommodationChange('pickup');
});
}
if (dropoffAccommodationSelect) {
dropoffAccommodationSelect.addEventListener('change', function() {
handleAccommodationChange('dropoff');
});
}
// Clear form button
document.getElementById('clear-form-btn').addEventListener('click', clearForm);
// Save draft button
document.getElementById('save-draft-btn').addEventListener('click', saveDraft);
// Multi-transfer functionality
const addLegBtn = document.getElementById('add-transfer-leg');
if (addLegBtn) {
addLegBtn.addEventListener('click', addTransferLeg);
}
}
function setupStaffCustomerLookup() {
const phoneInput = document.getElementById('staff-phone');
const customerSuggestions = document.getElementById('staff-customer-suggestions');
const firstNameInput = document.getElementById('staff-first-name');
const lastNameInput = document.getElementById('staff-last-name');
const emailInput = document.getElementById('staff-email');
const titleSelect = document.getElementById('staff-title');
const customerTypeSelect = document.getElementById('staff-customer-type');
console.log('Setting up customer lookup...');
console.log('Phone input element:', phoneInput);
console.log('Customer suggestions element:', customerSuggestions);
if (!phoneInput || !customerSuggestions) {
console.error('Required customer lookup elements not found:', {
phoneInput: !!phoneInput,
customerSuggestions: !!customerSuggestions
});
return;
}
let lookupTimeout;
// Mock customer database (same as public form)
const mockCustomers = [
{
phone: '0400123456',
title: 'mr',
firstName: 'John',
lastName: 'Smith',
email: 'john.smith@email.com',
customerType: 'personal'
},
{
phone: '0412345678',
title: 'mrs',
firstName: 'Sarah',
lastName: 'Jones',
email: 'sarah.jones@email.com',
customerType: 'corporate'
},
{
phone: '0401234567',
title: 'dr',
firstName: 'John',
lastName: 'Wilson',
email: 'john.wilson@email.com',
customerType: 'personal'
},
{
phone: '0412356789',
title: 'ms',
firstName: 'Sarah',
lastName: 'Brown',
email: 'sarah.brown@email.com',
customerType: 'agent'
}
];
phoneInput.addEventListener('input', function() {
const phone = this.value.trim();
clearTimeout(lookupTimeout);
customerSuggestions.style.display = 'none';
console.log('Phone input event triggered! Value:', phone, 'Length:', phone.replace(/\D/g, '').length);
if (phone.replace(/\D/g, '').length >= 3) {
lookupTimeout = setTimeout(() => {
console.log('Searching customers for:', phone);
searchCustomers(phone);
}, 200); // Faster for staff
}
});
console.log('Phone input event listener added successfully!');
phoneInput.addEventListener('blur', function() {
setTimeout(() => {
customerSuggestions.style.display = 'none';
}, 200);
});
phoneInput.addEventListener('focus', function() {
const phone = this.value.trim();
if (phone.replace(/\D/g, '').length >= 3) {
searchCustomers(phone);
}
});
function searchCustomers(phone) {
const normalizedInput = phone.replace(/\D/g, '');
const matches = mockCustomers.filter(customer => {
const customerPhone = customer.phone.replace(/\D/g, '');
return customerPhone.includes(normalizedInput);
});
if (matches.length > 0) {
showCustomerSuggestions(matches);
} else {
customerSuggestions.style.display = 'none';
}
}
function showCustomerSuggestions(customers) {
customerSuggestions.innerHTML = '';
customers.forEach(customer => {
const suggestionDiv = document.createElement('div');
suggestionDiv.className = 'customer-suggestion';
suggestionDiv.innerHTML = `
<div class="customer-name">${customer.title ? customer.title.charAt(0).toUpperCase() + customer.title.slice(1) + ' ' : ''}${customer.firstName} ${customer.lastName}</div>
<div class="customer-details">${customer.email}</div>
<div class="customer-phone">${customer.phone}</div>
`;
suggestionDiv.addEventListener('click', () => {
selectCustomer(customer);
});
customerSuggestions.appendChild(suggestionDiv);
});
customerSuggestions.style.display = 'block';
}
function selectCustomer(customer) {
phoneInput.value = customer.phone;
titleSelect.value = customer.title;
firstNameInput.value = customer.firstName;
lastNameInput.value = customer.lastName;
emailInput.value = customer.email;
customerTypeSelect.value = customer.customerType;
customerSuggestions.style.display = 'none';
// Trigger agent section if customer is agent
if (customer.customerType === 'agent') {
document.getElementById('staff-agent-row').style.display = 'grid';
}
// Auto-focus next field
document.getElementById('staff-trip-type').focus();
calculatePrice();
}
}
function setupStaffKeyboardShortcuts() {
document.addEventListener('keydown', function(e) {
// Ctrl+N for new booking
if (e.ctrlKey && e.key === 'n') {
e.preventDefault();
clearForm();
document.getElementById('staff-phone').focus();
}
// Ctrl+S for save draft
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
saveDraft();
}
// Ctrl+Enter for submit
if (e.ctrlKey && e.key === 'Enter') {
e.preventDefault();
form.dispatchEvent(new Event('submit'));
}
// Escape to clear form
if (e.key === 'Escape') {
clearForm();
}
});
}
async function calculatePrice() {
console.log('calculatePrice() function called');
const tripType = document.getElementById('staff-trip-type').value;
const pickup = document.getElementById('staff-pickup').value;
const dropoff = document.getElementById('staff-dropoff').value;
const passengers = parseInt(document.getElementById('staff-passengers').value);
const customerType = document.getElementById('staff-customer-type').value;
const serviceType = document.getElementById('staff-service-type').value;
console.log('Form values:', { tripType, pickup, dropoff, passengers, customerType, serviceType });
if (!pickup || !dropoff || !passengers || !serviceType) {
console.log('Missing required fields for pricing');
document.getElementById('staff-price-display').textContent = 'Select details';
return;
}
try {
const price = await calculatePriceForRoute(pickup, dropoff, passengers, serviceType, customerType, tripType);
if (price > 0) {
document.getElementById('staff-price-display').textContent = `$${price.toFixed(2)}`;
} else {
document.getElementById('staff-price-display').textContent = 'Route not available';
}
} catch (error) {
console.error('Pricing calculation error:', error);
document.getElementById('staff-price-display').textContent = 'Pricing error';
}
return; // Exit early - new pricing logic handles everything
// This will be determined below based on route type
// Rate sheet data (2025-2026 rates)
const airportRates = {
'kingscote-town': { // Kingscote
1: { shared: 45.00, nett: 36.00, private: 72.00 },
2: { shared: 90.00, nett: 72.00, private: 144.00 },
3: { shared: 110.00, nett: 88.00, private: 176.00 },
4: { shared: 130.00, nett: 104.00, private: 208.00 },
5: { shared: 150.00, nett: 120.00, private: 240.00 },
6: { shared: 170.00, nett: 136.00, private: 272.00 }
},
'american-river': {
2: { shared: 105.00, nett: 84.00, private: 126.00 },
3: { shared: 125.00, nett: 100.00, private: 150.00 },
4: { shared: 145.00, nett: 116.00, private: 174.00 },
5: { shared: 165.00, nett: 132.00, private: 198.00 },
6: { shared: 185.00, nett: 148.00, private: 222.00 }
},
'penneshaw-ferry': { // Penneshaw
2: { shared: 182.00, nett: 145.60, private: 218.40 },
3: { shared: 202.00, nett: 161.60, private: 242.40 },
4: { shared: 222.00, nett: 177.60, private: 266.40 },
5: { shared: 242.00, nett: 193.60, private: 290.40 },
6: { shared: 262.00, nett: 209.60, private: 314.40 }
},
'vivonne-bay': {
2: { shared: 168.00, nett: 134.40, private: 201.60 },
3: { shared: 188.00, nett: 150.40, private: 225.60 },
4: { shared: 208.00, nett: 166.40, private: 249.60 },
5: { shared: 228.00, nett: 182.40, private: 273.60 },
6: { shared: 248.00, nett: 198.40, private: 297.60 }
},
'flinders-chase': { // Represents Southern Ocean Lodge area
2: { shared: 315.00, nett: 252.00, private: 378.00 },
3: { shared: 335.00, nett: 268.00, private: 402.00 },
4: { shared: 355.00, nett: 284.00, private: 426.00 },
5: { shared: 375.00, nett: 300.00, private: 450.00 },
6: { shared: 395.00, nett: 316.00, private: 474.00 }
},
'flinders-chase-visitor-centre': {
2: { shared: 300.00, nett: 240.00, private: 360.00 },
3: { shared: 320.00, nett: 256.00, private: 384.00 },
4: { shared: 340.00, nett: 272.00, private: 408.00 },
5: { shared: 360.00, nett: 288.00, private: 432.00 },
6: { shared: 380.00, nett: 304.00, private: 456.00 }
},
'emu-bay': {
2: { shared: 94.50, nett: 75.60, private: 113.40 },
3: { shared: 114.50, nett: 91.60, private: 137.40 },
4: { shared: 134.50, nett: 107.60, private: 161.40 },
5: { shared: 154.50, nett: 123.60, private: 185.40 },
6: { shared: 174.50, nett: 139.60, private: 209.40 }
},
'parndana': {
2: { shared: 133.00, nett: 106.40, private: 159.60 },
3: { shared: 153.00, nett: 122.40, private: 183.60 },
4: { shared: 173.00, nett: 138.40, private: 207.60 },
5: { shared: 193.00, nett: 154.40, private: 231.60 },
6: { shared: 213.00, nett: 170.40, private: 255.60 }
}
};
// Kingscote to other destinations rates
const kingscoteRates = {
'kingscote-airport': { // Kingscote to Airport
1: { shared: 36.00, nett: 28.80, private: 57.60 },
2: { shared: 72.00, nett: 57.60, private: 115.20 },
3: { shared: 92.00, nett: 73.60, private: 147.20 },
4: { shared: 112.00, nett: 89.60, private: 179.20 },
5: { shared: 132.00, nett: 105.60, private: 211.20 },
6: { shared: 152.00, nett: 121.60, private: 243.20 }
},
'american-river': {
2: { shared: 138.60, nett: 110.88, private: 166.32 },
3: { shared: 158.60, nett: 126.88, private: 190.32 },
4: { shared: 178.60, nett: 142.88, private: 214.32 },
5: { shared: 198.60, nett: 158.88, private: 238.32 },
6: { shared: 218.60, nett: 174.88, private: 262.32 }
},
'penneshaw-ferry': {
2: { shared: 198.00, nett: 158.40, private: 237.60 },
3: { shared: 218.00, nett: 174.40, private: 261.60 },
4: { shared: 238.00, nett: 190.40, private: 285.60 },
5: { shared: 258.00, nett: 206.40, private: 309.60 },
6: { shared: 278.00, nett: 222.40, private: 333.60 }
},
'vivonne-bay': {
2: { shared: 198.00, nett: 158.40, private: 237.60 },
3: { shared: 218.00, nett: 174.40, private: 261.60 },
4: { shared: 238.00, nett: 190.40, private: 285.60 },
5: { shared: 258.00, nett: 206.40, private: 309.60 },
6: { shared: 278.00, nett: 222.40, private: 333.60 }
},
'flinders-chase': { // Southern Ocean Lodge area
2: { shared: 326.70, nett: 261.36, private: 392.04 },
3: { shared: 346.70, nett: 277.36, private: 416.04 },
4: { shared: 366.70, nett: 293.36, private: 440.04 },
5: { shared: 386.70, nett: 309.36, private: 464.04 },
6: { shared: 406.70, nett: 325.36, private: 488.04 }
},
'emu-bay': {
2: { shared: 89.10, nett: 71.28, private: 106.92 },
3: { shared: 109.10, nett: 87.28, private: 130.92 },
4: { shared: 129.10, nett: 103.28, private: 154.92 },
5: { shared: 149.10, nett: 119.28, private: 178.92 },
6: { shared: 169.10, nett: 135.28, private: 202.92 }
},
'parndana': {
2: { shared: 151.80, nett: 121.44, private: 182.16 },
3: { shared: 171.80, nett: 137.44, private: 206.16 },
4: { shared: 191.80, nett: 153.44, private: 230.16 },
5: { shared: 211.80, nett: 169.44, private: 254.16 },
6: { shared: 231.80, nett: 185.44, private: 278.16 }
}
};
// Penneshaw to other destinations rates
const penneshawRates = {
'kingscote-town': {
2: { shared: 198.00, nett: 158.40, private: 237.60 },
3: { shared: 218.00, nett: 174.40, private: 261.60 },
4: { shared: 238.00, nett: 190.40, private: 285.60 },
5: { shared: 258.00, nett: 206.40, private: 309.60 },
6: { shared: 278.00, nett: 222.40, private: 333.60 }
},
'american-river': {
2: { shared: 132.00, nett: 105.60, private: 158.40 },
3: { shared: 152.00, nett: 121.60, private: 182.40 },
4: { shared: 172.00, nett: 137.60, private: 206.40 },
5: { shared: 192.00, nett: 153.60, private: 230.40 },
6: { shared: 212.00, nett: 169.60, private: 254.40 }
},
'parndana': {
2: { shared: 257.40, nett: 205.92, private: 308.88 },
3: { shared: 277.40, nett: 221.92, private: 332.88 },
4: { shared: 297.40, nett: 237.92, private: 356.88 },
5: { shared: 317.40, nett: 253.92, private: 380.88 },
6: { shared: 337.40, nett: 269.92, private: 404.88 }
},
'vivonne-bay': {
2: { shared: 297.00, nett: 237.60, private: 356.40 },
3: { shared: 317.00, nett: 253.60, private: 380.40 },
4: { shared: 337.00, nett: 269.60, private: 404.40 },
5: { shared: 357.00, nett: 285.60, private: 428.40 },
6: { shared: 377.00, nett: 301.60, private: 452.40 }
},
'emu-bay': {
2: { shared: 227.70, nett: 182.16, private: 273.24 },
3: { shared: 247.70, nett: 198.16, private: 297.24 },
4: { shared: 267.70, nett: 214.16, private: 321.24 },
5: { shared: 287.70, nett: 230.16, private: 345.24 },
6: { shared: 307.70, nett: 246.16, private: 369.24 }
},
'kingscote-airport': {
2: { shared: 171.60, nett: 137.28, private: 205.92 },
3: { shared: 191.60, nett: 153.28, private: 229.92 },
4: { shared: 211.60, nett: 169.28, private: 253.92 },
5: { shared: 231.60, nett: 185.28, private: 277.92 },
6: { shared: 251.60, nett: 201.28, private: 301.92 }
},
'flinders-chase': { // Southern Ocean Lodge
2: { shared: 336.60, nett: 269.28, private: 403.92 },
3: { shared: 356.60, nett: 285.28, private: 427.92 },
4: { shared: 376.60, nett: 301.28, private: 451.92 },
5: { shared: 396.60, nett: 317.28, private: 475.92 },
6: { shared: 416.60, nett: 333.28, private: 499.92 }
}
};
// Determine which rate sheet to use and get destination
let rateSheet, destination;
if (pickup === 'kingscote-airport') {
rateSheet = airportRates;
destination = dropoff;
} else if (dropoff === 'kingscote-airport') {
rateSheet = airportRates;
destination = pickup;
} else if (pickup === 'kingscote-town') {
rateSheet = kingscoteRates;
destination = dropoff;
} else if (dropoff === 'kingscote-town') {
rateSheet = kingscoteRates;
destination = pickup;
} else if (pickup === 'penneshaw-ferry') {
rateSheet = penneshawRates;
destination = dropoff;
} else if (dropoff === 'penneshaw-ferry') {
rateSheet = penneshawRates;
destination = pickup;
} else {
document.getElementById('staff-price-display').textContent = 'Route not available';
return;
}
// Validate single passenger booking - only allowed for Airport ↔ Kingscote
if (passengers === 1 && !(
(pickup === 'kingscote-airport' && dropoff === 'kingscote-town') ||
(pickup === 'kingscote-town' && dropoff === 'kingscote-airport')
)) {
document.getElementById('staff-price-display').textContent = 'Min 2 PAX for this route';
return;
}
// Get passenger group (6+ uses 6 rate)
let paxGroup = passengers;
if (passengers > 6) paxGroup = 6; // 6+ uses 6 passenger rate
// Get rate for destination and passenger count
const destinationRates = rateSheet[destination];
if (!destinationRates) {
document.getElementById('staff-price-display').textContent = 'Destination not found';
return;
}
const rates = destinationRates[paxGroup];
if (!rates) {
document.getElementById('staff-price-display').textContent = 'Rate not available';
return;
}
let price = 0;
// Apply pricing based on customer type and service type
if (customerType === 'personal') {
// Personal customers get shared RRP or private RRP
price = serviceType === 'shared' ? rates.shared : rates.private;
} else if (customerType === 'agent') {
// Agents get nett price (shared nett or private calculated from nett)
if (serviceType === 'shared') {
price = rates.nett;
} else {
// Private nett = shared nett * (private RRP / shared RRP)
price = rates.nett * (rates.private / rates.shared);
}
} else if (customerType === 'corporate') {
// Corporate gets special structure - using nett rates for now
price = serviceType === 'shared' ? rates.nett : rates.nett * (rates.private / rates.shared);
}
// Apply return trip pricing - no discount, just double the one-way price
if (tripType === 'return') {
price *= 2.0; // Full double price for return
}
const formattedPrice = `$${price.toFixed(2)}`;
const priceElement = document.getElementById('staff-price-display');
console.log('Setting price to:', formattedPrice, 'Price element:', priceElement);
if (priceElement) {
priceElement.textContent = formattedPrice;
} else {
console.error('Price display element not found!');
}
}
function clearForm() {
form.reset();
// Reset to defaults
document.getElementById('staff-trip-type').value = 'one-way';
document.getElementById('staff-customer-type').value = 'personal';
document.getElementById('staff-passengers').value = '1';
document.getElementById('staff-service-type').value = 'shared';
departDateInput.value = today;
// Hide conditional sections
document.getElementById('staff-return-row').style.display = 'none';
document.getElementById('staff-agent-row').style.display = 'none';
document.getElementById('staff-travellers-group').style.display = 'none';
// Reset price display
document.getElementById('staff-price-display').textContent = 'Calculating...';
// Focus phone field
document.getElementById('staff-phone').focus();
}
function saveDraft() {
const formData = new FormData(form);
const draftData = Object.fromEntries(formData.entries());
// Save to localStorage (in Phase 2, this would save to database)
localStorage.setItem('staff-booking-draft', JSON.stringify(draftData));
showMessage('Draft saved successfully! ✅', 'success');
}
function showMessage(message, type) {
const existingMessage = document.querySelector('.success-message, .error-message');
if (existingMessage) {
existingMessage.remove();
}
const messageDiv = document.createElement('div');
messageDiv.className = type === 'success' ? 'success-message' : 'error-message';
messageDiv.textContent = message;
form.insertBefore(messageDiv, form.firstChild);
setTimeout(() => {
messageDiv.remove();
}, 3000);
}
// Form submission
form.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(form);
const booking = {
// Customer Information
customerType: formData.get('customerType'),
title: formData.get('title') || '',
firstName: formData.get('firstName'),
lastName: formData.get('lastName'),
email: formData.get('email') || '',
phone: formData.get('phone-lookup-field'),
// Trip Details
tripType: formData.get('tripType'),
serviceType: formData.get('serviceType'),
pickupLocation: formData.get('pickupLocation'),
dropoffLocation: formData.get('dropoffLocation'),
departDate: formData.get('departDate'),
departTime: formData.get('departTime'),
returnDate: formData.get('returnDate') || '',
returnTime: formData.get('returnTime') || '',
passengers: formData.get('passengers'),
travellerNames: formData.get('travellerNames') || '',
// Agent Information
agent: formData.get('agent') || '',
agentReference: formData.get('agentReference') || '',
// Additional Information
specialRequirements: formData.get('specialRequirements') || ''
};
if (validateStaffForm(booking)) {
submitStaffBooking(booking);
}
});
function validateStaffForm(booking) {
const errors = [];
// Check required fields
if (!booking.firstName.trim()) errors.push('First name is required');
if (!booking.lastName.trim()) errors.push('Last name is required');
if (!booking.phone.trim()) errors.push('Phone number is required');
if (!booking.tripType) errors.push('Trip type is required');
if (!booking.pickupLocation) errors.push('Pickup location is required');
if (!booking.dropoffLocation) errors.push('Drop-off location is required');
if (!booking.departDate) errors.push('Departure date is required');
if (!booking.departTime) errors.push('Departure time is required');
if (!booking.passengers) errors.push('Number of passengers is required');
// Check return trip requirements
if (booking.tripType === 'return') {
if (!booking.returnDate) errors.push('Return date is required');
if (!booking.returnTime) errors.push('Return time is required');
}
if (errors.length > 0) {
showMessage(`Errors: ${errors.join(', ')}`, 'error');
return false;
}
return true;
}
function submitStaffBooking(booking) {
// Show loading state
const submitBtn = document.getElementById('create-booking-btn');
const originalText = submitBtn.textContent;
submitBtn.innerHTML = '<span class="spinner"></span> Creating...';
submitBtn.disabled = true;
// Simulate API call
setTimeout(() => {
const pnr = generatePNR();
// Calculate final price
const price = calculateFinalPrice(booking);
// Create booking object for management system
const managementBooking = {
pnr: pnr,
customerType: booking.customerType,
title: booking.title,
firstName: booking.firstName,
lastName: booking.lastName,
email: booking.email,
phone: booking.phone,
tripType: booking.tripType,
serviceType: booking.serviceType,
pickupLocation: booking.pickupLocation,
dropoffLocation: booking.dropoffLocation,
departDate: booking.departDate,
departTime: booking.departTime,
returnDate: booking.returnDate,
returnTime: booking.returnTime,
passengers: parseInt(booking.passengers),
travellerNames: booking.travellerNames,
agent: booking.agent,
agentReference: booking.agentReference,
specialRequirements: booking.specialRequirements,
price: price,
status: 'pending',
driver: null,
vehicle: null,
created: new Date().toISOString()
};
// Save to management system
saveToManagementSystem(managementBooking);
showMessage(`✅ Booking ${pnr} created successfully!`, 'success');
// Reset form
clearForm();
// Add to recent bookings (mock)
addToRecentBookings(booking, pnr);
// Reset button
submitBtn.textContent = originalText;
submitBtn.disabled = false;
// Clear any saved draft
localStorage.removeItem('staff-booking-draft');
console.log('Staff booking submitted:', managementBooking);
}, 1000);
}
function calculateFinalPrice(booking) {
// Use the same calculation logic as the price display
const tripType = booking.tripType;
const pickup = booking.pickupLocation;
const dropoff = booking.dropoffLocation;
const passengers = parseInt(booking.passengers);
const customerType = booking.customerType;
const serviceType = booking.serviceType;
// Determine which rate sheet to use and get destination
let rateSheet, destination;
if (pickup === 'kingscote-airport') {
rateSheet = airportRates;
destination = dropoff;
} else if (dropoff === 'kingscote-airport') {
rateSheet = airportRates;
destination = pickup;
} else if (pickup === 'kingscote-town') {
rateSheet = kingscoteRates;
destination = dropoff;
} else if (dropoff === 'kingscote-town') {
rateSheet = kingscoteRates;
destination = pickup;
} else if (pickup === 'penneshaw-ferry') {
rateSheet = penneshawRates;
destination = dropoff;
} else if (dropoff === 'penneshaw-ferry') {
rateSheet = penneshawRates;
destination = pickup;
} else {
return 0; // Route not available
}
// Get passenger group
let paxGroup = passengers;
if (passengers > 6) paxGroup = 6;
// Get rate for destination and passenger count
const destinationRates = rateSheet[destination];
if (!destinationRates) return 0;
const rates = destinationRates[paxGroup];
if (!rates) return 0;
let price = 0;
// Apply pricing based on customer type and service type
if (customerType === 'personal') {
price = serviceType === 'shared' ? rates.shared : rates.private;
} else if (customerType === 'agent') {
if (serviceType === 'shared') {
price = rates.nett;
} else {
price = rates.nett * (rates.private / rates.shared);
}
} else if (customerType === 'corporate') {
price = serviceType === 'shared' ? rates.nett : rates.nett * (rates.private / rates.shared);
}
// Apply return trip pricing
if (tripType === 'return') {
price *= 2.0;
}
return price;
}
function saveToManagementSystem(booking) {
// Get existing bookings from management system
const existingBookings = JSON.parse(localStorage.getItem('kit-bookings') || '[]');
// Add new booking
existingBookings.push(booking);
// Save back to management system
localStorage.setItem('kit-bookings', JSON.stringify(existingBookings));
}
function addToRecentBookings(booking, pnr) {
const recentBookings = document.getElementById('recent-bookings');
const newBooking = document.createElement('div');
newBooking.className = 'booking-item';
const pickupName = getLocationName(booking.pickupLocation);
const dropoffName = getLocationName(booking.dropoffLocation);
const customerName = `${booking.firstName} ${booking.lastName}`;
const bookingTime = formatTime(booking.departTime);
newBooking.innerHTML = `
<div class="booking-pnr">${pnr}</div>
<div class="booking-customer">${customerName}</div>
<div class="booking-route">${pickupName} → ${dropoffName}</div>
<div class="booking-date">Today ${bookingTime}</div>
<div class="booking-status status-confirmed">Confirmed</div>
`;
recentBookings.insertBefore(newBooking, recentBookings.firstChild);
// Remove last item if more than 5
if (recentBookings.children.length > 5) {
recentBookings.removeChild(recentBookings.lastChild);
}
}
function generatePNR() {
const prefix = 'KIT';
const number = Math.floor(Math.random() * 9000) + 1000;
return prefix + number;
}
function getLocationName(locationValue) {
const locationMap = {
'kingscote-airport': 'Airport',
'penneshaw-ferry': 'Ferry',
'kingscote-town': 'Town',
'american-river': 'American River',
'emu-bay': 'Emu Bay',
'parndana': 'Parndana',
'vivonne-bay': 'Vivonne Bay',
'flinders-chase': 'Flinders Chase',
'remarkable-rocks': 'Remarkable Rocks',
'admirals-arch': 'Admirals Arch',
'other': 'Other'
};
return locationMap[locationValue] || locationValue;
}
function formatTime(timeString) {
const [hours, minutes] = timeString.split(':');
const date = new Date();
date.setHours(parseInt(hours), parseInt(minutes));
return date.toLocaleTimeString('en-AU', {
hour: 'numeric',
minute: '2-digit',
hour12: true
});
}
// Load saved draft on page load
const savedDraft = localStorage.getItem('staff-booking-draft');
if (savedDraft) {
const draftData = JSON.parse(savedDraft);
Object.keys(draftData).forEach(key => {
const field = form.querySelector(`[name="${key}"]`);
if (field) {
field.value = draftData[key];
}
});
showMessage('Draft booking loaded ✨', 'success');
calculatePrice();
}
// Initialize custom time pickers specifically for staff page
function initializeStaffTimePickers() {
console.log('Setting up time pickers...');
// Remove any existing global click listeners to prevent duplicates
document.removeEventListener('click', globalTimePickerHandler);
const timePickers = document.querySelectorAll('.custom-time-picker');
console.log('Found time pickers:', timePickers.length);
timePickers.forEach(picker => {