-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDumpTransaction.pm
More file actions
162 lines (146 loc) · 2.78 KB
/
DumpTransaction.pm
File metadata and controls
162 lines (146 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package DumpTransaction;
use warnings;
use strict;
our @EXPORT_OK = qw( delete_used_fields delete_unused_fields dump_transaction );
use Exporter;
use base 'Exporter';
# All transactions include all fields, whether or not they're needed.
# During debugging, it's useful to dump the raw input data. But we
# don't need to dump things that don't matter.
my @globally_irrelevant_fields = (
'',
'Action',
'Balance',
'Billed Date',
'Class',
'Credit',
'Debit',
'Deliv Date',
'Entered/Last Modified',
'Estimate Active',
'FOB',
'Last modified by',
'Open Balance',
'P. O. #',
'Print',
'Rep',
'Split', # TODO - Is this really not necessary?
'State',
'Terms',
'Via',
);
my @not_an_invoice = (
'Aging',
'Item Description',
'Item',
'Qty',
'Sales Price',
'Ship Date',
);
my @not_billable = (
'Billing Status',
);
my @not_payable = (
'Payment',
);
my @not_a_payment = (
'Pay Meth',
);
my @not_due = (
'Due Date',
);
my %irrelevant_fields = (
'Credit Card Charge' => [
@globally_irrelevant_fields,
@not_a_payment,
@not_an_invoice,
@not_due,
@not_payable,
],
'Bill' => [
@globally_irrelevant_fields,
@not_a_payment,
@not_an_invoice,
@not_payable,
],
'Bill Pmt -Check' => [
@globally_irrelevant_fields,
@not_a_payment,
@not_an_invoice,
@not_billable,
@not_due,
@not_payable,
],
'Bill Pmt -CCard' => [
@globally_irrelevant_fields,
@not_a_payment,
@not_an_invoice,
@not_billable,
@not_due,
@not_payable,
],
'Invoice' => [
@globally_irrelevant_fields,
@not_a_payment,
@not_billable,
@not_payable,
],
'Deposit' => [
@globally_irrelevant_fields,
@not_an_invoice,
@not_due,
],
'Payment' => [
@globally_irrelevant_fields,
@not_an_invoice,
@not_billable,
@not_due,
],
'Check' => [
@globally_irrelevant_fields,
@not_a_payment,
@not_an_invoice,
@not_due,
@not_payable,
],
'Credit Card Credit' => [
@globally_irrelevant_fields,
@not_a_payment,
@not_an_invoice,
@not_due,
@not_payable,
],
'Credit' => [
@globally_irrelevant_fields,
@not_a_payment,
@not_an_invoice,
@not_billable,
@not_due,
@not_payable,
],
'General Journal' => [
@globally_irrelevant_fields,
@not_an_invoice,
],
);
sub delete_unused_fields {
my ($transaction) = @_;
foreach (@$transaction) {
delete @{$_}{ @{ $irrelevant_fields{$_->{'Type'}} // [] } };
}
}
sub delete_used_fields {
my ($transaction) = shift();
delete @{$_}{ @_ } foreach @$transaction;
}
# Debugging function to dump abbreviated items in a transaction.
# Irrelevant fields are removed to keep the output brief.
sub dump_transaction {
my (
$transaction_type, $transaction_number, $transaction_date,
$any_posting, $transaction
) = @_;
#use YAML::Syck; print YAML::Syck::Dump($transaction);
use JSON::XS; print( encode_json($_), "\n") foreach @$transaction;
}
1;