From 1163cee7d5cfe9355a9d231ac544ce0943623d77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 29 Sep 2009 16:51:58 +0200 Subject: [PATCH] =?utf8?q?Warensuche:=20=C3=BCberlagerte=20custom=20variab?= =?utf8?q?les=20werden=20nun=20korrekt=20auch=20in=20der=20Warensuche=20?= =?utf8?q?=C3=BCberlagert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/CVar.pm | 10 ++++++++-- SL/IC.pm | 20 ++++++++++++++++---- bin/mozilla/ic.pl | 7 +++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/SL/CVar.pm b/SL/CVar.pm index 6e99ae404..6976a99a5 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -438,6 +438,7 @@ sub build_filter_query { my $f_op = $params{filter}->{"${name}_qtyop"}; + my $op; if ($f_op eq '==') { $op = '='; @@ -515,6 +516,11 @@ sub add_custom_variables_to_report { return; } + # allow sub_module to be a coderef or a fixed value + if (ref $params{sub_module} ne 'CODE') { + $params{sub_module} = sub { "$params{sub_module}" }; + } + my %cfg_map = map { $_->{id} => $_ } @{ $configs }; my @cfg_ids = keys %cfg_map; @@ -527,7 +533,7 @@ sub add_custom_variables_to_report { my $sth = prepare_query($form, $dbh, $query); foreach my $row (@{ $params{data} }) { - do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}), "$params{sub_module}"); + do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}), $params{sub_module}->($row)); while (my $ref = $sth->fetchrow_hashref()) { my $cfg = $cfg_map{$ref->{config_id}}; @@ -535,7 +541,7 @@ sub add_custom_variables_to_report { $row->{"cvar_$cfg->{name}"} = $cfg->{type} eq 'date' ? $ref->{date_value} : $cfg->{type} eq 'timestamp' ? $ref->{timestamp_value} - : $cfg->{type} eq 'number' ? $form->format_amount($myconfig, $ref->{number_value} * 1, $config->{precision}) + : $cfg->{type} eq 'number' ? $form->format_amount($myconfig, $ref->{number_value} * 1, $cfg->{precision}) : $cfg->{type} eq 'bool' ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No')) : $ref->{text_value}; } diff --git a/SL/IC.pm b/SL/IC.pm index c710af9fc..ff4ce095b 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -792,8 +792,8 @@ sub all_parts { pfac => 'LEFT JOIN price_factors pfac ON (pfac.id = p.price_factor_id)', invoice_oi => q|LEFT JOIN ( - SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, assemblyitem, deliverydate, 'invoice' AS ioi FROM invoice UNION - SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, FALSE AS assemblyitem, NULL AS deliverydate, 'orderitems' AS ioi FROM orderitems + SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, assemblyitem, deliverydate, 'invoice' AS ioi, id FROM invoice UNION + SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, FALSE AS assemblyitem, NULL AS deliverydate, 'orderitems' AS ioi, id FROM orderitems ) AS ioi ON ioi.parts_id = p.id|, apoe => q|LEFT JOIN ( @@ -824,6 +824,8 @@ sub all_parts { serialnumber => 'ioi.', quotation => 'apoe.', cv => 'cv.', + "ioi.id" => ' ', + "ioi.ioi" => ' ', ); # if the join condition in these blocks are met, the column @@ -841,6 +843,8 @@ sub all_parts { my %renamed_columns = ( 'factor' => 'price_factor', 'SUM(ioi.qty)' => 'soldtotal', + 'ioi.id' => 'ioi_id', + 'ioi.ioi' => 'ioi', ); if (($form->{searchitems} eq 'assembly') && $form->{l_lastcost}) { @@ -937,7 +941,7 @@ sub all_parts { my $bsooqr = any { $form->{$_} } @oe_flags; my @bsooqr_tokens = (); - push @select_tokens, @qsooqr_flags, 'quotation', 'cv' if $bsooqr; + push @select_tokens, @qsooqr_flags, 'quotation', 'cv', 'ioi.id', 'ioi.ioi' if $bsooqr; push @select_tokens, @deliverydate_flags if $bsooqr && $form->{l_deliverydate}; push @select_tokens, $q_assembly_lastcost if ($form->{searchitems} eq 'assembly') && $form->{l_lastcost}; push @bsooqr_tokens, q|module = 'ir' AND NOT ioi.assemblyitem| if $form->{bought}; @@ -1005,7 +1009,15 @@ sub all_parts { push @bind_vars, @cvar_values; } - my $query = qq|SELECT DISTINCT $select_clause FROM parts p $join_clause WHERE $where_clause $group_clause $order_clause $limit_clause|; + my $query = <<" SQL"; + SELECT DISTINCT $select_clause + FROM parts p + $join_clause + WHERE $where_clause + $group_clause + $order_clause + $limit_clause + SQL $form->{parts} = selectall_hashref_query($form, $dbh, $query, @bind_vars); diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl index faaa702dc..8cbb547f7 100644 --- a/bin/mozilla/ic.pl +++ b/bin/mozilla/ic.pl @@ -1241,6 +1241,13 @@ sub generate_report { 'column_defs' => \%column_defs, 'data' => $form->{parts}); + CVar->add_custom_variables_to_report('module' => 'IC', + 'sub_module' => sub { $_[0]->{ioi} }, + 'trans_id_field' => 'ioi_id', + 'configs' => $cvar_configs, + 'column_defs' => \%column_defs, + 'data' => $form->{parts}); + my @subtotal_columns = qw(sellprice listprice lastcost); my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns); my %totals = map { $_ => 0 } @subtotal_columns; -- 2.20.1