Revision de651621
Von Stephan Köhler vor etwa 19 Jahren hinzugefügt
SL/AR.pm | ||
---|---|---|
34 | 34 |
|
35 | 35 |
package AR; |
36 | 36 |
|
37 |
use Data::Dumper; |
|
38 |
|
|
37 | 39 |
sub post_transaction { |
38 | 40 |
$main::lxdebug->enter_sub(); |
39 | 41 |
|
... | ... | |
52 | 54 |
$form->check_exchangerate($myconfig, $form->{currency}, |
53 | 55 |
$form->{transdate}, 'buy'); |
54 | 56 |
} |
57 |
for $i (1 .. $form->{rowcount}) { |
|
58 |
$form->{AR_amounts}{"amount_$i"} = (split(/--/, $form->{"AR_amount_$i"}))[0]; |
|
59 |
} |
|
60 |
($form->{AR_amounts}{receivables}) = split(/--/, $form->{ARselected}); |
|
61 |
($form->{AR}{receivables}) = split(/--/, $form->{ARselected}); |
|
55 | 62 |
|
56 | 63 |
$form->{exchangerate} = |
57 | 64 |
($exchangerate) |
58 | 65 |
? $exchangerate |
59 | 66 |
: $form->parse_amount($myconfig, $form->{exchangerate}); |
60 | 67 |
|
61 |
for $i (1 .. 1) {
|
|
68 |
for $i (1 .. $form->{rowcount}) {
|
|
62 | 69 |
|
63 | 70 |
$form->{"amount_$i"} = |
64 | 71 |
$form->round_amount($form->parse_amount($myconfig, $form->{"amount_$i"}) |
... | ... | |
77 | 84 |
# taxincluded doesn't make sense if there is no amount |
78 | 85 |
|
79 | 86 |
$form->{taxincluded} = 0 if ($form->{amount} == 0); |
87 |
for $i (1 .. $form->{rowcount}) { |
|
88 |
($form->{"taxkey_$i"}, $NULL) = split /--/, $form->{"taxchart_$i"}; |
|
80 | 89 |
|
81 |
$query = |
|
82 |
qq| SELECT c.accno, t.rate FROM chart c, tax t where c.id=t.chart_id AND t.taxkey=$form->{taxkey}|; |
|
83 |
$sth = $dbh->prepare($query); |
|
84 |
$sth->execute || $form->dberror($query); |
|
85 |
($form->{AR}{tax}, $form->{taxrate}) = $sth->fetchrow_array; |
|
86 |
$sth->finish; |
|
90 |
$query = |
|
91 |
qq| SELECT c.accno, t.rate FROM chart c, tax t where c.id=t.chart_id AND t.taxkey=$form->{"taxkey_$i"}|; |
|
92 |
$sth = $dbh->prepare($query); |
|
93 |
$sth->execute || $form->dberror($query); |
|
94 |
($form->{AR_amounts}{"tax_$i"}, $form->{"taxrate_$i"}) = $sth->fetchrow_array; |
|
95 |
$form->{AR_amounts}{"tax_$i"}{taxkey} = $form->{"taxkey_$i"}; |
|
96 |
$form->{AR_amounts}{"amount_$i"}{taxkey} = $form->{"taxkey_$i"}; |
|
87 | 97 |
|
88 |
$form->{tax} = $form->{amount_1} * $form->{taxrate}; |
|
89 |
$form->{tax} = $form->round_amount($form->{tax} * $form->{exchangerate}, 2); |
|
90 |
$form->{total_tax} += $form->{tax}; |
|
98 |
$sth->finish; |
|
99 |
if (!$form->{"korrektur_$i"}) { |
|
100 |
if ($form->{taxincluded} *= 1) { |
|
101 |
$tax = $form->{"amount_$i"} - ($form->{"amount_$i"} / ($form->{"taxrate_$i"} + 1)); |
|
102 |
$amount = $form->{"amount_$i"} - $tax; |
|
103 |
$form->{"amount_$i"} = $form->round_amount($amount, 2); |
|
104 |
$diff += $amount - $form->{"amount_$i"}; |
|
105 |
$form->{"tax_$i"} = $form->round_amount($tax, 2); |
|
106 |
$form->{netamount} += $form->{"amount_$i"}; |
|
107 |
} |
|
108 |
$form->{"tax_$i"} = $form->{"amount_$i"} * $form->{"taxrate_$i"}; |
|
109 |
$form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"} * $form->{exchangerate}, 2); |
|
110 |
} |
|
111 |
$form->{total_tax} += $form->{"tax_$i"}; |
|
112 |
} |
|
91 | 113 |
|
92 | 114 |
# adjust paidaccounts if there is no date in the last row |
93 | 115 |
$form->{paidaccounts}-- unless ($form->{"datepaid_$form->{paidaccounts}"}); |
... | ... | |
104 | 126 |
|
105 | 127 |
} |
106 | 128 |
|
107 |
if ($form->{taxincluded} *= 1) { |
|
108 |
for $i (1 .. 1) { |
|
109 |
$tax = |
|
110 |
$form->{"amount_$i"} - ($form->{"amount_$i"} / ($form->{taxrate} + 1)); |
|
111 |
$amount = $form->{"amount_$i"} - $tax; |
|
112 |
$form->{"amount_$i"} = $form->round_amount($amount, 2); |
|
113 |
$diff += $amount - $form->{"amount_$i"}; |
|
114 |
$form->{tax} = $form->round_amount($tax, 2); |
|
115 |
$form->{total_tax} = $form->{tax}; |
|
116 |
} |
|
117 |
|
|
118 |
# deduct difference from amount_1 |
|
119 |
# $form->{amount_1} += $form->round_amount($diff, 2); |
|
120 |
$form->{netamount} = $form->{amount_1}; |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 | 129 |
$form->{amount} = $form->{netamount} + $form->{total_tax}; |
125 | 130 |
$form->{paid} = |
126 | 131 |
$form->round_amount($form->{paid} * $form->{exchangerate}, 2); |
... | ... | |
199 | 204 |
} |
200 | 205 |
|
201 | 206 |
# add individual transactions for AR, amount and taxes |
202 |
foreach my $item (keys %{ $form->{AR} }) {
|
|
203 |
if ($form->{$item} != 0) {
|
|
207 |
for $i (1 .. $form->{rowcount}) {
|
|
208 |
if ($form->{"amount_$i"} != 0) {
|
|
204 | 209 |
$project_id = 'NULL'; |
205 |
if ($item =~ /amount_/) {
|
|
206 |
if ($form->{"project_id_$'"} && $form->{"projectnumber_$'"}) {
|
|
207 |
$project_id = $form->{"project_id_$'"};
|
|
210 |
if ("amount_$i" =~ /amount_/) {
|
|
211 |
if ($form->{"project_id_$i"} && $form->{"projectnumber_$i"}) {
|
|
212 |
$project_id = $form->{"project_id_$i"};
|
|
208 | 213 |
} |
209 | 214 |
} |
215 |
if ("amount_$i" =~ /amount/) { |
|
216 |
$taxkey = $form->{AR_amounts}{"amount_$i"}{taxkey}; |
|
217 |
} |
|
210 | 218 |
|
211 | 219 |
# insert detail records in acc_trans |
212 | 220 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
213 | 221 |
project_id, taxkey) |
214 | 222 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
215 |
WHERE c.accno = '$form->{AR}{$item}'),
|
|
216 |
$form->{$item}, '$form->{transdate}', $project_id, '$form->{taxkey}')|;
|
|
223 |
WHERE c.accno = '$form->{AR_amounts}{"amount_$i"}'),
|
|
224 |
$form->{"amount_$i"}, '$form->{transdate}', $project_id, '$taxkey')|;
|
|
217 | 225 |
$dbh->do($query) || $form->dberror($query); |
226 |
if ($form->{"tax_$i"} !=0) { |
|
227 |
# insert detail records in acc_trans |
|
228 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
229 |
project_id, taxkey) |
|
230 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
231 |
WHERE c.accno = '$form->{AR_amounts}{"tax_$i"}'), |
|
232 |
$form->{"tax_$i"}, '$form->{transdate}', $project_id, '$taxkey')|; |
|
233 |
$dbh->do($query) || $form->dberror($query); |
|
234 |
} |
|
218 | 235 |
} |
219 | 236 |
} |
237 |
# add recievables |
|
238 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
239 |
project_id) |
|
240 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
241 |
WHERE c.accno = '$form->{AR_amounts}{receivables}'), |
|
242 |
$form->{receivables}, '$form->{transdate}', $project_id)|; |
|
243 |
$dbh->do($query) || $form->dberror($query); |
|
244 |
|
|
220 | 245 |
|
221 | 246 |
# add paid transactions |
222 | 247 |
for my $i (1 .. $form->{paidaccounts}) { |
Auch abrufbar als: Unified diff
Merge von 716 aus unstable: Splitbuchungen
Splittbuchungen fuer Debitorenbuchungen