Revision 361d8846
Von Sven Schöling vor fast 12 Jahren hinzugefügt
SL/AP.pm | ||
---|---|---|
209 | 209 |
# insert detail records in acc_trans |
210 | 210 |
$query = |
211 | 211 |
qq|INSERT INTO acc_trans | . |
212 |
qq| (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)| .
|
|
212 |
qq| (trans_id, chart_id, amount, transdate, project_id, taxkey)| . |
|
213 | 213 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
214 |
qq| ?, ?, ?, ?, (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
|
|
214 |
qq| ?, ?, ?, ?)|; |
|
215 | 215 |
@values = ($form->{id}, $form->{AP_amounts}{"amount_$i"}, |
216 | 216 |
$form->{"amount_$i"}, conv_date($form->{transdate}), |
217 |
$project_id, $form->{"taxkey_$i"}, $form->{AP_amounts}{"amount_$i"}, conv_date($form->{transdate}));
|
|
217 |
$project_id, $form->{"taxkey_$i"}); |
|
218 | 218 |
do_query($form, $dbh, $query, @values); |
219 | 219 |
|
220 | 220 |
if ($form->{"tax_$i"} != 0) { |
221 | 221 |
# insert detail records in acc_trans |
222 | 222 |
$query = |
223 | 223 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . |
224 |
qq| project_id, taxkey, tax_id) | .
|
|
224 |
qq| project_id, taxkey) | . |
|
225 | 225 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
226 |
qq| ?, ?, ?, ?, (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
|
|
226 |
qq| ?, ?, ?, ?)|; |
|
227 | 227 |
@values = ($form->{id}, $form->{AP_amounts}{"tax_$i"}, |
228 | 228 |
$form->{"tax_$i"}, conv_date($form->{transdate}), |
229 |
$project_id, $form->{"taxkey_$i"}, $form->{AP_amounts}{"tax_$i"}, conv_date($form->{transdate}));
|
|
229 |
$project_id, $form->{"taxkey_$i"}); |
|
230 | 230 |
do_query($form, $dbh, $query, @values); |
231 | 231 |
} |
232 | 232 |
|
... | ... | |
235 | 235 |
|
236 | 236 |
# add payables |
237 | 237 |
$query = |
238 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) | .
|
|
238 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) | . |
|
239 | 239 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, | . |
240 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?),| . |
|
241 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
240 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
242 | 241 |
@values = ($form->{id}, $form->{AP_amounts}{payables}, $form->{payables}, |
243 |
conv_date($form->{transdate}), $form->{AP_amounts}{payables}, $form->{AP_amounts}{payables}, conv_date($form->{transdate}));
|
|
242 |
conv_date($form->{transdate}), $form->{AP_amounts}{payables}); |
|
244 | 243 |
do_query($form, $dbh, $query, @values); |
245 | 244 |
} |
246 | 245 |
|
... | ... | |
284 | 283 |
2); |
285 | 284 |
if ($form->{payables}) { |
286 | 285 |
$query = |
287 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) | .
|
|
286 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) | . |
|
288 | 287 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, | . |
289 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?),| . |
|
290 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
288 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
291 | 289 |
@values = ($form->{id}, $form->{AP_payables}, $amount, |
292 | 290 |
conv_date($form->{"datepaid_$i"}), $project_id, |
293 |
$form->{AP_payables}, $form->{AP_payables}, conv_date($form->{"datepaid_$i"}));
|
|
291 |
$form->{AP_payables}); |
|
294 | 292 |
do_query($form, $dbh, $query, @values); |
295 | 293 |
} |
296 | 294 |
$form->{payables} = $amount; |
... | ... | |
298 | 296 |
# add payment |
299 | 297 |
my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); |
300 | 298 |
$query = |
301 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id) | .
|
|
299 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey) | . |
|
302 | 300 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, | . |
303 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?), | . |
|
304 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
301 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
305 | 302 |
@values = ($form->{id}, $form->{"AP_paid_account_$i"}, $form->{"paid_$i"}, |
306 | 303 |
conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, |
307 |
$form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"}, |
|
308 |
$form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"})); |
|
304 |
$form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"}); |
|
309 | 305 |
do_query($form, $dbh, $query, @values); |
310 | 306 |
|
311 | 307 |
# add exchange rate difference |
... | ... | |
314 | 310 |
($form->{"exchangerate_$i"} - 1), 2); |
315 | 311 |
if ($amount != 0) { |
316 | 312 |
$query = |
317 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) | .
|
|
313 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) | . |
|
318 | 314 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . |
319 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?), | . |
|
320 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
315 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
321 | 316 |
@values = ($form->{id}, $form->{"AP_paid_account_$i"}, $amount, |
322 | 317 |
conv_date($form->{"datepaid_$i"}), $project_id, |
323 |
$form->{"AP_paid_account_$i"}, |
|
324 |
$form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"})); |
|
318 |
$form->{"AP_paid_account_$i"}); |
|
325 | 319 |
do_query($form, $dbh, $query, @values); |
326 | 320 |
} |
327 | 321 |
|
... | ... | |
333 | 327 |
|
334 | 328 |
if ($amount != 0) { |
335 | 329 |
$query = |
336 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) | .
|
|
330 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) | . |
|
337 | 331 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . |
338 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?)| . |
|
339 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
332 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
340 | 333 |
@values = ($form->{id}, ($amount > 0) ? |
341 | 334 |
$form->{fxgain_accno} : $form->{fxloss_accno}, |
342 | 335 |
$amount, conv_date($form->{"datepaid_$i"}), $project_id, |
343 | 336 |
($amount > 0) ? |
344 |
$form->{fxgain_accno} : $form->{fxloss_accno}, |
|
345 |
($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}, conv_date($form->{"datepaid_$i"})); |
|
337 |
$form->{fxgain_accno} : $form->{fxloss_accno}); |
|
346 | 338 |
do_query($form, $dbh, $query, @values); |
347 | 339 |
} |
348 | 340 |
|
SL/AR.pm | ||
---|---|---|
173 | 173 |
my $project_id = conv_i($form->{"project_id_$i"}); |
174 | 174 |
|
175 | 175 |
# insert detail records in acc_trans |
176 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)
|
|
177 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|;
|
|
176 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
177 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
178 | 178 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{"amount_$i"}, conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id, |
179 |
conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"}));
|
|
179 |
conv_i($form->{"taxkey_$i"})); |
|
180 | 180 |
do_query($form, $dbh, $query, @values); |
181 | 181 |
|
182 | 182 |
if ($form->{"tax_$i"} != 0) { |
183 | 183 |
# insert detail records in acc_trans |
184 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)
|
|
185 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|;
|
|
184 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
185 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
186 | 186 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{"tax_$i"}, conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id, |
187 |
conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"}));
|
|
187 |
conv_i($form->{"taxkey_$i"})); |
|
188 | 188 |
do_query($form, $dbh, $query, @values); |
189 | 189 |
} |
190 | 190 |
} |
191 | 191 |
} |
192 | 192 |
|
193 | 193 |
# add recievables |
194 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) |
|
195 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
196 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
197 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}), |
|
198 |
$form->{AR_amounts}{receivables}, $form->{AR_amounts}{receivables}, conv_date($form->{transdate})); |
|
194 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) |
|
195 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
196 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}), $form->{AR_amounts}{receivables}); |
|
199 | 197 |
do_query($form, $dbh, $query, @values); |
200 | 198 |
|
201 | 199 |
} else { |
... | ... | |
232 | 230 |
|
233 | 231 |
if ($amount != 0) { |
234 | 232 |
# add receivable |
235 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) |
|
236 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
237 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
238 |
@values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}, $form->{AR}{receivables}, conv_date($form->{"datepaid_$i"})); |
|
233 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
234 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
235 |
@values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}); |
|
239 | 236 |
do_query($form, $dbh, $query, @values); |
240 | 237 |
} |
241 | 238 |
|
... | ... | |
244 | 241 |
my $project_id = conv_i($form->{"paid_project_id_$i"}); |
245 | 242 |
my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); |
246 | 243 |
$amount = $form->{"paid_$i"} * -1; |
247 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id) |
|
248 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
249 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
250 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}, |
|
251 |
$form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"})); |
|
244 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey) |
|
245 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
246 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}); |
|
252 | 247 |
do_query($form, $dbh, $query, @values); |
253 | 248 |
|
254 | 249 |
# exchangerate difference for payment |
255 | 250 |
$amount = $form->round_amount( $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) * -1, 2); |
256 | 251 |
|
257 | 252 |
if ($amount != 0) { |
258 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) |
|
259 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
260 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
261 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"}, |
|
262 |
$form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"})); |
|
253 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) |
|
254 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
255 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"}); |
|
263 | 256 |
do_query($form, $dbh, $query, @values); |
264 | 257 |
} |
265 | 258 |
|
... | ... | |
268 | 261 |
|
269 | 262 |
if ($amount != 0) { |
270 | 263 |
my $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; |
271 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) |
|
272 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
273 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
274 |
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno, $accno, conv_date($form->{"datepaid_$i"})); |
|
264 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) |
|
265 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
266 |
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno); |
|
275 | 267 |
do_query($form, $dbh, $query, @values); |
276 | 268 |
} |
277 | 269 |
} |
SL/DB/Helper/PriceTaxCalculator.pm | ||
---|---|---|
119 | 119 |
$self->netamount($self->netamount + $sellprice * $item->qty / $item->price_factor); |
120 | 120 |
|
121 | 121 |
my $chart = $item->part->get_chart(type => $data->{is_sales} ? 'income' : 'expense', taxzone => $self->taxzone_id); |
122 |
$data->{amounts}->{ $chart->id } ||= { taxkey => $taxkey->taxkey_id, tax_id => $taxkey->tax_id, amount => 0 };
|
|
122 |
$data->{amounts}->{ $chart->id } ||= { taxkey => $taxkey->taxkey_id, amount => 0 }; |
|
123 | 123 |
$data->{amounts}->{ $chart->id }->{amount} += $linetotal; |
124 | 124 |
|
125 | 125 |
push @{ $data->{assembly_items} }, []; |
SL/DB/Invoice.pm | ||
---|---|---|
188 | 188 |
sub _post_add_acctrans { |
189 | 189 |
my ($self, $entries) = @_; |
190 | 190 |
|
191 |
my $default_tax_id = SL::DB::Manager::Tax->find_by(taxkey => 0)->id; |
|
192 |
|
|
193 | 191 |
while (my ($chart_id, $spec) = each %{ $entries }) { |
194 |
$spec = { taxkey => 0, tax_id => $default_tax_id, amount => $spec } unless ref $spec;
|
|
192 |
$spec = { taxkey => 0, amount => $spec } unless ref $spec; |
|
195 | 193 |
SL::DB::AccTransaction->new(trans_id => $self->id, |
196 | 194 |
chart_id => $chart_id, |
197 | 195 |
amount => $spec->{amount}, |
198 |
tax_id => $spec->{tax_id}, |
|
199 | 196 |
taxkey => $spec->{taxkey}, |
200 | 197 |
project_id => $self->globalproject_id, |
201 | 198 |
transdate => $self->transdate)->save; |
SL/DB/MetaSetup/AccTransaction.pm | ||
---|---|---|
26 | 26 |
taxkey => { type => 'integer' }, |
27 | 27 |
itime => { type => 'timestamp', default => 'now()' }, |
28 | 28 |
mtime => { type => 'timestamp' }, |
29 |
tax_id => { type => 'integer', not_null => 1 }, |
|
30 | 29 |
], |
31 | 30 |
|
32 | 31 |
primary_key_columns => [ 'acc_trans_id' ], |
33 | 32 |
|
33 |
allow_inline_column_values => 1, |
|
34 |
|
|
34 | 35 |
foreign_keys => [ |
35 | 36 |
chart => { |
36 | 37 |
class => 'SL::DB::Chart', |
SL/GL.pm | ||
---|---|---|
159 | 159 |
if ($amount != 0) { |
160 | 160 |
$query = |
161 | 161 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
162 |
source, memo, project_id, taxkey, ob_transaction, cb_transaction, tax_id)
|
|
162 |
source, memo, project_id, taxkey, ob_transaction, cb_transaction) |
|
163 | 163 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), |
164 |
?, ?, ?, ?, ?, ?, ?, ?, ?)|;
|
|
164 |
?, ?, ?, ?, ?, ?, ?, ?)|; |
|
165 | 165 |
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{transdate}), |
166 |
$form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f', conv_i($form->{"tax_id_$i"}));
|
|
166 |
$form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f'); |
|
167 | 167 |
do_query($form, $dbh, $query, @values); |
168 | 168 |
} |
169 | 169 |
|
... | ... | |
171 | 171 |
# add taxentry |
172 | 172 |
$query = |
173 | 173 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
174 |
source, memo, project_id, taxkey, tax_id)
|
|
174 |
source, memo, project_id, taxkey) |
|
175 | 175 |
VALUES (?, (SELECT chart_id FROM tax WHERE id = ?), |
176 |
?, ?, ?, ?, ?, ?, ?)|;
|
|
176 |
?, ?, ?, ?, ?, ?)|; |
|
177 | 177 |
@values = (conv_i($form->{id}), conv_i($form->{"tax_id_$i"}), |
178 | 178 |
$tax, conv_date($form->{transdate}), $form->{"source_$i"}, |
179 |
$form->{"memo_$i"}, $project_id, $taxkey, conv_i($form->{"tax_id_$i"}));
|
|
179 |
$form->{"memo_$i"}, $project_id, $taxkey); |
|
180 | 180 |
do_query($form, $dbh, $query, @values); |
181 | 181 |
} |
182 | 182 |
} |
SL/IR.pm | ||
---|---|---|
269 | 269 |
|
270 | 270 |
# allocated >= 0 |
271 | 271 |
# add entry for inventory, this one is for the sold item |
272 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?), |
|
273 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
274 |
@values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{inventory_accno_id}, $ref->{transdate}); |
|
272 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?))|; |
|
273 |
@values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}); |
|
275 | 274 |
do_query($form, $dbh, $query, @values); |
276 | 275 |
|
277 | 276 |
# add expense |
278 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?), |
|
279 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
280 |
@values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{expense_accno_id}, $ref->{transdate}); |
|
277 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?))|; |
|
278 |
@values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}); |
|
281 | 279 |
do_query($form, $dbh, $query, @values); |
282 | 280 |
} |
283 | 281 |
}; |
... | ... | |
480 | 478 |
|
481 | 479 |
next if $payments_only || !$form->{amount}{$trans_id}{$accno}; |
482 | 480 |
|
483 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id)
|
|
481 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
484 | 482 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
485 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?, |
|
486 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
483 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
487 | 484 |
@values = ($trans_id, $accno, $form->{amount}{$trans_id}{$accno}, |
488 |
conv_date($form->{invdate}), $accno, $project_id, $accno, conv_date($form->{invdate}));
|
|
485 |
conv_date($form->{invdate}), $accno, $project_id); |
|
489 | 486 |
do_query($form, $dbh, $query, @values); |
490 | 487 |
} |
491 | 488 |
} |
... | ... | |
520 | 517 |
|
521 | 518 |
# record AP |
522 | 519 |
if ($form->{amount}{ $form->{id} }{ $form->{AP} } != 0) { |
523 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id)
|
|
520 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
524 | 521 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
525 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?, |
|
526 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
522 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
527 | 523 |
@values = (conv_i($form->{id}), $form->{AP}, $amount, |
528 |
$form->{"datepaid_$i"}, $form->{AP}, $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}));
|
|
524 |
$form->{"datepaid_$i"}, $form->{AP}, $project_id); |
|
529 | 525 |
do_query($form, $dbh, $query, @values); |
530 | 526 |
} |
531 | 527 |
|
... | ... | |
533 | 529 |
my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); |
534 | 530 |
|
535 | 531 |
$query = |
536 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id)
|
|
532 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id) |
|
537 | 533 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, |
538 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?, |
|
539 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
534 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
540 | 535 |
@values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, |
541 |
$gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id, $accno, conv_date($form->{"datepaid_$i"}));
|
|
536 |
$gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id); |
|
542 | 537 |
do_query($form, $dbh, $query, @values); |
543 | 538 |
|
544 | 539 |
$exchangerate = 0; |
... | ... | |
576 | 571 |
$form->{fx}{$accno}{$transdate} = $form->round_amount($form->{fx}{$accno}{$transdate}, 2); |
577 | 572 |
next if ($form->{fx}{$accno}{$transdate} == 0); |
578 | 573 |
|
579 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id, tax_id) |
|
580 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?, |
|
581 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
582 |
@values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno, $form->{fx}{$accno}{$transdate}); |
|
574 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id) |
|
575 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?)|; |
|
576 |
@values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id); |
|
583 | 577 |
do_query($form, $dbh, $query, @values); |
584 | 578 |
} |
585 | 579 |
} |
SL/IS.pm | ||
---|---|---|
818 | 818 |
|
819 | 819 |
$project_id = conv_i($form->{"globalproject_id"}); |
820 | 820 |
|
821 |
my $taxdate = $form->{deliverydate} ? $form->{deliverydate} : $form->{invdate}; |
|
822 |
|
|
823 | 821 |
foreach my $trans_id (keys %{ $form->{amount_cogs} }) { |
824 | 822 |
foreach my $accno (keys %{ $form->{amount_cogs}{$trans_id} }) { |
825 | 823 |
next unless ($form->{expense_inventory} =~ /\Q$accno\E/); |
... | ... | |
828 | 826 |
|
829 | 827 |
if (!$payments_only && ($form->{amount_cogs}{$trans_id}{$accno} != 0)) { |
830 | 828 |
$query = |
831 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
832 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?)|;
|
|
829 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
830 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 0, ?)|; |
|
833 | 831 |
@values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id)); |
834 | 832 |
do_query($form, $dbh, $query, @values); |
835 | 833 |
$form->{amount_cogs}{$trans_id}{$accno} = 0; |
... | ... | |
841 | 839 |
|
842 | 840 |
if (!$payments_only && ($form->{amount_cogs}{$trans_id}{$accno} != 0)) { |
843 | 841 |
$query = |
844 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
845 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?)|;
|
|
842 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
843 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 0, ?)|; |
|
846 | 844 |
@values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id)); |
847 | 845 |
do_query($form, $dbh, $query, @values); |
848 | 846 |
} |
... | ... | |
857 | 855 |
|
858 | 856 |
if (!$payments_only && ($form->{amount}{$trans_id}{$accno} != 0)) { |
859 | 857 |
$query = |
860 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
858 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
861 | 859 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
862 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
863 | 860 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
864 |
@values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id));
|
|
861 |
@values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_i($project_id)); |
|
865 | 862 |
do_query($form, $dbh, $query, @values); |
866 | 863 |
$form->{amount}{$trans_id}{$accno} = 0; |
867 | 864 |
} |
... | ... | |
872 | 869 |
|
873 | 870 |
if (!$payments_only && ($form->{amount}{$trans_id}{$accno} != 0)) { |
874 | 871 |
$query = |
875 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
872 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
876 | 873 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
877 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
878 | 874 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
879 |
@values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id));
|
|
875 |
@values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_i($project_id)); |
|
880 | 876 |
do_query($form, $dbh, $query, @values); |
881 | 877 |
} |
882 | 878 |
} |
... | ... | |
922 | 918 |
|
923 | 919 |
if ($form->{amount}{ $form->{id} }{ $form->{AR} } != 0) { |
924 | 920 |
$query = |
925 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
921 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
926 | 922 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
927 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
928 | 923 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
929 |
@values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, $project_id);
|
|
924 |
@values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, $project_id); |
|
930 | 925 |
do_query($form, $dbh, $query, @values); |
931 | 926 |
} |
932 | 927 |
|
... | ... | |
935 | 930 |
my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); |
936 | 931 |
|
937 | 932 |
$query = |
938 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, tax_id, taxkey, project_id)
|
|
933 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id) |
|
939 | 934 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, |
940 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
941 | 935 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
942 | 936 |
@values = (conv_i($form->{"id"}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, |
943 |
$gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, $project_id);
|
|
937 |
$gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id); |
|
944 | 938 |
do_query($form, $dbh, $query, @values); |
945 | 939 |
|
946 | 940 |
# exchangerate difference |
... | ... | |
980 | 974 |
if ( $form->{fx}{$accno}{$transdate} != 0 ) { |
981 | 975 |
|
982 | 976 |
$query = |
983 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, tax_id, taxkey, project_id)
|
|
977 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id) |
|
984 | 978 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', |
985 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
986 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
987 |
@values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_date($taxdate), $accno, conv_i($project_id)); |
|
979 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
980 |
@values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_i($project_id)); |
|
988 | 981 |
do_query($form, $dbh, $query, @values); |
989 | 982 |
} |
990 | 983 |
} |
sql/Pg-upgrade2/add_tax_id_to_acc_trans.sql | ||
---|---|---|
1 |
-- @tag: add_tax_id_to_acc_trans |
|
2 |
-- @description: Neue Spalte tax_id in der acc_trans |
|
3 |
-- @depends: release_2_7_0 |
|
4 |
|
|
5 |
--Neue Spalte tax_id in acc_trans: |
|
6 |
ALTER TABLE acc_trans ADD tax_id integer; |
|
7 |
|
|
8 |
--Spalte mit Werten füllen: |
|
9 |
UPDATE acc_trans ac SET tax_id= |
|
10 |
(select tk.tax_id from taxkeys tk |
|
11 |
where tk.taxkey_id=ac.taxkey |
|
12 |
AND tk.startdate <= COALESCE( |
|
13 |
(select ar.deliverydate from ar where ar.id=ac.trans_id), |
|
14 |
(select ar.transdate from ar where ar.id=ac.trans_id), |
|
15 |
(select ap.transdate from ap where ap.id=ac.trans_id), |
|
16 |
(select gl.transdate from gl where gl.id=ac.trans_id), |
|
17 |
ac.transdate ) |
|
18 |
order by startdate desc limit 1); |
|
19 |
|
|
20 |
--Spalten, die noch null sind (nur bei Einträgen möglich, wo auch taxkey null ist) |
|
21 |
UPDATE acc_trans SET tax_id=0 where tax_id is null; |
|
22 |
|
|
23 |
--tax_id als Pflichtfeld definieren: |
|
24 |
ALTER TABLE acc_trans ALTER tax_id SET NOT NULL; |
|
25 |
|
Auch abrufbar als: Unified diff
Revert "tax_id in acc_trans"
This reverts commit 357d134d265637fb37ed2cd47da2ce3ef44d015a.