I have 3 tables looked like this
Employee Table
id | EmpId | Name |
1 | N1 | A |
2 | N2 | B |
3 | N3 | C |
Leave Table
id | EmpId | applydate | startdate | daysleave | reason | status |
1 | N2 | 2016-08-25 | 2016-08-25 | 4 | vacation | Approved |
Setting Table
id | var | val | valdef | status |
1 | MaxLeave | 12 | 12 | 1 |
Each employee has max leave 12 days taken from Setting Table.
If daysleave = 4,then maxleave it should be 8 days left. how did i do that ?should i add new field on Employee Table ?
Result Expected :
You can create get function in model to retrieve information you need example:
public function getDaysOfLeaveLeft() {
// query for the data you need and return days left
return $days;
}
Then in view you display it
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'daysOfLeaveLeft',
],
]) ?>
EDIT
Full function
public function getDaysOfLeaveLeft() {
$models = LeaveTable::findAll(['EmpId' => $this->EmpId]);
$leave = 0;
foreach ($models as $model) {
$leave += $model->daysleave;
}
$setting = Setting::find(['var' => 'MaxLeave']);
return $setting->val - $leave;
}