X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/be776964b83340e69fa2f02eae59b703c0c95b88..7635f647ec7dcdef51684b21601ee0930ea2bc5b:/SL/AM.pm diff --git a/SL/AM.pm b/SL/AM.pm index e4727047c..4934d866c 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -40,6 +40,7 @@ package AM; use Carp; use Data::Dumper; use Encode; +use List::MoreUtils qw(any); use SL::DBUtils; use strict; @@ -207,14 +208,15 @@ sub save_account { # connect to database, turn off AutoCommit my $dbh = $form->dbconnect_noauto($myconfig); - # sanity check, can't have AR with AR_... - if ($form->{AR} || $form->{AP} || $form->{IC}) { - map { delete $form->{$_} } - qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_sale IC_cogs IC_taxpart IC_income IC_expense IC_taxservice); + for (qw(AR_include_in_dropdown AP_include_in_dropdown summary_account)) { + $form->{$form->{$_}} = $form->{$_} if $form->{$_}; } - for (qw(AR_include_in_dropdown AP_include_in_dropdown)) { - $form->{$form->{$_}} = $form->{$_} if $form->{$_}; + # sanity check, can't have AR with AR_... + if ($form->{AR} || $form->{AP} || $form->{IC}) { + if (any { $form->{$_} } qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_sale IC_cogs IC_taxpart IC_income IC_expense IC_taxservice)) { + $form->error($::locale->text('It is not allowed that a summary account occurs in a drop-down menu!')); + } } $form->{link} = ""; @@ -1103,14 +1105,14 @@ sub save_defaults { for my $i (1..$form->{rowcount}) { if ($form->{"curr_$i"} ne $form->{"old_curr_$i"}) { - $query = qq|UPDATE currencies SET curr = '| . $form->{"curr_$i"} . qq|' WHERE curr = '| . $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 (curr) 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 +1294,12 @@ sub defaultaccounts { $sth->finish; #Get currencies: - $query = qq|SELECT 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 curr AS defaultcurrency FROM currencies WHERE id = (SELECT curr FROM defaults LIMIT 1);|; - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - $form->{defaultcurrency} = ($sth->fetchrow_hashref("NAME_lc"))->{defaultcurrency}; - - $sth->finish; + $query = qq|SELECT name AS defaultcurrency FROM currencies WHERE id = (SELECT currency_id FROM defaults LIMIT 1);|; + ($form->{defaultcurrency}) = selectrow_query($form, $dbh, $query); $dbh->disconnect; @@ -2127,9 +2116,10 @@ sub get_warehouse { map { $form->{$_} = $ref->{$_} } keys %{ $ref }; $query = qq|SELECT b.*, EXISTS - (SELECT i.warehouse_id - FROM inventory i + (SELECT i.warehouse_id, p.warehouse_id + FROM inventory i, parts p WHERE i.bin_id = b.id + OR p.bin_id = b.id LIMIT 1) AS in_use FROM bin b