summaryrefslogtreecommitdiff
path: root/view_component.php
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-02 18:24:15 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-02 18:24:15 +0100
commitce688ca66d15bd445c8ff0da099e5ec4eb22230f (patch)
tree604c9eab50aefa60c8070212250227c49872bf30 /view_component.php
parent3e3d270bb65d2b4443b80515b5c77bbb1c33ed3e (diff)
downloadstock-ce688ca66d15bd445c8ff0da099e5ec4eb22230f.tar.gz
stock-ce688ca66d15bd445c8ff0da099e5ec4eb22230f.tar.bz2
stock-ce688ca66d15bd445c8ff0da099e5ec4eb22230f.zip
view_component: add Stock Levels tab showing movement totals per qty type
Query mirrors list_stock.php for a single component. Tab shows level per qty type with danger/warning colouring, plus a link to filtered stock history. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'view_component.php')
-rwxr-xr-xview_component.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/view_component.php b/view_component.php
index 6f8ec93..de1958a 100755
--- a/view_component.php
+++ b/view_component.php
@@ -36,4 +36,29 @@ $gContent->addHit();
$gContent->mInfo['stockcomponent_types'] = $gContent->getXrefGroupList();
+// Stock levels for this component, calculated from movement xrefs
+if( $gContent->isValid() ) {
+ $X = BIT_DB_PREFIX;
+ $rows = $gBitDb->query(
+ "SELECT x.`item` AS qty_type,
+ SUM( CASE WHEN EXISTS (
+ SELECT 1 FROM `{$X}liberty_xref` r
+ WHERE r.`content_id` = x.`content_id` AND r.`item` IN ('TRANS','ORDER')
+ ) THEN CAST(x.`xkey` AS DOUBLE PRECISION)
+ ELSE -CAST(x.`xkey` AS DOUBLE PRECISION) END ) AS stock_level
+ FROM `{$X}liberty_xref` x
+ INNER JOIN `{$X}liberty_content` mc ON mc.`content_id` = x.`content_id`
+ AND mc.`content_type_guid` = 'stockmovement'
+ WHERE x.`xref` = ? AND x.`item` IN ('SGL','PCK','SHT','VOL')
+ AND x.`xkey` SIMILAR TO '[0-9]+(\.[0-9]+)?'
+ GROUP BY x.`item`",
+ [ $gContent->mContentId ]
+ );
+ $stockLevels = [];
+ foreach( $rows as $row ) {
+ $stockLevels[$row['qty_type']] = (float)$row['stock_level'];
+ }
+ $gBitSmarty->assign( 'componentStockLevels', $stockLevels );
+}
+
require_once STOCK_PKG_INCLUDE_PATH.'display_stock_component_inc.php';