+  #/transdate
+  my $inc_exp = $form->{"vc"} eq "customer" ? "income_accno_id" : "expense_accno_id";
+
+  my @part_ids = grep { $_ } values %args;
+  my $in       = join ',', ('?') x @part_ids;
+
+  my %accno_by_part = map { $_->{id} => $_ }
+    selectall_hashref_query($form, $dbh, <<SQL, @part_ids);
+    SELECT
+      p.id, p.inventory_accno_id AS is_part,
+      bg.inventory_accno_id,
+      tc.income_accno_id AS income_accno_id,
+      tc.expense_accno_id AS expense_accno_id,
+      c1.accno AS inventory_accno,
+      c2.accno AS income_accno,
+      c3.accno AS expense_accno
+    FROM parts p
+    LEFT JOIN buchungsgruppen bg ON p.buchungsgruppen_id = bg.id
+    LEFT JOIN taxzone_charts tc on bg.id = tc.buchungsgruppen_id
+    LEFT JOIN chart c1 ON bg.inventory_accno_id = c1.id
+    LEFT JOIN chart c2 ON tc.income_accno_id = c2.id
+    LEFT JOIN chart c3 ON tc.expense_accno_id = c3.id
+    WHERE
+    tc.taxzone_id = '$form->{taxzone_id}'
+    and
+    p.id IN ($in)
+SQL
+
+  my $sth_tax = prepare_query($::form, $dbh, <<SQL);
+    SELECT c.accno, t.taxdescription AS description, t.rate, t.taxnumber
+    FROM tax t
+    LEFT JOIN chart c ON c.id = t.chart_id
+    WHERE t.id IN
+      (SELECT tk.tax_id
+       FROM taxkeys tk
+       WHERE tk.chart_id = ? AND startdate <= ?
+       ORDER BY startdate DESC LIMIT 1)
+SQL
+
+  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"};
+
+    my %accounts;
+    for my $type (qw(inventory income expense)) {
+      next unless $ref->{"${type}_accno_id"};
+      ($accounts{"${type}_accno_id"}, $accounts{"${type}_accno"}) =
+        $self->follow_account_chain($form, $dbh, $transdate, $ref->{"${type}_accno_id"}, $ref->{"${type}_accno"});
+    }