summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-06 10:15:47 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-06 10:15:47 +0100
commitb2ae92f41dc18de0a212e579ee4b1e3362e5a4a6 (patch)
treecb36db6525c42c4227f7fcc386843db1824697f3 /includes
parentccb6c9dfdcee8d10fe845b08cea9f76fd3530a70 (diff)
downloadstock-b2ae92f41dc18de0a212e579ee4b1e3362e5a4a6.tar.gz
stock-b2ae92f41dc18de0a212e579ee4b1e3362e5a4a6.tar.bz2
stock-b2ae92f41dc18de0a212e579ee4b1e3362e5a4a6.zip
Refactor xref display to LibertyXrefGroup path throughout
- StockBase/StockAssembly/StockMovement: add loadXrefInfo() overrides to enrich supplier group with contact titles and BOM group with component titles, descriptions and pack sizes - display_stock_assembly_inc, view/edit_component, view/edit_assembly, view_movement: replace getXrefGroupList() with loadXrefInfo() + assign gXrefInfo; edit pages pass allow_edit=true - All view/edit templates: switch {section} over stockXxx_types arrays to {foreach $gXrefInfo->mGroups as $xrefGroup} object path - BOM and supplier group templates rewritten: $xrefGroup object, column widths, class="table", conditional colspan - All BOM/supplier item templates: $gContent->mInfo.$source[xref].x -> $xrefInfo.x; $source ne 'history' -> $isHistory - Dead code removed: list_xref_stock.tpl, view_xref_pck_item.tpl Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
-rwxr-xr-xincludes/classes/StockAssembly.php26
-rwxr-xr-xincludes/classes/StockBase.php19
-rw-r--r--includes/classes/StockMovement.php20
-rwxr-xr-xincludes/display_stock_assembly_inc.php3
4 files changed, 67 insertions, 1 deletions
diff --git a/includes/classes/StockAssembly.php b/includes/classes/StockAssembly.php
index 762c89b..c8b2367 100755
--- a/includes/classes/StockAssembly.php
+++ b/includes/classes/StockAssembly.php
@@ -88,6 +88,32 @@ class StockAssembly extends StockBase {
}
}
+ public function loadXrefInfo(): void {
+ parent::loadXrefInfo();
+ if( empty( $this->mXrefInfo ) ) return;
+ $bomGroup = $this->mXrefInfo->mGroups['quantity'] ?? null;
+ if( !$bomGroup || empty( $bomGroup->mXrefs ) ) return;
+ usort( $bomGroup->mXrefs, fn($a,$b) => ( $a['xorder'] <=> $b['xorder'] ) ?: strcmp( $a['item'], $b['item'] ) );
+ $componentIds = array_values( array_unique( array_filter( array_column( $bomGroup->mXrefs, 'xref' ) ) ) );
+ if( !$componentIds ) return;
+ $components = $this->mDb->getAssoc(
+ "SELECT lc.`content_id`, lc.`title`, lc.`data`, pck.`xkey` AS `pack_size`, pck.`xkey_ext` AS `pack_size_ext`
+ FROM `".BIT_DB_PREFIX."liberty_content` lc
+ LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` pck ON pck.`content_id` = lc.`content_id` AND pck.`item` = 'PCK'
+ WHERE lc.`content_id` IN (".implode( ',', array_fill( 0, count( $componentIds ), '?' ) ).")",
+ $componentIds
+ );
+ foreach( $bomGroup->mXrefs as &$row ) {
+ if( !empty( $row['xref'] ) && isset( $components[$row['xref']] ) ) {
+ $row['xref_title'] = $components[$row['xref']]['title'];
+ $row['xref_data'] = $components[$row['xref']]['data'];
+ $row['pack_size'] = $components[$row['xref']]['pack_size'];
+ $row['pack_size_ext'] = $components[$row['xref']]['pack_size_ext'];
+ }
+ }
+ unset( $row );
+ }
+
public function loadXrefList(): void {
parent::loadXrefList();
if( !empty( $this->mInfo['quantity'] ) ) {
diff --git a/includes/classes/StockBase.php b/includes/classes/StockBase.php
index 6f90752..1de52a7 100755
--- a/includes/classes/StockBase.php
+++ b/includes/classes/StockBase.php
@@ -55,6 +55,25 @@ abstract class StockBase extends LibertyContent
}
}
+ public function loadXrefInfo(): void {
+ parent::loadXrefInfo();
+ if( empty( $this->mXrefInfo ) ) return;
+ $supplierGroup = $this->mXrefInfo->mGroups['supplier'] ?? null;
+ if( !$supplierGroup || empty( $supplierGroup->mXrefs ) ) return;
+ $contactIds = array_values( array_unique( array_filter( array_column( $supplierGroup->mXrefs, 'xref' ) ) ) );
+ if( !$contactIds ) return;
+ $contacts = $this->mDb->getAssoc(
+ "SELECT lc.`content_id`, lc.`title` FROM `".BIT_DB_PREFIX."liberty_content` lc WHERE lc.`content_id` IN (".implode( ',', array_fill( 0, count( $contactIds ), '?' ) ).")",
+ $contactIds
+ );
+ foreach( $supplierGroup->mXrefs as &$row ) {
+ if( !empty( $row['xref'] ) && isset( $contacts[$row['xref']] ) ) {
+ $row['xref_title'] = $contacts[$row['xref']];
+ }
+ }
+ unset( $row );
+ }
+
public function enrichXrefDisplay( array &$pXrefInfo ): void {
if( !empty( $pXrefInfo['xref'] ) && ( $pXrefInfo['x_group'] ?? '' ) === 'supplier' ) {
if( $contact = $this->mDb->getRow(
diff --git a/includes/classes/StockMovement.php b/includes/classes/StockMovement.php
index 6754650..ec70203 100644
--- a/includes/classes/StockMovement.php
+++ b/includes/classes/StockMovement.php
@@ -131,6 +131,26 @@ class StockMovement extends LibertyContent {
return true;
}
+ public function loadXrefInfo(): void {
+ parent::loadXrefInfo();
+ if( empty( $this->mXrefInfo ) ) return;
+ $bomGroup = $this->mXrefInfo->mGroups['quantity'] ?? null;
+ if( !$bomGroup || empty( $bomGroup->mXrefs ) ) return;
+ $componentIds = array_values( array_unique( array_filter( array_column( $bomGroup->mXrefs, 'xref' ) ) ) );
+ if( !$componentIds ) return;
+ $components = $this->mDb->getAssoc(
+ "SELECT lc.`content_id`, lc.`title`, lc.`data` FROM `".BIT_DB_PREFIX."liberty_content` lc WHERE lc.`content_id` IN (".implode( ',', array_fill( 0, count( $componentIds ), '?' ) ).")",
+ $componentIds
+ );
+ foreach( $bomGroup->mXrefs as &$row ) {
+ if( !empty( $row['xref'] ) && isset( $components[$row['xref']] ) ) {
+ $row['xref_title'] = $components[$row['xref']]['title'];
+ $row['xref_data'] = $components[$row['xref']]['data'];
+ }
+ }
+ unset( $row );
+ }
+
public function loadXrefList(): void {
parent::loadXrefList();
if( !empty( $this->mInfo['quantity'] ) ) {
diff --git a/includes/display_stock_assembly_inc.php b/includes/display_stock_assembly_inc.php
index 0e684ad..54fbb6f 100755
--- a/includes/display_stock_assembly_inc.php
+++ b/includes/display_stock_assembly_inc.php
@@ -14,7 +14,8 @@ $listHash['max_records'] = $gContent->mInfo["images_per_page"] ?? $max_records;
$gContent->loadComponents( $listHash );
$gContent->loadParentAssemblies();
-$gContent->mInfo['stockassembly_types'] = $gContent->getXrefGroupList();
+$gContent->loadXrefInfo();
+$gBitSmarty->assign( 'gXrefInfo', $gContent->mXrefInfo );
$gContent->addHit();
$gBitSmarty->assign( 'listInfo', $listHash['listInfo'] );