Verbesserung Lesbarkeit von Code
authorNiclas Zimmermann <niclas@kivitendo-premium.de>
Fri, 10 May 2013 11:13:32 +0000 (13:13 +0200)
committerNiclas Zimmermann <niclas@kivitendo-premium.de>
Fri, 10 May 2013 11:13:32 +0000 (13:13 +0200)
Dieser Commit verbessert noch an Stellen, die Währungen betreffen,
die Lesbarkeit des Codes.

SL/AM.pm
SL/Form.pm
SL/IR.pm
SL/IS.pm

index fb600ba..6989e35 100644 (file)
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -1103,14 +1103,14 @@ sub save_defaults {
 
   for my $i (1..$form->{rowcount}) {
     if ($form->{"curr_$i"} ne $form->{"old_curr_$i"}) {
-      $query = qq|UPDATE currencies SET name = '| . $form->{"curr_$i"} . qq|' WHERE name = '| . $form->{"old_curr_$i"} . qq|'|;
-      do_query($form, $dbh, $query);
+      $query = qq|UPDATE currencies SET name = ? WHERE name = ?|;
+      do_query($form, $dbh, $query, $form->{"curr_$i"}, $form->{"old_curr_$i"});
     }
   }
 
   if (length($form->{new_curr}) > 0) {
-    $query = qq|INSERT INTO currencies (name) VALUES ('| . $form->{new_curr} . qq|')|;
-    do_query($form, $dbh, $query);
+    $query = qq|INSERT INTO currencies (name) VALUES (?)|;
+    do_query($form, $dbh, $query, $form->{new_curr});
   }
 
   $dbh->commit();
@@ -1292,25 +1292,12 @@ sub defaultaccounts {
   $sth->finish;
 
   #Get currencies:
-  $query = qq|SELECT name AS curr FROM currencies ORDER BY id|;
-
-  $form->{CURRENCIES} = [];
-
-  $sth = prepare_execute_query($form, $dbh, $query);
-  $sth->execute || $form->dberror($query);
-  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
-    push @{ $form->{ CURRENCIES } } , $ref;
-  }
-  $sth->finish;
+  $query              = qq|SELECT name AS curr FROM currencies ORDER BY id|;
+  $form->{CURRENCIES} = selectall_hashref_query($form, $dbh, $query);
 
   #Which of them is the default currency?
   $query = qq|SELECT name AS defaultcurrency FROM currencies WHERE id = (SELECT currency_id FROM defaults LIMIT 1);|;
-  $sth   = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
-
-  $form->{defaultcurrency}               = ($sth->fetchrow_hashref("NAME_lc"))->{defaultcurrency};
-
-  $sth->finish;
+  ($form->{defaultcurrency}) = selectrow_query($form, $dbh, $query);
 
   $dbh->disconnect;
 
index 0080dcc..f7097bd 100644 (file)
@@ -1631,14 +1631,8 @@ sub get_all_currencies {
   my $dbh      = $self->get_standard_dbh($myconfig);
   my @currencies =();
 
-  my $query = qq|SELECT name AS curr FROM currencies|;
-
-  my $sth = prepare_execute_query($self, $dbh, $query);
-
-  while (my $ref = $sth->fetchrow_hashref()) {
-    push(@currencies, $ref->{curr});
-  }
-  $sth->finish;
+  my $query = qq|SELECT name FROM currencies|;
+  my @currencies = map { $_->{name} } selectall_hashref_query($self, $dbh, $query);
 
   $main::lxdebug->leave_sub();
 
index 85f6b18..70a747e 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -1087,12 +1087,13 @@ sub get_vendor {
          v.id AS vendor_id, v.name AS vendor, v.discount as vendor_discount,
          v.creditlimit, v.terms, v.notes AS intnotes,
          v.email, v.cc, v.bcc, v.language_id, v.payment_id,
-         v.street, v.zipcode, v.city, v.country, v.taxzone_id, (SELECT cu.name FROM currencies cu WHERE cu.id=v.currency_id) AS curr, v.direct_debit,
+         v.street, v.zipcode, v.city, v.country, v.taxzone_id, cu.name AS curr, v.direct_debit,
          $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
          b.description AS business
        FROM vendor v
        LEFT JOIN business b       ON (b.id = v.business_id)
        LEFT JOIN payment_terms pt ON (v.payment_id = pt.id)
+       LEFT JOIN currencies cu    ON (v.currency_id = cu.id)
        WHERE 1=1 $where|;
   my $ref = selectfirst_hashref_query($form, $dbh, $query, @values);
   map { $params->{$_} = $ref->{$_} } keys %$ref;
@@ -1384,9 +1385,10 @@ sub vendor_details {
   # fax and phone and email as vendor*
   my $query =
     qq|SELECT ct.*, cp.*, ct.notes as vendornotes, phone as vendorphone, fax as vendorfax, email as vendoremail,
-         (SELECT cu.name FROM currencies cu WHERE cu.id=ct.currency_id) AS currency
+         cu.name AS currency
        FROM vendor ct
        LEFT JOIN contacts cp ON (ct.id = cp.cp_cv_id)
+       LEFT JOIN currencies cu ON (ct.currency_id = cu.id)
        WHERE (ct.id = ?) $contact
        ORDER BY cp.cp_id
        LIMIT 1|;
index 46a10f4..35c2c40 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -458,9 +458,10 @@ sub customer_details {
   my $query =
     qq|SELECT ct.*, cp.*, ct.notes as customernotes,
          ct.phone AS customerphone, ct.fax AS customerfax, ct.email AS customeremail,
-         (SELECT cu.name FROM currencies cu WHERE cu.id=ct.currency_id) AS currency
+         cu.name AS currency
        FROM customer ct
        LEFT JOIN contacts cp on ct.id = cp.cp_cv_id
+       LEFT JOIN currencies cu ON (ct.currency_id = cu.id)
        WHERE (ct.id = ?) $where
        ORDER BY cp.cp_id
        LIMIT 1|;
@@ -1750,13 +1751,14 @@ sub get_customer {
          c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit, c.terms,
          c.email, c.cc, c.bcc, c.language_id, c.payment_id,
          c.street, c.zipcode, c.city, c.country,
-         c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, (SELECT cu.name FROM currencies cu WHERE cu.id=c.currency_id) AS curr,
+         c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, cu.name AS curr,
          c.taxincluded_checked, c.direct_debit,
          $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
          b.discount AS tradediscount, b.description AS business
        FROM customer c
        LEFT JOIN business b ON (b.id = c.business_id)
        LEFT JOIN payment_terms pt ON ($payment_id (c.payment_id = pt.id))
+       LEFT JOIN currencies cu ON (c.currency_id=cu.id)
        WHERE c.id = ?|;
   push @values, $cid;
   $ref = selectfirst_hashref_query($form, $dbh, $query, @values);