From 0ae47a88c53911b20b2275ff526d9a9f5d49c238 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Fri, 19 Jun 2026 14:05:21 +0100 Subject: Add list_elves.php — kit elf roster with stock counts and links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lists all contact persons with a linked user account (contact.role_id set). Shows assembly and movement counts as links to filtered list_assemblies, list_movements, and list_stock views. Menu entry added under p_contact_view gate between Assemblies and Components. Co-Authored-By: Claude Sonnet 4.6 --- list_elves.php | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ templates/list_elves.tpl | 50 +++++++++++++++++++++++++++++++++++++++++++++++ templates/menu_stock.tpl | 3 +++ 3 files changed, 104 insertions(+) create mode 100644 list_elves.php create mode 100644 templates/list_elves.tpl diff --git a/list_elves.php b/list_elves.php new file mode 100644 index 0000000..84ba902 --- /dev/null +++ b/list_elves.php @@ -0,0 +1,51 @@ +verifyPackage( 'stock' ); +$gBitUser->requirePermission( 'p_contact_view' ); + +global $gBitSystem, $gBitSmarty, $gBitDb; + +$X = BIT_DB_PREFIX; + +$rs = $gBitDb->query( + "SELECT con.`content_id`, con.`role_id` AS user_id, + lc.`title`, + x00.`xkey_ext` AS name_parts, + uu.`login` AS linked_user_login, + uu.`real_name` AS linked_user_name, + (SELECT COUNT(*) FROM `{$X}liberty_content` ac + WHERE ac.`content_type_guid` = 'stockassembly' AND ac.`user_id` = con.`role_id`) AS assembly_count, + (SELECT COUNT(*) FROM `{$X}liberty_content` mc + WHERE mc.`content_type_guid` = 'stockmovement' AND mc.`user_id` = con.`role_id`) AS movement_count + FROM `{$X}contact` con + INNER JOIN `{$X}liberty_content` lc ON lc.`content_id` = con.`content_id` + INNER JOIN `{$X}users_users` uu ON uu.`user_id` = con.`role_id` + LEFT JOIN `{$X}liberty_xref` x00 ON x00.`content_id` = con.`content_id` AND x00.`item` = 'P01' + WHERE con.`role_id` IS NOT NULL + ORDER BY lc.`title`" +); + +$elves = []; +while( $row = $rs->fetchRow() ) { + $parts = explode( '|', $row['name_parts'] ?? '' ); + $row['display_name'] = trim( implode( ' ', array_filter( [ + $parts[0] ?? '', + $parts[1] ?? '', + $parts[2] ?? '', + $parts[3] ?? '', + ] ) ) ) ?: $row['linked_user_name'] ?: $row['title']; + $elves[] = $row; +} + +$gBitSmarty->assign( 'elves', $elves ); +$gBitSystem->setBrowserTitle( 'Kit Elves' ); +$gBitSystem->display( 'bitpackage:stock/list_elves.tpl', null, [ 'display_mode' => 'list' ] ); diff --git a/templates/list_elves.tpl b/templates/list_elves.tpl new file mode 100644 index 0000000..d35ffc4 --- /dev/null +++ b/templates/list_elves.tpl @@ -0,0 +1,50 @@ +{strip} +
+
+

{tr}Kit Elves{/tr}

+
+ +
+ + + + + + + + + + + + {foreach $elves as $elf} + + + + + + + + {foreachelse} + + {/foreach} + +
{tr}Name{/tr}{tr}Login{/tr}{tr}Assemblies{/tr}{tr}Movements{/tr}{tr}Stock{/tr}
+ {$elf.display_name|escape} + {$elf.linked_user_login|escape} + {if $elf.assembly_count} + {$elf.assembly_count} + {else} + 0 + {/if} + + {if $elf.movement_count} + {$elf.movement_count} + {else} + 0 + {/if} + + {tr}Stock levels{/tr} +
{tr}No kit elves found.{/tr}
+
+
+{/strip} diff --git a/templates/menu_stock.tpl b/templates/menu_stock.tpl index 8794dbf..949b78c 100755 --- a/templates/menu_stock.tpl +++ b/templates/menu_stock.tpl @@ -4,6 +4,9 @@ {if $gBitUser->hasPermission('p_stock_view')}
  • {biticon ipackage="icons" iname="view-grid-symbolic" iexplain="Kitlocker" ilocation=menu}
  • {biticon ipackage="icons" iname="view-group" iexplain="List Assemblies" ilocation=menu}
  • + {if $gBitUser->hasPermission('p_contact_view')} +
  • {biticon ipackage="icons" iname="contact-new" iexplain="Kit Elves" ilocation=menu}
  • + {/if}
  • {biticon ipackage="icons" iname="view-list-tree" iexplain="List Components" ilocation=menu}
  • {biticon ipackage="icons" iname="view-list-details" iexplain="List Movements" ilocation=menu}
  • {biticon ipackage="icons" iname="view-form-table" iexplain="Stock Levels" ilocation=menu}
  • -- cgit v1.3