Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
36112 ranu 1
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
35631 ranu 2
<style>
36112 ranu 3
    #rbm-call-target-table th, #breakTimeDetailsContent th {
4
        font-size: 13px;
35631 ranu 5
        text-align: center;
6
        padding: 0.4rem;
7
        vertical-align: middle;
8
    }
9
 
36112 ranu 10
    #rbm-call-target-table td, #breakTimeDetailsContent td {
11
        font-size: 13px;
12
        text-align: center;
13
        padding: 0.2rem;
14
        vertical-align: middle;
15
    }
16
 
35852 ranu 17
    .badge {
18
        display: inline-block;
19
        padding: 4px 8px;
20
        font-size: 12px;
21
        font-weight: 600;
22
        border-radius: 4px;
23
    }
24
 
25
    .agent-status-cell, .time-in-status-cell {
26
        min-width: 80px;
27
    }
28
 
35631 ranu 29
    #rbm-call-target-table thead th {
30
        background-color: #343a40;
31
        color: white;
32
        font-weight: 600;
33
    }
34
 
35
    #rbm-call-target-table tbody tr:first-child td {
36
        font-weight: bold;
37
        background-color: #00d6b2;
38
    }
39
 
40
    .highlight-target {
41
        background-color: #fff3cd !important;
42
        font-weight: bold;
43
    }
44
 
45
    .highlight-achieved {
46
        background-color: #d4edda !important;
47
    }
48
 
49
    .highlight-oos {
50
        background-color: #f8d7da !important;
51
    }
52
 
53
    .highlight-plan-today {
54
        background-color: #0f57a4 !important;
55
        color: white !important;
56
    }
57
 
58
    .highlight-carry-forward {
59
        background-color: #ffc107 !important;
60
        color: #000 !important;
61
    }
62
 
63
    .highlight-untouched {
64
        background-color: #dc3545 !important;
65
        color: white !important;
66
    }
67
 
68
    .highlight-future-plan {
69
        background-color: #6c757d !important;
70
        color: #000 !important;
71
    }
72
 
73
    .clickable {
74
        cursor: pointer;
75
        text-decoration: underline;
76
        color: #007bff;
77
    }
78
 
79
    .clickable:hover {
80
        color: #0056b3;
81
    }
82
 
83
    .modal-body table {
84
        width: 100%;
85
    }
86
 
87
    .modal-body table th, .modal-body table td {
88
        padding: 8px;
89
        border: 1px solid #ddd;
90
    }
35654 ranu 91
 
92
    #oosDetailsContent table td, #oosDetailsContent table th {
93
        font-size: 12px;
94
    }
35670 ranu 95
 
96
    #calledDetailsContent table td, #calledDetailsContent table th {
97
        font-size: 12px;
98
    }
35631 ranu 99
</style>
100
 
101
<div class="container-fluid">
102
    <h3>RBM Call Target Summary</h3>
35852 ranu 103
    <div class="row">
104
        <div class="col-md-7">
105
            <!-- Date-wise Called Partner Filter -->
106
            <div class="card mb-3" style="max-width: 500px;">
107
                <div class="card-body py-2">
108
                    <div class="d-flex align-items-center">
109
                        <label for="historyDate" class="mb-0 mr-2"
110
                               style="font-size: 14px; white-space: nowrap;">Date:</label>
111
                        <input type="date" id="historyDate" class="form-control form-control-sm mr-2"
112
                               style="width: 140px;">
113
                        <label for="historyRbm" class="mb-0 mr-2"
114
                               style="font-size: 14px; white-space: nowrap;">RBM:</label>
115
                        <select id="historyRbm" class="form-control form-control-sm mr-2" style="width: 150px;">
116
                            <option value="">Select RBM</option>
117
                            #foreach($model in $rbmCallTargetModels)
118
                                <option value="$model.getAuthId()">$model.getRbmName()</option>
119
                            #end
120
                        </select>
121
                        <button type="button" class="btn btn-primary btn-sm" onclick="showHistoryCalledPartners()">
122
                            View
123
                        </button>
124
                    </div>
125
                </div>
35730 ranu 126
            </div>
127
        </div>
35852 ranu 128
        <div class="col-md-5">
129
            <!-- Download All Call Data by Date -->
130
            <div class="card mb-3" style="max-width: 450px;">
131
                <div class="card-body py-2">
132
                    <div class="d-flex align-items-center">
133
                        <label for="downloadDate" class="mb-0 mr-2" style="font-size: 14px; white-space: nowrap;">Download
134
                            Call Data:</label>
135
                        <input type="date" id="downloadDate" class="form-control form-control-sm mr-2"
136
                               style="width: 140px;">
137
                        <button type="button" class="btn btn-success btn-sm" onclick="downloadCallData()">Download CSV
138
                        </button>
139
                    </div>
140
                </div>
141
            </div>
142
 
143
        </div>
35730 ranu 144
    </div>
145
 
35852 ranu 146
 
35631 ranu 147
    <table id="rbm-call-target-table" class="table table-bordered table-striped">
148
        <thead>
149
        <tr>
36112 ranu 150
            <th colspan="2">RBM Name</th>
