Subversion Repositories SmartDukaan

Rev

Rev 35879 | Rev 35984 | 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">
35953 ranu 368
    // Store current authId for break time loading
369
    var currentModalAuthId = null;
370
    var currentModalDate = null;
371
 
35638 ranu 372
    document.addEventListener('DOMContentLoaded', function () {
373
        var elems = document.querySelectorAll('.lakh');
374
        for (var i = 0; i < elems.length; i++) {
375
            var val = parseInt(elems[i].textContent.trim());
35636 ranu 376
            if (!isNaN(val)) {
35638 ranu 377
                elems[i].textContent = (val / 100000).toFixed(1) + 'L';
35636 ranu 378
            }
35638 ranu 379
        }
35636 ranu 380
    });
381
 
35631 ranu 382
    function showOutOfSequenceDetails(authId, rbmName) {
383
        document.getElementById('oosModalLabel').textContent = 'Out of Sequence Calls - ' + rbmName;
384
        document.getElementById('oosDetailsContent').innerHTML = '<p>Loading...</p>';
385
        $('#oosModal').modal('show');
386
 
387
        fetch('/indent/rbm_call_target/oos_details?authId=' + authId)
388
                .then(function (response) {
389
                    return response.json();
390
                })
391
                .then(function (data) {
392
                    if (data && data.length > 0) {
393
                        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>';
394
                        for (var i = 0; i < data.length; i++) {
395
                            html += '<tr><td>' + (i + 1) + '</td><td>' + data[i].partyName + '</td><td>' + data[i].code + '</td><td>' + data[i].time + '</td></tr>';
396
                        }
397
                        html += '</tbody></table>';
398
                        document.getElementById('oosDetailsContent').innerHTML = html;
399
                    } else {
400
                        document.getElementById('oosDetailsContent').innerHTML = '<p>No out of sequence calls found.</p>';
401
                    }
402
                })
403
                .catch(function () {
404
                    document.getElementById('oosDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
405
                });
406
    }
35670 ranu 407
 
408
    function showCalledPartnerDetails(authId, rbmName) {
35953 ranu 409
        // Store authId for break time tab
410
        currentModalAuthId = authId;
411
        currentModalDate = null;
412
 
413
        document.getElementById('calledModalLabel').textContent = 'Activity - ' + rbmName;
35670 ranu 414
        document.getElementById('calledDetailsContent').innerHTML = '<p>Loading...</p>';
35953 ranu 415
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Click to load break time data.</p>';
416
 
417
        // Reset to Called tab
418
        $('#called-tab').tab('show');
419
 
35670 ranu 420
        $('#calledModal').modal('show');
421
 
422
        fetch('/indent/rbm_call_target/called_details?authId=' + authId)
423
                .then(function (response) {
424
                    return response.json();
425
                })
426
                .then(function (data) {
427
                    if (data && data.length > 0) {
35763 ranu 428
                        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 429
                        for (var i = 0; i < data.length; i++) {
35703 ranu 430
                            var recordingHtml = '-';
431
                            if (data[i].recordingUrl) {
35731 ranu 432
                                recordingHtml = '<audio controls style="width: 150px; height: 30px;"><source src="' + data[i].recordingUrl + '" type="audio/mpeg">Your browser does not support audio.</audio>';
35703 ranu 433
                            }
35763 ranu 434
                            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>';
35670 ranu 435
                        }
436
                        html += '</tbody></table>';
437
                        document.getElementById('calledDetailsContent').innerHTML = html;
438
                    } else {
439
                        document.getElementById('calledDetailsContent').innerHTML = '<p>No called partners found.</p>';
440
                    }
441
                })
442
                .catch(function () {
443
                    document.getElementById('calledDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
444
                });
445
    }
35730 ranu 446
 
35953 ranu 447
    // Load break time data when tab is clicked
448
    document.addEventListener('DOMContentLoaded', function () {
449
        var breakTimeTab = document.getElementById('break-time-tab');
450
        if (breakTimeTab) {
451
            breakTimeTab.addEventListener('shown.bs.tab', loadBreakTimeData);
452
            breakTimeTab.addEventListener('click', function () {
453
                // For Bootstrap 4 compatibility
454
                setTimeout(loadBreakTimeData, 100);
455
            });
456
        }
457
    });
458
 
459
    function loadBreakTimeData() {
460
        if (!currentModalAuthId) {
461
            return;
462
        }
463
 
464
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Loading break time data...</p>';
465
 
466
        var url = '/indent/rbm_call_target/break_time_details?authId=' + currentModalAuthId;
467
        if (currentModalDate) {
468
            url += '&date=' + currentModalDate;
469
        }
470
 
471
        fetch(url)
472
                .then(function (response) {
473
                    return response.json();
474
                })
475
                .then(function (data) {
476
                    var html = '';
477
 
478
                    // Summary cards
479
                    html += '<div class="row mb-3">';
480
                    html += '<div class="col-md-12"><button class="btn btn-warning"> Total Break Time -: ' + (data.totalBreakTime || '0h 0m 0s');
481
                    html += '</button> &nbsp;';
482
                    html += '&nbsp; <button class="btn btn-danger"> Total Logged Out -: ' + (data.totalLoggedOutTime || '0h 0m 0s');
483
                    html += '</button></div>';
484
                    html += '</div>';
485
 
486
                    // Details table
487
                    if (data.details && data.details.length > 0) {
488
                        html += '<table class="table table-bordered table-sm"><thead><tr>';
489
                        html += '<th>S.No</th><th>Status</th><th>Log Time</th><th>Duration</th>';
490
                        html += '</tr></thead><tbody>';
491
 
492
                        for (var i = 0; i < data.details.length; i++) {
493
                            var detail = data.details[i];
494
                            var statusClass = '';
495
                            if (detail.status && detail.status.toLowerCase().indexOf('break') >= 0) {
496
                                statusClass = 'style="background-color: #fff3cd;"';
497
                            } else if (detail.status && detail.status.toLowerCase().indexOf('logged out') >= 0) {
498
                                statusClass = 'style="background-color: #f8d7da;"';
499
                            } else if (detail.status && detail.status.toLowerCase().indexOf('available') >= 0) {
500
                                statusClass = 'style="background-color: #d4edda;"';
501
                            }
502
 
503
                            html += '<tr ' + statusClass + '>';
504
                            html += '<td>' + (i + 1) + '</td>';
505
                            html += '<td>' + (detail.status || '-') + '</td>';
506
                            html += '<td>' + (detail.logTime || '-') + '</td>';
507
                            html += '<td>' + (detail.duration || '-') + '</td>';
508
                            html += '</tr>';
509
                        }
510
                        html += '</tbody></table>';
511
                    } else {
512
                        html += '<p class="text-muted">No break time data available. Data is collected at 12 PM, 4 PM, and 8 PM daily.</p>';
513
                    }
514
 
515
                    document.getElementById('breakTimeDetailsContent').innerHTML = html;
516
                })
517
                .catch(function (err) {
518
                    console.error('Error loading break time:', err);
519
                    document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Error loading break time data. Please try again.</p>';
520
                });
521
    }
522
 
35730 ranu 523
    // Date-wise Called Partner History
524
    function showHistoryCalledPartners() {
525
        var selectedDate = document.getElementById('historyDate').value;
526
        var selectedRbm = document.getElementById('historyRbm');
527
        var authId = selectedRbm.value;
528
        var rbmName = selectedRbm.options[selectedRbm.selectedIndex].text;
529
 
530
        if (!selectedDate) {
531
            alert('Please select a date');
532
            return;
533
        }
534
        if (!authId) {
535
            alert('Please select an RBM');
536
            return;
537
        }
538
 
35953 ranu 539
        // Store authId and date for break time tab
540
        currentModalAuthId = authId;
541
        currentModalDate = selectedDate;
542
 
543
        document.getElementById('calledModalLabel').textContent = 'Activity - ' + rbmName + ' (' + selectedDate + ')';
35730 ranu 544
        document.getElementById('calledDetailsContent').innerHTML = '<p>Loading...</p>';
35953 ranu 545
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Click to load break time data.</p>';
546
 
547
        // Reset to Called tab
548
        $('#called-tab').tab('show');
549
 
35730 ranu 550
        $('#calledModal').modal('show');
551
 
552
        fetch('/indent/rbm_call_target/called_details?authId=' + authId + '&date=' + selectedDate)
553
                .then(function (response) {
554
                    return response.json();
555
                })
556
                .then(function (data) {
557
                    if (data && data.length > 0) {
35763 ranu 558
                        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 559
                        for (var i = 0; i < data.length; i++) {
560
                            var recordingHtml = '-';
561
                            if (data[i].recordingUrl) {
35731 ranu 562
                                recordingHtml = '<audio controls style="width: 150px; height: 30px;"><source src="' + data[i].recordingUrl + '" type="audio/mpeg">Your browser does not support audio.</audio>';
35730 ranu 563
                            }
35763 ranu 564
                            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 565
                        }
566
                        html += '</tbody></table>';
567
                        document.getElementById('calledDetailsContent').innerHTML = html;
568
                    } else {
569
                        document.getElementById('calledDetailsContent').innerHTML = '<p>No called partners found for selected date.</p>';
570
                    }
571
                })
572
                .catch(function () {
573
                    document.getElementById('calledDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
574
                });
575
    }
35852 ranu 576
 
577
    // Auto-refresh agent status every 30 seconds
578
    function refreshAgentStatus() {
579
        fetch('/indent/rbm_call_target/get_agent_statuses')
35879 ranu 580
                .then(function (response) {
581
                    return response.json();
582
                })
583
                .then(function (data) {
584
                    if (data && data.length > 0) {
585
                        for (var i = 0; i < data.length; i++) {
586
                            var agent = data[i];
587
                            var statusCell = document.querySelector('.agent-status-cell[data-authid="' + agent.authId + '"]');
588
                            var timeCell = document.querySelector('.time-in-status-cell[data-authid="' + agent.authId + '"]');
35852 ranu 589
 
35879 ranu 590
                            if (statusCell) {
591
                                var statusHtml = getStatusBadge(agent.agentStatus);
592
                                statusCell.innerHTML = statusHtml;
593
                            }
594
                            if (timeCell) {
595
                                timeCell.textContent = agent.timeInStatus || '-';
596
                            }
35852 ranu 597
                        }
598
                    }
35879 ranu 599
                })
600
                .catch(function (err) {
601
                    console.error('Error refreshing agent status:', err);
602
                });
35852 ranu 603
    }
604
 
605
    function getStatusBadge(status) {
606
        if (!status) return '<span class="badge" style="background-color: #6c757d; color: white;">-</span>';
607
 
608
        var bgColor = '#6c757d';
609
        var textColor = 'white';
610
 
611
        if (status === 'On Call') {
612
            bgColor = '#28a745';
613
        } else if (status === 'Available') {
614
            bgColor = '#17a2b8';
615
        } else if (status === 'On Break') {
616
            bgColor = '#ffc107';
617
            textColor = 'black';
618
        } else if (status === 'Logged Out') {
619
            bgColor = '#dc3545';
620
        } else if (status === 'Trying') {
621
            bgColor = '#fd7e14';
622
        }
623
 
624
        return '<span class="badge" style="background-color: ' + bgColor + '; color: ' + textColor + ';">' + status + '</span>';
625
    }
626
 
627
    // Refresh every 20 seconds
628
    setInterval(refreshAgentStatus, 20000);
629
 
630
    // Initial refresh after page load
631
    setTimeout(refreshAgentStatus, 2000);
632
 
633
    // Download All Call Data by Date
634
    function downloadCallData() {
635
        var selectedDate = document.getElementById('downloadDate').value;
636
        if (!selectedDate) {
637
            alert('Please select a date');
638
            return;
639
        }
640
        window.location.href = '/indent/rbm_call_target/download_call_data?date=' + selectedDate;
641
    }
35631 ranu 642
</script>