From e8aa652c4f0d2f780171d7bbd2c351c05a1025e9 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Sun, 14 Jun 2026 10:49:24 +0100 Subject: Add multi-user (kitelf) stock filtering and PBLD prebuild movement type - list_movements/list_stock: filter by user_id (kitelf) with breadcrumb navigation; creator names in list_movements are clickable filter links - list_movements: unified part_content_id replaces separate assembly_content_id/component_content_id URL params; type-aware breadcrumb and qty column (assembly kit count vs component qty) - StockMovement::getList(): $partId/$partIsAsm collapse cmp/asm into one variable; unified part_qty/part_qty_type SELECT; PBLD added to all ref_type IN() lists and sort subqueries; lc.user_id added to SELECT - New PBLD (Prebuild) movement type: add_prebuild.php/tpl creates PBLD movements (assemblies only, BOM exploded, optional note); add_requisition retired from UI; PBLD handled in edit/view with isBuild/isPbld flags; view/edit show Build Date/Completed labels for PBLD - schema_inc.php: PBLD registered in stockmovement reference xref items - view_movement.tpl: updated to
/
pattern with kitelf breadcrumb; getDirection() explicit for PBLD Co-Authored-By: Claude Sonnet 4.6 --- add_prebuild.php | 112 +++++++++++++++++++++++++++++++++ admin/schema_inc.php | 3 +- edit_movement.php | 13 ++-- includes/classes/StockMovement.php | 68 ++++++++++++--------- list_movements.php | 72 +++++++++++++++------- list_stock.php | 32 ++++++++-- templates/add_prebuild.tpl | 119 ++++++++++++++++++++++++++++++++++++ templates/edit_movement.tpl | 10 +-- templates/list_movements.tpl | 31 +++++++--- templates/list_stock.tpl | 11 +++- templates/menu_stock.tpl | 2 +- templates/stock_simple_list_inc.tpl | 2 +- templates/view_component.tpl | 2 +- templates/view_movement.tpl | 22 ++++--- view_movement.php | 5 +- 15 files changed, 412 insertions(+), 92 deletions(-) create mode 100644 add_prebuild.php create mode 100644 templates/add_prebuild.tpl diff --git a/add_prebuild.php b/add_prebuild.php new file mode 100644 index 0000000..2c0e9fe --- /dev/null +++ b/add_prebuild.php @@ -0,0 +1,112 @@ +verifyPermission( 'p_stock_create' ); + +if( !empty( $_REQUEST['fCancel'] ) ) { + header( 'Location: '.STOCK_PKG_URL.'list_movements.php' ); + die; +} + +if( !empty( $_REQUEST['fCreate'] ) ) { + $targetContentId = 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 + ? (float)$_REQUEST['kit_count'] : 1; + $title = trim( $_REQUEST['title'] ?? '' ); + $rqRef = trim( $_REQUEST['rq_ref'] ?? '' ); + + if( !$targetContentId ) { + $errors[] = KernelTools::tra( 'Please select an assembly.' ); + } elseif( $title === '' ) { + $errors[] = KernelTools::tra( 'Please enter a build reference.' ); + } else { + $targetRow = $gBitDb->getRow( + "SELECT `title` FROM `".BIT_DB_PREFIX."liberty_content` + WHERE `content_id` = ? AND `content_type_guid` = 'stockassembly'", + [ $targetContentId ] + ); + if( !$targetRow ) { + $errors[] = KernelTools::tra( 'Assembly not found.' ); + } else { + $movement = new StockMovement(); + $paramHash = [ + 'title' => $title, + 'content_type_guid' => STOCKMOVEMENT_CONTENT_TYPE_GUID, + 'edit' => $rqRef, + ]; + if( $movement->store( $paramHash ) ) { + $pbldHash = [ + 'content_id' => $movement->mContentId, + 'item' => 'PBLD', + 'xkey' => $title, + 'fAddXref' => 1, + ]; + $movement->storeXref( $pbldHash ); + $assemblyHash = [ + 'content_id' => $movement->mContentId, + 'item' => 'ASSEMBLY', + 'xref' => $targetContentId, + 'xkey' => (string)$kitCount, + 'xkey_ext' => $targetRow['title'], + 'edit' => 'stockassembly', + 'fAddXref' => 1, + ]; + $movement->storeXref( $assemblyHash ); + $movement->explodeFromAssembly( $targetContentId, $kitCount ); + header( 'Location: '.STOCK_PKG_URL.'edit_movement.php?content_id='.$movement->mContentId ); + die; + } + $errors = $movement->mErrors; + } + } +} + +$assembly = new StockAssembly(); +$asmHash = [ 'show_empty' => true, 'sort_mode' => 'title_asc', 'max_records' => 1000 ]; +$assemblyList = $assembly->getList( $asmHash ); + +$preselect = 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'] : 1; + +$itemIds = array_column( $assemblyList, 'content_id' ); +$klidMap = []; +if( $itemIds ) { + $klidRows = $gBitDb->getAll( + "SELECT x.`content_id`, x.`xkey` FROM `".BIT_DB_PREFIX."liberty_xref` x + WHERE x.`item` = 'KLID' AND x.`content_id` IN (".implode( ',', array_fill( 0, count( $itemIds ), '?' ) ).")", + $itemIds + ); + foreach( $klidRows as $r ) { $klidMap[$r['content_id']] = $r['xkey']; } +} +$itemListJson = json_encode( array_map( + fn( $i ) => [ 'id' => (int)$i['content_id'], 'text' => $i['title'], 'klid' => $klidMap[$i['content_id']] ?? '' ], + $assemblyList +) ); +$preselectTitle = ''; +if( $preselect ) { + foreach( $assemblyList as $item ) { + if( (int)$item['content_id'] === $preselect ) { $preselectTitle = $item['title']; break; } + } +} + +$gBitSmarty->assign( 'itemListJson', $itemListJson ); +$gBitSmarty->assign( 'preselect', $preselect ); +$gBitSmarty->assign( 'preselectTitle', $preselectTitle ); +$gBitSmarty->assign( 'kitCount', $kitCount ); +$gBitSmarty->assign( 'errors', $errors ?? [] ); + +$gBitSystem->display( 'bitpackage:stock/add_prebuild.tpl', KernelTools::tra( 'Create Prebuild' ), [ 'display_mode' => 'edit' ] ); diff --git a/admin/schema_inc.php b/admin/schema_inc.php index edf8463..e9ab919 100755 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -163,8 +163,9 @@ $xrefTypes[] = "INSERT INTO `{$X}liberty_xref_group` (`x_group`,`content_type_gu // assembly item — links the movement to its assembly or component (multiple=1 for future multi-item reqns) $xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('ASSEMBLY','stockmovement','assembly','Assembly',1,3,'','assembly',NULL)"; -// reference items — REQN=out, TRANS=in from elf, ORDER=in from supplier +// reference items — REQN=out to kitlocker, PBLD=out prebuild, TRANS=in from elf, ORDER=in from supplier $xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('REQN', 'stockmovement','reference','Requisition',1,3,'','text',NULL)"; +$xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('PBLD','stockmovement','reference','Prebuild', 1,3,'','text',NULL)"; $xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('TRANS','stockmovement','reference','Transfer', 1,3,'','text',NULL)"; $xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('ORDER','stockmovement','reference','Order', 1,3,'','text',NULL)"; diff --git a/edit_movement.php b/edit_movement.php index 1167efd..defc9f4 100644 --- a/edit_movement.php +++ b/edit_movement.php @@ -47,7 +47,7 @@ if( !empty( $_REQUEST['fSave'] ) ) { if( !empty( $_REQUEST['movement_type'] ) && isset( $refTypes[$_REQUEST['movement_type']] ) ) { $existingRef = $gBitDb->getRow( "SELECT `xref_id` FROM `".BIT_DB_PREFIX."liberty_xref` - WHERE `content_id`=? AND `item` IN ('REQN','TRANS','ORDER') ORDER BY `xorder`", + WHERE `content_id`=? AND `item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY `xorder`", [ $gContent->mContentId ] ); $refHash = [ @@ -66,7 +66,7 @@ if( !empty( $_REQUEST['fSave'] ) ) { if( !empty( $_REQUEST['ordered_date'] ) && ($ts = parseMovementDate( $_REQUEST['ordered_date'] )) ) { $gBitDb->query( "UPDATE `".BIT_DB_PREFIX."liberty_xref` SET `start_date`=? - WHERE `content_id`=? AND `item` IN ('REQN','TRANS','ORDER')", + WHERE `content_id`=? AND `item` IN ('REQN','TRANS','ORDER','PBLD')", [ date( 'Y-m-d H:i:s', $ts ), $gContent->mContentId ] ); } @@ -187,8 +187,11 @@ $gBitSmarty->assign( 'orderedDateVal', $orderedDateVal ); $gBitSmarty->assign( 'receivedDateVal', $receivedDateVal ); $gBitSmarty->assign( 'contactLookupUrl', CONTACT_PKG_URL.'includes/lookup_contact.php' ); -$isReqn = ( ( $gContent->mInfo['ref_type'] ?? '' ) === 'REQN' ); -if( $isReqn ) { +$refType = $gContent->mInfo['ref_type'] ?? ''; +$isReqn = $refType === 'REQN'; +$isPbld = $refType === 'PBLD'; +$isBuild = in_array( $refType, [ 'REQN', 'PBLD' ] ); +if( $isBuild ) { $assembly = new StockAssembly(); $asmHash = [ 'show_empty' => true, 'sort_mode' => 'title_asc', 'max_records' => 1000 ]; $assemblyList = $assembly->getList( $asmHash ); @@ -212,6 +215,8 @@ if( $isReqn ) { ) ); } $gBitSmarty->assign( 'isReqn', $isReqn ); +$gBitSmarty->assign( 'isPbld', $isPbld ); +$gBitSmarty->assign( 'isBuild', $isBuild ); $gBitSmarty->assign( 'refTypes', $refTypes ); $gBitSmarty->assign( 'errors', $gContent->mErrors ); diff --git a/includes/classes/StockMovement.php b/includes/classes/StockMovement.php index 57e8146..178944d 100644 --- a/includes/classes/StockMovement.php +++ b/includes/classes/StockMovement.php @@ -93,24 +93,24 @@ class StockMovement extends LibertyContent { , uue.`login` AS `modifier_user`, uue.`real_name` AS `modifier_real_name` , uuc.`login` AS `creator_user`, uuc.`real_name` AS `creator_real_name` , (SELECT FIRST 1 x.`start_date` FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_start_date , (SELECT FIRST 1 xi.`cross_ref_title` FROM `{$X}liberty_xref` x JOIN `{$X}liberty_xref_item` xi ON xi.`item` = x.`item` AND xi.`content_type_guid` = 'stockmovement' - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_type_title , (SELECT FIRST 1 x.`xref` FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_contact_id , (SELECT FIRST 1 lc2.`title` FROM `{$X}liberty_xref` x JOIN `{$X}liberty_content` lc2 ON lc2.`content_id` = x.`xref` - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_contact_name , (SELECT FIRST 1 x.`item` FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_type , (SELECT FIRST 1 x.`data` FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_from_data FROM `".BIT_DB_PREFIX."liberty_content` lc LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON uue.`user_id` = lc.`modifier_user_id` @@ -208,9 +208,9 @@ class StockMovement extends LibertyContent { */ public function getDirection(): string { $refType = $this->mInfo['ref_type'] ?? null; - if( $refType === 'REQN' ) return 'O'; + if( in_array( $refType, [ 'REQN', 'PBLD' ] ) ) return 'O'; if( in_array( $refType, [ 'TRANS', 'ORDER' ] ) ) return 'I'; - return 'O'; + return ''; } /** @return bool TRUE when lc.event_time is non-zero (movement has been received). */ @@ -301,19 +301,22 @@ class StockMovement extends LibertyContent { $whereSql = " AND lc.`content_type_guid` = '".STOCKMOVEMENT_CONTENT_TYPE_GUID."'"; - if( !empty( $pListHash['ref_type'] ) && in_array( $pListHash['ref_type'], [ 'REQN', 'TRANS', 'ORDER' ] ) ) { + if( !empty( $pListHash['ref_type'] ) && in_array( $pListHash['ref_type'], [ 'REQN', 'TRANS', 'ORDER', 'PBLD' ] ) ) { $joinSql .= " INNER JOIN `".BIT_DB_PREFIX."liberty_xref` xrf ON xrf.`content_id` = lc.`content_id` AND xrf.`item` = ?"; $bindVars[] = $pListHash['ref_type']; } + $partId = 0; + $partIsAsm = false; if( $this->verifyId( $pListHash['assembly_content_id'] ?? 0 ) ) { + $partId = (int)$pListHash['assembly_content_id']; + $partIsAsm = true; $joinSql .= " INNER JOIN `".BIT_DB_PREFIX."liberty_xref` xasm ON xasm.`content_id` = lc.`content_id` AND xasm.`item` = 'ASSEMBLY' AND xasm.`xref` = ?"; - $bindVars[] = (int)$pListHash['assembly_content_id']; - } - $cmpContentId = $this->verifyId( $pListHash['component_content_id'] ?? 0 ) ? (int)$pListHash['component_content_id'] : 0; - if( $cmpContentId ) { + $bindVars[] = $partId; + } elseif( $this->verifyId( $pListHash['component_content_id'] ?? 0 ) ) { + $partId = (int)$pListHash['component_content_id']; $whereSql .= " AND EXISTS (SELECT 1 FROM `".BIT_DB_PREFIX."liberty_xref` xcf - WHERE xcf.`content_id` = lc.`content_id` AND xcf.`item` IN ('SGL','PRT','SHT','VOL') AND xcf.`xref` = $cmpContentId)"; + WHERE xcf.`content_id` = lc.`content_id` AND xcf.`item` IN ('SGL','PRT','SHT','VOL') AND xcf.`xref` = $partId)"; } if( $this->verifyId( $pListHash['user_id'] ?? 0 ) ) { $whereSql .= " AND lc.`user_id` = ?"; @@ -330,8 +333,8 @@ class StockMovement extends LibertyContent { $orderby = match( $sortMode ) { 'event_time_asc' => ' ORDER BY lc.event_time ASC', 'event_time_desc' => ' ORDER BY lc.event_time DESC', - 'ref_start_date_asc' => ' ORDER BY (SELECT FIRST 1 x.start_date FROM '.BIT_DB_PREFIX.'liberty_xref x WHERE x.content_id=lc.content_id AND x.item IN (\'REQN\',\'TRANS\',\'ORDER\') ORDER BY x.xorder) ASC', - 'ref_start_date_desc' => ' ORDER BY (SELECT FIRST 1 x.start_date FROM '.BIT_DB_PREFIX.'liberty_xref x WHERE x.content_id=lc.content_id AND x.item IN (\'REQN\',\'TRANS\',\'ORDER\') ORDER BY x.xorder) DESC', + 'ref_start_date_asc' => ' ORDER BY (SELECT FIRST 1 x.start_date FROM '.BIT_DB_PREFIX.'liberty_xref x WHERE x.content_id=lc.content_id AND x.item IN (\'REQN\',\'TRANS\',\'ORDER\',\'PBLD\') ORDER BY x.xorder) ASC', + 'ref_start_date_desc' => ' ORDER BY (SELECT FIRST 1 x.start_date FROM '.BIT_DB_PREFIX.'liberty_xref x WHERE x.content_id=lc.content_id AND x.item IN (\'REQN\',\'TRANS\',\'ORDER\',\'PBLD\') ORDER BY x.xorder) DESC', default => !empty( $sortMode ) ? ' ORDER BY '.$this->mDb->convertSortmode( $sortMode ) : ' ORDER BY lc.last_modified DESC', @@ -351,26 +354,31 @@ class StockMovement extends LibertyContent { ); $X = BIT_DB_PREFIX; - $cmpQtySelect = $cmpContentId - ? ", (SELECT FIRST 1 x.`item` FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('SGL','PRT','SHT','VOL') AND x.`xref` = $cmpContentId - ORDER BY x.`xorder`) AS cmp_qty_type, - (SELECT SUM(CAST(x.`xkey` AS DOUBLE PRECISION)) FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('SGL','PRT','SHT','VOL') AND x.`xref` = $cmpContentId) AS cmp_qty" - : ", CAST(NULL AS VARCHAR(4)) AS cmp_qty_type, CAST(NULL AS DOUBLE PRECISION) AS cmp_qty"; + if( $partIsAsm ) { + $partQtySelect = ", CAST(NULL AS VARCHAR(4)) AS part_qty_type + , CAST(xasm.`xkey` AS DOUBLE PRECISION) AS part_qty"; + } elseif( $partId ) { + $partQtySelect = ", (SELECT FIRST 1 x.`item` FROM `{$X}liberty_xref` x + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('SGL','PRT','SHT','VOL') AND x.`xref` = $partId + ORDER BY x.`xorder`) AS part_qty_type + , (SELECT SUM(CAST(x.`xkey` AS DOUBLE PRECISION)) FROM `{$X}liberty_xref` x + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('SGL','PRT','SHT','VOL') AND x.`xref` = $partId) AS part_qty"; + } else { + $partQtySelect = ", CAST(NULL AS VARCHAR(4)) AS part_qty_type, CAST(NULL AS DOUBLE PRECISION) AS part_qty"; + } $query = "SELECT lc.`content_id`, lc.`title`, lc.`created`, lc.`last_modified`, lc.`event_time`, - uu.`login`, uu.`real_name`, + lc.`user_id`, uu.`login`, uu.`real_name`, (SELECT FIRST 1 x.`item` FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_type, (SELECT FIRST 1 x.`xkey` FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_key, (SELECT FIRST 1 x.`start_date` FROM `{$X}liberty_xref` x - WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY x.`xorder`) AS ref_start_date - $cmpQtySelect + $partQtySelect $selectSql FROM `{$X}liberty_content` lc INNER JOIN `{$X}users_users` uu ON uu.`user_id` = lc.`user_id` @@ -456,7 +464,7 @@ class StockMovement extends LibertyContent { if( $ref !== '' ) { $existingRow = $this->mDb->getRow( "SELECT `xref_id`, `item` FROM `".BIT_DB_PREFIX."liberty_xref` - WHERE `content_id` = ? AND `item` IN ('REQN','TRANS','ORDER') ORDER BY `xorder`", + WHERE `content_id` = ? AND `item` IN ('REQN','TRANS','ORDER','PBLD') ORDER BY `xorder`", [ $this->mContentId ] ); // Preserve existing type if already set; default to TRANS for new rows @@ -482,7 +490,7 @@ class StockMovement extends LibertyContent { $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."liberty_xref` SET `start_date` = ? - WHERE `content_id` = ? AND `item` IN ('REQN','TRANS','ORDER')", + WHERE `content_id` = ? AND `item` IN ('REQN','TRANS','ORDER','PBLD')", [ date( 'Y-m-d H:i:s', $ts ), $this->mContentId ] ); } diff --git a/list_movements.php b/list_movements.php index 1172fd3..700c824 100644 --- a/list_movements.php +++ b/list_movements.php @@ -11,34 +11,62 @@ global $gBitSystem, $gBitSmarty, $gBitDb; $gBitSystem->verifyPermission( 'p_stock_view' ); -$componentContentId = isset( $_REQUEST['component_content_id'] ) && is_numeric( $_REQUEST['component_content_id'] ) - ? (int)$_REQUEST['component_content_id'] : null; +$partContentId = isset( $_REQUEST['part_content_id'] ) && is_numeric( $_REQUEST['part_content_id'] ) + ? (int)$_REQUEST['part_content_id'] : null; + +$partTitle = ''; +$partType = ''; +$partSize = null; +if( $partContentId ) { + $pRow = $gBitDb->getRow( + "SELECT `title`, `content_type_guid` FROM `".BIT_DB_PREFIX."liberty_content` WHERE `content_id` = ?", + [ $partContentId ] + ); + $partTitle = $pRow['title'] ?? ''; + $partType = match( $pRow['content_type_guid'] ?? '' ) { + 'stockassembly' => 'assembly', + 'stockcomponent' => 'component', + default => '', + }; + if( $partType === 'component' ) { + $ps = $gBitDb->getOne( + "SELECT CAST(x.`xkey` AS DOUBLE PRECISION) FROM `".BIT_DB_PREFIX."liberty_xref` x + WHERE x.`content_id` = ? AND x.`item` = 'PRT'", + [ $partContentId ] + ); + $partSize = $ps ? (float)$ps : null; + } +} + +$listHash = $_REQUEST; +if( $partContentId && $partType === 'assembly' ) { + $listHash['assembly_content_id'] = $partContentId; +} elseif( $partContentId && $partType === 'component' ) { + $listHash['component_content_id'] = $partContentId; +} +unset( $listHash['part_content_id'] ); $movement = new StockMovement(); -$listHash = $_REQUEST; $movementList = $movement->getList( $listHash ); -$componentTitle = ''; -$partSize = null; -if( $componentContentId ) { - $componentTitle = $gBitDb->getOne( - "SELECT `title` FROM `".BIT_DB_PREFIX."liberty_content` WHERE `content_id` = ?", - [ $componentContentId ] - ) ?: ''; - $ps = $gBitDb->getOne( - "SELECT CAST(x.`xkey` AS DOUBLE PRECISION) FROM `".BIT_DB_PREFIX."liberty_xref` x - WHERE x.`content_id` = ? AND x.`item` = 'PRT'", - [ $componentContentId ] +$filterUserId = isset( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) ? (int)$_REQUEST['user_id'] : null; +$filterUserName = ''; +if( $filterUserId ) { + $uRow = $gBitDb->getRow( + "SELECT `login`, `real_name` FROM `".BIT_DB_PREFIX."users_users` WHERE `user_id` = ?", + [ $filterUserId ] ); - $partSize = $ps ? (float)$ps : null; + $filterUserName = $uRow['real_name'] ?: $uRow['login'] ?: ''; } -$gBitSmarty->assign( 'listInfo', $listHash['listInfo'] ); -$gBitSmarty->assign( 'movementList', $movementList ); -$gBitSmarty->assign( 'filterType', $_REQUEST['ref_type'] ?? '' ); -$gBitSmarty->assign( 'assemblyContentId', isset( $_REQUEST['assembly_content_id'] ) && is_numeric( $_REQUEST['assembly_content_id'] ) ? (int)$_REQUEST['assembly_content_id'] : null ); -$gBitSmarty->assign( 'componentContentId', $componentContentId ); -$gBitSmarty->assign( 'componentTitle', $componentTitle ); -$gBitSmarty->assign( 'partSize', $partSize ); +$gBitSmarty->assign( 'listInfo', $listHash['listInfo'] ); +$gBitSmarty->assign( 'movementList', $movementList ); +$gBitSmarty->assign( 'filterType', $_REQUEST['ref_type'] ?? '' ); +$gBitSmarty->assign( 'partContentId', $partContentId ); +$gBitSmarty->assign( 'partTitle', $partTitle ); +$gBitSmarty->assign( 'partType', $partType ); +$gBitSmarty->assign( 'partSize', $partSize ); +$gBitSmarty->assign( 'filterUserId', $filterUserId ); +$gBitSmarty->assign( 'filterUserName', $filterUserName ); $gBitSystem->display( 'bitpackage:stock/list_movements.tpl', 'Movements', [ 'display_mode' => 'list' ] ); diff --git a/list_stock.php b/list_stock.php index 796161d..6ad176e 100644 --- a/list_stock.php +++ b/list_stock.php @@ -18,15 +18,31 @@ $assemblyContentId = isset( $_REQUEST['assembly_content_id'] ) && is_numeric( $_ ? (int)$_REQUEST['assembly_content_id'] : null; $kitCount = isset( $_REQUEST['kit_count'] ) && is_numeric( $_REQUEST['kit_count'] ) && (float)$_REQUEST['kit_count'] > 0 ? (float)$_REQUEST['kit_count'] : 1; +$filterUserId = isset( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) + ? (int)$_REQUEST['user_id'] : null; +$filterUserName = ''; +if( $filterUserId ) { + $uRow = $gBitDb->getRow( + "SELECT `login`, `real_name` FROM `".BIT_DB_PREFIX."users_users` WHERE `user_id` = ?", + [ $filterUserId ] + ); + $filterUserName = $uRow['real_name'] ?: $uRow['login'] ?: ''; +} $X = BIT_DB_PREFIX; $bindVars = []; if( $assemblyContentId ) { - // BOM view: start from BOM items so components with no movements still appear + // BOM view: start from BOM items so components with no movements still appear. + // Bind var order must match ? positions in the SQL: user_id (in subquery SELECT) first, + // then assemblyContentId (in FROM JOIN), then find (in WHERE). + $userSubSql = ''; + if( $filterUserId ) { + $userSubSql = " AND mc.`user_id` = ?"; + $bindVars[] = $filterUserId; + } $findSql = $find !== '' ? " AND UPPER(lc.`title`) LIKE ?" : ''; - if( $find !== '' ) $bindVars[] = '%'.strtoupper( $find ).'%'; $query = "SELECT lc.`content_id`, lc.`title`, lc.`data`, bom.`item` AS qty_type, @@ -49,7 +65,8 @@ if( $assemblyContentId ) { AND mc.`content_type_guid` = 'stockmovement' WHERE mx.`xref` = lc.`content_id` AND mx.`item` = bom.`item` - AND mx.`xkey` SIMILAR TO '[0-9]+(\.[0-9]+)?') AS stock_level + AND mx.`xkey` SIMILAR TO '[0-9]+(\.[0-9]+)?' + $userSubSql) AS stock_level FROM `{$X}liberty_content` lc INNER JOIN `{$X}liberty_xref` bom ON bom.`content_id` = ? AND bom.`item` IN ('SGL','PRT','SHT','VOL') @@ -58,11 +75,16 @@ if( $assemblyContentId ) { $findSql ORDER BY bom.`xorder`"; $bindVars[] = $assemblyContentId; + if( $find !== '' ) $bindVars[] = '%'.strtoupper( $find ).'%'; } else { // General list: only components with movement history $whereSql = ''; + if( $filterUserId ) { + $whereSql .= " AND mc.`user_id` = ?"; + $bindVars[] = $filterUserId; + } if( $find !== '' ) { - $whereSql = " AND UPPER(lc.`title`) LIKE ?"; + $whereSql .= " AND UPPER(lc.`title`) LIKE ?"; $bindVars[] = '%'.strtoupper( $find ).'%'; } @@ -187,5 +209,7 @@ $gBitSmarty->assign( 'find', $find ); $gBitSmarty->assign( 'showBom', (bool)$assemblyContentId ); $gBitSmarty->assign( 'showShortages', $showShortages ); $gBitSmarty->assign( 'kitCount', $kitCount ); +$gBitSmarty->assign( 'filterUserId', $filterUserId ); +$gBitSmarty->assign( 'filterUserName', $filterUserName ); $gBitSystem->display( 'bitpackage:stock/list_stock.tpl', 'Stock Levels', [ 'display_mode' => 'list' ] ); diff --git a/templates/add_prebuild.tpl b/templates/add_prebuild.tpl new file mode 100644 index 0000000..2f1755b --- /dev/null +++ b/templates/add_prebuild.tpl @@ -0,0 +1,119 @@ +{strip} +
+
+

{tr}Create Prebuild{/tr}

+
+ +
+ {formfeedback error=$errors} + + {form id="addPrebuildForm" ipackage="stock" ifile="add_prebuild.php"} + +
+ {formlabel label="Build Ref" for="title" mandatory="y"} + {forminput} + + {/forminput} +
+ +
+ {formlabel label="Assembly" for="assembly_search" mandatory="y"} + {forminput} + +
+ + +
+ {/forminput} +
+ +
+ {formlabel label="Qty" for="kit_count"} + {forminput} + + {/forminput} +
+ +
+ {formlabel label="Against RQ" for="rq_ref"} + {forminput} + + {/forminput} +
+ +
+ + +
+ + {/form} +
+
+{/strip} + diff --git a/templates/edit_movement.tpl b/templates/edit_movement.tpl index c4081dc..19dc70d 100644 --- a/templates/edit_movement.tpl +++ b/templates/edit_movement.tpl @@ -24,7 +24,7 @@ {/forminput} - {if !$isReqn} + {if !$isBuild} {if $refTypes}
{formlabel label="Movement Type" mandatory="y"} @@ -65,7 +65,7 @@ {/if}
- {formlabel label="Ordered" for="ordered_date"} + {formlabel label="{if $isPbld}Build Date{else}Ordered{/if}" for="ordered_date"} {forminput} @@ -73,7 +73,7 @@
- {formlabel label="Received" for="received_date"} + {formlabel label="{if $isPbld}Completed{else}Received{/if}" for="received_date"} {forminput} @@ -110,7 +110,7 @@ {if $gXrefInfo->mGroups} {jstabs} {foreach $gXrefInfo->mGroups as $xrefGroup} - {if $xrefGroup->mXGroup neq 'reference' && ($xrefGroup->mXGroup neq 'assembly' || $isReqn)} + {if $xrefGroup->mXGroup neq 'reference' && ($xrefGroup->mXGroup neq 'assembly' || $isBuild)} {include file=$gContent->getXrefListTemplate($xrefGroup->mTemplate) xrefGroup=$xrefGroup allow_add=true @@ -120,7 +120,7 @@ {/jstabs} {/if} - {if !$isReqn} + {if !$isBuild} {* ── Upload CSV (orders/transfers only) ── *}

{tr}Upload CSV{/tr}

{form enctype="multipart/form-data" ipackage="stock" ifile="edit_movement.php"} diff --git a/templates/list_movements.tpl b/templates/list_movements.tpl index 442f29d..424fff9 100644 --- a/templates/list_movements.tpl +++ b/templates/list_movements.tpl @@ -4,16 +4,18 @@
{if $gBitUser->hasPermission('p_stock_create')} - {biticon ipackage="icons" iname="list-add" iexplain="Add Requisition"} + {biticon ipackage="icons" iname="package-x-generic" iexplain="Add Prebuild"} {biticon ipackage="icons" iname="view-task-add" iexplain="Add Movement"} {/if}
- {if $componentContentId}{/if} + {if $partContentId}{/if} + {if $filterUserId}{/if}
@@ -27,13 +29,18 @@
-

{tr}Movements{/tr}{if $componentTitle} — {$componentTitle|escape}{/if}

+

{tr}Movements{/tr}{if $partTitle} — {$partTitle|escape}{/if}

+ + {tr}Movements{/tr} + {if $partTitle}› {$partTitle|escape}{/if} + {if $filterUserName}› {$filterUserName|escape}{/if} +
- {if $componentContentId} -

← {tr}Back to component{/tr}

+ {if $partContentId} +

← {if $partType eq 'assembly'}{tr}Back to assembly{/tr}{else}{tr}Back to component{/tr}{/if}

{/if} @@ -41,7 +48,7 @@ - {if $componentContentId}{/if} + {if $partContentId}{/if} @@ -54,13 +61,17 @@ - {if $componentContentId} - + {if $partContentId} + {if $partType eq 'assembly'} + + {else} + + {/if} {/if} - + {if $gBitUser->hasPermission('p_stock_update')}
{smartlink ititle="Reference" isort="title"} {tr}Type{/tr}{tr}Qty{/tr}{tr}Qty{/tr}{smartlink ititle="Ordered" isort="ref_start_date" ifile="list_movements.php" ipackage="stock"} {smartlink ititle="Received" isort="event_time" ifile="list_movements.php" ipackage="stock"} {smartlink ititle="Date" isort="created_desc"}
{$mov.title|escape} {$mov.ref_type|escape|default:'—'}{if $mov.cmp_qty_type eq 'PRT' && $partSize > 0}{math equation="q/p" q=$mov.cmp_qty p=$partSize format="%.2f"}{elseif $mov.cmp_qty_type eq 'SHT'}{$mov.cmp_qty|string_format:"%.2f"}{else}{$mov.cmp_qty|string_format:"%.0f"}{/if} {$mov.cmp_qty_type|escape}{$mov.part_qty|string_format:"%.0f"}{if $mov.part_qty_type eq 'PRT' && $partSize > 0}{math equation="q/p" q=$mov.part_qty p=$partSize format="%.2f"}{elseif $mov.part_qty_type eq 'SHT'}{$mov.part_qty|string_format:"%.2f"}{else}{$mov.part_qty|string_format:"%.0f"}{/if} {$mov.part_qty_type|escape}{if $mov.ref_start_date}{$mov.ref_start_date|bit_short_date}{else}—{/if} {if $mov.event_time}{$mov.event_time|bit_short_date}{else}—{/if} {$mov.created|bit_short_date}{$mov.real_name|default:$mov.login|escape}{$mov.real_name|default:$mov.login|escape} {biticon ipackage="icons" iname="edit" iexplain="Edit"} @@ -74,7 +85,7 @@
diff --git a/templates/list_stock.tpl b/templates/list_stock.tpl index 3250427..5a992f3 100644 --- a/templates/list_stock.tpl +++ b/templates/list_stock.tpl @@ -5,13 +5,14 @@ {if $showShortages} {biticon ipackage="icons" iname="text-csv" iexplain="Download CSV"} + href="{$smarty.const.STOCK_PKG_URL}list_stock.php?shortages=1{if $assemblyContentId}&assembly_content_id={$assemblyContentId|escape:'url'}&kit_count={$kitCount|escape:'url'}{/if}{if $filterUserId}&user_id={$filterUserId|escape:'url'}{/if}&format=csv">{biticon ipackage="icons" iname="text-csv" iexplain="Download CSV"} {if $gBitUser->hasPermission('p_stock_create')} {biticon ipackage="icons" iname="view-task-add" iexplain="Create Order"} + href="{$smarty.const.STOCK_PKG_URL}add_order.php?shortages=1{if $assemblyContentId}&assembly_content_id={$assemblyContentId|escape:'url'}&kit_count={$kitCount|escape:'url'}{/if}{if $find}&find={$find|escape:'url'}{/if}{if $filterUserId}&user_id={$filterUserId|escape:'url'}{/if}">{biticon ipackage="icons" iname="view-task-add" iexplain="Create Order"} {/if} {/if}
+ {if $filterUserId}{/if}
@@ -45,12 +46,16 @@ {if $showBom && $gBitUser->hasPermission('p_stock_create')} {tr}Create Requisition{/tr} + href="{$smarty.const.STOCK_PKG_URL}add_prebuild.php?assembly_content_id={$assemblyContentId}&kit_count={$kitCount}{if $filterUserId}&user_id={$filterUserId}{/if}">{tr}Create Prebuild{/tr} {/if}

{tr}Stock Levels{/tr}{if $assemblyTitle} — {$assemblyTitle|escape}{/if}

+ + {tr}Stock Levels{/tr} + {if $filterUserName}› {$filterUserName|escape}{/if} +
diff --git a/templates/menu_stock.tpl b/templates/menu_stock.tpl index 2f8a327..8794dbf 100755 --- a/templates/menu_stock.tpl +++ b/templates/menu_stock.tpl @@ -12,7 +12,7 @@
  • {biticon ipackage="icons" iname="kt-add-filters" iexplain="Create a Component" ilocation=menu}
  • {biticon ipackage="icons" iname="view-list-icons" iexplain="Create an Assembly" ilocation=menu}
  • {biticon ipackage="icons" iname="view-task-add" iexplain="Add Movement" ilocation=menu}
  • -
  • {biticon ipackage="icons" iname="view-task-child-add" iexplain="Create Requisition" ilocation=menu}
  • +
  • {biticon ipackage="icons" iname="package-x-generic" iexplain="Create Prebuild" ilocation=menu}
  • {/if} {/strip} diff --git a/templates/stock_simple_list_inc.tpl b/templates/stock_simple_list_inc.tpl index 8ff0126..4f3347f 100755 --- a/templates/stock_simple_list_inc.tpl +++ b/templates/stock_simple_list_inc.tpl @@ -8,7 +8,7 @@ {/if} {biticon ipackage="icons" iname="document-print" iexplain="Print Parts List"} {biticon ipackage="icons" iname="package-x-generic" iexplain="View Stock"} - {biticon ipackage="icons" iname="go-next" iexplain="View Movements"} + {biticon ipackage="icons" iname="go-next" iexplain="View Movements"} {if $gContent->hasAdminPermission()} {biticon ipackage="icons" iname="user-trash" iexplain="Delete Assembly"} {/if} diff --git a/templates/view_component.tpl b/templates/view_component.tpl index 80466e7..c5d94b5 100755 --- a/templates/view_component.tpl +++ b/templates/view_component.tpl @@ -59,7 +59,7 @@ {/if} - {tr}Stock history{/tr} + {tr}Stock history{/tr} {/jstab} {/jstabs}
    diff --git a/templates/view_movement.tpl b/templates/view_movement.tpl index f038cb6..b815618 100644 --- a/templates/view_movement.tpl +++ b/templates/view_movement.tpl @@ -1,15 +1,19 @@ {strip}
    -
    +
    - {if $gBitUser->hasPermission('p_stock_create')} + {if $gContent->hasUpdatePermission()} {biticon ipackage="icons" iname="edit" iexplain="Edit Movement"} {/if}

    {$gContent->getTitle()|escape}

    -
    + + {tr}Movements{/tr} + › {$gContent->mInfo.creator|escape} + + -
    +
    {tr}Type{/tr}
    @@ -26,11 +30,11 @@
    {tr}Created{/tr}
    {$gContent->mInfo.created|bit_short_datetime} {tr}by{/tr} {$gContent->mInfo.creator|escape}
    {if $gContent->mInfo.ref_start_date} -
    {tr}Ordered{/tr}
    +
    {if $isPbld}{tr}Build Date{/tr}{else}{tr}Ordered{/tr}{/if}
    {$gContent->mInfo.ref_start_date|bit_short_date}
    {/if} -
    {tr}Received{/tr}
    -
    {if $gContent->isReceived()}{$gContent->mInfo.event_time|bit_short_date}{else}{tr}Pending{/tr}{/if}
    +
    {if $isPbld}{tr}Completed{/tr}{else}{tr}Received{/tr}{/if}
    +
    {if $gContent->isReceived()}{$gContent->mInfo.event_time|bit_short_date}{else}{if $isPbld}{tr}In progress{/tr}{else}{tr}Pending{/tr}{/if}{/if}
    {if $gContent->mInfo.last_modified neq $gContent->mInfo.created}
    {tr}Modified{/tr}
    {$gContent->mInfo.last_modified|bit_short_datetime} {tr}by{/tr} {$gContent->mInfo.editor|escape}
    @@ -44,7 +48,7 @@ {if $gXrefInfo->mGroups} {jstabs} {foreach $gXrefInfo->mGroups as $xrefGroup} - {if $xrefGroup->mXGroup neq 'reference' && ($xrefGroup->mXGroup neq 'assembly' || $isReqn)} + {if $xrefGroup->mXGroup neq 'reference' && ($xrefGroup->mXGroup neq 'assembly' || $isBuild)} {include file=$gContent->getXrefListTemplate($xrefGroup->mTemplate) xrefGroup=$xrefGroup allow_add=false @@ -54,6 +58,6 @@ {/jstabs} {/if} -
    +
    {/strip} diff --git a/view_movement.php b/view_movement.php index 395fce0..eca7f01 100644 --- a/view_movement.php +++ b/view_movement.php @@ -23,6 +23,9 @@ $gBitSystem->setCanonicalLink( $gContent->getDisplayUrl() ); $gContent->loadXrefInfo(); $gBitSmarty->assign( 'gXrefInfo', $gContent->mXrefInfo ); -$gBitSmarty->assign( 'isReqn', ( ( $gContent->mInfo['ref_type'] ?? '' ) === 'REQN' ) ); +$refType = $gContent->mInfo['ref_type'] ?? ''; +$gBitSmarty->assign( 'isReqn', $refType === 'REQN' ); +$gBitSmarty->assign( 'isPbld', $refType === 'PBLD' ); +$gBitSmarty->assign( 'isBuild', in_array( $refType, [ 'REQN', 'PBLD' ] ) ); $gBitSystem->display( 'bitpackage:stock/view_movement.tpl', $gContent->getTitle() ); -- cgit v1.3