4 -- Quantity on Hand By Location
5 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
6 -- See www.xtuple.com/CPAL for the full text of the software license.
8 <? if exists("byLocation") ?>
9 SELECT itemloc_id, alt_id, warehous_code, item_number,
10 f_descrip, f_lotserial, uom_name,
12 'qty' AS qoh_xtnumericrole,
13 'qty' AS reservedqty_xtnumericrole,
16 SELECT itemloc_id, 0 AS alt_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
17 (item_descrip1 || ' ' || item_descrip2) AS f_descrip,
18 formatlotserialnumber(itemloc_ls_id) AS f_lotserial, uom_name,
20 <? if exists("EnableSOReservationsByLocation") ?>
21 qtyReservedLocation(itemloc_id) AS reservedqty
25 FROM itemloc, itemsite, whsinfo, item, uom
26 WHERE ((itemloc_itemsite_id=itemsite_id)
27 AND (itemsite_item_id=item_id)
28 AND (item_inv_uom_id=uom_id)
29 AND (itemsite_warehous_id=warehous_id)
30 AND (itemloc_location_id=<? value("location_id") ?>))
32 SELECT -1 AS itemloc_id, 0 AS alt_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
33 (item_descrip1 || ' ' || item_descrip2) AS f_descrip,
34 <? value("na") ?> AS f_lotserial, uom_name,
35 itemsite_qtyonhand AS qoh,
37 FROM itemsite, whsinfo, item, uom
38 WHERE ((itemsite_item_id=item_id)
39 AND (item_inv_uom_id=uom_id)
40 AND (itemsite_warehous_id=warehous_id)
41 AND (NOT itemsite_loccntrl)
42 AND (itemsite_location_id=<? value("location_id") ?>))
43 <? if exists("EnableSOReservationsByLocation") ?>
45 SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
46 (reserve_demand_type || '-' || formatSOItemNumber(reserve_demand_id)) AS f_descrip,
47 '' AS f_lotserial, '' AS uom_name,
49 reserve_qty AS reservedqty
50 FROM reserve, itemloc, itemsite, item
51 WHERE ((reserve_supply_id=itemloc_id)
52 AND (reserve_supply_type='I')
53 AND (itemsite_id=itemloc_itemsite_id)
54 AND(item_id=itemsite_item_id)
55 AND(itemloc_location_id=<? value("location_id") ?>))
57 <? if exists("ShowDemand") ?>
59 SELECT itemloc_id, coitem_cohead_id AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
60 (<? value("so") ?>|| '-' || formatSOItemNumber(coitem_id)) AS f_descrip,
61 '' AS f_lotserial, '' AS uom_name,
62 itemUOMtoUOM(item_id, coitem_qty_uom_id, NULL, (coitem_qtyord - coitem_qtyshipped - qtyAtShipping(coitem_id))) AS qoh,
64 FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
65 JOIN item ON (item_id=itemsite_item_id)
66 JOIN coitem ON (coitem_itemsite_id=itemloc_itemsite_id AND coitem_status='O')
67 WHERE ((coitem_qtyord > (coitem_qtyshipped + qtyAtShipping(coitem_id)))
68 AND(itemloc_location_id=<? value("location_id") ?>))
70 SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
71 (<? value("wo") ?>|| '-' || formatWONumber(womatl_wo_id)) AS f_descrip,
72 '' AS f_lotserial, '' AS uom_name,
73 (womatl_qtyreq - womatl_qtyiss) AS qoh,
75 FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
76 JOIN item ON (item_id=itemsite_item_id)
77 JOIN womatl ON (womatl_itemsite_id=itemloc_itemsite_id)
78 WHERE ((womatl_qtyreq > womatl_qtyiss)
79 AND(itemloc_location_id=<? value("location_id") ?>))
81 SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
82 (<? value("to") ?>|| '-' || formatTONumber(toitem_id)) AS f_descrip,
83 '' AS f_lotserial, '' AS uom_name,
84 (toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS qoh,
86 FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
87 JOIN item ON (item_id=itemsite_item_id)
88 JOIN toitem ON (toitem_item_id=item_id AND toitem_status='O')
89 JOIN tohead ON (tohead_id=toitem_tohead_id AND tohead_src_warehous_id=itemsite_warehous_id)
90 WHERE ((toitem_qty_ordered > (toitem_qty_shipped + qtyAtShipping('TO', toitem_id)))
91 AND(itemloc_location_id=<? value("location_id") ?>))
95 sortkey, itemloc_id, level;
97 <? if exists("asOf") ?>
98 SELECT forwardupdateinvbalance(invbal_id)
100 SELECT DISTINCT ON (itemsite_id) invbal_id
101 FROM invbal, itemsite, item, whsinfo, classcode, uom, costcat, period
102 WHERE ((invbal_dirty)
103 AND (invbal_period_id=period_id)
104 AND (itemsite_item_id=item_id)
105 AND (itemsite_warehous_id=warehous_id)
106 AND (itemsite_active)
107 AND (item_inv_uom_id=uom_id)
108 AND (item_classcode_id=classcode_id)
109 AND (itemsite_costcat_id=costcat_id)
110 <? if exists("item_id") ?>
111 AND (itemsite_item_id=<? value("item_id") ?>)
113 <? if exists("classcode_id") ?>
114 AND (classcode_id=<? value("classcode_id") ?>)
116 <? if exists("classcode_pattern") ?>
117 AND (classcode_id IN (SELECT classcode_id
119 WHERE classcode_code ~ <? value("classcode_pattern") ?>))
121 <? if exists("costcat_id") ?>
122 AND (costcat_id=<? value("costcat_id") ?>)
124 <? if exists("costcat_pattern") ?>
125 AND (costcat_id IN (SELECT costcat_id
127 WHERE costcat_code ~ <? value("costcat_pattern") ?>))
129 <? if exists("itemgrp_id") ?>
130 AND (item_id IN (SELECT itemgrpitem_item_id
132 WHERE (itemgrpitem_itemgrp_id=<? value("itemgrp_id") ?>)))
134 <? if exists("itemgrp_pattern") ?>
135 AND (item_id IN (SELECT itemgrpitem_item_id
136 FROM itemgrpitem, itemgrp
137 WHERE ((itemgrpitem_itemgrp_id=itemgrp_id)
138 AND (itemgrp_name ~ <? value("itemgrp_pattern") ?>))))
140 <? if exists("showPositive") ?>
141 AND (itemsite_qtyonhand > 0)
142 <? elseif exists("showNegative") ?>
143 AND (itemsite_qtyonhand < 0)
145 <? if exists("warehous_id") ?>
146 AND (itemsite_warehous_id=<? value("warehous_id") ?>)
149 ORDER BY itemsite_id, period_start
154 SELECT itemsite_id, detail,warehous_code,
155 classcode_code, item_number, uom_name,
157 item_descrip1, item_descrip2,
158 (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,
160 reorderlevel, formatQty(reorderlevel) AS f_reorderlevel,
161 qoh, formatQty(qoh) AS f_qoh,
162 nnqoh, formatQty(nnqoh) AS f_nnqoh,
163 CASE WHEN (itemsite_loccntrl) THEN nnqoh END AS f_nnqoh,
164 cost, (cost * qoh) AS value,
165 CASE WHEN (itemsite_loccntrl) THEN (cost * nnqoh) END AS nnvalue,
166 CASE WHEN(itemsite_costmethod='A') THEN 'Average'
167 WHEN(itemsite_costmethod='S') THEN 'Standard'
168 WHEN(itemsite_costmethod='J') THEN 'Job'
169 WHEN(itemsite_costmethod='N') THEN 'None'
172 <? if exists("showValue") ?>
173 formatMoney(cost) AS f_cost, (cost * qoh) AS f_value,
174 CASE WHEN (itemsite_loccntrl) THEN (cost * nnqoh) END AS f_nnvalue,
175 CASE WHEN(itemsite_costmethod='A') THEN 'Average'
176 WHEN(itemsite_costmethod='S') THEN 'Standard'
177 WHEN(itemsite_costmethod='J') THEN 'Job'
178 WHEN(itemsite_costmethod='N') THEN 'None'
182 'qty' AS reorderlevel_xtnumericrole,
183 'qty' AS qoh_xtnumericrole,
184 'qty' AS f_nnqoh_xtnumericrole,
185 0 AS qoh_xttotalrole,
186 0 AS nnqoh_xttotalrole,
187 'cost' AS cost_xtnumericrole,
188 'curr' AS value_xtnumericrole,
189 'curr' AS nnvalue_xtnumericrole,
190 0 AS value_xttotalrole,
191 0 AS nnvalue_xttotalrole,
192 <? value("na") ?> AS nnqoh_xtnullrole,
193 <? value("na") ?> AS nnvalue_xtnullrole,
194 CASE WHEN (qoh < 0) THEN 'error' END AS qoh_qtforegroundrole,
195 CASE WHEN (reorderlevel > qoh) THEN 'warning' END AS qoh_qtforegroundrole
197 SELECT itemsite_id, itemsite_loccntrl, itemsite_costmethod,
198 ((itemsite_loccntrl) OR (itemsite_controlmethod IN ('L', 'S')) ) AS detail,
199 classcode_code, item_number, uom_name, item_descrip1, item_descrip2,
201 CASE WHEN (NOT useDefaultLocation(itemsite_id)) THEN <? value("none") ?>
202 ELSE defaultLocationName(itemsite_id)
203 END AS defaultlocation,
205 CASE WHEN(itemsite_useparams) THEN itemsite_reorderlevel ELSE 0.0 END AS reorderlevel,
206 <? if exists("asOf") ?>
207 COALESCE(invbal_qoh_ending,0) AS qoh,
208 COALESCE(invbal_nn_ending,0) AS nnqoh,
210 itemsite_qtyonhand AS qoh,
211 itemsite_nnqoh AS nnqoh,
213 <? if exists("useStandardCosts") ?>
214 stdcost(item_id) AS cost
215 <? elseif exists("useActualCosts") ?>
216 actcost(item_id) AS cost
218 <? if exists("asOf") ?>
219 COALESCE((invbal_value_ending / CASE WHEN(invbal_qoh_ending=0) THEN 1
220 ELSE invbal_qoh_ending END),0) AS cost
222 (itemsite_value / CASE WHEN((itemsite_qtyonhand + itemsite_nnqoh)=0) THEN 1
223 ELSE (itemsite_qtyonhand + itemsite_nnqoh) END) AS cost
226 FROM item, whsinfo, classcode, uom, costcat, itemsite
227 <? if exists("asOf") ?>
228 LEFT OUTER JOIN invbal ON ((itemsite_id=invbal_itemsite_id)
229 AND (invbal_period_id=<? value("asOf") ?>))
231 WHERE ((itemsite_item_id=item_id)
232 AND (itemsite_warehous_id=warehous_id)
233 AND (itemsite_active)
234 AND (item_inv_uom_id=uom_id)
235 AND (item_classcode_id=classcode_id)
236 AND (itemsite_costcat_id=costcat_id)
237 <? if exists("item_id") ?>
238 AND (itemsite_item_id=<? value("item_id") ?>)
240 <? if exists("classcode_id") ?>
241 AND (classcode_id=<? value("classcode_id") ?>)
243 <? if exists("classcode_pattern") ?>
244 AND (classcode_id IN (SELECT classcode_id
246 WHERE classcode_code ~ <? value("classcode_pattern") ?>))
248 <? if exists("costcat_id") ?>
249 AND (costcat_id=<? value("costcat_id") ?>)
251 <? if exists("costcat_pattern") ?>
252 AND (costcat_id IN (SELECT costcat_id
254 WHERE costcat_code ~ <? value("costcat_pattern") ?>))
256 <? if exists("itemgrp_id") ?>
257 AND (item_id IN (SELECT itemgrpitem_item_id
259 WHERE (itemgrpitem_itemgrp_id=<? value("itemgrp_id") ?>)))
261 <? if exists("itemgrp_pattern") ?>
262 AND (item_id IN (SELECT itemgrpitem_item_id
263 FROM itemgrpitem, itemgrp
264 WHERE ((itemgrpitem_itemgrp_id=itemgrp_id)
265 AND (itemgrp_name ~ <? value("itemgrp_pattern") ?>))))
267 <? if exists("showPositive") ?>
268 <? if exists("asOf") ?>
269 AND (COALESCE(invbal_qoh_ending,0) > 0)
271 AND (itemsite_qtyonhand > 0)
273 <? elseif exists("showNegative") ?>
274 <? if exists("asOf") ?>
275 AND (COALESCE(invbal_qoh_ending,0) < 0)
277 AND (itemsite_qtyonhand < 0)
280 <? if exists("warehous_id") ?>
281 AND (itemsite_warehous_id=<? value("warehous_id") ?>)
285 ORDER BY warehous_code, item_number;