Code Master
Master and Transaction tables are used in most databases. Master tables contain data which seldom changes. Transaction tables contain data which frequently changes. CodeMaster was developed in order to handle the maintenance and display of most Master tables.
- CodeMaster data can be maintained interactively ( see: [SysAdmin]->Code Master menu option )
- CodeMaster data can be organization specific
-
CodeMaster data can be presented in html select list using the buildSelectList() view function
( see: libs/View.php ) - CodeMaster can be category dependent, if category option is chosen, selected values will be filter based on the value of another column or codemaster type code
-
TODO ..in future CodeMaster can be effective dated. If this option is chosen, the data is selected based on the date passed.
This is useful when you have rates or commission tables that keep changing with time
Code Master Header Table CM
Org ID | organization id ( default: 0 - applies to all organizations) |
CM Type | codemaster type code (string) |
Category | is it category value dependent <yes/no> |
Effective Date | effective date that will take effect (i.e. rates, commissions) TODO in future |
Description | description of codemaster type code |
Code Detail Table CD
CM Type | codedetail type code (replicates codemaster type code) |
Category | category code or value |
Effective Date | effective date that will take effect i.e. rates, commissions (optional) TODO in future |
Seq | codedetail display sequence |
CD Code | codedetail type code |
CD Description | description of codedetail type code |
CD Short Description | short description of codedetail type code (optional) |
getCodeDetail() retrieves code master data
based on code master value provided, it returns array data with codedetail values in columns:
- selcode - as 'code'
- seldesc - as 'desc'
Parameters - getCodeDetail( CM code, seloption, category )
- CM code - string, code master code to retrieved data from code detail
- seloption - default: 'seldesc' | 'shortdesc' , code detail description column to pull
-
category :
null (default), for standard usage
value, for value category based usage
this function is located in libs/Model.php
// Example standard usage: Fetch price plans
$PRICEPLAN = $this->model->getCodeDetail('PRICEPLAN');
// Example category usage: Fetch assessments based on dept value 'SCIENCE'
$dept = 'SCIENCE';
$ASSESSMENT = $this->model->getCodeDetail('ASSESSMENT', $desc='seldesc', $category=$dept);
// Sample getCodeDetail() Output Array ( [0] => Array ( [code] => plan1 [desc] => description-01 ) [1] => Array ( [code] => plan2 [desc] => description-02 ) [2] => Array ( [code] => plan3 [desc] => description-03 ) )
buildSelectList() builds html select list
returns built select markup based on DATA and PARM passed to function
Parameters - buildSelectList( selname, DATA, PARM, seloption )
- selname - string, column name to be used in id element
- DATA - array, listing data, each element must have 'code' , 'desc' keys
[0] 'code'=>CM code1 , 'desc'=>CM description1
[1] 'code'=>CM code2 , 'desc'=>CM description2
- PARM - array, arguments to html select list
- seloption - default: true, builds select open and close tags
this function is located in libs/View.php
$SLPARM = array('allLabel'=>'Select','class'=>'form-control');
$sel = "plancode AS 'code', description AS 'desc'";
$ar = $this->db->select('groupplan', $where=array(), $sel); // fetch all group plan records
$this->view->planSelectList = $this->view->buildSelectList('plancode', $ar, $SLPARM );
$this->view->render('controller/addplan', false);
Standard Usage Process
Example Standard Usage Process
-
invokes getCodeDetail() to fetch listing array data,
buildSelectList() to build html select markup (PHP) - place select list view variable at form display div (HTML)
// Example [controller/mycontroller] calls getCodeDetail, buildSelectList
function addPlan() {
$SLPARM = array('allLabel'=>'Select','class'=>'form-control');
$STATES = $this->model->getCodeDetail('USSTATES');
$this->view->stateSelectList = $this->view->buildSelectList('state', $STATES, $SLPARM );
$this->view->render('mycontroller/addplan', false);
}
// Example [views/mycontroller] - HTML places view variable in form-group
<div class="col-xs-2">
<div class="form-group">
<label for="state" class="control-label" >State</label>
<div role="button" class="form-inline">
<?php echo $this->stateSelectList ?>
</div>
</div>
</div>
Category Usage Process
Example Category Usage Process
-
invokes getCodeDetail() with category option, to fetch listing array data,
buildSelectList() to build html select markup (PHP) - place select list view variable at form display div (HTML)
// Example [controller/mycontroller] calls getCodeDetail (with category option), buildSelectList
function editPlan() {
$assessment = "fetch assessment from database";
// because we are Editing $assessment variable is passed to select list
// multiple option set to true - allows multiple options to be selected
$SLPARM = array('allLabel'=>'Select','class'=>'form-control');
$NEW_SLPARM = array_merge($SLPARM, array('selval'=>$assessment,'multiple'=>true))
$dept = "fetch department from database";
$ASSESSMENT = $this->model->getCodeDetail('ASSESSMENT', $desc='seldesc', $category=$dept);
$this->view->assessSelectList = $this->view->buildSelectList('assessment', $ASSESSMENT, $NEW_SLPARM );
$this->view->render('mycontroller/editplan', false);
}
// Example [views/mycontroller] - HTML places view variable in form-group
<div class="row">
<div class="col-xs-12 col-md-6 col-sm-6">
<div class="form-group">
<label for="assessment" class="control-label col-sm-4">Assessment : </label>
<div role="button" class="form-inline">
<?php echo $this->assessSelectList ?>
</div>
</div>
</div>
</div>