, group_concat(distinct comments separator ';') as order_comment
, group_concat(distinct comment separator ';') as detail_comment
, max(quantity_before) as quantity_before
- , sum(if($held_condition, d.quantity, 0)) as quantity_held
- , sum(if($held_condition, d.quantity, 0)*unit_price*(1-discount_percent/100)) as amount_held
+ , sum(if($held_condition, greatest(least(d.quantity, qoh.quantity - quantity_before), 0), 0)) as quantity_held
, sum(if($held_condition, 0, greatest(least(d.quantity, qoh.quantity - quantity_before), 0))) as available_quantity
, sum(if($held_condition, 0, greatest(least(d.quantity, qoh.quantity - quantity_before), 0)*unit_price*(1-discount_percent/100))) as available_amount
, sum(p.quantity) as quantity_to_pick
, `min(delivery_date)` as delivery_date
, sum(sub.quantity) as quantity
, sum(sub.amount) as amount
- , sum(greatest(least(sub.quantity -quantity_held, qoh.quantity - quantity_before), 0))
- , sum(sub.amount*greatest(least(sub.quantity -quantity_held, qoh.quantity - quantity_before), 0)/sub.quantity)
, sum(sub.available_quantity)
, sum(sub.available_amount)
, sum(quantity_held) as quantity_help
_("Amount") => array('ord' => '', 'type' => 'amount'),
_("Avail. Q") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
_("Avail. A") => array('ord' => '', 'type' => 'amount', 'dec' => 0),
-_("Avai2. Q") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
-_("Avai2. A") => array('ord' => '', 'type' => 'amount', 'dec' => 0),
_("Held. Q") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
_("required date") => array('ord' => '', 'type' => 'date'),
_("Comments") => array('ord' => '', 'fun' => 'aggregate_comment'),
_("comment 2 ") => 'skip',
-_("Q to Pick") => array('ord' => '', 'type' => 'qty'),
+_("Q to Pick") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
_("A to Pick") => array('ord' => '', 'type' => 'amount'),
_("Pick")=> array('insert'=>true, 'fun'=>'pick_checkbox'),
);