VbzCart/docs/queries/qryRstkItms expected: Difference between revisions

From Woozle Writes Code
< VbzCart‎ | docs‎ | queries
Jump to navigation Jump to search
imported>Woozle
(fixed SQL syntax, I hope)
imported>Woozle
(QtyOrd->QtyExp)
Line 2: Line 2:
* '''Returns''': Restock items requested (ordered), not yet received, but possibly expected because the restock request hasn't been terminated (closed, orphaned, or killed).
* '''Returns''': Restock items requested (ordered), not yet received, but possibly expected because the restock request hasn't been terminated (closed, orphaned, or killed).
* '''Requires''': {{vbzcart/table|rstk_rcd_line}}, {{vbzcart/table|rstk_rcd}}, {{vbzcart/query|qryRstkItms_active}}
* '''Requires''': {{vbzcart/table|rstk_rcd_line}}, {{vbzcart/table|rstk_rcd}}, {{vbzcart/query|qryRstkItms_active}}
* '''Used by''':
* '''Used by''': admin listing of needed items
* '''Algorithm''': any positive quantities in '''&lt;'''{{vbzcart/query|qryRstkItms_active|&lt;all items in &lt;active restock requests&gt;&gt;}} - &lt;{{vbzcart|table|rstk_rcd_line|items received}} on those item requests&gt;'''&gt;'''
* '''History''':
* '''History''':
** '''2008-11-19''' Created for new restock process
** '''2008-11-19''' Created for new restock process
Line 8: Line 9:
** '''2008-12-04''' renamed: qryRstkItms_en_route &rarr; qryRstkItms_expected
** '''2008-12-04''' renamed: qryRstkItms_en_route &rarr; qryRstkItms_expected
** '''2010-01-03''' fixed syntax: have to recalculate aggregate functions to use them in a HAVING clause (bleh)
** '''2010-01-03''' fixed syntax: have to recalculate aggregate functions to use them in a HAVING clause (bleh)
** '''2010-01-04''' updated to use QtyExp instead of QtyOrd (field renamed/changed in {{vbzcart/query|qryRstkItms_active}})
==SQL==
==SQL==
<section begin=sql /><mysql>CREATE OR REPLACE VIEW qryRstkItms_expected AS
<section begin=sql /><mysql>CREATE OR REPLACE VIEW qryRstkItms_expected AS
Line 13: Line 15:
   rqi.ID_Restock,
   rqi.ID_Restock,
   rqi.ID_Item,
   rqi.ID_Item,
   SUM(rqi.QtyOrd) AS QtyOrd,
   SUM(rqi.QtyExp) AS QtyExp,
   SUM(IFNULL(rcl.QtyRecd,rcl.QtyFiled)) AS QtyRecd
   SUM(IFNULL(rcl.QtyRecd,rcl.QtyFiled)) AS QtyRecd
FROM
FROM
Line 20: Line 22:
     LEFT JOIN qryRstkItms_active AS rqi ON (rc.ID_Restock=rqi.ID_Restock) AND (rcl.ID_Item=rqi.ID_Item)
     LEFT JOIN qryRstkItms_active AS rqi ON (rc.ID_Restock=rqi.ID_Restock) AND (rcl.ID_Item=rqi.ID_Item)
GROUP BY rqi.ID_Restock, rqi.ID_Item
GROUP BY rqi.ID_Restock, rqi.ID_Item
HAVING (SUM(rqi.QtyOrd)-SUM(IFNULL(rcl.QtyRecd,rcl.QtyFiled)))>0;</mysql>
HAVING (SUM(rqi.QtyExp)-SUM(IFNULL(rcl.QtyRecd,rcl.QtyFiled)))>0;</mysql>
<section end=sql />
<section end=sql />

Revision as of 00:47, 5 January 2010

About

  • Returns: Restock items requested (ordered), not yet received, but possibly expected because the restock request hasn't been terminated (closed, orphaned, or killed).
  • Requires: Template:Vbzcart/table, Template:Vbzcart/table, Template:Vbzcart/query
  • Used by: admin listing of needed items
  • Algorithm: any positive quantities in <Template:Vbzcart/query - <Template:Vbzcart on those item requests>>
  • History:
    • 2008-11-19 Created for new restock process
    • 2008-11-24 QtyRecd falls back on QtyFiled if null
    • 2008-12-04 renamed: qryRstkItms_en_route → qryRstkItms_expected
    • 2010-01-03 fixed syntax: have to recalculate aggregate functions to use them in a HAVING clause (bleh)
    • 2010-01-04 updated to use QtyExp instead of QtyOrd (field renamed/changed in Template:Vbzcart/query)

SQL

<section begin=sql /><mysql>CREATE OR REPLACE VIEW qryRstkItms_expected AS SELECT

 rqi.ID_Restock,
 rqi.ID_Item,
 SUM(rqi.QtyExp) AS QtyExp,
 SUM(IFNULL(rcl.QtyRecd,rcl.QtyFiled)) AS QtyRecd

FROM

 (rstk_rcd_line AS rcl
   LEFT JOIN rstk_rcd AS rc ON rcl.ID_RstkRcd=rc.ID)
   LEFT JOIN qryRstkItms_active AS rqi ON (rc.ID_Restock=rqi.ID_Restock) AND (rcl.ID_Item=rqi.ID_Item)

GROUP BY rqi.ID_Restock, rqi.ID_Item HAVING (SUM(rqi.QtyExp)-SUM(IFNULL(rcl.QtyRecd,rcl.QtyFiled)))>0;</mysql> <section end=sql />