Revision b099c63c
Von Sven Schöling vor 11 Monaten hinzugefügt
SL/Form.pm | ||
---|---|---|
2563 | 2563 |
c.accno, c.description, |
2564 | 2564 |
a.acc_trans_id, a.source, a.amount, a.memo, a.transdate, a.gldate, a.cleared, a.project_id, a.taxkey, a.chart_id, |
2565 | 2565 |
p.projectnumber, |
2566 |
t.rate, t.id |
|
2566 |
t.rate, t.id, |
|
2567 |
a.fx_transaction |
|
2567 | 2568 |
FROM acc_trans a |
2568 | 2569 |
LEFT JOIN chart c ON (c.id = a.chart_id) |
2569 | 2570 |
LEFT JOIN project p ON (p.id = a.project_id) |
2570 | 2571 |
LEFT JOIN tax t ON (t.id= a.tax_id) |
2571 | 2572 |
WHERE a.trans_id = ? |
2572 |
AND a.fx_transaction = '0' |
|
2573 | 2573 |
ORDER BY a.acc_trans_id, a.transdate|; |
2574 | 2574 |
$sth = $dbh->prepare($query); |
2575 | 2575 |
do_statement($self, $sth, $query, $self->{id}); |
... | ... | |
2579 | 2579 |
$self->{id}, $arap); |
2580 | 2580 |
|
2581 | 2581 |
my $index = 0; |
2582 |
my @fx_transaction_entries; |
|
2582 | 2583 |
|
2583 | 2584 |
# store amounts in {acc_trans}{$key} for multiple accounts |
2584 | 2585 |
while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { |
2586 |
# skip fx_transaction entries and add them for post processing |
|
2587 |
if ($ref->{fx_transaction}) { |
|
2588 |
die "first entry in a record transaction should not be fx_transaction" unless @fx_transaction_entries; |
|
2589 |
push @{ $fx_transaction_entries[-1] }, $ref; |
|
2590 |
next; |
|
2591 |
} else { |
|
2592 |
push @fx_transaction_entries, [ $ref ]; |
|
2593 |
} |
|
2594 |
|
|
2595 |
|
|
2585 | 2596 |
# credit and debit bookings calc fx rate for positions |
2586 |
# also used as exchangerate_$i for payments |
|
2597 |
# also used as exchangerate_$i for payments - exchangerate here can come from frontend or from bank transactions
|
|
2587 | 2598 |
$ref->{exchangerate} = |
2588 | 2599 |
$self->check_exchangerate($myconfig, $self->{currency}, $ref->{transdate}, $fld); |
2589 | 2600 |
if (!($xkeyref{ $ref->{accno} } =~ /tax/)) { |
... | ... | |
2597 | 2608 |
push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref; |
2598 | 2609 |
} |
2599 | 2610 |
|
2611 |
# post process fx_transactions. |
|
2612 |
# old bin/mozilla code first posts the intended foreign currency amount and then the correction for exchange flagged as fx_transaction |
|
2613 |
# for example: when posting 20 USD on a system in EUR with an exchangerate of 1.1, the resulting acc_trans will say: |
|
2614 |
# +20 no fx (intended: 20 USD) |
|
2615 |
# +2 fx (but it's actually 22 EUR) |
|
2616 |
# |
|
2617 |
# for payments this is followed by the fxgain/loss. when paying the above invoice with 20 USD at 1.3 exchange: |
|
2618 |
# -20 no fx (intended: 20 USD) |
|
2619 |
# -6 fx (but it's actually 26 EUR) |
|
2620 |
# +4 fx (but 4 of them go to fxgain) |
|
2621 |
# |
|
2622 |
# bin/mozilla/ controllers will display the intended amount as is, but would have to guess at the actual book value |
|
2623 |
# without the extra fields |
|
2624 |
# |
|
2625 |
# bank transactions however will convert directly into internal currency, so a foreign currency invoice might end up |
|
2626 |
# having non-fxtransactions. to make sure that these are roundtrip safe, flag the fx-transaction payments as fx and give the |
|
2627 |
# intendended internal amount |
|
2628 |
# |
|
2629 |
# this still operates on the cached entries of form->{acc_trans} |
|
2630 |
for my $fx_block (@fx_transaction_entries) { |
|
2631 |
my ($ref, @fx_entries) = @$fx_block; |
|
2632 |
for my $fx_ref (@fx_entries) { |
|
2633 |
if ($fx_ref->{chart_id} == $ref->{chart_id}) { |
|
2634 |
$ref->{defaultcurrency_paid} //= $ref->{amount}; |
|
2635 |
$ref->{defaultcurrency_paid} += $fx_ref->{amount}; |
|
2636 |
$ref->{fx_transaction} = 1; |
|
2637 |
} |
|
2638 |
} |
|
2639 |
} |
|
2640 |
|
|
2600 | 2641 |
$sth->finish; |
2601 | 2642 |
#check das: |
2602 | 2643 |
$query = |
Auch abrufbar als: Unified diff
Form::create_links - fx_transaction payments besser parsen
Bei Fremdwährungszahlungen wird jetzt zusätzlich:
- fx_transaction gesetzt
- defaultcurrency_paid gesetzt