Here i am doing task allocation per employee wise, almost i completed i have to do Hours calculation in project wise
<?php
include("dbconfig.php");
include("functions.php");
$sql = "SELECT DISTINCT date_add(date(d_started_on), interval i day) as allocation_date,t_project,t_assign_to,t_start_time,t_end_time FROM ( SELECT date(STR_TO_DATE(t_started_on, '%Y-%m-%d')) as d_started_on, datediff( date(STR_TO_DATE(t_due_on, '%Y-%m-%d')), date(STR_TO_DATE(t_started_on, '%Y-%m-%d')) ) as days,t_project,t_assign_to,t_start_time,t_end_time FROM task ) as base INNER JOIN nums ON i <= days ORDER BY 1";
$mysql = mysql_query($sql);
$productsArray = array();
while($rowRes = mysql_fetch_assoc($mysql)){
$rowRes['allocated_day'] = $rowRes['allocation_date'];
$productsArray[] = $rowRes;
}
$project_name = array();
foreach($productsArray as $key0 => $info) {
$key1 = $info['t_assign_to'];
$key2 = $info['t_project'];
$key3 = $info['allocated_day'];
$project_name[$key1][$key2][$key3] = $info['t_start_time'].' '.$info['t_end_time'];
}
print_r($project_name);
?>
OUTPUT
Array
(
[G2E0357] => Array
(
[10001] => Array
(
[2018-01-01] => 01:30 PM 11:30 AM
[2018-01-02] => 01:30 PM 11:30 AM
[2018-01-03] => 01:30 PM 11:30 AM
)
[10008] => Array
(
[2018-01-25] => 10:30 AM 01:30 PM
[2018-01-26] => 10:30 AM 01:30 PM
[2018-01-27] => 10:30 AM 01:30 PM
)
)
[XPL0315] => Array
(
[10008] => Array
(
[2018-01-18] => 11:30 AM 07:30 PM
[2018-01-19] => 11:30 AM 07:30 PM
[2018-01-20] => 11:30 AM 07:30 PM
)
)
)
- G2E0357 and XPL0315 these are employee id's
- 10001 and 10008 these are project id's
- 2018-01-01(project start date ) 2018-01-03 (project end date)
- 01:30 PM(start time) 11:30 AM(end time)
Explnation
employee id XPL0315 having one project allocation (10008) .timeline is 2018-01-18
11:30 AM INTO 2018-01-20
07:30 PM,
Instead of displaying t_start_time and t_end_time. i have to calculate per day how many Hours employee has to work
My Office timing is 9.30 AM into 7.30 PM (Totally 10 Hrs)
employee id XPL0315 and project id 10008 having 3 days allocation but working hours it will be different based allocation ,because
- 2018-01-18 date he is going to start 11.30 PM(7 Hrs Only)
- 2018-01-19 employee has to start the work 9.30 AM into 7.30 PM because allocation ending date 2018-01-18 07:30 PM (10 Hrs)
- 2018-01-20 also employee has to start the work 9.30 AM into 7.30 PM because allocation ending date 2018-01-18 07:30 PM (10 Hrs) suppose ending date is 2018-01-20 06:30 PM (9 Hrs)
Expected output should come like this
Array
(
[G2E0357] => Array
(
[10001] => Array
(
[2018-01-01] => 6 Hrs
[2018-01-02] => 10 Hrs
[2018-01-03] => 2 Hrs
)
[10008] => Array
(
[2018-01-25] => 9 Hrs
[2018-01-26] => 10 Hrs
[2018-01-27] => 4 Hrs
)
)
[XPL0315] => Array
(
[10008] => Array
(
[2018-01-18] => 7 Hrs
[2018-01-19] => 10 Hrs
[2018-01-20] => 10 Hrs
)
)
)
I think we have to take first index and last index,
- first index means we have to take t_start_time and do the calculation
- last index means we have to take t_end_time and do the calculation