Revision 4c23c478
Von Sven Schöling vor mehr als 17 Jahren hinzugefügt
SL/AR.pm | ||
---|---|---|
42 | 42 |
|
43 | 43 |
my ($self, $myconfig, $form) = @_; |
44 | 44 |
|
45 |
my ($null, $taxrate, $amount, $tax, $diff);
|
|
45 |
my ($query, $sth, $null, $taxrate, $amount, $tax);
|
|
46 | 46 |
my $exchangerate = 0; |
47 | 47 |
my $i; |
48 | 48 |
|
... | ... | |
50 | 50 |
|
51 | 51 |
my $dbh = $form->dbconnect_noauto($myconfig); |
52 | 52 |
|
53 |
if ($form->{currency} eq $form->{defaultcurrency}) { |
|
54 |
$form->{exchangerate} = 1; |
|
55 |
} else { |
|
56 |
$exchangerate = |
|
57 |
$form->check_exchangerate($myconfig, $form->{currency}, |
|
58 |
$form->{transdate}, 'buy'); |
|
59 |
} |
|
60 |
for $i (1 .. $form->{rowcount}) { |
|
61 |
$form->{AR_amounts}{"amount_$i"} = |
|
62 |
(split(/--/, $form->{"AR_amount_$i"}))[0]; |
|
63 |
} |
|
53 |
# set exchangerate |
|
54 |
$form->{exchangerate} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 : |
|
55 |
( $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy') || |
|
56 |
$form->parse_amount($myconfig, $form->{exchangerate}) ); |
|
57 |
|
|
58 |
# get the charts selected |
|
59 |
map { ($form->{AR_amounts}{"amount_$_"}) = split /--/, $form->{"AR_amount_$_"} } 1 .. $form->{rowcount}; |
|
60 |
|
|
64 | 61 |
$form->{AR_amounts}{receivables} = $form->{ARselected}; |
65 | 62 |
$form->{AR}{receivables} = $form->{ARselected}; |
66 | 63 |
|
67 |
$form->{exchangerate} = |
|
68 |
($exchangerate) |
|
69 |
? $exchangerate |
|
70 |
: $form->parse_amount($myconfig, $form->{exchangerate}); |
|
71 |
|
|
64 |
# parsing |
|
72 | 65 |
for $i (1 .. $form->{rowcount}) { |
73 |
|
|
74 |
$form->{"amount_$i"} = |
|
75 |
$form->round_amount($form->parse_amount($myconfig, $form->{"amount_$i"}) |
|
76 |
* $form->{exchangerate}, |
|
77 |
2); |
|
78 |
|
|
79 |
$form->{netamount} += $form->{"amount_$i"}; |
|
80 |
|
|
81 |
# parse tax_$i for later |
|
82 |
$form->{"tax_$i"} = $form->parse_amount($myconfig, $form->{"tax_$i"}); |
|
66 |
$form->{"amount_$i"} = $form->round_amount($form->parse_amount($myconfig, $form->{"amount_$i"}) * $form->{exchangerate}, 2); |
|
67 |
$form->{amount} += $form->{"amount_$i"}; |
|
68 |
$form->{"tax_$i"} = $form->parse_amount($myconfig, $form->{"tax_$i"}); |
|
83 | 69 |
} |
84 | 70 |
|
85 | 71 |
# this is for ar |
86 |
|
|
87 |
$form->{amount} = $form->{netamount}; |
|
88 |
|
|
89 | 72 |
$form->{tax} = 0; |
90 | 73 |
$form->{netamount} = 0; |
91 | 74 |
$form->{total_tax} = 0; |
92 | 75 |
|
93 | 76 |
# taxincluded doesn't make sense if there is no amount |
77 |
$form->{taxincluded} = 0 unless $form->{amount}; |
|
94 | 78 |
|
95 |
$form->{taxincluded} = 0 if ($form->{amount} == 0); |
|
96 | 79 |
for $i (1 .. $form->{rowcount}) { |
97 |
($form->{"tax_id_$i"}, $NULL) = split /--/, $form->{"taxchart_$i"};
|
|
80 |
($form->{"tax_id_$i"}) = split /--/, $form->{"taxchart_$i"}; |
|
98 | 81 |
|
99 |
$query = |
|
100 |
qq|SELECT c.accno, t.taxkey, t.rate | . |
|
101 |
qq|FROM tax t LEFT JOIN chart c on (c.id = t.chart_id) | . |
|
102 |
qq|WHERE t.id = ? | . |
|
103 |
qq|ORDER BY c.accno|; |
|
82 |
$query = qq|SELECT c.accno, t.taxkey, t.rate FROM tax t LEFT JOIN chart c ON (c.id = t.chart_id) WHERE t.id = ? ORDER BY c.accno|; |
|
83 |
($form->{AR_amounts}{"tax_$i"}, $form->{"taxkey_$i"}, $form->{"taxrate_$i"}) = selectrow_query($form, $dbh, $query, $form->{"tax_id_$i"}); |
|
104 | 84 |
|
105 |
($form->{AR_amounts}{"tax_$i"}, $form->{"taxkey_$i"}, $form->{"taxrate_$i"}) = |
|
106 |
selectrow_query($form, $dbh, $query, $form->{"tax_id_$i"}); |
|
107 | 85 |
$form->{AR_amounts}{"tax_$i"}{taxkey} = $form->{"taxkey_$i"}; |
108 |
$form->{AR_amounts}{"amount_$i"}{taxkey} = $form->{"taxkey_$i"}; |
|
86 |
$form->{AR_amounts}{"amounts_$i"}{taxkey} = $form->{"taxkey_$i"};
|
|
109 | 87 |
|
110 | 88 |
if ($form->{taxincluded} *= 1) { |
111 |
if (!$form->{"korrektur_$i"}) { |
|
112 |
$tax = |
|
113 |
$form->{"amount_$i"} - |
|
114 |
($form->{"amount_$i"} / ($form->{"taxrate_$i"} + 1)); |
|
115 |
} else { |
|
116 |
$tax = $form->{"tax_$i"}; |
|
117 |
} |
|
118 |
$amount = $form->{"amount_$i"} - $tax; |
|
119 |
$form->{"amount_$i"} = $form->round_amount($amount, 2); |
|
120 |
$diff += $amount - $form->{"amount_$i"}; |
|
121 |
$form->{"tax_$i"} = $form->round_amount($tax, 2); |
|
122 |
$form->{netamount} += $form->{"amount_$i"}; |
|
89 |
$tax = $form->{"korrektur_$i"} |
|
90 |
? $form->{"tax_$i"} |
|
91 |
: $form->{"amount_$i"} - ($form->{"amount_$i"} / ($form->{"taxrate_$i"} + 1)); # should be same as taxrate * amount / (taxrate + 1) |
|
92 |
$form->{"amount_$i"} = $form->round_amount($form->{"amount_$i"} - $tax, 2); |
|
93 |
$form->{"tax_$i"} = $form->round_amount($tax, 2); |
|
123 | 94 |
} else { |
124 |
if (!$form->{"korrektur_$i"}) { |
|
125 |
$form->{"tax_$i"} = $form->{"amount_$i"} * $form->{"taxrate_$i"}; |
|
126 |
} |
|
127 |
$form->{"tax_$i"} = |
|
128 |
$form->round_amount($form->{"tax_$i"} * $form->{exchangerate}, 2); |
|
129 |
$form->{netamount} += $form->{"amount_$i"}; |
|
95 |
$form->{"tax_$i"} = $form->{"amount_$i"} * $form->{"taxrate_$i"} unless $form->{"korrektur_$i"}; |
|
96 |
$form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"} * $form->{exchangerate}, 2); |
|
130 | 97 |
} |
131 |
|
|
132 |
$form->{total_tax} += $form->{"tax_$i"}; |
|
98 |
$form->{netamount} += $form->{"amount_$i"}; |
|
99 |
$form->{total_tax} += $form->{"tax_$i"};
|
|
133 | 100 |
} |
134 | 101 |
|
135 | 102 |
# adjust paidaccounts if there is no date in the last row |
136 |
$form->{paidaccounts}-- unless ($form->{"datepaid_$form->{paidaccounts}"});
|
|
103 |
$form->{paidaccounts}-- unless $form->{"datepaid_$form->{paidaccounts}"};
|
|
137 | 104 |
$form->{paid} = 0; |
138 | 105 |
|
139 | 106 |
# add payments |
140 | 107 |
for $i (1 .. $form->{paidaccounts}) { |
141 |
$form->{"paid_$i"} = |
|
142 |
$form->round_amount($form->parse_amount($myconfig, $form->{"paid_$i"}), |
|
143 |
2); |
|
144 |
|
|
145 |
$form->{paid} += $form->{"paid_$i"}; |
|
146 |
$form->{datepaid} = $form->{"datepaid_$i"}; |
|
147 |
|
|
108 |
$form->{"paid_$i"} = $form->round_amount($form->parse_amount($myconfig, $form->{"paid_$i"}), 2); |
|
109 |
$form->{paid} += $form->{"paid_$i"}; |
|
110 |
$form->{datepaid} = $form->{"datepaid_$i"}; |
|
148 | 111 |
} |
149 | 112 |
|
150 | 113 |
$form->{amount} = $form->{netamount} + $form->{total_tax}; |
151 |
$form->{paid} = |
|
152 |
$form->round_amount($form->{paid} * $form->{exchangerate}, 2); |
|
153 |
|
|
154 |
my ($query, $sth, $null); |
|
114 |
$form->{paid} = $form->round_amount($form->{paid} * $form->{exchangerate}, 2); |
|
155 | 115 |
|
156 | 116 |
($null, $form->{employee_id}) = split /--/, $form->{employee}; |
157 |
unless ($form->{employee_id}) { |
|
158 |
$form->get_employee($dbh); |
|
159 |
} |
|
160 | 117 |
|
161 |
# if we have an id delete old records |
|
118 |
$form->get_employee($dbh) unless $form->{employee_id}; |
|
119 |
|
|
120 |
# if we have an id delete old records else make one |
|
162 | 121 |
if ($form->{id}) { |
163 | 122 |
# delete detail records |
164 | 123 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ?|; |
165 | 124 |
do_query($form, $dbh, $query, $form->{id}); |
166 |
|
|
167 | 125 |
} else { |
168 | 126 |
$query = qq|SELECT nextval('glid')|; |
169 | 127 |
($form->{id}) = selectrow_query($form, $dbh, $query); |
170 |
|
|
171 | 128 |
$query = qq|INSERT INTO ar (id, invnumber, employee_id) VALUES (?, 'dummy', ?)|; |
172 | 129 |
do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}); |
173 |
|
|
174 |
if (!$form->{invnumber}) { |
|
175 |
$form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh); |
|
176 |
} |
|
130 |
$form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh) unless $form->{invnumber}; |
|
177 | 131 |
} |
178 | 132 |
|
179 | 133 |
# update department |
... | ... | |
181 | 135 |
$form->{department_id} *= 1; |
182 | 136 |
|
183 | 137 |
# record last payment date in ar table |
184 |
$form->{datepaid} = $form->{transdate} unless $form->{datepaid};
|
|
138 |
$form->{datepaid} ||= $form->{transdate} ;
|
|
185 | 139 |
my $datepaid = ($form->{paid} != 0) ? $form->{datepaid} : undef; |
186 | 140 |
|
187 | 141 |
$query = |
188 |
qq|UPDATE ar set | . |
|
189 |
qq| invnumber = ?, ordnumber = ?, transdate = ?, customer_id = ?, | . |
|
190 |
qq| taxincluded = ?, amount = ?, duedate = ?, paid = ?, datepaid = ?, | . |
|
191 |
qq| netamount = ?, curr = ?, notes = ?, department_id = ?, | . |
|
192 |
qq| employee_id = ? | . |
|
193 |
qq|WHERE id = ?|; |
|
194 |
my @values = ($form->{invnumber}, $form->{ordnumber}, |
|
195 |
conv_date($form->{transdate}), conv_i($form->{customer_id}), |
|
196 |
$form->{taxincluded} ? 't' : 'f', $form->{amount}, |
|
197 |
conv_date($form->{duedate}), $form->{paid}, |
|
198 |
conv_date($datepaid), $form->{netamount}, |
|
199 |
$form->{currency}, $form->{notes}, |
|
200 |
conv_i($form->{department_id}), |
|
201 |
conv_i($form->{employee_id}), |
|
202 |
conv_i($form->{id})); |
|
142 |
qq|UPDATE ar set |
|
143 |
invnumber = ?, ordnumber = ?, transdate = ?, customer_id = ?, |
|
144 |
taxincluded = ?, amount = ?, duedate = ?, paid = ?, datepaid = ?, |
|
145 |
netamount = ?, curr = ?, notes = ?, department_id = ?, |
|
146 |
employee_id = ? |
|
147 |
WHERE id = ?|; |
|
148 |
my @values = ($form->{invnumber}, $form->{ordnumber}, conv_date($form->{transdate}), conv_i($form->{customer_id}), $form->{taxincluded} ? 't' : 'f', $form->{amount}, |
|
149 |
conv_date($form->{duedate}), $form->{paid}, conv_date($datepaid), $form->{netamount}, $form->{currency}, $form->{notes}, conv_i($form->{department_id}), |
|
150 |
conv_i($form->{employee_id}), conv_i($form->{id})); |
|
203 | 151 |
do_query($form, $dbh, $query, @values); |
204 | 152 |
|
205 | 153 |
# amount for AR account |
206 | 154 |
$form->{receivables} = $form->round_amount($form->{amount}, 2) * -1; |
207 | 155 |
|
208 | 156 |
# update exchangerate |
209 |
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) { |
|
210 |
$form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, |
|
211 |
$form->{exchangerate}, 0); |
|
212 |
} |
|
157 |
$form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, $form->{exchangerate}, 0) |
|
158 |
if ($form->{currency} ne $form->{defaultcurrency}) && $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy'); |
|
159 |
|
|
213 | 160 |
|
214 | 161 |
# add individual transactions for AR, amount and taxes |
215 | 162 |
for $i (1 .. $form->{rowcount}) { |
216 | 163 |
if ($form->{"amount_$i"} != 0) { |
217 | 164 |
my $project_id = conv_i($form->{"project_id_$i"}); |
218 |
$taxkey = $form->{AR_amounts}{"amount_$i"}{taxkey}; |
|
165 |
$taxkey = $form->{AR_amounts}{"amounts_$i"}{taxkey};
|
|
219 | 166 |
|
220 | 167 |
# insert detail records in acc_trans |
221 |
$query = |
|
222 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . |
|
223 |
qq| project_id, taxkey) | . |
|
224 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
225 |
@values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"amount_$i"}), |
|
226 |
conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), |
|
227 |
$project_id, conv_i($taxkey)); |
|
168 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
169 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
170 |
@values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"amount_$i"}), conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id, conv_i($taxkey)); |
|
228 | 171 |
do_query($form, $dbh, $query, @values); |
229 | 172 |
|
230 | 173 |
if ($form->{"tax_$i"} != 0) { |
231 | 174 |
# insert detail records in acc_trans |
232 |
$query = |
|
233 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . |
|
234 |
qq| project_id, taxkey) | . |
|
235 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
|
236 |
qq| ?, ?, ?, ?)|; |
|
237 |
@values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"tax_$i"}), |
|
238 |
conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), |
|
239 |
$project_id, conv_i($taxkey)); |
|
175 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
176 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
177 |
@values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"tax_$i"}), conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id, conv_i($taxkey)); |
|
240 | 178 |
do_query($form, $dbh, $query, @values); |
241 | 179 |
} |
242 | 180 |
} |
243 | 181 |
} |
244 | 182 |
|
245 | 183 |
# add recievables |
246 |
$query = |
|
247 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) | . |
|
248 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, | . |
|
249 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
250 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, |
|
251 |
conv_i($form->{receivables}), conv_date($form->{transdate}), |
|
252 |
$form->{AR_amounts}{receivables}); |
|
184 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) |
|
185 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
186 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}), $form->{AR_amounts}{receivables}); |
|
253 | 187 |
do_query($form, $dbh, $query, @values); |
254 | 188 |
|
255 | 189 |
# add paid transactions |
... | ... | |
262 | 196 |
$form->{"datepaid_$i"} = $form->{transdate} |
263 | 197 |
unless ($form->{"datepaid_$i"}); |
264 | 198 |
|
265 |
$exchangerate = 0; |
|
266 |
if ($form->{currency} eq $form->{defaultcurrency}) { |
|
267 |
$form->{"exchangerate_$i"} = 1; |
|
268 |
} else { |
|
269 |
$exchangerate = |
|
270 |
$form->check_exchangerate($myconfig, $form->{currency}, |
|
271 |
$form->{"datepaid_$i"}, 'buy'); |
|
272 |
|
|
273 |
$form->{"exchangerate_$i"} = |
|
274 |
($exchangerate) |
|
275 |
? $exchangerate |
|
276 |
: $form->parse_amount($myconfig, $form->{"exchangerate_$i"}); |
|
277 |
} |
|
199 |
$form->{"exchangerate_$i"} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 : |
|
200 |
( $form->check_exchangerate($myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy') || |
|
201 |
$form->parse_amount($myconfig, $form->{"exchangerate_$i"}) ); |
|
278 | 202 |
|
279 | 203 |
# if there is no amount and invtotal is zero there is no exchangerate |
280 |
if ($form->{amount} == 0 && $form->{netamount} == 0) { |
|
281 |
$form->{exchangerate} = $form->{"exchangerate_$i"}; |
|
282 |
} |
|
204 |
$form->{exchangerate} = $form->{"exchangerate_$i"} |
|
205 |
if ($form->{amount} == 0 && $form->{netamount} == 0); |
|
283 | 206 |
|
284 | 207 |
# receivables amount |
285 |
$amount = |
|
286 |
$form->round_amount($form->{"paid_$i"} * $form->{exchangerate}, 2); |
|
208 |
$amount = $form->round_amount($form->{"paid_$i"} * $form->{exchangerate}, 2); |
|
287 | 209 |
|
288 | 210 |
if ($form->{receivables} != 0) { |
289 | 211 |
# add receivable |
290 |
$query = |
|
291 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) | . |
|
292 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, | . |
|
293 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
294 |
@values = (conv_i($form->{id}), $form->{AR}{receivables}, |
|
295 |
$amount, conv_date($form->{"datepaid_$i"}), $project_id, |
|
296 |
$form->{AR}{receivables}); |
|
212 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
213 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
214 |
@values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}); |
|
297 | 215 |
do_query($form, $dbh, $query, @values); |
298 | 216 |
} |
299 | 217 |
$form->{receivables} = $amount; |
... | ... | |
302 | 220 |
my $project_id = conv_i($form->{"paid_project_id_$i"}); |
303 | 221 |
# add payment |
304 | 222 |
$amount = $form->{"paid_$i"} * -1; |
305 |
$query = |
|
306 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, project_id, taxkey) | . |
|
307 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, | . |
|
308 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
309 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, |
|
310 |
conv_date($form->{"datepaid_$i"}), $form->{"source_$i"}, |
|
311 |
$form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}); |
|
223 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, project_id, taxkey) |
|
224 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
225 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}); |
|
312 | 226 |
do_query($form, $dbh, $query, @values); |
313 | 227 |
|
314 | 228 |
# exchangerate difference for payment |
315 |
$amount = |
|
316 |
$form->round_amount( |
|
317 |
$form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) * -1, |
|
318 |
2); |
|
229 |
$amount = $form->round_amount( $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) * -1, 2); |
|
319 | 230 |
|
320 | 231 |
if ($amount != 0) { |
321 |
$query = |
|
322 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) | . |
|
323 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . |
|
324 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
325 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, |
|
326 |
$amount, conv_date($form->{"datepaid_$i"}), $project_id, |
|
327 |
$form->{AR}{"paid_$i"}); |
|
232 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) |
|
233 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
234 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"}); |
|
328 | 235 |
do_query($form, $dbh, $query, @values); |
329 | 236 |
} |
330 | 237 |
|
331 | 238 |
# exchangerate gain/loss |
332 |
$amount = |
|
333 |
$form->round_amount( |
|
334 |
$form->{"paid_$i"} * |
|
335 |
($form->{exchangerate} - $form->{"exchangerate_$i"}) * -1, |
|
336 |
2); |
|
239 |
$amount = $form->round_amount( $form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}) * -1, 2); |
|
337 | 240 |
|
338 | 241 |
if ($amount != 0) { |
339 |
$accno = |
|
340 |
($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; |
|
341 |
$query = |
|
342 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) | . |
|
343 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . |
|
344 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
345 |
@values = (conv_i($form->{id}), $accno, $amount, |
|
346 |
conv_date($form->{"datepaid_$i"}), $project_id, $accno); |
|
242 |
$accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; |
|
243 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) |
|
244 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
245 |
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno); |
|
347 | 246 |
do_query($form, $dbh, $query, @values); |
348 | 247 |
} |
349 | 248 |
} |
350 | 249 |
|
351 | 250 |
# update exchangerate record |
352 |
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) { |
|
353 |
$form->update_exchangerate($dbh, $form->{currency}, |
|
354 |
$form->{"datepaid_$i"}, |
|
355 |
$form->{"exchangerate_$i"}, 0); |
|
356 |
} |
|
251 |
$form->update_exchangerate($dbh, $form->{currency}, $form->{"datepaid_$i"}, $form->{"exchangerate_$i"}, 0) |
|
252 |
if ($form->{currency} ne $form->{defaultcurrency}) && !$form->check_exchangerate($myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'); |
|
357 | 253 |
} |
358 | 254 |
} |
359 | 255 |
|
360 | 256 |
my $rc = $dbh->commit; |
361 | 257 |
$dbh->disconnect; |
362 | 258 |
|
363 |
$main::lxdebug->leave_sub(); |
|
364 |
|
|
365 |
return $rc; |
|
259 |
$main::lxdebug->leave_sub() and return $rc; |
|
366 | 260 |
} |
367 | 261 |
|
368 | 262 |
sub post_payment { |
... | ... | |
473 | 367 |
$amount; |
474 | 368 |
} |
475 | 369 |
|
476 |
$diff = 0; |
|
477 |
|
|
478 | 370 |
# update exchange rate |
479 | 371 |
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) { |
480 | 372 |
$form->update_exchangerate($dbh, $form->{currency}, |
Auch abrufbar als: Unified diff
Fix zu Bug 618.
Kommentar:
perl -le 'map ${$a{$_}=1}{k}=$_, 0,1; print $a{1}{k}'