diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-06-02 18:24:15 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-06-02 18:24:15 +0100 |
| commit | ce688ca66d15bd445c8ff0da099e5ec4eb22230f (patch) | |
| tree | 604c9eab50aefa60c8070212250227c49872bf30 | |
| parent | 3e3d270bb65d2b4443b80515b5c77bbb1c33ed3e (diff) | |
| download | stock-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>
| -rwxr-xr-x | templates/view_component.tpl | 32 | ||||
| -rwxr-xr-x | view_component.php | 25 |
2 files changed, 53 insertions, 4 deletions
diff --git a/templates/view_component.tpl b/templates/view_component.tpl index f97373c..a9bcd43 100755 --- a/templates/view_component.tpl +++ b/templates/view_component.tpl @@ -25,8 +25,8 @@ <p class="description">{$gContent->mInfo.parsed_data}</p> {/if} - {if $gContent->mInfo.stockcomponent_types} - {jstabs} + {jstabs} + {if $gContent->mInfo.stockcomponent_types} {section name=xrefGroup loop=$gContent->mInfo.stockcomponent_types} {include file=$gContent->getXrefListTemplate($gContent->mInfo.stockcomponent_types[xrefGroup].template) source=$gContent->mInfo.stockcomponent_types[xrefGroup].source @@ -34,8 +34,32 @@ group=$gContent->mInfo.stockcomponent_types[xrefGroup].sort_order allow_edit=false} {/section} - {/jstabs} - {/if} + {/if} + + {jstab title="{tr}Stock{/tr}"} + <table class="table table-condensed"> + <thead> + <tr> + <th>{tr}Type{/tr}</th> + <th class="text-right">{tr}Level{/tr}</th> + </tr> + </thead> + <tbody> + {if $componentStockLevels} + {foreach from=$componentStockLevels key=qtype item=level} + <tr{if $level < 0} class="danger"{elseif $level == 0} class="warning"{/if}> + <td>{$qtype|escape}</td> + <td class="text-right">{$level|string_format:"%.0f"}</td> + </tr> + {/foreach} + {else} + <tr class="norecords"><td colspan="2">{tr}No stock movements recorded{/tr}</td></tr> + {/if} + </tbody> + </table> + <a class="btn btn-default btn-xs" href="{$smarty.const.STOCK_PKG_URL}list_stock.php?find={$gContent->getTitle()|escape:'url'}">{tr}Stock history{/tr}</a> + {/jstab} + {/jstabs} </div><!-- end .body --> {include file="bitpackage:liberty/services_inc.tpl" serviceLocation='view' serviceHash=$gContent->mInfo} 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'; |
