Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
35631 ranu 1
<style>
35953 ranu 2
    #rbm-call-target-table td, #rbm-call-target-table th, #breakTimeDetailsContent td, #breakTimeDetailsContent th {
35631 ranu 3
        font-size: 14px;
4
        text-align: center;
5
        padding: 0.4rem;
6
        vertical-align: middle;
7
    }
8
 
35852 ranu 9
    .badge {
10
        display: inline-block;
11
        padding: 4px 8px;
12
        font-size: 12px;
13
        font-weight: 600;
14
        border-radius: 4px;
15
    }
16
 
17
    .agent-status-cell, .time-in-status-cell {
18
        min-width: 80px;
19
    }
20
 
35631 ranu 21
    #rbm-call-target-table thead th {
22
        background-color: #343a40;
23
        color: white;
24
        font-weight: 600;
25
    }
26
 
27
    #rbm-call-target-table tbody tr:first-child td {
28
        font-weight: bold;
29
        background-color: #00d6b2;
30
    }
31
 
32
    .highlight-target {
33
        background-color: #fff3cd !important;
34
        font-weight: bold;
35
    }
36
 
37
    .highlight-achieved {
38
        background-color: #d4edda !important;
39
    }
40
 
41
    .highlight-oos {
42
        background-color: #f8d7da !important;
43
    }
44
 
45
    .highlight-plan-today {
46
        background-color: #0f57a4 !important;
47
        color: white !important;
48
    }
49
 
50
    .highlight-carry-forward {
51
        background-color: #ffc107 !important;
52
        color: #000 !important;
53
    }
54
 
55
    .highlight-untouched {
56
        background-color: #dc3545 !important;
57
        color: white !important;
58
    }
59
 
60
    .highlight-future-plan {
61
        background-color: #6c757d !important;
62
        color: #000 !important;
63
    }
64
 
65
    .clickable {
66
        cursor: pointer;
67
        text-decoration: underline;
68
        color: #007bff;
69
    }
70
 
71
    .clickable:hover {
72
        color: #0056b3;
73
    }
74
 
75
    .modal-body table {
76
        width: 100%;
77
    }
78
 
79
    .modal-body table th, .modal-body table td {
80
        padding: 8px;
81
        border: 1px solid #ddd;
82
    }
35654 ranu 83
 
84
    #oosDetailsContent table td, #oosDetailsContent table th {
85
        font-size: 12px;
86
    }
35670 ranu 87
 
88
    #calledDetailsContent table td, #calledDetailsContent table th {
89
        font-size: 12px;
90
    }
35631 ranu 91
</style>
92
 
93
<div class="container-fluid">
94
    <h3>RBM Call Target Summary</h3>
35852 ranu 95
    <div class="row">
96
        <div class="col-md-7">
97
            <!-- Date-wise Called Partner Filter -->
98
            <div class="card mb-3" style="max-width: 500px;">
99
                <div class="card-body py-2">
100
                    <div class="d-flex align-items-center">
101
                        <label for="historyDate" class="mb-0 mr-2"
102
                               style="font-size: 14px; white-space: nowrap;">Date:</label>
103
                        <input type="date" id="historyDate" class="form-control form-control-sm mr-2"
104
                               style="width: 140px;">
105
                        <label for="historyRbm" class="mb-0 mr-2"
106
                               style="font-size: 14px; white-space: nowrap;">RBM:</label>
107
                        <select id="historyRbm" class="form-control form-control-sm mr-2" style="width: 150px;">
108
                            <option value="">Select RBM</option>
109
                            #foreach($model in $rbmCallTargetModels)
110
                                <option value="$model.getAuthId()">$model.getRbmName()</option>
111
                            #end
112
                        </select>
113
                        <button type="button" class="btn btn-primary btn-sm" onclick="showHistoryCalledPartners()">
114
                            View
115
                        </button>
116
                    </div>
117
                </div>
35730 ranu 118
            </div>
119
        </div>
35852 ranu 120
        <div class="col-md-5">
121
            <!-- Download All Call Data by Date -->
122
            <div class="card mb-3" style="max-width: 450px;">
