-
Notifications
You must be signed in to change notification settings - Fork 760
/
transaction.scm
1328 lines (1142 loc) · 60.1 KB
/
transaction.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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; transaction-report.scm : Report on all transactions in account(s)
;;
;; 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
;;
;; 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 standard-reports transaction))
(use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing.
(use-modules (srfi srfi-1))
(use-modules (srfi srfi-13))
(use-modules (ice-9 regex))
(use-modules (gnucash gnc-module))
(use-modules (gnucash gettext))
(use-modules (gnucash printf))
(gnc:module-load "gnucash/report/report-system" 0)
(define-macro (addto! alist element)
`(set! ,alist (cons ,element ,alist)))
;; Define the strings here to avoid typos and make changes easier.
(define reportname (N_ "Transaction Report"))
;;Accounts
(define optname-accounts (N_ "Accounts"))
(define optname-filterby (N_ "Filter By..."))
(define optname-filtertype (N_ "Filter Type"))
(define optname-void-transactions (N_ "Void Transactions"))
;;Display
(define optname-detail-level (N_ "Detail Level"))
;;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-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-table-export (N_ "Table for Exporting"))
(define optname-common-currency (N_ "Common Currency"))
(define optname-currency (N_ "Report's currency"))
;;Filtering
(define pagename-filter (N_ "Filter"))
(define optname-account-matcher (N_ "Account Matcher"))
(define optname-account-matcher-regex (N_ "Account Matcher uses regular expressions for extended matching"))
(define optname-transaction-matcher (N_ "Transaction Matcher"))
(define optname-transaction-matcher-regex (N_ "Transaction Matcher uses regular expressions for extended matching"))
(define optname-reconcile-status (N_ "Reconcile Status"))
;;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 (_ "No matching transactions found"))
(define NO-MATCHING-TRANS-TEXT (_ "No transactions were found that \
match the time interval and account selection specified \
in the Options panel."))
(define NO-MATCHING-ACCT-HEADER (N_ "No matching accounts found"))
(define NO-MATCHING-ACCT-TEXT (N_ "No account were found that match the \
options specified in the Options panels."))
(define DATE-SORTING-TYPES (list 'date 'reconciled-date))
;; The option-values of the sorting key multichoice option, for
;; which a subtotal should be enabled.
(define SUBTOTAL-ENABLED (list 'account-name 'corresponding-acc-name
'account-code 'corresponding-acc-code))
(define sortkey-list
;;
;; 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 which retrieves number/string used for comparing splits
;; 'text - text displayed in Display tab
;; 'tip - tooltip displayed in Display tab
;; 'renderer-key - helper symbol to select subtotal/subheading renderer
;;
(list (cons 'account-name (list (cons 'sortkey (list SPLIT-ACCT-FULLNAME))
(cons 'split-sortvalue (lambda (a) (gnc-account-get-full-name (xaccSplitGetAccount a))))
(cons 'text (N_ "Account Name"))
(cons 'tip (N_ "Sort & subtotal by account name."))
(cons 'renderer-key 'account)))
(cons 'account-code (list (cons 'sortkey (list SPLIT-ACCOUNT ACCOUNT-CODE-))
(cons 'split-sortvalue (lambda (a) (xaccAccountGetCode (xaccSplitGetAccount a))))
(cons 'text (N_ "Account Code"))
(cons 'tip (N_ "Sort & subtotal by account code."))
(cons 'renderer-key 'account)))
(cons 'date (list (cons 'sortkey (list SPLIT-TRANS TRANS-DATE-POSTED))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Date"))
(cons 'tip (N_ "Sort by date."))
(cons 'renderer-key #f)))
(cons 'reconciled-date (list (cons 'sortkey (list SPLIT-DATE-RECONCILED))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Reconciled Date"))
(cons 'tip (N_ "Sort by the Reconciled Date."))
(cons 'renderer-key #f)))
(cons 'register-order (list (cons 'sortkey (list QUERY-DEFAULT-SORT))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Register Order"))
(cons 'tip (N_ "Sort as in the register."))
(cons 'renderer-key #f)))
(cons 'corresponding-acc-name (list (cons 'sortkey (list SPLIT-CORR-ACCT-NAME))
(cons 'split-sortvalue (lambda (a) (xaccSplitGetCorrAccountFullName a)))
(cons 'text (N_ "Other Account Name"))
(cons 'tip (N_ "Sort by account transferred from/to's name."))
(cons 'renderer-key 'other-acc)))
(cons 'corresponding-acc-code (list (cons 'sortkey (list SPLIT-CORR-ACCT-CODE))
(cons 'split-sortvalue (lambda (a) (xaccSplitGetCorrAccountCode a)))
(cons 'text (N_ "Other Account Code"))
(cons 'tip (N_ "Sort by account transferred from/to's code."))
(cons 'renderer-key 'other-acct)))
(cons 'amount (list (cons 'sortkey (list SPLIT-VALUE))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Amount"))
(cons 'tip (N_ "Sort by amount."))
(cons 'renderer-key #f)))
(cons 'description (list (cons 'sortkey (list SPLIT-TRANS TRANS-DESCRIPTION))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Description"))
(cons 'tip (N_ "Sort by description."))
(cons 'renderer-key #f)))
(if (qof-book-use-split-action-for-num-field (gnc-get-current-book))
(cons 'number (list (cons 'sortkey (list SPLIT-ACTION))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Number/Action"))
(cons 'tip (N_ "Sort by check number/action."))
(cons 'renderer-key #f)))
(cons 'number (list (cons 'sortkey (list SPLIT-TRANS TRANS-NUM))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Number"))
(cons 'tip (N_ "Sort by check/transaction number."))
(cons 'renderer-key #f))))
(cons 't-number (list (cons 'sortkey (list SPLIT-TRANS TRANS-NUM))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Transaction Number"))
(cons 'tip (N_ "Sort by transaction number."))
(cons 'renderer-key #f)))
(cons 'memo (list (cons 'sortkey (list SPLIT-MEMO))
(cons 'split-sortvalue #f)
(cons 'text (N_ "Memo"))
(cons 'tip (N_ "Sort by memo."))
(cons 'renderer-key #f)))
(cons 'none (list (cons 'sortkey '())
(cons 'split-sortvalue #f)
(cons 'text (N_ "None"))
(cons 'tip (N_ "Do not sort."))
(cons 'renderer-key #f)))))
(define (sortkey-get-info sortkey info)
(cdr (assq info (cdr (assq sortkey sortkey-list)))))
(define (timepair-year tp) (gnc:timepair-get-year tp))
(define (timepair-quarter tp) (+ (* 10 (timepair-year tp)) (gnc:timepair-get-quarter tp)))
(define (timepair-month tp) (+ (* 100 (timepair-year tp)) (gnc:timepair-get-month tp)))
(define (timepair-week tp) (+ (* 100 (timepair-year tp)) (gnc:timepair-get-week tp)))
(define (split-week a) (timepair-week (gnc-transaction-get-date-posted (xaccSplitGetParent a))))
(define (split-month a) (timepair-month (gnc-transaction-get-date-posted (xaccSplitGetParent a))))
(define (split-quarter a) (timepair-quarter (gnc-transaction-get-date-posted (xaccSplitGetParent a))))
(define (split-year a) (timepair-year (gnc-transaction-get-date-posted (xaccSplitGetParent a))))
(define date-subtotal-list
;; List for date option.
;; Defines the different date sorting keys, as an association-list. Each entry:
;; 'split-sortvalue - function which retrieves number/string used for comparing splits
;; 'text - text displayed in Display tab
;; 'tip - tooltip displayed in Display tab
;; 'renderer-key - helper symbol to select subtotal/subheading renderer
(list
(cons 'none (list
(cons 'split-sortvalue #f)
(cons 'text (N_ "None"))
(cons 'tip (N_ "None."))
(cons 'renderer-key #f)))
(cons 'weekly (list
(cons 'split-sortvalue split-week)
(cons 'text (N_ "Weekly"))
(cons 'tip (N_ "Weekly."))
(cons 'renderer-key 'week)))
(cons 'monthly (list
(cons 'split-sortvalue split-month)
(cons 'text (N_ "Monthly"))
(cons 'tip (N_ "Monthly."))
(cons 'renderer-key 'month)))
(cons 'quarterly (list
(cons 'split-sortvalue split-quarter)
(cons 'text (N_ "Quarterly"))
(cons 'tip (N_ "Quarterly."))
(cons 'renderer-key 'quarter)))
(cons 'yearly (list
(cons 'split-sortvalue split-year)
(cons 'text (N_ "Yearly"))
(cons 'tip (N_ "Yearly."))
(cons 'renderer-key 'year)))))
(define (date-subtotal-get-info sortkey info)
(cdr (assq info (cdr (assq sortkey date-subtotal-list)))))
(define (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))
;; General options
(gnc:options-add-date-interval!
options gnc:pagename-general optname-startdate optname-enddate "a")
(gnc:register-trep-option
(gnc:make-complex-boolean-option
gnc:pagename-general optname-common-currency
"e" (N_ "Convert all transactions into a common currency.") #f
#f
(lambda (x) (gnc-option-db-set-option-selectable-by-name
options gnc:pagename-general optname-currency
x))))
(gnc:options-add-currency!
options gnc:pagename-general optname-currency "f")
(gnc:register-trep-option
(gnc:make-simple-boolean-option
gnc:pagename-general optname-table-export
"g" (N_ "Formats the table suitable for cut & paste exporting with extra cells.") #f))
;; Filtering Options
(gnc:register-trep-option
(gnc:make-string-option
pagename-filter optname-account-matcher
"a5" (N_ "Match only accounts whose fullname is matched e.g. ':Travel' will match \
Expenses:Travel:Holiday and Expenses:Business:Travel. It can be left blank, which will \
disable the matcher.")
""))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-account-matcher-regex
"a6"
(N_ "By default the account matcher 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-string-option
pagename-filter optname-transaction-matcher
"i1" (N_ "Match only transactions whose substring is matched e.g. '#gift' \
will find all transactions with #gift in description, notes or memo. It can be left \
blank, which will disable the matcher.")
""))
(gnc:register-trep-option
(gnc:make-simple-boolean-option
pagename-filter optname-transaction-matcher-regex
"i2"
(N_ "By default the transaction matcher 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-multichoice-option
pagename-filter optname-reconcile-status
"j1" (N_ "Filter by reconcile status.")
#f
(list (vector #f (N_ "All") (N_ "Show All Transactions"))
(vector '(#\n) (N_ "Unreconciled") (N_ "Unreconciled only"))
(vector '(#\c) (N_ "Cleared") (N_ "Cleared only"))
(vector '(#\y) (N_ "Reconciled") (N_ "Reconciled only")))))
;; Accounts options
;; account to do report on
(gnc:register-trep-option
(gnc:make-account-list-option
gnc:pagename-accounts optname-accounts
"a" (N_ "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
"b" (N_ "Filter on these accounts.")
(lambda ()
'())
#f #t))
(gnc:register-trep-option
(gnc:make-multichoice-option
gnc:pagename-accounts optname-filtertype
"c" (N_ "Filter account.")
'none
(list (vector 'none
(N_ "None")
(N_ "Do not do any filtering."))
(vector 'include
(N_ "Include Transactions to/from Filter Accounts")
(N_ "Include transactions to/from filter accounts only."))
(vector 'exclude
(N_ "Exclude Transactions to/from Filter Accounts")
(N_ "Exclude transactions to/from all filter accounts.")))))
;;
(gnc:register-trep-option
(gnc:make-multichoice-option
gnc:pagename-accounts optname-void-transactions
"d" (N_ "How to handle void transactions.")
'non-void-only
(list
(vector 'non-void-only (N_ "Non-void only") (N_ "Show only non-voided transactions."))
(vector 'void-only (N_ "Void only") (N_ "Show only voided transactions."))
(vector 'both (N_ "Both") (N_ "Show both (and include void transactions in totals).")))))
;; Sorting options
(let ((ascending-choice-list
(list (vector 'ascend
(N_ "Ascending")
(N_ "Smallest to largest, earliest to latest."))
(vector 'descend
(N_ "Descending")
(N_ "Largest to smallest, latest to earliest."))))
(prime-sortkey 'account-name)
(prime-sortkey-subtotal-true #t)
(sec-sortkey 'register-order)
(sec-sortkey-subtotal-true #f)
(key-choice-list (map
(lambda (sortpair)
(vector
(car sortpair)
(sortkey-get-info (car sortpair) 'text)
(sortkey-get-info (car sortpair) 'tip)))
sortkey-list))
(date-subtotal-choice-list (map
(lambda (date-sortpair)
(vector
(car date-sortpair)
(date-subtotal-get-info (car date-sortpair) 'text)
(date-subtotal-get-info (car date-sortpair) 'tip)))
date-subtotal-list)))
(define (apply-selectable-by-name-sorting-options)
(let* ((prime-sortkey-enabled (not (eq? prime-sortkey 'none)))
(prime-sortkey-subtotal-enabled (member prime-sortkey SUBTOTAL-ENABLED))
(prime-date-sortingtype-enabled (member prime-sortkey DATE-SORTING-TYPES))
(sec-sortkey-enabled (not (eq? sec-sortkey 'none)))
(sec-sortkey-subtotal-enabled (member sec-sortkey SUBTOTAL-ENABLED))
(sec-date-sortingtype-enabled (member 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-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" (N_ "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"
(N_ "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"
(N_ "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"
(N_ "Show the account description for subheadings?")
#f))
(gnc:register-trep-option
(gnc:make-complex-boolean-option
pagename-sorting optname-prime-subtotal
"e5"
(N_ "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-option
pagename-sorting optname-prime-date-subtotal
"e2" (N_ "Do a date subtotal.")
'monthly
date-subtotal-choice-list))
(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-sorting optname-prime-sortorder
"e" (N_ "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"
(N_ "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"
(N_ "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-option
pagename-sorting optname-sec-date-subtotal
"i2" (N_ "Do a date subtotal.")
'monthly
date-subtotal-choice-list))
(gnc:register-trep-option
(gnc:make-multichoice-option
pagename-sorting optname-sec-sortorder
"i" (N_ "Order of Secondary sorting.")
'ascend
ascending-choice-list)))
;; Display options
(let ((disp-memo? #t)
(disp-accname? #t)
(disp-other-accname? #f)
(is-single? #t))
(define (apply-selectable-by-name-display-options)
(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")
is-single?)
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display (N_ "Use Full Other Account Name")
(and disp-other-accname? is-single?))
(gnc-option-db-set-option-selectable-by-name
options gnc:pagename-display (N_ "Other Account Code")
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" (N_ "Display the date?") #t)
(list (N_ "Reconciled Date") "a2" (N_ "Display the reconciled date?") #f)
(if BOOK-SPLIT-ACTION
(list (N_ "Num/Action") "b" (N_ "Display the check number?") #t)
(list (N_ "Num") "b" (N_ "Display the check number?") #t))
(list (N_ "Description") "c" (N_ "Display the description?") #t)
(list (N_ "Notes") "d2" (N_ "Display the notes if the memo is unavailable?") #t)
;; account name option appears here
(list (N_ "Use Full Account Name") "f" (N_ "Display the full account name?") #t)
(list (N_ "Account Code") "g" (N_ "Display the account code?") #f)
;; other account name option appears here
(list (N_ "Use Full Other Account Name") "i" (N_ "Display the full account name?") #f)
(list (N_ "Other Account Code") "j" (N_ "Display the other account code?") #f)
(list (N_ "Shares") "k" (N_ "Display the number of shares?") #f)
(list (N_ "Price") "l" (N_ "Display the shares price?") #f)
;; note the "Amount" multichoice option in between here
(list (N_ "Running Balance") "n" (N_ "Display a running balance?") #f)
(list (N_ "Totals") "o" (N_ "Display the totals?") #t)))
(if BOOK-SPLIT-ACTION
(gnc:register-trep-option
(gnc:make-simple-boolean-option
gnc:pagename-display (N_ "Trans Number")
"b2" (N_ "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" (N_ "Display the memo?") #t
disp-memo?
(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" (N_ "Display the account name?") #t
disp-accname?
(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" (N_ "Display the other account name? (if this is a split transaction, this parameter is guessed).") #f
disp-other-accname?
(lambda (x)
(set! disp-other-accname? x)
(apply-selectable-by-name-display-options))))
(gnc:register-trep-option
(gnc:make-multichoice-callback-option
gnc:pagename-display optname-detail-level
"h" (N_ "Amount of detail to display per transaction.")
'single
(list (vector 'multi-line
(N_ "Multi-Line")
(N_ "Display all splits in a transaction on a separate line."))
(vector 'single
(N_ "Single")
(N_ "Display one line per transaction, merging multiple splits where required.")))
#f
(lambda (x)
(set! is-single? (eq? x 'single))
(apply-selectable-by-name-display-options))))
(gnc:register-trep-option
(gnc:make-multichoice-option
gnc:pagename-display (N_ "Amount")
"m" (N_ "Display the amount?")
'single
(list
(vector 'none (N_ "None") (N_ "No amount display."))
(vector 'single (N_ "Single") (N_ "Single Column Display."))
(vector 'double (N_ "Double") (N_ "Two Column Display.")))))
(gnc:register-trep-option
(gnc:make-multichoice-option
gnc:pagename-display (N_ "Sign Reverses")
"p" (N_ "Reverse amount display for certain account types.")
'credit-accounts
(list (vector 'none
(N_ "None")
(N_ "Don't change any displayed amounts."))
(vector 'income-expense
(N_ "Income and Expense")
(N_ "Reverse amount display for Income and Expense Accounts."))
(vector 'credit-accounts
(N_ "Credit Accounts")
(N_ "Reverse amount display for Liability, Payable, Equity, \
Credit Card, and Income accounts."))))))
(gnc:options-set-default-section options gnc:pagename-general)
options)
;; ;;;;;;;;;;;;;;;;;;;;
;; Here comes the big function that builds the whole table.
(define (make-split-table splits options
primary-subtotal-comparator
secondary-subtotal-comparator
primary-renderer-key
secondary-renderer-key)
(define (opt-val section name) (gnc:option-value (gnc:lookup-option options section name)))
(define BOOK-SPLIT-ACTION (qof-book-use-split-action-for-num-field (gnc-get-current-book)))
(define (build-columns-used)
(define is-single? (eq? (opt-val gnc:pagename-display optname-detail-level) 'single))
(define amount-setting (opt-val gnc:pagename-display (N_ "Amount")))
(list (cons 'date (opt-val gnc:pagename-display (N_ "Date")))
(cons 'reconciled-date (opt-val gnc:pagename-display (N_ "Reconciled Date")))
(cons 'num (if BOOK-SPLIT-ACTION
(opt-val gnc:pagename-display (N_ "Num/Action"))
(opt-val gnc:pagename-display (N_ "Num"))))
(cons 'description (opt-val gnc:pagename-display (N_ "Description")))
(cons 'account-name (opt-val gnc:pagename-display (N_ "Account Name")))
(cons 'other-account-name (and is-single?
(opt-val gnc:pagename-display (N_ "Other Account Name"))))
(cons 'shares (opt-val gnc:pagename-display (N_ "Shares")))
(cons 'price (opt-val gnc:pagename-display (N_ "Price")))
(cons 'amount-single (eq? amount-setting 'single))
(cons 'amount-double (eq? amount-setting 'double))
(cons 'running-balance (opt-val gnc:pagename-display (N_ "Running Balance")))
(cons 'account-full-name (opt-val gnc:pagename-display (N_ "Use Full Account Name")))
(cons 'memo (opt-val gnc:pagename-display (N_ "Memo")))
(cons 'account-code (opt-val gnc:pagename-display (N_ "Account Code")))
(cons 'other-account-code (and is-single?
(opt-val gnc:pagename-display (N_ "Other Account Code"))))
(cons 'other-account-full-name (and is-single?
(opt-val gnc:pagename-display (N_ "Use Full Other Account Name"))))
(cons 'sort-account-code (opt-val pagename-sorting (N_ "Show Account Code")))
(cons 'sort-account-full-name (opt-val pagename-sorting (N_ "Show Full Account Name")))
(cons 'sort-account-description (opt-val pagename-sorting (N_ "Show Account Description")))
(cons 'notes (opt-val gnc:pagename-display (N_ "Notes")))))
(define (column-uses? param columns-used)
(cdr (assq param columns-used)))
(define (make-heading-list columns-used)
(define (add-if pred? . items) (if pred? items '()))
(append
(add-if (column-uses? 'date columns-used)
(_ "Date"))
(add-if (column-uses? 'reconciled-date columns-used)
(_ "Reconciled Date"))
(add-if (column-uses? 'num columns-used)
(if (and (qof-book-use-split-action-for-num-field (gnc-get-current-book))
(opt-val gnc:pagename-display (N_ "Trans Number")))
(_ "Num/T-Num")
(_ "Num")))
(add-if (column-uses? 'description columns-used)
(_ "Description"))
(add-if (column-uses? 'memo columns-used)
(if (column-uses? 'notes columns-used)
(string-append (_ "Memo") "/" (_ "Notes"))
(_ "Memo")))
(add-if (or (column-uses? 'account-name columns-used)
(column-uses? 'account-code columns-used))
(_ "Account"))
(add-if (or (column-uses? 'other-account-name columns-used)
(column-uses? 'other-account-code columns-used))
(_ "Transfer from/to"))
(add-if (column-uses? 'shares columns-used)
(_ "Shares"))
(add-if (column-uses? 'price columns-used)
(_ "Price"))
(add-if (column-uses? 'amount-single columns-used)
(_ "Amount"))
;; FIXME: Proper labels: what?
(add-if (column-uses? 'amount-double columns-used)
(_ "Debit")
(_ "Credit"))
(add-if (column-uses? 'running-balance columns-used)
(_ "Balance"))))
(let* ((work-to-do (length splits))
(work-done 0)
(table (gnc:make-html-table))
(used-columns (build-columns-used))
(headings (make-heading-list used-columns))
(width (length headings))
(account-types-to-reverse
(case (opt-val gnc:pagename-display (N_ "Sign Reverses"))
((none) '())
((income-expense) (list ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE))
((credit-accounts) (list ACCT-TYPE-LIABILITY ACCT-TYPE-PAYABLE
ACCT-TYPE-EQUITY ACCT-TYPE-CREDIT
ACCT-TYPE-INCOME))))
(is-multiline? (eq? (opt-val gnc:pagename-display optname-detail-level) 'multi-line))
(export? (opt-val gnc:pagename-general optname-table-export)))
(define (add-subheading data subheading-style)
(let ((heading-cell (gnc:make-html-table-cell data)))
(gnc:html-table-cell-set-colspan! heading-cell width)
(gnc:html-table-append-row/markup!
table subheading-style
(list heading-cell))))
(define (add-subtotal-row string collector style)
(let ((currency-totals (collector 'format gnc:make-gnc-monetary #f)))
(gnc:html-table-append-row/markup!
table style
(if export?
(append! (cons (gnc:make-html-table-cell/markup "total-label-cell" string)
(gnc:html-make-empty-cells (- width 2)))
(list (gnc:make-html-table-cell/markup
"total-number-cell"
(car currency-totals))))
(list (gnc:make-html-table-cell/size/markup 1 (- width 1) "total-label-cell"
string)
(gnc:make-html-table-cell/markup
"total-number-cell"
(car currency-totals)))))
(for-each (lambda (currency)
(gnc:html-table-append-row/markup!
table style
(append!
(if export?
(gnc:html-make-empty-cells (- width 1))
(list (gnc:make-html-table-cell/size 1 (- width 1) #f)))
(list (gnc:make-html-table-cell/markup
"total-number-cell" currency)))))
(cdr currency-totals))))
(define (total-string str) (string-append (_ "Total For ") str))
;; display an account name depending on the options the user has set
(define (account-namestring account show-account-code? show-account-name? show-account-full-name?)
;;# on multi-line splits we can get an empty ('()) account
(if (null? account)
(_ "Split Transaction")
(string-append
;; display account code?
(if show-account-code?
(string-append (xaccAccountGetCode account) " ")
"")
;; display account name?
(if show-account-name?
;; display full account name?
(if show-account-full-name?
(gnc-account-get-full-name account)
(xaccAccountGetName account))
""))))
(define (render-date renderer-key split)
((case renderer-key
((week) gnc:date-get-week-year-string)
((month) gnc:date-get-month-year-string)
((quarter) gnc:date-get-quarter-year-string)
((year) gnc:date-get-year-string))
(gnc:timepair->date
(gnc-transaction-get-date-posted
(xaccSplitGetParent split)))))
(define (render-account renderer-key split anchor?)
(let* ((account (case renderer-key
((account) (xaccSplitGetAccount split))
((other-acc) (xaccSplitGetAccount (xaccSplitGetOtherSplit split)))))
(name (account-namestring account
(column-uses? 'sort-account-code used-columns)
#t
(column-uses? 'sort-account-full-name used-columns)))
(description (if (and (column-uses? 'sort-account-description used-columns)
(not (string-null? (xaccAccountGetDescription account))))
(string-append ": " (xaccAccountGetDescription account))
"")))
(if (and anchor? (not (null? account))) ;html anchor for 2-split transactions only
(gnc:make-html-text
(gnc:html-markup-anchor (gnc:account-anchor-text account) name)
description)
name)))
(define (render-summary split renderer-key anchor?)
(case renderer-key
((week month quarter year) (render-date renderer-key split))
((account other-acc) (render-account renderer-key split anchor?))
(else #f)))
(define (render-grand-total)
(_ "Grand Total"))
(define (add-split-row split row-style transaction-row?)
(let* ((row-contents '())
(parent (xaccSplitGetParent split))
(account (xaccSplitGetAccount split))
(account-type (xaccAccountGetType account))
(currency (if (null? account)
(gnc-default-currency)
(xaccAccountGetCommodity account)))
(report-currency (if (opt-val gnc:pagename-general optname-common-currency)
(opt-val gnc:pagename-general optname-currency)
currency))
(damount (if (gnc:split-voided? split)
(xaccSplitVoidFormerAmount split)
(xaccSplitGetAmount split)))
(trans-date (gnc-transaction-get-date-posted parent))
(split-value (gnc:exchange-by-pricedb-nearest
(gnc:make-gnc-monetary
currency
(if (member account-type account-types-to-reverse)
(gnc-numeric-neg damount)
damount))
report-currency
;; Use midday as the transaction time so it matches a price
;; on the same day. Otherwise it uses midnight which will
;; likely match a price on the previous day
(timespecCanonicalDayTime trans-date))))
(if (column-uses? 'date used-columns)
(addto! row-contents
(if transaction-row?
(gnc:make-html-table-cell/markup
"date-cell"
(gnc-print-date trans-date))
"")))
(if (column-uses? 'reconciled-date used-columns)
(addto! row-contents
(gnc:make-html-table-cell/markup
"date-cell"
(let ((date (gnc-split-get-date-reconciled split)))
(if (equal? date (cons 0 0))
""
(gnc-print-date date))))))
(if (column-uses? 'num used-columns)
(addto! row-contents
(if transaction-row?
(if BOOK-SPLIT-ACTION
(let* ((num (gnc-get-num-action parent split))
(t-num (if (if (gnc:lookup-option options gnc:pagename-display
(N_ "Trans Number"))
(opt-val gnc:pagename-display (N_ "Trans Number"))
"")
(gnc-get-num-action parent #f)
""))
(num-string (if (string-null? t-num)
num
(string-append num "/" t-num))))
(gnc:make-html-table-cell/markup "text-cell" num-string))
(gnc:make-html-table-cell/markup "text-cell"
(gnc-get-num-action parent split)))
"")))
(if (column-uses? 'description used-columns)
(addto! row-contents
(if transaction-row?
(gnc:make-html-table-cell/markup
"text-cell"
(xaccTransGetDescription parent))
"")))
(if (column-uses? 'memo used-columns)
(let ((memo (xaccSplitGetMemo split)))
(if (and (string-null? memo) (column-uses? 'notes used-columns))
(addto! row-contents (xaccTransGetNotes parent))
(addto! row-contents memo))))
(if (or (column-uses? 'account-name used-columns) (column-uses? 'account-code used-columns))
(addto! row-contents (account-namestring account
(column-uses? 'account-code used-columns)
(column-uses? 'account-name used-columns)
(column-uses? 'account-full-name used-columns))))
(if (or (column-uses? 'other-account-name used-columns) (column-uses? 'other-account-code used-columns))
(addto! row-contents (account-namestring (xaccSplitGetAccount (xaccSplitGetOtherSplit split))
(column-uses? 'other-account-code used-columns)
(column-uses? 'other-account-name used-columns)
(column-uses? 'other-account-full-name used-columns))))
(if (column-uses? 'shares used-columns)
(addto! row-contents (xaccSplitGetAmount split)))
(if (column-uses? 'price used-columns)
(addto! row-contents (gnc:make-gnc-monetary (xaccTransGetCurrency parent)
(xaccSplitGetSharePrice split))))
(if (column-uses? 'amount-single used-columns)
(addto! row-contents
(gnc:make-html-table-cell/markup
"number-cell" (gnc:html-transaction-anchor parent split-value))))
(if (column-uses? 'amount-double used-columns)
(if (gnc-numeric-positive-p (gnc:gnc-monetary-amount split-value))
(begin
(addto! row-contents
(gnc:make-html-table-cell/markup
"number-cell" (gnc:html-transaction-anchor
parent split-value)))
(addto! row-contents ""))
(begin
(addto! row-contents "")
(addto! row-contents
(gnc:make-html-table-cell/markup
"number-cell" (gnc:html-transaction-anchor
parent (gnc:monetary-neg split-value)))))))