Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoexp.pls
More file actions
941 lines (926 loc) · 28.8 KB
/
autoexp.pls
File metadata and controls
941 lines (926 loc) · 28.8 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
.
. Simple Auto Expense tracking
. By Matthew Lake
. Feb 2006
.
. Illustrates
. FINDFILE to not rely on traps
. MDICLIENT and MDICHILD windows
. IMPLODE / EXPLODE to get/set data in objects.
. ListView object...variouse methods.
.
. Optimization technique...
. Multple routines have logic in common...
. For example AutoFirst/Next
. AutoFirst doesn't return and allows AutoNext to complete the processing
.
.
SEQ FORM "-1"
EOF FORM "-3"
RSEQ FORM "-4"
ZERO FORM "0"
$Change EQU 3
FM10 FORM 10
FM10a FORM 10
FM2 FORM 2
New FORM 1
Update FORM 1
fm4p3 FORM 4.3
fm4p3a FORM 4.3
fm6p1 FORM 6.1
fm6p1a FORM 6.1
$ff INIT 0xff
.
DIM8 DIM 9(7)
DIM9 DIM 9
rcrdbuff DIM 200
YN DIM 3(0..1),(" "),("Yes")
ExpKey DIM 23
ExpKey2 DIM 106
DateR RECORD
YY FORM 4
MM FORM 2
DD FORM 2
RECORDEND
DateR2 RECORD LIKE DateR
Auto FILE fixed=106
AutoR RECORD ;106 bytes
Year DIM 4 ;1-4
Make DIM 20 ;5-24
Model DIM 20 ;25-44
Colr DIM 10 ;45-54
VIN DIM 20 ;55-74
PurDate DIM 8 ;75-82
SelDate DIM 8 ;83-90
PurOd FORM 6.1 ;91-98
SelOd FORM 6.1 ;99-106
.PurPrice form 6.2 ;107-115 todo
.TotalExpenses form 6.2 ;116-124 todo
RECORDEND
Expense AFILE
ExpR RECORD ;156 bytes
ID DIM 20 ; Auto.vin ;1-20
Date DIM 8 ;21-28
Od FORM 6.1 ;29-36
FuelGal FORM 4.3 ;37-44
Price FORM 6.2 ;45-53
Tires FORM 2 ; # of New tires ;54-55
TRota FORM 1 ; rotation ;55
Oil FORM 1 ; oil change ;56
Brakes FORM 1 ; new brakes ;57
Misc DIM 100 ; notes ;58-157
RECORDEND
SMaint IFILE
SchedMaint RECORD
ID DIM 20 ; Auto.vin ;1-20
MType FORM 1 ; 0=miles 1=date ;21
FMl FORM 6.1 ; how often ( Miles ) ;22-29
FDt FORM 2 ; how Often ( Months ) ;30-31
TRota FORM 1 ; rotation ;32
Oil FORM 1 ; oil change ;33
Brakes FORM 1 ; new brakes ;34
Misc DIM 100 ; description of Other maintenance to do ;35-134
RECORDEND
mwin PLFORM automain.plf
AutoDescF PLFORM autodesc.plf
AutoExpL PLFORM autoexpL.plf
AutoExpD PLFORM autoexpD.plf
AutoMnt PLFORM automnt.plf
usrflds COLLECTION
.
WINHIDE
.
. Start of program. Make sure our data files exist and if not, create them
.
. Vehicle descriptions is a sequential flie.
.
FINDFILE "Autodefs.txt"
IF NOT EQUAL
PREP Auto,"Autodefs"
ELSE
OPEN Auto,"Autodefs"
ENDIF
.
. Auto Expense log is an aam file
.
FINDFILE "AutoExp.txt"
IF NOT EQUAL
PREP Expense,"AutoExp","AutoExp","U,1-20,56-157","157"
ELSE
OPEN Expense,"AutoExp"
ENDIF
.
. Scheduled maintenance is isi file.
.
FINDFILE "AutoSMnt.txt"
IF NOT EQUAL
PREP SMaint,"AutoSMnt","AutoSMnt","1-20","134"
ELSE
OPEN SMaint,"AutoSMnt"
ENDIF
.
. When program first begins, check to see if any vehicles need scheduled
. maintenance.
.
CALL ChkSMaint ; check for scheduled Maintenance Due
.
. load the main MDIClient window.
.
FORMLOAD mwin
.
. Wait for user actions.
.
LOOP
EVENTWAIT
REPEAT
*************************************************************************
. Vehicle description display and edit routines.
.
.************************************************************************
ShowDesc
.
. Load the vehicle description MDIChild window into the main window
.
FORMLOAD AutoDescF,AutoMWin
.
. Setup a collection of user editable fields
.
LISTINS usrflds,AutoDEditText002,AutoDEditText003:
AutoDEditText004,AutoDEditText005,AutoDEditText006:
AutoDEditText007,AutoDEditText008,AutoDEditNumber001:
AutoDEditNumber002
.
. Eventreg on collection cause we want to know when anything changes
.
EVENTREG usrflds,$Change,SetUpdate
.
. Get the first vehicle
.
AutoFirst
IF ( New || Update )
.
. If currently displayed vehicle changed,
. check to see if we need to save changes
.
CALL AutoYN
ENDIF
.
. Position to the beginning of vehicle description file
.
REPOSIT Auto,ZERO
.
. This routine is called when the next button is clicked on the screen
.
AutoNext
IF ( New || Update )
.
. If currently displayed vehicle changed,
. check to see if we need to save changes
.
CALL AutoYN
ENDIF
.
. Read the next sequential record
.
READ Auto,SEQ;*LL,AutoR
IF OVER
.
. If we reached the end, set state variable for a new description
.
CLEAR AutoR
SET New
SETPROP AutoDButton002,visible=1
ENDIF
.
. Jump to the display routine
.
GOTO SetAutoDrcrd
AutoLast
IF ( New || Update )
CALL AutoYN
ENDIF
.
. Position to the end of the file
.
READ Auto,EOF;;
AutoPrev
IF ( New || Update )
CALL AutoYN
ENDIF
.
. Read the previous sequential record
.
READ Auto,RSEQ;*LL,AutoR
.
. If we reach the beginning of the file, go back to the first record
.
GOTO AutoFirst IF OVER
.
. Routine to load the vehicle description record into objects.
.
SetAutoDrcrd
.
. Implode the record into a delimited string
.
IMPLODE rcrdbuff,$ff,AutoR
.
. Explode can insert data from a delimited string into a list of objects
.
EXPLODE rcrdbuff,$ff,AutoDEditText002,AutoDEditText003:
AutoDEditText004,AutoDEditText005,AutoDEditText006:
AutoDEditText007,AutoDEditText008,AutoDEditNumber001:
AutoDEditNumber002
RETURN
.
. Ask if we want to save vehicle description record?
.
AutoYN
ALERT PLAIN,"Save Changes?",FM2,"Data Changed"
IF ( FM2 = "6" ) ;YES
CALL SaveAutoDrcrd
ELSE IF ( FM2="3" ) ; Cancel
NORETURN
ELSE
CLEAR New,Update
SETPROP AutoDButton002,visible=0
ENDIF
RETURN
.
. SetUpdate routine is called when a user changes any field in the
. editable objects collection defined above
.
SetUpdate
. we assume changes when a new entry is being made
RETURN IF (New)
.
. Set the update state and show the Update button so user can
. explicitly save changes.
.
SET Update
SETPROP AutoDButton002,Title="Update"
SETPROP AutoDButton002,visible=1
RETURN
SaveAutoDrcrd
. Start by getting the data from the objects
CALL GetAutoDrcrd
.
IF ( New )
.
. The auto description file is a sequential file so we
. will write new records at the end of the file.
.
WRITE Auto,EOF;AutoR
ELSE IF (Update)
.
. If we changed an existing record, the file position is aleady at
. the record being modified. Since we are using a fixed length file
. we can simplu UPDATE the file with the new data.
.
UPDATE Auto;AutoR
.
. Reset save button title
.
SETPROP AutoDButton002,Title="Save"
ENDIF
. Hide the save button as it is not shown if there is nothing to save
SETPROP AutoDButton002,Visible=0
RETURN
.
GetAutoDrcrd
.
. Get the data from the object into a delimited string
.
IMPLODE rcrdbuff,$ff,AutoDEditText002,AutoDEditText003:
AutoDEditText004,AutoDEditText005,AutoDEditText006:
AutoDEditText007,AutoDEditText008,AutoDEditNumber001:
AutoDEditNumber002
.
. Explode the delimited string into our record variable
.
EXPLODE rcrdbuff,$ff,AutoR
RETURN
*************************************************************************
. Expense log routines
.************************************************************************
.
ShowMaint
. Load the expense log screen
FORMLOAD AutoExpL,AutoMWin
SETFOCUS ExpLwin
RETURN
.
. Once a vehicle is selected, we can load the expense log
.
ExprEdit FORM 1
MPGtxt DIM 5
MPG FORM 3.3
LastOD FORM 6.1
TripMiles FORM 3.1
TripMilesTxt DIM 5 ;also scratch space.
TotalExp FORM 6.3
LoadMaint
.
. Make sure we are starting fresh
.
CLEAR LastOD,MPGtxt,TotalExp
ExpLListView001.DeleteAllItems
.
. Get the selected vehicle
.
GETITEM ExpLCarlist,0,FM2
IF ( FM2 )
. Listviews load faster when AutoRedraw is turned off
SETPROP ExpLListView001,AutoRedraw=0
.
. Get the vehicle description record using a record number
.
DECR FM2
READ Auto,FM2;*ll,AutoR
.
. Build the expense log aam key using the vehicle VIN number
.
PACK ExpKey,"01x",AutoR.VIN
READ Expense,ExpKey;*LL,ExpR
LOOP
UNTIL OVER
.
. Save the record position of current entry
.
FPOSITB Expense,FM10
.
. If we have odometer readings, tabulate the miles so we can calculate
. fuel milage
.
IF (LastOD)
IF ( Expr.FuelGal )
CALC TripMiles = Expr.Od - LastOD
CALC MPG=TripMiles / Expr.FuelGal
MOVE MPG,MPGtxt
MOVE TripMiles,TripMilesTxt
ELSE
CLEAR MPGtxt,TripMilesTxt
ENDIF
ENDIF
.
. Add the record to the listview
.
CALL AddExpR2LV
.
. If this entry included fuel, save the odometer reading for milage
. calculate on next fuel entry.
.
IF (Expr.FuelGal)
MOVE ExpR.Od,LastOD
ENDIF
.
. Keep a running total of all expenses for this vehicle
.
ADD Expr.Price,TotalExp
.
. Read the next record
.
READKG Expense;*LL,ExpR
REPEAT
.
. With all entries loaded, set the AutoRedraw on the listview true so
. they will be displayed
.
SETPROP ExpLListView001,AutoRedraw=1
ENDIF
.
. Get total miles since vehicle was purchased.
.
SUB AutoR.PurOd,LastOD
.
. Using running total expense, we can figure overall cost per mile
.
DIV LastOD,TotalExp
MOVE TotalExp,DIM9
SETITEM ExpLCostPerMile,0,DIM9
.
. Clear out residue
CLEAR MPGtxt,fm6p1,fm6p1a,fm4p3,fm4p3a
.
. Calculate the last 5 tank avg from data in listview
.
ExpLListView001.GetitemCount giving FM10a
IF ( FM10a > "6" )
MOVE "6",FM10a
ELSE
DECR FM10a // use data available if there is not enough
ENDIF
.
. Get start and ending odometer reading for 5 tank average
.
ExpLListView001.GetItemText giving DIM8(1) using FM10a,1
ExpLListView001.GetItemText giving DIM8(2) using 0,1
MOVE DIM8(1),fm6p1
MOVE DIM8(2),fm6p1a
SUB fm6p1,fm6p1a ; number of miles...
.
. Get the total fuel.
.
FOR FM10,"0",(FM10a-1)
ExpLListView001.GetItemText giving rcrdbuff using FM10,2
MOVE rcrdbuff,fm4p3
ADD fm4p3,fm4p3a ; total fuel
REPEAT
.
. Calculate the 5 tank average based on record fuel and miles.
.
CALC fm4p3=fm6p1a/fm4p3a
PACK rcrdbuff,fm4p3," MPG"
SETITEM ExpLAvgMPG,0,rcrdbuff
.
RETURN
AddExpR2LV
.
. Build a delimited string from the record
.
IMPLODE rcrdbuff,$ff,ExpR.Od,ExpR.FuelGal,ExpR.Price:
ExpR.Tires,YN(ExpR.TRota),YN(ExpR.Oil):
YN(ExpR.Brakes)
.
. Explode the delimited string into an array
.
EXPLODE rcrdbuff,$ff,DIM8
.
. Ddon't display 0 tires
.
IF ( ExpR.Tires = 0 )
CLEAR DIM8(4)
ENDIF
.
. If we are not editting and existing record, insert at beginning of LV
.
IF ( ExprEdit = 0 )
CLEAR FM10a
ENDIF
.
. Insert the record into the listview using the *PARAM to record
. the record position within the file.
.
ExpLListView001.InsertItemEx using Expr.Date,FM10a:
*SubItem1=DIM8(1),*SubItem2=DIM8(2):
*SubItem3=DIM8(3),*SubItem4=MPGtxt:
*SubItem5=DIM8(4),*SubItem6=DIM8(5),*SubItem7=DIM8(6):
*SubItem8=DIM8(7),*SubItem9=Expr.Misc:
*SUbItem10=TripMilesTxt,*PARAM=FM10
RETURN
.
. New expense record
.
NewExpR
.
. Load the expense entry child window into the MDIClient
.
FORMLOAD AutoExpD,AutoMWin
.
. Get vehicle selection data
.
GETITEM ExpLCarlist,0,FM2
GETITEM ExpLCarlist,FM2,rcrdbuff
.
. Set selection data in expense form
.
SETITEM ExpID,0,AutoR.VIN
SETITEM ExpDesc,0,rcrdbuff
.
. Set the focus to the new MDIChild window
SETFOCUS ExpWin
. Then to the object within that window
SETFOCUS ExpEditDateTime001
RETURN
.
SaveExpR
.
. Get the data from all the objects into a delimiet string
.
IMPLODE rcrdbuff,$ff,ExpID,ExpEditDateTime001,ExpOd:
ExpFuelGal,ExpPrice,ExpTires,ExpRotation:
ExpOil,ExpBrakes,ExpMisc
.
. Explode the delimited string into expense record
.
EXPLODE rcrdbuff,$ff,ExpR
.
. Check odometer against previous odometer reading
.
ExpLListView001.GetItemText giving rcrdbuff using 0,1
MOVE rcrdbuff,fm6p1
IF ( Expr.Od < fm6p1 AND ExprEdit =0 )
ALERT TYPE=4,"Bad Odometer Sequence. Continue?",FM2,"Odometer"
RETURN IF (FM2!="6") ; only continue if YES
ENDIF
.
IF ( ExprEdit )
. If were are editing an existing record, update the file and remove
. the entry from the listview
UPDATE Expense;Expr
EVENTSEND ExpButton002,4 ;click the close button.
ExpLListView001.DeleteItem using FM10a
ExpLListView001.GetItemText giving TripMilesTxt using FM10a,1
MOVE TripMilesTxt,LastOD
ELSE
. Write the new recorde and get the file position
WRITE Expense;Expr
FPOSITB Expense,FM10
ENDIF
.
. If entry was for fuel, calculate MPG
.
IF ( Expr.FuelGal )
CALC TripMiles= Expr.Od - LastOD
CALC MPG= TripMiles / Expr.FuelGal
MOVE MPG,MPGtxt
MOVE TripMiles,TripMilesTxt
MOVE Expr.Od,LastOD
ELSE
CLEAR MPGtxt,TripMilesTxt
ENDIF
.
. Add the entry to the listivew
CALL AddExpR2LV
.
. Clean up
.
CLEAR Expr,ExprEdit
IMPLODE rcrdbuff,$ff,ExpR
EXPLODE rcrdbuff,$ff,ExpEditDateTime001,ExpOd:
ExpFuelGal,ExpPrice,ExpTires,ExpRotation:
ExpOil,ExpBrakes,TripMilesTxt,ExpMisc
RETURN
.
. Routine to edit existing expense record
.
EditExpDetail
ExpLListView001.GetNextItem giving FM10a using 2 ; selected
.
. Abort if nothing is selected
.
RETURN IF (FM10a = SEQ)
.
. Get the file position from the item parameter of the listview
.
ExpLListView001.GetItemParam giving FM10 using FM10a
.
. Reposition the file and read it so it can be updated using UPDATE
.
REPOSIT Expense,FM10
READ Expense,SEQ;*LL,ExpR
.
. load the expense detail screen
.
CALL NewExpR
.
. Set the edit state and the data into the expense detail screen
.
SET ExprEdit
IMPLODE rcrdbuff,$ff,ExpR
EXPLODE rcrdbuff,$ff,ExpID,ExpEditDateTime001,ExpOd:
ExpFuelGal,ExpPrice,ExpTires,ExpRotation:
ExpOil,ExpBrakes,ExpMisc
.
RETURN
.
. Export expense data to a CSV file.
.
ExportExpData
ExpName DIM 50
ExpPath DIM 200
ExpFName DIM 250
.
. Get a file name
.
GETFNAME PREP,"Save File",ExpName,ExpPath,"CSV"
RETURN IF OVER
.
. Make sure path has a trailing "\"
.
ENDSET ExpPath
CMATCH "\",ExpPath
IF NOT EQUAL
APPEND "\",ExpPath
ENDIF
RESET ExpPath
.
. Build a fully qualified file name
.
PACK ExpFName,ExpPath,ExpName
.
. Use the listview SaveCSVFile method to export the data.
.
ExpLListView001.SaveCSVFile using ExpFName
RETURN
*************************************************************************
. Auto Maintenance routines
.************************************************************************
.
FreqData1 DIM 10
FreqData2 DIM 10
FreqData3 DIM 20
DescData DIM 100
.
. routine to check if any maintenance is due.
.
ChkSMaint
.
. Read through vehicle descriptions and look at what scheduled maintenance
. exist for the car.
. Then check each scheduled maintenance for an expense record. Check the data
. against the Maint frequency. If maintenance is due, show on list.
.
CurOD FORM 6.1
.
. Start at the beginning maintenance list.
.
REPOSIT Auto,ZERO
LOOP
READ Auto,SEQ;*ll,AutoR
UNTIL Over
.
. If the vehicle has a odometer reading when sold, don't check maintenance
.
CONTINUE if ( AutoR.SelOd )
.
PACK ExpKey,"01x",AutoR.VIN
.
. Get a scheduled maintenance record
.
READ SMaint,AutoR.VIN;*ll,SchedMaint
LOOP
UNTIL OVER
.
. Start at the end of the expense log looking for a matching expense
.
READLAST Expense,ExpKey;*ll,ExpR
IF NOT OVER
.
. Get the most recent odometer reading
.
MOVE Expr.Od,CurOD
PACK ExpKey2,"02L",SchedMaint.TRota,SchedMaint.Oil:
SchedMaint.Brakes,SchedMaint.Misc
BUMP ExpKey2
.
. Use wild cards for entries we don't care about
.
REPLACE "0?",ExpKey2
RESET ExpKey2
.
. Find last occurrance of maintenance.
.
CALL LastSchMaintOccr
.
ENDIF
. Get the next scheduled maintenance record
.
READKS SMaint;*ll,SchedMaint
REPEAT until (SchedMaint.ID != AutoR.VIN)
.
REPEAT
.
RETURN
.
. Routine to notify user that maintenance is due for a vehicle
.
ShowMaintDue
.
. to-do...maintenance due list
. .
CALL BuildFreqData
PACK rcrdbuff,AutoR.Year,"-",AutoR.Model," - ",DescData
ALERT NOTE,rcrdbuff,FM2,"Maintenance Due"
.
RETURN
.
. Show the maintenance schedual
.
SMaint
.
. load the maintenance MDIChild window into the MDIClient
.
FORMLOAD AutoMnt,AutoMWin
.
. Setup the listview
.
MaintListView001.InsertColumn using "Freq",80,0
MaintListView001.InsertColumn using "Description",200,1
MaintListView001.InsertColumn using "Next",200,2
.
. Show which vehicle is selected
.
SETITEM MaintID,0,AutoR.VIN
PACK rcrdbuff,AutoR.Year,"-",AutoR.Model
SETITEM MaintLabelText001,0,rcrdbuff
.
. Load the schedual
.
CALL LoadSchMaint
.
. Make sure maintenance window had focus, then the object on the window
.
SETFOCUS MaintWIn
SETFOCUS MaintFreq
.
RETURN
.
. Routine to get the maintenance data
.
LoadSchMaint
.
. Get a maintenance record
.
READ SMaint,AutoR.VIN;*ll,SchedMaint
.
LOOP
UNTIL OVER
.
. Based on expense record, find out how long until maintenance item is due
.
PACK ExpKey,"01x",AutoR.VIN
CALL LastSchMaintOccr
IF ( CurOD )
.
. If maintenance is based on miles, how many more miles until it
. needs to be done
.
SUB CurOD,SchedMaint.FMl,CurOD
PACK rcrdbuff,CurOD," Miles"
ELSE
. Otherwise, just use due date
IMPLODE rcrdbuff,"-",DateR2
ENDIF
.
. Put result in the maintenance listview
.
CALL AddShed2LV
.
. Get next scheduled maintenance record
.
READKS SMaint;*ll,SchedMaint
REPEAT until ( SchedMaint.ID != AutoR.VIN )
.
RETURN
.
. Routine to figure out the last time a maintenance item was done
.
LastSchMaintOccr
.
. Get the current odometer reading from the last recorded expense
.
READLAST Expense,ExpKey;*ll,ExpR
IF NOT OVER
MOVE Expr.Od,CurOD ;most recent odometer reading
.
. Build a key that selects the maintenance item we are looking for
.
PACK ExpKey2,"02L",SchedMaint.TRota,SchedMaint.Oil:
SchedMaint.Brakes,SchedMaint.Misc
BUMP ExpKey2
REPLACE "0?",ExpKey2
RESET ExpKey2
.
. Since we want the most recent occurrance, we start reading
. at the last record
.
READLAST Expense,ExpKey,ExpKey2;*ll,ExpR
IF NOT OVER
.
. Figure out the maintenance schedual
.
IF ( SchedMaint.MType )
.
. If it is by date, we don't care about odometer readings
.
CLEAR CurOD
.
. Get today's date
.
CLOCK TIMESTAMP,rcrdbuff
UNPACK rcrdbuff,DateR
UNPACK ExpR.Date,DateR2
.
. Offset last maintenance date by frequency
.
ADD SchedMaint.FDt,DateR2.MM
IF ( DateR2.MM > "12" )
SUB "12",DateR2.MM
INCR DateR2.YY
ENDIF
.
. If maintenance is past due, notify user
.
IF ( DateR2.YY < DateR.YY || DateR2.MM < DateR.MM )
CALL ShowMaintDue
ENDIF
.
ELSE
.
. If frequency is mileage based, how many miles have we logged since
. it was last done
SUB ExpR.Od,CurOD
.
. If maintenance is past due, notify user
.
IF ( CurOD > SchedMaint.FMl )
CALL ShowMaintDue
ENDIF
ENDIF
ELSE
.
. If no expense record exists for maintenance item, assume it is due.
.
CALL ShowMaintDue
ENDIF
ENDIF
.
RETURN
.
. Add an item to the scheduled maintenance list
.
SaveSchMaint
.
. Make sure we do not have residual data
.
CLEAR SchedMaint
.
. Use the vehicle VIN number as ID
.
GETITEM MaintID,0,SchedMaint.ID
.
. Get the schedule type ( date or miles )
.
GETITEM MaintRdoMnth,0,SchedMaint.MType
.
. Get the frequency data
.
IF (SchedMaint.MType)
GETPROP MaintFreq,VALUE=SchedMaint.FDt
ELSE
GETPROP MaintFreq,VALUE=SchedMaint.FMl
ENDIF
.
. Maintenance record description
.
MaintDesc.GetText giving rcrdbuff
SWITCH rcrdbuff
CASE "Oil Change"
SET SchedMaint.Oil
CASE "Service Brakes"
SET SchedMaint.Brakes
CASE "Tire Rotation"
SET SchedMaint.TRota
DEFAULT
MOVE rcrdbuff,SchedMaint.Misc
ENDSWITCH
.
. Record the item and add it to the listview
.
WRITE SMaint;SchedMaint
CALL AddShed2LV
.
RETURN
.
. Add maintenance record to listview
.
AddShed2LV
.
. call data formatting routine
.
CALL BuildFreqData
.
. Insert all the columns with one statement
.
MaintListView001.InsertItemEx Using FreqData3,*SubItem1=DescData,*SubItem2=rcrdbuff
.
RETURN
BuildFreqData
.
. Get frequency value and description
.
LOAD FreqData1,(SchedMaint.MType+1),SchedMaint.FMl,SchedMaint.FDt
LOAD FreqData2,(SchedMaint.MType+1)," Miles", " Months"
.
. Build a meaningful description
.
PACK FreqData3,FreqData1,FreqData2
.
. Interpret description data
.
IF ( SchedMaint.TRota )
MOVE "Tire Rotation",DescData
ELSE IF ( SchedMaint.Oil )
MOVE "Oil Change",DescData
ELSE IF ( SchedMaint.Brakes )
MOVE "Brake Service",DescData
ELSE
MOVE SchedMaint.Misc,DescData
ENDIF
.
RETURN
DelSchMaint
.
. Not implemented
.
RETURN
You can’t perform that action at this time.
