summaryrefslogtreecommitdiff
path: root/list_elves.php
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 /list_elves.php
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>
Diffstat (limited to 'list_elves.php')
-rw-r--r--list_elves.php51
1 files changed, 51 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' ] );