package IC;
use Data::Dumper;
-use List::MoreUtils qw(all any);
+use List::MoreUtils qw(all any uniq);
use YAML;
use SL::CVar;
if (($form->{"make_$i"}) || ($form->{"model_$i"})) {
$query = qq|INSERT INTO makemodel (parts_id, make, model) | .
- qq|VALUES (?, ?, ?)|;
- @values = (conv_i($form->{id}), conv_i($form->{"make_$i"}), $form->{"model_$i"});
+ qq|VALUES (?, ?, ?)|;
+ @values = (conv_i($form->{id}), conv_i($form->{"make_$i"}), $form->{"model_$i"});
do_query($form, $dbh, $query, @values);
}
$query =
qq|INSERT INTO partstax (parts_id, chart_id)
VALUES (?, (SELECT id FROM chart WHERE accno = ?))|;
- @values = (conv_i($form->{id}), $item);
+ @values = (conv_i($form->{id}), $item);
do_query($form, $dbh, $query, @values);
}
}
if ($form->{"qty_$i"} != 0) {
$form->{"bom_$i"} *= 1;
$query = qq|INSERT INTO assembly (id, parts_id, qty, bom) | .
- qq|VALUES (?, ?, ?, ?)|;
- @values = (conv_i($form->{id}), conv_i($form->{"id_$i"}), conv_i($form->{"qty_$i"}), $form->{"bom_$i"} ? 't' : 'f');
+ qq|VALUES (?, ?, ?, ?)|;
+ @values = (conv_i($form->{id}), conv_i($form->{"id_$i"}), conv_i($form->{"qty_$i"}), $form->{"bom_$i"} ? 't' : 'f');
do_query($form, $dbh, $query, @values);
}
}
) AS ioi ON ioi.parts_id = p.id|,
apoe =>
q|LEFT JOIN (
- SELECT id, transdate, 'ir' AS module, ordnumber, quonumber, invnumber, FALSE AS quotation, NULL AS customer_id, vendor_id, NULL AS deliverydate, 'invoice' AS ioi FROM ap UNION
- SELECT id, transdate, 'is' AS module, ordnumber, quonumber, invnumber, FALSE AS quotation, customer_id, NULL AS vendor_id, deliverydate, 'invoice' AS ioi FROM ar UNION
- SELECT id, transdate, 'oe' AS module, ordnumber, quonumber, NULL AS invnumber, quotation, customer_id, vendor_id, NULL AS deliverydate, 'orderitems' AS ioi FROM oe
+ SELECT id, transdate, 'ir' AS module, ordnumber, quonumber, invnumber, FALSE AS quotation, NULL AS customer_id, vendor_id, NULL AS deliverydate, 'invoice' AS ioi FROM ap UNION
+ SELECT id, transdate, 'is' AS module, ordnumber, quonumber, invnumber, FALSE AS quotation, customer_id, NULL AS vendor_id, deliverydate, 'invoice' AS ioi FROM ar UNION
+ SELECT id, transdate, 'oe' AS module, ordnumber, quonumber, NULL AS invnumber, quotation, customer_id, vendor_id, reqdate AS deliverydate, 'orderitems' AS ioi FROM oe
) AS apoe ON ((ioi.trans_id = apoe.id) AND (ioi.ioi = apoe.ioi))|,
cv =>
q|LEFT JOIN (
#my $order_clause = " ORDER BY $form->{sort} $sort_order";
- my $limit_clause = " LIMIT 100" if $form->{top100};
+ my $limit_clause;
+ $limit_clause = " LIMIT 100" if $form->{top100};
+ $limit_clause = " LIMIT " . $form->{limit} * 1 if $form->{limit} * 1;
#=== joins and complicated filters ========#
# now the master trick: soldtotal.
if ($form->{l_soldtotal}) {
- push @where_tokens, 'ioi.qty >= 0';
+ push @where_tokens, 'NOT ioi.qty = 0';
push @group_tokens, @select_tokens;
map { s/.*\sAS\s+//si } @group_tokens;
push @select_tokens, 'SUM(ioi.qty)';
my $where_clause = join ' AND ', map { "($_)" } @where_tokens;
my $group_clause = ' GROUP BY ' . join ', ', map { $token_builder->($_) } @group_tokens if scalar @group_tokens;
- my ($cvar_where, @cvar_values) = CVar->build_filter_query('module' => 'IC',
- 'trans_id_field' => 'p.id',
- 'filter' => $form);
+ my %oe_flag_to_cvar = (
+ bought => 'invoice',
+ sold => 'invoice',
+ onorder => 'orderitems',
+ ordered => 'orderitems',
+ rfq => 'orderitems',
+ quoted => 'orderitems',
+ );
+
+ my ($cvar_where, @cvar_values) = CVar->build_filter_query(
+ module => 'IC',
+ trans_id_field => $bsooqr ? 'ioi.id': 'p.id',
+ filter => $form,
+ sub_module => $bsooqr ? [ uniq grep { $oe_flag_to_cvar{$form->{$_}} } @oe_flags ] : undef,
+ );
if ($cvar_where) {
$where_clause .= qq| AND ($cvar_where)|;
qq| cnew.accno | .
qq|FROM chart c | .
qq|LEFT JOIN chart cnew ON c.new_chart_id = cnew.id | .
- qq|WHERE (c.id = ?) AND NOT c.new_chart_id ISNULL AND (c.new_chart_id > 0)|;
+ qq|WHERE (c.id = ?) AND NOT c.new_chart_id IS NULL AND (c.new_chart_id > 0)|;
$sth = prepare_query($form, $dbh, $query);
while (1) {