"tables",
"triggers",
"types",
- "remove from 440_schema.sql everything that's defined here. it's now redundant",
- "public/functions/getaddrid.sql",
- "public/functions/getcharid.sql",
- "public/functions/getcntctid.sql",
- "public/functions/getcrmacctid.sql",
- "public/functions/getcurrid.sql",
- "public/functions/getcustid.sql",
- "public/functions/getimageid.sql",
- "public/functions/getincdtcatid.sql",
- "public/functions/getincdtcrmacctid.sql",
- "public/functions/getincdtpriorityid.sql",
- "public/functions/getincdtresolutionid.sql",
- "public/functions/getincdtseverityid.sql",
- "public/functions/getincidentid.sql",
- "public/functions/getprjid.sql",
- "public/functions/getprjtaskid.sql",
- "public/functions/getusrid.sql",
- "public/functions/getwarehousid.sql"
+ "remove from 440_schema.sql everything that's defined here. it's now redundant"
],
"databaseScripts": [
"public/tables/metric.sql",
"public/functions/asofinvbal.sql",
"public/functions/asofinvnn.sql",
"public/functions/asofinvqty.sql",
+ "public/functions/assessfinancecharge.sql",
"public/functions/attachcontact.sql",
"public/functions/attachquotetoopportunity.sql",
"public/functions/attachsalesordertoopportunity.sql",
"public/functions/calcbillingamts.sql",
"public/functions/calccashbudget.sql",
"public/functions/calccreditmemoamts.sql",
+ "public/functions/calcinvoiceamt.sql",
"public/functions/calcpendingarapplications.sql",
"public/functions/calcquoteamt.sql",
"public/functions/calcsalesorderamt.sql",
"public/functions/changeprdate.sql",
"public/functions/changeprqty.sql",
"public/functions/changepseudofkeypointers.sql",
+ "public/functions/changepurchasedropship.sql",
"public/functions/changewodates.sql",
"public/functions/changewoproject.sql",
"public/functions/changewoqty.sql",
"public/functions/freightdetailquote.sql",
"public/functions/freightforrecv.sql",
"public/functions/getactiverevid.sql",
+ "public/functions/getaddrid.sql",
"public/functions/getadjustmenttaxtypeid.sql",
"public/functions/getaropenid.sql",
"public/functions/getbankaccntid.sql",
"public/functions/getbooitemseqid.sql",
"public/functions/getbudgheadid.sql",
"public/functions/getcashrcptid.sql",
+ "public/functions/getcharid.sql",
"public/functions/getclasscodeid.sql",
"public/functions/getcmheadid.sql",
"public/functions/getcmnttypeid.sql",
+ "public/functions/getcntctid.sql",
"public/functions/getcoheadid.sql",
"public/functions/getcoitemid.sql",
"public/functions/getcostcatid.sql",
"public/functions/getcostelemid.sql",
+ "public/functions/getcrmacctid.sql",
+ "public/functions/getcurrid.sql",
"public/functions/getcustnamefrominfo.sql",
+ "public/functions/getcustid.sql",
"public/functions/getcusttypeid.sql",
"public/functions/getdeptid.sql",
"public/functions/getediprofileid.sql",
"public/functions/getfreighttaxtypeid.sql",
"public/functions/getgainlossaccntid.sql",
"public/functions/getglaccntid.sql",
+ "public/functions/getimageid.sql",
+ "public/functions/getincdtcatid.sql",
+ "public/functions/getincdtcrmacctid.sql",
+ "public/functions/getincdtpriorityid.sql",
+ "public/functions/getincdtresolutionid.sql",
+ "public/functions/getincdtseverityid.sql",
+ "public/functions/getincidentid.sql",
"public/functions/getinvcheadid.sql",
"public/functions/getinvcitemlotserial.sql",
"public/functions/getipsheadid.sql",
"public/functions/getpacklistitemlotserial.sql",
"public/functions/getperiodid.sql",
"public/functions/getpkgheadid.sql",
+ "public/functions/getopenshipment.sql",
"public/functions/getplancodeid.sql",
"public/functions/getpoheadid.sql",
"public/functions/getpoitemid.sql",
"public/functions/getprjaccntid.sql",
+ "public/functions/getprjid.sql",
+ "public/functions/getprjtaskid.sql",
"public/functions/getprodcatid.sql",
"public/functions/getprospectid.sql",
"public/functions/getquoteid.sql",
+ "public/functions/getquotescheddate.sql",
"public/functions/getquotelineitemid.sql",
"public/functions/getrevid.sql",
"public/functions/getrsnid.sql",
"public/functions/getshipviaid.sql",
"public/functions/getshipzoneid.sql",
"public/functions/getsitetypeid.sql",
+ "public/functions/getsoitemstatus.sql",
"public/functions/getsoscheddate.sql",
"public/functions/getsostatus.sql",
"public/functions/getsubtax.sql",
"public/functions/getunassignedaccntid.sql",
"public/functions/getuomid.sql",
"public/functions/getuomtypeid.sql",
+ "public/functions/getusrid.sql",
"public/functions/getvendaddrid.sql",
"public/functions/getvendid.sql",
"public/functions/getvendtypeid.sql",
+ "public/functions/getwarehousid.sql",
"public/functions/getwhsezoneid.sql",
"public/functions/grantallmodulecmnttypesource.sql",
"public/functions/grantallmodulepriv.sql",
"public/functions/qtylocation.sql",
"public/functions/qtyordered.sql",
"public/functions/qtypr.sql",
+ "public/functions/qtyreserved.sql",
"public/functions/qtytoreceive.sql",
"public/functions/recallshipment.sql",
"public/functions/recallwo.sql",
"public/functions/releasewo.sql",
"public/functions/releasewonumber.sql",
"public/functions/relocateinventory.sql",
+ "public/functions/reopenbankreconciliation.sql",
"public/functions/reorderdate.sql",
"public/functions/replaceallvoidedapchecks.sql",
"public/functions/replaceallvoidedchecks.sql",
"public/tables/metasql/package-items.mql",
"public/tables/metasql/packingList-getreport.mql",
"public/tables/metasql/packingList-shipment.mql",
+ "public/tables/metasql/packingListBatch-clear.mql",
"public/tables/metasql/packingListBatch-detail.mql",
"public/tables/metasql/packingListBatch-print.mql",
"public/tables/metasql/packingListBatchByShipVia-print.mql",
"public/tables/metasql/purchaseOrders-detail.mql",
"public/tables/metasql/qoh-detail.mql",
"public/tables/metasql/quoteItems-detail.mql",
+ "public/tables/metasql/quoteItems-list.mql",
"public/tables/metasql/quotes-detail.mql",
"public/tables/metasql/receipt-detail.mql",
"public/tables/metasql/receipt-receiveAll.mql",
CREATE OR REPLACE FUNCTION acknowledgeMessage(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pMsgid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION actCost(INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN actCost($1, NULL, baseCurrId());
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION actCost(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN actCost($1, $2, baseCurrId());
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION actCost(INTEGER, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION addrUseCount(integer) RETURNS integer STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAddrId ALIAS FOR $1;
-- NULL if there has been an error
CREATE OR REPLACE FUNCTION addTaxToGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, DATE, DATE, TEXT, INTEGER, TEXT) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
BEGIN
-- MIN because error codes are negative
- SELECT MIN(addToPackingListBatch(''SO'', pSoheadid, shiphead_id)) INTO returnVal
+ SELECT MIN(addToPackingListBatch('SO', pSoheadid, shiphead_id)) INTO returnVal
FROM shiphead
WHERE ((shiphead_order_id=pSoheadid)
AND (NOT shiphead_shipped)
- AND (shiphead_order_type=''SO''));
+ AND (shiphead_order_type='SO'));
IF (NOT FOUND OR returnVal IS NULL) THEN
- returnVal := addToPackingListBatch(''SO'', pSoheadid, NULL);
+ returnVal := addToPackingListBatch('SO', pSoheadid, NULL);
END IF;
RETURN returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER, INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
- RETURN addToPackingListBatch(''SO'', $1, $2);
+ RETURN addToPackingListBatch('SO', $1, $2);
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pheadtype ALIAS FOR $1;
RETURN returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER, TEXT, INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ pwarehousid ALIAS FOR $1;
+ pheadtype ALIAS FOR $2;
+ pheadid ALIAS FOR $3;
+ returnVal INTEGER;
+BEGIN
+ -- MIN because error codes are negative
+ SELECT MIN(addToPackingListBatch(pheadtype, pheadid,
+ getOpenShipmentId(pheadtype, pheadid, pwarehousid))) INTO returnVal;
+
+ IF (NOT FOUND OR returnVal IS NULL) THEN
+ returnVal := addToPackingListBatch(pheadtype, pheadid, NULL);
+ END IF;
+
+ RETURN returnVal;
+END;
+$$ LANGUAGE 'plpgsql';
+
+
+CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pheadtype ALIAS FOR $1;
VALUES
( pheadtype, pheadid, pshipheadid, FALSE );
-- Auto Firm Sales Orders conditionally based on metric
- IF ( (pheadtype = ''SO'') AND (fetchMetricBool(''FirmSalesOrderPackingList'')) ) THEN
+ IF ( (pheadtype = 'SO') AND (fetchMetricBool('FirmSalesOrderPackingList')) ) THEN
UPDATE coitem SET coitem_firm=TRUE
WHERE (coitem_cohead_id=pheadid);
END IF;
RETURN pheadid;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION adjustInvValue(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION adjustments(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTransType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION allocatedForSo(INTEGER, INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION allocatedForSo(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION allocatedForSo(INTEGER, DATE, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION allocatedForWo(INTEGER, INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION allocatedForWo(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION allocatedForWo(INTEGER, DATE, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION alterencrypt(text, text)
RETURNS integer AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOldKey ALIAS FOR $1;
SELECT dropIfExists('FUNCTION', 'apaging(date, boolean)', 'public');
CREATE OR REPLACE FUNCTION apaging(date, boolean) RETURNS SETOF apaging AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAsOfDate ALIAS FOR $1;
--report uses currency rate snapshot to convert all amounts to base based on apopen_docdate to ensure the same exchange rate
--today and greater base:
- CASE WHEN((apopen_duedate >= DATE(_asOfDate)))
- THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
- CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS cur_val,
+ CASE WHEN((apopen.apopen_duedate >= DATE(_asOfDate)))
+ THEN (((apopen.apopen_amount - apopen.apopen_paid +
+ COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+ CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS cur_val,
--0 to 30 base
- CASE WHEN((apopen_duedate >= DATE(_asOfDate)-30) AND (apopen_duedate < DATE(_asOfDate)))
- THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
- CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS thirty_val,
+ CASE WHEN((apopen.apopen_duedate >= DATE(_asOfDate)-30) AND (apopen.apopen_duedate < DATE(_asOfDate)))
+ THEN (((apopen.apopen_amount - apopen.apopen_paid +
+ COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+ CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS thirty_val,
--30-60 base
- CASE WHEN((apopen_duedate >= DATE(_asOfDate)-60) AND (apopen_duedate < DATE(_asOfDate) - 30 ))
- THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
- CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS sixty_val,
+ CASE WHEN((apopen.apopen_duedate >= DATE(_asOfDate)-60) AND (apopen.apopen_duedate < DATE(_asOfDate) - 30 ))
+ THEN (((apopen.apopen_amount - apopen.apopen_paid +
+ COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+ CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS sixty_val,
--60-90 base
- CASE WHEN((apopen_duedate >= DATE(_asOfDate)-90) AND (apopen_duedate < DATE(_asOfDate) - 60))
- THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
- CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS ninety_val,
+ CASE WHEN((apopen.apopen_duedate >= DATE(_asOfDate)-90) AND (apopen.apopen_duedate < DATE(_asOfDate) - 60))
+ THEN (((apopen.apopen_amount - apopen.apopen_paid +
+ COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+ CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS ninety_val,
--greater than 90 base:
- CASE WHEN((apopen_duedate > DATE(_asOfDate)-10000) AND (apopen_duedate < DATE(_asOfDate) - 90))
- THEN (((apopen_amount-apopen_paid + COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
- CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS plus_val,
+ CASE WHEN((apopen.apopen_duedate > DATE(_asOfDate)-10000) AND (apopen.apopen_duedate < DATE(_asOfDate) - 90))
+ THEN (((apopen.apopen_amount - apopen.apopen_paid +
+ COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+ CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS plus_val,
--total amount base:
- CASE WHEN((apopen_duedate > DATE(_asOfDate)-10000))
- THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
- CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS total_val,
+ CASE WHEN((apopen.apopen_duedate > DATE(_asOfDate)-10000))
+ THEN (((apopen.apopen_amount - apopen.apopen_paid +
+ COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+ CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS total_val,
--AP Open Amount base
- CASE WHEN apopen_doctype IN ('C', 'R')
- THEN (apopen_amount * -1) / apopen_curr_rate
- ELSE apopen_amount / apopen_curr_rate END AS apopen_amount,
+ CASE WHEN apopen.apopen_doctype IN ('C', 'R')
+ THEN (apopen.apopen_amount / apopen.apopen_curr_rate * -1.0)
+ ELSE (apopen.apopen_amount / apopen.apopen_curr_rate) END AS apopen_amount,
- apopen_docdate,
- apopen_duedate,
- apopen_ponumber,
- apopen_invcnumber,
- apopen_docnumber,
- apopen_doctype,
+ apopen.apopen_docdate,
+ apopen.apopen_duedate,
+ apopen.apopen_ponumber,
+ apopen.apopen_invcnumber,
+ apopen.apopen_docnumber,
+ apopen.apopen_doctype,
vend_id,
vend_name,
vend_number,
vend_vendtype_id,
vendtype_code,
terms_descrip,
- determineDiscountDate(terms_id, apopen_docdate) AS discdate,
- noNeg(apopen_discountable_amount *
- CASE WHEN (CURRENT_DATE <= determineDiscountDate(terms_id, apopen_docdate)) THEN terms_discprcnt
+ determineDiscountDate(terms_id, apopen.apopen_docdate) AS discdate,
+ noNeg(apopen.apopen_discountable_amount *
+ CASE WHEN (CURRENT_DATE <= determineDiscountDate(terms_id, apopen.apopen_docdate)) THEN terms_discprcnt
ELSE 0.0 END) AS disc_val,
terms_discdays AS discdays,
(terms_discprcnt * 100.0) AS discprcnt
LEFT OUTER JOIN apapply ON (((apopen_id=apapply_target_apopen_id)
OR (apopen_id=apapply_source_apopen_id))
AND (apapply_postdate >_asOfDate))
- WHERE ( (apopen_vend_id = vend_id)
+ LEFT OUTER JOIN apopen target ON (target.apopen_id=apapply_target_apopen_id)
+ WHERE ( (apopen.apopen_vend_id = vend_id)
AND (vend_vendtype_id=vendtype_id)
- AND (CASE WHEN (pUseDocDate) THEN apopen_docdate ELSE apopen_distdate END <= _asOfDate)
- AND (COALESCE(apopen_closedate,_asOfDate+1)>_asOfDate) )
- GROUP BY apopen_id,apopen_docdate,apopen_duedate,apopen_ponumber, apopen_invcnumber, apopen_docnumber,apopen_doctype,apopen_paid,
- apopen_curr_id,apopen_amount,vend_id,vend_name,vend_number,vend_vendtype_id,vendtype_code,terms_descrip,
- apopen_curr_rate, terms_id, terms_discdays, terms_discprcnt, apopen_discountable_amount
- ORDER BY vend_number, apopen_duedate
+ AND (CASE WHEN (pUseDocDate) THEN apopen.apopen_docdate ELSE apopen.apopen_distdate END <= _asOfDate)
+ AND (COALESCE(apopen.apopen_closedate,_asOfDate+1)>_asOfDate) )
+ GROUP BY apopen.apopen_id,apopen.apopen_docdate,apopen.apopen_duedate,apopen.apopen_ponumber,
+ apopen.apopen_invcnumber,apopen.apopen_docnumber,apopen.apopen_doctype,apopen.apopen_paid,
+ apopen.apopen_curr_id,apopen.apopen_amount,vend_id,vend_name,vend_number,vend_vendtype_id,vendtype_code,terms_descrip,
+ apopen.apopen_curr_rate, terms_id, terms_discdays, terms_discprcnt, apopen.apopen_discountable_amount
+ ORDER BY vend_number, apopen.apopen_duedate
LOOP
_row.apaging_docdate := _x.apopen_docdate;
_row.apaging_duedate := _x.apopen_duedate;
CREATE OR REPLACE FUNCTION apapplied(INTEGER, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION apCheckPending(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
WHERE ((checkitem_apopen_id=pApopenid)
AND (NOT checkhead_deleted)
AND (NOT checkhead_replaced)
+ AND (NOT checkhead_void)
AND (NOT checkhead_posted));
RETURN COALESCE(_qty, 0.0);
-- negative values = a loss.
CREATE OR REPLACE FUNCTION apcurrGain(INTEGER, INTEGER, NUMERIC, DATE)
RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION applyAPCreditMemoToBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION applyapcredits(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION applyARCreditMemoToBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAropenid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION applyARCreditMemoToBalance(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSourceAropenid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION applyCashReceiptLineBalance(INTEGER, INTEGER, NUMERIC, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCashrcptId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION applyCashReceiptToBalance(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCashrcptid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION applyCashReceiptToBalance(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCashrcptid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION applyCashReceiptToBalance(INTEGER, NUMERIC, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCashrcptid ALIAS FOR $1;
SELECT dropIfExists('FUNCTION', 'araging(date)', 'public');
CREATE OR REPLACE FUNCTION araging(date, boolean) RETURNS SETOF araging AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAsOfDate ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION araging(date, boolean, boolean) RETURNS SETOF araging AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAsOfDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION arapplied(INTEGER, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAropenid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION archiveSalesHistory(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSohistid ALIAS FOR $1;
-- negative values = a loss.
CREATE OR REPLACE FUNCTION arcurrGain(INTEGER, INTEGER, NUMERIC, DATE)
RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAropenId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION asofinvbal(INTEGER, DATE) RETURNS SETOF invbal STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION asofinvnn(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION asofinvqty(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteId ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION assessFinanceCharge(pAropenid INTEGER,
+ pAssessDate DATE,
+ pAssessAmount NUMERIC) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _fc RECORD;
+ _ar RECORD;
+ _invcheadid INTEGER;
+
+BEGIN
+
+ -- cache some information
+ SELECT * INTO _fc FROM fincharg;
+ IF (NOT FOUND) THEN
+ RAISE EXCEPTION 'assessFinanceCharge, configuration not set.';
+ END IF;
+
+ SELECT * INTO _ar FROM aropen WHERE (aropen_id=pAropenid);
+ IF (NOT FOUND) THEN
+ RAISE EXCEPTION 'assessFinanceCharge, aropen not found.';
+ END IF;
+
+ -- create invoice head
+ INSERT INTO invchead
+ ( invchead_cust_id,
+ invchead_shipto_id,
+ invchead_ordernumber,
+ invchead_orderdate,
+ invchead_posted,
+ invchead_printed,
+ invchead_invcnumber,
+ invchead_invcdate,
+ invchead_shipdate,
+ invchead_ponumber,
+ invchead_shipvia,
+ invchead_fob,
+ invchead_billto_name,
+ invchead_billto_address1,
+ invchead_billto_address2,
+ invchead_billto_address3,
+ invchead_billto_city,
+ invchead_billto_state,
+ invchead_billto_zipcode,
+ invchead_billto_phone,
+ invchead_shipto_name,
+ invchead_shipto_address1,
+ invchead_shipto_address2,
+ invchead_shipto_address3,
+ invchead_shipto_city,
+ invchead_shipto_state,
+ invchead_shipto_zipcode,
+ invchead_shipto_phone,
+ invchead_salesrep_id,
+ invchead_commission,
+ invchead_terms_id,
+ invchead_freight,
+ invchead_misc_amount,
+ invchead_misc_descrip,
+ invchead_misc_accnt_id,
+ invchead_payment,
+ invchead_paymentref,
+ invchead_notes,
+ invchead_billto_country,
+ invchead_shipto_country,
+ invchead_prj_id,
+ invchead_curr_id,
+ invchead_gldistdate,
+ invchead_recurring,
+ invchead_recurring_interval,
+ invchead_recurring_type,
+ invchead_recurring_until,
+ invchead_recurring_invchead_id,
+ invchead_shipchrg_id,
+ invchead_taxzone_id,
+ invchead_void,
+ invchead_saletype_id,
+ invchead_shipzone_id )
+ SELECT
+ invchead_cust_id,
+ invchead_shipto_id,
+ invchead_ordernumber,
+ invchead_orderdate,
+ FALSE,
+ FALSE,
+ fetchInvcNumber(),
+ pAssessDate,
+ invchead_shipdate,
+ invchead_ponumber,
+ invchead_shipvia,
+ invchead_fob,
+ invchead_billto_name,
+ invchead_billto_address1,
+ invchead_billto_address2,
+ invchead_billto_address3,
+ invchead_billto_city,
+ invchead_billto_state,
+ invchead_billto_zipcode,
+ invchead_billto_phone,
+ invchead_shipto_name,
+ invchead_shipto_address1,
+ invchead_shipto_address2,
+ invchead_shipto_address3,
+ invchead_shipto_city,
+ invchead_shipto_state,
+ invchead_shipto_zipcode,
+ invchead_shipto_phone,
+ invchead_salesrep_id,
+ 0.0,
+ invchead_terms_id,
+ 0.0,
+ 0.0,
+ NULL,
+ NULL,
+ 0.0,
+ NULL,
+ '',
+ invchead_billto_country,
+ invchead_shipto_country,
+ invchead_prj_id,
+ invchead_curr_id,
+ NULL,
+ FALSE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ invchead_shipchrg_id,
+ invchead_taxzone_id,
+ invchead_void,
+ invchead_saletype_id,
+ invchead_shipzone_id
+ FROM invchead
+ WHERE (invchead_invcnumber=_ar.aropen_docnumber)
+ RETURNING invchead_id INTO _invcheadid;
+
+ -- create invoice item
+ INSERT INTO invcitem
+ ( invcitem_invchead_id,
+ invcitem_linenumber,
+ invcitem_item_id,
+ invcitem_warehous_id,
+ invcitem_custpn,
+ invcitem_number,
+ invcitem_descrip,
+ invcitem_ordered,
+ invcitem_billed,
+ invcitem_custprice,
+ invcitem_price,
+ invcitem_notes,
+ invcitem_salescat_id,
+ invcitem_taxtype_id,
+ invcitem_qty_uom_id,
+ invcitem_qty_invuomratio,
+ invcitem_price_uom_id,
+ invcitem_price_invuomratio,
+ invcitem_coitem_id,
+ invcitem_updateinv,
+ invcitem_rev_accnt_id )
+ VALUES
+ ( _invcheadid,
+ 1,
+ -1,
+ -1,
+ NULL,
+ _fc.fincharg_markoninvoice,
+ 'Finance Charge Assessment',
+ 1.0,
+ 1.0,
+ pAssessAmount,
+ pAssessAmount,
+ '',
+ _fc.fincharg_salescat_id,
+ NULL,
+ NULL,
+ 1.0,
+ NULL,
+ 1.0,
+ NULL,
+ FALSE,
+ _fc.fincharg_accnt_id );
+
+ -- update aropen
+ UPDATE aropen SET aropen_fincharg_date = pAssessDate,
+ aropen_fincharg_amount = COALESCE(aropen_fincharg_amount, 0.0) + pAssessAmount
+ WHERE (aropen_id=pAropenid);
+
+
+ RETURN 0;
+
+END;
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION attachContact(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pcntctId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION attachQuoteToOpportunity(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION attachSalesOrderToOpportunity(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION averageSalesPrice(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION avgCost(pItemsiteid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_value NUMERIC;
CREATE OR REPLACE FUNCTION balanceItemsite(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION baseCurrID ()
RETURNS INTEGER IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
returnVal INTEGER;
CREATE OR REPLACE FUNCTION BOMContains(INTEGER, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pparentitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION bomhistSequence(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pHistid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION bomitem(INTEGER) RETURNS SETOF bomitem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT * FROM bomitem WHERE ((bomitem_parent_item_id=$1) AND (bomitem_rev_id=getActiveRevId('BOM',$1)));
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION bomitem(INTEGER,INTEGER) RETURNS SETOF bomitem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT * FROM bomitem WHERE ((bomitem_parent_item_id=$1) AND (bomitem_rev_id=$2));
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION bomLevelByItem(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION bomLevelByItem(INTEGER,INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION bomworkEffective( INTEGER, DATE ) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
workid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION bomworkExpired( INTEGER, DATE ) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
workid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION bomworkItemSequence(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWorkid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION bomworkSequence(INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWorkid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION buildInvBal(integer) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calcCobillAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobillid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION calcCobillTax(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobillid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION calcCobmiscAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobmiscid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION calcCobmiscTax(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobmiscid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calccashbudget(integer, integer, character) RETURNS numeric AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAccntId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calcCmheadAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION calcCmheadTax(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmheadid ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION calcInvoiceAmt(pInvcheadid INTEGER) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+ RETURN calcInvoiceAmt(pInvcheadid, 'T');
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION calcInvoiceAmt(pInvcheadid INTEGER,
+ pType TEXT) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _subtotal NUMERIC := 0.0;
+ _cost NUMERIC := 0.0;
+ _tax NUMERIC := 0.0;
+ _freight NUMERIC := 0.0;
+ _misc NUMERIC := 0.0;
+ _amount NUMERIC := 0.0;
+
+BEGIN
+
+ -- pType: S = line item subtotal
+ -- T = total
+ -- X = tax
+ -- M = margin
+
+ SELECT COALESCE(SUM(ROUND((invcitem_billed * invcitem_qty_invuomratio) *
+ (invcitem_price / COALESCE(invcitem_price_invuomratio, 1.0)), 2)), 0.0),
+ COALESCE(SUM(ROUND((invcitem_billed * invcitem_qty_invuomratio) *
+ COALESCE(coitem_unitcost, itemCost(itemsite_id), 0.0), 2)), 0.0)
+ INTO _subtotal, _cost
+ FROM invcitem LEFT OUTER JOIN coitem ON (coitem_id=invcitem_coitem_id)
+ LEFT OUTER JOIN itemsite ON (itemsite_item_id=invcitem_item_id AND itemsite_warehous_id=invcitem_warehous_id)
+ WHERE (invcitem_invchead_id=pInvcheadid);
+
+ IF (pType IN ('T', 'X')) THEN
+ SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) INTO _tax
+ FROM calculateTaxDetailSummary('I', pInvcheadid, 'T');
+ END IF;
+
+ IF (pType = 'T') THEN
+ SELECT COALESCE(invchead_freight, 0), COALESCE(invchead_misc_amount, 0)
+ INTO _freight, _misc
+ FROM invchead
+ WHERE (invchead_id=pinvcheadid);
+ END IF;
+
+ _amount := CASE pType WHEN 'S' THEN (_subtotal)
+ WHEN 'T' THEN (_subtotal + _tax + _freight + _misc)
+ WHEN 'X' THEN (_tax)
+ WHEN 'M' THEN (_subtotal - _cost)
+ ELSE 0.0
+ END;
+
+ RETURN _amount;
+
+END;
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION calcpendingarapplications(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION calcpendingarapplications(INTEGER) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
paropenid ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION calcPurchaseOrderAmt(pPoheadid INTEGER) RETURNS NUMERIC AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+ RETURN calcPurchaseOrderAmt(pPoheadid, 'T');
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION calcPurchaseOrderAmt(pPoheadid INTEGER,
+ pType TEXT) RETURNS NUMERIC AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _subtotal NUMERIC := 0;
+ _freightsub NUMERIC := 0;
+ _tax NUMERIC := 0;
+ _freight NUMERIC := 0;
+ _currid INTEGER := 0;
+ _effdate DATE := CURRENT_DATE;
+ _amount NUMERIC := 0;
+
+BEGIN
+
+ -- pType: S = line item subtotal
+ -- T = total
+ -- X = tax
+
+ SELECT COALESCE(SUM(ROUND(poitem_qty_ordered * poitem_unitprice, 2)), 0),
+ COALESCE(SUM(ROUND(poitem_freight, 2)), 0)
+ INTO _subtotal, _freightsub
+ FROM poitem
+ WHERE (poitem_pohead_id=pPoheadid);
+
+ SELECT COALESCE(SUM(tax), 0) INTO _tax
+ FROM ( SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) AS tax
+ FROM tax JOIN calculateTaxDetailSummary('PO', pPoheadid, 'T') ON (taxdetail_tax_id=tax_id)
+ GROUP BY tax_id ) AS data;
+
+ SELECT COALESCE(pohead_freight, 0), pohead_curr_id, pohead_orderdate
+ INTO _freight, _currid, _effdate
+ FROM pohead
+ WHERE (pohead_id=pPoheadid);
+
+ _amount := currToBase(_currid,
+ CASE pType WHEN 'S' THEN (_subtotal)
+ WHEN 'T' THEN (_subtotal + _tax + _freight + _freightsub)
+ WHEN 'X' THEN (_tax)
+ ELSE 0.0
+ END,
+ _effdate);
+
+ RETURN _amount;
+
+END;
+$$ LANGUAGE 'plpgsql';
--- /dev/null
+CREATE OR REPLACE FUNCTION calcPurchaseOrderDueDate(pPoheadid INTEGER) RETURNS DATE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _result DATE;
+BEGIN
+
+ SELECT MIN(poitem_duedate) INTO _result
+ FROM poitem
+ WHERE (poitem_pohead_id=pPoheadid);
+
+ RETURN _result;
+
+END;
+$$ LANGUAGE 'plpgsql';
-DROP FUNCTION IF EXISTS calcquoteamt(integer);
-CREATE OR REPLACE FUNCTION calcQuoteAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION calcQuoteAmt(pQuheadid INTEGER) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+ RETURN calcQuoteAmt(pQuheadid, 'T');
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION calcQuoteAmt(pQuheadid INTEGER,
+ pType TEXT) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pQuheadid ALIAS FOR $1;
- _subtotal NUMERIC := 0;
- _tax NUMERIC := 0;
- _freight NUMERIC := 0;
- _misc NUMERIC := 0;
- _amount NUMERIC := 0;
+ _subtotal NUMERIC := 0.0;
+ _cost NUMERIC := 0.0;
+ _tax NUMERIC := 0.0;
+ _freight NUMERIC := 0.0;
+ _misc NUMERIC := 0.0;
+ _amount NUMERIC := 0.0;
BEGIN
+ -- pType: S = line item subtotal
+ -- T = total
+ -- X = tax
+ -- M = margin
+
SELECT COALESCE(SUM(ROUND((quitem_qtyord * quitem_qty_invuomratio) *
- (quitem_price / quitem_price_invuomratio), 2)), 0) INTO _subtotal
+ (quitem_price / quitem_price_invuomratio), 2)), 0.0),
+ COALESCE(SUM(ROUND((quitem_qtyord * quitem_qty_invuomratio) *
+ quitem_unitcost, 2)), 0.0)
+ INTO _subtotal, _cost
FROM quitem
WHERE (quitem_quhead_id=pQuheadid);
- SELECT COALESCE(SUM(tax), 0) INTO _tax
- FROM ( SELECT ROUND(SUM(taxdetail_tax), 2) AS tax
- FROM tax JOIN calculateTaxDetailSummary('Q', pQuheadid, 'T') ON (taxdetail_tax_id=tax_id)
- GROUP BY tax_id ) AS data;
+ IF (pType IN ('T', 'X')) THEN
+ SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) INTO _tax
+ FROM calculateTaxDetailSummary('Q', pQuheadid, 'T');
+ END IF;
- SELECT COALESCE(quhead_freight, 0), COALESCE(quhead_misc, 0) INTO _freight, _misc
- FROM quhead
- WHERE (quhead_id=pQuheadid);
+ IF (pType = 'T') THEN
+ SELECT COALESCE(quhead_freight, 0), COALESCE(quhead_misc, 0) INTO _freight, _misc
+ FROM quhead
+ WHERE (quhead_id=pQuheadid);
+ END IF;
- _amount := _subtotal + _tax + _freight + _misc;
+ _amount := CASE pType WHEN 'S' THEN (_subtotal)
+ WHEN 'T' THEN (_subtotal + _tax + _freight + _misc)
+ WHEN 'X' THEN (_tax)
+ WHEN 'M' THEN (_subtotal - _cost)
+ ELSE 0.0
+ END;
RETURN _amount;
-DROP FUNCTION IF EXISTS calcsalesorderamt(integer);
-CREATE OR REPLACE FUNCTION calcSalesOrderAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION calcSalesOrderAmt(pCoheadid INTEGER) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+ RETURN calcSalesOrderAmt(pCoheadid, 'T');
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION calcSalesOrderAmt(pCoheadid INTEGER,
+ pType TEXT) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pCoheadid ALIAS FOR $1;
- _subtotal NUMERIC := 0;
- _tax NUMERIC := 0;
- _freight NUMERIC := 0;
- _misc NUMERIC := 0;
- _amount NUMERIC := 0;
+ _subtotal NUMERIC := 0.0;
+ _cost NUMERIC := 0.0;
+ _tax NUMERIC := 0.0;
+ _freight NUMERIC := 0.0;
+ _misc NUMERIC := 0.0;
+ _credit NUMERIC := 0.0;
+ _amount NUMERIC := 0.0;
BEGIN
+ -- pType: S = line item subtotal
+ -- T = total
+ -- B = balance due
+ -- C = allocated credits
+ -- X = tax
+ -- M = margin
+
SELECT COALESCE(SUM(ROUND((coitem_qtyord * coitem_qty_invuomratio) *
- (coitem_price / coitem_price_invuomratio), 2)), 0) INTO _subtotal
+ (coitem_price / coitem_price_invuomratio), 2)), 0.0),
+ COALESCE(SUM(ROUND((coitem_qtyord * coitem_qty_invuomratio) *
+ coitem_unitcost, 2)), 0.0)
+ INTO _subtotal, _cost
FROM coitem
WHERE (coitem_cohead_id=pCoheadid)
AND (coitem_status != 'X');
- SELECT COALESCE(SUM(tax), 0) INTO _tax
- FROM ( SELECT ROUND(SUM(taxdetail_tax), 2) AS tax
- FROM tax JOIN calculateTaxDetailSummary('S', pCoheadid, 'T') ON (taxdetail_tax_id=tax_id)
- GROUP BY tax_id ) AS data;
+ IF (pType IN ('T', 'B', 'X')) THEN
+ SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) INTO _tax
+ FROM calculateTaxDetailSummary('S', pCoheadid, 'T');
+ END IF;
- SELECT COALESCE(cohead_freight, 0), COALESCE(cohead_misc, 0) INTO _freight, _misc
- FROM cohead
- WHERE (cohead_id=pCoheadid);
+ IF (pType IN ('T', 'B', 'C')) THEN
+ SELECT COALESCE(cohead_freight, 0), COALESCE(cohead_misc, 0),
+ COALESCE(SUM(currToCurr(aropenalloc_curr_id, cohead_curr_id,
+ aropenalloc_amount, CURRENT_DATE)),0)
+ INTO _freight, _misc, _credit
+ FROM cohead
+ LEFT OUTER JOIN aropenalloc ON (aropenalloc_doctype='S' AND aropenalloc_doc_id=cohead_id)
+ WHERE (cohead_id=pCoheadid)
+ GROUP BY cohead_freight, cohead_misc, cohead_curr_id;
+ END IF;
- _amount := _subtotal + _tax + _freight + _misc;
+ _amount := CASE pType WHEN 'S' THEN (_subtotal)
+ WHEN 'T' THEN (_subtotal + _tax + _freight + _misc)
+ WHEN 'B' THEN (_subtotal + _tax + _freight + _misc - _credit)
+ WHEN 'C' THEN (_credit)
+ WHEN 'X' THEN (_tax)
+ WHEN 'M' THEN (_subtotal - _cost)
+ ELSE 0.0
+ END;
RETURN _amount;
CREATE OR REPLACE FUNCTION calcShipFreight(integer) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipheadId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calcTotalSlipQty(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTagid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calculateFreightDetail(integer,integer,text,integer,integer,text,date,text,integer,character varying,integer,integer,numeric)
RETURNS SETOF freightData AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calculatesubtax(integer, date, integer, numeric, integer)
RETURNS SETOF taxdetail AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxCodeId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calculatetax(integer, integer, date, integer, numeric)
RETURNS numeric AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxZoneId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calculatetaxdetail(integer, integer, date, integer, numeric)
RETURNS SETOF taxdetail AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxZoneId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calculatetaxdetailline(text, integer)
RETURNS SETOF taxdetail AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrderType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calculatetaxdetailsummary(text, integer, text)
RETURNS SETOF taxdetail AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrderType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calculatetaxhist(text, integer, integer, integer, date, integer, numeric)
RETURNS boolean AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTableName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calcVoucherFreight(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVoucherid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION calcVoucherTax(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVoucherid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION calcVoucherAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVoucherid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION calcWooperStartStub(INTEGER, INTEGER) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION cancelBillingSelection(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobmiscid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION changeAccountingPeriodDates(INTEGER, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION changeAccountingYearPeriodDates(INTEGER, DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION changeFKeyPointers(TEXT, TEXT, INTEGER, INTEGER, TEXT[], BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSchema ALIAS FOR $1;
-DROP FUNCTION IF EXISTS changepoitemduedate(integer, date);
-CREATE OR REPLACE FUNCTION changePoitemDueDate(INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION changePoitemDueDate(pPoitemid INTEGER,
+ pDate DATE) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-DECLARE
- pPoitemid ALIAS FOR $1;
- pDate ALIAS FOR $2;
+BEGIN
+
+ RETURN changePoitemDueDate(pPoitemid, pDate, false);
+
+END;
+$$ LANGUAGE 'plpgsql';
+CREATE OR REPLACE FUNCTION changePoitemDueDate(pPoitemid INTEGER,
+ pDate DATE,
+ pBySO BOOLEAN) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
- IF ( ( SELECT (poitem_status IN (''C''))
+ IF ( ( SELECT (poitem_status IN ('C'))
FROM poitem
WHERE (poitem_id=pPoitemid) ) ) THEN
RETURN -1;
SET poitem_duedate=pDate
WHERE (poitem_id=pPoitemid);
+ IF (pBySO) THEN
+ --Generate the PoItemUpdatedBySo event
+ PERFORM postEvent('PoItemUpdatedBySo', 'P', poitem_id,
+ itemsite_warehous_id,
+ (pohead_number || '-'|| poitem_linenumber || ': ' || item_number),
+ NULL, NULL, NULL, NULL)
+ FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
+ JOIN itemsite ON (itemsite_id=poitem_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ WHERE (poitem_id=pPoitemid)
+ AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence));
+ END IF;
+
RETURN pPoitemid;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-DROP FUNCTION IF EXISTS changepoitemqty(integer, numeric);
-CREATE OR REPLACE FUNCTION changePoitemQty(INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION changePoitemQty(pPoitemid INTEGER,
+ pQty NUMERIC) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+ RETURN changePoitemQty(pPoitemid, pQty, false);
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION changePoitemQty(pPoitemid INTEGER,
+ pQty NUMERIC,
+ pBySO BOOLEAN) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pPoitemid ALIAS FOR $1;
- pQty ALIAS FOR $2;
BEGIN
- IF ( ( SELECT (poitem_status IN (''C''))
+ IF ( ( SELECT (poitem_status IN ('C'))
FROM poitem
WHERE (poitem_id=pPoitemid) ) ) THEN
RETURN -1;
SET poitem_qty_ordered=pQty
WHERE (poitem_id=pPoitemid);
+ IF (pBySO) THEN
+ --Generate the PoItemUpdatedBySo event
+ PERFORM postEvent('PoItemUpdatedBySo', 'P', poitem_id,
+ itemsite_warehous_id,
+ (pohead_number || '-'|| poitem_linenumber || ': ' || item_number),
+ NULL, NULL, NULL, NULL)
+ FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
+ JOIN itemsite ON (itemsite_id=poitem_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ WHERE (poitem_id=pPoitemid)
+ AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence));
+ END IF;
+
RETURN pPoitemid;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION changePrDate(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION changePrQty(INTEGER, NUMERIC) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION changePseudoFKeyPointers(TEXT, TEXT, TEXT, INTEGER, TEXT, TEXT, INTEGER, TEXT, TEXT, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSchema ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION changePurchaseDropShip(pCoitemId INTEGER,
+ pPoitemId INTEGER,
+ pDropShip BOOLEAN) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _s RECORD;
+ _w RECORD;
+ _p RECORD;
+ _result INTEGER;
+ _poitemid INTEGER;
+
+BEGIN
+
+ -- Check for existing poitem for this coitem
+ SELECT * INTO _p
+ FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
+ WHERE (poitem_id=pPoitemId)
+ AND (poitem_order_id=pCoitemId)
+ AND (poitem_order_type='S');
+ IF (NOT FOUND) THEN
+ RAISE EXCEPTION 'Change Purchase Drop Ship PO not found';
+ END IF;
+
+ SELECT * INTO _s
+ FROM coitem JOIN cohead ON (cohead_id = coitem_cohead_id)
+ LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
+ LEFT OUTER JOIN cntct ON (shipto_cntct_id = cntct_id)
+ LEFT OUTER JOIN addr ON (shipto_addr_id = addr_id)
+ WHERE (coitem_id = pCoitemId);
+ IF (NOT FOUND) THEN
+ RETURN -1;
+ END IF;
+
+ IF (_p.pohead_status != 'U') THEN
+ RETURN -3;
+ END IF;
+
+ SELECT deletePoitem(_p.poitem_id) INTO _result;
+ IF (_result < 0) THEN
+ RETURN _result;
+ END IF;
+
+ SELECT createPurchaseToSale(_s.coitem_id, _p.poitem_itemsrc_id,
+ pDropShip, _s.coitem_qtyord,
+ _s.coitem_scheddate, _p.poitem_unitprice)
+ INTO _poitemid;
+
+ RETURN _poitemid;
+
+END;
+$$ LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION changeWoDates(INTEGER, DATE, DATE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
returnCode := 0;
ELSIF (_p.wo_status IN ('R','I')) THEN
- INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
- evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number,
- evntlog_olddate, evntlog_newdate)
- SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
- 'W', wo_id, itemsite_warehous_id, formatWoNumber(wo_id),
- wo_duedate, pDueDate
- FROM evntnot, evnttype, itemsite, item, wo
- WHERE ( (evntnot_evnttype_id=evnttype_id)
- AND (evntnot_warehous_id=itemsite_warehous_id)
- AND (wo_itemsite_id=itemsite_id)
- AND (itemsite_item_id=item_id)
- AND (evnttype_name='RWoDueDateRequestChange')
- AND (wo_id=pWoid) );
+ PERFORM postEvent('RWoDueDateRequestChange', 'W', wo_id,
+ itemsite_warehous_id, formatWoNumber(wo_id),
+ NULL, NULL, pDueDate, wo_duedate)
+ FROM wo JOIN itemsite ON (itemsite_id=wo_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ WHERE (wo_id=pWoid);
returnCode := 0;
CREATE OR REPLACE FUNCTION changeWoProject(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION changeWoQty(INTEGER, NUMERIC, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
END IF;
IF (_r.wo_status IN ('R','I')) THEN
- INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
- evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number,
- evntlog_oldvalue, evntlog_newvalue)
- SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
- 'W', wo_id, itemsite_warehous_id, formatWoNumber(wo_id),
- wo_qtyord, pQty
- FROM evntnot, evnttype, itemsite, item, wo
- WHERE ( (evntnot_evnttype_id=evnttype_id)
- AND (evntnot_warehous_id=itemsite_warehous_id)
- AND (wo_itemsite_id=itemsite_id)
- AND (itemsite_item_id=item_id)
- AND (evnttype_name='RWoQtyRequestChange')
- AND (wo_id=pWoid) );
+ PERFORM postEvent('RWoQtyRequestChange', 'W', wo_id,
+ itemsite_warehous_id, formatWoNumber(wo_id),
+ pQty, wo_qtyord, NULL, NULL)
+ FROM wo JOIN itemsite ON (itemsite_id=wo_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ WHERE (wo_id=pWoid);
_result = 0;
END IF;
CREATE OR REPLACE FUNCTION characteristicsToString(TEXT, INTEGER, TEXT, TEXT) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTargetType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkCreditMemoSitePrivs(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkDetailFormatted(INTEGER, INTEGER) RETURNS SETOF checkdata
AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCheckheadid ALIAS FOR $1;
formatMoney(checkitem_discount) AS disc_cred
FROM checkitem, apopen
WHERE ((checkitem_checkhead_id=pCheckheadid)
- AND (checkitem_vouchernumber = apopen_docnumber)
+ AND (checkitem_apopen_id = apopen_id)
AND (apopen_doctype = 'D'))
UNION
- SELECT --CREDITs--------------------------
+ SELECT --CREDIT MEMO -------------------------
+ 2 AS ord,
+ 1 AS sequence_value,
+ checkitem_invcnumber,
+ checkitem_ponumber,
+ formatMoney(checkitem_amount * -1.0) AS f_amount,
+ 'Credit Memo PO#: ' || checkitem_ponumber AS doc_number,
+ '' AS f_docdate,
+ 'Credit Memo: ' || checkitem_vouchernumber AS doc_reference,
+ checkitem_vouchernumber AS vouchernumber,
+ '' AS amount,
+ formatMoney(checkitem_amount) AS disc_cred
+ FROM checkitem, apopen
+ WHERE ((checkitem_checkhead_id=pCheckheadid)
+ AND (checkitem_apopen_id = apopen_id)
+ AND (apopen_doctype = 'C'))
+
+ UNION
+
+ SELECT --CREDITs FOR VOUCHERS-----------------
3 AS ord,
1 AS sequence_value,
checkitem_invcnumber,
formatDate(vohead_docdate) AS f_docdate,
'Credit Applied: ' || apapply_source_doctype || ' ' ||
apapply_source_docnumber AS doc_reference,
- 'Voucher ' || checkitem_vouchernumber AS vouchernumber,
+ 'Voucher: ' || checkitem_vouchernumber AS vouchernumber,
'' AS amount,
formatMoney((apapply_amount)) AS disc_cred
FROM checkitem, vohead, apapply
WHERE ((checkitem_checkhead_id=pCheckheadid)
AND (checkitem_vouchernumber = vohead_number)
- AND (apapply_target_docnumber = checkitem_vouchernumber ))
+ AND (apapply_target_docnumber = checkitem_vouchernumber)
+ AND (apapply_target_doctype = 'V')
+ AND (apapply_source_doctype = 'C'))
+
+ UNION
+
+ SELECT --CREDITs FOR DEBIT MEMOS-----------
+ 3 AS ord,
+ 1 AS sequence_value,
+ checkitem_invcnumber,
+ checkitem_ponumber,
+ formatMoney(checkitem_amount) AS f_amount,
+ 'Debit Memo PO#: ' || checkitem_ponumber AS doc_number,
+ '' AS f_docdate,
+ 'Credit Applied: ' || apapply_source_doctype || ' ' ||
+ apapply_source_docnumber AS doc_reference,
+ 'Debit Memo: ' || checkitem_vouchernumber AS vouchernumber,
+ '' AS amount,
+ formatMoney((apapply_amount)) AS disc_cred
+ FROM checkitem, apopen, apapply
+ WHERE ((checkitem_checkhead_id=pCheckheadid)
+ AND (checkitem_vouchernumber = apopen_docnumber)
+ AND (apopen_doctype = 'D')
+ AND (apapply_target_docnumber = checkitem_vouchernumber)
+ AND (apapply_target_doctype = 'D')
+ AND (apapply_source_doctype = 'C'))
UNION
CREATE OR REPLACE FUNCTION checkInvoiceSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkPOSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkPrivilege(text) RETURNS BOOLEAN STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrivilege ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkQuoteSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION checkQuoteSitePrivs(INTEGER, INTEGER) RETURNS BOOLEAN STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkRASitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pRaheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkShipmentSitePrivs(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkSOSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION checkVoucherSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION clearNumberIssue(psequence TEXT, pnumber INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
__seqiss seqiss[];
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION clearNumberIssue(psequence TEXT, pnumber TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_castpnumber INTEGER;
CREATE OR REPLACE FUNCTION clearPayment(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApselectid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION closeAccountingPeriod(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION closeAccountingYearPeriod(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pYearPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION closePo(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION closeWo(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION closeWo(INTEGER, BOOLEAN, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
BEGIN
+ --Comment this out
+ --In addition to IssueToShipping driving PostProduction,
+ --not PostProduction can drive IssueToShipping.
+ --Must allow closing of Job items
+
--If this is item type Job then we cannot close here
- SELECT itemsite_costmethod INTO _check
- FROM wo,itemsite
- WHERE ((wo_id=pWoid)
- AND (wo_itemsite_id=itemsite_id)
- AND (itemsite_costmethod = 'J'));
- IF (FOUND) THEN
- RAISE EXCEPTION 'Work orders for Job items are closed when all quantities are shipped';
- END IF;
+ --SELECT itemsite_costmethod INTO _check
+ --FROM wo,itemsite
+ --WHERE ((wo_id=pWoid)
+ --AND (wo_itemsite_id=itemsite_id)
+ --AND (itemsite_costmethod = 'J'));
+ --IF (FOUND) THEN
+ -- RAISE EXCEPTION 'Work orders for Job items are closed when all quantities are shipped';
+ --END IF;
SELECT formatWoNumber(pWoid) INTO _woNumber;
CREATE OR REPLACE FUNCTION cntct() RETURNS SETOF cntct AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row cntct%ROWTYPE;
CREATE OR REPLACE FUNCTION cntctdups(text, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean) RETURNS SETOF cntctdup AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSearchText ALIAS FOR $1;
CREATE OR REPLACE FUNCTION cntctmerge(integer, integer, boolean) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSourceCntctId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION cntctrestore(integer) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCntctId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION cntctselect(integer, boolean) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCntctId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION cntctselectcol(integer, integer) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCntctId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION cntctused(integer) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCntctId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION coheadstatecolor(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCoheadId ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION public.compareversion(text, text DEFAULT split_part(version(), ' '::text, 2))
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+-- Returns 1 if the left version is greater than the right version
+-- -1 if the right is greater than the left
+-- 0 if the versions are equal.
+-- parameter two defaults to current server version
+ RETURNS integer AS
+$BODY$
+DECLARE
+ _leftVersion ALIAS FOR $1;
+ _rightVersion ALIAS FOR $2;
+ _leftMajor SMALLINT;
+ _leftMinor SMALLINT;
+ _leftPatch SMALLINT;
+ _rightMajor SMALLINT;
+ _rightMinor SMALLINT;
+ _rightPatch SMALLINT;
+ _returnCode SMALLINT;
+ DEBUG BOOLEAN := false;
+BEGIN
+
+-- left
+SELECT substring(_leftVersion FROM $$(\d+)\.\d+\.\d+$$)::SMALLINT,
+ substring(_leftVersion FROM $$\d+\.(\d+)\.\d+$$)::SMALLINT,
+ substring(_leftVersion FROM $$\d+\.\d+\.(\d+)$$)::SMALLINT
+ INTO _leftMajor, _leftMinor, _leftPatch;
+
+IF (DEBUG)
+ THEN RAISE NOTICE 'Left Version --> % Major --> % Minor --> % Patch --> % ', _leftVersion, _leftMajor, _leftMinor, _leftPatch;
+END IF;
+
+-- right
+SELECT substring(_rightVersion FROM $$(\d+)\.\d+\.\d+$$)::SMALLINT,
+ substring(_rightVersion FROM $$\d+\.(\d+)\.\d+$$)::SMALLINT,
+ substring(_rightVersion FROM $$\d+\.\d+\.(\d+)$$)::SMALLINT
+ INTO _rightMajor, _rightMinor, _rightPatch;
+
+IF (DEBUG)
+ THEN RAISE NOTICE 'Right Version --> % Major --> % Minor --> % Patch --> % ', _rightVersion, _rightMajor, _rightMinor, _rightPatch;
+END IF;
+
+-- check major version
+IF (_leftMajor > _rightMajor) THEN _returnCode := 1;
+ELSIF (_leftMajor < _rightMajor) THEN _returnCode := -1;
+ELSIF (_leftMajor = _rightMajor) THEN
+ -- if major is equal, check minor version
+ IF (_leftMinor > _rightMinor) THEN _returnCode := 1;
+ ELSIF (_leftMinor < _rightMinor) THEN _returnCode := -1;
+ ELSIF (_leftMinor = _rightMinor) THEN
+ -- if major and minor are equal, check patch version
+ IF (_leftPatch > _rightPatch) THEN _returnCode := 1;
+ ELSIF (_leftPatch < _rightPatch) THEN _returnCode := -1;
+ ELSIF (_leftPatch = _rightPatch) THEN _returnCode := 0;
+ END IF;
+ END IF;
+-- if we somehow don't match those three operators it probably means someone passed in a version that wasn't in numerical major.minor.patch format
+ELSE RAISE EXCEPTION 'One or more of the version parameters is invalid. Expected numerical Major.Minor.Patch version string. Left --> % Right --> %', _leftVersion, _rightVersion;
+END IF;
+
+RETURN _returnCode;
+
+END;
+$BODY$
+ LANGUAGE plpgsql STABLE;
+ALTER FUNCTION public.compareversion(text, text)
+ OWNER TO admin;
DROP AGGREGATE IF EXISTS concatagg(TEXT);
CREATE OR REPLACE FUNCTION concataggSfunc(TEXT, TEXT) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
prevstate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION consolidateLocations(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
WHERE crmacct_cust_id=pCustId;
*/
CREATE OR REPLACE FUNCTION convertCustomerToProspect(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION convertProspectToCustomer(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN convertProspectToCustomer($1, FALSE);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION convertProspectToCustomer(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pProspectId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION convertQuote(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
WHERE ((itemsite_id IS NULL)
AND (quitem_quhead_id=pQuheadid));
IF (FOUND) THEN
- INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
- evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number)
- SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
- 'Q', quhead_id, quhead_warehous_id, quhead_number
- FROM evntnot, evnttype, quhead
- WHERE ( (evntnot_evnttype_id=evnttype_id)
- AND (evntnot_warehous_id=quhead_warehous_id)
- AND (evnttype_name='CannotConvertQuote')
- AND (quhead_id=pQuheadid) );
+ PERFORM postEvent('CannotConvertQuote', 'Q', quhead_id,
+ quhead_warehous_id, quhead_number,
+ NULL, NULL, NULL, NULL)
+ FROM quhead
+ WHERE (quhead_id=pQuheadid);
RETURN -1;
END IF;
CREATE OR REPLACE FUNCTION convertQuoteToInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
WHERE ((itemsite_id IS NULL)
AND (quitem_quhead_id=pQuheadid));
IF (FOUND) THEN
- INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
- evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number)
- SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
- 'Q', quhead_id, quhead_warehous_id, quhead_number
- FROM evntnot, evnttype, quhead
- WHERE ( (evntnot_evnttype_id=evnttype_id)
- AND (evntnot_warehous_id=quhead_warehous_id)
- AND (evnttype_name='CannotConvertQuote')
- AND (quhead_id=pQuheadid) );
+ PERFORM postEvent('CannotConvertQuote', 'Q', quhead_id,
+ quhead_warehous_id, quhead_number,
+ NULL, NULL, NULL, NULL)
+ FROM quhead
+ WHERE (quhead_id=pQuheadid);
RETURN -1;
END IF;
CREATE OR REPLACE FUNCTION copyBOM(pSItemid INTEGER,
pTItemid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_result INTEGER;
CREATE OR REPLACE FUNCTION copyBOM(pSItemid INTEGER,
pTItemid INTEGER,
pCopyUsedAt BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_bh RECORD;
_bi RECORD;
+ _bomheadfound BOOLEAN := FALSE;
_bomheadid INTEGER;
_bomitemid INTEGER;
_bomworksetid INTEGER;
WHERE ((bomhead_item_id=pSItemid)
AND (bomhead_rev_id=getActiveRevID('BOM', pSItemid)));
- IF (NOT FOUND) THEN
- RETURN -1;
- END IF;
+-- bomhead may not exist
+-- IF (NOT FOUND) THEN
+-- RETURN -1;
+-- END IF;
+ IF (FOUND) THEN
+ _bomheadfound := TRUE;
+ END IF;
-- Make sure that source bomitems exist
SELECT bomitem_id INTO _bomitemid
FROM bomitem
- WHERE ((bomitem_parent_item_id=_bh.bomhead_item_id)
- AND (bomitem_rev_id=_bh.bomhead_rev_id))
+ WHERE ((bomitem_parent_item_id=pSItemid)
+ AND (bomitem_rev_id=getActiveRevID('BOM', pSItemid)))
LIMIT 1;
IF (NOT FOUND) THEN
AND (bomhead_rev_id= -1));
IF (NOT FOUND) THEN
- INSERT INTO bomhead
- ( bomhead_item_id, bomhead_serial, bomhead_docnum,
- bomhead_batchsize, bomhead_requiredqtyper )
- VALUES
- ( pTItemid, _bh.bomhead_serial, _bh.bomhead_docnum,
- _bh.bomhead_batchsize, _bh.bomhead_requiredqtyper );
+ IF (_bomheadfound) THEN
+ INSERT INTO bomhead
+ ( bomhead_item_id, bomhead_serial, bomhead_docnum,
+ bomhead_batchsize, bomhead_requiredqtyper )
+ VALUES
+ ( pTItemid, _bh.bomhead_serial, _bh.bomhead_docnum,
+ _bh.bomhead_batchsize, _bh.bomhead_requiredqtyper );
+ END IF;
END IF;
FOR _bi IN SELECT bomitem.*
CREATE OR REPLACE FUNCTION copyBudget(INTEGER, TEXT, TEXT, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBudgheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION copycmd(INTEGER, TEXT, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmdId ALIAS FOR $1;
pNumber TEXT,
pEffective DATE,
pExpires DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_contrctid INTEGER;
CREATE OR REPLACE FUNCTION copyFinancialGroup(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSourceGroup ALIAS FOR $1;
CREATE OR REPLACE FUNCTION copyGLSeries(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION copyIncdt(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pparentid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION copyInvoice(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION copyItem(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION copyItem(INTEGER, TEXT, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION copyItem(INTEGER, TEXT, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION copyItem(INTEGER, TEXT, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSItemid ALIAS FOR $1;
-DROP FUNCTION IF EXISTS copyitemsite(integer, integer);
-CREATE OR REPLACE FUNCTION copyItemSite(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION copyItemSite(pitemsiteid INTEGER,
+ pdestwhsid INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+
+BEGIN
+
+ RETURN copyItemSite(pitemsiteid, pdestwhsid, NULL);
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+
+CREATE OR REPLACE FUNCTION copyItemSite(pitemsiteid INTEGER,
+ pdestwhsid INTEGER,
+ pdestitemid INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pitemsiteid ALIAS FOR $1;
SELECT itemsite_id INTO _new.itemsite_id
FROM itemsite
- WHERE ((itemsite_item_id=_new.itemsite_item_id)
+ WHERE ((itemsite_item_id=COALESCE(pdestitemid, _new.itemsite_item_id))
AND (itemsite_warehous_id=pdestwhsid OR
(itemsite_warehous_id IS NULL AND pdestwhsid IS NULL)));
IF (FOUND) THEN
itemsite_autoreg,
itemsite_planning_type, itemsite_supply_itemsite_id
) VALUES (
- _new.itemsite_id, _new.itemsite_item_id,
+ _new.itemsite_id, COALESCE(pdestitemid, _new.itemsite_item_id),
_new.itemsite_warehous_id, _new.itemsite_qtyonhand,
_new.itemsite_costmethod, _new.itemsite_value,
_new.itemsite_reorderlevel, _new.itemsite_ordertoqty,
CREATE OR REPLACE FUNCTION copyLocale(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocaleid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION copyPO(INTEGER, INTEGER, DATE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSrcid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION copypricingschedule(pIpsheadId INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_ipsheadid INTEGER;
CREATE OR REPLACE FUNCTION copyPrj(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pparentid ALIAS FOR $1;
-
-CREATE OR REPLACE FUNCTION copyProject(INTEGER, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION copyproject(integer, text, text, date)
+ RETURNS integer AS
+$BODY$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrjId ALIAS FOR $1;
pPrjNumber ALIAS FOR $2;
- pDueDateOffset ALIAS FOR $3;
+ pPrjName ALIAS FOR $3;
+ pDueDate ALIAS FOR $4;
_prjid INTEGER;
+ _offset INTEGER;
BEGIN
RETURN -1;
END IF;
+ IF (COALESCE(pPrjName, '') = '') THEN
+ RETURN -1;
+ END IF;
+
IF (EXISTS(SELECT prj_id FROM prj WHERE UPPER(prj_number)=UPPER(pPrjNumber))) THEN
RETURN -2;
END IF;
RETURN -3;
END IF;
+ IF (pDueDate IS NULL) THEN
+ RETURN -4;
+ END IF;
+
+ SELECT (pDueDate - prj_due_date) INTO _offset
+ FROM prj
+ WHERE (prj_id=pPrjId);
+
SELECT NEXTVAL('prj_prj_id_seq') INTO _prjid;
INSERT INTO prj
prj_due_date, prj_assigned_date, prj_completed_date,
prj_username, prj_recurring_prj_id,
prj_crmacct_id, prj_cntct_id )
- SELECT _prjid, UPPER(pPrjNumber), prj_name,
+ SELECT _prjid, UPPER(pPrjNumber), pPrjName,
prj_descrip, 'P',
prj_so, prj_wo, prj_po,
prj_owner_username, NULL,
- (prj_due_date + COALESCE(pDueDateOffset, 0)),
+ (prj_due_date + COALESCE(_offset, 0)),
CASE WHEN (prj_username IS NULL) THEN NULL ELSE CURRENT_DATE END, NULL,
prj_username, prj_recurring_prj_id,
prj_crmacct_id, prj_cntct_id
prjtask_hours_budget, 0.0,
prjtask_exp_budget, 0.0,
prjtask_owner_username, NULL,
- (prjtask_due_date + COALESCE(pDueDateOffset, 0)),
+ (prjtask_due_date + COALESCE(_offset, 0)),
CASE WHEN (prjtask_username IS NULL) THEN NULL ELSE CURRENT_DATE END,
NULL, prjtask_username
FROM prjtask
RETURN _prjid;
END;
-$$ LANGUAGE 'plpgsql';
-
+$BODY$
+ LANGUAGE plpgsql VOLATILE
+ COST 100;
+ALTER FUNCTION copyproject(integer, text, text, date)
+ OWNER TO admin;
CREATE OR REPLACE FUNCTION copyQuote(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION copySo(pSoheadid INTEGER,
pSchedDate DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_soheadid INTEGER;
CREATE OR REPLACE FUNCTION copyTodoitem(INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pparentid ALIAS FOR $1;
CAST(alarm_time - DATE_TRUNC('day',alarm_time) AS TIME),
alarm_time_offset,
alarm_time_qualifier,
- alarm_event, alarm_event_recipient,
- alarm_email, alarm_email_recipient,
- alarm_sysmsg, alarm_sysmsg_recipient,
+ (alarm_event_recipient IS NOT NULL), alarm_event_recipient,
+ (alarm_email_recipient IS NOT NULL AND fetchMetricBool('EnableBatchManager')), alarm_email_recipient,
+ (alarm_sysmsg_recipient IS NOT NULL), alarm_sysmsg_recipient,
'TODO', _todoitemid, 'CHANGEONE')
INTO _alarmid
FROM alarm
CREATE OR REPLACE FUNCTION copyVoucher(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION correctPoReceipt(INTEGER, NUMERIC, NUMERIC, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPorecvid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION correctPoReceipt(INTEGER, NUMERIC, NUMERIC, INTEGER, INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN correctReceipt(''PO'', $1, $2, $3, $4, $5, $6);
CREATE OR REPLACE FUNCTION correctProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE 'correctProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN) has been deprecated. Use corrrectProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER) or a package-specific version instead.';
CREATE OR REPLACE FUNCTION correctProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE 'correctProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER) has been deprecated. Use corrrectProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER) or a package-specific version instead.';
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION correctProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION correctProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION correctReceipt(INTEGER, NUMERIC, NUMERIC, INTEGER, INTEGER, DATE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
precvid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION cosByCustomerValue(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION costsByCustomerByItemSite(INTEGER, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION costsByCustomerValue(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION costsByCustomerValue(INTEGER, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION costsByCustomerValue(INTEGER, INTEGER, TEXT) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAccountingPeriod(DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStartDate ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createaccountingperiod(DATE, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStartDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAccountingYearPeriod(DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStartDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPChecks(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE 'createAPChecks() is deprecated - use createChecks() instead';
CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pId ALIAS FOR $1;
pTargetApopenId INTEGER,
pAmount NUMERIC,
pCurrId INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_apCreditApplyId INTEGER;
BEGIN
- IF (pAmount > (SELECT currToCurr(apopen_curr_id, pCurrId, ROUND(apopen_amount - apopen_paid, 2), apopen_docdate)
+ IF (pAmount > (SELECT ROUND(currToCurr(apopen_curr_id, pCurrId, (apopen_amount - apopen_paid), apopen_docdate), 2)
FROM apopen
WHERE (apopen_id=pTargetApopenId))) THEN
RETURN -1;
CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createAPDiscount(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createAPDiscount(INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createARCashDeposit(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
pCurrId INTEGER = baseCurrId(),
pArAccntid INTEGER = NULL,
pCoCcpayId INTEGER = NULL) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_accntid INTEGER;
pDocDate, '',
pOrderNumber, '', pDocDate,
'C', pDocNumber, pDocDate,
- 1, (pAmount - _taxBaseValue) * -1, 0,
+ 1, (pAmount + _taxBaseValue) * -1, 0, -- taxBaseValue is negative, so we add
CASE WHEN pSalesrepid < 0 THEN NULL ELSE pSalesrepid END,
(pCommissiondue * -1.0), FALSE,
pCurrId, _glSequence, pCoCcpayId)
CREATE OR REPLACE FUNCTION createARDebitMemo(INTEGER, INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, INTEGER, INTEGER, DATE, INTEGER, INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createbillingheader(integer)
RETURNS integer AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
BOOL, INTEGER, BOOL, TEXT, CHAR, INTEGER,
INTEGER, TEXT, TEXT, TEXT )
RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBomitemid ALIAS FOR $1;
END IF;
-- Make sure that the parent is not used in the component at some level
- IF ( SELECT (item_type IN ('M', 'F'))
- FROM item
- WHERE (item_id=pComponentItemid) ) THEN
- SELECT indentedWhereUsed(pParentItemid) INTO _bomworksetid;
- SELECT bomwork_id INTO _temp
- FROM bomwork
- WHERE ( (bomwork_set_id=_bomworksetid)
- AND (bomwork_item_id=pComponentItemid) )
- LIMIT 1;
- IF (FOUND) THEN
- PERFORM deleteBOMWorkset(_bomworksetid);
- RETURN -2;
- END IF;
+ SELECT indentedWhereUsed(pParentItemid) INTO _bomworksetid;
+ SELECT bomwork_id INTO _temp
+ FROM bomwork
+ WHERE ( (bomwork_set_id=_bomworksetid)
+ AND (bomwork_item_id=pComponentItemid) )
+ LIMIT 1;
+ IF (FOUND) THEN
+ PERFORM deleteBOMWorkset(_bomworksetid);
+ RETURN -2;
END IF;
PERFORM deleteBOMWorkset(_bomworksetid);
BOOL, INTEGER, BOOL, TEXT, CHAR, INTEGER,
INTEGER, TEXT )
RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBomitemid ALIAS FOR $1;
BOOL, INTEGER, BOOL, TEXT, CHAR(1), INTEGER,
INTEGER, TEXT, TEXT, TEXT )
RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBomitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createCheck(INTEGER, TEXT, INTEGER, DATE, NUMERIC, INTEGER, INTEGER, INTEGER, TEXT, TEXT, BOOL) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankaccntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createCheck(INTEGER, TEXT, INTEGER, DATE, NUMERIC, INTEGER, INTEGER, INTEGER, TEXT, TEXT, BOOL, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankaccntid ALIAS FOR $1;
-DROP FUNCTION IF EXISTS createchecks(integer, date);
-CREATE OR REPLACE FUNCTION createChecks(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION createChecks(pBankaccntid INTEGER,
+ pCheckDate DATE) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pBankaccntid ALIAS FOR $1;
- pCheckDate ALIAS FOR $2;
_v RECORD;
_r RECORD;
_c RECORD;
AND (apselect_date <= pCheckDate)) LOOP
-- if we owe this vendor anything (we might not) then create a check
- IF ((SELECT
- SUM(apselect_amount * _check_curr_rate / apopen_curr_rate)
- FROM apselect, apopen
- WHERE ((apselect_apopen_id=apopen_id)
- AND (apopen_vend_id=_v.vend_id)
- AND (apselect_bankaccnt_id=pBankaccntid)) ) > 0) THEN
+ -- allow $0 checks
+ IF ((SELECT SUM(CASE apopen_doctype WHEN 'C' THEN (apselect_amount * -1.0)
+ ELSE apselect_amount END * _check_curr_rate / apopen_curr_rate)
+ FROM apselect JOIN apopen ON (apopen_id=apselect_apopen_id)
+ WHERE ((apopen_vend_id=_v.vend_id)
+ AND (apselect_bankaccnt_id=pBankaccntid)) ) >= 0) THEN
-- 0.01 is a temporary amount; we''ll update the check amount later
_checkid := createCheck(pBankaccntid, 'V', _v.vend_id,
pCheckDate, 0.01, _check_curr_id,
-- one check can pay for purchases on multiple dates in multiple currencies
UPDATE checkhead
- SET checkhead_amount = (SELECT SUM(checkitem_amount / checkitem_curr_rate)
- FROM checkitem
+ SET checkhead_amount = (SELECT SUM(CASE WHEN (apopen_doctype='C') THEN checkitem_amount / checkitem_curr_rate * -1.0
+ ELSE checkitem_amount / checkitem_curr_rate END)
+ FROM checkitem LEFT OUTER JOIN apopen ON (apopen_id=checkitem_apopen_id)
WHERE (checkitem_checkhead_id=checkhead_id))
WHERE (checkhead_id=_checkid);
CREATE OR REPLACE FUNCTION createCountTag(int, text, bool, bool) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createcounttag(integer, text, boolean, boolean, integer)
RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createCycleCountsByWarehouse(INTEGER, INTEGER, TEXT, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createcyclecountsbywarehouse(integer, integer, text, boolean, boolean, integer, boolean)
RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createCycleCountsByWarehouse(INTEGER, INTEGER, INTEGER, TEXT, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createCycleCountsByWarehouse(INTEGER, TEXT, INTEGER, TEXT, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createcyclecountsbywarehousebyclasscode(integer, integer, integer, text, boolean, boolean, integer, boolean)
RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createcyclecountsbywarehousebyclasscode(integer, text, integer, text, boolean, boolean, integer, boolean)
RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createcyclecountsbywarehousebyplannercode(integer, integer, integer, text, boolean, boolean, integer, boolean)
RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createcyclecountsbywarehousebyplannercode(integer, text, integer, text, boolean, boolean, integer, boolean)
RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobmiscid ALIAS FOR $1;
WHERE taxhist_parent_id = pCobmiscid
AND taxhist_taxtype_id = getadjustmenttaxtypeid();
+-- Create the Invoice Characteristic Assignments
+ INSERT INTO charass
+ (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default, charass_price)
+ SELECT 'INV', _invcheadid, charass_char_id, charass_value, charass_default, charass_price
+ FROM cobmisc JOIN cohead ON (cohead_id=cobmisc_cohead_id)
+ JOIN charass ON ((charass_target_type='SO') AND (charass_target_id=cohead_id))
+ JOIN char ON (char_id=charass_char_id AND char_invoices)
+ WHERE (cobmisc_id=pCobmiscid);
+
-- Create the Invoice items
FOR _r IN SELECT coitem_id, coitem_linenumber, coitem_subnumber, coitem_custpn,
coitem_qtyord, cobill_qty,
CREATE OR REPLACE FUNCTION createInvoiceConsolidated(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createInvoices() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_counter INTEGER;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createInvoices(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN createinvoices($1, false);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createInvoices(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustTypeId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createMiscAPCheck(INTEGER, INTEGER, DATE, NUMERIC, INTEGER, TEXT, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''createMiscAPCheck() is deprecated - use createCheck() instead'';
CREATE OR REPLACE FUNCTION createMiscAPCheck(INTEGER, INTEGER, DATE, NUMERIC, INTEGER, INTEGER, TEXT, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''createMiscAPCheck() is deprecated - use createCheck() instead'';
CREATE OR REPLACE FUNCTION createPkgSchema(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pname ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createPr(INTEGER, INTEGER, NUMERIC, DATE, TEXT, CHARACTER(1), INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createPr(INTEGER, INTEGER, NUMERIC, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createPr(INTEGER, CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createPr(CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pParentType ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createpr(INTEGER, CHARACTER, INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createPriv(text, text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pModule ALIAS FOR $1;
SELECT dropIfExists('FUNCTION', 'createPurchaseToSale(integer, integer, boolean, numeric, date, numeric)', 'fixcountry');
CREATE OR REPLACE FUNCTION createPurchaseToSale(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCoitemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createPurchaseToSale(INTEGER, INTEGER, BOOLEAN, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCoitemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createPurchaseToSale(INTEGER, INTEGER, BOOLEAN, NUMERIC, DATE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCoitemId ALIAS FOR $1;
SELECT *,
COALESCE(roundQty(item_fractional, (coitem_qtyord * coitem_qty_invuomratio)), 0.0) AS orderqty
INTO _s
- FROM cohead JOIN coitem ON (cohead_id = coitem_cohead_id)
- LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
- LEFT OUTER JOIN itemsite ON (coitem_itemsite_id = itemsite_id)
- LEFT OUTER JOIN item ON (item_id = itemsite_item_id)
+ FROM coitem JOIN cohead ON (cohead_id = coitem_cohead_id)
+ LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
+ LEFT OUTER JOIN addr ON (shipto_addr_id = addr_id)
+ LEFT OUTER JOIN cntct ON (shipto_cntct_id = cntct_id)
+ LEFT OUTER JOIN itemsite ON (coitem_itemsite_id = itemsite_id)
+ LEFT OUTER JOIN item ON (item_id = itemsite_item_id)
WHERE (coitem_id = pCoitemId);
IF (NOT FOUND) THEN
RETURN -1;
END IF;
SELECT * INTO _w
- FROM whsinfo JOIN addr ON (warehous_addr_id = addr_id)
- JOIN cntct ON (warehous_cntct_id = cntct_id)
- JOIN itemsite ON (warehous_id = itemsite_warehous_id)
+ FROM itemsite JOIN whsinfo ON (warehous_id = itemsite_warehous_id)
+ LEFT OUTER JOIN addr ON (warehous_addr_id = addr_id)
+ LEFT OUTER JOIN cntct ON (warehous_cntct_id = cntct_id)
WHERE (itemsite_id = _s.itemsite_id);
SELECT * INTO _i
FROM itemsrc JOIN vendinfo ON (itemsrc_vend_id = vend_id)
- LEFT OUTER JOIN cntct ON (vend_cntct1_id = cntct_id)
- LEFT OUTER JOIN addr ON (vend_addr_id = addr_id)
+ LEFT OUTER JOIN cntct ON (vend_cntct1_id = cntct_id)
+ LEFT OUTER JOIN addr ON (vend_addr_id = addr_id)
WHERE (itemsrc_id = pItemSourceId);
IF (NOT FOUND) THEN
RETURN -2;
END IF;
- SELECT * INTO _shipto
- FROM shiptoinfo JOIN cntct ON (shipto_cntct_id = cntct_id)
- JOIN addr ON (shipto_addr_id = addr_id)
- RIGHT OUTER JOIN cohead ON (cohead_cust_id = shipto_cust_id)
- WHERE (cohead_id = _s.cohead_id)
- LIMIT 1;
-
IF (pDropShip) THEN
SELECT COALESCE(pohead_id, -1) INTO _temp
FROM pohead
WHERE ( (pohead_status = 'U')
AND (pohead_vend_id = _i.itemsrc_vend_id)
- AND (pohead_shiptoaddress_id = _s.shipto_addr_id) );
+ AND (pohead_shiptoname = COALESCE(_s.cohead_shiptoname, _s.shipto_name, ''))
+ AND (pohead_shiptoaddress1 = COALESCE(_s.cohead_shiptoaddress1, _s.addr_line1, ''))
+ AND (pohead_shiptoaddress2 = COALESCE(_s.cohead_shiptoaddress2, _s.addr_line2, ''))
+ AND (pohead_shiptoaddress3 = COALESCE(_s.cohead_shiptoaddress3, _s.addr_line3, ''))
+ AND (pohead_shiptocity = COALESCE(_s.cohead_shiptocity, _s.addr_city, ''))
+ AND (pohead_shiptostate = COALESCE(_s.cohead_shiptostate, _s.addr_state, ''))
+ AND (pohead_shiptozipcode = COALESCE(_s.cohead_shiptozipcode, _s.addr_postalcode, ''))
+ AND (pohead_shiptocountry = COALESCE(_s.cohead_shiptocountry, _s.addr_country, '')) );
ELSE
SELECT COALESCE(pohead_id, -1) INTO _temp
FROM pohead
WHERE ( (pohead_status = 'U')
AND (pohead_vend_id = _i.itemsrc_vend_id)
- AND (pohead_shiptoaddress_id = _w.addr_id) );
+ AND (pohead_shiptoaddress1 = COALESCE(_w.addr_line1, ''))
+ AND (pohead_shiptoaddress2 = COALESCE(_w.addr_line2, ''))
+ AND (pohead_shiptoaddress3 = COALESCE(_w.addr_line3, ''))
+ AND (pohead_shiptocity = COALESCE(_w.addr_city, ''))
+ AND (pohead_shiptostate = COALESCE(_w.addr_state, ''))
+ AND (pohead_shiptozipcode = COALESCE(_w.addr_postalcode, ''))
+ AND (pohead_shiptocountry = COALESCE(_w.addr_country, '')) );
END IF;
IF (FOUND) THEN
pohead_shipto_cntct_suffix, pohead_shipto_cntct_phone,
pohead_shipto_cntct_title, pohead_shipto_cntct_fax,
pohead_shipto_cntct_email, pohead_shiptoaddress_id,
+ pohead_shiptoname,
pohead_shiptoaddress1,
pohead_shiptoaddress2,
pohead_shiptoaddress3,
getEffectiveXtUser(), _i.itemsrc_vend_id, _i.vend_taxzone_id,
CURRENT_DATE, COALESCE(_i.vend_curr_id, basecurrid()), _s.cohead_id,
COALESCE(_s.cohead_warehous_id, -1), COALESCE(_i.vend_shipvia, TEXT('')),
- COALESCE(_i.vend_terms_id, -1), COALESCE(_s.cohead_shipto_cntct_id, _shipto.shipto_cntct_id),
- COALESCE(_s.cohead_shipto_cntct_honorific, _shipto.cntct_honorific), COALESCE(_s.cohead_shipto_cntct_first_name, _shipto.cntct_first_name),
- COALESCE(_s.cohead_shipto_cntct_middle, _shipto.cntct_middle), COALESCE(_s.cohead_shipto_cntct_last_name, _shipto.cntct_last_name),
- COALESCE(_s.cohead_shipto_cntct_suffix, _shipto.cntct_suffix), COALESCE(_s.cohead_shipto_cntct_phone, _shipto.cntct_phone),
- COALESCE(_s.cohead_shipto_cntct_title, _shipto.cntct_title), COALESCE(_s.cohead_shipto_cntct_fax, _shipto.cntct_fax),
- COALESCE(_s.cohead_shipto_cntct_email, _shipto.cntct_email), COALESCE(_s.shipto_addr_id, _shipto.addr_id),
- COALESCE(_s.cohead_shiptoaddress1, _shipto.addr_line1),
- COALESCE(_s.cohead_shiptoaddress2, _shipto.addr_line2),
- COALESCE(_s.cohead_shiptoaddress3, _shipto.addr_line3),
- COALESCE(_s.cohead_shiptocity, _shipto.addr_city),
- COALESCE(_s.cohead_shiptostate, _shipto.addr_state), COALESCE(_s.cohead_shiptozipcode, _shipto.addr_postalcode),
- COALESCE(_s.cohead_shiptocountry, _shipto.addr_country), _i.cntct_id,
+ COALESCE(_i.vend_terms_id, -1), COALESCE(_s.cohead_shipto_cntct_id, _s.shipto_cntct_id),
+ COALESCE(_s.cohead_shipto_cntct_honorific, _s.cntct_honorific), COALESCE(_s.cohead_shipto_cntct_first_name, _s.cntct_first_name),
+ COALESCE(_s.cohead_shipto_cntct_middle, _s.cntct_middle), COALESCE(_s.cohead_shipto_cntct_last_name, _s.cntct_last_name),
+ COALESCE(_s.cohead_shipto_cntct_suffix, _s.cntct_suffix), COALESCE(_s.cohead_shipto_cntct_phone, _s.cntct_phone),
+ COALESCE(_s.cohead_shipto_cntct_title, _s.cntct_title), COALESCE(_s.cohead_shipto_cntct_fax, _s.cntct_fax),
+ COALESCE(_s.cohead_shipto_cntct_email, _s.cntct_email), COALESCE(_s.shipto_addr_id, _s.addr_id),
+ COALESCE(_s.cohead_shiptoname, _s.shipto_name, ''),
+ COALESCE(_s.cohead_shiptoaddress1, _s.addr_line1, ''),
+ COALESCE(_s.cohead_shiptoaddress2, _s.addr_line2, ''),
+ COALESCE(_s.cohead_shiptoaddress3, _s.addr_line3, ''),
+ COALESCE(_s.cohead_shiptocity, _s.addr_city, ''),
+ COALESCE(_s.cohead_shiptostate, _s.addr_state, ''), COALESCE(_s.cohead_shiptozipcode, _s.addr_postalcode, ''),
+ COALESCE(_s.cohead_shiptocountry, _s.addr_country, ''), _i.cntct_id,
COALESCE(_i.cntct_honorific, TEXT('')), COALESCE(_i.cntct_first_name, TEXT('')),
COALESCE(_i.cntct_middle, TEXT('')), COALESCE(_i.cntct_last_name, TEXT('')),
COALESCE(_i.cntct_suffix, TEXT('')), COALESCE(_i.cntct_phone, TEXT('')),
_w.cntct_suffix, _w.cntct_phone,
_w.cntct_title, _w.cntct_fax,
_w.cntct_email, _w.addr_id,
- _w.addr_line1,
- _w.addr_line2,
- _w.addr_line3,
- _w.addr_city,
- _w.addr_state, _w.addr_postalcode,
- _w.addr_country, _i.cntct_id,
+ COALESCE(_w.addr_line1, ''),
+ COALESCE(_w.addr_line2, ''),
+ COALESCE(_w.addr_line3, ''),
+ COALESCE(_w.addr_city, ''),
+ COALESCE(_w.addr_state, ''), COALESCE(_w.addr_postalcode, ''),
+ COALESCE(_w.addr_country, ''), _i.cntct_id,
COALESCE(_i.cntct_honorific, TEXT('')), COALESCE(_i.cntct_first_name, TEXT('')),
COALESCE(_i.cntct_middle, TEXT('')), COALESCE(_i.cntct_last_name, TEXT('')),
COALESCE(_i.cntct_suffix, TEXT('')), COALESCE(_i.cntct_phone, TEXT('')),
WHERE (itemtax_item_id = _i.itemsrc_item_id);
IF (pPrice IS NULL) THEN
- SELECT itemsrcPrice(pItemSourceId, COALESCE(_s.cohead_warehous_id, -1), pDropShip,
- COALESCE(pQty, _s.orderqty), COALESCE(_i.vend_curr_id, baseCurrId()), CURRENT_DATE) INTO _price;
+ SELECT itemsrcPrice(pItemSourceId,
+ COALESCE(_s.cohead_warehous_id, -1),
+ pDropShip,
+ (COALESCE(pQty, _s.orderqty) / COALESCE(_i.itemsrc_invvendoruomratio, 1.00)),
+ COALESCE(_i.vend_curr_id, baseCurrId()),
+ CURRENT_DATE) INTO _price;
ELSE
_price := pPrice;
END IF;
poitem_unitprice, poitem_vend_item_number,
poitem_itemsrc_id, poitem_order_id, poitem_order_type, poitem_prj_id, poitem_stdcost,
poitem_manuf_name, poitem_manuf_item_number,
- poitem_manuf_item_descrip, poitem_taxtype_id )
+ poitem_manuf_item_descrip, poitem_taxtype_id, poitem_comments )
VALUES
( _poitemid, 'U', _poheadid, _polinenumber,
COALESCE(pDueDate, _s.coitem_scheddate), _s.coitem_itemsite_id,
_price, COALESCE(_i.itemsrc_vend_item_number, TEXT('')),
pItemSourceId, pCoitemId, 'S', _s.cohead_prj_id, stdcost(_i.itemsrc_item_id),
COALESCE(_i.itemsrc_manuf_name, TEXT('')), COALESCE(_i.itemsrc_manuf_item_number, TEXT('')),
- COALESCE(_i.itemsrc_manuf_item_descrip, TEXT('')), _taxtypeid );
+ COALESCE(_i.itemsrc_manuf_item_descrip, TEXT('')), _taxtypeid,
+ COALESCE(_s.coitem_memo, TEXT('')));
END IF;
-- Copy characteristics from the coitem to the poitem
INSERT INTO charass
WHERE ( coitem_id = pCoitemId );
-- Generate the PoItemCreatedBySo event notice
- INSERT INTO evntlog
- ( evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
- evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id,
- evntlog_number )
- SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id ,
- 'P', poitem_id, itemsite_warehous_id,
- (pohead_number || '-' || poitem_linenumber || ': ' || item_number)
- FROM evntnot JOIN evnttype ON (evntnot_evnttype_id=evnttype_id)
- JOIN itemsite ON (evntnot_warehous_id=itemsite_warehous_id)
- JOIN item ON (itemsite_item_id=item_id)
- JOIN poitem ON (poitem_itemsite_id=itemsite_id)
- JOIN pohead ON (poitem_pohead_id=pohead_id)
- WHERE ( (poitem_id=_poitemid)
- AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence))
- AND (evnttype_name='PoItemCreatedBySo') );
+ PERFORM postEvent('PoItemCreatedBySo', 'P', poitem_id,
+ itemsite_warehous_id,
+ (pohead_number || '-'|| poitem_linenumber || ': ' || item_number),
+ NULL, NULL, NULL, NULL)
+ FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
+ JOIN itemsite ON (itemsite_id=poitem_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ WHERE (poitem_id=_poitemid)
+ AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence));
RETURN _poitemid;
CREATE OR REPLACE FUNCTION createRecurringInvoices() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE 'createRecurringInvoices() has been deprecated; use createRecurringItems(NULL, ''I'') instead.';
CREATE OR REPLACE FUNCTION createRecurringItems(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pParentid ALIAS FOR $1; -- if NULL then all items with the given pType
CREATE OR REPLACE FUNCTION createTodoItem(INTEGER, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, DATE, DATE, CHARACTER(1), DATE, DATE, INTEGER, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN createTodoItem($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, NULL);
CREATE OR REPLACE FUNCTION createTodoItem(INTEGER, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, DATE, DATE, CHARACTER(1), DATE, DATE, INTEGER, TEXT, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ptodoid ALIAS FOR $1;
DROP FUNCTION IF EXISTS createUser(TEXT, BOOLEAN);
CREATE OR REPLACE FUNCTION createUser(pUsername TEXT, pCreateUsers BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
IF (pCreateUsers) THEN
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT, CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT, CHAR, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT, CHAR, INTEGER, INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT, CHAR, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT, CHAR, INTEGER, INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT, CHAR, INTEGER, INTEGER, INTEGER, INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT, CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION createWoMaterial(INTEGER, INTEGER, char(1), NUMERIC, NUMERIC, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createWoMaterial(INTEGER, INTEGER, char(1), INTEGER, NUMERIC, NUMERIC, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION createWoMaterial(INTEGER, INTEGER, char(1), INTEGER, NUMERIC, NUMERIC, NUMERIC, INTEGER, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
pRef TEXT,
pWooperId INTEGER,
pPickList BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _womatlid INTEGER;
+
+BEGIN
+
+ SELECT createWoMaterial(pWoid,
+ pItemsiteid,
+ pIssueMethod,
+ pUomId,
+ pQtyFxd,
+ pQtyPer,
+ pScrap,
+ pBomitemId,
+ pNotes,
+ pRef,
+ pWooperId,
+ pPickList,
+ 0.0) INTO _womatlid;
+
+ RETURN _womatlid;
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION createWoMaterial(pWoid INTEGER,
+ pItemsiteid INTEGER,
+ pIssueMethod CHAR(1),
+ pUomId INTEGER,
+ pQtyFxd NUMERIC,
+ pQtyPer NUMERIC,
+ pScrap NUMERIC,
+ pBomitemId INTEGER,
+ pNotes TEXT,
+ pRef TEXT,
+ pWooperId INTEGER,
+ pPickList BOOLEAN,
+ pPrice NUMERIC) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_womatlid INTEGER;
womatl_qtyper, womatl_scrap, womatl_qtyreq,
womatl_qtyiss, womatl_qtywipscrap, womatl_wooper_id,
womatl_bomitem_id, womatl_duedate, womatl_notes,
- womatl_ref, womatl_picklist )
+ womatl_ref, womatl_picklist, womatl_price )
SELECT _womatlid, wo_id, pItemsiteid,
pIssueMethod, pUomId, pQtyFxd,
pQtyPer, pScrap, roundQty(item_fractional, (pQtyFxd + wo_qtyord * pQtyPer) * (1 + pScrap) ),
0, 0, COALESCE(pWooperId, -1),
pBomitemId, wo_startdate, pNotes,
- pRef, COALESCE(pPickList, item_picklist)
+ pRef, COALESCE(pPickList, item_picklist), pPrice
FROM wo, itemsite JOIN item ON (item_id=itemsite_item_id)
WHERE ( (wo_id=pWoid)
AND (itemsite_id=pItemsiteid) );
CREATE OR REPLACE FUNCTION creditmemototal(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCreditmemoId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION crmacct() RETURNS SETOF crmacct AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row crmacct%ROWTYPE;
CREATE OR REPLACE FUNCTION currConcat(VARCHAR(3), VARCHAR(9))
RETURNS VARCHAR(15) AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
curr_abbr ALIAS FOR $1;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION currConcat(INTEGER) RETURNS VARCHAR(15) AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
id ALIAS FOR $1;
CREATE OR REPLACE FUNCTION currentAPMemoNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_number INTEGER;
CREATE OR REPLACE FUNCTION currentARMemoNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_number INTEGER;
CREATE OR REPLACE FUNCTION currentCashRcptNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_number INTEGER;
CREATE OR REPLACE FUNCTION currentNumber(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pName ALIAS FOR $1;
-- negative values = a loss.
CREATE OR REPLACE FUNCTION currGain(INTEGER, NUMERIC, DATE, DATE)
RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION currRate(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN currRate($1, NULL, $2);
CREATE OR REPLACE FUNCTION currRate(pFromCurr INTEGER,
pToCurr INTEGER,
pDate DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_fromRate NUMERIC := 1.0;
-- curr_rate. see mantis #3901.
CREATE OR REPLACE FUNCTION currToBase (integer, numeric, date) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION currToCurr(INTEGER, INTEGER, NUMERIC, DATE)
RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFromCurr ALIAS FOR $1;
-- curr_rate. see mantis #3901.
CREATE OR REPLACE FUNCTION currToLocal (integer, numeric, date) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION custitem(cust_id INTEGER, shipto_id INTEGER DEFAULT -1, asof DATE DEFAULT CURRENT_DATE) RETURNS SETOF integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-- Non Exclusive
CREATE OR REPLACE FUNCTION customerCanPurchase(INTEGER, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pitemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION customerCanPurchase(INTEGER, INTEGER, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pitemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION customerCanPurchase(INTEGER, INTEGER, INTEGER, DATE) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION defaultLocationName(INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteAccount(integer) RETURNS integer
AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAccntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteAccountingPeriod(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteAccountingYearPeriod(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteAddress(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
paddrId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''deleteAPCheck() is deprecated - use deleteCheck() instead'';
CREATE OR REPLACE FUNCTION deleteBankAdjustmentType(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankadjtypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteBankReconciliation(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pbankrecid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deletebom(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteBOMWorkset(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWorksetid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteBudget(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBudgheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteBudgetItems(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBudgheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteCashrcpt(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pcashrcptid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteCharacteristic(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCharid ALIAS FOR $1;
RETURN -6;
ELSIF (_r.charass_target_type = 'EMP') THEN
RETURN -7;
+ ELSIF (_r.charass_target_type = 'QU') THEN
+ RETURN -8;
+ ELSIF (_r.charass_target_type = 'SO') THEN
+ RETURN -9;
+ ELSIF (_r.charass_target_type = 'INV') THEN
+ RETURN -10;
+ ELSIF (_r.charass_target_type = 'V') THEN
+ RETURN -11;
+ ELSIF (_r.charass_target_type = 'PO') THEN
+ RETURN -12;
+ ELSIF (_r.charass_target_type = 'VO') THEN
+ RETURN -13;
ELSE
RETURN -99;
END IF;
CREATE OR REPLACE FUNCTION deleteCheck(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCheckid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteClassCode(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pClasscodeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteCompany(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pcompanyid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteCreditMemo(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteCustomer(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteCustomerType(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCusttypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteEmpGrp(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pempgrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteexpiredips() RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_r RECORD;
CREATE OR REPLACE FUNCTION deleteFlgrp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlgrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteForm(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFormid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteFreightClass(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFreightClassid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteGlSeries(INTEGER, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteIncident(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pincdtid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcheadid ALIAS FOR $1;
WHERE (aropenalloc_doctype='I')
AND (aropenalloc_doc_id=pInvcheadid);
+ DELETE FROM charass
+ WHERE (charass_target_type='INV')
+ AND (charass_target_id=pInvcheadid);
+
DELETE FROM invcitem
WHERE (invcitem_invchead_id=pInvcheadid);
CREATE OR REPLACE FUNCTION deleteIpsItem(pIpsItemId INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
CREATE OR REPLACE FUNCTION deleteIpsProdCat(pIpsItemId INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
CREATE OR REPLACE FUNCTION deleteItem(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteItemCost(INTEGER, INTEGER) RETURNS INTEGER AS $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteItemSite(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteItemUOM(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemuomid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteItemUOMConv(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemuomconvid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteLocation(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocationid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteMetaSQL(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteOpenRecurringItems(INTEGER, TEXT, TIMESTAMP WITH TIME ZONE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pParentid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteOpportunity(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOpheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deletePackage(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ppkgheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deletePo(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deletepoitem(integer) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPoitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deletePr(CHAR, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pParentType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deletePr(INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteProductCategory(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pProdcatid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteProfitCenter(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteProject(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrjid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteProjectTask(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrjtaskid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteQryhead(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pqryheadid ALIAS FOR $1;
-SELECT dropIfExists('FUNCTION', 'deleteQuote(integer)', 'public');
-SELECT dropIfExists('FUNCTION', 'deleteQuote(integer, integer)', 'public');
+--SELECT dropIfExists('FUNCTION', 'deleteQuote(integer)', 'public');
+--SELECT dropIfExists('FUNCTION', 'deleteQuote(integer, integer)', 'public');
CREATE OR REPLACE FUNCTION deleteQuote(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION deleteQuote(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION deleteQuote(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuheadid ALIAS FOR $1;
_quoteNumber := pQuoteNumber;
END IF;
- DELETE FROM quitem
+ PERFORM deleteQuoteItem(quitem_id)
+ FROM quitem
WHERE (quitem_quhead_id=pQuheadid);
+ DELETE FROM charass
+ WHERE (charass_target_type='QU')
+ AND (charass_target_id=pQuheadid);
+
DELETE FROM quhead
WHERE (quhead_id=pQuheadid);
--- /dev/null
+SELECT dropIfExists('FUNCTION', 'deleteQuoteItem(integer)', 'public');
+
+CREATE OR REPLACE FUNCTION deleteQuoteItem(INTEGER) RETURNS INTEGER AS $$
+DECLARE
+ pQuitemid ALIAS FOR $1;
+
+ _result INTEGER;
+
+BEGIN
+
+ DELETE FROM charass
+ WHERE (charass_target_type='QI')
+ AND (charass_target_id=pQuitemid);
+
+ DELETE FROM quitem
+ WHERE (quitem_id=pQuitemid);
+
+ RETURN 0;
+
+END;
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION deleteRecvForOrder(TEXT, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteSalesCategory(integer) RETURNS integer
AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSalescatid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteShippingCharge(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipchrgid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteShippingChargeType (integer) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipchrgid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteShipto(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShiptoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteSo(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION deleteSo(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
DELETE FROM pack
WHERE (pack_head_id=pSoheadid and pack_head_type = 'SO');
+ DELETE FROM charass
+ WHERE (charass_target_type='SO')
+ AND (charass_target_id=pSoheadid);
+
DELETE FROM cohead
WHERE (cohead_id=pSoheadid);
WHERE ((aropenalloc_doctype='S')
AND (aropenalloc_doc_id=pSoheadid));
- IF (COALESCE(pSonumber,'') != '') THEN
- _result = releaseSoNumber(pSonumber);
- ELSEIF (_r.cohead_number IS NOT NULL) THEN
- _result = releaseSoNumber(_r.cohead_number);
+ IF ( (NOT _r.cohead_wasquote) AND (NOT _r.cohead_imported) ) THEN
+ IF (COALESCE(pSonumber,'') != '') THEN
+ _result = releaseSoNumber(pSonumber);
+ ELSEIF (_r.cohead_number IS NOT NULL) THEN
+ _result = releaseSoNumber(_r.cohead_number);
+ END IF;
END IF;
IF (_poStatus < 0) THEN
CREATE OR REPLACE FUNCTION deleteSoItem(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoitemid ALIAS FOR $1;
END IF;
END IF;
+-- Delete characteristic assignments
+ DELETE FROM charass
+ WHERE (charass_target_type='SI')
+ AND (charass_target_id=pSoitemid);
+
+-- Delete reservations
+ IF (fetchMetricBool('EnableSOReservationsByLocation')) THEN
+ DELETE FROM reserve
+ WHERE (reserve_demand_type='SO')
+ AND (reserve_demand_id=pSoitemid);
+ END IF;
+
-- Delete the coitem
DELETE FROM coitem
WHERE (coitem_id=pSoitemid);
CREATE OR REPLACE FUNCTION deleteStandardJournal(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStdjrnlid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteStandardJournalGroup(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStdjrnlgrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteSubaccount(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteSubAccountType (integer) RETURNS integer
AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSubAccntTypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION public.deletetax(integer)
RETURNS integer AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ptaxid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deletetaxclass(integer)
RETURNS integer AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxclassid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteTaxType(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxtypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deletetaxzone(integer)
RETURNS integer AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxzoneid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteTodoItem(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ptodoItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteUnusedClassCodes() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION deleteUnusedFreightClasses() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION deleteUnusedProductCategories() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION deleteUOM(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUomid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteUOMConv(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUomconvid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteUserPreference(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrefname ALIAS FOR $1;
' LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION deleteUserPreference(TEXT, TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteVendorAddress(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendaddrid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteVendorType(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendtypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION deleteWo(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION deleteWo(INTEGER, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
END IF;
IF (woStatus = 'R') THEN
- INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
- evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number)
- SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
- 'W', wo_id, itemsite_warehous_id, formatWoNumber(wo_id)
- FROM evntnot, evnttype, itemsite, item, wo
- WHERE ( (evntnot_evnttype_id=evnttype_id)
- AND (evntnot_warehous_id=itemsite_warehous_id)
- AND (wo_itemsite_id=itemsite_id)
- AND (itemsite_item_id=item_id)
- AND (evnttype_name='RWoRequestCancel')
- AND (wo_id=pWoid) );
+ PERFORM postEvent('RWoRequestCancel', 'W', wo_id,
+ itemsite_warehous_id, formatWoNumber(wo_id),
+ NULL, NULL, NULL, NULL)
+ FROM wo JOIN itemsite ON (itemsite_id=wo_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ WHERE (wo_id=pWoid);
RETURN 0;
ELSE
CREATE OR REPLACE FUNCTION deleteWoMaterial(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION detachCCPayFromSO(INTEGER, INTEGER, INTEGER)
RETURNS INTEGER AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pcoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION detachContact(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pcntctId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION detag(TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSource ALIAS FOR $1;
CREATE OR REPLACE FUNCTION detailedNNQOH(INTEGER, BOOLEAN) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION detailedQOH(INTEGER, BOOLEAN) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION determineDiscountDate(INTEGER, DATE) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTermsid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION determineDueDate(INTEGER, DATE) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTermsid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION disablePackage(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ppkgname ALIAS FOR $1;
LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION disablePackage(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ppkgheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION distributeItemlocSeries(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemlocSeries ALIAS FOR $1;
CREATE OR REPLACE FUNCTION distributeToDefault(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemlocdistid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION distributeToDefault(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemlocdistid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION distributeToDefaultItemLoc(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemlocdistid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION distributeToDefaultItemLoc(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemlocdistid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION distributeToLocations(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemlocdistid ALIAS FOR $1;
SELECT nextval('shipitemlocrsrv_shipitemlocrsrv_id_seq'),
shipitem_id, itemloc_itemsite_id, itemloc_location_id,
itemloc_ls_id, itemloc_expiration, itemloc_warrpurc,
- least(_itemlocdist.qty, itemlocrsrv_qty)
+ least((_itemlocdist.qty * -1.0), reserve_qty)
FROM shipitem, itemloc
- JOIN itemlocrsrv ON (itemloc_id=itemlocrsrv_itemloc_id)
+ JOIN reserve ON (itemloc_id=reserve_supply_id AND reserve_supply_type='I')
WHERE ( (shipitem_invhist_id=_itemlocdist.invhistid)
AND (itemloc_id=_itemlocid)
- AND (itemlocrsrv_source=_itemlocdist.ordertype)
- AND (itemlocrsrv_source_id=_itemlocdist.orderid) );
+ AND (reserve_demand_type=_itemlocdist.ordertype)
+ AND (reserve_demand_id=_itemlocdist.orderid) );
END IF;
--- Update the itemloc reservation
- UPDATE itemlocrsrv
- SET itemlocrsrv_qty = (itemlocrsrv_qty + _itemlocdist.qty)
- WHERE ( (itemlocrsrv_itemloc_id=_itemlocid)
- AND (itemlocrsrv_source=_itemlocdist.ordertype)
- AND (itemlocrsrv_source_id=_itemlocdist.orderid) );
+-- Update the reservation
+ UPDATE reserve
+ SET reserve_qty = (reserve_qty + _itemlocdist.qty)
+ WHERE ( (reserve_supply_id=_itemlocid)
+ AND (reserve_supply_type='I')
+ AND (reserve_demand_type=_itemlocdist.ordertype)
+ AND (reserve_demand_id=_itemlocdist.orderid) );
-- Delete reservation if fully distributed
- DELETE FROM itemlocrsrv
- WHERE ( (itemlocrsrv_itemloc_id=_itemlocid)
- AND (itemlocrsrv_source=_itemlocdist.ordertype)
- AND (itemlocrsrv_source_id=_itemlocdist.orderid)
- AND (itemlocrsrv_qty=0) );
+ DELETE FROM reserve
+ WHERE ( (reserve_supply_id=_itemlocid)
+ AND (reserve_supply_type='I')
+ AND (reserve_demand_type=_itemlocdist.ordertype)
+ AND (reserve_demand_id=_itemlocdist.orderid)
+ AND (reserve_qty=0) );
END IF;
END IF;
CREATE OR REPLACE FUNCTION distributeVoucherLine(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVoucherId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION doPostCosts(BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION doPostCosts(INTEGER, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
CREATE OR REPLACE FUNCTION doUpdateCosts(BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION doUpdateCosts(BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION doUpdateCosts(INTEGER, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
CREATE OR REPLACE FUNCTION doUpdateCosts(INTEGER, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
CREATE OR REPLACE FUNCTION dropIfExists(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN dropIfExists($1, $2, 'public');
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION dropIfExists(TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN dropIfExists($1, $2, $3, false);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION dropIfExists(TEXT, TEXT, TEXT, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pType ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION dropIfExists(TEXT, TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION editccnumber(text, text)
RETURNS text AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCcardnum ALIAS FOR $1;
CREATE OR REPLACE FUNCTION enablePackage(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ppkgname ALIAS FOR $1;
LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION enablePackage(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ppkgheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION endoftime() RETURNS DATE IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DATE('2100-01-01') as result;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION enterCount(int, numeric, text) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION enterPoReceipt(INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN enterReceipt(''PO'', $1, $2, 0.0, '''', NULL, NULL);
CREATE OR REPLACE FUNCTION enterPoReceipt(INTEGER, NUMERIC, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN enterPoReceipt(''PO'', $1, $2, 0.0, $3, NULL, NULL);
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION enterPoReceipt(INTEGER, NUMERIC, NUMERIC, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN enterPoReceipt(''PO'', $1, $2, $3, $4, NULL, NULL);
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION enterPoReceipt(INTEGER, NUMERIC, NUMERIC, TEXT, INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN enterReceipt(''PO'', $1, $2, $3, $4, $5, $6);
CREATE OR REPLACE FUNCTION enterPoReturn(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN enterPoReturn($1, $2, $3, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION enterPoReturn(INTEGER, NUMERIC, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPoitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION enterReceipt(TEXT, INTEGER, NUMERIC, NUMERIC, TEXT, INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN enterReceipt($1, $2, $3, $4, $5, $6, $7, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION enterReceipt(TEXT, INTEGER, NUMERIC, NUMERIC, TEXT, INTEGER, DATE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION expireCreditCard(integer, bytea)
RETURNS text AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCust ALIAS FOR $1;
CREATE OR REPLACE FUNCTION explodeBOM(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION explodeBOM(INTEGER, INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION explodeKit(INTEGER, INTEGER, INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION explodeKit(INTEGER, INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION explodeKit(INTEGER, INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION explodePhantomOrder(INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPlanordid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION explodeWo(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
-- Create the W/O Material Requirements
INSERT INTO womatl
( womatl_wo_id, womatl_bomitem_id, womatl_wooper_id, womatl_schedatwooper,
- womatl_itemsite_id,
- womatl_duedate,
+ womatl_itemsite_id, womatl_duedate,
womatl_uom_id, womatl_qtyfxd, womatl_qtyper, womatl_scrap,
womatl_qtyreq,
womatl_qtyiss, womatl_qtywipscrap,
womatl_lastissue, womatl_lastreturn, womatl_cost,
womatl_picklist, womatl_createwo, womatl_issuewo,
- womatl_issuemethod, womatl_notes, womatl_ref )
+ womatl_issuemethod, womatl_notes, womatl_ref,
+ womatl_price )
SELECT wo_id, bomitem_id, bomitem_booitem_seq_id, bomitem_schedatwooper,
- cs.itemsite_id,
- CASE WHEN bomitem_schedatwooper THEN COALESCE(calcWooperStartStub(wo_id,bomitem_booitem_seq_id), wo_startdate)
- ELSE wo_startdate
- END,
+ matl_itemsite, duedate,
bomitem_uom_id, bomitem_qtyfxd, bomitem_qtyper, bomitem_scrap,
- roundQty(itemuomfractionalbyuom(bomitem_item_id, bomitem_uom_id), (bomitem_qtyfxd + bomitem_qtyper * wo_qtyord) * (1 + bomitem_scrap)),
- 0, 0,
+ qtyreq, 0, 0,
startOfTime(), startOfTime(), 0,
- item_picklist, ( (item_type='M') AND (bomitem_createwo) ),
- CASE WHEN ( (item_type='M') AND (bomitem_issuewo) ) THEN TRUE
- WHEN (cs.itemsite_costmethod='J') THEN TRUE
- ELSE FALSE
- END,
- bomitem_issuemethod, bomitem_notes, bomitem_ref
- FROM bomitem, wo, itemsite AS ps, itemsite AS cs, item
- WHERE ( (wo_itemsite_id=ps.itemsite_id)
- AND (bomitem_parent_item_id=ps.itemsite_item_id)
- AND (bomitem_item_id=cs.itemsite_item_id)
- AND (bomitem_rev_id=wo_bom_rev_id)
- AND (ps.itemsite_warehous_id=cs.itemsite_warehous_id)
- AND (cs.itemsite_item_id=item_id)
- AND (woEffectiveDate(wo_startdate) BETWEEN bomitem_effective AND (bomitem_expires - 1))
- AND (wo_id=pWoid)
- AND ((bomitem_char_id IS NULL)
- OR EXISTS (
- SELECT charass_id
- FROM coitem,charass
- WHERE ((charass_target_type='SI')
- AND (charass_target_id=coitem_id)
- AND (charass_char_id=bomitem_char_id)
- AND (charass_value=bomitem_value)
- AND (wo_ordtype='S')
- AND (coitem_id=wo_ordid)))) );
+ item_picklist, ( (item_type='M') AND (bomitem_createwo) ), issuewo,
+ bomitem_issuemethod, bomitem_notes, bomitem_ref,
+ CASE WHEN (price=-9999.0) THEN 0.0
+ ELSE price
+ END
+ FROM (SELECT *, cs.itemsite_id AS matl_itemsite,
+ CASE WHEN bomitem_schedatwooper THEN COALESCE(calcWooperStartStub(wo_id,bomitem_booitem_seq_id), wo_startdate)
+ ELSE wo_startdate
+ END AS duedate,
+ roundQty(itemuomfractionalbyuom(bomitem_item_id, bomitem_uom_id), (bomitem_qtyfxd + bomitem_qtyper * wo_qtyord) * (1 + bomitem_scrap)) AS qtyreq,
+ CASE WHEN ( (item_type='M') AND (bomitem_issuewo) ) THEN TRUE
+ WHEN (cs.itemsite_costmethod='J') THEN TRUE
+ ELSE FALSE
+ END AS issuewo,
+ CASE WHEN (cohead_id IS NULL) THEN item_listprice
+ ELSE (SELECT itemprice_price
+ FROM itemIpsPrice(item_id, cohead_cust_id, cohead_shipto_id,
+ roundQty(itemuomfractionalbyuom(bomitem_item_id, bomitem_uom_id), (bomitem_qtyfxd + bomitem_qtyper * wo_qtyord) * (1 + bomitem_scrap)),
+ bomitem_uom_id, bomitem_uom_id, cohead_curr_id, CURRENT_DATE, CURRENT_DATE, cohead_warehous_id) LIMIT 1)
+ END AS price
+ FROM wo JOIN itemsite ps ON (ps.itemsite_id=wo_itemsite_id)
+ JOIN bomitem ON (bomitem_parent_item_id=ps.itemsite_item_id AND
+ bomitem_rev_id=wo_bom_rev_id AND
+ woEffectiveDate(wo_startdate) BETWEEN bomitem_effective and (bomitem_expires - 1))
+ JOIN itemsite cs ON (cs.itemsite_item_id=bomitem_item_id AND
+ cs.itemsite_warehous_id=ps.itemsite_warehous_id)
+ JOIN item ON (item_id=cs.itemsite_item_id)
+ LEFT OUTER JOIN coitem ON (wo_ordtype='S' AND
+ wo_ordid=coitem_id)
+ LEFT OUTER JOIN cohead ON (cohead_id=coitem_cohead_id)
+ WHERE ( (wo_id=pWoid)
+ AND ((bomitem_char_id IS NULL)
+ OR EXISTS (
+ SELECT charass_id
+ FROM coitem,charass
+ WHERE ((charass_target_type='SI')
+ AND (charass_target_id=coitem_id)
+ AND (charass_char_id=bomitem_char_id)
+ AND (charass_value=bomitem_value)
+ AND (wo_ordtype='S')
+ AND (coitem_id=wo_ordid)))) )
+ ) AS data;
-- Update any created P/R's the have the project id as the parent WO.
UPDATE pr SET pr_prj_id=wo_prj_id
wooper_suconsumed, wooper_sucomplete,
wooper_rnconsumed, wooper_rncomplete,
wooper_qtyrcv, wooper_instruc, wooper_scheduled,
- wooper_wip_location_id )
+ wooper_wip_location_id, wooper_price )
SELECT wo_id, booitem_id, booitem_seqnumber,
booitem_wrkcnt_id, booitem_stdopn_id,
booitem_descrip1, booitem_descrip2, booitem_toolref,
0::NUMERIC, FALSE,
0::NUMERIC, booitem_instruc,
calculatenextworkingdate(itemsite_warehous_id,wo_startdate,booitem_execday-1),
- booitem_wip_location_id
+ booitem_wip_location_id,
+ (xtmfg.directlaborcostoper(booitem_id) + xtmfg.overheadcostoper(booitem_id) + xtmfg.machineoverheadcostoper(booitem_id))
FROM xtmfg.booitem, wo, itemsite
WHERE ((wo_itemsite_id=itemsite_id)
AND (itemsite_item_id=booitem_item_id)
CREATE OR REPLACE FUNCTION explodeWoEffective() RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_value TEXT;
CREATE OR REPLACE FUNCTION fetchAPMemoNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('APMemoNumber')::INTEGER;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchARMemoNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('ARMemoNumber');
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchCashRcptNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('CashRcptNumber');
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchCMNumber() RETURNS text AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('CmNumber');
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION fetchCRMAccountNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('CRMAccountNumber')::INTEGER;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION FetchDefaultFob(pWarehousId INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT warehous_fob
FROM whsinfo
CREATE OR REPLACE FUNCTION FetchDefaultShipVia() RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal TEXT;
CREATE OR REPLACE FUNCTION fetchGLSequence() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_sequence INTEGER;
CREATE OR REPLACE FUNCTION fetchIncidentNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('IncidentNumber')::integer;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchInvcNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('InvcNumber')::integer;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchItemUomConvTypes(integer)
RETURNS text[] AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemUomConvId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION fetchjournalnumber(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUse ALIAS FOR $1;
CREATE OR REPLACE FUNCTION FetchMetricBool(text) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_pMetricName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION FetchMetricText(text) RETURNS TEXT STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_pMetricName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION FetchMetricValue(text) RETURNS NUMERIC STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_pMetricName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION fetchNextCheckNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankaccntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION fetchNextNumber(TEXT) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
psequence ALIAS FOR $1;
END LOOP;
UPDATE orderseq SET
- orderseq_number = _nextnum,
- orderseq_seqiss = orderseq_seqiss || _seqiss
+ orderseq_number = _nextnum
WHERE (orderseq_name=psequence);
+ IF (fetchMetricBool('EnableGaplessNumbering')) THEN
+ UPDATE orderseq SET
+ orderseq_seqiss = orderseq_seqiss || _seqiss
+ WHERE (orderseq_name=psequence);
+ END IF;
+
RETURN _number;
END;
CREATE OR REPLACE FUNCTION fetchPoNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('PoNumber');
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION FetchPrefWarehousId() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_result INTEGER;
CREATE OR REPLACE FUNCTION fetchPrNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('PrNumber')::INTEGER;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchQuNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('QuNumber');
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchshipmentnumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_number TEXT;
CREATE OR REPLACE FUNCTION fetchSoNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('SoNumber');
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchToNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('ToNumber');
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION FetchUsrPrefBool(text) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_pPrefName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION fetchVoNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('VcNumber')::INTEGER;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION fetchWoNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT fetchNextNumber('WoNumber')::INTEGER;
$$ LANGUAGE 'sql';
SELECT dropIfExists('FUNCTION','financialreport(INTEGER,_int4,bpchar,bool)');
CREATE OR REPLACE FUNCTION financialreport(INTEGER, INTEGER, INTEGER) RETURNS bool AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION financialreport(INTEGER, INTEGER, bpchar, INTEGER)
RETURNS bool AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION financialreport(INTEGER, INTEGER, bool, bool, INTEGER)
RETURNS SETOF flstmtitem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlcolid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION financialreport(INTEGER,_int4,bpchar,bool,INTEGER)
RETURNS SETOF fltrenditem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlheadId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findAPAccount(INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findAPDiscountAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findAPPrepaidAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findARAccount(INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findardiscountaccount(integer) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findCalendarOrigin(INTEGER) RETURNS DATE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCalheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findCustomerForm(INTEGER, CHARACTER(1)) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findDeferredAccount(INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findFreightAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findPeriodEnd(INTEGER) RETURNS DATE STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCalitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findPeriodStart(INTEGER) RETURNS DATE STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCalitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findPrepaidAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION findSalesAccnt(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN findSalesAccnt($1, 'IS', $2, NULL, NULL);
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION findSalesAccnt(INTEGER, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN findSalesAccnt($1, $2, $3, NULL, NULL);
pCustid INTEGER,
pSaletypeid INTEGER,
pShipzoneid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_s RECORD;
CREATE OR REPLACE FUNCTION findSpecialFinancial(TEXT, TEXT, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUnit ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION copyFinancialLayout(INTEGER, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSourceFlheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION firstLine(TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSource ALIAS FOR $1;
CREATE OR REPLACE FUNCTION fixACL() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_r RECORD;
CREATE OR REPLACE FUNCTION formatabachecks(integer, integer, text)
RETURNS SETOF achline AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pbankaccntid ALIAS FOR $1; -- all unprinted checks for this bankaccnt
CREATE OR REPLACE FUNCTION formatACHChecks(INTEGER, INTEGER, TEXT) RETURNS SETOF achline AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pbankaccntid ALIAS FOR $1; -- all unprinted checks for this bankaccnt
CREATE OR REPLACE FUNCTION formatACHCompanyId() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN CASE WHEN fetchMetricText('ACHCompanyIdType') = 'D' THEN '3'
CREATE OR REPLACE FUNCTION formatAddr(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAddrId ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION formatAddr(TEXT, TEXT, TEXT, TEXT, INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
f_addr1 ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION formatAddr(TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
f_addr1 ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION formatAddr(TEXT, TEXT, TEXT, TEXT, TEXT) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
f_addr1 ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatBoolYN(BOOLEAN) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE pBool ALIAS FOR $1;
BEGIN
CREATE OR REPLACE FUNCTION formatBooSeq(INTEGER, INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatbytea(bytea)
RETURNS text AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pField ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatCCdashes(text, text)
RETURNS text AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCCard ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatccnumber(text)
RETURNS text AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCcardnum ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatccnumber(bytea)
RETURNS text AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCcardnum ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatCntctName(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCntctId ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION formatCntctName(TEXT, TEXT, TEXT, TEXT, TEXT) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pHonorific ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatCost(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN formatNumeric($1, ''cost'');
CREATE OR REPLACE FUNCTION formatCountTagBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCnttagid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatCreditMemoNumber(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatDate(TIMESTAMP WITH TIME ZONE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT TO_CHAR($1, COALESCE((SELECT locale_dateformat
FROM locale, usr
CREATE OR REPLACE FUNCTION formatDate(DATE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT TO_CHAR($1, COALESCE((SELECT locale_dateformat
FROM locale, usr
' LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatDate(DATE, TEXT) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatDateTime(TIMESTAMP WITHOUT TIME ZONE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT TO_CHAR($1, COALESCE((SELECT locale_timestampformat
FROM locale, usr
' LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatDateTime(TIMESTAMP WITH TIME ZONE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT TO_CHAR($1, COALESCE((SELECT locale_timestampformat
FROM locale, usr
CREATE OR REPLACE FUNCTION formatExtPrice(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN formatNumeric($1, ''extprice'');
CREATE OR REPLACE FUNCTION formatflitemdescrip(int4)
RETURNS text AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlitemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatGLAccount(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAccntid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION formatGLAccount(TEXT, TEXT, TEXT, TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCompany ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatGLAccountLong(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAccntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatindent(text,int4)
RETURNS text AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pText ALIAS FOR $1;
-- treat NUMERIC as number of minutes
CREATE OR REPLACE FUNCTION formatInterval(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT TO_CHAR((''@ '' || trunc($1) || '' min '' ||
($1 - trunc($1)) * 60 || '' sec'')::INTERVAL,
' LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatInterval(INTERVAL) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT TO_CHAR($1, ( SELECT locale_intervalformat
FROM locale, usr
CREATE OR REPLACE FUNCTION formatInvcNumber(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobmiscid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatItemSiteBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatLocationBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocationid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatLocationContentsBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocationid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatLocationIssueBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocationid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatLocationName(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocationid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatLotSerialNumber(INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLotSerialId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatMoney(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN formatNumeric($1, ''curr'');
CREATE OR REPLACE FUNCTION formatNumeric(NUMERIC, TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_value NUMERIC := $1;
CREATE OR REPLACE FUNCTION formatPeriodName( INTEGER, char) RETURNS text AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatPloNumber(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPlanordid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatPrcnt(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT formatNumeric($1 * 100, 'percent') AS result
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatPrice(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT formatNumeric($1, 'salesprice') AS result;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatPurchPrice(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN formatNumeric($1, ''purchprice'');
CREATE OR REPLACE FUNCTION formatQty(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN formatNumeric($1, ''qty'');
CREATE OR REPLACE FUNCTION formatQtyPer(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN formatNumeric($1, ''qtyper'');
CREATE OR REPLACE FUNCTION formatRatio(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT formatNumeric($1, 'uomratio');
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatRevNumber(TEXT, INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pRevType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatSalesPrice(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN formatNumeric($1, ''salesprice'');
CREATE OR REPLACE FUNCTION formatScrap(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT formatNumeric(($1 * 100), 'percent') AS result
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatShipmentNumber(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pshipheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatSoBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatSoitemBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatSoitemNumber(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
targetSoitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatSoLineNumber(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatSoNumber(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT COALESCE((SELECT (text(cohead_number) || '-' || formatSoLineNumber(coitem_id))
FROM coitem JOIN cohead ON (coitem_cohead_id=cohead_id)
WHERE (coitem_id=($1))),'DELETED');
-$$ LANGUAGE 'SQL' STABLE;
+$$ LANGUAGE 'sql' STABLE;
CREATE OR REPLACE FUNCTION formatTime(TIMESTAMP WITH TIME ZONE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT TO_CHAR($1, ( SELECT locale_timeformat
FROM locale, usr
CREATE OR REPLACE FUNCTION formatTime(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT LTRIM(TO_CHAR(COALESCE($1, 0), ''999999990.0''));
' LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatUOMRatio(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN formatNumeric($1, ''uomratio'');
CREATE OR REPLACE FUNCTION formatUserBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUserid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION formatUserBarcode(TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatWeight(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT formatNumeric($1, 'weight') AS result
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION formatWoBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatWoNumber(integer) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION formatwooperseq(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWooperId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION forwardUpdateAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAccntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION forwardUpdateInvBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvbalid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION forwardUpdateItemsite(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION forwardUpdateTrialBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTrialbalid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION freezeAccountingPeriod(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION freightDetail(text,integer,integer,integer,date,text,integer)
RETURNS SETOF freightData AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrderType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION freightDetailQuote(integer,text,integer,text,date,text,text,text[][])
RETURNS SETOF freightData AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustId ALIAS FOR $1;
-- if $3 == true then calculate freight on posted records
-- if $3 == false then calculate freight on unposted records
CREATE OR REPLACE FUNCTION freightForRecv(TEXT, INTEGER, BOOLEAN) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getActiveRevId(TEXT,INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTargetType ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION getAddrId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getAddrId(pAddressNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pAddressNumber ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
- IF (pAddressNumber IS NULL OR pAddressNumber = '''') THEN
+ IF (pAddressNumber IS NULL OR pAddressNumber = '') THEN
RETURN NULL;
END IF;
WHERE (addr_number=pAddressNumber);
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Address Number % not found.'', pAddressNumber;
+ RAISE EXCEPTION 'Address Number % not found.', pAddressNumber;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getadjustmenttaxtypeid()
RETURNS integer AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_taxtypeid INTEGER;
CREATE OR REPLACE FUNCTION getAropenId(text, character, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getBankAccntId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankAccntName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getBomitemId(text,text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getBooitemSeqId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getBudgheadId(text)
RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBudghead ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getCashrcptId(text, text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustNumber ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION getCharId(text, text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getCharId(pChar text,
+ pType text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pChar ALIAS FOR $1;
- pType ALIAS FOR $2;
_returnVal INTEGER;
BEGIN
IF (COALESCE(pChar, '') = '') THEN
CREATE OR REPLACE FUNCTION getClassCodeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pClassCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getCmheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCreditMemoNumber ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getCmheadId(text, boolean) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCreditMemoNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getCmntTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmntType ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION getCntctId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getCntctId(pContactNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pContactNumber ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
SELECT getCntctId(pContactNumber,true) INTO _returnVal;
END;
$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getCntctId(text,boolean) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getCntctId(pContactNumber text,
+ pNotFoundErr boolean) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pContactNumber ALIAS FOR $1;
- pNotFoundErr ALIAS FOR $2;
_returnVal INTEGER;
BEGIN
IF (COALESCE(TRIM(pContactNumber), '') = '') THEN
CREATE OR REPLACE FUNCTION getCoheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSalesOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getCoItemId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSalesOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getContrctEffective(pContrctNumber text) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal DATE;
CREATE OR REPLACE FUNCTION getContrctExpires(pContrctNumber text) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal DATE;
CREATE OR REPLACE FUNCTION getContrctId(pContrctNumber text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
CREATE OR REPLACE FUNCTION getCostCatId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCostCat ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getCostElemId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCostElemType ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION getCrmAcctId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getCrmAcctId(pAcctNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pAcctNumber ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
-CREATE OR REPLACE FUNCTION getCurrId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getCurrId(pCurrName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pCurrName ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
IF (pCurrName IS NULL) THEN
WHERE (curr_abbr=pCurrName);
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Currency % not found.'', pCurrName;
+ RAISE EXCEPTION 'Currency % not found.', pCurrName;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getCustId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getCustId(pCustNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pCustNumber ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getCustId(text,boolean) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getCustId(pCustNumber text,
+ pInclProspects boolean) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pCustNumber ALIAS FOR $1;
- pInclProspects ALIAS FOR $2;
_returnVal INTEGER;
BEGIN
IF (pCustNumber IS NULL) THEN
FROM prospect
WHERE (UPPER(prospect_number)=UPPER(pCustNumber));
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Neither Customer nor Prospect Number % found.'', pCustNumber;
+ RAISE EXCEPTION 'Neither Customer nor Prospect Number % found.', pCustNumber;
END IF;
ELSE
- RAISE EXCEPTION ''Customer Number % not found.'', pCustNumber;
+ RAISE EXCEPTION 'Customer Number % not found.', pCustNumber;
END IF;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getCustNameFromInfo(TEXT, TEXT, TEXT, TEXT, TEXT, BOOLEAN) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_email TEXT := COALESCE(UPPER($1), '''');
CREATE OR REPLACE FUNCTION getCustTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustTypeCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getDeptId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pDeptNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getEdiProfileId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pEdiProfileName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getEdiProfileName(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pEdiProfileId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getEffectiveXtUser() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
/*
CREATE OR REPLACE FUNCTION getEmpId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pEmpCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getExpcatId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pExpcatCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getflcoldata(int4, int4)
RETURNS SETOF flcoldata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlcolid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getflcoldata(char(1), int[], boolean)
RETURNS SETOF flcoldata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInterval ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getflstmthead(int4, int4)
RETURNS SETOF flstmthead AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlcolid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getfltrendhead(INTEGER, _int4, bpChar)
RETURNS SETOF fltrendhead AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getFreightClassId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFreightClassCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getFreightTaxTypeId() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_taxtypeid INTEGER;
CREATE OR REPLACE FUNCTION getGainLossAccntId(integer) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAccntId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getGlAccntId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pGlAccnt ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getglaccntid(TEXT,TEXT,TEXT,TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCompany ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION getImageId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getImageId(pImageName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pImageName ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
- IF (COALESCE(TRIM(pImageName), '''') = '''') THEN
+ IF (COALESCE(TRIM(pImageName), '') = '') THEN
RETURN NULL;
END IF;
WHERE (image_name=pImageName);
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Image % not found.'', pImageName;
+ RAISE EXCEPTION 'Image % not found.', pImageName;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getIncdtCatId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getIncdtCatId(pIncdtCatName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pIncdtCatName ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
IF (pIncdtCatName IS NULL) THEN
-CREATE OR REPLACE FUNCTION getIncdtCrmAcctId(integer) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getIncdtCrmAcctId(pIncidentNumber integer) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pIncidentNumber ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
IF (pIncidentNumber IS NULL) THEN
WHERE (incdt_number=pIncidentNumber);
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Incident Number % not found.'', pIncidentNumber;
+ RAISE EXCEPTION 'Incident Number % not found.', pIncidentNumber;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getIncdtPriorityId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getIncdtPriorityId(pIncdtPriorityName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pIncdtPriorityName ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
IF (pIncdtPriorityName IS NULL) THEN
WHERE (incdtpriority_name=pIncdtPriorityName);
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Incident Priority Name % not found.'', pIncdtPriorityName;
+ RAISE EXCEPTION 'Incident Priority Name % not found.', pIncdtPriorityName;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getIncdtResolutionId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getIncdtResolutionId(pIncdtResolutionName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pIncdtResolutionName ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
IF (pIncdtResolutionName IS NULL) THEN
WHERE (incdtresolution_name=pIncdtResolutionName);
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Incident Resolution Name % not found.'', pIncdtResolutionName;
+ RAISE EXCEPTION 'Incident Resolution Name % not found.', pIncdtResolutionName;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getIncdtSeverityId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getIncdtSeverityId(pIncdtSeverityName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pIncdtSeverityName ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
IF (pIncdtSeverityName IS NULL) THEN
WHERE (incdtseverity_name=pIncdtSeverityName);
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Incident Severity Name % not found.'', pIncdtSeverityName;
+ RAISE EXCEPTION 'Incident Severity Name % not found.', pIncdtSeverityName;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getIncidentId(integer) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getIncidentId(pIncidentNumber integer) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pIncidentNumber ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
IF (pIncidentNumber IS NULL) THEN
WHERE (incdt_number=pIncidentNumber);
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Incident Number % not found.'', pIncidentNumber;
+ RAISE EXCEPTION 'Incident Number % not found.', pIncidentNumber;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getInvcheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getInvcitemLotSerial(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getIpsheadId(pIpsName TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
pQtyBreak NUMERIC,
pQtyUom TEXT,
pPriceUom TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
CREATE OR REPLACE FUNCTION getIpsProdcatId(pIpsName TEXT,
pProdCat TEXT,
pQtyBreak NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
CREATE OR REPLACE FUNCTION getItemId(text) RETURNS INTEGER IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getitemidfromupc(text)
RETURNS integer AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemUPC ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getItemsiteId(text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehouseCode ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getItemsiteId(text, text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehouseCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getItemSrcId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getItemTaxType(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getlasttrialbalid(INTEGER, INTEGER)
RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAccntId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getLocationId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehouse ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getLotSerialId(text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemNumber ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION getOpenShipment(pOrderType TEXT,
+ pOrderId INTEGER,
+ pWarehousId INTEGER) RETURNS TEXT AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _result TEXT := '';
+
+BEGIN
+
+ IF (pOrderType = 'SO') THEN
+ SELECT shiphead_number INTO _result
+ FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+ JOIN coitem ON (coitem_id=shipitem_orderitem_id)
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+ WHERE (shiphead_order_id=pOrderId)
+ AND (shiphead_order_type='SO')
+ AND (NOT shiphead_shipped)
+ AND (CASE WHEN (pWarehousId IS NULL) THEN TRUE
+ ELSE itemsite_warehous_id=pWarehousId END)
+ ORDER BY shiphead_number
+ LIMIT 1;
+ ELSEIF (pOrderType = 'TO') THEN
+ SELECT shiphead_number INTO _result
+ FROM shiphead JOIN tohead ON (tohead_id=shiphead_order_id)
+ WHERE (shiphead_order_id=pOrderId)
+ AND (shiphead_order_type='TO')
+ AND (NOT shiphead_shipped)
+ AND (CASE WHEN (pWarehousId IS NULL) THEN TRUE
+ ELSE tohead_src_warehous_id=pWarehousId END)
+ ORDER BY shiphead_number
+ LIMIT 1;
+ END IF;
+
+ RETURN _result;
+
+END;
+$$ LANGUAGE 'plpgsql' STABLE;
+
+CREATE OR REPLACE FUNCTION getOpenShipmentId(pOrderType TEXT,
+ pOrderId INTEGER,
+ pWarehousId INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _result INTEGER := -1;
+
+BEGIN
+
+ IF (pOrderType = 'SO') THEN
+ SELECT shiphead_id INTO _result
+ FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+ JOIN coitem ON (coitem_id=shipitem_orderitem_id)
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+ WHERE (shiphead_order_id=pOrderId)
+ AND (shiphead_order_type='SO')
+ AND (NOT shiphead_shipped)
+ AND (CASE WHEN (pWarehousId IS NULL) THEN TRUE
+ ELSE itemsite_warehous_id=pWarehousId END)
+ ORDER BY shiphead_number
+ LIMIT 1;
+ ELSEIF (pOrderType = 'TO') THEN
+ SELECT shiphead_id INTO _result
+ FROM shiphead JOIN tohead ON (tohead_id=shiphead_order_id)
+ WHERE (shiphead_order_id=pOrderId)
+ AND (shiphead_order_type='TO')
+ AND (NOT shiphead_shipped)
+ AND (CASE WHEN (pWarehousId IS NULL) THEN TRUE
+ ELSE tohead_src_warehous_id=pWarehousId END)
+ ORDER BY shiphead_number
+ LIMIT 1;
+ END IF;
+
+ RETURN _result;
+
+END;
+$$ LANGUAGE 'plpgsql' STABLE;
CREATE OR REPLACE FUNCTION getOpHeadId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOpHeadName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPacklistCharName(INTEGER, INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipheadId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPacklistCharValue(INTEGER, INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipheadId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPacklistItemLotSerial(INTEGER, INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipheadId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getperiodid(INTEGER, char) RETURNS SETOF INTEGER IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPeriodId(date)
RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPkgheadId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ppkgname ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPlanCodeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPlanCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPoheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPurchaseOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPoitemId(text,integer) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPurchaseOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getPrjAccntId(INTEGER, INTEGER) RETURNS INTEGER IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrjid ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION getPrjId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getPrjId(pPrjNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pPrjNumber ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
IF (pPrjNumber IS NULL) THEN
RETURN _returnVal;
END;
-$$ LANGUAGE 'plpgsql' STABLE;
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION getPrjTaskId(text, text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getPrjTaskId(pPrjNumber text,
+ pTaskNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pPrjNumber ALIAS FOR $1;
- pTaskNumber ALIAS FOR $2;
_returnVal INTEGER;
BEGIN
IF (pPrjNumber IS NULL OR pTaskNumber IS NULL) THEN
RETURN _returnVal;
END;
-$$ LANGUAGE 'plpgsql' STABLE;
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getProdCatId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pProdCat ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getProspectId(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pProspectNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getQuoteId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuoteNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getQuoteLineItemId(text,integer) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuoteNumber ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION getQuoteSchedDate(INTEGER) RETURNS DATE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ pQuheadid ALIAS FOR $1;
+ _minscheddate DATE;
+
+BEGIN
+
+ SELECT MIN(quitem_scheddate) INTO _minscheddate
+ FROM quitem
+ WHERE (quitem_quhead_id=pQuheadid);
+
+ RETURN _minscheddate;
+
+END;
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getRevId(text,text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getRsnId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pRsnCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getSalesCatId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSalesCatName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getSalesLineItemId(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSalesOrderItem ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getSalesLineItemId(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN getSalesLineItemId($1, $2, 0);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getSalesLineItemId(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSalesOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getSalesOrderId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSalesOrderNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getSalesRepId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSalesRepNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getSaleTypeId(pSaleType TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
CREATE OR REPLACE FUNCTION getShiftId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShiftNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getShipChrgId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipChrgName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getShipFormId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipFormName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getShipheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipmentNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getShiptoId(text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getShipToNumberFromInfo(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, BOOLEAN, BOOLEAN) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_custname TEXT := COALESCE(TRIM(UPPER( $1)), '');
CREATE OR REPLACE FUNCTION getShipViaId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipViaCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getShipZoneId(pShipZoneName TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
CREATE OR REPLACE FUNCTION getSiteTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSiteType ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION getSoitemStatus(pCoitemid INTEGER) RETURNS TEXT AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _result TEXT;
+
+BEGIN
+
+ SELECT
+ (CASE WHEN (coitem_status='O' AND (SELECT cust_creditstatus FROM custinfo WHERE cust_id=cohead_cust_id)='H') THEN 'H'
+ WHEN (coitem_status='O' AND ((SELECT SUM(invcitem_billed)
+ FROM invchead, invcitem
+ WHERE ((CAST(invchead_ordernumber AS text)=cohead_number)
+ AND (invcitem_invchead_id=invchead_id)
+ AND (invcitem_item_id=itemsite_item_id)
+ AND (invcitem_warehous_id=itemsite_warehous_id)
+ AND (invcitem_linenumber=coitem_linenumber))) >= coitem_qtyord)) THEN 'I'
+ WHEN (coitem_status='O' AND ((SELECT SUM(invcitem_billed)
+ FROM invchead, invcitem
+ WHERE ((CAST(invchead_ordernumber AS text)=cohead_number)
+ AND (invcitem_invchead_id=invchead_id)
+ AND (invcitem_item_id=itemsite_item_id)
+ AND (invcitem_warehous_id=itemsite_warehous_id)
+ AND (invcitem_linenumber=coitem_linenumber))) > 0)) THEN 'P'
+ WHEN (coitem_status='O' AND (itemsite_qtyonhand - qtyAllocated(itemsite_id, CURRENT_DATE)
+ + qtyOrdered(itemsite_id, CURRENT_DATE))
+ >= ((coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio)) THEN 'R'
+ ELSE coitem_status END
+ || CASE WHEN (coitem_firm) THEN 'F' ELSE '' END
+ ) INTO _result
+ FROM coitem JOIN cohead ON (cohead_id=coitem_cohead_id)
+ JOIN custinfo ON (cust_id=cohead_cust_id)
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+ WHERE (coitem_id=pCoitemid);
+
+ RETURN _result;
+
+END;
+$$ LANGUAGE 'plpgsql' STABLE;
CREATE OR REPLACE FUNCTION getSoSchedDate(INTEGER) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getSoStatus(INTEGER) RETURNS CHAR(1) AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getsubtax(integer, integer)
RETURNS SETOF subtax AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxCodeId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getTaxAuthId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxAuthCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getTaxId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getTaxTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getTaxZoneId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxZone ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getTermsId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTermsCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getUnassignedAccntId() RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_test INTEGER;
CREATE OR REPLACE FUNCTION getUomId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUom ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getUomTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUomType ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getUomTypeId(text[]) RETURNS INTEGER[] AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUomTypes ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION getUsrId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getUsrId(pUsr text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pUsr ALIAS FOR $1;
_returnVal INTEGER;
BEGIN
SELECT usr_id INTO _returnVal
CREATE OR REPLACE FUNCTION getUsrLocaleId() RETURNS INTEGER IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
CREATE OR REPLACE FUNCTION getVendAddrId(text, text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getVendId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION getVendTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendTypeCode ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION getWarehousId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION getWarehousId(pWarehousCode text,
+ pType text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pWarehousCode ALIAS FOR $1;
- pType ALIAS FOR $2;
_active BOOL;
_shipping BOOL;
_returnVal INTEGER;
RETURN NULL;
END IF;
- IF (UPPER(pType) NOT IN (''ALL'',''ACTIVE'',''SHIPPING'')) THEN
- RAISE EXCEPTION ''Warehouse lookip type % not valid. Valid types are ALL, ACTIVE and SHIPPING'', pType;
+ IF (UPPER(pType) NOT IN ('ALL','ACTIVE','SHIPPING')) THEN
+ RAISE EXCEPTION 'Warehouse lookip type % not valid. Valid types are ALL, ACTIVE and SHIPPING', pType;
END IF;
SELECT warehous_id, warehous_active, warehous_shipping INTO _returnVal, _active, _shipping
WHERE (warehous_code=UPPER(pWarehousCode));
IF (_returnVal IS NULL) THEN
- RAISE EXCEPTION ''Warehouse Code % not found.'', pWarehousCode;
- ELSE IF ((pType=''SHIPPING'') AND (_shipping=false)) THEN
- RAISE EXCEPTION ''Warehouse Code % is not a vaild shipping warehouse.'', pWarehousCode;
- ELSE IF ((pType IN (''SHIPPING'',''ACTIVE'')) AND (_active=false)) THEN
- RAISE EXCEPTION ''Warehouse Code % is inactive.'', pWarehousCode;
+ RAISE EXCEPTION 'Warehouse Code % not found.', pWarehousCode;
+ ELSE IF ((pType='SHIPPING') AND (_shipping=false)) THEN
+ RAISE EXCEPTION 'Warehouse Code % is not a vaild shipping warehouse.', pWarehousCode;
+ ELSE IF ((pType IN ('SHIPPING','ACTIVE')) AND (_active=false)) THEN
+ RAISE EXCEPTION 'Warehouse Code % is inactive.', pWarehousCode;
END IF;
END IF;
END IF;
RETURN _returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION getWhseZoneId(text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWhseCode ALIAS FOR $1;
CREATE OR REPLACE FUNCTION grantAllModuleCmnttypeSource(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmnttypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION grantAllModulePriv(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION grantAllModulePrivGroup(INTEGER, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pGrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION grantCmnttypeSource(INTEGER, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmnttypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION grantGroup(TEXT, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION grantPriv(TEXT, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION grantPriv(TEXT, TEXT) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION grantPrivGroup(INTEGER, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pGrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION hasAlarms() RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_alarm RECORD;
CREATE OR REPLACE FUNCTION hasEvents() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION hasMessages() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION hasPriv(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrivName ALIAS FOR $1;
pObjectType TEXT,
pObjectId INTEGER = NULL,
pUser TEXT = NULL) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_haspriv BOOLEAN := FALSE;
CREATE OR REPLACE FUNCTION implodeWo(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION incdt() RETURNS SETOF incdt AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row incdt%ROWTYPE;
CREATE OR REPLACE FUNCTION indentedBOM(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION indentedBOM(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION indentedBOM(INTEGER, INTEGER, INTEGER, INTEGER) RETURNS SETOF bomdata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION indentedWhereUsed(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
WHILE ( ( SELECT count(*)
FROM bomwork
- WHERE ((bomwork_item_type IN ('M', 'F'))
- AND (bomwork_status='U')
+ WHERE ((bomwork_status='U')
AND (bomwork_set_id=_indexid)) ) > 0) LOOP
_level := _level + 1;
AND (CURRENT_DATE BETWEEN bomitem_effective AND (bomitem_expires - 1))
AND (bomitem_rev_id=getActiveRevId('BOM',bomitem_parent_item_id)) )
JOIN item ON (item_id=bomitem_parent_item_id)
- WHERE ((bomwork_status='U')
- AND (bomwork_item_type IN ('M', 'F')));
+ WHERE (bomwork_status='U');
UPDATE bomwork
SET bomwork_status='C'
CREATE OR REPLACE FUNCTION indentedwo(integer, boolean, boolean, boolean) RETURNS SETOF wodata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pwoid ALIAS FOR $1;
SELECT wo_id,wo_number,wo_subnumber,wo_status,wo_startdate,
wo_duedate,wo_adhoc,wo_itemsite_id,itemsite_qtyonhand,
wo_qtyord,wo_qtyrcv,wo_prodnotes, item_number,
- item_descrip1, item_descrip2, uom_name
+ item_descrip1, item_descrip2, item_listprice, uom_name
FROM wo, itemsite, item, uom
WHERE ((wo_id = pwoid)
AND (itemsite_id = wo_itemsite_id)
_row.wodata_startdate := _x.wo_startdate;
_row.wodata_duedate := _x.wo_duedate;
_row.wodata_adhoc := _x.wo_adhoc;
- _row.wodata_itemsite_id := _x.wo_itemsite_id;
+ _row.wodata_itemsite_id := _x.wo_itemsite_id;
+ _row.wodata_custprice := _x.item_listprice;
+ _row.wodata_listprice := _x.item_listprice;
_row.wodata_qoh := _x.itemsite_qtyonhand;
_row.wodata_short := noneg(_x.wo_qtyord - _x.wo_qtyrcv);
_row.wodata_qtyrcv := _x.wo_qtyrcv;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION indentedwo(integer, integer, integer, boolean, boolean) RETURNS SETOF wodata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pwoid ALIAS FOR $1;
--find all WO with the ordid of the next level up
_qry := 'SELECT wo_id,wo_number,wo_subnumber,wo_status,wo_startdate,wo_duedate,
wo_adhoc,wo_itemsite_id,itemsite_qtyonhand,wo_qtyord,wo_qtyrcv, wo_prodnotes,
- item_number,item_descrip1, item_descrip2, uom_name,
+ item_number,item_descrip1, item_descrip2, item_listprice, uom_name,
womatl_qtyiss, womatl_scrap, womatl_wooper_id
FROM itemsite, wo, item, uom, womatl
WHERE ((wo_ordid = ' || pwoid || ')
_row.wodata_duedate := _x.wo_duedate;
_row.wodata_adhoc := _x.wo_adhoc;
_row.wodata_itemsite_id := _x.wo_itemsite_id;
+ _row.wodata_custprice := _x.item_listprice;
+ _row.wodata_listprice := _x.item_listprice;
_row.wodata_qoh := _x.itemsite_qtyonhand;
_row.wodata_short := noneg(_x.wo_qtyord - _x.wo_qtyrcv);
_row.wodata_qtyiss := _x.womatl_qtyiss;
CREATE OR REPLACE FUNCTION indentedwomatl(integer, integer) RETURNS SETOF wodata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pwoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION indentedwomatl(integer, integer, integer) RETURNS SETOF wodata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pwoid ALIAS FOR $1;
wo_startdate, womatl_duedate, womatl_itemsite_id,
itemsite_qtyonhand, womatl_qtyreq, womatl_qtyiss,
womatl_qtyper, womatl_qtyreq, womatl_scrap,
- womatl_ref, womatl_notes, item_number,
- item_descrip1, item_descrip2, uom_name
+ womatl_ref, womatl_notes, womatl_price, item_listprice,
+ item_number, item_descrip1, item_descrip2,
+ uom_name
FROM womatl, wo, itemsite, item, uom
WHERE ((wo_id = womatl_wo_id)
AND (wo_id = ' || pwoid || ')
_subrow.wodata_startdate := _subx.wo_startdate;
_subrow.wodata_duedate := _subx.womatl_duedate;
_subrow.wodata_itemsite_id := _subx.womatl_itemsite_id;
+ _subrow.wodata_custprice := _subx.womatl_price;
+ _subrow.wodata_listprice := _subx.item_listprice;
_subrow.wodata_qoh := _subx.itemsite_qtyonhand;
IF((_subx.itemsite_qtyonhand > (_subx.womatl_qtyreq - _subx.womatl_qtyiss))) THEN
_subrow.wodata_short := 0;
CREATE OR REPLACE FUNCTION initEffectiveXtUser() RETURNS VOID AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
-- Effective users use a temporary table to store the user information
CREATE OR REPLACE FUNCTION initialDistribution(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION insertIntoGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insertIntoGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, NUMERIC, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insertIntoGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, NUMERIC, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insertIntoGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, NUMERIC, DATE, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION insertccard(text,boolean,text,bytea,bytea,bytea,bytea,bytea,bytea,bytea,bytea,bytea,bytea,text) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustomer ALIAS FOR $1;
CREATE OR REPLACE FUNCTION insertFlGroup(INTEGER, INTEGER, INTEGER, INTEGER, BOOLEAN) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insertFlGroup(INTEGER, INTEGER, INTEGER, INTEGER, BOOLEAN, CHAR) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insertflgroup(INTEGER, INTEGER, INTEGER, INTEGER, BOOLEAN, CHAR, INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION insertGLTransaction(TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSource ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insertGLTransaction(TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSource ALIAS FOR $1;
CREATE OR REPLACE FUNCTION insertGLTransaction(INTEGER, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pJournalNumber ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insertGLTransaction(INTEGER, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pJournalNumber ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insertGLTransaction(INTEGER, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pJournalNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION insertItemCost(INTEGER, INTEGER, INTEGER, NUMERIC, BOOLEAN) RETURNS INTEGER AS $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION intervalToMinutes(INTERVAL) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT (EXTRACT(DAY FROM $1) * 24 * 60 +
EXTRACT(HOUR FROM $1) * 60 +
CREATE OR REPLACE FUNCTION invAdjustment(INTEGER, NUMERIC, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN invAdjustment($1, $2, $3, $4, CURRENT_TIMESTAMP, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION invAdjustment(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN invAdjustment($1, $2, $3, $4, $5, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION invAdjustment(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
DEFAULT CURRENT_TIMESTAMP,
pPrjid INTEGER DEFAULT NULL)
RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_invhistid INTEGER;
CREATE OR REPLACE FUNCTION invhistSense(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvhistId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION invoiceTotal(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvoiceId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION invReceipt(INTEGER, NUMERIC, TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN invReceipt($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION invReceipt(INTEGER, NUMERIC, TEXT, TEXT, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN invReceipt($1, $2, $3, $4, $5, $6, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION invReceipt(INTEGER, NUMERIC, TEXT, TEXT, TEXT, TIMESTAMP WITH TIME ZONE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION invScrap(INTEGER, NUMERIC, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN invScrap($1, $2, $3, $4, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION invScrap(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN invScrap($1, $2, $3, $4, $5, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION invScrap(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN invScrap($1, $2, $3, $4, $5, $6, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION invScrap(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION isMultiCurr() RETURNS BOOL IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN (SELECT (count(*) > 1)
CREATE OR REPLACE FUNCTION isNumeric(TEXT) RETURNS BOOLEAN IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pText ALIAS FOR $1;
CREATE OR REPLACE FUNCTION issueAllBalanceToShipping(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN issueAllBalanceToShipping('SO', $1, 0, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueAllBalanceToShipping(TEXT, INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
BEGIN
IF (pordertype = 'SO') THEN
FOR _s IN SELECT coitem_id,
- noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned -
- ( SELECT COALESCE(SUM(shipitem_qty), 0)
- FROM shipitem, shiphead
- WHERE ( (shipitem_orderitem_id=coitem_id)
- AND (shipitem_shiphead_id=shiphead_id)
- AND (NOT shiphead_shipped)
- AND (shiphead_order_type=pordertype) ) ) ) AS balance
+ CASE WHEN (fetchMetricBool('RequireSOReservations'))
+ THEN coitem_qtyreserved
+ ELSE noNeg( coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping('SO', coitem_id) )
+ END AS _balance
FROM coitem LEFT OUTER JOIN (itemsite JOIN item ON (itemsite_item_id=item_id)) ON (coitem_itemsite_id=itemsite_id)
WHERE ( (coitem_status NOT IN ('C','X'))
AND (item_type != 'K')
ELSEIF (pordertype = 'TO') THEN
FOR _s IN SELECT toitem_id,
- noNeg( toitem_qty_ordered - toitem_qty_shipped -
- ( SELECT COALESCE(SUM(shipitem_qty), 0)
- FROM shipitem, shiphead
- WHERE ( (shipitem_orderitem_id=toitem_id)
- AND (shipitem_shiphead_id=shiphead_id)
- AND (NOT shiphead_shipped)
- AND (shiphead_order_type=pordertype) ) ) ) AS balance
+ noNeg( toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id) )
+ AS balance
FROM toitem
WHERE ( (toitem_status NOT IN ('C','X'))
AND (toitem_tohead_id=pheadid) ) LOOP
CREATE OR REPLACE FUNCTION issueLineBalanceToShipping(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN issueLineBalanceToShipping('SO', $1, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueLineBalanceToShipping(TEXT, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN issueLineBalanceToShipping($1, $2, $3, 0, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueLineBalanceToShipping(TEXT, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
_itemlocSeries := COALESCE(pitemlocseries,0);
IF (pordertype = 'SO') THEN
- SELECT noNeg( coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned -
- ( SELECT COALESCE(SUM(shipitem_qty), 0)
- FROM shipitem, shiphead
- WHERE ((shipitem_orderitem_id=coitem_id)
- AND (shipitem_shiphead_id=shiphead_id)
- AND (NOT shiphead_shipped) ) ) ) INTO _qty
+ SELECT CASE WHEN (fetchMetricBool('RequireSOReservations'))
+ THEN coitem_qtyreserved
+ ELSE noNeg( coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping('SO', coitem_id) )
+ END INTO _qty
FROM coitem
WHERE (coitem_id=pitemid);
ELSEIF (pordertype = 'TO') THEN
- SELECT noNeg( toitem_qty_ordered - toitem_qty_shipped -
- ( SELECT COALESCE(SUM(shipitem_qty), 0)
- FROM shipitem, shiphead
- WHERE ( (shipitem_orderitem_id=toitem_id)
- AND (shipitem_shiphead_id=shiphead_id)
- AND (NOT shiphead_shipped) ) ) ) INTO _qty
+ SELECT noNeg( toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id) )
+ INTO _qty
FROM toitem
WHERE (toitem_id=pitemid);
ELSE
CREATE OR REPLACE FUNCTION issues(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTransType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION issueToShipping(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN issueToShipping('SO', $1, $2, 0, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueToShipping(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN issueToShipping('SO', $1, $2, $3, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueToShipping(TEXT, INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN issueToShipping($1, $2, $3, $4, $5, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueToShipping(TEXT, INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
END IF;
SELECT shiphead_id INTO _shipheadid
- FROM shiphead, coitem
- WHERE ((shiphead_order_id=coitem_cohead_id)
- AND (NOT shiphead_shipped)
- AND (coitem_id=pitemid)
- AND (shiphead_order_type=pordertype));
+ FROM shiphead, coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+ WHERE ( (coitem_id=pitemid)
+ AND (shiphead_number=getOpenShipment(pordertype, coitem_cohead_id, itemsite_warehous_id)) );
IF (NOT FOUND) THEN
SELECT NEXTVAL('shiphead_shiphead_id_seq') INTO _shipheadid;
AND (itemsite_costcat_id=costcat_id)
AND (toitem_id=pitemid) );
+ SELECT (invhist_unitcost * invhist_invqty) INTO _value
+ FROM invhist
+ WHERE (invhist_id=_invhistid);
+
SELECT shiphead_id INTO _shipheadid
- FROM shiphead, toitem
- WHERE ((shiphead_order_id=toitem_tohead_id)
- AND (NOT shiphead_shipped)
- AND (toitem_id=pitemid)
- AND (shiphead_order_type=pordertype));
+ FROM shiphead, toitem JOIN tohead ON (tohead_id=toitem_tohead_id)
+ WHERE ( (toitem_id=pitemid)
+ AND (shiphead_number=getOpenShipment(pordertype, tohead_id, tohead_src_warehous_id)) );
IF (NOT FOUND) THEN
_shipheadid := NEXTVAL('shiphead_shiphead_id_seq');
INSERT INTO shipitem
( shipitem_shiphead_id, shipitem_orderitem_id, shipitem_qty,
- shipitem_transdate, shipitem_trans_username, shipitem_value,
- shipitem_invhist_id )
- SELECT
- _shipheadid, pitemid, pQty,
- _timestamp, getEffectiveXtUser(), invhist_invqty * invhist_unitcost,
- _invhistid
- FROM toitem, item, invhist
- WHERE ((toitem_id=pitemid)
- AND (item_id=toitem_item_id)
- AND (invhist_id=_invhistid));
+ shipitem_transdate, shipitem_trans_username, shipitem_invoiced,
+ shipitem_value, shipitem_invhist_id )
+ VALUES
+ ( _shipheadid, pitemid, pQty,
+ _timestamp, getEffectiveXtUser(), FALSE,
+ _value,
+ CASE WHEN _invhistid = -1 THEN NULL
+ ELSE _invhistid
+ END
+ );
ELSE
RETURN -11;
CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER, BOOLEAN, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN issueWoMaterial($1, $2, $3, $4, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, BOOLEAN, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION issueWoMaterialBatch(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemAltCapInvRat(INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemAltCapUOM(INTEGER) RETURNS TEXT STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemCapInvRat(INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemCapUOM(INTEGER) RETURNS TEXT STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, NUMERIC) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, INTEGER, NUMERIC) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, INTEGER, NUMERIC, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, INTEGER, NUMERIC, INTEGER, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, INTEGER, NUMERIC, INTEGER, DATE, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemCharValue(INTEGER, TEXT) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemCost(INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemInventoryUOMInUse(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
-CREATE OR REPLACE FUNCTION itemInvPriceRat(INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION itemInvPriceRat(INTEGER) RETURNS NUMERIC STABLE AS '
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
pEffective DATE,
pAsOf DATE,
pSiteid INTEGER) RETURNS SETOF itemprice AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row itemprice%ROWTYPE;
_listprice NUMERIC := 0.0;
_qty NUMERIC;
_asof DATE;
+ _wholesalepricecosting BOOLEAN := false;
+ _long30markups BOOLEAN := false;
+ _itempricingprecedence BOOLEAN := false;
BEGIN
+ _wholesalepricecosting := fetchMetricBool('WholesalePriceCosting');
+ _long30markups := fetchMetricBool('Long30Markups');
+ _itempricingprecedence := fetchMetricBool('ItemPricingPrecedence');
+
-- Return the itemPrice in the currency passed in as pCurrid
_qty := itemuomtouom(pItemid, pQtyUOM, NULL, pQty);
_asof := COALESCE(pAsOf, CURRENT_DATE);
-- Cache Item, Customer and Shipto
- SELECT * INTO _item
- FROM item
+ SELECT item.*, itemCost(itemsite_id) AS invcost INTO _item
+ FROM item LEFT OUTER JOIN itemsite ON (itemsite_item_id=item_id AND itemsite_warehous_id=pSiteid)
WHERE (item_id=pItemid);
SELECT * INTO _cust
currToCurr(ipshead_curr_id, pCurrid, ipsprice_price, pEffective) AS rightprice, ipsitem_type AS righttype
FROM (
SELECT ipsitem_ipshead_id AS ipsprice_ipshead_id, ipsitem_type,
- CASE WHEN ipsitem_type = 'N' THEN (ipsitem_price * itemuomtouomratio(_item.item_id, pPriceUOM, ipsitem_price_uom_id))
- WHEN ipsitem_type = 'D' THEN noNeg(_item.item_listprice - (_item.item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount) * _iteminvpricerat
- WHEN ipsitem_type = 'M' THEN (_item.item_listcost + (_item.item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+ CASE WHEN (ipsitem_type = 'N') THEN
+ (ipsitem_price * itemuomtouomratio(_item.item_id, pPriceUOM, ipsitem_price_uom_id))
+ WHEN (ipsitem_type = 'D') THEN
+ noNeg(_item.item_listprice - (_item.item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount) * _iteminvpricerat
+ WHEN ((ipsitem_type = 'M') AND _long30markups AND _wholesalepricecosting) THEN
+ (_item.item_listcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+ WHEN ((ipsitem_type = 'M') AND _long30markups) THEN
+ (_item.invcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+ WHEN (ipsitem_type = 'M' AND _wholesalepricecosting) THEN
+ (_item.item_listcost + (_item.item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+ WHEN (ipsitem_type = 'M') THEN
+ (_item.invcost + (_item.invcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
ELSE 0.00
END AS ipsprice_price,
CASE WHEN (ipsitem_item_id=_item.item_id) THEN itemuomtouom(ipsitem_item_id, ipsitem_qty_uom_id, NULL, ipsitem_qtybreak)
ELSE ipsitem_qtybreak
END AS ipsprice_qtybreak,
- (ipsitem_price_uom_id=COALESCE(pPriceUOM,-1)) AS uommatched
+ (COALESCE(ipsitem_price_uom_id, -1)=COALESCE(pPriceUOM,-1)) AS uommatched,
+ CASE WHEN (_itempricingprecedence) THEN (COALESCE(ipsitem_item_id, -1)=_item.item_id)
+ ELSE true END AS itemmatched
FROM ipsiteminfo
WHERE(ipsitem_item_id=_item.item_id) OR (ipsitem_prodcat_id=_item.item_prodcat_id) ) AS
ipsprice, ipshead, ipsass, sale
OR (ipsass_custtype_id=_cust.cust_custtype_id)
OR ((COALESCE(LENGTH(ipsass_custtype_pattern), 0) > 0) AND (_cust.custtype_code ~ ipsass_custtype_pattern)) )
)
- ORDER BY uommatched DESC, ipsprice_qtybreak DESC, ipsprice_price ASC
+ ORDER BY itemmatched DESC, uommatched DESC, ipsprice_qtybreak DESC, ipsprice_price ASC
LIMIT 1;
-- Find the best Price Schedule Price
WHEN (COALESCE(LENGTH(ipsass_custtype_pattern), 0) > 0) THEN 5
ELSE 99
END AS assignseq,
- CASE WHEN ipsitem_type = 'N' THEN (ipsitem_price * itemuomtouomratio(_item.item_id, pPriceUOM, ipsitem_price_uom_id))
- WHEN ipsitem_type = 'D' THEN noNeg(_item.item_listprice - (_item.item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount) * _iteminvpricerat
- WHEN ipsitem_type = 'M' THEN (_item.item_listcost + (_item.item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+ CASE WHEN (ipsitem_type = 'N') THEN
+ (ipsitem_price * itemuomtouomratio(_item.item_id, pPriceUOM, ipsitem_price_uom_id))
+ WHEN (ipsitem_type = 'D') THEN
+ noNeg(_item.item_listprice - (_item.item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount) * _iteminvpricerat
+ WHEN ((ipsitem_type = 'M') AND _long30markups AND _wholesalepricecosting) THEN
+ (_item.item_listcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+ WHEN ((ipsitem_type = 'M') AND _long30markups) THEN
+ (_item.invcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+ WHEN (ipsitem_type = 'M' AND _wholesalepricecosting) THEN
+ (_item.item_listcost + (_item.item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+ WHEN (ipsitem_type = 'M') THEN
+ (_item.invcost + (_item.invcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
ELSE 0.00
END AS protoprice,
CASE WHEN (ipsitem_item_id=_item.item_id) THEN itemuomtouom(ipsitem_item_id, ipsitem_qty_uom_id, NULL, ipsitem_qtybreak)
ELSE ipsitem_qtybreak
END AS protoqtybreak,
- (COALESCE(ipsitem_price_uom_id, -1)=COALESCE(pPriceUOM, -1)) AS uommatched
+ (COALESCE(ipsitem_price_uom_id, -1)=COALESCE(pPriceUOM,-1)) AS uommatched,
+ CASE WHEN (_itempricingprecedence) THEN (COALESCE(ipsitem_item_id, -1)=_item.item_id)
+ ELSE true END AS itemmatched
FROM ipsass JOIN ipshead ON (ipshead_id=ipsass_ipshead_id)
JOIN ipsiteminfo ON (ipsitem_ipshead_id=ipshead_id)
WHERE ((ipsitem_item_id=_item.item_id) OR (ipsitem_prodcat_id=_item.item_prodcat_id))
)
) AS proto
WHERE (protoqtybreak <= pQty)
- ORDER BY assignseq, protoqtybreak DESC, rightprice
+ ORDER BY assignseq, itemmatched DESC, protoqtybreak DESC, rightprice
LIMIT 1;
IF (_ips.rightprice IS NOT NULL) THEN
CREATE OR REPLACE FUNCTION itemlocdistQty(TEXT, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTypes ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemlocdistQty(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocationid ALIAS FOR $1;
pQty NUMERIC,
pCurrid INTEGER,
pEffective DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_item RECORD;
pPriceUOM INTEGER,
pCurrid INTEGER,
pEffective DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCurrid INTEGER,
pEffective DATE,
pAsOf DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pEffective DATE,
pAsOf DATE,
pSiteid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_r RECORD;
CREATE OR REPLACE FUNCTION itemSellingUOM(INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
pQty NUMERIC,
pCurrid INTEGER,
pEffective DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_price NUMERIC := 0.0;
pQty NUMERIC,
pCurrid INTEGER,
pEffective DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_price NUMERIC := 0.0;
CREATE OR REPLACE FUNCTION itemUOMByType(INTEGER, TEXT) RETURNS TEXT STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemUOMFractionalByType(INTEGER, TEXT) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemUOMFractionalByUOM(INTEGER, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemUOMRatioByType(INTEGER, TEXT) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION itemuomtouom(INTEGER, INTEGER, INTEGER, NUMERIC) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN itemuomtouom($1, $2, $3, $4, 'qty');
pUomidTo INTEGER,
pQtyFrom NUMERIC,
pLocale TEXT) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_uomidFrom INTEGER;
CREATE OR REPLACE FUNCTION itemuomtouomratio(pItemid INTEGER,
pUomidFrom INTEGER,
pUomidTo INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_uomidFrom INTEGER;
-
CREATE OR REPLACE FUNCTION public.login() RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_p RECORD;
END;
$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION public.login(boolean) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+
+CREATE OR REPLACE FUNCTION login(boolean)
+ RETURNS integer AS
+$BODY$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_setSearchPath ALIAS FOR $1;
_p RECORD;
BEGIN
-
- PERFORM pg_try_advisory_lock(datid::integer, procpid)
+ -- added support for PostgreSQL 9.2.0, Incident 21852
+ IF (compareversion('9.2.0') <= 0)
+ THEN
+ PERFORM pg_try_advisory_lock(datid::integer, pid)
+ FROM pg_stat_activity
+ WHERE(pid = pg_backend_pid());
+ ELSE
+ PERFORM pg_try_advisory_lock(datid::integer, procpid)
FROM pg_stat_activity
WHERE(procpid = pg_backend_pid());
+ END IF;
-- This is new to version 9.0 and higher and will error on older versions
- IF (select CAST(split_part(split_part(version(), ' ', 2),'.',1) AS integer) >= 9) THEN
+ IF (compareversion('9.0.0') <= 0) THEN
SET bytea_output TO escape;
END IF;
RETURN 1;
END;
-$$ LANGUAGE 'plpgsql';
-
+$BODY$
+ LANGUAGE plpgsql VOLATILE
+ COST 100;
+ALTER FUNCTION login(boolean)
+ OWNER TO admin;
CREATE OR REPLACE FUNCTION logout() RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
PERFORM pg_advisory_unlock(datid::integer, procpid)
CREATE OR REPLACE FUNCTION lowerCost(INTEGER, TEXT) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION lowerCost(INTEGER, TEXT, BOOLEAN) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION maintainBOMWorkspace() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_test TEXT;
CREATE OR REPLACE FUNCTION markAPCheckASPosted(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''markAPCheckAsPosted() is deprecated - use markCheckAsPosted() instead'';
CREATE OR REPLACE FUNCTION markAPCheckAsPrinted(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''markAPCheckAsPrinted() is deprecated - use markCheckAsPrinted()'';
CREATE OR REPLACE FUNCTION markCheckASPosted(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCheckid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION markCheckAsPrinted(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCheckid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION massExpireBomitem(INTEGER, DATE, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION massReplaceBomitem(INTEGER, INTEGER, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNewItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION merge2crmaccts(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSourceId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION mergecrmaccts(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTargetId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveBomitemDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBomitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveBomitemUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBomitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveccarddown(int4)
RETURNS int4 AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCcardid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveccardup(int4)
RETURNS int4 AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCcardid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveFlGroupDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlgrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveFlGroupUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlgrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveFlItemDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveFlItemUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveFlSpecDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlspecid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveFlSpecUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pFlspecid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveScript(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pscriptid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION moveUiform(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
puiformid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION nextPeriodByInterval(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION nextPrSubnumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION nextWoSubnumber(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT COALESCE((MAX(wo_subnumber) + 1), 1)
FROM wo
CREATE OR REPLACE FUNCTION noNeg(NUMERIC) RETURNS NUMERIC IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pValue ALIAS FOR $1;
CREATE OR REPLACE FUNCTION noPos(NUMERIC) RETURNS NUMERIC IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pValue ALIAS FOR $1;
CREATE OR REPLACE FUNCTION normalizeTrialBal(INTEGER, CHARACTER(1)) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTrialbalid ALIAS FOR $1;
-
CREATE OR REPLACE FUNCTION numOfDatabaseUsers() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_count INTEGER;
BEGIN
+ -- in version 9.2.0 the column "procpid" was changed to just "pid" Incident #21852
+ IF (compareversion('9.2.0') <= 0)
+ THEN
+ SELECT count(*)
+ INTO _count
+ FROM pg_stat_activity, pg_locks
+ WHERE((database=datid)
+ AND (classid=datid)
+ AND (objsubid=2)
+ AND (pg_stat_activity.pid = pg_backend_pid()));
+ ELSE
SELECT count(*)
INTO _count
FROM pg_stat_activity, pg_locks
AND (classid=datid)
AND (objsubid=2)
AND (procpid = pg_backend_pid()));
+ END IF;
+
IF (_count IS NULL) THEN
_count := 0;
END IF;
END;
$$ LANGUAGE 'plpgsql';
-
CREATE OR REPLACE FUNCTION numOfServerUsers() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_count INTEGER;
CREATE OR REPLACE FUNCTION openAccountingPeriod(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION openAccountingYearPeriod(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pYearPeriodId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION openAPItemsValue(pVendid INTEGER,
pPeriodid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_value NUMERIC;
CREATE OR REPLACE FUNCTION openARItemsValue(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION openRecurringItems(INTEGER, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pParentid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION ophead() RETURNS SETOF ophead AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row ophead%ROWTYPE;
CREATE OR REPLACE FUNCTION orderedByPo(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION orderedByPo(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION orderedByWo(INTEGER, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION orderedByWo(INTEGER, DATE, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION orderhead() RETURNS SETOF ordhead AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row ordhead%ROWTYPE;
CREATE OR REPLACE FUNCTION orderitem() RETURNS SETOF orditem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row orditem%ROWTYPE;
CREATE OR REPLACE FUNCTION orderitemData(TEXT, INTEGER, INTEGER) RETURNS SETOF orderitemtype
AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrdertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION packageIsEnabled(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT COUNT(*) >= 8
FROM pg_inherits, pg_class, pg_namespace, pkghead
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION packageIsEnabled(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT COUNT(*) >= 8
FROM pg_inherits, pg_class, pg_namespace
CREATE OR REPLACE FUNCTION pkgMayBeModified(NAME) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pschemaname ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''postAPCheck() is deprecated - use postCheck() instead'';
CREATE OR REPLACE FUNCTION postAPCheck(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''postAPCheck() is deprecated - use postCheck() instead'';
CREATE OR REPLACE FUNCTION postAPChecks(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION postAPCreditMemoApplication(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
END IF;
END IF;
- IF (_src.apopen_accnt_id > -1) THEN
- _apaccntid := _src.apopen_accnt_id;
- ELSE
+-- do not post gain/loss to alternate prepaid
+-- IF (_src.apopen_accnt_id > -1) THEN
+-- _apaccntid := _src.apopen_accnt_id;
+-- ELSE
_apaccntid := findAPAccount(_src.apopen_vend_id);
- END IF;
+-- END IF;
PERFORM insertGLTransaction(fetchJournalNumber('AP-MISC'), 'A/P', 'CM',
_src.apopen_docnumber, 'CM Application',
CREATE OR REPLACE FUNCTION postApopenItems() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION postARCreditMemoApplication(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAropenid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postARCreditMemoApplication(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAropenid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postAropenItems() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION postBankAdjustment(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankadjid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postBankReconciliation(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankrecid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postbillingselection(integer)
RETURNS integer AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobmiscid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postbillingselectionconsolidated(integer)
RETURNS integer AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postBillingSelections() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postBillingSelections(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE 'postBillingselections(int) has been deprecated. Please use createInvoices(int).';
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postBillingSelections(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCustTypeId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCashReceipt(pCashrcptid INTEGER,
pJournalNumber INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_ccpayid INTEGER;
CREATE OR REPLACE FUNCTION postCashReceiptDisc(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCashrcptItemId ALIAS FOR $1;
pdoctype TEXT DEFAULT NULL,
pamount NUMERIC DEFAULT NULL) RETURNS INTEGER AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_aropenid INTEGER;
CREATE OR REPLACE FUNCTION postCCcredit(INTEGER, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCCpay ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCCVoid(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pccpayid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCheck(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pcheckid ALIAS FOR $1;
ELSE
FOR _r IN SELECT checkitem_amount, checkitem_discount,
- CASE WHEN (checkitem_apopen_id IS NOT NULL) THEN
- checkitem_amount / apopen_curr_rate
- ELSE
- currToBase(checkitem_curr_id,
- checkitem_amount,
- COALESCE(checkitem_docdate, _p.checkhead_checkdate))
+ CASE WHEN (checkitem_apopen_id IS NOT NULL AND apopen_doctype='C') THEN
+ checkitem_amount / apopen_curr_rate * -1.0
+ WHEN (checkitem_apopen_id IS NOT NULL) THEN
+ checkitem_amount / apopen_curr_rate
+ ELSE
+ currToBase(checkitem_curr_id,
+ checkitem_amount,
+ COALESCE(checkitem_docdate, _p.checkhead_checkdate))
END AS checkitem_amount_base,
currTocurr(checkitem_curr_id, _p.checkhead_curr_id,
- checkitem_amount,
+ CASE WHEN (checkitem_apopen_id IS NOT NULL AND apopen_doctype='C') THEN
+ checkitem_amount * -1.0
+ ELSE checkitem_amount END,
_p.checkhead_checkdate) AS amount_check,
apopen_id, apopen_doctype, apopen_docnumber,
aropen_id, aropen_doctype, aropen_docnumber,
_exchGain := _exchGain + _exchGainTmp;
PERFORM insertIntoGLSeries( _sequence, _t.checkrecip_gltrans_source,
- 'CK', CAST(_p.checkhead_number AS TEXT),
+ 'CK', CAST(_p.checkhead_number AS TEXT),
_t.checkrecip_accnt_id,
- round(_r.checkitem_amount_base, 2) * -1,
+ round(_r.checkitem_amount_base, 2) * -1.0,
_p.checkhead_checkdate, _gltransNote, pcheckid );
IF (_exchGainTmp <> 0) THEN
PERFORM insertIntoGLSeries( _sequence, _t.checkrecip_gltrans_source,
- 'CK', CAST(_p.checkhead_number AS TEXT),
- getGainLossAccntId(_t.checkrecip_accnt_id), round(_exchGainTmp,2),
- _p.checkhead_checkdate, _gltransNote, pcheckid );
+ 'CK', CAST(_p.checkhead_number AS TEXT),
+ getGainLossAccntId(_t.checkrecip_accnt_id),
+ round(_exchGainTmp,2),
+ _p.checkhead_checkdate, _gltransNote, pcheckid );
END IF;
_amount_check := (_amount_check + _r.amount_check);
CREATE OR REPLACE FUNCTION postChecks(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankaccntid ALIAS FOR $1;
pSource TEXT,
pSourceid INTEGER,
pText TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_cmnttypeid INTEGER;
pSource TEXT,
pSourceid INTEGER,
pText TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSourceid INTEGER,
pText TEXT,
pPublic BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_commentid INTEGER;
CREATE OR REPLACE FUNCTION postCost(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemcostid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCountSlip(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCntslipid ALIAS FOR $1;
SELECT dropIfExists('FUNCTION', 'postCountTag(integer, boolean, text)', 'public');
CREATE OR REPLACE FUNCTION postCountTag(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCountTagLocation(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCountTags(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCreditMemo(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCreditMemo(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postCreditMemos(BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPostUnprinted ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postCreditMemos(BOOLEAN, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPostUnprinted ALIAS FOR $1;
--- /dev/null
+
+CREATE OR REPLACE FUNCTION postEvent(pEvnttypename TEXT,
+ pOrdtype TEXT,
+ pOrdid INTEGER,
+ pWhsid INTEGER,
+ pNumber TEXT,
+ pNewValue NUMERIC,
+ pOldValue NUMERIC,
+ pNewDate DATE,
+ pOldDate DATE) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ _evnttypeid INTEGER;
+ _whsid INTEGER;
+
+BEGIN
+ -- Find event type
+ SELECT evnttype_id INTO _evnttypeid
+ FROM evnttype
+ WHERE (evnttype_name=pEvnttypename);
+ IF (NOT FOUND) THEN
+ RAISE EXCEPTION 'Event type % not found.', pEvnttypename;
+ END IF;
+
+ IF (pWhsid IS NULL) THEN
+ -- Find user preferred warehouse
+ SELECT usrpref_value INTO _whsid
+ FROM usrpref
+ WHERE usrpref_username = getEffectiveXtUser()
+ AND usrpref_name = 'PreferredWarehouse';
+ ELSE
+ _whsid := pWhsid;
+ END IF;
+
+ INSERT INTO evntlog ( evntlog_evnttime, evntlog_evnttype_id,
+ evntlog_ordtype, evntlog_ord_id,
+ evntlog_warehous_id, evntlog_number,
+ evntlog_newvalue, evntlog_oldvalue,
+ evntlog_newdate, evntlog_olddate,
+ evntlog_username )
+ SELECT CURRENT_TIMESTAMP, evnttype_id,
+ pOrdtype, pOrdid,
+ _whsid, pNumber,
+ pNewValue, pOldValue,
+ pNewDate, pOldDate,
+ evntnot_username
+ FROM evnttype JOIN evntnot ON ( (evntnot_evnttype_id=evnttype_id) AND
+ (evntnot_warehous_id=_whsid) )
+ WHERE (evnttype_id=_evnttypeid);
+
+ RETURN 0;
+
+END
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postGLSeries(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postGLSeries(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postGLSeries(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postGLSeriesNoSumm(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postGLSeriesNoSumm(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postIntoInvBalance(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvhistId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postIntoTrialBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postInvHist( INTEGER ) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvhistId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postInvoice(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postInvoice(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcheadid ALIAS FOR $1;
_totalAmount := _totalAmount - currToCurr(_tmpCurrId, _p.invchead_curr_id,
_appliedAmount, _firstExchDate);
END IF;
+
+ -- delete the allocation
+ DELETE FROM aropenalloc
+ WHERE (aropenalloc_doctype='I')
+ AND (aropenalloc_doc_id=_p.invchead_id);
+
END IF;
END LOOP;
END IF;
CREATE OR REPLACE FUNCTION postInvoices(BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPostUnprinted ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postInvoices(BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPostUnprinted ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postInvoices(BOOLEAN, BOOLEAN, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPostUnprinted ALIAS FOR $1;
pCostOvrld NUMERIC DEFAULT NULL,
pInvhistid INTEGER DEFAULT NULL)
RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-- pInvhistid is the original transaction to be returned, reversed, etc.
DECLARE
CREATE OR REPLACE FUNCTION postItemlocSeries(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemlocseries ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postJournals(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postJournals(TEXT[], DATE, DATE, DATE) RETURNS SETOF INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSources ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postJournals(TEXT, DATE, DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSource ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postMessage(TIMESTAMP, TIMESTAMP, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pScheduled ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postMessage(TIMESTAMP, TIMESTAMP, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pScheduled ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postMessage(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postMiscCount(pItemsiteid INTEGER,
pQty NUMERIC,
pComments TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postPoGLTransactions() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION postPoReceipt(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN postReceipt($1, $2);
CREATE OR REPLACE FUNCTION postPoReceipts(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN postReceipts(''PO'', $1, NULL);
CREATE OR REPLACE FUNCTION postPoReturnCreditMemo(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPorejectId ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postPoReturnCreditMemo(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPorejectId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postPoReturns(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPoheadid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postPoReturns(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE 'postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN) is deprecated. please use postProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) instead';
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE 'postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER) is deprecated. please use postProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) instead';
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE 'postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER, TEXT, TEXT) is deprecated. please use postProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) instead';
WHERE (poitem_id=_o.orderitem_id);
ELSEIF ( (_r.recv_order_type = 'RA') AND
- (_r.itemsite_id = -1 OR _r.itemsite_id IS NULL OR _r.itemsite_controlmethod = 'N') ) THEN
+ (_r.itemsite_id = -1 OR _r.itemsite_id IS NULL) ) THEN
RAISE NOTICE 'itemsite controlmethod is %, cannot post receipt.', _r.itemsite_controlmethod;
RETURN -14; -- otherwise how do we get the accounts?
FROM rahead, raitem
WHERE ((rahead_id=raitem_rahead_id)
AND (raitem_id=_r.recv_orderitem_id));
- SELECT postInvTrans(_r.itemsite_id, 'RR',
- _recvinvqty,
- 'S/R',
- _r.recv_order_type, _ra.rahead_number::TEXT || '-' || _ra.raitem_linenumber::TEXT,
- '',
- 'Receive Inventory from ' || _ordertypeabbr,
- costcat_asset_accnt_id,
- CASE WHEN(COALESCE(_ra.raitem_cos_accnt_id, -1) != -1) THEN
- getPrjAccntId(_o.prj_id, _ra.raitem_cos_accnt_id)
- WHEN (_ra.raitem_warranty) THEN
- getPrjAccntId(_o.prj_id, resolveCOWAccount(_r.itemsite_id, _ra.rahead_cust_id, _ra.rahead_saletype_id, _ra.rahead_shipzone_id))
- ELSE getPrjAccntId(_o.prj_id, resolveCORAccount(_r.itemsite_id, _ra.rahead_cust_id, _ra.rahead_saletype_id, _ra.rahead_shipzone_id))
- END,
- _itemlocSeries, _glDate, COALESCE(_o.unitcost,stdcost(itemsite_item_id)) * _recvinvqty) INTO _tmp
- FROM itemsite, costcat
- WHERE ( (itemsite_costcat_id=costcat_id)
- AND (itemsite_id=_r.itemsite_id) );
- IF (NOT FOUND) THEN
- RAISE EXCEPTION 'Could not post inventory transaction: no cost category found for itemsite_id %', _r.itemsite_id;
- ELSIF (_tmp < -1) THEN -- less than -1 because -1 means it is a none controlled item
- IF(_tmp = -3) THEN
- RAISE NOTICE 'The GL trans value was 0 which means we likely do not have a std cost';
- RETURN -12; -- The GL trans value was 0 which means we likely do not have a std cost
- END IF;
- RETURN _tmp;
+ IF (_r.itemsite_controlmethod = 'N') THEN
+ SELECT insertGLTransaction( fetchJournalNumber('GL-MISC'),
+ 'S/R', _r.recv_order_type, _o.orderhead_number,
+ 'Receive Non-Controlled Inventory from ' || _ordertypeabbr,
+ costcat_liability_accnt_id,
+ getPrjAccntId(_o.prj_id, costcat_exp_accnt_id), -1,
+ round((_o.item_unitprice_base * _r.recv_qty),2),
+ _glDate::DATE, false ) INTO _tmp
+ FROM itemsite JOIN costcat ON (costcat_id=itemsite_costcat_id)
+ WHERE(itemsite_id=_r.itemsite_id);
+ IF (NOT FOUND) THEN
+ RAISE EXCEPTION 'Could not post inventory transaction: no cost category found for itemsite_id %', _r.itemsite_id;
+-- ELSIF (_tmp < -1) THEN
+-- RETURN _tmp;
+ END IF;
+ ELSE
+ SELECT postInvTrans(_r.itemsite_id, 'RR',
+ _recvinvqty,
+ 'S/R',
+ _r.recv_order_type, _ra.rahead_number::TEXT || '-' || _ra.raitem_linenumber::TEXT,
+ '',
+ 'Receive Inventory from ' || _ordertypeabbr,
+ costcat_asset_accnt_id,
+ CASE WHEN(COALESCE(_ra.raitem_cos_accnt_id, -1) != -1) THEN
+ getPrjAccntId(_o.prj_id, _ra.raitem_cos_accnt_id)
+ WHEN (_ra.raitem_warranty) THEN
+ getPrjAccntId(_o.prj_id, resolveCOWAccount(_r.itemsite_id, _ra.rahead_cust_id, _ra.rahead_saletype_id, _ra.rahead_shipzone_id))
+ ELSE
+ getPrjAccntId(_o.prj_id, resolveCORAccount(_r.itemsite_id, _ra.rahead_cust_id, _ra.rahead_saletype_id, _ra.rahead_shipzone_id))
+ END,
+ _itemlocSeries, _glDate, COALESCE(_o.unitcost,stdcost(itemsite_item_id)) * _recvinvqty) INTO _tmp
+ FROM itemsite, costcat
+ WHERE ( (itemsite_costcat_id=costcat_id)
+ AND (itemsite_id=_r.itemsite_id) );
+
+ IF (NOT FOUND) THEN
+ RAISE EXCEPTION 'Could not post inventory transaction: no cost category found for itemsite_id %', _r.itemsite_id;
+ ELSIF (_tmp < -1) THEN -- less than -1 because -1 means it is a none controlled item
+ IF(_tmp = -3) THEN
+ RAISE NOTICE 'The GL trans value was 0 which means we likely do not have a std cost';
+ RETURN -12; -- The GL trans value was 0 which means we likely do not have a std cost
+ END IF;
+ RETURN _tmp;
+ END IF;
END IF;
INSERT INTO rahist (rahist_itemsite_id, rahist_date,
IF (_o.pohead_dropship = TRUE) THEN
-- Generate the PoItemDropShipped event
- INSERT INTO evntlog
- ( evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
- evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id,
- evntlog_number )
- SELECT
- CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
- 'P', _o.orderitem_id, evntnot_warehous_id,
- (pohead_number || '-' || poitem_linenumber || ': ' || item_number)
- FROM evntnot JOIN evnttype ON (evntnot_evnttype_id = evnttype_id)
- JOIN itemsite ON (evntnot_warehous_id = itemsite_warehous_id)
- JOIN item ON (itemsite_item_id = item_id)
- JOIN poitem ON (poitem_itemsite_id = itemsite_id)
- JOIN pohead ON (poitem_pohead_id = pohead_id)
- WHERE( (poitem_id = _o.orderitem_id)
- AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence))
- AND (evnttype_name = 'PoItemDropShipped') );
+ PERFORM postEvent('PoItemDropShipped', 'P', poitem_id,
+ itemsite_warehous_id,
+ (pohead_number || '-' || poitem_linenumber || ': ' || item_number),
+ NULL, NULL, NULL, NULL)
+ FROM poitem JOIN itemsite ON (itemsite_id=poitem_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ JOIN pohead ON (pohead_id=poitem_pohead_id)
+ WHERE (poitem_id=_o.orderitem_id)
+ AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence));
END IF;
END IF;
CREATE OR REPLACE FUNCTION postReceipts(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postSoGLTransactions() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
CREATE OR REPLACE FUNCTION postSoItemProduction(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoitemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postSoItemProduction(INTEGER, NUMERIC, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoitemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postStandardJournal(INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStdjrnlid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postStandardJournal(INTEGER, DATE, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStdjrnlid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postStandardJournal(INTEGER, DATE, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStdjrnlid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postStandardJournal(INTEGER, DATE, BOOLEAN, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStdjrnlid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postStandardJournalGroup(INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStdjrnlgrpid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION postStandardJournalGroup(INTEGER, DATE, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStdjrnlgrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postValueintoInvBalance(INTEGER, DATE, NUMERIC, NUMERIC, NUMERIC, NUMERIC) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postVoucher(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postVoucher(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION postVouchers(BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPostCosts ALIAS FOR $1;
CREATE OR REPLACE FUNCTION primaryKeyFields(TEXT, TEXT) RETURNS TEXT[] AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSchema ALIAS FOR $1;
CREATE OR REPLACE FUNCTION prj() RETURNS SETOF prj AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row prj%ROWTYPE;
CREATE OR REPLACE FUNCTION prjtask() RETURNS SETOF prjtask AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row prjtask%ROWTYPE;
CREATE OR REPLACE FUNCTION purgeCreditMemos(DATE) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCutoffDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION purgecrmacctmerge(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pDestid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION purgeInvoiceRecord(DATE, INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCutoffDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION purgeInvoiceRecords(DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCutoffDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION purgePostedCountSlips(DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCutoffDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION purgePostedCountTags(DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCutoffDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION purgeShipments(DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pcutoff ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyAllocated(INTEGER, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyAllocated(INTEGER, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyAllocated(INTEGER, DATE, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyAtShipping(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN qtyAtShipping('SO', $1);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION qtyAtShipping(TEXT, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN qtyAtShipping($1, $2, 'U');
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION qtyAtShipping(TEXT, INTEGER, TEXT) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyAvailable(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyAvailable(INTEGER, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyInShipment(TEXT, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
SELECT dropIfExists('FUNCTION','qtyLocation(INTEGER, INTEGER, DATE, DATE, INTEGER, TEXT, INTEGER)');
CREATE OR REPLACE FUNCTION qtyLocation(INTEGER, INTEGER, DATE, DATE, INTEGER, TEXT, INTEGER, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocationId ALIAS FOR $1;
AND (COALESCE(ls.itemlocdist_warranty, endoftime())=COALESCE(pWarranty, ls.itemlocdist_warranty, endoftime()))
AND (ls.itemlocdist_id != pItemlocdistId ) );
--- Summarize itemlocrsrv qty for this location/itemsite
+-- Summarize reserved qty for this location/itemsite
-- that is reserved for a different order
IF (fetchMetricBool('EnableSOReservationsByLocation')) THEN
- SELECT COALESCE(SUM(itemlocrsrv_qty), 0) INTO _qtyReserved
- FROM itemloc JOIN itemlocrsrv ON ( (itemlocrsrv_itemloc_id=itemloc_id)
- AND ((itemlocrsrv_source <> COALESCE(pOrderType, '')) OR
- (itemlocrsrv_source_id <> COALESCE(pOrderId, -1))) )
+ SELECT COALESCE(SUM(reserve_qty), 0) INTO _qtyReserved
+ FROM itemloc JOIN reserve ON ( (reserve_supply_id=itemloc_id AND reserve_supply_type='I')
+ AND ((reserve_demand_type <> COALESCE(pOrderType, '')) OR
+ (reserve_demand_id <> COALESCE(pOrderId, -1))) )
WHERE ( (itemloc_itemsite_id=pItemsiteId)
AND (itemloc_location_id=pLocationId)
AND (COALESCE(itemloc_ls_id, -1)=COALESCE(pLsId, itemloc_ls_id, -1))
CREATE OR REPLACE FUNCTION qtyOrdered(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyOrdered(INTEGER, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtyOrdered(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION qtypr(integer, integer) RETURNS numeric AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION qtypr(integer, date) RETURNS numeric AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION qtypr(integer, date, date) RETURNS numeric AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION qtyReserved(INTEGER) RETURNS NUMERIC AS '
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/EULA for the full text of the software license.
+DECLARE
+ pItemsiteid ALIAS FOR $1;
+ _qty NUMERIC;
+
+BEGIN
+
+ SELECT COALESCE(SUM(coitem_qtyreserved),0) INTO _qty
+ FROM coitem
+ WHERE(coitem_itemsite_id=pItemsiteid);
+
+ RETURN _qty;
+END;
+' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION qtyToReceive(TEXT, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION recallShipment(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN recallShipment($1, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION recallShipment(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pshipheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION recallWo(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION receipts(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTransType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION releaseAPMemoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('APMemoNumber', $1::INTEGER) > 0;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releaseARMemoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
select releaseNumber('ARMemoNumber', $1::INTEGER) > 0;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releaseCashRcptNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('CashRcptNumber', $1) > 0;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releaseCMNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('CmNumber', $1) > 0;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION releaseCMNumber(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('CmNumber', $1::INTEGER) > 0;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION releaseCRMAccountNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('CRMAccountNumber', $1::INTEGER) > 0;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION releaseIncidentNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('IncidentNumber', $1) = 1;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION releaseInvcNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('InvcNumber', $1) > 0;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION releaseInvcNumber(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('InvcNumber', $1::INTEGER) > 0;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION releaseNumber(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
psequence ALIAS FOR $1;
pnumber ALIAS FOR $2;
BEGIN
- -- drop the number back into the pool if it was not committed
- PERFORM clearNumberIssue(psequence, pnumber);
+ IF (fetchMetricBool('EnableGaplessNumbering')) THEN
+ -- drop the number back into the pool if it was not committed
+ PERFORM clearNumberIssue(psequence, pnumber);
+ END IF;
UPDATE orderseq SET
orderseq_number = LEAST(pnumber, orderseq_number)
CREATE OR REPLACE FUNCTION releasePoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('PoNumber', $1) > 0;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releasePoNumber(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('PoNumber', $1::INTEGER) > 0;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releasePrNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('PrNumber', $1) > 0;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releasePurchaseOrder(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION releaseQuNumber(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('QuNumber', $1);
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releaseQuNumber(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('QuNumber', $1::INTEGER);
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releaseShipmentNumber(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION releaseSohead(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION releaseSoNumber(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('SoNumber', $1);
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releaseSoNumber(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
IF (COALESCE($1, '') = '' OR $1 ~ '[^0-9]')
CREATE OR REPLACE FUNCTION releaseUnusedBillingHeader(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCobmiscid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION releaseVoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('VcNumber', $1) > 0;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION releaseWo(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION releaseWoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT releaseNumber('WoNumber', $1) > 0;
$$ LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION relocateInventory(INTEGER, INTEGER, INTEGER, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN relocateInventory($1, $2, $3, $4, $5, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION relocateInventory(INTEGER, INTEGER, INTEGER, NUMERIC, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSourceItemlocid ALIAS FOR $1;
_GlDistTS TIMESTAMP WITH TIME ZONE := $6;
_targetItemlocid INTEGER;
_invhistid INTEGER;
- _p RECORD;
- _qty NUMERIC;
- _itemlocSeries INTEGER := NEXTVAL('itemloc_series_seq');
+ _p RECORD;
+ _rsrv RECORD;
+ _qty NUMERIC;
+ _qtyunreserved NUMERIC := 0.0;
+ _qtytomove NUMERIC := 0.0;
+ _result INTEGER := -1;
+ _itemlocSeries INTEGER := NEXTVAL('itemloc_series_seq');
BEGIN
AND (NOT itemsite_freeze)
AND (itemloc_id=pSourceItemlocid) );
--- Check to see if there is anything left at the source Itemloc and delete if not
- DELETE FROM itemloc
- WHERE ( (itemloc_qty=0)
- AND (itemloc_id=pSourceItemlocid) );
-
-- Check to see if any of the current Lot/Serial #/Expiration exists at the target location
SELECT itemloc_id INTO _targetItemlocid
FROM itemloc
WHERE ( (itemloc_qty=0)
AND (itemloc_id=_targetItemlocid) );
+-- Handle Reservations
+ IF (fetchMetricBool('EnableSOReservationsByLocation')) THEN
+ SELECT CASE WHEN (qtyReservedLocation(itemloc_id) > itemloc_qty)
+ THEN (qtyReservedLocation(itemloc_id) - itemloc_qty)
+ ELSE 0.0
+ END INTO _qtyunreserved
+ FROM itemloc
+ WHERE (itemloc_id=pSourceItemlocid);
+ -- Move reservations as necessary
+ WHILE (_qtyunreserved > 0.0) LOOP
+ SELECT * INTO _rsrv
+ FROM reserve
+ WHERE ((reserve_supply_type='I')
+ AND (reserve_supply_id=pSourceItemlocid))
+ ORDER BY reserve_qty;
+ IF (NOT FOUND) THEN
+ RAISE EXCEPTION 'Cannot find reservation to unreserve.';
+ END IF;
+ IF (_rsrv.reserve_qty > _qtyunreserved) THEN
+ _qtytomove := _qtyunreserved;
+ ELSE
+ _qtytomove := _rsrv.reserve_qty;
+ END IF;
+ -- Unreserve Source Location
+ SELECT unreserveSOLineQty(_rsrv.reserve_demand_id,
+ _qtytomove,
+ pSourceItemlocid) INTO _result;
+ IF (_result < 0) THEN
+ RAISE EXCEPTION 'unreserveSOLineQty failed with result=%, reserve_id=%, qty=%',
+ _result, _rsrv.reserve_id, _qtytomove;
+ END IF;
+ -- Reserve to new Location
+ SELECT reserveSOLineQty(_rsrv.reserve_demand_id,
+ TRUE,
+ _qtytomove,
+ _targetItemlocid) INTO _result;
+ IF (_result < 0) THEN
+ RAISE EXCEPTION 'reserveSOLineQty failed with result=%, reserve_id=%, qty=%',
+ _result, _rsrv.reserve_id, _qtytomove;
+ END IF;
+ -- Calculate running total
+ _qtyunreserved := _qtyunreserved - _qtytomove;
+ END LOOP;
+ END IF;
+
+-- Check to see if there is anything left at the source Itemloc and delete if not
+ DELETE FROM itemloc
+ WHERE ( (itemloc_qty=0)
+ AND (itemloc_id=pSourceItemlocid) );
+
-- Return the invhist_id
RETURN _invhistid;
--- /dev/null
+
+CREATE OR REPLACE FUNCTION reopenBankReconciliation(INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+ pBankrecid ALIAS FOR $1;
+ _bankrecid INTEGER;
+ _accntid INTEGER;
+ _sequence INTEGER;
+ _gltransid INTEGER;
+ _r RECORD;
+
+BEGIN
+
+-- Check the accnt information to make sure it is valid
+ SELECT accnt_id INTO _accntid
+ FROM bankrec, bankaccnt, accnt
+ WHERE ( (bankaccnt_accnt_id=accnt_id)
+ AND (bankrec_bankaccnt_id=bankaccnt_id)
+ AND (bankrec_id=pBankrecid) );
+ IF ( NOT FOUND ) THEN
+ RETURN -1;
+ END IF;
+
+ SELECT bankrec_id INTO _bankrecid
+ FROM bankrec
+ WHERE (NOT bankrec_posted);
+ IF (FOUND) THEN
+ -- Delete any bankrecitem records for unposted periods
+ DELETE FROM bankrecitem
+ WHERE (bankrecitem_bankrec_id=_bankrecid);
+ -- Delete any bankrec records for unposted period
+ DELETE FROM bankrec
+ WHERE (bankrec_id=_bankrecid);
+ END IF;
+
+-- Mark all the gltrans items that have been cleared as unreconciled.
+ UPDATE gltrans
+ SET gltrans_rec = FALSE
+ WHERE ( (gltrans_id IN (SELECT bankrecitem_source_id
+ FROM bankrecitem
+ WHERE ((bankrecitem_source = 'GL')
+ AND (bankrecitem_cleared)
+ AND (bankrecitem_bankrec_id=pBankrecid) ) ) )
+ AND (gltrans_accnt_id=_accntid) ) ;
+
+-- Mark all the sltrans items that have been cleared as unreconciled.
+ UPDATE sltrans
+ SET sltrans_rec = FALSE
+ WHERE ( (sltrans_id IN (SELECT bankrecitem_source_id
+ FROM bankrecitem
+ WHERE ((bankrecitem_source = 'SL')
+ AND (bankrecitem_cleared)
+ AND (bankrecitem_bankrec_id=pBankrecid) ) ) )
+ AND (sltrans_accnt_id=_accntid) ) ;
+
+-- Mark the bankrec record as unposted
+ UPDATE bankrec SET
+ bankrec_posted = FALSE,
+ bankrec_postdate = NULL
+ WHERE (bankrec_id=pBankrecid);
+
+ RETURN pBankrecid;
+END;
+$$ LANGUAGE 'plpgsql';
+
CREATE OR REPLACE FUNCTION reorderDate(INTEGER, INTEGER, BOOL) RETURNS DATE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION replaceAllVoidedAPChecks(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''replaceAllVoidedAPChecks() is deprecated - use replaceAllVoidedChecks() instead'';
CREATE OR REPLACE FUNCTION replaceAllVoidedChecks(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankaccntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION replaceVoidedAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''replaceVoidedAPCheck() is deprecated - use replaceVoidedCheck()'';
CREATE OR REPLACE FUNCTION replaceVoidedCheck(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCheckid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION reprioritizeWo(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION resetDBObjPerms(TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pObjname ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION resetDBObjPerms() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_count INTEGER := 0;
CREATE OR REPLACE FUNCTION resetLowLevelCode(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
CREATE OR REPLACE FUNCTION resetQOHBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN resetQOHBalance($1, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION resetQOHBalance(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION resolveCOSAccount(INTEGER, INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
pCustid INTEGER,
pSaletypeid INTEGER,
pShipzoneid INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_salesaccntid INTEGER;
CREATE OR REPLACE FUNCTION resolveCOWAccount(INTEGER, INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
pCustid INTEGER,
pSaletypeid INTEGER,
pShipzoneid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_salesaccntid INTEGER;
CREATE OR REPLACE FUNCTION resolveCreditAccount(INTEGER, INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
pCustid INTEGER,
pSaletypeid INTEGER,
pShipzoneid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_salesaccntid INTEGER;
CREATE OR REPLACE FUNCTION resolveSalesAccount(INTEGER, INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
pCustid INTEGER,
pSaletypeid INTEGER,
pShipzoneid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_salesaccntid INTEGER;
CREATE OR REPLACE FUNCTION restoreSalesHistory(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAsohistid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION returnCompleteShipment(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN returnCompleteShipment($1, 0, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION returnCompleteShipment(INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pshipheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION returnItemShipments(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN returnItemShipments('SO', $1, 0, CURRENT_TIMESTAMP);
CREATE OR REPLACE FUNCTION returnItemShipments(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN returnItemShipments('SO', $1, $2, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION returnItemShipments(TEXT, INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION returnShipmentTransaction(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN returnShipmentTransaction($1, 0, CURRENT_TIMESTAMP);
CREATE OR REPLACE FUNCTION returnShipmentTransaction(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN returnShipmentTransaction($1, $2, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION returnShipmentTransaction(INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipitemId ALIAS FOR $1;
pTimestamp ALIAS FOR $3;
_itemlocSeries INTEGER;
_invhistid INTEGER;
- _itemlocrsrvid INTEGER;
+ _reserveid INTEGER;
_coheadid INTEGER;
_rows INTEGER;
_r RECORD;
WHERE (shipitemlocrsrv_shipitem_id=_r.shipitem_id)
LOOP
-- See if a reservation record still exists
- SELECT itemlocrsrv_id, itemlocrsrv_qty INTO _itemlocrsrvid
- FROM itemlocrsrv JOIN itemloc ON (itemlocrsrv_itemloc_id=itemloc_id)
- WHERE ((itemlocrsrv_source = 'SO')
- AND (itemlocrsrv_source_id = _r.shipitem_orderitem_id )
+ SELECT reserve_id INTO _reserveid
+ FROM reserve JOIN itemloc ON (reserve_supply_id=itemloc_id)
+ WHERE ((reserve_supply_type='I')
+ AND (reserve_demand_type = 'SO')
+ AND (reserve_demand_id = _r.shipitem_orderitem_id )
AND (itemloc_itemsite_id=_rsrv.shipitemlocrsrv_itemsite_id)
AND (itemloc_location_id=_rsrv.shipitemlocrsrv_location_id)
AND (COALESCE(itemloc_ls_id, -1)=COALESCE(_rsrv.shipitemlocrsrv_ls_id, -1))
GET DIAGNOSTICS _rows = ROW_COUNT;
IF (_rows > 0 ) THEN
-- Update existing
- UPDATE itemlocrsrv
- SET itemlocrsrv_qty = (itemlocrsrv_qty + _rsrv.shipitemlocrsrv_qty)
- WHERE (itemlocrsrv_id=_itemlocrsvrid);
+ UPDATE reserve
+ SET reserve_qty = (reserve_qty + _rsrv.shipitemlocrsrv_qty)
+ WHERE (reserve_id=_reserveid);
ELSE
-- Recreate record
- INSERT INTO itemlocrsrv
- SELECT nextval('itemlocrsrv_itemlocrsrv_id_seq'), 'SO', _r.shipitem_orderitem_id,
- itemloc_id, _rsrv.shipitemlocrsrv_qty
+ INSERT INTO reserve
+ SELECT nextval('reserve_reserve_id_seq'), 'SO', _r.shipitem_orderitem_id,
+ 'I', itemloc_id, _rsrv.shipitemlocrsrv_qty, 'R'
FROM itemloc
WHERE ((itemloc_itemsite_id=_rsrv.shipitemlocrsrv_itemsite_id)
AND (itemloc_location_id=_rsrv.shipitemlocrsrv_location_id)
CREATE OR REPLACE FUNCTION returnWoMaterial(INTEGER, NUMERIC, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION returnWoMaterial(INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
select dropIfExists('FUNCTION', 'returnWoMaterial(INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE)');
CREATE OR REPLACE FUNCTION returnWoMaterial(INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE, BOOLEAN DEFAULT FALSE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION returnWoMaterialBatch(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION reverseCashReceipt(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCashrcptid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION reverseCashReceiptDisc(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCashrcptItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION reverseGLSeries(INTEGER, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION revokeAllModuleCmnttypeSource(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmnttypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION revokeAllModulePriv(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION revokeAllModulePrivGroup(INTEGER, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pGrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION revokeCmnttypeSource(INTEGER, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmnttypeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION revokeGroup(TEXT, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION revokePriv(TEXT, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION revokePriv(TEXT, TEXT) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION revokePrivGroup(INTEGER, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pGrpid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION rollUpActualCost(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION rollUpSorACost(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION rollUpStandardCost(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION roundCost(pCost NUMERIC) RETURNS NUMERIC IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_scale INTEGER;
CREATE OR REPLACE FUNCTION roundLocale(pFractional BOOLEAN,
pQty NUMERIC,
pLocale TEXT) RETURNS NUMERIC IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_r RECORD;
CREATE OR REPLACE FUNCTION roundQty(pFractional BOOLEAN,
pQty NUMERIC) RETURNS NUMERIC IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_scale INTEGER;
CREATE OR REPLACE FUNCTION roundSale(pSale NUMERIC) RETURNS NUMERIC IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_scale INTEGER;
CREATE OR REPLACE FUNCTION roundUp(NUMERIC) RETURNS NUMERIC IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
CREATE OR REPLACE FUNCTION saveAddr(int4, text, text, text, text, text, text, text, text, boolean, text, text)
RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAddrId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION saveAddr(int4, text, text, text, text, text, text, text, text, text)
RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAddrId ALIAS FOR $1;
SELECT dropIfExists('FUNCTION', 'saveAlarm(int,text,text,timestamp,int,text,text,text,int,text)', 'public');
CREATE OR REPLACE FUNCTION saveAlarm(int,text,date,time,int,text,boolean,text,boolean,text,boolean,text,text,int,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pAlarmId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION saveBomHead(integer,text,date,text,numeric,numeric)
RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
pTitle TEXT,
pFlag TEXT,
pOwnerUsername TEXT ) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_cntctId INTEGER;
pNotes TEXT,
pTitle TEXT,
pFlag TEXT ) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
pWebAddr TEXT,
pTitle TEXT,
pFlag TEXT ) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_returnVal INTEGER;
CREATE OR REPLACE FUNCTION saveImageAss(TEXT, INTEGER, CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSource ALIAS FOR $1;
pPercent NUMERIC,
pFixedAmt NUMERIC,
pType TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_ipsitemid INTEGER;
pDiscount NUMERIC,
pFixedAmtDiscount NUMERIC,
pType TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_ipsitemid INTEGER;
CREATE OR REPLACE FUNCTION saveItemImage(INTEGER, CHAR, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION saveItemUomConv(integer, integer, numeric, integer, numeric, boolean, integer[])
RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION saveMetasql(TEXT, TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN saveMetasql($1, $2, $3, $4, true, NULL, 0);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION saveMetasql(TEXT,TEXT,TEXT,TEXT,BOOL) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN saveMetasql($1, $2, $3, $4, $5, NULL, 0);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION saveMetasql(TEXT,TEXT,TEXT,TEXT,BOOL,TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN saveMetasql($1, $2, $3, $4, $5, $6, 0);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION saveMetasql(TEXT,TEXT,TEXT,TEXT,BOOL,TEXT,INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pGroup ALIAS FOR $1;
CREATE OR REPLACE FUNCTION scraps(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTransType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION scrapWoMaterial(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN scrapWoMaterial($1, $2, CURRENT_TIMESTAMP);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION scrapWoMaterial(INTEGER, NUMERIC, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWomatlid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectBalanceForBilling(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectDiscountItemsForPayment(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectDueItemsForPayment(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pVendid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectforbilling(integer, numeric, boolean)
RETURNS integer AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectforbilling(integer, numeric, boolean, integer)
RETURNS integer AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectPayment(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
SELECT apopen_amount, apopen_paid,
apopen_doctype, apopen_docdate,
apopen_curr_id,
- apopen_amount - apopen_paid
- - COALESCE((SELECT SUM(currToCurr(checkitem_curr_id,
- apopen_curr_id,
- checkitem_amount + checkitem_discount,
- checkhead_checkdate))
- FROM checkitem, checkhead
- WHERE((checkitem_checkhead_id=checkhead_id)
- AND (checkitem_apopen_id=apopen_id)
- AND (NOT checkhead_deleted)
- AND (NOT checkhead_replaced)
- AND (NOT checkhead_posted)) ),0) AS balance,
+ apopen_amount - apopen_paid - apCheckPending(apopen_id) AS balance,
noNeg(COALESCE(apopen_discountable_amount, 0) *
CASE WHEN (CURRENT_DATE <= determineDiscountDate(apopen_terms_id, apopen_docdate)) THEN terms_discprcnt
ELSE 0.0 END - discount_applied) AS discount_available
AND (apapply_source_apopen_id=apopen_id)
AND (apopen_discount)) ) AS data
WHERE(apopen_id=pApopenid);
- IF(NOT FOUND OR (NOT _p.apopen_doctype IN ('V','D'))) THEN
+ IF(NOT FOUND OR (NOT _p.apopen_doctype IN ('V','D','C'))) THEN
RETURN -1;
END IF;
CREATE OR REPLACE FUNCTION selectuninvoicedshipment(INTEGER) RETURNS INTEGER AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectUninvoicedShipments(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectUninvoicedShipments(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION selectUninvoicedShipments(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWarehousid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setApJournalNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_journalNumber INTEGER;
CREATE OR REPLACE FUNCTION setArJournalNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_journalNumber INTEGER;
CREATE OR REPLACE FUNCTION setBudget(INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION setBudget(INTEGER, INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBudgheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setbytea(text)
RETURNS bytea AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pMetricName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setbytea(bytea)
RETURNS bytea AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pMetricName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setCCBankAccnt(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pccardtype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setEffectiveXtUser(TEXT) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setGlJournalNumber(DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStartDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setMetric(TEXT, TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pMetricName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setmetricenc(text, text, text)
RETURNS bool AS
'
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pMetricName ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextAPMemoNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextARMemoNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextCashRcptNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextCheckNumber(INTEGER, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankaccntid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextCmNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextCRMAccountNumber(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextIncidentNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextInvcNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextNumber(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
psequence ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextPoNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextPrNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextQuNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pQuNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextShipmentNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pShipmentNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextSoNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSoNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextVcNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pNumber ALIAS FOR $1;
CREATE OR REPLACE FUNCTION setNextWoNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pWoNumber ALIAS FOR $1;
DROP FUNCTION IF EXISTS setuserCanCreateUsers(TEXT, BOOLEAN);
CREATE OR REPLACE FUNCTION setuserCanCreateUsers(pUsername TEXT, pCreateUser BOOLEAN) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
IF (pCreateUser) THEN
CREATE OR REPLACE FUNCTION setUserPreference(TEXT, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPrefName ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION setUserPreference(TEXT, TEXT, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION shipments(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTransType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION shipShipment(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT shipShipment($1, CURRENT_TIMESTAMP);
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION shipShipment(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pshipheadid ALIAS FOR $1;
--We do not need to distribute lot/serial info for transit, post trans and discard dist detail
PERFORM postIntoTrialBalance(itemlocpost_glseq) FROM itemlocpost WHERE (itemlocpost_itemlocseries=_itemlocSeries);
- PERFORM postInvHist(_invhistid);
+ IF (_invhistid > 0) THEN
+ PERFORM postInvHist(_invhistid);
+ END IF;
DELETE FROM itemlocdist WHERE (itemlocdist_series=_itemlocSeries);
DELETE FROM itemlocpost WHERE (itemlocpost_itemlocSeries=_itemlocSeries);
AND (ti.itemsite_warehous_id=_to.tohead_trns_warehous_id));
--We do not need to distribute lot/serial info for transit, post trans and discard dist detail
PERFORM postIntoTrialBalance(itemlocpost_glseq) FROM itemlocpost WHERE (itemlocpost_itemlocseries=_itemlocSeries);
- PERFORM postInvHist(_invhistid);
+ IF (_invhistid > 0) THEN
+ PERFORM postInvHist(_invhistid);
+ END IF;
DELETE FROM itemlocdist WHERE (itemlocdist_series=_itemlocSeries);
DELETE FROM itemlocpost WHERE (itemlocpost_itemlocSeries=_itemlocSeries);
CREATE OR REPLACE FUNCTION singleCharacteristicsToString(TEXT, INTEGER, TEXT, TEXT, INTEGER) RETURNS text AS
$$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTargetType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION singlelevelBOM(INTEGER, INTEGER, INTEGER, INTEGER) RETURNS SETOF bomdata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION site() RETURNS SETOF whsinfo AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row whsinfo%ROWTYPE;
CREATE OR REPLACE FUNCTION snoozeMessage(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pMsgid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION spellAmount(NUMERIC) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN spellAmount($1, baseCurrId());
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION spellAmount(NUMERIC, INTEGER) RETURNS text AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pN ALIAS FOR $1;
CREATE OR REPLACE FUNCTION splitReceipt(INTEGER, NUMERIC, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
precvid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION splitRecurrence(INTEGER, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pParentid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION startoftime() RETURNS DATE IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DATE('1970-01-01') AS return;
$$ LANGUAGE sql;
-CREATE OR REPLACE FUNCTION stdCost(INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION stdCost(INTEGER) RETURNS NUMERIC STABLE AS '
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN stdCost($1, NULL);
END;
' LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION stdCost(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+CREATE OR REPLACE FUNCTION stdCost(INTEGER, INTEGER) RETURNS NUMERIC STABLE AS '
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION sufficientInventoryToShipItem(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION sufficientInventoryToShipItem(TEXT, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
- pordertype ALIAS FOR $1;
- porderitemid ALIAS FOR $2;
- pqty ALIAS FOR $3;
- _returnVal INTEGER;
- _isqtyavail BOOLEAN;
+ pordertype ALIAS FOR $1;
+ porderitemid ALIAS FOR $2;
+ pqty ALIAS FOR $3;
+ _returnVal INTEGER;
+ _isqtyavail BOOLEAN;
BEGIN
IF (porderitemid IS NULL) THEN
WHERE (coitem_id=porderitemid)) THEN
RETURN 0;
END IF;
+
SELECT (((COALESCE(pqty, roundQty(item_fractional,
noNeg(coitem_qtyord - coitem_qtyshipped +
coitem_qtyreturned - qtyAtShipping(pordertype, coitem_id)
RETURN -3;
END IF;
+ IF (pordertype = 'SO') THEN
+ IF ( SELECT fetchMetricBool('RequireSOReservations') ) THEN
+ SELECT (COALESCE(pqty, coitem_qtyreserved) <= coitem_qtyreserved)
+ INTO _isqtyavail
+ FROM coitem, itemsite, item
+ WHERE ((coitem_itemsite_id=itemsite_id)
+ AND (coitem_status <> 'X')
+ AND (NOT ((item_type IN ('R','J')) OR (itemsite_controlmethod = 'N')))
+ AND (itemsite_item_id=item_id)
+ AND (coitem_id=porderitemid));
+ END IF;
+ END IF;
+
+ IF (NOT _isqtyavail) THEN
+ RETURN -4;
+ END IF;
+
RETURN 0;
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION sufficientInventoryToShipOrder(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pordertype ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summarizedBOM(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summarizedBOM(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summarizedBOM(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION summarizedBOM(INTEGER, INTEGER, INTEGER, INTEGER) RETURNS SETOF bomdata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summarizeTransactions(INTEGER, DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summDemand(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summDemand(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summProd(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summProd(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransA (INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransA(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransC (INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransC(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransI (INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransI(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransR (INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransR(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransS (pItemsiteid INTEGER,
pStartDate DATE,
pEndDate DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_value NUMERIC;
CREATE OR REPLACE FUNCTION summTransS(pItemsiteid INTEGER,
pCalitemid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransT (INTEGER, DATE, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION summTransT(INTEGER, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION taxassignments(integer, integer)
RETURNS SETOF taxassign AS
$BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTaxZoneId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION thawAccountingPeriod(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION thawItemSite(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION todoitem() RETURNS SETOF todoitem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_row todoitem%ROWTYPE;
CREATE OR REPLACE FUNCTION todoItemMove(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ptodoItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION todoItemMoveDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ptodoItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION todoItemMoveUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ptodoItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION toggleBankrecCleared(INTEGER, TEXT, INTEGER, NUMERIC, NUMERIC) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBankrecid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION toggleBomitemCost(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pBomitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION toNumeric(TEXT, NUMERIC) RETURNS NUMERIC IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pText ALIAS FOR $1;
CREATE OR REPLACE FUNCTION transitWhs() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_id INTEGER;
CREATE OR REPLACE FUNCTION transType(TEXT, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTransType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION tryLock(integer, integer) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pKey1 ALIAS FOR $1;
CREATE OR REPLACE FUNCTION undomerge(TEXT, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pSchema ALIAS FOR $1;
--- /dev/null
+CREATE OR REPLACE FUNCTION unreleasePurchaseOrder(pPoheadid INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+ IF ( ( SELECT (COUNT(*) > 0)
+ FROM poitem
+ WHERE ( (poitem_pohead_id=pPoheadid)
+ AND ( (poitem_status='C') OR
+ (poitem_qty_received > 0.0) OR
+ (poitem_qty_returned > 0.0) OR
+ (poitem_qty_vouchered > 0.0) ) ) ) ) THEN
+ RETURN -1;
+ END IF;
+
+ IF ( ( SELECT (pohead_status='O')
+ FROM pohead
+ WHERE (pohead_id=pPoheadid) ) ) THEN
+
+ --update status and erase the date that the order was released on
+ UPDATE pohead
+ SET pohead_status='U', pohead_released = NULL
+ WHERE (pohead_id=pPoheadid);
+
+ END IF;
+
+ --update status and erase the duedates at release
+ UPDATE poitem
+ SET poitem_status='U', poitem_rlsd_duedate = NULL
+ WHERE (poitem_pohead_id=pPoheadid);
+
+ RETURN 1;
+
+END;
+$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION uomusedforitem(INTEGER) RETURNS SETOF uom AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateABCClass(TEXT, NUMERIC, NUMERIC, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pClassCodePattern ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateABCClass(TEXT, INTEGER, NUMERIC, NUMERIC, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pClassCodePattern ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateABCClass(INTEGER, NUMERIC, NUMERIC, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pClasscodeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateABCClass(INTEGER, INTEGER, NUMERIC, NUMERIC, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pClasscodeid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateCharAssignment(TEXT, INTEGER, INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTargetType ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION updateCharAssignment(TEXT, INTEGER, INTEGER, TEXT, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pTargetType ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateCost(INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemcostid ALIAS FOR $1;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION updateCost(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemcostid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateCost(INTEGER, TEXT, BOOLEAN, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
returnVal INTEGER;
CREATE OR REPLACE FUNCTION updateCost(INTEGER, INTEGER, BOOLEAN, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
returnVal INTEGER;
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION updateCost(INTEGER, TEXT, BOOLEAN, NUMERIC, INTEGER) RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateCost(INTEGER, INTEGER, BOOLEAN, NUMERIC, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateCustomPrivs() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_r RECORD;
CREATE OR REPLACE FUNCTION UpdateItemCost(INTEGER, INTEGER, INTEGER, NUMERIC, BOOLEAN) RETURNS INTEGER AS $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemId ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateItemSiteLeadTime(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateListPrice(INTEGER, NUMERIC) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateLowerUserCosts(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION updateLowerUserCosts(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateLowlevel(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
CREATE OR REPLACE FUNCTION updateOUTLevel(INTEGER, INTEGER, INTEGER[]) RETURNS boolean AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateReorderLevel(INTEGER, INTEGER, INTEGER[]) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
_usage NUMERIC;
_totalUsage NUMERIC;
_totalDays INTEGER;
- _reorderLevel NUMERIC;
+ _reorderLevel INTEGER;
_averageUsage NUMERIC;
_result TEXT;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION updateReorderLevel(INTEGER[], INTEGER, BOOLEAN, INTEGER[]) RETURNS SETOF reordlvl AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteids ALIAS FOR $1;
_pcursor INTEGER := 1;
_totalUsage NUMERIC := 0;
_totalDays INTEGER := 0;
- _reorderLevel NUMERIC := 0;
+ _reorderLevel INTEGER := 0;
_result TEXT;
_usage NUMERIC;
_averageUsage NUMERIC;
CREATE OR REPLACE FUNCTION updateRetainedEarnings(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pYearPeriodid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateSorACost(INTEGER, TEXT, BOOLEAN, NUMERIC, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateStdCost(INTEGER, NUMERIC, NUMERIC, TEXT, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemcostid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateStdCost(INTEGER, TEXT, BOOLEAN, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION updateTodoItem(INTEGER, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, DATE, DATE, CHARACTER(1), DATE, DATE, INTEGER, TEXT, BOOLEAN, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN updateTodoItem($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, NULL);
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION updateTodoItem(INTEGER, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, DATE, DATE, CHARACTER(1), DATE, DATE, INTEGER, TEXT, BOOLEAN, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
ptodoitemid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION useDefaultLocation(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION userCanCreateUsers(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT rolcreaterole OR rolsuper
FROM pg_roles
DROP VIEW IF EXISTS usr;
DROP FUNCTION IF EXISTS userCanLogin(TEXT);
CREATE OR REPLACE FUNCTION userCanLogin(pUsername TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_isactive BOOLEAN;
CREATE OR REPLACE FUNCTION userId(TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pUsername ALIAS FOR $1;
CREATE OR REPLACE FUNCTION validateOrderQty(INTEGER, NUMERIC, BOOLEAN) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pItemsiteid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION validLocation(INTEGER, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pLocationid ALIAS FOR $1;
-- testing.
-- TODO: uncomment the following and test it. if it works, drop the one above
-- CREATE OR REPLACE FUNCTION validLocation(INTEGER, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-- DECLARE
-- pLocationid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION valueAtShipping(plineitemid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RETURN valueAtShipping('SO', plineitemid);
CREATE OR REPLACE FUNCTION valueAtShipping(pordertype TEXT,
plineitemid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_value NUMERIC := 0.0;
CREATE OR REPLACE FUNCTION voidAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''voidAPCheck() is deprecated - use voidCheck() instead'';
CREATE OR REPLACE FUNCTION voidApopenVoucher(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION voidApopenVoucher(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pApopenid ALIAS FOR $1;
apopen_amount, apopen_paid, apopen_open, apopen_notes, apopen_discount, apopen_curr_rate )
SELECT _apopenid, getEffectiveXtUser(), pJournalnumber,
apopen_vend_id, apopen_docnumber, 'C', apopen_ponumber,
- CURRENT_DATE, CURRENT_DATE, CURRENT_DATE, -1, apopen_curr_id,
+ _glDate, _glDate, _glDate, -1, apopen_curr_id,
apopen_amount - apopen_paid, 0, TRUE, _reference, TRUE, apopen_curr_rate
FROM apopen
WHERE (apopen_id=_n.apopen_id);
CREATE OR REPLACE FUNCTION voidCheck(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCheckid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION voidCreditMemo(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCmheadid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION voidInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pInvcheadid ALIAS FOR $1;
SELECT invchead.*,
findFreightAccount(invchead_cust_id) AS freightaccntid,
findARAccount(invchead_cust_id) AS araccntid,
- aropen_id,
+ aropen_id, cohist_unitcost,
( SELECT COALESCE(SUM(taxhist_tax), 0)
FROM invcheadtax
WHERE ( (taxhist_parent_id = invchead_id)
AND (taxhist_taxtype_id = getAdjustmentTaxtypeId()) ) ) AS adjtax
INTO _p
FROM invchead JOIN aropen ON (aropen_doctype='I' AND aropen_docnumber=invchead_invcnumber)
+ JOIN cohist ON (cohist_doctype='I' AND cohist_invcnumber=invchead_invcnumber)
WHERE (invchead_id=pInvcheadid);
IF (NOT FOUND) THEN
RAISE EXCEPTION 'Cannot Void Invoice as invchead not found';
JOIN item ON (item_id=invcitem_item_id)
WHERE (invchead_id=_p.invchead_id) LOOP
--- Issue billed stock from inventory
+-- Return billed stock to inventory
IF (_itemlocSeries = 0) THEN
SELECT NEXTVAL('itemloc_series_seq') INTO _itemlocSeries;
END IF;
'S/O', 'IN', _r.invchead_invcnumber, '',
('Invoice Voided ' || _r.item_number),
getPrjAccntId(_r.prj_id, resolveCOSAccount(itemsite_id, _r.cust_id, _r.saletype_id, _r.shipzone_id)),
- costcat_asset_accnt_id, _itemlocSeries, _glDate) INTO _invhistid
- FROM itemsite, costcat
- WHERE ( (itemsite_costcat_id=costcat_id)
- AND (itemsite_id=_r.itemsite_id) );
+ costcat_asset_accnt_id, _itemlocSeries, _glDate,
+ (_p.cohist_unitcost * _r.qty)) INTO _invhistid
+ FROM itemsite JOIN costcat ON (itemsite_costcat_id=costcat_id)
+ WHERE (itemsite_id=_r.itemsite_id);
END LOOP;
CREATE OR REPLACE FUNCTION voidPostedAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''voidPostedAPCheck() is deprecated - use voidPostedCheck() instead'';
CREATE OR REPLACE FUNCTION voidPostedAPCheck(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''voidPostedAPCheck() is deprecated - use voidPostedCheck() instead'';
' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION voidPostedAPCheck(INTEGER, INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
BEGIN
RAISE NOTICE ''voidPostedAPCheck() is deprecated - use voidPostedCheck() instead'';
CREATE OR REPLACE FUNCTION voidPostedCheck(INTEGER, INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pCheckid ALIAS FOR $1;
SELECT trans_id INTO _result
FROM ( SELECT gltrans_id AS trans_id
FROM gltrans
- WHERE ((gltrans_doctype='CK')
- AND (gltrans_misc_id=_p.checkhead_id)
- AND (gltrans_rec))
+ LEFT OUTER JOIN bankrecitem ON (bankrecitem_source='GL' AND bankrecitem_source_id=gltrans_id)
+ WHERE ( (gltrans_doctype='CK')
+ AND (gltrans_misc_id=_p.checkhead_id)
+ AND ((gltrans_rec) OR (bankrecitem_id IS NOT NULL)) )
UNION ALL
SELECT sltrans_id AS trans_id
FROM sltrans
- WHERE ((sltrans_doctype='CK')
- AND (sltrans_misc_id=_p.checkhead_id)
- AND (sltrans_rec)) ) AS data;
+ LEFT OUTER JOIN bankrecitem ON (bankrecitem_source='GL' AND bankrecitem_source_id=sltrans_id)
+ WHERE ( (sltrans_doctype='CK')
+ AND (sltrans_misc_id=_p.checkhead_id)
+ AND ((sltrans_rec) OR (bankrecitem_id IS NOT NULL)) )
+ ) AS data;
IF (FOUND) THEN
RETURN -14;
END IF;
ELSE
FOR _r IN SELECT checkitem_amount, checkitem_discount,
- CASE WHEN (checkitem_apopen_id IS NOT NULL) THEN
- checkitem_amount / apopen_curr_rate
- ELSE
- currToBase(checkitem_curr_id,
- checkitem_amount,
- COALESCE(checkitem_docdate, _p.checkhead_checkdate))
+ CASE WHEN (checkitem_apopen_id IS NOT NULL AND apopen_doctype='C') THEN
+ checkitem_amount / apopen_curr_rate * -1.0
+ WHEN (checkitem_apopen_id IS NOT NULL) THEN
+ checkitem_amount / apopen_curr_rate
+ ELSE
+ currToBase(checkitem_curr_id,
+ checkitem_amount,
+ COALESCE(checkitem_docdate, _p.checkhead_checkdate))
END AS checkitem_amount_base,
- checkitem_amount / checkitem_curr_rate AS amount_check,
+ currTocurr(checkitem_curr_id, _p.checkhead_curr_id,
+ CASE WHEN (checkitem_apopen_id IS NOT NULL AND apopen_doctype='C') THEN
+ checkitem_amount * -1.0
+ ELSE checkitem_amount END,
+ _p.checkhead_checkdate) AS amount_check,
apopen_id, apopen_doctype, apopen_docnumber, apopen_curr_rate, apopen_docdate,
aropen_id, aropen_doctype, aropen_docnumber,
checkitem_curr_id, checkitem_curr_rate,
PERFORM insertIntoGLSeries( _sequence, _p.checkrecip_gltrans_source,
- 'DS', _r.apopen_docnumber,
+ 'DS', _r.apopen_docnumber,
findAPDiscountAccount(_p.checkhead_recip_id),
round(_r.checkitem_discount / _r.apopen_curr_rate, 2) * -1,
pVoidDate, _gltransNote, pCheckid);
PERFORM insertIntoGLSeries( _sequence, _p.checkrecip_gltrans_source,
- 'DS', _r.apopen_docnumber,
+ 'DS', _r.apopen_docnumber,
findAPAccount(_p.checkhead_recip_id),
round(_r.checkitem_discount / _r.apopen_curr_rate, 2),
pVoidDate, _gltransNote, pCheckid);
END IF;
ELSE
-- unusual condition where bank overridden and different currency from voucher
- IF (_r.apopen_docdate > _p.checkhead_checkdate) THEN
- _exchGainTmp := ((_r.checkitem_amount/_r.checkitem_curr_rate) - (_r.checkitem_amount / _r.apopen_curr_rate)) * -1;
- ELSE
- _exchGainTmp := ((_r.checkitem_amount / _r.apopen_curr_rate) - (_r.checkitem_amount/_r.checkitem_curr_rate));
- END IF;
+ -- this does not work for all situations
+ --IF (_r.apopen_docdate > _p.checkhead_checkdate) THEN
+ -- _exchGainTmp := ((_r.checkitem_amount/_r.checkitem_curr_rate) - (_r.checkitem_amount / _r.apopen_curr_rate)) * -1;
+ --ELSE
+ -- _exchGainTmp := ((_r.checkitem_amount / _r.apopen_curr_rate) - (_r.checkitem_amount/_r.checkitem_curr_rate));
+ --END IF;
+ _exchGainTmp := 0.0;
END IF;
ELSE
SELECT arCurrGain(_r.aropen_id,_r.checkitem_curr_id, _r.checkitem_amount,
CREATE OR REPLACE FUNCTION woEffectiveDate(DATE) RETURNS DATE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pStartDate ALIAS FOR $1;
CREATE OR REPLACE FUNCTION woinvavail(integer, boolean, boolean, boolean, boolean)
RETURNS SETOF woinvav AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pwoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION woinvavail(integer, integer, boolean, boolean)
RETURNS SETOF woinvav AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pwoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION woinvavailmatl(integer, integer, boolean, boolean)
RETURNS SETOF woinvav AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pwoid ALIAS FOR $1;
CREATE OR REPLACE FUNCTION wostarted(pWoid INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
_result BOOLEAN := FALSE;
-- Group: accountNumbers
-- Name: detail
-- Notes: used by accountNumbers
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT accnt_id, *,
-- Group: addresses
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT ON (addr_country, addr_state, addr_city, addr_line1, addr_number)
-- Group: allocations
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT source_id, type, order_number, item_number, totalqty, relievedqty, balanceqty, duedate,
-- Group: apAging
-- Name: detail
-- Notes: used by dspTimePhasedOpenAPItems
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT apaging_vend_id, apaging_vend_number, apaging_vend_name,
-- Group: apApplications
-- Name: detail
-- Notes: used by dspAPApplications
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT apapply.*,
-- Group: apOpenItems
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT apopen_id, apopen_ponumber, apopen_docnumber,
-- Group: apOpenItems
-- Name: selectedpayments
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-SELECT apopen_id, apselect_id,
- (bankaccnt_name || '-' || bankaccnt_descrip) AS f_bank,
- (vend_number || '-' || vend_name) AS f_vendor,
+SELECT *,
CASE WHEN (apopen_doctype='V') THEN <? value("voucher") ?>
WHEN (apopen_doctype='D') THEN <? value("debitmemo") ?>
+ WHEN (apopen_doctype='C') THEN <? value("creditmemo") ?>
END AS doctype,
- apopen_docnumber, apopen_ponumber, apselect_amount,
- apopen_invcnumber,
- currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_amount_base,
- currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_running_base,
- currConcat(apselect_curr_id) AS currAbbr,
'curr' AS apselect_amount_xtnumericrole,
'curr' AS apselect_amount_base_xtnumericrole,
'curr' AS apselect_running_base_xtnumericrole,
0 AS apselect_running_base_xtrunninginit,
1 AS apselect_running_base_xtrunningrole
+FROM (
+-- Vouchers and Debits
+SELECT apopen_id, apselect_id,
+ (bankaccnt_name || '-' || bankaccnt_descrip) AS f_bank,
+ (vend_number || '-' || vend_name) AS f_vendor,
+ apopen_docnumber, apopen_ponumber, apselect_amount,
+ apopen_invcnumber, apopen_doctype,
+ currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_amount_base,
+ currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_running_base,
+ currConcat(apselect_curr_id) AS currAbbr
+FROM apopen, apselect, vendinfo, bankaccnt
+WHERE ( (apopen_vend_id=vend_id)
+ AND (apselect_apopen_id=apopen_id)
+ AND (apselect_bankaccnt_id=bankaccnt_id)
+ AND (apopen_doctype IN ('V', 'D'))
+<? if exists("bankaccntid") ?>
+ AND (bankaccnt_id=<? value("bankaccntid") ?>)
+<? endif ?>
+<? if exists("vend_id") ?>
+ AND (vend_id=<? value("vend_id") ?>)
+<? elseif exists("vendtype_id") ?>
+ AND (vend_vendtype_id=<? value("vendtype_id") ?>)
+<? elseif exists("vendtype_pattern") ?>
+ AND (vend_vendtype_id IN (SELECT vendtype_id
+ FROM vendtype
+ WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))
+<? endif ?>
+ )
+UNION
+-- Credits
+SELECT apopen_id, apselect_id,
+ (bankaccnt_name || '-' || bankaccnt_descrip) AS f_bank,
+ (vend_number || '-' || vend_name) AS f_vendor,
+ apopen_docnumber, apopen_ponumber, apselect_amount,
+ apopen_invcnumber, apopen_doctype,
+ currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_amount_base,
+ currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) * -1.0 AS apselect_running_base,
+ currConcat(apselect_curr_id) AS currAbbr
FROM apopen, apselect, vendinfo, bankaccnt
WHERE ( (apopen_vend_id=vend_id)
AND (apselect_apopen_id=apopen_id)
AND (apselect_bankaccnt_id=bankaccnt_id)
+ AND (apopen_doctype='C')
<? if exists("bankaccntid") ?>
AND (bankaccnt_id=<? value("bankaccntid") ?>)
<? endif ?>
WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))
<? endif ?>
)
-ORDER BY bankaccnt_name, vend_number, apopen_docnumber;
+ORDER BY f_bank, f_vendor, apopen_docnumber
+) AS data;
-- Group: apOpenItems
-- Name: selectpayments
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-SELECT * FROM (
-SELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,
- (vend_number || '-' || vend_name) AS vendor,
+SELECT *,
CASE WHEN (apopen_doctype='V') THEN <? value("voucher") ?>
- When (apopen_doctype='D') THEN <? value("debitMemo") ?>
+ WHEN (apopen_doctype='D') THEN <? value("debitMemo") ?>
+ WHEN (apopen_doctype='C') THEN <? value("creditMemo") ?>
END AS doctype,
- apopen_docnumber, apopen_ponumber,
- apopen_duedate,
- apopen_docdate, apopen_status,
- CASE WHEN (apopen_status = 'H') THEN 'error' END AS qtforegroundrole,
- (apopen_amount - apopen_paid - apCheckPending(apopen_id)) AS amount,
- ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS base_amount,
- ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS running_amount,
- COALESCE(apselect_amount, 0.0) AS selected,
- (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS base_selected,
- (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS running_selected,
- COALESCE(apselect_discount,0.0) AS discount,
- (COALESCE(apselect_discount,0.0) / apopen_curr_rate)AS base_discount,
CASE WHEN (apopen_duedate < CURRENT_DATE) THEN 'error'
WHEN(apopen_duedate > CURRENT_DATE) THEN 'emphasis'
WHEN(CURRENT_DATE <= determineDiscountDate(apopen_terms_id, apopen_docdate)) THEN 'altemphasis'
END AS apopen_duedate_qtforegroundrole,
- apopen_invcnumber,
- currConcat(apopen_curr_id) AS curr_concat,
+ CASE WHEN (apopen_status = 'H') THEN 'error' END AS qtforegroundrole,
'curr' AS amount_xtnumericrole,
'curr' AS selected_xtnumericrole,
'curr' AS running_selected_xtnumericrole,
0 AS running_amount_xtrunninginit,
1 AS running_selected_xtrunningrole,
1 AS running_amount_xtrunningrole
+ FROM (
+-- Vouchers and Debits
+SELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,
+ (vend_number || '-' || vend_name) AS vendor,
+ apopen_doctype, apopen_docnumber, apopen_ponumber, apopen_invcnumber,
+ apopen_duedate, apopen_terms_id, apopen_docdate, apopen_status,
+ (apopen_amount - apopen_paid - apCheckPending(apopen_id)) AS amount,
+ ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS base_amount,
+ ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS running_amount,
+ COALESCE(apselect_amount, 0.0) AS selected,
+ (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS base_selected,
+ (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS running_selected,
+ COALESCE(apselect_discount,0.0) AS discount,
+ (COALESCE(apselect_discount,0.0) / apopen_curr_rate)AS base_discount,
+ currConcat(apopen_curr_id) AS curr_concat
FROM vendinfo JOIN apopen ON (apopen_vend_id=vend_id)
LEFT OUTER JOIN apselect ON (apselect_apopen_id=apopen_id)
WHERE ( (apopen_open)
AND (apopen_curr_id=<? value("curr_id") ?>)
<? endif ?>
)
-ORDER BY apopen_duedate, (apopen_amount - apopen_paid) DESC) AS data
+UNION
+-- Credits
+SELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,
+ (vend_number || '-' || vend_name) AS vendor,
+ apopen_doctype, apopen_docnumber, apopen_ponumber, apopen_invcnumber,
+ apopen_duedate, apopen_terms_id, apopen_docdate, apopen_status,
+ (apopen_amount - apopen_paid - apCheckPending(apopen_id)) AS amount,
+ ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS base_amount,
+ ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) * -1.0 AS running_amount,
+ COALESCE(apselect_amount, 0.0) AS selected,
+ (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS base_selected,
+ (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) * -1.0 AS running_selected,
+ COALESCE(apselect_discount,0.0) AS discount,
+ (COALESCE(apselect_discount,0.0) / apopen_curr_rate)AS base_discount,
+ currConcat(apopen_curr_id) AS curr_concat
+FROM vendinfo JOIN apopen ON (apopen_vend_id=vend_id)
+ LEFT OUTER JOIN apselect ON (apselect_apopen_id=apopen_id)
+WHERE ( (apopen_open)
+ AND (apopen_doctype = 'C')
+<? if exists("vend_id") ?>
+ AND (vend_id=<? value("vend_id") ?>)
+<? elseif exists("vendtype_id") ?>
+ AND (vend_vendtype_id=<? value("vendtype_id") ?>)
+<? elseif exists("vendtype_pattern") ?>
+ AND (vend_vendtype_id IN (SELECT vendtype_id
+ FROM vendtype
+ WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))
+<? endif ?>
+<? if exists("olderDate") ?>
+ AND (apopen_duedate <= <? value("olderDate") ?>)
+<? elseif exists("startDate") ?>
+ AND (apopen_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
+<? endif ?>
+<? if exists("curr_id") ?>
+ AND (apopen_curr_id=<? value("curr_id") ?>)
+<? endif ?>
+)
+ORDER BY apopen_duedate, amount DESC) AS data
WHERE (amount != 0);
-- Group: arAging
-- Name: detail
-- Notes: used by dspTimePhasedOpenARItems
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT araging_cust_id, araging_cust_number, araging_cust_name,
-- Group: arApplications
-- Name: detail
-- Notes: used by dspARApplications
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT arapply.*,
-- Group: arHistory
-- Name: detail
-- Notes: used by dspCustomerARHistory, dspCustomerInformation
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT aropen_id, applyid,
-- Group: arOpenApplications
-- Name: detail
-- Notes: used by applyARCreditMemo, cashReceipt
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
(CASE WHEN aropen_doctype IN ('C','R') THEN -1 ELSE 1 END ) AS balance,
aropen_curr_id AS balance_curr,
<? if exists("cashrcpt_id") ?>
- (SELECT COALESCE(SUM(p.cashrcptitem_amount), 0)
- FROM cashrcptitem p
- WHERE (p.cashrcptitem_aropen_id=aropen_id)
- AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))
- AS applied,
- (SELECT COALESCE(SUM(p.cashrcptitem_discount), 0)
- FROM cashrcptitem p
- WHERE (p.cashrcptitem_aropen_id=aropen_id)
- AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))
- AS discount,
+ COALESCE(s.cashrcptitem_amount, 0.0) AS applied,
+ COALESCE(s.cashrcptitem_discount, 0.0) AS discount,
+-- (SELECT COALESCE(SUM(p.cashrcptitem_amount), 0)
+-- FROM cashrcptitem p
+-- WHERE (p.cashrcptitem_aropen_id=aropen_id)
+-- AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))
+-- AS applied,
+-- (SELECT COALESCE(SUM(p.cashrcptitem_discount), 0)
+-- FROM cashrcptitem p
+-- WHERE (p.cashrcptitem_aropen_id=aropen_id)
+-- AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))
+-- AS discount,
currConcat(cashrcpt_curr_id) AS applied_curr,
<? elseif exists("source_aropen_id") ?>
COALESCE(arcreditapply_amount, 0) AS applied,
-- Group: arOpenItems
-- Name: detail
-- Notes: used by arWorkBench, dspAROpenItems
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("totalOnly") ?>
NULL::date AS aropen_duedate,
NULL::text AS ordernumber,
-1 AS ordernumber_xtidrole,
- <? value("creditMemo") ?> AS doctype,
+ <? value("return") ?> AS doctype,
CASE WHEN (NOT cmhead_posted) THEN 'emphasis'
END AS doctype_qtforegroundrole,
creditmemototal(cmhead_id) AS amount,
-- display class. Used to be printed version got an extra parameter. Formatted
-- values slow things down considerably on screen version otherwise. This
-- should go away if/when we get OpenRPT to do its own formatting.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("totalOnly") ?>
NULL::date AS aropen_duedate,
NULL::text AS ordernumber,
-1 AS ordernumber_xtidrole,
- <? value("creditMemo") ?> AS doctype,
+ <? value("return") ?> AS doctype,
CASE WHEN (NOT cmhead_posted) THEN 'emphasis'
END AS doctype_qtforegroundrole,
creditmemototal(cmhead_id) AS amount,
--- /dev/null
+-- Group: assessFinanceCharges
+-- Name: detail
+-- Notes:
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+
+SELECT aropen_id, aropen_docnumber, aropen_duedate, aropen_docdate,
+ aropen_amount, aropen_paid, balance, aropen_fincharg_date, aropen_fincharg_amount,
+ cust_number, cust_name,
+ CASE WHEN (currToLocal(aropen_curr_id, fincharg_mincharg, aropen_distdate) >
+ (CASE WHEN (fincharg_assessoverdue)
+ THEN (balance + prevfincharge)
+ ELSE balance END * fincharg_air / 100.0 / 365 * CASE WHEN (fincharg_calcfrom=1)
+ THEN duedateoverdue
+ ELSE docdateoverdue END))
+ THEN currToLocal(aropen_curr_id, fincharg_mincharg, aropen_distdate)
+ ELSE (CASE WHEN (fincharg_assessoverdue)
+ THEN (balance + prevfincharge)
+ ELSE balance END * fincharg_air / 100.0 / 365 * CASE WHEN (fincharg_calcfrom=1)
+ THEN duedateoverdue
+ ELSE docdateoverdue END)
+ END AS fincharge
+FROM fincharg,
+ (SELECT *,
+ (aropen_amount - aropen_paid) AS balance,
+ COALESCE(aropen_fincharg_amount, 0.0) AS prevfincharge,
+ (<? value("assessmentDate") ?> - COALESCE(aropen_fincharg_date, aropen_duedate)) AS duedateoverdue,
+ (<? value("assessmentDate") ?> - COALESCE(aropen_fincharg_date, aropen_docdate)) AS docdateoverdue
+ FROM aropen JOIN custinfo ON (cust_id=aropen_cust_id)
+ LEFT OUTER JOIN terms ON (terms_id=aropen_terms_id)
+ LEFT OUTER JOIN custtype ON (cust_custtype_id=custtype_id)
+ LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)
+ WHERE ((aropen_doctype='I')
+ AND (aropen_open)
+ AND (COALESCE(terms_fincharg, FALSE))
+ AND (COALESCE(cust_financecharge, TRUE))
+ <? if exists("cust_id") ?>
+ AND (aropen_cust_id=<? value("cust_id") ?>)
+ <? endif ?>
+ <? if exists("custtype_id") ?>
+ AND (custtype_id=<? value("custtype_id") ?>)
+ <? endif ?>
+ <? if exists("custtype_pattern") ?>
+ AND (custtype_code~<? value("custtype_pattern") ?>)
+ <? endif ?>
+ <? if exists("custgrp_id") ?>
+ AND (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)
+ <? endif ?>
+ )) AS data
+WHERE ((COALESCE(aropen_fincharg_date, aropen_duedate) + COALESCE(cust_gracedays, fincharg_graceperiod)) < <? value("assessmentDate") ?>)
+ORDER BY cust_number, aropen_docnumber;
-- Name: detail
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
JOIN site() ON (warehous_id=itemsite_warehous_id)
JOIN item ON (item_id=itemsite_item_id)
JOIN uom ON (uom_id=coitem_qty_uom_id)
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?>
+ ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?>
+ ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?>
+ ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
WHERE (coitem_id IN (SELECT coitem_id
FROM coitem
WHERE coitem_status = 'O'
<? if exists("warehous_id") ?>
AND (itemsite_warehous_id=<? value("warehous_id") ?>)
<? endif ?>
+ <? literal("charClause") ?>
)
UNION
JOIN site() ON (warehous_id=itemsite_warehous_id)
JOIN item ON (item_id=itemsite_item_id)
JOIN uom ON (uom_id=coitem_qty_uom_id)
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?>
+ ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?>
+ ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?>
+ ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
WHERE ( (coitem_status='O')
<? if exists("cohead_id") ?>
AND (coitem_cohead_id=<? value("cohead_id") ?>)
<? if exists("warehous_id") ?>
AND (itemsite_warehous_id=<? value("warehous_id") ?>)
<? endif ?>
+ <? literal("charClause") ?>
)
) AS dummy
-- Group: bankrec
-- Name: checks
-- Notes: used by reconcileBankaccount
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("summary") ?>
-- Group: bankrec
-- Name: clearedbalance
-- Notes: used by reconcileBankaccount
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT (COALESCE(SUM(amount),0.0) + <? value("begBal") ?>) AS cleared_amount,
-- Group: bankrec
-- Name: receipts
-- Notes: used by reconcileBankaccount
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("summary") ?>
-- Group: bankrecHistory
-- Name: reconciled
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("treeView") ?>
-- Group: bankrecHistory
-- Name: unreconciled
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT gltrans_id, gltrans_date, formatDate(gltrans_date) AS f_date,
-- Group: billingSelections
-- Name: detail
-- Notes: used by dspBillingSelections
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cobmisc_id, cohead_id,
-- Group: bom
-- Name: detail
-- Notes: used by dspIndentedBOM, dspSingleLevelBOM, dspSummarizedBOM
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT <? if exists("bySingleLvl") ?>
-- Group: bomItems
-- Name: detail
-- Notes: used by bom, booItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT bomitem_id, item_id, *,
-- Group: bookings
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT coitem_id AS id, coitem_cohead_id AS altId,
JOIN item ON (item_id=itemsite_item_id)
JOIN uom ON (uom_id=coitem_qty_uom_id)
JOIN curr_symbol ON (curr_id=cohead_curr_id)
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?>
+ ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?>
+ ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?>
+ ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
WHERE ( (coitem_status<>'X')
<? if exists("cohead_id") ?>
AND (coitem_cohead_id=<? value("cohead_id") ?>)
<? if exists("warehous_id") ?>
AND (itemsite_warehous_id=<? value("warehous_id") ?>)
<? endif ?>
+ <? literal("charClause") ?>
)
<? if exists("orderByScheddate") ?>
-- Group: briefEarnedCommission
-- Name: detail
-- Notes: used by dspBriefEarnedCommissions
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cohist_salesrep_id, salesrep_number, salesrep_name, cust_number, cust_name,
-- Group: briefSalesHistory
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: capacityUOMs
-- Name: detail
-- Notes: used by dspCapacityUOMsByClassCode, dspCapacityUOMsByProductCategory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT item_id, item_number,
-- There are 2 display modes for this query:
-- 1) Legacy mode which uses A/R Application information
-- 2) Version 3.3.0 upgrade mode which uses Cash Receipt information
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("LegacyDisplayMode") ?>
-- Group: ccpayments
-- Name: list
-- Notes: list credit card payments, optionally by customer
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT ccpay_id AS id,
-- Group: charass
-- Name: populate
-- Notes: Populate characteristic assignments combobox
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("name") ?>
-- check number(optional), and recipient(optional), optionally restricted
-- to 'new' (un-posted/replaced/deleted) checks for viewing check runs.
-- fills in the check item detail if showDetail is passed.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT checkhead_id AS checkid,
SELECT checkitem_checkhead_id AS checkid, 0 AS extra, checkitem_id,
checkhead_void, checkhead_misc,
checkhead_printed, checkhead_posted,
- CAST(COALESCE(checkitem_ranumber, checkitem_vouchernumber) AS TEXT) AS number,
+ (CASE apopen_doctype WHEN 'V' THEN <? value("voucher") ?>
+ WHEN 'D' THEN <? value("debitMemo") ?>
+ WHEN 'C' THEN <? value("creditMemo") ?>
+ ELSE ''
+ END || '-' || CAST(COALESCE(checkitem_ranumber, checkitem_vouchernumber) AS TEXT)) AS number,
CAST(COALESCE(checkitem_invcnumber, checkitem_cmnumber) AS TEXT) AS description,
CAST(NULL AS DATE) AS checkdate,
checkitem_amount AS amount,
'' AS checkhead_void_qtdisplayrole, '' AS checkhead_misc_qtdisplayrole,
'' AS checkhead_printed_qtdisplayrole, '' AS checkhead_posted_qtdisplayrole,
1 AS xtindentrole
- FROM checkitem, checkhead
- WHERE ((checkitem_checkhead_id=checkhead_id)
- AND (checkhead_bankaccnt_id=<? value("bankaccnt_id") ?>)
+ FROM checkhead JOIN checkitem ON (checkitem_checkhead_id=checkhead_id)
+ LEFT OUTER JOIN apopen ON (apopen_id=checkitem_apopen_id)
+ WHERE ((checkhead_bankaccnt_id=<? value("bankaccnt_id") ?>)
<? if exists("startDate") ?>
AND (checkhead_checkdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
<? elseif exists("newOnly") ?>
-- Group: checks
-- Name: detail
-- Notes: used by printChecks
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT checkhead.*, form_report_name AS report_name
-- Notes: This query determines whether a given contact should be kept
-- active because other active records depend on it.
-- Todo - should this be moved to the cntctAfterTrigger?
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT EXISTS(
-- Group: contact
-- Name: uses
-- Notes: Find and report uses of the contact
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if not exists('core') ?>
-- Group: contactmerge
-- Name: contactused
-- Notes: Checks to see if this contact is used anywhere
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntctused(<? value("cntct_id") ?>) AS used;
-- Group: contactmerge
-- Name: delete
-- Notes: Delete a contact
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DELETE FROM cntct WHERE (cntct_id=<? value("cntct_id") ?>);
-- Group: contactmerge
-- Name: deselect
-- Notes: Removes contact selection
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DELETE FROM cntctsel
-- Group: contactmerge
-- Name: merge
-- Notes: Merge contact selections
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntctmerge(
-- Group: contactmerge
-- Name: merged
-- Notes: Lists all merged contacts
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntct_id,
-- Group: contactmerge
-- Name: populate
-- Notes: Queries selected contact info
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntct.*,
-- Group: contactmerge
-- Name: purge
-- Notes: Purge contact(s) that was/were previously merged
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DELETE FROM cntct WHERE cntct_id IN
-- Group: contactmerge
-- Name: restore
-- Notes: Restore a contact that was previously merged
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntctrestore(cntctmrgd_cntct_id) AS result
-- Group: contactmerge
-- Name: search
-- Notes: Search for contacts
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntct_id,
-- Group: contactmerge
-- Name: select
-- Notes: Processes contact selections
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntctselect(
-- Group: contactmerge
-- Name: selectcol
-- Notes: Selects a specific column
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntctselectcol(<? value("cntct_id") ?>, <? value("col_number") ?>);
-- Group: contacts
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT ON (length(cntct_last_name)=0, length(cntct_first_name)=0, cntct_last_name, cntct_first_name, cntct_number)
--- /dev/null
+-- Group: contract
+-- Name: itemsources
+-- Notes: Selection of Contract Related Item Sources
+SELECT itemsrc_id,
+ -1 AS pohead_id,
+ ' ' AS seq,
+ ' ' AS poitem_ordnumber,
+ item_number,
+ item_descrip1,
+ itemsrc_vend_uom,
+ itemsrc_vend_item_number,
+ itemsrc_contrct_min,
+ sum(poitem_qty_unreleased) AS poitem_qty_unreleased,
+ sum(poitem_qty_ordered) AS poitem_qty_ordered,
+ sum(poitem_qty_received) AS poitem_qty_received,
+ sum(poitem_qty_returned) AS poitem_qty_returned,
+ null AS poitem_duedate,
+ null AS poitem_status,
+ 0 AS xtindentrole
+ FROM (SELECT contrct_id,
+ itemsrc_id,
+ pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber,
+ item_number,
+ item_descrip1,
+ itemsrc_vend_uom,
+ itemsrc_vend_item_number,
+ itemsrc_contrct_min,
+ CASE WHEN poitem_status = 'U' THEN poitem_qty_ordered
+ ELSE 0
+ END AS poitem_qty_unreleased,
+ CASE WHEN poitem_status = 'O' THEN poitem_qty_ordered
+ WHEN poitem_status = 'C' THEN poitem_qty_ordered
+ ELSE 0
+ END AS poitem_qty_ordered,
+ poitem_qty_received,
+ poitem_qty_returned,
+ poitem_duedate,
+ poitem_status
+ FROM contrct JOIN itemsrc ON (itemsrc_contrct_id = contrct_id)
+ LEFT OUTER JOIN poitem ON (poitem_itemsrc_id = itemsrc_id)
+ LEFT OUTER JOIN pohead ON (pohead_id = poitem_pohead_id)
+ JOIN item ON (itemsrc_item_id = item_id)
+ WHERE (contrct_id = <? value("contrct_id") ?>)) AS dummy1
+ WHERE (contrct_id = <? value("contrct_id") ?>)
+ GROUP BY itemsrc_id, itemsrc_vend_item_number, itemsrc_vend_uom, itemsrc_contrct_min,
+ item_number, item_descrip1
+
+UNION -- PO Line Items
+
+SELECT itemsrc_id,
+ pohead_id,
+ pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS seq,
+ pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber,
+ null AS item_number,
+ null AS item_descrip1,
+ null AS itemsrc_vend_uom,
+ null AS itemsrc_vend_item_number,
+ null AS itemsrc_contrct_min,
+ CASE WHEN poitem_status = 'U' THEN poitem_qty_ordered
+ ELSE 0
+ END AS poitem_qty_unreleased,
+ CASE WHEN poitem_status = 'O' THEN poitem_qty_ordered
+ WHEN poitem_status = 'C' THEN poitem_qty_ordered
+ ELSE 0
+ END AS poitem_qty_ordered,
+ poitem_qty_received,
+ poitem_qty_returned,
+ poitem_duedate,
+ CASE WHEN poitem_status = 'O' THEN 'Open'
+ WHEN poitem_status = 'C' THEN 'Closed'
+ ELSE 'Unreleased'
+ END AS poitem_status,
+ 1 AS xtindentrole
+ FROM contrct JOIN itemsrc ON (itemsrc_contrct_id = contrct_id)
+ JOIN poitem ON (poitem_itemsrc_id = itemsrc_id)
+ JOIN pohead ON (pohead_id = poitem_pohead_id)
+ JOIN itemsite ON (poitem_itemsite_id = itemsite_id)
+ JOIN item ON (itemsite_item_id = item_id)
+ WHERE (contrct_id = <? value("contrct_id") ?>)
+
+UNION -- Receipts
+
+SELECT itemsrc_id,
+ pohead_id,
+ poitem_ordnumber || 'R' || to_char(recv_date, 'YYYYMMDDHH24:MI:SS') AS seq,
+ 'Receipt' AS poitem_ordnumber,
+ null AS item_number,
+ null AS item_descrip1,
+ recv_vend_uom AS vend_uom,
+ null AS itemsrc_vend_item_number,
+ null AS itemsrc_contrct_min,
+ null AS poitem_qty_unreleased,
+ null AS poitem_qty_ordered,
+ recv_qty AS poitem_qty_received,
+ null AS poitem_qty_returned,
+ recv_date AS poitem_duedate,
+ recv_trans_usr_name AS username,
+ 2 AS xtindentrole
+ FROM recv JOIN (SELECT pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber,
+ poitem_pohead_id, poitem_linenumber, poitem_id, pohead_id,
+ poitem_itemsrc_id
+ FROM poitem JOIN pohead ON (pohead_id = poitem_pohead_id)) AS dummy ON (poitem_id = recv_orderitem_id)
+ JOIN itemsite ON (itemsite_id = recv_itemsite_id)
+ JOIN item ON (item_id = itemsite_item_id)
+ JOIN itemsrc ON (poitem_itemsrc_id = itemsrc_id)
+ WHERE (itemsrc_contrct_id = <? value("contrct_id") ?>)
+
+UNION -- Returns
+
+SELECT itemsrc_id,
+ pohead_id,
+ poitem_ordnumber || 'R' || to_char(poreject_date, 'YYYYMMDDHH24:MI:SS') AS seq,
+ 'Return' AS poitem_ordnumber,
+ null AS item_number,
+ null AS item_descrip1,
+ poreject_vend_uom AS vend_uom,
+ null AS itemsrc_vend_item_number,
+ null AS itemsrc_contrct_min,
+ null AS poitem_qty_unreleased,
+ null AS poitem_qty_ordered,
+ null AS poitem_qty_received,
+ poreject_qty AS poitem_qty_returned,
+ poreject_date AS poitem_duedate,
+ poreject_trans_username AS username,
+ 2 AS xtindentrole
+ FROM poreject JOIN (SELECT pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber,
+ poitem_pohead_id, poitem_linenumber, poitem_id, pohead_id,
+ poitem_itemsrc_id
+ FROM poitem JOIN pohead ON (pohead_id = poitem_pohead_id)) AS dummy ON (poitem_id = poreject_poitem_id)
+ JOIN itemsite ON (itemsite_id = poreject_itemsite_id)
+ JOIN item ON (item_id = itemsite_item_id)
+ JOIN itemsrc ON (poitem_itemsrc_id = itemsrc_id)
+ WHERE (itemsrc_contrct_id = <? value("contrct_id") ?>)
+
+ORDER BY itemsrc_id, seq, poitem_ordnumber, poitem_duedate, xtindentrole;
-- Group: contracts
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT contrct_id,
-- Group: costedBOM
-- Name: detail
-- Notes: used by dspCostedIndentedBOM, dspCostedSingleLevelBOM, dspCostedSummarizedBOM
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Name: unusedbyitem
-- Notes: list the cost elements that can be applied to an item that have
-- not already been applied to that item. takes an item_id and type.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("item_id") ?>
-- Group: countSlip
-- Name: detail
-- Notes: used by dspCountSlipEditList, dspCountSlipsByWarehouse
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cntslip_id,
-- Group: countTag
-- Name: detail
-- Notes: used by dspCountTagEditList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
-- Group: countTags
-- Name: create
-- Notes: used by createCountTagsByParameterList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT createCountTag(itemsite_id, <? value("comments") ?>, <? value("priority") ?>, <? value("freeze") ?>, <? value("location_id") ?>)
-- Group: countTags
-- Name: detail
-- Notes: used by dspCountTagsByClassCode, dspCountTagsByItem, dspCountTagsByWarehouse
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT invcnt_id, invcnt_tagnumber, warehous_code,
-- Group: creditCards
-- Name: detail
-- Notes: used by cashReceipt, customer, salesOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT ccard_id, ccard_seq,
-- Group: creditMemo
-- Name: editlist
-- Notes: used by creditMemoEditList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
-- Group: creditMemoCreditCards
-- Name: detail
-- Notes: used by arWorkBench, returnAuthorization, returnAuthorizationWorkbench
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cmhead_number, cmhead_freight, cmhead_curr_id,
-- Notes: select details about countries used throughout the database
-- that do not match country.country_name
--
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("count") ?>
-- Name: pickdatasources
-- Notes: Show the records the user has selected to merge crm accounts. Emphasize
-- the particular fields in each record that s/he has selected.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT c.crmacct_id,
-- data to purge. this includes those that have been started
-- but not completed as well as those that have been completed
-- but neither purged nor undone.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT
-- Group: crmaccounts
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT ON (crmacct_number)
-- Notes: used by currencyConversions
-- the N in round(curr_rate, N) has to be SCALE - 1 of curr_rates
-- NUMERIC(p, SCALE) type definition
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT curr_rate_id, currConcat(curr_id) AS f_curr,
-- Group: customers
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT ON ( cust_number )
custtype_code,
bill_cntct.cntct_first_name AS bill_first_name,
bill_cntct.cntct_last_name AS bill_last_name,
+ bill_cntct.cntct_title AS bill_title,
bill_cntct.cntct_phone AS bill_phone,
bill_cntct.cntct_fax AS bill_fax,
bill_cntct.cntct_email AS bill_email,
-- CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1
-- ELSE 1 END) > 0)
--ORDER BY cust_number;
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT araging_cust_id AS cust_id,
-- Group: depositesRegister
-- Name: detail
-- Notes: used by dspDepositsRegister
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT trans_id, trans_date, trans_source,
-- Group: detailedInventoryHistory
-- Name: detail
-- Notes: used by dspDetailedInventoryHistoryByLocation, dspDetailedInventoryHistoryByLotSerial
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: distributeInventory
-- Name: locations
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT id, type, locationname, defaultlocation,
-- Group: employees
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT emp_id, warehous_code, emp_active, emp_code, emp_number,
-- Group: events
-- Name: detail
-- Notes: used by eventManager
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT evntlog_id, evntlog_ord_id, evntlog_newdate,
-- Group: expiredInventory
-- Name: detail
-- Notes: used by dspExpiredInventoryByClassCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, itemloc_id, warehous_code, item_number, uom_name,
-- Group: freightPrices
-- Name: detail
-- Notes: used by dspFreightPricesByCustomer, dspFreightPricesByCustomerType
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemid, sourcetype, ipshead_name, source, ipsfreight_qtybreak, ipsfreight_price,
-- Group: frozenItemSites
-- Name: detail
-- Notes: used by dspFrozenItemSites
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, warehous_code, item_number,
-- Group: glseries
-- Name: checkeditable
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT gltrans_id
-- Group: glseries
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
-- Group: glseries
-- Name: postjournal
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT postJournals(<? value("sequence") ?>) AS result;
-- Group: gltransactions
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT gltrans_id, gltrans_accnt_id,gltrans_date,gltrans_created,gltrans_source,
-- Group: incidents
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT ON (incdt_number) incdt_id AS id,
-- Group: invalidBillsofMaterials
-- Name: detail
-- Notes: used by dspInvalidBillsOfMaterials
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, parent.item_id AS pitem_id,
-- Name: byCustOrSO
-- Notes: query to get item availability by either customer id/type/pattern
-- or by cohead_id
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT id, altid, cohead_id,
-- Group: inventoryAvailability
-- Name: general
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, altId,
-- Group: inventoryAvailabilitybyWorkorder
-- Name: detail
-- Notes: used by dspInventoryAvailabilityByWorkOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *, 'qty' AS woinvav_qoh_xtnumericrole,
-- Group: inventoryHistory
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT invhist_id, invdetail_id, invhist_transdate AS sortdate,
-- Group: inventoryLocator
-- Name: detail
-- Notes: used by dspInventoryLocator
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- Lot/Serial Characteristics additions by Specter Vision Solutions, Inc.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
CASE WHEN (itemsite_warrpurc) THEN itemloc_warrpurc
END AS warranty,
itemloc_qty AS qoh
+<? foreach("char_id_text_list") ?>
+ , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>
+<? endforeach ?>
FROM itemsite, whsinfo,
itemloc LEFT OUTER JOIN location ON (itemloc_location_id=location_id)
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='LS')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=itemloc_ls_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='LS')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=itemloc_ls_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='LS')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=itemloc_ls_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
WHERE ((itemsite_loccntrl OR (itemsite_controlmethod IN ('L', 'S')))
AND (itemloc_itemsite_id=itemsite_id)
AND (itemsite_warehous_id=warehous_id)
<? if exists("warehous_id") ?>
AND (itemsite_warehous_id=<? value("warehous_id") ?>)
<? endif ?>
+ <? if exists("site") ?>
+ AND (itemsite_warehous_id=<? value("site")?>)
+ <? endif ?>
+ <? if exists("lot_serial") ?>
+ AND (formatlotserialnumber(itemloc_ls_id)=<? value("lot_serial")?>)
+ <? endif ?>
+ <? if exists("_location_name") ?>
+ AND (formatLocationName(location_id)=<? value("_location_name")?>)
+ <? endif ?>
+ <? literal("charClause") ?>
)
UNION
SELECT itemsite_id, 2 AS type, warehous_code,
NULL AS expiration,
NULL AS warranty,
itemsite_qtyonhand AS qoh
+<? foreach("char_id_text_list" ?>
+ , NULL AS char<? value("char_id_text_list") ?>
+<? endforeach ?>
+<? foreach("char_id_list_list" ?>
+ , NULL AS char<? value("char_id_list_list") ?>
+<? endforeach ?>
+<? foreach("char_id_date_list" ?>
+ , NULL AS char<? value("char_id_date_list") ?>
+<? endforeach ?>
FROM itemsite, whsinfo
WHERE ((NOT itemsite_loccntrl)
AND (itemsite_controlmethod NOT IN ('L', 'S'))
-- Group: invoiceInformation
-- Name: detail
-- Notes: used by dspInvoiceInformation
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT arapply_id,
-- Group: invoiceRegister
-- Name: detail
-- Notes: used by dspInvoiceRegister
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT *
-- Group: invoices
-- Name: detail
-- Notes: used by reprintInvoices, unpostedInvoices, dspRecurringInvoices
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT invchead_id, cust_id,
invchead_invcnumber AS docnumber,
findCustomerForm(cust_id, 'I') AS reportname,
<? endif ?>
+ CASE WHEN (calcInvoiceAmt(invchead_id,'S') != 0.0)
+ THEN (calcInvoiceAmt(invchead_id,'M') / calcInvoiceAmt(invchead_id,'S'))
+ ELSE 1.0
+ END AS marginpercent,
+ 'percent' AS marginpercent_xtnumericrole,
'curr' AS extprice_xtnumericrole,
'curr' AS balance_xtnumericrole,
CASE WHEN (aropen_id IS NULL) THEN 'Unposted' END AS balance_qtdisplayrole
-- Group: invoices
-- Name: print
-- Notes: used by printInvoices
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT invchead_id, invchead_id AS docid,
-- Group: issueToShipping
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
noNeg(qtyord - qtyshipped + qtyreturned) AS balance,
+ indent AS xtindentrole,
'qty' AS qtyord_xtnumericrole,
'qty' AS qtyshipped_xtnumericrole,
'qty' AS qtyreturned_xtnumericrole,
FROM (
<? if exists("sohead_id") ?>
SELECT coitem_id AS lineitem_id,
- CASE
- WHEN (itemsite_costmethod = 'J') THEN
- 1
- ELSE
- 0
- END AS job,
- MIN(s1.shiphead_number) AS shiphead_number,
+ CASE WHEN (itemsite_costmethod = 'J') THEN 1
+ ELSE 0
+ END AS job, 0 AS indent,
+ getOpenShipment('SO', <? value("sohead_id") ?>, <? value("warehous_id") ?>) AS shiphead_number,
formatSoLineNumber(coitem_id) AS linenumber, item_number,
(item_descrip1 || ' ' || item_descrip2) AS itemdescrip,
warehous_code,
coitem_qtyord AS qtyord,
coitem_qtyshipped AS qtyshipped,
coitem_qtyreturned AS qtyreturned,
- COALESCE(SUM(shipitem_qty), 0) AS atshipping,
- coitem_linenumber AS seq1, coitem_subnumber AS seq2
-FROM itemsite, item, site(), uom,
- coitem LEFT OUTER JOIN
- ( shipitem JOIN shiphead s1
- ON ( (shipitem_shiphead_id=s1.shiphead_id)
- AND (s1.shiphead_order_type='SO')
- AND (NOT s1.shiphead_shipped) )
- ) ON (shipitem_orderitem_id=coitem_id)
--- TODO - need a facility to select which shipment you are working on
--- LEFT OUTER JOIN shiphead s2 ON ((s2.shiphead_order_id=coitem_cohead_id)
--- AND (s2.shiphead_order_type='SO')
--- AND (NOT s2.shiphead_shipped ))
-WHERE ( (coitem_itemsite_id=itemsite_id)
- AND (coitem_qty_uom_id=uom_id)
- AND (itemsite_item_id=item_id)
- AND (itemsite_warehous_id=warehous_id)
- AND (coitem_status NOT IN ('C','X'))
- AND (item_type != 'K')
- AND (coitem_cohead_id=<? value("sohead_id") ?>) )
-GROUP BY coitem_id, linenumber, item_number,
- item_descrip1, item_descrip2, warehous_code,
- coitem_scheddate, uom_name,
- coitem_qtyord, coitem_qtyshipped, coitem_qtyreturned,
- coitem_linenumber, coitem_subnumber,
--- s2.shiphead_number,
- itemsite_costmethod, itemsite_controlmethod
+ qtyAtShipping(coitem_id) AS atshipping,
+ coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3
+FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ JOIN site() ON (warehous_id=itemsite_warehous_id)
+ JOIN uom ON (uom_id=coitem_qty_uom_id)
+WHERE ( (coitem_status NOT IN ('C','X'))
+ AND (item_type != 'K')
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id=<? value("warehous_id") ?>)
+<? endif ?>
+ AND (coitem_cohead_id=<? value("sohead_id") ?>) )
+
+<? if exists("includeReservations") ?>
+UNION ALL
+SELECT coitem_id AS lineitem_id,
+ CASE WHEN (itemsite_costmethod = 'J') THEN 1
+ ELSE 0
+ END AS job, 1 AS indent,
+ '' AS shiphead_number,
+ '' AS linenumber, formatLocationName(itemloc_location_id) AS item_number,
+ formatLotSerialNumber(itemloc_ls_id) AS itemdescrip,
+ '' AS warehous_code,
+ NULL AS scheddate,
+ '' AS uom_name,
+ reserve_qty AS qtyord,
+ NULL AS qtyshipped,
+ NULL AS qtyreturned,
+ NULL AS atshipping,
+ coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3
+FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ JOIN site() ON (warehous_id=itemsite_warehous_id)
+ JOIN reserve ON (reserve_demand_id=coitem_id AND
+ reserve_demand_type='SO' AND
+ reserve_supply_type='I')
+ JOIN itemloc ON (itemloc_id=reserve_supply_id)
+WHERE ( (coitem_status NOT IN ('C','X'))
+ AND (item_type != 'K')
+ AND ((itemsite_controlmethod IN ('L', 'S')) OR (itemsite_loccntrl))
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id=<? value("warehous_id") ?>)
+<? endif ?>
+ AND (coitem_cohead_id=<? value("sohead_id") ?>) )
+UNION ALL
+SELECT coitem_id AS lineitem_id,
+ CASE WHEN (itemsite_costmethod = 'J') THEN 1
+ ELSE 0
+ END AS job, 1 AS indent,
+ '' AS shiphead_number,
+ '' AS linenumber, 'N/A',
+ 'N/A' AS itemdescrip,
+ '' AS warehous_code,
+ NULL AS scheddate,
+ '' AS uom_name,
+ coitem_qtyreserved AS qtyord,
+ NULL AS qtyshipped,
+ NULL AS qtyreturned,
+ NULL AS atshipping,
+ coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3
+FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ JOIN site() ON (warehous_id=itemsite_warehous_id)
+WHERE ( (coitem_status NOT IN ('C','X'))
+ AND (item_type != 'K')
+ AND ((itemsite_controlmethod = 'R') AND (NOT itemsite_loccntrl))
+ AND (coitem_qtyreserved > 0.0)
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id=<? value("warehous_id") ?>)
+<? endif ?>
+ AND (coitem_cohead_id=<? value("sohead_id") ?>) )
+<? endif ?>
+
<? elseif exists("tohead_id") ?>
+
SELECT toitem_id AS lineitem_id,
- 0 AS lsJob,
- MIN(s1.shiphead_number) AS shiphead_number,
+ 0 AS lsJob, 0 AS indent,
+ getOpenShipment('TO', <? value("tohead_id") ?>, <? value("warehous_id") ?>) AS shiphead_number,
toitem_linenumber AS linenumber, item_number,
(item_descrip1 || ' ' || item_descrip2) AS itemdescrip,
tohead_srcname AS warehous_code,
toitem_qty_ordered AS qtyord,
toitem_qty_shipped AS qtyshipped,
0 AS qtyreturned,
- COALESCE(SUM(shipitem_qty), 0) AS atshipping,
- toitem_linenumber AS seq1, 0 AS seq2
-FROM item, tohead, site(), uom,
- toitem LEFT OUTER JOIN
- ( shipitem JOIN shiphead s1
- ON ( (shipitem_shiphead_id=s1.shiphead_id)
- AND (s1.shiphead_order_type='TO')
- AND (NOT s1.shiphead_shipped) )
- ) ON (shipitem_orderitem_id=toitem_id)
--- TODO - need a facility to select which shipment you are working on
--- LEFT OUTER JOIN shiphead s2 ON ((s2.shiphead_order_id=toitem_tohead_id)
--- AND (s2.shiphead_order_type='TO')
--- AND (NOT s2.shiphead_shipped ))
+ qtyAtShipping('TO', toitem_id) AS atshipping,
+ toitem_schedshipdate AS seq1, toitem_linenumber AS seq2, 0 AS seq3
+FROM item, tohead, site(), uom, toitem
WHERE ( (toitem_item_id=item_id)
AND (toitem_status NOT IN ('C','X'))
AND (toitem_tohead_id=tohead_id)
AND (tohead_src_warehous_id=warehous_id)
AND (item_inv_uom_id=uom_id)
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id=<? value("warehous_id") ?>)
+<? endif ?>
AND (tohead_id=<? value("tohead_id") ?>) )
-GROUP BY toitem_id, toitem_linenumber, item_number,
- item_descrip1, item_descrip2, tohead_srcname,
- toitem_schedshipdate, uom_name,
- toitem_qty_ordered, toitem_qty_shipped
--- s2.shiphead_number
<? endif ?>
) AS sub
-ORDER BY scheddate, seq1, seq2;
+ORDER BY seq1, seq2, seq3, indent;
-- Group: itemCost
-- Name: detail
-- Notes: used by dspItemCostSummary, dspItemCostsByClassCode, dspItemCostHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: itemCost
-- Name: list
-- Notes: used by maintainItemCosts, bomItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-- The order of checking for item_id first is important.
-- Group: itemPricingSchedule
-- Name: detail
-- Notes: used by itemPricingSchedule
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
price.uom_name AS priceuom,
((COALESCE(ipsitem_discntprcnt, 0.0) * 100) + ipsitem_price) AS price,
(COALESCE(ipsitem_fixedamtdiscount, 0.0) + 0.00) AS fixedAmt,
- noNeg(CASE WHEN (ipsitem_type='N') THEN ipsitem_price
- WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * COALESCE(ipsitem_discntprcnt, 0.0)) - COALESCE(ipsitem_fixedamtdiscount, 0.0))
- WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * COALESCE(ipsitem_discntprcnt, 0.0)) + COALESCE(ipsitem_fixedamtdiscount, 0.0))
+ noNeg(CASE WHEN (ipsitem_type='N') THEN
+ ipsitem_price
+ WHEN (ipsitem_type='D') THEN
+ (item_listprice - (item_listprice * COALESCE(ipsitem_discntprcnt, 0.0)) - COALESCE(ipsitem_fixedamtdiscount, 0.0))
+ WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups') AND fetchMetricBool('WholesalePriceCosting')) THEN
+ (item_listcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+ WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN
+ (itemCost(itemsite_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+ WHEN (ipsitem_type = 'M' AND fetchMetricBool('WholesalePriceCosting')) THEN
+ (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+ WHEN (ipsitem_type = 'M') THEN
+ (itemCost(itemsite_id) + (itemCost(itemsite_id) * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
ELSE 0.0
END) AS netPrice,
CASE WHEN (ipsitem_type='N') THEN <? value("nominal") ?>
LEFT OUTER JOIN prodcat ON (prodcat_id=ipsitem_prodcat_id)
LEFT OUTER JOIN uom AS qty ON (qty.uom_id=ipsitem_qty_uom_id)
LEFT OUTER JOIN uom AS price ON (price.uom_id=ipsitem_price_uom_id)
+ LEFT OUTER JOIN itemsite ON (itemsite_item_id=item_id AND itemsite_warehous_id=<? value("warehous_id") ?>)
WHERE (ipsitem_ipshead_id=<? value("ipshead_id") ?>)
UNION
-- Name: populateEdit
-- Notes: used by enterPoitemReceipt, splitReceipt
------PURCHASE ORDER----------
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT pohead_number AS order_number, poitem_linenumber AS orderitem_linenumber,
-- Name: populateNew
-- Notes: used by enterPoitemReceipt
---------PURCHASE ORDERS-------------
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT pohead_number AS order_number, poitem_linenumber AS orderitem_linenumber,
-- Group: itemReceipt
-- Name: sourceItemSite
-- Notes: used by enterPoitemReceipt
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("poitem_id") ?> -- this should never be called
-- Name: detail
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id,warehous_code,itemsite_qtyonhand, itemsite_active,
-- Group: itemSources
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
-
-SELECT itemsrc_id,
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+<? if not exists("defaultOnly") ?>
+ SELECT itemsrc_id,
vend_name,
item_number, uom_name,
(item_descrip1 || ' ' || item_descrip2) AS item_descrip,
contrct_number,
+ COALESCE( (SELECT SUM(poitem_qty_ordered)
+ FROM poitem
+ WHERE (poitem_itemsrc_id=itemsrc_id)), 0.0) AS purchased_qty,
itemsrc.*,
'qty' AS itemsrc_invvendoruomratio_xtnumericrole,
CASE WHEN COALESCE(itemsrc_effective, startOfTime()) <=
CASE WHEN (COALESCE(itemsrc_expires, endOfTime()) < CURRENT_DATE) THEN 'expired'
WHEN (COALESCE(itemsrc_effective, startOfTime()) > CURRENT_DATE) THEN 'future'
END AS qtforegroundrole
-FROM itemsrc JOIN vendinfo ON (vend_id=itemsrc_vend_id AND vend_active)
- JOIN item ON (item_id=itemsrc_item_id)
- JOIN uom ON (uom_id=item_inv_uom_id)
- LEFT OUTER JOIN contrct ON (contrct_id=itemsrc_contrct_id)
-WHERE ((true)
+ FROM itemsrc JOIN vendinfo ON (vend_id=itemsrc_vend_id AND vend_active)
+ JOIN item ON (item_id=itemsrc_item_id)
+ JOIN uom ON (uom_id=item_inv_uom_id)
+ LEFT OUTER JOIN contrct ON (contrct_id=itemsrc_contrct_id)
+ WHERE ((true)
<? if not exists("showInactive") ?>
AND (itemsrc_active)
<? endif ?>
<? if exists("item_id") ?>
- AND (itemsrc_item_id=<? value("item_id") ?>)
+ AND (itemsrc_item_id=<? value("item_id") ?>)
<? endif ?>
<? if exists("vend_id") ?>
- AND (itemsrc_vend_id=<? value("vend_id") ?>)
+ AND (itemsrc_vend_id=<? value("vend_id") ?>)
<? endif ?>
<? if exists("contrct_id") ?>
- AND (itemsrc_contrct_id=<? value("contrct_id") ?>)
+ AND (itemsrc_contrct_id=<? value("contrct_id") ?>)
<? endif ?>
<? if exists("contract_number_pattern") ?>
- AND (contrct_number ~* <? value("contract_number_pattern") ?>)
+ AND (contrct_number ~* <? value("contract_number_pattern") ?>)
<? endif ?>
<? if not exists("showExpired") ?>
- AND (itemsrc_expires > CURRENT_DATE)
+ AND (itemsrc_expires > CURRENT_DATE)
<? endif ?>
<? if not exists("showFuture") ?>
- AND (itemsrc_effective <= CURRENT_DATE)
+ AND (itemsrc_effective <= CURRENT_DATE)
<? endif ?>
)
<? if exists("item_id") ?>
-ORDER BY itemsrc_ranking, vend_name,
+ORDER BY itemsrc_contrct_id, itemsrc_ranking, vend_name,
itemsrc_vend_item_number, itemsrc_manuf_name,
itemsrc_manuf_item_number
<? else ?>
ORDER By item_number, vend_name
<? endif ?>
+<? else ?>
+ SELECT itemsrc_id, 0 AS ranked FROM itemsrc, contrct
+ WHERE ((itemsrc_item_id= <? value("item_id") ?>) AND (itemsrc_default)
+ AND (contrct_id = itemsrc_contrct_id))
+ UNION
+ SELECT itemsrc_id, 2 AS ranked
+ FROM itemsrc JOIN (SELECT * FROM
+ (SELECT CASE WHEN ((itemsrc_item_id=<? value("item_id") ?>) AND (NOT itemsrc_default)
+ AND (contrct_id = itemsrc_contrct_id)) THEN -1
+ ELSE itemsrc_id
+ END AS dummy_id FROM itemsrc, contrct
+ WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (NOT itemsrc_default)
+ AND (contrct_id = itemsrc_contrct_id))
+ UNION
+ SELECT itemsrc_id AS dummy_id
+ FROM itemsrc
+ WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (itemsrc_default))
+ ) AS dummy
+ LIMIT 1) AS dummy2
+ ON (itemsrc_id=dummy_id)
+ WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (itemsrc_default) AND (COALESCE(itemsrc_contrct_id,0)=0))
+
+ORDER by ranked
+<? endif ?>
;
-- Group: itemSources
-- Name: prices
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsrcp_id, itemsrc_id,
-- Group: itemSources
-- Name: search
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsrc_id AS id,
1 AS altid,
itemsrc_vend_item_descrip,
itemsrc_manuf_name,
itemsrc_manuf_item_number,
- itemsrc_manuf_item_descrip
+ itemsrc_manuf_item_descrip,
+ contrct_number
FROM vendinfo JOIN itemsrc ON (itemsrc_vend_id=vend_id)
JOIN item ON (item_id=itemsrc_item_id)
+ LEFT OUTER JOIN contrct ON (itemsrc_contrct_id = contrct_id)
WHERE (vend_id=<? value("vend_id") ?>)
AND ( (FALSE)
<? if exists("searchNumber") ?>
poitem_vend_item_descrip,
poitem_manuf_name,
poitem_manuf_item_number,
- poitem_manuf_item_descrip
+ poitem_manuf_item_descrip,
+ null AS contrct_id
FROM vendinfo JOIN pohead ON (pohead_vend_id=vend_id)
JOIN poitem ON (poitem_pohead_id=pohead_id)
LEFT OUTER JOIN expcat ON (poitem_expcat_id=expcat_id)
-- Group: itemcostdetail
-- Name: detail
-- Notes: dspItemCostDetail
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT id, item.item_id, seqnumber, item_number,
-- Group: items
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: itemsWithoutItemSources
-- Name: detail
-- Notes: used by dspItemsWithoutItemSources
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT item_id, item_number,
-- Group: journals
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT sltrans.*,
-- Group: maintainShipping
-- Name: detail
-- Notes: used by maintainShipping
--- order header info
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+-- order header info
+-- Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+-- order header info
SELECT shiphead_id AS parent_id, cohead_id AS child_id,
shiphead_number, cohead_number AS linenumber,
'SO' AS ordertype,
NULL AS f_shipqty, NULL AS f_shipvalue,
<? endif ?>
cohead_holdtype AS holdtype,
+ shiphead_notes AS notes,
shiphead_number AS shiphead_number_qtdisplayrole,
'SO' AS ordertype_qtdisplayrole,
'qty' AS shipqty_xtnumericrole,
'cost' AS shipvalue_xtnumericrole,
0 AS shipvalue_xttotalrole,
0 AS xtindentrole,
- CAST(shiphead_id AS TEXT) AS sort
+ shiphead_id AS seq1, shiphead_order_id AS seq2,
+ 0 AS seq3, 0 AS seq4
FROM shiphead, custinfo, cohead
<? if exists("warehous_id") ?>
JOIN coitem ON (coitem_cohead_id=cohead_id)
AND (shiphead_order_type='SO')
AND (shiphead_order_id=cohead_id)
AND (cohead_cust_id=cust_id)
+<? if exists("cust_id") ?>
+ AND (cust_id=<? value("cust_id") ?>)
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND (cohead_id=<? value("cohead_id") ?>)
+<? endif ?>
)
-- order line info
UNION ALL
SELECT cohead_id AS parent_id, coitem_id AS child_id,
'' AS shiphead_number, CAST(coitem_linenumber AS TEXT) AS linenumber,
- 'SO' AS ordertype,
+ 'SO Item' AS ordertype,
NULL AS sfstatus,
item_number AS dest, (item_descrip1 || ' ' || item_descrip2) AS description,
NULL AS shiphead_shipvia, uom_name,
formatCost(valueAtShipping('SO', coitem_id)) AS f_shipvalue,
<? endif ?>
cohead_holdtype AS holdtype,
+ '' as notes,
NULL AS shiphead_number_qtdisplayrole,
NULL AS ordertype_qtdisplayrole,
'qty' AS shipqty_xtnumericrole,
'cost' AS shipvalue_xtnumericrole,
0 AS shipvalue_xttotalrole,
1 AS xtindentrole,
- CAST(shiphead_id AS TEXT) || CAST(shiphead_order_id AS TEXT) ||
- TO_CHAR(coitem_id, '0000000') || '1' AS sort
+ shiphead_id AS seq1, shiphead_order_id AS seq2,
+ coitem_id AS seq3, 0 AS seq4
FROM shiphead, cohead, coitem, uom, itemsite, item
WHERE ((NOT shiphead_shipped)
AND (shiphead_order_type='SO')
<? if exists("warehous_id") ?>
AND (itemsite_warehous_id=<? value("warehous_id") ?>)
<? endif ?>
+<? if exists("cust_id") ?>
+ AND (cohead_cust_id=<? value("cust_id") ?>)
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND (cohead_id=<? value("cohead_id") ?>)
+<? endif ?>
)
-- shipitem info
UNION ALL
SELECT shiphead_id AS parent_id, shipitem_id AS child_id,
'' AS shiphead_number, '' AS linenumber,
- 'SO' AS ordertype,
+ 'SO Ship' AS ordertype,
NULL AS sfstatus,
'' AS dest,
formatDate(shipitem_transdate) || ' by ' || shipitem_trans_username AS description,
NULL AS f_shipvalue,
<? endif ?>
'' AS holdtype,
+ '' AS notes,
NULL AS shiphead_number_qtdisplayrole,
NULL AS ordertype_qtdisplayrole,
'qty' AS shipqty_xtnumericrole,
'cost' AS shipvalue_xtnumericrole,
0 AS shipvalue_xttotalrole,
2 AS xtindentrole,
- CAST(shiphead_id AS TEXT) || CAST(shiphead_order_id AS TEXT) ||
- TO_CHAR(shipitem_orderitem_id, '0000000') || '2' AS sort
-FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+ shiphead_id AS seq1, shiphead_order_id AS seq2,
+ shipitem_orderitem_id AS seq3, shipitem_id AS seq4
+FROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)
+ JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
<? if exists("warehous_id") ?>
JOIN coitem ON ((shipitem_orderitem_id=coitem_id)
AND (shiphead_order_type='SO'))
<? endif ?>
WHERE ((NOT shiphead_shipped)
AND (shiphead_order_type='SO')
+<? if exists("cust_id") ?>
+ AND (cohead_cust_id=<? value("cust_id") ?>)
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND (cohead_id=<? value("cohead_id") ?>)
+<? endif ?>
)
+<? if exists("includeDistributions") ?>
+-- distribution info
+UNION ALL
+SELECT shiphead_id AS parent_id, shipitem_id AS child_id,
+ '' AS shiphead_number, '' AS linenumber,
+ 'SO Dist' AS ordertype,
+ NULL AS sfstatus,
+ formatLocationName(invdetail_location_id) AS dest,
+ formatLotSerialNumber(invdetail_ls_id) AS description,
+ formatDate(invdetail_expiration) AS shiphead_shipvia, '' AS uom_name,
+ invdetail_qty AS shipqty,
+ NULL AS shipvalue,
+<? if exists("includeFormatted") ?>
+ formatQty(invdetail_qty) AS f_shipqty,
+ NULL AS f_shipvalue,
+<? endif ?>
+ '' AS holdtype,
+ '' AS notes,
+ NULL AS shiphead_number_qtdisplayrole,
+ NULL AS ordertype_qtdisplayrole,
+ 'qty' AS shipqty_xtnumericrole,
+ 'cost' AS shipvalue_xtnumericrole,
+ 0 AS shipvalue_xttotalrole,
+ 3 AS xtindentrole,
+ shiphead_id AS seq1, shiphead_order_id AS seq2,
+ shipitem_orderitem_id AS seq3, shipitem_id AS seq4
+FROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)
+ JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+ LEFT OUTER JOIN invhist ON (invhist_id=shipitem_invhist_id)
+ LEFT OUTER JOIN invdetail ON (invdetail_invhist_id=invhist_id)
+ <? if exists("warehous_id") ?>
+ JOIN coitem ON ((shipitem_orderitem_id=coitem_id)
+ AND (shiphead_order_type='SO'))
+ JOIN itemsite ON ((coitem_itemsite_id=itemsite_id)
+ AND (itemsite_warehous_id=<? value("warehous_id") ?>))
+ <? endif ?>
+WHERE ((NOT shiphead_shipped)
+ AND (shiphead_order_type='SO')
+<? if exists("cust_id") ?>
+ AND (cohead_cust_id=<? value("cust_id") ?>)
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND (cohead_id=<? value("cohead_id") ?>)
+<? endif ?>
+)
+<? endif ?>
<? if exists("MultiWhs") ?>
UNION ALL
NULL AS f_shipqty, NULL AS f_shipvalue,
<? endif ?>
'TO' AS holdtype,
+ shiphead_notes AS notes,
shiphead_number AS shiphead_number_qtdisplayrole,
'TO' AS ordertype_qtdisplayrole,
'qty' AS shipqty_xtnumericrole,
'cost' AS shipvalue_xtnumericrole,
0 AS shipvalue_xttotalrole,
0 AS xtindentrole,
- CAST(shiphead_id AS TEXT) AS sort
+ shiphead_id AS seq1, shiphead_order_id AS seq2,
+ 0 AS seq3, 0 AS seq4
FROM shiphead, tohead
<? if exists("warehous_id") ?>
JOIN toitem ON (toitem_tohead_id=tohead_id)
WHERE ((NOT shiphead_shipped)
AND (shiphead_order_type='TO')
AND (shiphead_order_id=tohead_id)
+<? if exists("cust_id") ?>
+ AND FALSE
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND FALSE
+<? endif ?>
)
-- order line info
UNION ALL
formatCost(valueAtShipping('TO', toitem_id)) AS f_shipvalue,
<? endif ?>
'TO' AS holdtype,
+ '' AS notes,
NULL AS shiphead_number_qtdisplayrole,
NULL AS ordertype_qtdisplayrole,
'qty' AS shipqty_xtnumericrole,
'cost' AS shipvalue_xtnumericrole,
0 AS shipvalue_xttotalrole,
1 AS xtindentrole,
- CAST(shiphead_id AS TEXT) || CAST(shiphead_order_id AS TEXT) ||
- TO_CHAR(toitem_id, '0000000') || '1' AS sort
+ shiphead_id AS seq1, shiphead_order_id AS seq2,
+ toitem_id AS seq3, 0 AS seq4
FROM shiphead, tohead, item, toitem
<? if exists("warehous_id") ?>
JOIN itemsite ON ((toitem_item_id=itemsite_item_id)
AND (shiphead_order_id=tohead_id)
AND (tohead_id=toitem_tohead_id)
AND (toitem_item_id=item_id)
+<? if exists("cust_id") ?>
+ AND FALSE
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND FALSE
+<? endif ?>
)
-- shipitem info
UNION
NULL AS f_shipvalue,
<? endif ?>
'' AS holdtype,
+ '' AS notes,
NULL AS shiphead_number_qtdisplayrole,
NULL AS ordertype_qtdisplayrole,
'qty' AS shipqty_xtnumericrole,
'cost' AS shipvalue_xtnumericrole,
0 AS shipvalue_xttotalrole,
2 AS xtindentrole,
- CAST(shiphead_id AS TEXT) || CAST(shiphead_order_id AS TEXT) ||
- TO_CHAR(shipitem_orderitem_id, '0000000') || '2' AS sort
+ shiphead_id AS seq1, shiphead_order_id AS seq2,
+ shipitem_orderitem_id AS seq3, shipitem_id AS seq4
FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
<? if exists("warehous_id") ?>
JOIN toitem ON ((shipitem_orderitem_id=toitem_id)
<? endif ?>
WHERE ((NOT shiphead_shipped)
AND (shiphead_order_type='TO')
+<? if exists("cust_id") ?>
+ AND FALSE
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND FALSE
+<? endif ?>
)
<? endif ?>
-ORDER BY sort;
+ORDER BY seq1, seq2, seq3, seq4, xtindentrole;
-- Group: manufacture
-- Name: jobcosting
-- Notes: used by dspJobCosting
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *, 0 AS cost_xttotalrole,
-- Group: metasqls
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists('byPackage') ?>
-- Group: mrpDetail
-- Name: detail
-- Notes: used by dspMRPDetail
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT formatQty(itemsite_qtyonhand) AS f_qoh,itemsite_qtyonhand
-- Group: mrpDetail
-- Name: item
-- Notes: used by dspMRPDetail
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, item_type, item_number,
-- Group: openVouchers
-- Name: populate
-- Notes: used by openVouchers
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT vohead_id, COALESCE(pohead_id, -1), vohead_number,
-- Group: openpurchaseorders
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-SELECT pohead_id, COALESCE(pohead_cohead_id, -1) AS pohead_cohead_id,
- pohead_number, vend_name,
- MIN(poitem_duedate) AS min_duedate,
- pohead_status, pohead_printed,
- vend_number, vendtype_code, pohead_agent_username
- FROM pohead
- JOIN vendinfo ON (pohead_vend_id=vend_id)
- JOIN vendtype ON (vend_vendtype_id=vendtype_id)
- <? if exists("pohead_agent_usr_id") ?>
- JOIN usr ON (pohead_agent_username=usr_username)
- <? endif ?>
- <? if exists("warehous_id") ?>
- JOIN poitem ON (poitem_pohead_id=pohead_id)
- JOIN itemsite ON (poitem_itemsite_id=itemsite_id)
- <? else ?>
- LEFT OUTER JOIN poitem ON (poitem_pohead_id=pohead_id)
- <? endif ?>
- WHERE ( true
- <? if exists("search_pattern") ?>
- AND ((pohead_number::text ~* <? value("search_pattern") ?>)
- OR (vend_number ~* <? value("search_pattern") ?>)
- OR (vend_name ~* <? value("search_pattern") ?>)
-
- OR (pohead_agent_username ~* <? value("search_pattern") ?>)
- OR (vendtype_code ~* <? value("search_pattern") ?>)
-
- OR (COALESCE(pohead_vend_cntct_first_name,'') || ' ' || COALESCE(pohead_vend_cntct_last_name,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_vend_cntct_phone,'') ||' ' || COALESCE(pohead_vend_cntct_fax,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_vend_cntct_email,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_vendaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_vendcity,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_vendstate,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_vendzipcode,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_vendcountry,'') ~* <? value("search_pattern") ?>)
-
- OR (COALESCE(pohead_shipto_cntct_first_name,'') || ' ' || COALESCE(pohead_shipto_cntct_last_name,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_shipto_cntct_phone,'') || ' ' || COALESCE(pohead_shipto_cntct_fax,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_shipto_cntct_email,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_shiptoaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_shiptocity,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_shiptostate,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_shiptozipcode,'') ~* <? value("search_pattern") ?>)
- OR (COALESCE(pohead_shiptocountry,'') ~* <? value("search_pattern") ?>)
- )
- <? endif ?>
- <? if exists("showUnreleased") ?>
- AND (pohead_status ='U')
- <? endif ?>
- <? if exists("showOpen") ?>
- AND (pohead_status='O' )
- <? endif ?>
- <? if exists("showBoth") ?>
- AND (pohead_status IN ('U', 'O') )
- <? endif ?>
- <? if exists("shownothing") ?>
- AND (pohead_status NOT IN ('U', 'O', 'C'))
- <? endif ?>
- <? if exists("vend_id") ?>
- AND (vend_id=<? value("vend_id") ?>)
- <? endif ?>
- <? if exists("vendtype_id") ?>
- AND (vend_vendtype_id=<? value("vendtype_id") ?>)
- <? endif ?>
- <? if exists("vendtype_pattern") ?>
- AND (vendtype_code ~* <? value("vendtype_pattern") ?>)
- <? endif ?>
- <? if exists("pohead_agent_usr_id") ?>
- AND (usr_id = <? value("pohead_agent_usr_id") ?>)
- <? endif ?>
- <? if exists("warehous_id") ?>
- AND (itemsite_warehous_id = <? value("warehous_id") ?>)
- <? endif ?>
- )
- GROUP BY pohead_number, pohead_id, pohead_cohead_id,
- vend_name, pohead_status, pohead_printed,
- vendtype_code, pohead_agent_username, vend_number
- ORDER BY pohead_number;
+SELECT DISTINCT
+ pohead_id AS id, COALESCE(pohead_cohead_id, -1) AS altid,
+ pohead.*,
+ calcPurchaseOrderDueDate(pohead_id) AS min_duedate,
+ calcPurchaseOrderAmt(pohead_id) AS order_total,
+ vend_name, vend_number, vendtype_code,
+<? foreach("char_id_text_list") ?>
+ charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,
+<? endforeach ?>
+ CASE WHEN(pohead_status='C') THEN <? value("closed") ?>
+ WHEN(pohead_status='U') THEN <? value("unposted") ?>
+ WHEN(pohead_status='O') THEN <? value("open") ?>
+ ELSE pohead_status
+ END AS pohead_status_qtdisplayrole,
+ 'currency' AS order_total_xtnumericrole
+FROM pohead
+ JOIN vendinfo ON (pohead_vend_id=vend_id)
+ JOIN vendtype ON (vend_vendtype_id=vendtype_id)
+<? if exists("pohead_agent_usr_id") ?>
+ JOIN usr ON (pohead_agent_username=usr_username)
+<? endif ?>
+<? if exists("warehous_id") ?>
+ JOIN poitem ON (poitem_pohead_id=pohead_id)
+ JOIN itemsite ON (poitem_itemsite_id=itemsite_id)
+<? endif ?>
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?>
+ ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='PO')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=pohead_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?>
+ ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='PO')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=pohead_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?>
+ ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='PO')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=pohead_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
+WHERE ( true
+<? if exists("search_pattern") ?>
+ AND ((pohead_number::text ~* <? value("search_pattern") ?>)
+ OR (vend_number ~* <? value("search_pattern") ?>)
+ OR (vend_name ~* <? value("search_pattern") ?>)
+ OR (pohead_agent_username ~* <? value("search_pattern") ?>)
+ OR (vendtype_code ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_vend_cntct_first_name,'') || ' ' || COALESCE(pohead_vend_cntct_last_name,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_vend_cntct_phone,'') ||' ' || COALESCE(pohead_vend_cntct_fax,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_vend_cntct_email,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_vendaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_vendcity,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_vendstate,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_vendzipcode,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_vendcountry,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_shipto_cntct_first_name,'') || ' ' || COALESCE(pohead_shipto_cntct_last_name,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_shipto_cntct_phone,'') || ' ' || COALESCE(pohead_shipto_cntct_fax,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_shipto_cntct_email,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_shiptoaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_shiptocity,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_shiptostate,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_shiptozipcode,'') ~* <? value("search_pattern") ?>)
+ OR (COALESCE(pohead_shiptocountry,'') ~* <? value("search_pattern") ?>)
+ )
+<? endif ?>
+<? if exists("showUnreleased") ?>
+ AND (pohead_status ='U')
+<? endif ?>
+<? if exists("showOpen") ?>
+ AND (pohead_status='O' )
+<? endif ?>
+<? if exists("showBoth") ?>
+ AND (pohead_status IN ('U', 'O') )
+<? endif ?>
+<? if exists("shownothing") ?>
+ AND (pohead_status NOT IN ('U', 'O', 'C'))
+<? endif ?>
+<? if exists("vend_id") ?>
+ AND (vend_id=<? value("vend_id") ?>)
+<? endif ?>
+<? if exists("vendtype_id") ?>
+ AND (vend_vendtype_id=<? value("vendtype_id") ?>)
+<? endif ?>
+<? if exists("vendtype_pattern") ?>
+ AND (vendtype_code ~* <? value("vendtype_pattern") ?>)
+<? endif ?>
+<? if exists("pohead_agent_usr_id") ?>
+ AND (usr_id = <? value("pohead_agent_usr_id") ?>)
+<? endif ?>
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+<? literal("charClause") ?>
+ )
+ORDER BY pohead_number;
-- Group: opensalesorders
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-SELECT DISTINCT cohead.*,
- COALESCE(cust_number, :error) AS cust_number,
- getSoSchedDate(cohead_id) AS scheddate,
- getSoStatus(cohead_id) AS status,
- firstline(cohead_ordercomments) AS notes
- FROM cohead
- JOIN custinfo ON (cohead_cust_id=cust_id)
- JOIN custtype ON (cust_custtype_id=custtype_id)
- <? if exists("selectedSites") ?>
- JOIN coitem ON (coitem_cohead_id=cohead_id)
- JOIN itemsite ON (coitem_itemsite_id=itemsite_id)
- JOIN site() ON (itemsite_warehous_id=warehous_id)
- <? elseif exists("warehous_id") ?>
- LEFT OUTER JOIN coitem ON (coitem_cohead_id=cohead_id)
- LEFT OUTER JOIN itemsite ON (coitem_itemsite_id=itemsite_id)
- LEFT OUTER JOIN whsinfo ON (itemsite_warehous_id=warehous_id)
- <? endif ?>
- WHERE((true)
- <? if exists("cust_id") ?>
- AND (cust_id=<? value("cust_id") ?> )
- <? endif ?>
- <? if exists("custtype_id") ?>
- AND (cust_custtype_id=<? value("custtype_id") ?>)
- <? endif ?>
- <? if exists("custtype_pattern") ?>
- AND (custtype_code ~* <? value("custtype_pattern") ?>)
- <? endif ?>
- <? if exists("poNumber") ?>
- AND (cohead_custponumber~*<? value("poNumber") ?>)
- <? endif ?>
- <? if exists("startDate") ?>
- AND (cohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
- <? endif ?>
- <? if not exists("showClosed") ?>
- AND (cohead_status='O')
- <? endif ?>
- <? if exists("warehous_id") ?>
- AND (warehous_id=<? value("warehous_id") ?>)
- <? endif ?>
- <? if exists("salesrep_id") ?>
- AND (cohead_salesrep_id=<? value("salesrep_id") ?>)
- <? endif ?>
- )
- ORDER BY cohead_number;
+SELECT DISTINCT
+ cohead.*,
+ COALESCE(cust_number, :error) AS cust_number,
+ getSoSchedDate(cohead_id) AS scheddate,
+ getSoStatus(cohead_id) AS status,
+<? foreach("char_id_text_list") ?>
+ charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,
+<? endforeach ?>
+ firstline(cohead_ordercomments) AS notes,
+ calcSalesOrderAmt(cohead_id) AS ordertotal,
+ CASE WHEN (calcSalesOrderAmt(cohead_id,'S') != 0.0)
+ THEN (calcSalesOrderAmt(cohead_id,'M') / calcSalesOrderAmt(cohead_id,'S'))
+ ELSE 1.0
+ END AS ordermarginpercent,
+ 'percent' AS ordermarginpercent_xtnumericrole,
+ 'extprice' AS ordertotal_xtnumericrole
+FROM cohead
+ JOIN custinfo ON (cohead_cust_id=cust_id)
+ JOIN custtype ON (cust_custtype_id=custtype_id)
+<? if exists("selectedSites") ?>
+ JOIN coitem ON (coitem_cohead_id=cohead_id)
+ JOIN itemsite ON (coitem_itemsite_id=itemsite_id)
+ JOIN site() ON (itemsite_warehous_id=warehous_id)
+<? elseif exists("warehous_id") ?>
+ LEFT OUTER JOIN coitem ON (coitem_cohead_id=cohead_id)
+ LEFT OUTER JOIN itemsite ON (coitem_itemsite_id=itemsite_id)
+ LEFT OUTER JOIN whsinfo ON (itemsite_warehous_id=warehous_id)
+<? endif ?>
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?>
+ ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?>
+ ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?>
+ ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
+WHERE((true)
+<? if exists("cust_id") ?>
+ AND (cust_id=<? value("cust_id") ?> )
+<? endif ?>
+<? if exists("custtype_id") ?>
+ AND (cust_custtype_id=<? value("custtype_id") ?>)
+<? endif ?>
+<? if exists("custtype_pattern") ?>
+ AND (custtype_code ~* <? value("custtype_pattern") ?>)
+<? endif ?>
+<? if exists("poNumber") ?>
+ AND (cohead_custponumber~*<? value("poNumber") ?>)
+<? endif ?>
+<? if exists("startDate") ?>
+ AND (cohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
+<? endif ?>
+<? if not exists("showClosed") ?>
+ AND (cohead_status='O')
+<? endif ?>
+<? if exists("warehous_id") ?>
+ AND (warehous_id=<? value("warehous_id") ?>)
+<? endif ?>
+<? if exists("salesrep_id") ?>
+ AND (cohead_salesrep_id=<? value("salesrep_id") ?>)
+<? endif ?>
+<? literal("charClause") ?>
+ )
+ORDER BY cohead_number;
-- Group: opportunities
-- Name: detail
-- Notes: used by opportunityList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT ON (incdtpriority_order, ophead_target_date, ophead_name, ophead_id)
ophead_target_date,
ophead_actual_date,
formatMoney(ophead_amount) AS f_amount,
+ formatMoney(COALESCE(ophead_amount,0) * COALESCE(ophead_probability_prcnt * 0.01)) AS f_value,
formatDate(ophead_target_date) AS f_targetdate,
formatDate(ophead_actual_date) AS f_actualdate,
'extprice' AS ophead_amount_xtnumericrole,
-- Group: opportunitiesByCRM
-- Name: detail
-- Notes: used by crmaccount
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT ophead_id, *,
-- Group: orderActivityByProject
-- Name: detail
--- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+-- Notes: All projects
SELECT *,
formatQty(qty) AS f_qty,
formatMoney(value) AS f_value,
'curr' AS qty_xtnumericrole,
- 'curr' AS value_xtnumericrole
+ 'curr' AS value_xtnumericrole,
+ CASE WHEN COALESCE(hrs_balance,0) < 0 THEN 'red' END AS hrs_balance_qtforegroundrole,
+ CASE WHEN COALESCE(exp_balance,0) < 0 THEN 'red' END AS exp_balance_qtforegroundrole
FROM (
+SELECT prj_id AS id,
+ 1 AS type,
+ '0' AS subtype,
+ 0 AS section,
+ NULL AS section_qtdisplayrole,
+ prj_number AS name,
+ CASE
+ WHEN prj_status = 'C' THEN <? value('complete') ?>
+ WHEN prj_status = 'O' THEN <? value('inprocess') ?>
+ WHEN prj_status = 'P' THEN <? value('planning') ?>
+ END AS status,
+ prjtype_code AS project_type,
+ prj_name AS item,
+ firstline(prj_descrip) AS descrip,
+ crmacct_name AS customer,
+ cntct_name AS contact,
+ addr_city AS city,
+ addr_state AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ prj_due_date AS due,
+ prj_assigned_date AS assigned,
+ prj_start_date AS started,
+ prj_completed_date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+ CASE WHEN (prj_status = 'O' AND prj_due_date < current_date) THEN 'red'
+ WHEN (prj_status = 'O' AND prj_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange'
+ END AS due_qtforegroundrole,
+ 0 AS xtindentrole
+ FROM prj
+ LEFT OUTER JOIN prjtype ON (prj_prjtype_id=prjtype_id)
+ LEFT OUTER JOIN crmacct ON (prj_crmacct_id=crmacct_id)
+ LEFT OUTER JOIN cntct ON (crmacct_cntct_id_1=cntct_id)
+ LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (prj_id = <? value("prj_id") ?> )
+
+UNION ALL
+----- TASKS -----
+SELECT DISTINCT -1 AS id,
+ 3 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ 'Tasks' AS section_qtdisplayrole,
+ 'Tasks' AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+
+UNION ALL
+
+SELECT prjtask_id AS id,
+ 5 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ NULL AS section_qtdisplayrole,
+ prjtask_number AS name,
+ CASE
+ WHEN prjtask_status = 'C' THEN <? value('complete') ?>
+ WHEN prjtask_status = 'O' THEN <? value('inprocess') ?>
+ WHEN prjtask_status = 'P' THEN <? value('planning') ?>
+ END AS status,
+ NULL::text AS project_type,
+ prjtask_name AS item,
+ prjtask_descrip AS descrip,
+ cust_name as customer,
+ cntct_name AS contact,
+ addr_city AS city,
+ addr_state AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ prjtask_due_date AS due,
+ prjtask_assigned_date AS assigned,
+ prjtask_start_date AS started,
+ prjtask_completed_date AS completed,
+ prjtask_hours_budget AS hrs_budget,
+ prjtask_hours_actual AS hrs_actual,
+ (prjtask_hours_budget-prjtask_hours_actual) AS hrs_balance,
+ prjtask_exp_budget AS exp_budget,
+ prjtask_exp_actual AS exp_actual,
+ (prjtask_exp_budget-prjtask_exp_actual) AS exp_balance,
+ CASE WHEN (prjtask_status = 'O' AND prjtask_due_date < current_date) THEN 'red'
+ WHEN (prjtask_status = 'O' AND prjtask_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange'
+ END AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM prjtask
+ LEFT OUTER JOIN te.teprjtask ON (prjtask_id = teprjtask_prjtask_id)
+ LEFT OUTER JOIN custinfo ON (teprjtask_cust_id=cust_id)
+ LEFT OUTER JOIN cntct ON (cust_corrcntct_id=cntct_id)
+ LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (prjtask_prj_id = <? value("prj_id") ?> )
+ GROUP BY custinfo.cust_name, prjtask.prjtask_id, addr.addr_city, addr.addr_state, cntct_name
+
+<? if exists("showIn") ?>
+UNION ALL
+----- INCIDENTS -----
+
+SELECT DISTINCT -1 AS id,
+ 100 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ 'Incidents' AS section_qtdisplayrole,
+ 'Incidents' AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM incdt
+UNION ALL
+
+SELECT incdt_id AS id,
+ 105 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ NULL AS section_qtdisplayrole,
+ incdt_number::text AS name,
+ CASE
+ WHEN incdt_status = 'L' THEN <? value('closed') ?>
+ WHEN incdt_status = 'N' THEN <? value('new') ?>
+ WHEN incdt_status = 'F' THEN <? value('feedback') ?>
+ WHEN incdt_status = 'A' THEN <? value('assigned') ?>
+ WHEN incdt_status = 'R' THEN <? value('resolved') ?>
+ WHEN incdt_status = 'C' THEN <? value('confirmed') ?>
+ END AS status,
+ NULL::text AS project_type,
+ incdt_number::text AS item,
+ incdt_summary AS descrip,
+ crmacct_number AS customer,
+ crmacct_name AS contact,
+ addr_city AS city,
+ addr_state AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM incdt
+ LEFT OUTER JOIN crmacct ON (incdt_crmacct_id=crmacct_id)
+ LEFT OUTER JOIN cntct ON (incdt_cntct_id=cntct_id)
+ LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (incdt_prj_id = <? value("prj_id") ?> )
+ 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
+<? endif ?>
+
<? if exists("showSo") ?>
+UNION ALL
+
----- QUOTES -----
SELECT DISTINCT -1 AS id,
10 AS type,
<? value("quotes") ?> AS section_qtdisplayrole,
<? value("quotes") ?> AS name,
NULL::text AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL::numeric AS qty,
NULL::text AS uom,
- NULL::numeric AS value,
- 0 AS xtindentrole
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
FROM quhead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=quhead_prj_id
ELSE
<? value("expired") ?>
END AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ cust_name AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
NULL AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM quhead
+ JOIN custinfo ON (quhead_cust_id=cust_id)
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=quhead_prj_id
AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))
<? if exists("owner_username") ?>
AND (quhead_owner_username=<? value("owner_username") ?>)
<? endif ?>
-GROUP BY quhead_id, quhead_number, quhead_status, quhead_expire, quhead_freight, quhead_misc
+GROUP BY quhead_id, quhead_number, quhead_status, quhead_expire, quhead_freight, quhead_misc, custinfo.cust_name
UNION ALL
ELSE
<? value("Expired") ?>
END AS status,
+ NULL::text AS project_type,
item_number AS item,
item_descrip1 || ' ' || item_descrip2 AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
quitem_qtyord,
uom_name AS uom,
(quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio) AS value,
- 2 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 3 AS xtindentrole
FROM quhead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=quhead_prj_id
<? value("quotes") ?> AS section_qtdisplayrole,
<? value("total") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM quhead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=quhead_prj_id
<? value("quotes") ?> AS section_qtdisplayrole,
<? value("total") ?> || ' ' || <? value("quotes") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM quhead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=quhead_prj_id
<? value("sos") ?> AS section_qtdisplayrole,
<? value("sos") ?> AS name,
NULL::text AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL::numeric AS qty,
NULL::text AS uom,
NULL::numeric AS value,
- 0 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
FROM cohead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=cohead_prj_id
ORDER BY type
LIMIT 1) AS sts) ,'O')
AS status,
- NULL::text AS item,
- NULL::text AS descrip,
+ NULL::text AS project_type,
+ shipto_num AS item,
+ shipto_name AS descrip,
+ cust_name AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
NULL AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM cohead
+ JOIN custinfo ON (cust_id = cohead_cust_id)
+ LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=cohead_prj_id
AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))
<? endif ?>
JOIN coitem ON (coitem_cohead_id = cohead_id)
WHERE (cohead_prj_id = <? value("prj_id") ?>)
-GROUP BY cohead_id, cohead_number
+GROUP BY cohead_id, cohead_number, shipto_num, shipto_name, cust_name
UNION ALL
WHEN (coitem_status = 'X') THEN
<? value("canceled") ?>
END AS status,
+ NULL::text AS project_type,
item_number AS item,
item_descrip1 || ' ' || item_descrip2 AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
coitem_qtyord,
uom_name AS uom,
(coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio) AS value,
- 2 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 3 AS xtindentrole
FROM cohead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=cohead_prj_id
<? value("sos") ?> AS section_qtdisplayrole,
<? value("total") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM cohead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=cohead_prj_id
<? value("sos") ?> AS section_qtdisplayrole,
<? value("total") ?> || ' ' || <? value("sos") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM cohead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=cohead_prj_id
<? value("invoices") ?> AS section_qtdisplayrole,
<? value("invoices") ?> AS name,
NULL::text AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL::numeric AS qty,
NULL::text AS uom,
NULL::numeric AS value,
- 0 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
FROM invchead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=invchead_prj_id
<? value("posted") ?>
ELSE <? value("unposted") ?>
END AS status,
- NULL::text AS item,
- NULL::text AS descrip,
+ NULL::text AS project_type,
+ shipto_num AS item,
+ shipto_name AS descrip,
+ cust_name AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
NULL AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM invchead
+ JOIN custinfo ON (cust_id=invchead_cust_id)
+ LEFT OUTER JOIN shiptoinfo ON (invchead_shipto_id = shipto_id)
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=invchead_prj_id
AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))
<? endif ?>
JOIN invcitem ON (invcitem_invchead_id = invchead_id)
WHERE (invchead_prj_id = <? value("prj_id") ?>)
-GROUP BY invchead_id, invchead_invcnumber, invchead_freight, invchead_misc_amount, invchead_posted
+GROUP BY invchead_id, invchead_invcnumber, shipto_num, shipto_name, invchead_freight, invchead_misc_amount, invchead_posted, cust_name
UNION ALL
<? value("posted") ?>
ELSE <? value("unposted") ?>
END AS status,
+ NULL::text AS project_type,
COALESCE(item_number,invcitem_number) AS item,
COALESCE(item_descrip1 || ' ' || item_descrip2,invcitem_descrip) AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
invcitem_billed AS qty,
uom_name AS uom,
(invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio) AS value,
- 2 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 3 AS xtindentrole
FROM invchead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=invchead_prj_id
<? value("invoices") ?> AS section_qtdisplayrole,
<? value("total") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM invchead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=invchead_prj_id
<? value("invoices") ?> AS section_qtdisplayrole,
<? value("total") ?> || ' ' || <? value("invoices") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM invchead
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=invchead_prj_id
<? if exists("showWo") ?>
-
-<? if exists("showSo") ?>
-
UNION ALL
-<? endif ?>
-
------ WORK ORDERS -------
SELECT DISTINCT -1 AS id,
40 AS type,
<? value("wos") ?> AS section_qtdisplayrole,
<? value("wos") ?> AS name,
NULL::text AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL::numeric AS qty,
NULL::text AS uom,
NULL::numeric AS value,
- 0 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
FROM wo
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=wo_prj_id
WHEN (wo_status = 'C') THEN
<? value("closed") ?>
END AS status,
+ NULL::text AS project_type,
item_number AS item,
item_descrip1 || ' ' || item_descrip2 AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
wo_qtyord AS qty,
uom_name AS uom,
wo_postedvalue AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM wo
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=wo_prj_id
<? value("wos") ?> AS section_qtdisplayrole,
<? value("total") ?> || ' ' || <? value("wos") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM(wo_postedvalue) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM wo
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=wo_prj_id
<? if exists("showPo") ?>
-<? if exists("showSo") ?>
- UNION ALL
-<? elseif exists("showWo") ?>
UNION ALL
-<? endif ?>
------ PURCHASE REQUESTS ------
SELECT DISTINCT -1 AS id,
50 AS type,
<? value("prs") ?> AS section_qtdisplayrole,
<? value("prs") ?> AS name,
NULL::text AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL::numeric AS qty,
NULL::text AS uom,
NULL::numeric AS value,
- 0 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
FROM pr
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=pr_prj_id
<? value("prs") ?> AS section_qtdisplayrole,
pr_number::text || '-' || pr_subnumber::text AS name,
<? value("open") ?> AS status,
+ NULL::text AS project_type,
item_number AS item,
(item_descrip1 || ' ' || item_descrip2) AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
pr_qtyreq AS qty,
uom_name AS uom,
stdcost(item_id) * pr_qtyreq AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM pr
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=pr_prj_id
<? value("prs") ?> AS section_qtdisplayrole,
<? value("total") ?> || ' ' || <? value("prs") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM(stdcost(item_id) * pr_qtyreq) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM pr
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=pr_prj_id
<? value("pos") ?> AS section_qtdisplayrole,
<? value("pos") ?> AS name,
NULL::text AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL::numeric AS qty,
NULL::text AS uom,
NULL::numeric AS value,
- 0 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
FROM poitem
<? if exists("owner_username") ?>
JOIN prj ON (prj_id=poitem_prj_id
WHEN (pohead_status = 'C') THEN
<? value("closed") ?>
END AS status,
- NULL::text AS item,
+ NULL::text AS project_type,
+ NULL AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL AS uom,
NULL AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM pohead
JOIN poitem ON (poitem_pohead_id = pohead_id)
<? if exists("owner_username") ?>
WHEN (poitem_status = 'C') THEN
<? value("closed") ?>
END AS status,
+ NULL::text AS project_type,
COALESCE(item_number,poitem_vend_item_number) AS item,
COALESCE((item_descrip1 || ' ' || item_descrip2),poitem_vend_item_descrip) AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
poitem_qty_ordered,
poitem_vend_uom AS uom,
(poitem_qty_ordered * poitem_unitprice) AS value,
- 2 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 3 AS xtindentrole
FROM pohead
JOIN poitem ON (poitem_pohead_id = pohead_id)
<? if exists("owner_username") ?>
<? value("pos") ?> AS section_qtdisplayrole,
<? value("total") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM(poitem_qty_ordered * poitem_unitprice) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM pohead
JOIN poitem ON (poitem_pohead_id = pohead_id)
<? if exists("owner_username") ?>
<? value("sos") ?> AS section_qtdisplayrole,
<? value("total") ?> || ' ' || <? value("pos") ?> AS name,
NULL AS status,
+ NULL::text AS project_type,
NULL::text AS item,
NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
NULL AS qty,
NULL::text AS uom,
SUM(poitem_qty_ordered * poitem_unitprice) AS value,
- 1 AS xtindentrole
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
FROM pohead
JOIN poitem ON (poitem_pohead_id = pohead_id)
<? if exists("owner_username") ?>
-- Group: orders
-- Name: detail
-- Notes: used by dspOrders
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT source_id, type, order_type, order_status, order_number, duedate,
-- and tables so we never miss anything and do not have to maintain the
-- data
-- TODO: is there a better sort order?
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
-- Group: packingList
-- Name: getreport
-- Notes: get the reportname should be used for a packing list or pick list
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists('sohead_id') ?>
-- Group: packingList
-- Name: shipment
-- Notes: used by printPackingList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT shiphead_order_id, shiphead_order_type, shiphead_shipform_id, cohead_number AS number
--- /dev/null
+-- Group: packingListBatch
+-- Name: clear
+-- Notes: used by packingListBatch
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+
+DELETE FROM pack WHERE pack_id IN
+ (SELECT pack_id
+ FROM pack JOIN cohead ON (cohead_id=pack_head_id)
+ JOIN coitem ON (coitem_cohead_id=cohead_id)
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+ WHERE ( (checkSOSitePrivs(cohead_id))
+ AND (pack_head_type='SO')
+ AND (pack_printed)
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
+ );
+
+<? if exists("MultiWhs") ?>
+DELETE FROM pack WHERE pack_id IN
+ (SELECT pack_id
+ FROM pack JOIN tohead ON (tohead_id=pack_head_id)
+ WHERE ( (pack_head_type='TO')
+ AND (pack_printed)
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
+ );
+<? endif ?>
-- Group: packingListBatch
-- Name: detail
-- Notes: used by packingListBatch
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-SELECT cohead_id, pack_shiphead_id,
+SELECT DISTINCT
+ cohead_id, pack_shiphead_id,
cohead_number AS order_number, pack_head_type,
cohead_shipvia AS shipvia,
formatShipmentNumber(pack_shiphead_id) AS shipment_number,
ELSE <? value("other") ?>
END AS f_holdtype,
pack_printed
-FROM pack, cohead, custinfo
-WHERE pack_head_id=cohead_id
- AND cohead_cust_id=cust_id
- AND pack_head_type='SO'
+FROM pack JOIN cohead ON (cohead_id=pack_head_id)
+ JOIN custinfo ON (cust_id=cohead_cust_id)
+ JOIN coitem ON (coitem_cohead_id=cohead_id)
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+WHERE ( (pack_head_type='SO')
+ AND (checkSOSitePrivs(cohead_id))
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
+
<? if exists("MultiWhs") ?>
- AND checkSOSitePrivs(cohead_id)
-UNION
+UNION ALL
SELECT tohead_id, pack_shiphead_id,
tohead_number AS order_number, pack_head_type,
tohead_shipvia AS shipvia,
tohead_destname AS number, tohead_destcntct_name AS name,
'' AS f_holdtype,
pack_printed
-FROM pack, tohead
-WHERE ((pack_head_id=tohead_id)
- AND (pack_head_type='TO'))
+FROM pack JOIN tohead ON (tohead_id=pack_head_id)
+WHERE ( (pack_head_type='TO')
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
<? endif ?>
ORDER BY 3;
-- Group: packingListBatch
-- Name: print
-- Notes: used by packingListBatch
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-SELECT pack_id, pack_head_id, pack_head_type, pack_shiphead_id,
+SELECT DISTINCT
+ pack_id, pack_head_id, pack_head_type, pack_shiphead_id,
COALESCE(shipform_report_name, findCustomerForm(cohead_cust_id, 'P')) AS packform,
findCustomerForm(cohead_cust_id, 'L') AS pickform
FROM pack JOIN cohead ON (cohead_id=pack_head_id)
+ JOIN coitem ON (coitem_cohead_id=cohead_id)
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
LEFT OUTER JOIN shipform ON (shipform_id=cohead_shipform_id)
-WHERE ((checkSOSitePrivs(cohead_id))
- AND (pack_head_type='SO')
- AND (NOT pack_printed) )
+WHERE ( (checkSOSitePrivs(cohead_id))
+ AND (pack_head_type='SO')
+ AND (NOT pack_printed)
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
+
<? if exists("MultiWhs") ?>
-UNION
+UNION ALL
SELECT pack_id, pack_head_id, pack_head_type, pack_shiphead_id,
COALESCE(shipform_report_name, findTOForm(tohead_id, 'P')) AS packform,
findTOForm(tohead_id, 'L') AS pickform
FROM pack JOIN tohead ON (tohead_id=pack_head_id)
LEFT OUTER JOIN shipform ON (shipform_id=tohead_shipform_id)
-WHERE ((pack_head_type='TO')
- AND (NOT pack_printed))
+WHERE ( (pack_head_type='TO')
+ AND (NOT pack_printed)
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
<? endif ?>
;
-- Group: packingListBatchByShipVia
-- Name: print
-- Notes: used by printPackingListBatchByShipVia
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT pack_head_id, pack_head_type, pack_shiphead_id, getSoStatus(cohead_id) AS orderhead_status,
COALESCE(shipform_report_name, findCustomerForm(cohead_cust_id, 'P')) AS packform,
findCustomerForm(cohead_cust_id, 'L') AS pickform
FROM pack JOIN cohead ON (cohead_id=pack_head_id)
- JOIN coitem ON (coitem_cohead_id = cohead_id)
+ JOIN coitem ON (coitem_cohead_id=cohead_id)
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
LEFT OUTER JOIN shipform ON (shipform_id=cohead_shipform_id)
WHERE ( (NOT pack_printed)
AND (pack_head_type='SO')
AND (getSoStatus(cohead_id) <> 'C')
+<? if exists("shipvia") ?>
AND (cohead_shipvia=<? value("shipvia") ?>)
+<? endif ?>
AND (checkSOSitePrivs(cohead_id))
- AND (coitem_scheddate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) )
+ AND (coitem_scheddate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
<? if exists("MultiWhs") ?>
UNION ALL
WHERE ( (NOT pack_printed)
AND (pack_head_type='TO')
AND (tohead_status <> 'C')
+<? if exists("shipvia") ?>
AND (tohead_shipvia=<? value("shipvia") ?>)
- AND (toitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) )
+<? endif ?>
+ AND (toitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
<? endif ?>
;
-- Group: packingListBatchByShipVia
-- Name: shipVia
-- Notes: used by printPackingListBatchByShipVia
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT max(id), shipvia
FROM (
SELECT max(cohead_id) AS id, cohead_shipvia AS shipvia
-FROM pack, cohead, coitem
+FROM pack JOIN cohead ON (cohead_id=pack_head_id)
+ JOIN coitem ON (coitem_cohead_id=cohead_id AND coitem_status='O')
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
WHERE ( (NOT pack_printed)
- AND (cohead_id=pack_head_id)
AND (pack_head_type='SO')
- AND (coitem_cohead_id=cohead_id)
- AND (coitem_status='O') )
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
GROUP BY cohead_shipvia
<? if exists("MultiWhs") ?>
UNION
SELECT max(tohead_id) AS id, tohead_shipvia AS shipvia
-FROM pack, tohead
+FROM pack JOIN tohead ON (tohead_id=pack_head_id AND tohead_status='O')
WHERE ( (NOT pack_printed)
- AND (tohead_status = 'O')
- AND (tohead_id=pack_head_id)
- AND (pack_head_type='TO') )
+ AND (pack_head_type='TO')
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+ )
GROUP BY tohead_shipvia
<? endif ?>
) data
-- Group: partiallyShippedOrders
-- Name: detail
-- Notes: used by dspPartiallyShippedOrders
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT CASE WHEN (cohead_holdtype IN ('P', 'C', 'R')) THEN -1
-- Group: pendingAvailability
-- Name: detail
-- Notes: used by dspPendingAvailability
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("showIndented") ?>
-- Group: pendingBOMChanges
-- Name: detail
-- Notes: used by dspPendingBOMChanges
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT bomitem_id, actiondate, action,
-- Group: poDeliveryDateVariances
-- Name: detail
-- Notes: used by dspPoDeliveryDateVariancesByItem, dspPoDeliveryDateVariancesByVendor
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT <? if exists("byItem") ?>
-- Group: poHistory
-- Name: detail
-- Notes: used by dspPoHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT poitem_id, poitem.*,
-- Group: poItems
-- Name: detail
-- Notes: used by dspPoItemsByVendor, dspPoItemsByItem, dspPoItemsByDate
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT pohead_id, poitem_id, pohead_number, poitem_status,
-- Group: poItems
-- Name: list
-- Notes: used by purchaseOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT poitem.*,
CASE WHEN(poitem_status='C') THEN <? value("closed") ?>
CASE WHEN (itemsite_id IS NULL) THEN firstLine(poitem_vend_item_descrip)
ELSE (item_descrip1 || ' ' || item_descrip2)
END AS item_descrip,
+ contrct_number,
poitem_rlsd_duedate AS orgl_duedate,
(poitem_unitprice * poitem_qty_ordered) AS extprice,
CASE WHEN(poitem_status='C') THEN <? value("closed") ?>
LEFT OUTER JOIN item ON (itemsite_item_id=item_id)
LEFT OUTER JOIN coitem ON (poitem_order_type='S' AND poitem_order_id = coitem_id)
LEFT OUTER JOIN womatl ON (poitem_order_type='W' AND poitem_order_id = womatl_id)
+ LEFT OUTER JOIN itemsrc ON (poitem_itemsrc_id=itemsrc_id)
+ LEFT OUTER JOIN contrct ON (itemsrc_contrct_id=contrct_id)
WHERE (poitem_pohead_id=<? value("pohead_id") ?>)
ORDER BY poitem_linenumber;
-- Group: poPriceVariances
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *
-- Group: poReturns
-- Name: detail
-- Notes: used by dspPoReturnsByVendor
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT poreject_id, poreject_ponumber, vend_name,
-- Group: postCountTags
-- Name: post
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT MIN(postCountTag(invcnt_id, <? value('thaw') ?>)) AS result
-- Group: postJournals
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *
-- Group: postJournals
-- Name: post
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *
-- Then the outer query modifies the sourcecode to indicate
-- item vs product category.
-- TODO: possible improvements include removing OUTER JOINs with uom table
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT sourcecode + CASE WHEN source='P' THEN 10 ELSE 0 END AS source,
ELSE ipsitem_qtybreak
END AS invqty,
ipsitem_qtybreak AS qtybreak,
- CASE WHEN ipsitem_type = 'N' THEN (ipsitem_price * itemuomtouomratio(<? value('item_id') ?>, NULL, ipsitem_price_uom_id)) *
- iteminvpricerat(ipsitem_item_id)
- WHEN ipsitem_type = 'D' THEN noNeg(<? value('item_listprice') ?> - (<? value('item_listprice') ?> * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
- WHEN ipsitem_type = 'M' THEN (<? value('item_listcost') ?> + (<? value('item_listcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+ CASE WHEN (ipsitem_type = 'N') THEN
+ (ipsitem_price * itemuomtouomratio(<? value('item_id') ?>, NULL, ipsitem_price_uom_id)) * iteminvpricerat(ipsitem_item_id)
+ WHEN (ipsitem_type = 'D') THEN
+ noNeg(<? value('item_listprice') ?> - (<? value('item_listprice') ?> * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+ WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN
+ (<? value('item_unitcost') ?> / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+ WHEN (ipsitem_type = 'M') THEN
+ (<? value('item_unitcost') ?> + (<? value('item_unitcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
ELSE 0.00
END AS price,
ipsitem_qty_uom_id AS qtybreak_uom_id,
CASE WHEN ipsitem_type = 'N' THEN (ipsitem_price * itemuomtouomratio(<? value('item_id') ?>, NULL, ipsitem_price_uom_id)) *
iteminvpricerat(ipsitem_item_id)
WHEN ipsitem_type = 'D' THEN noNeg(<? value('item_listprice') ?> - (<? value('item_listprice') ?> * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
- WHEN ipsitem_type = 'M' THEN (<? value('item_listcost') ?> + (<? value('item_listcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+ WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN
+ (<? value('item_unitcost') ?> / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+ WHEN (ipsitem_type = 'M') THEN
+ (<? value('item_unitcost') ?> + (<? value('item_unitcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
ELSE 0.00
END AS price,
ipsitem_qty_uom_id AS qtybreak_uom_id,
-- Group: prices
-- Name: detail
-- Notes: used by dspPricesByCustomerType, dspPricesByCustomer, dspPricesByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemid, sourcetype, schedulename, type,
<? if exists("byCustomer") ?>
AND (item_price_uom_id=uom_id)
AND (ipsass_cust_id=<? value("cust_id") ?>)
+ <? if exists("item_id") ?>
+ AND (item_id=<? value("item_id") ?>)
+ <? endif ?>
<? else ?>
AND (ipsass_cust_id=cust_id)
AND (item_id=<? value("item_id") ?>)
<? elseif exists("byCustomer") ?>
AND (ipsass_custtype_id=cust_custtype_id)
AND (cust_id=<? value("cust_id") ?>)
+ <? if exists("item_id") ?>
+ AND (item_id=<? value("item_id") ?>)
+ <? endif ?>
<? else ?>
AND (ipsass_custtype_id=custtype_id)
AND (item_id=<? value("item_id") ?>)
AND (custtype_id=<? value("custtype_id") ?>)
<? elseif exists("byCustomer") ?>
AND (cust_id=<? value("cust_id") ?>)
+ <? if exists("item_id") ?>
+ AND (item_id=<? value("item_id") ?>)
+ <? endif ?>
<? else ?>
AND (item_id=<? value("item_id") ?>)
<? endif ?>
AND (NOT item_exclusive)
<? if exists("byCustomer") ?>
AND (cust_id=<? value("cust_id") ?>)
+ <? if exists("item_id") ?>
+ AND (item_id=<? value("item_id") ?>)
+ <? endif ?>
<? endif ?>
)
) AS data
-- Group: pricingFreight
-- Name: detail
-- Notes: used by itemPricingScheduleItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT ipsfreight.*
-- Group: projectTasks
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT prjtask_id, prjtask_number, prjtask_name,
-- Group: projects
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
-
-SELECT prj_id AS id, prj_number, prj_name, prj_descrip,
- prj_start_date, prj_due_date, prj_assigned_date, prj_completed_date,
- CASE WHEN(prj_status='P') THEN <? value("planning") ?>
- WHEN(prj_status='O') THEN <? value("open") ?>
- WHEN(prj_status='C') THEN <? value("complete") ?>
- ELSE <? value("undefined") ?>
- END AS prj_status,
- prj_username, prj_owner_username,
- crmacct_number, formatCntctName(prj_cntct_id) AS contact_name,
- COALESCE(SUM(prjtask_hours_budget), 0.0) AS budget_hrs,
- COALESCE(SUM(prjtask_hours_actual), 0.0) AS actual_hrs,
- COALESCE(SUM(prjtask_hours_budget - prjtask_hours_actual), 0.0) AS balance_hrs,
- CASE WHEN COALESCE(SUM(prjtask_hours_budget - prjtask_hours_actual), 0.0) < 0 THEN
- 'error' END AS balance_hrs_qtforegroundrole,
- 'qty' AS budget_hrs_xtnumericrole,
- 'qty' AS actual_hrs_xtnumericrole,
- 'qty' AS balance_hrs_xtnumericrole
-FROM prj()
- LEFT OUTER JOIN prjtask ON (prj_id=prjtask_prj_id)
- LEFT OUTER JOIN crmacct ON (crmacct_id=prj_crmacct_id)
+-- Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+--
+-- xTuple version 4.2.0 - Modified to significantly amend the display of this screen and its filters.
+-- xTuple version 4.3.0 - Add Incidents to hierarchy display
+SELECT *,
+ formatQty(qty) AS f_qty,
+ formatMoney(value) AS f_value,
+ 'curr' AS qty_xtnumericrole,
+ 'curr' AS value_xtnumericrole,
+ CASE WHEN COALESCE(hrs_balance,0) < 0 THEN 'red' END AS hrs_balance_qtforegroundrole,
+ CASE WHEN COALESCE(exp_balance,0) < 0 THEN 'red' END AS exp_balance_qtforegroundrole
+FROM (
+SELECT prj_id AS id,
+ 1 AS type,
+ '0' AS subtype,
+ 0 AS section,
+ prj_id AS project,
+ NULL AS section_qtdisplayrole,
+ prj_number AS name,
+ CASE
+ WHEN prj_status = 'C' THEN <? value('complete') ?>
+ WHEN prj_status = 'O' THEN <? value('inprocess') ?>
+ WHEN prj_status = 'P' THEN <? value('planning') ?>
+ END AS status,
+ COALESCE(prjtype_descr, 'Undefined') AS project_type,
+ prj_username,
+ prj_owner_username,
+ prj_name AS item,
+ firstline(prj_descrip) AS descrip,
+ crmacct_name AS customer,
+ cntct_name AS contact,
+ addr_city AS city,
+ addr_state AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ prj_due_date AS due,
+ prj_assigned_date AS assigned,
+ prj_start_date AS started,
+ prj_completed_date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+ CASE WHEN (prj_status = 'O' AND prj_due_date < current_date) THEN 'red'
+ WHEN (prj_status = 'O' AND prj_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange'
+ END AS due_qtforegroundrole,
+ 0 AS xtindentrole
+ FROM prj()
+ LEFT OUTER JOIN prjtype ON (prj_prjtype_id=prjtype_id)
+ LEFT OUTER JOIN crmacct ON (prj_crmacct_id=crmacct_id)
+ LEFT OUTER JOIN cntct ON (crmacct_cntct_id_1=cntct_id)
+ LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (1=1 )
+
+UNION ALL
+----- TASKS -----
+SELECT DISTINCT -1 AS id,
+ 3 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ prjtask_prj_id AS project,
+ <? value('tasks') ?> AS section_qtdisplayrole,
+ <? value('tasks') ?> AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM prjtask
+UNION ALL
+
+SELECT prjtask_id AS id,
+ 5 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ prjtask_prj_id AS project,
+ NULL AS section_qtdisplayrole,
+ prjtask_number AS name,
+ CASE
+ WHEN prjtask_status = 'C' THEN <? value('complete') ?>
+ WHEN prjtask_status = 'O' THEN <? value('inprocess') ?>
+ WHEN prjtask_status = 'P' THEN <? value('planning') ?>
+ END AS status,
+ NULL::text AS project_type,
+ prjtask_username AS prj_username,
+ prjtask_owner_username AS prj_owner_username,
+ prjtask_name AS item,
+ prjtask_descrip AS descrip,
+ cust_name as customer,
+ cntct_name AS contact,
+ addr_city AS city,
+ addr_state AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ prjtask_due_date AS due,
+ prjtask_assigned_date AS assigned,
+ prjtask_start_date AS started,
+ prjtask_completed_date AS completed,
+ prjtask_hours_budget AS hrs_budget,
+ prjtask_hours_actual AS hrs_actual,
+ (prjtask_hours_budget-prjtask_hours_actual) AS hrs_balance,
+ prjtask_exp_budget AS exp_budget,
+ prjtask_exp_actual AS exp_actual,
+ (prjtask_exp_budget-prjtask_exp_actual) AS exp_balance,
+ CASE WHEN (prjtask_status = 'O' AND prjtask_due_date < current_date) THEN 'red'
+ WHEN (prjtask_status = 'O' AND prjtask_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange'
+ END AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM prjtask
+ LEFT OUTER JOIN te.teprjtask ON (prjtask_id = teprjtask_prjtask_id)
+ LEFT OUTER JOIN custinfo ON (teprjtask_cust_id=cust_id)
+ LEFT OUTER JOIN cntct ON (cust_corrcntct_id=cntct_id)
+ LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (1=1 )
+ 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
+
+<? if exists("showIn") ?>
+
+UNION ALL
+----- INCIDENTS -----
+SELECT DISTINCT -1 AS id,
+ 100 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ incdt_prj_id AS project,
+ 'Incidents' AS section_qtdisplayrole,
+ 'Incidents' AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM incdt
+UNION ALL
+
+SELECT incdt_id AS id,
+ 105 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ incdt_prj_id AS project,
+ NULL AS section_qtdisplayrole,
+ incdt_number::text AS name,
+ CASE
+ WHEN incdt_status = 'L' THEN <? value('closed') ?>
+ WHEN incdt_status = 'N' THEN <? value('new') ?>
+ WHEN incdt_status = 'F' THEN <? value('feedback') ?>
+ WHEN incdt_status = 'A' THEN <? value('assigned') ?>
+ WHEN incdt_status = 'R' THEN <? value('resolved') ?>
+ WHEN incdt_status = 'C' THEN <? value('confirmed') ?>
+ END AS status,
+ NULL::text AS project_type,
+ incdt_assigned_username AS prj_username,
+ incdt_owner_username AS prj_owner_username,
+ incdt_number::text AS item,
+ incdt_summary AS descrip,
+ crmacct_number AS customer,
+ crmacct_name AS contact,
+ addr_city AS city,
+ addr_state AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM incdt
+ LEFT OUTER JOIN crmacct ON (incdt_crmacct_id=crmacct_id)
+ LEFT OUTER JOIN cntct ON (incdt_cntct_id=cntct_id)
+ LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (1=1 )
+ 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
+<? endif ?>
+
+<? if exists("showSo") ?>
+UNION ALL
+
+----- QUOTES -----
+SELECT DISTINCT -1 AS id,
+ 10 AS type,
+ '0' AS subtype,
+ 1 AS section,
+ prj_id AS project,
+ <? value("quotes") ?> AS section_qtdisplayrole,
+ <? value("quotes") ?> AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM quhead
+ JOIN prj() ON (quhead_prj_id=prj_id)
+ WHERE (1=1)
+UNION ALL
+
+SELECT quhead_id AS id,
+ 15 AS type,
+ quhead_number AS subtype,
+ 1 AS section,
+ prj_id AS project,
+ <? value("quotes") ?> AS section_qtdisplayrole,
+ quhead_number AS name,
+ CASE WHEN (quhead_status = 'C') THEN
+ <? value("converted") ?>
+ WHEN (quhead_status = 'X') THEN
+ <? value("canceled") ?>
+ WHEN (COALESCE(quhead_expire, current_date + 1) > current_date) THEN
+ <? value("open") ?>
+ ELSE
+ <? value("expired") ?>
+ END AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ cust_name AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ NULL AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM quhead
+ JOIN prj() ON (quhead_prj_id=prj_id)
+ JOIN custinfo ON (quhead_cust_id=cust_id)
+ JOIN quitem ON (quitem_quhead_id = quhead_id)
+ WHERE (1=1)
+GROUP BY prj_id, quhead_id, quhead_number, quhead_status, quhead_expire, quhead_freight, quhead_misc, custinfo.cust_name
+
+UNION ALL
+
+SELECT quitem_id AS id,
+ 17 AS type,
+ quhead_number AS subtype,
+ 1 AS section,
+ prj_id AS project,
+ <? value("quotes") ?> AS section_qtdisplayrole,
+ quitem_linenumber::text AS name,
+ CASE WHEN (quhead_status = 'C') THEN
+ <? value("converted") ?>
+ WHEN (quhead_status = 'X') THEN
+ <? value("canceled") ?>
+ WHEN (COALESCE(quhead_expire, current_date + 1) > current_date) THEN
+ <? value("open") ?>
+ ELSE
+ <? value("expired") ?>
+ END AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ item_number AS item,
+ item_descrip1 || ' ' || item_descrip2 AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ quitem_qtyord,
+ uom_name AS uom,
+ (quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+ NULL::text AS due_qtforegroundrole,
+ 3 AS xtindentrole
+ FROM quhead
+ JOIN prj() ON (quhead_prj_id=prj_id)
+ JOIN quitem ON (quitem_quhead_id = quhead_id)
+ JOIN uom ON (quitem_qty_uom_id = uom_id)
+ JOIN itemsite ON (quitem_itemsite_id = itemsite_id)
+ JOIN item ON (itemsite_item_id = item_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT quhead_id AS id,
+ 18 AS type,
+ quhead_number AS subtype,
+ 1 AS section,
+ prj_id AS project,
+ <? value("quotes") ?> AS section_qtdisplayrole,
+ <? value("total") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM quhead
+ JOIN prj() ON (quhead_prj_id=prj_id)
+ JOIN quitem ON (quitem_quhead_id = quhead_id)
+ WHERE (1=1)
+GROUP BY prj_id, quhead_id, quhead_number
+
+UNION ALL
+
+SELECT -1 AS id,
+ 19 AS type,
+ MAX(quhead_number) AS subtype,
+ 1 AS section,
+ prj_id AS project,
+ <? value("quotes") ?> AS section_qtdisplayrole,
+ <? value("total") ?> || ' ' || <? value("quotes") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM quhead
+ JOIN prj() ON (quhead_prj_id=prj_id)
+ JOIN quitem ON (quitem_quhead_id = quhead_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+
+UNION ALL
+
+------ SALES ORDERS ------
+SELECT DISTINCT -1 AS id,
+ 20 AS type,
+ '0' AS subtype,
+ 2 AS section,
+ prj_id AS project,
+ <? value("sos") ?> AS section_qtdisplayrole,
+ <? value("sos") ?> AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM cohead
+ JOIN prj() ON (cohead_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT cohead_id AS id,
+ 25 AS type,
+ cohead_number::text AS subtype,
+ 2 AS section,
+ prj_id AS project,
+ <? value("sos") ?> AS section_qtdisplayrole,
+ cohead_number::text AS name,
+ COALESCE((SELECT
+ CASE WHEN (coitem_status = 'O') THEN
+ <? value("open") ?>
+ WHEN (coitem_status = 'C') THEN
+ <? value("closed" ?>
+ ELSE
+ <? value("canceled") ?>
+ END
+ FROM
+ (SELECT coitem_status,
+ CASE
+ WHEN (coitem_status = 'O') THEN 1
+ WHEN (coitem_status = 'C') then 2
+ ELSE 3
+ END AS type
+ FROM coitem
+ WHERE (coitem_cohead_id=cohead_id)
+ ORDER BY type
+ LIMIT 1) AS sts) ,'O')
+ AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ shipto_num AS item,
+ shipto_name AS descrip,
+ cust_name AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ NULL AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM cohead
+ JOIN prj() ON (cohead_prj_id=prj_id)
+ JOIN custinfo ON (cust_id = cohead_cust_id)
+ LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
+ JOIN coitem ON (coitem_cohead_id = cohead_id)
+ WHERE (1=1)
+GROUP BY prj_id,cohead_id, cohead_number, shipto_num, shipto_name, cust_name
+
+UNION ALL
+
+SELECT coitem_id AS id,
+ 27 AS type,
+ cohead_number::text AS subtype,
+ 2 AS section,
+ prj_id AS project,
+ <? value("sos") ?> AS section_qtdisplayrole,
+ coitem_linenumber::text AS name,
+ CASE WHEN (coitem_status = 'O') THEN
+ <? value("open") ?>
+ WHEN (coitem_status = 'C') THEN
+ <? value("closed" ?>
+ WHEN (coitem_status = 'X') THEN
+ <? value("canceled") ?>
+ END AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ item_number AS item,
+ item_descrip1 || ' ' || item_descrip2 AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ coitem_qtyord,
+ uom_name AS uom,
+ (coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 3 AS xtindentrole
+ FROM cohead
+ JOIN prj() ON (cohead_prj_id=prj_id)
+ JOIN coitem ON (coitem_cohead_id = cohead_id)
+ JOIN uom ON (coitem_qty_uom_id = uom_id)
+ JOIN itemsite ON (coitem_itemsite_id = itemsite_id)
+ JOIN item ON (itemsite_item_id = item_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT cohead_id AS id,
+ 28 AS type,
+ cohead_number::text AS subtype,
+ 2 AS section,
+ prj_id AS project,
+ <? value("sos") ?> AS section_qtdisplayrole,
+ <? value("total") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM cohead
+ JOIN prj() ON (cohead_prj_id=prj_id)
+ JOIN coitem ON (coitem_cohead_id = cohead_id)
+ WHERE (1=1)
+GROUP BY prj_id,cohead_id, cohead_number
+
+UNION ALL
+
+SELECT -1 AS id,
+ 29 AS type,
+ MAX(cohead_number::text) AS subtype,
+ 2 AS section,
+ prj_id AS project,
+ <? value("sos") ?> AS section_qtdisplayrole,
+ <? value("total") ?> || ' ' || <? value("sos") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM cohead
+ JOIN prj() ON (cohead_prj_id=prj_id)
+ JOIN coitem ON (coitem_cohead_id = cohead_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+
+UNION ALL
+
+------ INVOICES -------
+SELECT DISTINCT -1 AS id,
+ 30 AS type,
+ '0' AS subtype,
+ 3 AS section,
+ prj_id AS project,
+ <? value("invoices") ?> AS section_qtdisplayrole,
+ <? value("invoices") ?> AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM invchead
+ JOIN prj() ON (invchead_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT invchead_id AS id,
+ 35 AS type,
+ invchead_invcnumber::text AS subtype,
+ 3 AS section,
+ prj_id AS project,
+ <? value("invoices") ?> AS section_qtdisplayrole,
+ invchead_invcnumber::text AS name,
+ CASE WHEN (invchead_posted) THEN
+ <? value("posted") ?>
+ ELSE <? value("unposted") ?>
+ END AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ shipto_num AS item,
+ shipto_name AS descrip,
+ cust_name AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ NULL AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM invchead
+ JOIN prj() ON (invchead_prj_id=prj_id)
+ JOIN custinfo ON (cust_id=invchead_cust_id)
+ LEFT OUTER JOIN shiptoinfo ON (invchead_shipto_id = shipto_id)
+
+ JOIN invcitem ON (invcitem_invchead_id = invchead_id)
+ WHERE (1=1)
+GROUP BY prj_id,invchead_id, invchead_invcnumber, shipto_num, shipto_name, invchead_freight, invchead_misc_amount, invchead_posted, cust_name
+
+UNION ALL
+
+SELECT invcitem_id AS id,
+ 37 AS type,
+ invchead_invcnumber::text AS subtype,
+ 3 AS section,
+ prj_id AS project,
+ <? value("invoices") ?> AS section_qtdisplayrole,
+ invcitem_linenumber::text AS name,
+ CASE WHEN (invchead_posted) THEN
+ <? value("posted") ?>
+ ELSE <? value("unposted") ?>
+ END AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ COALESCE(item_number,invcitem_number) AS item,
+ COALESCE(item_descrip1 || ' ' || item_descrip2,invcitem_descrip) AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ invcitem_billed AS qty,
+ uom_name AS uom,
+ (invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 3 AS xtindentrole
+ FROM invchead
+ JOIN prj() ON (invchead_prj_id=prj_id)
+ JOIN invcitem ON (invcitem_invchead_id = invchead_id)
+ LEFT OUTER JOIN item ON (invcitem_item_id = item_id)
+ LEFT OUTER JOIN uom ON (invcitem_qty_uom_id = uom_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT invchead_id AS id,
+ 38 AS type,
+ invchead_invcnumber::text AS subtype,
+ 3 AS section,
+ prj_id AS project,
+ <? value("invoices") ?> AS section_qtdisplayrole,
+ <? value("total") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM invchead
+ JOIN prj() ON (invchead_prj_id=prj_id)
+ JOIN invcitem ON (invcitem_invchead_id = invchead_id)
+ WHERE (1=1)
+GROUP BY prj_id,invchead_id, invchead_invcnumber
+
+UNION ALL
+
+SELECT -1 AS id,
+ 39 AS type,
+ MAX(invchead_invcnumber::text) AS subtype,
+ 3 AS section,
+ prj_id AS project,
+ <? value("invoices") ?> AS section_qtdisplayrole,
+ <? value("total") ?> || ' ' || <? value("invoices") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM invchead
+ JOIN prj() ON (invchead_prj_id=prj_id)
+ JOIN invcitem ON (invcitem_invchead_id = invchead_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+
+<? endif ?>
+
+<? if exists("showWo") ?>
+UNION ALL
+
+------ WORK ORDERS -------
+SELECT DISTINCT -1 AS id,
+ 40 AS type,
+ '0' AS subtype,
+ 4 AS section,
+ prj_id AS project,
+ <? value("wos") ?> AS section_qtdisplayrole,
+ <? value("wos") ?> AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM wo
+ JOIN prj() ON (wo_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT wo_id AS id,
+ 45 AS type,
+ formatWoNumber(wo_id) AS subtype,
+ 4 AS section,
+ prj_id AS project,
+ <? value("wos") ?> AS section_qtdisplayrole,
+ formatWoNumber(wo_id) AS name,
+ CASE WHEN (wo_status = 'O') THEN
+ <? value("open") ?>
+ WHEN (wo_status = 'E') THEN
+ <? value("exploded") ?>
+ WHEN (wo_status = 'R') THEN
+ <? value("released") ?>
+ WHEN (wo_status = 'I') THEN
+ <? value("inprocess") ?>
+ WHEN (wo_status = 'C') THEN
+ <? value("closed" ?>
+ END AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ item_number AS item,
+ item_descrip1 || ' ' || item_descrip2 AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ wo_qtyord AS qty,
+ uom_name AS uom,
+ wo_postedvalue AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM wo
+ JOIN prj() ON (wo_prj_id=prj_id)
+ JOIN itemsite ON (itemsite_id=wo_itemsite_id)
+ JOIN item ON (itemsite_item_id=item_id)
+ JOIN uom ON (item_inv_uom_id=uom_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT -1 AS id,
+ 49 AS type,
+ MAX(formatWoNumber(wo_id)) AS subtype,
+ 4 AS section,
+ prj_id AS project,
+ <? value("wos") ?> AS section_qtdisplayrole,
+ <? value("total") ?> || ' ' || <? value("wos") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM(wo_postedvalue) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM wo
+ JOIN prj() ON (wo_prj_id=prj_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+
+<? endif ?>
+
+
+<? if exists("showPo") ?>
+ UNION ALL
+------ PURCHASE REQUESTS ------
+SELECT DISTINCT -1 AS id,
+ 50 AS type,
+ '0' AS subtype,
+ 5 AS section,
+ prj_id AS project,
+ <? value("prs") ?> AS section_qtdisplayrole,
+ <? value("prs") ?> AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM pr
+ JOIN prj() ON (pr_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT pr_id AS id,
+ 55 AS type,
+ pr_number::text || '-' || pr_subnumber::text AS subtype,
+ 5 AS section,
+ prj_id AS project,
+ <? value("prs") ?> AS section_qtdisplayrole,
+ pr_number::text || '-' || pr_subnumber::text AS name,
+ <? value("open") ?> AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ item_number AS item,
+ (item_descrip1 || ' ' || item_descrip2) AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ pr_qtyreq AS qty,
+ uom_name AS uom,
+ stdcost(item_id) * pr_qtyreq AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM pr
+ JOIN prj() ON (pr_prj_id=prj_id)
+ JOIN itemsite ON (itemsite_id = pr_itemsite_id)
+ JOIN item ON (itemsite_item_id = item_id)
+ JOIN uom ON (item_inv_uom_id = uom_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT -1 AS id,
+ 59 AS type,
+ MAX(pr_number::text || '-' || pr_subnumber::text) AS subtype,
+ 5 AS section,
+ prj_id AS project,
+ <? value("prs") ?> AS section_qtdisplayrole,
+ <? value("total") ?> || ' ' || <? value("prs") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM(stdcost(item_id) * pr_qtyreq) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM pr
+ JOIN prj() ON (pr_prj_id=prj_id)
+ JOIN itemsite ON (itemsite_id = pr_itemsite_id)
+ JOIN item ON (itemsite_item_id = item_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+
+UNION ALL
+
+------ PURCHASE ORDERS ------
+SELECT DISTINCT -1 AS id,
+ 60 AS type,
+ '0' AS subtype,
+ 6 AS section,
+ prj_id AS project,
+ <? value("pos") ?> AS section_qtdisplayrole,
+ <? value("pos") ?> AS name,
+ NULL::text AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL::numeric AS qty,
+ NULL::text AS uom,
+ NULL::numeric AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 1 AS xtindentrole
+ FROM poitem
+ JOIN prj() ON (poitem_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT pohead_id AS id,
+ 65 AS type,
+ pohead_number::text AS subtype,
+ 6 AS section,
+ prj_id AS project,
+ <? value("pos") ?> AS section_qtdisplayrole,
+ pohead_number::text AS name,
+ CASE WHEN (pohead_status = 'U') THEN
+ <? value("unreleased") ?>
+ WHEN (pohead_status = 'O') THEN
+ <? value("open") ?>
+ WHEN (pohead_status = 'C') THEN
+ <? value("closed" ?>
+ END AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL AS uom,
+ NULL AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM pohead
+ JOIN poitem ON (poitem_pohead_id = pohead_id)
+ JOIN prj() ON (poitem_prj_id=prj_id)
+ WHERE (1=1)
+GROUP BY prj_id,pohead_id, pohead_number, pohead_freight, pohead_status
+
+UNION ALL
+
+SELECT poitem_id AS id,
+ 67 AS type,
+ pohead_number::text AS subtype,
+ 6 AS section,
+ prj_id AS project,
+ <? value("pos") ?> AS section_qtdisplayrole,
+ poitem_linenumber::text AS name,
+ CASE WHEN (poitem_status = 'U') THEN
+ <? value("unreleased") ?>
+ WHEN (poitem_status = 'O') THEN
+ <? value("open") ?>
+ WHEN (poitem_status = 'C') THEN
+ <? value("closed" ?>
+ END AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ COALESCE(item_number,poitem_vend_item_number) AS item,
+ COALESCE((item_descrip1 || ' ' || item_descrip2),poitem_vend_item_descrip) AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ poitem_qty_ordered,
+ poitem_vend_uom AS uom,
+ (poitem_qty_ordered * poitem_unitprice) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 3 AS xtindentrole
+ FROM pohead
+ JOIN poitem ON (poitem_pohead_id = pohead_id)
+ JOIN prj() ON (poitem_prj_id=prj_id)
+ LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)
+ LEFT OUTER JOIN item ON (itemsite_item_id = item_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT pohead_id AS id,
+ 68 AS type,
+ pohead_number::text AS subtype,
+ 6 AS section,
+ prj_id AS project,
+ <? value("pos") ?> AS section_qtdisplayrole,
+ <? value("total") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM(poitem_qty_ordered * poitem_unitprice) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM pohead
+ JOIN poitem ON (poitem_pohead_id = pohead_id)
+ JOIN prj() ON (poitem_prj_id=prj_id)
+ WHERE (1=1)
+GROUP BY prj_id,pohead_id, pohead_number
+
+UNION ALL
+
+SELECT -1 AS id,
+ 69 AS type,
+ MAX(pohead_number::text) AS subtype,
+ 6 AS section,
+ prj_id AS project,
+ 'qty' AS section_qtdisplayrole,
+ <? value("total") ?> || ' ' || <? value("pos") ?> AS name,
+ NULL AS status,
+ NULL::text AS project_type,
+ NULL::text AS prj_username,
+ NULL::text AS prj_owner_username,
+ NULL::text AS item,
+ NULL::text AS descrip,
+ NULL::text AS customer,
+ NULL::text AS contact,
+ NULL::text AS city,
+ NULL::text AS state,
+ NULL AS qty,
+ NULL::text AS uom,
+ SUM(poitem_qty_ordered * poitem_unitprice) AS value,
+ NULL::date AS due,
+ NULL::date AS assigned,
+ NULL::date AS started,
+ NULL::date AS completed,
+ NULL::numeric AS hrs_budget,
+ NULL::numeric AS hrs_actual,
+ NULL::numeric AS hrs_balance,
+ NULL::numeric AS exp_budget,
+ NULL::numeric AS exp_actual,
+ NULL::numeric AS exp_balance,
+
+ NULL::text AS due_qtforegroundrole,
+ 2 AS xtindentrole
+ FROM pohead
+ JOIN poitem ON (poitem_pohead_id = pohead_id)
+ JOIN prj() ON (poitem_prj_id=prj_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+
+<? endif ?>
+
+) data
+
WHERE (true)
<? if exists("search_pattern") ?>
- AND ( (prj_number ~* <? value("search_pattern") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE ( (prj_number ~* <? value("search_pattern") ?>)
OR (prj_name ~* <? value("search_pattern") ?>)
- OR (prj_descrip ~* <? value("search_pattern") ?>) )
+ OR (prj_descrip ~* <? value("search_pattern") ?>) ))
<? endif ?>
<? if exists("username") ?>
AND (prj_username=<? value("username") ?> OR prj_owner_username=<? value("username") ?>)
AND (prj_username ~ <? value("assigned_usr_pattern") ?>)
<? endif ?>
<? if exists("owner_username") ?>
- AND (prj_owner_username=<? value("owner_username") ?>)
+ AND (prj_owner_username=<? value("owner_username") ?>)
<? elseif exists("owner_usr_pattern") ?>
AND (prj_owner_username ~ <? value("owner_usr_pattern") ?>)
<? endif ?>
<? if exists("crmacct_id") ?>
- AND (prj_crmacct_id=<? value("crmacct_id") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_crmacct_id=<? value("crmacct_id") ?>))
<? endif ?>
<? if exists("cntct_id") ?>
- AND (prj_cntct_id=<? value("cntct_id") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_cntct_id=<? value("cntct_id") ?>))
<? endif ?>
<? if exists("startStartDate") ?>
- AND (prj_start_date >= <? value("startStartDate") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_start_date >= <? value("startStartDate") ?>))
<? endif ?>
<? if exists("startEndDate") ?>
- AND (prj_start_date <= <? value("startEndDate") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_start_date <= <? value("startEndDate") ?>))
<? endif ?>
<? if exists("dueStartDate") ?>
- AND (prj_due_date >= <? value("dueStartDate") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_due_date >= <? value("dueStartDate") ?>))
<? endif ?>
<? if exists("dueEndDate") ?>
- AND (prj_due_date <= <? value("dueEndDate") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_due_date <= <? value("dueEndDate") ?>))
<? endif ?>
<? if exists("assignedStartDate") ?>
- AND (prj_assigned_date >= <? value("assignedStartDate") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_assigned_date >= <? value("assignedStartDate") ?>))
<? endif ?>
<? if exists("assignedEndDate") ?>
- AND (prj_assigned_date <= <? value("assignedEndDate") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_assigned_date <= <? value("assignedEndDate") ?>))
<? endif ?>
<? if exists("completedStartDate") ?>
- AND (prj_completed_date >= <? value("completedStartDate") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_completed_date >= <? value("completedStartDate") ?>))
<? endif ?>
<? if exists("completedEndDate") ?>
- AND (prj_completed_date <= <? value("completedEndDate") ?>)
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_completed_date <= <? value("completedEndDate") ?>))
<? endif ?>
<? if not exists("showComplete") ?>
- AND (prj_status <> 'C')
+ AND project IN (SELECT prj_id FROM prj WHERE prj_status <> 'C')
+<? endif ?>
+<? if exists("prj_id") ?>
+ AND (project=<? value("prj_id") ?>)
+<? endif ?>
+<? if exists("prjtype_id") ?>
+ AND project IN (SELECT prj_id FROM prj WHERE (prj_prjtype_id=<? value("prjtype_id") ?>))
+<? endif ?>
+<? if exists("project_task") ?>
+ AND project IN (SELECT DISTINCT prjtask_prj_id FROM prjtask where ((prjtask_number ~* <? value("project_task") ?>)
+ OR (prjtask_name ~* <? value("project_task") ?>)
+ OR (prjtask_descrip ~* <? value("project_task") ?>)))
<? endif ?>
-<? if exists("id") ?>
- AND (prj_id=<? value("id") ?>)
+<? if exists("cohead_id") ?>
+ AND project IN (SELECT cohead_prj_id FROM cohead where cohead_id=<? value("cohead_id") ?>)
<? endif ?>
-GROUP BY prj_id, prj_number, prj_name, prj_descrip, prj_status, prj_username, prj_owner_username,
- crmacct_number, prj_cntct_id,
- prj_start_date, prj_due_date, prj_assigned_date, prj_completed_date
-ORDER BY prj_number;
+<? if exists("wo_id") ?>
+ AND project IN (SELECT wo_prj_id FROM wo WHERE wo_id=<? value("wo_id") ?>)
+<? endif ?>
+<? if exists("pohead_id") ?>
+ AND project IN (SELECT poitem_prj_id FROM pohead JOIN poitem ON (pohead_id=poitem_pohead_id)
+ WHERE pohead_id=<? value("pohead_id") ?>)
+<? endif ?>
+
+
+ORDER BY project, section, subtype, type, id;
--- /dev/null
+-- Group: projects
+-- Name: detail_nohierarchy
+-- Notes: Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+--
+-- Non-hierarchical view to support CSV export from Project List screen
+
+SELECT prj_id AS id, 1 AS altId,
+ prj.*, crmacct_name, cntct_name,
+ addr_city, addr_state,
+ prjtype_descr AS project_type,
+ CASE WHEN (prj_status='P') THEN 'Planning'
+ WHEN (prj_status='O') THEN 'In-Process'
+ WHEN (prj_status='C') THEN 'Completed'
+ ELSE 'Unknown' END AS project_status
+<? foreach("char_id_text_list") ?>
+ , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>
+<? endforeach ?>
+FROM prj()
+LEFT JOIN prjtype ON (prj_prjtype_id=prjtype_id)
+LEFT JOIN crmacct ON (prj_crmacct_id=crmacct_id)
+LEFT JOIN cntct ON (crmacct_cntct_id_1=cntct_id)
+LEFT JOIN addr ON (cntct_addr_id=addr_id)
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='PROJ')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=prj_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='PROJ')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=prj_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='PROJ')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=prj_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
+WHERE (true)
+<? if exists("search_pattern") ?>
+ AND ( (prj_number ~* <? value("search_pattern") ?>)
+ OR (prj_name ~* <? value("search_pattern") ?>)
+ OR (prj_descrip ~* <? value("search_pattern") ?>) )
+<? endif ?>
+<? if exists("username") ?>
+ AND (prj_username=<? value("username") ?> OR prj_owner_username=<? value("username") ?>)
+<? endif ?>
+<? if exists("assigned_username") ?>
+ AND (prj_username=<? value("assigned_username") ?>)
+<? elseif exists("assigned_usr_pattern") ?>
+ AND (prj_username ~ <? value("assigned_usr_pattern") ?>)
+<? endif ?>
+<? if exists("owner_username") ?>
+ AND (prj_owner_username=<? value("owner_username") ?>)
+<? elseif exists("owner_usr_pattern") ?>
+ AND (prj_owner_username ~ <? value("owner_usr_pattern") ?>)
+<? endif ?>
+<? if exists("crmacct_id") ?>
+ AND (prj_crmacct_id=<? value("crmacct_id") ?>)
+<? endif ?>
+<? if exists("cntct_id") ?>
+ AND (prj_cntct_id=<? value("cntct_id") ?>)
+<? endif ?>
+<? if exists("startStartDate") ?>
+ AND (prj_start_date >= <? value("startStartDate") ?>)
+<? endif ?>
+<? if exists("startEndDate") ?>
+ AND (prj_start_date <= <? value("startEndDate") ?>)
+<? endif ?>
+<? if exists("dueStartDate") ?>
+ AND (prj_due_date >= <? value("dueStartDate") ?>)
+<? endif ?>
+<? if exists("dueEndDate") ?>
+ AND (prj_due_date <= <? value("dueEndDate") ?>)
+<? endif ?>
+<? if exists("assignedStartDate") ?>
+ AND (prj_assigned_date >= <? value("assignedStartDate") ?>)
+<? endif ?>
+<? if exists("assignedEndDate") ?>
+ AND (prj_assigned_date <= <? value("assignedEndDate") ?>)
+<? endif ?>
+<? if exists("completedStartDate") ?>
+ AND (prj_completed_date >= <? value("completedStartDate") ?>)
+<? endif ?>
+<? if exists("completedEndDate") ?>
+ AND (prj_completed_date <= <? value("completedEndDate") ?>)
+<? endif ?>
+<? if not exists("showComplete") ?>
+ AND (prj_status <> 'C')
+<? endif ?>
+<? if exists("id") ?>
+ AND (prj_id=<? value("id") ?>)
+<? endif ?>
+<? literal("charClause") ?>
+ORDER BY prj_number;
-- Group: prospects
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: purchase
-- Name: purchaserequests
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-SELECT pr_id, itemsite_id, item_number,
- (item_descrip1 || ' ' || item_descrip2) AS description,
+SELECT pr_id, itemsite_id, itemsite_qtyonhand, itemsite_reorderlevel,
+ item_number, (item_descrip1 || ' ' || item_descrip2) AS description,
pr.*,
CASE WHEN (pr_order_type='W') THEN ('W/O ' || ( SELECT formatWoNumber(womatl_wo_id)
FROM womatl
WHEN (pr_order_type='M') THEN <? value("manual") ?>
ELSE <? value("other") ?>
END AS parent,
+ 'qty' AS itemsite_qtyonhand_xtnumericrole,
+ 'qty' AS itemsite_reorderlevel_xtnumericrole,
'qty' AS pr_qtyreq_xtnumericrole
FROM pr, itemsite, item
WHERE ((pr_itemsite_id=itemsite_id)
-- Group: purchaseOrderItems
-- Name: detail
-- Notes: used by purchaseOrderItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT pohead_number, pohead_taxzone_id,
pohead_curr_id, pohead_orderdate,
END AS order_number,
poitem_unitprice * poitem_qty_ordered AS extended_price,
COALESCE(coitem_prcost, 0.0) AS override_cost,
+ contrct_number,
itemsrc.*
FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
LEFT OUTER JOIN itemsrc ON (itemsrc_id=poitem_itemsrc_id)
LEFT OUTER JOIN coitem ON (poitem_order_type='S' AND coitem_id=poitem_order_id)
LEFT OUTER JOIN womatl ON (poitem_order_type='W' AND womatl_id=poitem_order_id)
+ LEFT OUTER JOIN contrct ON (itemsrc_contrct_id=contrct_id)
WHERE ( (TRUE)
<? if exists("poitem_id") ?>
AND (poitem_id=<? value("poitem_id") ?>)
-- Group: purchaseOrders
-- Name: detail
-- Notes: used by dspPosByVendor, dspPOsByDate
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT pohead_id, pohead_number,
-- Name: detail
-- Notes:
-- Quantity on Hand By Location
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("byLocation") ?>
-SELECT itemloc_id, warehous_code, item_number,
+SELECT itemloc_id, alt_id, warehous_code, item_number,
f_descrip, f_lotserial, uom_name,
qoh, reservedqty,
'qty' AS qoh_xtnumericrole,
'qty' AS reservedqty_xtnumericrole,
level AS xtindentrole
FROM (
- SELECT itemloc_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
+ SELECT itemloc_id, 0 AS alt_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
(item_descrip1 || ' ' || item_descrip2) AS f_descrip,
formatlotserialnumber(itemloc_ls_id) AS f_lotserial, uom_name,
itemloc_qty AS qoh,
AND (itemsite_warehous_id=warehous_id)
AND (itemloc_location_id=<? value("location_id") ?>))
UNION
- SELECT -1 AS itemloc_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
+ SELECT -1 AS itemloc_id, 0 AS alt_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
(item_descrip1 || ' ' || item_descrip2) AS f_descrip,
<? value("na") ?> AS f_lotserial, uom_name,
itemsite_qtyonhand AS qoh,
AND (itemsite_location_id=<? value("location_id") ?>))
<? if exists("EnableSOReservationsByLocation") ?>
UNION
- SELECT itemloc_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
- (itemlocrsrv_source || '-' || formatSOItemNumber(itemlocrsrv_source_id)) AS f_descrip,
+ SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
+ (reserve_demand_type || '-' || formatSOItemNumber(reserve_demand_id)) AS f_descrip,
'' AS f_lotserial, '' AS uom_name,
NULL AS qoh,
- itemlocrsrv_qty AS reservedqty
- FROM itemlocrsrv, itemloc, itemsite, item
- WHERE ((itemlocrsrv_itemloc_id=itemloc_id)
+ reserve_qty AS reservedqty
+ FROM reserve, itemloc, itemsite, item
+ WHERE ((reserve_supply_id=itemloc_id)
+ AND (reserve_supply_type='I')
AND (itemsite_id=itemloc_itemsite_id)
AND(item_id=itemsite_item_id)
AND(itemloc_location_id=<? value("location_id") ?>))
+ <? endif ?>
+ <? if exists("ShowDemand") ?>
+ UNION
+ SELECT itemloc_id, coitem_cohead_id AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
+ (<? value("so") ?>|| '-' || formatSOItemNumber(coitem_id)) AS f_descrip,
+ '' AS f_lotserial, '' AS uom_name,
+ itemUOMtoUOM(item_id, coitem_qty_uom_id, NULL, (coitem_qtyord - coitem_qtyshipped - qtyAtShipping(coitem_id))) AS qoh,
+ 0 AS reservedqty
+ FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ JOIN coitem ON (coitem_itemsite_id=itemloc_itemsite_id AND coitem_status='O')
+ WHERE ((coitem_qtyord > (coitem_qtyshipped + qtyAtShipping(coitem_id)))
+ AND(itemloc_location_id=<? value("location_id") ?>))
+ UNION
+ SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
+ (<? value("wo") ?>|| '-' || formatWONumber(womatl_wo_id)) AS f_descrip,
+ '' AS f_lotserial, '' AS uom_name,
+ (womatl_qtyreq - womatl_qtyiss) AS qoh,
+ 0 AS reservedqty
+ FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ JOIN womatl ON (womatl_itemsite_id=itemloc_itemsite_id)
+ WHERE ((womatl_qtyreq > womatl_qtyiss)
+ AND(itemloc_location_id=<? value("location_id") ?>))
+ UNION
+ SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
+ (<? value("to") ?>|| '-' || formatTONumber(toitem_id)) AS f_descrip,
+ '' AS f_lotserial, '' AS uom_name,
+ (toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS qoh,
+ 0 AS reservedqty
+ FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
+ JOIN item ON (item_id=itemsite_item_id)
+ JOIN toitem ON (toitem_item_id=item_id AND toitem_status='O')
+ JOIN tohead ON (tohead_id=toitem_tohead_id AND tohead_src_warehous_id=itemsite_warehous_id)
+ WHERE ((toitem_qty_ordered > (toitem_qty_shipped + qtyAtShipping('TO', toitem_id)))
+ AND(itemloc_location_id=<? value("location_id") ?>))
<? endif ?>
) AS data
ORDER BY
-- Group: quoteItems
-- Name: detail
-- Notes: used by dspQuotesByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT quitem_id, quhead_id,
--- /dev/null
+-- Group: quoteItems
+-- Name: list
+-- Notes: used by salesOrder
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+
+SELECT quitem_id,
+ quitem_linenumber AS f_linenumber,
+ 0 AS coitem_subnumber, item_type,
+ item_number, (item_descrip1 || ' ' || item_descrip2) AS description,
+ warehous_code, '' AS enhanced_status,
+ quitem_scheddate AS coitem_scheddate,
+ quom.uom_name AS qty_uom,
+ quitem_qtyord AS coitem_qtyord,
+ 0 AS qtyshipped, 0 AS qtyatshipping, 0 AS balance,
+ puom.uom_name AS price_uom,
+ quitem_price AS coitem_price,
+ ROUND((quitem_qtyord * quitem_qty_invuomratio) *
+ (quitem_price / quitem_price_invuomratio),2) AS extprice,
+ quitem_custprice AS coitem_custprice,
+ CASE WHEN (quitem_custprice = 0.0) THEN 100.0
+ ELSE ((1.0 - (quitem_price / quitem_custprice)) * 100.0)
+ END AS discountfromcust,
+ quitem_unitcost AS coitem_unitcost,
+ ROUND((quitem_qtyord * quitem_qty_invuomratio) *
+ ((quitem_price / quitem_price_invuomratio) - quitem_unitcost),2) AS margin,
+ CASE WHEN (quitem_price = 0.0) THEN 100.0
+ ELSE ((quitem_price - quitem_unitcost) / quitem_price)
+ END AS marginpercent,
+ CASE WHEN (quitem_custpn != '') THEN quitem_custpn
+ ELSE item_number
+ END AS item_number_cust,
+ (quitem_qtyord / quitem_qty_invuomratio * item_prodweight) AS prodweight,
+ (quitem_qtyord / quitem_qty_invuomratio * item_packweight) AS packweight,
+ itemsite_qtyonhand,
+ 'qty' AS coitem_qtyord_xtnumericrole,
+ 'qty' AS qtyshipped_xtnumericrole,
+ 'qty' AS balance_xtnumericrole,
+ 'qty' AS qtyatshipping_xtnumericrole,
+ 'qty' AS prodweight_xtnumericrole,
+ 'qty' AS packweight_xtnumericrole,
+ 'qty' AS itemsite_qtyonhand_xtnumericrole,
+ 'salesprice' AS coitem_price_xtnumericrole,
+ 'cost' AS coitem_unitcost_xtnumericrole,
+ 'curr' AS margin_xtnumericrole,
+ 'percent' AS marginpercent_xtnumericrole,
+ 'curr' AS extprice_xtnumericrole
+ FROM item, uom AS quom, uom AS puom,
+ quitem LEFT OUTER JOIN (itemsite JOIN whsinfo ON (itemsite_warehous_id=warehous_id)) ON (quitem_itemsite_id=itemsite_id)
+ WHERE ( (quitem_item_id=item_id)
+ AND (quitem_qty_uom_id=quom.uom_id)
+ AND (quitem_price_uom_id=puom.uom_id)
+ AND (quitem_quhead_id=<? value("quhead_id") ?>) )
+ORDER BY quitem_linenumber;
-- Group: quotes
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT quhead.*, firstline(quhead_ordercomments) AS notes, quhead_id AS id,
- CASE WHEN quhead_status = 'O' THEN <? value("open") ?>
- WHEN quhead_status = 'C' THEN <? value("converted") ?>
- ELSE <? value("undefined") ?> END AS quhead_status_qtdisplayrole,
+ calcQuoteAmt(quhead_id) AS ordertotal,
+ 'extprice' AS ordertotal_xtnumericrole,
+ <? foreach("char_id_text_list") ?>
+ charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,
+ <? endforeach ?>
+ <? foreach("char_id_list_list") ?>
+ charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,
+ <? endforeach ?>
+ <? foreach("char_id_date_list") ?>
+ charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,
+ <? endforeach ?>
+ CASE WHEN quhead_status = 'O' THEN <? value("open") ?>
+ WHEN quhead_status = 'C' THEN <? value("converted") ?>
+ ELSE <? value("undefined") ?>
+ END AS quhead_status_qtdisplayrole,
<? if exists("customersOnly") ?>
cust_id, cust_number, cust_name,
<? endif ?>
LEFT OUTER
<? endif ?>
JOIN custinfo ON (quhead_cust_id=cust_id)
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?>
+ ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='QU')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=quhead_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?>
+ ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='QU')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=quhead_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?>
+ ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='QU')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=quhead_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
WHERE (checkQuoteSitePrivs(quhead_id, <? value("warehous_id") ?>))
<? if exists("owner_username") ?>
AND (quhead_owner_username=<? value("owner_username") ?>)
<? if exists("id") ?>
AND (quhead_id = <? value("id") ?>)
<? endif ?>
+<? literal("charClause") ?>
<? if exists("orderByCust") ?>
ORDER BY cust_number, quhead_number;
<? else ?>
-- Group: receipt
-- Name: detail
-- Notes: used by enterPoReceipt
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("pohead_id") ?>
-- Group: receipt
-- Name: receiveAll
-- Notes: used by enterPoReceipt, returnAuthorization, shipOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists ("shiphead_id") ?>
-- Group: receivings
-- Name: detail
-- Notes: used by dspPoItemReceivingsByDate, dspPoItemReceivingsByItem, dspPoItemReceivingsByVendor
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT recv_id, 1 AS altid, recv_order_number AS ponumber,
-- Group: reorderExceptionsByPlannerCode
-- Name: detail
-- Notes: used by dspReorderExceptionsByPlannerCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, itemtype, warehous_code, item_number,
-- Group: reports
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists('byPackage') ?>
-- Group: reservations
-- Name: detail
-- Notes: used by dspReservations
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT source_id, order_number, scheddate,
SELECT coitem_scheddate AS sortkey, 1 AS level, coitem_id AS source_id,
(formatLocationName(itemloc_location_id) || ' ' || formatLotSerialNumber(itemloc_ls_id)) AS order_number,
NULL AS totalqty, NULL AS relievedqty,
- (itemlocrsrv_qty * coitem_qty_invuomratio) AS reservedqty,
+ (reserve_qty * coitem_qty_invuomratio) AS reservedqty,
NULL AS balanceqty, NULL AS scheddate
-FROM itemlocrsrv, itemloc, coitem, itemsite
-WHERE ( (itemloc_id=itemlocrsrv_itemloc_id)
- AND (coitem_id=itemlocrsrv_source_id)
+FROM reserve, itemloc, coitem, itemsite
+WHERE ( (itemloc_id=reserve_supply_id)
+ AND (reserve_supply_type='I')
+ AND (coitem_id=reserve_demand_id)
+ AND (reserve_demand_type='SO')
AND (itemsite_id=coitem_itemsite_id)
AND (itemsite_warehous_id=<? value("warehous_id") ?>)
AND (itemsite_item_id=<? value("item_id") ?>) )
-- Name: detail
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT rahead_id, rahead_number, rahead_billtoname,
-- Group: runningAvailability
-- Name: detail
-- Notes: used by dspRunningAvailability, itemAvailabilityWorkbench
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT orderid, altorderid, ordertype, ordernumber, sequence, item_number,
- duedate, qtyordered, qtyreceived, balance,
+ duedate, amount, qtyordered, qtyreceived, balance,
balance AS runningavail,
<? if exists("isReport") ?>
CASE WHEN duedate = startOfTime() THEN ''
ELSE formatDate(duedate) END AS f_duedate,
+ formatMoney(amount) AS f_amount,
formatQty(qtyordered) AS f_qtyordered,
formatQty(qtyreceived) AS f_qtyreceived,
formatQty(balance) AS f_balance,
<? endif ?>
+ notes,
1 AS runningavail_xtrunningrole,
<? value("qoh") ?> AS runningavail_xtrunninginit,
CASE WHEN late THEN 'error' END AS duedate_qtforegroundrole,
ordertype ~ <? value("plannedWo") ?> OR
ordertype ~ <? value("plannedTo") ?> THEN
'emphasis' END AS qtforegroundrole,
+ 'currency' AS amount_xtnumericrole,
'qty' AS qtyordered_xtnumericrole,
'qty' AS qtyreceived_xtnumericrole,
'qty' AS balance_xtnumericrole
'' AS item_number,
startOfTime() AS duedate,
FALSE AS late,
+ 0 AS amount,
0 AS qtyordered,
0 AS qtyreceived,
- <? value("qoh") ?> AS balance
+ <? value("qoh") ?> AS balance,
+ '' AS notes
UNION
<? endif ?>
<? if exists("MultiWhs") ?>
tohead_srcname || '/' || tohead_destname AS item_number,
toitem_duedate AS duedate,
(toitem_duedate < CURRENT_DATE) AS late,
+ (toitem_stdcost * toitem_qty_ordered) AS amount,
toitem_qty_ordered AS qtyordered,
toitem_qty_received AS qtyreceived,
- noNeg(toitem_qty_ordered - toitem_qty_received) AS balance
+ noNeg(toitem_qty_ordered - toitem_qty_received) AS balance,
+ tohead_ordercomments AS notes
FROM tohead, toitem
WHERE ((toitem_tohead_id=tohead_id)
AND (toitem_status NOT IN ('C', 'X'))
tohead_srcname || '/' || tohead_destname AS item_number,
toitem_duedate AS duedate,
(toitem_duedate < CURRENT_DATE) AS late,
+ (toitem_stdcost * toitem_qty_ordered) AS amount,
toitem_qty_ordered AS qtyordered,
toitem_qty_received AS qtyreceived,
- -1 * noNeg(toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS balance
+ -1 * noNeg(toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS balance,
+ tohead_ordercomments AS notes
-- TODO: old code had ^^^^ for formatted balance and vvvv used to calc running avail! which is right?
-- -1 * noNeg(toitem_qty_ordered - toitem_qty_received) AS balance
FROM tohead, toitem
item_number,
wo_duedate AS duedate,
(wo_duedate < CURRENT_DATE) AS late,
+ (itemCost(wo_itemsite_id) * wo_qtyord) AS amount,
wo_qtyord AS qtyordered,
wo_qtyrcv AS qtyreceived,
- noNeg(wo_qtyord - wo_qtyrcv) AS balance
+ noNeg(wo_qtyord - wo_qtyrcv) AS balance,
+ wo_prodnotes AS notes
FROM wo, itemsite, item
WHERE ((wo_status<>'C')
AND (wo_itemsite_id=itemsite_id)
item_number,
wo_duedate AS duedate,
(wo_duedate < CURRENT_DATE) AS late,
+ (womatl_cost * womatl_qtyreq) AS amount,
womatl_qtyreq AS qtyordered,
COALESCE(SUM(abs(invhist_invqty)),0) AS qtyreceived,
- noNeg(womatl_qtyreq - COALESCE(SUM(abs(invhist_invqty)),0)) AS balance
+ noNeg(womatl_qtyreq - COALESCE(SUM(abs(invhist_invqty)),0)) AS balance,
+ wo_prodnotes AS notes
FROM womatl
JOIN wo ON (wo_id=womatl_wo_id)
JOIN itemsite ON (womatl_itemsite_id=itemsite_id)
AND (itemsite_warehous_id=<? value("warehous_id") ?>)
AND (itemsite_item_id=<? value("item_id") ?>)
AND (item_type = 'T'))
-GROUP BY wo_id, wo_duedate, item_number, womatl_qtyreq
+GROUP BY wo_id, wo_duedate, item_number, womatl_qtyreq, womatl_cost, wo_prodnotes
<? if exists("Manufacturing") ?>
UNION
item_number,
wo_duedate AS duedate,
(wo_duedate < CURRENT_DATE) AS late,
+ (itemCost(wo_itemsite_id) * wo_qtyord * brddist_stdqtyper) AS amount,
(wo_qtyord * brddist_stdqtyper) AS qtyordered,
(wo_qtyrcv * brddist_stdqtyper) AS qtyreceived,
- noNeg((wo_qtyord - wo_qtyrcv) * brddist_stdqtyper) AS balance
+ noNeg((wo_qtyord - wo_qtyrcv) * brddist_stdqtyper) AS balance,
+ wo_prodnotes AS notes
FROM xtmfg.brddist, wo, itemsite, item
WHERE ((wo_status<>'C')
AND (brddist_wo_id=wo_id)
woi.item_number,
womatl_duedate AS duedate,
FALSE AS late,
+ (itemCost(womatl_itemsite_id) * itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq)) AS amount,
itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq) AS qtyordered,
itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyiss) AS qtyreceived,
- itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq - womatl_qtyiss) * -1)) AS balance
+ itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq - womatl_qtyiss) * -1)) AS balance,
+ wo_prodnotes AS notes
FROM womatl, wo, itemsite AS wois, item AS woi, itemsite AS womatlis, item AS womatli
WHERE ((wo_status<>'C')
AND (wo_itemsite_id=wois.itemsite_id)
woi.item_number,
womatl_duedate AS duedate,
FALSE AS late,
+ (womatl_cost * itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq)) AS amount,
itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq) AS qtyordered,
COALESCE(SUM(invhist_invqty),0) AS qtyreceived,
- (itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq))) - COALESCE(SUM(invhist_invqty),0)) * -1 AS balance
+ (itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq))) - COALESCE(SUM(invhist_invqty),0)) * -1 AS balance,
+ wo_prodnotes AS notes
FROM itemsite AS wois, item AS woi, itemsite AS womatlis, item AS womatli, wo, womatl
LEFT OUTER JOIN womatlpost ON (womatl_id=womatlpost_womatl_id)
LEFT OUTER JOIN invhist ON ((womatlpost_invhist_id=invhist_id)
AND (womatlis.itemsite_item_id=<? value("item_id") ?>)
AND (womatlis.itemsite_warehous_id=<? value("warehous_id") ?>)
AND (womatl_itemsite_id=womatlis.itemsite_id) )
-GROUP BY wo_id, woi.item_number, womatl_id, womatl_duedate, womatlis.itemsite_item_id, womatl_uom_id, womatl_qtyreq
+GROUP BY wo_id, woi.item_number, womatl_id, womatl_duedate, womatlis.itemsite_item_id, womatl_uom_id, womatl_qtyreq, womatl_cost, wo_prodnotes
UNION
SELECT pohead_id AS orderid, poitem_id AS altorderid,
'P/O' AS ordertype,
TEXT(pohead_number) AS ordernumber,
1 AS sequence,
- '' AS item_number,
+ vend_name AS item_number,
poitem_duedate AS duedate,
(poitem_duedate < CURRENT_DATE) AS late,
+ (poitem_unitprice * poitem_qty_ordered) AS amount,
(poitem_qty_ordered * poitem_invvenduomratio) AS qtyordered,
(NoNeg(poitem_qty_received - poitem_qty_returned) * poitem_invvenduomratio) AS qtyreceived,
- (noNeg(poitem_qty_ordered - poitem_qty_received) * poitem_invvenduomratio) AS balance
-FROM pohead, poitem, itemsite, item
-WHERE ((poitem_pohead_id=pohead_id)
+ (noNeg(poitem_qty_ordered - poitem_qty_received) * poitem_invvenduomratio) AS balance,
+ pohead_comments AS notes
+FROM pohead, vendinfo, poitem, itemsite, item
+WHERE ((vend_id=pohead_vend_id)
+ AND (poitem_pohead_id=pohead_id)
AND (poitem_status <> 'C')
AND (poitem_itemsite_id=itemsite_id)
AND (itemsite_warehous_id=<? value("warehous_id") ?>)
cust_name AS item_number,
coitem_scheddate AS duedate,
(coitem_scheddate < CURRENT_DATE) AS late,
+ (coitem_price * coitem_qtyord) AS amount,
(coitem_qtyord * coitem_qty_invuomratio) AS qtyordered,
(coitem_qty_invuomratio * (coitem_qtyshipped - coitem_qtyreturned + qtyAtShipping(coitem_id))) AS qtyreceived,
- (coitem_qty_invuomratio * noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping(coitem_id)) * -1) AS balance
+ (coitem_qty_invuomratio * noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping(coitem_id)) * -1) AS balance,
+ cohead_ordercomments AS notes
FROM coitem, cohead, custinfo, itemsite, item
WHERE ((coitem_status='O')
AND (cohead_cust_id=cust_id)
'' AS item_number,
planord_duedate AS duedate,
FALSE AS late,
+ (itemCost(planord_itemsite_id) * planord_qty) AS amount,
planord_qty AS qtyordered,
NULL AS qtyreceived,
- planord_qty AS balance
+ planord_qty AS balance,
+ planord_comments AS notes
FROM planord, itemsite
WHERE ((planord_type='P')
AND (planord_itemsite_id=itemsite_id)
'' AS item_number,
planord_duedate AS duedate,
FALSE AS late,
+ (itemCost(planord_itemsite_id) * planord_qty) AS amount,
planord_qty AS qtyordered,
NULL AS qtyreceived,
- planord_qty AS balance
+ planord_qty AS balance,
+ planord_comments AS notes
FROM planord, itemsite
WHERE ((planord_type='W')
AND (planord_itemsite_id=itemsite_id)
item_number,
planord_duedate AS duedate,
FALSE AS late,
+ (itemCost(planreq_itemsite_id) * planreq_qty) AS amount,
planreq_qty AS qtyordered,
NULL AS qtyreceived,
- planreq_qty AS balance
+ planreq_qty AS balance,
+ planord_comments AS notes
FROM planreq
JOIN itemsite ON (itemsite_id=planreq_itemsite_id)
JOIN item ON (item_id=itemsite_item_id)
srcwhsinfo.warehous_code || '/' || whsinfo.warehous_code AS item_number,
planord_duedate AS duedate,
FALSE AS late,
+ (itemCost(planord_itemsite_id) * planord_qty) AS amount,
planord_qty AS qtyordered,
NULL AS qtyreceived,
- planord_qty AS balance
+ planord_qty AS balance,
+ planord_comments AS notes
FROM planord JOIN itemsite ON (itemsite.itemsite_id=planord_itemsite_id)
JOIN whsinfo ON (whsinfo.warehous_id=itemsite.itemsite_warehous_id)
JOIN itemsite srcitemsite ON (srcitemsite.itemsite_id=planord_supply_itemsite_id)
srcwhsinfo.warehous_code || '/' || whsinfo.warehous_code AS item_number,
planord_duedate AS duedate,
FALSE AS late,
+ (itemCost(planord_itemsite_id) * planord_qty) AS amount,
planord_qty AS qtyordered,
NULL AS qtyreceived,
- (planord_qty * -1) AS balance
+ (planord_qty * -1) AS balance,
+ planord_comments AS notes
FROM planord JOIN itemsite ON (itemsite.itemsite_id=planord_itemsite_id)
JOIN whsinfo ON (whsinfo.warehous_id=itemsite.itemsite_warehous_id)
JOIN itemsite srcitemsite ON (srcitemsite.itemsite_id=planord_supply_itemsite_id)
) AS item_number,
planord_startdate AS duedate,
FALSE AS late,
+ (itemCost(planreq_itemsite_id) * planreq_qty) AS amount,
planreq_qty AS f_qtyordered,
NULL AS qtyreceived,
- (planreq_qty * -1) AS balance
+ (planreq_qty * -1) AS balance,
+ planreq_notes AS notes
FROM planreq, planord, itemsite, item
WHERE ((planreq_source='P')
AND (planreq_source_id=planord_id)
'' AS item_number,
pr_duedate AS duedate,
FALSE AS late,
+ (itemCost(pr_itemsite_id) * pr_qtyreq) AS amount,
pr_qtyreq AS qtyordered,
NULL AS qtyreceived,
- pr_qtyreq AS balance
+ pr_qtyreq AS balance,
+ pr_releasenote AS notes
FROM pr, itemsite, item
WHERE ((pr_itemsite_id=itemsite_id)
AND (itemsite_item_id=item_id)
-- Group: salesAccounts
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT salesaccnt_id,
-- Group: salesHistory
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cohist.*,
-- Group: salesOrderItems
-- Name: detail
-- Notes: used by dspBacklogByCustomer, dspBacklogByItem, dspBacklogByParameterList, dspBacklogBySalesOrder, dspBookingsByCustomer, dspBookingsByCustomerGroup, dspBookingsByItem, dspBookingsByProductCategory, dspBookingsBySalesRep, dspBookingsByShipTo, dspSalesOrdersByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: salesOrderItems
-- Name: list
-- Notes: used by salesOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT coitem_id, coitem_altid, groupby,
coitem_linenumber, coitem_subnumber, f_linenumber,
warehous_code, item_number, item_type, description,
item_number_cust, item_descrip1_cust, item_descrip2_cust, item_barcode,
+ prodweight, packweight,
enhanced_status, coitem_firm,
qty_uom, price_uom, ship_uom,
coitem_memo,
CASE WHEN (extprice_shipped > 0.0) THEN formatMoney(extprice_shipped) ELSE NULL END AS f_extprice_shipped,
-- end formatted columns
coitem_scheddate, coitem_price, coitem_custprice, discountfromcust,
+ coitem_unitcost, margin, marginpercent,
coitem_qtyord, qtyshipped, balance, qtyatshipping,
extprice, extprice_shipped,
CASE WHEN (discountfromcust=100.0) THEN 'N/A' END AS discountfromcust_qtdisplayrole,
'qty' AS qtyshipped_xtnumericrole,
'qty' AS balance_xtnumericrole,
'qty' AS qtyatshipping_xtnumericrole,
+ 'qty' AS prodweight_xtnumericrole,
+ 'qty' AS packweight_xtnumericrole,
'salesprice' AS coitem_price_xtnumericrole,
'salesprice' AS coitem_custprice_xtnumericrole,
+ 'cost' AS coitem_unitcost_xtnumericrole,
'curr' AS extprice_xtnumericrole,
'curr' AS extprice_shipped_xtnumericrole,
+ 'curr' AS margin_xtnumericrole,
+ 'percent' AS marginpercent_xtnumericrole,
CASE WHEN fetchMetricBool('EnableSOShipping') AND
coitem_scheddate > CURRENT_DATE AND
(noNeg(coitem_qtyord) <> qtyAtShipping('SO', coitem_id)) THEN 'future'
CASE WHEN coitem_subnumber = 0 THEN 0
ELSE 1
END AS xtindentrole,
- spplytype, ordrnumbr
+ spplytype, ordrnumbr,
+ itemsite_qtyonhand,
+ 'qty' AS itemsite_qtyonhand_xtnumericrole
+<? if exists("includeReservations") ?>
+ ,
+ reserved,
+ reservable,
+ 'qty' AS reserved_xtnumericrole,
+ 'qty' AS reservable_xtnumericrole
+<? endif?>
FROM (
SELECT coitem_id,
CASE WHEN (coitem_status='C') THEN 1
ELSE item_descrip2
END AS item_descrip2_cust,
formatitemsitebarcode(itemsite_id) AS item_barcode,
+ (coitem_qtyord / coitem_qty_invuomratio * item_prodweight) AS prodweight,
+ (coitem_qtyord / coitem_qty_invuomratio * item_packweight) AS packweight,
coitem_status, coitem_firm,
- (CASE WHEN (coitem_status='O' AND (SELECT cust_creditstatus FROM custinfo WHERE cust_id=cohead_cust_id)='H') THEN 'H'
- WHEN (coitem_status='O' AND ((SELECT SUM(invcitem_billed)
- FROM cohead, invchead, invcitem
- WHERE ((CAST(invchead_ordernumber AS text)=cohead_number)
- AND (invcitem_invchead_id=invchead_id)
- AND (invcitem_item_id=item_id)
- AND (invcitem_warehous_id=warehous_id)
- AND (invcitem_linenumber=coitem_linenumber)
- AND (cohead_id=coitem_cohead_id))) >= coitem_qtyord)) THEN 'I'
- WHEN (coitem_status='O' AND ((SELECT SUM(invcitem_billed)
- FROM cohead, invchead, invcitem
- WHERE ((CAST(invchead_ordernumber AS text)=cohead_number)
- AND (invcitem_invchead_id=invchead_id)
- AND (invcitem_item_id=item_id)
- AND (invcitem_warehous_id=warehous_id)
- AND (invcitem_linenumber=coitem_linenumber)
- AND (cohead_id=coitem_cohead_id))) > 0)) THEN 'P'
- WHEN (coitem_status='O' AND (itemsite_qtyonhand - qtyAllocated(itemsite_id, CURRENT_DATE)
- + qtyOrdered(itemsite_id, CURRENT_DATE))
- >= ((coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio)) THEN 'R'
- ELSE coitem_status END
- || CASE WHEN (coitem_firm) THEN 'F' ELSE '' END
- ) AS enhanced_status,
+ getSoitemStatus(coitem_id) AS enhanced_status,
quom.uom_name AS qty_uom, puom.uom_name AS price_uom,
itemSellingUOM(item_id) AS ship_uom,
coitem_memo,
CASE WHEN (coitem_custprice = 0.0) THEN 100.0
ELSE ((1.0 - (coitem_price / coitem_custprice)) * 100.0)
END AS discountfromcust,
+ coitem_unitcost,
+ ROUND((coitem_qtyord * coitem_qty_invuomratio) *
+ ((coitem_price / coitem_price_invuomratio) - coitem_unitcost),2) AS margin,
+ CASE WHEN (coitem_price = 0.0) THEN 100.0
+ ELSE ((coitem_price - coitem_unitcost) / coitem_price)
+ END AS marginpercent,
noNeg(coitem_qtyshipped - coitem_qtyreturned) AS qtyshipped,
noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS balance,
qtyAtShipping('SO', coitem_id) AS qtyatshipping,
WHEN coitem_order_type='P' THEN (pohead_number || '-' || poitem_linenumber)
WHEN coitem_order_type='R' THEN (pr_number || '-' || pr_subnumber)
ELSE TEXT (' ')
- END AS ordrnumbr
+ END AS ordrnumbr,
+ itemsite_qtyonhand
+<? if exists("includeReservations") ?>
+ ,
+ coitem_qtyreserved AS reserved,
+ itemsite_qtyonhand - qtyreserved(itemsite_id) AS reservable
+<? endif?>
FROM cohead
JOIN coitem ON (coitem_cohead_id=cohead_id)
JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
-- Group: salesOrderStatus
-- Name: detail
-- Notes: used by dspSalesOrderStatus
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT coitem_id, coitem_linenumber, item_number,
-- Group: salesOrders
-- Name: detail
-- Notes: used by dspSalesOrdersByCustomer, dspSalesOrdersByCustomerPO, dspSalesOrdersByParameterList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cohead_id, cust_id,
-- Group: saletype
-- Name: table
-- Notes: maintain saletype table
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("ViewMode") ?>
-- Group: schedule
-- Name: plannedorders
-- Notes: used by dpsPlannedOrdersByItem, dspPlannedOrdersByPlannerCode, dspPlannedRevenueExpensesByPlannerCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
plorevenue - plocost AS profit,
-- Group: scripts
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists('byPackage') ?>
-- Group: selectPayments
-- Name: applyallcredits
-- Notes: used by selectPayments
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-- Group: shipments
-- Name: detail
-- Notes: used by dspShipmentsByDate, dspShipmentsBySalesOrder, dspShipmentsByShipment
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT shiphead_id, lineitem_id,
CASE WHEN (level=0) THEN order_number
formatQty(qtyord) AS f_qtyord,
qtyshipped,
formatQty(qtyshipped) AS f_qtyshipped,
+ notes,
'qty' AS qtyord_xtnumericrole,
'qty' AS qtyshipped_xtnumericrole,
'curr' AS shiphead_freight_xtnumericrole,
CASE WHEN (COALESCE(shiphead_freight, 0) = 0) THEN '' END AS shiphead_freight_qtdisplayrole,
level AS xtindentrole
FROM (
-SELECT shiphead_id, -1 AS lineitem_id, cohead_number AS sortkey1, shiphead_number AS sortkey2, 0 AS level,
+SELECT DISTINCT
+ shiphead_id, -1 AS lineitem_id, cohead_number AS sortkey1, shiphead_number AS sortkey2, 0 AS level,
shiphead_order_type,
shiphead_number,
cohead_number AS order_number,
'' AS itemdescription,
'' AS warehous_code,
0 AS qtyord,
- 0 AS qtyshipped
-FROM shiphead, cohead, custinfo
+ 0 AS qtyshipped,
+ firstline(shiphead_notes) AS notes
+FROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)
+ JOIN custinfo ON (cust_id=cohead_cust_id)
+<? if exists("warehous_id") ?>
+ JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+ JOIN coitem ON (coitem_id=shipitem_orderitem_id)
+ JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+<? endif ?>
WHERE ( (shiphead_order_id=cohead_id)
AND (cohead_cust_id=cust_id)
AND (shiphead_shipped)
<? if exists("startDate") ?>
AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)
<? endif ?>
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
<? if exists("sohead_id") ?>
AND (cohead_id = <? value("sohead_id") ?>)
<? endif ?>
(item_descrip1 || ' ' || item_descrip2) AS itemdescription,
warehous_code,
coitem_qtyord AS qtyord,
- SUM(shipitem_qty) AS qtyshipped
+ SUM(shipitem_qty) AS qtyshipped,
+ '' AS notes
FROM shipitem, shiphead, coitem, cohead, custinfo, itemsite, item, whsinfo
WHERE ( (shipitem_shiphead_id=shiphead_id)
AND (shipitem_orderitem_id=coitem_id)
<? if exists("startDate") ?>
AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)
<? endif ?>
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
<? if exists("sohead_id") ?>
AND (cohead_id = <? value("sohead_id") ?>)
<? endif ?>
'' AS itemdescription,
'' AS warehous_code,
0 AS qtyord,
- 0 AS qtyshipped
+ 0 AS qtyshipped,
+ firstline(shiphead_notes) AS notes
FROM shiphead, tohead
WHERE ( (shiphead_order_id=tohead_id)
AND (shiphead_shipped)
<? if exists("startDate") ?>
AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)
<? endif ?>
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
<? if exists("tohead_id") ?>
AND (tohead_id = <? value("tohead_id") ?>)
<? endif ?>
(item_descrip1 || ' ' || item_descrip2) AS itemdescription,
tohead_srcname AS warehous_code,
toitem_qty_ordered AS qtyord,
- SUM(shipitem_qty) AS qtyshipped
+ SUM(shipitem_qty) AS qtyshipped,
+ '' AS notes
FROM shipitem, shiphead, toitem, tohead, item
WHERE ( (shipitem_shiphead_id=shiphead_id)
AND (shipitem_orderitem_id=toitem_id)
<? if exists("startDate") ?>
AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)
<? endif ?>
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
<? if exists("tohead_id") ?>
AND (tohead_id = <? value("tohead_id") ?>)
<? endif ?>
tohead_number, shiphead_shipdate,
toitem_linenumber, item_number, item_descrip1, item_descrip2,
tohead_srcname, shiphead_tracknum, toitem_qty_ordered,
- shiphead_freight, shiphead_freight_curr_id
+ shiphead_freight, shiphead_freight_curr_id, notes
<? endif ?>
) AS data
ORDER BY sortkey1, sortkey2, level, linenumber DESC;
-- Group: shippingForm
-- Name: shipment
-- Notes: used by printShippingForm
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cohead_id AS order_id, cohead_shiptoname AS shipto,
-- Group: slowMovingInventoryByClassCode
-- Name: detail
-- Notes: used by dspSlowMovingInventoryByClassCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, warehous_code, item_number,
-- Group: standardJournalHistory
-- Name: detail
-- Notes: used by dspStandardJournalHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT gltrans_sequence, gltrans_id,
-- Group: substituteAvailability
-- Name: detail
-- Notes: used by dspSubstituteAvailabilityByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT s_itemsite_id, warehous_code, item_number, itemdescrip,
-- Group: summarizedBacklogByWarehouse
-- Name: counts
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT COUNT(coitem.*) AS totalitems
-- Group: summarizedBacklogByWarehouse
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT * FROM (
-- Group: summarizedBacklogByWarehouse
-- Name: qtys
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT formatQty(COALESCE(SUM(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned), 0)) AS f_totalqty
-- Group: summarizedBacklogByWarehouse
-- Name: totals
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT COUNT(cohead_id) AS totalorders
-- Group: summarizedBankrecHistory
-- Name: detail
-- Notes: used by dspSummarizedBankrecHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-SELECT bankrec_posted, bankrec_postdate,
- bankrec_username, bankrec_opendate,
- bankrec_enddate, bankrec_openbal, bankrec_endbal,
+SELECT *,
'curr' AS bankrec_openbal_xtnumericrole,
'curr' AS bankrec_endbal_xtnumericrole
FROM bankrec
-- Group: summarizedGLTransactions
-- Name: detail
-- Notes: used by dspSummarizedGLTransactions
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT accnt_id, gltrans_id,
-- Group: summarizedSalesHistory
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT 1 AS dummy,
-- Group: taxAuthorities
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: taxBreakdown
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("invchead_id") ?>
-- Notes:
-----------BEGIN SUMMARY----------
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists("summary") ?>
-- Group: timePhasedAvailability
-- Name: detail
-- Notes: used by dspTimePhasedAvailability
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, itemtype,
-- Group: timePhasedBookings
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: timePhasedSales
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: timePhasedUsageStatisticsByItem
-- Name: detail
-- Notes: used by dspTimePhasedUsageStatisticsByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
-- Group: todolist
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT * FROM (
-- Group: trialBalances
-- Name: detail
-- Notes: used by dspTrialBalances
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT accnt_id, period_id, accnt_descrip, trialbal_dirty,
-- Group: uiforms
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
<? if exists('byPackage') ?>
-- Group: unbalancedQOHByClassCode
-- Name: detail
-- Notes: used by dspUnbalancedQOHByClassCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT itemsite_id, warehous_code, item_number,
-- Group: undefinedManufacturedItems
-- Name: detail
-- Notes: used by dspUndefinedManufacturedItems
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT item_id, 2, item_number, (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,
-- Group: uninvoicedReceivings
-- Name: detail
-- Notes: used by dspUninvoicedReceivings
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT recv_id AS id,
-- Group: uninvoicedShipments
-- Name: detail
-- Notes: used by uninvoicedShipments
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT cohead_id, shipitem_id, cohead_number, coitem_linenumber,
-- Group: unpostedCashReceipts
-- Name: detail
-- Notes: Used by arWorkBench, cashReceiptsEditList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT
-- Name: detail
-- Notes: used by unpostedPoReceipts
---------PURCHASE ORDERS----------
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT recv_id, recv_orderitem_id, recv_order_number, recv_order_type,
-- Group: unusedPurchasedItems
-- Name: detail
-- Notes: used by dspUnusedPurchasedItems.cpp
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT DISTINCT item_id, item_number,
-- Group: uoms
-- Name: item
-- Notes: used by bomItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT uom_id, uom_name
-- Group: updateListPrices
-- Name: update
-- Notes: Calculates and immediately updates list prices to the database
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
UPDATE item SET item_listprice=
-- Name: add
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
INSERT INTO selsched
-- Name: availsched
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT ipshead_id, ipshead_name, ipshead_descrip,
-- Name: createselsched
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
CREATE TEMPORARY TABLE selsched (
-- Name: dropselsched
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DROP TABLE selsched;
-- Name: remove
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DELETE FROM selsched
-- Name: selsched
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT selsched_ipshead_id, ipshead_name, ipshead_descrip
-- Name: update
-- Notes:
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
UPDATE ipsiteminfo SET
-- Group: updateprices
-- Name: updatechar
-- Notes: used by updatePrices
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
UPDATE ipsitemchar SET
-- Group: updateReorderLevels
-- Name: post
-- Notes: itemsite with new reorder level
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
UPDATE itemsite SET
-- Group: updateReorderLevels
-- Name: query
-- Notes: Calculates reorder point levels and returns a proposed result set
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
'qty' AS reordlvl_curr_level_xtnumericrole,
- 'qty' AS reordlvl_calc_level_xtnumericrole,
'qty' AS reordlvl_total_usage_xtnumericrole
FROM updateReorderLevel((
SELECT array(
-- Group: updateReorderLevels
-- Name: update
-- Notes: Calculates and immediatly updates reorder point levels to the database
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT updateReorderLevel(itemsite_id,<? value("daysOfStock") ?>,
-- Group: usageStatistics
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT *,
-- Group: validLocationsByItem
-- Name: detail
-- Notes: used by dspValidLocationsByItem.cpp
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT location_id, warehous_code,
-- Group: vendorAPHistory
-- Name: detail
-- Notes: used by dspVendorAPHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT apopen_id, -1 AS applyid, 0 AS type,
-- Group: vendors
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
vend_id, vend_vendtype_id,
vend_active, vend_number, vend_name,
vendtype_code,
+<? foreach("char_id_text_list") ?>
+ charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,
+<? endforeach ?>
cntct.*, addr.*
FROM vendinfo
JOIN vendtype ON (vend_vendtype_id=vendtype_id)
LEFT OUTER JOIN cntct ON (vend_cntct1_id=cntct_id)
LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+<? foreach("char_id_text_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?>
+ ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='V')
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=vend_id)
+ AND (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?>
+ ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='V')
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=vend_id)
+ AND (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+ 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)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+ LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?>
+ ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='V')
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=vend_id)
+ AND (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+ 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)
+<? endforeach ?>
WHERE true
<? if not exists("showInactive") ?>
AND vend_active
<? if exists("addr_country_pattern") ?>
AND (COALESCE(addr_country,'') ~* <? value("addr_country_pattern") ?>)
<? endif ?>
+<? literal("charClause") ?>
ORDER BY vend_number;
-- line item
-- credit account
-- debit account for entire order
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT orderid, seq,
-- Group: voucherItem
-- Name: distributions
-- Notes: used by voucherItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT vodist_id, vodist_amount,
-- Group: voucherItem
-- Name: receipts
-- Notes: used by voucherItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT recv_id AS item_id, 1 AS item_type, 'REC' AS action,
WHERE ( (NOT recv_invoiced)
AND (recv_posted)
AND ((recv_vohead_id IS NULL) OR (recv_vohead_id=<? value("vohead_id") ?>))
+ AND (recv_order_type='PO')
AND (recv_orderitem_id=<? value("poitem_id") ?>) )
UNION
-- Group: voucherRegister
-- Name: detail
-- Notes: used by dspVoucherRegister
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT gltrans_id, gltrans_date,
-- Group: whereUsed
-- Name: detail
-- Notes: used by dspSingleLevelWhereUsed, dspIndentedWhereUsed
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT <? if exists("byIndented") ?>
-- Group: workOrderHistory
-- Name: detail
-- Notes: used by dspWoHistoryByNumber, dspWoHistoryByItem, dspWoHistoryByClassCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT
-- Group: workOrderMaterial
-- Name: detail
-- Notes: used by dspWoMaterialsByItem, dspWoMaterialsByWorkOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT womatl.*, formatWONumber(wo_id) AS wonumber, item_number,
-- Group: workOrderSchedule
-- Name: detail
-- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT wo_id,
-- Group: workOrderSchedule
-- Name: parameterlist
-- Notes: used by dspWoScheduleByParameterList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT wo_id,
-- Notes: used by dspMaterialUsageVarianceByBOMItem, dspMaterialUsageVarianceByComponentItem,
-- dspMaterialUsageVarianceByItem, dspMaterialUsageVarianceByWarehouse,
-- dspMaterialUsageVarianceByWorkOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
SELECT womatlvar_id, posted,
-
-SELECT dropIfExists('VIEW', 'cust', 'public', true);
-CREATE VIEW cust AS
+CREATE OR REPLACE VIEW cust AS
SELECT cust_id, cust_active, cust_custtype_id, cust_salesrep_id,
cust_commprcnt, cust_name,
m.addr_line1 AS cust_address1,
CASE WHEN (ipsitem_type='N') THEN (ipsitem_price * itemuomtouomratio(ipsitem_item_id, NULL, ipsitem_price_uom_id)) *
iteminvpricerat(ipsitem_item_id)
WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+ WHEN ((ipsitem_type='M') AND fetchMetricBool('Long30Markups')) THEN
+ (stdCost(item_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
END AS ipsprice_price,
ipsitem_qtybreak AS ipsprice_uomqtybreak,
ipsitem_qty_uom_id AS ipsprice_uomqtybreak_uom_id,
CASE WHEN (ipsitem_type='N') THEN ipsitem_price
WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+ WHEN ((ipsitem_type='M') AND fetchMetricBool('Long30Markups')) THEN
+ (stdCost(item_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
END AS ipsprice_uomprice,
ipsitem_price_uom_id AS ipsprice_uomprice_uom_id,
item_id AS ipsprice_item_id,
ipsitem_qtybreak AS ipsprice_qtybreak,
CASE WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+ WHEN ((ipsitem_type='M') AND fetchMetricBool('Long30Markups')) THEN
+ (stdCost(item_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
END AS ipsprice_price,
ipsitem_qtybreak AS ipsprice_uomqtybreak,
item_inv_uom_id AS ipsprice_uomqtybreak_uom_id,
CASE WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+ WHEN ((ipsitem_type='M') AND fetchMetricBool('Long30Markups')) THEN
+ (stdCost(item_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
END AS ipsprice_uomprice,
item_price_uom_id AS ipsprice_uomprice_uom_id,