From: Niclas Zimmermann Date: Fri, 10 May 2013 11:13:32 +0000 (+0200) Subject: Verbesserung Lesbarkeit von Code X-Git-Tag: release-3.1.0beta1~401^2~21^2~6 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ba6a136694f2e54e7bf21b1ecfabfcb872784ef4;p=kivitendo-erp.git Verbesserung Lesbarkeit von Code Dieser Commit verbessert noch an Stellen, die Währungen betreffen, die Lesbarkeit des Codes. --- diff --git a/SL/AM.pm b/SL/AM.pm index fb600ba62..6989e3590 100644 --- 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; diff --git a/SL/Form.pm b/SL/Form.pm index 0080dccd8..f7097bda3 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -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(); diff --git a/SL/IR.pm b/SL/IR.pm index 85f6b18f6..70a747efa 100644 --- 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|; diff --git a/SL/IS.pm b/SL/IS.pm index 46a10f4e3..35c2c4091 100644 --- 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);