summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-03 22:07:34 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-03 22:07:34 +0100
commit8fd8add7673c2440ea8f7653f1c3b44e9518cf38 (patch)
treeaa759a432e86368a21b80c9df0fa2be7f7b09f40 /includes
parent4bbff18f76c601324b865a2084b3d1e4bf8dc7e5 (diff)
downloadstock-8fd8add7673c2440ea8f7653f1c3b44e9518cf38.tar.gz
stock-8fd8add7673c2440ea8f7653f1c3b44e9518cf38.tar.bz2
stock-8fd8add7673c2440ea8f7653f1c3b44e9518cf38.zip
stock: movement contact linkage, note field, view/edit tidy
- importCsv: look up contact by SCREF xref.data, store content_id in xref.xref - load(): add ref_contact_id, ref_contact_name, ref_type_title subqueries - edit_movement.php: contact lookup URL; save xref.xref from manual picker; fix refRow.edit → refRow.data fallback - edit_movement.tpl: From field with contact autocomplete + hidden id; Note field - view_movement.tpl: supplier above dates, reference tab removed, note shown, Type shows cross_ref_title, contact links to contact record Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
-rw-r--r--includes/classes/StockMovement.php18
1 files changed, 18 insertions, 0 deletions
diff --git a/includes/classes/StockMovement.php b/includes/classes/StockMovement.php
index 747099a..d478796 100644
--- a/includes/classes/StockMovement.php
+++ b/includes/classes/StockMovement.php
@@ -71,6 +71,17 @@ class StockMovement extends LibertyContent {
, (SELECT FIRST 1 x.`start_date` FROM `{$X}liberty_xref` x
WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER')
ORDER BY x.`xorder`) AS ref_start_date
+ , (SELECT FIRST 1 xi.`cross_ref_title` FROM `{$X}liberty_xref` x
+ JOIN `{$X}liberty_xref_item` xi ON xi.`item` = x.`item` AND xi.`content_type_guid` = 'stockmovement'
+ WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER')
+ ORDER BY x.`xorder`) AS ref_type_title
+ , (SELECT FIRST 1 x.`xref` FROM `{$X}liberty_xref` x
+ WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER')
+ ORDER BY x.`xorder`) AS ref_contact_id
+ , (SELECT FIRST 1 lc2.`title` FROM `{$X}liberty_xref` x
+ JOIN `{$X}liberty_content` lc2 ON lc2.`content_id` = x.`xref`
+ WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER')
+ ORDER BY x.`xorder`) AS ref_contact_name
FROM `".BIT_DB_PREFIX."liberty_content` lc
LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON uue.`user_id` = lc.`modifier_user_id`
LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON uuc.`user_id` = lc.`user_id`
@@ -354,7 +365,14 @@ class StockMovement extends LibertyContent {
);
// Preserve existing type if already set; default to TRANS for new rows
$refItem = $existingRow['item'] ?? 'TRANS';
+ // Look up contact by SCREF short name
+ $contactId = $from !== '' ? (int)$this->mDb->getOne(
+ "SELECT `content_id` FROM `".BIT_DB_PREFIX."liberty_xref`
+ WHERE `item`='SCREF' AND `data`=?",
+ [ $from ]
+ ) : 0;
$refHash = [ 'content_id' => $this->mContentId, 'item' => $refItem, 'xkey' => $ref, 'edit' => $from ];
+ if( $contactId ) $refHash['xref'] = $contactId;
$existingRow ? $refHash['xref_id'] = $existingRow['xref_id'] : $refHash['fAddXref'] = 1;
$this->storeXref( $refHash );
}