my $f_op = $params{filter}->{"${name}_qtyop"};
+ my $op;
if ($f_op eq '==') {
$op = '=';
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;
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}};
$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};
}
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 (
serialnumber => 'ioi.',
quotation => 'apoe.',
cv => 'cv.',
+ "ioi.id" => ' ',
+ "ioi.ioi" => ' ',
);
# if the join condition in these blocks are met, the column
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}) {
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};
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);
'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;