require SL::DB::Part;
require SL::DB::Employee;
- my $employee = SL::DB::Manager::Employee->find_by(login => $::myconfig{login});
+ my $employee = SL::DB::Manager::Employee->current;
my ($now) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT current_date|);
my @directions = (undef, qw(out in transfer));
my $where_clause = @filter_ary ? join(" AND ", @filter_ary) . " AND " : '';
+ my ($cvar_where, @cvar_values) = CVar->build_filter_query(
+ module => 'IC',
+ trans_id_field => 'p.id',
+ filter => $form,
+ sub_module => undef,
+ );
+
+ if ($cvar_where) {
+ $where_clause .= qq| ($cvar_where) AND |;
+ push @filter_vars, @cvar_values;
+ }
+
$select_tokens{'trans'} = {
"parts_id" => "i1.parts_id",
"qty" => "ABS(SUM(i1.qty))",
# 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_shippingdate) );
+ ( grep( { !/qty$/ and !/^l_cvar/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_qty l_partunit l_shippingdate) );
}
my $group_clause = join ", ", map { +/^l_/; "r_$'" }
- ( grep( { !/qty$/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_partunit l_shippingdate l_itime) );
+ ( grep( { !/qty$/ and !/^l_cvar/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form), qw(l_parts_id l_partunit l_shippingdate l_itime) );
$where_clause = defined($where_clause) ? $where_clause : '';
push @filter_vars, $filter{partsid};
}
+ if ($filter{partsgroup_id}) {
+ push @filter_ary, "p.partsgroup_id = ?";
+ push @filter_vars, $filter{partsgroup_id};
+ }
+
if ($filter{chargenumber}) {
push @filter_ary, "i.chargenumber ILIKE ?";
push @filter_vars, like($filter{chargenumber});
$form->{l_part_type} = 'Y';
my $select_clause = join ', ', map { +/^l_/; "$select_tokens{$'} AS $'" }
- ( grep( { !/qty/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form),
+ ( grep( { !/qty/ and !/^l_cvar/ 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_cvar/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form),
qw(l_parts_id l_partunit) );
my %join_tokens = (
);
my $joins = join ' ', grep { $_ } map { +/^l_/; $join_tokens{"$'"} }
- ( grep( { !/qty/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form),
+ ( grep( { !/qty/ and !/^l_cvar/ and /^l_/ and $form->{$_} eq 'Y' } keys %$form),
qw(l_parts_id l_qty l_partunit) );
+ my ($cvar_where, @cvar_values) = CVar->build_filter_query(
+ module => 'IC',
+ trans_id_field => 'p.id',
+ filter => $form,
+ sub_module => undef,
+ );
+
+ if ($cvar_where) {
+ $where_clause .= qq| AND ($cvar_where)|;
+ push @filter_vars, @cvar_values;
+ }
+
my $query =
qq|SELECT * FROM ( SELECT $select_clause
FROM inventory i