Пример #1
0
function searchArrayById($array, $id, $field, $myFieldId = "")
{
    $returnArray = array();
    $i = 0;
    foreach ($array as $data) {
        if ($data[$field] == $id && !in_array_key($myFieldId, $data[$myFieldId], $returnArray)) {
            $returnArray[$i] = $data;
            $i++;
        }
    }
    return $returnArray;
}
Пример #2
0
 private function calc_ot()
 {
     $this->load->model('Worktime_model');
     $this->load->model('Worktime_ot_model');
     $this->load->model('Worktime_ot_conditions_model');
     //คิด OT
     //เช็คเวลาการทำโอทีที่ t_worktime, t_worktime_ot
     //เช็คเรทการจ่ายเงินที่ t_worktime_ot_conditions ว่าจ่ายเรทเท่าไหร่
     $list_ot = $this->Worktime_ot_model->ot_hour_for_pay($this->emp_user_id, $this->year, $this->month);
     $list_ot = $list_ot->result_array();
     $list_worktime = $this->Worktime_model->get_list_by_year_and_month($this->emp_user_id, $this->year, $this->month);
     $list_worktime = $list_worktime->result_array();
     foreach ($list_ot as $list_ot) {
         $list_ot['ot_pay_multiplier'] = 1.5;
         //โอทีนี้จ่ายกี่เท่า ไว้ใช้ตอนคิดเรทเปลี่ยนค่าตามเรทที่คิด
         //เช็ควัน-เวลาที่ทำงานจริง ๆ
         //โดยใช้วันที่ลง OT เทียบกับวันที่มีการติ๊ดนิ้ว
         //แล้วค่อยเอามาเทียบเวลาแบบ + - 1 ชม.
         //เช็คว่าวันที่ลงทำโอที มีตารางเวลาที่ติ๊ดนิ้วอยู่จริง
         if (in_array_key('WTDate', $list_ot['wot_date'], $list_worktime) == TRUE) {
             //เทียบเวลาที่ขอทำ OT กับเวลาที่ติ๊ดนิ้วเข้ามาจริง ๆ
             $time_ot_start = $list_ot['wot_time_from'];
             $temp_arr = explode(":", $time_ot_start);
             $time_ot_start_minus1 = intval($temp_arr[0]) - 1 . ":" . $temp_arr[1] . ":" . $temp_arr[2];
             $time_ot_start_plus1 = intval($temp_arr[0]) + 1 . ":" . $temp_arr[1] . ":" . $temp_arr[2];
             $time_ot_start_before_start = "";
             $time_ot_start_after_start = "";
             $time_ot_end = $list_ot['wot_time_to'];
             $temp_arr = explode(':', $time_ot_end);
             $time_ot_end_minus1 = intval($temp_arr[0]) - 1 . ":" . $temp_arr[1] . ":" . $temp_arr[2];
             $time_ot_end_plus1 = intval($temp_arr[0]) + 1 . ":" . $temp_arr[1] . ":" . $temp_arr[2];
             //เก็บค่าที่ใกล้เคียงกับเวลามากที่สุด เช่น เวลาคือ 19.00 ถ้ามีติ๊ดนิ้ว 2 ครั้งคือเวลา 18.59 กับ 19.03 จะใช้เวลา 18.59 เป็นตัวตั้งต้น และเวลาที่ออกก็ใช้แบบเดียวกัน
             $worktime_start = "";
             $worktime_end = "";
             $start1 = "";
             $start2 = "";
             $start3 = "";
             $start4 = "";
             $start_finish = "";
             //สิ้นสุดการคำนวณ
             $end1 = "";
             $end2 = "";
             $end3 = "";
             $end4 = "";
             $end_finish = "";
             //สิ้นสุดการคำนวณ
             //หาเวลาทำงานที่ใกล้เคียงเวลาจริงที่สุด
             foreach ($list_worktime as $worktime) {
                 $wttime = strtotime($worktime['WTTime']);
                 //for start ot
                 if ($wttime >= strtotime($time_ot_start_minus1) && $wttime < strtotime($time_ot_start)) {
                     $start2 = $worktime['WTTime'];
                     if ($start1 == "") {
                         $start1 = $start2;
                     }
                     if (strtotime($start2) > strtotime($start1)) {
                         $start1 = $start2;
                     }
                 } else {
                     if ($wttime >= strtotime($time_ot_start) && $wttime < strtotime($time_ot_start_plus1)) {
                         $start4 = $worktime['WTTime'];
                         if ($start3 == "") {
                             $start3 = $start4;
                         }
                         if (strtotime($start4) < strtotime($start3)) {
                             $start3 = $start4;
                         }
                     }
                 }
                 //end of start ot stored at $start1, $start3
                 //for end ot
                 if ($wttime >= strtotime($time_ot_end_minus1) && $wttime < strtotime($time_ot_end)) {
                     $end2 = $worktime['WTTime'];
                     if ($end1 == "") {
                         $end1 = $end2;
                     }
                     if (strtotime($end2) > strtotime($end1)) {
                         $end1 = $end2;
                     }
                 } else {
                     if ($wttime >= strtotime($time_ot_end) && $wttime <= strtotime($time_ot_end_plus1)) {
                         $end4 = $worktime['WTTime'];
                         if ($end3 == "") {
                             $end3 = $end4;
                         }
                         if (strtotime($end4) < strtotime($end3)) {
                             $end3 = $start4;
                         }
                     }
                 }
                 //end of start ot stored at $end1, $end3
             }
             //ได้เวลามา 2 ค่าให้เอาค่าเวลาที่ห่างกับเวลาที่ลงทำ OT น้อยที่สุดมาคิด เช่น 18.58 19.03 เวลาทำ OT จริงคือ 19.00 ก็จะใช้ 18.58 เพราะห่างเวลาจริงเพียง 2 นาที
             if (strtotime($time_ot_start) - strtotime($start1) <= strtotime($start3) - strtotime($time_ot_start)) {
                 $start_finish = $start1;
             } else {
                 $start_finish = $start3;
             }
             //ถ้าเวลาไหนเกินกว่าเวลาที่ทำโอทีมากกว่าก็เอาเวลานั้น
             if (strtotime($end3) - strtotime($time_ot_end) >= strtotime($time_ot_end) - strtotime($end1)) {
                 $end_finish = $end3;
             } else {
                 $end_finish = $end1;
             }
             $list_ot['real_wot_time_from'] = $start_finish;
             $list_ot['real_wot_time_to'] = $end_finish;
             //ตอนนี้จะได้เวลาเริ่มต้นกับเวลาสิ้นสุดที่ทำโอทีจริงแล้ว
             //อยู่ใน $start_finish กับ $end_finish
             //นำมาหาว่าทำไปกี่ ชม. เทียบกับเวลาที่ขอทำ
             //แล้วนำไปคูณกับเรทจำนวนชั่วโมง
             $total_ot_time = round(timeDiff($start_finish, $end_finish));
             //เอาจำนวนที่ทำจริง ไปเทียบกบที่ขอทำ มากกว่าน้อยกว่า 10 นาทีไม่เป็นไร
             //ถือว่าตรง แต่ถ้าน้อยกว่าเกิน 30 นาทีขึ้นไป หรือตามที่กำหนด
             //ถือว่าปรับเป็น ไม่จ่ายทั้ง ชม. มั้ย อันนี้ก็ต้องมาคุยกันอีกที
             //rate ot มี 3  แบบ
             //1. ทำงานวันปกติ 1.5 เท่าของเงินรายชั่วโมง
             //2. ทำงานวันหยุด 2 เท่าของเงินรายชั่วโมง
             //3. ทำงานวันหยุดนักขัตฤกษ์ 3 เท่าของเงินรายชั่วโมง
             $is_holiday_shiftwork = is_holiday_shiftwork($this->user_id, $list_ot['wot_date']);
             //เช็คจากกะวันทำงาน
             $is_thailand_official_holiday = is_thailand_official_holiday($list_ot['wot_date']);
             //เช็ควันหยุดราชการ
             if ($is_thailand_official_holiday == TRUE) {
                 //*3
                 $list_ot['ot_pay_multiplier'] = 3;
             } else {
                 if ($is_holiday_shiftwork == TRUE) {
                     //*2
                     $list_ot['ot_pay_multiplier'] = 2;
                 }
             }
             if (floatval($total_ot_time) >= floatval($list_ot['wot_request_hour'])) {
                 //เอาเรทมาคูณ
                 //เอาวันที่ทำงานไปหาว่าเป็นวันอะไร
                 //เอาวันที่ไปเทียบกับวันหยุดนักขัตฤกษ์ ว่าเป็นวันหยุดนักขัตฤกษ์ไหม
                 $ot_money = $this->my_salary_per_hour * intval($list_ot['wot_request_hour']) * $list_ot['ot_pay_multiplier'];
                 $list_ot['real_ot_money'] = $ot_money;
                 $list_ot['real_wot_request_hour'] = $list_ot['wot_request_hour'];
                 $this->my_ot = intval($this->my_ot) + $ot_money;
                 array_push($this->my_ot_data, $list_ot);
             } else {
                 //ถ้าเวลาที่ทำโอทีไม่ถึงจำนวน ชม. ที่ขอเป็นเวลากี่นาที จะลดเหลือเท่านั้นหรือไม่อย่างไร อันนี้ต้องคุยดูอีกที
                 //ถ้าทำไม่ถึง 1 ชม. ปรับเศษลง
                 $ot_money = $this->my_salary_per_hour * intval(floor($total_ot_time)) * $list_ot['ot_pay_multiplier'];
                 $list_ot['real_ot_money'] = $ot_money;
                 $list_ot['real_wot_request_hour'] = $total_ot_time;
                 $this->my_ot = intval($this->my_ot) + $ot_money;
                 array_push($this->my_ot_data, $list_ot);
             }
         }
     }
 }
Пример #3
0
									<td class="right-align"><a href="javascript:void(0);" class="btn red" onclick="removeShiftwork('<?php 
    echo $row["esw_swid"];
    ?>
');">ลบ</a></td>
								</tr>
							<?php 
}
?>
						</table>
						<a href="javascript:void(0);" class="btn" onclick="$('#allShiftworkList').toggleClass('hide');">เลือกกะงาน</a>
						<table id="allShiftworkList" class="bordered highlight hide">
							<?php 
foreach ($queryShiftwork as $row) {
    ?>
								<?php 
    if (in_array_key("esw_swid", $row["swid"], $queryEmpShiftwork)) {
        ?>
									<tr class="hide">
								<?php 
    } else {
        ?>
									<tr>
								<?php 
    }
    ?>
									<td id="shiftworkName_<?php 
    echo $row["swid"];
    ?>
"><?php 
    echo $row["swname"];
    ?>