| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Business::AU::Ledger::Database::Payment; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
568
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Business::AU::Ledger::Database::Base'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use namespace::autoclean; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.88'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ----------------------------------------------- |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub add |
|
14
|
|
|
|
|
|
|
{ |
|
15
|
|
|
|
|
|
|
my($self, $payment) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
eval |
|
18
|
|
|
|
|
|
|
{ |
|
19
|
|
|
|
|
|
|
$self -> simple -> begin; |
|
20
|
|
|
|
|
|
|
$self -> save_payment_record('add', $payment); |
|
21
|
|
|
|
|
|
|
$self -> simple -> commit; |
|
22
|
|
|
|
|
|
|
}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ($@) |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
|
|
|
|
|
|
warn "add_payment died: $@"; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
eval{$self -> simple -> rollback}; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
die $@; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self -> log(__PACKAGE__ . '. Leaving add'); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} # End of add. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# ----------------------------------------------- |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub get_payment_category_codes |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
|
|
|
|
|
|
my($self) = @_; |
|
42
|
|
|
|
|
|
|
my $category = $self -> simple -> query('select name, id from category_codes where tx_type_id = 1') -> map; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self -> log(__PACKAGE__ . ". Leaving get_payment_category_codes"); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $category; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} # End of get_payment_category_codes. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# ----------------------------------------------- |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get_payment_gst_codes |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
|
|
|
|
|
|
my($self) = @_; |
|
55
|
|
|
|
|
|
|
my $gst = $self -> simple -> query('select name, id from gst_codes where tx_type_id = 1') -> map; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self -> log(__PACKAGE__ . ". Leaving get_payment_gst_codes"); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return $gst; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} # End of get_payment_gst_codes. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# ----------------------------------------------- |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub get_payment_payment_methods |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
|
|
|
|
|
|
my($self) = @_; |
|
68
|
|
|
|
|
|
|
my $payment_method = $self -> simple -> query('select name, id from payment_methods') -> map; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$self -> log(__PACKAGE__ . ". Leaving get_payment_payment_methods"); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return $payment_method; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} # End of get_payment_payment_methods. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# ----------------------------------------------- |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_payment_tx_details |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
|
|
|
|
|
|
my($self) = @_; |
|
81
|
|
|
|
|
|
|
my $detail = $self -> simple -> query('select name, id from tx_details') -> map; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$self -> log(__PACKAGE__ . ". Leaving get_payment_tx_details"); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return $detail; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} # End of get_payment_tx_details. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# ----------------------------------------------- |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_payments_via_ym |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
|
|
|
|
|
|
my($self, $year, $month) = @_; |
|
94
|
|
|
|
|
|
|
my($timestamp) = sprintf('%4i-%02i', $year, $month); |
|
95
|
|
|
|
|
|
|
my $payment = $self -> simple -> query("select * from payments where to_char(timestamp, 'YYYY-MM') = '$timestamp'") -> hashes; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$self -> log(__PACKAGE__ . ". Leaving get_payments_via_ym: $timestamp"); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return $payment; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} # End of get_payments_via_ym. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# -------------------------------------------------- |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub save_payment_record |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
|
|
|
|
|
|
my($self, $context, $payment) = @_; |
|
108
|
|
|
|
|
|
|
my($table_name) = 'payments'; |
|
109
|
|
|
|
|
|
|
my(@field) = (qw/category_code gst_code month payment_method tx_detail amount comment gst_amount petty_cash_in petty_cash_out private_use_amount private_use_percent reference timestamp/); |
|
110
|
|
|
|
|
|
|
my($data) = {}; |
|
111
|
|
|
|
|
|
|
my(%id) = |
|
112
|
|
|
|
|
|
|
( |
|
113
|
|
|
|
|
|
|
category_code => 1, |
|
114
|
|
|
|
|
|
|
gst_code => 1, |
|
115
|
|
|
|
|
|
|
month => 1, |
|
116
|
|
|
|
|
|
|
payment_method => 1, |
|
117
|
|
|
|
|
|
|
tx_detail => 1, |
|
118
|
|
|
|
|
|
|
); |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my($field_name); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
for (@field) |
|
123
|
|
|
|
|
|
|
{ |
|
124
|
|
|
|
|
|
|
if ($id{$_}) |
|
125
|
|
|
|
|
|
|
{ |
|
126
|
|
|
|
|
|
|
$field_name = "${_}_id"; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
else |
|
129
|
|
|
|
|
|
|
{ |
|
130
|
|
|
|
|
|
|
$field_name = $_; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$$data{$field_name} = $$payment{$_}; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my($id); |
|
137
|
|
|
|
|
|
|
my($sql); |
|
138
|
|
|
|
|
|
|
my(@where); |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
if ($context eq 'add') |
|
141
|
|
|
|
|
|
|
{ |
|
142
|
|
|
|
|
|
|
$sql = "insert into $table_name"; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
else |
|
145
|
|
|
|
|
|
|
{ |
|
146
|
|
|
|
|
|
|
$id = $$payment{'id'}; |
|
147
|
|
|
|
|
|
|
$sql = "update $table_name set"; |
|
148
|
|
|
|
|
|
|
@where = ('where id = ', $id); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$self -> simple -> iquery($sql, $data, @where); |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
if ($context eq 'add') |
|
154
|
|
|
|
|
|
|
{ |
|
155
|
|
|
|
|
|
|
$self -> db -> get_last_insert_id($table_name); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$$payment{'id'} = $$data{'id'} = $self -> db -> last_insert_id; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$self -> log(__PACKAGE__ . '. Leaving save_payment_record'); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} # End of save_payment_record. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# -------------------------------------------------- |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__PACKAGE__ -> meta -> make_immutable; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |