summaryrefslogtreecommitdiff
path: root/add_prebuild.php
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-14 10:49:24 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-14 10:49:24 +0100
commite8aa652c4f0d2f780171d7bbd2c351c05a1025e9 (patch)
tree2ee249d771ee88e7d3d1cc209a3048fd37161b56 /add_prebuild.php
parent3866f6c02cfae647d04e9123392b608e0d0aa3a6 (diff)
downloadstock-e8aa652c4f0d2f780171d7bbd2c351c05a1025e9.tar.gz
stock-e8aa652c4f0d2f780171d7bbd2c351c05a1025e9.tar.bz2
stock-e8aa652c4f0d2f780171d7bbd2c351c05a1025e9.zip
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 <header>/<section> pattern with kitelf breadcrumb; getDirection() explicit for PBLD Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'add_prebuild.php')
-rw-r--r--add_prebuild.php112
1 files changed, 112 insertions, 0 deletions
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 @@
+<?php
+/**
+ * @package stock
+ * @subpackage functions
+ */
+
+namespace Bitweaver\Stock;
+
+use Bitweaver\KernelTools;
+
+require_once '../kernel/includes/setup_inc.php';
+
+global $gBitSystem, $gBitSmarty, $gBitUser, $gBitDb;
+
+$gBitSystem->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' ] );