summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xadmin/schema_inc.php5
-rwxr-xr-xincludes/classes/StockAssembly.php1
-rwxr-xr-xincludes/classes/StockBase.php33
-rwxr-xr-xtemplates/edit_component.tpl2
-rw-r--r--templates/stockcomponent/edit_xref_sup_item.tpl52
-rw-r--r--templates/stockcomponent/view_xref_sup_group.tpl34
-rw-r--r--templates/stockcomponent/view_xref_sup_item.tpl31
-rwxr-xr-xtemplates/view_component.tpl5
8 files changed, 158 insertions, 5 deletions
diff --git a/admin/schema_inc.php b/admin/schema_inc.php
index 96c3be4..e58c2ed 100755
--- a/admin/schema_inc.php
+++ b/admin/schema_inc.php
@@ -137,13 +137,14 @@ $xrefTypes = [];
$xrefItems = [];
foreach( [ 'stockcomponent', 'stockassembly' ] as $guid ) {
- $xrefTypes[] = "INSERT INTO `{$X}liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('supplier','{$guid}','Supplier', 1,3,'')";
+ $supGrpTpl = ( $guid === 'stockcomponent' ) ? 'sup' : '';
+ $xrefTypes[] = "INSERT INTO `{$X}liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`,`template`) VALUES ('supplier','{$guid}','Supplier', 1,3,'','{$supGrpTpl}')";
$qtyGrpTpl = ( $guid === 'stockassembly' ) ? 'bom' : '';
$xrefTypes[] = "INSERT INTO `{$X}liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`,`template`) VALUES ('quantity','{$guid}','Quantity', 2,3,'','{$qtyGrpTpl}')";
$xrefTypes[] = "INSERT INTO `{$X}liberty_xref_group` (`x_group`,`content_type_guid`,`title`,`sort_order`,`role_id`,`type_href`) VALUES ('values', '{$guid}','Values', 3,3,'')";
// Supplier sources — multi=1 (multiple suppliers per item)
- $xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('#SUP','{$guid}','supplier','Supplier', 1,3,'../contact/?content_id=','text',NULL)";
+ $xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('#SUP','{$guid}','supplier','Supplier', 1,3,'../contact/?content_id=','sup', NULL)";
$xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('#PN', '{$guid}','supplier','Part Number', 1,3,'', 'text',NULL)";
$xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('#PR', '{$guid}','supplier','Price', 1,3,'', 'text',NULL)";
$xrefItems[] = "INSERT INTO `{$X}liberty_xref_item` (`item`,`content_type_guid`,`x_group`,`cross_ref_title`,`multiple`,`role_id`,`cross_ref_href`,`template`,`data`) VALUES ('#URL','{$guid}','supplier','Supplier URL', 1,3,'', 'text',NULL)";
diff --git a/includes/classes/StockAssembly.php b/includes/classes/StockAssembly.php
index c3cf0f0..59e946c 100755
--- a/includes/classes/StockAssembly.php
+++ b/includes/classes/StockAssembly.php
@@ -74,6 +74,7 @@ class StockAssembly extends StockBase {
}
public function enrichXrefDisplay( array &$pXrefInfo ): void {
+ parent::enrichXrefDisplay( $pXrefInfo );
if( !empty( $pXrefInfo['xref'] ) ) {
if( $comp = $this->mDb->getRow(
"SELECT lc.`title`, lc.`data`, pck.`xkey` AS `pack_size`, pck.`xkey_ext` AS `pack_size_ext`
diff --git a/includes/classes/StockBase.php b/includes/classes/StockBase.php
index 165f98e..ba0ff16 100755
--- a/includes/classes/StockBase.php
+++ b/includes/classes/StockBase.php
@@ -32,6 +32,39 @@ abstract class StockBase extends LibertyContent
}
// regular expression to determine if the title was computer generated
+ public function loadXrefList(): void {
+ parent::loadXrefList();
+ if( !empty( $this->mInfo['supplier'] ) ) {
+ $contactIds = array_values( array_unique( array_filter( array_column( $this->mInfo['supplier'], 'xref' ) ) ) );
+ if( $contactIds ) {
+ $placeholders = implode( ',', array_fill( 0, count( $contactIds ), '?' ) );
+ $contacts = $this->mDb->getAssoc(
+ "SELECT lc.`content_id` AS hash_key, lc.`title`
+ FROM `".BIT_DB_PREFIX."liberty_content` lc
+ WHERE lc.`content_id` IN ($placeholders)",
+ $contactIds
+ );
+ foreach( $this->mInfo['supplier'] as &$row ) {
+ if( !empty( $row['xref'] ) && isset( $contacts[$row['xref']] ) ) {
+ $row['xref_title'] = $contacts[$row['xref']]['title'];
+ }
+ }
+ unset( $row );
+ }
+ }
+ }
+
+ public function enrichXrefDisplay( array &$pXrefInfo ): void {
+ if( !empty( $pXrefInfo['xref'] ) && ( $pXrefInfo['x_group'] ?? '' ) === 'supplier' ) {
+ if( $contact = $this->mDb->getRow(
+ "SELECT lc.`title` FROM `".BIT_DB_PREFIX."liberty_content` lc WHERE lc.`content_id` = ?",
+ [ (int)$pXrefInfo['xref'] ]
+ ) ) {
+ $pXrefInfo['xref_title'] = $contact['title'];
+ }
+ }
+ }
+
public function isMachineName( $pString ) {
if ( !empty($pString) ) {
return preg_match( '/(^[0-9][-0-9 ]*$)|(^[-0-9 ]*(img|dsc|dscn|pict|htg|dscf|p)[-0-9 ][-0-9 ]*.*$)/i', trim( $pString ) );
diff --git a/templates/edit_component.tpl b/templates/edit_component.tpl
index 197028f..380fd1f 100755
--- a/templates/edit_component.tpl
+++ b/templates/edit_component.tpl
@@ -30,7 +30,7 @@
{if $gContent->mInfo.stockcomponent_types}
{jstabs}
{section name=xrefGroup loop=$gContent->mInfo.stockcomponent_types}
- {include file="bitpackage:liberty/list_xref.tpl"
+ {include file=$gContent->getXrefListTemplate($gContent->mInfo.stockcomponent_types[xrefGroup].template)
source=$gContent->mInfo.stockcomponent_types[xrefGroup].source
source_title=$gContent->mInfo.stockcomponent_types[xrefGroup].title
group=$gContent->mInfo.stockcomponent_types[xrefGroup].sort_order
diff --git a/templates/stockcomponent/edit_xref_sup_item.tpl b/templates/stockcomponent/edit_xref_sup_item.tpl
new file mode 100644
index 0000000..3411efb
--- /dev/null
+++ b/templates/stockcomponent/edit_xref_sup_item.tpl
@@ -0,0 +1,52 @@
+{strip}
+<div class="edit stock">
+ <div class="header">
+ <h1>{tr}Edit Supplier{/tr}: {$gContent->getTitle()|escape}</h1>
+ </div>
+ <div class="body">
+ {formfeedback error=$errors}
+ {form id="editXrefForm"}
+ <input type="hidden" name="content_id" value="{$xrefInfo.content_id|escape}" />
+ <input type="hidden" name="xref_id" value="{$xrefInfo.xref_id|escape}" />
+ <input type="hidden" name="item" value="{$xrefInfo.item|escape}" />
+
+ {if $xrefInfo.xref_title}
+ <div class="form-group">
+ {formlabel label="Supplier"}
+ {forminput}
+ <p class="form-control-static">
+ <a href="{$smarty.const.CONTACT_PKG_URL}display_contact.php?content_id={$xrefInfo.xref|escape}">{$xrefInfo.xref_title|escape}</a>
+ </p>
+ {/forminput}
+ </div>
+ {/if}
+
+ <div class="form-group">
+ {formlabel label="Part Number" for="xkey"}
+ {forminput}
+ <input type="text" class="form-control input-small" name="xkey" id="xkey" value="{$xrefInfo.xkey|escape}" />
+ {/forminput}
+ </div>
+
+ <div class="form-group">
+ {formlabel label="Price" for="xkey_ext"}
+ {forminput}
+ <input type="text" class="form-control input-small" name="xkey_ext" id="xkey_ext" value="{$xrefInfo.xkey_ext|escape}" />
+ {/forminput}
+ </div>
+
+ <div class="form-group">
+ {formlabel label="Note" for="edit"}
+ {forminput}
+ <input type="text" class="form-control" name="edit" id="edit" value="{$xrefInfo.data|escape}" />
+ {/forminput}
+ </div>
+
+ <div class="form-group submit">
+ <input type="submit" class="btn btn-default" name="fCancel" value="{tr}Cancel{/tr}" />
+ <input type="submit" class="btn btn-primary" name="fSaveXref" value="{tr}Save{/tr}" />
+ </div>
+ {/form}
+ </div>
+</div>
+{/strip}
diff --git a/templates/stockcomponent/view_xref_sup_group.tpl b/templates/stockcomponent/view_xref_sup_group.tpl
new file mode 100644
index 0000000..c8914da
--- /dev/null
+++ b/templates/stockcomponent/view_xref_sup_group.tpl
@@ -0,0 +1,34 @@
+{assign var=xrefcnt value=$gContent->mInfo.$source|default:[]|@count}
+{assign var=xrefAllowEdit value=$allow_edit|default:true}
+{jstab title="$source_title ($xrefcnt)"}
+{legend legend=$source_title}
+<div class="form-group table-responsive">
+ <table>
+ <thead>
+ <tr>
+ <th>{tr}Supplier{/tr}</th>
+ <th>{tr}Part No.{/tr}</th>
+ <th>{tr}Price{/tr}</th>
+ <th>{tr}Note{/tr}</th>
+ {if $xrefAllowEdit}<th>{tr}Added{/tr}</th><th>{tr}Updated{/tr}</th><th>{tr}Edit{/tr}</th>{/if}
+ </tr>
+ </thead>
+ <tbody>
+ {section name=xref loop=$gContent->mInfo.$source}
+ {assign var=_rowTpl value=$gContent->mInfo.$source[xref].template}
+ {include file=$gContent->getXrefRecordTemplate($_rowTpl)}
+ {sectionelse}
+ <tr class="norecords">
+ <td colspan="7">{tr}No supplier records found{/tr}</td>
+ </tr>
+ {/section}
+ </tbody>
+ </table>
+</div>
+{if $allow_add && $gContent->isValid() && $gContent->hasUpdatePermission() && $source ne 'history'}
+ <div>
+ {smartlink ititle="Add record" ipackage="liberty" ifile="add_xref.php" booticon="icon-note-add" content_id=$gContent->mInfo.content_id group=$group}
+ </div>
+{/if}
+{/legend}
+{/jstab}
diff --git a/templates/stockcomponent/view_xref_sup_item.tpl b/templates/stockcomponent/view_xref_sup_item.tpl
new file mode 100644
index 0000000..21377c0
--- /dev/null
+++ b/templates/stockcomponent/view_xref_sup_item.tpl
@@ -0,0 +1,31 @@
+{strip}
+<tr class="{cycle values="even,odd"}">
+ <td>
+ {if $gContent->mInfo.$source[xref].xref > 0}
+ <a href="{$smarty.const.CONTACT_PKG_URL}display_contact.php?content_id={$gContent->mInfo.$source[xref].xref|escape}">{$gContent->mInfo.$source[xref].xref_title|default:$gContent->mInfo.$source[xref].xref|escape}</a>
+ {else}
+ &nbsp;
+ {/if}
+ </td>
+ <td>{$gContent->mInfo.$source[xref].xkey|escape}</td>
+ <td>{$gContent->mInfo.$source[xref].xkey_ext|escape}</td>
+ <td>{$gContent->mInfo.$source[xref].data|escape}</td>
+ <td>{$gContent->mInfo.$source[xref].last_update_date|bit_short_date}</td>
+ {if $xrefAllowEdit|default:true}
+ <td>
+ <span class="actionicon">
+ {if $gContent->hasUpdatePermission() && $source ne 'history'}
+ {smartlink ititle="Edit" ipackage="liberty" ifile="edit_xref.php" booticon="icon-note-edit" content_id=$gContent->mInfo.content_id xref_id=$gContent->mInfo.$source[xref].xref_id}
+ {/if}
+ {if $gContent->hasExpungePermission()}
+ {if $source eq 'history'}
+ {smartlink ititle="Restore" ipackage="liberty" ifile="edit_xref.php" booticon="icon-note-edit" content_id=$gContent->mInfo.content_id xref_id=$gContent->mInfo.$source[xref].xref_id expunge=-1}
+ {else}
+ {smartlink ititle="Delete" ipackage="liberty" ifile="edit_xref.php" booticon="icon-note-delete" content_id=$gContent->mInfo.content_id xref_id=$gContent->mInfo.$source[xref].xref_id expunge=1}
+ {/if}
+ {/if}
+ </span>
+ </td>
+ {/if}
+</tr>
+{/strip}
diff --git a/templates/view_component.tpl b/templates/view_component.tpl
index 379e839..f97373c 100755
--- a/templates/view_component.tpl
+++ b/templates/view_component.tpl
@@ -28,10 +28,11 @@
{if $gContent->mInfo.stockcomponent_types}
{jstabs}
{section name=xrefGroup loop=$gContent->mInfo.stockcomponent_types}
- {include file="bitpackage:liberty/list_xref.tpl"
+ {include file=$gContent->getXrefListTemplate($gContent->mInfo.stockcomponent_types[xrefGroup].template)
source=$gContent->mInfo.stockcomponent_types[xrefGroup].source
source_title=$gContent->mInfo.stockcomponent_types[xrefGroup].title
- group=$gContent->mInfo.stockcomponent_types[xrefGroup].sort_order}
+ group=$gContent->mInfo.stockcomponent_types[xrefGroup].sort_order
+ allow_edit=false}
{/section}
{/jstabs}
{/if}