summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-19 14:05:21 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-19 14:05:21 +0100
commit0ae47a88c53911b20b2275ff526d9a9f5d49c238 (patch)
tree23dc3cf99abecf32d4b9b80d8638dabfa5a3c40b
parentce69ba3685c2043eb0310fed1712fd3084661176 (diff)
downloadstock-0ae47a88c53911b20b2275ff526d9a9f5d49c238.tar.gz
stock-0ae47a88c53911b20b2275ff526d9a9f5d49c238.tar.bz2
stock-0ae47a88c53911b20b2275ff526d9a9f5d49c238.zip
Add list_elves.php — kit elf roster with stock counts and links
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 <noreply@anthropic.com>
-rw-r--r--list_elves.php51
-rw-r--r--templates/list_elves.tpl50
-rwxr-xr-xtemplates/menu_stock.tpl3
3 files changed, 104 insertions, 0 deletions
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 @@
+<?php
+/**
+ * List kit elves — contact persons with a linked user account.
+ * Shows assembly and movement counts with links to filtered stock views.
+ * @package stock
+ */
+
+namespace Bitweaver\Stock;
+
+require_once '../kernel/includes/setup_inc.php';
+
+$gBitSystem->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}
+<div class="listing stock">
+ <header>
+ <h1>{tr}Kit Elves{/tr}</h1>
+ </header>
+
+ <section class="body">
+ <table class="table table-striped table-hover">
+ <thead>
+ <tr>
+ <th>{tr}Name{/tr}</th>
+ <th>{tr}Login{/tr}</th>
+ <th class="text-right">{tr}Assemblies{/tr}</th>
+ <th class="text-right">{tr}Movements{/tr}</th>
+ <th>{tr}Stock{/tr}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {foreach $elves as $elf}
+ <tr>
+ <td>
+ <a href="{$smarty.const.CONTACT_PKG_URL}display_contact.php?content_id={$elf.content_id}">{$elf.display_name|escape}</a>
+ </td>
+ <td>{$elf.linked_user_login|escape}</td>
+ <td class="text-right">
+ {if $elf.assembly_count}
+ <a href="{$smarty.const.STOCK_PKG_URL}list_assemblies.php?user_id={$elf.user_id}">{$elf.assembly_count}</a>
+ {else}
+ 0
+ {/if}
+ </td>
+ <td class="text-right">
+ {if $elf.movement_count}
+ <a href="{$smarty.const.STOCK_PKG_URL}list_movements.php?user_id={$elf.user_id}">{$elf.movement_count}</a>
+ {else}
+ 0
+ {/if}
+ </td>
+ <td>
+ <a href="{$smarty.const.STOCK_PKG_URL}list_stock.php?user_id={$elf.user_id}">{tr}Stock levels{/tr}</a>
+ </td>
+ </tr>
+ {foreachelse}
+ <tr><td colspan="5" class="norecords">{tr}No kit elves found.{/tr}</td></tr>
+ {/foreach}
+ </tbody>
+ </table>
+ </section>
+</div>
+{/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')}
<li><a class="item" href="{$smarty.const.STOCK_PKG_URL}view_kitlocker.php">{biticon ipackage="icons" iname="view-grid-symbolic" iexplain="Kitlocker" ilocation=menu}</a></li>
<li><a class="item" href="{$smarty.const.STOCK_PKG_URL}list_assemblies.php">{biticon ipackage="icons" iname="view-group" iexplain="List Assemblies" ilocation=menu}</a></li>
+ {if $gBitUser->hasPermission('p_contact_view')}
+ <li><a class="item" href="{$smarty.const.STOCK_PKG_URL}list_elves.php">{biticon ipackage="icons" iname="contact-new" iexplain="Kit Elves" ilocation=menu}</a></li>
+ {/if}
<li><a class="item" href="{$smarty.const.STOCK_PKG_URL}list_components.php">{biticon ipackage="icons" iname="view-list-tree" iexplain="List Components" ilocation=menu}</a></li>
<li><a class="item" href="{$smarty.const.STOCK_PKG_URL}list_movements.php">{biticon ipackage="icons" iname="view-list-details" iexplain="List Movements" ilocation=menu}</a></li>
<li><a class="item" href="{$smarty.const.STOCK_PKG_URL}list_stock.php">{biticon ipackage="icons" iname="view-form-table" iexplain="Stock Levels" ilocation=menu}</a></li>