Subversion Repositories SmartDukaan

Rev

Rev 36645 | Rev 36669 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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