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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器