diff options
| -rw-r--r-- | list_stock.php | 30 | ||||
| -rw-r--r-- | templates/list_stock.tpl | 13 |
2 files changed, 25 insertions, 18 deletions
diff --git a/list_stock.php b/list_stock.php index 9771d4e..4589334 100644 --- a/list_stock.php +++ b/list_stock.php @@ -13,7 +13,7 @@ global $gBitSystem, $gBitSmarty, $gBitDb; $gBitSystem->verifyPermission( 'p_stock_view' ); $find = trim( $_REQUEST['find'] ?? '' ); -$hideZero = empty( $_REQUEST['show_zero'] ); +$showShortages = !empty( $_REQUEST['shortages'] ); $assemblyContentId = isset( $_REQUEST['assembly_content_id'] ) && is_numeric( $_REQUEST['assembly_content_id'] ) ? (int)$_REQUEST['assembly_content_id'] : null; $kitCount = isset( $_REQUEST['kit_count'] ) && is_numeric( $_REQUEST['kit_count'] ) && (float)$_REQUEST['kit_count'] > 0 @@ -115,19 +115,23 @@ foreach( $rows as $row ) { ]; } - // In BOM view show all components; in general list respect hide-zero filter - if( $assemblyContentId || !$hideZero || $level != 0 ) { - $stockList[$cid]['stock'][$row['qty_type']] = [ - 'level' => $level, - 'bom_qty' => $row['bom_qty'] !== null ? (float)$row['bom_qty'] : null, - 'pack_size' => $row['pack_size'] !== null ? (float)$row['pack_size'] : null, - ]; - } + $stockList[$cid]['stock'][$row['qty_type']] = [ + 'level' => $level, + 'bom_qty' => $row['bom_qty'] !== null ? (float)$row['bom_qty'] : null, + 'pack_size' => $row['pack_size'] !== null ? (float)$row['pack_size'] : null, + ]; } -// General list only: drop components with no stock rows after zero filter -if( !$assemblyContentId && $hideZero ) { - $stockList = array_filter( $stockList, fn($c) => !empty( $c['stock'] ) ); +if( $showShortages ) { + $stockList = array_filter( $stockList, function( $comp ) use ( $kitCount, $assemblyContentId ) { + foreach( $comp['stock'] as $row ) { + $short = $assemblyContentId && $row['bom_qty'] !== null + ? ( $row['level'] - $row['bom_qty'] * $kitCount ) < 0 + : $row['level'] < 0; + if( $short ) return true; + } + return false; + } ); } // Assembly selector list @@ -162,8 +166,8 @@ $gBitSmarty->assign( 'assemblyListJson', $assemblyListJson ); $gBitSmarty->assign( 'assemblyContentId', $assemblyContentId ); $gBitSmarty->assign( 'assemblyTitle', $assemblyTitle ); $gBitSmarty->assign( 'find', $find ); -$gBitSmarty->assign( 'showZero', !$hideZero ); $gBitSmarty->assign( 'showBom', (bool)$assemblyContentId ); +$gBitSmarty->assign( 'showShortages', $showShortages ); $gBitSmarty->assign( 'kitCount', $kitCount ); $gBitSystem->display( 'bitpackage:stock/list_stock.tpl', 'Stock Levels', [ 'display_mode' => 'list' ] ); diff --git a/templates/list_stock.tpl b/templates/list_stock.tpl index 6e9ede7..d70c606 100644 --- a/templates/list_stock.tpl +++ b/templates/list_stock.tpl @@ -9,7 +9,7 @@ <section class="body"> - {form ipackage="stock" ifile="list_stock.php" method="get"} + <form action="{$smarty.const.STOCK_PKG_URL}list_stock.php" method="get"> <div class="form-inline" style="margin-bottom:1em"> <div class="form-group"> <input type="hidden" name="assembly_content_id" id="ls_asm_id" value="{$assemblyContentId|default:''|escape}" /> @@ -36,17 +36,20 @@ {/if} <div class="form-group"> <label class="checkbox-inline"> - <input type="checkbox" name="show_zero" value="1" - {if $showZero} checked="checked"{/if} /> {tr}Show zero stock{/tr} + <input type="checkbox" name="shortages" value="1" + {if $showShortages} checked="checked"{/if} /> {tr}Shortages only{/tr} </label> </div> <button type="submit" class="btn btn-default btn-sm">{tr}Go{/tr}</button> + {if $showShortages} + <button type="button" class="btn btn-default btn-sm" onclick="window.print()">{tr}Print{/tr}</button> + {/if} {if $showBom && $gBitUser->hasPermission('p_stock_create')} <a class="btn btn-warning btn-sm" href="{$smarty.const.STOCK_PKG_URL}add_requisition.php?assembly_content_id={$assemblyContentId}&kit_count={$kitCount}">{tr}Create Requisition{/tr}</a> {/if} </div> - {/form} + </form> {if $stockList} <table class="table table-hover table-condensed"> @@ -64,7 +67,7 @@ <tbody> {assign var=lastBomGroup value=-1} {foreach from=$stockList item=comp} - {if $showBom && $comp.bom_group !== $lastBomGroup} + {if $showBom && !$showShortages && $comp.bom_group !== $lastBomGroup} <tr class="active"> <th colspan="10">{tr}Group{/tr} {$comp.bom_group}</th> </tr> |
