-
Notifications
You must be signed in to change notification settings - Fork 762
/
trep-engine.scm
2293 lines (2031 loc) · 97.5 KB
/
trep-engine.scm
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; trep-engine.scm : Transaction Report engine
;;
;; Original report by Robert Merkel <rgmerk@mira.net>
;; Contributions by Bryan Larsen <blarsen@ada-works.com>
;; More contributions for new report generation code by Robert Merkel
;; More contributions by Christian Stimming <stimming@tuhh.de>
;; Modified to support the intersection of two account lists by
;; Michael T. Garrison Stuber
;; Modified account names display by Tomas Pospisek
;; <tpo_deb@sourcepole.ch> with a lot of help from "warlord"
;; Refactored by Christopher Lam (2017)
;; - introduced account/transaction substring/regex matcher
;; - add custom sorter in scheme
;; - common currency - optionally show original currency amount
;; and enable multiple data columns
;; - add support for indenting for better grouping
;; - add subtotal summary grid
;; - by default, exclude closing transactions from the report
;; - converted to module in 2019
;; - CSV export, exports the report headers and totals
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA gnu@gnu.org
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (gnucash report trep-engine))
(use-modules (gnucash core-utils))
(use-modules (gnucash engine))
(use-modules (gnucash app-utils))
(use-modules (gnucash utilities))
(use-modules (gnucash report report-core)
(gnucash report report-utilities)
(gnucash report options-utilities)
(gnucash report commodity-utilities)
(gnucash report html-document)
(gnucash report html-style-info)
(gnucash report html-utilities)
(gnucash report html-table)
(gnucash report html-text))
(use-modules (srfi srfi-11))
(use-modules (srfi srfi-1))
(use-modules (ice-9 match))
(export gnc:trep-options-generator)
(export gnc:trep-renderer)
(export gnc:lists->csv)
;; Define the strings here to avoid typos and make changes easier.
;;Accounts
(define optname-accounts (N_ "Accounts"))
(define optname-filterby (N_ "Filter By..."))
(define optname-filtertype (N_ "Filter Type"))
;;Display
(define optname-detail-level (N_ "Detail Level"))
(define optname-grid (N_ "Subtotal Table"))
;;Sorting
(define pagename-sorting (N_ "Sorting"))
(define optname-prime-sortkey (N_ "Primary Key"))
(define optname-prime-subtotal (N_ "Primary Subtotal"))
(define optname-prime-sortorder (N_ "Primary Sort Order"))
(define optname-prime-date-subtotal (N_ "Primary Subtotal for Date Key"))
(define optname-full-account-name (N_ "Show Full Account Name"))
(define optname-show-account-code (N_ "Show Account Code"))
(define optname-show-account-description (N_ "Show Account Description"))
(define optname-show-informal-headers (N_ "Show Informal Debit/Credit Headers"))
(define optname-show-subtotals-only
(N_ "Show subtotals only (hide transactional data)"))
(define optname-indenting (N_ "Add indenting columns"))
(define optname-sec-sortkey (N_ "Secondary Key"))
(define optname-sec-subtotal (N_ "Secondary Subtotal"))
(define optname-sec-sortorder (N_ "Secondary Sort Order"))
(define optname-sec-date-subtotal (N_ "Secondary Subtotal for Date Key"))
;;General
(define optname-startdate (N_ "Start Date"))
(define optname-enddate (N_ "End Date"))
(define optname-date-source (N_ "Date Filter"))
(define optname-table-export (N_ "Table for Exporting"))
(define optname-infobox-display (N_ "Add options summary"))
;; Currency
(define pagename-currency (N_ "Currency"))
(define optname-price-source (N_ "Price Source"))
(define optname-common-currency (N_ "Common Currency"))
(define optname-orig-currency (N_ "Show original currency amount"))
(define optname-currency (N_ "Report's currency"))
;;Filtering
(define pagename-filter (N_ "Filter"))
(define optname-account-matcher (N_ "Account Name Filter"))
(define optname-account-matcher-regex
(N_ "Use regular expressions for account name filter"))
(define optname-account-matcher-exclude
(N_ "Account Name Filter excludes matched strings"))
(define optname-transaction-matcher (N_ "Transaction Filter"))
(define optname-transaction-matcher-regex
(N_ "Use regular expressions for transaction filter"))
(define optname-transaction-matcher-exclude
(N_ "Transaction Filter excludes matched strings"))
(define optname-transaction-matcher-caseinsensitive
(N_ "Transaction Filter is case insensitive"))
(define optname-reconcile-status (N_ "Reconciled Status"))
(define optname-void-transactions (N_ "Void Transactions"))
(define optname-closing-transactions (N_ "Closing transactions"))
;;Styles
(define def:grand-total-style "grand-total")
(define def:normal-row-style "normal-row")
(define def:alternate-row-style "alternate-row")
(define def:primary-subtotal-style "primary-subheading")
(define def:secondary-subtotal-style "secondary-subheading")
(define NO-MATCHING-TRANS-HEADER (G_ "No matching transactions found"))
(define NO-MATCHING-TRANS-TEXT (G_ "No transactions were found that \
match the time interval and account selection specified \
in the Options panel."))
(define DATE-SORTING-TYPES
(list 'date 'reconciled-date))
(define ACCOUNT-SORTING-TYPES
(list 'account-name 'corresponding-acc-name
'account-code 'corresponding-acc-code))
(define SORTKEY-INFORMAL-HEADERS
(list 'account-name 'account-code))
(define reconcile-list
(list (cons #\n (G_ "Unreconciled"))
(cons #\c (G_ "Cleared"))
(cons #\y (G_ "Reconciled"))
(cons #\f (G_ "Frozen"))
(cons #\v (G_ "Voided"))))
(define (sortkey-list split-action?)
;; Defines the different sorting keys, as an association-list
;; together with the subtotal functions. Each entry:
;; 'sortkey - sort parameter sent via qof-query
;; 'split-sortvalue - function retrieves number/string for comparing splits
;; 'text - text displayed in Display tab
;; 'renderer-fn - helper function to select subtotal/subheading renderer
;; behaviour varies according to sortkey.
;; account-types converts split->account
;; #f means the sortkey cannot be subtotalled
;; otherwise it converts split->string
;;
(list (list 'account-name
(cons 'sortkey (list SPLIT-ACCT-FULLNAME))
(cons 'split-sortvalue
(compose gnc-account-get-full-name xaccSplitGetAccount))
(cons 'text (G_ "Account Name"))
(cons 'renderer-fn xaccSplitGetAccount))
(list 'account-code
(cons 'sortkey (list SPLIT-ACCOUNT ACCOUNT-CODE-))
(cons 'split-sortvalue (compose xaccAccountGetCode xaccSplitGetAccount))
(cons 'text (G_ "Account Code"))
(cons 'renderer-fn xaccSplitGetAccount))
(list 'date
(cons 'sortkey (list SPLIT-TRANS TRANS-DATE-POSTED))
(cons 'split-sortvalue (compose xaccTransGetDate xaccSplitGetParent))
(cons 'text (G_ "Date"))
(cons 'renderer-fn #f))
(list 'reconciled-date
(cons 'sortkey (list SPLIT-DATE-RECONCILED))
(cons 'split-sortvalue xaccSplitGetDateReconciled)
(cons 'text (G_ "Reconciled Date"))
(cons 'renderer-fn #f))
(list 'reconciled-status
(cons 'sortkey #f)
(cons 'split-sortvalue (lambda (s)
(length (memv (xaccSplitGetReconcile s)
(map car reconcile-list)))))
(cons 'text (G_ "Reconciled Status"))
(cons 'renderer-fn (lambda (s)
(assv-ref reconcile-list
(xaccSplitGetReconcile s)))))
(list 'register-order
(cons 'sortkey (list QUERY-DEFAULT-SORT))
(cons 'split-sortvalue #f)
(cons 'text (G_ "Register Order"))
(cons 'renderer-fn #f))
(list 'corresponding-acc-name
(cons 'sortkey (list SPLIT-CORR-ACCT-NAME))
(cons 'split-sortvalue xaccSplitGetCorrAccountFullName)
(cons 'text (G_ "Other Account Name"))
(cons 'renderer-fn (compose xaccSplitGetAccount xaccSplitGetOtherSplit)))
(list 'corresponding-acc-code
(cons 'sortkey (list SPLIT-CORR-ACCT-CODE))
(cons 'split-sortvalue xaccSplitGetCorrAccountCode)
(cons 'text (G_ "Other Account Code"))
(cons 'renderer-fn (compose xaccSplitGetAccount xaccSplitGetOtherSplit)))
(list 'amount
(cons 'sortkey (list SPLIT-VALUE))
(cons 'split-sortvalue xaccSplitGetValue)
(cons 'text (G_ "Amount"))
(cons 'renderer-fn #f))
(list 'description
(cons 'sortkey (list SPLIT-TRANS TRANS-DESCRIPTION))
(cons 'split-sortvalue (compose xaccTransGetDescription
xaccSplitGetParent))
(cons 'text (G_ "Description"))
(cons 'renderer-fn (compose xaccTransGetDescription xaccSplitGetParent)))
(if split-action?
(list 'number
(cons 'sortkey (list SPLIT-ACTION))
(cons 'split-sortvalue xaccSplitGetAction)
(cons 'text (G_ "Number/Action"))
(cons 'renderer-fn #f))
(list 'number
(cons 'sortkey (list SPLIT-TRANS TRANS-NUM))
(cons 'split-sortvalue (compose xaccTransGetNum xaccSplitGetParent))
(cons 'text (G_ "Number"))
(cons 'renderer-fn #f)))
(list 't-number
(cons 'sortkey (list SPLIT-TRANS TRANS-NUM))
(cons 'split-sortvalue (compose xaccTransGetNum xaccSplitGetParent))
(cons 'text (G_ "Transaction Number"))
(cons 'renderer-fn #f))
(list 'memo
(cons 'sortkey (list SPLIT-MEMO))
(cons 'split-sortvalue xaccSplitGetMemo)
(cons 'text (G_ "Memo"))
(cons 'renderer-fn xaccSplitGetMemo))
(list 'notes
(cons 'sortkey #f)
(cons 'split-sortvalue (compose xaccTransGetNotes xaccSplitGetParent))
(cons 'text (G_ "Notes"))
(cons 'renderer-fn (compose xaccTransGetNotes xaccSplitGetParent)))
(list 'none
(cons 'sortkey '())
(cons 'split-sortvalue #f)
(cons 'text (G_ "None"))
(cons 'renderer-fn #f))))
(define (time64-year t64)
(gnc:date-get-year (gnc-localtime t64)))
(define (time64-quarter t64)
(+ (* 10 (gnc:date-get-year (gnc-localtime t64)))
(gnc:date-get-quarter (gnc-localtime t64))))
(define (time64-month t64)
(+ (* 100 (gnc:date-get-year (gnc-localtime t64)))
(gnc:date-get-month (gnc-localtime t64))))
(define (time64-week t64)
(gnc:date-get-week (gnc-localtime t64)))
(define (time64-day t64)
(+ (* 500 (gnc:date-get-year (gnc-localtime t64)))
(gnc:date-get-year-day (gnc-localtime t64))))
(define (split->time64 s)
(xaccTransGetDate (xaccSplitGetParent s)))
(define date-subtotal-list
;; List for date option.
;; Defines the different date sorting keys, as an association-list. Each entry:
;; 'split-sortvalue - func retrieves number/string used for comparing splits
;; 'text - text displayed in Display tab
;; 'renderer-fn - func retrieves string for subtotal/subheading renderer
;; #f means the date sortkey is not grouped
;; otherwise it converts split->string
(list
(list 'none
(cons 'split-sortvalue #f)
(cons 'date-sortvalue #f)
(cons 'text (G_ "None"))
(cons 'renderer-fn #f))
(list 'daily
(cons 'split-sortvalue (lambda (s) (time64-day (split->time64 s))))
(cons 'date-sortvalue time64-day)
(cons 'text (G_ "Daily"))
(cons 'renderer-fn (lambda (s) (qof-print-date (split->time64 s)))))
(list 'weekly
(cons 'split-sortvalue (lambda (s) (time64-week (split->time64 s))))
(cons 'date-sortvalue time64-week)
(cons 'text (G_ "Weekly"))
(cons 'renderer-fn (compose gnc:date-get-week-year-string
gnc-localtime
split->time64)))
(list 'monthly
(cons 'split-sortvalue (lambda (s) (time64-month (split->time64 s))))
(cons 'date-sortvalue time64-month)
(cons 'text (G_ "Monthly"))
(cons 'renderer-fn (compose gnc:date-get-month-year-string
gnc-localtime
split->time64)))
(list 'quarterly
(cons 'split-sortvalue (lambda (s) (time64-quarter (split->time64 s))))
(cons 'date-sortvalue time64-quarter)
(cons 'text (G_ "Quarterly"))
(cons 'renderer-fn (compose gnc:date-get-quarter-year-string
gnc-localtime
split->time64)))
(list 'yearly
(cons 'split-sortvalue (lambda (s) (time64-year (split->time64 s))))
(cons 'date-sortvalue time64-year)
(cons 'text (G_ "Yearly"))
(cons 'renderer-fn (compose gnc:date-get-year-string
gnc-localtime
split->time64)))))
(define filter-list
(list
(list 'none
(cons 'text (G_ "Do not do any filtering")))
(list 'include
(cons 'text (G_ "Include Transactions to/from Filter Accounts")))
(list 'exclude
(cons 'text (G_ "Exclude Transactions to/from Filter Accounts")))))
(define show-void-list
(list
(list 'non-void-only
(cons 'how (logand CLEARED-ALL (lognot CLEARED-VOIDED)))
(cons 'text (G_ "Non-void only")))
(list 'void-only
(cons 'how CLEARED-VOIDED)
(cons 'text (G_ "Void only")))
(list 'both
(cons 'how CLEARED-ALL)
(cons 'text (G_ "Both (and include void transactions in totals)")))))
(define show-closing-list
(list
(list 'exclude-closing
(cons 'text (G_ "Exclude closing transactions"))
(cons 'closing-match #f))
(list 'include-both
(cons 'text (G_ "Show both closing and regular transactions"))
(cons 'closing-match 'both))
(list 'closing-only
(cons 'text (G_ "Show closing transactions only"))
(cons 'closing-match #t))))
(define reconcile-status-list
;; 'filter-types must be either #f (i.e. disable reconcile filter)
;; or a value defined as defined in Query.c
;; e.g. CLEARED-NO for unreconciled
;; (logior CLEARED-NO CLEARED-CLEARED) for unreconciled & cleared
(list
(list 'all
(cons 'text (G_ "Show All Transactions"))
(cons 'filter-types CLEARED-ALL))
(list 'unreconciled
(cons 'text (G_ "Unreconciled only"))
(cons 'filter-types CLEARED-NO))
(list 'cleared
(cons 'text (G_ "Cleared only"))
(cons 'filter-types CLEARED-CLEARED))
(list 'reconciled
(cons 'text (G_ "Reconciled only"))
(cons 'filter-types CLEARED-RECONCILED))))
(define ascending-list
(list
(list 'ascend
(cons 'text (G_ "Ascending")))
(list 'descend
(cons 'text (G_ "Descending")))))
(define sign-reverse-list
(list
(list 'global
(cons 'text (G_ "Use Global Preference"))
(cons 'acct-types #f))
(list 'none
(cons 'text (G_ "Don't change any displayed amounts"))
(cons 'acct-types '()))
(list 'income-expense
(cons 'text (G_ "Income and Expense"))
(cons 'acct-types (list ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE)))
(list 'credit-accounts
(cons 'text (G_ "Credit Accounts"))
(cons 'acct-types (list ACCT-TYPE-LIABILITY ACCT-TYPE-PAYABLE
ACCT-TYPE-EQUITY ACCT-TYPE-CREDIT
ACCT-TYPE-INCOME)))))
(define (keylist-get-info keylist key info)
(assq-ref (assq-ref keylist key) info))
(define (keylist->vectorlist keylist)
(map
(lambda (item)
(vector
(car item)
(keylist-get-info keylist (car item) 'text)))
keylist))
(define (SUBTOTAL-ENABLED? sortkey split-action?)
;; this returns whether sortkey *can* be subtotalled/grouped.
;; it checks whether a renderer-fn is defined.
(keylist-get-info (sortkey-list split-action?) sortkey 'renderer-fn))
(define (CUSTOM-SORTING? sortkey split-action?)
;; sortkey -> bool
;;
;; this returns which sortkeys which *must* use the custom sorter.
;; it filters whereby a split-sortvalue is defined (i.e. the splits
;; can be compared according to their 'sortvalue) but the QofQuery
;; sortkey is not defined (i.e. their 'sortkey is #f).
(and (keylist-get-info (sortkey-list split-action?) sortkey 'split-sortvalue)
(not (keylist-get-info (sortkey-list split-action?) sortkey 'sortkey))))
(define (lists->csv lst)
;; converts a list of lists into CSV
;; this function aims to follow RFC4180, and will pad lists to
;; ensure equal number of items per row.
;; e.g. '(("from" "01/01/2010")
;; ("to" "31/12/2010")
;; ("total" 23500 30000 25/7 'sym))
;; will output
;; "from","01/01/2010",,,
;; "to","31/12/2010",,,
;; "total",23500.0,30000.0,3.5714285714285716,sym
(define (string-sanitize-csv str)
(call-with-output-string
(lambda (port)
(display #\" port)
(string-for-each
(lambda (c)
(if (char=? c #\") (display #\" port))
(display c port))
str)
(display #\" port))))
(define max-items
(let lp ((lst lst) (maximum 0))
(cond
((null? lst) maximum)
((pair? lst) (lp (cdr lst) (max maximum (length (car lst)))))
(else (error "strify " lst " must be a proper list")))))
(define (strify obj)
(cond
((or (null? obj) (not obj)) "")
((string? obj) (string-sanitize-csv obj))
((number? obj) (number->string (exact->inexact obj)))
((pair? obj) (let lp ((row obj) (acc '()) (pad max-items))
(cond
((zero? pad) (string-concatenate-reverse acc))
((null? row) (lp '() (cons "," acc) (1- pad)))
((pair? row) (lp (cdr row)
(cons* (if (pair? (cdr row)) "," "")
(strify (car row))
acc)
(1- pad)))
(else (error "strify " obj " must be a proper list")))))
((gnc:gnc-monetary? obj) (strify (gnc:gnc-monetary-amount obj)))
(else (object->string obj))))
(string-join (map strify lst) "\n"))
(define gnc:lists->csv lists->csv)
;;
;; Default Transaction Report
;;
(define (gnc:trep-options-generator)
(define options (gnc:new-options))
(define BOOK-SPLIT-ACTION
(qof-book-use-split-action-for-num-field (gnc-get-current-book)))
(define (gnc:register-trep-option new-option)
(gnc:register-option options new-option))
;; (Feb 2018) Note to future hackers - this gnc:trep-options-generator
;; defines a long set of options to be assigned as an object in
;; the report. This long list (52 at Feb 2018 count) of options
;; may be modified in a derived report (see income-gst-statement.scm)
;; via gnc:make-internal! and gnc-unregister-option to hide
;; and remove options, respectively. If an option is unregistered,
;; don't forget to re-register them via gnc:register-option, unless
;; your derived report truly does not require them.
;; General options
(gnc:options-add-date-interval!
options gnc:pagename-general optname-startdate optname-enddate "a")
(gnc:register-trep-option
(gnc:make-multichoice-option
gnc:pagename-general optname-date-source
"a5" (G_ "Specify date to filter by...")
'posted
(list (vector 'posted (G_ "Date Posted"))
(vector 'reconciled (G_ "Reconciled Date"))
(vector 'entered (G_ "Date Entered")))))
(gnc:register-trep-option
(gnc:make-complex-boolean-option
pagename-currency optname-common-currency
"a" (G_ "Convert all transactions into a common currency.") #f #f
(lambda (x)
(gnc-option-db-set-option-selectable-by-name
options pagename-currency optname-currency x)
(gnc-option-db-set-option-selectable-by-name
options pagename-currency optname-orig-currency x)
(gnc-option-db-set-option-selectable-by-name
options pagename-currency optname-price-source x))))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-currency optname-orig-currency
"b" (G_ "Also show original currency amounts") #f))
(gnc:options-add-currency!
options pagename-currency optname-currency "c")
(gnc:options-add-price-source!
options pagename-currency optname-price-source "d" 'pricedb-nearest)
(gnc:register-trep-option
(gnc:make-simple-boolean-option
gnc:pagename-general optname-table-export
"g" (G_ "Formats the table suitable for cut & paste exporting with extra cells.")
#f))
(gnc:register-trep-option
(gnc:make-multichoice-option
gnc:pagename-general optname-infobox-display
"h" (G_ "Add summary of options.")
'no-match
;; This is an alist of conditions for displaying the infobox
;; 'no-match for empty-report
;; 'match for generated report
(list (vector 'no-match (G_ "If no transactions matched"))
(vector 'always (G_ "Always"))
(vector 'never (G_ "Never")))))
;; Filtering Options
(gnc:register-trep-option
(gnc:make-string-option
pagename-filter optname-account-matcher
"a5" (G_ "Show only accounts whose full name matches this filter e.g. ':Travel' will match \
Expenses:Travel:Holiday and Expenses:Business:Travel. It can be left blank, which will \
disable the filter.")
""))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-account-matcher-regex
"a6"
(G_ "By default the account filter will search substring only. Set this to true to \
enable full POSIX regular expressions capabilities. 'Car|Flights' will match both \
Expenses:Car and Expenses:Flights. Use a period (.) to match a single character e.g. \
'20../.' will match 'Travel 2017/1 London'. ")
#f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-account-matcher-exclude "a7"
(G_ "If this option is selected, accounts matching filter are excluded.")
#f))
(gnc:register-trep-option
(gnc:make-string-option
pagename-filter optname-transaction-matcher
"i1" (G_ "Show only transactions where description, notes, or memo matches this filter.
e.g. '#gift' will find all transactions with #gift in description, notes or memo. It can be left \
blank, which will disable the filter.")
""))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-transaction-matcher-regex
"i2"
(G_ "By default the transaction filter will search substring only. Set this to true to \
enable full POSIX regular expressions capabilities. '#work|#family' will match both \
tags within description, notes or memo.")
#f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-transaction-matcher-exclude
"i3"
(G_ "If this option is selected, transactions matching filter are excluded.")
#f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-transaction-matcher-caseinsensitive
"i4"
(G_ "If this option is selected, transactions matching filter is not case sensitive.")
#f))
(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-filter optname-reconcile-status
"j1" (G_ "Filter by reconcile status.")
'all
(keylist->vectorlist reconcile-status-list)))
(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-filter optname-void-transactions
"k" (N_ "How to handle void transactions.")
'non-void-only
(keylist->vectorlist show-void-list)))
(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-filter optname-closing-transactions
"l" (G_ "By default most users should not include closing \
transactions in a transaction report. Closing transactions are \
transfers from income and expense accounts to equity, and must usually \
be excluded from periodic reporting.")
'exclude-closing
(keylist->vectorlist show-closing-list)))
;; Accounts options
;; account to do report on
(gnc:register-trep-option
(gnc:make-account-list-option
gnc:pagename-accounts optname-accounts
"a" (G_ "Report on these accounts.")
;; select, by default, no accounts! Selecting all accounts will
;; always imply an insanely long waiting time upon opening, and it
;; is almost never useful. So we instead display the normal error
;; message saying "Click here", and the user knows how to
;; continue.
(lambda ()
'())
#f #t))
(gnc:register-trep-option
(gnc:make-account-list-option
gnc:pagename-accounts optname-filterby
"c1" (G_ "Filter on these accounts.")
(lambda ()
'())
#f #t))
(gnc:register-trep-option
(gnc:make-multichoice-callback-option
gnc:pagename-accounts optname-filtertype
"c" (G_ "Filter account.")
'none
(keylist->vectorlist filter-list)
#f
(lambda (x)
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-accounts optname-filterby
(not (eq? x 'none))))))
;; Sorting options
(let ((ascending-choice-list (keylist->vectorlist ascending-list))
(key-choice-list (keylist->vectorlist (sortkey-list BOOK-SPLIT-ACTION)))
(date-subtotal-choice-list (keylist->vectorlist date-subtotal-list))
(prime-sortkey 'account-name)
(prime-sortkey-subtotal-true #t)
(prime-date-subtotal 'monthly)
(sec-sortkey 'register-order)
(sec-sortkey-subtotal-true #f)
(sec-date-subtotal 'monthly))
(define (apply-selectable-by-name-sorting-options)
(let* ((prime-sortkey-enabled (not (eq? prime-sortkey 'none)))
(prime-sortkey-subtotal-enabled
(SUBTOTAL-ENABLED? prime-sortkey BOOK-SPLIT-ACTION))
(prime-date-sortingtype-enabled (memq prime-sortkey DATE-SORTING-TYPES))
(sec-sortkey-enabled (not (eq? sec-sortkey 'none)))
(sec-sortkey-subtotal-enabled
(SUBTOTAL-ENABLED? sec-sortkey BOOK-SPLIT-ACTION))
(sec-date-sortingtype-enabled (memq sec-sortkey DATE-SORTING-TYPES)))
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-prime-subtotal
prime-sortkey-subtotal-enabled)
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-prime-sortorder
prime-sortkey-enabled)
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-sec-subtotal
sec-sortkey-subtotal-enabled)
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-sec-sortorder
sec-sortkey-enabled)
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-full-account-name
(or (and prime-sortkey-subtotal-enabled prime-sortkey-subtotal-true)
(and sec-sortkey-subtotal-enabled sec-sortkey-subtotal-true)))
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-show-account-code
(or (and prime-sortkey-subtotal-enabled prime-sortkey-subtotal-true)
(and sec-sortkey-subtotal-enabled sec-sortkey-subtotal-true)))
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-show-account-description
(or (and prime-sortkey-subtotal-enabled prime-sortkey-subtotal-true)
(and sec-sortkey-subtotal-enabled sec-sortkey-subtotal-true)))
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-indenting
(or (and prime-sortkey-subtotal-enabled prime-sortkey-subtotal-true)
(and sec-sortkey-subtotal-enabled sec-sortkey-subtotal-true)
(and prime-date-sortingtype-enabled (not (eq? 'none prime-date-subtotal)))
(and sec-date-sortingtype-enabled (not (eq? 'none sec-date-subtotal)))))
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-show-subtotals-only
(or (and prime-sortkey-subtotal-enabled prime-sortkey-subtotal-true)
(and sec-sortkey-subtotal-enabled sec-sortkey-subtotal-true)
(and prime-date-sortingtype-enabled (not (eq? 'none prime-date-subtotal)))
(and sec-date-sortingtype-enabled (not (eq? 'none sec-date-subtotal)))))
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-show-informal-headers
(or (memq prime-sortkey (list 'account-name 'account-code))
(memq sec-sortkey (list 'account-name 'account-code))))
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-prime-date-subtotal
prime-date-sortingtype-enabled)
(gnc-option-db-set-option-selectable-by-name
options pagename-sorting optname-sec-date-subtotal
sec-date-sortingtype-enabled)))
;; primary sorting criterion
(gnc:register-trep-option
(gnc:make-multichoice-callback-option
pagename-sorting optname-prime-sortkey
"a" (G_ "Sort by this criterion first.")
prime-sortkey
key-choice-list #f
(lambda (x)
(set! prime-sortkey x)
(apply-selectable-by-name-sorting-options))))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-sorting optname-full-account-name
"j1"
(G_ "Show the full account name for subtotals and subheadings?")
#f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-sorting optname-show-account-code
"j2"
(G_ "Show the account code for subtotals and subheadings?")
#f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-sorting optname-show-account-description
"j3"
(G_ "Show the account description for subheadings?")
#f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-sorting optname-show-informal-headers
"j4"
(G_ "Show the informal headers for debit/credit accounts?")
#f))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-sorting optname-indenting
"j5"
(G_ "Add indenting columns with grouping and subtotals?")
#t))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-sorting optname-show-subtotals-only
"j6"
(G_ "Show subtotals only, hiding transactional detail?")
#f))
(gnc:register-trep-option
(gnc:make-complex-boolean-option
pagename-sorting optname-prime-subtotal
"e5"
(G_ "Subtotal according to the primary key?")
prime-sortkey-subtotal-true #f
(lambda (x)
(set! prime-sortkey-subtotal-true x)
(apply-selectable-by-name-sorting-options))))
(gnc:register-trep-option
(gnc:make-multichoice-callback-option
pagename-sorting optname-prime-date-subtotal
"e2" (G_ "Do a date subtotal.")
prime-date-subtotal
date-subtotal-choice-list #f
(lambda (x)
(set! prime-date-subtotal x)
(apply-selectable-by-name-sorting-options))))
(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-sorting optname-prime-sortorder
"e" (G_ "Order of primary sorting.")
'ascend
ascending-choice-list))
;; Secondary sorting criterion
(gnc:register-trep-option
(gnc:make-multichoice-callback-option
pagename-sorting optname-sec-sortkey
"f"
(G_ "Sort by this criterion second.")
sec-sortkey
key-choice-list #f
(lambda (x)
(set! sec-sortkey x)
(apply-selectable-by-name-sorting-options))))
(gnc:register-trep-option
(gnc:make-complex-boolean-option
pagename-sorting optname-sec-subtotal
"i5"
(G_ "Subtotal according to the secondary key?")
sec-sortkey-subtotal-true #f
(lambda (x)
(set! sec-sortkey-subtotal-true x)
(apply-selectable-by-name-sorting-options))))
(gnc:register-trep-option
(gnc:make-multichoice-callback-option
pagename-sorting optname-sec-date-subtotal
"i2" (G_ "Do a date subtotal.")
sec-date-subtotal
date-subtotal-choice-list #f
(lambda (x)
(set! sec-date-subtotal x)
(apply-selectable-by-name-sorting-options))))
(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-sorting optname-sec-sortorder
"i" (G_ "Order of Secondary sorting.")
'ascend
ascending-choice-list)))
;; Display options
(let ((disp-memo? #t)
(disp-accname? #f)
(disp-other-accname? #t)
(disp-detail-level? 'single)
(amount-value 'double))
(define (apply-selectable-by-name-display-options)
(define detail-is-single? (eq? disp-detail-level? 'single))
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display (N_ "Use Full Account Name")
disp-accname?)
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display (N_ "Other Account Name")
detail-is-single?)
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display (N_ "Sign Reverses")
(eq? amount-value 'single))
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display optname-grid
(not (eq? amount-value 'none)))
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display "Enable Links"
(not (eq? amount-value 'none)))
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display (N_ "Use Full Other Account Name")
(and disp-other-accname? detail-is-single?))
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display (N_ "Other Account Code")
detail-is-single?)
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display (N_ "Notes")
disp-memo?))
(for-each
(lambda (l)
(gnc:register-trep-option
(gnc:make-simple-boolean-option
gnc:pagename-display (car l) (cadr l) (caddr l) (cadddr l))))
;; One list per option here with: option-name, sort-tag,
;; help-string, default-value
(list
(list (N_ "Date") "a" (G_ "Display the date?") #t)
(list (N_ "Reconciled Date") "a2" (G_ "Display the reconciled date?") #f)
(list (N_ "Date Entered") "a3" (G_ "Display the entered date?") #f)
(if BOOK-SPLIT-ACTION
(list (N_ "Num/Action") "b" (G_ "Display the check number?") #t)
(list (N_ "Num") "b" (G_ "Display the check number?") #t))
(list (N_ "Description") "c" (G_ "Display the description?") #t)
(list (N_ "Notes") "d2" (G_ "Display the notes if the memo is unavailable?") #t)
;; account name option appears here
(list (N_ "Use Full Account Name") "f" (G_ "Display the full account name?") #t)
(list (N_ "Account Code") "g" (G_ "Display the account code?") #f)
;; other account name option appears here
(list (N_ "Use Full Other Account Name") "i" (G_ "Display the full account name?") #f)
(list (N_ "Other Account Code") "j" (G_ "Display the other account code?") #f)
(list (N_ "Shares") "k" (G_ "Display the number of shares?") #f)
(list (N_ "Link") "l5" (G_ "Display the transaction linked document") #f)
(list (N_ "Price") "l" (G_ "Display the shares price?") #f)
;; note the "Amount" multichoice option in between here
(list optname-grid "m5" (G_ "Display a subtotal summary table.") #f)
(list (N_ "Running Balance") "n" (G_ "Display a running balance?") #f)
(list (N_ "Totals") "o" (G_ "Display the totals?") #t)))
(when BOOK-SPLIT-ACTION
(gnc:register-trep-option
(gnc:make-simple-boolean-option
gnc:pagename-display (N_ "Trans Number")
"b2" (G_ "Display the trans number?") #f)))
;; Add an option to display the memo, and disable the notes option
;; when memos are not included.
(gnc:register-trep-option
(gnc:make-complex-boolean-option
gnc:pagename-display (N_ "Memo")
"d" (G_ "Display the memo?") disp-memo? #f
(lambda (x)
(set! disp-memo? x)
(apply-selectable-by-name-display-options))))
;; Ditto for Account Name #t -> Use Full Account Name is selectable
(gnc:register-trep-option
(gnc:make-complex-boolean-option
gnc:pagename-display (N_ "Account Name")
"e" (G_ "Display the account name?") disp-accname? #f
(lambda (x)
(set! disp-accname? x)
(apply-selectable-by-name-display-options))))
;; Ditto for Other Account Name #t -> Use Full Other Account Name is selectable
(gnc:register-trep-option
(gnc:make-complex-boolean-option
gnc:pagename-display (N_ "Other Account Name")
"h5" (G_ "Display the other account name? (if this is a split transaction, this parameter is guessed).") disp-other-accname? #f
(lambda (x)
(set! disp-other-accname? x)
(apply-selectable-by-name-display-options))))
(gnc:register-trep-option
(gnc:make-multichoice-callback-option