first commit

This commit is contained in:
LAPTOP-V9RRD1TL\Michelle's Computer
2025-07-21 21:38:17 +08:00
commit f8f8fcaf96
2529 changed files with 227800 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$extra = $array['extra'] ;
$rating = $array['rating'] ;
if ( $task_id != '' ){
$status = '278' ;
if ( $rating != '' ){
$status = '201' ;
$select = $mysqli->query( "SELECT task_so, task_type, difficulty, date_end, assigned_by, incentive, incentive2, confirmed_at, updated_at FROM task
WHERE deleted_at IS NULL AND task_id = '".$task_id."' AND ( created_by = '".$staff_info['staff_id']."' ) AND status = 'confirmed' LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '212' ;
$row = $select->fetch_assoc() ;
$is_late = 'yes' ;
if ( $row['date_end'] >= $row['confirmed_at'] ){
$is_late = 'no' ;
}
if ( $mysqli->query( "UPDATE task SET
extra = '".$extra."',
rating = '".$rating."',
is_late = '".$is_late."',
status = 'approved'
WHERE task_id = '".$task_id."'" ) ) {
// $earned_assigned = ( $extra ) ;
// $earned_executed = ( $extra ) ;
// if ( $row['date_end'] >= $row['updated_at'] ){
$earned_assigned = ( $row['incentive'] + $extra ) ;
$earned_executed = ( $row['incentive2'] + $extra ) ;
// }
$remark1 = 'Earn point from task ' . $row['task_so'] ;
$remark2 = 'Earn incentive from task ' . $row['task_so'] ;
if ( $row['assigned_by'] > 0 ){
pointMovement( 'task', $task_id, $rating, 'normal', $row['assigned_by'], '0', $remark1 ) ;
pointMovement( 'task', $task_id, $row['task_type'], $row['difficulty'], $row['assigned_by'], $earned_assigned, $remark2 ) ;
}
// joinstaff earn point
$select_joinstaff = $mysqli->query( "SELECT staff_id FROM task_joinstaff
WHERE task_id = '".$task_id."'" ) ;
if ( $select_joinstaff->num_rows > 0 ){
while ( $row_joinstaff = $select_joinstaff->fetch_assoc() ){
pointMovement( 'task', $task_id, $rating, 'normal', $row_joinstaff['staff_id'], '0', $remark1 ) ;
pointMovement( 'task', $task_id, $row['task_type'], $row['difficulty'], $row_joinstaff['staff_id'], $earned_executed, $remark2 ) ;
}
}
$status = '200' ;
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Approved', 'Task ( '.$row['task_so'].' ) has been approved' ) ;
}
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+85
View File
@@ -0,0 +1,85 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$incentive2 = $array['incentive2'] ;
$assigned_to = $array['assigned_to'] ;
$joinstaffs = ( checkExists( $array['joinstaffs'] ) ? $array['joinstaffs'] : [] ) ;
if ( $task_id != '' && count( $joinstaffs ) > 0 ){
$status = '303' ;
$staff_tier = [] ;
$staff_tier = getRelatedTierID( 'no', $staff_info['staff_tier_level'] ) ;
$related_staffs = [] ;
if ( count( $joinstaffs ) > 0 ){
foreach ( $joinstaffs as $k => $v ){
$related_staffs[] = $v['id'] ;
}
}
$select_staff = $mysqli->query( "SELECT a.staff_id, a.staff_idno, a.staff_name, a.staff_shortname, a.staff_tier FROM staff a
WHERE a.deleted_at IS NULL AND ( a.staff_date_resigned >= '".date("Y-m-d",time())."' OR a.staff_date_resigned = '0000-00-00' OR a.staff_date_resigned IS NULL ) AND staff_id IN ( '".implode("', '", $related_staffs)."' ) AND staff_tier IN ( '".implode("', '", $staff_tier)."' )" ) ;
if ( $select_staff->num_rows == count( $related_staffs ) ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' 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 ) ) AND a.status IN ( 'pending', 'assigned', 'resubmit', 'progress' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '212' ;
$row = $select->fetch_assoc() ;
// get all task
$update_status = 'assigned' ;
$count_todo_done = 0 ;
$select_task_todo = $mysqli->query( "SELECT is_done FROM task_todo
WHERE deleted_at IS NULL AND task_id = '".$task_id."'" ) ;
if ( $select_task_todo->num_rows > 0 ){
while ( $row_todo = $select_task_todo->fetch_assoc() ){
if ( $row_todo['is_done'] == 'yes' ){
$count_todo_done++ ;
}
}
}
if ( $count_todo_done > 0 ){
$update_status = 'progress' ;
}
if ( $mysqli->query( "UPDATE task SET
incentive2 = '".$incentive2."',
status = '".$update_status."'
WHERE task_id = '".$task_id."'" ) ) {
$status = '200' ;
// deleted all related staff
$mysqli->query( "DELETE FROM `task_joinstaff` WHERE task_id = '".$task_id."'" ) ;
if ( checkExists($joinstaffs) ){
foreach ( $joinstaffs as $k => $v ){
$mysqli->query( "INSERT INTO `task_joinstaff` ( `task_id`, `staff_id` ) VALUES ( '".$task_id."', '".$v['id']."' )" ) ;
}
}
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Assign', 'Task ( '.$row['task_so'].' ) has been assigned' ) ;
}
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+45
View File
@@ -0,0 +1,45 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$reason = $array['reason'] ;
if ( $task_id != '' && $reason != '' ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' AND a.created_by = '".$staff_info['staff_id']."' AND a.status IN ( 'pending', 'assigned', 'resubmit', 'progress', 'completed', 'confirmed' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '303' ;
$row = $select->fetch_assoc() ;
if ( $mysqli->query( "UPDATE task SET
status = 'cancelled'
WHERE task_id = '".$task_id."'" ) ) {
$mysqli->query( "INSERT INTO task_rejected
( `task_id`, `staff_id`, `remark` ) VALUES
( '".$task_id."', '".$staff_info['staff_id']."', '".$reason."' )" ) ;
$status = '200' ;
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Cancelled', 'Task ( '.$row['task_so'].' ) has been cancelled' ) ;
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+140
View File
@@ -0,0 +1,140 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '200' ;
$staffs = [] ;
$departments = [] ;
$staff_departments = [] ;
$difficultys = [] ;
$all_tier = getAllTier( $array['lang'] ) ;
// select all staff
$select = $mysqli->query( "SELECT a.staff_id, a.staff_idno, a.staff_name, a.staff_shortname, a.staff_tier FROM staff a
WHERE a.deleted_at IS NULL AND a.branch_id = '".$array['branch_id']."' AND ( a.staff_date_resigned >= '".date("Y-m-d",time())."' OR a.staff_date_resigned = '0000-00-00' OR a.staff_date_resigned IS NULL ) " ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
$get_staff_tier = $all_tier[$row['staff_tier']] ;
$staffs[$row['staff_id']] = [
'id' => $row['staff_id'],
'title' => $row['staff_shortname'] . ' ('.$row['staff_idno'].' / '.strtoupper( $get_staff_tier['title'] ).')',
'name' => $row['staff_name'],
'tier' => $get_staff_tier['level']
] ;
}
}
// select all department
$select = $mysqli->query( "SELECT a.department_id, b.department_desc FROM setting_department a
LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."'" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
$departments[] = $row ;
}
}
// select all staff department
$select = $mysqli->query( "SELECT a.staff_id, a.department_id FROM staff_department a
WHERE a.deleted_at IS NULL" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
if ( $staffs[ $row['staff_id'] ] != null && $staffs[ $row['staff_id'] ] != undefined ){
$staff = $staffs[ $row['staff_id'] ] ;
$staff_departments[$row['department_id']][] = $staff ;
}
}
}
// reset
$reset_departments[] = [
'id' => '0',
'title' => 'Cross Department',
'staffs' => []
] ;
foreach ( $departments as $k => $v ){
if ( $staff_departments[$v['department_id']] != null && $staff_departments[$v['department_id']] != undefined ){
$reset_departments[] = [
'id' => $v['department_id'],
'title' => $v['department_desc'],
'staffs' => $staff_departments[$v['department_id']]
] ;
}
}
$task_types = [
[
'id' => '1time',
'title' => 'One Time Only'
],
[
'id' => 'daily',
'title' => 'Daily Update'
],
[
'id' => 'weekly',
'title' => 'Weekly Update'
],
[
'id' => 'monthly',
'title' => 'Monthly Update'
],
[
'id' => 'yearly',
'title' => 'Yearly Update'
]
] ;
// select all department
$select = $mysqli->query( "SELECT a.code, b.title FROM setting_difficulty a
LEFT JOIN setting_difficulty_translation b ON ( a.difficulty_id = b.difficulty_id )
WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."' AND set_tier LIKE '%|".$staff_info['staff_tier']."|%'
ORDER BY a.sortable" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
$difficultys[] = [
'id' => $row['code'],
'title' => $row['title'],
] ;
}
}
$data = [
'task_types' => $task_types,
'departments' => $reset_departments,
'difficultys' => $difficultys
] ;
}
require( $require_sub.'footer.php' ) ;
?>
+40
View File
@@ -0,0 +1,40 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
if ( $task_id != '' ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' 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 ) ) AND a.status IN ( 'completed' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '212' ;
$row = $select->fetch_assoc() ;
if ( $mysqli->query( "UPDATE task SET
status = 'confirmed',
confirmed_at = '".TODAYDATE."'
WHERE task_id = '".$task_id."'" ) ) {
$status = '200' ;
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Confirmed', 'Task ( '.$row['task_so'].' ) has been confirmed' ) ;
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+128
View File
@@ -0,0 +1,128 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '201' ;
// select all department
$department_list = [] ;
$select = $mysqli->query( "SELECT a.department_id, b.department_desc FROM setting_department a
LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."'" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
$department_list[$row['department_id']] = $row['department_desc'] ;
}
}
// select all staff
$staff_list = [] ;
$select = $mysqli->query( "SELECT a.staff_id, a.staff_name, a.staff_shortname, a.staff_idno FROM staff a
WHERE a.deleted_at IS NULL" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
$staff_list[$row['staff_id']] = $row['staff_name'] . ' ( '.$row['staff_idno'].' )' ;
}
}
$search_query = '' ;
if ( $array['search'] != '' ){
$search_query .= " AND a.title LIKE '%".$array['search']."%'" ;
}
if ( $array['searchstatus'] != '' ){
// $search_query .= " AND a.status = '".$array['searchstatus']."'" ;
$search_status = [] ;
switch ( $array['searchstatus'] ){
case 'approved' :
$search_status = [ 'approved' ] ;
break ;
case 'rejected' :
$search_status = [ 'rejected' ] ;
break ;
default :
$search_status = [ 'pending', 'assigned', 'resubmit', 'progress', 'completed', 'confirmed' ] ;
}
$search_query .= " AND a.status IN ( '".implode("', '", $search_status)."' )" ;
}else{
$search_query .= " AND a.status != 'rejected'" ;
}
switch ( $array['searchincharge'] ){
case 'create' :
$search_query .= " AND a.created_by = '".$staff_info['staff_id']."'" ;
break ;
case 'assign' :
$search_query .= " AND a.assigned_by = '".$staff_info['staff_id']."'" ;
break ;
case 'execute' :
$search_query .= " AND 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 )" ;
break ;
}
$query = "SELECT a.task_id, a.task_type, a.title, a.department_id, a.created_by, a.assigned_by, a.difficulty, a.date_start, a.date_end, a.remark, a.todo_list, a.todo_done, a.status, a.created_at, a.updated_at FROM task a
WHERE a.deleted_at IS NULL AND ( a.created_branch_id = '".$array['branch_id']."' 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 ;
$mysqli_query = $mysqli->query( $query . " ORDER BY a.created_at DESC LIMIT " . getLimit( $current ) ) ;
if ( $mysqli_query->num_rows > 0 ){
$status = '200' ;
$list = [] ;
$task_ids = [] ;
while ( $row = $mysqli_query->fetch_assoc() ){
$task_type_name = '' ;
switch ( $row['task_type'] ){
case '1time' : $task_type_name = 'One Time Only' ; break ;
case 'daily' : $task_type_name = 'Daily Update' ; break ;
case 'weekly' : $task_type_name = 'Weekly Update' ; break ;
case 'monthly' : $task_type_name = 'Monthly Update' ; break ;
case 'yearly' : $task_type_name = 'Yearly Update' ; break ;
}
$row['title'] = dataFilter( $row['title'] ) ;
$row['task_type_name'] = $task_type_name ;
$row['expired'] = strtotime( $row['date_end'] ) ;
$row['is_warning'] = ( $row['date_end'] == TODAYDAY ? 'yes' : 'no' ) ;
$row['department'] = ( checkExists( $department_list[ $row['department_id'] ] ) ? $department_list[ $row['department_id'] ] : 'Cross Department' ) ;
$row['created_by_name'] = $staff_list[ $row['created_by'] ] ;
$row['assigned_by_name'] = checkExists( $staff_list[ $row['assigned_by'] ] ) ;
$row['progress'] = ( $row['todo_done'] > 0 ? ( numberFormat( ( $row['todo_done'] / $row['todo_list'] * 100 ), 2 ) + 0 ) : 0 ) ;
$list[$row['task_id']] = $row ;
$task_ids[] = $row['task_id'] ;
}
// join staff
$query_joinstaff = $mysqli->query( "SELECT * FROM task_joinstaff
WHERE task_id IN ( ".implode(', ', $task_ids)." )" ) ;
$joinstaffs = [] ;
if ( $query_joinstaff->num_rows > 0 ){
while ( $row_joinstaff = $query_joinstaff->fetch_assoc() ){
$joinstaffs[$row_joinstaff['task_id']][] = $staff_list[ $row_joinstaff['staff_id'] ] ;
}
}
// reset list
$new_list = [] ;
foreach ( $list as $k => $v ){
$assigned_by_name = ( checkExists( $joinstaffs[$v['task_id']] ) ? implode( ', ', $joinstaffs[$v['task_id']] ) : $v['assigned_by_name'] ) ;
$v['assigned_by_name'] = $assigned_by_name ;
$new_list[] = $v ;
}
$data['list'] = $new_list ;
}
}
require( $require_sub.'footer.php' ) ;
?>
+92
View File
@@ -0,0 +1,92 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$todo_list = $array['todo_list'] ;
if ( $task_id != '' && count( $todo_list ) > 0 ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' 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 ) ) AND a.status IN ( 'pending', 'assigned', 'resubmit', 'progress', 'completed' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '202' ;
$row = $select->fetch_assoc() ;
$count_todo_list = 0 ;
$count_todo_done = 0 ;
if ( checkExists($array['todo_list']) ){
foreach ( $array['todo_list'] as $k => $v ){
if ( $v['is_delete'] == 'no' ){
$count_todo_list++ ;
if ( $v['is_done'] == 'yes' ){
$count_todo_done++ ;
}
}
}
}
if ( checkExists($array['todo_list']) ){
foreach ( $array['todo_list'] as $k => $v ){
if ( $v['is_delete'] == 'no' ){
if ( $v['id'] > 0 ){
$mysqli->query( "UPDATE task_todo SET
title = '".$v['title']."',
sortable = '".$v['sortable']."'
WHERE todo_id = '".$v['id']."'" ) ;
}else{
$mysqli->query( "INSERT INTO task_todo
( `task_id`, `title`, `sortable` ) VALUES
( '".$task_id."', '".$v['title']."', '".$v['sortable']."' )" ) ;
}
}else{
if ( $v['id'] > 0 ){
$mysqli->query( "UPDATE task_todo SET
deleted_at = '".TODAYDATE."'
WHERE todo_id = '".$v['id']."'" ) ;
}
}
}
}
$update_status = 'pending' ;
if ( $row['assigned_by'] > 0 ){
$update_status = 'assigned' ;
}
if ( $count_todo_done > 0 ){
$update_status = 'progress' ;
}
if ( $count_todo_list == $count_todo_done ){
$update_status = 'completed' ;
}
if ( $mysqli->query( "UPDATE task SET
status = '".$update_status."',
todo_list = '".$count_todo_list."',
todo_done = '".$count_todo_done."'
WHERE task_id = '".$task_id."'" ) ) {
$status = '200' ;
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Todo', 'Task ( '.$row['task_so'].' ) todo has been updated' ) ;
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+36
View File
@@ -0,0 +1,36 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$reason = $array['reason'] ;
if ( $task_id != '' && $reason != '' ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' 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 ) ) AND a.status IN ( 'pending', 'assigned' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '212' ;
if ( $mysqli->query( "UPDATE task SET
status = 'rejected',
rejected_at = '".TODAYDATE."',
rejected_by = '".$staff_info['staff_id']."',
rejected_reason = '".$reason."'
WHERE task_id = '".$task_id."'" ) ) {
$status = '200' ;
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+66
View File
@@ -0,0 +1,66 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$reason = $array['reason'] ;
if ( $task_id != '' && $reason != '' ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' 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 ) ) AND a.status IN ( 'pending', 'assigned', 'completed', 'confirmed' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '303' ;
$row = $select->fetch_assoc() ;
$update_status = '' ;
if ( $row['status'] == 'confirmed' ){
if ( $row['created_by'] == $staff_info['staff_id'] ){
$update_status = 'resubmit' ;
}
}else{
$update_status = 'rejected' ;
}
if ( $update_status != '' ){
$status = '202' ;
if ( $mysqli->query( "UPDATE task SET
todo_done = '0',
status = '".$update_status."'
WHERE task_id = '".$task_id."'" ) ) {
$mysqli->query( "INSERT INTO task_rejected
( `task_id`, `staff_id`, `remark` ) VALUES
( '".$task_id."', '".$staff_info['staff_id']."', '".$reason."' )" ) ;
if ( $update_status == 'resubmit' ){
$mysqli->query( "UPDATE task_todo SET
is_done = 'no'
WHERE task_id = '".$task_id."'" ) ;
}
$status = '200' ;
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Rejected', 'Task ( '.$row['task_so'].' ) has been rejected' ) ;
}
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+67
View File
@@ -0,0 +1,67 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$todo_id = $array['todo_id'] ;
$remark_list = $array['remark_list'] ;
if ( $task_id != '' && $todo_id != '' && count( $remark_list ) > 0 ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' 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 ) ) AND a.status IN ( 'pending', 'assigned', 'resubmit', 'progress', 'completed' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$row = $select->fetch_assoc() ;
// check if selected todo exists
$select_todo = $mysqli->query( "SELECT * FROM task_todo
WHERE deleted_at IS NULL AND task_id = '".$task_id."' AND todo_id = '".$todo_id."' LIMIT 1" ) ;
if ( $select_todo->num_rows > 0 ){
$status = '202' ;
if ( checkExists($array['remark_list']) ){
foreach ( $array['remark_list'] as $k => $v ){
if ( $v['is_delete'] == 'no' ){
if ( $v['id'] > 0 ){
$mysqli->query( "UPDATE task_todo_remark SET
title = '".$v['title']."'
WHERE remark_id = '".$v['id']."'" ) ;
}else{
$mysqli->query( "INSERT INTO task_todo_remark
( `task_id`, `todo_id`, `staff_id`, `title` ) VALUES
( '".$task_id."', '".$todo_id."', '".$staff_info['staff_id']."', '".$v['title']."' )" ) ;
}
}else{
if ( $v['id'] > 0 ){
$mysqli->query( "UPDATE task_todo_remark SET
deleted_at = '".TODAYDATE."'
WHERE remark_id = '".$v['id']."'" ) ;
}
}
}
$status = '200' ;
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Remark', 'Task ( '.$row['task_so'].' ) remark updated' ) ;
}
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+351
View File
@@ -0,0 +1,351 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
require( $require_path.'languages/'.$array['lang'].'.php' ) ;
$html = '' ;
if ( $boolean_login ){
$status = '201' ;
$search_year = ( $array['search_year'] != '' ? $array['search_year'] : date('Y') ) ;
$search_type = ( $array['search_type'] != '' ? $array['search_type'] : 'personal' ) ;
$staff_settings = $staff_info['staff_settings'] ;
// select all month
$months = [] ;
$months_name = [ $lang['Jan'], $lang['Feb'], $lang['Mar'], $lang['Apr'], $lang['May'], $lang['Jun'], $lang['Jul'], $lang['Aug'], $lang['Sep'], $lang['Oct'], $lang['Nov'], $lang['Dec'] ] ;
for ( $a = 1 ; $a <= 12 ; $a++ ){ $months[$a] = 0 ; }
// select all department
$departments = [ '0' => $months ] ;
$departments_name = [ '0' => $lang['Cross Department'] ] ;
$select_departments = $mysqli->query( "SELECT a.department_id, b.department_desc FROM setting_department a
LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."'" ) ;
if ( $select_departments->num_rows > 0 ){
while ( $row_departments = $select_departments->fetch_assoc() ){
$departments[$row_departments['department_id']] = $months ;
$departments_name[$row_departments['department_id']] = $row_departments['department_desc'] ;
}
}
// monthly report = by personal or whole branch
$array_report = [
'personal' => [
// 'late' => [
// 'name' => $lang['On Time Or Delayed Report'],
// 'subname' => $months_name,
// 'sub' => [
// 'no' => [ 'name' => $lang['On Time'], 'lists' => $months ],
// 'yes' => [ 'name' => $lang['Delayed'], 'lists' => $months ]
// ]
// ],
'complete' => [
'name' => $lang['Completed Or Incompleted Report'],
'subname' => $months_name,
'sub' => [
'yes' => [ 'name' => $lang['Completed'], 'lists' => $months ],
'no' => [ 'name' => $lang['Incompleted'], 'lists' => $months ],
'cancel' => [ 'name' => $lang['Cancelled'], 'lists' => $months ]
]
],
'department' => [
'name' => $lang['Department Task Given Report'],
'subname' => $months_name,
'sub' => $departments
]
]
] ;
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'], 'lists' => $months ],
// 'yes' => [ 'name' => $lang['Delayed'], 'lists' => $months ]
// ]
// ],
'complete' => [
'name' => $lang['Completed Or Incompleted Report'],
'subname' => $months_name,
'sub' => [
'yes' => [ 'name' => $lang['Completed'], 'lists' => $months ],
'no' => [ 'name' => $lang['Incompleted'], 'lists' => $months ],
'cancel' => [ 'name' => $lang['Cancelled'], 'lists' => $months ]
]
],
'department' => [
'name' => $lang['Department Task Given Report'],
'subname' => $months_name,
'sub' => $departments
]
] ;
}
$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']]['lists'][$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']['lists'][$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']['lists'][$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']['lists'][$row_task['month']] = $row_task['total'] ;
}
}
// department complete report
$select_task = $mysqli->query( "SELECT COUNT(a.department_id) as total, a.department_id, MONTH(a.confirmed_at) as month FROM task a
WHERE a.deleted_at IS NULL AND a.status IN ( 'approved' ) AND a.confirmed_at LIKE '%".$search_year."%' ".$search_query."
GROUP BY a.department_id, MONTH(a.confirmed_at)" ) ;
if ( $select_task->num_rows > 0 ){
while ( $row_task = $select_task->fetch_assoc() ){
$array_report[$v]['department']['sub'][$row_task['department_id']][$row_task['month']] = $row_task['total'] ;
}
}
}
// direct echo
if ( $array['iswebview'] == 'yes' ){
$html .= '
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="'.PATH.'css/bootstrap.css?v='.filemtime($require_path.'css/bootstrap.css').'" />
<script src="'.PATH.'scripts/chart.js"></script>
</head>
<body>
<div class="report_chart_main">
<div class="report_chart_filter_year">
<a href="?search_year='.( $search_year - 1 ).resetGetParams($array, [ 'search_year' ]).'" class="report_chart_filter_year_button">
<i class="fa fa-chevron-left" aria-hidden="true"></i>
</a>
<span class="report_chart_filter_year_span">'. $search_year .'</span>
<a href="?search_year='.( $search_year + 1 ).resetGetParams($array, [ 'search_year' ]).'" class="report_chart_filter_year_button">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
</div>' ;
if ( count($array_report) > 1 ){
$html .= '
<div class="report_chart_filter_type">
<a href="?search_type=personal'.resetGetParams($array, [ 'search_type' ]).'" class="report_chart_filter_type_button '.( $search_type == 'personal' ? 'active' : '' ).'">
'.$lang['By Personal'].'
</a>
<a href="?search_type=branch'.resetGetParams($array, [ 'search_type' ]).'" class="report_chart_filter_type_button '.( $search_type == 'branch' ? 'active' : '' ).'">
'.$lang['By Branch'].'
</a>
</div>' ;
}
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 = [] ;
switch ( $ktype ){
case 'late' :
case 'complete' :
foreach ( $vtype['sub'] as $ksub => $vsub ){
$temp = [] ;
foreach ( $vsub['lists'] as $klist => $vlist ){
$temp[] = "$vlist" ;
}
$datasets[] = [
'label' => $vsub['name'],
'data' => $temp
] ;
}
$html .= '
<div class="report_chart_line">
<canvas id="'.$idname.'"></canvas>
</div>
<script>
const '.$ctxname.' = document.getElementById("'.$idname.'") ;
const '.$configname.' = {
type : "line",
data : {
datasets : '.json_encode($datasets).',
labels : [ "'.implode( '", "', $vtype['subname'] ).'" ]
},
options: {
responsive : true,
maintainAspectRatio : false,
plugins : {
legend : {
position : "top",
},
title : {
display : true,
text : "'.$titlename.'"
}
}
}
} ;
new Chart( '.$ctxname.', '.$configname.' ) ;
</script>' ;
break ;
case 'department' :
foreach ( $departments_name as $kdepartment => $vdepartment ){
$temp = [] ;
foreach ( $vtype['sub'][$kdepartment] as $klist => $vlist ){
$temp[] = "$vlist" ;
}
$datasets[] = [
'label' => $vdepartment,
'data' => $temp
] ;
}
$html .= '
<div class="report_chart_bar">
<canvas id="'.$idname.'"></canvas>
</div>
<script>
const '.$ctxname.' = document.getElementById("'.$idname.'") ;
const '.$configname.' = {
type : "bar",
data : {
datasets : '.json_encode($datasets).',
labels : [ "'.implode( '", "', $vtype['subname'] ).'" ]
},
options: {
responsive : true,
maintainAspectRatio : false,
elements : {
bar : {
borderWidth : 2
}
},
indexAxis : "y",
plugins : {
legend : {
position : "top",
align : "left"
},
title : {
display : true,
text : "'.$titlename.'"
}
}
}
} ;
new Chart( '.$ctxname.', '.$configname.' ) ;
</script>' ;
break ;
}
}
}
}
$html .= '
</div>
</body>
</html>' ;
}
}
if ( $array['iswebview'] == 'yes' ){
echo $html ;
exit ;
}
require( $require_sub.'footer.php' ) ;
?>
+248
View File
@@ -0,0 +1,248 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
require( $require_path.'languages/'.$array['lang'].'.php' ) ;
$html = '' ;
if ( $boolean_login ){
$status = '201' ;
$search_year = ( $array['search_year'] != '' ? $array['search_year'] : date('Y') ) ;
$search_type = ( $array['search_type'] != '' ? $array['search_type'] : 'personal' ) ;
$staff_settings = $staff_info['staff_settings'] ;
$months = [] ;
$months_name = [ $lang['Jan'], $lang['Feb'], $lang['Mar'], $lang['Apr'], $lang['May'], $lang['Jun'], $lang['Jul'], $lang['Aug'], $lang['Sep'], $lang['Oct'], $lang['Nov'], $lang['Dec'] ] ;
for ( $a = 1 ; $a <= 12 ; $a++ ){ $months[$a] = 0 ; }
// monthly report = by personal or whole branch
$array_report = [
'personal' => [
'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 .= '
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="'.PATH.'css/bootstrap.css?v='.filemtime($require_path.'css/bootstrap.css').'" />
<script src="'.PATH.'scripts/chart.js"></script>
</head>
<body>
<div class="report_chart_main">
<div class="report_chart_filter_year">
<a href="?search_year='.( $search_year - 1 ).resetGetParams($array, [ 'search_year' ]).'" class="report_chart_filter_year_button">
<i class="fa fa-chevron-left" aria-hidden="true"></i>
</a>
<span class="report_chart_filter_year_span">'. $search_year .'</span>
<a href="?search_year='.( $search_year + 1 ).resetGetParams($array, [ 'search_year' ]).'" class="report_chart_filter_year_button">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
</div>' ;
if ( count($array_report) > 1 ){
$html .= '
<div class="report_chart_filter_type">
<a href="?search_type=personal'.resetGetParams($array, [ 'search_type' ]).'" class="report_chart_filter_type_button '.( $search_type == 'personal' ? 'active' : '' ).'">
'.$lang['By Personal'].'
</a>
<a href="?search_type=branch'.resetGetParams($array, [ 'search_type' ]).'" class="report_chart_filter_type_button '.( $search_type == 'branch' ? 'active' : '' ).'">
'.$lang['By Branch'].'
</a>
</div>' ;
}
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 .= '
<div class="report_chart_line">
<canvas id="'.$idname.'"></canvas>
</div>
<script>
const '.$ctxname.' = document.getElementById("'.$idname.'") ;
const '.$configname.' = {
type : "line",
data : {
datasets : '.json_encode($datasets).',
labels : [ "'.implode( '", "', $vtype['subname'] ).'" ]
},
options: {
responsive : true,
maintainAspectRatio : false,
plugins : {
legend : {
position : "top",
},
title : {
display : true,
text : "'.$titlename.'"
}
}
}
} ;
new Chart( '.$ctxname.', '.$configname.' ) ;
</script>' ;
}
}
}
$html .= '
</div>
</body>
</html>' ;
}
}
if ( $array['iswebview'] == 'yes' ){
echo $html ;
exit ;
}
require( $require_sub.'footer.php' ) ;
?>
+361
View File
@@ -0,0 +1,361 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
require( $require_path.'languages/'.$array['lang'].'.php' ) ;
$html = '' ;
if ( $boolean_login ){
$status = '201' ;
$search_year = ( $array['search_year'] != '' ? $array['search_year'] : date('Y') ) ;
$search_type = ( $array['search_type'] != '' ? $array['search_type'] : 'personal' ) ;
$staff_settings = $staff_info['staff_settings'] ;
// select all month
$months = [] ;
$months_name = [ $lang['Jan'], $lang['Feb'], $lang['Mar'], $lang['Apr'], $lang['May'], $lang['Jun'], $lang['Jul'], $lang['Aug'], $lang['Sep'], $lang['Oct'], $lang['Nov'], $lang['Dec'] ] ;
for ( $a = 1 ; $a <= 12 ; $a++ ){ $months[$a] = 0 ; }
// select all department
$departments = [ '0' => $months ] ;
$departments_name = [ '0' => [ 'desc' => $lang['Cross Department'], 'colour' => '#EB5406' ] ] ;
$select_departments = $mysqli->query( "SELECT a.department_id, a.department_colour, b.department_desc FROM setting_department a
LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."'" ) ;
if ( $select_departments->num_rows > 0 ){
while ( $row_departments = $select_departments->fetch_assoc() ){
$departments[$row_departments['department_id']] = $months ;
$departments_name[$row_departments['department_id']] = [
'desc' => dataFilter( $row_departments['department_desc'] ),
'colour' => $row_departments['department_colour']
] ;
}
}
// monthly report = by personal or whole branch
$array_report = [
'personal' => [
// 'late' => [
// 'name' => $lang['On Time Or Delayed Report'],
// 'subname' => $months_name,
// 'sub' => [
// 'no' => [ 'name' => $lang['On Time'], 'lists' => $months ],
// 'yes' => [ 'name' => $lang['Delayed'], 'lists' => $months ]
// ]
// ],
'complete' => [
'name' => $lang['Completed Or Incompleted Report'],
'subname' => $months_name,
'sub' => [
'yes' => [ 'name' => $lang['Completed'], 'lists' => $months ],
'no' => [ 'name' => $lang['Incompleted'], 'lists' => $months ],
'cancel' => [ 'name' => $lang['Cancelled'], 'lists' => $months ]
]
],
'department' => [
'name' => $lang['Department Task Given Report'],
'subname' => $months_name,
'sub' => $departments
]
]
] ;
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'], 'lists' => $months ],
// 'yes' => [ 'name' => $lang['Delayed'], 'lists' => $months ]
// ]
// ],
'complete' => [
'name' => $lang['Completed Or Incompleted Report'],
'subname' => $months_name,
'sub' => [
'yes' => [ 'name' => $lang['Completed'], 'lists' => $months ],
'no' => [ 'name' => $lang['Incompleted'], 'lists' => $months ],
'cancel' => [ 'name' => $lang['Cancelled'], 'lists' => $months ]
]
],
'department' => [
'name' => $lang['Department Task Given Report'],
'subname' => $months_name,
'sub' => $departments
]
] ;
}
$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']]['lists'][$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']['lists'][$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']['lists'][$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']['lists'][$row_task['month']] = $row_task['total'] ;
}
}
// department complete report
$select_task = $mysqli->query( "SELECT COUNT(a.department_id) as total, a.department_id, MONTH(a.confirmed_at) as month FROM task a
WHERE a.deleted_at IS NULL AND a.status IN ( 'approved' ) AND a.confirmed_at LIKE '%".$search_year."%' ".$search_query."
GROUP BY a.department_id, MONTH(a.confirmed_at)" ) ;
if ( $select_task->num_rows > 0 ){
while ( $row_task = $select_task->fetch_assoc() ){
$array_report[$v]['department']['sub'][$row_task['department_id']][$row_task['month']] = $row_task['total'] ;
}
}
}
// direct echo
if ( $array['iswebview'] == 'yes' ){
$html .= '
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="'.PATH.'css/bootstrap.css?v='.filemtime($require_path.'css/bootstrap.css').'" />
<script src="'.PATH.'scripts/chart.js"></script>
</head>
<body>
<div class="report_chart_main">
<div class="report_chart_filter_year">
<a href="?search_year='.( $search_year - 1 ).resetGetParams($array, [ 'search_year' ]).'" class="report_chart_filter_year_button">
<i class="fa fa-chevron-left" aria-hidden="true"></i>
</a>
<span class="report_chart_filter_year_span">'. $search_year .'</span>
<a href="?search_year='.( $search_year + 1 ).resetGetParams($array, [ 'search_year' ]).'" class="report_chart_filter_year_button">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
</div>' ;
if ( count($array_report) > 1 ){
$html .= '
<div class="report_chart_filter_type">
<a href="?search_type=personal'.resetGetParams($array, [ 'search_type' ]).'" class="report_chart_filter_type_button '.( $search_type == 'personal' ? 'active' : '' ).'">
'.$lang['By Personal'].'
</a>
<a href="?search_type=branch'.resetGetParams($array, [ 'search_type' ]).'" class="report_chart_filter_type_button '.( $search_type == 'branch' ? 'active' : '' ).'">
'.$lang['By Branch'].'
</a>
</div>' ;
}
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 = [] ;
switch ( $ktype ){
case 'late' :
case 'complete' :
$count_color = 0 ;
foreach ( $vtype['sub'] as $ksub => $vsub ){
$temp = [] ;
foreach ( $vsub['lists'] as $klist => $vlist ){
$temp[] = "$vlist" ;
}
$datasets[] = [
'label' => $vsub['name'],
'data' => $temp,
'backgroundColor' => $colors[$count_color]
] ;
$count_color++ ;
}
$html .= '
<div class="report_chart_line">
<canvas id="'.$idname.'"></canvas>
</div>
<script>
const '.$ctxname.' = document.getElementById("'.$idname.'") ;
const '.$configname.' = {
type : "line",
data : {
datasets : '.json_encode($datasets).',
labels : [ "'.implode( '", "', $vtype['subname'] ).'" ]
},
options: {
responsive : true,
maintainAspectRatio : false,
plugins : {
legend : {
position : "top",
},
title : {
display : true,
text : "'.$titlename.'"
}
}
}
} ;
new Chart( '.$ctxname.', '.$configname.' ) ;
</script>' ;
break ;
case 'department' :
$count_color = 0 ;
foreach ( $departments_name as $kdepartment => $vdepartment ){
$temp = [] ;
foreach ( $vtype['sub'][$kdepartment] as $klist => $vlist ){
$temp[] = "$vlist" ;
}
$datasets[] = [
'label' => $vdepartment['desc'],
'data' => $temp,
'backgroundColor' => $vdepartment['colour']
] ;
$count_color++ ;
}
$html .= '
<div class="report_chart_bar">
<canvas id="'.$idname.'"></canvas>
</div>
<script>
const '.$ctxname.' = document.getElementById("'.$idname.'") ;
const '.$configname.' = {
type : "bar",
data : {
datasets : '.json_encode($datasets).',
labels : [ "'.implode( '", "', $vtype['subname'] ).'" ]
},
options: {
responsive : true,
maintainAspectRatio : false,
elements : {
bar : {
borderWidth : 2
}
},
indexAxis : "y",
plugins : {
legend : {
position : "top"
},
title : {
display : true,
text : "'.$titlename.'"
}
}
}
} ;
new Chart( '.$ctxname.', '.$configname.' ) ;
</script>' ;
break ;
}
}
}
}
$html .= '
</div>
</body>
</html>' ;
}
}
if ( $array['iswebview'] == 'yes' ){
echo $html ;
exit ;
}
require( $require_sub.'footer.php' ) ;
?>
+240
View File
@@ -0,0 +1,240 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '201' ;
$all_tier = getAllTier( $array['lang'] ) ;
// select all department
$department_list = [] ;
$select = $mysqli->query( "SELECT a.department_id, b.department_desc FROM setting_department a
LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."'" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
$department_list[$row['department_id']] = $row['department_desc'] ;
}
}
// select all staff
$staff_list = [] ;
$select = $mysqli->query( "SELECT a.staff_id, a.staff_name, a.staff_shortname, a.staff_idno, a.staff_tier FROM staff a
WHERE a.deleted_at IS NULL" ) ;
if ( $select->num_rows > 0 ){
while ( $row = $select->fetch_assoc() ){
$get_staff_tier = $all_tier[$row['staff_tier']] ;
$staff_list[$row['staff_id']] = $row['staff_shortname'] . ' ( '.$row['staff_idno'].' / '.strtoupper( $get_staff_tier['title'] ).')' ;
}
}
// default parameter
$isupdate = 'no' ;
$iscancel = 'no' ;
$isreject = 'no' ;
$isassigned = 'no' ;
$search_query = '' ;
$search_query .= " AND task_id = '".$array['task_id']."'" ;
$query = "SELECT task_id, task_type, task_so, title, department_id, created_by, assigned_by, difficulty, date_start, date_end, remark, incentive, incentive2, extra, rating, todo_list, todo_done, status, created_at, updated_at FROM task
WHERE deleted_at IS NULL " . $search_query ;
$mysqli_query = $mysqli->query( $query . " LIMIT 1" ) ;
if ( $mysqli_query->num_rows > 0 ){
$status = '200' ;
$list = [] ;
$row = $mysqli_query->fetch_assoc() ;
$task_type_name = '' ;
switch ( $row['task_type'] ){
case '1time' : $task_type_name = 'One Time Only' ; break ;
case 'daily' : $task_type_name = 'Daily Update' ; break ;
case 'weekly' : $task_type_name = 'Weekly Update' ; break ;
case 'monthly' : $task_type_name = 'Monthly Update' ; break ;
case 'yearly' : $task_type_name = 'Yearly Update' ; break ;
}
$row['title'] = dataFilter( $row['title'] ) ;
$row['task_type_name'] = $task_type_name ;
$row['expired'] = strtotime( $row['date_end'] . ' 23:59:59' ) ;
$row['is_warning'] = ( $row['date_end'] == TODAYDAY ? 'yes' : 'no' ) ;
$row['department_name'] = checkExists( $department_list[ $row['department_id'] ] ) ;
$row['created_by_name'] = checkExists( $staff_list[ $row['created_by'] ] ) ;
$row['assigned_by_name'] = checkExists( $staff_list[ $row['assigned_by'] ] ) ;
$row['progress'] = ( $row['todo_done'] > $row['todo_list'] ? ( numberFormat( ( $row['todo_done'] / $row['todo_list'] * 100 ), 2 ) + 0 ) : 0 ) ;
// get all joinstaff
$joinstaff_list = [] ;
$select_joinstaff = $mysqli->query( "SELECT staff_id FROM task_joinstaff
WHERE task_id = '".$array['task_id']."'" ) ;
if ( $select_joinstaff->num_rows > 0 ){
while ( $row_joinstaff = $select_joinstaff->fetch_assoc() ){
$joinstaff_list[] = [
'id' => $row_joinstaff['staff_id'],
'title' => $staff_list[ $row_joinstaff['staff_id'] ]
] ;
if ( $row_joinstaff['staff_id'] == $staff_info['staff_id'] ){
$isreject = 'yes' ;
}
}
}
$row['joinstaffs'] = $joinstaff_list ;
// get all todo remark
$todo_remark_list = [] ;
$select_task_todo_remark = $mysqli->query( "SELECT * FROM task_todo_remark
WHERE deleted_at IS NULL AND task_id = '".$array['task_id']."'" ) ;
if ( $select_task_todo_remark->num_rows > 0 ){
while ( $row_todo_remark = $select_task_todo_remark->fetch_assoc() ){
$todo_remark_list[$row_todo_remark['todo_id']][] = [
'id' => $row_todo_remark['remark_id'],
'title' => dataFilter( $row_todo_remark['title'] ),
'is_delete' => 'no'
] ;
}
}
// get all todo task
$todo_list = [] ;
$select_task_todo = $mysqli->query( "SELECT * FROM task_todo
WHERE deleted_at IS NULL AND task_id = '".$array['task_id']."'
ORDER BY sortable ASC, todo_id ASC" ) ;
if ( $select_task_todo->num_rows > 0 ){
while ( $row_todo = $select_task_todo->fetch_assoc() ){
$todo_list[] = [
'id' => $row_todo['todo_id'],
'title' => dataFilter( $row_todo['title'] ),
'is_done' => $row_todo['is_done'],
'done_by' => $row_todo['done_by'],
'done_name' => $staff_list[ $row_todo['done_by'] ],
'done_at' => $row_todo['done_at'],
'is_delete' => 'no',
'remark' => ( checkExists( $todo_remark_list[$row_todo['todo_id']] ) ? $todo_remark_list[$row_todo['todo_id']] : [] )
] ;
}
}
$row['todo_list'] = $todo_list ;
// get all reject
$rejected_list = [] ;
$select_rejected = $mysqli->query( "SELECT * FROM task_rejected
WHERE deleted_at IS NULL AND task_id = '".$array['task_id']."'" ) ;
if ( $select_rejected->num_rows > 0 ){
while ( $row_rejected = $select_rejected->fetch_assoc() ){
$rejected_list[] = [
'id' => $row_rejected['reject_id'],
'title' => dataFilter( $row_rejected['remark'] ),
'staff_name' => $staff_list[ $row_rejected['staff_id'] ],
'created_at' => $row_rejected['created_at']
] ;
}
}
$row['rejected_list'] = $rejected_list ;
// get all media
$select_media = $mysqli->query( "SELECT media_id, file, filetype FROM task_media
WHERE deleted_at IS NULL AND task_id = '".$array['task_id']."' AND todo_id = '".$array['todo_id']."'" ) ;
$photos = [] ;
$attachments = [] ;
if ( $select_media->num_rows > 0 ){
while ( $row_media = $select_media->fetch_assoc() ){
switch ( $row_media['filetype'] ){
case 'jpg' :
case 'jpeg' :
case 'png' :
$photos[] = [
'media_id' => $row_media['media_id'],
'type' => 'online',
'filetype' => $row_media['filetype'],
'file' => ( $row_media['file'] != '' ? PATH.'uploads/Task/b/'.$row_media['file'] : '' )
] ;
break ;
default :
$attachments[] = [
'media_id' => $row_media['media_id'],
'type' => 'online',
'filetype' => $row_media['filetype'],
'file' => ( $row_media['file'] != '' ? PATH.'uploads/Task/'.$row_media['file'] : '' )
] ;
}
}
}
$row['photos'] = $photos ;
$row['attachments'] = $attachments ;
// check update permission
// check cancel permission
switch ( $row['status'] ){
case 'pending' :
case 'assigned' :
case 'resubmit' :
case 'progress' :
case 'completed' :
case 'confirmed' :
if ( $row['created_by'] == $staff_info['staff_id'] ){
$isupdate = 'yes' ;
$iscancel = 'yes' ;
}
break ;
}
$row['isupdate'] = $isupdate ;
$row['iscancel'] = $iscancel ;
// check reject permission
switch ( $row['status'] ){
case 'pending' :
case 'assigned' :
case 'resubmit' :
case 'progress' :
case 'completed' :
if ( $row['assigned_by'] == $staff_info['staff_id'] ){
$isreject = 'yes' ;
}
break ;
case 'confirmed' :
if ( $row['created_by'] == $staff_info['staff_id'] ){
$isreject = 'yes' ;
}
break ;
}
$row['isreject'] = $isreject ;
// check assign permission
if ( $staff_info['staff_tier_is_task_assigned'] == 'yes' ){
$isassigned = 'yes' ;
}
$row['isassigned'] = $isassigned ;
$data = $row ;
}
}
require( $require_sub.'footer.php' ) ;
?>
+81
View File
@@ -0,0 +1,81 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$todo_list = $array['todo_list'] ;
if ( $task_id != '' && count( $todo_list ) > 0 ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' 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 ) ) AND a.status IN ( 'pending', 'assigned', 'resubmit', 'progress', 'completed' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '202' ;
$row = $select->fetch_assoc() ;
$count_todo_list = 0 ;
$count_todo_done = 0 ;
if ( checkExists($array['todo_list']) ){
foreach ( $array['todo_list'] as $k => $v ){
if ( $v['is_delete'] == 'no' ){
$count_todo_list++ ;
if ( $v['is_done'] == 'yes' ){
$count_todo_done++ ;
}
}
}
}
if ( checkExists($array['todo_list']) ){
foreach ( $array['todo_list'] as $k => $v ){
if ( $v['is_done'] == 'yes' ){
$mysqli->query( "UPDATE task_todo SET
is_done = 'yes',
done_by = '".$staff_info['staff_id']."',
done_at = '".TODAYDATE."'
WHERE todo_id = '".$v['id']."' AND is_done = 'no'" ) ;
}
}
}
$update_status = 'pending' ;
if ( $row['assigned_by'] > 0 ){
$update_status = 'assigned' ;
}
if ( $count_todo_done > 0 ){
$update_status = 'progress' ;
}
if ( $count_todo_list == $count_todo_done ){
$update_status = 'completed' ;
}
if ( $mysqli->query( "UPDATE task SET
status = '".$update_status."',
todo_done = '".$count_todo_done."'
WHERE task_id = '".$task_id."'" ) ) {
$status = '200' ;
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Todo', 'Task ( '.$row['task_so'].' ) todo has been updated' ) ;
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+176
View File
@@ -0,0 +1,176 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '303' ;
$boolean_permission = false ;
if ( $staff_info['staff_tier_is_task'] == 'yes' ){
$boolean_permission = true ;
}
if ( $boolean_permission ){
$status = '300' ;
$push_staffid = [] ;
$is_updated = false ;
$task_id = $array['task_id'] ;
$joinstaffs = ( checkExists( $array['joinstaffs'] ) ? $array['joinstaffs'] : [] ) ;
if ( $array['task_type'] != '' && $array['title'] != '' && $array['difficulty'] != '' && $array['department_id'] != '' && $array['date_start'] != '' && $array['date_end'] != '' ){
$status = '260' ;
if ( $array['assigned_by'] > 0 || count( $joinstaffs ) > 0 ){
$status = '303' ;
$staff_tier = [] ;
$staff_tier = getRelatedTierID( 'no', $staff_info['staff_tier_level'] ) ;
$related_staffs = [] ;
if ( $array['assigned_by'] > 0 ){
$related_staffs[$array['assigned_by']] = $array['assigned_by'] ;
}
if ( count( $joinstaffs ) > 0 ){
foreach ( $joinstaffs as $k => $v ){
$related_staffs[$v['id']] = $v['id'] ;
}
}
$select_staff = $mysqli->query( "SELECT a.staff_id, a.staff_idno, a.staff_name, a.staff_shortname, a.staff_tier FROM staff a
WHERE a.deleted_at IS NULL AND ( a.staff_date_resigned >= '".date("Y-m-d",time())."' OR a.staff_date_resigned = '0000-00-00' OR a.staff_date_resigned IS NULL ) AND staff_id IN ( '".implode("', '", $related_staffs)."' ) AND staff_tier IN ( '".implode("', '", $staff_tier)."' )" ) ;
if ( $select_staff->num_rows == count( $related_staffs ) ){
$status = '201' ;
$count_todo_list = 0 ;
$count_todo_done = 0 ;
if ( checkExists($array['todo_list']) ){
if ( count($array['todo_list']) > 0 ){
foreach ( $array['todo_list'] as $k => $v ){
if ( $v['is_delete'] == 'no' ){
$count_todo_list++ ;
if ( $v['is_done'] == 'yes' ){
$count_todo_done++ ;
}
}
}
}
}
// check update status
$task_status = 'pending' ;
if ( $array['assigned_by'] > 0 && count( $joinstaffs ) > 0 ){
$task_status = 'assigned' ;
}
// check if task id exsits
$boolean_submit = false ;
if ( $task_id > 0 ){
$select = $mysqli->query( "SELECT * FROM task
WHERE deleted_at IS NULL AND task_id = '".$task_id."' AND created_by = '".$staff_info['staff_id']."' AND status IN ( 'pending', 'assigned', 'resubmit', 'progress', 'completed', 'confirmed' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '202' ;
$row = $select->fetch_assoc() ;
if ( $mysqli->query( "UPDATE task SET
task_type = '".$array['task_type']."',
title = '".$array['title']."',
department_id = '".$array['department_id']."',
assigned_by = '".$array['assigned_by']."',
difficulty = '".$array['difficulty']."',
date_start = '".$array['date_start']."',
date_end = '".$array['date_end']."',
remark = '".$array['remark']."',
incentive = '".$array['incentive']."',
todo_list = '".$count_todo_list."',
todo_done = '".$count_todo_done."'
WHERE task_id = '".$task_id."'" ) ) {
$boolean_submit = true ;
$is_updated = true ;
$push_staffid[$array['assigned_by']] = $array['assigned_by'] ;
}
}
}else{
$status = '203' ;
if ( $mysqli->query( "INSERT INTO task
( `task_type`, `title`, `department_id`, `created_branch_id`, `created_by`, `assigned_by`, `difficulty`, `date_start`, `date_end`, `remark`, `incentive`, `todo_list`, `todo_done`, `status` ) VALUES
( '".$array['task_type']."', '".$array['title']."', '".$array['department_id']."', '".$array['branch_id']."', '".$staff_info['staff_id']."', '".$array['assigned_by']."', '".$array['difficulty']."', '".$array['date_start']."', '".$array['date_end']."', '".$array['remark']."', '".$array['incentive']."', '".$count_todo_list."', '".$count_todo_done."', '".$task_status."' )" ) ){
$boolean_submit = true ;
$task_id = $mysqli->insert_id ;
$task_so = 'PT'.strPad( 6, $task_id ) ;
$mysqli->query( "UPDATE task SET
task_so = '".$task_so."'
WHERE task_id = '".$task_id."'" ) ;
$push_staffid[$staff_info['staff_id']] = $staff_info['staff_id'] ;
$push_staffid[$array['assigned_by']] = $array['assigned_by'] ;
}
}
if ( $boolean_submit ){
$status = '203' ;
// deleted all related staff
$mysqli->query( "DELETE FROM `task_joinstaff` WHERE task_id = '".$task_id."'" ) ;
if ( checkExists($joinstaffs) ){
foreach ( $joinstaffs as $k => $v ){
$mysqli->query( "INSERT INTO `task_joinstaff` ( `task_id`, `staff_id` ) VALUES ( '".$task_id."', '".$v['id']."' )" ) ;
$push_staffid[$v['id']] = $v['id'] ;
}
}
if ( checkExists($array['todo_list']) ){
if ( count($array['todo_list']) > 0 ){
foreach ( $array['todo_list'] as $k => $v ){
if ( $v['is_delete'] == 'no' ){
if ( $v['id'] > 0 ){
$mysqli->query( "UPDATE task_todo SET title = '".$v['title']."' WHERE todo_id = '".$v['id']."'" ) ;
}else{
$mysqli->query( "INSERT INTO task_todo ( `task_id`, `title`, `sortable` ) VALUES ( '".$task_id."', '".$v['title']."', '9999' )" ) ;
}
}else{
if ( $v['id'] > 0 ){
$mysqli->query( "UPDATE task_todo SET deleted_at = '".TODAYDATE."' WHERE todo_id = '".$v['id']."'" ) ;
}
}
}
}
}
$status = '200' ;
// push to notification
foreach ( $push_staffid as $k => $v ){
if ( $is_updated ){
pushToUserCron( 'task', $task_id, $v, 'Task Updated', 'Task ( '.$row['task_so'].' ) has been updated' ) ;
}else{
pushToUserCron( 'task', $task_id, $v, 'Task Created', 'New task ( '.$task_so.' ) appoint to you' ) ;
}
}
}
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>
+68
View File
@@ -0,0 +1,68 @@
<?php
$must_login = true ;
$require_path = '../../../' ;
$require_sub = '../../' ;
require( $require_sub.'header.php' ) ;
if ( $boolean_login ){
$status = '300' ;
$task_id = $array['task_id'] ;
$todo_id = $array['todo_id'] ;
$photos = $array['photos'] ;
$attachments = $array['attachments'] ;
if ( $task_id != '' && $todo_id != '' && ( count( $photos ) > 0 || count( $attachments ) > 0 ) ){
$status = '201' ;
$select = $mysqli->query( "SELECT * FROM task a
WHERE a.deleted_at IS NULL AND a.task_id = '".$task_id."' 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 ) ) AND a.status IN ( 'pending', 'assigned', 'resubmit', 'progress', 'completed', 'confirmed' ) LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '201' ;
$row = $select->fetch_assoc() ;
$select = $mysqli->query( "SELECT * FROM task_todo
WHERE deleted_at IS NULL AND task_id = '".$task_id."' AND todo_id = '".$todo_id."' LIMIT 1" ) ;
if ( $select->num_rows > 0 ){
$status = '205' ;
$row_todo = $select->fetch_assoc() ;
if ( checkExists($photos) || checkExists($attachments) ){
foreach ( [ $photos, $attachments ] as $upload_key => $upload_value ){
foreach ( $upload_value as $k => $v ){
if ( $v['type'] == 'local' ){
$file_upload = ( $v['file'] ) ;
$upload = uploadImage( 'Task', $task_id.'-'.$todo_id, $file_upload ) ;
if ( $upload['status'] != '200' ){
$count_upload++ ;
}else{
$mysqli->query( "INSERT INTO task_media
( task_id, todo_id, file, filetype ) VALUES
( '".$task_id."', '".$todo_id."', '".$upload['data']['file_name']."', '".$upload['data']['file_type']."' )" ) ;
$status = '200' ;
}
}
}
}
if ( $status == '200' ){
// push to notification
$related_staffid = getTaskRelatedStaff( $task_id, $row['created_by'], $row['assigned_by'] ) ;
foreach ( $related_staffid as $k => $v ){
pushToUserCron( 'task', $task_id, $v, 'Task Uploaded', 'Task ( '.$row['task_so'].' ) file uploaded' ) ;
}
}
}
}
}
}
}
require( $require_sub.'footer.php' ) ;
?>