-- Group: unbalancedQOHByClassCode
-- Name: detail
-- Notes: used by dspUnbalancedQOHByClassCode
-- 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 itemsite_id, warehous_code, item_number,
       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip, uom_name,
       itemsite_qtyonhand,
       detailedQOH(itemsite_id, FALSE) AS detailedqoh,
       'qty' AS itemsite_qtyonhand_xtnumericrole,
       'qty' AS detailedqoh_xtnumericrole
FROM whsinfo, item, itemsite, uom
WHERE ( (itemsite_item_id=item_id)
    AND (item_inv_uom_id=uom_id)
    AND (itemsite_warehous_id=warehous_id)
    AND ((itemsite_loccntrl) OR (itemsite_controlmethod IN ('L', 'S')))
    AND (itemsite_qtyonhand <> detailedQOH(itemsite_id, FALSE))
<? if exists("classcode_id") ?>
    AND (item_classcode_id=<? value("classcode_id") ?>)
<? elseif exists("classcode_pattern") ?>
    AND (item_classcode_id IN (SELECT classcode_id
                               FROM classcode
                               WHERE (classcode_code ~ <? value("classcode_pattern") ?>)))
<? endif ?>
<? if exists("warehous_id") ?>
    AND (warehous_id=<? value("warehous_id") ?>)
<? endif ?>
      )
ORDER BY item_number;
