Falschen Spaltennamen korrigiert.
[kivitendo-erp.git] / SL / Form.pm
index 50b2e02..172da36 100644 (file)
@@ -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|<body>|;
-    print qq|<p><b>|.$main::locale->text('Mark as paid?').qq|</b></p>|;
-    print qq|<input type="button" value="|.$main::locale->text('yes').qq|" onclick="document.location.href='|.$referer.qq|'">&nbsp;|;
-    print qq|<input type="button" value="|.$main::locale->text('no').qq|" onclick="javascript:history.back();">|;
-    print qq|</body></html>|;
-  }
-  
-  $main::lxdebug->leave_sub();
-}
-
 1;