From a87dd0ec36ef206227750773a4e36e20689a9f57 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 22 Jul 2010 12:37:05 +0200 Subject: [PATCH] Batchaccounts angewendet. Ausserdem einen subtilen Bug behoben, und ein Query gecacht. --- SL/IC.pm | 28 ++++++++++++++++------------ bin/mozilla/io.pl | 6 +----- bin/mozilla/oe.pl | 4 +--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/SL/IC.pm b/SL/IC.pm index bb8f194cc..88256cd25 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -1,4 +1,4 @@ -#===================================================================== + #===================================================================== # LX-Office ERP # Copyright (C) 2004 # Based on SQL-Ledger Version 2.1.9 @@ -1477,16 +1477,18 @@ sub follow_account_chain { } sub retrieve_accounts { - $main::lxdebug->enter_sub(2); + $main::lxdebug->enter_sub; my $self = shift; my $myconfig = shift; my $form = shift; my $dbh = $form->get_standard_dbh; - my %args = @_; # part_id => index + my %args = @_; # index => part_id $form->{taxzone_id} *= 1; + return unless grep $_, values %args; # shortfuse if no part_id supplied + # transdate madness. my $transdate = ""; if ($form->{type} eq "invoice") { @@ -1507,10 +1509,15 @@ sub retrieve_accounts { $transdate = $dbh->quote($transdate); } #/transdate + my $inc_exp = $form->{"vc"} eq "customer" ? "income" : "expense"; + + my @part_ids = grep { $_ } values %args; + my $in = join ',', ('?') x @part_ids; - my $sth_accno = prepare_query($::form, $dbh, <{id} => $_ } + selectall_hashref_query($form, $dbh, <{taxzone_id} AS income_accno_id, bg.expense_accno_id_$form->{taxzone_id} AS expense_accno_id, @@ -1522,7 +1529,7 @@ sub retrieve_accounts { LEFT JOIN chart c1 ON bg.inventory_accno_id = c1.id LEFT JOIN chart c2 ON bg.income_accno_id_$form->{taxzone_id} = c2.id LEFT JOIN chart c3 ON bg.expense_accno_id_$form->{taxzone_id} = c3.id - WHERE p.id = ? + WHERE p.id IN ($in) SQL my $sth_tax = prepare_query($::form, $dbh, <execute($part_id); - my $ref = $sth_accno->fetchrow_hashref or next; + while (my ($index => $part_id) = each %args) { + my $ref = $accno_by_part{$part_id} or next; $ref->{"inventory_accno_id"} = undef unless $ref->{"is_part"}; @@ -1551,7 +1557,6 @@ SQL $form->{"${_}_accno_$index"} = $accounts{"${_}_accno"} for qw(inventory income expense); - my $inc_exp = $form->{"vc"} eq "customer" ? "income" : "expense"; $sth_tax->execute($accounts{"${inc_exp}_accno_id"}, quote_db_date($transdate)); $ref = $sth_tax->fetchrow_hashref or next; @@ -1561,10 +1566,9 @@ SQL $form->{"$ref->{accno}_${_}"} = $ref->{$_} for qw(rate description taxnumber); } - $sth_accno->finish; $sth_tax->finish; - $::lxdebug->leave_sub(2); + $::lxdebug->leave_sub; } sub get_basic_part_info { diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index c2e4bd45e..adaa39946 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -1977,11 +1977,7 @@ sub relink_accounts { } $form->{"taxaccounts"} = ""; - for (my $i = 1; $i <= $form->{"rowcount"}; $i++) { - if ($form->{"id_$i"}) { - IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i); - } - } + IC->retrieve_accounts(\%myconfig, $form, map { $_ => $form->{"id_$_"} } 1 .. $form->{rowcount}); $main::lxdebug->leave_sub(); } diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 2e9ab7f90..20bb0fd28 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -1896,9 +1896,7 @@ sub display_form { } $form->{"taxaccounts"} = ""; - for my $i (1 .. $form->{"rowcount"}) { - IC->retrieve_accounts(\%myconfig, $form, $form->{"id_$i"}, $i) if $form->{"id_$i"}; - } + IC->retrieve_accounts(\%myconfig, $form, map { $_ => $form->{"id_$_"} } 1 .. $form->{rowcount}); $form->{rowcount}++; $form->{"project_id_$form->{rowcount}"} = $form->{globalproject_id}; -- 2.20.1