123
                <div class="card-body py-2">
124
                    <div class="d-flex align-items-center">
125
                        <label for="downloadDate" class="mb-0 mr-2" style="font-size: 14px; white-space: nowrap;">Download
126
                            Call Data:</label>
127
                        <input type="date" id="downloadDate" class="form-control form-control-sm mr-2"
128
                               style="width: 140px;">
129
                        <button type="button" class="btn btn-success btn-sm" onclick="downloadCallData()">Download CSV
130
                        </button>
131
                    </div>
132
                </div>
133
            </div>
134
 
135
        </div>
35730 ranu 136
    </div>
137
 
35852 ranu 138
 
35631 ranu 139
    <table id="rbm-call-target-table" class="table table-bordered table-striped">
140
        <thead>
141
        <tr>
142
            <th>RBM Name</th>
35879 ranu 143
            <th style="background-color: #17a2b8; color: white;">Agent Status</th>
144
            <th style="background-color: #17a2b8; color: white;">Time in Status</th>
35631 ranu 145
            <th>Partner Count</th>
35645 ranu 146
            <th>(Ach/Tgt)</th>
35631 ranu 147
            <th>Calling Target</th>
148
            <th>Called</th>
149
            <th class="highlight-plan-today">Plan Today</th>
150
            <th class="highlight-carry-forward">Carry Forward</th>
151
            <th style="background-color: #1e6e0e; color: white;">Zero Billing</th>
152
            <th class="highlight-untouched">Untouched</th>
153
            <th class="highlight-future-plan">Future Plan</th>
154
            <th>Normal</th>
155
            <th style="background-color: #c0392b;">Out of Sequence</th>
35645 ranu 156
            <th>Download</th>
35631 ranu 157
        </tr>
158
        </thead>
159
        <tbody>
160
            #set($totalPartnerCount = 0)
161
            #set($totalTodayTarget = 0)
162
            #set($totalValueAchieved = 0)
163
            #set($totalMovedToFuture = 0)
164
            #set($totalPlanToday = 0)
165
            #set($totalCarryForward = 0)
166
            #set($totalZeroBilling = 0)
167
            #set($totalUntouched = 0)
168
            #set($totalFuturePlan = 0)
169
            #set($totalNormal = 0)
170
            #set($totalOutOfSequence = 0)
171
            #set($totalL2CallingList = 0)
172
            #set($totalArrAchieved = 0)
173
            #set($totalArrTarget = 0)
174
 
175
            ## Total row first
176
            #foreach($model in $rbmCallTargetModels)
35662 ranu 177
                #if(!$model.isL2Position())
178
                    #set($totalPartnerCount = $totalPartnerCount + $model.getPartnerCount())
179
                #end
35631 ranu 180
                #set($totalTodayTarget = $totalTodayTarget + $model.getTodayTargetOfCall())
181
                #set($totalValueAchieved = $totalValueAchieved + $model.getValueTargetAchieved())
182
                #set($totalMovedToFuture = $totalMovedToFuture + $model.getMovedToFuture())
183
                #set($totalPlanToday = $totalPlanToday + $model.getPlanToday())
184
                #set($totalCarryForward = $totalCarryForward + $model.getCarryForward())
185
                #set($totalZeroBilling = $totalZeroBilling + $model.getZeroBilling())
186
                #set($totalUntouched = $totalUntouched + $model.getUntouched())
187
                #set($totalFuturePlan = $totalFuturePlan + $model.getFuturePlan())
188
                #set($totalNormal = $totalNormal + $model.getNormal())
189
                #set($totalOutOfSequence = $totalOutOfSequence + $model.getOutOfSequenceCount())
190
                #set($totalL2CallingList = $totalL2CallingList + $model.getL2CallingList())
191
                #if($arrAchievedByAuthId && $arrAchievedByAuthId.get($model.getAuthId()))
192
                    #set($totalArrAchieved = $totalArrAchieved + $arrAchievedByAuthId.get($model.getAuthId()))
193
                #end
194
                #if($arrTargetByAuthId && $arrTargetByAuthId.get($model.getAuthId()))
