基于与公司服务多年的病假日权利

时间:2012-07-04 13:35:02

标签: php cakephp

通过我的功能获得了更新。这现在也可以正常使用,但是我需要根据多年的服务情况计算完全生病,直到他们生病的第一天。希望我已经说清楚了。我已经标记出可以解决我生病的代码行,但我只是一直给我一个,即使我知道所选用户的年份更长。

请帮帮忙?

Glenn Curtis

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项目中使用的页面编写的。

非常感谢

Glenn Curtis

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

1 个答案:

答案 0 :(得分:0)

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

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

你需要根据他们签约的时间来计算他们的权利 - 这很简单,你需要从他们已经服用的天数开始他们的假期。再次,似乎很容易。

如果他们还有剩余天数,您想要返回true。如果已经使用了他们的津贴,或者已经过去,则返回false。

还是我错过了什么?