病假权利基于在公司的服务年限


Sick Day Entitlement based on years of service with a company

我的函数为您提供了更新。这现在也可以正常工作,但我需要它来计算出完全生病的情况,基于他们生病第一天的服务年限。希望我已经说清楚了。我已经标记了解决我生病的代码行,但我只一直给我一个,即使我知道该选定用户的年限在哪里。

请帮忙?

格伦·柯蒂斯

function sickDay($id = null) {
    if($this->CURRENT_USER['User']['role_id'] > 3) { //directors and admins
        /*if(empty($this->data) || !isset($this->data['Holiday']['id'])) {
        } else {*/
        //Get the user sick days
        $userSickDays = $this->Holiday->find(
            'all',
            array(
                'conditions' => array(
                    'Holiday.holidaystype_id' => 3,
                    'Holiday.user_id' => $id
                ),
                'order' => 'Holiday.startson ASC'
            ));
        //Get years of service
        $userContracts = $this->Holiday->User->Contract->find(
            'all',
                array(
                    'conditions' => array( 'Contract.user_id' => $id), //$data['user_id']),
                    'order' => array( 'Contract.startson' => 'ASC' )
            ));
        //Loop through the user's sick days
        foreach ($userSickDays as $k => $sickDay) {
            //Get number of days in the current sick day
            $totSickdays = $this->Holiday->getNumberDaysFromHoliday($sickDay['Holiday']['id']);
            //Get number of sick days for the past 12 months
            if($k > 0) {
                for($i=0; $i<$k; $i++) {
                    if((strtotime(gmdate("Y-m-d", $sickDay['Holiday']['startson'])." -1 year GMT")) <= $userSickDays[$i]['Holiday']['startson']) {
                        $totSickdays += $this->Holiday->getNumberDaysFromHoliday($userSickDays[$i]['Holiday']['id']);
                    }
                }
            }
            foreach ($userContracts as $y => $contract) {
        THIS LINE HERE->$yearsService = $contract['Contract']['startson'] <= $sickDay['Holiday']['startson'];
                if ($contract['Contract']['startson'] <= $sickDay['Holiday']['startson']) {
                    if ($yearsService <= 1) {
                        $entitlement = 10;
                        $remaingDays = $entitlement - $totSickdays;
                        //echo 'one year';
                    } elseif ($yearsService <= 2) {
                        $entitlement = 20;
                        $remaingDays = $entitlement - $totSickdays;
                        //echo 'two years';
                    } elseif ($yearsService <= 4) {
                        $entitlement = 40;
                        $remaingDays = $entitlement - $totSickdays;
                        //echo 'up to five years';
                    } elseif ($yearsService >= 5) {
                        $entitlement = 60;
                        $remaingDays = $entitlement - $totSickdays;
                        //echo 'five years or more';
                    } else {
                        $entitlement = 0;
                        $remaingDays = 0;
                        //echo 'no sick pay';
                    }
                } //End of if statement.
            } //End of $userContracts Foreach Loop

            debug($yearsService);                           
        } //End of Foreach Loop
        //$this->render('/artists/holidayslist');
        //} //End For if empty check
    } // End for if CURRENT_USER
    die();
} //End of Function

下面的旧帖子

现在我以前曾就此寻求帮助,但是这超出了我职能的一个选定领域,以获得病假天数。现在它可以工作了,我在我正在处理的站点中找到了一个为我构建的功能。所以我在数据库中输入了病假总数。现在我似乎无法弄清楚为什么我不能将其设置为我的服务年限。

为了让我自己更清楚,此功能的结果是检查所选年份内的当前用户生病。但到一年,一个合同年,例如五月到五月。

这就是为什么我有许多if语句来设置用户权利,因为它根据服务年限而变化。然后,当设置好后,取消用户在该合同年度内的病假。

我希望我已经解释了我想做什么,如果不清楚,请告诉我,我会尝试更详细地解释。

请帮忙,这是为CakePHP项目中使用的页面编写的。

非常感谢

格伦·柯蒂斯

function sickDay($id = null) {
    if($this->CURRENT_USER['User']['role_id'] > 3) { //directors and admins
        //Caculate if it's a full pay, half pay or nothing
        //$data = $this->data['Holiday'];
        //Get Holidaytypes
        $userSickDays = $this->Holiday->find(
            'all',
            array(
                'conditions' => array(
                    'Holiday.holidaystype_id' => 3,
                    'Holiday.user_id' => $id
                )
            )
        );
        //Get starting date
        $contracts = $this->Holiday->User->Contract->find(
            'all',
            array(
                'conditions' => array(
                    'Contract.user_id' => $id //$data['user_id']
                ),
                'order' => array(
                    'Contract.startson' => 'ASC'
                )
            )
        );
        $start = array_shift($contracts);
        $end = array_pop($contracts);
        $endDate = $end['Contract']['endson'];
        $startDate = $start['Contract']['startson'];
        if (empty($endDate)) { $endDate = time('now'); }
        $SortEnd = strftime("%Y", $endDate);
        $SortStart = strftime("%Y", $startDate);
        $YearsService = $SortEnd - $SortStart;
        //Get How Many sick days
        foreach ($userSickDays as $sickDay) {
            $typesDataEnds =  strtotime($sickDay['Holiday']['endson']);
            $typesDataStarts = $sickDay['Holiday']['startson'];
            $DateNow = date('U', strtotime('Now'));
            $GetSickDays = $this->Holiday->getNumberDaysFromHoliday($sickDay['Holiday']['id']);
            $TotalSick += $GetSickDays;
            if ($YearsService <= 1) {
                    $SetFullEntitlement = 5;
                    $SetHalfEntitlement = 5;
                    //echo 'one year';
            } elseif ($YearsService <= 2) {
                    $SetFullEntitlement = 10;
                    $SetHalfEntitlement = 10;
                    //echo 'two years';
            } elseif ($YearsService <= 5) {
                    $SetFullEntitlement = 20;
                    $SetHalfEntitlement = 20;
                    //echo 'up to five years';
            } elseif ($YearsService >= 6) {
                    $SetFullEntitlement = 30;
                    $SetHalfEntitlement = 30;
                    //echo 'five years or more';
            } else {
                    $SetFullEntitlement = 0;
                    $SetHalfEntitlement = 0;
                    //echo 'no sick pay';
            }
        } 
        //$this->render('/artists/holidayslist');
    } // End for if CURRENT_USER
    die();
} //End of Function

你的代码似乎太复杂了(看起来)只是

return (($TotalAnnualEntitlement - $SickDaysTakenThisYear) > 0) ? true : false;

您需要根据他们

签订合同的时间来确定他们的权利 - 很简单,然后您需要从他们已经占用的天数中享受他们有权的假期。同样,似乎很容易。

如果他们还有剩余天数,您希望返回 true。如果有使用了他们的津贴,或者超过了,则返回假。

还是我错过了什么?