195
                    #set($totalArrTarget = $totalArrTarget + $arrTargetByAuthId.get($model.getAuthId()))
196
                #end
197
            #end
198
 
199
            #set($adjustedTotalTarget = $totalTodayTarget + $totalMovedToFuture)
200
            #set($adjustedTotalAchieved = $totalValueAchieved + $totalMovedToFuture)
201
 
202
        <tr>
203
            <td><strong>TOTAL</strong></td>
35879 ranu 204
            <td>-</td>
205
            <td>-</td>
35631 ranu 206
            <td><strong>$totalPartnerCount</strong></td>
35636 ranu 207
            <td><strong><span class="lakh">$totalArrAchieved</span> / <span class="lakh">$totalArrTarget</span></strong>
35631 ranu 208
            </td>
209
            <td class="highlight-target"><strong>$adjustedTotalTarget</strong></td>
210
            <td class="highlight-achieved currency"><strong>$adjustedTotalAchieved</strong></td>
211
            <td class="highlight-plan-today"><strong>$totalPlanToday</strong></td>
212
            <td class="highlight-carry-forward"><strong>$totalCarryForward</strong></td>
213
            <td><strong>$totalZeroBilling</strong></td>
214
            <td class="highlight-untouched"><strong>$totalUntouched</strong></td>
215
            <td class="highlight-future-plan"><strong>$totalFuturePlan</strong></td>
216
            <td><strong>$totalNormal</strong></td>
217
            <td class="highlight-oos"><strong>$totalOutOfSequence</strong></td>
35645 ranu 218
            <td></td>
35631 ranu 219
        </tr>
220
 
221
            #foreach($model in $rbmCallTargetModels)
222
                #set($rowTarget = $model.getTodayTargetOfCall() + $model.getMovedToFuture())
223
                #set($rowAchieved = $model.getValueTargetAchieved() + $model.getMovedToFuture())
35852 ranu 224
                #set($agentStatus = $agentStatusByAuthId.get($model.getAuthId()))
35631 ranu 225
            <tr>
226
                <td>$model.getRbmName()</td>
35879 ranu 227
                <td class="agent-status-cell" data-authid="$model.getAuthId()">
35852 ranu 228
                    #if($agentStatus && $agentStatus.getAgentStatus())
229
                        #if($agentStatus.getAgentStatus() == "On Call")
230
                            <span class="badge" style="background-color: #28a745; color: white;">$agentStatus.getAgentStatus()</span>
231
                        #elseif($agentStatus.getAgentStatus() == "Available")
232
                            <span class="badge" style="background-color: #17a2b8; color: white;">$agentStatus.getAgentStatus()</span>
233
                        #elseif($agentStatus.getAgentStatus() == "On Break")
234
                            <span class="badge" style="background-color: #ffc107; color: black;">$agentStatus.getAgentStatus()</span>
235
                        #elseif($agentStatus.getAgentStatus() == "Logged Out")
236
                            <span class="badge" style="background-color: #dc3545; color: white;">$agentStatus.getAgentStatus()</span>
237
                        #elseif($agentStatus.getAgentStatus() == "Trying")
238
                            <span class="badge" style="background-color: #fd7e14; color: white;">$agentStatus.getAgentStatus()</span>
239
                        #else
240
                            <span class="badge" style="background-color: #6c757d; color: white;">$agentStatus.getAgentStatus()</span>
241
                        #end
242
                    #else
243
                        <span class="badge" style="background-color: #6c757d; color: white;">-</span>
244
                    #end
245
                </td>
246
                <td class="time-in-status-cell" data-authid="$model.getAuthId()">
247
                    #if($agentStatus && $agentStatus.getTimeInStatus())
248
                        $agentStatus.getTimeInStatus()
249
                    #else
250
                        -
251
                    #end
35879 ranu 252
                </td>
35631 ranu 253
                <td>$model.getPartnerCount()</td>
254
                <td>
255
                    #if($arrAchievedByAuthId && $arrAchievedByAuthId.get($model.getAuthId()))