36101 ranu 151
            <th style="background-color: #ffc107; color: black;">Rating</th>
35879 ranu 152
            <th style="background-color: #17a2b8; color: white;">Agent Status</th>
153
            <th style="background-color: #17a2b8; color: white;">Time in Status</th>
36179 ranu 154
            <th style="background-color: #007bff; color: white;"><i class="fa fa-clock"></i> Login</th>
155
            <th style="background-color: #28a745; color: white;"><i class="fa fa-phone"></i> On Call</th>
156
            <th style="background-color: #dc3545; color: white;"><i class="fa fa-user-clock"></i> Idle</th>
157
            <th style="background-color: #fd7e14; color: white;"><i class="fa fa-coffee"></i> Break</th>
35631 ranu 158
            <th>Partner Count</th>
35645 ranu 159
            <th>(Ach/Tgt)</th>
35631 ranu 160
            <th>Calling Target</th>
161
            <th>Called</th>
162
            <th class="highlight-plan-today">Plan Today</th>
163
            <th class="highlight-carry-forward">Carry Forward</th>
164
            <th style="background-color: #1e6e0e; color: white;">Zero Billing</th>
165
            <th class="highlight-untouched">Untouched</th>
166
            <th class="highlight-future-plan">Future Plan</th>
167
            <th>Normal</th>
168
            <th style="background-color: #c0392b;">Out of Sequence</th>
169
        </tr>
170
        </thead>
171
        <tbody>
172
            #set($totalPartnerCount = 0)
173
            #set($totalTodayTarget = 0)
174
            #set($totalValueAchieved = 0)
175
            #set($totalMovedToFuture = 0)
176
            #set($totalPlanToday = 0)
177
            #set($totalCarryForward = 0)
178
            #set($totalZeroBilling = 0)
179
            #set($totalUntouched = 0)
180
            #set($totalFuturePlan = 0)
181
            #set($totalNormal = 0)
182
            #set($totalOutOfSequence = 0)
183
            #set($totalL2CallingList = 0)
184
            #set($totalArrAchieved = 0)
185
            #set($totalArrTarget = 0)
186
 
187
            ## Total row first
188
            #foreach($model in $rbmCallTargetModels)
35662 ranu 189
                #if(!$model.isL2Position())
190
                    #set($totalPartnerCount = $totalPartnerCount + $model.getPartnerCount())
191
                #end
35631 ranu 192
                #set($totalTodayTarget = $totalTodayTarget + $model.getTodayTargetOfCall())
193
                #set($totalValueAchieved = $totalValueAchieved + $model.getValueTargetAchieved())
194
                #set($totalMovedToFuture = $totalMovedToFuture + $model.getMovedToFuture())
195
                #set($totalPlanToday = $totalPlanToday + $model.getPlanToday())
196
                #set($totalCarryForward = $totalCarryForward + $model.getCarryForward())
197
                #set($totalZeroBilling = $totalZeroBilling + $model.getZeroBilling())
198
                #set($totalUntouched = $totalUntouched + $model.getUntouched())
199
                #set($totalFuturePlan = $totalFuturePlan + $model.getFuturePlan())
200
                #set($totalNormal = $totalNormal + $model.getNormal())
201
                #set($totalOutOfSequence = $totalOutOfSequence + $model.getOutOfSequenceCount())
202
                #set($totalL2CallingList = $totalL2CallingList + $model.getL2CallingList())
203
                #if($arrAchievedByAuthId && $arrAchievedByAuthId.get($model.getAuthId()))
204
                    #set($totalArrAchieved = $totalArrAchieved + $arrAchievedByAuthId.get($model.getAuthId()))
205
                #end
206
                #if($arrTargetByAuthId && $arrTargetByAuthId.get($model.getAuthId()))
207
                    #set($totalArrTarget = $totalArrTarget + $arrTargetByAuthId.get($model.getAuthId()))
208
                #end
209
            #end
210
 
211
            #set($adjustedTotalTarget = $totalTodayTarget + $totalMovedToFuture)
212
            #set($adjustedTotalAchieved = $totalValueAchieved + $totalMovedToFuture)
213
 
214
        <tr>
36112 ranu 215
            <td colspan="2"><strong>TOTAL</strong></td>
35879 ranu 216
            <td>-</td>
217
            <td>-</td>
36101 ranu 218
            <td>-</td>
36179 ranu 219
            <td>-</td>
220
            <td>-</td>
221
            <td>-</td>
222
            <td>-</td>
35631 ranu 223
            <td><strong>$totalPartnerCount</strong></td>
35636 ranu 224
            <td><strong><span class="lakh">$totalArrAchieved</span> / <span class="lakh">$totalArrTarget</span></strong>
35631 ranu 225
            </td>
226
            <td class="highlight-target"><strong>$adjustedTotalTarget</strong></td>
227
            <td class="highlight-achieved currency"><strong>$adjustedTotalAchieved</strong></td>
228
            <td class="highlight-plan-today"><strong>$totalPlanToday</strong></td>
229
            <td class="highlight-carry-forward"><strong>$totalCarryForward</strong></td>
230
            <td><strong>$totalZeroBilling</strong></td>
