-- Group: packingListBatchByShipVia
-- Name: shipVia
-- Notes: used by printPackingListBatchByShipVia
-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.


SELECT max(id), shipvia
FROM (
SELECT max(cohead_id) AS id, cohead_shipvia AS shipvia
FROM pack JOIN cohead ON (cohead_id=pack_head_id)
          JOIN coitem ON (coitem_cohead_id=cohead_id AND coitem_status='O')
          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
WHERE ( (NOT pack_printed)
  AND   (pack_head_type='SO')
<? if exists("warehous_id") ?>
  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)
<? endif ?>
      )
GROUP BY cohead_shipvia
<? if exists("MultiWhs") ?>
UNION
SELECT max(tohead_id) AS id, tohead_shipvia AS shipvia
FROM pack JOIN tohead ON (tohead_id=pack_head_id AND tohead_status='O')
WHERE ( (NOT pack_printed)
  AND   (pack_head_type='TO')
<? if exists("warehous_id") ?>
  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)
<? endif ?>
      )
GROUP BY tohead_shipvia
<? endif ?>
) data
GROUP BY shipvia
ORDER BY shipvia
