From a1f105327081e1bf4b139f531a158136d55b1f8c Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Tue, 14 Jun 2016 15:27:56 +0200 Subject: [PATCH] =?utf8?q?AR/AP.pm=20-=20W=C3=A4hrungskonten=20pr=C3=BCfen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Vor dem Buchen von Zahlungen mit Wechselkursen auf die Standardkonten von Wechselkurserträgen und Wechselkursaufwendungen prüfen. Abbrechen wenn keine definiert, ansonsten geht sowieso die SQL-Abfrage kaputt. --- SL/AP.pm | 9 +++++++++ SL/AR.pm | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/SL/AP.pm b/SL/AP.pm index e8dd4958a..95b0d5208 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -319,6 +319,15 @@ sub post_transaction { $form->{"exchangerate_$i"}), 2); if ($amount != 0) { + # fetch fxgain and fxloss chart info from defaults if charts aren't already filled in form + if ( !$form->{fxgain_accno} && $::instance_conf->get_fxgain_accno_id ) { + $form->{fxgain_accno} = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxgain_accno_id)->accno; + }; + if ( !$form->{fxloss_accno} && $::instance_conf->get_fxloss_accno_id ) { + $form->{fxloss_accno} = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxloss_accno_id)->accno; + }; + die "fxloss_accno missing" if $amount < 0 and not $form->{fxloss_accno}; + die "fxgain_accno missing" if $amount > 0 and not $form->{fxgain_accno}; $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) | . qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . diff --git a/SL/AR.pm b/SL/AR.pm index d64ddb219..8e8cf2f2c 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -275,6 +275,15 @@ sub post_transaction { $amount = $form->round_amount( $form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}) * -1, 2); if ($amount != 0) { + # fetch fxgain and fxloss chart info from defaults if charts aren't already filled in form + if ( !$form->{fxgain_accno} && $::instance_conf->get_fxgain_accno_id ) { + $form->{fxgain_accno} = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxgain_accno_id)->accno; + }; + if ( !$form->{fxloss_accno} && $::instance_conf->get_fxloss_accno_id ) { + $form->{fxloss_accno} = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxloss_accno_id)->accno; + }; + die "fxloss_accno missing" if $amount < 0 and not $form->{fxloss_accno}; + die "fxgain_accno missing" if $amount > 0 and not $form->{fxgain_accno}; my $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), -- 2.20.1