X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FForm.pm;h=172da36c77f5568e56dcda93e7754abdce0f5821;hb=89dd4ca84494de24ac1ecc7bd3b84fdd35e28020;hp=d39625d482fc34fd5430370e892596b14435d6dc;hpb=820f3066c313c0538f7abdf90b3a8e12a28449e2;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index d39625d48..172da36c7 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1066,7 +1066,7 @@ sub dbconnect_noauto { $main::lxdebug->enter_sub(); my ($self, $myconfig) = @_; - + # connect to database $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, @@ -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();