Revision a7873339
Von Stephan Köhler vor etwa 19 Jahren hinzugefügt
SL/AP.pm | ||
---|---|---|
61 | 61 |
: $form->parse_amount($myconfig, $form->{exchangerate}); |
62 | 62 |
} |
63 | 63 |
|
64 |
for $i (1 .. $form->{rowcount}) { |
|
65 |
$form->{AP_amounts}{"amount_$i"} = |
|
66 |
(split(/--/, $form->{"AP_amount_$i"}))[0]; |
|
67 |
} |
|
68 |
($form->{AP_amounts}{payables}) = split(/--/, $form->{APselected}); |
|
69 |
($form->{AP}{payables}) = split(/--/, $form->{APselected}); |
|
70 |
|
|
64 | 71 |
# reverse and parse amounts |
65 |
for my $i (1 .. 1) {
|
|
72 |
for my $i (1 .. $form->{rowcount}) {
|
|
66 | 73 |
$form->{"amount_$i"} = |
67 | 74 |
$form->round_amount( |
68 | 75 |
$form->parse_amount($myconfig, $form->{"amount_$i"}) * |
... | ... | |
77 | 84 |
# taxincluded doesn't make sense if there is no amount |
78 | 85 |
$form->{taxincluded} = 0 if ($form->{amount} == 0); |
79 | 86 |
|
80 |
$query = |
|
81 |
qq| SELECT c.accno, t.rate FROM chart c, tax t where c.id=t.chart_id AND t.taxkey=$form->{taxkey}|; |
|
82 |
$sth = $dbh->prepare($query); |
|
83 |
$sth->execute || $form->dberror($query); |
|
84 |
($form->{AP}{"tax"}, $form->{taxrate}) = $sth->fetchrow_array; |
|
85 |
$sth->finish; |
|
87 |
for $i (1 .. $form->{rowcount}) { |
|
88 |
($form->{"taxkey_$i"}, $NULL) = split /--/, $form->{"taxchart_$i"}; |
|
86 | 89 |
|
87 |
$formtax = $form->parse_amount($myconfig, $form->{"tax"}); |
|
88 |
|
|
89 |
$form->{"tax"} = $form->{amount} * $form->{taxrate}; |
|
90 |
$form->{"tax"} = |
|
91 |
$form->round_amount($form->{"tax"} * $form->{exchangerate}, 2) * -1; |
|
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->{AP_amounts}{"tax_$i"}, $form->{"taxrate_$i"}) = |
|
95 |
$sth->fetchrow_array; |
|
96 |
$form->{AP_amounts}{"tax_$i"}{taxkey} = $form->{"taxkey_$i"}; |
|
97 |
$form->{AP_amounts}{"amount_$i"}{taxkey} = $form->{"taxkey_$i"}; |
|
92 | 98 |
|
93 |
if ($form->{taxcheck}) { |
|
94 |
$form->{"tax"} = $formtax * -1; |
|
99 |
$sth->finish; |
|
100 |
if (!$form->{"korrektur_$i"}) { |
|
101 |
if ($form->{taxincluded} *= 1) { |
|
102 |
$tax = |
|
103 |
$form->{"amount_$i"} - |
|
104 |
($form->{"amount_$i"} / ($form->{"taxrate_$i"} + 1)); |
|
105 |
$amount = $form->{"amount_$i"} - $tax; |
|
106 |
$form->{"amount_$i"} = $form->round_amount($amount, 2); |
|
107 |
$diff += $amount - $form->{"amount_$i"}; |
|
108 |
$form->{"tax_$i"} = $form->round_amount($tax, 2); |
|
109 |
$form->{netamount} += $form->{"amount_$i"}; |
|
110 |
} else { |
|
111 |
$form->{"tax_$i"} = $form->{"amount_$i"} * $form->{"taxrate_$i"}; |
|
112 |
$form->{"tax_$i"} = |
|
113 |
$form->round_amount($form->{"tax_$i"} * $form->{exchangerate}, 2); |
|
114 |
$form->{netamount} += $form->{"amount_$i"}; |
|
115 |
} |
|
116 |
} |
|
117 |
$form->{total_tax} += $form->{"tax_$i"} * -1; |
|
95 | 118 |
} |
96 | 119 |
|
97 |
$form->{total_tax} += ($form->{"tax"} * -1); |
|
98 |
|
|
99 | 120 |
# adjust paidaccounts if there is no date in the last row |
100 | 121 |
$form->{paidaccounts}-- unless ($form->{"datepaid_$form->{paidaccounts}"}); |
101 | 122 |
|
102 | 123 |
$form->{invpaid} = 0; |
124 |
$form->{netamount} *= -1; |
|
103 | 125 |
|
104 | 126 |
# add payments |
105 | 127 |
for my $i (1 .. $form->{paidaccounts}) { |
... | ... | |
115 | 137 |
$form->{invpaid} = |
116 | 138 |
$form->round_amount($form->{invpaid} * $form->{exchangerate}, 2); |
117 | 139 |
|
118 |
if ($form->{taxincluded} *= 1) { |
|
119 |
for $i (1 .. 1) { |
|
120 |
$tax = |
|
121 |
$form->{"amount_$i"} - ($form->{"amount_$i"} / ($form->{taxrate} + 1)); |
|
122 |
if ($form->{taxcheck}) { |
|
123 |
$tax = $formtax * -1; |
|
124 |
} |
|
125 |
$amount = $form->{"amount_$i"} - $tax; |
|
126 |
$form->{"amount_$i"} = $form->round_amount($amount, 2); |
|
127 |
$diff += $amount - $form->{"amount_$i"}; |
|
128 |
$form->{tax} = $form->round_amount($tax, 2); |
|
129 |
$form->{total_tax} = $form->{tax} * -1; |
|
130 |
} |
|
131 |
print(STDERR "Steuer $form->{tax}\n"); |
|
132 |
print(STDERR "TotalSteuer $form->{total_tax}\n"); |
|
133 |
|
|
134 |
# deduct taxes from amount |
|
135 |
# $form->{amount} -= $form->{total_tax}; |
|
136 |
# deduct difference from amount_1 |
|
137 |
# $form->{amount_1} += $form->round_amount($diff, 2); |
|
138 |
$form->{amount} = $form->{amount_1} * -1; |
|
139 |
} |
|
140 |
|
|
141 |
$form->{netamount} = $form->{amount}; |
|
142 |
|
|
143 | 140 |
# store invoice total, this goes into ap table |
144 |
$form->{invtotal} = $form->{amount} + $form->{total_tax}; |
|
141 |
$form->{invtotal} = $form->{netamount} + $form->{total_tax};
|
|
145 | 142 |
|
146 | 143 |
# amount for total AP |
147 | 144 |
$form->{payables} = $form->{invtotal}; |
148 |
|
|
145 |
print(STDERR $form->{payables}, |
|
146 |
" Payables\n", |
|
147 |
$form->{invtotal}, |
|
148 |
" Invtotal\n", |
|
149 |
$form->{netamount}, |
|
150 |
" Netamount\n", |
|
151 |
$form->{total_tax}, |
|
152 |
" Total_Tax\n\n"); |
|
149 | 153 |
my ($query, $sth); |
150 | 154 |
|
151 | 155 |
# if we have an id delete old records |
... | ... | |
211 | 215 |
} |
212 | 216 |
|
213 | 217 |
# add individual transactions |
214 |
foreach my $item (keys %{ $form->{AP} }) {
|
|
215 |
if ($form->{$item} != 0) {
|
|
218 |
for $i (1 .. $form->{rowcount}) {
|
|
219 |
if ($form->{"amount_$i"} != 0) {
|
|
216 | 220 |
$project_id = 'NULL'; |
217 |
if ($item =~ /amount_/) {
|
|
218 |
if ($form->{"project_id_$'"} && $form->{"projectnumber_$'"}) {
|
|
219 |
$project_id = $form->{"project_id_$'"};
|
|
221 |
if ("amount_$i" =~ /amount_/) {
|
|
222 |
if ($form->{"project_id_$i"} && $form->{"projectnumber_$i"}) {
|
|
223 |
$project_id = $form->{"project_id_$i"};
|
|
220 | 224 |
} |
221 | 225 |
} |
226 |
if ("amount_$i" =~ /amount/) { |
|
227 |
$taxkey = $form->{AP_amounts}{"amount_$i"}{taxkey}; |
|
228 |
} |
|
222 | 229 |
|
223 | 230 |
# insert detail records in acc_trans |
224 | 231 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
225 | 232 |
project_id, taxkey) |
226 | 233 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
227 |
WHERE c.accno = '$form->{AP}{$item}'),
|
|
228 |
$form->{$item}, '$form->{transdate}', $project_id, '$form->{taxkey}')|;
|
|
234 |
WHERE c.accno = '$form->{AP_amounts}{"amount_$i"}'),
|
|
235 |
$form->{"amount_$i"}, '$form->{transdate}', $project_id, '$taxkey')|;
|
|
229 | 236 |
$dbh->do($query) || $form->dberror($query); |
230 | 237 |
|
238 |
if ($form->{"tax_$i"} != 0) { |
|
239 |
|
|
240 |
# insert detail records in acc_trans |
|
241 |
$query = |
|
242 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
243 |
project_id, taxkey) |
|
244 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
245 |
WHERE c.accno = '$form->{AP_amounts}{"tax_$i"}'), |
|
246 |
$form->{"tax_$i"}, '$form->{transdate}', $project_id, '$taxkey')|; |
|
247 |
$dbh->do($query) || $form->dberror($query); |
|
248 |
} |
|
249 |
|
|
231 | 250 |
} |
232 | 251 |
} |
233 | 252 |
|
253 |
# add payables |
|
254 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
255 |
project_id) |
|
256 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
257 |
WHERE c.accno = '$form->{AP_amounts}{payables}'), |
|
258 |
$form->{payables}, '$form->{transdate}', $project_id)|; |
|
259 |
$dbh->do($query) || $form->dberror($query); |
|
260 |
|
|
234 | 261 |
# if there is no amount but a payment record a payable |
235 | 262 |
if ($form->{amount} == 0 && $form->{invtotal} == 0) { |
236 | 263 |
$form->{payables} = $form->{invpaid}; |
Auch abrufbar als: Unified diff
Merge von 733 aus unstable: Splitbuchungen Kreditoren
Splitbuchungen fuer Kreditoren ergaenzt