diff options
| -rw-r--r-- | add_supplier.php | 57 | ||||
| -rwxr-xr-x | includes/classes/StockBase.php | 2 | ||||
| -rw-r--r-- | templates/add_supplier.tpl | 53 | ||||
| -rw-r--r-- | templates/stockcomponent/view_xref_sup_group.tpl | 2 |
4 files changed, 113 insertions, 1 deletions
diff --git a/add_supplier.php b/add_supplier.php new file mode 100644 index 0000000..c76f978 --- /dev/null +++ b/add_supplier.php @@ -0,0 +1,57 @@ +<?php +/** + * @package stock + * @subpackage functions + */ + +namespace Bitweaver\Stock; + +use Bitweaver\Contact\Contact; +use Bitweaver\KernelTools; + +require_once '../kernel/includes/setup_inc.php'; + +global $gBitSystem, $gBitSmarty, $gBitUser, $gContent; + +include_once STOCK_PKG_INCLUDE_PATH.'component_lookup_inc.php'; + +if( !$gContent->isValid() ) { + $gBitSystem->fatalError( 'No valid component specified.' ); +} + +$gContent->verifyUpdatePermission(); + +if( !empty( $_REQUEST['fCancel'] ) ) { + header( 'Location: '.$gContent->getEditUrl() ); + die; +} + +if( !empty( $_REQUEST['fAddSupplier'] ) ) { + if( empty( $_REQUEST['supplier_content_id'] ) || !is_numeric( $_REQUEST['supplier_content_id'] ) ) { + $gContent->mErrors[] = KernelTools::tra( 'Please select a supplier.' ); + } else { + $gContent->storeXref( [ + 'content_id' => $gContent->mContentId, + 'item' => '#SUP', + 'xref' => (int)$_REQUEST['supplier_content_id'], + 'xkey' => trim( $_REQUEST['part_number'] ?? '' ), + 'xkey_ext' => trim( $_REQUEST['price'] ?? '' ), + 'edit' => trim( $_REQUEST['note'] ?? '' ), + 'fAddXref' => 1, + ] ); + + if( empty( $gContent->mErrors ) ) { + header( 'Location: '.$gContent->getEditUrl() ); + die; + } + } +} + +$contact = new Contact(); +$listHash = [ 'contact_type_guid' => ['$04'], 'sort_mode' => 'title_asc', 'max_records' => 500 ]; +$supplierList = $contact->getList( $listHash ); + +$gBitSmarty->assign( 'supplierList', $supplierList ); +$gBitSmarty->assign( 'errors', $gContent->mErrors ); + +$gBitSystem->display( 'bitpackage:stock/add_supplier.tpl', KernelTools::tra( 'Add Supplier' ), [ 'display_mode' => 'edit' ] ); diff --git a/includes/classes/StockBase.php b/includes/classes/StockBase.php index 839216f..a9c7fe5 100755 --- a/includes/classes/StockBase.php +++ b/includes/classes/StockBase.php @@ -10,6 +10,8 @@ namespace Bitweaver\Stock; use Bitweaver\Liberty\LibertyContent; +defined( 'STOCKASSEMBLY_CONTENT_TYPE_GUID' ) || define( 'STOCKASSEMBLY_CONTENT_TYPE_GUID', 'stockassembly' ); + /** * @package stock */ diff --git a/templates/add_supplier.tpl b/templates/add_supplier.tpl new file mode 100644 index 0000000..72e0195 --- /dev/null +++ b/templates/add_supplier.tpl @@ -0,0 +1,53 @@ +{strip} +<div class="edit stock"> + <div class="header"> + <h1>{tr}Add Supplier{/tr}: {$gContent->getTitle()|escape}</h1> + </div> + + <div class="body"> + {formfeedback error=$errors} + + {form id="addSupplierForm"} + <input type="hidden" name="content_id" value="{$gContent->mContentId}" /> + + <div class="form-group"> + {formlabel label="Supplier" for="supplier_content_id"} + {forminput} + <select name="supplier_content_id" id="supplier_content_id" class="form-control"> + <option value="">{tr}-- Select supplier --{/tr}</option> + {foreach from=$supplierList item=sup} + <option value="{$sup.content_id|escape}">{$sup.title|escape}</option> + {/foreach} + </select> + {/forminput} + </div> + + <div class="form-group"> + {formlabel label="Part Number" for="part_number"} + {forminput} + <input type="text" class="form-control input-small" name="part_number" id="part_number" value="" /> + {/forminput} + </div> + + <div class="form-group"> + {formlabel label="Price" for="price"} + {forminput} + <input type="text" class="form-control input-small" name="price" id="price" value="" /> + {/forminput} + </div> + + <div class="form-group"> + {formlabel label="Note" for="note"} + {forminput} + <input type="text" class="form-control" name="note" id="note" value="" /> + {/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="fAddSupplier" value="{tr}Save{/tr}" /> + </div> + {/form} + </div><!-- end .body --> +</div><!-- end .stock --> +{/strip} diff --git a/templates/stockcomponent/view_xref_sup_group.tpl b/templates/stockcomponent/view_xref_sup_group.tpl index c8914da..06d4586 100644 --- a/templates/stockcomponent/view_xref_sup_group.tpl +++ b/templates/stockcomponent/view_xref_sup_group.tpl @@ -27,7 +27,7 @@ </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} + {smartlink ititle="Add supplier" ipackage="stock" ifile="add_supplier.php" booticon="icon-note-add" content_id=$gContent->mInfo.content_id} </div> {/if} {/legend} |
