Subversion Repositories SmartDukaan

Rev

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