| 36645 |
vikas |
1 |
<script>
|
|
|
2 |
if (!window.google || !window.google.maps) {
|
|
|
3 |
var s = document.createElement('script');
|
| 36693 |
vikas |
4 |
s.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyAckO0y4Z6WhBOuMjNjioWLSYZDhGEvGBc&libraries=geometry&v=weekly';
|
| 36645 |
vikas |
5 |
document.head.appendChild(s);
|
|
|
6 |
}
|
|
|
7 |
</script>
|
|
|
8 |
|
|
|
9 |
<div class="col-lg-12">
|
|
|
10 |
<table class="table table-border table-condensed table-bordered" id="beatReportTable" style="width:100%">
|
|
|
11 |
<thead>
|
|
|
12 |
<tr>
|
|
|
13 |
<th>User Name</th>
|
| 36693 |
vikas |
14 |
<th>Punch In</th>
|
|
|
15 |
<th>Punch Out</th>
|
| 36645 |
vikas |
16 |
<th>Total Visits</th>
|
|
|
17 |
<th>Completed Visits</th>
|
|
|
18 |
<th>Pending Visits</th>
|
|
|
19 |
<th>Deferred</th>
|
| 36693 |
vikas |
20 |
<th>Battery</th>
|
|
|
21 |
<th>Map</th>
|
| 36645 |
vikas |
22 |
</tr>
|
|
|
23 |
</thead>
|
|
|
24 |
<tbody>
|
|
|
25 |
#set($rowIndex = 0)
|
|
|
26 |
#foreach($row in $reportRows)
|
|
|
27 |
<tr>
|
|
|
28 |
<td><a href="javascript:void(0);" class="beat-user-detail-link" data-userid="$row.get('userId')" style="color:#2c3e50; font-weight:bold; text-decoration:underline; cursor:pointer;">$row.get("username")</a></td>
|
| 36693 |
vikas |
29 |
<td>#if($row.get("punchInTime") != "")<span class="label label-success">$row.get("punchInTime")</span>#else<span style="color:#ccc;">--</span>#end</td>
|
|
|
30 |
<td>#if($row.get("punchOutTime") != "")<span class="label label-danger">$row.get("punchOutTime")</span>#else<span style="color:#ccc;">--</span>#end</td>
|
| 36645 |
vikas |
31 |
<td><a href="javascript:void(0);" class="beat-detail-link" data-row="$rowIndex" data-type="total" style="color:#1abc9c; font-weight:bold; text-decoration:underline; cursor:pointer;">$row.get("total")</a></td>
|
|
|
32 |
<td><a href="javascript:void(0);" class="beat-detail-link" data-row="$rowIndex" data-type="completed" style="color:#1abc9c; font-weight:bold; text-decoration:underline; cursor:pointer;">$row.get("completed")</a></td>
|
|
|
33 |
<td><a href="javascript:void(0);" class="beat-detail-link" data-row="$rowIndex" data-type="pending" style="color:#e67e22; font-weight:bold; text-decoration:underline; cursor:pointer;">$row.get("pending")</a></td>
|
|
|
34 |
<td><a href="javascript:void(0);" class="beat-detail-link" data-row="$rowIndex" data-type="deferred" style="color:#e74c3c; font-weight:bold; text-decoration:underline; cursor:pointer;">$row.get("deferred")</a></td>
|
| 36693 |
vikas |
35 |
<td>#if($row.get("batteryLevel"))$row.get("batteryLevel")%#else<span style="color:#ccc;">--</span>#end</td>
|
| 36645 |
vikas |
36 |
<td><a href="javascript:void(0);" class="beat-map-link" data-row="$rowIndex" style="cursor:pointer;"><i class="fa fa-map-marker" style="color:#1abc9c; font-size:18px;"></i></a></td>
|
|
|
37 |
</tr>
|
|
|
38 |
|
|
|
39 |
<script>
|
|
|
40 |
window.beatReportData = window.beatReportData || {};
|
|
|
41 |
window.beatReportData[$rowIndex] = {
|
|
|
42 |
username: "$row.get('username').replace('"', '\"')",
|
|
|
43 |
total: [
|
|
|
44 |
#foreach($lt in $row.get("totalList"))
|
|
|
45 |
{ taskName: "$!lt.getTaskName().replace('"', '\"')", markType: "$!lt.getMarkType()", address: "$!lt.getAddress().replace('"', '\"').replace("'", "\'")", checkInTime: "$!lt.getCheckInTime()", checkOutTime: "$!lt.getCheckOutTime()", timeSpent: "$!lt.getTimeSpent()", taskType: "$!lt.getTaskType()", visitLocation: "$!lt.getVisitLocation()", checkInLatLng: "$!lt.getCheckInLatLng()", taskDescription: "$!lt.getTaskDescription().replace('"', '\"')", attachment: "$!lt.getAttachment()" },
|
|
|
46 |
#end
|
|
|
47 |
],
|
|
|
48 |
completed: [
|
|
|
49 |
#foreach($lt in $row.get("completedList"))
|
|
|
50 |
{ taskName: "$!lt.getTaskName().replace('"', '\"')", markType: "$!lt.getMarkType()", address: "$!lt.getAddress().replace('"', '\"').replace("'", "\'")", checkInTime: "$!lt.getCheckInTime()", checkOutTime: "$!lt.getCheckOutTime()", timeSpent: "$!lt.getTimeSpent()", taskType: "$!lt.getTaskType()", visitLocation: "$!lt.getVisitLocation()", checkInLatLng: "$!lt.getCheckInLatLng()", taskDescription: "$!lt.getTaskDescription().replace('"', '\"')", attachment: "$!lt.getAttachment()" },
|
|
|
51 |
#end
|
|
|
52 |
],
|
|
|
53 |
pending: [
|
|
|
54 |
#foreach($lt in $row.get("pendingList"))
|
|
|
55 |
{ taskName: "$!lt.getTaskName().replace('"', '\"')", markType: "$!lt.getMarkType()", address: "$!lt.getAddress().replace('"', '\"').replace("'", "\'")", checkInTime: "$!lt.getCheckInTime()", checkOutTime: "$!lt.getCheckOutTime()", timeSpent: "$!lt.getTimeSpent()", taskType: "$!lt.getTaskType()", visitLocation: "$!lt.getVisitLocation()", checkInLatLng: "$!lt.getCheckInLatLng()", taskDescription: "$!lt.getTaskDescription().replace('"', '\"')", attachment: "$!lt.getAttachment()" },
|
|
|
56 |
#end
|
|
|
57 |
],
|
|
|
58 |
deferred: [
|
|
|
59 |
#foreach($lt in $row.get("deferredList"))
|
|
|
60 |
{ taskName: "$!lt.getTaskName().replace('"', '\"')", markType: "$!lt.getMarkType()", address: "$!lt.getAddress().replace('"', '\"').replace("'", "\'")", checkInTime: "$!lt.getCheckInTime()", checkOutTime: "$!lt.getCheckOutTime()", timeSpent: "$!lt.getTimeSpent()", taskType: "$!lt.getTaskType()", visitLocation: "$!lt.getVisitLocation()", checkInLatLng: "$!lt.getCheckInLatLng()", taskDescription: "$!lt.getTaskDescription().replace('"', '\"')", attachment: "$!lt.getAttachment()" },
|
|
|
61 |
#end
|
|
|
62 |
]
|
|
|
63 |
};
|
|
|
64 |
</script>
|
|
|
65 |
#set($rowIndex = $rowIndex + 1)
|
|
|
66 |
#end
|
|
|
67 |
</tbody>
|
|
|
68 |
</table>
|
|
|
69 |
</div>
|
|
|
70 |
|
|
|
71 |
<!-- Map Modal -->
|
|
|
72 |
<div class="modal fade" id="beatMapModal" tabindex="-1" role="dialog">
|
|
|
73 |
<div class="modal-dialog modal-lg" role="document" style="width:90%;">
|
|
|
74 |
<div class="modal-content">
|
|
|
75 |
<div class="modal-header" style="background:#1abc9c; color:white;">
|
|
|
76 |
<button type="button" class="close" data-dismiss="modal" style="color:white;">×</button>
|
|
|
77 |
<h4 class="modal-title" id="beatMapModalTitle">Visit Locations</h4>
|
|
|
78 |
</div>
|
|
|
79 |
<div class="modal-body" style="padding:0;">
|
|
|
80 |
<div id="beatMapContainer" style="height:500px; width:100%;"></div>
|
|
|
81 |
<div id="beatMapInfo" style="padding:6px 15px; background:#fff3cd; border-top:1px solid #ddd; color:#856404; display:none;"></div>
|
|
|
82 |
<div style="padding:8px 15px; background:#f5f5f5; border-top:1px solid #ddd;">
|
|
|
83 |
<span style="margin-right:15px;"><i class="fa fa-circle" style="color:#4285F4;"></i> Check In</span>
|
|
|
84 |
<span style="margin-right:15px;"><i class="fa fa-circle" style="color:#0F9D58;"></i> Completed</span>
|
|
|
85 |
<span style="margin-right:15px;"><i class="fa fa-circle" style="color:#F4B400;"></i> Pending</span>
|
|
|
86 |
<span><i class="fa fa-circle" style="color:#DB4437;"></i> Deferred</span>
|
|
|
87 |
</div>
|
|
|
88 |
</div>
|
|
|
89 |
<div class="modal-footer">
|
|
|
90 |
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
|
|
91 |
</div>
|
|
|
92 |
</div>
|
|
|
93 |
</div>
|
|
|
94 |
</div>
|
|
|
95 |
|
|
|
96 |
<!-- Detail Popup Modal -->
|
|
|
97 |
<div class="modal fade" id="beatDetailModal" tabindex="-1" role="dialog">
|
|
|
98 |
<div class="modal-dialog modal-lg" role="document">
|
|
|
99 |
<div class="modal-content">
|
|
|
100 |
<div class="modal-header" style="background:#1abc9c; color:white;">
|
|
|
101 |
<button type="button" class="close" data-dismiss="modal" style="color:white;">×</button>
|
|
|
102 |
<h4 class="modal-title" id="beatDetailModalTitle">Visit Details</h4>
|
|
|
103 |
</div>
|
|
|
104 |
<div class="modal-body">
|
|
|
105 |
<table class="table table-bordered table-condensed table-striped" id="beatDetailTable" style="width:100%">
|
|
|
106 |
<thead>
|
|
|
107 |
<tr>
|
|
|
108 |
<th>#</th>
|
| 36669 |
vikas |
109 |
<th>Agenda/Partner Name</th>
|
| 36645 |
vikas |
110 |
<th>Type</th>
|
|
|
111 |
<th>Status</th>
|
|
|
112 |
<th>Address</th>
|
|
|
113 |
<th>Check In</th>
|
|
|
114 |
<th>Check Out</th>
|
|
|
115 |
<th>Time Spent</th>
|
|
|
116 |
<th>Description</th>
|
| 36666 |
vikas |
117 |
<th>Extimated Time</th>
|
| 36645 |
vikas |
118 |
<th>Attachment</th>
|
|
|
119 |
</tr>
|
|
|
120 |
</thead>
|
|
|
121 |
<tbody id="beatDetailTableBody"></tbody>
|
|
|
122 |
</table>
|
|
|
123 |
</div>
|
|
|
124 |
<div class="modal-footer">
|
|
|
125 |
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
|
|
126 |
</div>
|
|
|
127 |
</div>
|
|
|
128 |
</div>
|
|
|
129 |
</div>
|
|
|
130 |
|
|
|
131 |
<script>
|
|
|
132 |
$('#beatReportTable').DataTable({
|
|
|
133 |
"scrollX": true,
|
| 36685 |
vikas |
134 |
"pageLength": 50,
|
| 36645 |
vikas |
135 |
"bPaginate": true,
|
|
|
136 |
"bLengthChange": true,
|
|
|
137 |
"bFilter": true,
|
|
|
138 |
"bInfo": true,
|
|
|
139 |
"bAutoWidth": false
|
|
|
140 |
});
|
|
|
141 |
|
|
|
142 |
var beatMapMarkerColors = {
|
|
|
143 |
'PENDING': '#F4B400',
|
|
|
144 |
'DEFERRED': '#DB4437',
|
|
|
145 |
'CHECKIN': '#4285F4',
|
|
|
146 |
'CHECKIN-CHECKOUT': '#0F9D58',
|
|
|
147 |
'CHECKOUT': '#0F9D58'
|
|
|
148 |
};
|
|
|
149 |
|
|
|
150 |
function getMarkerColor(markType) {
|
|
|
151 |
return beatMapMarkerColors[markType] || '#999999';
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
function createColoredMarkerIcon(color, label) {
|
|
|
155 |
var svg = '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="42" viewBox="0 0 32 42">' +
|
|
|
156 |
'<path d="M16 0C7.2 0 0 7.2 0 16c0 12 16 26 16 26s16-14 16-26C32 7.2 24.8 0 16 0z" fill="' + color + '"/>' +
|
|
|
157 |
'<circle cx="16" cy="15" r="10" fill="white"/>' +
|
|
|
158 |
'<text x="16" y="20" text-anchor="middle" font-size="12" font-weight="bold" fill="' + color + '">' + label + '</text>' +
|
|
|
159 |
'</svg>';
|
|
|
160 |
return 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
function getLatLng(item) {
|
|
|
164 |
var loc = item.visitLocation || item.checkInLatLng || '';
|
|
|
165 |
if (!loc || loc === '0.0000,0.0000') return null;
|
|
|
166 |
var parts = loc.split(',');
|
|
|
167 |
if (parts.length !== 2) return null;
|
|
|
168 |
var lat = parseFloat(parts[0].trim());
|
|
|
169 |
var lng = parseFloat(parts[1].trim());
|
|
|
170 |
if (isNaN(lat) || isNaN(lng) || (lat === 0 && lng === 0)) return null;
|
|
|
171 |
return { lat: lat, lng: lng };
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
$(document).on('click', '.beat-map-link', function () {
|
|
|
175 |
var rowIndex = $(this).data('row');
|
|
|
176 |
var data = window.beatReportData[rowIndex];
|
|
|
177 |
if (!data) return;
|
|
|
178 |
|
|
|
179 |
var items = data.total || [];
|
|
|
180 |
var username = data.username;
|
|
|
181 |
$('#beatMapModalTitle').text(username + ' - Visit Locations (' + items.length + ')');
|
|
|
182 |
|
|
|
183 |
if (typeof google === 'undefined' || !google.maps) {
|
|
|
184 |
alert('Google Maps is still loading. Please try again in a moment.');
|
|
|
185 |
return;
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
$('#beatMapModal').modal('show');
|
|
|
189 |
|
|
|
190 |
setTimeout(function () {
|
|
|
191 |
var mapDiv = document.getElementById('beatMapContainer');
|
|
|
192 |
var bounds = new google.maps.LatLngBounds();
|
|
|
193 |
var hasMarkers = false;
|
|
|
194 |
|
|
|
195 |
var map = new google.maps.Map(mapDiv, {
|
|
|
196 |
zoom: 10,
|
|
|
197 |
center: { lat: 20.5937, lng: 78.9629 },
|
|
|
198 |
mapTypeId: 'roadmap'
|
|
|
199 |
});
|
|
|
200 |
|
|
|
201 |
var infoWindow = new google.maps.InfoWindow();
|
|
|
202 |
|
|
|
203 |
for (var i = 0; i < items.length; i++) {
|
|
|
204 |
var item = items[i];
|
|
|
205 |
var pos = getLatLng(item);
|
|
|
206 |
if (!pos) continue;
|
|
|
207 |
|
|
|
208 |
hasMarkers = true;
|
|
|
209 |
bounds.extend(pos);
|
|
|
210 |
|
|
|
211 |
var color = getMarkerColor(item.markType);
|
|
|
212 |
var marker = new google.maps.Marker({
|
|
|
213 |
position: pos,
|
|
|
214 |
map: map,
|
|
|
215 |
title: item.taskName || item.markType,
|
|
|
216 |
icon: {
|
|
|
217 |
url: createColoredMarkerIcon(color, (i + 1)),
|
|
|
218 |
scaledSize: new google.maps.Size(32, 42),
|
|
|
219 |
anchor: new google.maps.Point(16, 42)
|
|
|
220 |
}
|
|
|
221 |
});
|
|
|
222 |
|
|
|
223 |
(function (m, itm, idx) {
|
|
|
224 |
google.maps.event.addListener(m, 'click', function () {
|
|
|
225 |
var content = '<div style="min-width:200px;">' +
|
|
|
226 |
'<strong>' + (idx + 1) + '. ' + (itm.taskName || '--') + '</strong><br>' +
|
|
|
227 |
'<b>Status:</b> ' + (itm.markType || '--') + '<br>' +
|
|
|
228 |
'<b>Address:</b> ' + (itm.address || '--') + '<br>' +
|
|
|
229 |
'<b>Check In:</b> ' + (itm.checkInTime || '--') + '<br>' +
|
|
|
230 |
'<b>Check Out:</b> ' + (itm.checkOutTime || '--') + '<br>' +
|
|
|
231 |
'<b>Time Spent:</b> ' + (itm.timeSpent || '--') +
|
|
|
232 |
'</div>';
|
|
|
233 |
infoWindow.setContent(content);
|
|
|
234 |
infoWindow.open(map, m);
|
|
|
235 |
});
|
|
|
236 |
})(marker, item, i);
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
var markerCount = 0;
|
|
|
240 |
for (var j = 0; j < items.length; j++) { if (getLatLng(items[j])) markerCount++; }
|
|
|
241 |
|
|
|
242 |
var infoDiv = document.getElementById('beatMapInfo');
|
|
|
243 |
if (markerCount < items.length) {
|
|
|
244 |
infoDiv.innerHTML = '<i class="fa fa-exclamation-triangle"></i> Showing ' + markerCount + ' of ' + items.length + ' visits on map. ' + (items.length - markerCount) + ' visits have no location data.';
|
|
|
245 |
infoDiv.style.display = 'block';
|
|
|
246 |
} else {
|
|
|
247 |
infoDiv.style.display = 'none';
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
if (hasMarkers) {
|
|
|
251 |
map.fitBounds(bounds);
|
|
|
252 |
if (markerCount === 1) {
|
|
|
253 |
map.setZoom(14);
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
}, 400);
|
|
|
257 |
});
|
|
|
258 |
|
|
|
259 |
$(document).on('click', '.beat-detail-link', function () {
|
|
|
260 |
var rowIndex = $(this).data('row');
|
|
|
261 |
var type = $(this).data('type');
|
|
|
262 |
var data = window.beatReportData[rowIndex];
|
|
|
263 |
if (!data) return;
|
|
|
264 |
|
|
|
265 |
var items = data[type] || [];
|
|
|
266 |
var username = data.username;
|
|
|
267 |
|
|
|
268 |
var typeLabel = type.charAt(0).toUpperCase() + type.slice(1);
|
|
|
269 |
$('#beatDetailModalTitle').text(username + ' - ' + typeLabel + ' Visits (' + items.length + ')');
|
|
|
270 |
|
|
|
271 |
var tbody = '';
|
|
|
272 |
for (var i = 0; i < items.length; i++) {
|
|
|
273 |
var item = items[i];
|
|
|
274 |
tbody += '<tr>' +
|
|
|
275 |
'<td>' + (i + 1) + '</td>' +
|
|
|
276 |
'<td>' + (item.taskName || '--') + '</td>' +
|
|
|
277 |
'<td>' + (item.taskType || '--') + '</td>' +
|
|
|
278 |
'<td>' + (item.markType || '--') + '</td>' +
|
|
|
279 |
'<td>' + (item.address || '--') + '</td>' +
|
|
|
280 |
'<td>' + (item.checkInTime || '--') + '</td>' +
|
|
|
281 |
'<td>' + (item.checkOutTime || '--') + '</td>' +
|
|
|
282 |
'<td>' + (item.timeSpent || '--') + '</td>' +
|
|
|
283 |
'<td>' + (item.taskDescription || '--') + '</td>' +
|
| 36666 |
vikas |
284 |
'<td>' + (item.estimatedTime || '--') + '</td>' +
|
| 36645 |
vikas |
285 |
'<td>' + (item.attachment ? '<a href="https://partners.smartdukaan.com/document/' + item.attachment + '" target="_blank"><i class="fa fa-paperclip"></i> View</a>' : '--') + '</td>' +
|
|
|
286 |
'</tr>';
|
|
|
287 |
}
|
|
|
288 |
if (items.length === 0) {
|
|
|
289 |
tbody = '<tr><td colspan="10" class="text-center">No records found</td></tr>';
|
|
|
290 |
}
|
|
|
291 |
$('#beatDetailTableBody').html(tbody);
|
|
|
292 |
$('#beatDetailModal').modal('show');
|
|
|
293 |
});
|
| 36693 |
vikas |
294 |
|
| 36645 |
vikas |
295 |
</script>
|