35636 ranu 256
                        <span class="lakh">$arrAchievedByAuthId.get($model.getAuthId())</span>
35631 ranu 257
                    #else
258
 
259
                    #end
260
                    /
261
                    #if($arrTargetByAuthId && $arrTargetByAuthId.get($model.getAuthId()))
35636 ranu 262
                        <span class="lakh">$arrTargetByAuthId.get($model.getAuthId())</span>
35631 ranu 263
                    #else
264
 
265
                    #end
266
                </td>
267
                <td class="highlight-target">$rowTarget</td>
35670 ranu 268
                <td class="highlight-achieved currency">
35953 ranu 269
                    <span class="clickable"
270
                          onclick="showCalledPartnerDetails($model.getAuthId(), '$model.getRbmName()')">$rowAchieved</span>
35670 ranu 271
                </td>
35631 ranu 272
                <td class="highlight-plan-today">$model.getPlanToday()</td>
273
                <td class="highlight-carry-forward">$model.getCarryForward()</td>
274
                <td>$model.getZeroBilling()</td>
275
                <td class="highlight-untouched">$model.getUntouched()</td>
276
                <td class="highlight-future-plan">$model.getFuturePlan()</td>
277
                <td>$model.getNormal()</td>
278
                <td class="highlight-oos" style="color: red;">
279
                    #if($model.getOutOfSequenceCount() > 0)
280
                        <span class="clickable" style="color: #e80404"
281
                              onclick="showOutOfSequenceDetails($model.getAuthId(), '$model.getRbmName()')">$model.getOutOfSequenceCount()</span>
282
                    #else
283
 
284
                    #end
285
                </td>
35645 ranu 286
                <td>
287
                    <a href="/indent/rbm_call_target/download_raw_data?authId=$model.getAuthId()" target="_blank"
288
                       class="btn btn-sm btn-outline-success">CSV</a>
289
                </td>
35631 ranu 290
            </tr>
291
            #end
292
        </tbody>
293
    </table>
294
</div>
295
 
35953 ranu 296
<!-- Modal for Called Partner Details with Tabs -->
297
<div class="modal fade" id="calledModal" tabindex="-1" role="dialog" aria-labelledby="calledModalLabel"
298
     aria-hidden="true">
299
    <div class="modal-dialog modal-lg" role="document" style="max-width: 90%;">
300
        <div class="modal-content">
301
            <div class="modal-header">
302
                <h5 class="modal-title" id="calledModalLabel">Called Partners</h5>
303
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
304
                    <span aria-hidden="true">&times;</span>
305
                </button>
306
            </div>
307
            <div class="modal-body">
308
                <!-- Tabs Navigation -->
309
                <ul class="nav nav-tabs" id="calledModalTabs" role="tablist">
310
                    <li class="nav-item">
311
                        <a class="nav-link active" id="called-tab" data-toggle="tab" href="#calledTabContent"
312
                           role="tab">
313
                            Called Partners
314
                        </a>
315
                    </li>
316
                    <li class="nav-item">
317
                        <a class="nav-link" id="break-time-tab" data-toggle="tab" href="#breakTimeTabContent"
318
                           role="tab">
319
                            Break Time
320
                        </a>
321
                    </li>
322
                </ul>
323
                <!-- Tabs Content -->
324
                <div class="tab-content mt-3" id="calledModalTabContent">
325
                    <div class="tab-pane fade show active" id="calledTabContent" role="tabpanel">
326
                        <div id="calledDetailsContent">
327
                            <p>Loading...</p>
328
                        </div>
329
                    </div>
330
                    <div class="tab-pane fade" id="breakTimeTabContent" role="tabpanel">
331
                        <div id="breakTimeDetailsContent">
332
                            <p>Click on Break Time tab to load data.</p>
333
                        </div>
334
                    </div>
335
                </div>
336
            </div>
337
            <div class="modal-footer">
338
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
339
            </div>
340
        </div>
341
    </div>
342
</div>
343
 
344
<!-- Modal for Out of Sequence Details -->
345
<div class="modal fade" id="oosModal" tabindex="-1" role="dialog" aria-labelledby="oosModalLabel"
346
     aria-hidden="true">
