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

DELETE FROM pack WHERE pack_id IN
  (SELECT pack_id
   FROM pack JOIN cohead ON (cohead_id=pack_head_id)
             JOIN coitem ON (coitem_cohead_id=cohead_id)
             JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
   WHERE ( (checkSOSitePrivs(cohead_id))
     AND   (pack_head_type='SO')
     AND   (pack_printed) 
<? if exists("warehous_id") ?>
     AND   (itemsite_warehous_id = <? value("warehous_id") ?>)
<? endif ?>
         )
  );

<? if exists("MultiWhs") ?>
DELETE FROM pack WHERE pack_id IN
  (SELECT pack_id
   FROM pack JOIN tohead ON (tohead_id=pack_head_id)
   WHERE ( (pack_head_type='TO')
     AND   (pack_printed)
<? if exists("warehous_id") ?>
     AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)
<? endif ?>
         )
  );
<? endif ?>
