X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIC.pm;h=3845017f36551c697f9cc21d68abc91fdc94ba99;hb=ad27efa6a3b7e8feea8497c24acebe5bd501156b;hp=13cf55e00e9d89d7a5e79e6e48cd1eb5dfa3b968;hpb=1228aa97dd33175f74c5dfbdf759a6b3d9458f93;p=kivitendo-erp.git diff --git a/SL/IC.pm b/SL/IC.pm index 13cf55e00..3845017f3 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 @@ -1453,17 +1453,17 @@ sub follow_account_chain { my ($query, $sth); - $query = - qq|SELECT c.new_chart_id, date($transdate) >= c.valid_from AS is_valid, | . - qq| cnew.accno | . - qq|FROM chart c | . - qq|LEFT JOIN chart cnew ON c.new_chart_id = cnew.id | . - qq|WHERE (c.id = ?) AND NOT c.new_chart_id IS NULL AND (c.new_chart_id > 0)|; - $sth = prepare_query($form, $dbh, $query); + $form->{ACCOUNT_CHAIN_BY_ID} ||= { + map { $_->{id} => $_ } + selectall_hashref_query($form, $dbh, <= c.valid_from AS is_valid, cnew.accno + FROM chart c + LEFT JOIN chart cnew ON c.new_chart_id = cnew.id + WHERE NOT c.new_chart_id IS NULL AND (c.new_chart_id > 0) +SQL while (1) { - do_statement($form, $sth, $query, $accno_id); - my $ref = $sth->fetchrow_hashref(); + my $ref = $form->{ACCOUNT_CHAIN_BY_ID}->{$accno_id}; last unless ($ref && $ref->{"is_valid"} && !grep({ $_ == $ref->{"new_chart_id"} } @visited_accno_ids)); $accno_id = $ref->{"new_chart_id"}; @@ -1477,18 +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 ($query, $sth); + 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") { @@ -1509,10 +1509,15 @@ sub retrieve_accounts { $transdate = $dbh->quote($transdate); } #/transdate + my $inc_exp = $form->{"vc"} eq "customer" ? "income_accno_id" : "expense_accno_id"; - 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, @@ -1524,10 +1529,10 @@ 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_tx = prepare_query($::form, $dbh, <fetchrow_hashref($part_id) 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"}; @@ -1552,8 +1557,8 @@ SQL $form->{"${_}_accno_$index"} = $accounts{"${_}_accno"} for qw(inventory income expense); - my $inc_exp = $form->{"vc"} eq "customer" ? "income" : "expense"; - $ref = $sth->fetchrow_hashref($accounts{"${inc_exp}_accno_id"}, quote_db_date($transdate)) or next; + $sth_tax->execute($accounts{$inc_exp}, quote_db_date($transdate)); + $ref = $sth_tax->fetchrow_hashref or next; $form->{"taxaccounts_$index"} = $ref->{"accno"}; $form->{"taxaccounts"} .= "$ref->{accno} "if $form->{"taxaccounts"} !~ /$ref->{accno}/; @@ -1561,7 +1566,9 @@ SQL $form->{"$ref->{accno}_${_}"} = $ref->{$_} for qw(rate description taxnumber); } - $::lxdebug->leave_sub(2); + $sth_tax->finish; + + $::lxdebug->leave_sub; } sub get_basic_part_info {