douxia5179 2016-08-25 03:59
浏览 24
已采纳

设置最大休假员工3表

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 : Result Expected

  • 写回答

1条回答 默认 最新

  • douwuli4512 2016-08-25 07:34
    关注

    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;
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?