/
view_presence_by_unit.php
134 lines (96 loc) · 3.34 KB
/
view_presence_by_unit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
require_once("inc/config.php");
check_role($ROLE_LEADER);
function dates_inbetween($date1, $date2) {
$day = 60 * 60 * 24;
$date1 = strtotime($date1);
$date2 = strtotime($date2);
$days_diff = round(($date2 - $date1) / $day); // Unix time difference devided by 1 day to get total days in between
$dates_array = array();
$dates_array[] = date('Y-m-d', $date1);
for ($x = 1; $x < $days_diff; $x++) {
$dates_array[] = date('Y-m-d', ($date1 + ($day * $x)));
}
$dates_array[] = date('Y-m-d', $date2);
return $dates_array;
}
// Usage
$dates_array = dates_inbetween('2011-01-01', '2011-01-31');
for ($x=1;$x<13;$x++) {
//gremo cez vse mesce ///
$from_date = "2011-".$x."-01";
$to_date = "2011-".$x."-".date("t",strtotime($from_date));
$dates_array = dates_inbetween($from_date, $to_date);
$prazniki = array('2011-01-01', '2011-01-02', '2011-02-08', '2011-04-24', '2011-04-25', '2011-04-27', '2011-05-01', '2011-05-02', '2011-06-25', '2011-08-15', '2011-10-31', '2011-11-01', '2011-12-25', '2011-12-26');
$number_days=0;
unset($percentage_month);
$percentage_month=array();
foreach ($dates_array as $date) {
$weekday = date('l', strtotime($date)); // note: first arg to date() is lower-case L
$weekdaynum = date('w', strtotime($date));
if (($weekdaynum > 0) && ($weekdaynum < 6)) {
$free_day = FALSE;
foreach ($prazniki as $praznik) {
if ($praznik == $date) {
$free_day = $praznik;
$continue;
}
}
if ($free_day) {
//echo $date ." = " .$free_day."<br>"; // praznik//
continue; //za ta datum in gremo na novga//
} else {
//gledama za ta dan//
$number_days++;
$q = new DAL();
$q2 = new DAL();
unset($res_work);
$res_work = $q->get_count_persons_available_by_date($date);
//if ($x==12) print_r($res_work);
//var_dump($res_work);
//die()
foreach ($res_work as $work_c) {
$unit_id = $work_c["unit_id"];
$stevilo = $work_c["stevilo"];
//if ($unit_id==77 and $x==12) echo $date." ".$stevilo." ---- ".print_r($work_c)."<br><br><hr>";
$work_count[$date][$unit_id]=$stevilo;
//echo $stevilo." - u:". $unit_id." $date <br>";
}
unset($res_full);
$res_full = $q2->get_count_persons_registered_by_unit($date);
//if ($x==12 ) print_r($res_full);
// var_dump($res_full);
foreach ($res_full as $all) {
$unit_id = $all["unit_id"];
$stevilo = $all["stevilo"];
$all_sum[$unit_id]=$stevilo;
if ($work_count[$date][$unit_id]==0) continue;
//echo $stevilo." ALL -".$unit_id."<br>";
//if ($unit_id==77 and $x==12) echo "dodal bom v percentage month:". $work_count[$date][$unit_id]/$all_sum[$unit_id]. " ( ".$work_count[$unit_id]." / ". $all_sum[$unit_id].") $date <br>";
$percentage_month[$unit_id]+=$work_count[$date][$unit_id]/$all_sum[$unit_id];
//echo "noter";
}
}
}
}
///print out report///
//print_r($percentage_month);
//die();
foreach ($percentage_month as $key => $percent) {
//echo $key." - value ".$percent."/".$number_days." =====";
$end_result[$key][$x]=$percent*100/$number_days;
}
}
foreach ($end_result as $key => $value ) {
if ($key == 0) continue;
echo "$key;";
$sum ='';
for ($x=1;$x<13;$x++) {
echo $value[$x].";";
$sum += $value[$x];
}
$sum= $sum/12;
//rtrim($out,";");
echo $sum."\n";
}
?>