Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

21943 #110

Merged
merged 3 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2013
  1. @garyhgohoos
Commits on Jan 16, 2014
  1. @garyhgohoos
Commits on Jan 17, 2014
  1. @garyhgohoos

    Issue #21943:tweaks

    garyhgohoos authored
This page is out of date. Refresh to see the latest.
View
48 dbscripts/functions/addtopackinglistbatch.sql
@@ -1,4 +1,4 @@
-CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER) RETURNS INTEGER AS '
+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
@@ -7,30 +7,30 @@ DECLARE
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 '
+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 '
+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
@@ -51,10 +51,32 @@ BEGIN
RETURN returnVal;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS '
+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
@@ -78,7 +100,7 @@ BEGIN
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;
@@ -87,4 +109,4 @@ BEGIN
RETURN pheadid;
END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
View
77 dbscripts/functions/getopenshipment.sql
@@ -0,0 +1,77 @@
+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;
View
39 dbscripts/functions/getsoitemstatus.sql
@@ -0,0 +1,39 @@
+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;
View
16 dbscripts/functions/issuetoshipping.sql
@@ -89,11 +89,9 @@ BEGIN
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;
@@ -241,11 +239,9 @@ BEGIN
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');
View
37 dbscripts/metasql/issueToShipping-detail.mql
@@ -22,12 +22,7 @@ SELECT coitem_id AS lineitem_id,
CASE WHEN (itemsite_costmethod = 'J') THEN 1
ELSE 0
END AS job, 0 AS indent,
- ( SELECT shiphead_number FROM shiphead
- WHERE ((shiphead_order_id=coitem_cohead_id)
- AND (shiphead_order_type='SO')
- AND (NOT shiphead_shipped))
- ORDER BY shiphead_number
- LIMIT 1 ) AS shiphead_number,
+ 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,
@@ -44,6 +39,9 @@ FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_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") ?>
@@ -72,6 +70,9 @@ FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
JOIN itemloc ON (itemloc_id=reserve_supply_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") ?>) )
<? endif ?>
@@ -79,7 +80,7 @@ WHERE ( (coitem_status NOT IN ('C','X'))
SELECT toitem_id AS lineitem_id,
0 AS lsJob, 0 AS indent,
- MIN(s1.shiphead_number) AS shiphead_number,
+ 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,
@@ -88,30 +89,18 @@ SELECT toitem_id AS lineitem_id,
toitem_qty_ordered AS qtyord,
toitem_qty_shipped AS qtyshipped,
0 AS qtyreturned,
- COALESCE(SUM(shipitem_qty), 0) AS atshipping,
+ qtyAtShipping('TO', toitem_id) AS atshipping,
toitem_schedshipdate AS seq1, toitem_linenumber AS seq2, 0 AS seq3
-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 ))
+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 seq1, seq2, seq3, indent;
View
32 dbscripts/metasql/packingListBatch-clear.mql
@@ -0,0 +1,32 @@
+-- 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 ?>
View
30 dbscripts/metasql/packingListBatch-detail.mql
@@ -4,7 +4,8 @@
-- 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,
@@ -17,13 +18,19 @@ SELECT cohead_id, pack_shiphead_id,
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,
@@ -31,8 +38,11 @@ SELECT tohead_id, pack_shiphead_id,
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;
View
26 dbscripts/metasql/packingListBatch-print.mql
@@ -4,22 +4,34 @@
-- 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 ?>
;
View
19 dbscripts/metasql/packingListBatchByShipVia-print.mql
@@ -8,14 +8,21 @@ SELECT DISTINCT pack_head_id, pack_head_type, pack_shiphead_id, getSoStatus(cohe
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
@@ -28,8 +35,14 @@ FROM pack JOIN tohead ON (tohead_id=pack_head_id)
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 ?>
;
View
21 dbscripts/metasql/packingListBatchByShipVia-shipVia.mql
@@ -8,21 +8,26 @@
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
View
24 dbscripts/metasql/salesOrderItems-list.mql
@@ -87,29 +87,7 @@ SELECT coitem_id,
(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,
View
23 dbscripts/metasql/shipments-detail.mql
@@ -38,7 +38,8 @@ SELECT shiphead_id, lineitem_id,
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,
@@ -53,7 +54,13 @@ SELECT shiphead_id, -1 AS lineitem_id, cohead_number AS sortkey1, shiphead_numbe
0 AS qtyord,
0 AS qtyshipped,
firstline(shiphead_notes) AS notes
-FROM shiphead, cohead, custinfo
+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)
@@ -61,6 +68,9 @@ WHERE ( (shiphead_order_id=cohead_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 ?>
@@ -98,6 +108,9 @@ WHERE ( (shipitem_shiphead_id=shiphead_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 ?>
@@ -134,6 +147,9 @@ WHERE ( (shiphead_order_id=tohead_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 ?>
@@ -168,6 +184,9 @@ WHERE ( (shipitem_shiphead_id=shiphead_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 ?>
View
3  dbscripts/package.xml
@@ -481,6 +481,7 @@
<createfunction file="functions/getpacklistitemlotserial.sql" name="getpacklistitemlotserial" />
<createfunction file="functions/getperiodid.sql" name="getperiodid" />
<createfunction file="functions/getpkgheadid.sql" name="getpkgheadid" />
+ <createfunction file="functions/getopenshipment.sql" name="getopenshipment" />
<createfunction file="functions/getplancodeid.sql" name="getplancodeid" />
<createfunction file="functions/getpoheadid.sql" name="getpoheadid" />
<createfunction file="functions/getpoitemid.sql" name="getpoitemid" />
@@ -508,6 +509,7 @@
<createfunction file="functions/getshipviaid.sql" name="getshipviaid" />
<createfunction file="functions/getshipzoneid.sql" name="getshipzoneid" />
<createfunction file="functions/getsitetypeid.sql" name="getsitetypeid" />
+ <createfunction file="functions/getsoitemstatus.sql" name="getsoitemstatus" />
<createfunction file="functions/getsoscheddate.sql" name="getsoscheddate" />
<createfunction file="functions/getsostatus.sql" name="getsostatus" />
<createfunction file="functions/getsubtax.sql" name="getsubtax" />
@@ -1101,6 +1103,7 @@
<loadmetasql file="metasql/package-items.mql" />
<loadmetasql file="metasql/packingList-getreport.mql" />
<loadmetasql file="metasql/packingList-shipment.mql" />
+ <loadmetasql file="metasql/packingListBatch-clear.mql" />
<loadmetasql file="metasql/packingListBatch-detail.mql" />
<loadmetasql file="metasql/packingListBatch-print.mql" />
<loadmetasql file="metasql/packingListBatchByShipVia-print.mql" />
Something went wrong with that request. Please try again.