good day, I want to exclude lunch break in total working hours, holidays seems to work only lunch break wont, I don't know what could be the condition to apply, I just new here please help me.
here is my code in blade..
,,, <?php
$start_time = Carbon\Carbon::createFromFormat('H:i:s', "08:15:00");
$end_time = Carbon\Carbon::createFromFormat('H:i:s', "16:45:00");
$work_date_start = Carbon\Carbon::createFromFormat('Y-m-d', date('Y-m-d', strtotime($works->start))); //date start
$work_start_time = Carbon\Carbon::createFromFormat('H:i:s', date('H:i:s', strtotime($works->start))); //time start
$work_date_end = Carbon\Carbon::createFromFormat('Y-m-d', date('Y-m-d', strtotime($works->end))); //date start
$work_end_time = Carbon\Carbon::createFromFormat('H:i:s', date('H:i:s', strtotime($works->end))); //time start
$time = 0;
$total_hours = 0;
//Calculate time difference from start to end (same date)
if($work_date_start == $work_date_end){
$time = $works->start->diffInMinutes($works->end);
$total_hours += $time;
Log::info('TOTAL HOURS1:' .$total_hours. '| START:' .$works->start. '| END:' .$works->end. '| JO:' .$data->getJobOrder->jo_no);
}else{
// Calculate the time difference from work start (current date)
if(strtotime($work_start_time) >= strtotime($start_time) && strtotime($work_start_time) <= strtotime($end_time)){
$time += $work_start_time->diffInMinutes($end_time);
Log::info('TOTAL HOURS_T1:' .$time. '| START:' .$works->start. '| END:' .$works->end. '| JO:' .$data->getJobOrder->jo_no);
}
// Calculate the time difference from work end (next date)
if(strtotime($work_end_time) >= strtotime($start_time) && strtotime($work_end_time) <= strtotime($end_time)){
$time += $start_time->diffInMinutes($work_end_time);
Log::info('TOTAL HOURS_T2:' .$time. '| START:' .$works->start. '| END:' .$works->end. '| JO:' .$data->getJobOrder->jo_no);
}
//If multiple days are different (multiple date)
$current_date = Carbon\Carbon::createFromFormat('Y-m-d', date('Y-m-d', strtotime($works->start)));
if($work_date_start->diffInDays($work_date_end) > 1){
for ($i=0; $i < $work_date_start->diffInDays($work_date_end); $i++) {
// Get the current date
$current_date->addDay();
if($holidays != null){
foreach ($holidays as $data) {
if(date('Y-m-d', strtotime($current_date)) == date('Y-m-d', strtotime($data->date))){
continue;
}
}
}elseif(date('l', strtotime($current_date)) == "Sunday"){
continue;
}elseif (date('Y-m-d', strtotime($current_date)) != date('Y-m-d', strtotime($work_date_end))){
$date_hours_diff = 8;
$time += 60 * $date_hours_diff;
Log::info('TOTAL HOURS_T3:' .$time. '| START:' .$works->start. '| END:' .$works->end. '| JO:' .$data->getJobOrder->jo_no);
}
}
}
$total_hours += $time;
// Log::info('TOTAL HOURS2:' .$total_hours. '| START:' .$works->start. '| END:' .$works->end. '| JO:' .$data->getJobOrder->jo_no);
}
//ACTUAL TIME
$hours = floor($total_hours / 60);
$minutes = $total_hours % 60;
$actual_time = $hours + round($minutes/ 60, 2);
//EFFICIENCY
if($actual_time != 0) {
$efficiency = ($works->allot_hours / $actual_time) * 100;
}else{
$efficiency = 0;
}
//TOTAL ACTUAL TIME
$total_all_actual_time += $actual_time;
//TOTAL COMMITED TIME
$total_all_commited_time += $works->allot_hours;
?>