From 8faef82f3ad9eafa081e74a84cb68d80d4a44c2c Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Fri, 19 Jun 2026 14:36:40 +0100 Subject: Add pagination to list_stock.php, default 20 records per page General list only (BOM view is assembly-bounded). Full result set is fetched and grouped in PHP first so shortages filter and CSV export see all rows; array_slice applies the page window after CSV exits. Extra URL params (user_id, find, shortages) are threaded into listInfo for the pagination links. Co-Authored-By: Claude Sonnet 4.6 --- list_stock.php | 23 +++++++++++++++++++++++ templates/list_stock.tpl | 1 + 2 files changed, 24 insertions(+) diff --git a/list_stock.php b/list_stock.php index 3de65e4..850b024 100644 --- a/list_stock.php +++ b/list_stock.php @@ -6,6 +6,8 @@ namespace Bitweaver\Stock; +use Bitweaver\BitBase; + require_once '../kernel/includes/setup_inc.php'; global $gBitSystem, $gBitSmarty, $gBitDb; @@ -31,6 +33,16 @@ if( $filterUserId ) { $X = BIT_DB_PREFIX; +$listHash = $_REQUEST; +if( !$assemblyContentId ) { + if( empty( $listHash['max_records'] ) ) { + $listHash['max_records'] = 20; + } + BitBase::prepGetList( $listHash ); +} +$maxRecords = $listHash['max_records'] ?? 20; +$offset = $listHash['offset'] ?? 0; + $bindVars = []; if( $assemblyContentId ) { @@ -203,6 +215,17 @@ if( $showShortages && isset( $_REQUEST['format'] ) && $_REQUEST['format'] === 'c exit; } +if( !$assemblyContentId ) { + $listHash['cant'] = count( $stockList ); + $stockList = array_slice( $stockList, $offset, $maxRecords, true ); + $listHash['page_records'] = count( $stockList ); + if( $filterUserId ) $listHash['listInfo']['parameters']['user_id'] = $filterUserId; + if( $find !== '' ) $listHash['listInfo']['parameters']['find'] = $find; + if( $showShortages ) $listHash['listInfo']['parameters']['shortages'] = 1; + BitBase::postGetList( $listHash ); + $gBitSmarty->assign( 'listInfo', $listHash['listInfo'] ); +} + $gBitSmarty->assign( 'stockList', $stockList ); $gBitSmarty->assign( 'assemblyListJson', $assemblyListJson ); $gBitSmarty->assign( 'assemblyContentId', $assemblyContentId ); diff --git a/templates/list_stock.tpl b/templates/list_stock.tpl index 5a992f3..71b7c88 100644 --- a/templates/list_stock.tpl +++ b/templates/list_stock.tpl @@ -106,6 +106,7 @@ {else}

{tr}No stock records found.{/tr}

{/if} + {if $listInfo}{include file="bitpackage:kernel/pagination.tpl"}{/if} -- cgit v1.3