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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
|
package main
import (
//"os"
"fmt"
"strconv"
"strings"
"time"
"github.com/abiosoft/ishell"
//"github.com/EPRparadox82/ishell"
"github.com/fatih/color"
)
//var mastercol *color.Color
func interact(fulldb bool) {
//stdOut()
shell := ishell.New()
shell.SetMultiChoicePrompt(" ->", " - ")
shell.SetChecklistOptions("[ ] ", "[X] ")
//fmt.Println(os.Args)
//cyan := color.New(color.FgCyan).SprintFunc()
//yellow := color.New(color.FgYellow).SprintFunc()
//green := color.New(color.FgGreen).SprintFunc()
boldBlue := color.New(color.FgBlue, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
boldMag := color.New(color.FgMagenta, color.Bold).SprintFunc()
boldCyan := color.New(color.FgCyan, color.Bold).SprintFunc()
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldYell := color.New(color.FgYellow, color.Bold).SprintFunc()
promptcol := boldBlue
//PromptColor(GetColor())
if fulldb {
promptcol = PromptColor(GetColor()).SprintFunc()
}
// display info.
//shell.Println("Starting interactive Shell")
shell.SetPrompt(promptcol(">>>"))
// New Customer / New Project
{
newcmd := &ishell.Cmd{
Name: "new",
Help: "project / customer",
LongHelp: ` Usage: new <command>`,
}
newcmd.AddCmd(&ishell.Cmd{
Name: "project",
Help: "Start new Project",
LongHelp: ` Usage: new project
If no Task is currently running a new project will be added to database and opened.
When there is an open Task the user will be notified to stop it before adding a new Project`,
Func: func(c *ishell.Context) {
//c.Print("\033[H\033[2J")
//c.Println(boldGreen("Start New Project"))
newProject()
//showLastProject()
stdOut()
c.Println(promptcol("______________________"))
},
})
newcmd.AddCmd(&ishell.Cmd{
Name: "customer",
Help: "Add new Customer",
LongHelp: ` Usage: new customer
Add a new Customer to Database`,
Func: func(c *ishell.Context) {
addCustomer()
c.Println(promptcol("______________________"))
},
})
paycmd := &ishell.Cmd{
Name: "payment",
Help: "<Date>/now - Enter a Payment",// at a specific Time 'YYYY-MM-DD' Or 'now'",
LongHelp: ` Usage: new payment <Date>/now
Enter a new Payment at <Date>.
Use Format "YYYY-MM-DD" for date.
'now' will start the Task at current local date.`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
if isDate(arg){
AddPayment(arg)
}else{
c.Println(boldRed("new payment <Date> - Please enter a valid Date of Format 'YYYY-MM-DD'"))
}
} else {
c.Println(boldRed("new payment <Date> - Please enter a Date"))
}
stdOut()
c.Println(promptcol("______________________"))
},
}
paycmd.AddCmd(&ishell.Cmd{
Name: "now",
Help: "Enter a new Payment dated today",
LongHelp: ` Usage: new payment now
Enter a new Payment with current local date`,
Func: func(c *ishell.Context) {
AddPayment("jetzt")
stdOut()
c.Println(promptcol("______________________"))
},
})
newcmd.AddCmd(paycmd)
shell.AddCmd(newcmd)
}
shell.AddCmd(&ishell.Cmd{
Name: "resume",
Help: "Resume the Paused Task",
LongHelp: ` Usage: resume
Resume the Task that was paused 'now'.`,
Func: func(c *ishell.Context) {
newTask(true)
stdOut()
setPauseTask(0)
c.Println(promptcol("______________________"))
},
})
shell.AddCmd(&ishell.Cmd{
Name: "pause",
Help: "Close the Current Task and remember it",
LongHelp: ` Usage: pause
Closes the current task 'now' and remember it to continue later.
The User is not asked to enter a comment.`,
Func: func(c *ishell.Context) {
if opentask.Id > 0 {
setPauseTask(opentask.Id)
c.Println("Pausing Task", pausetask)
}
closeTask(false)
stdOut()
c.Println(promptcol("______________________"))
},
})
shell.AddCmd(&ishell.Cmd{
Name: "status",
Help: "Show Current Project and Tasks",
LongHelp: ` Usage: status
Shows the current Project, its last Tasks and if there is a open Task.`,
Func: func(c *ishell.Context) {
//stdOut()
showStatus(true)
c.Println(promptcol("______________________"))
},
})
/* OLD CHECKBILL
shell.AddCmd(&ishell.Cmd{
Name: "checkbill",
Help: "<id> check a Bill with the following id as paid",
LongHelp: ` Usage: checkbill <id>
Check the bill of the set <id> as paid on the current date`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
checkBill(argi)
//stdOut()
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
c.Println(boldRed("checkbill <id> - Please enter an id"))
showLastBills(0)
}
c.Println(promptcol("______________________"))
},
})
*/
// Delete Commands: Bill / Task / Payment
{
delcmd := &ishell.Cmd{
Name: "delete",
Help: "task / bill",
LongHelp: ` Usage: delete <command>`,
}
delcmd.AddCmd(&ishell.Cmd{
Name: "bill",
Help: "<id> Delete a Bill with the following id",
LongHelp: ` Usage: delete bill <id>
Delete the bill of the set <id> and set its Task back to unbilled`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
deleteBill(argi)
stdOut()
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
c.Println(boldRed("deletebill <id> - Please enter an id"))
showLastBills(0)
}
c.Println(promptcol("______________________"))
},
})
delcmd.AddCmd(&ishell.Cmd{
Name: "payment",
Help: "<id> Delete the Payment with the following id",
LongHelp: ` Usage: delete payment <id>
Delete the payment of the set <id>`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
DeletePayment(argi)
stdOut()
} else {
c.Println(boldRed(arg, " is not a valid id!"))
}
} else {
selids, lids := GetPaymentList()
choice := c.MultiChoice(lids, "Select a Payment to Edit")
if choice > -1 {
DeletePayment(selids[choice])
}
}
c.Println(promptcol("______________________"))
},
})
delcmd.AddCmd(&ishell.Cmd{
Name: "task",
Help: "<id> Delete a Task with the following id",
LongHelp: ` Usage: delete task <id>
Delete the Task of the set <id>`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
deleteTask(argi)
stdOut()
} else {
c.Println(boldRed(arg, " is not a valid id!"))
}
} else {
tids := GetTaskIds()
selids, lids := GetTaskList(tids, false,false)
choice := c.MultiChoice(lids, "Select a Task to Delete")
if choice > -1 {
deleteTask(selids[choice])
}
//c.Println(boldRed("deletetask <id> - Please enter an id"))
//allProjects()
}
c.Println(promptcol("______________________"))
},
})
shell.AddCmd(delcmd)
}
// OPEN PROJECT COMMAND
shell.AddCmd(&ishell.Cmd{
Name: "project",
Help: "<id> Open a Project of the following id",
LongHelp: ` Usage: project <id>
Open the Project with the set <id>
If there is an open Task the user will be notified to close it first.`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
setProject(argi)
stdOut()
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
pids := GetProjectIds()
selids, lids := getProjectList(pids)
choice := c.MultiChoice(lids, "Select a Project to Edit")
if choice > -1 {
setProject(selids[choice])
}
//c.Println(boldRed("editproject <id> - Please enter an id"))
//c.Println(boldRed("project <id> - Please enter an id"))
//allProjects()
}
c.Println(promptcol("______________________"))
},
})
// EDIT COMMAND
{
editcmd := &ishell.Cmd{
Name: "edit",
Help: " customer / payment / project / task",
LongHelp: ` Usage: edit <command>`,
/* customer <id> - Edit Customer of given id.
project <id> - Edit Project of given id.
task <id> - Edit Task of given id.`, */
}
editcmd.AddCmd(&ishell.Cmd{
Name: "task",
Help: "<id> Edit a Task of the following id",
LongHelp: ` Usage: edit task <id>
Edit Task of the set <id>.
Press <Enter> on empty line to keep the old entry`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
editTask(argi)
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
tids := GetTaskIds()
selids, lids := GetTaskList(tids, false,false)
choice := c.MultiChoice(lids, "Select a Task to Edit")
//c.Println(tids)
//c.Println(selids)
if choice > -1 {
editTask(selids[choice])
//c.Println(choice,selids[choice])
}
//c.Println(boldRed("edittask <id> - Please enter an id"))
}
c.Println(promptcol("______________________"))
},
})
editcmd.AddCmd(&ishell.Cmd{
Name: "project",
Help: "<id> Edit the Project of the following id",
LongHelp: ` Usage: edit project <id>
Edit Project of the set <id>.
Press <Enter> on empty line to keep the old entry`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
editProject(argi)
//allProjects()
//stdOut()
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
pids := GetProjectIds()
selids, lids := getProjectList(pids)
choice := c.MultiChoice(lids, "Select a Project to Edit")
//c.Println(pids)
//c.Println(selids)
if choice > -1 {
editProject(selids[choice])
//c.Println(choice,selids[choice])
}
//c.Println(boldRed("editproject <id> - Please enter an id"))
//allProjects()
}
c.Println(promptcol("______________________"))
},
})
editcmd.AddCmd(&ishell.Cmd{
Name: "payment",
Help: "<id> Edit the Payment of the following id",
LongHelp: ` Usage: edit payment <id>
Edit Payment of the set <id>.
Press <Enter> on empty line to keep the old entry`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
EditPayment(argi)
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
selids, lids := GetPaymentList()
choice := c.MultiChoice(lids, "Select a Payment to Edit")
if choice > -1 {
EditPayment(selids[choice])
}
}
c.Println(promptcol("______________________"))
},
})
editcmd.AddCmd(&ishell.Cmd{
Name: "customer",
Help: "<id> Edit the Customer of the following id",
LongHelp: ` Usage: edit customer <id>
Edit Customer of the set <id>.
Press <Enter> on empty line to keep the old entry`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
editCustomer(argi)
allCustomers(false)
//stdOut()
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
selids, lids := getCustomerList()
choice := c.MultiChoice(lids, "Select a Customer to Edit")
if choice > -1 {
editCustomer(selids[choice])
}
//c.Println(boldRed("editcustomer <id> - Please enter an id"))
//allCustomers()
}
c.Println(promptcol("______________________"))
},
})
editcmd.AddCmd(&ishell.Cmd{
Name: "bill",
Help: "<id> Edit a Bill of the following id",
LongHelp: ` Usage: edit bill <id>
Edit Bill of the set <id>.
Press <Enter> on empty line to keep the old entry`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
editBill(argi)
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
tids := GetBillIds(false)
selids, lids := GetBillList(tids)
choice := c.MultiChoice(lids, "Select a Bill to Edit")
//c.Println(tids)
//c.Println(selids)
if choice > -1 {
editBill(selids[choice])
//c.Println(choice,selids[choice])
}
//c.Println(boldRed("edittask <id> - Please enter an id"))
}
c.Println(promptcol("______________________"))
},
})
shell.AddCmd(editcmd)
}
{
startcmd := &ishell.Cmd{
Name: "start",
Help: "<DateTime>/now - Start a Task",// at a specific Time 'YYYY-MM-DD HH:MM' Or 'HH:MM' Or 'now'",
LongHelp: ` Usage: start <DateTime>/now
Start a new Task in the currently open Project at <DateTime>.
Use Format "YYYY-MM-DD HH:MM" or "HH:MM" for datetime.
If the latter is used the current local Date will be set.
'now' will start the Task at current local time.`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
newTaskTime(arg)
stdOut()
} else {
c.Println(boldRed("start <DateTime> - Please enter a Datetime"))
}
c.Println(promptcol("______________________"))
},
}
startcmd.AddCmd(&ishell.Cmd{
Name: "now",
Help: "Start a new Task immediately",
LongHelp: ` Usage: start now
Start a new Task in the currently open Project with current local time`,
Func: func(c *ishell.Context) {
newTask(false)
stdOut()
c.Println(promptcol("______________________"))
},
})
shell.AddCmd(startcmd)
}
// STOP Command group
{
stopcmd := &ishell.Cmd{
Name: "stop",
Help: "<DateTime>/now - Stop Open Task",// at a specific Time 'YYYY-MM-DD HH:MM' Or 'HH:MM'",
LongHelp: ` Usage: stop <DateTime>/now
Stop the active Task at <DateTime>.
Use Format "YYYY-MM-DD HH:MM" or "HH:MM" for datetime.
If the latter is used the current local Date will be set.
'now' will stop the Task at current local time.
In case of a Stop-time before Task start user will be notified.`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
closeTaskTime(arg)
stdOut()
} else {
c.Println(boldRed("stop <DateTime> - Please enter a Datetime"))
}
c.Println(promptcol("______________________"))
},
}
stopcmd.AddCmd(&ishell.Cmd{
Name: "now",
Help: "Stop the currently Open Task immediately",
LongHelp: ` Usage: stop now
Stop the open Task at the current local time.
If no task is open the user will be notified.`,
Func: func(c *ishell.Context) {
closeTask(true)
stdOut()
c.Println(promptcol("______________________"))
},
})
shell.AddCmd(stopcmd)
}
// PRINT commans
{
printcmd := &ishell.Cmd{
Name: "print",
Help: "yyy / xxx / bills",
LongHelp: ` Usage: print <command>
Print Bills and Reports.`,
}
printcmd.AddCmd(&ishell.Cmd{
Name: "bills",
Help: "Print selected Bills again to pdf",
LongHelp: ` Usage: print bills
Show all Projects with a small summary, sorted by Customer.`,
Func: func(c *ishell.Context) {
tids := GetBillIds(false)
ids, str := GetBillList(tids)
choices := c.Checklist(str,
"Which Bills should be Printed again ?",
nil)
out := func() (c []int) {
for _, v := range choices {
if v > -1 {
c = append(c, ids[v])
}
}
return
}
prbills := loadBills(out())
if isInterSure(fmt.Sprintf("Print %v Bills?",len(prbills))) {
c.ProgressBar().Indeterminate(true)
c.ProgressBar().Start()
for i,_ := range prbills {
_, cust := GetProject(prbills[i].project)
files := billTemplate(prbills[i], cust)
err = runLatex(files.Main, prbills[i].identity)
}
c.ProgressBar().Stop()
if err == nil {
c.Println("Finished without Errors")
} else {
c.Println("Finished with error:", err)
}
c.Print("<<Continue>>")
c.ReadLine()
}else{
c.Println(boldRed("Charging Aborted"))
}
c.Println(promptcol("______________________"))
},
})
shell.AddCmd(printcmd)
}
// SHOW commands
{
showcmd := &ishell.Cmd{
Name: "show",
Help: "all / customers / bills / invoice / project",
LongHelp: ` Usage: show <command>`,
// Show all Projects with a small summary sorted by Customer.`,
}
showcmd.AddCmd(&ishell.Cmd{
Name: "all",
Help: "Show all Projects sorted by customers",
LongHelp: ` Usage: show all
Show all Projects with a small summary, sorted by Customer.`,
Func: func(c *ishell.Context) {
allProjects()
stdOut()
c.Println(promptcol("______________________"))
},
})
/* showcmd.AddCmd(&ishell.Cmd{
Name: "bills",
Help: "Show all Bills",
LongHelp: ` Usage: all bills
Show all previous Bills with small summary.`,
Func: func(c *ishell.Context) {
showLastBills(0)
c.Println(promptcol("______________________"))
},
}) */
showcmd.AddCmd(&ishell.Cmd{
Name: "customers",
Help: "Show all Customers",
LongHelp: ` Usage: all customers
Show all Customers.`,
Func: func(c *ishell.Context) {
allCustomers(false)
c.Println(promptcol("______________________"))
},
})
showcmd.AddCmd(&ishell.Cmd{
Name: "bills",
Help: "<n> - Show the last n bills. If no n specified all Bills are shown ",
LongHelp: ` Usage: show bills <n>
Show the last n Bills with a small summary. If no <n> is specified all bills are shown.`,
Func: func(c *ishell.Context) {
//c.ClearScreen()
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
showLastBills(argi)
} else {
c.Println(boldRed(arg, "is not a valid integer!"))
}
} else {
showLastBills(0)
//c.Println(boldRed("showbills <n> - Please enter an integer"))
}
//stdOut()
c.Println(promptcol("______________________"))
},
})
showcmd.AddCmd(&ishell.Cmd{
Name: "invoice",
Help: "<id> - Show details of the invoice with given id.",
LongHelp: ` Usage: show invoice <id>
Show detailed information of Invoice with given id. If no <id> is specified a selection screen is shown.`,
Func: func(c *ishell.Context) {
//c.ClearScreen()
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
if isBill(argi){
mid := []int{argi}
thebill := loadBills(mid)
ShowBill(thebill[0], true)
}else{
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
c.Println(boldRed(arg, "is not a valid integer!"))
}
} else {
tids := GetBillIds(false)
selids, lids := GetBillList(tids)
choice := c.MultiChoice(lids, "Select a Bill to Edit")
//c.Println(tids)
//c.Println(selids)
if choice > -1 {
mid := []int{selids[choice]}
thebill := loadBills(mid)
ShowBill(thebill[0], true)
}
}
//stdOut()
c.Println(promptcol("______________________"))
},
})
showcmd.AddCmd(&ishell.Cmd{
Name: "project",
Help: "<id> - Show details of the project with given id.",
LongHelp: ` Usage: show project <id>
Show detailed information of Project with given id. If no <id> is specified a selection screen is shown.`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
ShowProjectStatus(argi)
//allProjects()
//stdOut()
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
pids := GetProjectIds()
selids, lids := getProjectList(pids)
choice := c.MultiChoice(lids, "Select a Project to Show")
if choice > -1 {
ShowProjectStatus(selids[choice])
}
}
c.Println(promptcol("______________________"))
},
})
showcmd.AddCmd(&ishell.Cmd{
Name: "payment",
Help: "<id> - Show details of the payment with given id.",
LongHelp: ` Usage: show invoice <id>
Show detailed information of payment with given id. If no <id> is specified a selection screen is shown.`,
Func: func(c *ishell.Context) {
arg := "none"
if len(c.Args) > 0 {
arg = strings.Join(c.Args, " ")
argi, err := strconv.Atoi(arg)
if err == nil {
ShowPayment(argi)
//fmt.Println("COMING SOON")
//ShowProjectStatus(argi)
//allProjects()
//stdOut()
} else {
c.Println(boldRed(arg, "is not a valid id!"))
}
} else {
//pids := GetProjectIds()
selids, lids := GetPaymentList()
choice := c.MultiChoice(lids, "Select a Payment to Show")
if choice > -1 {
ShowPayment(selids[choice])
}
}
c.Println(promptcol("______________________"))
},
})
// Analysis commands
analcmd := &ishell.Cmd{
Name: "analysis",
Help: "monthly / yearly",
LongHelp: ` Usage: show analysis <command>`,
// Show all Projects with a small summary sorted by Customer.`,
}
analcmd.AddCmd(&ishell.Cmd{
Name: "monthly",
Help: "Show a montly Report of all available data",
LongHelp: ` Usage: show analysis monthly
Show a monthly report of all available data.`,
Func: func(c *ishell.Context) {
MakeAnalysis()
ShowMonthlyAnalysis()
stdOut()
c.Println(promptcol("______________________"))
},
})
analcmd.AddCmd(&ishell.Cmd{
Name: "yearly",
Help: "Show a yearly Report of all available data",
LongHelp: ` Usage: show analysis yearly
Show a yearly report of all available data.`,
Func: func(c *ishell.Context) {
MakeAnalysis()
ShowYearlyAnalysis()
stdOut()
c.Println(promptcol("______________________"))
},
})
showcmd.AddCmd(analcmd)
shell.AddCmd(showcmd)
}
/*
// multiple choice
shell.AddCmd(&ishell.Cmd{
Name: "choice",
Help: "multiple choice prompt",
Func: func(c *ishell.Context) {
choice := c.MultiChoice([]string{
"Golangers",
"Go programmers",
"Gophers",
"Goers",
}, "What are Go programmers called ?")
if choice == 2 {
c.Println("You got it!")
} else {
c.Println("Sorry, you're wrong.")
}
},
})
// multiple choice
shell.AddCmd(&ishell.Cmd{
Name: "checklist",
Help: "checklist prompt",
Func: func(c *ishell.Context) {
languages := []string{"Python", "Go", "Haskell", "Rust"}
choices := c.Checklist(languages,
"What are your favourite programming languages ?",
nil)
out := func() (c []string) {
for _, v := range choices {
c = append(c, languages[v])
}
return
}
c.Println("Your choices are", strings.Join(out(), ", "))
},
})
*/
//Test stuff in shell
{
//var autostuff = []string{"fuck This is Awsome","this cannot be real","shit my pants"}
testcmd := &ishell.Cmd{
Name: "test",
Help: "Test some functions in interactive mode",
LongHelp: ` Usage: test
Test functions in interactive mode`,
Func: func(c *ishell.Context) {
if len(c.Args) > 0 {
c.Println("SomeArgs",c.Args)
}else{
c.Println("No Args")
}
},
}
testcmd.AddCmd(&ishell.Cmd{
Name: "new",
Help: "Test export",
LongHelp: ` Usage: export
Test Export`,
Func: func(c *ishell.Context) {
c.Println("Said new!!!")
MakeAnalysis()
//getInterAutoInput("Really?",autostuff)
},
})
shell.AddCmd(testcmd)
}
// DATA commands
{
datacmd := &ishell.Cmd{
Name: "data",
Help: "import/export",
LongHelp: ` Usage: data <command>`,
}
datacmd.AddCmd(&ishell.Cmd{
Name: "export",
Help: "export data from db",
LongHelp: ` Usage: data export
Export data from customers, projects and all closed tasks
as csv files and tar them together`,
Func: func(c *ishell.Context) {
prid := GetProjectIds()
cuid := GetCustomerIds()
taid := GetTaskIds()
//biid := GetBillIds()
prs := GetSelectedProjects(prid)
cus := GetSelectedCustomers(cuid)
tas := GetSelectedTasks(taid)
bls := GetAllBills()
pys := GetAllPayments()
c.Println(frame(boldGreen("Export DB Data"),true))
c.Println(nli+"Customers:",len(cus))
c.Println(nli+" Projects:",len(prs))
c.Println(nli+" Tasks:",len(tas))
c.Println(nli+" Bills:",len(bls))
c.Println(nli+" Payments:",len(pys))
//c.Println("Customers:",cus)
if isInterSure(sli+"Export this data?"){
filen := getNewInterInput("Filename: ","export.tar",nli)
ExportCustomers(cus)
ExportProjects(prs)
ExportTasks(tas)
ExportBills(bls)
ExportPayments(pys)
TarExports(filen)
PurgeTemps()
c.Println(nli+"Data exported to",filen)
c.Println(frame(posR(),false))
}else{
c.Println(frame(negR(),false))
}
},
})
datacmd.AddCmd(&ishell.Cmd{
Name: "import",
Help: "import data into db",
LongHelp: ` Usage: data import
takes a tarball of csv data and imports it into the DB`,
Func: func(c *ishell.Context) {
//autostuff = append(autostuff,"scheissdreck")
c.Println(frame(boldGreen("Import Data into DB"),true))
filen := getNewInterInput("Filename: ","export.tar",nli)
err := UnTarExports(filen)
if err != nil {
c.Println(boldRed(err))
c.Println(frame(negR(),false))
return
}else{
c.Println(nli,boldGreen("File Loaded"))
c.Println(frame(posR(),false))
}
icus := ImportCustomers()
itas := ImportTasks()
iprs := ImportProjects()
ibls := ImportBills()
ipys := ImportPayments()
PurgeTemps()
//c.Println(sli,"Loaded Data")
//c.Println(nli,"Customers:",len(icus))
//c.Println(nli," Projects:",len(iprs))
//c.Println(nli," Tasks:",len(itas))
//if isInterSure(sli+"Import this into DB?"){
SaveImportsToDB(icus,iprs,itas,ibls,ipys)
//c.Println(boldGreen("Import Successful"))
//c.Println(frame(posR(),false))
//}else{
// c.Println(boldRed("Nothing Imported"))
// c.Println(frame(negR(),false))
//}
},
//c.Println("Projects:",iprs)
})
shell.AddCmd(datacmd)
}
// Config Commands
{
confcmd := &ishell.Cmd{
Name: "config",
Help: "View and Edit Configuration",
LongHelp: ` Usage: config [<commands>]
Show the current configuration and ask if it should be edited.
Configurations contains the location of the database file
and the Personal Data needed for charging.
If config is edited press <Enter> on empty line to keep the old entry`,
Func: func(c *ishell.Context) {
editConf()
c.Println(promptcol("______________________"))
},
}
// Prompt Color
confcmd.AddCmd(&ishell.Cmd{
Name: "color",
Help: "Select the Color of the prompt",
LongHelp: ` Usage: config color
Select the color of the prompt`,
Func: func(c *ishell.Context) {
choice := c.MultiChoice([]string{
boldMag("Magenta"),
boldBlue("Blue"),
boldCyan("Cyan"),
boldGreen("Green"),
boldYell("Yellow"),
boldRed("Red"),
}, "What Color should the Prompt be?")
promptcol = PromptColor(choice).SprintFunc()
//promptcol = mastercol.SprintFunc()
c.SetPrompt(promptcol(">>>"))
c.Println(promptcol("As You Wish!"))
c.Println(promptcol("______________________"))
},
})
shell.AddCmd(confcmd)
}
// Gather Tasks For Bills
shell.AddCmd(&ishell.Cmd{
Name: "charge",
Help: "Select Tasks to be charged",
LongHelp: ` Usage: charge
Select the tasks that should be merged into a Bill.
The Task selection cannot be changed afterward. The
bill can be deleted and a new selection made.`,
Func: func(c *ishell.Context) {
nix := []int{0}
ids, str := GetTaskList(nix, true,true)
choices := c.Checklist(str,
"Which Tasks should be charged in the new bill ?",
nil)
out := func() (c []int) {
for _, v := range choices {
if v > -1 {
c = append(c, ids[v])
}
}
return
}
//All selected ids
selids := out()
//bids,str2 := getTaskList(selids,false)
//c.Println(bids,str2)
c.Println(len(selids), "Tasks Selected")
//If None Selected end
if len(selids) == 0 {
return
}
//get if selected tasks have multicustomers, are from multipe projects, and get the ids of the projects
multicust, multiproj, projids := checkCustomerProjects(selids)
billprojid := 0
// CHECK IF ONLY ONE CUSTOMER
if multicust {
c.Println(boldRed("Cannot Write One Bill to multiple Customers! Please Select different Tasks"))
} else {
// CHECK IF ONLY ONE PROJECT ELSE CHOOSE ONE
if multiproj {
prid, prstr := getProjectList(projids)
sel := c.MultiChoice(prstr, "What Project Should be Billed ?")
if sel > -1 {
billprojid = prid[sel]
}
} else {
billprojid = projids[0]
}
seltasks := GetSelectedTasks(selids)
count, hours, dur := AnalyzeTasks(seltasks)
//c.Printf("%v Tasks Selected. Totaling %.2f (h) - Dates: %s\n",count,hours,dur)
proj, cust := GetProject(billprojid)
// IF CUSTOMER 0 NO BILL CAN BE CREATED
if cust.Id == 0 {
c.Println(boldRed("Customer ", cust.Company, " with id ", cust.Id, " Cannot be billed. Please move ", proj.Name, " to a valid Customer"))
return
}
//billid,billident := newBill(billprojid)
//prs,cus := getProjectName(billprojid)
//c.Println("For",cust.company,"-",cust.name)
//c.Println("Project:",proj.name,"- ID:",proj.id)
//c.Println("Projected Income:",hours*cust.satz,"€")
//c.Println("Create New Bill:",billid)
//c.ReadLine() //Make NEW BILL WITH ID and INV No
c.ShowPrompt(false)
//fullbillinfo := fmt.Sprintf("For: %s - %s - %.2f(€/h) - Invoice: %s Id:%v\nProject: %s - Id:%v\n%v Tasks Selected. Totaling %.2f (h) - Dates: %s\nProjected Income: %.2f(€)\n",cust.company,cust.name,cust.satz,billident,billid,proj.name,proj.id,count,hours,dur,hours*cust.satz)
fullbillinfo := fmt.Sprintf("For: %s - %s - %.2f(€/h) \nProject: %s - Id:%v\n%v Tasks Selected. Totaling %.2f (h) - Dates: %s\nProjected Income: %.2f(€)\n", cust.Company, cust.Name, cust.Satz, proj.Name, proj.Id, count, hours, dur, hours*cust.Satz)
sep := "-------------------------\n"
restinfo := "Here some Info about the rest"
restids := selids
var allitems []billitem
//allaccounted := false
//resttasks := seltasks
//SELECT SUBSET AND NAME BILLITEM
//c.clear()//Println(some,"Str2:",str2)
for {
doneinfo2 := ""
sumh := 0.0
if len(restids) == 0 {
break
}
for _,itm := range allitems {
doneinfo2 = fmt.Sprintf("%s %s - %v(h)\n",doneinfo2,itm.Task,itm.Hours)
sumh += itm.Hours
}
doneinfo1 := fmt.Sprintf("Already Billed: %v(h)\n",sumh)
doneinfo := fmt.Sprintf("%s%s",doneinfo1,doneinfo2)
resttasks := GetSelectedTasks(restids)
rcount, rhours, _ := AnalyzeTasks(resttasks)
rids, rstr := GetTaskList(restids, false,false)
qu := "Select Tasks to Group as Billitem"
restinfo = fmt.Sprintf("%v Tasks Left, Total %.2f(h)\n%s", rcount, rhours, qu)
pre := ""
if len(allitems) > 0{
pre = fmt.Sprintf("%s%s%s%s%s", fullbillinfo, sep,doneinfo,sep, restinfo)
}else{
pre = fmt.Sprintf("%s%s%s", fullbillinfo, sep, restinfo)
}
choices2 := c.Checklist(rstr, pre, nil)
out = func() (c []int) {
for _, v := range choices2 {
if v > -1 {
c = append(c, rids[v])
}
}
return
}
taskids := out()
restids = removeItems(restids, taskids)
if len(taskids) > 0 {
ittasks := GetSelectedTasks(taskids)
comm := GetSelectedComments(ittasks)
itcount, ithours, itdur := AnalyzeTasks(ittasks)
c.Printf("\n%v Tasks Selected, Total %.2f(h), Date: %s\n", itcount, ithours, itdur)
if len(comm) >0 {
c.Printf(" Comments on selected Tasks:\n%s\n",StrLines(comm," "))
}
c.ShowPrompt(false)
c.Print("Name your Item for the Bill: ")
tsk := c.ReadLine()
var hrf float64
for {
c.Print("How Many Hours: ")
hr := c.ReadLine()
hrf, err = strconv.ParseFloat(hr, 64)
if err != nil {
c.Println(hr, boldRed("can not be Parsed as a Float."), "Try a shape of X.X")
} else {
break
}
}
//c.Printf("%T %v - %T %v\n", tsk, tsk, hrf, hrf)
allitems = append(allitems, billitem{tsk, itdur, hrf, Round(hrf*cust.Satz, 1)})
c.Print("<<Continue>>")
c.ReadLine()
//c.ShowPrompt(true)
}
}
halfbill := bill{0, "None", dur, proj.Id, proj.Name, time.Time{}, time.Time{}, allitems, 0}
ShowBill(halfbill,false)
if isInterSure("Is this bill Correct?") {
billid, billident := newBill(billprojid)
//c.Println(green("Bill Completed"))
fullbill := bill{billid, billident, dur, proj.Id, proj.Name, time.Time{}, time.Time{}, allitems, 0}
saveBill(fullbill)
checkTasks(selids, billid)
c.ProgressBar().Indeterminate(true)
c.ProgressBar().Start()
testid := []int{billid}
testbill := loadBills(testid)
//c.Println(testbill[0].projectname,testbill[0].items)
files := billTemplate(testbill[0], cust)
c.Println(files)
err = runLatex(files.Main, testbill[0].identity)
c.ProgressBar().Stop()
if err == nil {
c.Println("Finished without Errors")
} else {
c.Println("Finished with error:", err)
}
c.Print("<<Continue>>")
c.ReadLine()
}else{
c.Println(boldRed("Charging Aborted"))
}
stdOut()
}
c.Println(promptcol("______________________"))
c.ShowPrompt(true)
},
})
// Decide if interactive mode should be started
//args := removeStringFromArray(os.Args[1:],"-file",1)
if len(interArgs) > 0 {
//args := removeStringFromArray(os.Args[1:],"-file",1)
//fmt.Println(args)
shell.Process(interArgs...)
} else {
//shell.Println("Starting interactive Shell")
stdOut()
//start shell
shell.Run()
// teardown
shell.Close()
}
//fmt.Println("Laboravi emeritus...")
}
func isInterSure(question string) bool {
shell := ishell.New()
shell.ShowPrompt(false)
defer shell.ShowPrompt(true)
shell.Printf("%s ('y/Y/yes' Default: n) : ", question)
line := shell.ReadLine()
if line == "yes" || line == "y" || line == "Y" {
return true
} else {
return false
}
}
/*
func getInterAutoInput(question string,autocom []string) (out string) {
shell := ishell.New()
shell.ShowPrompt(false)
defer shell.ShowPrompt(true)
shell.AddCmd(&ishell.Cmd{
Name: "",
Help: "never to be seen",
Completer: func([]string) []string {
return autocom},
Func: func(c *ishell.Context) {
c.Print(question)
//out = shell.ReadLine()
out = fmt.Sprint(c.Args)
},
})
//shell.SetRootCmd("fun")
shell.Run()
return
} */
func getInterInput(question string) (out string) {
shell := ishell.New()
shell.ShowPrompt(false)
defer shell.ShowPrompt(true)
shell.Print(question)
out = shell.ReadLine()
return
}
func getNewInterInput(question, old, border string) string {
shell := ishell.New()
shell.ShowPrompt(false)
defer shell.ShowPrompt(true)
if old != "" {
shell.Println(border+"Current:", old)
}
shell.Print(border+question)
line := shell.ReadLine()
if line == "" {
return old
} else {
return line
}
}
func getInterMultiInput(question string) (out string) {
shell := ishell.New()
//shell.ShowPrompt(false)
//defer shell.ShowPrompt(true)
shell.SetPrompt(nli+">>>")
shell.SetMultiPrompt(nli+"...")
shell.Println(question, "(Multiline input, end with ';')")
out = shell.ReadMultiLines(";")
shell.Println(sli+" -Done-")
return
}
func getNewInterMultiInput(question, old, border string) (out string) {
shell := ishell.New()
//shell.ShowPrompt(false)
//defer shell.ShowPrompt(true)
shell.SetPrompt(border+">>>")
shell.SetMultiPrompt(border+"...")
if old != "" {
shell.Println(border,"Current:\n", old)
shell.Println(border,"Should current entry be replaced? A Newline will be added otherwise")
}
if isInterSure(border+" ") {
shell.Println(border, question, "(Multiline input, end with ';')")
out = shell.ReadMultiLines(";")
shell.Println(border," -Done-")
} else {
shell.Print(nli+question)
txt := shell.ReadLine()
if txt == "" {
out = old
} else {
out = old + "\n" + txt
}
}
return
/*if line == "" {
return old
}else{
return line
}*/
}
// Invoke an Multiplechoice Question with a question and
// the list of options and return the selected list id
func Multichoice(question string,list []string) (int) {
shell := ishell.New()
marker := li+li+">"
shell.SetMultiChoicePrompt(marker,nli)
shell.SetChecklistOptions("[ ] ", "[X] ")
qu1 := line(marker,false)
qu2 := frame(question,true)
quest := qu1 + strings.TrimLeft(qu2,"\n")
choice := -1
choice = shell.MultiChoice(list,quest)
return choice
/*shell.AddCmd(&ishell.Cmd{
Name: "choice",
Help: "multiple choice prompt",
Func: func(c *ishell.Context) {
choice := c.MultiChoice([]string{
"Golangers",
"Go programmers",
"Gophers",
"Goers",
}, "What are Go programmers called ?")
if choice == 2 {
c.Println("You got it!")
} else {
c.Println("Sorry, you're wrong.")
}
},
})
str := "choice"
shell.Process(str)
shell.Println(about)*/
}
// Invoke a Checklist Question with a leading Question
// line and return an int slice of the selected rows of the list
func Checklist(question string, list []string) ([]int) {
shell := ishell.New()
marker := li+li+">"
shell.SetMultiChoicePrompt(marker,nli)
shell.SetChecklistOptions("[ ] ", "[X] ")
qu1 := line(marker,false)
qu2 := frame(question,true)
quest := qu1 + strings.TrimLeft(qu2,"\n")
choices := shell.Checklist(list,quest,nil)
return choices
}
|