231
            <td class="highlight-untouched"><strong>$totalUntouched</strong></td>
232
            <td class="highlight-future-plan"><strong>$totalFuturePlan</strong></td>
233
            <td><strong>$totalNormal</strong></td>
234
            <td class="highlight-oos"><strong>$totalOutOfSequence</strong></td>
235
        </tr>
236
 
237
            #foreach($model in $rbmCallTargetModels)
238
                #set($rowTarget = $model.getTodayTargetOfCall() + $model.getMovedToFuture())
239
                #set($rowAchieved = $model.getValueTargetAchieved() + $model.getMovedToFuture())
35852 ranu 240
                #set($agentStatus = $agentStatusByAuthId.get($model.getAuthId()))
35631 ranu 241
            <tr>
36101 ranu 242
                <td>
36112 ranu 243
                    #set($rank = $rbmCombinedRankMap.get($model.getRbmName()))
244
                    #if($rank == 1)
36122 ranu 245
                        <img src="../../../resources/images/king.png" style="width: 35px;">
36112 ranu 246
                    #elseif($rank == 2)
36123 ranu 247
                        <img src="../../../resources/images/trophy-cup.png" style="width: 30px;">
36112 ranu 248
                    #elseif($rank == 3)
36123 ranu 249
                        <img src="../../../resources/images/bronze-medal.png" style="width: 30px;">
36112 ranu 250
                    #elseif($rank == 4)
36123 ranu 251
                        <img src="../../../resources/images/star-badge.png" style="width: 30px;">
36112 ranu 252
                    #elseif($rank && $rank > 4)
36123 ranu 253
                        <img src="../../../resources/images/clock.png" style="width: 22px;">
36101 ranu 254
                    #else
36124 ranu 255
                        <img src="../../../resources/images/clock.png" style="width: 22px;">
36101 ranu 256
                    #end
257
                </td>
36112 ranu 258
                <td>$model.getRbmName()</td>
36101 ranu 259
                <td>
36112 ranu 260
                    #set($ratingData = $rbmNameToRatingMap.get($model.getRbmName()))
261
                    #set($rank = $rbmCombinedRankMap.get($model.getRbmName()))
262
                    #if($ratingData && $ratingData.getRating())
263
                        #set($rating = $ratingData.getRating())
264
                        <div style="line-height: 1.2;">
265
                            #if($rating && $rating > 0 && $rating <= 1)
266
                                <b style="color: goldenrod; font-size: 12px;">&#9733;</b>
267
                            #elseif($rating && $rating > 1 && $rating <= 2)
268
                                <b style="color: goldenrod; font-size: 12px;">&#9733;&#9733;</b>
269
                            #elseif($rating && $rating > 2 && $rating <= 3)
270
                                <b style="color: goldenrod; font-size: 12px;">&#9733;&#9733;&#9733;</b>
271
                            #elseif($rating && $rating > 3 && $rating <= 4)
272
                                <b style="color: goldenrod; font-size: 12px;">&#9733;&#9733;&#9733;&#9733;</b>
273
                            #elseif($rating && $rating > 4 && $rating <= 5)
274
                                <b style="color: goldenrod; font-size: 12px;">&#9733;&#9733;&#9733;&#9733;&#9733;</b>
275
                            #end
276
                            <br>
277
                            <span style="font-size: 10px; color: #555;">#$rank | $ratingData.getPartnerCount() rated</span>
278
                        </div>
36101 ranu 279
                    #else
280
                        -
281
                    #end
282
                </td>
35879 ranu 283
                <td class="agent-status-cell" data-authid="$model.getAuthId()">
35852 ranu 284
                    #if($agentStatus && $agentStatus.getAgentStatus())
285
                        #if($agentStatus.getAgentStatus() == "On Call")
286
                            <span class="badge" style="background-color: #28a745; color: white;">$agentStatus.getAgentStatus()</span>
287
                        #elseif($agentStatus.getAgentStatus() == "Available")
35994 ranu 288
                            <span class="badge"
289
                                  style="background-color: #dc3545; color: white;">$agentStatus.getAgentStatus()</span>
290
                        #elseif($agentStatus.getAgentStatus().toLowerCase().contains("break"))
291
                            <span class="badge"
36057 ranu 292
                                  style="background-color: #fd7e14; color: white;">$agentStatus.getAgentStatus()</span>
35852 ranu 293
                        #elseif($agentStatus.getAgentStatus() == "Logged Out")
36057 ranu 294
                            <span class="badge"
295
                                  style="background-color: #6c757d; color: white;">$agentStatus.getAgentStatus()</span>
35852 ranu 296
                        #elseif($agentStatus.getAgentStatus() == "Trying")
36057 ranu 297
                            <span class="badge"
298
                                  style="background-color: #ffc107; color: black;">$agentStatus.getAgentStatus()</span>
35852 ranu 299
                        #else
300
                            <span class="badge" style="background-color: #6c757d; color: white;">$agentStatus.getAgentStatus()</span>
301
                        #end
302
                    #else
303
                        <span class="badge" style="background-color: #6c757d; color: white;">-</span>
304
                    #end
305
                </td>
306
                <td class="time-in-status-cell" data-authid="$model.getAuthId()">
