[ 'late' => [ 'name' => $lang['On Time Or Delayed Report'], 'subname' => $months_name, 'sub' => [ 'no' => [ 'name' => $lang['On Time'], 'months' => $months ], 'yes' => [ 'name' => $lang['Delayed'], 'months' => $months ] ] ], 'complete' => [ 'name' => $lang['Completed Or Incompleted Report'], 'subname' => $months_name, 'sub' => [ 'yes' => [ 'name' => $lang['Completed'], 'months' => $months ], 'no' => [ 'name' => $lang['Incompleted'], 'months' => $months ], 'cancel' => [ 'name' => $lang['Cancelled'], 'months' => $months ] ] ] ] ] ; if ( $staff_settings['reporttaskbranch'] == 'yes' ){ $array_report['branch'] = [ 'late' => [ 'name' => $lang['On Time Or Delayed Report'], 'subname' => $months_name, 'sub' => [ 'no' => [ 'name' => $lang['On Time'], 'months' => $months ], 'yes' => [ 'name' => $lang['Delayed'], 'months' => $months ] ] ], 'complete' => [ 'name' => $lang['Completed Or Incompleted Report'], 'subname' => $months_name, 'sub' => [ 'yes' => [ 'name' => $lang['Completed'], 'months' => $months ], 'no' => [ 'name' => $lang['Incompleted'], 'months' => $months ], 'cancel' => [ 'name' => $lang['Cancelled'], 'months' => $months ] ] ], ] ; } $filtertype = [] ; foreach ( $array_report as $k => $v ){ if ( $k == $search_type ){ $filtertype[] = $k ; } } foreach ( $filtertype as $k => $v ){ $search_query = " AND ( a.created_branch_id = '".$array['branch_id']."' XXXXXX )" ; switch ( $v ){ case 'personal' : $search_query = str_replace( 'XXXXXX', " AND a.created_by = '".$staff_info['staff_id']."' OR a.assigned_by = '".$staff_info['staff_id']."' OR EXISTS ( SELECT b.staff_id FROM task_joinstaff b WHERE a.task_id = b.task_id AND b.staff_id = '".$staff_info['staff_id']."' LIMIT 1 )", $search_query ) ; break ; case 'branch' : $search_query = str_replace( 'XXXXXX', '', $search_query ) ; break ; } // late report $select_task = $mysqli->query( "SELECT COUNT(a.is_late) as total, a.is_late, MONTH(a.confirmed_at) as month FROM task a WHERE a.deleted_at IS NULL AND a.status = 'approved' AND a.confirmed_at LIKE '%".$search_year."%' ".$search_query." GROUP BY a.is_late, MONTH(a.confirmed_at)" ) ; if ( $select_task->num_rows > 0 ){ while ( $row_task = $select_task->fetch_assoc() ){ $array_report[$v]['late']['sub'][$row_task['is_late']]['months'][$row_task['month']] = $row_task['total'] ; } } // complete report $select_task = $mysqli->query( "SELECT COUNT(a.status) as total, MONTH(a.created_at) as month FROM task a WHERE a.deleted_at IS NULL AND a.status IN ( 'approved' ) AND a.created_at LIKE '%".$search_year."%' ".$search_query." GROUP BY MONTH(a.created_at)" ) ; if ( $select_task->num_rows > 0 ){ while ( $row_task = $select_task->fetch_assoc() ){ $array_report[$v]['complete']['sub']['yes']['months'][$row_task['month']] = $row_task['total'] ; } } // incomplete report $select_task = $mysqli->query( "SELECT COUNT(a.status) as total, MONTH(a.created_at) as month FROM task a WHERE a.deleted_at IS NULL AND a.status IN ( 'pending','assigned','resubmit','progress','completed','confirmed' ) AND a.created_at LIKE '%".$search_year."%' ".$search_query." GROUP BY MONTH(a.created_at)" ) ; if ( $select_task->num_rows > 0 ){ while ( $row_task = $select_task->fetch_assoc() ){ $array_report[$v]['complete']['sub']['no']['months'][$row_task['month']] = $row_task['total'] ; } } // cancel report $select_task = $mysqli->query( "SELECT COUNT(a.status) as total, MONTH(a.created_at) as month FROM task a WHERE a.deleted_at IS NULL AND a.status IN ( 'rejected', 'cancelled' ) AND a.created_at LIKE '%".$search_year."%' ".$search_query." GROUP BY MONTH(a.created_at)" ) ; if ( $select_task->num_rows > 0 ){ while ( $row_task = $select_task->fetch_assoc() ){ $array_report[$v]['complete']['sub']['cancel']['months'][$row_task['month']] = $row_task['total'] ; } } } // direct echo if ( $array['iswebview'] == 'yes' ){ $html .= '
'. $search_year .'
' ; if ( count($array_report) > 1 ){ $html .= '
'.$lang['By Personal'].' '.$lang['By Branch'].'
' ; } foreach ( $array_report as $kreport => $vreport ){ if ( $kreport == $search_type ){ foreach ( $vreport as $ktype => $vtype ){ $title = $vtype['name'] ; $titlename = $title.' ( '.$lang['Year'].' '.$search_year.' )' ; $idname = 'myChart_'.$kreport.'_'.$ktype ; $ctxname = 'ctx_'.$idname ; $configname = 'config_'.$idname ; $datasets = [] ; foreach ( $vtype['sub'] as $ksub => $vsub ){ $temp = [] ; foreach ( $vsub['months'] as $kmonth => $vmonth ){ $temp[] = $vmonth ; } $datasets[] = [ 'label' => $vsub['name'], 'data' => $temp ] ; } $html .= '
' ; } } } $html .= '
' ; } } if ( $array['iswebview'] == 'yes' ){ echo $html ; exit ; } require( $require_sub.'footer.php' ) ; ?>