From fb37acdc4c87cf9bc4ef6abb54e486c1b3829d6c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 8 Jun 2007 14:19:06 +0000 Subject: [PATCH] =?utf8?q?Probleme=20mit=20mehreren=20W=C3=A4hrungen=20und?= =?utf8?q?=20Wechselkursen=20behoben.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/AP.pm | 2 ++ SL/AR.pm | 3 ++- SL/Form.pm | 68 ++++++++++++++++++++++++++++++++++++++++++----- SL/IR.pm | 1 + SL/IS.pm | 2 ++ SL/RP.pm | 1 + bin/mozilla/ap.pl | 16 ++++++++++- bin/mozilla/ar.pl | 16 +++++++++++ bin/mozilla/is.pl | 9 ++++++- bin/mozilla/oe.pl | 14 ++++++++++ 10 files changed, 122 insertions(+), 10 deletions(-) diff --git a/SL/AP.pm b/SL/AP.pm index 0f2e8ee07..3bd658cb5 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -48,6 +48,8 @@ sub post_transaction { my ($null, $taxrate, $amount); my $exchangerate = 0; + $form->{defaultcurrency} = $form->get_default_currency($myconfig); + ($null, $form->{department_id}) = split(/--/, $form->{department}); $form->{department_id} *= 1; diff --git a/SL/AR.pm b/SL/AR.pm index 410ac99aa..b6c04f730 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -50,6 +50,7 @@ sub post_transaction { my @values; my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig); + $form->{defaultcurrency} = $form->get_default_currency($myconfig); # set exchangerate $form->{exchangerate} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 : @@ -147,7 +148,7 @@ sub post_transaction { # update exchangerate $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, $form->{exchangerate}, 0) - if ($form->{currency} ne $form->{defaultcurrency}) && $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy'); + if ($form->{currency} ne $form->{defaultcurrency}) && !$form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy'); if (!$payments_only) { $query = diff --git a/SL/Form.pm b/SL/Form.pm index f5305e044..172da36c7 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1127,6 +1127,16 @@ sub update_exchangerate { if ($curr eq '') { $main::lxdebug->leave_sub(); return; + } + my $query = qq|SELECT curr FROM defaults|; + + my ($currency) = selectrow_query($self, $dbh, $query); + my ($defaultcurrency) = split m/:/, $currency; + + + if ($curr eq $defaultcurrency) { + $main::lxdebug->leave_sub(); + return; } my $query = qq|SELECT e.curr FROM exchangerate e @@ -1134,6 +1144,16 @@ sub update_exchangerate { FOR UPDATE|; my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate); + if ($buy == 0) { + $buy = ""; + } + if ($sell == 0) { + $sell = ""; + } + + $buy = conv_i($buy, "NULL"); + $sell = conv_i($sell, "NULL"); + my $set; if ($buy != 0 && $sell != 0) { $set = "buy = $buy, sell = $sell"; @@ -1148,6 +1168,7 @@ sub update_exchangerate { SET $set WHERE curr = ? AND transdate = ?|; + } else { $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate) VALUES (?, $buy, $sell, ?)|; @@ -1165,12 +1186,15 @@ sub save_exchangerate { my $dbh = $self->dbconnect($myconfig); - my ($buy, $sell) = (0, 0); + my ($buy, $sell); + $buy = $rate if $fld eq 'buy'; $sell = $rate if $fld eq 'sell'; + $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell); + $dbh->disconnect; $main::lxdebug->leave_sub(); @@ -1186,13 +1210,21 @@ sub get_exchangerate { return 1; } + my $query = qq|SELECT curr FROM defaults|; + + my ($currency) = selectrow_query($self, $dbh, $query); + my ($defaultcurrency) = split m/:/, $currency; + + if ($currency eq $defaultcurrency) { + $main::lxdebug->leave_sub(); + return 1; + } + my $query = qq|SELECT e.$fld FROM exchangerate e WHERE e.curr = ? AND e.transdate = ?|; my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate); - if (!$exchangerate) { - $exchangerate = 1; - } + $main::lxdebug->leave_sub(); @@ -1209,14 +1241,19 @@ sub check_exchangerate { return ""; } - my $dbh = $self->dbconnect($myconfig); + my ($defaultcurrency) = $self->get_default_currency($myconfig); + + if ($currency eq $defaultcurrency) { + $main::lxdebug->leave_sub(); + return 1; + } + my $dbh = $self->get_standard_dbh($myconfig); my $query = qq|SELECT e.$fld FROM exchangerate e WHERE e.curr = ? AND e.transdate = ?|; + my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate); - $dbh->disconnect(); - $exchangerate = 1 if ($exchangerate == 0); $exchangerate = 1 if ($exchangerate eq ""); $main::lxdebug->leave_sub(); @@ -1224,6 +1261,23 @@ sub check_exchangerate { return $exchangerate; } +sub get_default_currency { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig) = @_; + my $dbh = $self->get_standard_dbh($myconfig); + + my $query = qq|SELECT curr FROM defaults|; + + my ($curr) = selectrow_query($self, $dbh, $query); + my ($defaultcurrency) = split m/:/, $curr; + + $main::lxdebug->leave_sub(); + + return $defaultcurrency; +} + + sub set_payment_options { $main::lxdebug->enter_sub(); diff --git a/SL/IR.pm b/SL/IR.pm index 98a53536f..177a287f0 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -46,6 +46,7 @@ sub post_invoice { # connect to database, turn off autocommit my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig); + $form->{defaultcurrency} = $form->get_default_currency($myconfig); my ($query, $sth, @values, $project_id); my ($allocated, $taxrate, $taxamount, $taxdiff, $item); diff --git a/SL/IS.pm b/SL/IS.pm index 78c065264..84baa08cb 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -492,6 +492,8 @@ sub post_invoice { if (!$form->{employee_id}) { $form->get_employee($dbh); } + + $form->{defaultcurrency} = $form->get_default_currency($myconfig); ($null, $form->{department_id}) = split(/--/, $form->{department}); diff --git a/SL/RP.pm b/SL/RP.pm index 21b199e02..68c6c75b6 100644 --- a/SL/RP.pm +++ b/SL/RP.pm @@ -980,6 +980,7 @@ sub trial_balance { $project AND ac.amount > 0 AND c.accno = ?) AS credit |; + $drcr = prepare_query($form, $dbh, $q_drcr); if ($form->{project_id}) { diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 4b2b4e1bd..6f86e90a1 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -213,10 +213,21 @@ sub form_header { ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0; $readonly = ($form->{radier}) ? "" : $readonly; + $form->{exchangerate} = $exchangerate + if ( + $form->{forex} = ( + $exchangerate = + $form->check_exchangerate( + \%myconfig, $form->{currency}, $form->{transdate}, 'sell' + ))); + + # format amounts $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); - + if ($form->{exchangerate} == 0) { + $form->{exchangerate} = ""; + } $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); $form->{creditremaining} = @@ -647,6 +658,9 @@ $jsscript } $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + if ($form->{"exchangerate_$i"} == 0) { + $form->{"exchangerate_$i"} = ""; + } $exchangerate = qq| |; if ($form->{currency} ne $form->{defaultcurrency}) { diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index ba98a8e38..c653382f7 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -232,10 +232,22 @@ sub form_header { s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } + $form->{exchangerate} = $exchangerate + if ( + $form->{forex} = ( + $exchangerate = + $form->check_exchangerate( + \%myconfig, $form->{currency}, $form->{transdate}, 'buy' + ))); + # format amounts $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); + if ($form->{exchangerate} == 0) { + $form->{exchangerate} = ""; + } + $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); $form->{creditremaining} = @@ -678,6 +690,10 @@ $jsscript $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + if ($form->{"exchangerate_$i"} == 0) { + $form->{"exchangerate_$i"} = ""; + } + $exchangerate = qq| |; if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{"forex_$i"}) { diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index cd20dda0d..feb43ace0 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -302,7 +302,7 @@ sub form_header { } } } - + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0; @@ -1031,6 +1031,9 @@ if ($form->{type} eq "credit_note") { $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + if ($form->{"exchangerate_$i"} == 0) { + $form->{"exchangerate_$i"} = ""; + } $exchangerate = qq| |; if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{"forex_$i"}) { @@ -1379,6 +1382,8 @@ sub update { sub post_payment { $lxdebug->enter_sub(); + + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); for $i (1 .. $form->{paidaccounts}) { if ($form->{"paid_$i"}) { $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); @@ -1410,6 +1415,8 @@ sub post_payment { sub post { $lxdebug->enter_sub(); + + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); $form->isblank("invdate", $locale->text('Invoice Date missing!')); $form->isblank("customer", $locale->text('Customer missing!')); diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 6ee8520c2..c1f06162f 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -331,6 +331,8 @@ sub form_header { $form->{salesman_id} = $form->{old_salesman_id}; } + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + map { $form->{$_} =~ s/\"/"/g } qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact @@ -570,6 +572,10 @@ sub form_header { $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); + if (!$form->{exchangerate}) { + $form->{exchangerate} = ""; + } + if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) { $creditwarning = 1; } else { @@ -1924,6 +1930,9 @@ sub subtotal { sub save_and_close { $lxdebug->enter_sub(); + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + + if ($form->{type} =~ /_order$/) { $form->isblank("transdate", $locale->text('Order Date missing!')); } else { @@ -2019,6 +2028,9 @@ sub save_and_close { sub save { $lxdebug->enter_sub(); + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + + if ($form->{type} =~ /_order$/) { $form->isblank("transdate", $locale->text('Order Date missing!')); } else { @@ -2270,6 +2282,8 @@ sub invoice { $form->{rowcount}--; $form->{shipto} = 1; + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + if ($form->{type} =~ /_order$/) { $form->{exchangerate} = $exchangerate; &create_backorder; -- 2.20.1