307
                    #if($agentStatus && $agentStatus.getTimeInStatus())
308
                        $agentStatus.getTimeInStatus()
309
                    #else
310
                        -
311
                    #end
35879 ranu 312
                </td>
36179 ranu 313
                <td style="background-color: #e7f1ff;">
314
                    #if($loginTimeByAuthId && $loginTimeByAuthId.get($model.getAuthId()))
315
                        $loginTimeByAuthId.get($model.getAuthId())
316
                    #else
317
                        -
318
                    #end
319
                </td>
320
                <td style="background-color: #d4edda;">
321
                    #if($onCallTimeByAuthId && $onCallTimeByAuthId.get($model.getAuthId()))
322
                        $onCallTimeByAuthId.get($model.getAuthId())
323
                    #else
324
                        -
325
                    #end
326
                </td>
327
                <td style="background-color: #f8d7da;">
328
                    #if($availableTimeByAuthId && $availableTimeByAuthId.get($model.getAuthId()))
329
                        $availableTimeByAuthId.get($model.getAuthId())
330
                    #else
331
                        -
332
                    #end
333
                </td>
334
                <td style="background-color: #ffe5cc;">
335
                    #if($breakTimeByAuthId && $breakTimeByAuthId.get($model.getAuthId()))
336
                        $breakTimeByAuthId.get($model.getAuthId())
337
                    #else
338
                        -
339
                    #end
340
                </td>
35631 ranu 341
                <td>$model.getPartnerCount()</td>
342
                <td>
343
                    #if($arrAchievedByAuthId && $arrAchievedByAuthId.get($model.getAuthId()))
35636 ranu 344
                        <span class="lakh">$arrAchievedByAuthId.get($model.getAuthId())</span>
35631 ranu 345
                    #else
346
 
347
                    #end
348
                    /
349
                    #if($arrTargetByAuthId && $arrTargetByAuthId.get($model.getAuthId()))
35636 ranu 350
                        <span class="lakh">$arrTargetByAuthId.get($model.getAuthId())</span>
35631 ranu 351
                    #else
352
 
353
                    #end
354
                </td>
355
                <td class="highlight-target">$rowTarget</td>
35670 ranu 356
                <td class="highlight-achieved currency">
35953 ranu 357
                    <span class="clickable"
358
                          onclick="showCalledPartnerDetails($model.getAuthId(), '$model.getRbmName()')">$rowAchieved</span>
35670 ranu 359
                </td>
35631 ranu 360
                <td class="highlight-plan-today">$model.getPlanToday()</td>
361
                <td class="highlight-carry-forward">$model.getCarryForward()</td>
362
                <td>$model.getZeroBilling()</td>
363
                <td class="highlight-untouched">$model.getUntouched()</td>
364
                <td class="highlight-future-plan">$model.getFuturePlan()</td>
365
                <td>$model.getNormal()</td>
366
                <td class="highlight-oos" style="color: red;">
367
                    #if($model.getOutOfSequenceCount() > 0)
368
                        <span class="clickable" style="color: #e80404"
369
                              onclick="showOutOfSequenceDetails($model.getAuthId(), '$model.getRbmName()')">$model.getOutOfSequenceCount()</span>
370
                    #else
371
 
372
                    #end
373
                </td>
374
            </tr>
375
            #end
376
        </tbody>
377
    </table>
378
</div>
379
 
35953 ranu 380
<!-- Modal for Called Partner Details with Tabs -->
381
<div class="modal fade" id="calledModal" tabindex="-1" role="dialog" aria-labelledby="calledModalLabel"
382
     aria-hidden="true">
383
    <div class="modal-dialog modal-lg" role="document" style="max-width: 90%;">
384
        <div class="modal-content">
385
            <div class="modal-header">
386
                <h5 class="modal-title" id="calledModalLabel">Called Partners</h5>
387
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
388
                    <span aria-hidden="true">&times;</span>
389
                </button>
390
            </div>
391
            <div class="modal-body">
392
                <!-- Tabs Navigation -->
393
                <ul class="nav nav-tabs" id="calledModalTabs" role="tablist">
394
                    <li class="nav-item">
395
                        <a class="nav-link active" id="called-tab" data-toggle="tab" href="#calledTabContent"
396
                           role="tab">
397
                            Called Partners
398
                        </a>
399
                    </li>
400
                    <li class="nav-item">
401
                        <a class="nav-link" id="break-time-tab" data-toggle="tab" href="#breakTimeTabContent"
402
                           role="tab">
403
                            Break Time
404
                        </a>
405
                    </li>
406
                </ul>
407
                <!-- Tabs Content -->
408
                <div class="tab-content mt-3" id="calledModalTabContent">
409
                    <div class="tab-pane fade show active" id="calledTabContent" role="tabpanel">
410
                        <div id="calledDetailsContent">
411
                            <p>Loading...</p>
412
                        </div>
413
                    </div>
414
                    <div class="tab-pane fade" id="breakTimeTabContent" role="tabpanel">
415
                        <div id="breakTimeDetailsContent">
416
                            <p>Click on Break Time tab to load data.</p>
417
                        </div>
