X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=172da36c77f5568e56dcda93e7754abdce0f5821;hb=89dd4ca84494de24ac1ecc7bd3b84fdd35e28020;hp=50b2e025d68bb394de22840248ebd506b4dd602d;hpb=ce47a2340ef118b494854deae1b0ddc74b1d1c5a;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index 50b2e025d..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(); @@ -2706,30 +2760,4 @@ sub all_years { $main::lxdebug->leave_sub(); } -sub mark_as_paid { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $db_name) = @_; - - if($self->{mark_as_paid}) { - my $dbh ||= $self->get_standard_dbh($myconfig); - my $query = qq|UPDATE $db_name SET paid = amount WHERE id = ?|; - do_query($self, $dbh, $query, $self->{id}); - $dbh->commit(); - $self->redirect($main::locale->text("Marked as paid")); - } - else { - my $referer = $ENV{HTTP_REFERER}; - $referer =~ s/^(.*)action\=.*\&(.*)$/$1action\=mark_as_paid\&mark_as_paid\=1\&login\=$self->{login}\&password\=$self->{password}\&id\=$self->{id}\&$2/; - $self->header(); - print qq||; - print qq|

|.$main::locale->text('Mark as paid?').qq|

|; - print qq| |; - print qq||; - print qq||; - } - - $main::lxdebug->leave_sub(); -} - 1;