From 47c3bf62b5126f914de54609b0cfbb29e0c033b4 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 28 Nov 2008 14:54:33 +0000 Subject: [PATCH] =?utf8?q?Einige=20Variablen=20der=20Warenstammdaten=20auc?= =?utf8?q?h=20beim=20Ausdruck=20zur=20Verf=C3=BCgung=20stellen:=20ean,=20m?= =?utf8?q?ake,=20model.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/IC.pm | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SL/IS.pm | 3 +++ SL/OE.pm | 3 +++ 3 files changed, 74 insertions(+) diff --git a/SL/IC.pm b/SL/IC.pm index 45fcebb1b..a643557d7 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -1796,5 +1796,73 @@ sub get_basic_part_info { return %info_map; } +sub prepare_parts_for_printing { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + my $prefix = $params{prefix} || 'id_'; + my $rowcount = defined $params{rowcount} ? $params{rowcount} : $form->{rowcount}; + + my @part_ids = keys %{ { map { $_ => 1 } grep { $_ } map { $form->{"${prefix}${_}"} } (1 .. $rowcount) } }; + + if (!@part_ids) { + $main::lxdebug->leave_sub(); + return; + } + + my $placeholders = join ', ', ('?') x scalar(@part_ids); + my $query = qq|SELECT parts_id, make, model + FROM makemodel + WHERE parts_id IN ($placeholders)|; + my %makemodel = (); + + my $sth = prepare_execute_query($form, $dbh, $query, @part_ids); + + while (my $ref = $sth->fetchrow_hashref()) { + $makemodel{$ref->{parts_id}} ||= []; + push @{ $makemodel{$ref->{parts_id}} }, $ref; + } + + $sth->finish(); + + my @columns = qw(ean); + + $query = qq|SELECT id, | . join(', ', @columns) . qq| + FROM parts + WHERE id IN ($placeholders)|; + + my %data = selectall_as_map($form, $dbh, $query, 'id', \@columns, @part_ids); + + map { $form->{$_} = [] } (qw(make model), @columns); + + foreach my $i (1 .. $rowcount) { + my $id = $form->{"${prefix}${i}"}; + + next if (!$id); + + foreach (@columns) { + push @{ $form->{$_} }, $data{$id}->{$_}; + } + + push @{ $form->{make} }, []; + push @{ $form->{model} }, []; + + next if (!$makemodel{$id}); + + foreach my $ref (@{ $makemodel{$id} }) { + map { push @{ $form->{$_}->[-1] }, $ref->{$_} } qw(make model); + } + } + + $main::lxdebug->leave_sub(); +} + 1; diff --git a/SL/IS.pm b/SL/IS.pm index b782fef26..af47ca7d0 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -43,6 +43,7 @@ use SL::Common; use SL::DBUtils; use SL::DO; use SL::MoreCommon; +use SL::IC; use Data::Dumper; sub invoice_details { @@ -132,6 +133,8 @@ sub invoice_details { $form->{discount} = []; + IC->prepare_parts_for_printing(); + my @arrays = qw(runningnumber number description longdescription qty ship unit bin deliverydate_oe ordnumber_oe transdate_oe licensenumber validuntil diff --git a/SL/OE.pm b/SL/OE.pm index 6013d24c5..3afd46262 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -39,6 +39,7 @@ use List::Util qw(max); use SL::AM; use SL::Common; use SL::DBUtils; +use SL::IC; sub transactions { $main::lxdebug->enter_sub(); @@ -950,6 +951,8 @@ sub order_details { $form->{discount} = []; + IC->prepare_parts_for_printing(); + my @arrays = qw(runningnumber number description longdescription qty ship unit bin partnotes serialnumber reqdate sellprice listprice netprice -- 2.20.1