-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattendance.php
169 lines (152 loc) · 5.31 KB
/
attendance.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php include('db_connect.php') ?>
<div class="container-fluid " >
<div class="col-lg-12">
<br />
<br />
<div class="card">
<div class="card-header">
<span><b>Attendance List</b></span>
<button class="btn btn-primary btn-sm btn-block col-md-3 float-right" type="button" id="new_attendance_btn"><span class="fa fa-plus"></span> Add Attendance</button>
</div>
<div class="card-body">
<table id="table" class="table table-bordered table-striped">
<colgroup>
<col width="10%">
<col width="20%">
<col width="30%">
<col width="30%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Date</th>
<th>Employee No</th>
<th>Name</th>
<th>Time Record</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$att=$conn->query("SELECT a.*,e.employee_no, concat(e.lastname,', ',e.firstname,' ',e.middlename) as ename FROM attendance a inner join employee e on a.employee_id = e.id order by UNIX_TIMESTAMP(datetime_log) asc ") or die(mysqli_error());
$lt_arr = array(1 => " Time-in AM",2=>"Time-out AM",3 => " Time-in PM",4=>"Time-out PM");
while($row=$att->fetch_array()){
$date = date("Y-m-d",strtotime($row['datetime_log']));
$attendance[$row['employee_id']."_".$date]['details'] = array("eid"=>$row['employee_id'],"name"=>$row['ename'],"eno"=>$row['employee_no'],"date"=>$date);
if($row['log_type'] == 1 || $row['log_type'] == 3){
if(!isset($attendance[$row['employee_id']."_".$date]['log'][$row['log_type']]))
$attendance[$row['employee_id']."_".$date]['log'][$row['log_type']] = array('id'=>$row['id'],"date" => $row['datetime_log']);
}else{
$attendance[$row['employee_id']."_".$date]['log'][$row['log_type']] =array('id'=>$row['id'],"date" => $row['datetime_log']);
}
}
foreach ($attendance as $key => $value) {
?>
<tr>
<td><?php echo date("M d,Y",strtotime($attendance[$key]['details']['date'])) ?></td>
<td><?php echo $attendance[$key]['details']['eno'] ?></td>
<td><?php echo $attendance[$key]['details']['name'] ?></td>
<td>
<div class="row">
<?php
$att_ids = array();
foreach($attendance[$key]['log'] as $k => $v) :
?>
<div class="col-sm-6" style="">
<p>
<small><b><?php echo $lt_arr[$k].": <br/>" ?>
<?php echo (date("h:i A",strtotime($attendance[$key]['log'][$k]['date']))) ?> </b>
<span class="badge badge-danger rem_att" data-id="<?php echo $attendance[$key]['log'][$k]['id'] ?>"><i class="fa fa-trash"></i></span>
</small>
</p>
</div>
<?php endforeach; ?>
</div>
</td>
<td>
<center>
<button class="btn btn-sm btn-outline-danger remove_attendance" data-id="<?php echo $key ?>" type="button"><i class="fa fa-trash"></i></button>
</center>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<style>
td p{
margin: unset;
}
.rem_att{
cursor: pointer;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('#table').DataTable();
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$('.edit_attendance').click(function(){
var $id=$(this).attr('data-id');
uni_modal("Edit Employee","manage_attendance.php?id="+$id)
});
$('.view_attendance').click(function(){
var $id=$(this).attr('data-id');
uni_modal("Employee Details","view_attendance.php?id="+$id,"mid-large")
});
$('#new_attendance_btn').click(function(){
uni_modal("New Time Record/s","manage_attendance.php",'mid-large')
})
$('.remove_attendance').click(function(){
var d = '"'+($(this).attr('data-id')).toString()+'"';
_conf("Are you sure to delete this employee's time log record?","remove_attendance",[d])
})
$('.rem_att').click(function(){
var $id=$(this).attr('data-id');
_conf("Are you sure to delete this time log?","rem_att",[$id])
})
});
function remove_attendance(id){
// console.log(id)
// return false;
start_load()
$.ajax({
url:'ajax.php?action=delete_employee_attendance',
method:"POST",
data:{id:id},
error:err=>console.log(err),
success:function(resp){
if(resp == 1){
alert_toast("Selected employee's time log data successfully deleted","success");
setTimeout(function(){
location.reload();
},1000)
}
}
})
}
function rem_att(id){
start_load()
$.ajax({
url:'ajax.php?action=delete_employee_attendance_single',
method:"POST",
data:{id:id},
error:err=>console.log(err),
success:function(resp){
if(resp == 1){
alert_toast("Selected employee's time log data successfully deleted","success");
setTimeout(function(){
location.reload();
},1000)
}
}
})
}
</script>