include("../php_scripts/connect_database.php");
// echo "ABS_STARTPERIOD=$ABS_STARTPERIOD , ABS_ENDPERIOD=$ABS_ENDPERIOD
";
include("php_scripts/data_absent.php");
if(!$PER_TYPE){ $PER_TYPE=1; }
$ABS_STARTPERIOD = (trim($ABS_STARTPERIOD))? $ABS_STARTPERIOD : 3;
// echo "ABS_STARTPERIOD=$ABS_STARTPERIOD
";
$ABS_ENDPERIOD = (trim($ABS_ENDPERIOD))? $ABS_ENDPERIOD : ($ABS_STARTPERIOD);
// echo "ABS_ENDPERIOD=$ABS_ENDPERIOD
";
$ABS_LETTER = (trim($ABS_LETTER))? $ABS_LETTER : 1;
$search_ab_code = trim($search_ab_code);
$search_abs_startdate = trim($search_abs_startdate);
$search_abs_enddate = trim($search_abs_enddate);
$per_id_search = "";
$per_id_join = "";
/*if($SEARCHABS_PER_ID){ // $SEARCHABS_PER_ID (ผู้ลาที่ค้นหา) + $PER_ID (ล็อกอิน)
$arr_search_condition[] = "(a.PER_ID = $SEARCHABS_PER_ID and (a.PER_ID = $PER_ID or a.REVIEW1_PER_ID = $PER_ID or a.REVIEW2_PER_ID = $PER_ID or a.AUDIT_PER_ID = $PER_ID or a.APPROVE_PER_ID = $PER_ID))";
}else{*/
if ($SESS_PER_ID){
if($search_onlyme_flag==1){
$arr_search_condition[] = "(a.PER_ID = $SESS_PER_ID)";
}else{
$arr_search_condition[] = "(a.PER_ID = $SESS_PER_ID or a.REVIEW1_PER_ID = $SESS_PER_ID or a.REVIEW2_PER_ID = $SESS_PER_ID or a.AUDIT_PER_ID = $SESS_PER_ID or a.APPROVE_PER_ID = $SESS_PER_ID)";
}
}
//}
if ($search_ab_code) $arr_search_condition[] = "(a.AB_CODE = '$search_ab_code')";
if ($search_per_type){
$arr_search_condition[] = "(trim(b.PER_TYPE) = $search_per_type)";
}else if ($search_per_type==0) { //ทั้งหมด
$arr_search_condition[] = "(trim(b.PER_TYPE) in('1','2','3','4')) ";
}
if ($search_abs_startdate || $search_abs_enddate) {
$temp_date = explode("/", $search_abs_startdate);
$temp_start = ($temp_date[2] - 543) ."-". $temp_date[1] ."-". $temp_date[0];
$temp_date = explode("/", $search_abs_enddate);
$temp_end = ($temp_date[2] - 543) ."-". $temp_date[1] ."-". $temp_date[0];
$arr_search_condition[] = "(a.ABS_STARTDATE >= '$temp_start' and a.ABS_ENDDATE <= '$temp_end')";
}
if(!$search_abs_approve) $search_abs_approve=4;
if($search_abs_approve==4){
$arr_search_condition[] = "(a.APPROVE_FLAG in(0,1,2) or a.APPROVE_FLAG is null)";
}else{
if($search_abs_approve==3){
$arr_search_condition[] = "(a.APPROVE_FLAG = 0 or a.APPROVE_FLAG is null)";
} else{
if($search_abs_approve==1) $search_abs_approve_tmp = 1;
if($search_abs_approve==2) $search_abs_approve_tmp = 2;
$arr_search_condition[] = "(a.APPROVE_FLAG in($search_abs_approve_tmp))";
}
}
if($search_cancel_flag==1) $arr_search_condition[] = "(a.CANCEL_FLAG = 1)";
if($search_org_id){
if($select_org_structure==0) $arr_search_condition[] = "(d.ORG_ID=$search_org_id or e.ORG_ID=$search_org_id or f.ORG_ID=$search_org_id or g.ORG_ID=$search_org_id)";
if($select_org_structure==1) $arr_search_condition[] = "(b.ORG_ID=$search_org_id)";
}elseif($search_department_id){
$arr_search_condition[] = "(b.DEPARTMENT_ID = $search_department_id)";
}elseif($search_ministry_id){
$cmd = " select ORG_ID from PER_ORG where ORG_ID_REF=$search_ministry_id ";
$db_dpis->send_cmd($cmd);
while($data = $db_dpis->get_array()) $arr_org[] = $data[ORG_ID];
$arr_search_condition[] = "(b.DEPARTMENT_ID in (". implode(",", $arr_org) ."))";
} // end if
if(trim($search_per_name)) $arr_search_condition[] = "(b.PER_NAME like '$search_per_name%')";
if(trim($search_per_surname)) $arr_search_condition[] = "(b.PER_SURNAME like '$search_per_surname%')";
// SORT -----------------------
if(!$sort_by) $sort_by=3;
$sort_type = (isset($sort_type))? $sort_type : "3:desc";
$arrSort=explode(":",$sort_type);
$SortType[$arrSort[0]] =$arrSort[1];
if(!$order_by) $order_by=3;
if($order_by==1){ //ชื่อ-สกุล
$order_str = "b.PER_NAME ".$SortType[$order_by].",b.PER_SURNAME ".$SortType[$order_by];
}elseif($order_by==2){ //ประเภท
$order_str = "AB_NAME ".$SortType[$order_by];
} elseif($order_by==3) { //ตั้งแต่วันที่
$order_str = "ABS_STARTDATE ".$SortType[$order_by].",CREATE_DATE ".$SortType[$order_by];
//if($temp_todate){
//$having_str = "HAVING ABS_STARTDATE<= ('$temp_todate') ";
//}
} elseif($order_by==4) { //ถึงวันที่
$order_str = "ABS_ENDDATE ".$SortType[$order_by];
}elseif($order_by==5) { //จำนวนวัน
$order_str = "ABS_DAY ".$SortType[$order_by];
}elseif($order_by==6) { //การส่งใบลา
$order_str = "ABS_LETTER ".$SortType[$order_by];
}elseif($order_by==7) { //อนุมัติ
$order_str = "a.APPROVE_FLAG ".$SortType[$order_by];
}elseif($order_by==8) { //ประเภทบุคลากร
$order_str = "b.PER_TYPE ".$SortType[$order_by];
}elseif($order_by==9) { //วันที่ส่งใบลา
$order_str = "a.CREATE_DATE ".$SortType[$order_by];
}
//--------------------------------
$search_condition = "";
if ($arr_search_condition) $search_condition = " and " . implode(" and ", $arr_search_condition);
$cmd =" select a.PER_ID
from PER_ABSENT a, PER_PERSONAL b, PER_POSITION d, PER_POS_EMP e, PER_POS_EMPSER f, PER_POS_TEMP g
where a.PER_ID=b.PER_ID and b.POS_ID=d.POS_ID(+) and b.POEM_ID=e.POEM_ID(+) and b.POEMS_ID=f.POEMS_ID(+) and b.POT_ID=g.POT_ID(+)
$search_condition
order by $order_str";
$count_data = $db_dpis->send_cmd($cmd);
//$db_dpis->show_error();
$total_page = ceil( $count_data / $data_per_page );
$page_link = create_link_page($total_page, $current_page);
$limit_data = "";
?>
if ($UPD) $OPTIONAL_TITLE=" > แก้ไขข้อมูล"; elseif ($VIEW) $OPTIONAL_TITLE=" > ดูข้อมูล"; include("current_location.html"); ?> |