my ($null, $department_id) = split /--/, $form->{department};
my $department = " AND o.department_id = $department_id" if $department_id;
+ my @values;
+
+ if ($form->{"project_id"}) {
+ $department .=
+ qq|AND ((globalproject_id = ?) OR EXISTS | .
+ qq| (SELECT * FROM orderitems oi | .
+ qq| WHERE oi.project_id = ? AND oi.trans_id = o.id))|;
+ push(@values, $form->{"project_id"}, $form->{"project_id"});
+ }
my $rate = ($form->{vc} eq 'customer') ? 'buy' : 'sell';
my $query = qq|SELECT o.id, o.ordnumber, o.transdate, o.reqdate,
o.amount, ct.name, o.netamount, o.$form->{vc}_id,
+ o.globalproject_id, pr.projectnumber AS globalprojectnumber,
ex.$rate AS exchangerate,
o.closed, o.delivered, o.quonumber, o.shippingpoint, o.shipvia,
e.name AS employee
LEFT JOIN employee e ON (o.employee_id = e.id)
LEFT JOIN exchangerate ex ON (ex.curr = o.curr
AND ex.transdate = o.transdate)
+ LEFT JOIN project pr ON o.globalproject_id = pr.id
WHERE o.quotation = '$quotation'
$department|;
$query .= " ORDER by $sortorder";
my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth->execute(@values) ||
+ $form->dberror($query . " (" . join(", ", @values) . ")");
+
+ dump_query(0, "laqje", $query, @values);
my %id = ();
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
$netamount += $form->{"sellprice_$i"} * $form->{"qty_$i"};
- $project_id = 'NULL';
- if ($form->{"projectnumber_$i"}) {
- $project_id = $form->{"projectnumber_$i"};
- }
$reqdate =
($form->{"reqdate_$i"}) ? qq|'$form->{"reqdate_$i"}'| : "NULL";
$query .= qq|$form->{id}, $form->{"id_$i"},
'$form->{"description_$i"}', '$form->{"longdescription_$i"}', $form->{"qty_$i"}, $baseqty,
$fxsellprice, $form->{"discount_$i"},
- '$form->{"unit_$i"}', $reqdate, (SELECT id from project where projectnumber = '$project_id'),
+ '$form->{"unit_$i"}', $reqdate, | . conv_i($form->{"project_id_$i"}, 'NULL') . qq|,
'$form->{"serialnumber_$i"}', $form->{"ship_$i"}, '$pricegroup_id',
'$form->{"ordnumber_$i"}', '$form->{"transdate_$i"}', '$form->{"cusordnumber_$i"}', '$subtotal')|;
$dbh->do($query) || $form->dberror($query);
o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber,
d.description AS department, o.payment_id, o.language_id, o.taxzone_id,
o.delivery_customer_id, o.delivery_vendor_id, o.proforma, o.shipto_id,
- o.globalproject_id, pr.projectnumber AS globalprojectnumber,
+ o.globalproject_id,
o.delivered
FROM oe o
JOIN $form->{vc} cv ON (o.$form->{vc}_id = cv.id)
LEFT JOIN employee e ON (o.employee_id = e.id)
LEFT JOIN department d ON (o.department_id = d.id)
- LEFT JOIN project pr ON (o.globalproject_id = pr.id)
|
. ($form->{id}
? qq|WHERE o.id = $form->{id}|