347
    <div class="modal-dialog modal-lg" role="document">
348
        <div class="modal-content">
349
            <div class="modal-header">
350
                <h5 class="modal-title" id="oosModalLabel">Out of Sequence Calls</h5>
351
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
352
                    <span aria-hidden="true">&times;</span>
353
                </button>
354
            </div>
355
            <div class="modal-body">
356
                <div id="oosDetailsContent">
357
                    <p>Loading...</p>
358
                </div>
359
            </div>
360
            <div class="modal-footer">
361
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
362
            </div>
363
        </div>
364
    </div>
365
</div>
366
 
35631 ranu 367
<script type="text/javascript">
35984 ranu 368
    // Store current authId and agentName for break time loading
35953 ranu 369
    var currentModalAuthId = null;
370
    var currentModalDate = null;
35984 ranu 371
    var currentModalAgentName = null;
35953 ranu 372
 
35638 ranu 373
    document.addEventListener('DOMContentLoaded', function () {
374
        var elems = document.querySelectorAll('.lakh');
375
        for (var i = 0; i < elems.length; i++) {
376
            var val = parseInt(elems[i].textContent.trim());
35636 ranu 377
            if (!isNaN(val)) {
35638 ranu 378
                elems[i].textContent = (val / 100000).toFixed(1) + 'L';
35636 ranu 379
            }
35638 ranu 380
        }
35636 ranu 381
    });
382
 
