push @values, "$transfer->{comment}";
- $qty = $transfer->{qty};
+ my $qty = $transfer->{qty};
if ($transfer->{unit}) {
my $partunit = $partunits{$transfer->{parts_id}};
}
if ($filter{chargenumber}) {
- push @filter_ary, "w1.chargenumber ILIKE ?";
+ push @filter_ary, "i1.chargenumber ILIKE ?";
push @filter_vars, '%' . $filter{chargenumber} . '%';
}
# build the select clauses.
# take all the requested ones from the first hash and overwrite them from the out/in hashes if present.
for my $i ('trans', 'out', 'in') {
- $select{$i} = join ', ', map { +/l_/; ($select_tokens{$i}{"$'"} || $select_tokens{'trans'}{"$'"}) . " AS r_$'" }
- ( grep( { !/qty$/ and /l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_qty l_partunit l_itime) );
+ $select{$i} = join ', ', map { +/^l_/; ($select_tokens{$i}{"$'"} || $select_tokens{'trans'}{"$'"}) . " AS r_$'" }
+ ( grep( { !/qty$/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_qty l_partunit l_itime) );
}
my $group_clause = join ", ", map { +/^l_/; "r_$'" }
- ( grep( { !/qty$/ and /l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_partunit l_itime) );
+ ( grep( { !/qty$/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_partunit l_itime) );
my $query =
qq|SELECT DISTINCT $select{trans}
"chargeid" => "c.id",
"warehousedescription" => "w.description",
"partunit" => "p.unit",
+ "stock_value" => "p.lastcost / COALESCE(pfac.factor, 1)",
);
- my $select_clause = join ', ', map { +/l_/; "$select_tokens{$'} AS $'" }
- ( grep( { !/qty/ and /l_/ and $form->{$_} eq 'Y' } keys %$form),
+ my $select_clause = join ', ', map { +/^l_/; "$select_tokens{$'} AS $'" }
+ ( grep( { !/qty/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form),
qw(l_parts_id l_qty l_partunit) );
my $group_clause = join ", ", map { +/^l_/; "$'" }
- ( grep( { !/qty/ and /l_/ and $form->{$_} eq 'Y' } keys %$form),
+ ( grep( { !/qty/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form),
qw(l_parts_id l_partunit) );
+ my %join_tokens = (
+ "stock_value" => "LEFT JOIN price_factors pfac ON (p.price_factor_id = pfac.id)",
+ );
+
+ my $joins = join ' ', grep { $_ } map { +/^l_/; $join_tokens{"$'"} }
+ ( grep( { !/qty/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form),
+ qw(l_parts_id l_qty l_partunit) );
+
my $query =
qq|SELECT $select_clause
$columns
LEFT JOIN parts p ON i.parts_id = p.id
LEFT JOIN bin b ON i.bin_id = b.id
LEFT JOIN warehouse w ON i.warehouse_id = w.id
+ $joins
WHERE $where_clause
GROUP BY $group_clause $group_by
ORDER BY $form->{sort}|;
@all_fields = keys %{ $ref } unless (@all_fields);
}
+ $ref->{stock_value} *= $ref->{qty};
+
push @contents, $ref;
}