418
                    </div>
419
                </div>
420
            </div>
421
            <div class="modal-footer">
422
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
423
            </div>
424
        </div>
425
    </div>
426
</div>
427
 
428
<!-- Modal for Out of Sequence Details -->
429
<div class="modal fade" id="oosModal" tabindex="-1" role="dialog" aria-labelledby="oosModalLabel"
430
     aria-hidden="true">
431
    <div class="modal-dialog modal-lg" role="document">
432
        <div class="modal-content">
433
            <div class="modal-header">
434
                <h5 class="modal-title" id="oosModalLabel">Out of Sequence Calls</h5>
435
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
436
                    <span aria-hidden="true">&times;</span>
437
                </button>
438
            </div>
439
            <div class="modal-body">
440
                <div id="oosDetailsContent">
441
                    <p>Loading...</p>
442
                </div>
443
            </div>
444
            <div class="modal-footer">
445
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
446
            </div>
447
        </div>
448
    </div>
449
</div>
450
 
35631 ranu 451
<script type="text/javascript">
35984 ranu 452
    // Store current authId and agentName for break time loading
35953 ranu 453
    var currentModalAuthId = null;
454
    var currentModalDate = null;
35984 ranu 455
    var currentModalAgentName = null;
35953 ranu 456
 
35638 ranu 457
    document.addEventListener('DOMContentLoaded', function () {
458
        var elems = document.querySelectorAll('.lakh');
459
        for (var i = 0; i < elems.length; i++) {
460
            var val = parseInt(elems[i].textContent.trim());
35636 ranu 461
            if (!isNaN(val)) {
35638 ranu 462
                elems[i].textContent = (val / 100000).toFixed(1) + 'L';
35636 ranu 463
            }
35638 ranu 464
        }
35636 ranu 465
    });
466
 