35631 ranu 383
    function showOutOfSequenceDetails(authId, rbmName) {
384
        document.getElementById('oosModalLabel').textContent = 'Out of Sequence Calls - ' + rbmName;
385
        document.getElementById('oosDetailsContent').innerHTML = '<p>Loading...</p>';
386
        $('#oosModal').modal('show');
387
 
388
        fetch('/indent/rbm_call_target/oos_details?authId=' + authId)
389
                .then(function (response) {
390
                    return response.json();
391
                })
392
                .then(function (data) {
393
                    if (data && data.length > 0) {
394
                        var html = '<table class="table table-bordered table-sm"><thead><tr><th>S.No</th><th>Party Name</th><th>Code</th><th>Time</th></tr></thead><tbody>';
395
                        for (var i = 0; i < data.length; i++) {
396
                            html += '<tr><td>' + (i + 1) + '</td><td>' + data[i].partyName + '</td><td>' + data[i].code + '</td><td>' + data[i].time + '</td></tr>';
397
                        }
398
                        html += '</tbody></table>';
399
                        document.getElementById('oosDetailsContent').innerHTML = html;
400
                    } else {
401
                        document.getElementById('oosDetailsContent').innerHTML = '<p>No out of sequence calls found.</p>';
402
                    }
403
                })
404
                .catch(function () {
405
                    document.getElementById('oosDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
406
                });
407
    }
35670 ranu 408
 
409
    function showCalledPartnerDetails(authId, rbmName) {
35984 ranu 410
        // Store authId and agentName for break time tab
35953 ranu 411
        currentModalAuthId = authId;
412
        currentModalDate = null;
35984 ranu 413
        currentModalAgentName = rbmName;
35953 ranu 414
 
415
        document.getElementById('calledModalLabel').textContent = 'Activity - ' + rbmName;
35670 ranu 416
        document.getElementById('calledDetailsContent').innerHTML = '<p>Loading...</p>';
35953 ranu 417
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Click to load break time data.</p>';
418
 
419
        // Reset to Called tab
420
        $('#called-tab').tab('show');
421
 
35670 ranu 422
        $('#calledModal').modal('show');
423
 
35984 ranu 424
        fetch('/indent/rbm_call_target/called_details?authId=' + authId + '&agentName=' + encodeURIComponent(rbmName))
35670 ranu 425
                .then(function (response) {
426
                    return response.json();
427
                })
428
                .then(function (data) {
429
                    if (data && data.length > 0) {
35763 ranu 430
                        var html = '<table class="table table-bordered table-sm"><thead><tr><th>S.No</th><th style="width: 200px;">Party Name</th><th>Code</th><th style="width: 350px;">Remark</th><th>Call Status</th><th>Call Duration</th><th>Call Date/Time</th><th>Recording</th></tr></thead><tbody>';
35670 ranu 431
                        for (var i = 0; i < data.length; i++) {
35984 ranu 432
                            var rowStyle = '';
35703 ranu 433
                            var recordingHtml = '-';
35984 ranu 434
 
435
                            // Check if this is a break log entry
436
                            if (data[i].breakLog) {
437
                                rowStyle = 'style="background-color: #f8d7da; color: #721c24; font-weight: bold;"';
438
                                html += '<tr ' + rowStyle + '><td>' + (i + 1) + '</td><td colspan="5"><i class="fa fa-coffee"></i> ' + (data[i].breakStatus || 'On Break') + '</td><td>' + (data[i].callDateTime || '-') + '</td><td>-</td></tr>';
439
                            } else {
440
                                if (data[i].recordingUrl) {
441
                                    recordingHtml = '<audio controls style="width: 150px; height: 30px;"><source src="' + data[i].recordingUrl + '" type="audio/mpeg">Your browser does not support audio.</audio>';
442
                                }
443
                                html += '<tr><td>' + (i + 1) + '</td><td>' + data[i].partyName + '</td><td>' + data[i].code + '</td><td>' + data[i].remark + '- &nbsp;' + (data[i].message || '-') + '</td><td>' + (data[i].callStatus || '-') + '</td><td>' + (data[i].callDuration || '-') + '</td><td>' + (data[i].callDateTime || '-') + '</td><td>' + recordingHtml + '</td></tr>';
35703 ranu 444
                            }
35670 ranu 445
                        }
446
                        html += '</tbody></table>';
447
                        document.getElementById('calledDetailsContent').innerHTML = html;
448
                    } else {
449
                        document.getElementById('calledDetailsContent').innerHTML = '<p>No called partners found.</p>';
450
                    }
451
                })
452
                .catch(function () {
453
                    document.getElementById('calledDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
454
                });
455
    }
35730 ranu 456
 
35953 ranu 457
    // Load break time data when tab is clicked
458
    document.addEventListener('DOMContentLoaded', function () {
459
        var breakTimeTab = document.getElementById('break-time-tab');
460
        if (breakTimeTab) {
461
            breakTimeTab.addEventListener('shown.bs.tab', loadBreakTimeData);
462
            breakTimeTab.addEventListener('click', function () {
463
                // For Bootstrap 4 compatibility
464
                setTimeout(loadBreakTimeData, 100);
465
            });
466
        }
467
    });
468
 
469
    function loadBreakTimeData() {
470
        if (!currentModalAuthId) {
471
            return;
472
        }
473
 
474
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Loading break time data...</p>';
475
 
476
        var url = '/indent/rbm_call_target/break_time_details?authId=' + currentModalAuthId;
477
        if (currentModalDate) {
478
            url += '&date=' + currentModalDate;
479
        }
35984 ranu 480
        if (currentModalAgentName) {
481
            url += '&agentName=' + encodeURIComponent(currentModalAgentName);
482
        }
35953 ranu 483
 
484
        fetch(url)
485
                .then(function (response) {
486
                    return response.json();
487
                })
488
                .then(function (data) {
489
                    var html = '';
490
 
491
                    // Summary cards
492
                    html += '<div class="row mb-3">';
493
                    html += '<div class="col-md-12"><button class="btn btn-warning"> Total Break Time -: ' + (data.totalBreakTime || '0h 0m 0s');
494
                    html += '</button> &nbsp;';
495
                    html += '&nbsp; <button class="btn btn-danger"> Total Logged Out -: ' + (data.totalLoggedOutTime || '0h 0m 0s');
496
                    html += '</button></div>';
497
                    html += '</div>';
498
 
499
                    // Details table
500
                    if (data.details && data.details.length > 0) {
501
                        html += '<table class="table table-bordered table-sm"><thead><tr>';
502
                        html += '<th>S.No</th><th>Status</th><th>Log Time</th><th>Duration</th>';
503
                        html += '</tr></thead><tbody>';
504
 
505
                        for (var i = 0; i < data.details.length; i++) {
506
                            var detail = data.details[i];
507
                            var statusClass = '';
508
                            if (detail.status && detail.status.toLowerCase().indexOf('break') >= 0) {
509
                                statusClass = 'style="background-color: #fff3cd;"';
510
                            } else if (detail.status && detail.status.toLowerCase().indexOf('logged out') >= 0) {
511
                                statusClass = 'style="background-color: #f8d7da;"';
512
                            } else if (detail.status && detail.status.toLowerCase().indexOf('available') >= 0) {
513
                                statusClass = 'style="background-color: #d4edda;"';
514
                            }
515
 
516
                            html += '<tr ' + statusClass + '>';
517
                            html += '<td>' + (i + 1) + '</td>';
518
                            html += '<td>' + (detail.status || '-') + '</td>';
519
                            html += '<td>' + (detail.logTime || '-') + '</td>';
520
                            html += '<td>' + (detail.duration || '-') + '</td>';
521
                            html += '</tr>';
522
                        }
523
                        html += '</tbody></table>';
524
                    } else {
35984 ranu 525
                        html += '<p class="text-muted">No break time data available. Data is collected at 12 PM, 3 PM, 6 PM, and 9 PM daily.</p>';
35953 ranu 526
                    }
527
 
528
                    document.getElementById('breakTimeDetailsContent').innerHTML = html;
529
                })
530
                .catch(function (err) {
531
                    console.error('Error loading break time:', err);
532
                    document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Error loading break time data. Please try again.</p>';
533
                });
534
    }
535
 
35730 ranu 536
    // Date-wise Called Partner History
537
    function showHistoryCalledPartners() {
538
        var selectedDate = document.getElementById('historyDate').value;
539
        var selectedRbm = document.getElementById('historyRbm');
540
        var authId = selectedRbm.value;
541
        var rbmName = selectedRbm.options[selectedRbm.selectedIndex].text;
542
 
543
        if (!selectedDate) {
544
            alert('Please select a date');
545
            return;
546
        }
547
        if (!authId) {
548
            alert('Please select an RBM');
549
            return;
550
        }
551
 
35984 ranu 552
        // Store authId, date and agentName for break time tab
35953 ranu 553
        currentModalAuthId = authId;
554
        currentModalDate = selectedDate;
35984 ranu 555
        currentModalAgentName = rbmName;
35953 ranu 556
 
557
        document.getElementById('calledModalLabel').textContent = 'Activity - ' + rbmName + ' (' + selectedDate + ')';
35730 ranu 558
        document.getElementById('calledDetailsContent').innerHTML = '<p>Loading...</p>';
35953 ranu 559
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Click to load break time data.</p>';
560
 
561
        // Reset to Called tab
562
        $('#called-tab').tab('show');
563
 
35730 ranu 564
        $('#calledModal').modal('show');
565
 
35984 ranu 566
        fetch('/indent/rbm_call_target/called_details?authId=' + authId + '&date=' + selectedDate + '&agentName=' + encodeURIComponent(rbmName))
35730 ranu 567
                .then(function (response) {
568
                    return response.json();
569
                })
570
                .then(function (data) {
571
                    if (data && data.length > 0) {
35763 ranu 572
                        var html = '<table class="table table-bordered table-sm"><thead><tr><th>S.No</th><th style="width: 200px;">Party Name</th><th>Code</th><th style="width: 350px;">Remark</th><th>Call Status</th><th>Call Duration</th><th>Call Date/Time</th><th>Recording</th></tr></thead><tbody>';
35730 ranu 573
                        for (var i = 0; i < data.length; i++) {
35984 ranu 574
                            var rowStyle = '';
35730 ranu 575
                            var recordingHtml = '-';
35984 ranu 576
 
577
                            // Check if this is a break log entry
578
                            if (data[i].breakLog) {
579
                                rowStyle = 'style="background-color: #f8d7da; color: #721c24; font-weight: bold;"';
580
                                html += '<tr ' + rowStyle + '><td>' + (i + 1) + '</td><td colspan="5"><i class="fa fa-coffee"></i> ' + (data[i].breakStatus || 'On Break') + '</td><td>' + (data[i].callDateTime || '-') + '</td><td>-</td></tr>';
581
                            } else {
582
                                if (data[i].recordingUrl) {
583
                                    recordingHtml = '<audio controls style="width: 150px; height: 30px;"><source src="' + data[i].recordingUrl + '" type="audio/mpeg">Your browser does not support audio.</audio>';
584
                                }
585
                                html += '<tr><td>' + (i + 1) + '</td><td>' + data[i].partyName + '</td><td>' + data[i].code + '</td><td>' + data[i].remark + '- &nbsp;' + (data[i].message || '-') + '</td><td>' + (data[i].callStatus || '-') + '</td><td>' + (data[i].callDuration || '-') + '</td><td>' + (data[i].callDateTime || '-') + '</td><td>' + recordingHtml + '</td></tr>';
35730 ranu 586
                            }
587
                        }
588
                        html += '</tbody></table>';
589
                        document.getElementById('calledDetailsContent').innerHTML = html;
590
                    } else {
591
                        document.getElementById('calledDetailsContent').innerHTML = '<p>No called partners found for selected date.</p>';
592
                    }
593
                })
594
                .catch(function () {
595
                    document.getElementById('calledDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
596
                });
597
    }
35852 ranu 598
 
599
    // Auto-refresh agent status every 30 seconds
600
    function refreshAgentStatus() {
601
        fetch('/indent/rbm_call_target/get_agent_statuses')
35879 ranu 602
                .then(function (response) {
603
                    return response.json();
604
                })
605
                .then(function (data) {
606
                    if (data && data.length > 0) {
607
                        for (var i = 0; i < data.length; i++) {
608
                            var agent = data[i];
609
                            var statusCell = document.querySelector('.agent-status-cell[data-authid="' + agent.authId + '"]');
610
                            var timeCell = document.querySelector('.time-in-status-cell[data-authid="' + agent.authId + '"]');
35852 ranu 611
 
35879 ranu 612
                            if (statusCell) {
613
                                var statusHtml = getStatusBadge(agent.agentStatus);
614
                                statusCell.innerHTML = statusHtml;
615
                            }
616
                            if (timeCell) {
617
                                timeCell.textContent = agent.timeInStatus || '-';
618
                            }
35852 ranu 619
                        }
620
                    }
35879 ranu 621
                })
622
                .catch(function (err) {
623
                    console.error('Error refreshing agent status:', err);
624
                });
35852 ranu 625
    }
626
 
627
    function getStatusBadge(status) {
628
        if (!status) return '<span class="badge" style="background-color: #6c757d; color: white;">-</span>';
629
 
630
        var bgColor = '#6c757d';
631
        var textColor = 'white';
632
 
633
        if (status === 'On Call') {
634
            bgColor = '#28a745';
635
        } else if (status === 'Available') {
636
            bgColor = '#17a2b8';
637
        } else if (status === 'On Break') {
638
            bgColor = '#ffc107';
639
            textColor = 'black';
640
        } else if (status === 'Logged Out') {
641
            bgColor = '#dc3545';
642
        } else if (status === 'Trying') {
643
            bgColor = '#fd7e14';
644
        }
645
 
646
        return '<span class="badge" style="background-color: ' + bgColor + '; color: ' + textColor + ';">' + status + '</span>';
647
    }
648
 
649
    // Refresh every 20 seconds
650
    setInterval(refreshAgentStatus, 20000);
651
 
652
    // Initial refresh after page load
653
    setTimeout(refreshAgentStatus, 2000);
654
 
655
    // Download All Call Data by Date
656
    function downloadCallData() {
657
        var selectedDate = document.getElementById('downloadDate').value;
658
        if (!selectedDate) {
659
            alert('Please select a date');
660
            return;
661
        }
662
        window.location.href = '/indent/rbm_call_target/download_call_data?date=' + selectedDate;
663
    }
35631 ranu 664
</script>