-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBluecoinsImportTool.h
More file actions
1268 lines (992 loc) · 35 KB
/
BluecoinsImportTool.h
File metadata and controls
1268 lines (992 loc) · 35 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
#pragma once
// BluecoinsImportTool.h : Include file for standard system include files,
// or project specific include files.
#include "utils.h"
#include "displayUtils.h"
#include "./entryDataStruct.h"
ENTRY entry;
const string defaultJsonFileName = "D:\\WinLibrary\\Documents\\GIT-Code\\Bluecoins-ImportTool\\Tests\\ktn_new.json";
bool splitTransac = false,
usedSplit = false,
multiLine = false;
// Global variables related with file output.
ifstream fileCheck;
ofstream file;
bool append = false;
bool writebackChanges = false;
string outFilename = "",
jsonFilename = "";
// Used to store all properties in the json file.
json properties;
// Utility functions:
// Resets all entry to initial values.
void reset() {
entry.type.reset_input();
entry.transCat.reset_input();
entry.transChild.reset_input();
entry.accCat.reset_input();
entry.accChild.reset_input();
entry.year.reset_input();
entry.month.reset_input();
entry.day.reset_input();
entry.hour.reset_input();
entry.mins.reset_input();
entry.amount.reset_input();
entry.title.reset_input();
entry.notes.reset_input();
entry.status.reset_input();
entry.label.reset_input();
entry.sourceAccCat.reset_input();
entry.sourceAccChild.reset_input();
entry.destAccCat.reset_input();
entry.destAccChild.reset_input();
}
// Some arbituary introduction to the program during launch.
void introduction() {
// pause();
}
// Outputs all properties and their respective values.
void outAllProperties() {
heading("Output all fields");
// If filepath property exist then load it as default path, and change behaviour accordingly
cout << "Current output path : " << outFilename << endl;
if (properties.contains("outFile")) {
if (properties["outFile"].contains("filePath")) {
cout << "JSON-Defined output path : " << returnString(properties["outFile"]["filePath"]) << endl;
}
if (properties["outFile"].contains("advFormat")) {
cout << "Advanced file type : " << properties["outFile"]["advFormat"] << endl;
}
if (properties["outFile"].contains("defaultAppend")) {
cout << " Default is append : " << properties["outFile"]["defaultAppend"] << endl;
}
if (properties["outFile"].contains("writebackChanges")) {
cout << " Write-back changes : " << properties["outFile"]["writebackChanges"] << endl;
}
}
for (json type : properties["presetLists"]) {
cout << returnString(type["type"]) << " : " << endl;
for (json cat : type["catList"]) {
line(4, ' ', false);
cout << returnString(cat["cat"]) << " : " << endl;
for (json child : cat["child"]) {
line(8, ' ', false);
cout << returnString(child["childName"]);
// If exist then only display
if (child.contains("currency")) {
cout << " (" << returnString(child["currency"]) << ") ";
}
cout << endl;
if (child.contains("bluecoinsBal")) {
line(10, ' ', false);
cout << "Bluecoins Balance: " << child["bluecoinsBal"] << endl;
}
if (child.contains("targetBal")) {
line(10, ' ', false);
cout << "Target Balance: " << child["targetBal"] << endl;
}
}
}
line();
}
system("pause");
}
// === Unused function ===
// Outputs elements one level below, excluding unspecified arrays.
// Place a space if want to output all types.
// If only type provided, list cat.
// If both type and cat provided, list child.
void outArray(string selectionType, string cat = " ") {
heading("Output all fields one level below");
bool found0 = false;
if (selectionType == " ") { // If type is space show all types.
for (json type : properties["presetLists"]) {
cout << returnString(type["type"]) << endl;
}
}
else {
for (json type : properties["presetLists"]) {
if (returnString(type["type"]) == selectionType) {
found0 = true;
if (cat == " ") { // If only type stated then only output list of categories.
for (json cat : type["catList"]) {
cout << returnString(cat["cat"]) << endl;
}
break;
}
else { // Else if stated then output child
bool found1 = false;
for (json cat : type["catList"]) {
if (returnString(cat["cat"]) == cat) {
found1 = true;
for (json child : cat["child"]) {
cout << returnString(child["childName"]);
if (child.contains("currency")) {
cout << " (" << returnString(child["currency"]) << ") ";
}
cout << endl;
}
}
break;
}
if (!found1) { // If not found in list then category not found.
cout << "Category not found." << endl;
}
}
break;
}
}
if (!found0) { // If not found in list then type not found.
cout << "Type not found." << endl;
}
}
}
// Outputs all elements one level below according to the index number.
// Also provides index number in the process.
// *Does not output bank accounts unless specified.
void outArray(bool isAccount = false, int type = -1, int cat = -1) {
int i = 0;
// If selection is account, then start from array entry 1.
if (!isAccount) {
i = 1;
}
if (type == -1) { // If type is unspecified show all types.
menuHeading();
for (i; i < properties["presetLists"].size(); i++) {
cout << left << setw(5) << i << returnString(properties["presetLists"][i]["type"]) << endl;
}
}
else {
if (type < properties["presetLists"].size()) { // Only display if type is less than size of presetList
if (cat == -1) { // If only type stated then only output list of categories.
menuHeading();
for (int j = 0; j < properties["presetLists"][type]["catList"].size(); j++) {
cout << left << setw(5) << j << returnString(properties["presetLists"][type]["catList"][j]["cat"]) << endl;
}
}
else { // If type and cat stated then output child.
int j = 0;
if (cat < properties["presetLists"][type]["catList"].size()) {
menuHeading();
for (int j = 0; j < properties["presetLists"][type]["catList"][cat]["child"].size(); j++) {
cout << left << setw(5) << j << returnString(properties["presetLists"][type]["catList"][cat]["child"][j]["childName"]);
if (properties["presetLists"][type]["catList"][cat]["child"][j].contains("currency")) {
cout << " (" << returnString(properties["presetLists"][type]["catList"][cat]["child"][j]["currency"]) << ") ";
}
cout << endl;
}
}
else {
cout << "Category number invalid." << endl;
}
}
}
else {
cout << "Type number invalid." << endl;
}
}
cout << endl;
}
/*
For user to input all entry information.
There are 3 types of codes to be returned:
- 0 -> Everything is good, write result to file.
- 1 -> Everything is good, but discard results.
- 9 -> User exit halfway through input.
*/
int entryInput(ENTRY entryTemplate) {
// tempEntry copies from template, to have respect to selected "fixed" fields
ENTRY tempEntry = entryTemplate;
int type_index = 0; // To describe type of transaction
if (tempEntry.type.isFixed) {
type_index = tempEntry.type.fixedIndex;
}
// User input : Short Description
Title_input:
while (!tempEntry.title.isFixed) {
string userInput = "";
// To cancel changes done by current section, if being called back.
tempEntry.title.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
cout << "Transaction title? " << endl << "> ";
getline(cin, userInput);
USER_INPUT_STRING_RETURN else if (userInput == "-1") { return 9; }
if (userInput == "") {
cout << "Please insert a title." << endl;
pause();
continue;
}
else {
tempEntry.title.set(userInput);
break;
}
}
// User input : Type of Transaction
Type_input:
while (!tempEntry.type.isFixed) {
int userInput = 0;
// To cancel changes done by current section, if being called back.
tempEntry.transCat.reset_input();
tempEntry.transChild.reset_input();
tempEntry.type.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
outArray(false);
if (!splitTransac) { cout << endl << left << setw(5) << "5" << "Transfer" << endl; }
cout << endl << "Type? ";
userInput = inputNumber<int>();
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto Title_input; }
if ((userInput == 1) || (userInput == 2) || ((userInput == 5) && !splitTransac)) {
type_index = userInput;
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// If transaction type is transfer -- split transactions never come here
if ((type_index == 5) && !splitTransac) {
heading("Transaction input: Transfer");
// Transfer cases
if (!tempEntry.type.isFixed) {
tempEntry.transCat.set("(Transfer)");
tempEntry.transChild.set("(Transfer)");
tempEntry.type.set("Transfer");
}
// To determine source account
// User input : Account Type
TransferSourceAccType_input:
while (!tempEntry.sourceAccCat.isFixed) {
int userInput = -1;
// To cancel changes done by current section, if being called back.
tempEntry.sourceAccCat.reset_input();
heading("Transaction input: Transfer -> Select Source Account");
show_inputted(tempEntry);
outArray(true, 0);
cout << "Source Account Type? ";
userInput = inputNumber<int>();
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto Type_input; }
if ((userInput < properties["presetLists"][0]["catList"].size()) && (userInput >= 0)) {
tempEntry.sourceAccCat.set(
returnString(properties["presetLists"][0]["catList"][userInput]["cat"]),
userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Account
TransferSourceAcc_input:
while (!tempEntry.sourceAccChild.isFixed) {
int userInput = -1;
int parentIndex = tempEntry.sourceAccCat.fixedIndex;
// To cancel changes done by current section, if being called back.
tempEntry.sourceAccChild.reset_input();
heading("Transaction input: Transfer -> Select Source Account");
show_inputted(tempEntry);
outArray(true, 0, parentIndex);
cout << "Source Account Child? ";
userInput = inputNumber<int>();
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto TransferSourceAccType_input; }
if ((userInput < properties["presetLists"][0]["catList"][parentIndex]["child"].size()) && (userInput >= 0)) {
tempEntry.sourceAccChild.set(
returnString(properties["presetLists"][0]["catList"][parentIndex]["child"][userInput]["childName"]),
userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Account Type
TransferDestAccType_input:
while (!tempEntry.destAccCat.isFixed) {
int userInput = -1;
// To cancel changes done by current section, if being called back.
tempEntry.destAccCat.reset_input();
heading("Transaction input: Transfer -> Select Destination Account");
show_inputted(tempEntry);
outArray(true, 0);
cout << "Destination Account Type? ";
userInput = inputNumber<int>();
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto TransferSourceAcc_input; }
if ((userInput < properties["presetLists"][0]["catList"].size()) && (userInput >= 0)) {
tempEntry.destAccCat.set(
returnString(properties["presetLists"][0]["catList"][userInput]["cat"]),
userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Account
TransferDestAcc_input:
while (!tempEntry.destAccChild.isFixed) {
int userInput = -1;
int parentIndex = tempEntry.destAccCat.fixedIndex;
// To cancel changes done by current section, if being called back.
tempEntry.destAccChild.reset_input();
heading("Transaction input: Transfer -> Select Destination Account");
show_inputted(tempEntry);
outArray(true, 0, parentIndex);
cout << "Destination Account Child? ";
userInput = inputNumber<int>();
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto TransferDestAccType_input; }
if ((userInput < properties["presetLists"][0]["catList"][parentIndex]["child"].size()) && (userInput >= 0)) {
tempEntry.destAccChild.set(
returnString(properties["presetLists"][0]["catList"][parentIndex]["child"][userInput]["childName"]),
userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
}
else {
if (!tempEntry.type.isFixed) {
splitTransac ?
tempEntry.type.fix(returnString(properties["presetLists"][type_index]["type"]), type_index) :
tempEntry.type.set(returnString(properties["presetLists"][type_index]["type"]));
}
// User input : Expense / Income Parent Category
TransCat_input:
while (!tempEntry.transCat.isFixed) {
int userInput = -1;
// To cancel changes done by current section, if being called back.
tempEntry.transCat.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
outArray(false, type_index);
cout << "Category? ";
userInput = inputNumber<int>();
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto Type_input; }
if ((userInput < properties["presetLists"][type_index]["catList"].size()) && (userInput >= 0)) {
tempEntry.transCat.set(
returnString(properties["presetLists"][type_index]["catList"][userInput]["cat"]),
userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Expense / Income Category
TransType_input:
while (!tempEntry.transChild.isFixed) {
int userInput = -1;
int parentIndex = tempEntry.transCat.fixedIndex;
// To cancel changes done by current section, if being called back.
tempEntry.transChild.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
outArray(false, type_index, parentIndex);
cout << "Category Child? ";
userInput = inputNumber<int>(false);
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto TransCat_input; }
if ((userInput < properties["presetLists"][type_index]["catList"][parentIndex]["child"].size()) && (userInput >= 0)) {
tempEntry.transChild.set(
returnString(properties["presetLists"][type_index]["catList"][parentIndex]["child"][userInput]["childName"]),
userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Account Type
AccCat_input:
while (!tempEntry.accCat.isFixed) {
int userInput = -1;
// To cancel changes done by current section, if being called back.
tempEntry.accCat.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
outArray(true, 0);
cout << "Account Type? ";
userInput = inputNumber<int>(false);
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto TransType_input; }
if ((userInput < properties["presetLists"][0]["catList"].size()) && (userInput >= 0)) {
tempEntry.accCat.set(
returnString(properties["presetLists"][0]["catList"][userInput]["cat"]),
userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Account
AccType_input:
while (!tempEntry.accChild.isFixed) {
int userInput = 0;
int parentIndex = tempEntry.accCat.fixedIndex;
// To cancel changes done by current section, if being called back.
tempEntry.accChild.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
outArray(true, 0, parentIndex);
cout << "Account Child? ";
userInput = inputNumber<int>(false);
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto AccCat_input; }
if ((userInput < properties["presetLists"][0]["catList"][parentIndex]["child"].size()) && (userInput >= 0)) {
tempEntry.accChild.set(returnString(properties["presetLists"][0]["catList"][parentIndex]["child"][userInput]["childName"]));
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
}
// Date & time input :
// User input : Year
Year_input:
while (!tempEntry.year.isFixed) {
int userInput = 0;
// To cancel changes done by current section, if being called back.
tempEntry.year.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
line(50, '-');
cout << "Date & time input: " << endl;
cout << "Year? ";
userInput = inputNumber<int>(false);
USER_INPUT_NUMBER_RETURN else if ((type_index == 5) && (userInput == -1)) { goto TransferDestAcc_input; }
else if (userInput == -1) { goto AccType_input; }
if (userInput > 0) {
splitTransac ?
tempEntry.year.fix(userInput) :
tempEntry.year.set(userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Month
Month_input:
while (!tempEntry.month.isFixed) {
int userInput = 0;
// To cancel changes done by current section, if being called back.
tempEntry.month.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
line(50, '-');
cout << "Date & time input: " << endl;
cout << "Month? ";
userInput = inputNumber<int>(false);
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto Year_input; }
if (userInput > 0 && userInput <= 12) {
splitTransac ?
tempEntry.month.fix(userInput) :
tempEntry.month.set(userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Day
Day_input:
while (!tempEntry.day.isFixed) {
int userInput = 0;
// To cancel changes done by current section, if being called back.
tempEntry.day.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
line(50, '-');
cout << "Date & time input: " << endl;
cout << "Day? ";
userInput = inputNumber<int>(false);
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto Month_input; }
if (userInput > 0 && userInput <= 31) {
splitTransac ?
tempEntry.day.fix(userInput) :
tempEntry.day.set(userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Hour
Hour_input:
while (!tempEntry.hour.isFixed) {
int userInput = 0;
// To cancel changes done by current section, if being called back.
tempEntry.hour.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
line(50, '-');
cout << "Date & time input: " << endl;
cout << "Hour? ";
userInput = inputNumber<int>(false);
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto Day_input; }
if (userInput >= 0 && userInput <= 23) {
splitTransac ?
tempEntry.hour.fix(userInput) :
tempEntry.hour.set(userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// User input : Mins
Min_input:
while (!tempEntry.mins.isFixed) {
int userInput = 0;
// To cancel changes done by current section, if being called back.
tempEntry.mins.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
line(50, '-');
cout << "Date & time input: " << endl;
cout << "Mins? ";
userInput = inputNumber<int>(false);
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto Hour_input; }
if (userInput >= 0 && userInput <= 59) {
splitTransac ?
tempEntry.mins.fix(userInput) :
tempEntry.mins.set(userInput);
break;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
// ==================================================
// User input : Amount
Amount_input:
while (!tempEntry.amount.isFixed) {
double userInput = 0;
// To cancel changes done by current section, if being called back.
tempEntry.amount.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
line(50, '-');
cout << "Amount? ";
userInput = inputNumber<double>(false);
USER_INPUT_NUMBER_RETURN else if (userInput == -1) { goto Min_input; }
tempEntry.amount.set(userInput);
break;
}
// User input : Notes (No multi-line)
Notes_input:
while (!tempEntry.notes.isFixed) {
string userInput = "";
// To cancel changes done by current section, if being called back.
tempEntry.notes.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
line(50, '-');
if (multiLine) {
cout << "Notes? (Multi-line mode on. Input \" then enter to save and exit note-ing mode.)" << endl;
line(50, '-');
getline(cin, userInput, '\"');
}
else {
cout << "Notes? (Multi-line mode off. Enter to save and exit note-ing mode.)" << endl;
line(50, '-');
getline(cin, userInput);
}
USER_INPUT_STRING_RETURN else if (userInput == "-1") { goto Amount_input; }
tempEntry.notes.set(userInput);
break;
}
// User input : Status
Status_input:
while (!tempEntry.status.isFixed) {
string userInput = "";
// To cancel changes done by current section, if being called back.
tempEntry.status.reset_input();
heading("Transaction input");
show_inputted(tempEntry);
menuHeading();
cout << left << setw(5) << "R" << "Reconciled" << endl;
cout << left << setw(5) << "C" << "Cleared" << endl;
cout << left << setw(5) << "0" << "<None>" << endl;
cout << "Status? ";
getline(cin, userInput);
USER_INPUT_STRING_RETURN else if (userInput == "-1") { goto Notes_input; }
if (userInput == "R" || userInput == "r") {
splitTransac ?
tempEntry.status.fix('R') :
tempEntry.status.set('R');
break;
}
else if (userInput == "C" || userInput == "c") {
splitTransac ?
tempEntry.status.fix('C') :
tempEntry.status.set('C');
break;
}
else {
splitTransac ?
tempEntry.status.fix('\0') :
tempEntry.status.set('\0');
break;
}
}
// System generate : Label
time_t rawtime = time(&rawtime);
struct tm now;
localtime_s(&now, &rawtime);
int thisYear = now.tm_year + 1900;
tempEntry.label.set("Import " + to_string(thisYear) + return_fixed_digits(now.tm_mon, 2));
// Review entry, then press key to return commit intent.
while (true) {
string userInput = "";
entry = tempEntry;
heading("Transaction input -> Entry Review");
show_inputted(tempEntry);
line(50, '-');
cout << "Commit changes? (y / n / -1) : ";
getline(cin, userInput);
USER_INPUT_STRING_RETURN else if (userInput == "-1") { goto Status_input; }
if ((userInput == "Y") || (userInput == "y")) {
// 0 for "Everything fine, commit changes."
return 0;
}
else if ((userInput == "N") || (userInput == "n")) {
// 1 for "Everything fine, but discard changes."
return 1;
}
else {
cout << "Illegal action!" << endl;
system("pause");
continue;
}
}
}
// Function to load output file.
void fileFunc(string path = "", bool toAppend = false) {
if (file.is_open()) {
file.close();
}
heading("Select Output File");
if (path == "") {
cout << "File path for output file? ";
getline(cin, outFilename);
}
fileCheck.open(outFilename);
heading("Select Output File");
if (!fileCheck) {
cout << "Output file does not exist, create file? ";
// TODO: outFilename get overridden no matter file status
if (decider()) {
// TODO: File Creation does not work.
file.open(outFilename);
}
}
else {
// TODO: Fix logic to prioritize file-defined append action
string intent = "\0";
if (!toAppend) {
cout << "Output file exists, append? (y/n/c) \nSelecting 'n' will clear the existing file. Press 'c' to cancel. " << endl;
getline(cin, intent);
}
if (intent == "c") {
outFilename = "";
}
else if ((intent == "y") || (toAppend == true)) {
file.open(outFilename, ios::app);
append = true;
}
else if ((intent == "n") || (toAppend == false)) {
file.open(outFilename, ios::trunc);
append = false;
}
}
fileCheck.close();
}
// Request json file path, opens it and imports it into the json struct.
void readFile() {
heading("JSON File Import");
cout << "Please make sure that your json file is updated to the latest format." << endl << endl;
ifstream jsonFile;
while (true) {
cout << "File path for json file ? ";
getline(cin, jsonFilename);
if (jsonFilename == "d") {
jsonFilename = defaultJsonFileName;
}
jsonFile.open(jsonFilename);
if (!jsonFile) {
cout << "File does not exist. " << endl;
continue;
}
else {
break;
}
}
try {
jsonFile >> properties;
}
catch (...) {
cout << "JSON File Read Error. Please check using linters to make sure that the JSON is in correct form." << endl
<< "The program will now exit.";
pause();
exit(1);
}
// If filepath property exist then load it as default path, and change behaviour accordingly
if (properties.contains("outFile")) {
if (properties["outFile"].contains("filePath")) {
outFilename = returnString(properties["outFile"]["filePath"]);
}
if (properties["outFile"].contains("defaultAppend")) {
append = properties["outFile"]["defaultAppend"];
}
if (properties["outFile"].contains("writebackChanges")) {
writebackChanges = properties["outFile"]["writebackChanges"];
if (!properties["outFile"].contains("writebackJSONSpacing")) {
properties["outFile"]["writebackJSONSpacing"] = 4;
}
}
fileFunc(outFilename, append);
}
cout << "File succesfully imported." << endl;