35631 ranu 467
    function showOutOfSequenceDetails(authId, rbmName) {
468
        document.getElementById('oosModalLabel').textContent = 'Out of Sequence Calls - ' + rbmName;
469
        document.getElementById('oosDetailsContent').innerHTML = '<p>Loading...</p>';
470
        $('#oosModal').modal('show');
471
 
472
        fetch('/indent/rbm_call_target/oos_details?authId=' + authId)
473
                .then(function (response) {
474
                    return response.json();
475
                })
476
                .then(function (data) {
477
                    if (data && data.length > 0) {
478
                        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>';
479
                        for (var i = 0; i < data.length; i++) {
480
                            html += '<tr><td>' + (i + 1) + '</td><td>' + data[i].partyName + '</td><td>' + data[i].code + '</td><td>' + data[i].time + '</td></tr>';
481
                        }
482
                        html += '</tbody></table>';
483
                        document.getElementById('oosDetailsContent').innerHTML = html;
484
                    } else {
485
                        document.getElementById('oosDetailsContent').innerHTML = '<p>No out of sequence calls found.</p>';
486
                    }
487
                })
488
                .catch(function () {
489
                    document.getElementById('oosDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
490
                });
491
    }
35670 ranu 492
 
493
    function showCalledPartnerDetails(authId, rbmName) {
35984 ranu 494
        // Store authId and agentName for break time tab
35953 ranu 495
        currentModalAuthId = authId;
496
        currentModalDate = null;
35984 ranu 497
        currentModalAgentName = rbmName;
35953 ranu 498
 
499
        document.getElementById('calledModalLabel').textContent = 'Activity - ' + rbmName;
35670 ranu 500
        document.getElementById('calledDetailsContent').innerHTML = '<p>Loading...</p>';
35953 ranu 501
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Click to load break time data.</p>';
502
 
503
        // Reset to Called tab
504
        $('#called-tab').tab('show');
505
 
35670 ranu 506
        $('#calledModal').modal('show');
507
 
35984 ranu 508
        fetch('/indent/rbm_call_target/called_details?authId=' + authId + '&agentName=' + encodeURIComponent(rbmName))
35670 ranu 509
                .then(function (response) {
510
                    return response.json();
511
                })
512
                .then(function (data) {
513
                    if (data && data.length > 0) {
35763 ranu 514
                        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 515
                        for (var i = 0; i < data.length; i++) {
35984 ranu 516
                            var rowStyle = '';
35703 ranu 517
                            var recordingHtml = '-';
35984 ranu 518
 
519
                            // Check if this is a break log entry
520
                            if (data[i].breakLog) {
36097 ranu 521
                                var status = (data[i].breakStatus || '').toLowerCase();
522
                                if (status.indexOf('available') >= 0) {
36099 ranu 523
                                    rowStyle = 'style="background-color: #f8d7da; color: #721c24;"'; // Light red
36097 ranu 524
                                } else if (status.indexOf('trying') >= 0) {
525
                                    rowStyle = 'style="background-color: #fff3cd; color: #856404;"'; // Light yellow
526
                                } else if (status.indexOf('logged out') >= 0 || status.indexOf('logout') >= 0) {
527
                                    rowStyle = 'style="background-color: #e2e3e5; color: #383d41;"'; // Light grey
528
                                } else if (status.indexOf('break') >= 0) {
529
                                    rowStyle = 'style="background-color: #ffe5cc; color: #c45200;"'; // Light orange
530
                                } else {
531
                                    rowStyle = 'style="background-color: #f8f9fa; color: #333;"'; // Default light
532
                                }
36098 ranu 533
                                var timeRange = data[i].callDateTime || '-';
534
                                if (data[i].breakEndTime) {
535
                                    // Extract just the time part from callDateTime and show range
536
                                    var startTime = timeRange.split(' ').slice(-2).join(' '); // Get "hh:mm AM/PM"
537
                                    timeRange = startTime + ' to ' + data[i].breakEndTime;
538
                                }
539
                                html += '<tr ' + rowStyle + '><td>' + (i + 1) + '</td><td colspan="4"><i class="fa fa-coffee"></i> ' + (data[i].breakStatus || 'On Break') + '</td><td>' + (data[i].callDuration || '-') + '</td><td>' + timeRange + '</td><td>-</td></tr>';
35984 ranu 540
                            } else {
541
                                if (data[i].recordingUrl) {
542
                                    recordingHtml = '<audio controls style="width: 150px; height: 30px;"><source src="' + data[i].recordingUrl + '" type="audio/mpeg">Your browser does not support audio.</audio>';
543
                                }
544
                                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 545
                            }
35670 ranu 546
                        }
547
                        html += '</tbody></table>';
548
                        document.getElementById('calledDetailsContent').innerHTML = html;
549
                    } else {
550
                        document.getElementById('calledDetailsContent').innerHTML = '<p>No called partners found.</p>';
551
                    }
552
                })
553
                .catch(function () {
554
                    document.getElementById('calledDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
555
                });
556
    }
35730 ranu 557
 
35953 ranu 558
    // Load break time data when tab is clicked
559
    document.addEventListener('DOMContentLoaded', function () {
560
        var breakTimeTab = document.getElementById('break-time-tab');
561
        if (breakTimeTab) {
562
            breakTimeTab.addEventListener('shown.bs.tab', loadBreakTimeData);
563
            breakTimeTab.addEventListener('click', function () {
564
                // For Bootstrap 4 compatibility
565
                setTimeout(loadBreakTimeData, 100);
566
            });
567
        }
568
    });
569
 
570
    function loadBreakTimeData() {
571
        if (!currentModalAuthId) {
572
            return;
573
        }
574
 
575
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Loading break time data...</p>';
576
 
577
        var url = '/indent/rbm_call_target/break_time_details?authId=' + currentModalAuthId;
578
        if (currentModalDate) {
579
            url += '&date=' + currentModalDate;
580
        }
35984 ranu 581
        if (currentModalAgentName) {
582
            url += '&agentName=' + encodeURIComponent(currentModalAgentName);
583
        }
35953 ranu 584
 
585
        fetch(url)
586
                .then(function (response) {
587
                    return response.json();
588
                })
589
                .then(function (data) {
590
                    var html = '';
591
 
36086 ranu 592
                    // 4 Summary boxes in a row
593
                    html += '<div class="row">';
35953 ranu 594
 
36086 ranu 595
                    // Available Box - Green
596
                    html += '<div class="col-md-3 col-sm-6 mb-3">';
597
                    html += '<div class="card text-white bg-success">';
598
                    html += '<div class="card-body text-center">';
599
                    html += '<h5 class="card-title">Available</h5>';
600
                    html += '<h3 class="mb-0">' + (data.totalAvailableTime || '0h 0m 0s') + '</h3>';
601
                    html += '<small>(' + (data.availableCount || 0) + ' times)</small>';
602
                    html += '</div></div></div>';
35953 ranu 603
 
36086 ranu 604
                    // Trying Box - Yellow
605
                    html += '<div class="col-md-3 col-sm-6 mb-3">';
606
                    html += '<div class="card text-dark bg-warning">';
607
                    html += '<div class="card-body text-center">';
608
                    html += '<h5 class="card-title">Trying</h5>';
609
                    html += '<h3 class="mb-0">' + (data.totalTryingTime || '0h 0m 0s') + '</h3>';
610
                    html += '<small>(' + (data.tryingCount || 0) + ' times)</small>';
611
                    html += '</div></div></div>';
35953 ranu 612
 
36086 ranu 613
                    // Logged Out Box - Red/Grey
614
                    html += '<div class="col-md-3 col-sm-6 mb-3">';
615
                    html += '<div class="card text-white bg-secondary">';
616
                    html += '<div class="card-body text-center">';
617
                    html += '<h5 class="card-title">Logged Out</h5>';
618
                    html += '<h3 class="mb-0">' + (data.totalLoggedOutTime || '0h 0m 0s') + '</h3>';
619
                    html += '<small>(' + (data.loggedOutCount || 0) + ' times)</small>';
620
                    html += '</div></div></div>';
621
 
622
                    // Break Box - Orange
623
                    html += '<div class="col-md-3 col-sm-6 mb-3">';
624
                    html += '<div class="card text-dark" style="background-color: #fd7e14;">';
625
                    html += '<div class="card-body text-center">';
626
                    html += '<h5 class="card-title">Break</h5>';
627
                    html += '<h3 class="mb-0">' + (data.totalBreakTime || '0h 0m 0s') + '</h3>';
628
                    html += '<small>(' + (data.breakCount || 0) + ' times)</small>';
629
                    html += '</div></div></div>';
630
 
631
                    html += '</div>';
632
 
36179 ranu 633
                    // Second row: On Call, Total Login Time, Total On Call Time
634
                    html += '<div class="row">';
635
 
636
                    // On Call Box - Dark Green
637
                    html += '<div class="col-md-4 col-sm-6 mb-3">';
638
                    html += '<div class="card text-white" style="background-color: #28a745;">';
639
                    html += '<div class="card-body text-center">';
640
                    html += '<h5 class="card-title"><i class="fa fa-phone"></i> On Call</h5>';
641
                    html += '<h3 class="mb-0">' + (data.totalOnCallTime || '0h 0m 0s') + '</h3>';
642
                    html += '<small>(From Call Logs)</small>';
643
                    html += '</div></div></div>';
644
 
645
                    // Total Login Time Box - Blue
646
                    html += '<div class="col-md-4 col-sm-6 mb-3">';
647
                    html += '<div class="card text-white bg-primary">';
648
                    html += '<div class="card-body text-center">';
649
                    html += '<h5 class="card-title"><i class="fa fa-sign-in-alt"></i> Total Login Time</h5>';
650
                    html += '<h3 class="mb-0">' + (data.totalLoginTime || '0h 0m 0s') + '</h3>';
651
                    html += '<small>(Available + Trying + Break + On Call)</small>';
652
                    html += '</div></div></div>';
653
 
654
                    // Total Idle Time Box - Red
655
                    html += '<div class="col-md-4 col-sm-6 mb-3">';
656
                    html += '<div class="card text-white bg-danger">';
657
                    html += '<div class="card-body text-center">';
658
                    html += '<h5 class="card-title"><i class="fa fa-clock"></i> Total Idle Time</h5>';
659
                    html += '<h3 class="mb-0">' + (data.totalAvailableTime || '0h 0m 0s') + '</h3>';
660
                    html += '<small>(Available - Not on call)</small>';
661
                    html += '</div></div></div>';
662
 
663
                    html += '</div>';
664
 
36086 ranu 665
                    // Check if no data
666
                    if ((data.totalAvailableSeconds || 0) + (data.totalTryingSeconds || 0) +
36179 ranu 667
                            (data.totalLoggedOutSeconds || 0) + (data.totalBreakSeconds || 0) +
668
                            (data.totalOnCallSeconds || 0) === 0) {
36086 ranu 669
                        html += '<p class="text-muted text-center mt-3">No break time data available for this date.</p>';
35953 ranu 670
                    }
671
 
672
                    document.getElementById('breakTimeDetailsContent').innerHTML = html;
673
                })
674
                .catch(function (err) {
675
                    console.error('Error loading break time:', err);
676
                    document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Error loading break time data. Please try again.</p>';
677
                });
678
    }
679
 
35730 ranu 680
    // Date-wise Called Partner History
681
    function showHistoryCalledPartners() {
682
        var selectedDate = document.getElementById('historyDate').value;
683
        var selectedRbm = document.getElementById('historyRbm');
684
        var authId = selectedRbm.value;
685
        var rbmName = selectedRbm.options[selectedRbm.selectedIndex].text;
686
 
687
        if (!selectedDate) {
688
            alert('Please select a date');
689
            return;
690
        }
691
        if (!authId) {
692
            alert('Please select an RBM');
693
            return;
694
        }
695
 
35984 ranu 696
        // Store authId, date and agentName for break time tab
35953 ranu 697
        currentModalAuthId = authId;
698
        currentModalDate = selectedDate;
35984 ranu 699
        currentModalAgentName = rbmName;
35953 ranu 700
 
701
        document.getElementById('calledModalLabel').textContent = 'Activity - ' + rbmName + ' (' + selectedDate + ')';
35730 ranu 702
        document.getElementById('calledDetailsContent').innerHTML = '<p>Loading...</p>';
35953 ranu 703
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Click to load break time data.</p>';
704
 
705
        // Reset to Called tab
706
        $('#called-tab').tab('show');
707
 
35730 ranu 708
        $('#calledModal').modal('show');
709
 
35984 ranu 710
        fetch('/indent/rbm_call_target/called_details?authId=' + authId + '&date=' + selectedDate + '&agentName=' + encodeURIComponent(rbmName))
35730 ranu 711
                .then(function (response) {
712
                    return response.json();
713
                })
714
                .then(function (data) {
715
                    if (data && data.length > 0) {
35763 ranu 716
                        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 717
                        for (var i = 0; i < data.length; i++) {
35984 ranu 718
                            var rowStyle = '';
35730 ranu 719
                            var recordingHtml = '-';
35984 ranu 720
 
721
                            // Check if this is a break log entry
722
                            if (data[i].breakLog) {
36097 ranu 723
                                var status = (data[i].breakStatus || '').toLowerCase();
724
                                if (status.indexOf('available') >= 0) {
36099 ranu 725
                                    rowStyle = 'style="background-color: #f8d7da; color: #721c24;"'; // Light red
36097 ranu 726
                                } else if (status.indexOf('trying') >= 0) {
727
                                    rowStyle = 'style="background-color: #fff3cd; color: #856404;"'; // Light yellow
728
                                } else if (status.indexOf('logged out') >= 0 || status.indexOf('logout') >= 0) {
729
                                    rowStyle = 'style="background-color: #e2e3e5; color: #383d41;"'; // Light grey
730
                                } else if (status.indexOf('break') >= 0) {
731
                                    rowStyle = 'style="background-color: #ffe5cc; color: #c45200;"'; // Light orange
732
                                } else {
733
                                    rowStyle = 'style="background-color: #f8f9fa; color: #333;"'; // Default light
734
                                }
36098 ranu 735
                                var timeRange = data[i].callDateTime || '-';
736
                                if (data[i].breakEndTime) {
737
                                    // Extract just the time part from callDateTime and show range
738
                                    var startTime = timeRange.split(' ').slice(-2).join(' '); // Get "hh:mm AM/PM"
739
                                    timeRange = startTime + ' to ' + data[i].breakEndTime;
740
                                }
741
                                html += '<tr ' + rowStyle + '><td>' + (i + 1) + '</td><td colspan="4"><i class="fa fa-coffee"></i> ' + (data[i].breakStatus || 'On Break') + '</td><td>' + (data[i].callDuration || '-') + '</td><td>' + timeRange + '</td><td>-</td></tr>';
35984 ranu 742
                            } else {
743
                                if (data[i].recordingUrl) {
744
                                    recordingHtml = '<audio controls style="width: 150px; height: 30px;"><source src="' + data[i].recordingUrl + '" type="audio/mpeg">Your browser does not support audio.</audio>';
745
                                }
746
                                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 747
                            }
748
                        }
749
                        html += '</tbody></table>';
750
                        document.getElementById('calledDetailsContent').innerHTML = html;
751
                    } else {
752
                        document.getElementById('calledDetailsContent').innerHTML = '<p>No called partners found for selected date.</p>';
753
                    }
754
                })
755
                .catch(function () {
756
                    document.getElementById('calledDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
757
                });
758
    }
35852 ranu 759
 
760
    // Auto-refresh agent status every 30 seconds
761
    function refreshAgentStatus() {
762
        fetch('/indent/rbm_call_target/get_agent_statuses')
35879 ranu 763
                .then(function (response) {
764
                    return response.json();
765
                })
766
                .then(function (data) {
767
                    if (data && data.length > 0) {
768
                        for (var i = 0; i < data.length; i++) {
769
                            var agent = data[i];
770
                            var statusCell = document.querySelector('.agent-status-cell[data-authid="' + agent.authId + '"]');
771
                            var timeCell = document.querySelector('.time-in-status-cell[data-authid="' + agent.authId + '"]');
35852 ranu 772
 
35879 ranu 773
                            if (statusCell) {
774
                                var statusHtml = getStatusBadge(agent.agentStatus);
775
                                statusCell.innerHTML = statusHtml;
776
                            }
777
                            if (timeCell) {
778
                                timeCell.textContent = agent.timeInStatus || '-';
779
                            }
35852 ranu 780
                        }
781
                    }
35879 ranu 782
                })
783
                .catch(function (err) {
784
                    console.error('Error refreshing agent status:', err);
785
                });
35852 ranu 786
    }
787
 
788
    function getStatusBadge(status) {
789
        if (!status) return '<span class="badge" style="background-color: #6c757d; color: white;">-</span>';
790
 
791
        var bgColor = '#6c757d';
792
        var textColor = 'white';
35994 ranu 793
        var lowerStatus = status.toLowerCase();
35852 ranu 794
 
795
        if (status === 'On Call') {
796
            bgColor = '#28a745';
797
        } else if (status === 'Available') {
35994 ranu 798
            bgColor = '#dc3545';
799
        } else if (lowerStatus.indexOf('break') !== -1) {
36057 ranu 800
            bgColor = '#fd7e14';  // Orange for break
35852 ranu 801
        } else if (status === 'Logged Out') {
36057 ranu 802
            bgColor = '#6c757d';  // Grey for logged out
35852 ranu 803
        } else if (status === 'Trying') {
36057 ranu 804
            bgColor = '#ffc107';  // Yellow for trying
805
            textColor = 'black';
35852 ranu 806
        }
807
 
808
        return '<span class="badge" style="background-color: ' + bgColor + '; color: ' + textColor + ';">' + status + '</span>';
809
    }
810
 
36057 ranu 811
    // Refresh every 10 seconds
812
    setInterval(refreshAgentStatus, 10000);
35852 ranu 813
 
814
    // Initial refresh after page load
815
    setTimeout(refreshAgentStatus, 2000);
816
 
817
    // Download All Call Data by Date
818
    function downloadCallData() {
819
        var selectedDate = document.getElementById('downloadDate').value;
820
        if (!selectedDate) {
821
            alert('Please select a date');
822
            return;
823
        }
824
        window.location.href = '/indent/rbm_call_target/download_call_data?date=' + selectedDate;
825
    }
35631 ranu 826
</script>