253	inventoryAvailabilitybyWorkorder	detail	 used by dspInventoryAvailabilityByWorkOrder\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: inventoryAvailabilitybyWorkorder\n-- Name: detail\n-- Notes: used by dspInventoryAvailabilityByWorkOrder\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *, 'qty' AS woinvav_qoh_xtnumericrole,\n       'qty' AS woinvav_balance_xtnumericrole,\n       'qty' AS woinvav_allocated_xtnumericrole,\n       'qty' AS woinvav_ordered_xtnumericrole,\n       'qty' AS woinvav_woavail_xtnumericrole,\n       'qty' AS woinvav_totalavail_xtnumericrole,\n       CASE WHEN (woinvav_womatl_id) = -1 THEN 'altemphasis'\n            WHEN (woinvav_qoh < 0) THEN 'error'\n            WHEN (woinvav_qoh < woinvav_reorderlevel) THEN 'warning'\n            WHEN ((woinvav_qoh - woinvav_balance) < 0) THEN 'altemphasis'\n            WHEN ((woinvav_qoh - woinvav_allocated) < 0) THEN 'altemphasis'\n       END AS woinvav_qoh_qtforegroundrole,\n       CASE WHEN (woinvav_womatl_id) = -1 THEN 'altemphasis'\n            WHEN ((woinvav_qoh + woinvav_ordered - woinvav_balance) < 0) THEN 'error'\n            WHEN ((woinvav_qoh + woinvav_ordered - woinvav_balance) < woinvav_reorderlevel) THEN 'warning'\n       END AS woinvav_woavail_qtforegroundrole,\n       CASE WHEN (woinvav_womatl_id) = -1 THEN 'altemphasis'\n            WHEN ((woinvav_qoh + woinvav_ordered - woinvav_allocated) < 0) THEN 'error'\n            WHEN ((woinvav_qoh + woinvav_ordered - woinvav_allocated) < woinvav_reorderlevel) THEN 'warning'\n       END AS woinvav_totalavail_qtforegroundrole,\n       CASE WHEN (woinvav_womatl_id = -1) THEN 'altemphasis'\n         ELSE null\n       END AS qtforegroundrole,\n       woinvav_level AS xtindentrole\nFROM woinvavail(<? value("wo_id") ?>,\n<? if exists("IndentedParentChild") ?>\n                true,\n<? else ?>\n                false,\n<? endif ?>\n<? if exists("summarizedParentChild") ?>\n                true,\n<? else ?>\n                false,\n<? endif ?>\n<? if exists("onlyShowShortages") ?>\n                true,\n<? else ?>\n                false,\n<? endif ?>\n<? if exists("onlyShowInsufficientInventory") ?>\n                true\n<? else ?>\n                false\n<? endif ?>\n               ) AS data;\n	admin	2015-10-01	0
254	inventoryLocator	detail	 used by dspInventoryLocator\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n Lot/Serial Characteristics additions by Specter Vision Solutions, Inc.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: inventoryLocator\n-- Name: detail\n-- Notes: used by dspInventoryLocator\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- Lot/Serial Characteristics additions by Specter Vision Solutions, Inc.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       <? value("na") ?> AS locationname_xtnullrole,\n       <? value("na") ?> AS netable_xtnullrole,\n       <? value("na") ?> AS usable_xtnullrole,\n       <? value("na") ?> AS lotserial_xtnullrole,\n       <? value("na") ?> AS expiration_xtnullrole,\n       <? value("na") ?> AS warranty_xtnullrole,\n       CASE WHEN (itemsite_perishable\n                  AND itemloc_expiration <= CURRENT_DATE) THEN 'error'\n            WHEN (itemsite_warrpurc\n                  AND itemloc_warrpurc <= CURRENT_DATE) THEN 'error'\n       END AS qtforegroundrole,\n       'qty' AS qoh_xtnumericrole\nFROM (SELECT itemloc_id, 1 AS type, warehous_code,\n             itemsite_perishable, itemloc_expiration,\n             itemsite_warrpurc, itemloc_warrpurc,\n             CASE WHEN (location_id IS NOT NULL) THEN\n                        (formatLocationName(location_id) || '-' || firstLine(location_descrip))\n             END AS locationname,\n             CASE WHEN (location_id IS NOT NULL) THEN location_netable\n             END AS netable,\n             CASE WHEN (location_id IS NOT NULL) THEN location_usable\n             END AS usable,\n             CASE WHEN (itemsite_controlmethod IN ('L', 'S')) THEN\n                        formatlotserialnumber(itemloc_ls_id)\n             END AS lotserial,\n             CASE WHEN (itemsite_perishable) THEN itemloc_expiration\n             END AS expiration,\n             CASE WHEN (itemsite_warrpurc) THEN itemloc_warrpurc\n             END AS warranty,\n             itemloc_qty AS qoh\n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , CASE WHEN (charass_alias<? literal("char_id_date_list") ?>.charass_value = '') THEN NULL::date\n         ELSE charass_alias<? literal("char_id_date_list") ?>.charass_value::date \n    END AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\n      FROM itemsite, whsinfo,\n           itemloc LEFT OUTER JOIN location ON (itemloc_location_id=location_id)\n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='LS')\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=itemloc_ls_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='LS')\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=itemloc_ls_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='LS')\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=itemloc_ls_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\n      WHERE ((itemsite_loccntrl OR (itemsite_controlmethod IN ('L', 'S')))\n         AND (itemloc_itemsite_id=itemsite_id)\n         AND (itemsite_warehous_id=warehous_id)\n         AND (itemsite_item_id=<? value("item_id") ?>)\n      <? if exists("warehous_id") ?>\n         AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n      <? endif ?>\n      <? if exists("site") ?>\n         AND (itemsite_warehous_id=<? value("site")?>)\n      <? endif ?>\n      <? if exists("lot_serial") ?>\n         AND (formatlotserialnumber(itemloc_ls_id)=<? value("lot_serial")?>)\n      <? endif ?>\n      <? if exists("_location_name") ?>\n         AND (formatLocationName(location_id)=<? value("_location_name")?>)\n      <? endif ?>\n      <? literal("charClause") ?>\n            )\n      UNION\n      SELECT itemsite_id, 2 AS type, warehous_code,\n             itemsite_perishable, NULL AS itemloc_expiration,\n             itemsite_warrpurc, NULL AS itemloc_warrpurc,\n             NULL AS locationname,\n             NULL AS netable,\n             NULL AS usable,\n             NULL AS lotserial,\n             NULL AS expiration,\n             NULL AS warranty,\n             itemsite_qtyonhand AS qoh\n<? foreach("char_id_text_list" ?>\n          , NULL AS char<? value("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list" ?>\n          , NULL AS char<? value("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list" ?>\n          , NULL AS char<? value("char_id_date_list") ?>\n<? endforeach ?>\n      FROM itemsite, whsinfo\n      WHERE ((NOT itemsite_loccntrl)\n         AND (itemsite_controlmethod NOT IN ('L', 'S'))\n         AND (itemsite_warehous_id=warehous_id)\n         AND (itemsite_item_id=<? value("item_id") ?>)\n      <? if exists("warehous_id") ?>\n         AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n      <? endif ?>\n            )\n     ) AS dummy\nORDER BY warehous_code, locationname, lotserial;\n	admin	2015-10-01	0
255	invoiceInformation	detail	 used by dspInvoiceInformation\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: invoiceInformation\n-- Name: detail\n-- Notes: used by dspInvoiceInformation\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT arapply_id,\n       CASE WHEN (arapply_source_doctype = 'C') THEN <? value("creditMemo") ?>\n            WHEN (arapply_source_doctype = 'R') THEN <? value("cashdeposit") ?>\n            WHEN (arapply_fundstype='C') THEN <? value("check") ?>\n            WHEN (arapply_fundstype='T') THEN <? value("certifiedCheck") ?>\n            WHEN (arapply_fundstype='M') THEN <? value("masterCard") ?>\n            WHEN (arapply_fundstype='V') THEN <? value("visa") ?>\n            WHEN (arapply_fundstype='A') THEN <? value("americanExpress") ?>\n            WHEN (arapply_fundstype='D') THEN <? value("discoverCard") ?>\n            WHEN (arapply_fundstype='R') THEN <? value("otherCreditCard") ?>\n            WHEN (arapply_fundstype='K') THEN <? value("cash") ?>\n            WHEN (arapply_fundstype='W') THEN <? value("wireTransfer") ?>\n            WHEN (arapply_fundstype='O') THEN <? value("other") ?>\n       END AS doctype,\n       CASE WHEN (arapply_source_doctype IN ('C','R')) THEN arapply_source_docnumber\n            WHEN (arapply_source_doctype = 'K') THEN arapply_refnumber\n         ELSE <? value("error") ?>\n       END AS docnumber,\n       arapply_postdate, arapply_applied,\n       currConcat(arapply_curr_id) AS currabbr,\n       currToBase(arapply_curr_id, arapply_applied, arapply_postdate) AS baseapplied,\n       'curr' AS arapply_applied_xtnumericrole,\n       'curr' AS baseapplied_xtnumericrole\nFROM arapply\nWHERE ((arapply_target_doctype='I')\n   AND (arapply_target_docnumber=<? value("aropen_docnumber") ?>))\nORDER BY arapply_postdate;\n	admin	2015-10-01	0
256	invoiceRegister	detail	 used by dspInvoiceRegister\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: invoiceRegister\n-- Name: detail\n-- Notes: used by dspInvoiceRegister\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT *\nFROM (\n-- G/L Transactions\nSELECT DISTINCT\n       -1 AS gltrans_id, -1 AS altId,\n       gltrans_date,  '' AS gltrans_source,\n       '' AS doctype, '' AS gltrans_docnumber,\n       '' AS notes,   '' AS account,\n       CAST(NULL AS NUMERIC) AS debit,\n       CAST(NULL AS NUMERIC) AS credit,\n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole,\n       0 AS xtindentrole,\n       gltrans_date AS transdate\nFROM gltrans\nWHERE ((gltrans_doctype IN ('IN', 'CM', 'DM', 'CD'))\n   AND (gltrans_source = 'A/R')\n   AND (gltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("accnt_id") ?>\n   AND (gltrans_accnt_id=<? value("accnt_id") ?>)\n<? endif ?>\n      )\n\nUNION\n-- Journals\nSELECT DISTINCT\n       -1 AS gltrans_id, -1 AS altId,\n       sltrans_date AS gltrans_date,  '' AS gltrans_source,\n       '' AS doctype, '' AS gltrans_docnumber,\n       '' AS notes,   '' AS account,\n       CAST(NULL AS NUMERIC) AS debit,\n       CAST(NULL AS NUMERIC) AS credit,\n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole,\n       0 AS xtindentrole,\n       sltrans_date AS transdate\nFROM sltrans\nWHERE ((sltrans_doctype IN ('IN', 'CM', 'DM', 'CD'))\n   AND (sltrans_source = 'A/R')\n   AND (sltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("accnt_id") ?>\n   AND (sltrans_accnt_id=<? value("accnt_id") ?>)\n<? endif ?>\n      )\n) AS data\n\nUNION\n-- G/L Transactions\nSELECT gltrans_id,\n       CASE WHEN(gltrans_doctype='IN') THEN 1\n            WHEN(gltrans_doctype='CM') THEN 2\n            WHEN(gltrans_doctype='DM') THEN 3\n            WHEN(gltrans_doctype='CD') THEN 4\n         ELSE -1\n       END AS altId,\n       gltrans_date, gltrans_source,\n       CASE WHEN(gltrans_doctype='IN') THEN <? value("invoice") ?>\n            WHEN(gltrans_doctype='CM') THEN <? value("creditmemo") ?>\n            WHEN(gltrans_doctype='DM') THEN <? value("debitmemo") ?>\n            WHEN(gltrans_doctype='CD') THEN <? value("cashdeposit") ?>\n         ELSE gltrans_doctype\n       END AS doctype,\n       gltrans_docnumber,\n       CASE WHEN(gltrans_doctype='IN') THEN\n                 (SELECT invchead_shipto_name\n                  FROM aropen LEFT OUTER JOIN\n                       invchead\n                       ON (invchead_id=aropen_cobmisc_id\n                       AND invchead_cust_id=aropen_cust_id)\n                  WHERE ((aropen_docnumber=gltrans_docnumber)\n                     AND (aropen_doctype='I')))\n         ELSE firstLine(gltrans_notes)\n       END AS f_notes,\n       (formatGLAccount(accnt_id) || ' - ' || accnt_descrip) AS f_accnt,\n       CASE WHEN (gltrans_amount < 0) THEN ABS(gltrans_amount)\n         ELSE 0\n       END AS debit,\n       CASE WHEN (gltrans_amount > 0) THEN gltrans_amount\n         ELSE 0\n       END AS credit,\n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole,\n       1 AS xtindentrole,\n       NULL AS transdate\nFROM gltrans, accnt\nWHERE ((gltrans_accnt_id=accnt_id)\n   AND (gltrans_doctype IN ('IN', 'CM', 'DM', 'CD'))\n   AND (gltrans_source = 'A/R')\n   AND (gltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("accnt_id") ?>\n   AND (gltrans_accnt_id=<? value("accnt_id") ?>)\n<? endif ?>\n   )\n\nUNION\n-- Journals\nSELECT sltrans_id,\n       CASE WHEN(sltrans_doctype='IN') THEN 1\n            WHEN(sltrans_doctype='CM') THEN 2\n            WHEN(sltrans_doctype='DM') THEN 3\n            WHEN(sltrans_doctype='CD') THEN 4\n         ELSE -1\n       END AS altId,\n       sltrans_date AS gltrans_date, sltrans_source AS gltrans_date,\n       CASE WHEN(sltrans_doctype='IN') THEN <? value("invoice") ?>\n            WHEN(sltrans_doctype='CM') THEN <? value("creditmemo") ?>\n            WHEN(sltrans_doctype='DM') THEN <? value("debitmemo") ?>\n            WHEN(sltrans_doctype='CD') THEN <? value("cashdeposit") ?>\n         ELSE sltrans_doctype\n       END AS doctype,\n       sltrans_docnumber AS gltrans_docnumber,\n       CASE WHEN(sltrans_doctype='IN') THEN\n                 (SELECT invchead_shipto_name\n                  FROM aropen LEFT OUTER JOIN\n                       invchead\n                       ON (invchead_id=aropen_cobmisc_id\n                       AND invchead_cust_id=aropen_cust_id)\n                  WHERE ((aropen_docnumber=sltrans_docnumber)\n                     AND (aropen_doctype='I')))\n         ELSE firstLine(sltrans_notes)\n       END AS f_notes,\n       (formatGLAccount(accnt_id) || ' - ' || accnt_descrip) AS f_accnt,\n       CASE WHEN (sltrans_amount < 0) THEN ABS(sltrans_amount)\n         ELSE 0\n       END AS debit,\n       CASE WHEN (sltrans_amount > 0) THEN sltrans_amount\n         ELSE 0\n       END AS credit,\n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole,\n       1 AS xtindentrole,\n       NULL AS transdate\nFROM sltrans, accnt\nWHERE ((sltrans_accnt_id=accnt_id)\n   AND (sltrans_doctype IN ('IN', 'CM', 'DM', 'CD'))\n   AND (sltrans_source = 'A/R')\n   AND (sltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("accnt_id") ?>\n   AND (sltrans_accnt_id=<? value("accnt_id") ?>)\n<? endif ?>\n      )\nORDER BY gltrans_date, gltrans_docnumber, xtindentrole;\n	admin	2015-10-01	0
55	invoices	detail	 used by reprintInvoices, unpostedInvoices, dspRecurringInvoices\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: invoices\n-- Name: detail\n-- Notes: used by reprintInvoices, unpostedInvoices, dspRecurringInvoices\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT invchead_id, cust_id,\n       invchead.*,\n       cust_number, cust_name,\n       (TEXT(cust_number) || ' - ' || cust_name) AS customer,\n       COALESCE(invchead_gldistdate, invchead_invcdate) AS gldistdate,\n       invoicetotal(invchead_id) AS extprice,\n       CASE WHEN (aropen_open) THEN (aropen_amount - aropen_paid)\n            ELSE 0\n       END AS balance,\n       (invchead_recurring_invchead_id IS NOT NULL) AS isRecurring,\n       recur_freq,\n       recur_period,\n       CASE WHEN (recur_period='D') THEN <? value("day") ?>\n            WHEN (recur_period='W') THEN <? value("week") ?>\n            WHEN (recur_period='M') THEN <? value("month") ?>\n            WHEN (recur_period='Y') THEN <? value("year") ?>\n            WHEN (recur_period='m') THEN <? value("minute") ?>\n            WHEN (recur_period='H') THEN <? value("hour") ?>\n            ELSE <? value("none") ?>\n       END AS recur_period_qtdisplayrole,\n       recur_end,\n       <? if exists('getForm') ?>\n         invchead_invcnumber AS docnumber,\n         findCustomerForm(cust_id, 'I') AS reportname,\n       <? endif ?>\n       CASE WHEN (calcInvoiceAmt(invchead_id,'S') != 0.0)\n              THEN calcInvoiceAmt(invchead_id,'M')\n            ELSE 0.0\n       END AS margin,\n       CASE WHEN (calcInvoiceAmt(invchead_id,'S') != 0.0)\n              THEN (calcInvoiceAmt(invchead_id,'M') / calcInvoiceAmt(invchead_id,'S'))\n            ELSE 1.0\n       END AS marginpercent,\n       'percent' AS marginpercent_xtnumericrole,\n       'curr' AS margin_xtnumericrole,\n       'curr' AS extprice_xtnumericrole,\n       'curr' AS balance_xtnumericrole,\n       CASE WHEN (aropen_id IS NULL) THEN 'Unposted' END AS balance_qtdisplayrole\nFROM invchead JOIN custinfo ON (cust_id=invchead_cust_id)\n              LEFT OUTER JOIN aropen ON ( (aropen_doctype='I') AND (aropen_docnumber=invchead_invcnumber) )\n              LEFT OUTER JOIN recur ON (invchead_recurring_invchead_id=recur_parent_id AND recur_parent_type='I')\nWHERE ( (true)\n<? if exists("unpostedOnly") ?>\n  AND   (NOT invchead_posted)\n<? endif ?>\n<? if exists("postedOnly") ?>\n  AND   (invchead_posted)\n<? endif ?>\n<? if exists("recurringOnly") ?>\n  AND   (invchead_recurring_invchead_id IS NOT NULL)\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND   (invchead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND   (invchead_invcdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("invc_pattern") ?>\n  AND   (invchead_invcnumber ~ <? value("invc_pattern") ?>)\n<? endif ?>\n<? if exists("balanceOnly") ?>\n  AND   (aropen_open AND (aropen_amount - aropen_paid > 0))\n<? endif ?>\n  AND   (checkInvoiceSitePrivs(invchead_id)) )\nORDER BY invchead_invcnumber\n;\n	admin	2015-10-01	0
475	issueToShipping	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: issueToShipping\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       noNeg(qtyord - qtyshipped + qtyreturned) AS balance,\n       indent AS xtindentrole,\n       'qty' AS qtyord_xtnumericrole,\n       'qty' AS qtyshipped_xtnumericrole,\n       'qty' AS qtyreturned_xtnumericrole,\n       'qty' AS balance_xtnumericrole,\n       'qty' AS atshipping_xtnumericrole,\n       CASE WHEN (scheddate > CURRENT_DATE AND\n                  noNeg(qtyord - qtyshipped + qtyreturned) <> atshipping) THEN 'future'\n            WHEN (noNeg(qtyord - qtyshipped + qtyreturned) <> atshipping) THEN 'expired'\n       END AS qtforegroundrole \nFROM (\n<? if exists("sohead_id") ?>\nSELECT coitem_id AS lineitem_id, \n       CASE WHEN (itemsite_costmethod = 'J') THEN 1 \n            ELSE 0 \n       END AS job, 0 AS indent,\n       getOpenShipment('SO', <? value("sohead_id") ?>, <? value("warehous_id") ?>) AS shiphead_number, \n       formatSoLineNumber(coitem_id) AS linenumber, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n       warehous_code,\n       coitem_scheddate AS scheddate,\n       uom_name,\n       coitem_qtyord AS qtyord,\n       coitem_qtyshipped AS qtyshipped,\n       coitem_qtyreturned AS qtyreturned,\n       qtyAtShipping(coitem_id) AS atshipping, \n       coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3 \nFROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n            JOIN item ON (item_id=itemsite_item_id)\n            JOIN site() ON (warehous_id=itemsite_warehous_id)\n            JOIN uom ON (uom_id=coitem_qty_uom_id)\nWHERE ( (coitem_status NOT IN ('C','X'))\n  AND   (item_type != 'K')\n<? if exists("warehous_id") ?>\n  AND   (itemsite_warehous_id=<? value("warehous_id") ?>) \n<? endif ?>\n  AND   (coitem_cohead_id=<? value("sohead_id") ?>) ) \n\n<? if exists("includeReservations") ?>\nUNION ALL\nSELECT coitem_id AS lineitem_id, \n       CASE WHEN (itemsite_costmethod = 'J') THEN 1 \n            ELSE 0 \n       END AS job, 1 AS indent,\n       '' AS shiphead_number, \n       '' AS linenumber, formatLocationName(itemloc_location_id) AS item_number,\n       formatLotSerialNumber(itemloc_ls_id) AS itemdescrip,\n       '' AS warehous_code,\n       NULL AS scheddate,\n       '' AS uom_name,\n       reserve_qty AS qtyord,\n       NULL AS qtyshipped,\n       NULL AS qtyreturned,\n       NULL AS atshipping, \n       coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3 \nFROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n            JOIN item ON (item_id=itemsite_item_id)\n            JOIN site() ON (warehous_id=itemsite_warehous_id)\n            JOIN reserve ON (reserve_demand_id=coitem_id AND\n                             reserve_demand_type='SO' AND\n                             reserve_supply_type='I')\n            JOIN itemloc ON (itemloc_id=reserve_supply_id)\nWHERE ( (coitem_status NOT IN ('C','X'))\n  AND   (item_type != 'K')\n  AND   ((itemsite_controlmethod IN ('L', 'S')) OR (itemsite_loccntrl))\n<? if exists("warehous_id") ?>\n  AND   (itemsite_warehous_id=<? value("warehous_id") ?>) \n<? endif ?>\n  AND   (coitem_cohead_id=<? value("sohead_id") ?>) ) \nUNION ALL\nSELECT coitem_id AS lineitem_id, \n       CASE WHEN (itemsite_costmethod = 'J') THEN 1 \n            ELSE 0 \n       END AS job, 1 AS indent,\n       '' AS shiphead_number, \n       '' AS linenumber, 'N/A',\n       'N/A' AS itemdescrip,\n       '' AS warehous_code,\n       NULL AS scheddate,\n       '' AS uom_name,\n       coitem_qtyreserved AS qtyord,\n       NULL AS qtyshipped,\n       NULL AS qtyreturned,\n       NULL AS atshipping, \n       coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3 \nFROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n            JOIN item ON (item_id=itemsite_item_id)\n            JOIN site() ON (warehous_id=itemsite_warehous_id)\nWHERE ( (coitem_status NOT IN ('C','X'))\n  AND   (item_type != 'K')\n  AND   ((itemsite_controlmethod = 'R') AND (NOT itemsite_loccntrl))\n  AND   (coitem_qtyreserved > 0.0)\n<? if exists("warehous_id") ?>\n  AND   (itemsite_warehous_id=<? value("warehous_id") ?>) \n<? endif ?>\n  AND   (coitem_cohead_id=<? value("sohead_id") ?>) ) \n<? endif ?>\n\n<? elseif exists("tohead_id") ?>\n\nSELECT toitem_id AS lineitem_id, \n       0 AS lsJob, 0 AS indent,\n       getOpenShipment('TO', <? value("tohead_id") ?>, <? value("warehous_id") ?>) AS shiphead_number, \n       toitem_linenumber AS linenumber, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n       tohead_srcname AS warehous_code,\n       toitem_schedshipdate AS scheddate,\n       uom_name,\n       toitem_qty_ordered AS qtyord,\n       toitem_qty_shipped AS qtyshipped,\n       0 AS qtyreturned,\n       qtyAtShipping('TO', toitem_id) AS atshipping, \n       toitem_schedshipdate AS seq1, toitem_linenumber AS seq2, 0 AS seq3 \nFROM item, tohead, site(), uom, toitem\nWHERE ( (toitem_item_id=item_id)\n AND (toitem_status NOT IN ('C','X'))\n AND (toitem_tohead_id=tohead_id)\n AND (tohead_src_warehous_id=warehous_id)\n AND (item_inv_uom_id=uom_id)\n<? if exists("warehous_id") ?>\n  AND   (tohead_src_warehous_id=<? value("warehous_id") ?>) \n<? endif ?>\n AND (tohead_id=<? value("tohead_id") ?>) ) \n<? endif ?>\n) AS sub \nORDER BY seq1, seq2, seq3, indent;\n	admin	2015-10-01	0
257	itemCost	detail	 used by dspItemCostSummary, dspItemCostsByClassCode, dspItemCostHistory\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemCost\n-- Name: detail\n-- Notes: used by dspItemCostSummary, dspItemCostsByClassCode, dspItemCostHistory\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT \n      <? if exists("byHistory") ?>\n        costhist_id, costelem_type,\n        formatBoolYN(costhist_lowlevel) AS lowlevel,\n        CASE WHEN costhist_type='A' THEN <? value("actual") ?>\n             WHEN costhist_type='S' THEN <? value("standard") ?>\n             WHEN costhist_type='D' THEN <? value("delete") ?>\n             WHEN costhist_type='N' THEN <? value("new") ?>\n        END AS type,\n        costhist_date,\n        costhist_username AS username,\n        costhist_oldcost,\n        currConcat(costhist_oldcurr_id) AS oldcurr, \n\tcosthist_newcost,\n        currConcat(costhist_newcurr_id) AS newcurr,\n        'cost' AS costhist_oldcost_xtnumericrole,\n        'cost' AS costhist_newcost_xtnumericrole\n      <? elseif exists("byClassCode") ?>\n        item_id, item_number, description, item_active, \n        uom_name, scost, acost, \n        CASE WHEN (scost = 0) THEN NULL  \n          ELSE ((acost - scost) / scost)      \n        END AS percent_variance,\n        'percent' AS percent_variance_xtnumericrole, \n        CASE WHEN (scost = 0) THEN NULL \n             WHEN (((acost - scost) / scost) < 0) THEN 'error' \n          ELSE NULL \n        END AS percent_variance_qtforegroundrole, \n        <? if exists("onlyShowDiffCosts") ?>\n          CASE WHEN (scost != acost\n                     AND ABS(scost - acost) < 10 ^ (-1 * <? value("costscale") ?>))\n               THEN 'altemphasis' \n          END AS qtforegroundrole,\n        <? endif ?> \n        'cost' AS scost_xtnumericrole,\n        'cost' AS acost_xtnumericrole \n      <? elseif exists("bySummrey") ?>\n        itemcost_id,\n        CASE WHEN (costelem_sys) THEN 1\n          ELSE 0\n        END,\n        costelem_type, formatBoolYN(itemcost_lowlevel) AS lowlevel,\n        itemcost_stdcost,\n        currToBase(itemcost_curr_id, itemcost_actcost, NULL) AS itemcost_actcost,\n        itemcost_updated, itemcost_posted,\n        'cost' AS itemcost_stdcost_xtnumericrole,\n        'cost' AS itemcost_actcost_xtnumericrole,\n        0 AS itemcost_stdcost_xttotalrole,\n        0 AS itemcost_actcost_xttotalrole,\n        CASE WHEN COALESCE(itemcost_posted, endOfTime()) >= endOfTime() \n             THEN <? value("never") ?>\n        END AS itemcost_posted_qtdisplayrole,\n        CASE WHEN COALESCE(itemcost_updated, endOfTime()) >= endOfTime()\n             THEN <? value("never") ?>\n        END AS itemcost_updated_qtdisplayrole\n      <? endif ?>\nFROM <? if exists("byClassCode") ?>\n       (SELECT item_id, item_number, item_active,\n               (item_descrip1 || ' ' || item_descrip2) AS description,\n               uom_name, stdcost(item_id) AS scost, actcost(item_id) AS acost\n        FROM item, classcode, uom\n        WHERE ((item_classcode_id=classcode_id)\n          AND  (item_inv_uom_id=uom_id)\n          <? if exists("classcode_id") ?>\n            AND (classcode_id=<? value("classcode_id") ?>)\n          <? elseif exists("classcode_pattern") ?>\n            AND (classcode_code ~ <? value("classcode_pattern") ?>)\n          <? endif ?> \n              ) ) AS data \n     <? elseif exists("byHistory") ?>\n       costhist,costelem\n     <? elseif exists("bySummrey") ?>\n       itemcost, costelem\n     <? endif ?>   \nWHERE ( <? if exists("byHistory") ?>\n         (costhist_costelem_id=costelem_id)\n     AND (costhist_item_id=<? value("item_id") ?>)\n        <? elseif exists("byClassCode") ?> \n          true \n          <? if exists("onlyShowZeroCosts") ?>\n            AND ((scost=0) OR (acost=0)) \n          <? endif ?> \n          <? if exists("onlyShowDiffCosts") ?>\n            AND (scost != acost) \n            AND (ABS(scost - acost) > 10 ^ (-1 * <? value("costscale") ?>))\n          <? endif ?>\n          <? if exists("onlyShowActive") ?>\n            AND (item_active) \n          <? endif ?> \n        <? elseif exists("bySummrey") ?>\n          (itemcost_costelem_id=costelem_id)\n      AND (itemcost_item_id=<? value("item_id") ?>)\n        <? endif ?>\n      ) \nORDER BY <? if exists("byHistory") ?>\n           costhist_date, costelem_type;\n         <? elseif exists("byClassCode") ?> \n           item_number;\n         <? elseif exists("bySummrey") ?>\n           itemcost_lowlevel, costelem_type;\n         <? endif ?>\n	admin	2015-10-01	0
457	itemCost	list	 used by maintainItemCosts, bomItem\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemCost\n-- Name: list\n-- Notes: used by maintainItemCosts, bomItem\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n-- The order of checking for item_id first is important.\n\n<? if exists("item_id") ?>\n\nSELECT itemcost_id,\n       CASE WHEN (costelem_sys) THEN 1\n            ELSE 0\n       END,\n       CASE WHEN itemcost_costelem_id = -1 THEN :error\n\t    ELSE costelem_type\n       END AS costelem_type, itemcost_lowlevel,\n       itemcost_stdcost, currConcat(baseCurrID()) AS baseCurr,\n       itemcost_posted,\n       itemcost_actcost, currConcat(itemcost_curr_id) AS costCurr,\n       itemcost_updated,\n       currToBase(itemcost_curr_id, itemcost_actcost, CURRENT_DATE) AS actcostBase,\n       itemcost_curr_id,\n       CASE WHEN (COALESCE(itemcost_posted, startOfTime()) <= startOfTime()) THEN :never\n       END AS itemcost_posted_qtdisplayrole,\n       'cost' AS itemcost_stdcost_xtnumericrole,\n       'cost' AS itemcost_actcost_xtnumericrole\nFROM itemcost LEFT OUTER JOIN costelem ON (itemcost_costelem_id=costelem_id)\nWHERE (itemcost_item_id=<? value("item_id") ?>)\nORDER BY itemcost_lowlevel, costelem_type;\n\n<? elseif exists("bomitem_id") ?>\n\nSELECT bomitemcost_id AS itemcost_id,\n       CASE WHEN (costelem_sys) THEN 1\n            ELSE 0\n       END,\n       CASE WHEN bomitemcost_costelem_id = -1 THEN :error\n\t    ELSE costelem_type\n       END AS costelem_type,\n       bomitemcost_lowlevel AS itemcost_lowlevel,\n       bomitemcost_stdcost AS itemcost_stdcost, currConcat(baseCurrID()) AS baseCurr,\n       bomitemcost_posted AS itemcost_posted,\n       bomitemcost_actcost AS itemcost_actcost,\n       currConcat(bomitemcost_curr_id) AS costCurr,\n       bomitemcost_updated AS itemcost_updated,\n       currToBase(bomitemcost_curr_id, bomitemcost_actcost, CURRENT_DATE) AS actcostBase,\n       bomitemcost_curr_id AS itemcost_curr_id,\n       CASE WHEN (COALESCE(bomitemcost_posted, startOfTime()) <= startOfTime()) THEN :never\n       END AS itemcost_posted_qtdisplayrole,\n       'cost' AS itemcost_stdcost_xtnumericrole,\n       'cost' AS itemcost_actcost_xtnumericrole\nFROM bomitemcost LEFT OUTER JOIN costelem ON (bomitemcost_costelem_id=costelem_id)\nWHERE (bomitemcost_bomitem_id=<? value("bomitem_id") ?>)\nORDER BY bomitemcost_lowlevel, costelem_type;\n\n<? endif ?>\n	admin	2015-10-01	0
430	itemPricingSchedule	detail	 used by itemPricingSchedule\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemPricingSchedule\n-- Name: detail\n-- Notes: used by itemPricingSchedule\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n\nSELECT ipsitem_id AS id, 1 AS altid,\n       CASE WHEN (ipsitem_item_id IS NOT NULL) THEN <? value("item") ?>\n            ELSE <? value("prodcat") ?>\n       END AS target,\n       COALESCE(item_number, prodcat_code) AS number,\n       COALESCE(item_descrip1 || ' ' || item_descrip2, prodcat_descrip) AS descrip,\n       qty.uom_name AS qtyuom, ipsitem_qtybreak AS qtybreak,\n       price.uom_name AS priceuom,\n       ((COALESCE(ipsitem_discntprcnt, 0.0) * 100) + ipsitem_price) AS price,\n       (COALESCE(ipsitem_fixedamtdiscount, 0.0) + 0.00) AS fixedAmt,\n       noNeg(CASE WHEN (ipsitem_item_id IS NULL) THEN\n                   NULL\n                  WHEN (ipsitem_type='N') THEN\n                   ipsitem_price\n                  WHEN (ipsitem_type='D') THEN\n                   (item_listprice - (item_listprice * COALESCE(ipsitem_discntprcnt, 0.0)) - COALESCE(ipsitem_fixedamtdiscount, 0.0))\n                  WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups') AND fetchMetricBool('WholesalePriceCosting')) THEN\n                   (item_listcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                  WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN\n                   (itemCost(itemsite_id) / itemuomtouomratio(item_id, ipsitem_qty_uom_id, ipsitem_price_uom_id) /\n                   (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                  WHEN (ipsitem_type = 'M' AND fetchMetricBool('WholesalePriceCosting')) THEN\n                   (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                  WHEN (ipsitem_type = 'M') THEN\n                   (itemCost(itemsite_id) / itemuomtouomratio(item_id, ipsitem_qty_uom_id, ipsitem_price_uom_id) +\n                    (itemCost(itemsite_id) / itemuomtouomratio(item_id, ipsitem_qty_uom_id, ipsitem_price_uom_id) * ipsitem_discntprcnt) +\n                    ipsitem_fixedamtdiscount)\n                  ELSE 0.0\n             END) AS netPrice,\n       CASE WHEN (ipsitem_type='N') THEN <? value("nominal") ?>\n            WHEN (ipsitem_type='D') THEN <? value("discount") ?>\n            WHEN (ipsitem_type='M') THEN <? value("markup") ?>\n            ELSE 'error'\n       END AS type,\n       CASE WHEN (ipsitem_type='N') THEN <? value("price") ?>\n            WHEN ((ipsitem_type IN ('D', 'M')) AND (COALESCE(ipsitem_discntprcnt, 0.0)=0.0) AND (COALESCE(ipsitem_fixedamtdiscount, 0.0)<>0.0)) THEN <? value("fixed") ?>\n            WHEN ((ipsitem_type IN ('D', 'M')) AND (COALESCE(ipsitem_discntprcnt, 0.0)<>0.0) AND (COALESCE(ipsitem_fixedamtdiscount, 0.0)=0.0)) THEN <? value("percent") ?>\n            WHEN (ipsitem_type IN ('D', 'M')) THEN <? value("mixed") ?>\n            ELSE 'error'\n       END AS method,\n       'qty' AS qtybreak_xtnumericrole,\n       'salesprice' AS netPrice_xtnumericrole,\n       'salesprice' AS price_xtnumericrole\nFROM ipsiteminfo LEFT OUTER JOIN item ON (item_id=ipsitem_item_id)\n                 LEFT OUTER JOIN prodcat ON (prodcat_id=ipsitem_prodcat_id)\n                 LEFT OUTER JOIN uom AS qty ON (qty.uom_id=ipsitem_qty_uom_id)\n                 LEFT OUTER JOIN uom AS price ON (price.uom_id=ipsitem_price_uom_id)\n                 LEFT OUTER JOIN itemsite ON (itemsite_item_id=item_id AND itemsite_warehous_id=<? value("warehous_id") ?>)\nWHERE (ipsitem_ipshead_id=<? value("ipshead_id") ?>)\n\nUNION\n\nSELECT ipsfreight_id AS id, 2 AS altid, <? value("freight") ?> AS type,\n       CASE WHEN (ipsfreight_type='F') THEN <? value("flatrate") ?>\n            ELSE <? value("peruom") ?>\n       END AS number,\n       ('From ' || COALESCE(warehous_code, <? value("allsites") ?>) || ' To ' || COALESCE(shipzone_name, <? value("allzones") ?>)) AS descrip,\n       CASE WHEN (ipsfreight_type='P') THEN uom_name END AS qtyuom,\n       CASE WHEN (ipsfreight_type='P') THEN ipsfreight_qtybreak END AS qtybreak,\n       uom_name AS priceuom, ipsfreight_price AS price,\n       0.00 AS fixedAmt,\n       NULL AS netPrice,\n       NULL AS type,\n       NULL AS method,\n       'weight' AS qtybreak_xtnumericrole,\n       'salesprice' AS netPrice_xtnumericrole,\n       'salesprice' AS price_xtnumericrole\nFROM ipsfreight LEFT OUTER JOIN uom ON (uom_item_weight)\n                LEFT OUTER JOIN whsinfo ON (warehous_id=ipsfreight_warehous_id)\n                LEFT OUTER JOIN shipzone ON (shipzone_id=ipsfreight_shipzone_id)\nWHERE ( (ipsfreight_ipshead_id=<? value("ipshead_id") ?>) )\nORDER BY altid, number, qtybreak;\n	admin	2015-10-01	0
56	itemReceipt	populateEdit	 used by enterPoitemReceipt, splitReceipt\n----PURCHASE ORDER----------\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemReceipt\n-- Name: populateEdit\n-- Notes: used by enterPoitemReceipt, splitReceipt\n------PURCHASE ORDER----------\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT pohead_number AS order_number, poitem_linenumber AS orderitem_linenumber,\n       (poitem_itemsite_id > 0) AS inventoryitem,\n       COALESCE(poitem_itemsite_id, -1) AS itemsiteid,\n       COALESCE(poitem_vend_item_number, '') AS vend_item_number,\n       COALESCE(poitem_vend_uom, '') AS vend_uom,\n       COALESCE(poitem_vend_item_descrip, '') AS vend_item_descrip,\n       poitem_invvenduomratio AS orderitem_qty_invuomratio,\n       poitem_duedate AS duedate,\n       poitem_qty_ordered AS orderitem_qty_ordered,\n       recv_qty AS qtyreceived,\n       poitem_qty_returned AS qtyreturned,\n       qtyToReceive('PO', poitem_id) AS qtytoreceive,\n       (poitem_qty_ordered) AS receivable,\n       recv_notes AS notes, recv_freight, recv_order_type,\n       recv_freight_curr_id AS curr_id, recv_date AS effective,\n       recv_purchcost, recv_purchcost_curr_id,\n       CASE WHEN (itemsite_costmethod='A' AND NOT(recv_posted)) THEN TRUE\n            ELSE FALSE\n       END AS costmethod_average,\n       'uomratio' AS orderitem_qty_invuomratio_xtnumericrole,\n       'qty' AS orderitem_qty_ordered_xtnumericrole, \n       'qty' AS qtyreceived_xtnumericrole, \n       'qty' AS qtyreturned_xtnumericrole, \n       'qty' AS qtytoreceive_xtnumericrole, \n       'qty' AS receivable_xtnumericrole,\n       'purchprice' AS recv_purchcost_xtnumericrole \nFROM recv \n  JOIN  poitem ON ((recv_orderitem_id=poitem_id)\n               AND (recv_order_type='PO'))\n  JOIN  pohead ON (poitem_pohead_id=pohead_id)\n  LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)\nWHERE (recv_id=<? value("recv_id") ?>)\n<? if exists ("EnableReturnAuth") ?>\nUNION\n-------RETURN AUTHORIZATIONS-----------\nSELECT rahead_number AS order_number, raitem_linenumber AS orderitem_linenumber,\n       (raitem_itemsite_id > 0) AS inventoryitem,\n       COALESCE(raitem_itemsite_id, -1) AS itemsiteid,\n       '' AS vend_item_number,\n       '' AS vend_uom,\n       '' AS vend_item_descrip,\n       raitem_qty_invuomratio AS orderitem_qty_invuomratio,\n       raitem_scheddate AS duedate,\n       raitem_qtyauthorized AS orderitem_qty_ordered,\n       recv_qty AS qtyreceived,\n       0 AS qtyreturned,\n       qtyToReceive('RA', raitem_id) AS qtytoreceive,\n       (raitem_qtyauthorized) AS receivable,\n       recv_notes AS notes, recv_freight, recv_order_type,\n       recv_freight_curr_id AS curr_id, recv_date AS effective,\n       NULL AS recv_purchcost, NULL AS recv_purchcost_curr_id,\n       NULL AS costmethod_average,\n       'uomratio' AS orderitem_qty_invuomratio_xtnumericrole,\n       'qty' AS orderitem_qty_ordered_xtnumericrole, \n       'qty' AS qtyreceived_xtnumericrole, \n       'qty' AS qtyreturned_xtnumericrole, \n       'qty' AS qtytoreceive_xtnumericrole, \n       'qty' AS receivable_xtnumericrole,\n       'purchprice' AS recv_purchcost_xtnumericrole \nFROM recv\n  JOIN  raitem ON ((recv_orderitem_id=raitem_id)\n               AND (recv_order_type='RA'))\n  JOIN  rahead ON (raitem_rahead_id=rahead_id)\nWHERE (recv_id=<? value("recv_id") ?>)\n<? endif ?>\n<? if exists ("MultiWhs") ?>\nUNION\n----------TRANSFER ORDERS---------\nSELECT tohead_number AS order_number, toitem_linenumber AS orderitem_linenumber,\n       (itemsite_id > 0) AS inventoryitem,\n       itemsite_id AS itemsiteid,\n       '' AS vend_item_number,\n       '' AS vend_uom,\n       '' AS vend_item_descrip,\n       1 AS orderitem_qty_invuomratio,\n       toitem_duedate AS duedate,\n       toitem_qty_ordered AS orderitem_qty_ordered,\n       recv_qty AS qtyreceived,\n       0 AS qtyreturned,\n       qtyToReceive('TO', toitem_id) AS qtytoreceive,\n       (toitem_qty_ordered) AS receivable,\n       recv_notes AS notes, recv_freight, recv_order_type,\n       recv_freight_curr_id AS curr_id, recv_date AS effective,\n       NULL AS recv_purchcost, NULL AS recv_purchcost_curr_id,\n       NULL AS costmethod_average,\n       'uomratio' AS orderitem_qty_invuomratio_xtnumericrole,\n       'qty' AS orderitem_qty_ordered_xtnumericrole, \n       'qty' AS qtyreceived_xtnumericrole, \n       'qty' AS qtyreturned_xtnumericrole, \n       'qty' AS qtytoreceive_xtnumericrole, \n       'qty' AS receivable_xtnumericrole,\n       'purchprice' AS recv_purchcost_xtnumericrole \nFROM itemsite, recv\n  JOIN  toitem ON ((recv_orderitem_id=toitem_id)\n               AND (recv_order_type='TO'))\n  JOIN  tohead ON (toitem_tohead_id=tohead_id)\nWHERE ((recv_id=<? value("recv_id") ?>)\n  AND  (tohead_dest_warehous_id=itemsite_warehous_id)\n  AND  (toitem_item_id=itemsite_item_id))\n<? endif ?>;\n	admin	2015-10-01	0
57	itemReceipt	populateNew	 used by enterPoitemReceipt\n-------PURCHASE ORDERS-------------\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemReceipt\n-- Name: populateNew\n-- Notes: used by enterPoitemReceipt\n---------PURCHASE ORDERS-------------\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT pohead_number AS order_number, poitem_linenumber AS orderitem_linenumber,\n       (poitem_itemsite_id > 0) AS inventoryitem,\n       COALESCE(poitem_itemsite_id, -1) AS itemsiteid,\n       COALESCE(poitem_vend_item_number, '') AS vend_item_number,\n       COALESCE(poitem_vend_uom, '') AS vend_uom,\n       COALESCE(poitem_vend_item_descrip, '') AS vend_item_descrip,\n       poitem_invvenduomratio AS orderitem_qty_invuomratio,\n       poitem_duedate AS duedate,\n       poitem_qty_ordered AS orderitem_qty_ordered,\n       poitem_qty_received AS qtyreceived,\n       poitem_qty_returned AS qtyreturned,\n       qtyToReceive('PO', poitem_id) AS qtytoreceive,\n       (poitem_qty_ordered - poitem_qty_received) AS receivable,\n       ( SELECT recv_notes\n           FROM recv\n          WHERE ((recv_orderitem_id=poitem_id)\n\t    AND  (recv_order_type='PO')\n            AND  (NOT recv_posted))\n\t  LIMIT 1 ) AS notes,\n       COALESCE(freightForRecv('PO', poitem_id, false),\n\t\tpoitem_freight - freightForRecv('PO', poitem_id, true),\n\t\tfreightForRecv('PO', poitem_id, true)) AS recv_freight,\n       pohead_curr_id AS curr_id, CURRENT_DATE AS effective, \n       poitem_unitprice AS recv_purchcost,\n       pohead_curr_id AS recv_purchcost_curr_id,\n       CASE WHEN (itemsite_costmethod='A') THEN TRUE \n\t    ELSE FALSE \n       END AS costmethod_average,\n       'uomratio' AS orderitem_qty_invuomratio_xtnumericrole,\n       'qty' AS orderitem_qty_ordered_xtnumericrole, \n       'qty' AS qtyreceived_xtnumericrole, \n       'qty' AS qtyreturned_xtnumericrole, \n       'qty' AS qtytoreceive_xtnumericrole, \n       'qty' AS receivable_xtnumericrole,\n       'purchprice' AS recv_purchcost_xtnumericrole \nFROM pohead\n  JOIN poitem ON (pohead_id=poitem_pohead_id)\n  LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)\nWHERE ((poitem_status <> 'C')\n  AND  (poitem_id=<? value("orderitem_id") ?>)\n  AND  ('PO'=<? value("ordertype") ?>) )\n<? if exists ("EnableReturnAuth") ?>\nUNION\n---------RETURN AUTHORIZATIONS-------------\nSELECT rahead_number AS order_number, raitem_linenumber AS orderitem_linenumber,\n       (raitem_itemsite_id > 0) AS inventoryitem,\n       COALESCE(raitem_itemsite_id, -1) AS itemsiteid,\n       '' AS vend_item_number,\n       '' AS vend_uom,\n       '' AS vend_item_descrip,\n       raitem_qty_invuomratio AS orderitem_qty_invuomratio,\n       raitem_scheddate AS duedate,\n       raitem_qtyauthorized AS orderitem_qty_ordered,\n       raitem_qtyreceived AS qtyreceived,\n       0 AS qtyreturned,\n       qtyToReceive('RA', raitem_id) AS qtytoreceive,\n       (raitem_qtyauthorized - raitem_qtyreceived) AS receivable,\n       ( SELECT recv_notes\n           FROM recv\n          WHERE ((recv_orderitem_id=raitem_id)\n\t    AND  (recv_order_type='RA')\n            AND  (NOT recv_posted))\n\t  LIMIT 1 ) AS notes,\n       COALESCE(freightForRecv('RA', raitem_id, false),\n\t\tfreightForRecv('RA', raitem_id, true)) AS recv_freight,\n       rahead_curr_id AS curr_id, CURRENT_DATE AS effective, \n       NULL AS recv_purchcost, NULL AS recv_purchcost_curr_id,\n       NULL AS costmethod_average,\n       'uomratio' AS orderitem_qty_invuomratio_xtnumericrole,\n       'qty' AS orderitem_qty_ordered_xtnumericrole, \n       'qty' AS qtyreceived_xtnumericrole, \n       'qty' AS qtyreturned_xtnumericrole, \n       'qty' AS qtytoreceive_xtnumericrole, \n       'qty' AS receivable_xtnumericrole,\n       'purchprice' AS recv_purchcost_xtnumericrole \nFROM rahead\n  JOIN raitem ON (rahead_id=raitem_rahead_id)\nWHERE ((raitem_status <> 'C')\n  AND  (raitem_id=<? value("orderitem_id") ?>)\n  AND  ('RA'=<? value("ordertype") ?>) )\n<? endif ?>\n<? if exists ("MultiWhs") ?>\nUNION\n-------------TRANSFER ORDERS--------------\nSELECT tohead_number AS order_number, toitem_linenumber AS orderitem_linenumber,\n       (itemsite_id > 0) AS inventoryitem,\n       COALESCE(itemsite_id, -1) AS itemsiteid,\n       '' AS vend_item_number,\n       '' AS vend_uom,\n       '' AS vend_item_descrip,\n       1 AS orderitem_qty_invuomratio,\n       toitem_duedate AS duedate,\n       toitem_qty_ordered AS orderitem_qty_ordered,\n       toitem_qty_received AS qtyreceived,\n       toitem_qty_shipped AS qtyreturned,\n       qtyToReceive('TO', toitem_id) AS qtytoreceive,\n       (toitem_qty_ordered - toitem_qty_received) AS receivable,\n       ( SELECT recv_notes\n           FROM recv\n          WHERE ((recv_orderitem_id=toitem_id)\n\t    AND  (recv_order_type='TO')\n            AND  (NOT recv_posted))\n\t  LIMIT 1 ) AS notes,\n       COALESCE(freightForRecv('TO', toitem_id, false),\n\t\tfreightForRecv('TO', toitem_id, true)) AS recv_freight,\n       baseCurrId() AS curr_id, CURRENT_DATE AS effective, \n       NULL AS recv_purchcost, NULL AS recv_purchcost_curr_id,\n       NULL AS costmethod_average,\n       'uomratio' AS orderitem_qty_invuomratio_xtnumericrole,\n       'qty' AS orderitem_qty_ordered_xtnumericrole, \n       'qty' AS qtyreceived_xtnumericrole, \n       'qty' AS qtyreturned_xtnumericrole, \n       'qty' AS qtytoreceive_xtnumericrole, \n       'qty' AS receivable_xtnumericrole,\n       'purchprice' AS recv_purchcost_xtnumericrole \nFROM itemsite, tohead\n  JOIN toitem ON (tohead_id=toitem_tohead_id) \nWHERE ((toitem_status NOT IN ('C', 'X'))\n  AND  (toitem_id=<? value("orderitem_id") ?>)\n  AND  ('TO'=<? value("ordertype") ?>)\n  AND  (tohead_dest_warehous_id=itemsite_warehous_id)\n  AND  (toitem_item_id=itemsite_item_id))\n<? endif ?>;\n	admin	2015-10-01	0
58	itemReceipt	sourceItemSite	 used by enterPoitemReceipt\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemReceipt\n-- Name: sourceItemSite\n-- Notes: used by enterPoitemReceipt\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("poitem_id") ?>\t\t\t-- this should never be called\n  SELECT -1 AS itemsite_id, -1 AS warehous_id;\n<? elseif exists("toitem_id") ?>\n  SELECT itemsite_id, tohead_dest_warehous_id AS warehous_id\n  FROM tohead, toitem, itemsite \n  WHERE ((itemsite_item_id=toitem_item_id)\n    AND  (itemsite_warehous_id=tohead_src_warehous_id)\n    AND  (toitem_tohead_id=tohead_id)\n    AND  (toitem_id=<? value("toitem_id") ?>));\n<? elseif exists("recv_id") ?>\t\t\t-- this should never be called\n  SELECT itemsite_id, tohead_dest_warehous_id AS warehous_id\n  FROM tohead, toitem, itemsite, recv\n  WHERE ((itemsite_item_id=toitem_item_id)\n    AND  (itemsite_warehous_id=tohead_src_warehous_id)\n    AND  (toitem_tohead_id=tohead_id)\n    AND  (toitem_id=recv_orderitem_id)\n    AND  (recv_id=<? value("recv_id") ?>));\n<? endif ?>\n	admin	2015-10-01	0
259	itemSites	detail	\n Notes:\n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemSites\n-- Name: detail\n-- Notes:\n-- Notes:\n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsite_id,warehous_code,itemsite_qtyonhand, itemsite_active, \n       CASE WHEN ( (itemsite_loccntrl) OR\n                   (itemsite_controlmethod IN ('L', 'S')) ) THEN 1\n            ELSE 0\n       END AS altId,\n       CASE WHEN itemsite_controlmethod='R' THEN <? value("regular") ?>\n                           WHEN itemsite_controlmethod='N' THEN <? value("none") ?>\n                           WHEN itemsite_controlmethod='L' THEN <? value("lot") ?>\n                           WHEN itemsite_controlmethod='S' THEN <? value("serial") ?>\n                      END AS controlmethod,\n         itemsite_loccntrl,\n         item_number,\n         (item_descrip1 || ' ' || item_descrip2) AS description, \n         uom_name,\n         CASE WHEN (itemsite_sold) THEN TEXT(itemsite_soldranking)\n         END AS soldranking,\n         CASE WHEN (itemsite_datelastcount=startOfTime()) THEN NULL\n           ELSE itemsite_datelastcount\n         END AS datelastcount,\n         CASE WHEN (itemsite_datelastused=startOfTime()) THEN NULL\n           ELSE itemsite_datelastused\n         END AS datelastused,\n         itemsite_abcclass, itemsite_cyclecountfreq,\n         'qty' AS itemsite_qtyonhand_xtnumericrole,\n        <? value("na") ?> AS soldranking_xtnullrole,\n        <? value("never") ?> AS datelastused_xtnullrole,\n        <? value("never") ?> AS datelastcount_xtnullrole             \nFROM item, uom, itemsite, whsinfo\nWHERE ((itemsite_warehous_id=warehous_id)\n         AND (itemsite_item_id=item_id)\n         AND(item_inv_uom_id=uom_id)\n       <? if exists("search_pattern") ?>\n         AND ((item_number ~* <? value("search_pattern") ?>)\n           OR (COALESCE(item_descrip1,'') || ' ' || COALESCE(item_descrip2,'') ~* <? value("search_pattern") ?>)\n           OR (warehous_code ~* <? value("search_pattern") ?>))\n       <? endif ?>\n       <? if exists("item_id") ?>\n         AND (item_id=<? value("item_id") ?>)\n       <? endif ?>\n       <? if exists("classcode_id") ?>\n         AND (item_classcode_id=<? value("classcode_id") ?>)\n       <? endif ?>\n       <? if exists("itemgrp_id") ?>\n         AND (item_id IN (SELECT itemgrpitem_item_id \n                          FROM itemgrpitem \n                          WHERE (itemgrpitem_itemgrp_id=<? value("itemgrp_id") ?>)))\n       <? endif ?>\n       <? if exists("plancode_id") ?>\n         AND (itemsite_plancode_id=<? value("plancode_id") ?>)\n       <? endif ?>\n       <? if exists("costcat_id") ?>\n         AND (itemsite_costcat_id=<? value("costcat_id") ?>)\n       <? endif ?>\n       <? if exists("classcode_pattern") ?>\n         AND (item_classcode_id IN (SELECT classcode_id \n                                    FROM classcode \n                                    WHERE (classcode_code ~ <? value("classcode_pattern") ?>)))\n       <? endif ?>\n       <? if exists("itemgrp_pattern") ?>\n         AND (item_id IN (SELECT itemgrpitem_item_id \n                          FROM itemgrpitem, itemgrp \n                          WHERE ( (itemgrpitem_itemgrp_id=itemgrp_id) \n                              AND (itemgrp_name ~ <? value("itemgrp_pattern") ?>) ) ))\n       <? endif ?>\n       <? if exists("plancode_pattern") ?>\n         AND (itemsite_plancode_id IN (SELECT plancode_id \n                                       FROM plancode \n                                       WHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n       <? endif ?>\n       <? if exists("costcat_pattern") ?>\n         AND (itemsite_costcat_id IN (SELECT costcat_id \n                                      FROM costcat \n                                      WHERE (costcat_code ~ <? value("costcat_pattern") ?>)))\n       <? endif ?>\n     <? if exists("warehous_id") ?>\n       AND (warehous_id=<? value("warehous_id") ?>)\n     <? endif ?>\n     <? if exists("loc_cntrl") ?>\n       AND (itemsite_loccntrl = <? value("loc_cntrl") ?>)\n     <? endif ?>\n   <? if not exists("showInactive") ?>\n     AND (itemsite_active)\n   <? endif ?>\n       )\nORDER BY item_number, warehous_code;\n	admin	2015-10-01	0
260	itemSources	detail	 \n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemSources\n-- Name: detail\n-- Notes: \n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n<? if not exists("defaultOnly") ?>\n  SELECT itemsrc_id, \n       vend_number, vend_name, \n       item_number, uom_name,\n       (item_descrip1 || ' ' || item_descrip2) AS item_descrip,\n       contrct_number,\n       COALESCE( (SELECT SUM(poitem_qty_ordered)\n                  FROM poitem\n                  WHERE (poitem_itemsrc_id=itemsrc_id)), 0.0) AS purchased_qty,\n       itemsrc.*,\n       'qty' AS itemsrc_invvendoruomratio_xtnumericrole,\n       CASE WHEN COALESCE(itemsrc_effective, startOfTime()) <=\n                 startOfTime() THEN <? value("always") ?>\n       END AS itemsrc_effective_qtdisplayrole,\n       CASE WHEN COALESCE(itemsrc_expires, endOfTime()) >=\n                 endOfTime() THEN <? value("never") ?>\n       END AS itemsrc_expires_qtdisplayrole,\n       CASE WHEN (COALESCE(itemsrc_expires, endOfTime()) < CURRENT_DATE) THEN 'expired'\n            WHEN (COALESCE(itemsrc_effective, startOfTime()) > CURRENT_DATE) THEN 'future'\n       END AS qtforegroundrole\n  FROM itemsrc JOIN vendinfo ON (vend_id=itemsrc_vend_id AND vend_active)\n               JOIN item ON (item_id=itemsrc_item_id)\n               JOIN uom ON (uom_id=item_inv_uom_id)\n               LEFT OUTER JOIN contrct ON (contrct_id=itemsrc_contrct_id) \n  WHERE ((true)\n<? if not exists("showInactive") ?>\n   AND (itemsrc_active)\n<? endif ?>\n<? if exists("item_id") ?>\n   AND (itemsrc_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("vend_id") ?>\n   AND (itemsrc_vend_id=<? value("vend_id") ?>)\n<? endif ?>\n<? if exists("contrct_id") ?>\n   AND (itemsrc_contrct_id=<? value("contrct_id") ?>)\n<? endif ?>\n<? if exists("contract_number_pattern") ?>\n   AND (contrct_number ~* <? value("contract_number_pattern") ?>)\n<? endif ?>\n<? if not exists("showExpired") ?>\n   AND (itemsrc_expires > CURRENT_DATE)\n<? endif ?>\n<? if not exists("showFuture") ?>\n   AND (itemsrc_effective <= CURRENT_DATE)\n<? endif ?>\n)\n<? if exists("item_id") ?>\nORDER BY itemsrc_contrct_id, itemsrc_ranking, vend_name,\n         itemsrc_vend_item_number, itemsrc_manuf_name,\n         itemsrc_manuf_item_number\n<? else ?>\nORDER By item_number, vend_name\n<? endif ?>\n<? else ?>\n  SELECT itemsrc_id, 0 AS ranked FROM itemsrc, contrct \n    WHERE ((itemsrc_item_id= <? value("item_id") ?>) AND (itemsrc_default) \n           AND (contrct_id = itemsrc_contrct_id)) \n  UNION \n  SELECT itemsrc_id, 2 AS ranked \n    FROM itemsrc JOIN (SELECT * FROM \n                        (SELECT CASE WHEN ((itemsrc_item_id=<? value("item_id") ?>) AND (NOT itemsrc_default)\n                                            AND (contrct_id = itemsrc_contrct_id)) THEN -1\n                                     ELSE itemsrc_id\n                                END AS dummy_id FROM itemsrc, contrct \n                           WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (NOT itemsrc_default) \n                                  AND (contrct_id = itemsrc_contrct_id))\n                         UNION \n                         SELECT itemsrc_id AS dummy_id \n                           FROM itemsrc \n                           WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (itemsrc_default))\n                         ) AS dummy\n                       LIMIT 1) AS dummy2\n                        ON (itemsrc_id=dummy_id)\n    WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (itemsrc_default) AND (COALESCE(itemsrc_contrct_id,0)=0))\n\nORDER by ranked\n<? endif ?>\n;\n	admin	2015-10-01	0
476	itemSources	prices	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemSources\n-- Name: prices\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsrcp_id, itemsrc_id,\n       vend_number, vend_name,\n       currConcat(vend_curr_id) AS vend_curr,\n       item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS item_descrip,\n       warehous_code, uom_name,\n       contrct_number,\n       itemsrc.*,\n       (itemsrc_vend_item_number || '/' || itemsrc_manuf_item_number) AS itemsrc_descrip,\n       itemsrcp.*,\n       currConcat(itemsrcp_curr_id) AS item_curr,\n       noNeg(CASE WHEN (itemsrcp_type='N') THEN currToBase(itemsrcp_curr_id, itemsrcp_price, itemsrcp_updated)\n                  WHEN (itemsrcp_type='D') THEN (item_listcost - (item_listcost * COALESCE(itemsrcp_discntprcnt, 0.0)) - COALESCE(itemsrcp_fixedamtdiscount, 0.0))\n                  ELSE 0.0\n             END) AS price_base,\n       noNeg(CASE WHEN (itemsrcp_type='N') THEN itemsrcp_price\n                  WHEN (itemsrcp_type='D') THEN (item_listcost - (item_listcost * COALESCE(itemsrcp_discntprcnt, 0.0)) - COALESCE(itemsrcp_fixedamtdiscount, 0.0))\n                  ELSE 0.0\n             END) AS price_local,\n       CASE WHEN (itemsrcp_type='N') THEN <? value("nominal") ?>\n            WHEN (itemsrcp_type='D') THEN <? value("discount") ?>\n            ELSE 'error'\n       END AS type,\n       CASE WHEN (itemsrcp_type='N') THEN <? value("price") ?>\n            WHEN ((itemsrcp_type='D') AND (COALESCE(itemsrcp_discntprcnt, 0.0)=0.0) AND (COALESCE(itemsrcp_fixedamtdiscount, 0.0)<>0.0)) THEN <? value("fixed") ?>\n            WHEN ((itemsrcp_type='D') AND (COALESCE(itemsrcp_discntprcnt, 0.0)<>0.0) AND (COALESCE(itemsrcp_fixedamtdiscount, 0.0)=0.0)) THEN <? value("percent") ?>\n            WHEN (itemsrcp_type='D') THEN <? value("mixed") ?>\n            ELSE 'error'\n       END AS method,\n       'qty' AS itemsrc_invvendoruomratio_xtnumericrole,\n       'qty' AS itemsrc_minordqty_xtnumericrole,\n       'qty' AS itemsrc_ordqtymult_xtnumericrole,\n       'qty' AS itemsrcp_qtybreak_xtnumericrole,\n       'purchprice' AS price_local_xtnumericrole,\n       'purchprice' AS price_base_xtnumericrole,\n       'percent' AS itemsrcp_discntprcnt_xtnumericrole,\n       CASE WHEN (warehous_code IS NULL) THEN <? value("all") ?>\n       END AS warehous_code_qtdisplayrole,\n       CASE WHEN (itemsrcp_dropship) THEN <? value("dropship") ?>\n            ELSE <? value("stock") ?>\n       END AS itemsrcp_dropship_qtdisplayrole,\n       CASE WHEN COALESCE(itemsrc_effective, startOfTime()) <=\n                 startOfTime() THEN <? value("always") ?>\n       END AS itemsrc_effective_qtdisplayrole,\n       CASE WHEN COALESCE(itemsrc_expires, endOfTime()) >=\n                 endOfTime() THEN <? value("never") ?>\n       END AS itemsrc_expires_qtdisplayrole,\n       CASE WHEN (COALESCE(itemsrc_expires, endOfTime()) < CURRENT_DATE) THEN 'expired'\n            WHEN (COALESCE(itemsrc_effective, startOfTime()) > CURRENT_DATE) THEN 'future'\n       END AS qtforegroundrole\nFROM itemsrc JOIN vendinfo ON (vend_id=itemsrc_vend_id AND vend_active)\n             JOIN item ON (item_id=itemsrc_item_id)\n             JOIN uom ON (uom_id=item_inv_uom_id)\n             JOIN itemsrcp ON (itemsrcp_itemsrc_id=itemsrc_id)\n             LEFT OUTER JOIN contrct ON (contrct_id=itemsrc_contrct_id)\n             LEFT OUTER JOIN whsinfo ON (warehous_id=itemsrcp_warehous_id)\nWHERE ((true)\n<? if not exists("showInactive") ?>\n   AND (itemsrc_active)\n<? endif ?>\n<? if exists("item_id") ?>\n  AND (itemsrc_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("vend_id") ?>\n  AND (itemsrc_vend_id=<? value("vend_id") ?>)\n<? endif ?>\n<? if exists("itemsrc_id") ?>\n  AND (itemsrc_id=<? value("itemsrc_id") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n  AND (itemsrcp_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("showDropShip") ?>\n   AND (itemsrcp_dropship)\n<? endif ?>\n<? if exists("search_pattern") ?>\n  AND ( (item_number ~* <? value("search_pattern") ?>)\n    OR  (COALESCE(item_descrip1,'') || COALESCE(item_descrip2,'') ~* <? value("search_pattern") ?>) )\n<? endif ?>\n<? if exists("item_number_pattern") ?>\n  AND (item_number ~* <? value("item_number_pattern") ?>)\n<? endif ?>\n<? if exists("item_descrip_pattern") ?>\n  AND (COALESCE(item_descrip1,'') || COALESCE(item_descrip2,'') ~* <? value("item_descrip_pattern") ?>)\n<? endif ?>\n<? if exists("contrct_id") ?>\n  AND (itemsrc_contrct_id=<? value("contrct_id") ?>)\n<? endif ?>\n<? if exists("contract_number_pattern") ?>\n  AND (contrct_number ~* <? value("contract_number_pattern") ?>)\n<? endif ?>\n<? if exists("vend_name_pattern") ?>\n  AND (vend_name ~* <? value("vend_name_pattern") ?>)\n<? endif ?>\n<? if exists("vend_item_number_pattern") ?>\n  AND (itemsrc_vend_item_number ~* <? value("vend_item_number_pattern") ?>)\n<? endif ?>\n<? if exists("manuf_pattern") ?>\n  AND (itemsrc_manuf_name ~* <? value("manuf_pattern") ?>)\n<? endif ?>\n<? if exists("manuf_item_number_pattern") ?>\n  AND (itemsrc_manuf_item_number ~* <? value("manuf_item_number_pattern") ?>)\n<? endif ?>\n<? if exists("effectiveStartDate") ?>\n  AND (COALESCE(contrct_effective, itemsrc_effective) >= <? value("effectiveStartDate") ?>)\n<? endif ?>\n<? if exists("effectiveEndDate") ?>\n  AND (COALESCE(contrct_effective, itemsrc_effective) <= <? value("effectiveEndDate") ?>)\n<? endif ?>\n<? if exists("expireStartDate") ?>\n  AND (COALESCE(contrct_expires, itemsrc_expires) >= <? value("expireStartDate") ?>)\n<? endif ?>\n<? if exists("expireEndDate") ?>\n  AND (COALESCE(contrct_expires, itemsrc_expires) <= <? value("expireEndDate") ?>)\n<? endif ?>\n)\nORDER By item_number, vend_name, itemsrcp_qtybreak\n;\n	admin	2015-10-01	0
477	itemSources	search	 \n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemSources\n-- Name: search\n-- Notes: \n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\n  SELECT itemsrc_id AS id,\n         1 AS altid,\n         item_number,\n         (item_descrip1 || ' ' || item_descrip2) AS item_descrip,\n         vend_name,\n         itemsrc_vend_item_number,\n         itemsrc_vend_item_descrip,\n         itemsrc_manuf_name,\n         itemsrc_manuf_item_number,\n         itemsrc_manuf_item_descrip,\n         contrct_number\n    FROM vendinfo JOIN itemsrc ON (itemsrc_vend_id=vend_id)\n                  JOIN item ON (item_id=itemsrc_item_id)\n       LEFT OUTER JOIN contrct ON (itemsrc_contrct_id = contrct_id)\n   WHERE (vend_id=<? value("vend_id") ?>)\n     AND ( (FALSE)\n<? if exists("searchNumber") ?>\n        OR (item_number ~* <? value("searchNumber") ?>)\n<? endif ?>\n<? if exists("searchVendNumber") ?>\n        OR (itemsrc_vend_item_number ~* <? value("searchVendNumber") ?>)\n<? endif ?>\n<? if exists("searchDescrip1") ?>\n        OR (item_descrip1 ~* <? value("searchDescrip1") ?>)\n<? endif ?>\n<? if exists("searchDescrip2") ?>\n        OR (item_descrip2 ~* <? value("searchDescrip2") ?>)\n<? endif ?>\n<? if exists("searchVendDescrip") ?>\n        OR (itemsrc_vend_item_descrip ~* <? value("searchVendDescrip") ?>)\n<? endif ?>\n<? if exists("searchManufName") ?>\n        OR (itemsrc_manuf_name ~* <? value("searchManufName") ?>)\n<? endif ?>\n<? if exists("searchManufNumber") ?>\n        OR (itemsrc_manuf_item_number ~* <? value("searchManufNumber") ?>)\n<? endif ?>\n       )\n  UNION\n  SELECT DISTINCT poitem_expcat_id AS id,\n                  2 AS altid,\n                  <? value("non") ?> AS item_number,\n                  (expcat_code || ' ' || expcat_descrip) AS item_descrip,\n                  vend_name,\n                  poitem_vend_item_number,\n                  poitem_vend_item_descrip,\n                  poitem_manuf_name,\n                  poitem_manuf_item_number,\n                  poitem_manuf_item_descrip,\n                  null AS contrct_id \n    FROM vendinfo JOIN pohead ON (pohead_vend_id=vend_id)\n                  JOIN poitem ON (poitem_pohead_id=pohead_id)\n                  LEFT OUTER JOIN expcat ON (poitem_expcat_id=expcat_id)\n   WHERE (vend_id=<? value("vend_id") ?>)\n     AND (COALESCE(poitem_vend_item_number, '')!='')\n     AND (poitem_itemsite_id IS NULL)\n     AND ( (FALSE)\n<? if exists("searchVendNumber") ?>\n        OR (poitem_vend_item_number ~* <? value("searchVendNumber") ?>)\n<? endif ?>\n<? if exists("searchDescrip1") ?>\n        OR (expcat_code ~* <? value("searchDescrip1") ?>)\n        OR (expcat_descrip ~* <? value("searchDescrip1") ?>)\n<? endif ?>\n<? if exists("searchVendDescrip") ?>\n        OR (poitem_vend_item_descrip ~* <? value("searchVendDescrip") ?>)\n<? endif ?>\n<? if exists("searchManufName") ?>\n        OR (poitem_manuf_name ~* <? value("searchManufName") ?>)\n<? endif ?>\n<? if exists("searchManufNumber") ?>\n        OR (poitem_manuf_item_number ~* <? value("searchManufNumber") ?>)\n<? endif ?>\n       )\n  ORDER BY item_number, vend_name;\n	admin	2015-10-01	0
113	itemcostdetail	detail	 dspItemCostDetail\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemcostdetail\n-- Name:  detail\n-- Notes: dspItemCostDetail\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT id, item.item_id, seqnumber, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip, uom_name,\n       qtyper,       'qtyper' AS qtyper_xtnumericrole,\n       scrap,        'scrap' AS scrap_xtnumericrole,\n       cost,         'cost' AS cost_xtnumericrole,\n       extendedcost, 'cost' AS extendedcost_xtnumericrole,\n       0 AS extendedcost_xttotalrole \nFROM uom, item, (\n<? if exists("useBOM") ?>\n     SELECT bomitem_id AS id, bomitem_seqnumber AS seqnumber,\n            (itemuomtouomratio(bomitem_item_id, bomitem_uom_id, NULL) * bomitem_qtyper) AS qtyper,\n            bomitem_scrap AS scrap,\n            bomitem_item_id AS item_id,\n  <? if exists("standardCost") ?>\n            itemcost_stdcost AS cost,\n            (itemuomtouom(bomitem_item_id, bomitem_uom_id, NULL,\n                          (bomitem_qtyfxd/bomhead_batchsize + bomitem_qtyper) * (1 + bomitem_scrap), 'qtyper') * itemcost_stdcost) AS extendedcost\n  <? elseif exists("actualCost") ?>\n            currToBase(itemcost_curr_id, itemcost_actcost, NULL) AS cost,\n            (itemuomtouom(bomitem_item_id, bomitem_uom_id, NULL,\n                          (bomitem_qtyfxd/bomhead_batchsize + bomitem_qtyper) * (1 + bomitem_scrap), 'qtyper') *\n             currToBase(itemcost_curr_id, itemcost_actcost, NULL)) AS extendedcost \n  <? endif ?>\n    FROM bomitem\n         JOIN itemcost ON (itemcost_item_id=bomitem_item_id)\n         JOIN costelem ON (itemcost_costelem_id=costelem_id)\n         JOIN bomhead ON (bomhead_item_id=bomitem_parent_item_id AND bomhead_rev_id=bomitem_rev_id)\n  <? if exists("includeRevisionControl") ?>\n    LEFT OUTER JOIN rev ON ((bomitem_rev_id=rev_id) AND (COALESCE(rev_status, 'A')='A')) \n  <? endif ?>\n    WHERE ((CURRENT_DATE BETWEEN bomitem_effective AND (bomitem_expires-1))\n     AND (bomitem_parent_item_id=<? value("item_id") ?>)\n     AND (costelem_id=<? value("costelem_id") ?>) ) \n<? elseif exists("useBBOM") ?>\n     SELECT bbomitem_id AS id, bbomitem_seqnumber AS seqnumber,\n            bbomitem_qtyper AS qtyper,\n            bbomitem_costabsorb AS scrap,\n            bbomitem_parent_item_id AS item_id,\n  <? if exists("standardCost") ?>\n            itemcost_stdcost AS cost,\n            (itemcost_stdcost / bbomitem_qtyper *\n             bbomitem_costabsorb) AS extendedcost \n  <? elseif exists("actualCost") ?>\n            currToBase(itemcost_curr_id, itemcost_actcost, NULL) AS cost,\n            (currToBase(itemcost_curr_id, itemcost_actcost, NULL) / bbomitem_qtyper *\n             bbomitem_costabsorb) AS extendedcost \n  <? endif ?>\n    FROM xtmfg.bbomitem\n         JOIN itemcost ON (itemcost_item_id=bbomitem_parent_item_id)\n    WHERE ((CURRENT_DATE BETWEEN bbomitem_effective AND (bbomitem_expires-1))\n     AND (itemcost_costelem_id=<? value("costelem_id") ?>)\n     AND (bbomitem_item_id=<? value("item_id") ?>) )\n    UNION\n    SELECT source.bbomitem_id, source.bbomitem_seqnumber AS seqnumber,\n           source.bbomitem_qtyper, target.bbomitem_costabsorb,\n           item_id,\n  <? if exists("standardCost") ?>\n           itemcost_stdcost AS cost,\n           (itemcost_stdcost * source.bbomitem_qtyper /\n            target.bbomitem_qtyper * target.bbomitem_costabsorb) AS extendedcost \n  <? elseif exists("actualCost") ?>\n           currToBase(itemcost_curr_id, itemcost_actcost, NULL) AS cost,\n           (currToBase(itemcost_curr_id, itemcost_actcost, NULL) * source.bbomitem_qtyper /\n            target.bbomitem_qtyper * target.bbomitem_costabsorb) AS extendedcost \n  <? endif ?>\n    FROM xtmfg.bbomitem AS source\n         JOIN item     ON (source.bbomitem_item_id=item_id)\n         JOIN itemcost ON (source.bbomitem_item_id=itemcost_item_id)\n         JOIN xtmfg.bbomitem AS target\n              ON (source.bbomitem_parent_item_id=target.bbomitem_parent_item_id)\n    WHERE ((CURRENT_DATE BETWEEN source.bbomitem_effective\n                            AND (source.bbomitem_expires-1))\n     AND (CURRENT_DATE BETWEEN target.bbomitem_effective\n                          AND (target.bbomitem_expires-1))\n     AND (item_type='Y')\n     AND (target.bbomitem_item_id=<? value("item_id") ?>)\n     AND (itemcost_costelem_id=<? value("costelem_id") ?>) )\n<? endif ?>\n) AS data \nWHERE ((data.item_id=item.item_id)\n   AND (item_inv_uom_id=uom_id)) \nORDER BY seqnumber;\n	admin	2015-10-01	0
258	items	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: items\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n SELECT\n        <? if exists("ListNumericItemNumbersFirst") ?>\n         DISTINCT ON ( toNumeric(item_number, 999999999999999), item_number )\n        <? else ?>\n         DISTINCT ON ( item_number )\n        <? endif ?>\n               item.*, classcode.*, uom.*, prodcat.*, freightclass.*,\n               <? foreach("char_id_text_list") ?>\n                      charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,\n               <? endforeach ?>\n               <? foreach("char_id_list_list") ?>\n                      charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,\n               <? endforeach ?>\n               <? foreach("char_id_date_list") ?>\n                      charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,\n               <? endforeach ?>\n                      (COALESCE(item_descrip1,'') || ' ' || COALESCE(item_descrip2,'')) as item_descrip,\n                      CASE WHEN (item_type='P') THEN text(<? value("purchased") ?>)\n                           WHEN (item_type='M') THEN text(<? value("manufactured") ?>)\n                           WHEN (item_type='F') THEN text(<? value("phantom") ?>)\n                           WHEN (item_type='B') THEN text(<? value("breeder") ?>)\n                           WHEN (item_type='C') THEN text(<? value("coProduct") ?>)\n                           WHEN (item_type='Y') THEN text(<? value("byProduct") ?>)\n                           WHEN (item_type='R') THEN text(<? value("reference") ?>)\n                           WHEN (item_type='S') THEN text(<? value("costing") ?>)\n                           WHEN (item_type='T') THEN text(<? value("tooling") ?>)\n                           WHEN (item_type='A') THEN text(<? value("assortment") ?>)\n                           WHEN (item_type='O') THEN text(<? value("outside") ?>)\n                           WHEN (item_type='L') THEN text(<? value("planning") ?>)\n                           WHEN (item_type='K') THEN text(<? value("kit") ?>)\n                           ELSE text(<? value("error") ?>)\n                      END AS f_item_type,\n                      CASE WHEN (item_type='P') THEN text(<? value("purchased") ?>)\n                           WHEN (item_type='M') THEN text(<? value("manufactured") ?>)\n                           WHEN (item_type='F') THEN text(<? value("phantom") ?>)\n                           WHEN (item_type='B') THEN text(<? value("breeder") ?>)\n                           WHEN (item_type='C') THEN text(<? value("coProduct") ?>)\n                           WHEN (item_type='Y') THEN text(<? value("byProduct") ?>)\n                           WHEN (item_type='R') THEN text(<? value("reference") ?>)\n                           WHEN (item_type='S') THEN text(<? value("costing") ?>)\n                           WHEN (item_type='T') THEN text(<? value("tooling") ?>)\n                           WHEN (item_type='A') THEN text(<? value("assortment") ?>)\n                           WHEN (item_type='O') THEN text(<? value("outside") ?>)\n                           WHEN (item_type='L') THEN text(<? value("planning") ?>)\n                           WHEN (item_type='K') THEN text(<? value("kit") ?>)\n                           ELSE text(<? value("error") ?>)\n                      END AS item_type_qtdisplayrole\n               FROM item\n                 JOIN classcode ON (item_classcode_id=classcode_id)\n                 JOIN uom ON (item_inv_uom_id=uom_id)\n                 LEFT OUTER JOIN prodcat ON (item_prodcat_id=prodcat_id)\n                 LEFT OUTER JOIN freightclass ON (item_freightclass_id=freightclass_id)\n               <? if exists("itemgrp_id") ?>\n                 JOIN itemgrpitem ON (item_id=itemgrpitem_item_id)\n                 JOIN itemgrp ON (itemgrp_id=itemgrpitem_itemgrp_id)\n               <? endif ?>\n               <? foreach("char_id_text_list") ?>\n                 LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> \n                   ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='I') \n                   AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=item_id)\n                   AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n                 LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> \n                   ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n               <? endforeach ?>\n               <? foreach("char_id_list_list") ?>\n                 LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> \n                   ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='I') \n                   AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=item_id)\n                   AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n                 LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> \n                   ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n               <? endforeach ?>\n               <? foreach("char_id_date_list") ?>\n                 LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> \n                   ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='I') \n                   AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=item_id)\n                   AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n                 LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> \n                   ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n               <? endforeach ?>\n               WHERE ( true\n               <? if exists("search_pattern") ?>\n                AND ( (item_number ~* <? value("search_pattern") ?>)\n                      OR  (COALESCE(item_descrip1,'') || COALESCE(item_descrip2,'') ~* <? value("search_pattern") ?>) )\n               <? endif ?>\n               <? if exists("showPurchased") ?>\n                AND (item_type IN ('P', 'O'))\n               <? elseif exists("showManufactured") ?>\n                AND (item_type IN ('M', 'F', 'B','K'))\n               <? elseif exists("showSold") ?>\n                AND (item_sold)\n               <? endif ?>\n               <? if exists("item_type") ?>\n                AND (item_type=<? value("item_type") ?>)\n               <? endif ?>\n               <? if not exists("showInactive") ?>\n                AND (item_active)\n               <? endif ?>\n               <? if exists("classcode_id") ?>\n                AND (item_classcode_id=<? value("classcode_id") ?>)\n               <? endif ?>\n               <? if exists("prodcat_id") ?>\n                AND (item_prodcat_id=<? value("prodcat_id") ?>)\n               <? endif ?>\n               <? if exists("freightclass_id") ?>\n                AND (item_freightclass_id=<? value("freightclass_id") ?>)\n               <? endif ?>\n               <? if exists("itemgrp_id") ?>\n                AND (itemgrp_id=<? value("itemgrp_id") ?>)\n               <? endif ?>\n               <? if exists("item_number_pattern") ?>\n                AND (item_number ~* <? value("item_number_pattern") ?>)\n               <? endif ?>\n               <? if exists("item_descrip_pattern") ?>\n                AND (COALESCE(item_descrip1,'') || COALESCE(item_descrip2,'') ~* <? value("item_descrip_pattern") ?>)\n               <? endif ?>\n               <? if exists("classcode_pattern") ?>\n                AND (classcode_code ~* <? value("classcode_pattern") ?>)\n               <? endif ?>\n               <? if exists("prodcat_pattern") ?>\n                AND (prodcat_code  ~* <? value("prodcat_pattern") ?>)\n               <? endif ?>\n               <? if exists("freightclass_pattern") ?>\n                AND (freightclass_code ~* <? value("freightclass_pattern") ?>)\n               <? endif ?>\n               <? literal("charClause") ?>\n               ) ORDER BY\n               <? if exists("ListNumericItemNumbersFirst") ?>\n                toNumeric(item_number, 999999999999999),\n               <? endif ?>\n                item_number;\n	admin	2015-10-01	0
261	itemsWithoutItemSources	detail	 used by dspItemsWithoutItemSources\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: itemsWithoutItemSources\n-- Name: detail\n-- Notes: used by dspItemsWithoutItemSources\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT item_id, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS descrip,\n       CASE WHEN (item_type = 'P') THEN <? value("purchased") ?>\n            WHEN (item_type = 'O') THEN <? value("outside") ?>\n       END AS type \nFROM item \nWHERE ( (item_type IN ('P', 'O'))\n    AND (item_active)\n    AND (item_id NOT IN (SELECT DISTINCT itemsrc_item_id\n                         FROM itemsrc \n                         WHERE (itemsrc_active))) ) \nORDER BY item_number;\n	admin	2015-10-01	0
412	journals	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: journals\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT sltrans.*,\n       CASE WHEN(sltrans_docnumber='Misc.' AND\n              invhist_docnumber IS NOT NULL) THEN\n              (sltrans_docnumber || ' - ' || invhist_docnumber)\n            ELSE sltrans_docnumber\n       END AS docnumber,\n       firstLine(sltrans_notes) AS notes,\n       sltrans_journalnumber,\n       (formatGLAccount(accnt_id) || ' - ' || accnt_descrip) AS account,\n       CASE WHEN (sltrans_amount < 0) THEN ABS(sltrans_amount)\n            ELSE NULL\n       END AS debit,\n       CASE WHEN (sltrans_amount > 0) THEN sltrans_amount\n            ELSE NULL\n       END AS credit,\n       sltrans_gltrans_journalnumber,\n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole\nFROM sltrans JOIN accnt ON (sltrans_accnt_id=accnt_id) \n     LEFT OUTER JOIN invhist ON (sltrans_misc_id=invhist_id\n                            AND sltrans_docnumber='Misc.') \n<? if exists("company_id") ?>\n     JOIN company ON (accnt_company=company_number) \n<? endif ?>\n<? if exists("prfcntr_id") ?>\n     JOIN prftcntr ON (accnt_profit=prftcntr_number) \n<? endif ?>\n<? if exists("subaccnt_id") ?>\n     JOIN subaccnt ON (accnt_sub=subaccnt_number) \n<? endif ?>\n<? if exists("subType") ?>\n     JOIN subaccnttype ON (subaccnttype_code=accnt_subaccnttype_code) \n<? endif ?>\nWHERE (\n<? if exists("startDate") ?>\n  <? if exists("endDate") ?>\n       (sltrans_date BETWEEN <? value("startDate") ?>\n                         AND <? value("endDate") ?>)\n  <? else ?>\n       (sltrans_date BETWEEN <? value("startDate") ?>\n                         AND endoftime())\n  <? endif ?>\n<? else ?>\n  <? if exists("endDate") ?>\n       (sltrans_date BETWEEN startoftime()\n                         AND <? value("endDate") ?>)\n  <? else ?>\n       (sltrans_date BETWEEN startoftime()\n                         AND endoftime())\n  <? endif ?>\n<? endif ?>\n<? if exists("company_id") ?>\n   AND (company_id=<? value("company_id") ?>)\n<? endif ?>\n<? if exists("prfcntr_id") ?>\n   AND (prftcntr_id=<? value("prfcntr_id") ?>)\n<? endif ?>\n<? if exists("accnt_number") ?>\n   AND (accnt_number=<? value("accnt_number") ?>)\n<? endif ?>\n<? if exists("subaccnt_id") ?>\n   AND (subaccnt_id=<? value("subaccnt_id") ?>)\n<? endif ?>\n<? if exists("subType") ?>\n   AND (subaccnttype_id=<? value("subType") ?>)\n<? endif ?>\n<? if exists("accntType") ?>\n   AND (accnt_type= <? value("accntType") ?>)\n<? endif ?>\n<? if exists("accnt_id") ?>\n   AND (sltrans_accnt_id=<? value("accnt_id") ?>)\n<? endif ?>\n<? if exists("docnum") ?>\n   AND (sltrans_docnumber = case when <? value("docnum") ?> = '' then \n sltrans_docnumber else \n<? value("docnum") ?> end ) \n<? endif ?>\n<? if exists("source") ?>\n   AND (sltrans_source=<? value("source") ?>)\n<? endif ?>\n<? if exists("source_pattern") ?>\n   AND (sltrans_source ~* <? value("source_pattern") ?>)\n<? endif ?>\n<? if exists("posted") ?>\n   AND (sltrans_posted=<? value("posted") ?>)\n<? endif ?>\n<? if exists("journalnumber") ?>\n   AND (sltrans_gltrans_journalnumber::text=<? value("journalnumber") ?>)\n<? endif ?>\n) \nORDER BY sltrans_created,\n   sltrans_sequence, sltrans_amount;\n	admin	2015-10-01	0
60	manufacture	jobcosting	 used by dspJobCosting\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: manufacture\n-- Name: jobcosting\n-- Notes: used by dspJobCosting\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *, 0 AS cost_xttotalrole,\n       'qty' AS qty_xtnumericrole,\n       'cost' AS cost_xtnumericrole\nFROM (\n  SELECT womatl_id AS id, 3 AS sort,\n         <? value("material") ?> AS type, item_number AS code,\n         item_descrip1 AS descrip,\n         (SUM(COALESCE(invhist_invqty,0))) AS qty,\n         uom_name AS uom,\n         SUM(COALESCE(invhist_invqty * invhist_unitcost,0)) AS cost,\n         NULL as wooper_seqnumber\n  FROM womatl\n    LEFT OUTER JOIN womatlpost ON (womatl_id=womatlpost_womatl_id)\n    LEFT OUTER JOIN invhist ON (womatlpost_invhist_id=invhist_id),\n    itemsite, item, uom\n  WHERE ((womatl_wo_id=<? value("wo_id") ?>)\n     AND (womatl_itemsite_id=itemsite_id)\n     AND (itemsite_item_id=item_id)\n     AND (item_inv_uom_id=uom_id))\n  GROUP BY womatl_id, item_number, item_descrip1, uom_name\n  ) AS data\nORDER BY sort, code;\n	admin	2015-10-01	0
451	metasqls	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: metasqls\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists('byPackage') ?>\nSELECT metasql_id, metasql_group, metasql_name,\n       firstline(metasql_notes) AS metasql_notes, metasql_grade,\n       CASE nspname WHEN 'public' THEN '' ELSE nspname END AS pkgname,\n       CASE nspname WHEN 'public' THEN 0\n                                  ELSE 1 END AS xtindentrole,\n       metasql_notes AS metasql_notes_qttooltiprole \n  FROM metasql\n  JOIN pg_class     ON (metasql.tableoid=pg_class.oid)\n  JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n UNION \nSELECT -1, pkghead_name, NULL,\n       firstline(pkghead_descrip), NULL,\n       pkghead_name, 0, pkghead_descrip\n  FROM metasql, pg_class, pg_namespace\n       RIGHT OUTER JOIN pkghead ON (nspname=pkghead_name)\n WHERE ((metasql.tableoid=pg_class.oid)\n    AND (relnamespace=pg_namespace.oid))\nORDER BY pkgname, xtindentrole, metasql_group, metasql_name,\n         metasql_grade DESC, metasql_id;\n<? else ?>\nSELECT metasql_id, metasql_group, metasql_name,\n       firstline(metasql_notes) AS metasql_notes,\n       metasql_grade,\n       CASE nspname WHEN 'public' THEN '' ELSE nspname END AS pkgname,\n       metasql_notes AS metasql_notes_qttooltiprole \n  FROM metasql\n  JOIN pg_class     ON (metasql.tableoid=pg_class.oid)\n  JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\nORDER BY metasql_group, metasql_name,\n         metasql_grade DESC, metasql_id;\n <? endif ?>\n	admin	2015-10-01	0
262	mrpDetail	detail	 used by dspMRPDetail\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: mrpDetail\n-- Name: detail\n-- Notes: used by dspMRPDetail\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT qtyNetable(itemsite_id) AS qoh, formatQty(qtyNetable(itemsite_id)) AS f_qoh,\n       qtyAllocated(itemsite_id, findPeriodStart(<? value("cursorId") ?>),\n                       findPeriodEnd(<? value("cursorId") ?>)) AS allocations<? value("counter") ?>,\n       qtyOrdered(itemsite_id, findPeriodStart(<? value("cursorId") ?>),\n                       findPeriodEnd(<? value("cursorId") ?>)) AS orders<? value("counter") ?>,\n       qtyFirmedAllocated(itemsite_id, findPeriodStart(<? value("cursorId") ?>),\n                       findPeriodEnd(<? value("cursorId") ?>)) AS firmedallocations<? value("counter") ?>,\n       qtyFirmed(itemsite_id, findPeriodStart(<? value("cursorId") ?>),\n                       findPeriodEnd(<? value("cursorId") ?>)) AS firmedorders<? value("counter") ?>\nFROM itemsite\nWHERE (itemsite_id=<? value("itemsite_id") ?>);\n	admin	2015-10-01	0
263	mrpDetail	item	 used by dspMRPDetail\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: mrpDetail\n-- Name: item\n-- Notes: used by dspMRPDetail\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsite_id, item_type, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS descrip,\n       warehous_code\nFROM itemsite, item, whsinfo\nWHERE ( (itemsite_active)\n    AND (itemsite_item_id=item_id)\n    AND (itemsite_warehous_id=warehous_id)\n    AND (itemsite_planning_type='M')\n<? if exists("plancode_id") ?>\n    AND (itemsite_plancode_id=<? value("plancode_id") ?>)\n<? elseif exists("plancode_pattern") ?>\n    AND (itemsite_plancode_id IN (SELECT plancode_id \n                                  FROM plancode \n                                  WHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n<? endif ?>\n<? if exists("warehous_id") ?>\n    AND (warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n      )\nORDER BY item_number, warehous_code;\n	admin	2015-10-01	0
440	openVouchers	populate	 used by openVouchers\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: openVouchers\n-- Name: populate\n-- Notes: used by openVouchers\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT vohead_id, COALESCE(pohead_id, -1), vohead_number,\n       COALESCE(TEXT(pohead_number), TEXT(<? value("misc") ?>)) AS ponumber,\n       (vend_number || '-' || vend_name) AS vendor, vendtype_code, vohead_invcnumber,\n       vohead_distdate, COALESCE(vohead_gldistdate, vohead_distdate) AS postdate,\n       vohead_amount, 'curr' AS vohead_amount_xtnumericrole,\n       formatDate(vohead_distdate) AS f_distdate,\n       formatDate(COALESCE(vohead_gldistdate, vohead_distdate)) AS f_postdate,\n       formatMoney(vohead_amount) AS f_amount\n  FROM vendinfo JOIN vendtype ON (vendtype_id=vend_vendtype_id)\n                JOIN vohead ON (vohead_vend_id=vend_id)\n                LEFT OUTER JOIN pohead ON (vohead_pohead_id=pohead_id) \n WHERE (NOT vohead_posted)\n<? if exists("vend_id") ?>\n AND (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n AND (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n AND (vendtype_code ~ <? value("vendtype_pattern") ?>)\n<? endif ?>\n ORDER BY vohead_number;\n \n	admin	2015-10-01	0
264	openpurchaseorders	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: openpurchaseorders\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT\n       pohead_id AS id, COALESCE(pohead_cohead_id, -1) AS altid,\n       pohead.*,\n       calcPurchaseOrderDueDate(pohead_id) AS min_duedate,\n       calcPurchaseOrderAmt(pohead_id) AS order_total,\n       vend_name, vend_number, vendtype_code,\n<? foreach("char_id_text_list") ?>\n       charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n       charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n       charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,\n<? endforeach ?>\n       CASE WHEN(pohead_status='C') THEN <? value("closed") ?>\n            WHEN(pohead_status='U') THEN <? value("unposted") ?>\n            WHEN(pohead_status='O') THEN <? value("open") ?>\n            ELSE pohead_status\n       END AS pohead_status_qtdisplayrole,\n       'currency' AS order_total_xtnumericrole\nFROM pohead \n     JOIN vendinfo ON (pohead_vend_id=vend_id)\n     JOIN vendtype ON (vend_vendtype_id=vendtype_id)\n<? if exists("pohead_agent_usr_id") ?>\n     JOIN usr ON (pohead_agent_username=usr_username)\n<? endif ?> \n<? if exists("warehous_id") ?>\n     JOIN poitem ON (poitem_pohead_id=pohead_id) \n     JOIN itemsite ON (poitem_itemsite_id=itemsite_id)\n<? endif ?> \n<? foreach("char_id_text_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> \n          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='PO') \n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=pohead_id)\n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> \n          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> \n          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='PO') \n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=pohead_id)\n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> \n          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> \n          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='PO') \n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=pohead_id)\n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> \n          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE ( true\n<? if exists("search_pattern") ?> \n  AND ((pohead_number::text ~* <? value("search_pattern") ?>) \n    OR (vend_number ~* <? value("search_pattern") ?>)\n    OR (vend_name ~* <? value("search_pattern") ?>)\n    OR (pohead_agent_username ~* <? value("search_pattern") ?>)\n    OR (vendtype_code ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_vend_cntct_first_name,'') || ' ' || COALESCE(pohead_vend_cntct_last_name,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_vend_cntct_phone,'') ||' ' || COALESCE(pohead_vend_cntct_fax,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_vend_cntct_email,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_vendaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_vendcity,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_vendstate,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_vendzipcode,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_vendcountry,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_shipto_cntct_first_name,'') || ' ' || COALESCE(pohead_shipto_cntct_last_name,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_shipto_cntct_phone,'') || ' ' || COALESCE(pohead_shipto_cntct_fax,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_shipto_cntct_email,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_shiptoaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_shiptocity,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_shiptostate,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_shiptozipcode,'') ~* <? value("search_pattern") ?>)\n    OR (COALESCE(pohead_shiptocountry,'') ~* <? value("search_pattern") ?>)\n    )\n<? endif ?> \n<? if exists("showUnreleased") ?> \n  AND (pohead_status ='U') \n<? endif ?> \n<? if exists("showOpen") ?>\n  AND (pohead_status='O' )\n<? endif ?> \n<? if exists("showBoth") ?> \n  AND (pohead_status IN ('U', 'O') ) \n<? endif ?> \n<? if exists("shownothing") ?> \n  AND (pohead_status NOT IN ('U', 'O', 'C')) \n<? endif ?> \n<? if exists("vend_id") ?>\n  AND (vend_id=<? value("vend_id") ?>)\n<? endif ?> \n<? if exists("vendtype_id") ?>\n  AND (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? endif ?> \n<? if exists("vendtype_pattern") ?>\n  AND (vendtype_code ~* <? value("vendtype_pattern") ?>)\n<? endif ?> \n<? if exists("pohead_agent_usr_id") ?>\n  AND (usr_id  = <? value("pohead_agent_usr_id") ?>)\n<? endif ?> \n<? if exists("warehous_id") ?>\n  AND (itemsite_warehous_id = <? value("warehous_id") ?>)\n<? endif ?> \n<? literal("charClause") ?>\n ) \nORDER BY pohead_number;\n	admin	2015-10-01	0
265	opensalesorders	detail	 \n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: opensalesorders\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT\n       cohead.*,\n       COALESCE(cust_number, :error) AS cust_number,\n       COALESCE(saletype_descr, :error) AS saletype_descr,\n       getSoSchedDate(cohead_id) AS scheddate, \n       getSoStatus(cohead_id) AS status,\n<? foreach("char_id_text_list") ?>\n       charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n       charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n       charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,\n<? endforeach ?>\n       firstline(cohead_ordercomments) AS notes,\n       calcSalesOrderAmt(cohead_id) AS ordertotal,\n       CASE WHEN (calcSalesOrderAmt(cohead_id,'S') != 0.0)\n              THEN calcSalesOrderAmt(cohead_id,'M')\n            ELSE 0.0\n       END AS ordermargin,\n       CASE WHEN (calcSalesOrderAmt(cohead_id,'S') != 0.0)\n              THEN (calcSalesOrderAmt(cohead_id,'M') / calcSalesOrderAmt(cohead_id,'S'))\n            ELSE 1.0\n       END AS ordermarginpercent,\n       'percent' AS ordermarginpercent_xtnumericrole,\n       'extprice' AS ordertotal_xtnumericrole,\n       'extprice' AS ordermargin_xtnumericrole\nFROM cohead \n     JOIN custinfo ON (cohead_cust_id=cust_id) \n     JOIN custtype ON (cust_custtype_id=custtype_id)\n     LEFT OUTER JOIN saletype ON (cohead_saletype_id=saletype_id)\n<? if exists("selectedSites") ?> \n     JOIN coitem ON (coitem_cohead_id=cohead_id) \n     JOIN itemsite ON (coitem_itemsite_id=itemsite_id) \n     JOIN site() ON (itemsite_warehous_id=warehous_id) \n<? elseif  exists("warehous_id") ?> \n     LEFT OUTER JOIN coitem ON (coitem_cohead_id=cohead_id) \n     LEFT OUTER JOIN itemsite ON (coitem_itemsite_id=itemsite_id) \n     LEFT OUTER JOIN whsinfo ON (itemsite_warehous_id=warehous_id) \n<? endif ?> \n<? foreach("char_id_text_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> \n          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> \n          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> \n          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> \n          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> \n          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO') \n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)\n         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> \n          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE((true) \n<? if exists("cust_id") ?>\n  AND (cust_id=<? value("cust_id") ?> )\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND (cust_custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND (custtype_code ~* <? value("custtype_pattern") ?>)\n<? endif ?>\n<? if exists("poNumber") ?>\n  AND  (cohead_custponumber~*<? value("poNumber") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND (cohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if not exists("showClosed") ?> \n  AND (cohead_status='O')\n<? endif ?>\n<? if  exists("warehous_id") ?>\n  AND (warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if  exists("salesrep_id") ?>\n  AND (cohead_salesrep_id=<? value("salesrep_id") ?>)\n<? endif ?>\n<? if  exists("saletype_id") ?>\n  AND (cohead_saletype_id=<? value("saletype_id") ?>)\n<? endif ?>\n<? literal("charClause") ?>\n  ) \nORDER BY cohead_number;\n	admin	2015-10-01	0
63	opportunities	detail	 used by opportunityList\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: opportunities\n-- Name: detail\n-- Notes: used by opportunityList\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT ON (incdtpriority_order, ophead_target_date, ophead_name, ophead_id) \n       ophead_id AS id,\n       CASE WHEN (ophead_active) THEN 0 ELSE 1 END AS altId,\n       ophead_number,\n       ophead_name,\n       ophead_active,\n       crmacct_number,\n       ophead_owner_username,\n       ophead_username,\n       opstage_name,\n       incdtpriority_name,\n       opsource_name,\n       optype_name,\n       (ophead_probability_prcnt * .01) AS ophead_probability_prcnt,\n       ophead_amount,\n       (COALESCE(ophead_amount,0) * COALESCE(ophead_probability_prcnt * 0.01)) AS value,\t\n       currConcat(ophead_curr_id) As f_currency,\n       ophead_target_date,\n       ophead_actual_date,\n       formatMoney(ophead_amount) AS f_amount,\n       formatMoney(COALESCE(ophead_amount,0) * COALESCE(ophead_probability_prcnt * 0.01)) AS f_value,\t\n       formatDate(ophead_target_date) AS f_targetdate,\n       formatDate(ophead_actual_date) AS f_actualdate,\n       'extprice' AS ophead_amount_xtnumericrole,\n       'extprice' AS value_xtnumericrole,\n       0 AS ophead_amount_xttotalrole,\n       0 AS value_xttotalrole,\n       'percent' AS ophead_probability_prcnt_xtnumericrole\n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\nFROM ophead()\n  LEFT OUTER JOIN incdtpriority ON (ophead_priority_id=incdtpriority_id)\n  LEFT OUTER JOIN crmacct ON (ophead_crmacct_id=crmacct_id)\n  LEFT OUTER JOIN opstage ON (ophead_opstage_id=opstage_id)\n  LEFT OUTER JOIN opsource ON (ophead_opsource_id=opsource_id)\n  LEFT OUTER JOIN optype ON (ophead_optype_id=optype_id)\n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='OPP') \n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=ophead_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='OPP') \n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=ophead_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='OPP') \n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=ophead_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE((true)\n<? if exists("startDate") ?>\n   AND ((ophead_target_date >= <? value("startDate") ?>)\n    OR (<? value("startDate") ?> <= startOfTime()) AND (ophead_target_date IS NULL))\n<? endif ?>\n<? if exists("endDate") ?>\n   AND ((ophead_target_date <= <? value("endDate") ?>)\n    OR (<? value("endDate") ?> >= endOfTime()) AND (ophead_target_date IS NULL))\n<? endif ?>\n<? if exists("opsource_id") ?>\n   AND (ophead_opsource_id=<? value("opsource_id") ?>)\n<? endif ?>\n<? if exists("opsource_pattern") ?>\n   AND (opsource_name ~ <? value("opsource_pattern") ?>)\n<? endif ?>\n<? if exists("opstage_id") ?>\n   AND (ophead_opstage_id=<? value("opstage_id") ?>)\n<? endif ?>\n<? if exists("opstage_pattern") ?>\n   AND (opstage_name ~ <? value("opstage_pattern") ?>)\n<? endif ?>\n<? if exists("optype_id") ?>\n   AND (ophead_optype_id=<? value("optype_id") ?>)\n<? endif ?>\n<? if exists("optype_pattern") ?>\n   AND (optype_name ~ <? value("optype_pattern") ?>)\n<? endif ?>\n<? if exists("username") ?>\n   AND (<? value("username") ?> IN (ophead_username, ophead_owner_username))\n<? endif ?>\n<? if exists("assigned_username") ?>\n   AND (ophead_username=<? value("assigned_username") ?>)\n<? endif ?>\n<? if exists("assigned_usr_pattern") ?>\n   AND (ophead_username ~ <? value("assigned_usr_pattern") ?>)\n<? endif ?>\n<? if exists("owner_username") ?>\n   AND (ophead_owner_username=<? value("owner_username") ?>)\n<? endif ?>\n<? if exists("owner_usr_pattern") ?>\n   AND (ophead_owner_username ~ <? value("owner_usr_pattern") ?>)\n<? endif ?>\n<? if exists("crmacct_id") ?>\n   AND (ophead_crmacct_id = <? value("crmacct_id") ?>)\n<? endif ?>\n<? if exists("search_pattern") ?> \n   AND (ophead_name ~* <? value("search_pattern") ?>)\n<? endif ?>\n<? if exists("activeOnly") ?> \n   AND (ophead_active)\n<? endif ?>\n<? if exists("id") ?>\n   AND (ophead_id=<? value("id") ?>\n<? endif ?>\n<? literal("charClause") ?>\n )\nORDER BY incdtpriority_order, ophead_target_date, ophead_name, ophead_id;\n	admin	2015-10-01	0
62	opportunitiesByCRM	detail	 used by crmaccount\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: opportunitiesByCRM\n-- Name: detail\n-- Notes: used by crmaccount\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT ophead_id, *,\n       currConcat(ophead_curr_id) AS ophead_currabbr,\n       'currval' AS ophead_amount_xtnumericrole\n  FROM ophead\n       LEFT OUTER JOIN crmacct ON (ophead_crmacct_id=crmacct_id)\n       LEFT OUTER JOIN opstage ON (ophead_opstage_id=opstage_id)\n       LEFT OUTER JOIN opsource ON (ophead_opsource_id=opsource_id)\n       LEFT OUTER JOIN optype ON (ophead_optype_id=optype_id)\n WHERE((crmacct_id=<? value("crmacct_id") ?>)\n<? if exists("username") ?>\n   AND (ophead_owner_username=<? value("username") ?>)\n<? elseif exists("usr_pattern") ?>\n   AND (ophead_owner_username ~ <? value("username_pattern") ?>)\n<? endif ?>\n )\n ORDER BY ophead_target_date;\n	admin	2015-10-01	0
266	orderActivityByProject	detail	 All projects\n	-- Group: orderActivityByProject\n-- Name:  detail\n-- Notes: All projects\n\nSELECT *, \n  formatQty(qty) AS f_qty,\n  formatMoney(value) AS f_value,\n  'curr' AS qty_xtnumericrole,\n  'curr' AS value_xtnumericrole,\n  CASE WHEN COALESCE(hrs_balance,0) < 0 THEN 'red' END AS hrs_balance_qtforegroundrole,\n  CASE WHEN COALESCE(exp_balance,0) < 0 THEN 'red' END AS exp_balance_qtforegroundrole\nFROM (\nSELECT prj_id AS id,\n       1 AS type,\n       '0' AS subtype,\n       0 AS section,\n       NULL  AS section_qtdisplayrole,\n       prj_number AS name,\n       CASE                         \n           WHEN prj_status = 'C' THEN <? value('complete') ?>\n           WHEN prj_status = 'O' THEN <? value('inprocess') ?>\n           WHEN prj_status = 'P' THEN <? value('planning') ?>\n       END AS status,\n       prjtype_code AS project_type,\n       prj_name AS item,\n       firstline(prj_descrip) AS descrip,\n       crmacct_name AS customer, \n       cntct_name AS contact,\n       addr_city AS city,\n       addr_state AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       prj_due_date AS due,\n       prj_assigned_date AS assigned,\n       prj_start_date AS started,\n       prj_completed_date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n       CASE WHEN (prj_status = 'O' AND prj_due_date < current_date) THEN 'red' \n         WHEN (prj_status = 'O' AND prj_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange' \n         END AS due_qtforegroundrole,\n       0 AS xtindentrole\n  FROM prj\n  LEFT OUTER JOIN prjtype ON (prj_prjtype_id=prjtype_id)\n  LEFT OUTER JOIN crmacct ON (prj_crmacct_id=crmacct_id)\n  LEFT OUTER JOIN cntct ON (crmacct_cntct_id_1=cntct_id)\n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)\n\n WHERE (prj_id = <? value("prj_id") ?> )\n \nUNION ALL\n----- TASKS -----\nSELECT DISTINCT -1 AS id, \n       3 AS type,\n       '0' AS subtype,\n       1 AS section,\n       'Tasks' AS section_qtdisplayrole,\n       'Tasks' AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n       NULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n\nUNION ALL\n\nSELECT prjtask_id AS id,\n       5 AS type,\n       '0' AS subtype,\n       1 AS section,\n       NULL AS section_qtdisplayrole,\n       prjtask_number AS name,\n       CASE                         \n           WHEN prjtask_status = 'C' THEN <? value('complete') ?>\n           WHEN prjtask_status = 'O' THEN <? value('inprocess') ?>\n           WHEN prjtask_status = 'P' THEN <? value('planning') ?>\n       END AS status,\n       NULL::text AS project_type,\n       prjtask_name AS item,\n       prjtask_descrip AS descrip,\n       cust_name as customer,\n       cntct_name AS contact,\n       addr_city AS city,\n       addr_state AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       prjtask_due_date AS due,\n       prjtask_assigned_date AS assigned,\n       prjtask_start_date AS started,\n       prjtask_completed_date AS completed,\n       prjtask_hours_budget AS hrs_budget,\n       prjtask_hours_actual AS hrs_actual,\n       (prjtask_hours_budget-prjtask_hours_actual) AS hrs_balance,\n       prjtask_exp_budget AS exp_budget,\n       prjtask_exp_actual AS exp_actual,\n       (prjtask_exp_budget-prjtask_exp_actual) AS exp_balance,\n       CASE WHEN (prjtask_status = 'O' AND prjtask_due_date < current_date) THEN 'red' \n         WHEN (prjtask_status = 'O' AND prjtask_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange' \n         END AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM prjtask\n  LEFT OUTER JOIN te.teprjtask ON (prjtask_id = teprjtask_prjtask_id)\n  LEFT OUTER JOIN custinfo ON (teprjtask_cust_id=cust_id)\n  LEFT OUTER JOIN cntct ON (cust_corrcntct_id=cntct_id)\n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)\n\n WHERE (prjtask_prj_id = <? value("prj_id") ?> )\n GROUP BY prjtask_prj_id, custinfo.cust_name, prjtask.prjtask_id, addr.addr_city, addr.addr_state, cntct_name, prjtask.prjtask_number, prjtask.prjtask_status, prjtask_username, prjtask.prjtask_owner_username, prjtask_name, prjtask_descrip, prjtask_due_date, prjtask_assigned_date, prjtask_start_date, prjtask_completed_date, prjtask_hours_budget, prjtask_hours_actual, prjtask_exp_budget, prjtask_exp_actual\n\n<? if exists("showIn") ?>\nUNION ALL\n----- INCIDENTS -----\n\nSELECT DISTINCT -1 AS id, \n       100 AS type,\n       '0' AS subtype,\n       1 AS section,\n       'Incidents' AS section_qtdisplayrole,\n       'Incidents' AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n       NULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n    FROM incdt\nUNION ALL\n\nSELECT incdt_id AS id,\n       105 AS type,\n       '0' AS subtype,\n       1 AS section,\n       NULL AS section_qtdisplayrole,\n       incdt_number::text AS name,\n       CASE                         \n           WHEN incdt_status = 'L' THEN <? value('closed') ?>\n           WHEN incdt_status = 'N' THEN <? value('new') ?>\n           WHEN incdt_status = 'F' THEN <? value('feedback') ?>\n           WHEN incdt_status = 'A' THEN <? value('assigned') ?>\t\n           WHEN incdt_status = 'R' THEN <? value('resolved') ?>\n           WHEN incdt_status = 'C' THEN <? value('confirmed') ?>\n       END AS status,\n       NULL::text AS project_type,\n       incdt_number::text AS item,\n       incdt_summary AS descrip,\n       crmacct_number AS customer,\n       crmacct_name AS contact,\n       addr_city AS city,\n       addr_state AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n       NULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM incdt\n  LEFT OUTER JOIN crmacct ON (incdt_crmacct_id=crmacct_id)\n  LEFT OUTER JOIN cntct ON (incdt_cntct_id=cntct_id)\n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)\n\n WHERE (incdt_prj_id = <? value("prj_id") ?> )\n GROUP BY incdt_id, incdt_prj_id, incdt_number, crmacct_number, crmacct_name, addr.addr_city, addr.addr_state, cntct_name, incdt_number, incdt_status, incdt_assigned_username, incdt_owner_username, incdt_number, incdt_summary \n<? endif ?>\n   \n<? if exists("showSo") ?>\nUNION ALL\n\n----- QUOTES -----\nSELECT DISTINCT -1 AS id, \n       10 AS type,\n       '0' AS subtype,\n       2 AS section,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       <? value("quotes") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value, \n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n       NULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM quhead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=quhead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (quhead_prj_id = <? value("prj_id") ?>)\n<? if exists("owner_username") ?>\n   AND (quhead_owner_username=<? value("owner_username") ?>)\n<? endif ?>\n\nUNION ALL\n\nSELECT quhead_id AS id, \n       15 AS type,\n       quhead_number AS subtype,\n       2 AS section,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       quhead_number AS name,\n       CASE WHEN (quhead_status = 'C') THEN \n         <? value("converted") ?>\n            WHEN (quhead_status = 'X') THEN\n         <? value("canceled") ?>\n            WHEN (COALESCE(quhead_expire, current_date + 1) > current_date) THEN\n         <? value("open") ?>\n            ELSE\n         <? value("expired") ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       cust_name AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       NULL AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n       NULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM quhead\n  JOIN custinfo ON (quhead_cust_id=cust_id)\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=quhead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN quitem ON (quitem_quhead_id = quhead_id)\n WHERE (quhead_prj_id = <? value("prj_id") ?>)\n<? if exists("owner_username") ?>\n   AND (quhead_owner_username=<? value("owner_username") ?>)\n<? endif ?>\nGROUP BY quhead_id, quhead_number, quhead_status, quhead_expire, quhead_freight, quhead_misc, custinfo.cust_name\n\nUNION ALL\n\nSELECT quitem_id AS id, \n       17 AS type,\n       quhead_number AS subtype,\n       2 AS section,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       quitem_linenumber::text AS name, \n       CASE WHEN (quhead_status = 'C') THEN \n         <? value("converted") ?>\n            WHEN (quhead_status = 'X') THEN\n         <? value("canceled") ?>\n            WHEN (COALESCE(quhead_expire, current_date + 1) > current_date) THEN\n         <? value("open") ?>\n            ELSE\n         <? value("Expired") ?>\n       END AS status,\n       NULL::text AS project_type,\n       item_number AS item,\n       item_descrip1 || ' ' || item_descrip2 AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       quitem_qtyord,\n       uom_name AS uom,\n       (quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n       NULL::text AS due_qtforegroundrole,\n       3 AS xtindentrole\n  FROM quhead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=quhead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN quitem ON (quitem_quhead_id = quhead_id)\n    JOIN uom ON (quitem_qty_uom_id = uom_id)\n    JOIN itemsite ON (quitem_itemsite_id = itemsite_id)\n    JOIN item ON (itemsite_item_id = item_id)\n WHERE (quhead_prj_id = <? value("prj_id") ?>)\n<? if exists("owner_username") ?>\n   AND (quhead_owner_username=<? value("owner_username") ?>)\n<? endif ?>\n\nUNION ALL\n\nSELECT quhead_id AS id, \n       18 AS type,\n       quhead_number AS subtype,\n       2 AS section,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       <? value("total") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM quhead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=quhead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN quitem ON (quitem_quhead_id = quhead_id)\n WHERE (quhead_prj_id = <? value("prj_id") ?>)\n<? if exists("owner_username") ?>\n   AND (quhead_owner_username=<? value("owner_username") ?>)\n<? endif ?>\nGROUP BY quhead_id, quhead_number\n\nUNION ALL\n\nSELECT -1 AS id, \n       19 AS type,\n       MAX(quhead_number) AS subtype,\n       2 AS section,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("quotes") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM quhead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=quhead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN quitem ON (quitem_quhead_id = quhead_id)\n WHERE (quhead_prj_id = <? value("prj_id") ?>)\n<? if exists("owner_username") ?>\n   AND (quhead_owner_username=<? value("owner_username") ?>)\n<? endif ?>\n\nUNION ALL\n\n------ SALES ORDERS ------\nSELECT DISTINCT -1 AS id, \n       20 AS type,\n       '0' AS subtype,\n       3 AS section,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       <? value("sos") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM cohead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=cohead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (cohead_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT cohead_id AS id, \n       25 AS type,\n       cohead_number::text AS subtype,\n       3 AS section,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       cohead_number::text AS name,\n       COALESCE((SELECT CASE coitem_status WHEN 'O' THEN <? value("open") ?>\n                                           WHEN 'C' THEN <? value("closed") ?>\n                                           ELSE <? value("canceled") ?>\n                        END\n                   FROM coitem\n                  WHERE (coitem_cohead_id=cohead_id)\n                 ORDER BY CASE coitem_status WHEN 'O' THEN 1\n                                             WHEN 'C' THEN 2\n                                             ELSE  3\n                          END\n                 LIMIT 1),'O')\n        AS status,\n       NULL::text AS project_type,\n       shipto_num AS item,\n       shipto_name AS descrip,\n       cust_name AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       NULL AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM cohead\n    JOIN custinfo ON (cust_id = cohead_cust_id)\n    LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=cohead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN coitem ON (coitem_cohead_id = cohead_id)\n WHERE (cohead_prj_id = <? value("prj_id") ?>)\nGROUP BY cohead_id, cohead_number, shipto_num, shipto_name, cust_name\n\nUNION ALL\n\nSELECT coitem_id AS id, \n       27 AS type,\n       cohead_number::text AS subtype,\n       3 AS section,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       coitem_linenumber::text AS name, \n       CASE WHEN (coitem_status = 'O') THEN\n         <? value("open") ?>\n            WHEN (coitem_status = 'C') THEN\n         <? value("closed") ?>\n            WHEN (coitem_status = 'X') THEN\n         <? value("canceled") ?>\n       END AS status,\n       NULL::text AS project_type,\n       item_number AS item,\n       item_descrip1 || ' ' || item_descrip2 AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       coitem_qtyord,\n       uom_name AS uom,\n       (coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       3 AS xtindentrole\n  FROM cohead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=cohead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN coitem ON (coitem_cohead_id = cohead_id)\n    JOIN uom ON (coitem_qty_uom_id = uom_id)\n    JOIN itemsite ON (coitem_itemsite_id = itemsite_id)\n    JOIN item ON (itemsite_item_id = item_id)\n WHERE (cohead_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT cohead_id AS id, \n       28 AS type,\n       cohead_number::text AS subtype,\n       3 AS section,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM cohead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=cohead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN coitem ON (coitem_cohead_id = cohead_id)\n WHERE (cohead_prj_id = <? value("prj_id") ?>)\nGROUP BY cohead_id, cohead_number\n\nUNION ALL\n\nSELECT -1 AS id, \n       29 AS type,\n       MAX(cohead_number::text) AS subtype,\n       3 AS section,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("sos") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \t\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM cohead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=cohead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN coitem ON (coitem_cohead_id = cohead_id)\n WHERE (cohead_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\n------ INVOICES -------\nSELECT DISTINCT -1 AS id, \n       30 AS type,\n       '0' AS subtype,\n       4 AS section,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       <? value("invoices") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM invchead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=invchead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (invchead_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT invchead_id AS id,\n       35 AS type,\n       invchead_invcnumber::text AS subtype,\n       4 AS section,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       invchead_invcnumber::text AS name,\n       CASE WHEN (invchead_posted) THEN\n         <? value("posted") ?>\n       ELSE <? value("unposted") ?>\n       END AS status,\n       NULL::text AS project_type,\n       shipto_num AS item,\n       shipto_name AS descrip,\n       cust_name AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       NULL AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM invchead\n    JOIN custinfo ON (cust_id=invchead_cust_id)\n    LEFT OUTER JOIN shiptoinfo ON (invchead_shipto_id = shipto_id)\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=invchead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN invcitem ON (invcitem_invchead_id = invchead_id)\n WHERE (invchead_prj_id = <? value("prj_id") ?>)\nGROUP BY invchead_id, invchead_invcnumber, shipto_num, shipto_name, invchead_freight, invchead_misc_amount, invchead_posted, cust_name\n\nUNION ALL\n\nSELECT invcitem_id AS id, \n       37 AS type,\n       invchead_invcnumber::text AS subtype,\n       4 AS section,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       invcitem_linenumber::text AS name, \n       CASE WHEN (invchead_posted) THEN\n         <? value("posted") ?>\n       ELSE <? value("unposted") ?>\n       END AS status,\n       NULL::text AS project_type,\n       COALESCE(item_number,invcitem_number) AS item,\n       COALESCE(item_descrip1 || ' ' || item_descrip2,invcitem_descrip) AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       invcitem_billed AS qty,\n       uom_name AS uom,\n       (invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       3 AS xtindentrole\n  FROM invchead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=invchead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN invcitem ON (invcitem_invchead_id = invchead_id)\n    LEFT OUTER JOIN item ON (invcitem_item_id = item_id)\n    LEFT OUTER JOIN uom ON (invcitem_qty_uom_id = uom_id)\n WHERE (invchead_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT invchead_id AS id, \n       38 AS type,\n       invchead_invcnumber::text AS subtype,\n       4 AS section,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       <? value("total") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n       \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM invchead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=invchead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN invcitem ON (invcitem_invchead_id = invchead_id)\n WHERE (invchead_prj_id = <? value("prj_id") ?>)\nGROUP BY invchead_id, invchead_invcnumber\n\nUNION ALL\n\nSELECT -1 AS id, \n       39 AS type,\n       MAX(invchead_invcnumber::text) AS subtype,\n       4 AS section,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("invoices") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM invchead\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=invchead_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN invcitem ON (invcitem_invchead_id = invchead_id)\n WHERE (invchead_prj_id = <? value("prj_id") ?>)\n\n<? endif ?>\n\n\n<? if exists("showWo") ?>\nUNION ALL\n\n------ WORK ORDERS -------\nSELECT DISTINCT -1 AS id, \n       40 AS type,\n       '0' AS subtype,\n       5 AS section,\n       <? value("wos") ?> AS section_qtdisplayrole,\n       <? value("wos") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM wo\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=wo_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (wo_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT wo_id AS id, \n       45 AS type,\n       formatWoNumber(wo_id) AS subtype,\n       5 AS section,\n       <? value("wos") ?> AS section_qtdisplayrole,\n       formatWoNumber(wo_id) AS name,\n       CASE WHEN (wo_status = 'O') THEN\n         <? value("open") ?>\n            WHEN (wo_status = 'E') THEN\n         <? value("exploded") ?>\n            WHEN (wo_status = 'R') THEN\n         <? value("released") ?>\n            WHEN (wo_status = 'I') THEN\n         <? value("inprocess") ?>\n            WHEN (wo_status = 'C') THEN\n         <? value("closed") ?>\n       END AS status,\n       NULL::text AS project_type,\n       item_number AS item,\n       item_descrip1 || ' ' || item_descrip2 AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       wo_qtyord AS qty,\n       uom_name AS uom,\n       wo_postedvalue AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n       \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM wo\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=wo_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN itemsite ON (itemsite_id=wo_itemsite_id)\n    JOIN item ON (itemsite_item_id=item_id)\n    JOIN uom ON (item_inv_uom_id=uom_id)\n WHERE (wo_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT -1 AS id, \n       49 AS type,\n       MAX(formatWoNumber(wo_id)) AS subtype,\n       5 AS section,\n       <? value("wos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("wos") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM(wo_postedvalue) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM wo\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=wo_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (wo_prj_id = <? value("prj_id") ?>)\n\n<? endif ?>\n\n\n<? if exists("showPo") ?>\n UNION ALL\n\n------ PURCHASE REQUESTS ------\nSELECT DISTINCT -1 AS id, \n       50 AS type,\n       '0' AS subtype,\n       6 AS section,\n       <? value("prs") ?> AS section_qtdisplayrole,\n       <? value("prs") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM pr\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=pr_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (pr_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT pr_id AS id, \n       55 AS type,\n       pr_number::text || '-' || pr_subnumber::text AS subtype,\n       6 AS section,\n       <? value("prs") ?> AS section_qtdisplayrole,\n       pr_number::text || '-' || pr_subnumber::text AS name,\n       <? value("open") ?> AS status, \n       NULL::text AS project_type,\n       item_number AS item,\n       (item_descrip1 || ' ' || item_descrip2) AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       pr_qtyreq AS qty,\n       uom_name AS uom,\n       stdcost(item_id) * pr_qtyreq AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pr\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=pr_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN itemsite ON (itemsite_id = pr_itemsite_id)\n    JOIN item ON (itemsite_item_id = item_id)\n    JOIN uom ON (item_inv_uom_id = uom_id)\n WHERE (pr_prj_id=<? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT -1 AS id, \n       59 AS type,\n       MAX(pr_number::text || '-' || pr_subnumber::text) AS subtype,\n       6 AS section,\n       <? value("prs") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("prs") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,       \n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM(stdcost(item_id) * pr_qtyreq) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pr\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=pr_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    JOIN itemsite ON (itemsite_id = pr_itemsite_id)\n    JOIN item ON (itemsite_item_id = item_id)\n WHERE (pr_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\n------ PURCHASE ORDERS ------\nSELECT DISTINCT -1 AS id, \n       60 AS type,\n       '0' AS subtype,\n       7 AS section,\n       <? value("pos") ?> AS section_qtdisplayrole,\n       <? value("pos") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM poitem\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=poitem_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (poitem_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT pohead_id AS id,\n       65 AS type,\n       pohead_number::text AS subtype,\n       7 AS section,\n       <? value("pos") ?> AS section_qtdisplayrole,\n       pohead_number::text AS name,\n       CASE WHEN (pohead_status = 'U') THEN\n         <? value("unreleased") ?>\n            WHEN (pohead_status = 'O') THEN\n         <? value("open") ?>\n            WHEN (pohead_status = 'C') THEN\n         <? value("closed") ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL AS uom,\n       NULL AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pohead\n    JOIN poitem ON (poitem_pohead_id = pohead_id)\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=poitem_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (poitem_prj_id = <? value("prj_id") ?>)\nGROUP BY pohead_id, pohead_number, pohead_freight, pohead_status\n\nUNION ALL\n\nSELECT poitem_id AS id, \n       67 AS type,\n       pohead_number::text AS subtype,\n       7 AS section,\n       <? value("pos") ?> AS section_qtdisplayrole,\n       poitem_linenumber::text AS name, \n       CASE WHEN (poitem_status = 'U') THEN\n         <? value("unreleased") ?>\n            WHEN (poitem_status = 'O') THEN\n         <? value("open") ?>\n            WHEN (poitem_status = 'C') THEN\n         <? value("closed") ?>\n       END AS status,\n       NULL::text AS project_type,\n       COALESCE(item_number,poitem_vend_item_number) AS item,\n       COALESCE((item_descrip1 || ' ' || item_descrip2),poitem_vend_item_descrip) AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       poitem_qty_ordered,\n       poitem_vend_uom AS uom,\n       (poitem_qty_ordered * poitem_unitprice) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       3 AS xtindentrole\n  FROM pohead\n    JOIN poitem ON (poitem_pohead_id = pohead_id)\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=poitem_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n    LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)\n    LEFT OUTER JOIN item ON (itemsite_item_id = item_id)\n WHERE (poitem_prj_id = <? value("prj_id") ?>)\n\nUNION ALL\n\nSELECT pohead_id AS id, \n       68 AS type,\n       pohead_number::text AS subtype,\n       7 AS section,\n       <? value("pos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM(poitem_qty_ordered * poitem_unitprice) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pohead\n    JOIN poitem ON (poitem_pohead_id = pohead_id)\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=poitem_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (poitem_prj_id = <? value("prj_id") ?>)\nGROUP BY pohead_id, pohead_number\n\nUNION ALL\n\nSELECT -1 AS id, \n       69 AS type,\n       MAX(pohead_number::text) AS subtype,\n       7 AS section,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("pos") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,       \n       NULL AS qty,\n       NULL::text AS uom,\n       SUM(poitem_qty_ordered * poitem_unitprice) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n        \n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pohead\n    JOIN poitem ON (poitem_pohead_id = pohead_id)\n<? if exists("owner_username") ?>\n    JOIN prj ON (prj_id=poitem_prj_id\n            AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))\n<? endif ?>\n WHERE (poitem_prj_id = <? value("prj_id") ?>)\n\n<? endif ?>\n\n) data\nORDER BY section, subtype, type, id;\n	admin	2015-10-01	0
64	orders	detail	 used by dspOrders\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: orders\n-- Name: detail\n-- Notes: used by dspOrders\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT source_id, type, order_type, order_status, order_number, duedate,\n       totalqty, relievedqty, balanceqty, balanceqty AS runningbalanceqty,\n       'qty' AS totalqty_xtnumericrole,\n       'qty' AS relievedqty_xtnumericrole,\n       'qty' AS balanceqty_xtnumericrole,\n       0 AS runningbalanceqty_xtrunningrole,\n       CASE WHEN (late) THEN 'error' END AS duedate_qtforegroundrole\nFROM\n(\nSELECT poitem_id AS source_id, 1 AS type, TEXT('P/O') AS order_type,\n       pohead_status AS order_status,\n       TEXT(pohead_number) AS order_number,\n       poitem_qty_ordered AS totalqty,\n       poitem_qty_received AS relievedqty,\n       noNeg(poitem_qty_ordered - poitem_qty_received) AS balanceqty,\n       poitem_duedate AS duedate,\n       (poitem_duedate < CURRENT_DATE) AS late\nFROM pohead, poitem, itemsite\nWHERE ((poitem_pohead_id=pohead_id)\n  AND  (poitem_status IN ('O','U'))\n  AND  (poitem_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? if exists("useLeadTime") ?>\n  AND  (poitem_duedate <= (CURRENT_DATE + itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND  (poitem_duedate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND  (poitem_duedate<=<? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND  (poitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\n\nUNION\nSELECT wo_id AS source_id, 2 AS type, TEXT('W/O') AS order_type,\n       wo_status AS order_status,\n       formatWONumber(wo_id) AS order_number,\n       wo_qtyord AS totalqty,\n       wo_qtyrcv AS relievedqty,\n       noNeg(wo_qtyord - wo_qtyrcv) AS balanceqty,\n       wo_duedate AS duedate,\n       (wo_duedate < CURRENT_DATE) AS late \nFROM wo, itemsite\nWHERE ((wo_status<>'C')\n  AND  (wo_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (<? value("itemType") ?> NOT IN ('C', 'Y'))\n<? if exists("useLeadTime") ?>\n  AND  (wo_duedate <= (CURRENT_DATE + itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND  (wo_duedate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND  (wo_duedate<=<? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND  (wo_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\n\n-- Tooling is also supply on Work Orders\nUNION\nSELECT wo_id AS source_id, 2 AS type, TEXT('W/O') AS order_type,\n       wo_status AS order_status,\n       formatWONumber(wo_id) AS order_number,\n       womatl_qtyreq AS totalqty,\n       COALESCE(sum(abs(invhist_invqty)),0) AS relievedqty,\n       noNeg(womatl_qtyreq - COALESCE(sum(abs(invhist_invqty)),0)) AS balanceqty,\n       wo_duedate AS duedate,\n       (wo_duedate < CURRENT_DATE) AS late \nFROM womatl\n  JOIN wo ON (wo_id=womatl_wo_id)\n  JOIN itemsite ON (itemsite_id=womatl_itemsite_id)\n  JOIN item ON (item_id=itemsite_item_id)\n  LEFT OUTER JOIN womatlpost ON (womatl_id=womatlpost_womatl_id)\n  LEFT OUTER JOIN invhist ON ((womatlpost_invhist_id=invhist_id)\n                          AND (invhist_invqty < 0))\nWHERE ((wo_status<>'C')\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (item_type = 'T')\n<? if exists("useLeadTime") ?>\n  AND  (wo_duedate <= (CURRENT_DATE + itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND  (wo_duedate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND  (wo_duedate<=<? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND  (wo_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\nGROUP BY wo_id, wo_status, womatl_qtyreq, wo_duedate\n\n<? if exists("Manufacturing") ?>\nUNION\nSELECT wo_id AS source_id, 2 AS type, TEXT('W/O') AS order_type,\n       wo_status AS order_status,\n       formatWONumber(wo_id) AS order_number,\n       wo_qtyord AS totalqty,\n       wo_qtyrcv AS relievedqty,\n       noNeg(wo_qtyord - wo_qtyrcv) AS balanceqty,\n       wo_duedate AS duedate,\n       (wo_duedate < CURRENT_DATE) AS late\nFROM wo, xtmfg.brddist, itemsite\nWHERE ((brddist_wo_id=wo_id)\n  AND  (wo_status<>'C')\n  AND  (brddist_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (<? value("itemType") ?> IN ('C', 'Y'))\n<? if exists("useLeadTime") ?>\n  AND (wo_duedate <= (CURRENT_DATE + itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND (wo_duedate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND (wo_duedate<=<? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND (wo_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n     )\n<? endif ?>\n\n<? if exists("Standard") ?>\nUNION\nSELECT toitem_id AS source_id, 3 AS type, TEXT('T/O') AS order_type,\n       tohead_status AS order_status,\n       TEXT(tohead_number) AS order_number,\n       toitem_qty_ordered AS totalqty,\n       toitem_qty_received AS relievedqty,\n       noNeg(toitem_qty_ordered - toitem_qty_received) AS balanceqty,\n       toitem_duedate AS duedate,\n       (toitem_duedate < CURRENT_DATE) AS late\nFROM tohead, toitem, itemsite\nWHERE ((toitem_tohead_id=tohead_id)\n  AND  (toitem_status='O')\n  AND  (toitem_item_id=itemsite_item_id)\n  AND  (tohead_dest_warehous_id=itemsite_warehous_id)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? if exists("useLeadTime") ?>\n  AND  (toitem_duedate <= (CURRENT_DATE + itemsite_leadtime))\n<? elseif exists("days") ?>\n  AND  (toitem_duedate <= (CURRENT_DATE + <? value("days") ?>))\n<? elseif exists("date") ?>\n  AND  (toitem_duedate<=<? value("date") ?>)\n<? elseif exists("startDate") ?>\n  AND  (toitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\n<? endif ?>\n\n) AS data\n\nORDER BY duedate;\n	admin	2015-10-01	0
111	package	items	 replace the not-so-old pkgitem table with direct query of catalogs\n        and tables so we never miss anything and do not have to maintain the\n        data\n TODO: is there a better sort order?\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: package\n-- Name:  items\n-- Notes: replace the not-so-old pkgitem table with direct query of catalogs\n--        and tables so we never miss anything and do not have to maintain the\n--        data\n-- TODO: is there a better sort order?\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       CASE WHEN pkgitem_type='C' THEN <? value("script") ?>\n            WHEN pkgitem_type='D' THEN <? value("cmd") ?>\n            WHEN pkgitem_type='F' THEN <? value("function") ?>\n            WHEN pkgitem_type='G' THEN <? value("trigger") ?>\n            WHEN pkgitem_type='I' THEN <? value("image") ?>\n            WHEN pkgitem_type='M' THEN <? value("metasql") ?>\n            WHEN pkgitem_type='P' THEN <? value("priv") ?>\n            WHEN pkgitem_type='R' THEN <? value("report") ?>\n            WHEN pkgitem_type='S' THEN <? value("schema") ?>\n            WHEN pkgitem_type='T' THEN <? value("table") ?>\n            WHEN pkgitem_type='U' THEN <? value("uiform") ?>\n            WHEN pkgitem_type='V' THEN <? value("view") ?>\n            WHEN pkgitem_type='sequence' THEN <? value("sequence") ?>\n            WHEN pkgitem_type='index'    THEN <? value("index") ?>\n       ELSE pkgitem_type END AS pkgitem_type_qtdisplayrole\nFROM (\nSELECT script_id AS pkgitem_id, 'C' AS pkgitem_type,\n       script_id AS pkgitem_item_id,\n       script_name AS pkgitem_name,\n       script_notes AS pkgitem_descrip\n  FROM <? literal("pkgname") ?>.pkgscript \nUNION \nSELECT cmd_id AS pkgitem_id, 'D' AS pkgitem_type,\n       cmd_id AS pkgitem_item_id,\n       cmd_name AS pkgitem_name,\n       cmd_descrip AS pkgitem_descrip \n  FROM <? literal("pkgname") ?>.pkgcmd \nUNION \nSELECT pg_proc.oid AS pkgitem_id, 'F' AS pkgitem_type,\n       pg_proc.oid AS pkgitem_item_id,\n       proname || '(' || oidvectortypes(proargtypes)\n               || ')' AS pkgitem_name,\n       pg_catalog.obj_description(pg_proc.oid, 'pg_proc') AS pkgitem_descrip \n  FROM pg_proc\n       JOIN pg_namespace ON (pronamespace=pg_namespace.oid)\n WHERE (nspname=<? value("pkgname") ?>) \nUNION \nSELECT t.oid AS pkgitem_id, 'G' AS pkgitem_type,\n       t.oid AS pkgitem_item_id,\n       tgname AS pkgitem_name,\n       pg_catalog.obj_description(t.oid, 'pg_trigger') AS pkgitem_descrip \n  FROM pg_trigger t\n       JOIN pg_class ON (tgrelid=pg_class.oid)\n       JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n WHERE ((nspname=<? value("pkgname") ?>) \n<? if not exists("showsystemdetails") ?>\n    AND (tgconstraint = 0)\n   AND  (tgname !~ '^pkg(cmd(arg)?|image|metasql|priv|report|script|uiform)')\n<? endif ?>\n    )\nUNION \nSELECT image_id AS pkgitem_id, 'I' AS pkgitem_type,\n       image_id AS pkgitem_item_id,\n       image_name AS pkgitem_name,\n       image_descrip AS pkgitem_descrip \n  FROM <? literal("pkgname") ?>.pkgimage \nUNION \nSELECT metasql_id AS pkgitem_id, 'M' AS pkgitem_type,\n       metasql_id AS pkgitem_item_id,\n       metasql_group || '-' || metasql_name AS pkgitem_name,\n       metasql_notes AS pkgitem_descrip \n  FROM <? literal("pkgname") ?>.pkgmetasql \nUNION \nSELECT priv_id AS pkgitem_id, 'P' AS pkgitem_type,\n       priv_id AS pkgitem_item_id,\n       priv_module || '.' || priv_name AS pkgitem_name,\n       priv_descrip AS pkgitem_descrip \n  FROM <? literal("pkgname") ?>.pkgpriv \nUNION \nSELECT report_id AS pkgitem_id, 'R' AS pkgitem_type,\n       report_id AS pkgitem_item_id,\n       report_name AS pkgitem_name,\n       report_descrip AS pkgitem_descrip \n  FROM <? literal("pkgname") ?>.pkgreport \nUNION \nSELECT n.oid AS pkgitem_id, 'S' AS pkgitem_type,\n       n.oid AS pkgitem_item_id,\n       nspname AS pkgitem_name,\n       pg_catalog.obj_description(n.oid, 'pg_namespace') AS pkgitem_descrip \n  FROM pg_namespace n\n WHERE (nspname=<? value("pkgname") ?>) \nUNION \nSELECT c.oid AS pkgitem_id, 'T' AS pkgitem_type,\n       c.oid AS pkgitem_item_id,\n       relname AS pkgitem_name,\n       pg_catalog.obj_description(c.oid, 'pg_class') AS pkgitem_descrip \n  FROM pg_class c\n       JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n WHERE ((nspname=<? value("pkgname") ?>)\n   AND  (relkind='r')\n<? if not exists("showsystemdetails") ?>\n   AND  (relname !~ '^pkg(cmd(arg)?|image|metasql|priv|report|script|uiform)$')\n<? endif ?>\n   )\nUNION \nSELECT uiform_id AS pkgitem_id, 'U' AS pkgitem_type,\n       uiform_id AS pkgitem_item_id,\n       uiform_name AS pkgitem_name,\n       uiform_notes AS pkgitem_descrip \n  FROM <? literal("pkgname") ?>.pkguiform \nUNION \nSELECT c.oid AS pkgitem_id, 'V' AS pkgitem_type,\n       c.oid AS pkgitem_item_id,\n       relname AS pkgitem_name,\n       pg_catalog.obj_description(c.oid, 'pg_class') AS pkgitem_descrip \n  FROM pg_class c\n       JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n WHERE ((nspname=<? value("pkgname") ?>)\n   AND  (relkind='v'))\n<? if exists("showsystemdetails") ?>\nUNION\nSELECT c.oid AS pkgitem_id, 'sequence' AS pkgitem_type,\n       c.oid AS pkgitem_item_id,\n       relname AS pkgitem_name,\n       pg_catalog.obj_description(c.oid, 'pg_class') AS pkgitem_descrip \n  FROM pg_class c\n       JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n WHERE ((nspname=<? value("pkgname") ?>)\n   AND  (relkind='S'))\nUNION\nSELECT c.oid AS pkgitem_id, 'index' AS pkgitem_type,\n       c.oid AS pkgitem_item_id,\n       relname AS pkgitem_name,\n       pg_catalog.obj_description(c.oid, 'pg_class') AS pkgitem_descrip \n  FROM pg_class c\n       JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n WHERE ((nspname=<? value("pkgname") ?>)\n   AND  (relkind='i'))\n<? endif ?>\n) AS pkgitem \nORDER BY pkgitem_type_qtdisplayrole, pkgitem_name;\n	admin	2015-10-01	0
69	packingList	shipment	 used by printPackingList\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: packingList\n-- Name: shipment\n-- Notes: used by printPackingList\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT shiphead_order_id, shiphead_order_type, shiphead_shipform_id, cohead_number AS number\nFROM shiphead, cohead\nWHERE ((shiphead_id=<? value("shiphead_id") ?>)\n  AND  (cohead_id=shiphead_order_id)\n  AND  (shiphead_order_type='SO'))\n<? if exists("MultiWhs") ?>\nUNION\nSELECT shiphead_order_id, shiphead_order_type, shiphead_shipform_id, tohead_number AS number\nFROM shiphead, tohead\nWHERE ((shiphead_id=<? value("shiphead_id") ?>)\n  AND  (tohead_id=shiphead_order_id)\n  AND  (shiphead_order_type='TO'))\n<? endif ?>\n;\n	admin	2015-10-01	0
485	packingListBatch	clear	 used by packingListBatch\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: packingListBatch\n-- Name: clear\n-- Notes: used by packingListBatch\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nDELETE FROM pack WHERE pack_id IN\n  (SELECT pack_id\n   FROM pack JOIN cohead ON (cohead_id=pack_head_id)\n             JOIN coitem ON (coitem_cohead_id=cohead_id)\n             JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n   WHERE ( (checkSOSitePrivs(cohead_id))\n     AND   (pack_head_type='SO')\n     AND   (pack_printed) \n<? if exists("warehous_id") ?>\n     AND   (itemsite_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n         )\n  );\n\n<? if exists("MultiWhs") ?>\nDELETE FROM pack WHERE pack_id IN\n  (SELECT pack_id\n   FROM pack JOIN tohead ON (tohead_id=pack_head_id)\n   WHERE ( (pack_head_type='TO')\n     AND   (pack_printed)\n<? if exists("warehous_id") ?>\n     AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n         )\n  );\n<? endif ?>\n	admin	2015-10-01	0
67	packingListBatch	detail	 used by packingListBatch\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: packingListBatch\n-- Name: detail\n-- Notes: used by packingListBatch\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT\n       cohead_id, pack_shiphead_id, \n       cohead_number AS order_number, pack_head_type,\n       cohead_shipvia AS shipvia,\n       formatShipmentNumber(pack_shiphead_id) AS shipment_number, \n       cust_number AS number, cohead_billtoname AS name,\n       CASE WHEN (cohead_holdtype='N') THEN <? value("none") ?>\n            WHEN (cohead_holdtype='C') THEN <? value("credit") ?>\n            WHEN (cohead_holdtype='S') THEN <? value("ship") ?>\n            WHEN (cohead_holdtype='P') THEN <? value("pack") ?>\n            WHEN (cohead_holdtype='R') THEN <? value("return") ?>\n            ELSE <? value("other") ?>\n       END AS f_holdtype,\n       pack_printed\nFROM pack JOIN cohead ON (cohead_id=pack_head_id)\n          JOIN custinfo ON (cust_id=cohead_cust_id)\n          JOIN coitem ON (coitem_cohead_id=cohead_id)\n          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\nWHERE ( (pack_head_type='SO')\n  AND   (checkSOSitePrivs(cohead_id))\n<? if exists("warehous_id") ?>\n  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n      )\n\n<? if exists("MultiWhs") ?>\nUNION ALL \nSELECT tohead_id, pack_shiphead_id, \n       tohead_number AS order_number, pack_head_type,\n       tohead_shipvia AS shipvia,\n       formatShipmentNumber(pack_shiphead_id) AS shipment_number, \n       tohead_destname AS number, tohead_destcntct_name AS name,\n       '' AS f_holdtype,\n       pack_printed\nFROM pack JOIN tohead ON (tohead_id=pack_head_id) \nWHERE ( (pack_head_type='TO') \n<? if exists("warehous_id") ?>\n  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n      )\n<? endif ?>\nORDER BY 3;\n	admin	2015-10-01	0
68	packingListBatch	print	 used by packingListBatch\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: packingListBatch\n-- Name: print\n-- Notes: used by packingListBatch\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT\n       pack_id, pack_head_id, pack_head_type, pack_shiphead_id,\n       COALESCE(shipform_report_name, findCustomerForm(cohead_cust_id, 'P')) AS packform,\n       findCustomerForm(cohead_cust_id, 'L') AS pickform \nFROM pack JOIN cohead ON (cohead_id=pack_head_id)\n          JOIN coitem ON (coitem_cohead_id=cohead_id)\n          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n          LEFT OUTER JOIN shipform ON (shipform_id=cohead_shipform_id)\nWHERE ( (checkSOSitePrivs(cohead_id))\n  AND   (pack_head_type='SO')\n  AND   (NOT pack_printed) \n<? if exists("warehous_id") ?>\n  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n      )\n\n<? if exists("MultiWhs") ?>\nUNION ALL\nSELECT pack_id, pack_head_id, pack_head_type, pack_shiphead_id,\n       COALESCE(shipform_report_name, findTOForm(tohead_id, 'P')) AS packform,\n       findTOForm(tohead_id, 'L') AS pickform \nFROM pack JOIN tohead ON (tohead_id=pack_head_id)\n          LEFT OUTER JOIN shipform ON (shipform_id=tohead_shipform_id)\nWHERE ( (pack_head_type='TO')\n  AND   (NOT pack_printed)\n<? if exists("warehous_id") ?>\n  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n      )\n<? endif ?>\n;\n	admin	2015-10-01	0
65	packingListBatchByShipVia	print	 used by printPackingListBatchByShipVia\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: packingListBatchByShipVia\n-- Name: print\n-- Notes: used by printPackingListBatchByShipVia\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT pack_head_id, pack_head_type, pack_shiphead_id, getSoStatus(cohead_id) AS orderhead_status,\n       COALESCE(shipform_report_name, findCustomerForm(cohead_cust_id, 'P')) AS packform,\n       findCustomerForm(cohead_cust_id, 'L') AS pickform\nFROM pack JOIN cohead ON (cohead_id=pack_head_id)\n          JOIN coitem ON (coitem_cohead_id=cohead_id)\n          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n          LEFT OUTER JOIN shipform ON (shipform_id=cohead_shipform_id)\nWHERE ( (NOT pack_printed)\n  AND   (pack_head_type='SO')\n  AND   (getSoStatus(cohead_id) <> 'C') \n<? if exists("shipvia") ?>\n  AND   (cohead_shipvia=<? value("shipvia") ?>)\n<? endif ?>\n  AND   (checkSOSitePrivs(cohead_id))\n  AND\t(coitem_scheddate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("warehous_id") ?>\n  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n      )\n\n<? if exists("MultiWhs") ?>\nUNION ALL\nSELECT DISTINCT pack_head_id, pack_head_type, pack_shiphead_id, tohead_status AS orderhead_status,\n       COALESCE(shipform_report_name, findTOForm(tohead_id, 'P')) AS packform,\n       findTOForm(tohead_id, 'L') AS pickform\nFROM pack JOIN tohead ON (tohead_id=pack_head_id)\n          JOIN toitem ON (toitem_tohead_id = tohead_id) \n          LEFT OUTER JOIN shipform ON (shipform_id=tohead_shipform_id)\nWHERE ( (NOT pack_printed)\n  AND   (pack_head_type='TO')\n  AND   (tohead_status <> 'C') \n<? if exists("shipvia") ?>\n  AND   (tohead_shipvia=<? value("shipvia") ?>)\n<? endif ?>\n  AND\t(toitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("warehous_id") ?>\n  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n      )\n<? endif ?>\n\n;\n	admin	2015-10-01	0
66	packingListBatchByShipVia	shipVia	 used by printPackingListBatchByShipVia\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: packingListBatchByShipVia\n-- Name: shipVia\n-- Notes: used by printPackingListBatchByShipVia\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n\nSELECT max(id), shipvia\nFROM (\nSELECT max(cohead_id) AS id, cohead_shipvia AS shipvia\nFROM pack JOIN cohead ON (cohead_id=pack_head_id)\n          JOIN coitem ON (coitem_cohead_id=cohead_id AND coitem_status='O')\n          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\nWHERE ( (NOT pack_printed)\n  AND   (pack_head_type='SO')\n<? if exists("warehous_id") ?>\n  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n      )\nGROUP BY cohead_shipvia\n<? if exists("MultiWhs") ?>\nUNION\nSELECT max(tohead_id) AS id, tohead_shipvia AS shipvia\nFROM pack JOIN tohead ON (tohead_id=pack_head_id AND tohead_status='O')\nWHERE ( (NOT pack_printed)\n  AND   (pack_head_type='TO')\n<? if exists("warehous_id") ?>\n  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n      )\nGROUP BY tohead_shipvia\n<? endif ?>\n) data\nGROUP BY shipvia\nORDER BY shipvia\n	admin	2015-10-01	0
267	partiallyShippedOrders	detail	 used by dspPartiallyShippedOrders\n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: partiallyShippedOrders\n-- Name: detail\n-- Notes: used by dspPartiallyShippedOrders\n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT CASE WHEN (cohead_holdtype IN ('P', 'C', 'R')) THEN -1\n         ELSE cohead_id\n       END AS _coheadid, cohead_id,\n       cohead_holdtype, cohead_number, cust_name, saletype_descr,\n       CASE WHEN (cohead_holdtype='N') THEN <? value("none") ?>\n            WHEN (cohead_holdtype='C') THEN <? value("credit") ?>\n            WHEN (cohead_holdtype='S') THEN <? value("ship") ?>\n            WHEN (cohead_holdtype='P') THEN <? value("pack") ?>\n            WHEN (cohead_holdtype='R') THEN <? value("return") ?>\n         ELSE <? value("other") ?>\n       END AS f_holdtype,\n       cohead_orderdate,\n       (MIN(coitem_scheddate)) AS minscheddate,\n       cohead_packdate,\n       SUM( (noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n                  (coitem_price / coitem_price_invuomratio) ) AS extprice,\n       currConcat(cohead_curr_id) AS currAbbr,\n       SUM(currToBase(cohead_curr_id,\n          (noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n          (coitem_price / coitem_price_invuomratio),\n          CURRENT_DATE)) AS extprice_base,\n       'curr' AS extprice_xtnumericrole,\n       'curr' AS extprice_base_xtnumericrole,\n       <? if exists("singlecurrency") ?>\n         0 AS extprice_xttotalrole \n       <? else ?>\n         0 AS extprice_base_xttotalrole \n       <? endif ?>\nFROM cohead\n  LEFT OUTER JOIN saletype ON (saletype_id=cohead_saletype_id)\n  JOIN custinfo ON (cust_id=cohead_cust_id)\n  JOIN coitem ON (coitem_cohead_id=cohead_id)\n  JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n  JOIN item ON (item_id=itemsite_item_id)\nWHERE ( (coitem_status='O')\n    AND (cohead_id IN ( SELECT DISTINCT coitem_cohead_id\n                        FROM coitem\n                        WHERE (coitem_qtyshipped > 0) ))\n    AND (coitem_qtyshipped < coitem_qtyord)\n    AND (coitem_scheddate BETWEEN <? value("startDate") ?>\n                              AND <? value("endDate") ?>)\n    <? if exists("warehous_id") ?>\n      AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n    <? endif ?>\n      ) \nGROUP BY cohead_id, saletype_descr, cohead_number, cust_name, \n         cohead_holdtype, cohead_orderdate, cohead_packdate,\n         cohead_curr_id \nORDER BY minscheddate, cohead_number;\n	admin	2015-10-01	0
268	pendingAvailability	detail	 used by dspPendingAvailability\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: pendingAvailability\n-- Name: detail\n-- Notes: used by dspPendingAvailability\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("showIndented") ?>\n\n-- Indented BOM\nSELECT itemsite_id, reorderlevel,\n       bomdata_bomwork_level,\n       bomdata_bomwork_id,\n       bomdata_bomwork_parent_id,\n       bomdata_bomwork_seqnumber AS bomitem_seqnumber,\n       bomdata_item_number AS item_number,\n       bomdata_itemdescription AS item_descrip,\n       bomdata_uom_name AS uom_name,\n       pendalloc,\n       ordered,\n       qoh,\n       (totalalloc + pendalloc) AS totalalloc,\n       (qoh + ordered - (totalalloc + pendalloc)) AS totalavail,\n       'qty' AS pendalloc_xtnumericrole,\n       'qty' AS ordered_xtnumericrole,\n       'qty' AS qoh_xtnumericrole,\n       'qty' AS totalalloc_xtnumericrole,\n       'qty' AS totalavail_xtnumericrole,\n       CASE WHEN (qoh < pendalloc) THEN 'error' END AS qoh_qtforegroundrole,\n       CASE WHEN ((qoh + ordered - (totalalloc + pendalloc)) < reorderlevel)  THEN 'error'\n            WHEN ((qoh + ordered - (totalalloc + pendalloc)) = reorderlevel) THEN 'warning'\n       END AS totalavail_qtforegroundrole,\n       bomdata_bomwork_level - 1 AS xtindentrole\n  FROM ( SELECT itemsite_id,\n                CASE WHEN(itemsite_useparams)\n                     THEN itemsite_reorderlevel\n                     ELSE 0.0\n                     END AS reorderlevel,\n                ib.*,\n                ((bomdata_qtyreq::NUMERIC * <? value("buildQty") ?>) * (1 + bomdata_scrap::NUMERIC)) AS pendalloc,\n                qtyAllocated(itemsite_id, DATE(<? value("buildDate") ?>)) AS totalalloc,\n                noNeg(qtyAvailable(itemsite_id)) AS qoh,\n                qtyOrdered(itemsite_id, DATE(<? value("buildDate") ?>)) AS ordered\n           FROM indentedBOM(<? value("item_id") ?>,\n                            getActiveRevId('BOM', <? value("item_id") ?>),\n                            0,0) ib LEFT OUTER JOIN\n                itemsite ON ((itemsite_item_id=bomdata_item_id)\n                         AND (itemsite_warehous_id=<? value("warehous_id") ?>))\n          WHERE (bomdata_item_id > 0)\n       <? if not exists("effective") ?>\n           AND (CURRENT_DATE BETWEEN bomdata_effective AND (bomdata_expires-1))\n       <? else ?>\n           AND (<? value("effective") ?> BETWEEN bomdata_effective AND (bomdata_expires-1))\n       <? endif ?>\n       ) AS data\n<? if exists("showShortages") ?>\n  WHERE ((qoh + ordered - (totalalloc + pendalloc)) < 0)\n<? endif ?>   \nORDER BY bomworkSequence(bomdata_bomwork_id);\n\n<? else ?>\n\n-- Single Level BOM\nSELECT itemsite_id, bomitem_seqnumber, item_number, item_descrip, uom_name,\n       pendalloc, (totalalloc + pendalloc) AS totalalloc,\n       qoh, (qoh + ordered - (totalalloc + pendalloc)) AS totalavail,\n       reorderlevel,\n       'qty' AS pendalloc_xtnumericrole,\n       'qty' AS totalalloc_xtnumericrole,\n       'qty' AS qoh_xtnumericrole,\n       'qty' AS totalavail_xtnumericrole,\n       CASE WHEN (qoh < pendalloc) THEN 'error' END AS qoh_qtforegroundrole,\n       CASE WHEN ((qoh + ordered - (totalalloc + pendalloc)) < reorderlevel) THEN 'error'\n            WHEN ((qoh + ordered - (totalalloc + pendalloc)) = reorderlevel) THEN 'warning'\n       END AS totalavail_qtforegroundrole\nFROM ( SELECT itemsite_id, bomitem_seqnumber, item_number,\n              (item_descrip1 || ' ' || item_descrip2) AS item_descrip, uom_name,\n              ((itemuomtouom(bomitem_item_id, bomitem_uom_id, NULL,\n                            (bomitem_qtyfxd + bomitem_qtyper * <? value("buildQty") ?>) * (1 + bomitem_scrap)))) AS pendalloc,\n              qtyAllocated(itemsite_id, DATE(<? value("buildDate") ?>)) AS totalalloc,\n              noNeg(qtyAvailable(itemsite_id)) AS qoh,\n              qtyOrdered(itemsite_id, DATE(<? value("buildDate") ?>)) AS ordered,\n              CASE WHEN(itemsite_useparams) THEN itemsite_reorderlevel ELSE 0.0 END AS reorderlevel\n       FROM itemsite, item, bomitem(<? value("item_id") ?>), uom\n       WHERE ( (bomitem_item_id=itemsite_item_id)\n           AND (itemsite_item_id=item_id)\n           AND (item_inv_uom_id=uom_id)\n           AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n       <? if not exists("effective") ?>\n           AND (CURRENT_DATE BETWEEN bomitem_effective AND (bomitem_expires-1))\n       <? else ?>\n           AND (<? value("effective") ?> BETWEEN bomitem_effective AND (bomitem_expires-1))\n       <? endif ?>\n             )\n     ) AS data\n<? if exists("showShortages") ?>\n  WHERE ((qoh + ordered - (totalalloc + pendalloc)) < 0)\n<? endif ?>   \nORDER BY bomitem_seqnumber;\n\n<? endif ?>   \n	admin	2015-10-01	0
269	pendingBOMChanges	detail	 used by dspPendingBOMChanges\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: pendingBOMChanges\n-- Name: detail\n-- Notes: used by dspPendingBOMChanges\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT bomitem_id, actiondate, action,\n       bomitem_seqnumber, item_number, description,\n       uom_name, qtyfxd, qtyper,\n       bomitem_scrap, actiondate,\n       'qty' AS qtyfxd_xtnumericrole,\n       'qtyper' AS qtyper_xtnumericrole,\n       'percent' AS bomitem_scrap_xtnumericrole \nFROM (SELECT bomitem_id, <? value("effective") ?> AS action,\n             bomitem_seqnumber, item_number, (item_descrip1 || ' ' || item_descrip2) AS description,\n             uom_name,\n             (itemuomtouomratio(bomitem_item_id, bomitem_uom_id, NULL) * bomitem_qtyfxd) AS qtyfxd,\n             (itemuomtouomratio(bomitem_item_id, bomitem_uom_id, NULL) * bomitem_qtyper) AS qtyper,\n             bomitem_scrap, bomitem_effective AS actiondate \n      FROM bomitem(<? value("item_id") ?>,<? value("revision_id") ?>), item, uom \n      WHERE ((bomitem_item_id=item_id)\n         AND (item_inv_uom_id=uom_id)\n         AND (bomitem_effective BETWEEN CURRENT_DATE AND <? value("cutOffDate") ?>)) \n      UNION \n      SELECT bomitem_id, <? value("expires") ?> AS action, \n             bomitem_seqnumber, item_number, (item_descrip1 || ' ' || item_descrip2) AS description,\n             uom_name,\n             (itemuomtouomratio(bomitem_item_id, bomitem_uom_id, NULL) * bomitem_qtyfxd) AS qtyfxd,\n             (itemuomtouomratio(bomitem_item_id, bomitem_uom_id, NULL) * bomitem_qtyper) AS qtyper,\n             bomitem_scrap, bomitem_expires AS actiondate \n      FROM bomitem(<? value("item_id") ?>,<? value("revision_id") ?>), item, uom \n      WHERE ((bomitem_item_id=item_id)\n         AND (item_inv_uom_id=uom_id)\n       <? if exists("cutOffDate") ?>\n         AND (bomitem_expires BETWEEN CURRENT_DATE AND <? value("cutOffDate") ?>) )\n       <? endif ?> \n     ) AS data \nORDER BY action, actiondate, bomitem_seqnumber;\n	admin	2015-10-01	0
488	permissions	privileges	 User Permissions (individual and role permissions)\n Notes: used by dspUserPrivileges\n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: permissions\n-- Name:  privileges\n-- Notes: User Permissions (individual and role permissions)\n-- Notes: used by dspUserPrivileges\n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n-- Role Privileges\nSELECT usr_id, grp_id AS altid, usrgrp_username as priv_username, grp_name, priv_module, priv_name, priv_descrip  \nFROM usrgrp\nJOIN usr ON (usrgrp_username=usr_username)\nJOIN grp ON (grp_id=usrgrp_grp_id)\nJOIN grppriv ON (grp_id=grppriv_grp_id)\nJOIN priv ON (priv_id=grppriv_priv_id)\nWHERE ((usr_active=true)\n<? if exists("username") ?>\n AND (usrgrp_username=<? value("username") ?>)\n<? endif ?>\n<? if exists("role") ?>\n AND (grp_id=<? value("role") ?>)\n<? endif ?>\n<? if exists("privilege") ?>\n AND (priv_name ~* <? value("privilege") ?>)\n<? endif ?>\n)\n\nUNION \n\n-- Individual Privileges\nSELECT  usr_id, -1 AS altid, usrpriv_username, 'User Privilege' AS grp_name, priv_module, priv_name, priv_descrip \nFROM usrpriv \nJOIN usr ON (usrpriv_username=usr_username)\nJOIN priv ON (priv_id=usrpriv_priv_id)\nWHERE ((usr_active=true)\n<? if exists("username") ?>\n AND (usrpriv_username=<? value("username") ?>)\n<? endif ?>\n<? if exists("privilege") ?>\n AND (priv_name ~* <? value("privilege") ?>)\n<? endif ?>\n<? if exists("role") ?>\n AND (false)\n<? endif ?>\n)\n\nORDER BY priv_username, priv_module, priv_name, grp_name;\n	admin	2015-10-01	0
489	permissions	role	 used by dspUserPrivileges\n        User Permissions (Role permissions)\n        Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: permissions\n-- Name:  role\n-- Notes: used by dspUserPrivileges\n--        User Permissions (Role permissions)\n--        Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT usrgrp_username as role_username,grp_name, grp_descrip  \nFROM usrgrp\nJOIN usr ON (usr_username=usrgrp_username)\nJOIN grp ON grp_id=usrgrp_grp_id\nWHERE (usr_active=true)\n<? if exists("username")?>\n  AND usrgrp_username=<? value("username")?>\n<? endif ?>\n<? if exists("role") ?>\n AND (grp_id=<? value("role") ?>)\n<? endif ?>\nORDER BY usrgrp_username,grp_name	admin	2015-10-01	0
270	poDeliveryDateVariances	detail	 used by dspPoDeliveryDateVariancesByItem, dspPoDeliveryDateVariancesByVendor\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: poDeliveryDateVariances\n-- Name: detail\n-- Notes: used by dspPoDeliveryDateVariancesByItem, dspPoDeliveryDateVariancesByVendor\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT <? if exists("byItem") ?>\n         recv.*, vend_name,\n         firstLine(recv_vend_item_number) AS itemnumber,\n         firstLine(recv_vend_item_descrip) AS itemdescrip,\n         DATE(recv_rlsd_duedate) - DATE(COALESCE(pohead_released, pohead_orderdate)) AS req_leadtime,\n         DATE(recv_duedate) - DATE(COALESCE(pohead_released, pohead_orderdate)) AS agrd_leadtime,\n         DATE(recv_date) - DATE(COALESCE(pohead_released, pohead_orderdate)) AS real_leadtime,\n         DATE(recv_date) - DATE(recv_rlsd_duedate) AS req_diff,\n\t DATE(recv_date) - DATE(recv_duedate) AS argd_diff,\n         DATE(recv_date) AS receivedate,\n         formatDate(COALESCE(pohead_released, pohead_orderdate)) AS orderdate,\n         formatDate(recv_date) AS f_recv_date,\n         recv_rlsd_duedate AS release_duedate,  \n\t recv_duedate AS argd_duedate,\n         CASE WHEN (DATE(recv_date) - DATE(recv_rlsd_duedate) > 0) THEN 'error'\n              END AS req_diff_qtforegroundrole,\n         CASE WHEN (DATE(recv_date) - DATE(recv_duedate) > 0) THEN 'error'\n              END AS argd_diff_qtforegroundrole, \n\t CASE WHEN (DATE(recv_date) > DATE(recv_duedate)) THEN 'error'\t\t\t   \n              END AS receivedate_qtforegroundrole,\t\t\t  \n         'qty' AS recv_qty_xtnumericrole\n       <? elseif exists("byVendor") ?>\n         recv_id, recv_order_number, vend_name,\n         DATE(recv_date) AS receivedate,\n         formatDate(COALESCE(pohead_released, pohead_orderdate)) AS orderdate,\n         firstLine(recv_vend_item_number) AS venditemnumber,\n         firstLine(recv_vend_item_descrip) AS venditemdescrip,\n         recv_qty, recv_duedate, recv_date,\n         formatDate(recv_date) AS f_recv_date,\n         DATE(recv_rlsd_duedate) - DATE(COALESCE(pohead_released, pohead_orderdate)) AS req_leadtime,\n         DATE(recv_duedate) - DATE(COALESCE(pohead_released, pohead_orderdate)) AS agrd_leadtime,\n   DATE(recv_date) - DATE(COALESCE(pohead_released, pohead_orderdate)) AS real_leadtime,\n   DATE(recv_date) - DATE(recv_rlsd_duedate) AS req_diff,\n         DATE(recv_date) - DATE(recv_duedate) AS argd_diff,\n         firstLine(item.item_number) AS  itemnumber,\n         recv_rlsd_duedate AS release_duedate,\n   recv_duedate AS argd_duedate,\n   CASE WHEN (DATE(recv_date) - DATE(recv_rlsd_duedate) > 0) THEN 'error'\n              END AS req_diff_qtforegroundrole,\n   CASE WHEN (DATE(recv_date) - DATE(recv_duedate) > 0) THEN 'error'\n              END AS argd_diff_qtforegroundrole,\n   CASE WHEN (DATE(recv_date) > DATE(recv_duedate)) THEN 'error'\n              END AS receivedate_qtforegroundrole,\n         'qty' AS recv_qty_xtnumericrole\n       <? endif ?>\n\nFROM recv LEFT OUTER JOIN vendinfo ON (vend_id=recv_vend_id)\n          LEFT OUTER JOIN pohead ON (pohead_number=recv_order_number AND recv_order_type='PO')\n          LEFT OUTER JOIN (itemsite JOIN item ON (item_id=itemsite_item_id)) ON (itemsite_id=recv_itemsite_id)\nWHERE ( TRUE\n<? if exists("item_id") ?>\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND  (DATE(recv_date) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n  AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("agentUsername") ?>\n  AND (recv_agent_username=<? value("agentUsername") ?>)\n<? endif ?>\n<? if exists("vend_id") ?>\n  AND (vend_id=<? value("vend_id") ?>)\n<? endif ?>\n<? if exists("selectedPurchasingAgent") ?>\n  AND (recv_agent_username=<? value("username") ?>)\n<? endif ?>\n      )\nORDER BY\n  recv_date DESC;\n	admin	2015-10-01	0
271	poHistory	detail	 used by dspPoHistory\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: poHistory\n-- Name: detail\n-- Notes: used by dspPoHistory\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT poitem_id, poitem.*,\n       COALESCE(item_number, <? value("nonInventory") ?>) AS itemnumber,\n       COALESCE(uom_name, <? value("na") ?>) AS uomname,\n       CASE WHEN (LENGTH(TRIM(BOTH '    ' FROM poitem_vend_item_descrip)) <= 0)\n            THEN(item_descrip1 || ' ' || item_descrip2)\n         ELSE poitem_vend_item_descrip\n       END AS itemdescription,\n       'qty' AS poitem_qty_ordered_xtnumericrole,\n       'qty' AS poitem_qty_received_xtnumericrole,\n       'qty' AS poitem_qty_returned_xtnumericrole\nFROM poitem LEFT OUTER JOIN\n     ( itemsite JOIN item\n       ON (itemsite_item_id=item_id) JOIN uom ON (item_inv_uom_id=uom_id))\n       ON (poitem_itemsite_id=itemsite_id)\nWHERE (poitem_pohead_id=<? value("pohead_id") ?>)\nORDER BY poitem_linenumber;\n	admin	2015-10-01	0
272	poItems	detail	 used by dspPoItemsByVendor, dspPoItemsByItem, dspPoItemsByDate\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: poItems\n-- Name: detail\n-- Notes: used by dspPoItemsByVendor, dspPoItemsByItem, dspPoItemsByDate\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT pohead_id, poitem_id, pohead_number, poitem_status,\n       CASE WHEN(poitem_status='C') THEN <? value("closed") ?>\n            WHEN(poitem_status='U') THEN <? value("unposted") ?>\n            WHEN(poitem_status='O' AND ((poitem_qty_received-poitem_qty_returned) > 0) \n                                   AND (poitem_qty_ordered>(poitem_qty_received-poitem_qty_returned))) \n            THEN <? value("partial") ?>\n            WHEN(poitem_status='O' AND ((poitem_qty_received-poitem_qty_returned) > 0) \n                                   AND (poitem_qty_ordered<=(poitem_qty_received-poitem_qty_returned))) \n            THEN <? value("received") ?>\n            WHEN(poitem_status='O') THEN <? value("open") ?>\n         ELSE poitem_status\n       END AS f_poitem_status,\n       vend_name,\n       (SELECT warehous_code\n          FROM whsinfo\n         WHERE (COALESCE(itemsite_warehous_id, pohead_warehous_id)=warehous_id)) AS warehous_code,\n       COALESCE(item_number, <? value("nonInv") ?>) AS itemnumber,\n       poitem_vend_item_number, poitem_vend_uom,\n       COALESCE(item_descrip1, firstLine(poitem_vend_item_descrip)) AS itemdescrip,\n       COALESCE(uom_name, poitem_vend_uom) AS itemuom,\n       poitem_duedate, poitem_qty_ordered, poitem_qty_received, poitem_qty_returned,\n       CASE WHEN (poitem_duedate < CURRENT_DATE) THEN 'error' END AS poitem_duedate_qtforegroundrole,\n       'qty' AS poitem_qty_ordered_xtnumericrole,\n       'qty' AS poitem_qty_received_xtnumericrole,\n       'qty' AS poitem_qty_returned_xtnumericrole \n  FROM pohead\n  JOIN poitem   ON (pohead_id=poitem_pohead_id)\n  JOIN vendinfo ON (pohead_vend_id=vend_id)\n  LEFT OUTER JOIN (itemsite\n                   JOIN item ON (itemsite_item_id=item_id)\n                   JOIN uom ON (item_inv_uom_id=uom_id))\n         ON (poitem_itemsite_id=itemsite_id)\nWHERE (TRUE\n<? if exists("byDate") ?>\n   AND (poitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n  AND (((itemsite_id IS NULL) AND\n        (pohead_warehous_id=<? value("warehous_id") ?>) )\n       OR\n       ((itemsite_id IS NOT NULL) AND\n        (itemsite_warehous_id=<? value("warehous_id") ?>) ) )\n<? endif ?>\n<? if exists("agentUsername") ?>\n   AND (pohead_agent_username=<? value("agentUsername") ?>)\n<? endif ?>\n<? if exists("openItems") ?>\n   AND (poitem_status='O')\n<? endif ?>\n<? if exists("closedItems") ?>\n   AND (poitem_status='C')\n<? endif ?>\n<? if exists("poNumber") ?>\n  AND (pohead_number=<? value("poNumber") ?>)\n<? endif ?>\n<? if exists("vend_id") ?>\n  AND (pohead_vend_id=<? value("vend_id") ?>) \n<? elseif exists("vendtype_id") ?>\n  AND (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n  AND (vend_vendtype_id IN (SELECT vendtype_id\n                              FROM vendtype\n                             WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n<? if exists("item_id") ?>\n  AND (itemsite_item_id=<? value("item_id") ?>) \n<? endif ?>\n      )\nORDER BY poitem_duedate, pohead_number, poitem_linenumber\n;\n	admin	2015-10-01	0
432	poItems	list	 used by purchaseOrder\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: poItems\n-- Name: list\n-- Notes: used by purchaseOrder\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT poitem.*,\n       CASE WHEN(poitem_status='C') THEN <? value("closed") ?>\n            WHEN(poitem_status='U') THEN <? value("unposted") ?>\n            WHEN(poitem_status='O' AND ((poitem_qty_received-poitem_qty_returned) > 0) AND (poitem_qty_ordered>(poitem_qty_received-poitem_qty_returned))) THEN <? value("partial") ?>\n            WHEN(poitem_status='O' AND ((poitem_qty_received-poitem_qty_returned) > 0) AND (poitem_qty_ordered<=(poitem_qty_received-poitem_qty_returned))) THEN <? value("received") ?>\n            WHEN(poitem_status='O') THEN <? value("open") ?>\n            ELSE poitem_status\n       END AS poitemstatus,\n       CASE WHEN (poitem_order_type='S') THEN <? value("so") ?>\n            WHEN (poitem_order_type='W') THEN <? value("wo") ?>\n            ELSE ''\n       END AS demand_type,\n       CASE WHEN (poitem_order_type='S') THEN formatSoNumber(coitem_id)\n            WHEN (poitem_order_type='W') THEN formatWoNumber(womatl_wo_id)\n            ELSE ''\n       END AS order_number,\n       CASE WHEN (itemsite_id IS NULL) THEN poitem_vend_item_number\n            ELSE item_number\n       END AS item_number,\n       CASE WHEN (itemsite_id IS NULL) THEN firstLine(poitem_vend_item_descrip)\n            ELSE (item_descrip1 || ' ' || item_descrip2)\n       END AS item_descrip,\n       contrct_number, \n       poitem_rlsd_duedate AS orgl_duedate,\n       (poitem_unitprice * poitem_qty_ordered) AS extprice,\n       CASE WHEN(poitem_status='C') THEN <? value("closed") ?>\n            WHEN(poitem_status='U') THEN <? value("unposted") ?>\n            WHEN(poitem_status='O' AND ((poitem_qty_received-poitem_qty_returned) > 0) AND (poitem_qty_ordered>(poitem_qty_received-poitem_qty_returned))) THEN <? value("partial") ?>\n            WHEN(poitem_status='O' AND ((poitem_qty_received-poitem_qty_returned) > 0) AND (poitem_qty_ordered<=(poitem_qty_received-poitem_qty_returned))) THEN <? value("received") ?>\n            WHEN(poitem_status='O') THEN <? value("open") ?>\n            ELSE poitem_status\n       END AS poitem_status_qtdisplayrole,\n       'qty' AS poitem_qty_ordered_xtnumericrole,\n       'qty' AS poitem_qty_received_xtnumericrole,\n       'qty' AS poitem_qty_returned_xtnumericrole,\n       'qty' AS poitem_qty_vouchered_xtnumericrole,\n       'purchprice' AS poitem_unitprice_xtnumericrole,\n       'curr' AS extprice_xtnumericrole,\n       'curr' AS poitem_freight_xtnumericrole,\n       'curr' AS poitem_freight_received_xtnumericrole,\n       'curr' AS poitem_freight_vouchered_xtnumericrole,\n       'curr' AS poitem_stdcost_xtnumericrole\nFROM pohead JOIN poitem  ON (poitem_pohead_id=pohead_id)\n            LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)\n            LEFT OUTER JOIN item     ON (itemsite_item_id=item_id)\n            LEFT OUTER JOIN coitem   ON (poitem_order_type='S' AND poitem_order_id = coitem_id)\n            LEFT OUTER JOIN womatl   ON (poitem_order_type='W' AND poitem_order_id = womatl_id)\n            LEFT OUTER JOIN itemsrc  ON (poitem_itemsrc_id=itemsrc_id)\n            LEFT OUTER JOIN contrct  ON (itemsrc_contrct_id=contrct_id)\nWHERE (poitem_pohead_id=<? value("pohead_id") ?>)\nORDER BY poitem_linenumber;\n	admin	2015-10-01	0
130	poPriceVariances	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: poPriceVariances\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *\n<? if exists("includeFormatted") ?>,\n  formatDate(distdate)        AS f_date,\n  formatQty(recv_qty)       AS f_qty,\n  formatCost(recv_recvcost) AS f_recv_recvcost,\n  formatMoney(recv_value)   AS f_recv_value,\n  formatPrice(vouchercost)    AS f_vouchercost,\n  formatMoney(voucher_value)  AS f_voucher_value,\n  formatMoney(variance)       AS f_variance, \n  formatPrcnt(varprcnt/100)       AS f_varprcnt\n<? endif ?>\n FROM (\nSELECT recv_id, recv_order_number, recv_date, recv_order_type,\n  DATE(recv_date) AS receivedate,\n  vohead_distdate AS distdate,\n  vend_number, vend_name,\n  COALESCE(item_number, (<? value("nonInv") ?> || recv_vend_item_number)) AS itemnumber,\n  firstLine(COALESCE(item_descrip1, recv_vend_item_descrip)) AS itemdescrip,\n  recv_qty,\n  recv_purchcost,\n  currConcat(recv_freight_curr_id) AS poCurrAbbr,\n<? if exists("baseCurr") ?>\n  COALESCE((recv_value / CASE WHEN (recv_qty <> 0.0) THEN recv_qty ELSE 1.0 END), 0.0) AS recv_recvcost,\n  COALESCE(recv_value, 0.0) AS recv_value,\n  COALESCE(currToBase(vohead_curr_id, SUM(vodist_amount) / CASE WHEN (SUM(vodist_qty) <> 0.0) THEN SUM(vodist_qty) ELSE 1.0 END, vohead_distdate), 0.0) AS vouchercost,\n  COALESCE(currToBase(vohead_curr_id, SUM(vodist_amount) / CASE WHEN (SUM(vodist_qty) <> 0.0) THEN SUM(vodist_qty) ELSE 1.0 END, vohead_distdate) * recv_qty, 0.0) AS voucher_value,\n  COALESCE(currToBase(vohead_curr_id, SUM(vodist_amount) / CASE WHEN (SUM(vodist_qty) <> 0.0) THEN SUM(vodist_qty) ELSE 1.0 END, vohead_distdate) * recv_qty - recv_value, 0.0) AS variance,\n  CASE WHEN (COALESCE(recv_value, 0.0) <> 0.0) THEN\n    ((currToBase(vohead_curr_id, SUM(vodist_amount) / CASE WHEN (SUM(vodist_qty) <> 0.0) THEN SUM(vodist_qty) ELSE 1.0 END, vohead_distdate) *\n     recv_qty / recv_value) -1.0) * 100.0\n       ELSE 100.0 END AS varprcnt,     \n  currConcat(baseCurrId()) AS currAbbr,\n  '0' AS recv_value_xttotalrole,\n  '0' AS voucher_value_xttotalrole,\n  '0' AS variance_xttotalrole,\n<? else ?> -- local Currency\n  COALESCE(currToLocal(vohead_curr_id, (recv_value / CASE WHEN (recv_qty <> 0.0) THEN recv_qty ELSE 1.0 END), vohead_distdate), 0.0) AS recv_recvcost,\n  COALESCE(currToLocal(vohead_curr_id, recv_value, vohead_distdate), 0.0) AS recv_value,\n  COALESCE(SUM(vodist_amount) / CASE WHEN (SUM(vodist_qty) <> 0.0) THEN SUM(vodist_qty) ELSE 1.0 END, 0.0)  AS vouchercost,\n  COALESCE(SUM(vodist_amount) / CASE WHEN (SUM(vodist_qty) <> 0.0) THEN SUM(vodist_qty) ELSE 1.0 END * recv_qty, 0.0) AS voucher_value,\n  COALESCE(SUM(vodist_amount) / CASE WHEN (SUM(vodist_qty) <> 0.0) THEN SUM(vodist_qty) ELSE 1.0 END * recv_qty - currToLocal(vohead_curr_id, recv_value, vohead_distdate), 0.0) AS variance,\n  CASE WHEN (COALESCE(recv_value, 0.0) <> 0.0) THEN\n    ((SUM(vodist_amount) / CASE WHEN (SUM(vodist_qty) <> 0.0) THEN SUM(vodist_qty) ELSE 1.0 END *\n     recv_qty / currToLocal(vohead_curr_id, recv_value, vohead_distdate)) -1.0) * 100.0\n       ELSE 100.0 END AS varprcnt,       \n  currConcat(vohead_curr_id) AS currAbbr,\n<? endif ?>\n  'qty' AS recv_qty_xtnumericrole,\n  'purchprice' AS recv_purchcost_xtnumericrole,\n  'curr' AS recv_value_xtnumericrole,\n  'purchprice' AS vouchercost_xtnumericrole,\n  'curr' AS  voucher_value_xtnumericrole,\n  'cost' AS recv_recvcost_xtnumericrole,\n  'curr' AS variance_xtnumericrole,\n  'prcnt' AS varprcnt_xtnumericrole\nFROM vendinfo\n  JOIN vendtype ON (vend_vendtype_id=vendtype_id), recv\n  LEFT OUTER JOIN (\n    itemsite JOIN item ON (itemsite_item_id=item_id) )\n    ON (recv_itemsite_id=itemsite_id)\n  JOIN vodist ON ((vodist_poitem_id=recv_orderitem_id)\n              AND (vodist_vohead_id=recv_vohead_id))\n  JOIN vohead ON ((vodist_vohead_id=vohead_id) \n              AND (vohead_posted))\nWHERE ( (recv_vend_id=vend_id)\nAND  (recv_order_type='PO')\n<? if exists("vend_id") ?>\n  AND (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n  AND (vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n  AND (vendtype_code ~ <? value("vendtype_pattern") ?>)\n<? endif ?>\n  AND (DATE(vohead_distdate) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) \n<? if exists("MultiWhs") ?>\n  AND (itemsite_warehous_id=<? value("MultiWhs") ?>)\n<? endif ?>\n<? if exists("item_id") ?>\n  AND (itemsite_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("agentUsername") ?>\n  AND (recv_agent_username=<? value("agentUsername") ?>)\n<? endif ?>\n )\nGROUP BY recv_id, recv_order_number, recv_order_type, recv_date, item_number, recv_vend_item_number,\n         item_descrip1, recv_vend_item_descrip, recv_qty, recv_purchcost, recv_recvcost,\n         vohead_curr_id, recv_freight_curr_id, vohead_docdate, vend_number, vend_name,\n         recv_value, vohead_distdate\n) data\n<? if exists("notZero") ?>\nWHERE (variance != 0)\n<? endif ?>\nORDER BY distdate, recv_order_number DESC;\n	admin	2015-10-01	0
273	poReturns	detail	 used by dspPoReturnsByVendor\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: poReturns\n-- Name: detail\n-- Notes: used by dspPoReturnsByVendor\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT poreject_id, poreject_ponumber, vend_name,\n       poreject_date, poreject_qty,\n       poreject_vend_item_number, poreject_vend_item_descrip,\n       rjctcode_code,\n       'qty' AS poreject_qty_xtnumericrole \nFROM poreject, vendinfo, itemsite, rjctcode\nWHERE ((poreject_posted)\n   AND (poreject_vend_id=vend_id)\n   AND (poreject_rjctcode_id=rjctcode_id)\n   AND (poreject_itemsite_id=itemsite_id)\n   AND (vend_id=<? value("vend_id") ?>)\n   AND (DATE(poreject_date) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("warehous_id") ?>\n   AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("username") ?>\n   AND (poreject_agent_username=<? value("username") ?>)\n<? endif ?>\n      ) \nORDER BY poreject_date DESC;\n	admin	2015-10-01	0
107	summarizedBacklogByWarehouse	counts	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: summarizedBacklogByWarehouse\n-- Name: counts\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT COUNT(coitem.*) AS totalitems \n         FROM cohead, coitem, itemsite, custinfo\n\t\t     WHERE ( (coitem_cohead_id=cohead_id)\n\t\t      AND (coitem_itemsite_id=itemsite_id)\n\t\t      AND (cohead_cust_id=cust_id)\n\t\t      AND (coitem_status NOT IN ('C','X'))\n\t\t      AND (coitem_scheddate BETWEEN <? value("startDate") ?>\n\t\t                                AND <? value("endDate") ?>)\n\t\t     <? if exists("warehous_id") ?>\n\t\t      AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n\t\t     <? endif ?>\n\t\t     <? if exists("custtype_id") ?>\n\t\t      AND (cust_custtype_id=<? value("custtype_id") ?>)\n\t\t     <? elseif exists("custtype_pattern") ?>\n\t\t      AND (cust_custtype_id IN (SELECT custtype_id FROM custtype\n\t\t       WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n\t\t     <? endif ?>\n\t\t     );\n	admin	2015-10-01	0
441	postCountTags	post	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: postCountTags\n-- Name:  post\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT MIN(postCountTag(invcnt_id, <? value('thaw') ?>)) AS result\n  FROM invcnt, itemsite, item\n WHERE ((invcnt_itemsite_id=itemsite_id)\n    AND (invcnt_qoh_after IS NOT NULL)\n    AND (NOT invcnt_posted)\n    AND (itemsite_item_id=item_id)\n<? if exists('warehous_id') ?>\n    AND (itemsite_warehous_id=<? value('warehous_id') ?>)\n<? endif ?>\n\n<? if exists('classcode_id') ?>\n    AND (item_classcode_id=<? value('classcode_id') ?>)\n<? elseif exists('classcode_pattern') ?>\n    AND (item_classcode_id IN (SELECT classcode_id\n                                 FROM classcode\n                                WHERE (classcode_code ~ <? value('classcode_pattern') ?>)))\n<? elseif exists('plancode_id') ?>\n    AND (itemsite_plancode_id=<? value('plancode_id') ?>)\n<? elseif exists('plancode_pattern') ?>\n    AND (itemsite_plancode_id IN (SELECT plancode_id\n                                    FROM plancode\n                                   WHERE (plancode_code ~ <? value('plancode_pattern') ?>)))\n<? endif ?>\n);\n	admin	2015-10-01	0
414	postJournals	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: postJournals\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *\nFROM (\n  SELECT 0 AS id,\n  sltrans_source,\n  0 AS xtindentrole,\n  CASE WHEN sltrans_source = 'A/P' THEN <? value("AP") ?>\n       WHEN sltrans_source = 'A/R' THEN <? value("AR") ?>\n       WHEN sltrans_source = 'G/L' THEN <? value("GL") ?>\n       WHEN sltrans_source = 'I/M' THEN <? value("IM") ?>\n       WHEN sltrans_source = 'P/D' THEN <? value("PD") ?>\n       WHEN sltrans_source = 'S/O' THEN <? value("SO") ?>\n       WHEN sltrans_source = 'S/R' THEN <? value("SR") ?>\n       WHEN sltrans_source = 'W/O' THEN <? value("WO") ?>\n       ELSE <? value("Other" ?>\n  END AS description, \n  NULL AS debit, \n  NULL AS credit, \n  count(sltrans_id) AS journals\n  FROM sltrans\n  WHERE ((NOT sltrans_posted)\n   AND (sltrans_amount > 0)\n   AND (sltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>))\n  GROUP BY sltrans_source\n<? if exists("preview") ?>\nUNION ALL\n  SELECT \n    sltrans_accnt_id AS id,\n    sltrans_source,\n    1 AS xtindentrole,\n    formatGLAccountLong(sltrans_accnt_id) AS description,\n    CASE WHEN SUM(sltrans_amount) < 0 THEN ABS(SUM(sltrans_amount))\n    END AS debit,\n    CASE WHEN SUM(sltrans_amount) > 0 THEN SUM(sltrans_amount)\n    END AS credit,\n    NULL AS journals\n    FROM sltrans\n    WHERE ((NOT sltrans_posted)\n     AND (sltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>))\n  GROUP BY sltrans_accnt_id, sltrans_source\n<? endif ?>\n) data\nORDER BY sltrans_source, xtindentrole\n	admin	2015-10-01	0
413	postJournals	post	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: postJournals\n-- Name:  post\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT * \nFROM postJournals(\nARRAY[\n<? foreach("source_list") ?>\n  <? if not isfirst("source_list") ?>\n,\n  <? endif ?>\n  <? value("source_list") ?>\n<? endforeach ?>\n],  \n<? value("startDate") ?>, \n<? value("endDate") ?>, \n<? value("distDate") ?>) AS result;\n	admin	2015-10-01	0
229	pricelist	detail	 This query displays price lists and the data used to perform\n        price calculations. It avoids price calculations where possible.\n        The UNION sets the sourcecode column to show how the price list entry\n        was derived:  customer vs customer type vs customer type regex ..., etc.\n        Then the outer query modifies the sourcecode to indicate\n        item vs product category.\n        TODO: possible improvements include removing OUTER JOINs with uom table\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: pricelist\n-- Name:  detail\n-- Notes: This query displays price lists and the data used to perform\n--        price calculations. It avoids price calculations where possible.\n--        The UNION sets the sourcecode column to show how the price list entry\n--        was derived:  customer vs customer type vs customer type regex ..., etc.\n--        Then the outer query modifies the sourcecode to indicate\n--        item vs product category.\n--        TODO: possible improvements include removing OUTER JOINs with uom table\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT sourcecode + CASE WHEN source='P' THEN 10 ELSE 0 END AS source,\n       sourceid, schedulename, type,\n       invqty AS qty_break,\n       CASE WHEN (qtybreak = -1) THEN <? value('na') ?>\n       END             AS qty_break_qtdisplayrole,\n       invuom.uom_name AS qty_uom,\n       price,\n       currConcat(curr_id) AS currency,\n       priceuom.uom_name   AS price_uom,\n       currToCurr(curr_id, <? value('curr_id') ?>,\n                  price,   <? value('effective') ?>) AS base_price,\n       discountpercent,\n       discountfixed,\n       CASE WHEN (price_type='N') THEN <? value('nominal') ?>\n            WHEN (price_type='D') THEN <? value('discount') ?>\n            WHEN (price_type='M') THEN <? value('markup') ?>\n       END AS price_type,\n       'qty'        AS qty_break_xtnumericrole,\n       'salesprice' AS price_xtnumericrole,\n       'salesprice' AS base_price_xtnumericrole,\n       'percent'    AS discountpercent_xtnumericrole,\n       'salesprice' AS discountfixed_xtnumericrole\nFROM ( \n\n    SELECT 4 AS sourcecode,\n           ipsitem_id AS sourceid,\n           CASE WHEN (ipsitem_item_id=<? value('item_id') ?>) THEN 'I'\n                WHEN (ipsitem_prodcat_id=<? value('prodcat_id') ?>) THEN 'P'\n                ELSE 'Error'\n           END AS source,\n           ipshead_id,\n           ipshead_name AS schedulename,\n           (<? value('sale') ?> || '-' || sale_name) AS type,\n           CASE WHEN (ipsitem_item_id=<? value('item_id') ?>) THEN itemuomtouom(ipsitem_item_id, ipsitem_qty_uom_id, NULL, ipsitem_qtybreak)\n                ELSE ipsitem_qtybreak\n           END AS invqty,\n           ipsitem_qtybreak AS qtybreak,\n           CASE WHEN (ipsitem_type = 'N') THEN\n                 (ipsitem_price * itemuomtouomratio(<? value('item_id') ?>, NULL, ipsitem_price_uom_id)) * iteminvpricerat(ipsitem_item_id)\n                WHEN (ipsitem_type = 'D') THEN\n                 noNeg(<? value('item_listprice') ?> - (<? value('item_listprice') ?> * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)\n                WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups') AND fetchMetricBool('WholesalePriceCosting')) THEN\n                 (<? value('item_listcost') ?> / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN\n                 (<? value('item_unitcost') ?> / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                WHEN (ipsitem_type = 'M' AND fetchMetricBool('WholesalePriceCosting')) THEN\n                 (<? value('item_listcost') ?> + (<? value('item_listcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                WHEN (ipsitem_type = 'M') THEN\n                 (<? value('item_unitcost') ?> + (<? value('item_unitcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                ELSE 0.00\n           END AS price,\n           ipsitem_qty_uom_id AS qtybreak_uom_id,\n           ipsitem_price_uom_id AS price_uom_id,\n           ipsitem_discntprcnt AS discountpercent,\n           ipsitem_fixedamtdiscount AS discountfixed,\n           ipshead_curr_id AS curr_id,\n           ipsitem_type AS price_type\n    FROM sale JOIN ipshead ON (ipshead_id=sale_ipshead_id)\n              JOIN ipsiteminfo ON (ipsitem_ipshead_id=ipshead_id)\n              JOIN ipsass ON (ipsass_ipshead_id=ipshead_id)\n   WHERE ((ipsitem_item_id=<? value('item_id') ?>) OR (ipsitem_prodcat_id=<? value('prodcat_id') ?>))\n      AND (<? value('asof') ?> BETWEEN sale_startdate AND sale_enddate)\n      AND ( ((COALESCE(ipsass_shipto_id, -1) > 0) AND (ipsass_shipto_id=<? value('shipto_id') ?>))\n       OR   ((COALESCE(LENGTH(ipsass_shipto_pattern), 0) > 0) AND (<? value('shipto_num') ?> ~ ipsass_shipto_pattern))\n       OR   (ipsass_cust_id=<? value('cust_id') ?>)\n       OR   (ipsass_custtype_id=<? value('custtype_id') ?>)\n       OR   ((COALESCE(LENGTH(ipsass_custtype_pattern), 0) > 0) AND (<? value('custtype_code') ?> ~ ipsass_custtype_pattern)) )\n\n    UNION\n\n    SELECT CASE WHEN (COALESCE(ipsass_shipto_id, -1) > 0) THEN 6\n                WHEN (COALESCE(LENGTH(ipsass_shipto_pattern), 0) > 0) THEN 7\n                WHEN (COALESCE(ipsass_cust_id, -1) > 0) THEN 1\n                WHEN (COALESCE(ipsass_custtype_id, -1) > 0) THEN 2\n                WHEN (COALESCE(LENGTH(ipsass_custtype_pattern), 0) > 0) THEN 3\n                ELSE 99\n           END AS sourcecode,\n           ipsitem_id AS sourceid,\n           CASE WHEN (ipsitem_item_id=<? value('item_id') ?>) THEN 'I'\n                WHEN (ipsitem_prodcat_id=<? value('prodcat_id') ?>) THEN 'P'\n                ELSE 'Error'\n           END AS source,\n           ipshead_id,\n           ipshead_name AS schedulename,\n           CASE WHEN (COALESCE(ipsass_shipto_id, -1) > 0) THEN <? value('shipTo') ?>\n                WHEN (COALESCE(LENGTH(ipsass_shipto_pattern), 0) > 0) THEN <? value('shipToPattern') ?>\n                WHEN (COALESCE(ipsass_cust_id, -1) > 0) THEN <? value('customer') ?>\n                WHEN (COALESCE(ipsass_custtype_id, -1) > 0) THEN <? value('custType') ?>\n                WHEN (COALESCE(LENGTH(ipsass_custtype_pattern), 0) > 0) THEN <? value('custTypePattern') ?>\n                ELSE 'Error'\n           END AS type,\n           CASE WHEN (ipsitem_item_id=<? value('item_id') ?>) THEN itemuomtouom(ipsitem_item_id, ipsitem_qty_uom_id, NULL, ipsitem_qtybreak)\n                ELSE ipsitem_qtybreak\n           END AS invqty,\n           ipsitem_qtybreak AS qtybreak,\n           CASE WHEN ipsitem_type = 'N' THEN\n                 (ipsitem_price * itemuomtouomratio(<? value('item_id') ?>, NULL, ipsitem_price_uom_id)) * iteminvpricerat(ipsitem_item_id)\n                WHEN ipsitem_type = 'D' THEN\n                 noNeg(<? value('item_listprice') ?> - (<? value('item_listprice') ?> * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)\n                WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups') AND fetchMetricBool('WholesalePriceCosting')) THEN\n                 (<? value('item_listcost') ?> / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN\n                 (<? value('item_unitcost') ?> / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                WHEN (ipsitem_type = 'M' AND fetchMetricBool('WholesalePriceCosting')) THEN\n                 (<? value('item_listcost') ?> + (<? value('item_listcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                WHEN (ipsitem_type = 'M') THEN\n                 (<? value('item_unitcost') ?> + (<? value('item_unitcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)\n                ELSE 0.00\n           END AS price,\n           ipsitem_qty_uom_id AS qtybreak_uom_id,\n           ipsitem_price_uom_id AS price_uom_id,\n           ipsitem_discntprcnt AS discountpercent,\n           ipsitem_fixedamtdiscount AS discountfixed,\n           ipshead_curr_id AS curr_id,\n           ipsitem_type AS price_type\n    FROM ipsass JOIN ipshead ON (ipshead_id=ipsass_ipshead_id)\n                JOIN ipsiteminfo ON (ipsitem_ipshead_id=ipshead_id)\n    WHERE ((ipsitem_item_id=<? value('item_id') ?>) OR (ipsitem_prodcat_id=<? value('prodcat_id') ?>))\n      AND (<? value('asof') ?> BETWEEN ipshead_effective AND ipshead_expires)\n      AND ( ((COALESCE(ipsass_shipto_id, -1) > 0) AND (ipsass_shipto_id=<? value('shipto_id') ?>))\n       OR   ((COALESCE(LENGTH(ipsass_shipto_pattern), 0) > 0) AND (<? value('shipto_num') ?> ~ ipsass_shipto_pattern))\n       OR   (ipsass_cust_id=<? value('cust_id') ?>)\n       OR   (ipsass_custtype_id=<? value('custtype_id') ?>)\n       OR   ((COALESCE(LENGTH(ipsass_custtype_pattern), 0) > 0) AND (<? value('custtype_code') ?> ~ ipsass_custtype_pattern))\n          )\n\n    UNION\n\n    SELECT 5 AS sourcecode,\n           item_id AS sourceid,\n           NULL AS source,\n           NULL AS ipshead_id,\n           '' AS schedulename,\n           <? value('listPrice') ?> AS type,\n           -1 AS invqty,\n           -1 AS qtybreak,\n           (item_listprice - (item_listprice * cust_discntprcnt)) AS price,\n           item_inv_uom_id   AS qtybreak_uom_id,\n           item_price_uom_id AS price_uom_id,\n           cust_discntprcnt  AS discountpercent,\n           NULL              AS discountfixed,\n           baseCurrId() AS curr_id,\n           NULL AS price_type\n    FROM item, custinfo\n    WHERE (item_sold\n      AND (NOT item_exclusive)\n       AND (item_id=<? value('item_id') ?>)\n       AND (cust_id=<? value('cust_id') ?>) ) ) AS data\n\n  LEFT OUTER JOIN uom AS invuom ON (invuom.uom_id=qtybreak_uom_id)\n  LEFT OUTER JOIN uom AS priceuom ON (priceuom.uom_id=price_uom_id)\n\n ORDER BY price_uom_id, price;\n	admin	2015-10-01	0
276	prices	detail	 used by dspPricesByCustomerType, dspPricesByCustomer, dspPricesByItem\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: prices\n-- Name: detail\n-- Notes: used by dspPricesByCustomerType, dspPricesByCustomer, dspPricesByItem\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemid, sourcetype, schedulename, type,\n<? if not exists("byItem") ?>\n       itemnumber, itemdescrip, priceuom,\n<? else ?>\n       typename,\n<? endif ?>\n       CASE WHEN (qtybreak <> -1) THEN qtybreak END AS f_qtybreak,\n       price,\n       currConcat(curr_id) AS currConcat,\n       'qty' AS f_qtybreak_xtnumericrole,\n       <? value("na") ?> AS f_qtybreak_xtnullrole,\n       'salesprice' AS price_xtnumericrole\n<? if exists("showCosts") ?>\n  <? if exists("byItem") ?>\n       , CASE WHEN (<? value("cost") ?> <> 0) THEN <? value("cost") ?> END AS f_cost,\n       CASE WHEN ((price <> 0) AND (<? value("cost") ?> <> 0)) THEN ((price - <? value("cost") ?>) /  price) END AS f_margin,\n  <? else ?>\n       , CASE WHEN (cost IS NOT NULL) THEN cost END AS f_cost,\n      CASE WHEN ((price <> 0) AND (cost <>0)) THEN ((price - cost) / price) END AS f_margin,\n  <? endif ?>\n       'cost' AS f_cost_xtnumericrole,\n       <? value("costna") ?> AS f_cost_xtnullrole,\n       'percent' AS f_margin_xtnumericrole,\n       <? value("na") ?> AS f_margin_xtnullrole,\n  <? if exists("byItem") ?>\n       CASE WHEN (<? value("cost") ?> > price) THEN 'error' END AS f_margin_qtforegroundrole\n  <? else ?>\n       CASE WHEN (cost > price) THEN 'error' END AS f_margin_qtforegroundrole\n  <? endif ?>\n<? endif ?>\nFROM (\n<? if not exists("byCustomerType") ?>\n      SELECT\n  <? if exists("byCustomer") ?>\n             ipsprice_id AS itemid, 1 AS sourcetype,\n             ipshead_name AS schedulename, <? value("customer") ?> AS type,\n             item_number AS itemnumber, uom_name AS priceuom, iteminvpricerat(item_id) AS invpricerat,\n             (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n             ipsprice_qtybreak AS qtybreak,\n             ipsprice_price AS price, ipshead_curr_id AS curr_id,\n             ipshead_updated AS effective\n    <? if exists("useStandardCosts") ?>\n             , (stdcost(item_id) * iteminvpricerat(item_id)) AS cost\n    <? elseif exists("useActualCosts") ?>\n             , (actcost(item_id) * iteminvpricerat(item_id)) AS cost\n    <? endif ?>\n  <? else ?>\n             ipsprice_id AS itemid, 1 AS sourcetype,\n             ipshead_name AS schedulename, <? value("customer") ?> AS type,\n             cust_name AS typename,\n             ipsprice_qtybreak AS qtybreak, ipsprice_price AS price, ipshead_curr_id AS curr_id\n  <? endif ?>\n      FROM ipsass, ipshead, ipsprice, item,\n  <? if exists("byCustomer") ?>\n           uom\n  <? else ?>\n          custinfo\n  <? endif ?>\n      WHERE ((ipsass_ipshead_id=ipshead_id)\n         AND (ipsprice_ipshead_id=ipshead_id)\n         AND (ipsprice_item_id=item_id)\n  <? if exists("byCustomer") ?>\n         AND (item_price_uom_id=uom_id)\n         AND (ipsass_cust_id=<? value("cust_id") ?>)\n         <? if exists("item_id") ?>\n         AND (item_id=<? value("item_id") ?>)\n         <? endif ?>\n  <? else ?>\n         AND (ipsass_cust_id=cust_id)\n         AND (item_id=<? value("item_id") ?>)\n  <? endif ?>\n         AND (COALESCE(LENGTH(ipsass_shipto_pattern), 0) = 0)\n  <? if not exists("showExpired") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n  <? endif ?>\n  <? if not exists("showFuture") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n  <? endif ?>\n            )\n\n      UNION\n<? endif ?>\n\n      SELECT\n<? if exists("byItem") ?>\n             ipsprice_id AS itemid, 2 AS sourcetype,\n             ipshead_name AS schedulename, <? value("custType") ?> AS type,\n             (custtype_code || '-' || custtype_descrip) AS typename,\n             ipsprice_qtybreak AS qtybreak, ipsprice_price AS price, ipshead_curr_id AS curr_id\n<? else ?>\n             ipsprice_id AS itemid,\n  <? if exists("byCustomerType") ?>\n             1 AS sourcetype,\n  <? elseif exists("byCustomer") ?>\n             2 AS sourcetype,\n  <? endif ?>\n             ipshead_name AS schedulename, <? value("custType") ?> AS type,\n             item_number AS itemnumber, uom_name AS priceuom, iteminvpricerat(item_id) AS invpricerat,\n             (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n             ipsprice_qtybreak AS qtybreak,\n             ipsprice_price AS price, ipshead_curr_id AS curr_id,\n             ipshead_updated AS effective\n  <? if exists("showCosts") ?>\n    <? if exists("useStandardCosts") ?>\n             , (stdcost(\n      <? if exists("byCustomerType") ?>\n                ipsprice_item_id\n      <? elseif exists("byCustomer") ?>\n                item_id\n      <? endif ?>\n                     ) * iteminvpricerat(item_id)) AS cost\n    <? elseif exists("useActualCosts") ?>\n             , (actcost(\n      <? if exists("byCustomerType") ?>\n                ipsprice_item_id\n      <? elseif exists("byCustomer") ?>\n                item_id\n      <? endif ?>\n                     ) * iteminvpricerat(item_id)) AS cost\n    <? endif ?>\n  <? endif ?>\n<? endif ?>\n      FROM ipsass, ipshead, ipsprice, item,\n<? if exists("byItem") ?>\n           custtype\n<? else ?>\n           uom\n<? endif ?>\n<? if exists("byCustomer") ?>\n           , custinfo\n<? endif ?>\n      WHERE ((ipsass_ipshead_id=ipshead_id)\n         AND (ipsprice_ipshead_id=ipshead_id)\n         AND (ipsprice_item_id=item_id)\n<? if not exists("byItem") ?>\n         AND (item_price_uom_id=uom_id)\n<? endif ?>\n<? if exists("byCustomerType") ?>\n         AND (ipsass_custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("byCustomer") ?>\n         AND (ipsass_custtype_id=cust_custtype_id)\n         AND (cust_id=<? value("cust_id") ?>)\n         <? if exists("item_id") ?>\n         AND (item_id=<? value("item_id") ?>)\n         <? endif ?>\n<? else ?>\n         AND (ipsass_custtype_id=custtype_id)\n         AND (item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if not exists("showExpired") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n<? endif ?>\n<? if not exists("showFuture") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n<? endif ?>\n            )\n\n      UNION\n\n      SELECT\n<? if exists("byItem") ?>\n             ipsprice_id AS itemid, 3 AS sourcetype,\n             ipshead_name AS schedulename, <? value("custTypePattern") ?> AS type,\n             (custtype_code || '-' || custtype_descrip) AS typename,\n             ipsprice_qtybreak AS qtybreak, ipsprice_price AS price, ipshead_curr_id AS curr_id\n<? else ?>\n             ipsprice_id AS itemid,\n  <? if exists("byCustomerType") ?>\n             2 AS sourcetype,\n  <? elseif exists("byCustomer") ?>\n             3 AS sourcetype,\n  <? endif ?>\n             ipshead_name AS schedulename, <? value("custTypePattern") ?> AS type,\n             item_number AS itemnumber, uom_name AS priceuom, iteminvpricerat(item_id) AS invpricerat,\n             (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n             ipsprice_qtybreak AS qtybreak,\n             ipsprice_price AS price, ipshead_curr_id AS curr_id,\n             ipshead_updated AS effective\n  <? if exists("showCosts") ?>\n    <? if exists("useStandardCosts") ?>\n             , (stdcost(\n      <? if exists("byCustomerType") ?>\n                ipsprice_item_id\n      <? elseif exists("byCustomer") ?>\n                item_id\n      <? endif ?>\n                     ) * iteminvpricerat(item_id)) AS cost\n    <? elseif exists("useActualCosts") ?>\n             , (actcost(\n      <? if exists("byCustomerType") ?>\n                ipsprice_item_id\n      <? elseif exists("byCustomer") ?>\n                item_id\n      <? endif ?>\n                     ) * iteminvpricerat(item_id)) AS cost\n    <? endif ?>\n  <? endif ?>\n<? endif ?>\n      FROM ipsass, ipshead, ipsprice, item, custtype\n<? if not exists("byItem") ?>\n           , uom\n<? endif ?>\n<? if exists("byCustomer") ?>\n           , custinfo\n<? endif ?>\n      WHERE ((ipsass_ipshead_id=ipshead_id)\n         AND (ipsprice_ipshead_id=ipshead_id)\n         AND (ipsprice_item_id=item_id)\n<? if not exists("byItem") ?>\n         AND (item_price_uom_id=uom_id)\n<? endif ?>\n         AND (coalesce(length(ipsass_custtype_pattern), 0) > 0)\n         AND (custtype_code ~ ipsass_custtype_pattern)\n<? if exists("byCustomerType") ?>\n         AND (custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("byCustomer") ?>\n         AND (cust_id=<? value("cust_id") ?>)\n         <? if exists("item_id") ?>\n         AND (item_id=<? value("item_id") ?>)\n         <? endif ?>\n<? else ?>\n         AND (item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if not exists("showExpired") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n<? endif ?>\n<? if not exists("showFuture") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n<? endif ?>\n            )\n\n      UNION\n\n      SELECT\n<? if exists("byItem") ?>\n             ipsprice_id AS itemid, 4 AS sourcetype,\n             ipshead_name AS schedulename, <? value("sale") ?> AS type,\n             sale_name AS typename,\n             ipsprice_qtybreak AS qtybreak, ipsprice_price AS price, ipshead_curr_id AS curr_id\n<? else ?>\n             ipsprice_id AS itemid,\n<? if exists("byCustomerType") ?>\n             3\n<? elseif exists("byCustomer") ?>\n             4\n<? endif ?> AS sourcetype,\n             ipshead_name AS schedulename, (<? value("sale") ?> || '-' || sale_name) AS type,\n             item_number AS itemnumber, uom_name AS priceuom, iteminvpricerat(item_id) AS invpricerat,\n             (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n             ipsprice_qtybreak AS qtybreak,\n             ipsprice_price AS price, ipshead_curr_id AS curr_id,\n             ipshead_updated AS effective\n<? if exists("showCosts") ?>\n  <? if exists("useStandardCosts") ?>\n             , (stdcost(\n    <? if exists("byCustomerType") ?>\n                ipsprice_item_id\n    <? elseif exists("byCustomer") ?>\n                item_id\n    <? endif ?>\n                     ) * iteminvpricerat(item_id)) AS cost\n    <? elseif exists("useActualCosts") ?>\n             , (actcost(\n    <? if exists("byCustomerType") ?>\n                ipsprice_item_id\n    <? elseif exists("byCustomer") ?>\n                item_id\n    <? endif ?>\n                     ) * iteminvpricerat(item_id)) AS cost\n    <? endif ?>\n  <? endif ?>\n<? endif ?>\n      FROM sale, ipshead, ipsprice, item\n<? if not exists("byItem") ?>\n           , uom\n<? endif ?>\n      WHERE ((sale_ipshead_id=ipshead_id)\n         AND (ipsprice_ipshead_id=ipshead_id)\n<? if not exists("byItem") ?>\n         AND (item_price_uom_id=uom_id)\n<? endif ?>\n<? if exists("byItem") ?>\n         AND (ipsprice_item_id=<? value("item_id") ?>)\n  <? if not exists("showExpired") ?>\n         AND (sale_enddate > CURRENT_DATE)\n  <? endif ?>\n  <? if not exists("showFuture") ?>\n         AND (sale_startdate <= CURRENT_DATE)\n  <? endif ?>\n<? else ?>\n         AND (ipsprice_item_id=item_id)\n  <? if not exists("showExpired") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n  <? endif ?>\n  <? if not exists("showFuture") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n  <? endif ?>\n<? endif ?>\n            )\n\n<? if exists("byItem") ?>\n\n      UNION\n\n      SELECT ipsprice_id AS itemid, 5 AS sourcetype,\n             ipshead_name AS schedulename, <? value("shipTo") ?> AS type,\n             (cust_name || '-' || shipto_num) AS typename,\n             ipsprice_qtybreak AS qtybreak, ipsprice_price AS price, ipshead_curr_id AS curr_id\n      FROM ipsass, ipshead, ipsprice, custinfo, shiptoinfo, item\n      WHERE ((ipsass_ipshead_id=ipshead_id)\n         AND (ipsprice_ipshead_id=ipshead_id)\n         AND (ipsass_shipto_id=shipto_id)\n         AND (shipto_cust_id=cust_id)\n         AND (ipsprice_item_id=item_id)\n         AND (item_id=<? value("item_id") ?>)\n  <? if not exists("showExpired") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n  <? endif ?>\n  <? if not exists("showFuture") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n  <? endif ?>\n            )\n\n      UNION\n\n      SELECT ipsprice_id AS itemid, 6 AS sourcetype,\n             ipshead_name AS schedulename, <? value("shipToPattern") ?> AS type,\n             (cust_name || '-' || shipto_num) AS typename,\n             ipsprice_qtybreak AS qtybreak, ipsprice_price AS price, ipshead_curr_id AS curr_id\n      FROM ipsass, ipshead, ipsprice, custinfo, shiptoinfo, item\n      WHERE ((ipsass_ipshead_id=ipshead_id)\n         AND (ipsprice_ipshead_id=ipshead_id)\n         AND (COALESCE(LENGTH(ipsass_shipto_pattern),0) > 0)\n         AND (shipto_num ~ ipsass_shipto_pattern)\n         AND (ipsass_cust_id=cust_id)\n         AND (shipto_cust_id=cust_id)\n         AND (ipsprice_item_id=item_id)\n         AND (item_id=:item_id)\n  <? if not exists("showExpired") ?>\n         AND (ipshead_expires > CURRENT_DATE)\n  <? endif ?>\n  <? if not exists("showFuture") ?>\n         AND (ipshead_effective <= CURRENT_DATE)\n  <? endif ?>\n            )\n<? endif ?>\n\n      UNION\n\n      SELECT\n<? if exists("byItem") ?>\n             item_id AS itemid, 0 AS sourcetype,\n             <? value("listPrice") ?> AS schedulename, <? value("na") ?> AS type,\n             '' AS typename,\n             -1 AS qtybreak, item_listprice AS price, baseCurrId() AS curr_id\n<? else ?>\n             item_id AS itemid, 0 AS sourcetype,\n             '' AS schedulename, <? value("listPrice") ?> AS type,\n             item_number AS itemnumber, uom_name AS priceuom, iteminvpricerat(item_id) AS invpricerat,\n             (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n             -1 AS qtybreak,\n  <? if exists("byCustomerType") ?>\n             item_listprice AS price,\n  <? elseif exists("byCustomer") ?>\n             (item_listprice - (item_listprice * cust_discntprcnt)) AS price,\n  <? endif ?>\n             baseCurrId() AS curr_id,\n             CURRENT_DATE AS effective\n  <? if exists("useStandardCosts") ?>\n             , (stdcost(item_id) * iteminvpricerat(item_id)) AS cost\n  <? elseif exists("useActualCosts") ?>\n             , (actcost(item_id) * iteminvpricerat(item_id)) AS cost\n  <? endif ?>\n<? endif ?>\n<? if exists("byCustomerType") ?>\n      FROM item JOIN uom ON (item_price_uom_id=uom_id)\n<? elseif exists("byCustomer") ?>\n      FROM custinfo, item JOIN uom ON (item_price_uom_id=uom_id)\n<? else ?>\n      FROM item\n<? endif ?>\n      WHERE (\n<? if not exists("byItem") ?>\n             (item_sold)\n         AND (item_active)\n<? else ?>\n             (item_id=<? value("item_id") ?>)\n<? endif ?>\n         AND (NOT item_exclusive)\n<? if exists("byCustomer") ?>\n         AND (cust_id=<? value("cust_id") ?>)\n         <? if exists("item_id") ?>\n         AND (item_id=<? value("item_id") ?>)\n         <? endif ?>\n<? endif ?>\n            )\n     ) AS data\nORDER BY\n<? if not exists("byItem") ?>\n         itemnumber,\n<? endif ?>\n         price;\n	admin	2015-10-01	0
442	pricingFreight	detail	 used by itemPricingScheduleItem\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: pricingFreight\n-- Name: detail\n-- Notes: used by itemPricingScheduleItem\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT ipsfreight.*\n  FROM ipsfreight\n WHERE ( (true)\n<? if exists("checkDup") ?>\n <? if exists("ipshead_id") ?>\n   AND (ipsfreight_ipshead_id=<? value("ipshead_id") ?>)\n <? endif ?>\n <? if exists("warehous_id") ?>\n   AND (ipsfreight_warehous_id=<? value("warehous_id") ?>)\n <? else ?>\n   AND (ipsfreight_warehous_id IS NULL)\n <? endif ?>\n <? if exists("shipzone_id") ?>\n   AND (ipsfreight_shipzone_id=<? value("shipzone_id") ?>)\n <? else ?>\n   AND (ipsfreight_shipzone_id IS NULL)\n <? endif ?>\n <? if exists("freightclass_id") ?>\n   AND (ipsfreight_freightclass_id=<? value("freightclass_id") ?>)\n <? else ?>\n   AND (ipsfreight_freightclass_id IS NULL)\n <? endif ?>\n <? if exists("shipvia") ?>\n   AND (ipsfreight_shipvia=<? value("shipvia") ?>)\n <? else ?>\n   AND (ipsfreight_shipvia IS NULL)\n <? endif ?>\n <? if exists("qtybreak") ?>\n   AND (ipsfreight_qtybreak=<? value("qtybreak") ?>)\n <? endif ?>\n   AND (ipsfreight_id <> <? value("ipsfreight_id") ?>)\n<? elseif exists("ipsfreight_id") ?>\n   AND (ipsfreight_id=<? value("ipsfreight_id") ?>)\n<? endif ?>\n      );\n	admin	2015-10-01	0
459	projectTasks	detail	 \n Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: projectTasks\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT prjtask_id, prjtask_number, prjtask_name,\n       COALESCE(prjtask_hours_budget - prjtask_hours_actual, 0.0) as prjtaskhrbal,\n       COALESCE(prjtask_exp_budget - prjtask_exp_actual, 0.0) as prjtaskexpbal,\n       firstLine(prjtask_descrip) AS prjtask_descrip,\n       totalhrbud, totalhract, totalhrbal,\n       totalexpbud, totalexpact, totalexpbal\nFROM (SELECT COALESCE(SUM(prjtask_hours_budget), 0.0) AS totalhrbud,\n             COALESCE(SUM(prjtask_hours_actual), 0.0) AS totalhract,\n             COALESCE(SUM(prjtask_hours_budget - prjtask_hours_actual), 0.0) AS totalhrbal,\n             COALESCE(SUM(prjtask_exp_budget), 0.0) AS totalexpbud,\n             COALESCE(SUM(prjtask_exp_actual), 0.0) AS totalexpact,\n             COALESCE(SUM(prjtask_exp_budget - prjtask_exp_actual), 0.0) AS totalexpbal\n      FROM prjtask\n      WHERE prjtask_prj_id = <? value("prj_id") ?>) foo, prjtask\nWHERE (prjtask_prj_id=<? value("prj_id") ?>)\nORDER BY prjtask_number;\n	admin	2015-10-01	0
480	projects	detail_nohierarchy	 Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n\n        Non-hierarchical view to support CSV export from Project List screen\n	-- Group: projects\n-- Name:  detail_nohierarchy\n-- Notes: Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n--\n--        Non-hierarchical view to support CSV export from Project List screen\n\nSELECT prj_id AS id, 1 AS altId,\n  prj.*, crmacct_name, cntct_name,\n  addr_city, addr_state,\n  prjtype_descr AS project_type,\n  CASE WHEN (prj_status='P') THEN <? value("planning") ?>\n       WHEN (prj_status='O') THEN <? value("open") ?>\n       WHEN (prj_status='C') THEN <? value("complete") ?>\n       ELSE <? value("undefined") ?> END AS project_status\n<? foreach("char_id_text_list") ?>\n  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>\n<? endforeach ?>\nFROM prj()\nLEFT JOIN prjtype ON (prj_prjtype_id=prjtype_id)\nLEFT JOIN crmacct ON (prj_crmacct_id=crmacct_id)\nLEFT JOIN cntct ON (crmacct_cntct_id_1=cntct_id)\nLEFT JOIN addr ON (cntct_addr_id=addr_id)\n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='PROJ')\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=prj_id)\n                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='PROJ')\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=prj_id)\n                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='PROJ')\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=prj_id)\n                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE (true)\n<? if exists("search_pattern") ?>\n   AND ( (prj_number ~* <? value("search_pattern") ?>)\n     OR  (prj_name ~* <? value("search_pattern") ?>)\n     OR  (prj_descrip ~* <? value("search_pattern") ?>) )\n<? endif ?>\n<? if exists("username") ?>\n  AND (prj_username=<? value("username") ?> OR prj_owner_username=<? value("username") ?>)\n<? endif ?>\n<? if exists("assigned_username") ?>\n  AND (prj_username=<? value("assigned_username") ?>)\n<? elseif exists("assigned_usr_pattern") ?>\n  AND (prj_username ~ <? value("assigned_usr_pattern") ?>)\n<? endif ?>\n<? if exists("owner_username") ?>\n  AND (prj_owner_username=<? value("owner_username") ?>)\n<? elseif exists("owner_usr_pattern") ?>\n  AND (prj_owner_username ~ <? value("owner_usr_pattern") ?>)\n<? endif ?>\n<? if exists("crmacct_id") ?>\n  AND (prj_crmacct_id=<? value("crmacct_id") ?>)\n<? endif ?>\n<? if exists("cntct_id") ?>\n  AND (prj_cntct_id=<? value("cntct_id") ?>)\n<? endif ?>\n<? if exists("prjtype_id") ?>\n  AND (prj_prjtype_id=<? value("prjtype_id") ?>)\n<? endif ?>\n<? if exists("prjstatus") ?>\n  AND (prj_status=<? value("prjstatus") ?>)\n<? elseif not exists("showComplete") ?>\n  AND (prj_status <> 'C')\n<? endif ?>\n<? if exists("startStartDate") ?>\n  AND (prj_start_date >= <? value("startStartDate") ?>)\n<? endif ?>\n<? if exists("startEndDate") ?>\n  AND (prj_start_date <= <? value("startEndDate") ?>)\n<? endif ?>\n<? if exists("dueStartDate") ?>\n  AND (prj_due_date >= <? value("dueStartDate") ?>)\n<? endif ?>\n<? if exists("dueEndDate") ?>\n  AND (prj_due_date <= <? value("dueEndDate") ?>)\n<? endif ?>\n<? if exists("assignedStartDate") ?>\n  AND (prj_assigned_date >= <? value("assignedStartDate") ?>)\n<? endif ?>\n<? if exists("assignedEndDate") ?>\n  AND (prj_assigned_date <= <? value("assignedEndDate") ?>)\n<? endif ?>\n<? if exists("completedStartDate") ?>\n  AND (prj_completed_date >= <? value("completedStartDate") ?>)\n<? endif ?>\n<? if exists("completedEndDate") ?>\n  AND (prj_completed_date <= <? value("completedEndDate") ?>)\n<? endif ?>\n<? if exists("id") ?>\n  AND (prj_id=<? value("id") ?>)\n<? endif ?>\n<? if exists("prj_id") ?>\n  AND (prj_id=<? value("prj_id") ?>)\n<? endif ?>\n<? if exists("project_task") ?>\n  AND prj_id IN (SELECT DISTINCT prjtask_prj_id FROM prjtask where ((prjtask_number ~* <? value("project_task") ?>)\n\t\t\t\t\t\tOR (prjtask_name ~* <? value("project_task") ?>)\n\t\t\t\t\t\tOR (prjtask_descrip ~* <? value("project_task") ?>)))\n<? endif ?>\n<? if exists("cohead_id") ?>\n  AND prj_id IN (SELECT cohead_prj_id FROM cohead where cohead_id=<? value("cohead_id") ?>)\n<? endif ?>\n<? if exists("wo_id") ?>\n  AND prj_id IN (SELECT wo_prj_id FROM wo WHERE wo_id=<? value("wo_id") ?>)\n<? endif ?>\n<? if exists("pohead_id") ?>\n  AND prj_id IN (SELECT poitem_prj_id FROM pohead JOIN poitem ON (pohead_id=poitem_pohead_id)\n\t\t\tWHERE pohead_id=<? value("pohead_id") ?>)\n<? endif ?>\n<? literal("charClause") ?>\nORDER BY prj_number;	admin	2015-10-01	0
277	projects	detail	\n        Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n\n        xTuple version 4.2.0 - Modified to significantly amend the display of this screen and its filters.\n        xTuple version 4.3.0 - Add Incidents to hierarchy display\n	-- Group: projects\n-- Name:  detail\n-- Notes:\n--        Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n--\n--        xTuple version 4.2.0 - Modified to significantly amend the display of this screen and its filters.\n--        xTuple version 4.3.0 - Add Incidents to hierarchy display\nSELECT *,\n  formatQty(qty) AS f_qty,\n  formatMoney(value) AS f_value,\n  'curr' AS qty_xtnumericrole,\n  'curr' AS value_xtnumericrole,\n  CASE WHEN COALESCE(hrs_balance,0) < 0 THEN 'red' END AS hrs_balance_qtforegroundrole,\n  CASE WHEN COALESCE(exp_balance,0) < 0 THEN 'red' END AS exp_balance_qtforegroundrole\nFROM (\nSELECT prj_id AS id,\n       1 AS type,\n       '0' AS subtype,\n       0 AS section,\n       prj_id AS project,\n       NULL  AS section_qtdisplayrole,\n       prj_number AS name,\n       CASE\n           WHEN prj_status = 'C' THEN <? value('complete') ?>\n           WHEN prj_status = 'O' THEN <? value('inprocess') ?>\n           WHEN prj_status = 'P' THEN <? value('planning') ?>\n       END AS status,\n       COALESCE(prjtype_descr, 'Undefined') AS project_type,\n       prj_username,\n       prj_owner_username,\n       prj_name AS item,\n       firstline(prj_descrip) AS descrip,\n       crmacct_name AS customer,\n       cntct_name AS contact,\n       addr_city AS city,\n       addr_state AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       prj_due_date AS due,\n       prj_assigned_date AS assigned,\n       prj_start_date AS started,\n       prj_completed_date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n       CASE WHEN (prj_status = 'O' AND prj_due_date < current_date) THEN 'red'\n         WHEN (prj_status = 'O' AND prj_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange'\n         END AS due_qtforegroundrole,\n       0 AS xtindentrole\n  FROM prj()\n  LEFT OUTER JOIN prjtype ON (prj_prjtype_id=prjtype_id)\n  LEFT OUTER JOIN crmacct ON (prj_crmacct_id=crmacct_id)\n  LEFT OUTER JOIN cntct ON (crmacct_cntct_id_1=cntct_id)\n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)\n\n WHERE (1=1 )\n\nUNION ALL\n----- TASKS -----\nSELECT DISTINCT -1 AS id,\n       3 AS type,\n       '0' AS subtype,\n       1 AS section,\n       prjtask_prj_id AS project,\n       <? value('tasks') ?> AS section_qtdisplayrole,\n       <? value('tasks') ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n       NULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n    FROM prjtask\nUNION ALL\n\nSELECT prjtask_id AS id,\n       5 AS type,\n       '0' AS subtype,\n       1 AS section,\n       prjtask_prj_id AS project,\n       NULL AS section_qtdisplayrole,\n       prjtask_number AS name,\n       CASE\n           WHEN prjtask_status = 'C' THEN <? value('complete') ?>\n           WHEN prjtask_status = 'O' THEN <? value('inprocess') ?>\n           WHEN prjtask_status = 'P' THEN <? value('planning') ?>\n       END AS status,\n       NULL::text AS project_type,\n       prjtask_username AS prj_username,\n       prjtask_owner_username AS prj_owner_username,\n       prjtask_name AS item,\n       prjtask_descrip AS descrip,\n       cust_name as customer,\n       cntct_name AS contact,\n       addr_city AS city,\n       addr_state AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       prjtask_due_date AS due,\n       prjtask_assigned_date AS assigned,\n       prjtask_start_date AS started,\n       prjtask_completed_date AS completed,\n       prjtask_hours_budget AS hrs_budget,\n       prjtask_hours_actual AS hrs_actual,\n       (prjtask_hours_budget-prjtask_hours_actual) AS hrs_balance,\n       prjtask_exp_budget AS exp_budget,\n       prjtask_exp_actual AS exp_actual,\n       (prjtask_exp_budget-prjtask_exp_actual) AS exp_balance,\n       CASE WHEN (prjtask_status = 'O' AND prjtask_due_date < current_date) THEN 'red'\n         WHEN (prjtask_status = 'O' AND prjtask_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange'\n         END AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM prjtask\n  LEFT OUTER JOIN te.teprjtask ON (prjtask_id = teprjtask_prjtask_id)\n  LEFT OUTER JOIN custinfo ON (teprjtask_cust_id=cust_id)\n  LEFT OUTER JOIN cntct ON (cust_corrcntct_id=cntct_id)\n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)\n\n WHERE (1=1 )\n GROUP BY prjtask_prj_id, custinfo.cust_name, prjtask.prjtask_id, addr.addr_city, addr.addr_state, cntct_name, prjtask.prjtask_number, prjtask.prjtask_status, prjtask_username, prjtask.prjtask_owner_username, prjtask_name, prjtask_descrip, prjtask_due_date, prjtask_assigned_date, prjtask_start_date, prjtask_completed_date, prjtask_hours_budget, prjtask_hours_actual, prjtask_exp_budget, prjtask_exp_actual\n\n<? if exists("showIn") ?>\n\nUNION ALL\n----- INCIDENTS -----\nSELECT DISTINCT -1 AS id,\n       100 AS type,\n       '0' AS subtype,\n       1 AS section,\n       incdt_prj_id AS project,\n       'Incidents' AS section_qtdisplayrole,\n       'Incidents' AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n       NULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n    FROM incdt\nUNION ALL\n\nSELECT incdt_id AS id,\n       105 AS type,\n       '0' AS subtype,\n       1 AS section,\n       incdt_prj_id AS project,\n       NULL AS section_qtdisplayrole,\n       incdt_number::text AS name,\n       CASE\n           WHEN incdt_status = 'L' THEN <? value('closed') ?>\n           WHEN incdt_status = 'N' THEN <? value('new') ?>\n           WHEN incdt_status = 'F' THEN <? value('feedback') ?>\n           WHEN incdt_status = 'A' THEN <? value('assigned') ?>\n           WHEN incdt_status = 'R' THEN <? value('resolved') ?>\n           WHEN incdt_status = 'C' THEN <? value('confirmed') ?>\n       END AS status,\n       NULL::text AS project_type,\n       incdt_assigned_username AS prj_username,\n       incdt_owner_username AS prj_owner_username,\n       incdt_number::text AS item,\n       incdt_summary AS descrip,\n       crmacct_number AS customer,\n       crmacct_name AS contact,\n       addr_city AS city,\n       addr_state AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n       NULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM incdt\n  LEFT OUTER JOIN crmacct ON (incdt_crmacct_id=crmacct_id)\n  LEFT OUTER JOIN cntct ON (incdt_cntct_id=cntct_id)\n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)\n\n WHERE (1=1 )\n GROUP BY incdt_id, incdt_prj_id, incdt_number, crmacct_number, crmacct_name, addr.addr_city, addr.addr_state, cntct_name, incdt_number, incdt_status, incdt_assigned_username, incdt_owner_username, incdt_number, incdt_summary\n<? endif ?>\n\n<? if exists("showSo") ?>\nUNION ALL\n\n----- QUOTES -----\nSELECT DISTINCT -1 AS id,\n       10 AS type,\n       '0' AS subtype,\n       1 AS section,\n       prj_id AS project,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       <? value("quotes") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n       NULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM quhead\n  JOIN prj() ON (quhead_prj_id=prj_id)\n WHERE (1=1)\nUNION ALL\n\nSELECT quhead_id AS id,\n       15 AS type,\n       quhead_number AS subtype,\n       1 AS section,\n       prj_id AS project,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       quhead_number AS name,\n       CASE WHEN (quhead_status = 'C') THEN\n         <? value("converted") ?>\n            WHEN (quhead_status = 'X') THEN\n         <? value("canceled") ?>\n            WHEN (COALESCE(quhead_expire, current_date + 1) > current_date) THEN\n         <? value("open") ?>\n            ELSE\n         <? value("expired") ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       cust_name AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       NULL AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n       NULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM quhead\n  JOIN prj() ON (quhead_prj_id=prj_id)\n  JOIN custinfo ON (quhead_cust_id=cust_id)\n    JOIN quitem ON (quitem_quhead_id = quhead_id)\n WHERE (1=1)\nGROUP BY prj_id, quhead_id, quhead_number, quhead_status, quhead_expire, quhead_freight, quhead_misc, custinfo.cust_name\n\nUNION ALL\n\nSELECT quitem_id AS id,\n       17 AS type,\n       quhead_number AS subtype,\n       1 AS section,\n       prj_id AS project,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       quitem_linenumber::text AS name,\n       CASE WHEN (quhead_status = 'C') THEN\n         <? value("converted") ?>\n            WHEN (quhead_status = 'X') THEN\n         <? value("canceled") ?>\n            WHEN (COALESCE(quhead_expire, current_date + 1) > current_date) THEN\n         <? value("open") ?>\n            ELSE\n         <? value("expired") ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       item_number AS item,\n       item_descrip1 || ' ' || item_descrip2 AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       quitem_qtyord,\n       uom_name AS uom,\n       (quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n       NULL::text AS due_qtforegroundrole,\n       3 AS xtindentrole\n  FROM quhead\n  JOIN prj() ON (quhead_prj_id=prj_id)\n    JOIN quitem ON (quitem_quhead_id = quhead_id)\n    JOIN uom ON (quitem_qty_uom_id = uom_id)\n    JOIN itemsite ON (quitem_itemsite_id = itemsite_id)\n    JOIN item ON (itemsite_item_id = item_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT quhead_id AS id,\n       18 AS type,\n       quhead_number AS subtype,\n       1 AS section,\n       prj_id AS project,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       <? value("total") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM quhead\n    JOIN prj() ON (quhead_prj_id=prj_id)\n    JOIN quitem ON (quitem_quhead_id = quhead_id)\n WHERE (1=1)\nGROUP BY prj_id, quhead_id, quhead_number\n\nUNION ALL\n\nSELECT -1 AS id,\n       19 AS type,\n       MAX(quhead_number) AS subtype,\n       1 AS section,\n       prj_id AS project,\n       <? value("quotes") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("quotes") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM quhead\n    JOIN prj() ON (quhead_prj_id=prj_id)\n    JOIN quitem ON (quitem_quhead_id = quhead_id)\n WHERE (1=1)\n GROUP BY prj_id\n\nUNION ALL\n\n------ SALES ORDERS ------\nSELECT DISTINCT -1 AS id,\n       20 AS type,\n       '0' AS subtype,\n       2 AS section,\n       prj_id AS project,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       <? value("sos") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM cohead\n    JOIN prj() ON (cohead_prj_id=prj_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT cohead_id AS id,\n       25 AS type,\n       cohead_number::text AS subtype,\n       2 AS section,\n       prj_id AS project,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       cohead_number::text AS name,\n      COALESCE((SELECT\n                  CASE WHEN (coitem_status = 'O') THEN\n                    <? value("open") ?>\n                       WHEN (coitem_status = 'C') THEN\n                    <? value("closed" ?>\n                      ELSE\n                    <? value("canceled") ?>\n                  END\n                FROM\n               (SELECT coitem_status,\n                   CASE\n                     WHEN (coitem_status = 'O') THEN 1\n                     WHEN (coitem_status = 'C') then 2\n                     ELSE  3\n                  END AS type\n                  FROM coitem\n                 WHERE (coitem_cohead_id=cohead_id)\n                 ORDER BY type\n                 LIMIT 1) AS sts) ,'O')\n        AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       shipto_num AS item,\n       shipto_name AS descrip,\n       cust_name AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       NULL AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM cohead\n    JOIN prj() ON (cohead_prj_id=prj_id)\n    JOIN custinfo ON (cust_id = cohead_cust_id)\n    LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)\n    JOIN coitem ON (coitem_cohead_id = cohead_id)\n WHERE (1=1)\nGROUP BY prj_id,cohead_id, cohead_number, shipto_num, shipto_name, cust_name\n\nUNION ALL\n\nSELECT coitem_id AS id,\n       27 AS type,\n       cohead_number::text AS subtype,\n       2 AS section,\n       prj_id AS project,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       coitem_linenumber::text AS name,\n       CASE WHEN (coitem_status = 'O') THEN\n         <? value("open") ?>\n            WHEN (coitem_status = 'C') THEN\n         <? value("closed" ?>\n            WHEN (coitem_status = 'X') THEN\n         <? value("canceled") ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       item_number AS item,\n       item_descrip1 || ' ' || item_descrip2 AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       coitem_qtyord,\n       uom_name AS uom,\n       (coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       3 AS xtindentrole\n  FROM cohead\n    JOIN prj() ON (cohead_prj_id=prj_id)\n    JOIN coitem ON (coitem_cohead_id = cohead_id)\n    JOIN uom ON (coitem_qty_uom_id = uom_id)\n    JOIN itemsite ON (coitem_itemsite_id = itemsite_id)\n    JOIN item ON (itemsite_item_id = item_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT cohead_id AS id,\n       28 AS type,\n       cohead_number::text AS subtype,\n       2 AS section,\n       prj_id AS project,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM cohead\n    JOIN prj() ON (cohead_prj_id=prj_id)\n    JOIN coitem ON (coitem_cohead_id = cohead_id)\n WHERE (1=1)\nGROUP BY prj_id,cohead_id, cohead_number\n\nUNION ALL\n\nSELECT -1 AS id,\n       29 AS type,\n       MAX(cohead_number::text) AS subtype,\n       2 AS section,\n       prj_id AS project,\n       <? value("sos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("sos") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM cohead\n    JOIN prj() ON (cohead_prj_id=prj_id)\n    JOIN coitem ON (coitem_cohead_id = cohead_id)\n WHERE (1=1)\n GROUP BY prj_id\n\nUNION ALL\n\n------ INVOICES -------\nSELECT DISTINCT -1 AS id,\n       30 AS type,\n       '0' AS subtype,\n       3 AS section,\n       prj_id AS project,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       <? value("invoices") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM invchead\n  JOIN prj() ON (invchead_prj_id=prj_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT invchead_id AS id,\n       35 AS type,\n       invchead_invcnumber::text AS subtype,\n       3 AS section,\n       prj_id AS project,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       invchead_invcnumber::text AS name,\n       CASE WHEN (invchead_posted) THEN\n         <? value("posted") ?>\n       ELSE <? value("unposted") ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       shipto_num AS item,\n       shipto_name AS descrip,\n       cust_name AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       NULL AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM invchead\n    JOIN prj() ON (invchead_prj_id=prj_id)\n    JOIN custinfo ON (cust_id=invchead_cust_id)\n    LEFT OUTER JOIN shiptoinfo ON (invchead_shipto_id = shipto_id)\n\n    JOIN invcitem ON (invcitem_invchead_id = invchead_id)\n WHERE (1=1)\nGROUP BY prj_id,invchead_id, invchead_invcnumber, shipto_num, shipto_name, invchead_freight, invchead_misc_amount, invchead_posted, cust_name\n\nUNION ALL\n\nSELECT invcitem_id AS id,\n       37 AS type,\n       invchead_invcnumber::text AS subtype,\n       3 AS section,\n       prj_id AS project,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       invcitem_linenumber::text AS name,\n       CASE WHEN (invchead_posted) THEN\n         <? value("posted") ?>\n       ELSE <? value("unposted") ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       COALESCE(item_number,invcitem_number) AS item,\n       COALESCE(item_descrip1 || ' ' || item_descrip2,invcitem_descrip) AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       invcitem_billed AS qty,\n       uom_name AS uom,\n       (invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       3 AS xtindentrole\n  FROM invchead\n    JOIN prj() ON (invchead_prj_id=prj_id)\n    JOIN invcitem ON (invcitem_invchead_id = invchead_id)\n    LEFT OUTER JOIN item ON (invcitem_item_id = item_id)\n    LEFT OUTER JOIN uom ON (invcitem_qty_uom_id = uom_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT invchead_id AS id,\n       38 AS type,\n       invchead_invcnumber::text AS subtype,\n       3 AS section,\n       prj_id AS project,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       <? value("total") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM invchead\n    JOIN prj() ON (invchead_prj_id=prj_id)\n    JOIN invcitem ON (invcitem_invchead_id = invchead_id)\n WHERE (1=1)\nGROUP BY prj_id,invchead_id, invchead_invcnumber\n\nUNION ALL\n\nSELECT -1 AS id,\n       39 AS type,\n       MAX(invchead_invcnumber::text) AS subtype,\n       3 AS section,\n       prj_id AS project,\n       <? value("invoices") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("invoices") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM invchead\n    JOIN prj() ON (invchead_prj_id=prj_id)\n    JOIN invcitem ON (invcitem_invchead_id = invchead_id)\n WHERE (1=1)\n GROUP BY prj_id\n\n<? endif ?>\n\n<? if exists("showWo") ?>\nUNION ALL\n\n------ WORK ORDERS -------\nSELECT DISTINCT -1 AS id,\n       40 AS type,\n       '0' AS subtype,\n       4 AS section,\n       prj_id AS project,\n       <? value("wos") ?> AS section_qtdisplayrole,\n       <? value("wos") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM wo\n  JOIN prj() ON (wo_prj_id=prj_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT wo_id AS id,\n       45 AS type,\n       formatWoNumber(wo_id) AS subtype,\n       4 AS section,\n       prj_id AS project,\n       <? value("wos") ?> AS section_qtdisplayrole,\n       formatWoNumber(wo_id) AS name,\n       CASE WHEN (wo_status = 'O') THEN\n         <? value("open") ?>\n            WHEN (wo_status = 'E') THEN\n         <? value("exploded") ?>\n            WHEN (wo_status = 'R') THEN\n         <? value("released") ?>\n            WHEN (wo_status = 'I') THEN\n         <? value("inprocess") ?>\n            WHEN (wo_status = 'C') THEN\n         <? value("closed" ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       item_number AS item,\n       item_descrip1 || ' ' || item_descrip2 AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       wo_qtyord AS qty,\n       uom_name AS uom,\n       wo_postedvalue AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM wo\n    JOIN prj() ON (wo_prj_id=prj_id)\n    JOIN itemsite ON (itemsite_id=wo_itemsite_id)\n    JOIN item ON (itemsite_item_id=item_id)\n    JOIN uom ON (item_inv_uom_id=uom_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT -1 AS id,\n       49 AS type,\n       MAX(formatWoNumber(wo_id)) AS subtype,\n       4 AS section,\n       prj_id AS project,\n       <? value("wos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("wos") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM(wo_postedvalue) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM wo\n     JOIN prj() ON (wo_prj_id=prj_id)\n WHERE (1=1)\n GROUP BY prj_id\n\n<? endif ?>\n\n\n<? if exists("showPo") ?>\n UNION ALL\n------ PURCHASE REQUESTS ------\nSELECT DISTINCT -1 AS id,\n       50 AS type,\n       '0' AS subtype,\n       5 AS section,\n       prj_id AS project,\n       <? value("prs") ?> AS section_qtdisplayrole,\n       <? value("prs") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM pr\n    JOIN prj() ON (pr_prj_id=prj_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT pr_id AS id,\n       55 AS type,\n       pr_number::text || '-' || pr_subnumber::text AS subtype,\n       5 AS section,\n       prj_id AS project,\n       <? value("prs") ?> AS section_qtdisplayrole,\n       pr_number::text || '-' || pr_subnumber::text AS name,\n       <? value("open") ?> AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       item_number AS item,\n       (item_descrip1 || ' ' || item_descrip2) AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       pr_qtyreq AS qty,\n       uom_name AS uom,\n       stdcost(item_id) * pr_qtyreq AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pr\n    JOIN prj() ON (pr_prj_id=prj_id)\n    JOIN itemsite ON (itemsite_id = pr_itemsite_id)\n    JOIN item ON (itemsite_item_id = item_id)\n    JOIN uom ON (item_inv_uom_id = uom_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT -1 AS id,\n       59 AS type,\n       MAX(pr_number::text || '-' || pr_subnumber::text) AS subtype,\n       5 AS section,\n       prj_id AS project,\n       <? value("prs") ?> AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("prs") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM(stdcost(item_id) * pr_qtyreq) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pr\n    JOIN prj() ON (pr_prj_id=prj_id)\n    JOIN itemsite ON (itemsite_id = pr_itemsite_id)\n    JOIN item ON (itemsite_item_id = item_id)\n WHERE (1=1)\n GROUP BY prj_id\n\nUNION ALL\n\n------ PURCHASE ORDERS ------\nSELECT DISTINCT -1 AS id,\n       60 AS type,\n       '0' AS subtype,\n       6 AS section,\n       prj_id AS project,\n       <? value("pos") ?> AS section_qtdisplayrole,\n       <? value("pos") ?> AS name,\n       NULL::text AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL::numeric AS qty,\n       NULL::text AS uom,\n       NULL::numeric AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       1 AS xtindentrole\n  FROM poitem\n    JOIN prj() ON (poitem_prj_id=prj_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT pohead_id AS id,\n       65 AS type,\n       pohead_number::text AS subtype,\n       6 AS section,\n       prj_id AS project,\n       <? value("pos") ?> AS section_qtdisplayrole,\n       pohead_number::text AS name,\n       CASE WHEN (pohead_status = 'U') THEN\n         <? value("unreleased") ?>\n            WHEN (pohead_status = 'O') THEN\n         <? value("open") ?>\n            WHEN (pohead_status = 'C') THEN\n         <? value("closed" ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL AS uom,\n       NULL AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pohead\n    JOIN poitem ON (poitem_pohead_id = pohead_id)\n    JOIN prj() ON (poitem_prj_id=prj_id)\n WHERE (1=1)\nGROUP BY prj_id,pohead_id, pohead_number, pohead_freight, pohead_status\n\nUNION ALL\n\nSELECT poitem_id AS id,\n       67 AS type,\n       pohead_number::text AS subtype,\n       6 AS section,\n       prj_id AS project,\n       <? value("pos") ?> AS section_qtdisplayrole,\n       poitem_linenumber::text AS name,\n       CASE WHEN (poitem_status = 'U') THEN\n         <? value("unreleased") ?>\n            WHEN (poitem_status = 'O') THEN\n         <? value("open") ?>\n            WHEN (poitem_status = 'C') THEN\n         <? value("closed" ?>\n       END AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       COALESCE(item_number,poitem_vend_item_number) AS item,\n       COALESCE((item_descrip1 || ' ' || item_descrip2),poitem_vend_item_descrip) AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       poitem_qty_ordered,\n       poitem_vend_uom AS uom,\n       (poitem_qty_ordered * poitem_unitprice) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       3 AS xtindentrole\n  FROM pohead\n    JOIN poitem ON (poitem_pohead_id = pohead_id)\n    JOIN prj() ON (poitem_prj_id=prj_id)\n    LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)\n    LEFT OUTER JOIN item ON (itemsite_item_id = item_id)\n WHERE (1=1)\n\nUNION ALL\n\nSELECT pohead_id AS id,\n       68 AS type,\n       pohead_number::text AS subtype,\n       6 AS section,\n       prj_id AS project,\n       <? value("pos") ?> AS section_qtdisplayrole,\n       <? value("total") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM(poitem_qty_ordered * poitem_unitprice) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pohead\n    JOIN poitem ON (poitem_pohead_id = pohead_id)\n    JOIN prj() ON (poitem_prj_id=prj_id)\n WHERE (1=1)\nGROUP BY prj_id,pohead_id, pohead_number\n\nUNION ALL\n\nSELECT -1 AS id,\n       69 AS type,\n       MAX(pohead_number::text) AS subtype,\n       6 AS section,\n       prj_id AS project,\n       'qty' AS section_qtdisplayrole,\n       <? value("total") ?> || ' ' || <? value("pos") ?> AS name,\n       NULL AS status,\n       NULL::text AS project_type,\n       NULL::text AS prj_username,\n       NULL::text AS prj_owner_username,\n       NULL::text AS item,\n       NULL::text AS descrip,\n       NULL::text AS customer,\n       NULL::text AS contact,\n       NULL::text AS city,\n       NULL::text AS state,\n       NULL AS qty,\n       NULL::text AS uom,\n       SUM(poitem_qty_ordered * poitem_unitprice) AS value,\n       NULL::date AS due,\n       NULL::date AS assigned,\n       NULL::date AS started,\n       NULL::date AS completed,\n       NULL::numeric AS hrs_budget,\n       NULL::numeric AS hrs_actual,\n       NULL::numeric AS hrs_balance,\n       NULL::numeric AS exp_budget,\n       NULL::numeric AS exp_actual,\n       NULL::numeric AS exp_balance,\n\n\tNULL::text AS due_qtforegroundrole,\n       2 AS xtindentrole\n  FROM pohead\n    JOIN poitem ON (poitem_pohead_id = pohead_id)\n    JOIN prj() ON (poitem_prj_id=prj_id)\n WHERE (1=1)\n GROUP BY prj_id\n\n<? endif ?>\n\n) data\n\nWHERE (true)\n<? if exists("search_pattern") ?>\n   AND project IN (SELECT prj_id FROM prj WHERE ( (prj_number ~* <? value("search_pattern") ?>)\n     OR  (prj_name ~* <? value("search_pattern") ?>)\n     OR  (prj_descrip ~* <? value("search_pattern") ?>) ))\n<? endif ?>\n<? if exists("username") ?>\n  AND (prj_username=<? value("username") ?> OR prj_owner_username=<? value("username") ?>)\n<? endif ?>\n<? if exists("assigned_username") ?>\n  AND (prj_username=<? value("assigned_username") ?>)\n<? elseif exists("assigned_usr_pattern") ?>\n  AND (prj_username ~ <? value("assigned_usr_pattern") ?>)\n<? endif ?>\n<? if exists("owner_username") ?>\n  AND (prj_owner_username=<? value("owner_username") ?>)\n<? elseif exists("owner_usr_pattern") ?>\n  AND (prj_owner_username ~ <? value("owner_usr_pattern") ?>)\n<? endif ?>\n<? if exists("crmacct_id") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_crmacct_id=<? value("crmacct_id") ?>))\n<? endif ?>\n<? if exists("cntct_id") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_cntct_id=<? value("cntct_id") ?>))\n<? endif ?>\n<? if exists("startStartDate") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_start_date >= <? value("startStartDate") ?>))\n<? endif ?>\n<? if exists("startEndDate") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_start_date <= <? value("startEndDate") ?>))\n<? endif ?>\n<? if exists("dueStartDate") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_due_date >= <? value("dueStartDate") ?>))\n<? endif ?>\n<? if exists("dueEndDate") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_due_date <= <? value("dueEndDate") ?>))\n<? endif ?>\n<? if exists("assignedStartDate") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_assigned_date >= <? value("assignedStartDate") ?>))\n<? endif ?>\n<? if exists("assignedEndDate") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_assigned_date <= <? value("assignedEndDate") ?>))\n<? endif ?>\n<? if exists("completedStartDate") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_completed_date >= <? value("completedStartDate") ?>))\n<? endif ?>\n<? if exists("completedEndDate") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_completed_date <= <? value("completedEndDate") ?>))\n<? endif ?>\n<? if not exists("showComplete") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE prj_status <> 'C')\n<? endif ?>\n<? if exists("prj_id") ?>\n  AND (project=<? value("prj_id") ?>)\n<? endif ?>\n<? if exists("prjtype_id") ?>\n  AND project IN (SELECT prj_id FROM prj WHERE (prj_prjtype_id=<? value("prjtype_id") ?>))\n<? endif ?>\n<? if exists("project_task") ?>\n  AND project IN (SELECT DISTINCT prjtask_prj_id FROM prjtask where ((prjtask_number ~* <? value("project_task") ?>)\n\t\t\t\t\t\tOR (prjtask_name ~* <? value("project_task") ?>)\n\t\t\t\t\t\tOR (prjtask_descrip ~* <? value("project_task") ?>)))\n<? endif ?>\n<? if exists("cohead_id") ?>\n  AND project IN (SELECT cohead_prj_id FROM cohead where cohead_id=<? value("cohead_id") ?>)\n<? endif ?>\n<? if exists("wo_id") ?>\n  AND project IN (SELECT wo_prj_id FROM wo WHERE wo_id=<? value("wo_id") ?>)\n<? endif ?>\n<? if exists("pohead_id") ?>\n  AND project IN (SELECT poitem_prj_id FROM pohead JOIN poitem ON (pohead_id=poitem_pohead_id)\n\t\t\tWHERE pohead_id=<? value("pohead_id") ?>)\n<? endif ?>\n\nORDER BY project, section, subtype, type, id;\n	admin	2015-10-01	0
278	prospects	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: prospects\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT \n  prospect.*,\n  cntct.*, addr.*\nFROM prospect \n  LEFT OUTER JOIN cntct ON (prospect_cntct_id=cntct_id) \n  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id) \nWHERE true\n<? if not exists("showInactive") ?> \n  AND prospect_active \n<? endif ?>\n<? if exists("owner_username") ?> \n  AND (prospect_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (prospect_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\n<? if exists("search_pattern") ?>\n  AND ((prospect_number ~* <? value("search_pattern") ?>)\n       OR (prospect_name ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_first_name,'') || ' ' || COALESCE(cntct_last_name,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_phone,'') || ' ' || COALESCE(cntct_phone2,'') || ' ' || COALESCE(cntct_fax,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(cntct_email,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_line1,'') || ' ' || COALESCE(addr_line2,'') || ' ' || COALESCE(addr_line3,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_city,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_state,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_postalcode,'') ~* <? value("search_pattern") ?>)\n       OR (COALESCE(addr_country,'') ~* <? value("search_pattern") ?>))\n<? endif ?>\n<? if exists("prospect_number_pattern") ?>\n  AND (prospect_number ~* <? value("prospect_number_pattern") ?>)\n<? endif ?>\n<? if exists("prospect_name_pattern") ?>\n  AND (prospect_name ~* <? value("prospect_name_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_name_pattern") ?>\n  AND (COALESCE(cntct_first_name,'') || ' ' || COALESCE(cntct_last_name,'') ~* <? value("cntct_name_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_phone_pattern") ?>\n  AND (COALESCE(cntct_phone,'') || ' ' || COALESCE(cntct_phone2,'') || ' ' || COALESCE(cntct_fax,'') ~* <? value("cntct_phone_pattern") ?>)\n<? endif ?>\n<? if exists("cntct_email_pattern") ?>\n  AND (COALESCE(cntct_email,'') ~* <? value("cntct_email_pattern") ?>)\n<? endif ?>\n<? if exists("addr_street_pattern") ?>\n  AND (COALESCE(addr_line1,'') || ' ' || COALESCE(addr_line2,'') || ' ' || COALESCE(addr_line3,'') ~* <? value("addr_street_pattern") ?>)\n<? endif ?>\n<? if exists("addr_city_pattern") ?>\n  AND (COALESCE(addr_city,'') ~* <? value("addr_city_pattern") ?>)\n<? endif ?>\n<? if exists("addr_state_pattern") ?>\n  AND (COALESCE(addr_state,'') ~* <? value("addr_state_pattern") ?>)\n<? endif ?>\n<? if exists("addr_postalcode_pattern") ?>\n  AND (COALESCE(addr_postalcode,'') ~* <? value("addr_postalcode_pattern") ?>)\n<? endif ?>\n<? if exists("addr_country_pattern") ?>\n  AND (COALESCE(addr_country,'') ~* <? value("addr_country_pattern") ?>)\n<? endif ?>\n<? if exists("id") ?>\n  AND (prospect_id=<? value("id") ?>\n<? endif ?>\nORDER BY prospect_number; \n	admin	2015-10-01	0
73	purchase	purchaserequests	\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: purchase\n-- Name:  purchaserequests\n-- Notes:\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT pr_id, itemsite_id, itemsite_qtyonhand, itemsite_reorderlevel,\n       qtyNetable(itemsite_id) AS netableqoh, qtyNetable(itemsite_id, FALSE) AS nonnetableqoh,\n       item_number, (item_descrip1 || ' ' || item_descrip2) AS description,\n       pr.*,\n       CASE WHEN (pr_order_type='W') THEN ('W/O ' || ( SELECT formatWoNumber(womatl_wo_id)\n                                                       FROM womatl\n                                                       WHERE (womatl_id=pr_order_id) ) )\n            WHEN (pr_order_type='S') THEN ('S/O ' || (SELECT formatSoNumber(pr_order_id)))\n            WHEN (pr_order_type='F') THEN ('Planned Order')\n            WHEN (pr_order_type='M') THEN <? value("manual") ?>\n            ELSE <? value("other") ?>\n       END AS parent,\n       'qty' AS itemsite_qtyonhand_xtnumericrole, \n       'qty' AS itemsite_reorderlevel_xtnumericrole,\n       'qty' AS pr_qtyreq_xtnumericrole \nFROM pr, itemsite, item \nWHERE ((pr_itemsite_id=itemsite_id)\n   AND (itemsite_item_id=item_id)\n<? if exists("startDate") ?>\n   AND (pr_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n   AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("item_id") ?>\n   AND (itemsite_item_id=<? value("item_id") ?>)\n<? elseif exists("plancode_id") ?>\n   AND (itemsite_plancode_id=<? value("plancode_id") ?>)\n<? elseif exists("plancode_pattern") ?>\n   AND (itemsite_plancode_id IN (SELECT plancode_id FROM\n                                 plancode\n                                 WHERE (plancode_code ~ <? value("plancode_pattern") ?>) ) )\n<? endif ?>\n) \nORDER BY pr_duedate;\n	admin	2015-10-01	0
443	purchaseOrderItems	detail	 used by purchaseOrderItem\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: purchaseOrderItems\n-- Name: detail\n-- Notes: used by purchaseOrderItem\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT pohead_number, pohead_taxzone_id,\n       pohead_curr_id, pohead_orderdate,\n       COALESCE(pohead_cohead_id, -1) AS pohead_cohead_id,\n       poitem_linenumber, poitem_vend_item_number,\n       poitem_vend_item_descrip, poitem_vend_uom,\n       poitem_invvenduomratio, poitem_status,\n       poitem_duedate, poitem_qty_ordered,\n       poitem_qty_received, poitem_unitprice,\n       poitem_freight, poitem_taxtype_id,\n       poitem_tax_recoverable, poitem_comments,\n       poitem_prj_id, poitem_bom_rev_id,\n       poitem_boo_rev_id, poitem_manuf_name,\n       poitem_manuf_item_number, poitem_manuf_item_descrip,\n       COALESCE(poitem_itemsite_id, -1) AS poitem_itemsite_id,\n       COALESCE(poitem_itemsrc_id, -1) AS poitem_itemsrc_id,\n       COALESCE(poitem_expcat_id, -1) AS poitem_expcat_id,\n       COALESCE(poitem_order_id, -1) AS poitem_order_id,\n       CASE WHEN (poitem_order_type='S') THEN TEXT(<? value("sonum") ?>)\n            WHEN (poitem_order_type='W') THEN TEXT(<? value("wonum") ?>)\n            ELSE ''\n       END AS demand_type,\n       CASE WHEN (poitem_order_type='S') THEN formatSoNumber(coitem_id)\n            WHEN (poitem_order_type='W') THEN formatWoNumber(womatl_wo_id)\n            ELSE ''\n       END AS order_number,\n       poitem_unitprice * poitem_qty_ordered AS extended_price,\n       COALESCE(coitem_prcost, 0.0) AS override_cost,\n       contrct_number,\n       itemsrc.*\n  FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)\n              LEFT OUTER JOIN itemsrc ON (itemsrc_id=poitem_itemsrc_id)\n              LEFT OUTER JOIN coitem  ON (poitem_order_type='S' AND coitem_id=poitem_order_id)\n              LEFT OUTER JOIN womatl  ON (poitem_order_type='W' AND womatl_id=poitem_order_id)\n              LEFT OUTER JOIN contrct ON (itemsrc_contrct_id=contrct_id)\n WHERE ( (TRUE)\n<? if exists("poitem_id") ?>\n   AND (poitem_id=<? value("poitem_id") ?>)\n<? endif ?>\n);\n	admin	2015-10-01	0
72	purchaseOrders	detail	 used by dspPosByVendor, dspPOsByDate\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: purchaseOrders\n-- Name: detail\n-- Notes: used by dspPosByVendor, dspPOsByDate\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT pohead_id, pohead_number,\n       warehous_code AS warehousecode,\n       poitem_status, pohead_orderdate,\n       CASE WHEN(poitem_status='C') THEN TEXT(<? value("closed") ?>)\n            WHEN(poitem_status='U') THEN TEXT(<? value("unposted") ?>)\n            WHEN(poitem_status='O'\n                AND (SUM(poitem_qty_received-poitem_qty_returned) > 0) \n                AND (SUM(poitem_qty_ordered)>SUM(poitem_qty_received-poitem_qty_returned))) \n              THEN TEXT(<? value("partial") ?>)\n            WHEN(poitem_status='O'\n                AND (SUM(poitem_qty_received-poitem_qty_returned) > 0) \n                AND (SUM(poitem_qty_ordered)<=SUM(poitem_qty_received-poitem_qty_returned))) \n              THEN TEXT(<? value("received") ?>)\n            WHEN(poitem_status='O') THEN TEXT(<? value("open") ?>)\n            ELSE poitem_status\n       END AS poitem_status_qtdisplayrole,\n<? if exists("byDate") ?>\n       vend_name,\n       MIN(poitem_duedate) AS minDueDate,\n       CASE WHEN (MIN(poitem_duedate) < CURRENT_DATE) THEN 'error'\n       END AS minDueDate_qtforegroundrole,\n<? else ?>\n       vend_number,\n<? endif ?>\n<? if exists("byReceiptDate") ?>\n       MIN(date(recv_date)) AS sortDate,\n<? elseif exists("byDueDate") ?>\n       MIN(poitem_duedate) AS sortDate,\n<? else ?>\n       pohead_orderdate AS sortDate,\n<? endif ?>\n       CASE WHEN (MIN(poitem_duedate) < CURRENT_DATE) THEN 'error' END AS sortDate_qtforegroundrole,\n-- Report formatting\n  formatDate(pohead_orderdate) AS f_orderdate,\n  formatDate(MIN(poitem_duedate)) AS f_duedate, \n       CASE WHEN(poitem_status='C') THEN TEXT(<? value("closed") ?>)\n            WHEN(poitem_status='U') THEN TEXT(<? value("unposted") ?>)\n            WHEN(poitem_status='O'\n                AND (SUM(poitem_qty_received-poitem_qty_returned) > 0) \n                AND (SUM(poitem_qty_ordered)>SUM(poitem_qty_received-poitem_qty_returned))) \n              THEN TEXT(<? value("partial") ?>)\n            WHEN(poitem_status='O'\n                AND (SUM(poitem_qty_received-poitem_qty_returned) > 0) \n                AND (SUM(poitem_qty_ordered)<=SUM(poitem_qty_received-poitem_qty_returned))) \n              THEN TEXT(<? value("received") ?>)\n            WHEN(poitem_status='O') THEN TEXT(<? value("open") ?>)\n            ELSE poitem_status\n       END AS f_status\n-- End Report formatting\n  FROM vendinfo, poitem,\n<? if exists("byReceiptDate") ?>\n       recv,\n<? endif ?>\n       pohead LEFT OUTER JOIN whsinfo ON (pohead_warehous_id=warehous_id)\n WHERE ((poitem_pohead_id=pohead_id)\n   AND  (pohead_vend_id=vend_id)\n<? if exists("byReceiptDate") ?>\n   AND  (recv_itemsite_id=poitem_itemsite_id)\n   AND  (recv_order_number=pohead_number)\n   AND  (date(recv_date) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n   AND  (recv_order_type='PO')\n<? elseif exists("byDueDate") ?>\n   AND  (poitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? else ?>\n   AND  (pohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n<? if exists("vend_id") ?>\n   AND  (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n   AND  (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n   AND (vend_vendtype_id IN (SELECT vendtype_id\n                               FROM vendtype\n                              WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n<? if exists("warehous_id") ?>\n   AND (pohead_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if not exists("showClosed") ?>\n   AND (poitem_status!='C')\n<? endif ?>\n<? if exists("agentUsername") ?>\n   AND (pohead_agent_username=<? value("agentUsername") ?>)\n<? endif ?>\n<? if exists("descrip_pattern") ?>\n  AND ((poitem_vend_item_descrip ~* <? value("descrip_pattern") ?>)\n    OR (poitem_itemsite_id IN (\n      SELECT itemsite_id\n        FROM itemsite, item\n       WHERE ((itemsite_item_id=item_id)\n         AND  ((item_descrip1 ~* <? value("descrip_pattern") ?>)\n            OR (item_descrip2 ~* <? value("descrip_pattern") ?>)))\n                              )))\n<? endif ?>\n\n)\nGROUP BY pohead_id, pohead_number, warehous_code,\n         poitem_status, pohead_orderdate,\n<? if exists("byDate") ?>\n         vend_name \n<? else ?>\n         vend_number\n<? endif ?>\nORDER BY\n<? if exists("byDate") ?>\n  minDueDate\n<? else ?>\n  sortDate\n<? endif ?>;\n	admin	2015-10-01	0
279	qoh	detail	 \n Quantity on Hand By Location\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: qoh\n-- Name: detail\n-- Notes: \n-- Quantity on Hand By Location\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("byLocation") ?>\nSELECT itemloc_id, alt_id, warehous_code, item_number,\n       f_descrip, f_lotserial, uom_name,\n       qoh, reservedqty,\n       'qty' AS qoh_xtnumericrole,\n       'qty' AS reservedqty_xtnumericrole,\n       level AS xtindentrole\nFROM (\n      SELECT itemloc_id, 0 AS alt_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,\n             (item_descrip1 || ' ' || item_descrip2) AS f_descrip,\n             formatlotserialnumber(itemloc_ls_id) AS f_lotserial, uom_name,\n             itemloc_qty AS qoh,\n  <? if exists("EnableSOReservationsByLocation") ?>\n             qtyReservedLocation(itemloc_id) AS reservedqty\n  <? else ?>\n             0 AS reservedqty\n  <? endif ?>\n      FROM itemloc, itemsite, whsinfo, item, uom\n      WHERE ((itemloc_itemsite_id=itemsite_id)\n         AND (itemsite_item_id=item_id)\n         AND (item_inv_uom_id=uom_id)\n         AND (itemsite_warehous_id=warehous_id)\n         AND (itemloc_location_id=<? value("location_id") ?>))\n      UNION\n      SELECT -1 AS itemloc_id, 0 AS alt_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,\n             (item_descrip1 || ' ' || item_descrip2) AS f_descrip,\n             <? value("na") ?> AS f_lotserial, uom_name,\n             itemsite_qtyonhand AS qoh,\n             0 AS reservedqty\n      FROM itemsite, whsinfo, item, uom\n      WHERE ((itemsite_item_id=item_id)\n         AND (item_inv_uom_id=uom_id)\n         AND (itemsite_warehous_id=warehous_id)\n         AND (NOT itemsite_loccntrl)\n         AND (itemsite_location_id=<? value("location_id") ?>))\n  <? if exists("EnableSOReservationsByLocation") ?>\n      UNION\n      SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,\n             (reserve_demand_type || '-' || formatSOItemNumber(reserve_demand_id)) AS f_descrip,\n             '' AS f_lotserial, '' AS uom_name,\n             NULL AS qoh,\n             reserve_qty AS reservedqty\n      FROM reserve, itemloc, itemsite, item\n      WHERE ((reserve_supply_id=itemloc_id)\n         AND (reserve_supply_type='I')\n         AND (itemsite_id=itemloc_itemsite_id)\n         AND(item_id=itemsite_item_id)\n         AND(itemloc_location_id=<? value("location_id") ?>))\n  <? endif ?>\n  <? if exists("ShowDemand") ?>\n      UNION\n      SELECT itemloc_id, coitem_cohead_id AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,\n             (<? value("so") ?>|| '-' || formatSOItemNumber(coitem_id)) AS f_descrip,\n             '' AS f_lotserial, '' AS uom_name,\n             itemUOMtoUOM(item_id, coitem_qty_uom_id, NULL, (coitem_qtyord - coitem_qtyshipped - qtyAtShipping(coitem_id))) AS qoh,\n             0 AS reservedqty\n      FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)\n                   JOIN item ON (item_id=itemsite_item_id)\n                   JOIN coitem ON (coitem_itemsite_id=itemloc_itemsite_id AND coitem_status='O')\n      WHERE ((coitem_qtyord > (coitem_qtyshipped + qtyAtShipping(coitem_id)))\n         AND(itemloc_location_id=<? value("location_id") ?>))\n      UNION\n      SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,\n             (<? value("wo") ?>|| '-' || formatWONumber(womatl_wo_id)) AS f_descrip,\n             '' AS f_lotserial, '' AS uom_name,\n             (womatl_qtyreq - womatl_qtyiss) AS qoh,\n             0 AS reservedqty\n      FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)\n                   JOIN item ON (item_id=itemsite_item_id)\n                   JOIN womatl ON (womatl_itemsite_id=itemloc_itemsite_id)\n      WHERE ((womatl_qtyreq > womatl_qtyiss)\n         AND(itemloc_location_id=<? value("location_id") ?>))\n      UNION\n      SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,\n             (<? value("to") ?>|| '-' || formatTONumber(toitem_id)) AS f_descrip,\n             '' AS f_lotserial, '' AS uom_name,\n             (toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS qoh,\n             0 AS reservedqty\n      FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)\n                   JOIN item ON (item_id=itemsite_item_id)\n                   JOIN toitem ON (toitem_item_id=item_id AND toitem_status='O')\n                   JOIN tohead ON (tohead_id=toitem_tohead_id AND tohead_src_warehous_id=itemsite_warehous_id)\n      WHERE ((toitem_qty_ordered > (toitem_qty_shipped + qtyAtShipping('TO', toitem_id)))\n         AND(itemloc_location_id=<? value("location_id") ?>))\n  <? endif ?>\n     ) AS data\nORDER BY\n         sortkey, itemloc_id, level;\n<? else ?>\n<? if exists("asOf") ?>\nSELECT forwardupdateinvbalance(invbal_id)\nFROM (\n      SELECT DISTINCT ON (itemsite_id) invbal_id\n      FROM invbal, itemsite, item, whsinfo, classcode, uom, costcat, period\n      WHERE ((invbal_dirty)\n         AND (invbal_period_id=period_id)\n         AND (itemsite_item_id=item_id)\n         AND (itemsite_warehous_id=warehous_id)\n         AND (itemsite_active)\n         AND (item_inv_uom_id=uom_id)\n         AND (item_classcode_id=classcode_id)\n         AND (itemsite_costcat_id=costcat_id)\n  <? if exists("item_id") ?>\n         AND (itemsite_item_id=<? value("item_id") ?>)\n  <? endif ?>\n  <? if exists("classcode_id") ?>\n         AND (classcode_id=<? value("classcode_id") ?>)\n  <? endif ?>\n  <? if exists("classcode_pattern") ?>\n         AND (classcode_id IN (SELECT classcode_id\n                               FROM classcode\n                               WHERE classcode_code ~ <? value("classcode_pattern") ?>))\n  <? endif ?>\n  <? if exists("costcat_id") ?>\n         AND (costcat_id=<? value("costcat_id") ?>)\n  <? endif ?>\n  <? if exists("costcat_pattern") ?>\n         AND (costcat_id IN (SELECT costcat_id\n                               FROM costcat\n                               WHERE costcat_code ~ <? value("costcat_pattern") ?>))\n  <? endif ?>\n  <? if exists("itemgrp_id") ?>\n         AND (item_id IN (SELECT itemgrpitem_item_id\n                          FROM itemgrpitem\n                          WHERE (itemgrpitem_itemgrp_id=<? value("itemgrp_id") ?>)))\n  <? endif ?>\n  <? if exists("itemgrp_pattern") ?>\n         AND (item_id IN (SELECT itemgrpitem_item_id\n                          FROM itemgrpitem, itemgrp\n                          WHERE ((itemgrpitem_itemgrp_id=itemgrp_id)\n                             AND (itemgrp_name ~ <? value("itemgrp_pattern") ?>))))\n  <? endif ?>\n  <? if exists("showPositive") ?>\n       AND (itemsite_qtyonhand > 0)\n  <? elseif exists("showNegative") ?>\n       AND (itemsite_qtyonhand < 0)\n  <? endif ?>\n  <? if exists("warehous_id") ?>\n         AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n  <? endif ?>\n            )\n       ORDER BY itemsite_id, period_start\n     ) AS data\n;\n<? endif ?>\n--  Quantity on Hand\nSELECT itemsite_id, detail,warehous_code,\n       classcode_code, item_number, uom_name,\n       costcat_code,\n       item_descrip1, item_descrip2,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n       defaultlocation,\n       reorderlevel, formatQty(reorderlevel) AS f_reorderlevel,\n       qoh, formatQty(qoh) AS f_qoh,\n       availqoh, formatQty(availqoh) AS f_availqoh,\n       nonavailqoh, formatQty(nonavailqoh) AS f_nonavailqoh,\n       netqoh, formatQty(netqoh) AS f_netqoh,\n       nonnetqoh, formatQty(nonnetqoh) AS f_nonnetqoh,\n       cost, (cost * qoh) AS value,\n       (cost * availqoh) AS availvalue,\n       (cost * nonavailqoh) AS nonavailvalue,\n       (cost * netqoh) AS netvalue,\n       (cost * nonnetqoh) AS nonnetvalue,\n       CASE WHEN(itemsite_costmethod='A') THEN 'Average'\n            WHEN(itemsite_costmethod='S') THEN 'Standard'\n            WHEN(itemsite_costmethod='J') THEN 'Job'\n            WHEN(itemsite_costmethod='N') THEN 'None'\n         ELSE 'UNKNOWN'\n       END AS costmethod,\n  <? if exists("showValue") ?>\n       formatMoney(cost) AS f_cost, (cost * qoh) AS f_value,\n       formatMoney(cost * availqoh) AS f_availvalue,\n       formatMoney(cost * nonavailqoh) AS f_nonavailvalue,\n       formatMoney(cost * netqoh) AS f_netvalue,\n       formatMoney(cost * nonnetqoh) AS f_nonnetvalue,\n       CASE WHEN(itemsite_costmethod='A') THEN 'Average'\n            WHEN(itemsite_costmethod='S') THEN 'Standard'\n            WHEN(itemsite_costmethod='J') THEN 'Job'\n            WHEN(itemsite_costmethod='N') THEN 'None'\n         ELSE 'UNKNOWN'\n       END AS f_costmethod,\n  <? endif ?>\n       'qty' AS reorderlevel_xtnumericrole,\n       'qty' AS qoh_xtnumericrole,\n       'qty' AS availqoh_xtnumericrole,\n       'qty' AS nonavailqoh_xtnumericrole,\n       'qty' AS netqoh_xtnumericrole,\n       'qty' AS nonnetqoh_xtnumericrole,\n       0 AS qoh_xttotalrole,\n       0 AS availqoh_xttotalrole,\n       0 AS nonavailqoh_xttotalrole,\n       0 AS netqoh_xttotalrole,\n       0 AS nonnetqoh_xttotalrole,\n       'cost' AS cost_xtnumericrole,\n       'curr' AS value_xtnumericrole,\n       'curr' AS availvalue_xtnumericrole,\n       'curr' AS nonavailvalue_xtnumericrole,\n       'curr' AS netvalue_xtnumericrole,\n       'curr' AS nonnetvalue_xtnumericrole,\n       0 AS value_xttotalrole,\n       0 AS availvalue_xttotalrole,\n       0 AS nonavailvalue_xttotalrole,\n       0 AS netvalue_xttotalrole,\n       0 AS nonnetvalue_xttotalrole,\n       <? value("na") ?> AS availqoh_xtnullrole,\n       <? value("na") ?> AS nonavailqoh_xtnullrole,\n       <? value("na") ?> AS availvalue_xtnullrole,\n       <? value("na") ?> AS nonavailvalue_xtnullrole,\n       <? value("na") ?> AS netqoh_xtnullrole,\n       <? value("na") ?> AS nonnetqoh_xtnullrole,\n       <? value("na") ?> AS netvalue_xtnullrole,\n       <? value("na") ?> AS nonnetvalue_xtnullrole,\n       CASE WHEN (qoh < 0) THEN 'error' END AS qoh_qtforegroundrole,\n       CASE WHEN (reorderlevel > qoh) THEN 'warning' END AS qoh_qtforegroundrole\nFROM (\n      SELECT itemsite_id, itemsite_loccntrl, itemsite_costmethod,\n             ((itemsite_loccntrl) OR (itemsite_controlmethod IN ('L', 'S')) ) AS detail,\n             classcode_code, item_number, uom_name, item_descrip1, item_descrip2,\n             costcat_code, \n             CASE WHEN (NOT useDefaultLocation(itemsite_id)) THEN <? value("none") ?>\n               ELSE defaultLocationName(itemsite_id)\n             END AS defaultlocation,\n             warehous_code,\n             CASE WHEN(itemsite_useparams) THEN itemsite_reorderlevel ELSE 0.0 END AS reorderlevel,\n  <? if exists("asOf") ?>\n             COALESCE(invbal_qoh_ending,0) AS qoh,\n             COALESCE(invbal_qoh_ending,0) AS availqoh,\n             COALESCE(invbal_nn_ending,0) AS nonavailqoh,\n             COALESCE(invbal_qoh_ending,0) AS netqoh,\n             COALESCE(invbal_nn_ending,0) AS nonnetqoh,\n  <? else ?>\n             itemsite_qtyonhand AS qoh,\n             qtyAvailable(itemsite_id) AS availqoh,\n             qtyAvailable(itemsite_id, FALSE) AS nonavailqoh,\n             qtyNetable(itemsite_id) AS netqoh,\n             qtyNetable(itemsite_id, FALSE) AS nonnetqoh,\n  <? endif ?>\n  <? if exists("useStandardCosts") ?>\n             stdcost(item_id) AS cost\n  <? elseif exists("useActualCosts") ?>\n             actcost(item_id) AS cost\n  <? else ?>\n    <? if exists("asOf") ?>\n             COALESCE((invbal_value_ending / CASE WHEN(invbal_qoh_ending=0) THEN 1\n                                                  ELSE invbal_qoh_ending END),0) AS cost\n    <? else ?>\n             (itemsite_value / CASE WHEN(itemsite_qtyonhand=0) THEN 1\n                                    ELSE itemsite_qtyonhand END) AS cost\n    <? endif ?>\n  <? endif ?>\n      FROM item, whsinfo, classcode, uom, costcat, itemsite\n  <? if exists("asOf") ?>\n        LEFT OUTER JOIN invbal ON ((itemsite_id=invbal_itemsite_id)\n                               AND (invbal_period_id=<? value("asOf") ?>))\n  <? endif ?>\n      WHERE ((itemsite_item_id=item_id)\n         AND (itemsite_warehous_id=warehous_id)\n         AND (itemsite_active)\n         AND (item_inv_uom_id=uom_id)\n         AND (item_classcode_id=classcode_id)\n         AND (itemsite_costcat_id=costcat_id)\n  <? if exists("item_id") ?>\n         AND (itemsite_item_id=<? value("item_id") ?>)\n  <? endif ?>\n  <? if exists("classcode_id") ?>\n         AND (classcode_id=<? value("classcode_id") ?>)\n  <? endif ?>\n  <? if exists("classcode_pattern") ?>\n         AND (classcode_id IN (SELECT classcode_id\n                               FROM classcode\n                               WHERE classcode_code ~ <? value("classcode_pattern") ?>))\n  <? endif ?>\n  <? if exists("costcat_id") ?>\n         AND (costcat_id=<? value("costcat_id") ?>)\n  <? endif ?>\n  <? if exists("costcat_pattern") ?>\n         AND (costcat_id IN (SELECT costcat_id\n                               FROM costcat\n                               WHERE costcat_code ~ <? value("costcat_pattern") ?>))\n  <? endif ?>\n  <? if exists("itemgrp_id") ?>\n         AND (item_id IN (SELECT itemgrpitem_item_id\n                          FROM itemgrpitem\n                          WHERE (itemgrpitem_itemgrp_id=<? value("itemgrp_id") ?>)))\n  <? endif ?>\n  <? if exists("itemgrp_pattern") ?>\n         AND (item_id IN (SELECT itemgrpitem_item_id\n                          FROM itemgrpitem, itemgrp\n                          WHERE ((itemgrpitem_itemgrp_id=itemgrp_id)\n                             AND (itemgrp_name ~ <? value("itemgrp_pattern") ?>))))\n  <? endif ?>\n  <? if exists("showPositive") ?>\n    <? if exists("asOf") ?>\n       AND (COALESCE(invbal_qoh_ending,0) > 0)\n    <? else ?>\n       AND (itemsite_qtyonhand > 0)\n    <? endif ?>\n  <? elseif exists("showNegative") ?>\n    <? if exists("asOf") ?>\n       AND (COALESCE(invbal_qoh_ending,0) < 0)\n    <? else ?>\n       AND (itemsite_qtyonhand < 0)\n    <? endif ?>\n  <? endif ?>\n  <? if exists("warehous_id") ?>\n         AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n  <? endif ?>\n            )\n     ) AS data\nORDER BY warehous_code, item_number;\n<? endif ?>\n	admin	2015-10-01	0
74	quoteItems	detail	 used by dspQuotesByItem\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: quoteItems\n-- Name: detail\n-- Notes: used by dspQuotesByItem\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT quitem_id, quhead_id,\n       quitem.*, quhead.*,\n       COALESCE(cust_number, prospect_number) AS cust_number,\n       COALESCE(cust_name, prospect_name) AS cust_name,\n       'qty' AS quitem_qtyord_xtnumericrole\nFROM quitem JOIN quhead ON (quhead_id=quitem_quhead_id)\n            LEFT OUTER JOIN custinfo ON (cust_id=quhead_cust_id)\n            LEFT OUTER JOIN prospect ON (prospect_id=quhead_cust_id)\n            JOIN itemsite ON (itemsite_id=quitem_itemsite_id)\n            JOIN site() ON (warehous_id=itemsite_warehous_id)\nWHERE ( (1=1)\n<? if exists("item_id") ?>\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("showConverted") ?>\n  AND (quhead_status IN ('C','O'))\n<? else ?>\n  AND (quhead_status NOT IN ('C','X'))\n<? endif ?>\n<? if exists("startDate") ?>\n  AND  (quhead_quotedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? endif ?>\n      )\nORDER BY quhead_number;\n\n	admin	2015-10-01	0
483	quoteItems	list	 used by salesOrder\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: quoteItems\n-- Name: list\n-- Notes: used by salesOrder\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT quitem_id,\n       quitem_linenumber AS f_linenumber,\n       0 AS coitem_subnumber, item_type,\n       item_number, (item_descrip1 || ' ' || item_descrip2) AS description,\n       warehous_code, '' AS enhanced_status,\n       quitem_scheddate AS coitem_scheddate,\n       quom.uom_name AS qty_uom,\n       quitem_qtyord AS coitem_qtyord,\n       0 AS qtyshipped, 0 AS qtyatshipping, 0 AS balance,\n       puom.uom_name AS price_uom,\n       quitem_price AS coitem_price,\n       ROUND((quitem_qtyord * quitem_qty_invuomratio) *\n             (quitem_price / quitem_price_invuomratio),2) AS extprice,\n       quitem_custprice AS coitem_custprice,\n       CASE WHEN (quitem_custprice = 0.0) THEN 100.0\n            ELSE ((1.0 - (quitem_price / quitem_custprice)) * 100.0)\n       END AS discountfromcust,\n       quitem_unitcost AS coitem_unitcost,\n       CASE WHEN (quitem_price = 0.0) THEN 0.0\n            ELSE ROUND((quitem_qtyord * quitem_qty_invuomratio) *\n                 ((quitem_price / quitem_price_invuomratio) - (quitem_unitcost / quitem_price_invuomratio)),2)\n       END AS margin,\n       CASE WHEN (quitem_price = 0.0) THEN 0.0\n            ELSE ((quitem_price - quitem_unitcost) / quitem_price)\n       END AS marginpercent,\n       CASE WHEN (quitem_custpn != '') THEN quitem_custpn\n            ELSE item_number\n       END AS item_number_cust,\n       (quitem_qtyord * quitem_qty_invuomratio * item_prodweight) AS prodweight,\n       (quitem_qtyord * quitem_qty_invuomratio * item_packweight) AS packweight,\n       qtyAvailable(itemsite_id) AS availableqoh,\n       'qty' AS coitem_qtyord_xtnumericrole,\n       'qty' AS qtyshipped_xtnumericrole,\n       'qty' AS balance_xtnumericrole,\n       'qty' AS qtyatshipping_xtnumericrole,\n       'qty' AS prodweight_xtnumericrole,\n       'qty' AS packweight_xtnumericrole,\n       'qty' AS availableqoh_xtnumericrole,\n       'salesprice' AS coitem_price_xtnumericrole,\n       'cost' AS coitem_unitcost_xtnumericrole,\n       'curr' AS margin_xtnumericrole,\n       'percent' AS marginpercent_xtnumericrole,\n       'curr' AS extprice_xtnumericrole\n  FROM item, uom AS quom, uom AS puom,\n       quitem LEFT OUTER JOIN (itemsite JOIN whsinfo ON (itemsite_warehous_id=warehous_id)) ON (quitem_itemsite_id=itemsite_id)\n WHERE ( (quitem_item_id=item_id)\n   AND   (quitem_qty_uom_id=quom.uom_id)\n   AND   (quitem_price_uom_id=puom.uom_id)\n   AND   (quitem_quhead_id=<? value("quhead_id") ?>) )\nORDER BY quitem_linenumber;	admin	2015-10-01	0
75	quotes	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: quotes\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT quhead.*, firstline(quhead_ordercomments) AS notes, quhead_id AS id,\n       calcQuoteAmt(quhead_id) AS ordertotal,\n       'extprice' AS ordertotal_xtnumericrole,\n       <? foreach("char_id_text_list") ?>\n         charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,\n       <? endforeach ?>\n       <? foreach("char_id_list_list") ?>\n         charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,\n       <? endforeach ?>\n       <? foreach("char_id_date_list") ?>\n         charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,\n       <? endforeach ?>\n       CASE WHEN quhead_status = 'O' THEN <? value("open") ?>\n            WHEN quhead_status = 'C' THEN <? value("converted") ?>\n            ELSE <? value("undefined") ?>\n       END AS quhead_status_qtdisplayrole,\n<? if exists("customersOnly") ?>\n       cust_id, cust_number, cust_name,\n<? endif ?>\n       ( SELECT MIN(quitem_scheddate)\n           FROM quitem\n          WHERE (quitem_quhead_id=quhead_id) ) AS min_scheddate,\n  CASE WHEN (quhead_expire < current_date) THEN\n    'error'\n   END AS quhead_expire_qtforegroundrole\nFROM quhead\n<? if not exists("customersOnly") ?>\n  LEFT OUTER \n<? endif ?>\n  JOIN custinfo ON (quhead_cust_id=cust_id)\n<? foreach("char_id_text_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> \n             ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='QU') \n            AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=quhead_id)\n            AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> \n             ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_list_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> \n             ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='QU') \n            AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=quhead_id)\n            AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> \n             ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)\n<? endforeach ?>\n<? foreach("char_id_date_list") ?>\n  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> \n             ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='QU') \n            AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=quhead_id)\n            AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))\n  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> \n             ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)\n<? endforeach ?>\nWHERE (checkQuoteSitePrivs(quhead_id, <? value("warehous_id") ?>))\n<? if exists("owner_username") ?> \n  AND (quhead_owner_username=<? value("owner_username") ?>) \n<? elseif exists("owner_usr_pattern") ?>\n  AND (quhead_owner_username ~ <? value("owner_usr_pattern") ?>) \n<? endif ?>\n<? if exists("showConverted") ?>\n  AND (quhead_status IN ('C','O'))\n<? else ?>\n  AND (quhead_status NOT IN ('C','X'))\n<? endif ?>\n<? if not exists("showExpired") ?>\n  AND ((quhead_expire IS NULL) OR (quhead_expire >= CURRENT_DATE))\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND  (quhead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND  (cust_custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND  (cust_custtype_id IN (SELECT custtype_id FROM custtype WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n<? if exists("poNumber") ?>\n  AND  (quhead_custponumber=<? value("poNumber") ?>)\n<? endif ?>\n<? if exists("startDate") ?>\n  AND  (quhead_quotedate >= <? value("startDate") ?> )\n<? endif ?>\n<? if exists("endDate") ?>\n  AND  (quhead_quotedate <= <? value("endDate") ?>)\n<? endif ?>\n<? if exists("salesrep_id") ?>\n  AND  (quhead_salesrep_id = <? value("salesrep_id") ?>)\n<? endif ?>\n<? if exists("id") ?>\n  AND  (quhead_id = <? value("id") ?>)\n<? endif ?>\n<? literal("charClause") ?>\n<? if exists("orderByCust") ?>\nORDER BY cust_number, quhead_number;\n<? else ?>\nORDER BY quhead_number;\n<? endif ?>\n\n	admin	2015-10-01	0
76	receipt	detail	 used by enterPoReceipt\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: receipt\n-- Name: detail\n-- Notes: used by enterPoReceipt\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("pohead_id") ?>\nSELECT poitem_id AS orderitem_id, COALESCE(poitem_itemsite_id,-1) AS itemsite_id, poitem_linenumber AS linenumber,\n       poitem_duedate AS duedate,\n       COALESCE(item_number, <? value("nonInventory") ?>) AS item_number,\n       CASE WHEN (LENGTH(TRIM(BOTH '    ' FROM poitem_vend_item_descrip)) <= 0) THEN\n                 (item_descrip1 || ' ' || item_descrip2)\n            ELSE poitem_vend_item_descrip\n       END AS itemdescription,\n       COALESCE(uom_name, <? value("na") ?>) AS inv_uom,\n       warehous_code,\n       poitem_vend_item_number AS vend_item_number,\n       poitem_vend_uom AS vend_uom,\n       poitem_manuf_name AS manuf_name,\n       poitem_manuf_item_number AS manuf_item_number,\n       poitem_qty_ordered AS qty_ordered,\n       poitem_qty_received AS qty_received,\n       poitem_qty_returned AS qty_returned,\n       qtyToReceive(<? value("ordertype") ?>, poitem_id) AS qty_toreceive,\n       'qty' AS qty_ordered_xtnumericrole,\n       'qty' AS qty_received_xtnumericrole,\n       'qty' AS qty_returned_xtnumericrole,\n       'qty' AS qty_toreceive_xtnumericrole\nFROM poitem \n  LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id) \n<? if exists("selectedOnly") ?>\n  LEFT OUTER JOIN usrsite ON (itemsite_warehous_id=usrsite_warehous_id) \n<? endif ?>\n  LEFT OUTER JOIN item ON (itemsite_item_id=item_id) \n  LEFT OUTER JOIN uom ON (item_inv_uom_id=uom_id)\n  LEFT OUTER JOIN whsinfo ON (itemsite_warehous_id=warehous_id)\n  LEFT OUTER JOIN itemsrc ON (itemsrc_id=poitem_itemsrc_id)\nWHERE ( (poitem_status <> 'C')\n<? if exists("selectedOnly") ?>\n AND (usrsite_username=getEffectiveXtUser()) \n<? endif ?>\n<? if exists("bc") ?>\n AND ( (item_number=<? value("bc") ?>) OR\n       (item_upccode=<? value("bc") ?>) OR \n       (poitem_vend_item_number=<? value("bc") ?>) OR \n       (poitem_manuf_item_number=<? value("bc") ?>) OR \n       (COALESCE(itemsrc_upccode, '')=<? value("bc") ?>) ) \n<? endif ?>\n AND (poitem_pohead_id=<? value("pohead_id") ?>) )\nORDER BY poitem_linenumber;\n<? elseif exists("rahead_id") ?>\nSELECT raitem_id AS orderitem_id, itemsite_id, raitem_linenumber AS linenumber,\n       rahead_expiredate AS duedate,\n       COALESCE(item_number, <? value("nonInventory") ?>) AS item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescription,\n       COALESCE(iu.uom_name, <? value("na") ?>) AS inv_uom,\n       warehous_code,\n       '' AS vend_item_number,\n       ru.uom_name AS vend_uom,\n       '' AS manuf_name,\n       '' AS manuf_item_number,\n       raitem_qtyauthorized AS qty_ordered,\n       raitem_qtyreceived AS qty_received,\n       0 AS qty_returned,\n       qtyToReceive(<? value("ordertype") ?>, raitem_id) AS qty_toreceive,\n       'qty' AS qty_ordered_xtnumericrole,\n       'qty' AS qty_received_xtnumericrole,\n       'qty' AS qty_returned_xtnumericrole,\n       'qty' AS qty_toreceive_xtnumericrole\n\nFROM rahead, raitem \n  LEFT OUTER JOIN \n     ( itemsite \n<? if exists("selectedOnly") ?>\n       JOIN usrsite ON (itemsite_warehous_id=usrsite_warehous_id) \n<? endif ?>\n       JOIN item ON (itemsite_item_id=item_id) \n       JOIN uom iu ON (item_inv_uom_id=uom_id)\n       JOIN whsinfo ON (itemsite_warehous_id=warehous_id)\n     ) ON (raitem_itemsite_id=itemsite_id), uom ru\nWHERE ( (raitem_status <> 'C')\n AND (item_type <> 'K')\n AND (raitem_qtyauthorized > 0)\n AND (raitem_disposition IN ('R','P','V'))\n AND (raitem_rahead_id=rahead_id)\n AND (raitem_qty_uom_id=ru.uom_id)\n<? if exists("selectedOnly") ?>\n AND (usrsite_username=getEffectiveXtUser()) \n<? endif ?>\n<? if exists("bc") ?>\n AND ( (item_number=<? value("bc") ?>) OR\n       (item_upccode=<? value("bc") ?>) )\n<? endif ?>\n AND (rahead_id=<? value("rahead_id") ?>) )\nORDER BY raitem_linenumber;\n<? elseif exists("tohead_id") ?>\nSELECT toitem_id AS orderitem_id, itemsite_id, toitem_linenumber AS linenumber,\n       toitem_duedate AS duedate,\n       COALESCE(item_number, <? value("nonInventory") ?>) AS item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescription,\n       COALESCE(uom_name, <? value("na") ?>) AS inv_uom,\n       warehous_code,\n       ''  AS vend_item_number,\n       toitem_uom AS vend_uom,\n       '' AS manuf_name,\n       '' AS manuf_item_number,\n       toitem_qty_ordered AS qty_ordered,\n       toitem_qty_received AS qty_received,\n       0 AS qty_returned,\n       qtyToReceive(<? value("ordertype") ?>, toitem_id) AS qty_toreceive,\n       'qty' AS qty_ordered_xtnumericrole,\n       'qty' AS qty_received_xtnumericrole,\n       'qty' AS qty_returned_xtnumericrole,\n       'qty' AS qty_toreceive_xtnumericrole\nFROM tohead, itemsite\n<? if exists("selectedOnly") ?>\n       JOIN usrsite ON (itemsite_warehous_id=usrsite_warehous_id) \n<? endif ?>\n, whsinfo, toitem, item JOIN uom ON (item_inv_uom_id=uom_id)\nWHERE ((toitem_item_id=item_id)\n  AND  (tohead_id=toitem_tohead_id)\n  AND  (tohead_dest_warehous_id=itemsite_warehous_id)\n  AND  (tohead_dest_warehous_id=warehous_id)\n  AND  (toitem_item_id=itemsite_item_id)\n  AND  (toitem_status NOT IN ('C','X'))\n  AND  (toitem_qty_shipped > toitem_qty_received)\n<? if exists("selectedOnly") ?>\n AND (usrsite_username=getEffectiveXtUser()) \n<? endif ?>\n<? if exists("bc") ?>\n AND ( (item_number=<? value("bc") ?>) OR\n       (item_upccode=<? value("bc") ?>) )\n<? endif ?>\n  AND  (toitem_tohead_id=<? value("tohead_id") ?>) )\nORDER BY toitem_linenumber;\n<? endif ?>\n	admin	2015-10-01	0
77	receipt	receiveAll	 used by enterPoReceipt, returnAuthorization, shipOrder\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: receipt\n-- Name: receiveAll\n-- Notes: used by enterPoReceipt, returnAuthorization, shipOrder\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists ("shiphead_id") ?>\n  SELECT enterReceipt(<? value("ordertype") ?>,\n                      shipitem_orderitem_id,\n                      shipitem_qty,\n                      (orderitem_freight - orderitem_freight_received),\n                      '',\n                      orderitem_freight_curr_id,\n                      CURRENT_DATE) AS result\n  FROM shipitem, orderitemData(<? value("ordertype") ?>,\n                               <? value("orderid") ?>,\n                               NULL) AS orderitem\n       LEFT OUTER JOIN recv ON ((recv_orderitem_id=orderitem_id)\n                            AND (recv_order_type=orderitem_orderhead_type))\n  <? if exists("EnableReturnAuth") ?>\n       LEFT OUTER JOIN raitem ON ((raitem_id=orderitem_id)\n                              AND ('RA' = orderitem_orderhead_type))\n  <? endif ?>\n  WHERE ( (shipitem_shiphead_id=<? value("shiphead_id") ?>)\n    AND   (shipitem_orderitem_id=orderitem_id)\n  <? if exists("EnableReturnAuth") ?>\n    AND   ((orderitem_orderhead_type != 'RA') OR (raitem_disposition IN (NULL,'R','V','P')))\n  <? endif?>\n        )\n\n<? else ?>\n  SELECT enterReceipt(orderitem_orderhead_type,\n                      orderitem_id,\n<? if exists("tohead_id") ?>\n                      (orderitem_qty_shipped - orderitem_qty_received),\n<? else ?>\n                      (orderitem_qty_ordered - orderitem_qty_received),\n<? endif ?>\n                      (orderitem_freight - orderitem_freight_received),\n                      '',\n                      orderitem_freight_curr_id,\n                      CURRENT_DATE) AS result\n  FROM orderitemData(<? value("ordertype") ?>,\n                     <? value("orderid") ?>,\n                     NULL) AS orderitem\n       LEFT OUTER JOIN recv ON ((recv_orderitem_id=orderitem_id)\n                            AND (recv_order_type=orderitem_orderhead_type))\n<? if exists("EnableReturnAuth") ?>\n       LEFT OUTER JOIN raitem ON ((raitem_id=orderitem_id)\n                              AND ('RA' = orderitem_orderhead_type))\n<? endif ?>\n  WHERE (orderitem_status NOT IN ('C', 'X'))\n<? if exists("tohead_id") ?>\n    AND (orderitem_qty_shipped > orderitem_qty_received)\n<? endif ?>\n<? if exists("EnableReturnAuth") ?>\n    AND (((orderitem_orderhead_type != 'RA') OR (raitem_disposition IN (NULL,'R','V','P'))))\n<? endif ?>\n<? endif ?>\n	admin	2015-10-01	0
297	trialBalances	detail	 used by dspTrialBalances\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: trialBalances\n-- Name: detail\n-- Notes: used by dspTrialBalances\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT accnt_id, period_id, accnt_descrip, trialbal_dirty,\n      period_start, period_end,\n       formatGLAccount(accnt_id) AS account,\n      (trialbal_debits) AS debits,\n       (trialbal_credits) AS credits,\n       trialbal_beginning AS beginning,\n       trialbal_ending AS ending,\n       (trialbal_debits - trialbal_credits) AS diff,\n       CASE WHEN ((trialbal_beginning*-1.0)<0.0) THEN 'CR' END AS beginningsense,\n       CASE WHEN ((trialbal_ending*-1.0)<0.0) THEN 'CR' END AS endingsense,\n       CASE WHEN ((trialbal_debits - trialbal_credits)<0.0) THEN 'CR' END AS diffsense,\n       'curr' AS beginning_xtnumericrole,\n       'curr' AS debits_xtnumericrole,\n       'curr' AS credits_xtnumericrole,\n       'curr' AS ending_xtnumericrole,\n       'curr' AS diff_xtnumericrole,\n       0 AS beginning_xttotalrole,\n       0 AS debits_xttotalrole,\n       0 AS credits_xttotalrole,\n       0 AS ending_xttotalrole,\n       0 AS diff_xttotalrole,\n       CASE WHEN (trialbal_beginning < 0.0) THEN ABS(trialbal_beginning) END AS beginning_qtdisplayrole,\n       CASE WHEN (trialbal_ending < 0.0) THEN ABS(trialbal_ending) END AS ending_qtdisplayrole,\n       CASE WHEN ((trialbal_debits - trialbal_credits) < 0.0) THEN ABS(trialbal_debits - trialbal_credits) END AS diff_qtdisplayrole,\n       CASE WHEN (trialbal_dirty) THEN 'warning' END AS ending_qtforegroundrole\nFROM trialbal, accnt, period\n<? if exists("company_id") ?>\n   ,company\n<? endif ?>\nWHERE ((trialbal_accnt_id=accnt_id)\n   AND (trialbal_period_id=period_id)\n<? if exists("accnt_id") ?>\n   AND (trialbal_accnt_id=<? value("accnt_id") ?>)\n<? endif ?>\n<? if exists("company_id") ?>\n   AND (accnt_company=company_number)\n   AND (company_id=<? value("company_id") ?>)\n<? endif ?>\n<? if exists("period_id") ?>\n   AND (period_id=<? value("period_id") ?>)\n<? endif ?>\n<? if not exists("showZero") ?>\n   AND (abs(trialbal_beginning)+abs(trialbal_ending)+abs(trialbal_debits)+abs(trialbal_credits) > 0)\n<? endif ?>\n      )\nORDER BY period_start, formatGLAccount(accnt_id);\n	admin	2015-10-01	0
78	receivings	detail	 used by dspPoItemReceivingsByDate, dspPoItemReceivingsByItem, dspPoItemReceivingsByVendor\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: receivings\n-- Name: detail\n-- Notes: used by dspPoItemReceivingsByDate, dspPoItemReceivingsByItem, dspPoItemReceivingsByVendor\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT recv_id, 1 AS altid, recv_order_number AS ponumber,\n       vend_name,\n       recv_duedate           AS duedate,\n       recv_date              AS recvdate,\n       recv_vend_item_number  AS itemnumber,\n       recv_vend_item_descrip AS itemdescrip,\n       COALESCE(item_number,\n                (<? value("nonInv") ?> || recv_vend_item_number)) AS venditemnumber,\n       COALESCE(item_descrip1, recv_vend_item_descrip) AS venditemdescrip,\n       CASE WHEN (recv_vohead_id IS NOT NULL) THEN\n         <? value("received") ?>  \n       ELSE <? value("unvouchered") ?>\n       END AS sense,\n       recv_qty               AS qty,\n       currToBase(recv_purchcost_curr_id, recv_purchcost, CAST(recv_date AS DATE)) AS purchcost,\n       CASE WHEN (recv_qty > 0) THEN\n         COALESCE(recv_value,0) / recv_qty\n       ELSE 0 END  AS recvcost,\n       recv_value             AS value,\n       recv_invoiced          AS invoiced,\n       recv_date              AS sortdate,\n<? if exists("isReport") ?>\n       formatDate(recv_duedate)       AS f_duedate,\n       formatDate(recv_date)          AS f_recvdate,\n       formatQty(recv_qty)            AS f_qty,\n  <? if exists("showVariances") ?>\n       formatCost(currToBase(recv_purchcost_curr_id, recv_purchcost, CAST(recv_date AS DATE))) AS f_purchcost,\n       formatCost(CASE WHEN (recv_qty > 0) THEN COALESCE(recv_value,0) / recv_qty\n                       ELSE 0\n                  END)                AS f_recvcost,\n       formatMoney(recv_value)        AS f_value,\n  <? else ?>\n       NULL                           AS f_purchcost,\n       NULL                           AS f_recvcost,\n       NULL                           AS f_value,\n  <? endif ?>\n<? endif ?>\n       'qty'                  AS qty_xtnumericrole,\n       'cost'                 AS purchcost_xtnumericrole,\n       'cost'                 AS recvcost_xtnumericrole,\n       'curr'                 AS value_xtnumericrole,\n        <? value("na") ?>     AS duedate_xtnullrole,\n        <? value("na") ?>     AS purchcost_xtnullrole,\n        <? value("na") ?>     AS recvcost_xtnullrole\nFROM vendinfo, recv LEFT OUTER JOIN\n    (itemsite JOIN\n     item ON (itemsite_item_id=item_id)) ON (recv_itemsite_id=itemsite_id)\nWHERE ( (recv_vend_id=vend_id)\n AND (recv_order_type='PO')\n AND (recv_posted)\n AND (DATE(recv_date) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("vend_id") ?>\n AND (vend_id=<? value ("vend_id") ?>)\n<? endif ?>\n<? if exists("item_id") ?>\n AND (itemsite_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("agentUsername") ?>\n AND (recv_agent_username=<? value("agentUsername") ?>)\n<? endif ?>\n<? if not exists("showUnvouchered") ?>\n AND (recv_vohead_id IS NOT NULL)\n AND (recv_invoiced)\n<? endif ?>\n)\nUNION\nSELECT poreject_id, 2, poreject_ponumber,\n       vend_name,\n       NULL,\n       poreject_date,\n       poreject_vend_item_number,\n       poreject_vend_item_descrip,\n       COALESCE(item_number,\n                (<? value("nonInv") ?> || poreject_vend_item_number)),\n       COALESCE(item_descrip1, poreject_vend_item_descrip),\n       <? value("returned") ?>,\n       poreject_qty,\n       NULL,\n       NULL,\n       poreject_value,\n       poreject_invoiced,\n       poreject_date,\n<? if exists("isReport") ?>\n       NULL                           AS f_duedate,\n       formatDate(poreject_date)      AS f_recvdate,\n       formatQty(poreject_qty)        AS f_qty,\n       NULL                           AS f_purchcost,\n       NULL                           AS f_recvcost,\n       formatMoney(poreject_value)    AS f_value,\n<? endif ?>\n       'qty',\n       'cost',\n       'cost',\n       'curr',\n        <? value("na") ?>     AS duedate_xtnullrole,\n        <? value("na") ?>     AS purchcost_xtnullrole,\n        <? value("na") ?>     AS recvcost_xtnullrole\nFROM vendinfo, poreject LEFT OUTER JOIN\n    (itemsite JOIN\n     item ON (itemsite_item_id=item_id)) ON (poreject_itemsite_id=itemsite_id)\nWHERE ( (poreject_vend_id=vend_id)\n AND (poreject_posted)\n AND (DATE(poreject_date) BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n<? if exists("vend_id") ?>\n AND (vend_id=<? value ("vend_id") ?>)\n<? endif ?>\n<? if exists("item_id") ?>\n AND (itemsite_item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("agentUsername") ?>\n AND (poreject_agent_username=<? value("agentUsername") ?>)\n<? endif ?>\n<? if not exists("showUnvouchered") ?>\n AND (poreject_vohead_id IS NOT NULL)\n AND (poreject_invoiced)\n<? endif ?>\n)\nORDER BY sortdate DESC;\n	admin	2015-10-01	0
280	reorderExceptionsByPlannerCode	detail	 used by dspReorderExceptionsByPlannerCode\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: reorderExceptionsByPlannerCode\n-- Name: detail\n-- Notes: used by dspReorderExceptionsByPlannerCode\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsite_id, itemtype, warehous_code, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n       reorderdate, reorderlevel,\n       (qtyNetable(itemsite_id) - qtyAllocated(itemsite_id, reorderdate) +\n         qtyOrdered(itemsite_id, reorderdate)) AS projavail,\n       'qty' AS reorderlevel_xtnumericrole,\n       'qty' AS projavail_xtnumericrole\nFROM (SELECT itemsite_id,\n             CASE WHEN (item_type IN ('M', 'B', 'T')) THEN 1\n                  WHEN (item_type IN ('P', 'O')) THEN 2\n               ELSE 3\n             END AS itemtype,\n             warehous_code, item_number, item_descrip1,\n             item_descrip2,\n             reorderDate(itemsite_id,\n                         <? value("lookAheadDays") ?>,\n                         <? value("includePlannedOrders") ?>)\n             AS reorderdate,\n             reorderlevel\n      FROM (SELECT itemsite_id, itemsite_item_id,\n                   itemsite_warehous_id,\n                   CASE WHEN(itemsite_useparams) THEN itemsite_reorderlevel\n                     ELSE 0.0\n                   END AS reorderlevel\n            FROM itemsite\n            WHERE ((true)\n            <? if exists("warehous_id") ?>\n               AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n            <? endif ?>\n            <? if exists("plancode_id") ?>\n               AND (itemsite_plancode_id=<? value("plancode_id") ?>)\n            <? elseif exists("plancode_pattern") ?>\n               AND (itemsite_plancode_id IN (SELECT plancode_id\n                                             FROM plancode\n                                             WHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n            <? endif ?>\n                  )\n           ) AS itemsitedata, item, whsinfo\n      WHERE ((itemsite_item_id=item_id)\n         AND (itemsite_warehous_id=warehous_id))\n     ) AS data\nWHERE (reorderdate IS NOT NULL)\nORDER BY reorderdate, item_number;\n	admin	2015-10-01	0
452	reports	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: reports\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists('byPackage') ?>\n  SELECT report_id, report_name,\n         firstline(report_descrip) AS report_descrip, report_grade,\n         CASE nspname WHEN 'public' THEN '' ELSE nspname END AS pkgname,\n         CASE nspname WHEN 'public' THEN 0\n                      ELSE 1        END AS xtindentrole,\n         report_descrip AS report_descrip_qttooltiprole\n    FROM report\n    JOIN pg_class     ON (report.tableoid=pg_class.oid)\n    JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n  UNION\n  SELECT -1, pkghead_name,\n         firstline(pkghead_descrip), NULL,\n         pkghead_name, 0, pkghead_descrip\n    FROM report, pg_class, pg_namespace\n    RIGHT OUTER JOIN pkghead ON (nspname=pkghead_name)\n   WHERE ((report.tableoid=pg_class.oid)\n      AND (relnamespace=pg_namespace.oid))\n  ORDER BY pkgname, xtindentrole, report_name,\n           report_grade DESC, report_id;\n<? else ?>\n  SELECT report_id, report_name,\n         firstline(report_descrip) AS report_descrip,\n         report_grade,\n         CASE nspname WHEN 'public' THEN '' ELSE nspname END AS pkgname,\n         report_descrip AS report_descrip_qttooltiprole\n    FROM report\n    JOIN pg_class     ON (report.tableoid=pg_class.oid)\n    JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n  ORDER BY report_name,\n           report_grade DESC, report_id;\n<? endif ?>\n	admin	2015-10-01	0
79	reservations	detail	 used by dspReservations\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: reservations\n-- Name: detail\n-- Notes: used by dspReservations\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT source_id, order_number, scheddate,\n       totalqty, relievedqty, reservedqty, balanceqty,\n       CASE WHEN (scheddate < CURRENT_DATE) THEN 'error' END AS scheddate_qtforegroundrold,\n       'qty' AS totalqty_xtnumericrole,\n       'qty' AS relievedqty_xtnumericrole,\n       'qty' AS reservedqty_xtnumericrole,\n       'qty' AS balanceqty_xtnumericrole,\n       0 AS balanceqty_xtrunningrole,\n       level AS xtindentrole\nFROM (\nSELECT coitem_scheddate AS sortkey, 0 AS level, coitem_id AS source_id,\n       formatSoNumber(coitem_id) AS order_number,\n       (coitem_qtyord * coitem_qty_invuomratio) AS totalqty,\n       ((coitem_qtyshipped + qtyAtShipping(coitem_id) - coitem_qtyreturned) * coitem_qty_invuomratio) as relievedqty,\n       (coitem_qtyreserved * coitem_qty_invuomratio) AS reservedqty,\n       (coitem_qtyreserved * coitem_qty_invuomratio) AS balanceqty,\n       coitem_scheddate AS scheddate\nFROM cohead, coitem, itemsite, item \nWHERE((coitem_cohead_id=cohead_id)\n  AND (coitem_itemsite_id=itemsite_id)\n  AND (coitem_qtyreserved > 0)\n  AND (itemsite_item_id=item_id)\n  AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND (itemsite_item_id=<? value("item_id") ?>))\nUNION\nSELECT coitem_scheddate AS sortkey, 1 AS level, coitem_id AS source_id,\n      (formatLocationName(itemloc_location_id) || ' ' || formatLotSerialNumber(itemloc_ls_id)) AS order_number,\n       NULL AS totalqty, NULL AS relievedqty,\n       (reserve_qty * coitem_qty_invuomratio) AS reservedqty,\n       NULL AS balanceqty, NULL AS scheddate\nFROM reserve, itemloc, coitem, itemsite\nWHERE ( (itemloc_id=reserve_supply_id)\n  AND (reserve_supply_type='I')\n  AND (coitem_id=reserve_demand_id)\n  AND (reserve_demand_type='SO')\n  AND (itemsite_id=coitem_itemsite_id)\n  AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND (itemsite_item_id=<? value("item_id") ?>) )\n    ) AS data\nORDER BY sortkey, source_id, level;\n	admin	2015-10-01	0
101	returnAuthorizations	detail	\n Notes:\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: returnAuthorizations\n-- Name: detail\n-- Notes:\n-- Notes:\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT DISTINCT rahead_id, rahead_number, rahead_billtoname,\n       rahead_authdate,rahead_expiredate,\n       COALESCE(cust_number, 'Undefined') AS custnumber,\n       CASE\n       WHEN rahead_disposition = 'C' THEN\n         <? value("credit") ?>\n       WHEN rahead_disposition = 'R' THEN\n         <? value("return") ?>\n       WHEN rahead_disposition = 'P' THEN\n         <? value("replace") ?>\n       WHEN rahead_disposition = 'V' THEN\n         <? value("service") ?>\n       WHEN rahead_disposition = 'M' THEN\n         <? value("substitute") ?>\n       END AS disposition,\n       formatDate(rahead_authdate) AS f_authorized,\n       formatDate(rahead_expiredate) AS f_expires,\n       CASE WHEN (rahead_expiredate < current_date) THEN\n         'error'\n       END AS rahead_expiredate_qtforegroundrole\n  FROM rahead LEFT OUTER JOIN custinfo ON (rahead_cust_id=cust_id)\n               <? if exists("selectedSites") ?> \n                   JOIN raitem ON (raitem_rahead_id=rahead_id) \n                   JOIN itemsite ON (raitem_itemsite_id=itemsite_id) \n                   JOIN site() ON (itemsite_warehous_id=warehous_id) \n               <? else ?> \n                   LEFT OUTER JOIN raitem ON (raitem_rahead_id=rahead_id) \n                   LEFT OUTER JOIN itemsite ON (raitem_itemsite_id=itemsite_id) \n                   LEFT OUTER JOIN whsinfo ON (itemsite_warehous_id=warehous_id) \n               <? endif ?> \n WHERE ((true)\n<? if not exists("showClosed") ?> \n   AND ((raitem_status = 'O') OR (raitem_status IS NULL)) \n<? endif ?>\n<? if not exists("showUnauthorized") ?> \n   AND (raitem_qtyauthorized > 0) \n<? endif ?>\n<? if not exists("showExpired") ?>\n   AND (COALESCE(rahead_expiredate,CURRENT_DATE) >= CURRENT_DATE)\n<? endif ?>\n<? if exists("warehous_id") ?>\n   AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("cust_id") ?>\n   AND (rahead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n      )\n GROUP BY cust_number,rahead_id,rahead_number,rahead_authdate,rahead_expiredate,\n   rahead_billtoname,rahead_disposition\n ORDER BY rahead_number\n	admin	2015-10-01	0
80	runningAvailability	detail	 used by dspRunningAvailability, itemAvailabilityWorkbench\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: runningAvailability\n-- Name: detail\n-- Notes: used by dspRunningAvailability, itemAvailabilityWorkbench\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT orderid, altorderid, ordertype, ordernumber, sequence, item_number,\n       duedate, amount, qtyordered,  qtyreceived, balance,\n       balance AS runningavail, balance AS runningnetable,\n<? if exists("isReport") ?>\n       CASE WHEN duedate = startOfTime() THEN ''\n            ELSE formatDate(duedate) END AS f_duedate,\n       formatMoney(amount) AS f_amount,\n       formatQty(qtyordered) AS f_qtyordered,\n       formatQty(qtyreceived) AS f_qtyreceived,\n       formatQty(balance) AS f_balance,\n<? endif ?>\n       notes,\n       1 AS runningavail_xtrunningrole,\n       1 AS runningnetable_xtrunningrole,\n       <? value("qoh") ?> AS runningavail_xtrunninginit,\n       <? value("netableqoh") ?> AS runningnetable_xtrunninginit,\n       CASE WHEN late THEN 'error' END AS duedate_qtforegroundrole,\n       CASE WHEN duedate = startOfTime() THEN '' END AS duedate_qtdisplayrole,\n       CASE WHEN ordertype ~ <? value("plannedPo") ?> OR\n                 ordertype ~ <? value("plannedWo") ?> OR\n                 ordertype ~ <? value("plannedTo") ?> THEN\n          'emphasis' END AS qtforegroundrole,\n      'currency' AS amount_xtnumericrole,\n      'qty' AS qtyordered_xtnumericrole,\n      'qty' AS qtyreceived_xtnumericrole,\n      'qty' AS balance_xtnumericrole\nFROM (\n<? if exists("isReport") ?>\nSELECT -1 AS orderid, -1 AS altorderid, 'QOH' AS ordertype,\n       NULL AS ordernumber,\n       0 AS sequence,\n       '' AS item_number,\n       startOfTime() AS duedate,\n       FALSE AS late,\n       0 AS amount,\n       0 AS qtyordered,\n       0 AS qtyreceived,\n       <? value("qoh") ?> AS balance,\n       '' AS notes\nUNION\n<? endif ?>\n<? if exists("MultiWhs") ?>\nSELECT tohead_id AS orderid, toitem_id AS altorderid, 'T/O' AS ordertype,\n       TEXT(tohead_number) AS ordernumber,\n       1 AS sequence,\n       tohead_srcname || '/' || tohead_destname AS item_number,\n       toitem_duedate AS duedate,\n       (toitem_duedate < CURRENT_DATE) AS late,\n       (toitem_stdcost * toitem_qty_ordered) AS amount,\n       toitem_qty_ordered AS qtyordered,\n       toitem_qty_received AS qtyreceived,\n       noNeg(toitem_qty_ordered - toitem_qty_received) AS balance,\n       tohead_ordercomments AS notes\nFROM tohead, toitem\nWHERE ((toitem_tohead_id=tohead_id)\n  AND  (toitem_status NOT IN ('C', 'X'))\n  AND  (toitem_item_id=<? value("item_id") ?>)\n  AND  (tohead_dest_warehous_id=<? value("warehous_id") ?>)\n  AND  (toitem_qty_ordered > toitem_qty_received) )\n\nUNION\nSELECT tohead_id AS orderid, toitem_id AS altorderid, 'T/O' AS ordertype,\n       TEXT(tohead_number) AS ordernumber,\n       1 AS sequence,\n       tohead_srcname || '/' || tohead_destname AS item_number,\n       toitem_duedate AS duedate,\n       (toitem_duedate < CURRENT_DATE) AS late,\n       (toitem_stdcost * toitem_qty_ordered) AS amount,\n       toitem_qty_ordered AS qtyordered,\n       toitem_qty_received AS qtyreceived,\n       -1 * noNeg(toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS balance,\n       tohead_ordercomments AS notes\n       -- TODO: old code had ^^^^ for formatted balance and vvvv used to calc running avail! which is right?\n       -- -1 * noNeg(toitem_qty_ordered - toitem_qty_received) AS balance\nFROM tohead, toitem\nWHERE ((toitem_tohead_id=tohead_id)\n  AND  (toitem_status NOT IN ('C', 'X'))\n  AND  (toitem_item_id=<? value("item_id") ?>)\n  AND  (tohead_src_warehous_id=<? value("warehous_id") ?>)\n  AND  (toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) > 0 )\n\nUNION\n<? endif ?>\nSELECT wo_id AS orderid, -1 AS altorderid,\n       'W/O' AS ordertype,\n       formatWoNumber(wo_id) AS ordernumber,\n       1 AS sequence,\n       item_number,\n       wo_duedate AS duedate,\n       (wo_duedate < CURRENT_DATE) AS late,\n       (itemCost(wo_itemsite_id) * wo_qtyord) AS amount,\n       wo_qtyord AS qtyordered,\n       wo_qtyrcv AS qtyreceived,\n       noNeg(wo_qtyord - wo_qtyrcv) AS balance,\n       wo_prodnotes AS notes\nFROM wo, itemsite, item\nWHERE ((wo_status<>'C')\n  AND  (wo_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (item_type NOT IN ('C', 'Y')))\n\nUNION\n\n-- Tools on work orders to be returned\nSELECT wo_id AS orderid, -1 AS altorderid,\n       'W/O' AS ordertype,\n       formatWoNumber(wo_id) AS ordernumber,\n       1 AS sequence,\n       item_number,\n       wo_duedate AS duedate,\n       (wo_duedate < CURRENT_DATE) AS late,\n       (womatl_cost * womatl_qtyreq) AS amount,\n       womatl_qtyreq AS qtyordered,\n       COALESCE(SUM(abs(invhist_invqty)),0) AS qtyreceived,\n       noNeg(womatl_qtyreq - COALESCE(SUM(abs(invhist_invqty)),0)) AS balance,\n       wo_prodnotes AS notes\nFROM womatl\n  JOIN wo ON (wo_id=womatl_wo_id)\n  JOIN itemsite ON (womatl_itemsite_id=itemsite_id)\n  JOIN item ON (itemsite_item_id=item_id)\n  LEFT OUTER JOIN womatlpost ON (womatl_id=womatlpost_womatl_id)\n  LEFT OUTER JOIN invhist ON ((womatlpost_invhist_id=invhist_id)\n                          AND (invhist_invqty < 0))\nWHERE ((wo_status<>'C')\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (item_type = 'T'))\nGROUP BY wo_id, wo_duedate, item_number, womatl_qtyreq, womatl_cost, wo_prodnotes\n\n<? if exists("Manufacturing") ?>\nUNION\nSELECT wo_id AS orderid, -1 AS altorderid,\n       'W/O' AS ordertype,\n       formatWoNumber(wo_id) AS ordernumber,\n       1 AS sequence,\n       item_number,\n       wo_duedate AS duedate,\n       (wo_duedate < CURRENT_DATE) AS late,\n       (itemCost(wo_itemsite_id) * wo_qtyord * brddist_stdqtyper) AS amount,\n       (wo_qtyord * brddist_stdqtyper) AS qtyordered,\n       (wo_qtyrcv * brddist_stdqtyper) AS qtyreceived,\n       noNeg((wo_qtyord - wo_qtyrcv) * brddist_stdqtyper) AS balance,\n       wo_prodnotes AS notes\nFROM xtmfg.brddist, wo, itemsite, item\nWHERE ((wo_status<>'C')\n  AND  (brddist_wo_id=wo_id)\n  AND  (wo_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id)\n  AND  (brddist_itemsite_id=itemsite_id)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (item_type IN ('C', 'Y')) )\n<? endif ?>\n\nUNION\nSELECT wo_id AS orderid, womatl_id AS altorderid,\n      'W/O' AS ordertype,\n      formatWoNumber(wo_id) AS ordernumber,\n      2 AS sequence,\n      woi.item_number,\n      womatl_duedate AS duedate,\n      FALSE AS late,\n      (itemCost(womatl_itemsite_id) * itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq)) AS amount,\n      itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq) AS qtyordered,\n      itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyiss) AS qtyreceived,\n      itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq - womatl_qtyiss) * -1)) AS balance,\n      wo_prodnotes AS notes\nFROM womatl, wo, itemsite AS wois, item AS woi, itemsite AS womatlis, item AS womatli\nWHERE ((wo_status<>'C')\n  AND  (wo_itemsite_id=wois.itemsite_id)\n  AND  (wois.itemsite_item_id=woi.item_id)\n  AND  (womatlis.itemsite_item_id=womatli.item_id)\n  AND  (womatli.item_type != 'T')\n  AND  (womatl_wo_id=wo_id)\n  AND  (womatlis.itemsite_item_id=<? value("item_id") ?>)\n  AND  (womatlis.itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (womatl_itemsite_id=womatlis.itemsite_id) )\n\nUNION\n-- Special handling for tools\nSELECT wo_id AS orderid, womatl_id AS altorderid,\n      'W/O' AS ordertype,\n      formatWoNumber(wo_id) AS ordernumber,\n      2 AS sequence,\n      woi.item_number,\n      womatl_duedate AS duedate,\n      FALSE AS late,\n      (womatl_cost * itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq)) AS amount,\n      itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq) AS qtyordered,\n      COALESCE(SUM(invhist_invqty),0) AS qtyreceived,\n      (itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq))) - COALESCE(SUM(invhist_invqty),0)) * -1 AS balance,\n      wo_prodnotes AS notes\nFROM itemsite AS wois, item AS woi, itemsite AS womatlis, item AS womatli, wo, womatl\n  LEFT OUTER JOIN womatlpost ON (womatl_id=womatlpost_womatl_id)\n  LEFT OUTER JOIN invhist ON ((womatlpost_invhist_id=invhist_id)\n                          AND (invhist_invqty > 0))\nWHERE ((wo_status<>'C')\n  AND  (wo_itemsite_id=wois.itemsite_id)\n  AND  (wois.itemsite_item_id=woi.item_id)\n  AND  (womatlis.itemsite_item_id=womatli.item_id)\n  AND  (womatli.item_type = 'T')\n  AND  (womatl_wo_id=wo_id)\n  AND  (womatlis.itemsite_item_id=<? value("item_id") ?>)\n  AND  (womatlis.itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (womatl_itemsite_id=womatlis.itemsite_id) )\nGROUP BY wo_id, woi.item_number, womatl_id, womatl_duedate, womatlis.itemsite_item_id, womatl_uom_id, womatl_qtyreq, womatl_cost, wo_prodnotes\n\nUNION\nSELECT pohead_id AS orderid, poitem_id AS altorderid,\n      'P/O' AS ordertype,\n      TEXT(pohead_number) AS ordernumber,\n      1 AS sequence,\n      vend_name AS item_number,\n      poitem_duedate AS duedate,\n      (poitem_duedate < CURRENT_DATE) AS late,\n      (poitem_unitprice * poitem_qty_ordered) AS amount,\n      (poitem_qty_ordered * poitem_invvenduomratio) AS qtyordered,\n      (NoNeg(poitem_qty_received - poitem_qty_returned) * poitem_invvenduomratio) AS qtyreceived,\n      (noNeg(poitem_qty_ordered - poitem_qty_received) * poitem_invvenduomratio) AS balance,\n       pohead_comments AS notes\nFROM pohead, vendinfo, poitem, itemsite, item\nWHERE ((vend_id=pohead_vend_id)\n  AND  (poitem_pohead_id=pohead_id)\n  AND  (poitem_status <> 'C')\n  AND  (poitem_itemsite_id=itemsite_id)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=item_id)\n  AND  (item_id=<? value("item_id") ?>) )\n\nUNION\nSELECT cohead_id AS orderid, coitem_id AS altorderid,\n       'S/O' AS ordertype,\n       TEXT(cohead_number) AS ordernumber,\n       2 AS sequence,\n       cust_name AS item_number,\n       coitem_scheddate AS duedate,\n       (coitem_scheddate < CURRENT_DATE) AS late,\n       (coitem_price * coitem_qtyord) AS amount,\n       (coitem_qtyord * coitem_qty_invuomratio) AS qtyordered,\n       (coitem_qty_invuomratio * (coitem_qtyshipped - coitem_qtyreturned + qtyAtShipping(coitem_id))) AS qtyreceived,\n       (coitem_qty_invuomratio * noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping(coitem_id)) * -1) AS balance,\n       cohead_ordercomments AS notes\nFROM coitem, cohead, custinfo, itemsite, item\nWHERE ((coitem_status='O')\n  AND  (cohead_cust_id=cust_id)\n  AND  (coitem_cohead_id=cohead_id)\n  AND  (coitem_itemsite_id=itemsite_id)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=item_id)\n  AND  (item_id=<? value("item_id") ?>))\n\n<? if exists("showPlanned") ?>\n<? if exists("showMRPplan") ?>\nUNION\nSELECT planord_id AS orderid, -1 AS altorderid,\n       CASE WHEN (planord_firm) THEN <? value("firmPo") ?> \n \t   ELSE <? value("plannedPo") ?> \n       END AS ordertype,\n       CAST(planord_number AS text) AS ordernumber,\n       1 AS sequence,\n       '' AS item_number,\n       planord_duedate AS duedate,\n       FALSE AS late,\n       (itemCost(planord_itemsite_id) * planord_qty) AS amount,\n       planord_qty AS qtyordered,\n       NULL AS qtyreceived,\n       planord_qty AS balance,\n       planord_comments AS notes\nFROM planord, itemsite\nWHERE ((planord_type='P')\n  AND  (planord_itemsite_id=itemsite_id)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>) )\n\nUNION\nSELECT planord_id AS orderid, -1 AS altorderid,\n       CASE WHEN (planord_firm) THEN <? value("firmWo") ?> \n\t    ELSE <? value("plannedWo") ?> \n       END AS ordertype,\n       CAST(planord_number AS text) AS ordernumber,\n       1 AS sequence,\n       '' AS item_number,\n       planord_duedate AS duedate,\n       FALSE AS late,\n       (itemCost(planord_itemsite_id) * planord_qty) AS amount,\n       planord_qty AS qtyordered,\n       NULL AS qtyreceived,\n       planord_qty AS balance,\n       planord_comments AS notes\nFROM planord, itemsite\nWHERE ((planord_type='W')\n  AND  (planord_itemsite_id=itemsite_id)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>) )\n\nUNION\n-- Tools on Planned Work Orders\nSELECT planord_id AS orderid, -1 AS altorderid,\n       CASE WHEN (planord_firm) THEN <? value("firmWo") ?> \n\t    ELSE <? value("plannedWo") ?> \n       END AS ordertype,\n       CAST(planord_number AS text) AS ordernumber,\n       1 AS sequence,\n       item_number,\n       planord_duedate AS duedate,\n       FALSE AS late,\n       (itemCost(planreq_itemsite_id) * planreq_qty) AS amount,\n       planreq_qty AS qtyordered,\n       NULL AS qtyreceived,\n       planreq_qty AS balance,\n       planord_comments AS notes\nFROM planreq\n  JOIN itemsite ON (itemsite_id=planreq_itemsite_id)\n  JOIN item ON (item_id=itemsite_item_id)\n  JOIN planord ON ((planreq_source_id=planord_id)\n              AND (planreq_source='P'))\nWHERE ((itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>)\n  AND  (item_type='T') )\n\nUNION\nSELECT planord_id AS orderid, -1 AS altorderid,\n       CASE WHEN (planord_firm) THEN <? value("firmTo") ?> \n\t    ELSE <? value("plannedTo") ?> \n       END AS ordertype,\n       CAST(planord_number AS text) AS ordernumber,\n       1 AS sequence,\n       srcwhsinfo.warehous_code || '/' || whsinfo.warehous_code AS item_number,\n       planord_duedate AS duedate,\n       FALSE AS late,\n       (itemCost(planord_itemsite_id) * planord_qty) AS amount,\n       planord_qty AS qtyordered,\n       NULL AS qtyreceived,\n       planord_qty AS balance,\n       planord_comments AS notes\nFROM planord JOIN itemsite ON (itemsite.itemsite_id=planord_itemsite_id)\n             JOIN whsinfo ON (whsinfo.warehous_id=itemsite.itemsite_warehous_id)\n             JOIN itemsite srcitemsite ON (srcitemsite.itemsite_id=planord_supply_itemsite_id)\n             JOIN whsinfo srcwhsinfo ON (srcwhsinfo.warehous_id=srcitemsite.itemsite_warehous_id)\nWHERE ((planord_type='T')\n  AND  (itemsite.itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite.itemsite_item_id=<? value("item_id") ?>) )\n\nUNION\nSELECT planord_id AS orderid, -1 AS altorderid,\n       CASE WHEN (planord_firm) THEN <? value("firmTo") ?> \n\t    ELSE <? value("plannedTo") ?> \n       END AS ordertype,\n       CAST(planord_number AS text) AS ordernumber,\n       1 AS sequence,\n       srcwhsinfo.warehous_code || '/' || whsinfo.warehous_code AS item_number,\n       planord_duedate AS duedate,\n       FALSE AS late,\n       (itemCost(planord_itemsite_id) * planord_qty) AS amount,\n       planord_qty AS qtyordered,\n       NULL AS qtyreceived,\n       (planord_qty * -1) AS balance,\n       planord_comments AS notes\nFROM planord JOIN itemsite ON (itemsite.itemsite_id=planord_itemsite_id)\n             JOIN whsinfo ON (whsinfo.warehous_id=itemsite.itemsite_warehous_id)\n             JOIN itemsite srcitemsite ON (srcitemsite.itemsite_id=planord_supply_itemsite_id)\n             JOIN whsinfo srcwhsinfo ON (srcwhsinfo.warehous_id=srcitemsite.itemsite_warehous_id)\nWHERE ((planord_type='T')\n  AND  (srcitemsite.itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (srcitemsite.itemsite_item_id=<? value("item_id") ?>) )\n\nUNION\nSELECT planreq_id AS orderid, -1 AS altorderid,\n       CASE WHEN (planord_firm) THEN <? value("firmWoReq") ?> \n\t    ELSE <? value("plannedWoReq") ?> \n       END AS ordertype,\n       CAST(planord_number AS text) AS ordernumber,\n       1 AS sequence,\n--get the planned order number for the higher level demand\n             (SELECT item_number\n                FROM item, itemsite\n               WHERE((itemsite_item_id=item_id)\n                 AND (itemsite_id=planord_itemsite_id))\n             ) AS item_number,\n       planord_startdate AS duedate,\n       FALSE AS late,\n       (itemCost(planreq_itemsite_id) * planreq_qty) AS amount,\n       planreq_qty AS f_qtyordered,\n       NULL AS qtyreceived,\n       (planreq_qty * -1) AS balance,\n       planreq_notes AS notes\nFROM planreq, planord, itemsite, item\nWHERE ((planreq_source='P')\n  AND  (planreq_source_id=planord_id)\n  AND  (planreq_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>) )\n<? endif ?>\n\nUNION\nSELECT pr_id AS orderid, -1 AS altorderid,\n       <? value("pr") ?> AS ordertype,\n       CAST(pr_number AS text) AS ordernumber,       \n       1 AS sequence,\n       '' AS item_number,\n       pr_duedate AS duedate,\n       FALSE AS late,\n       (itemCost(pr_itemsite_id) * pr_qtyreq) AS amount,\n       pr_qtyreq AS qtyordered,\n       NULL AS qtyreceived,\n       pr_qtyreq AS balance,\n       pr_releasenote AS notes\nFROM pr, itemsite, item\nWHERE ((pr_itemsite_id=itemsite_id)\n  AND  (itemsite_item_id=item_id)\n  AND  (pr_itemsite_id=itemsite_id)\n  AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  AND  (itemsite_item_id=<? value("item_id") ?>) )\n<? endif ?>\n) AS dummy\n\nORDER BY duedate, sequence;\n\n	admin	2015-10-01	0
81	salesHistory	detail	 \n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: salesHistory\n-- Name: detail\n-- Notes: \n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT *,\n       CASE WHEN (COALESCE(cohist_invcnumber, '-1') IN ('', '-1')) THEN  <? value("credit") ?>\n            ELSE cohist_invcnumber\n       END AS invoicenumber,\n<? if exists("isReport") ?>\n       formatDate(cohist_orderdate) AS f_orderdate,\n       formatDate(cohist_invcdate) AS f_invcdate,\n       formatQty(cohist_qtyshipped) AS f_qtyshipped,\n       formatBoolYN(cohist_commissionpaid) AS f_commissionpaid,\n       formatSalesPrice(baseunitprice) AS f_baseunitprice,\n       formatMoney(extprice) AS f_extprice,\n       formatMoney(baseextprice) AS f_baseextprice,\n       formatMoney(extcost) AS f_extcost,\n       formatMoney(margin) AS f_margin,\n       formatPrcnt(marginpercent) AS f_marginpercent,\n       formatMoney(basecommission) AS f_basecommission,\n<? endif ?>\n       <? value("return") ?> AS cohist_invcdate_xtnullrole,\n       0 AS cohist_qtyshipped_xttotalrole,\n       0 AS baseextprice_xttotalrole,\n       0 AS extcost_xttotalrole,\n       0 AS margin_xttotalrole,\n       0 AS basecommission_xttotalrole\n<? if exists("includeMisc") ?>\n  FROM saleshistorymisc\n<? else ?>\n  FROM saleshistory\n<? endif ?>\nWHERE ( (true)\n<? if exists("startDate") ?>\n  AND  (cohist_invcdate >= <? value("startDate") ?>)\n<? endif ?>\n<? if exists("endDate") ?>\n  AND  (cohist_invcdate <= <? value("endDate") ?>)\n<? endif ?>\n<? if exists("shipStartDate") ?>\n  AND  (cohist_shipdate >= <? value("shipStartDate") ?>)\n<? endif ?>\n<? if exists("shipEndDate") ?>\n  AND  (cohist_shipdate <= <? value("shipEndDate") ?>)\n<? endif ?>\n<? if exists("salesrep_id") ?>\n  AND  (cohist_salesrep_id=<? value("salesrep_id") ?>)\n<? endif ?>\n<? if exists("shipto_id") ?>\n  AND  (cohist_shipto_id=<? value("shipto_id") ?>)\n<? endif ?>\n<? if exists("billToName") ?>\n  AND  (UPPER(cohist_billtoname) ~ UPPER(<? value("billToName") ?>))\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND  (cohist_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND  (custtype_id=<? value("custtype_id") ?>)\n<? elseif exists("custtype_pattern") ?>\n  AND  (custtype_id IN (SELECT DISTINCT custtype_id\n                        FROM custtype\n                        WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n<? if exists("by_custgrp") ?>\n  AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                   FROM custgrpitem))\n<? endif ?>\n<? if exists("custgrp_id") ?>\n  AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                   FROM custgrpitem\n                   WHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)))\n<? endif ?>\n<? if exists("custgrp_pattern") ?>\n  AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                   FROM custgrp, custgrpitem\n                   WHERE ( (custgrpitem_custgrp_id=custgrp_id)\n                     AND   (custgrp_name ~ <? value("custgrp_pattern") ?>) )) )\n<? endif ?>\n\n<? if exists("item_id") ?>\n  AND  (item_id=<? value("item_id") ?>)\n<? endif ?>\n<? if exists("item_pattern") ?>\n  AND  (itemnumber ~* <? value("item_pattern") ?>)\n<? endif ?>\n<? if exists("prodcat_id") ?>\n  AND (prodcat_id=<? value("prodcat_id") ?>)\n<? endif ?>\n<? if exists("prodcat_pattern") ?>\n  AND (prodcat_id IN (SELECT DISTINCT prodcat_id\n                      FROM prodcat\n                      WHERE (prodcat_code ~ <? value("prodcat_pattern") ?>)))\n<? endif ?>\n<? if exists("classcode_id") ?>\n  AND (classcode_id=<? value("classcode_id") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n  AND  (warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("shipzone_id") ?>\n  AND (cohist_shipzone_id=<? value("shipzone_id") ?>)\n<? endif ?>\n<? if exists("saletype_id") ?>\n  AND (cohist_saletype_id=<? value("saletype_id") ?>)\n<? endif ?>\n<? if exists("cohead_id") ?>\n  AND (cohead_id=<? value("cohead_id") ?>)\n<? endif ?>\n      )\nORDER BY cohist_invcdate, itemnumber;\n\n	admin	2015-10-01	0
82	salesOrderItems	detail	 used by dspBacklogByCustomer, dspBacklogByItem, dspBacklogByParameterList, dspBacklogBySalesOrder, dspBookingsByCustomer, dspBookingsByCustomerGroup, dspBookingsByItem, dspBookingsByProductCategory, dspBookingsBySalesRep, dspBookingsByShipTo, dspSalesOrdersByItem\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: salesOrderItems\n-- Name: detail\n-- Notes: used by dspBacklogByCustomer, dspBacklogByItem, dspBacklogByParameterList, dspBacklogBySalesOrder, dspBookingsByCustomer, dspBookingsByCustomerGroup, dspBookingsByItem, dspBookingsByProductCategory, dspBookingsBySalesRep, dspBookingsByShipTo, dspSalesOrdersByItem\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT\n       cohead_id, coitem_id, *, currconcat(cohead_curr_id) AS currAbbr,\n<? if exists("item_id") ?>\n       CASE WHEN xtindentrole = 0 THEN cust_name\n       END AS item_number_qtdisplayrole,\n<? elseif exists("salesrep_id") ?>\n-- no alterations to displayroles\n<? elseif not exists("cohead_id") ?>\n       CASE WHEN xtindentrole = 0 THEN cohead_number\n       END AS coitem_linenumber_qtdisplayrole,\n       CASE WHEN xtindentrole = 0 THEN cust_name\n       END AS item_number_qtdisplayrole,\n <? endif ?>\n       'qty' AS coitem_qtyord_xtnumericrole,\n       'qty' AS coitem_qtyshipped_xtnumericrole,\n       'qty' AS coitem_qtyreturned_xtnumericrole,\n       'qty' AS qtyatshipping_xtnumericrole,\n       'qty' AS qtybalance_xtnumericrole,\n       'qty' AS qtyavailable_xtnumericrole,\n       'salesprice' AS coitem_price_xtnumericrole,\n       'salesprice' AS baseunitprice_xtnumericrole,\n       'curr' AS extprice_xtnumericrole,\n       'curr' AS baseextprice_xtnumericrole,\n       'curr' AS extpricebalance_xtnumericrole,\n       'curr' AS baseextpricebalance_xtnumericrole,\n       0 AS coitem_qtyord_xttotalrole,\n       0 AS coitem_qtyshipped_xttotalrole,\n       0 AS coitem_qtyreturned_xttotalrole,\n       0 AS qtybalance_xttotalrole,\n       0 AS baseextprice_xttotalrole,\n       0 AS baseextpricebalance_xttotalrole\nFROM (\n  <? if not exists("cohead_id") ?> -- get cohead info\n  <? if not exists("item_id") ?>\n  <? if not exists("salesrep_id") ?>\n  SELECT \n         0 AS xtindentrole,\n         -- dummy coitem record\n         -1            AS coitem_id,        NULL::INTEGER AS coitem_cohead_id,\n         -1            AS coitem_linenumber,NULL::INTEGER AS coitem_itemsite_id,\n         NULL::TEXT    AS coitem_status,    NULL::DATE AS coitem_scheddate,\n         getSoSchedDate(cohead_id) AS sort_scheddate,\n         NULL::DATE    AS coitem_promdate,  NULL::NUMERIC AS coitem_qtyord,\n         NULL::NUMERIC AS coitem_unitcost,  NULL::NUMERIC AS coitem_price,\n         NULL::NUMERIC AS coitem_custprice, NULL::NUMERIC AS coitem_qtyshipped,\n         NULL::INTEGER AS coitem_order_id,  NULL::TEXT    AS coitem_memo,\n         NULL::BOOLEAN AS coitem_imported,  NULL::NUMERIC AS coitem_qtyreturned,\n         NULL::TIMESTAMP AS coitem_closedate,\n         NULL::TEXT    AS coitem_custpn,    NULL::TEXT    AS coitem_order_type,\n         NULL::TEXT    AS coitem_close_username,\n         NULL::TIMESTAMP AS coitem_lastupdated,\n         NULL::INTEGER AS coitem_substitute_item_id,\n         NULL::TIMESTAMP AS coitem_created, NULL::TEXT    AS coitem_creator,\n         NULL::NUMERIC AS coitem_prcost,\n         NULL::INTEGER AS coitem_qty_uom_id,\n         NULL::NUMERIC AS coitem_qty_invuomratio,\n         NULL::INTEGER AS coitem_price_uom_id,\n         NULL::NUMERIC AS coitem_price_invuomratio,\n         NULL::BOOLEAN AS coitem_warranty,\n         NULL::INTEGER AS coitem_cos_accnt_id,\n         NULL::NUMERIC AS coitem_qtyreserved,\n         NULL::INTEGER AS coitem_subnumber,\n         cohead.*,\n         cust_number, cust_name,\n         NULL::TEXT AS item_number, NULL::TEXT AS item_descrip1,\n         NULL::TEXT AS itemdescription,\n         NULL::TEXT AS uom_name,\n         NULL::TEXT AS warehous_code,\n         NULL::NUMERIC AS qtyatshipping,\n         NULL::NUMERIC AS qtyavailable,\n         NULL::BOOLEAN AS stockout,\n         NULL::BOOLEAN AS reorder,\n         NULL::NUMERIC AS qtybalance,\n         NULL::NUMERIC AS baseunitprice,\n         NULL::NUMERIC AS extprice,\n         NULL::NUMERIC AS baseextprice,\n         NULL::NUMERIC AS extpricebalance,\n         NULL::NUMERIC AS baseextpricebalance,\n         NULL::TEXT    AS qtyavailable_qtforegroundrole\n\n  FROM coitem JOIN cohead ON (cohead_id=coitem_cohead_id)\n              JOIN custinfo ON (cust_id=cohead_cust_id)\n              JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n              JOIN site() ON (warehous_id=itemsite_warehous_id)\n              JOIN item ON (item_id=itemsite_item_id)\n              JOIN uom ON (uom_id=coitem_qty_uom_id)\n  WHERE ( (coitem_status<>'X')\n  <? if exists("cohead_id") ?>\n    AND  (coitem_cohead_id=<? value("cohead_id") ?>)\n  <? endif ?>\n  <? if exists("openOnly") ?>\n    AND  (coitem_status<>'C')\n  <? endif ?>\n  <? if exists("startDate") ?>\n    <? if exists("orderByOrderdate") ?>\n    AND  (cohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? else ?>\n    AND  (coitem_scheddate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? endif ?>\n  <? endif ?>\n\n  <? if exists("salesrep_id") ?>\n    AND  (cohead_salesrep_id=<? value("salesrep_id") ?>)\n  <? endif ?>\n  <? if exists("shipto_id") ?>\n    AND  (cohead_shipto_id=<? value("shipto_id") ?>)\n  <? endif ?>\n  <? if exists("cust_id") ?>\n    AND  (cohead_cust_id=<? value("cust_id") ?>)\n  <? elseif exists("custtype_id") ?>\n    AND  (cust_custtype_id=<? value("custtype_id") ?>)\n  <? elseif exists("custtype_pattern") ?>\n    AND  (cust_custtype_id IN (SELECT DISTINCT custtype_id\n                               FROM custtype\n                               WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n  <? elseif exists("custgrp") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem))\n  <? elseif exists("custgrp_id") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem\n                     WHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)))\n  <? elseif exists("custgrp_pattern") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrp, custgrpitem\n                     WHERE ( (custgrpitem_custgrp_id=custgrp_id)\n                       AND   (custgrp_name ~ <? value("custgrp_pattern") ?>) )) )\n  <? endif ?>\n\n  <? if exists("item_id") ?>\n    AND  (itemsite_item_id=<? value("item_id") ?>)\n  <? elseif exists("prodcat_id") ?>\n    AND (item_prodcat_id=<? value("prodcat_id") ?>)\n  <? elseif exists("prodcat_pattern") ?>\n    AND (item_prodcat_id IN (SELECT DISTINCT prodcat_id\n                             FROM prodcat\n                             WHERE (prodcat_code ~ <? value("prodcat_pattern") ?>)))\n  <? endif ?>\n\n  <? if exists("warehous_id") ?>\n    AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  <? endif ?>\n        )\n\n  UNION\n  <? endif ?> -- endif not exists "salesrep_id"\n  <? endif ?> -- endif not exists "item_id"\n  <? endif ?> -- endif not exists "cohead_id"\n\n  SELECT \n         <? if exists("cohead_id") ?> 0\n         <? elseif exists("item_id") ?> 0\n         <? elseif exists("salesrep_id") ?> 0\n         <? else ?> 1 <? endif ?> AS xtindentrole,\n         coitem_id,        coitem_cohead_id,\n         coitem_linenumber,coitem_itemsite_id,\n         coitem_status,    coitem_scheddate,\n         getSoSchedDate(cohead_id) AS sort_scheddate,\n         coitem_promdate,  coitem_qtyord,\n         coitem_unitcost,  coitem_price,\n         coitem_custprice, coitem_qtyshipped,\n         coitem_order_id,  coitem_memo,\n         coitem_imported,  coitem_qtyreturned,\n         coitem_closedate,\n         coitem_custpn,    coitem_order_type,\n         coitem_close_username,\n         coitem_lastupdated,\n         coitem_substitute_item_id,\n         coitem_created,   coitem_creator,\n         coitem_prcost,\n         coitem_qty_uom_id,\n         coitem_qty_invuomratio,\n         coitem_price_uom_id,\n         coitem_price_invuomratio,\n         coitem_warranty,\n         coitem_cos_accnt_id,\n         coitem_qtyreserved,\n         coitem_subnumber,\n         cohead.*,\n         cust_number, cust_name,\n         item_number, item_descrip1, (item_descrip1 || ' ' || item_descrip2) AS itemdescription,\n         uom_name,\n         warehous_code,\n         ( SELECT SUM(shipitem_qty)\n             FROM shipitem JOIN shiphead ON ( (shipitem_shiphead_id=shiphead_id) AND (shiphead_order_type='SO') AND (NOT shiphead_shipped) )\n            WHERE (shipitem_orderitem_id=coitem_id) ) AS qtyatshipping,\n         qtyAvailable(itemsite_id, coitem_scheddate) AS qtyavailable,\n         (qtyAvailable(itemsite_id, coitem_scheddate) < 0.0) AS stockout,\n         CASE WHEN (itemsite_useparams) THEN (qtyAvailable(itemsite_id, coitem_scheddate) <= itemsite_reorderlevel)\n              ELSE (qtyAvailable(itemsite_id, coitem_scheddate) <= 0.0)\n         END AS reorder,\n         noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS qtybalance,\n         currtobase(cohead_curr_id, coitem_price, cohead_orderdate) AS baseunitprice,\n         round((coitem_qtyord * coitem_qty_invuomratio) *\n                     (coitem_price / coitem_price_invuomratio), 2) AS extprice,\n         round((coitem_qtyord * coitem_qty_invuomratio) *\n                     (currtobase(cohead_curr_id, coitem_price, cohead_orderdate) / coitem_price_invuomratio), 2) AS baseextprice,\n         round((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n                     (coitem_price / coitem_price_invuomratio), 2) AS extpricebalance,\n         round((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n                     (currtobase(cohead_curr_id, coitem_price, cohead_orderdate) / coitem_price_invuomratio), 2) AS baseextpricebalance,\n         CASE WHEN (qtyAvailable(itemsite_id, coitem_scheddate) < 0.0) THEN 'error'\n              WHEN itemsite_useparams AND (qtyAvailable(itemsite_id, coitem_scheddate) <= itemsite_reorderlevel) THEN 'warning'\n              WHEN NOT itemsite_useparams AND (qtyAvailable(itemsite_id, coitem_scheddate) <= 0.0) THEN 'warning'\n         END AS qtyavailable_qtforegroundrole\n\n  FROM coitem JOIN cohead ON (cohead_id=coitem_cohead_id)\n              JOIN custinfo ON (cust_id=cohead_cust_id)\n              JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n              JOIN site() ON (warehous_id=itemsite_warehous_id)\n              JOIN item ON (item_id=itemsite_item_id)\n              JOIN uom ON (uom_id=coitem_qty_uom_id)\n  WHERE ( (coitem_status<>'X')\n  <? if exists("cohead_id") ?>\n    AND  (coitem_cohead_id=<? value("cohead_id") ?>)\n  <? endif ?>\n  <? if exists("openOnly") ?>\n    AND  (coitem_status<>'C')\n  <? endif ?>\n  <? if exists("startDate") ?>\n    <? if exists("orderByOrderdate") ?>\n    AND  (cohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? else ?>\n    AND  (coitem_scheddate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n    <? endif ?>\n  <? endif ?>\n\n  <? if exists("salesrep_id") ?>\n    AND  (cohead_salesrep_id=<? value("salesrep_id") ?>)\n  <? endif ?>\n  <? if exists("shipto_id") ?>\n    AND  (cohead_shipto_id=<? value("shipto_id") ?>)\n  <? endif ?>\n  <? if exists("cust_id") ?>\n    AND  (cohead_cust_id=<? value("cust_id") ?>)\n  <? elseif exists("custtype_id") ?>\n    AND  (cust_custtype_id=<? value("custtype_id") ?>)\n  <? elseif exists("custtype_pattern") ?>\n    AND  (cust_custtype_id IN (SELECT DISTINCT custtype_id\n                               FROM custtype\n                               WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n  <? elseif exists("custgrp") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem))\n  <? elseif exists("custgrp_id") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrpitem\n                     WHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)))\n  <? elseif exists("custgrp_pattern") ?>\n    AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                     FROM custgrp, custgrpitem\n                     WHERE ( (custgrpitem_custgrp_id=custgrp_id)\n                       AND   (custgrp_name ~ <? value("custgrp_pattern") ?>) )) )\n  <? endif ?>\n\n  <? if exists("item_id") ?>\n    AND  (itemsite_item_id=<? value("item_id") ?>)\n  <? elseif exists("prodcat_id") ?>\n    AND (item_prodcat_id=<? value("prodcat_id") ?>)\n  <? elseif exists("prodcat_pattern") ?>\n    AND (item_prodcat_id IN (SELECT DISTINCT prodcat_id\n                             FROM prodcat\n                             WHERE (prodcat_code ~ <? value("prodcat_pattern") ?>)))\n  <? endif ?>\n\n  <? if exists("warehous_id") ?>\n    AND  (itemsite_warehous_id=<? value("warehous_id") ?>)\n  <? endif ?>\n        )\n\n) AS dummy\n\n<? if exists("orderByScheddate") ?>\n  ORDER BY sort_scheddate, cohead_number, coitem_linenumber\n<? elseif exists("orderByOrderdate") ?>\n  ORDER BY cohead_orderdate, cohead_number, coitem_linenumber\n<? else ?>\n  ORDER BY cohead_number, coitem_linenumber\n<? endif ?>\n;\n	admin	2015-10-01	0
281	salesOrderStatus	detail	 used by dspSalesOrderStatus\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: salesOrderStatus\n-- Name: detail\n-- Notes: used by dspSalesOrderStatus\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT coitem_id, coitem_linenumber, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n       warehous_code,\n       coitem_qtyord, coitem_qtyshipped, coitem_qtyreturned,\n       SUM(COALESCE(cobill_qty, 0)) AS invoiced,\n       noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS balance,\n       CASE WHEN (coitem_status='C') THEN coitem_closedate END AS closedate,\n       CASE WHEN (coitem_status='C') THEN coitem_close_username END AS closeuser,\n       CASE WHEN (coitem_order_id=-1) THEN ''\n            WHEN (coitem_order_type='W') THEN ( SELECT (formatWoNumber(wo_id) || '/' || wo_status)\n                                                FROM wo\n                                                WHERE (wo_id=coitem_order_id) )\n         ELSE ''\n       END AS childinfo,\n       'qty' AS coitem_qtyord_xtnumericrole,\n       'qty' AS coitem_qtyshipped_xtnumericrole,\n       'qty' AS coitem_qtyreturned_xtnumericrole,\n       'qty' AS invoiced_xtnumericrole,\n       'qty' AS balance_xtnumericrole \nFROM itemsite, item, whsinfo, coitem LEFT OUTER JOIN\n     cobill ON (coitem_id=cobill_coitem_id AND\n                cobill_invcitem_id IS NOT NULL)\nWHERE ( (coitem_itemsite_id=itemsite_id)\n    AND (coitem_status <> 'X')\n    AND (itemsite_item_id=item_id)\n    AND (itemsite_warehous_id=warehous_id)\n    AND (coitem_cohead_id=<? value("sohead_id") ?>) ) \nGROUP BY coitem_id, coitem_linenumber, item_number, \n         item_descrip1, item_descrip2, warehous_code, \n         coitem_qtyord, coitem_qtyshipped, coitem_status, \n         coitem_closedate, coitem_close_username, \n         coitem_qtyreturned, coitem_order_id, \n         coitem_order_type \nORDER BY coitem_linenumber;\n	admin	2015-10-01	0
83	salesOrders	detail	 used by dspSalesOrders, dspSalesOrdersByCustomer, dspSalesOrdersByCustomerPO, dspSalesOrdersByParameterList\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: salesOrders\n-- Name: detail\n-- Notes: used by dspSalesOrders, dspSalesOrdersByCustomer, dspSalesOrdersByCustomerPO, dspSalesOrdersByParameterList\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cohead_id, cust_id,\n       cohead.*,\n       cust_number, cust_name,\n       saletype_descr,\n       getSoSchedDate(cohead_id) AS min_scheddate,\n       CASE\n         WHEN ( (SELECT COUNT(*)\n                   FROM coitem\n                  WHERE ((coitem_status<>'X') AND (coitem_cohead_id=cohead_id))) = 0) THEN <? value("noLines") ?>\n         WHEN ( ( (SELECT COUNT(*)\n                     FROM coitem\n                    WHERE ((coitem_status='C')\n                      AND (coitem_cohead_id=cohead_id))) > 0)\n                      AND ( (SELECT COUNT(*)\n                               FROM coitem\n                              WHERE ((coitem_status NOT IN ('C','X'))\n                                AND (coitem_cohead_id=cohead_id))) = 0) ) THEN <? value("closed") ?>\n         WHEN ( ( (SELECT COUNT(*)\n                     FROM coitem\n                    WHERE ((coitem_status='C')\n                      AND (coitem_cohead_id=cohead_id))) = 0)\n                      AND ( (SELECT COUNT(*)\n                               FROM coitem\n                              WHERE ((coitem_status NOT IN ('C','X'))\n                                AND (coitem_cohead_id=cohead_id))) > 0) ) THEN <? value("open") ?>\n         ELSE <? value("partial") ?>\n       END AS order_status\nFROM cohead \n  JOIN custinfo ON (cust_id=cohead_cust_id)\n  LEFT OUTER JOIN saletype ON (saletype_id=cohead_saletype_id)\nWHERE ( (1=1)\n<? if exists("warehous_id") ?>\n  AND (cohead_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("cust_id") ?>\n  AND  (cohead_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n<? if exists("custtype_id") ?>\n  AND  (cust_custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n<? if exists("custtype_pattern") ?>\n  AND  (cust_custtype_id IN (SELECT custtype_id FROM custtype WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n<? endif ?>\n<? if exists("poNumber") ?>\n  AND  (cohead_custponumber~*<? value("poNumber") ?>)\n<? endif ?>\n<? if exists("prj_id") ?>\n  AND (cohead_prj_id = <? value("prj_id") ?>)\n<? endif ?>\n<? if exists("salesrep_id") ?>\n  AND (cohead_salesrep_id = <? value("salesrep_id") ?>)\n<? endif ?>\n<? if exists("saletype_id") ?>\n  AND (cohead_saletype_id = <? value("saletype_id") ?>)\n<? endif ?>\n<? if exists("hideClosed") ?>\n  AND (cohead_status NOT IN ('C', 'X'))\n<? endif ?>\n<? if exists("startDate") ?>\n    AND (cohead_orderdate >= <? value("startDate") ?>)\n<? endif ?>\n<? if exists("endDate") ?>\n    AND (cohead_orderdate <= <? value("endDate") ?>)\n<? endif ?>\n\n  AND   ((SELECT COUNT(*)\n         FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n                     JOIN site() ON (warehous_id=itemsite_warehous_id)\n        WHERE (coitem_cohead_id=cohead_id)) > 0) )\n<? if exists("orderByCust") ?>\n  ORDER BY cust_number, cohead_number;\n<? else ?>\nORDER BY cohead_number;\n<? endif ?>\n\n	admin	2015-10-01	0
478	saletype	table	 maintain saletype table\n Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: saletype\n-- Name: table\n-- Notes: maintain saletype table\n-- Copyright (c) 1999-2015 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists("CheckMode") ?>\n  SELECT saletype_id\n    FROM saletype\n   WHERE true\n  <? if exists("saletype_id") ?>\n    AND (saletype_id != <? value("saletype_id") ?>) \n  <? endif ?>\n  <? if exists("saletype_code") ?>\n    AND (UPPER(saletype_code)=UPPER(<? value("saletype_code") ?>)) \n  <? endif ?>\n  ORDER BY saletype_code;\n\n<? elseif exists("ViewMode") ?>\n  SELECT *\n    FROM saletype\n   WHERE true\n  <? if exists("saletype_id") ?>\n    AND (saletype_id=<? value("saletype_id") ?>) \n  <? endif ?>\n  <? if exists("saletype_code") ?>\n    AND (UPPER(saletype_code)=UPPER(<? value("saletype_code") ?>)) \n  <? endif ?>\n  ORDER BY saletype_code;\n\n<? elseif exists("NewMode") ?>\n  INSERT INTO saletype\n    ( saletype_code,\n      saletype_descr,\n      saletype_active,\n      saletype_default )\n  VALUES\n    ( UPPER(<? value("saletype_code") ?>),\n      <? value("saletype_descr") ?>,\n      <? value("saletype_active") ?>,\n      <? value("saletype_default") ?> )\n  RETURNING saletype_id;\n\n<? elseif exists("EditMode") ?>\n  UPDATE saletype\n    SET saletype_code=UPPER(<? value("saletype_code") ?>),\n        saletype_descr=<? value("saletype_descr") ?>,\n        saletype_active=<? value("saletype_active") ?>,\n        saletype_default=<? value("saletype_default") ?>\n  WHERE (saletype_id=<? value("saletype_id") ?>);\n\n<? elseif exists("DeleteMode") ?>\n  DELETE FROM saletype WHERE saletype_id=<? value("saletype_id") ?>;\n\n<? elseif exists("DeleteUnusedMode") ?>\n  SELECT deleteUnusedSaleTypes() AS result;\n\n<? else ?>\n  RAISE EXCEPTION 'saletype invalid mode';\n<? endif ?>\n	admin	2015-10-01	0
454	uiforms	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: uiforms\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists('byPackage') ?>\nSELECT uiform_id, uiform_name, uiform_enabled,\n       firstline(uiform_notes) AS uiform_notes, uiform_order,\n       CASE nspname WHEN 'public' THEN '' ELSE nspname END AS pkgname,\n       CASE nspname WHEN 'public' THEN 0\n                                  ELSE 1 END AS xtindentrole,\n       uiform_notes AS uiform_notes_qttooltiprole\n  FROM uiform\n  JOIN pg_class     ON (uiform.tableoid=pg_class.oid)\n  JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\nUNION \nSELECT -1, pkghead_name, NULL,\n       firstline(pkghead_descrip), NULL,\n       pkghead_name, 0, pkghead_descrip\n  FROM uiform, pg_class, pg_namespace\n  RIGHT OUTER JOIN pkghead ON (nspname=pkghead_name) \n WHERE ((uiform.tableoid=pg_class.oid)\n    AND (relnamespace=pg_namespace.oid))\n ORDER BY pkgname, xtindentrole, uiform_name,\n          uiform_order, uiform_id;\n<? else ?>\nSELECT uiform_id, uiform_name, uiform_enabled,\n       firstline(uiform_notes) AS uiform_notes,\n       uiform_order,\n       CASE nspname WHEN 'public' THEN '' ELSE nspname END AS pkgname,\n       uiform_notes AS uiform_notes_qttooltiprole\n  FROM uiform\n  JOIN pg_class     ON (uiform.tableoid=pg_class.oid)\n  JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\nORDER BY uiform_name, uiform_order, uiform_id;\n<? endif ?>\n	admin	2015-10-01	0
84	schedule	plannedorders	 used by dpsPlannedOrdersByItem, dspPlannedOrdersByPlannerCode, dspPlannedRevenueExpensesByPlannerCode\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: schedule\n-- Name:  plannedorders\n-- Notes: used by dpsPlannedOrdersByItem, dspPlannedOrdersByPlannerCode, dspPlannedRevenueExpensesByPlannerCode\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n SELECT *,\n        plorevenue - plocost AS profit,\n        formatMoney(plorevenue - plocost) AS f_profit,\n        CASE WHEN plocost > plorevenue THEN 'error'\n        END AS plorevenue_xtforegroundrole,\n        CASE WHEN (planord_firm) THEN 'emphasis'\n        END AS qtforegroundrole,\n        'qty' AS planord_qty_xtnumericrole,\n        'curr' AS plocost_xtnumericrole,\n        'curr' AS plorevenue_xtnumericrole,\n        'curr' AS profit_xtnumericrole,\n        0 AS plocost_xttotalrole,\n        0 AS plorevenue_xttotalrole,\n        0 AS profit_xttotalrole\n FROM (\n SELECT planord_id, planord_itemsite_id,\n        planord.*,\n        (select plancode_code from plancode where plancode_id = itemsite.itemsite_plancode_id) as plancode,\n        formatPloNumber(planord_id) AS ordernum,\n        CASE WHEN (planord_type='P') THEN 'P/O'\n             WHEN (planord_type='W') THEN 'W/O'\n             WHEN (planord_type='T') THEN 'T/O'\n             ELSE '?'\n        END AS ordtype,\n        formatDate(planord_duedate) AS f_duedate,\n        formatDate(planord_startdate) AS f_startdate,\n        formatQty(planord_qty) AS f_qty,\n        formatboolYN(planord_firm) AS f_firm,\n        whsinfo.warehous_code AS warehous_code,\n        supplywhsinfo.warehous_code AS supply_warehous_code,\n        item_number,\n        (item_descrip1 || ' ' || item_descrip2) AS item_descrip,\n        firstline(planord_comments) AS comments,\n        uom_name,\n        (classcode_code || '-' || classcode_descrip) AS f_classcode,\n <? if exists("useActualCost") ?>\n        (actcost(item_id) * planord_qty)\n <? elseif exists("useStandardCost") ?>\n        (stdcost(item_id) * planord_qty)\n <? else ?>\n        0\n <? endif ?> AS plocost,\n <? if exists("useListPrice") ?>\n        (item_listprice * planord_qty)\n <? elseif exists("useAveragePrice") ?>\n        (CASE WHEN(averageSalesPrice(itemsite.itemsite_id,\n                                <? value("startEvalDate") ?>,\n                                <? value("endEvalDate") ?>)=0)\n                                THEN item_listprice\n              ELSE averageSalesPrice(itemsite.itemsite_id,\n                                <? value("startEvalDate") ?>,\n                                <? value("endEvalDate") ?>)\n              END * planord_qty)\n <? else ?>\n         0\n <? endif ?> AS plorevenue,\n <? if exists("useActualCost") ?>\n        formatMoney(actcost(item_id) * planord_qty)\n <? elseif exists("useStandardCost") ?>\n        formatMoney(stdcost(item_id) * planord_qty)\n <? else ?>\n        formatMoney(0)\n <? endif ?> AS f_plocost,\n <? if exists("useListPrice") ?>\n        formatMoney(item_listprice * planord_qty)\n <? elseif exists("useAveragePrice") ?>\n        formatMoney(CASE WHEN(averageSalesPrice(itemsite.itemsite_id,\n                                                <? value("startEvalDate") ?>,\n                                                <? value("endEvalDate") ?>)=0)\n                                 THEN item_listprice\n                         ELSE averageSalesPrice(itemsite.itemsite_id,\n                                                <? value("startEvalDate") ?>,\n                                                <? value("endEvalDate") ?>)\n                    END * planord_qty)\n <? else ?>\n         formatMoney(0)\n <? endif ?> AS f_plorevenue\n FROM planord JOIN itemsite ON (planord_itemsite_id=itemsite.itemsite_id)\n              JOIN whsinfo ON (itemsite.itemsite_warehous_id=whsinfo.warehous_id)\n              JOIN item ON (itemsite.itemsite_item_id=item_id)\n              JOIN uom ON (item_inv_uom_id=uom_id)\n              LEFT OUTER JOIN classcode ON (classcode_id=item_classcode_id)\n              LEFT OUTER JOIN itemsite supplyitemsite ON (planord_supply_itemsite_id=supplyitemsite.itemsite_id)\n              LEFT OUTER JOIN whsinfo supplywhsinfo ON (supplyitemsite.itemsite_warehous_id=supplywhsinfo.warehous_id)\n <? if exists("itemgrp_id") ?>\n              JOIN itemgrpitem ON (itemgrpitem_item_id=item_id)\n              JOIN itemgrp ON (itemgrp_id=itemgrpitem_itemgrp_id AND itemgrp_id=<? value("itemgrp_id") ?>)\n <? endif ?>\n WHERE (TRUE\n <? if exists("item_id") ?>\n    AND (itemsite.itemsite_item_id=<? value("item_id") ?>)\n <? endif ?>\n <? if exists("classcode_id") ?>\n    AND (item.item_classcode_id=<? value("classcode_id") ?>)\n <? endif ?>\n <? if exists("plancode_id") ?>\n    AND (itemsite.itemsite_plancode_id=<? value("plancode_id") ?>)\n <? elseif exists("plancode_pattern") ?>\n    AND (itemsite.itemsite_plancode_id IN (SELECT plancode_id\n                                           FROM plancode\n                                           WHERE (plancode_code ~ <? value("plancode_pattern") ?>)))\n <? endif ?>\n <? if exists("warehous_id") ?>\n    AND (itemsite.itemsite_warehous_id=<? value("warehous_id") ?>)\n <? endif ?>\n <? if exists("startDate") ?>\n    AND (planord_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n <? endif ?>\n <? if exists("soldOnly") ?>\n    AND (item_sold)\n <? endif ?>\n <? if exists("type_list") ?>\n    AND (\n   <? foreach("type_list") ?>\n    (planord_type=<? value("type_list") ?>) OR\n   <? endforeach ?>\n    FALSE )\n <? endif ?>\n  ) ) AS data\n ORDER BY planord_duedate, item_number;\n	admin	2015-10-01	0
453	scripts	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: scripts\n-- Name:  detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n<? if exists('byPackage') ?>\nSELECT script_id, script_name, script_enabled,\n       firstline(script_notes) AS script_notes, script_order,\n       CASE nspname WHEN 'public' THEN '' ELSE nspname END AS pkgname,\n       CASE nspname WHEN 'public' THEN 0\n                                  ELSE 1 END AS xtindentrole,\n       script_notes AS script_notes_qttooltiprole\n  FROM script\n  JOIN pg_class     ON (script.tableoid=pg_class.oid)\n  JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\n UNION \nSELECT -1, pkghead_name, NULL,\n       firstline(pkghead_descrip), NULL,\n       pkghead_name, 0, pkghead_descrip \n  FROM script, pg_class, pg_namespace\n     RIGHT OUTER JOIN pkghead ON (nspname=pkghead_name)\n   WHERE ((script.tableoid=pg_class.oid)\n     AND  (relnamespace=pg_namespace.oid))\n   ORDER BY pkgname, xtindentrole, script_name, script_order, script_id;\n<? else ?>\nSELECT script_id, script_name, script_enabled,\n       firstline(script_notes) AS script_notes, script_order,\n       CASE nspname WHEN 'public' THEN '' ELSE nspname END AS pkgname,\n       script_notes AS script_notes_qttooltiprole\n  FROM script\n  JOIN pg_class     ON (script.tableoid=pg_class.oid)\n  JOIN pg_namespace ON (relnamespace=pg_namespace.oid)\nORDER BY script_name, script_order, script_id;\n<? endif ?>\n	admin	2015-10-01	0
131	selectPayments	applyallcredits	 used by selectPayments\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: selectPayments\n-- Name: applyallcredits\n-- Notes: used by selectPayments\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n\nSELECT applyapcredits(vend_id) AS result\nFROM vendinfo\nWHERE ((TRUE)\n<? if exists("vend_id") ?>\n   AND (vend_id = <? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n   AND (vend_vendtype_id = <? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n   AND (vend_vendtype_id IN (SELECT vendtype_id\n                             FROM vendtype\n                             WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n      );\n	admin	2015-10-01	0
490	selectPayments	clearall	 used by selectPayments\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: selectPayments\n-- Name: clearall\n-- Notes: used by selectPayments\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\n\nSELECT clearPayment(apselect_id) AS result\nFROM vendinfo JOIN apopen ON (apopen_vend_id=vend_id)\n              JOIN apselect ON (apselect_apopen_id=apopen_id)\nWHERE ((TRUE)\n<? if exists("vend_id") ?>\n   AND (vend_id = <? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\n   AND (vend_vendtype_id = <? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\n   AND (vend_vendtype_id IN (SELECT vendtype_id\n                             FROM vendtype\n                             WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n      );\n	admin	2015-10-01	0
491	selectPayments	discountitems	 used by selectPayments\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: selectPayments\n-- Name: discountitems\n-- Notes: used by selectPayments\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT selectDiscountItemsForPayment(vend_id, <? value("bankaccnt_id") ?>) AS result\nFROM vendinfo\n<? if exists("vend_id") ?>\nWHERE (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\nWHERE (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\nWHERE (vend_vendtype_id IN (SELECT vendtype_id\n                            FROM vendtype\n                            WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n;\n	admin	2015-10-01	0
492	selectPayments	dueitems	 used by selectPayments\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: selectPayments\n-- Name: dueitems\n-- Notes: used by selectPayments\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT selectDueItemsForPayment(vend_id, <? value("bankaccnt_id") ?>) AS result\nFROM vendinfo\n<? if exists("vend_id") ?>\nWHERE (vend_id=<? value("vend_id") ?>)\n<? elseif exists("vendtype_id") ?>\nWHERE (vend_vendtype_id=<? value("vendtype_id") ?>)\n<? elseif exists("vendtype_pattern") ?>\nWHERE (vend_vendtype_id IN (SELECT vendtype_id\n                            FROM vendtype\n                            WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))\n<? endif ?>\n;\n	admin	2015-10-01	0
124	updateprices	remove	\n Notes:\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: updateprices\n-- Name: remove\n-- Notes:\n-- Notes:\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nDELETE FROM selsched\n<? if exists("ipshead_id") ?>\nWHERE (selsched_ipshead_id=<? value("ipshead_id") ?>)\n<? endif ?>\n;\n	admin	2015-10-01	0
85	shipments	detail	 used by dspShipmentsByDate, dspShipmentsBySalesOrder, dspShipmentsByShipment\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: shipments\n-- Name: detail\n-- Notes: used by dspShipmentsByDate, dspShipmentsBySalesOrder, dspShipmentsByShipment\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT shiphead_id, lineitem_id,\n       CASE WHEN (level=0) THEN order_number\n            ELSE item_number\n       END AS order_item,\n       CASE WHEN (level=0) THEN customer\n            ELSE itemdescription\n       END AS cust_desc,\n       shiphead_order_type,\n       shiphead_number, \n       order_number, \n       customer,\n       shiphead_shipdate,\n       formatDate(shiphead_shipdate) AS f_shipdate,\n       shiphead_tracknum,\n       shiphead_freight,\n       freight_curr_abbr,\n       linenumber,\n       item_number,\n       itemdescription,\n       warehous_code,\n       qtyord,\n       formatQty(qtyord) AS f_qtyord,\n       qtyshipped,\n       formatQty(qtyshipped) AS f_qtyshipped,\n       notes,\n       'qty' AS qtyord_xtnumericrole,\n       'qty' AS qtyshipped_xtnumericrole,\n       'curr' AS shiphead_freight_xtnumericrole,\n       CASE WHEN (COALESCE(linenumber, 0) = 0) THEN '' END AS linenumber_qtdisplayrole,\n       CASE WHEN (COALESCE(qtyord, 0) = 0) THEN '' END AS qtyord_qtdisplayrole,\n       CASE WHEN (COALESCE(qtyshipped, 0) = 0) THEN '' END AS qtyshipped_qtdisplayrole,\n       CASE WHEN (COALESCE(shiphead_freight, 0) = 0) THEN '' END AS shiphead_freight_qtdisplayrole,\n       level AS xtindentrole\nFROM (\nSELECT DISTINCT\n       shiphead_id, -1 AS lineitem_id, cohead_number AS sortkey1, shiphead_number AS sortkey2, 0 AS level,\n       shiphead_order_type,\n       shiphead_number,\n       cohead_number AS order_number, \n       (cust_number || '-' || cust_name) AS customer,\n       shiphead_shipdate,\n       shiphead_tracknum,\n       shiphead_freight,\n       currConcat(shiphead_freight_curr_id) AS freight_curr_abbr, \n       0 AS linenumber, '' AS item_number,\n       '' AS itemdescription,\n       '' AS warehous_code,\n       0 AS qtyord,\n       0 AS qtyshipped,\n       firstline(shiphead_notes) AS notes\nFROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)\n              JOIN custinfo ON (cust_id=cohead_cust_id)\n<? if exists("warehous_id") ?>\n              JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)\n              JOIN coitem ON (coitem_id=shipitem_orderitem_id)\n              JOIN itemsite ON (itemsite_id=coitem_itemsite_id)\n<? endif ?>\nWHERE ( (shiphead_order_id=cohead_id)\n AND (cohead_cust_id=cust_id)\n AND (shiphead_shipped)\n AND (shiphead_order_type='SO')\n<? if exists("startDate") ?>\n AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n AND (itemsite_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("sohead_id") ?>\n AND (cohead_id = <? value("sohead_id") ?>)\n<? endif ?>\n<? if exists("shiphead_id") ?>\n AND (shiphead_id = <? value("shiphead_id") ?>)\n<? endif ?>\n      ) \nUNION\nSELECT shiphead_id, coitem_id AS lineitem_id, cohead_number AS sortkey1, shiphead_number AS sortkey2, 1 AS level,\n       '' AS shiphead_order_type,\n       '' AS shiphead_number,\n       '' AS order_number, \n       '' AS customer,\n       CAST(NULL AS DATE) AS shiphead_shipdate,\n       '' AS shiphead_tracknum,\n       0 AS shiphead_freight,\n       '' AS freight_curr_abbr, \n       coitem_linenumber AS linenumber, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescription,\n       warehous_code,\n       coitem_qtyord AS qtyord,\n       SUM(shipitem_qty) AS qtyshipped,\n       '' AS notes\nFROM shipitem, shiphead, coitem, cohead, custinfo, itemsite, item, whsinfo\nWHERE ( (shipitem_shiphead_id=shiphead_id)\n AND (shipitem_orderitem_id=coitem_id)\n AND (coitem_itemsite_id=itemsite_id)\n AND (coitem_status <> 'X')\n AND (itemsite_item_id=item_id)\n AND (itemsite_warehous_id=warehous_id)\n AND (shiphead_order_id=cohead_id)\n AND (cohead_cust_id=cust_id)\n AND (shiphead_shipped)\n AND (shiphead_order_type='SO')\n<? if exists("startDate") ?>\n AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n AND (itemsite_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("sohead_id") ?>\n AND (cohead_id = <? value("sohead_id") ?>)\n<? endif ?>\n<? if exists("shiphead_id") ?>\n AND (shiphead_id = <? value("shiphead_id") ?>)\n<? endif ?>\n      ) \nGROUP BY shiphead_id, coitem_id, shiphead_order_type, shiphead_number,\n         cohead_number, cust_number, cust_name, shiphead_shipdate,\n         coitem_linenumber, item_number, item_descrip1, item_descrip2,\n         warehous_code, shiphead_tracknum, coitem_qtyord, \n         shiphead_freight, shiphead_freight_curr_id \n<? if exists("MultiWhs") ?>\nUNION\nSELECT shiphead_id, -1 AS lineitem_id, tohead_number AS sortkey1, shiphead_number AS sortkey2, 0 AS level,\n       shiphead_order_type,\n       shiphead_number,\n       tohead_number AS order_number, \n       tohead_destname AS customer,\n       shiphead_shipdate,\n       shiphead_tracknum,\n       shiphead_freight,\n       currConcat(shiphead_freight_curr_id) AS freight_curr_abbr, \n       0 AS linenumber, '' AS item_number,\n       '' AS itemdescription,\n       '' AS warehous_code,\n       0 AS qtyord,\n       0 AS qtyshipped,\n       firstline(shiphead_notes) AS notes\nFROM shiphead, tohead \nWHERE ( (shiphead_order_id=tohead_id)\n AND (shiphead_shipped)\n AND (shiphead_order_type='TO')\n<? if exists("startDate") ?>\n AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n AND (tohead_src_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("tohead_id") ?>\n AND (tohead_id = <? value("tohead_id") ?>)\n<? endif ?>\n<? if exists("shiphead_id") ?>\n AND (shiphead_id = <? value("shiphead_id") ?>)\n<? endif ?>\n      ) \nUNION\nSELECT shiphead_id, toitem_id AS lineitem_id, tohead_number AS sortkey1, shiphead_number AS sortkey2, 1 AS level,\n       '' AS shiphead_order_type,\n       '' AS shiphead_number,\n       '' AS order_number, \n       '' AS customer,\n       CAST(NULL AS DATE) AS shiphead_shipdate,\n       '' AS shiphead_tracknum,\n       0 AS shiphead_freight,\n       '' AS freight_curr_abbr, \n       toitem_linenumber AS linenumber, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescription,\n       tohead_srcname AS warehous_code,\n       toitem_qty_ordered AS qtyord,\n       SUM(shipitem_qty) AS qtyshipped,\n       '' AS notes\nFROM shipitem, shiphead, toitem, tohead, item \nWHERE ( (shipitem_shiphead_id=shiphead_id)\n AND (shipitem_orderitem_id=toitem_id)\n AND (toitem_status <> 'X')\n AND (toitem_item_id=item_id)\n AND (shiphead_order_id=tohead_id)\n AND (shiphead_shipped)\n AND (shiphead_order_type='TO')\n<? if exists("startDate") ?>\n AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)\n<? endif ?>\n<? if exists("warehous_id") ?>\n AND (tohead_src_warehous_id = <? value("warehous_id") ?>)\n<? endif ?>\n<? if exists("tohead_id") ?>\n AND (tohead_id = <? value("tohead_id") ?>)\n<? endif ?>\n<? if exists("shiphead_id") ?>\n AND (shiphead_id = <? value("shiphead_id") ?>)\n<? endif ?>\n      ) \nGROUP BY shiphead_id, toitem_id, shiphead_order_type, shiphead_number,\n         tohead_number, shiphead_shipdate,\n         toitem_linenumber, item_number, item_descrip1, item_descrip2,\n         tohead_srcname, shiphead_tracknum, toitem_qty_ordered, \n         shiphead_freight, shiphead_freight_curr_id, notes\n<? endif ?>\n   ) AS data\nORDER BY sortkey1, sortkey2, level, linenumber DESC;\n	admin	2015-10-01	0
86	shippingForm	shipment	 used by printShippingForm\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: shippingForm\n-- Name: shipment\n-- Notes: used by printShippingForm\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT cohead_id AS order_id, cohead_shiptoname AS shipto, \n       cohead_shiptoaddress1 AS addr1, shiphead_order_type, \n       shiphead_id, shiphead_shipchrg_id, shiphead_shipped, \n\tCOALESCE(shiphead_shipform_id, cohead_shipform_id) AS shipform_id \nFROM cohead, shiphead \nWHERE ((cohead_id=shiphead_order_id)\n  AND  (shiphead_order_type='SO')\n  AND  (shiphead_id=<? value("shiphead_id") ?> )\n<? if exists("sohead_id") ?>\n  AND  (cohead_id=<? value("sohead_id") ?> )\n<? endif ?>\n) \n<? if exists("MultiWhs") ?>\nUNION \nSELECT tohead_id AS order_id, tohead_destname AS shipto, \n       tohead_destaddress1 AS addr1, shiphead_order_type, \n       shiphead_id, shiphead_shipchrg_id, shiphead_shipped, \n\tCOALESCE(shiphead_shipform_id, tohead_shipform_id) AS shipform_id \nFROM tohead, shiphead \nWHERE ((tohead_id=shiphead_order_id)\n  AND  (shiphead_order_type='TO')\n  AND  (shiphead_id=<? value("shiphead_id") ?> )\n<? if exists("tohead_id") ?>\n  AND  (tohead_id=<? value("tohead_id") ?> )\n<? endif ?>\n) \nORDER BY shiphead_shipped \n<? endif ?>\nLIMIT 1;\n	admin	2015-10-01	0
282	slowMovingInventoryByClassCode	detail	 used by dspSlowMovingInventoryByClassCode\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: slowMovingInventoryByClassCode\n-- Name: detail\n-- Notes: used by dspSlowMovingInventoryByClassCode\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT itemsite_id, warehous_code, item_number,\n       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip, uom_name,\n       itemsite_qtyonhand, itemsite_datelastused, cost,\n       noNeg(cost * itemsite_qtyonhand) AS value,\n       CASE WHEN (COALESCE(itemsite_datelastused, startOfTime()) <= startOfTime()) THEN 'N/A'\n       END AS itemsite_datelastused_qtdisplayrole,\n       'qty' AS itemsite_qtyonhand_xtnumericrole,\n       'cost' AS cost_xtnumericrole,\n       'curr' AS value_xtnumericrole,\n       0 AS itemsite_qtyonhand_xttotalrole,\n       0 AS value_xttotalrole\nFROM ( SELECT itemsite_id, warehous_code, item_number,\n              item_descrip1, item_descrip2, uom_name,\n              itemsite_qtyonhand, itemsite_datelastused,\n            <? if exists("useActualCosts") ?>\n              actcost(itemsite_item_id) \n            <? else ?>\n              stdcost(itemsite_item_id) \n            <? endif ?> AS cost \n       FROM itemsite, item, whsinfo, uom\n       WHERE ((itemsite_item_id=item_id)\n          AND (item_inv_uom_id=uom_id)\n          AND (itemsite_warehous_id=warehous_id)\n          AND (itemsite_active)\n          AND (itemsite_datelastused < <? value("cutoffDate") ?>)\n        <? if exists("warehous_id") ?>\n          AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n        <? endif ?>\n        <? if exists("classcode_id") ?>\n          AND (item_classcode_id=<? value("classcode_id") ?>)\n        <? elseif exists("classcode_pattern") ?>\n          AND (item_classcode_id IN (SELECT classcode_id FROM classcode WHERE classcode_code ~ <? value("classcode_pattern") ?>))\n        <? endif ?>\n              )\n     ) AS data \nORDER BY warehous_code, \n     <? if exists("sortByItem") ?>\n       item_number\n     <? elseif exists("sortByDate") ?>\n       itemsite_datelastused\n     <? else ?>\n       noNeg(cost * itemsite_qtyonhand) DESC\n     <? endif ?>\n;\n	admin	2015-10-01	0
283	standardJournalHistory	detail	 used by dspStandardJournalHistory\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: standardJournalHistory\n-- Name: detail\n-- Notes: used by dspStandardJournalHistory\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT gltrans_sequence, gltrans_id,\n       sortdate, sortdoc, level, gltrans_amount,\n       gltrans_date, gltrans_journalnumber, gltrans_posted,\n       gltrans_docnumber, account,\n       debit, credit,\n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole,\n       CASE WHEN (debit = 0) THEN '' END AS debit_qtdisplayrole,\n       CASE WHEN (credit = 0) THEN '' END AS credit_qtdisplayrole,\n       level AS xtindentrole \nFROM (SELECT DISTINCT gltrans_sequence, -1 AS gltrans_id,\n             gltrans_date AS sortdate, gltrans_docnumber AS sortdoc, 0 AS level, 0 AS gltrans_amount,\n             gltrans_date, gltrans_journalnumber, gltrans_posted,\n             NULL AS gltrans_docnumber,\n             NULL AS account,\n             0 AS debit, 0 AS credit\n      FROM gltrans, accnt \n      WHERE ( (gltrans_accnt_id=accnt_id)\n          AND (NOT gltrans_deleted) \n          AND (gltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n          AND (gltrans_doctype='ST') ) \n      UNION \n      SELECT DISTINCT gltrans_sequence, -1 AS gltrans_id,\n             gltrans_date AS sortdate, gltrans_docnumber AS sortdoc, 1 AS level, 0 AS gltrans_amount,\n             CAST(NULL AS DATE) AS gltrans_date, CAST(NULL AS INTEGER) AS gltrans_journalnumber, \n             CAST(NULL AS BOOLEAN) AS gltrans_posted,\n             CASE WHEN (COALESCE(gltrans_docnumber, '') = '') THEN 'Unnamed'\n               ELSE gltrans_docnumber\n             END AS gltrans_docnumber,\n             NULL AS account,\n             0 AS debit, 0 AS credit \n      FROM gltrans, accnt \n      WHERE ( (gltrans_accnt_id=accnt_id)\n          AND (NOT gltrans_deleted)\n          AND (gltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n          AND (gltrans_doctype='ST') ) \n      UNION \n      SELECT gltrans_sequence, gltrans_id,\n             gltrans_date AS sortdate, gltrans_docnumber AS sortdoc, 2 AS level, gltrans_amount,\n             CAST(NULL AS DATE) AS gltrans_date, CAST(NULL AS INTEGER) AS gltrans_journalnumber,\n             CAST(NULL AS BOOLEAN) AS gltrans_posted,\n             NULL AS gltrans_docnumber,\n             (formatGLAccount(accnt_id) || ' - ' || accnt_descrip) AS account,\n             CASE WHEN (gltrans_amount < 0) THEN (gltrans_amount * -1)\n             END AS debit,\n             CASE WHEN (gltrans_amount > 0) THEN gltrans_amount\n             END AS credit \n      FROM gltrans, accnt \n      WHERE ( (gltrans_accnt_id=accnt_id)\n          AND (NOT gltrans_deleted) \n          AND (gltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)\n          AND (gltrans_doctype='ST') ) \n      ) AS data \nORDER BY sortdate, gltrans_sequence, sortdoc, level, gltrans_amount;\n	admin	2015-10-01	0
285	substituteAvailability	detail	 used by dspSubstituteAvailabilityByItem\n        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n        See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: substituteAvailability\n-- Name: detail\n-- Notes: used by dspSubstituteAvailabilityByItem\n--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n--        See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT s_itemsite_id, warehous_code, item_number, itemdescrip,\n       availableqoh, reorderlevel, leadtime, itemsub_rank,\n       allocated, ordered, available,\n       'qty' AS availableqoh_xtnumericrole,\n       'qty' AS allocated_xtnumericrole,\n       'qty' AS ordered_xtnumericrole,\n       'qty' AS reorderlevel_xtnumericrole,\n       'qty' AS available_xtnumericrole,\n       CASE WHEN (reorderlevel >= available) THEN 'error' END AS available_qtforegroundrole\nFROM (SELECT sub.itemsite_id AS s_itemsite_id,\n             warehous_code, item_number,\n             (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,\n<? if exists("normalize") ?>\n             (qtyAvailable(sub.itemsite_id) * itemsub_uomratio) AS availableqoh,\n             (CASE WHEN(sub.itemsite_useparams)\n                   THEN sub.itemsite_reorderlevel\n                ELSE 0.0\n             END * itemsub_uomratio) AS reorderlevel,\n             sub.itemsite_leadtime AS leadtime, itemsub_rank,\n<? else ?>\n             (qtyAvailable(sub.itemsite_id)) AS availableqoh,\n             CASE WHEN(sub.itemsite_useparams) THEN sub.itemsite_reorderlevel\n               ELSE 0.0\n             END AS reorderlevel,\n             sub.itemsite_leadtime AS leadtime, itemsub_rank,\n<? endif ?>\n<? if exists("leadTime") ?>\n  <? if exists("normalize") ?>\n             (qtyAllocated(sub.itemsite_id, sub.itemsite_leadtime) * itemsub_uomratio) AS allocated,\n             (qtyOrdered(sub.itemsite_id, sub.itemsite_leadtime) * itemsub_uomratio) AS ordered,\n             ((qtyAvailable(sub.itemsite_id) * itemsub_uomratio)\n              + (qtyOrdered(sub.itemsite_id, sub.itemsite_leadtime) * itemsub_uomratio)\n              - (qtyAllocated(sub.itemsite_id, sub.itemsite_leadtime) * itemsub_uomratio)) AS available\n  <? else ?>\n             (qtyAllocated(sub.itemsite_id, sub.itemsite_leadtime)) AS allocated,\n             (qtyOrdered(sub.itemsite_id, sub.itemsite_leadtime)) AS ordered,\n             (qtyAvailable(sub.itemsite_id) + qtyOrdered(sub.itemsite_id, sub.itemsite_leadtime)\n              - qtyAllocated(sub.itemsite_id, sub.itemsite_leadtime)) AS available\n  <? endif ?>\n<? elseif exists("byDays") ?>\n  <? if exists("normalize") ?>\n             (qtyAllocated(sub.itemsite_id, <? value("days") ?>) * itemsub_uomratio) AS allocated,\n             (qtyOrdered(sub.itemsite_id, <? value("days") ?>) * itemsub_uomratio) AS ordered,\n             ((qtyAvailable(sub.itemsite_id) * itemsub_uomratio) + (qtyOrdered(sub.itemsite_id, <? value("days") ?>) * itemsub_uomratio)\n              - (qtyAllocated(sub.itemsite_id, <? value("days") ?>) * itemsub_uomratio)) AS available\n  <? else ?>\n             (qtyAllocated(sub.itemsite_id, <? value("days") ?>)) AS allocated,\n             (qtyOrdered(sub.itemsite_id, <? value("days") ?>)) AS ordered,\n             (qtyAvailable(sub.itemsite_id) + qtyOrdered(sub.itemsite_id, <? value("days") ?>)\n              - qtyAllocated(sub.itemsite_id, <? value("days") ?>)) AS available\n  <? endif ?>\n<? elseif exists("byDate") ?>\n  <? if exists("normalize") ?>\n             (qtyAllocated(sub.itemsite_id, (<? value("date") ?> - CURRENT_DATE)) * itemsub_uomratio) AS allocated,\n             (qtyOrdered(sub.itemsite_id, (<? value("date") ?> - CURRENT_DATE)) * itemsub_uomratio) AS ordered,\n             ((qtyAvailable(sub.itemsite_id) * itemsub_uomratio) + (qtyOrdered(sub.itemsite_id, (<? value("date") ?> - CURRENT_DATE)) * itemsub_uomratio)\n              - (qtyAllocated(sub.itemsite_id, (<? value("date") ?> - CURRENT_DATE)) * itemsub_uomratio)) AS available\n  <? else ?>\n             (qtyAllocated(sub.itemsite_id, (<? value("date") ?> - CURRENT_DATE))) AS allocated,\n             (qtyOrdered(sub.itemsite_id, (<? value("date") ?> - CURRENT_DATE))) AS ordered,\n             (qtyAvailable(sub.itemsite_id) + qtyOrdered(sub.itemsite_id,\n             (<? value("date") ?> - CURRENT_DATE)) - qtyAllocated(sub.itemsite_id, (<? value("date") ?> - CURRENT_DATE))) AS available\n  <? endif ?>\n<? endif ?>\n      FROM item, itemsite AS sub, itemsite AS root, whsinfo, itemsub\n      WHERE ((sub.itemsite_item_id=item_id)\n         AND (root.itemsite_item_id=itemsub_parent_item_id)\n         AND (sub.itemsite_item_id=itemsub_sub_item_id)\n         AND (root.itemsite_warehous_id=sub.itemsite_warehous_id)\n         AND (sub.itemsite_warehous_id=warehous_id)\n         AND (root.itemsite_item_id=<? value("item_id") ?>)\n<? if exists("warehous_id") ?>\n         AND (root.itemsite_warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n            )\n     ) AS data\nORDER BY itemsub_rank;\n	admin	2015-10-01	0
125	updateprices	selsched	\n Notes:\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: updateprices\n-- Name: selsched\n-- Notes:\n-- Notes:\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT selsched_ipshead_id, ipshead_name, ipshead_descrip\nFROM selsched\n JOIN ipshead ON (selsched_ipshead_id=ipshead_id)\nORDER BY ipshead_name\n	admin	2015-10-01	0
108	summarizedBacklogByWarehouse	detail	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: summarizedBacklogByWarehouse\n-- Name: detail\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT * FROM (\n(SELECT cohead_id, 0 AS xtindentrole, salesrep_name, cohead_holdtype, cohead_number, \n   coheadstatecolor(cohead_id) AS qtforegroundrole, \n   cust_name,       \n   cohead_created, cohead_orderdate, cohead_packdate, pack_head_id,       \n          CASE WHEN (cohead_holdtype='N') THEN <? value("none") ?>\n               WHEN (cohead_holdtype='C') THEN <? value("credit") ?>\n               WHEN (cohead_holdtype='S') THEN <? value("ship") ?>\n               WHEN (cohead_holdtype='P') THEN <? value("pack") ?>\n               WHEN (cohead_holdtype='R') THEN <? value("return") ?>\n               ELSE <? value("other") ?>\n   END AS f_holdtype,       \n   MIN(coitem_scheddate) AS scheddate,       \n   SUM((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *            \n               (currToBase(cohead_curr_id, coitem_price, cohead_orderdate) / coitem_price_invuomratio) ) AS sales, \n   SUM((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) * stdcost(item_id) ) AS cost,\n   SUM((noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio) *\n               ((currToBase(cohead_curr_id, coitem_price, cohead_orderdate) / coitem_price_invuomratio) - stdcost(item_id)) ) AS margin,\n   'curr' AS sales_xtnumericrole,\n   'curr' AS cost_xtnumericrole,\n   'curr' AS margin_xtnumericrole,\n    NULL AS shiphead_id, \n    NULL AS shiphead_number, \n    NULL AS shipstatus,\n    NULL AS shipvia,\n    CASE WHEN (pack_head_id IS NOT NULL) THEN TRUE\n    ELSE FALSE\n    END AS packed \n   <? if exists("showPrices") ?> \n    , 0 AS sales_xttotalrole, 0 AS cost_xttotalrole, 0 AS margin_xttotalrole \n   <? endif ?>,\n   cohead_number AS seq\n   FROM coitem, itemsite, item, custinfo, cohead\n     LEFT OUTER JOIN pack ON (cohead_id = pack_head_id), salesrep \n   WHERE ( (coitem_cohead_id=cohead_id)\n    AND (salesrep_id = cohead_salesrep_id) \n    AND (cohead_cust_id=cust_id)\n    AND (coitem_itemsite_id=itemsite_id)\n    AND (itemsite_item_id=item_id)\n    AND (coitem_status NOT IN ('C','X'))\n    AND (coitem_scheddate BETWEEN <? value("startDate") ?>\n                              AND <? value("endDate") ?>)\n   <? if exists("warehous_id") ?>\n    AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n   <? endif ?>\n   <? if exists("custtype_id") ?>\n    AND (cust_custtype_id=<? value("custtype_id") ?>)\n   <? elseif exists("custtype_pattern") ?>\n    AND (cust_custtype_id IN (SELECT custtype_id FROM custtype\n     WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n   <? endif ?>\n   ) \n   GROUP BY cohead_id, salesrep_number, salesrep_name, cohead_number, cust_name,\n            cohead_holdtype, cohead_orderdate, cohead_packdate,\n            cohead_created, pack_head_id )\n   UNION \n   (SELECT cohead_id, 1 AS xtindentrole, NULL, NULL, \n   shiphead_number AS cohead_number, \n   CASE WHEN (shiphead_shipped IS NULL) THEN ''           \n   WHEN (shiphead_shipped) THEN 'altemphasis'            \n   WHEN (NOT shiphead_shipped) THEN 'emphasis' \n   WHEN ( (COALESCE(cobmisc_cohead_id,0) > 0)       \n   AND (SUM(noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned)) > 0)       \n   ) THEN 'error'       \n   END AS qtforegroundrole, \n   COALESCE(shiphead_shipvia, ''), NULL, shiphead_shipdate AS cohead_orderdate, \n   NULL, NULL,\n   CASE WHEN (shiphead_shipped) THEN <? value("yes") ?>         \n   ELSE <? value("no") ?>       \n   END AS f_holdtype,  MIN(coitem_scheddate), NULL, NULL, NULL, NULL, NULL, NULL, NULL,        \n   formatShipmentNumber(shiphead_id) AS shiphead_number,        \n   NULL,       \n   COALESCE(shiphead_shipvia, '') AS shipvia           \n   <? if exists("showPrices") ?> \n    , NULL, NULL, NULL \n   <? endif ?>\n   , NULL,\n   cohead_number AS seq \n   FROM coitem, itemsite, item, custinfo, cohead\n   LEFT OUTER JOIN shiphead ON ((shiphead_order_id=cohead_id)   \n                            AND (shiphead_order_type='SO'))\n   LEFT OUTER JOIN (SELECT DISTINCT cobmisc_cohead_id FROM cobmisc) AS cobmisc ON (cobmisc_cohead_id=cohead_id)   \n   LEFT OUTER JOIN pack ON (cohead_id = pack_head_id), salesrep \n   WHERE ( (coitem_cohead_id=cohead_id)\n    AND (salesrep_id = cohead_salesrep_id) \n    AND (cohead_cust_id=cust_id)\n    AND (coitem_itemsite_id=itemsite_id)\n    AND (itemsite_item_id=item_id)\n    AND (coitem_status NOT IN ('C','X'))\n    AND (coitem_scheddate BETWEEN <? value("startDate") ?>\n                              AND <? value("endDate") ?>)\n   <? if exists("warehous_id") ?>\n    AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n   <? endif ?>\n   <? if exists("custtype_id") ?>\n    AND (cust_custtype_id=<? value("custtype_id") ?>)\n   <? elseif exists("custtype_pattern") ?>\n    AND (cust_custtype_id IN (SELECT custtype_id FROM custtype\n     WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n   <? endif ?>\n   AND ((SELECT (count(*)>0) FROM shipitem WHERE ((shipitem_shiphead_id=shiphead_id) AND (NOT shipitem_invoiced))))) \n   GROUP BY cohead_id, salesrep_number, salesrep_name, cohead_number, cust_name,         \n   cohead_holdtype, cohead_orderdate, cohead_packdate,         \n   shiphead_shipped, shiphead_shipvia, shiphead_shipdate,         \n   shiphead_id, cobmisc_cohead_id, cohead_created, pack_head_id,\n   shiphead_number )) AS data\n  ORDER BY seq, cohead_number;\n\n\n	admin	2015-10-01	0
109	summarizedBacklogByWarehouse	qtys	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: summarizedBacklogByWarehouse\n-- Name: qtys\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT formatQty(COALESCE(SUM(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned), 0)) AS f_totalqty \n         FROM cohead, coitem, itemsite, item, custinfo\n\t\t     WHERE ( (coitem_cohead_id=cohead_id)\n\t\t      AND (coitem_itemsite_id=itemsite_id)\n\t\t      AND (itemsite_item_id=item_id)\n\t\t      AND (cohead_cust_id=cust_id)\n\t\t      AND (coitem_status NOT IN ('C','X'))\n\t\t      AND (coitem_scheddate BETWEEN <? value("startDate") ?>\n\t\t                                AND <? value("endDate") ?>)\n\t\t     <? if exists("warehous_id") ?>\n\t\t      AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n\t\t     <? endif ?>\n\t\t     <? if exists("custtype_id") ?>\n\t\t      AND (cust_custtype_id=<? value("custtype_id") ?>)\n\t\t     <? elseif exists("custtype_pattern") ?>\n\t\t      AND (cust_custtype_id IN (SELECT custtype_id FROM custtype\n\t\t       WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n\t\t     <? endif ?>\n\t\t     );\n	admin	2015-10-01	0
110	summarizedBacklogByWarehouse	totals	 \n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: summarizedBacklogByWarehouse\n-- Name: totals\n-- Notes: \n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT COUNT(cohead_id) AS totalorders \n\t\t     FROM ( SELECT DISTINCT cohead_id \n                FROM cohead, coitem, itemsite, custinfo\n\t\t            WHERE ( (coitem_cohead_id=cohead_id)\n\t\t             AND (coitem_itemsite_id=itemsite_id)\n\t\t             AND (cohead_cust_id=cust_id)\n\t\t             AND (coitem_status NOT IN ('C','X'))\n\t\t      AND (coitem_scheddate BETWEEN <? value("startDate") ?>\n\t\t                                AND <? value("endDate") ?>)\n\t\t     <? if exists("warehous_id") ?>\n\t\t      AND (itemsite_warehous_id=<? value("warehous_id") ?>)\n\t\t     <? endif ?>\n\t\t     <? if exists("custtype_id") ?>\n\t\t      AND (cust_custtype_id=<? value("custtype_id") ?>)\n\t\t     <? elseif exists("custtype_pattern") ?>\n\t\t      AND (cust_custtype_id IN (SELECT custtype_id FROM custtype\n\t\t       WHERE (custtype_code ~ <? value("custtype_pattern") ?>)))\n\t\t     <? endif ?>\n\t\t     ) ) AS data;\n	admin	2015-10-01	0
287	summarizedGLTransactions	detail	 used by dspSummarizedGLTransactions\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: summarizedGLTransactions\n-- Name: detail\n-- Notes: used by dspSummarizedGLTransactions\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT accnt_id, gltrans_id,\n       account, accnt_descrip,\n       gltrans_date, gltrans_source, gltrans_doctype, gltrans_docnumber,\n       f_notes,\n       debit, credit,\n       gltrans_username, gltrans_created,\n       CASE WHEN (level=0) THEN accnt_descrip\n            ELSE f_notes \n       END AS descrip_notes, \n       'curr' AS debit_xtnumericrole,\n       'curr' AS credit_xtnumericrole,\n       0 AS debit_xtnumericrole,\n       0 AS credit_xtnumericrole,\n       CASE WHEN (debit=0) THEN '' END AS debit_qtdisplayrole,\n       CASE WHEN (credit=0) THEN '' END AS credit_qtdisplayrole,\n       level AS xtindentrole \nFROM ( \nSELECT DISTINCT accnt_id, -1 AS gltrans_id, 0 AS level,\n       accnt_number, accnt_profit, accnt_sub, \n      formatGLAccount(accnt_id) AS account, accnt_descrip,\n       CAST(NULL AS DATE) AS gltrans_date, '' AS gltrans_source, '' AS gltrans_doctype, '' AS gltrans_docnumber,\n         '' AS f_notes,\n       SUM( CASE WHEN (gltrans_amount < 0) THEN (gltrans_amount * -1) \n                        ELSE 0 \n                   END ) AS debit, \n       SUM( CASE WHEN (gltrans_amount > 0) THEN gltrans_amount \n                       ELSE 0 \n                  END ) AS credit, \n       '' AS gltrans_username, CAST(NULL AS TIMESTAMP) AS gltrans_created \nFROM gltrans, accnt \nWHERE ( (gltrans_accnt_id=accnt_id)\n AND (NOT gltrans_deleted) \n AND (gltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) \n\n  \n<? if exists("source") ?>\n     AND (gltrans_source=<? value("source") ?>)\n<? endif ?>\n  \n<? if exists("unpostedTransactions") ?>\n     AND (NOT gltrans_posted)\n<? elseif exists("postedTransactions") ?>\n       AND (gltrans_posted)\n<? endif ?>\n  ) GROUP BY accnt_id, accnt_number, accnt_profit, accnt_sub, accnt_descrip \n               UNION \n               SELECT accnt_id, gltrans_id, 1 AS level,\n                      accnt_number, accnt_profit, accnt_sub, \n                      '' AS account, '' AS accnt_descrip,\n                      gltrans_date, gltrans_source, gltrans_doctype, gltrans_docnumber,\n                      firstLine(gltrans_notes) AS f_notes,\n                      CASE WHEN (gltrans_amount < 0) THEN (gltrans_amount * -1)\n                           ELSE 0\n                      END AS debit,\n                      CASE WHEN (gltrans_amount > 0) THEN gltrans_amount\n                           ELSE 0\n                      END AS credit,\n                      gltrans_username, gltrans_created \n               FROM gltrans, accnt \n               WHERE ((gltrans_accnt_id=accnt_id)\n                AND (NOT gltrans_deleted) \n                AND (gltrans_date BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) \n\n<? if exists("source") ?>\n     AND (gltrans_source=<? value("source") ?>)\n<? endif ?>\n\n<? if exists("unpostedTransactions") ?>\n     AND (NOT gltrans_posted)\n<? elseif exists("postedTransactions") ?>\n       AND (gltrans_posted)\n<? endif ?>\n\n)) AS data \n ORDER BY accnt_number, accnt_profit, accnt_sub, level, gltrans_date DESC, gltrans_created;\n	admin	2015-10-01	0
288	summarizedSalesHistory	detail	\n Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n See www.xtuple.com/CPAL for the full text of the software license.\n	-- Group: summarizedSalesHistory\n-- Name: detail\n-- Notes:\n-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\n-- See www.xtuple.com/CPAL for the full text of the software license.\n\nSELECT 1 AS dummy,\n-- Columns added to match columns of Printed Report\n<? foreach("groupLitList") ?>\n  <? literal("groupLitList") ?>\n  <? if not isLast("groupLitList") ?>\n  || E'\\n' ||\n  <? endif ?>\n<? endforeach ?> AS groupsLit,\n<? foreach("groupList") ?>\n  substring(<? literal("groupList") ?> from 1 for 15)\n  <? if not isLast("groupList") ?>\n  || E'\\n' ||\n  <? endif ?>\n<? endforeach ?> AS groups,\n<? foreach("groupDescripList") ?>\n  substring(<? literal("groupDescripList") ?> from 1 for 30)\n  <? if not isLast("groupDescripList") ?>\n  || E'\\n' ||\n  <? endif ?>\n<? endforeach ?> AS groupsDescrip,\n-- End of columns for printed report\n       <? if exists("byCustomer") ?>\n         cust_number, cohist_cust_id AS cust_number_xtidrole, cust_name,\n       <? endif ?>\n       <? if exists("byCustomerType") ?>\n         custtype_code, custtype_id AS custtype_code_xtidrole,\n       <? endif ?>\n       <? if exists("byItem") ?>\n         item_number, item_id AS item_number_xtidrole, itemdescription,\n       <? endif ?>\n       <? if exists("bySalesRep") ?>\n         salesrep_number, salesrep_id AS salesrep_number_xtidrole, salesrep_name,\n       <? endif ?>\n       <? if exists("byShippingZone") ?>\n         shipzone_name, shipzone_id AS shipzone_name_xtidrole,\n       <? endif ?>\n       <? if exists("bySite") ?>\n         warehous_code, warehous_id AS warehous_code_xtidrole,\n       <? endif ?>\n       <? if exists("byCurrency") ?>\n         currAbbr,\n         MIN(custunitprice) AS minprice, MAX(custunitprice) AS maxprice,\n         AVG(custunitprice) AS avgprice,\n         SUM(custextprice) AS totalsales,\n         CASE WHEN (SUM(cohist_qtyshipped) = 0) THEN 0\n         ELSE SUM(custextprice) / SUM(cohist_qtyshipped)\n         END AS wtavgprice,\n       <? else ?>\n         currConcat(baseCurrId()) AS currAbbr,\n         MIN(baseunitprice) AS minprice, MAX(baseunitprice) AS maxprice,\n         AVG(baseunitprice) AS avgprice,\n         SUM(baseextprice) AS totalsales,\n         CASE WHEN (SUM(cohist_qtyshipped) = 0) THEN 0\n         ELSE SUM(baseextprice) / SUM(cohist_qtyshipped)\n         END AS wtavgprice,\n       <? endif ?>\n         SUM(cohist_qtyshipped) AS totalunits,\n         MIN(cohist_invcdate) AS firstdate,\n         MAX(cohist_invcdate) AS lastdate,\n         SUM(cohist_qtyshipped) AS qtyshipped,\n         'salesprice' AS minprice_xtnumericrole,\n         'salesprice' AS maxprice_xtnumericrole,\n         'salesprice' AS avgprice_xtnumericrole,\n         'salesprice' AS wtavgprice_xtnumericrole,\n         'qty' AS qtyshipped_xtnumericrole,\n         'curr' AS extprice_xtnumericrole,\n         'qty' AS totalunits_xtnumericrole,\n         'curr' AS totalsales_xtnumericrole,\n         'qty' AS totalunits_xtnumericrole,\n         'curr' AS totalsales_xtnumericrole,\n         0 AS totalunits_xttotalrole,\n         0 AS totalsales_xttotalrole\n<? if exists("includeMisc") ?>\n  FROM saleshistorymisc\n<? else ?>\n  FROM saleshistory\n<? endif ?>\nWHERE ( (TRUE)\n<? if exists("startDate") ?>\n AND (cohist_invcdate >= <? value("startDate") ?>)\n<? endif ?>\n\n<? if exists("endDate") ?>\n AND (cohist_invcdate <= <? value("endDate") ?>)\n<? endif ?>\n\n<? if exists("shipStartDate") ?>\n AND (cohist_shipdate >= <? value("shipStartDate") ?>)\n<? endif ?>\n\n<? if exists("shipEndDate") ?>\n AND (cohist_shipdate <= <? value("shipEndDate") ?>)\n<? endif ?>\n\n<? if exists("warehous_id") ?>\n AND (warehous_id=<? value("warehous_id") ?>)\n<? endif ?>\n\n<? if exists("item_id") ?>\n AND (item_id=<? value("item_id") ?>)\n<? endif ?>\n\n<? if exists("cust_id") ?>\n AND (cohist_cust_id=<? value("cust_id") ?>)\n<? endif ?>\n\n<? if exists("shipto_id") ?>\n AND (cohist_shipto_id=<? value("shipto_id") ?>)\n<? endif ?>\n\n<? if exists("salesrep_id") ?>\n AND (salesrep_id=<? value("salesrep_id") ?>)\n<? endif ?>\n\n<? if exists("prodcat_id") ?>\n AND (prodcat_id=<? value("prodcat_id") ?>)\n<? endif ?>\n\n<? if exists("prodcat_pattern") ?>\n AND (prodcat_code ~ <? value("prodcat_pattern") ?>)\n<? endif ?>\n\n<? if exists("custtype_id") ?>\n AND (custtype_id=<? value("custtype_id") ?>)\n<? endif ?>\n\n<? if exists("custtype_pattern") ?>\n   AND (custtype_code ~ <? value("custtype_pattern") ?>)\n<? endif ?>\n\n<? if exists("custgrp_id") ?>\n  AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                   FROM custgrpitem\n                   WHERE (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)))\n<? endif ?>\n\n<? if exists("custgrp_pattern") ?>\n  AND (cust_id IN (SELECT DISTINCT custgrpitem_cust_id\n                   FROM custgrp, custgrpitem\n                   WHERE ( (custgrpitem_custgrp_id=custgrp_id)\n                     AND   (custgrp_name ~ <? value("custgrp_pattern") ?>) )) )\n<? endif ?>\n\n<? if exists("shipzone_id") ?>\n AND (shipzone_id=<? value("shipzone_id") ?>)\n<? endif ?>\n\n<? if exists("curr_id") ?>\n AND cust_curr_id = <? value("curr_id") ?>\n<? endif ?>\n\n<? if exists("currConcat_pattern") ?>\n AND (currAbbr ~ <? value("currConcat_pattern") ?>)\n<? endif ?>\n)\nGROUP BY dummy\n<? if exists("bySalesRep") ?>\n , salesrep_id, salesrep_number, salesrep_name\n<? endif ?>\n<? if exists("byShippingZone") ?>\n , shipzone_id, shipzone_name, shipzone_descrip\n<? endif ?>\n<? if exists("byCustomer") ?>\n , cohist_cust_id, cust_number, cust_name\n<? endif ?>\n<? if exists("byCustomerType") ?>\n , custtype_id, custtype_code, custtype_descrip\n<? endif ?>\n<? if exists("byItem") ?>\n , item_id, item_number, itemdescription\n<? endif ?>\n<? if exists("bySite") ?>\n , warehous_id, warehous_code, warehous_descrip\n<? endif ?>\n<? if exists("byCurrency") ?>\n , cust_curr_id, currAbbr\n<? endif ?>\n ORDER BY dummy\n<? if exists("bySalesRep") ?>\n , salesrep_number\n<? endif ?>\n<? if exists("byShippingZone") ?>\n , shipzone_name\n<? endif ?>\n<? if exists("byCustomer") ?>\n , cust_number\n<? endif ?>\n<? if exists("byCustomerType") ?>\n , custtype_code\n<? endif ?>\n<? if exists("byItem") ?>\n , item_number\n<? endif ?>\n<? if exists("bySite") ?>\n , warehous_code\n<? endif ?>\n;	admin	2015-10-01	0
