got an update for you with my function. This also now works as it should, but I need it to work out total sick, based on years of service up to the 1st day they take of sick. Hope I have made that clear. I have marked the line of code that works out my sick but i only gives me one all the time, even when I know where are more years for that selected user.
Please help?
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
OLD POST BELOW
Now I have asked for help on this before, however that was over one selected area of my function, to get number of sick days. That now works, I found a function that was built for me within the site I am working on. So I have total number of sick days entered within the database. Now I don't seem to be able to work out why I cant set that to my years of service.
To make my myself more clearly, the outcome of this function is to check the current users sick taken within a selected year. But to a annual year, a contracted year, e.g. may to may.
That is why I have a number of if statements to set up the users entitlement, as that changed based on years of service. Then when that is set, to take off the sick days the user has taken within that contracted year.
I hope I have explain what I want to do, if that is not clear, please let me know and I try and explain in more detail.
Please help, this is written for a page used in a CakePHP project.
Many Many Thanks
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
your code seems too complicated for what (it seems) is just
return (($TotalAnnualEntitlement - $SickDaysTakenThisYear) > 0) ? true : false;
You need to work out their entitlement, based on how long they have been contracted - easy enough, You then need to take their entitled holiday from the number of days they have already taken. Again, seems easy enough.
If they have any days remaining, you want to return true. If there have used their allowance, or gone over, return false.
or am i missing something?
Related
I'm trying to create hourly counting groups of tickets. I have to count three tickets for each hour and insert them as a bonus while inserting the remaining ones as a malus; every hour perform this count on a table where tickets are generated. I should calculate based on two time periods, one from 7 in the morning to 15 in the afternoon and one from 15 in the afternoon to 7 in the morning. I was taking a cue from this post, but I can't see the ticket number and time, while I can see the down, up, total and uptime columns. Can anyone help me perform this? I would also like to insert the count of time between the opening and closing of each intervention
Laravel group data by odd amount of hours throughout days
$uptimeData = Ticket::whereYear('created_at', '>=', Carbon::now()->year)
->whereYear('created_at', '<=', Carbon::now()->year)
->orderBy('created_at', 'asc')
->select('ticket_Id', 'created_at')
->get();
$intervals = \Carbon\CarbonInterval::hours(1)->toPeriod('2023/01/01 07:00:00', '2023/01/01 15:00:00');
$uptimeDataTimeline = $uptimeData->groupBy(function ($item, $key) use ($intervals) {
$date = Carbon::parse($item->created_at);
foreach ($intervals as $key => $interval) {
if ($date->hour == Carbon::parse($interval)->addHours(1)->hour) {
$actualHour1 = Carbon::parse($interval)->hour;
if (strlen($actualHour1) == 1) {
$actualHour1 = "0$actualHour1";
}
return $date->format("Y-m-d $actualHour1:00:00");
} else {
if ($date->hour == Carbon::parse($interval)->addHours(1)->hour) {
$actualHour2 = Carbon::parse($interval)->subHours(1)->hour;
if (strlen($actualHour2) == 1) {
$actualHour2 = "0$actualHour2";
}
return $date->format("Y-m-d $actualHour2:00:00");
}
}
}
return $date->format('Y-m-d H:00:00');
});
$uptimeDataTimeline = $uptimeDataTimeline->map(function ($checksInPeriod, $key) {
$down = 0;
$up = 0;
$total = 0;
$uptime = 0;
$fill = '#1fc777';
foreach ($checksInPeriod as $key => $value) {
$total++;
if ($total <= 3) {
$up++;
} else {
$down++;
}
}
$uptime = floatval(number_format(round($up / $total, 5) * 100, 2, '.', ','));
if ($uptime < 100) {
$fill = '#9deab8';
}
if ($uptime < 99) {
$fill = '#fbaa49';
}
if ($uptime < 98) {
$fill = '#e0465e';
}
return [
'total_ticket_Id' => $total,
'down_ticket_Id' => $down,
'up_ticket_Id' => $up,
'uptime' => $uptime,
'fill' => $fill,
];
});
I am having table like below
So there are priority and sqft, i want to start manufacturing schedule (from current date) that every day 1700 SQFT will be processed, like below image
but as you can see its not working
I have tried below code
foreach($priorityArraySum as $key=>$val)
{
$totalDays=ceil($val/1700);
$cutSQFT=$val;
for($j=1;$j<=$totalDays;$j++)
{
if($cutSQFT>1700)
{
echo '1700';
$cutDate=date('Y-m-d', strtotime($cutDate. ' + 1 days'));
$cutSQFT=$cutSQFT-1700;
}
else
{
echo $cutSQFT;
$cutSQFT=$cutSQFT-$cutSQFT;
}
}
}
#Nigel, to Make this dynamic, I have changed code to below, but its not working.
$pln_qry=mysql_query("select * from tbl_mfg_schedule where ms_date='".$today."'") or die(mysql_error());
$pln_data=mysql_fetch_array($pln_qry);
$max = $pln_data['ms_po_sqft'];
$dailyLeft = $max;
$current = reset($priorityArraySum);
$output = [];
//$day = date('Y-m-d');
$day = date('Y-m-d');
while (true) {
$pln_qry=mysql_query("select * from tbl_mfg_schedule where ms_date='".$today."'") or die(mysql_error());
$pln_data=mysql_fetch_array($pln_qry);
$max = $pln_data['ms_po_sqft'];
if ( $current >= $dailyLeft ) {
//$day=date('Y-m-d', strtotime($day. ' + 1 days'));
$output[] = ["priority" => key($priorityArraySum),
"amount" => $dailyLeft,
"day" => $day
];
$day=date('Y-m-d', strtotime($day. ' + 1 days'));
$current -= $dailyLeft;
$dailyLeft = $max;
}
else {
$output[] = ["priority" => key($priorityArraySum),
"amount" => $current,
"day" => $day
];
$dailyLeft -= $current;
if ( ($current = next($priorityArraySum)) === false ) {
break;
}
}
}
This code uses a while() loop to create an output array of the days work. It uses $current to keep track of each item and how much is left to allocate. It also uses $dailyLeft to keep track of how much capacity is left on a particular day. It checks the two and if the current is less than the daily capacity left, it allocates a full day to that item and resets the daily capacity. If there is extra capacity for that day it allocates this item to the day and gets the next item.
The day is only incremented (using $day++) when the capacity for that day is filled...
$max = 1700;
$dailyLeft = $max;
$current = reset($priorityArraySum);
$output = [];
$day = 1;
while (true) {
// echo $current."/".$dailyLeft."=".$day.PHP_EOL;
if ( $current >= $dailyLeft ) {
$output[] = ["priority" => key($priorityArraySum),
"amount" => $dailyLeft,
"day" => $day++
];
$current -= $dailyLeft;
$dailyLeft = $max;
}
else {
$output[] = ["priority" => key($priorityArraySum),
"amount" => $current,
"day" => $day
];
$dailyLeft -= $current;
if ( ($current = next($priorityArraySum)) === false ) {
break;
}
}
}
print_r($output);
I don't know either its the correct title for this question. Please, help me to edit this question if I am not adding appropriate title.
I am trying to work with hall space booking for event. There are three types of space booking:
Full - 0 (Can book by one team at same time)
Half - 1 (Can book by 2 team at same time)
Shared - 2 (Can book by 4 teams at same time)
So, I write following mention code.
<?php
$obj0 = new stdClass();
$obj0->id = '1';
$obj0->start = '2019-06-28';
$obj0->end = '2019-06-28';
$obj0->start_time = '07:00:00';
$obj0->end_time = '08:00:00';
$obj0->hall_space = '1';
$obj1 = new stdClass();
$obj1->id = '7';
$obj1->start = '2019-06-28';
$obj1->end = '2019-06-28';
$obj1->start_time = '06:00:00';
$obj1->end_time = '07:00:00';
$obj1->hall_space = '1';
$obj2 = new stdClass();
$obj2->id = '2';
$obj2->start = '2019-06-29';
$obj2->end = '2019-06-29';
$obj2->start_time = '07:00:00';
$obj2->end_time = '08:00:00';
$obj2->hall_space = '1';
$obj3 = new stdClass();
$obj3->id = '8';
$obj3->start = '2019-06-29';
$obj3->end = '2019-06-29';
$obj3->start_time = '06:00:00';
$obj3->end_time = '07:00:00';
$obj3->hall_space = '1';
$obj4 = new stdClass();
$obj4->id = '3';
$obj4->start = '2019-06-30';
$obj4->end = '2019-06-30';
$obj4->start_time = '07:00:00';
$obj4->end_time = '08:00:00';
$obj4->hall_space = '1';
$obj5 = new stdClass();
$obj5->id = '9';
$obj5->start = '2019-06-30';
$obj5->end = '2019-06-30';
$obj5->start_time = '06:00:00';
$obj5->end_time = '07:00:00';
$obj5->hall_space = '1';
$data = array($obj0, $obj1, $obj2, $obj3, $obj4, $obj5);
$hall_space = 1; //this means user is trying to book half space
if(count($data) > 0) {
$half = 0;
$shared = 0;
$error = false;
$looping_date = '';
$same_date = 0;
switch ($hall_space) {
case '0':
echo "aa";
$error = true;
break;
case '1':
foreach ($data as $dk => $dv) {
if($looping_date == $dv->start){
$same_date = $same_date + 1;
}else{
$same_date = 0;
}
if ($dv->hall_space == 0) {
echo "bb";
$error = true;
} elseif ($dv->hall_space == 1) {
$half = $half + 1;
if ($half == 2) {
echo "cc";
$error = true;
}
} elseif ($dv->hall_space == 3) {
$shared = $shared + 1;
if ($shared == 2) {
echo "dd";
$error = true;
}
}
}
break;
case '2':
foreach ($data as $dk => $dv) {
if ($dv->hall_space == 0) {
echo "ee";
$error = true;
} elseif ($dv->hall_space == 1) {
$half = $half + 1;
if ($half == 2) {
echo "ff";
$error = true;
}
} elseif ($dv->hall_space == 2) {
$shared = $shared + 1;
if ($shared == 3) {
echo "gg";
$error = true;
}
}
}
break;
}
}
if( isset($error) ){
echo "error";
}else{
echo "not error";
}
This was working fine for a singe event (i.e non-repeating). But, this is not working correctly for repeating events.
Here, in this scenario user trying to book half-space(i.e value 1) for date 2019-06-28 to 2019-06-30 from 6 am to 8am.
Above mentioned $data represents all the already booked events for that time frame, that means on every day there are are two half-spaced events (one from 6-7am and next from 7-8am) on each day. Which means this new events (half-spaced) should be allowed to book.
But, my logic is not working because, it is considering all those events as they are going to held in same date and time.That means, $half variable should be increased only if the events are on same date and time and finally should not generate error.
I tried to explain everything from myside, also you can just copy and paste the code for test. And, let me know if you need any further details.
$bookings = [
[
'period' => new DatePeriod(
new DateTime('2019-06-28 07:00:00'),
new DateInterval('PT1H'),
new DateTime('2019-06-28 08:00:00')
),
'byWho' => ['1' => 0.5, '2' => 0.5]
],
[
'period' => new DatePeriod(
new DateTime('2019-06-28 08:00:00'),
new DateInterval('PT1H'),
new DateTime('2019-06-28 09:00:00')
),
'byWho' => ['2' => 0.5]
]
];
Example data structure, between 7 and 8 on 2019-06-28 team '1' booked half the hall. Between 7 and 9 team '2' booked half the hall. All bookings should be 1 hour, if they're longer than an hour such as team two then they actually have two bookings right next to each other. If 1 hour is too long then you can change the interval if you like.
So instead of having an array of who booked when which is what you have, instead here you have an array showing a timeline, you just need to look at a specific time to see if it's booked and how full it is.
This way is better than yours because you can easily keep those dates sorted, bring this data in and out of a database into this structure with ease. Now because it's sorted you can really easily find the time you're booking for and you only need to look at the space available for that time period. But for yours you need to check every single booking to see if there is space.
If you want to check if there is space for a specific time you can use a binary search (choose your own search if you want to make this easier) to find an intersecting DatePeriod, then check values either side to find any other matching date periods. Then you simply do a check to see if in those periods there's space to fit the booking. To check for space it's as easy as summing up the values in 'byWho' + your booking size and see if it's greater than 1.
I'm trying to create a simple attendance application with Laravel. I'm just a little stuck with the logic side.
What I'm trying to do is to match up the time logs of users to the correct schedule.
So in our office, we could have from 2 to 3 breaks, so a typical work shift will look like this:
Time In - 06:00 AM
Break Out 1 - 07:15 AM
Break In 1 - 07:30 AM
Break Out 2 - 11:30 AM
Break In 2 - 12:00 PM
Time Out - 03:00 PM
Now a user typically just uses the biometric device and selects "in" or "out".
My problem is given something like this:
05:58 AM, in
07:17 AM, out
07:31 AM, in
05:58 AM, out
How can the system tell which time log (07:17 AM) belongs to which time slot (Break Out 1)?
Thank you so much for the help, and if my question is unclear, I'm sorry.
Here's a sample code of what I've done so far. It works but I think it's really messy:
$day_shift = [
"time_in" => date('H:i:s', strtotime("06:00 AM")),
"break_out_1" => date('H:i:s', strtotime("07:15 AM")),
"break_in_1" => date('H:i:s', strtotime("07:30 AM")),
"break_out_2" => date('H:i:s', strtotime("11:30 AM")),
"break_in_2" => date('H:i:s', strtotime("12:00 PM")),
"break_out_3" => '',
"break_in_3" => '',
"time_out" => date('H:i:s', strtotime("03:00 pM")),
];
foreach ($day_shift as $key => $userScheduleTime) {
if ($userScheduleTime !== "") {
$time = $logDate->date." ".$userScheduleTime;
} else {
$time = "";
}
$schedules[] = array('time' => $time, 'type' => $types[$i%2],'name'=>$key);
$i++;
}
// logTimes is a collection of time logs
foreach ($logTimes as $logTime) {
$logs[] = $logTime->toArray();
}
$cloneLogs = $logs;
$lastlog = end($cloneLogs);
if ($lastlog["log_type"] == "login") {
$dayOut = "";
} else {
$dayOut = $lastlog["log_time"];
}
$lastout = null;
$size = count($logs);
do {
if ($logs[$size-1]['log_type'] == 'logout') {
$lastout = $logs[$size-1];
break;
}
$size--;
} while ($size > 0);
$lastlog = null;
for ($i = 0; $i < count($schedules); $i++) {
$logTime = current($logs);
if ($lastlog == $logTime['log_type']) {
next($logs);
}
// checks the first log, calculates how late the person is
if ($i == 0) {
if ($logTime['log_type'] == "login") {
$timein = $schedules[0]['time'];
if (strtotime(date("Y-m-d H:i", strtotime($logTime['log_time']))) >
strtotime(date("Y-m-d H:i", strtotime($timein)))) {
$lates[$logTime['log_time']] = true;
$lates["totallate"] += getDifferenceInMinutes($logTime['log_time'], $timein);
}
$lastlog = $logTime["log_type"];
next($logs);
}
}
if ($schedules[$i]['type']==$logTime['log_type'] && $i!=0 && $lastlog !== $logTime["log_type"]) {
$nextSched = isset($schedules[$i+1])?$schedules[$i+1]:$schedules[$i];
$j = 1;
while ($nextSched['time']=="" && ($i+$j)<=count($schedules)) {
$nextSched = $schedules[$i+$j];
$j++;
}
if (strtotime($nextSched['time'])>strtotime($logTime['log_time']) && $logTime["log_time"] != $dayOut) {
// checks and calculates if the user has undertime
if (strtotime($nextSched['time']) > strtotime($logTime['log_time']) && $nextSched['type']=='login') {
if (strtotime($logTime['log_time']) < strtotime($schedules[$i]['time'])) {
$lates[$logTime['log_time']] = true;
$lates["totalunder"] += getDifferenceInMinutes($logTime['log_time'], $schedules[$i]['time']);
}
}
// checks and calculates if the user has overbreaks
if (date('H:i', strtotime($schedules[$i]['time'])) <
date('H:i', strtotime($logTime['log_time'])) &&
$logTime['log_type'] == 'login') {
$lates[$logTime['log_time']] = true;
$lates["totalover"] += getDifferenceInMinutes($schedules[$i]['time'], $logTime['log_time']);
}
$lastlog = $logTime["log_type"];
next($logs);
}
if ($i+1==count($schedules)) {
next($logs);
}
if ($logTime["log_time"] == $dayOut && $dayOut !== null) {
$timeOut = $schedules[count($schedules)-1]["time"];
if (strtotime(date("Y-m-d H:i", strtotime($logTime["log_time"]))) <
strtotime(date("Y-m-d H:i", strtotime($timeOut)))) {
$lates[$logTime["log_time"]] = true;
$lates["totalunder"] += getDifferenceInMinutes($logTime['log_time'], $timeOut);
$lastlog = $logTime["log_type"];
}
break;
}
}
}
This is my new code, its almost working, but I think my while loop is wrong some where?
Same as before, gets users taken sick puts it into a var. Then get users entitlement based on years of service, then work out what they have taken and see if the user has used all the full entitlement, then to see if they have used all there half pay entitlement.
Please Help?
if($this->CURRENT_USER['User']['role_id'] > 3) { //locks out user types
//Get Holidaytypes
$types = $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')
)
);
//Get How Many sick days
foreach ($types as $key => $value) {
global $SickTotal;
$typesDataEnds = strftime ("%u-%d-%Y", $types[$key]['Holiday']['endson']);
$typesDataStarts = strftime ("%u-%d-%Y", $types[$key]['Holiday']['startson']);
$SickTotal = count($typesDataEnds - $typesDataStarts);
//echo $SickTotal;
//Get Contract Start & End Dates
$start = array_shift($contracts);
$end = array_pop($contracts);
$endDate = $end['Contract']['endson'];
$startDate = $start['Contract']['startson'];
if (empty($endDate)) {
$endDate = time('now');
}
if (!empty($startDate)) {
$SortEnd = strftime("%Y", $endDate);
$SortStart = strftime("%Y", $startDate);
$YearsService = $SortEnd - $SortStart;
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 > 5) {
$SetFullEntitlement = 30;
$SetHalfEntitlement = 30;
//echo 'five years or more';
} else {
$SetFullEntitlement = 0;
$SetHalfEntitlement = 0;
//echo 'no sick pay';
}
} else {
$YearsService = 0;
//echo 'Sorry No Start Date For You Found!';
}
while ($SickTotal > 0) {
if ($SetFullEntitlement != 0) {
$SetFullEntitlement--;
} elseif ($SetHalfEntitlement != 0) {
$SetHalfEntitlement--;
}
}
echo 'FullPay:';
echo $SetFullEntitlement;
echo '<br/><br/>Halpay:';
echo $SetHalfEntitlement;
echo $SickTotal;
}
debug($types);
die();
//$this->render('/artists/holidayslist');
}
}
If ($startdate <= 1 year) {
If that's literally what you've typed, it's not going to work. Maybe strtotime might make some sense of it?
In any case,
For ($i = $Totalsick, $i >= $Fulldays, $i--) {
For ($i = $Totalsick, $>= $Halfdays, $i--) {
you're missing an $i in there - you're evaluating nothing against $Halfdays. You're also using $i for two seperate loops, so they're both on the same counter. switch your second loop to use a different variable.
I'm not quite sure I follow exactly what you are trying to do here but you could tidy up your code a bit and save on lines of code. I assume that $startdate is how many years ago the user started.
$sickdays= array( 0=>5, 1=>10, 2=>20, 5=>30 );
$userdays= 0;
foreach ( array_keys( $sickdays ) as $years_service )
{
if ( $years_service <= $startdate )
$userdays=$sickdays[$years_service];
}
Now $userdays should be the correct number of paid sick days and half days ( the two are always the same in your example ) for this user. A simple comparison should be sufficient to check whether they have taken less or more than their allotted number of days and half days.
I haven't tried this as I'm not working with PHP today, so I'm sure someone will shoot me down directly, but by setting your variables once and writing fewer lines you should find your code gets easier to maintain.