Subversion Repositories SmartDukaan

Rev

Rev 36229 | Rev 36235 | 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">
36234 ranu 102
    <div class="d-flex align-items-center mb-2">
103
        <h3 class="mb-0 mr-3">RBM Call Target Summary</h3>
104
        <div class="d-flex align-items-center">
105
            <label for="filterDate" class="mb-0 mr-2" style="font-size: 14px; white-space: nowrap;">Date:</label>
106
            <input type="date" id="filterDate" class="form-control form-control-sm mr-2" style="width: 150px;"
107
                   value="$queryDate">
108
            <button type="button" class="btn btn-primary btn-sm" onclick="filterByDate()">Go</button>
109
        </div>
110
    </div>
35852 ranu 111
    <div class="row">
112
        <div class="col-md-7">
113
            <!-- Date-wise Called Partner Filter -->
114
            <div class="card mb-3" style="max-width: 500px;">
115
                <div class="card-body py-2">
116
                    <div class="d-flex align-items-center">
117
                        <label for="historyDate" class="mb-0 mr-2"
118
                               style="font-size: 14px; white-space: nowrap;">Date:</label>
119
                        <input type="date" id="historyDate" class="form-control form-control-sm mr-2"
120
                               style="width: 140px;">
121
                        <label for="historyRbm" class="mb-0 mr-2"
122
                               style="font-size: 14px; white-space: nowrap;">RBM:</label>
123
                        <select id="historyRbm" class="form-control form-control-sm mr-2" style="width: 150px;">
124
                            <option value="">Select RBM</option>
125
                            #foreach($model in $rbmCallTargetModels)
126
                                <option value="$model.getAuthId()">$model.getRbmName()</option>
127
                            #end
128
                        </select>
129
                        <button type="button" class="btn btn-primary btn-sm" onclick="showHistoryCalledPartners()">
130
                            View
131
                        </button>
132
                    </div>
133
                </div>
35730 ranu 134
            </div>
135
        </div>
35852 ranu 136
        <div class="col-md-5">
137
            <!-- Download All Call Data by Date -->
138
            <div class="card mb-3" style="max-width: 450px;">
139
                <div class="card-body py-2">
140
                    <div class="d-flex align-items-center">
141
                        <label for="downloadDate" class="mb-0 mr-2" style="font-size: 14px; white-space: nowrap;">Download
142
                            Call Data:</label>
143
                        <input type="date" id="downloadDate" class="form-control form-control-sm mr-2"
144
                               style="width: 140px;">
145
                        <button type="button" class="btn btn-success btn-sm" onclick="downloadCallData()">Download CSV
146
                        </button>
147
                    </div>
148
                </div>
149
            </div>
150
 
151
        </div>
35730 ranu 152
    </div>
153
 
35852 ranu 154
 
35631 ranu 155
    <table id="rbm-call-target-table" class="table table-bordered table-striped">
156
        <thead>
157
        <tr>
36112 ranu 158
            <th colspan="2">RBM Name</th>
36101 ranu 159
            <th style="background-color: #ffc107; color: black;">Rating</th>
35879 ranu 160
            <th style="background-color: #17a2b8; color: white;">Agent Status</th>
161
            <th style="background-color: #17a2b8; color: white;">Time in Status</th>
36179 ranu 162
            <th style="background-color: #007bff; color: white;"><i class="fa fa-clock"></i> Login</th>
163
            <th style="background-color: #28a745; color: white;"><i class="fa fa-phone"></i> On Call</th>
164
            <th style="background-color: #dc3545; color: white;"><i class="fa fa-user-clock"></i> Idle</th>
165
            <th style="background-color: #fd7e14; color: white;"><i class="fa fa-coffee"></i> Break</th>
35631 ranu 166
            <th>Partner Count</th>
35645 ranu 167
            <th>(Ach/Tgt)</th>
35631 ranu 168
            <th>Calling Target</th>
169
            <th>Called</th>
170
            <th class="highlight-plan-today">Plan Today</th>
171
            <th class="highlight-carry-forward">Carry Forward</th>
172
            <th style="background-color: #1e6e0e; color: white;">Zero Billing</th>
173
            <th class="highlight-untouched">Untouched</th>
174
            <th class="highlight-future-plan">Future Plan</th>
175
            <th>Normal</th>
36182 ranu 176
            <th style="background-color: #8e44ad; color: white;">Revival</th>
35631 ranu 177
            <th style="background-color: #c0392b;">Out of Sequence</th>
178
        </tr>
179
        </thead>
180
        <tbody>
181
            #set($totalPartnerCount = 0)
182
            #set($totalTodayTarget = 0)
183
            #set($totalValueAchieved = 0)
184
            #set($totalMovedToFuture = 0)
185
            #set($totalPlanToday = 0)
186
            #set($totalCarryForward = 0)
187
            #set($totalZeroBilling = 0)
188
            #set($totalUntouched = 0)
189
            #set($totalFuturePlan = 0)
190
            #set($totalNormal = 0)
36182 ranu 191
            #set($totalRevival = 0)
35631 ranu 192
            #set($totalOutOfSequence = 0)
193
            #set($totalL2CallingList = 0)
36210 ranu 194
            #set($totalL3CallingList = 0)
35631 ranu 195
            #set($totalArrAchieved = 0)
196
            #set($totalArrTarget = 0)
197
 
198
            ## Total row first
199
            #foreach($model in $rbmCallTargetModels)
36228 ranu 200
                #if(!$model.isL3Position())
35662 ranu 201
                    #set($totalPartnerCount = $totalPartnerCount + $model.getPartnerCount())
202
                #end
35631 ranu 203
                #set($totalTodayTarget = $totalTodayTarget + $model.getTodayTargetOfCall())
204
                #set($totalValueAchieved = $totalValueAchieved + $model.getValueTargetAchieved())
205
                #set($totalMovedToFuture = $totalMovedToFuture + $model.getMovedToFuture())
206
                #set($totalPlanToday = $totalPlanToday + $model.getPlanToday())
207
                #set($totalCarryForward = $totalCarryForward + $model.getCarryForward())
208
                #set($totalZeroBilling = $totalZeroBilling + $model.getZeroBilling())
209
                #set($totalUntouched = $totalUntouched + $model.getUntouched())
210
                #set($totalFuturePlan = $totalFuturePlan + $model.getFuturePlan())
211
                #set($totalNormal = $totalNormal + $model.getNormal())
36182 ranu 212
                #set($totalRevival = $totalRevival + $model.getRevival())
35631 ranu 213
                #set($totalOutOfSequence = $totalOutOfSequence + $model.getOutOfSequenceCount())
214
                #set($totalL2CallingList = $totalL2CallingList + $model.getL2CallingList())
36210 ranu 215
                #set($totalL3CallingList = $totalL3CallingList + $model.getL3CallingList())
35631 ranu 216
                #if($arrAchievedByAuthId && $arrAchievedByAuthId.get($model.getAuthId()))
217
                    #set($totalArrAchieved = $totalArrAchieved + $arrAchievedByAuthId.get($model.getAuthId()))
218
                #end
219
                #if($arrTargetByAuthId && $arrTargetByAuthId.get($model.getAuthId()))
220
                    #set($totalArrTarget = $totalArrTarget + $arrTargetByAuthId.get($model.getAuthId()))
221
                #end
222
            #end
223
 
224
            #set($adjustedTotalTarget = $totalTodayTarget + $totalMovedToFuture)
225
            #set($adjustedTotalAchieved = $totalValueAchieved + $totalMovedToFuture)
226
 
227
        <tr>
36112 ranu 228
            <td colspan="2"><strong>TOTAL</strong></td>
35879 ranu 229
            <td>-</td>
230
            <td>-</td>
36101 ranu 231
            <td>-</td>
36179 ranu 232
            <td>-</td>
233
            <td>-</td>
234
            <td>-</td>
235
            <td>-</td>
35631 ranu 236
            <td><strong>$totalPartnerCount</strong></td>
35636 ranu 237
            <td><strong><span class="lakh">$totalArrAchieved</span> / <span class="lakh">$totalArrTarget</span></strong>
35631 ranu 238
            </td>
36229 ranu 239
            <td class="highlight-target">
240
                #if($totalL2CallingList > 0)
241
                    #set($totalL1OwnTarget = $adjustedTotalTarget - $totalL2CallingList)
242
                    <strong>${totalL1OwnTarget} + <span style="color: #e67e22;">$totalL2CallingList</span></strong>
243
                #else
244
                    <strong>$adjustedTotalTarget</strong>
245
                #end
246
            </td>
35631 ranu 247
            <td class="highlight-achieved currency"><strong>$adjustedTotalAchieved</strong></td>
248
            <td class="highlight-plan-today"><strong>$totalPlanToday</strong></td>
249
            <td class="highlight-carry-forward"><strong>$totalCarryForward</strong></td>
250
            <td><strong>$totalZeroBilling</strong></td>
251
            <td class="highlight-untouched"><strong>$totalUntouched</strong></td>
252
            <td class="highlight-future-plan"><strong>$totalFuturePlan</strong></td>
253
            <td><strong>$totalNormal</strong></td>
36182 ranu 254
            <td><strong>$totalRevival</strong></td>
35631 ranu 255
            <td class="highlight-oos"><strong>$totalOutOfSequence</strong></td>
256
        </tr>
257
 
258
            #foreach($model in $rbmCallTargetModels)
259
                #set($rowTarget = $model.getTodayTargetOfCall() + $model.getMovedToFuture())
260
                #set($rowAchieved = $model.getValueTargetAchieved() + $model.getMovedToFuture())
35852 ranu 261
                #set($agentStatus = $agentStatusByAuthId.get($model.getAuthId()))
35631 ranu 262
            <tr>
36101 ranu 263
                <td>
36112 ranu 264
                    #set($rank = $rbmCombinedRankMap.get($model.getRbmName()))
265
                    #if($rank == 1)
36122 ranu 266
                        <img src="../../../resources/images/king.png" style="width: 35px;">
36112 ranu 267
                    #elseif($rank == 2)
36123 ranu 268
                        <img src="../../../resources/images/trophy-cup.png" style="width: 30px;">
36112 ranu 269
                    #elseif($rank == 3)
36123 ranu 270
                        <img src="../../../resources/images/bronze-medal.png" style="width: 30px;">
36112 ranu 271
                    #elseif($rank == 4)
36123 ranu 272
                        <img src="../../../resources/images/star-badge.png" style="width: 30px;">
36112 ranu 273
                    #elseif($rank && $rank > 4)
36123 ranu 274
                        <img src="../../../resources/images/clock.png" style="width: 22px;">
36101 ranu 275
                    #else
36124 ranu 276
                        <img src="../../../resources/images/clock.png" style="width: 22px;">
36101 ranu 277
                    #end
278
                </td>
36112 ranu 279
                <td>$model.getRbmName()</td>
36101 ranu 280
                <td>
36112 ranu 281
                    #set($ratingData = $rbmNameToRatingMap.get($model.getRbmName()))
282
                    #set($rank = $rbmCombinedRankMap.get($model.getRbmName()))
283
                    #if($ratingData && $ratingData.getRating())
284
                        #set($rating = $ratingData.getRating())
285
                        <div style="line-height: 1.2;">
286
                            #if($rating && $rating > 0 && $rating <= 1)
287
                                <b style="color: goldenrod; font-size: 12px;">&#9733;</b>
288
                            #elseif($rating && $rating > 1 && $rating <= 2)
289
                                <b style="color: goldenrod; font-size: 12px;">&#9733;&#9733;</b>
290
                            #elseif($rating && $rating > 2 && $rating <= 3)
291
                                <b style="color: goldenrod; font-size: 12px;">&#9733;&#9733;&#9733;</b>
292
                            #elseif($rating && $rating > 3 && $rating <= 4)
293
                                <b style="color: goldenrod; font-size: 12px;">&#9733;&#9733;&#9733;&#9733;</b>
294
                            #elseif($rating && $rating > 4 && $rating <= 5)
295
                                <b style="color: goldenrod; font-size: 12px;">&#9733;&#9733;&#9733;&#9733;&#9733;</b>
296
                            #end
297
                            <br>
298
                            <span style="font-size: 10px; color: #555;">#$rank | $ratingData.getPartnerCount() rated</span>
299
                        </div>
36101 ranu 300
                    #else
301
                        -
302
                    #end
303
                </td>
35879 ranu 304
                <td class="agent-status-cell" data-authid="$model.getAuthId()">
36234 ranu 305
                    #if($isToday)
306
                        #if($agentStatus && $agentStatus.getAgentStatus())
307
                            #if($agentStatus.getAgentStatus() == "On Call")
308
                                <span class="badge"
309
                                      style="background-color: #28a745; color: white;">$agentStatus.getAgentStatus()</span>
310
                            #elseif($agentStatus.getAgentStatus() == "Available")
311
                                <span class="badge"
312
                                      style="background-color: #dc3545; color: white;">$agentStatus.getAgentStatus()</span>
313
                            #elseif($agentStatus.getAgentStatus().toLowerCase().contains("break"))
314
                                <span class="badge"
315
                                      style="background-color: #fd7e14; color: white;">$agentStatus.getAgentStatus()</span>
316
                            #elseif($agentStatus.getAgentStatus() == "Logged Out")
317
                                <span class="badge"
318
                                      style="background-color: #6c757d; color: white;">$agentStatus.getAgentStatus()</span>
319
                            #elseif($agentStatus.getAgentStatus() == "Trying")
320
                                <span class="badge"
321
                                      style="background-color: #ffc107; color: black;">$agentStatus.getAgentStatus()</span>
322
                            #else
323
                                <span class="badge"
324
                                      style="background-color: #6c757d; color: white;">$agentStatus.getAgentStatus()</span>
325
                            #end
35852 ranu 326
                        #else
36234 ranu 327
                            <span class="badge" style="background-color: #6c757d; color: white;">-</span>
35852 ranu 328
                        #end
329
                    #else
330
                        <span class="badge" style="background-color: #6c757d; color: white;">-</span>
331
                    #end
332
                </td>
333
                <td class="time-in-status-cell" data-authid="$model.getAuthId()">
36234 ranu 334
                    #if($isToday)
335
                        #if($agentStatus && $agentStatus.getTimeInStatus())
336
                            $agentStatus.getTimeInStatus()
337
                        #else
338
                            -
339
                        #end
35852 ranu 340
                    #else
341
                        -
342
                    #end
35879 ranu 343
                </td>
36179 ranu 344
                <td style="background-color: #e7f1ff;">
345
                    #if($loginTimeByAuthId && $loginTimeByAuthId.get($model.getAuthId()))
346
                        $loginTimeByAuthId.get($model.getAuthId())
347
                    #else
348
                        -
349
                    #end
350
                </td>
351
                <td style="background-color: #d4edda;">
352
                    #if($onCallTimeByAuthId && $onCallTimeByAuthId.get($model.getAuthId()))
353
                        $onCallTimeByAuthId.get($model.getAuthId())
354
                    #else
355
                        -
356
                    #end
357
                </td>
358
                <td style="background-color: #f8d7da;">
359
                    #if($availableTimeByAuthId && $availableTimeByAuthId.get($model.getAuthId()))
360
                        $availableTimeByAuthId.get($model.getAuthId())
361
                    #else
362
                        -
363
                    #end
364
                </td>
365
                <td style="background-color: #ffe5cc;">
366
                    #if($breakTimeByAuthId && $breakTimeByAuthId.get($model.getAuthId()))
367
                        $breakTimeByAuthId.get($model.getAuthId())
368
                    #else
369
                        -
370
                    #end
371
                </td>
35631 ranu 372
                <td>$model.getPartnerCount()</td>
373
                <td>
374
                    #if($arrAchievedByAuthId && $arrAchievedByAuthId.get($model.getAuthId()))
35636 ranu 375
                        <span class="lakh">$arrAchievedByAuthId.get($model.getAuthId())</span>
35631 ranu 376
                    #else
377
 
378
                    #end
379
                    /
380
                    #if($arrTargetByAuthId && $arrTargetByAuthId.get($model.getAuthId()))
35636 ranu 381
                        <span class="lakh">$arrTargetByAuthId.get($model.getAuthId())</span>
35631 ranu 382
                    #else
383
 
384
                    #end
385
                </td>
36229 ranu 386
                <td class="highlight-target">
387
                    #if($model.isL2Position() && $model.getL2CallingList() > 0)
388
                        #set($l1OwnTarget = $rowTarget - $model.getL2CallingList())
389
                        ${l1OwnTarget} + <span style="color: #e67e22; font-weight: bold;"
390
                                               title="L2 Escalation">$model.getL2CallingList()</span>
391
                    #else
392
                        $rowTarget
393
                    #end
394
                </td>
35670 ranu 395
                <td class="highlight-achieved currency">
35953 ranu 396
                    <span class="clickable"
397
                          onclick="showCalledPartnerDetails($model.getAuthId(), '$model.getRbmName()')">$rowAchieved</span>
35670 ranu 398
                </td>
35631 ranu 399
                <td class="highlight-plan-today">$model.getPlanToday()</td>
400
                <td class="highlight-carry-forward">$model.getCarryForward()</td>
401
                <td>$model.getZeroBilling()</td>
402
                <td class="highlight-untouched">$model.getUntouched()</td>
403
                <td class="highlight-future-plan">$model.getFuturePlan()</td>
404
                <td>$model.getNormal()</td>
36182 ranu 405
                <td>$model.getRevival()</td>
35631 ranu 406
                <td class="highlight-oos" style="color: red;">
407
                    #if($model.getOutOfSequenceCount() > 0)
408
                        <span class="clickable" style="color: #e80404"
409
                              onclick="showOutOfSequenceDetails($model.getAuthId(), '$model.getRbmName()')">$model.getOutOfSequenceCount()</span>
410
                    #else
411
 
412
                    #end
413
                </td>
414
            </tr>
415
            #end
416
        </tbody>
417
    </table>
418
</div>
419
 
35953 ranu 420
<!-- Modal for Called Partner Details with Tabs -->
421
<div class="modal fade" id="calledModal" tabindex="-1" role="dialog" aria-labelledby="calledModalLabel"
422
     aria-hidden="true">
423
    <div class="modal-dialog modal-lg" role="document" style="max-width: 90%;">
424
        <div class="modal-content">
425
            <div class="modal-header">
426
                <h5 class="modal-title" id="calledModalLabel">Called Partners</h5>
427
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
428
                    <span aria-hidden="true">&times;</span>
429
                </button>
430
            </div>
431
            <div class="modal-body">
36234 ranu 432
                <div id="calledDetailsContent">
433
                    <p>Loading...</p>
35953 ranu 434
                </div>
435
            </div>
436
            <div class="modal-footer">
437
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
438
            </div>
439
        </div>
440
    </div>
441
</div>
442
 
443
<!-- Modal for Out of Sequence Details -->
444
<div class="modal fade" id="oosModal" tabindex="-1" role="dialog" aria-labelledby="oosModalLabel"
445
     aria-hidden="true">
446
    <div class="modal-dialog modal-lg" role="document">
447
        <div class="modal-content">
448
            <div class="modal-header">
449
                <h5 class="modal-title" id="oosModalLabel">Out of Sequence Calls</h5>
450
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
451
                    <span aria-hidden="true">&times;</span>
452
                </button>
453
            </div>
454
            <div class="modal-body">
455
                <div id="oosDetailsContent">
456
                    <p>Loading...</p>
457
                </div>
458
            </div>
459
            <div class="modal-footer">
460
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
461
            </div>
462
        </div>
463
    </div>
464
</div>
465
 
35631 ranu 466
<script type="text/javascript">
36234 ranu 467
    // Store globally so it persists across AJAX reloads
468
    window.pageQueryDate = '$queryDate';
469
    var pageQueryDate = window.pageQueryDate;
470
 
471
    function filterByDate() {
472
        var date = document.getElementById('filterDate').value;
473
        if (date) {
474
            var container = document.getElementById('rbm-call-target-container');
475
            if (container) {
476
                // Update global date BEFORE AJAX so click handlers use new date
477
                window.pageQueryDate = date;
478
                // AJAX reload only calling target fragment
479
                container.innerHTML = '<div class="text-center p-5"><i class="fa fa-spinner fa-spin fa-2x"></i><br/>Loading...</div>';
480
                fetch('/indent/rbm_call_target?date=' + date)
481
                        .then(function (response) {
482
                            return response.text();
483
                        })
484
                        .then(function (html) {
485
                            container.innerHTML = html;
486
                            // Re-run lakh formatting
487
                            var elems = container.querySelectorAll('.lakh');
488
                            for (var i = 0; i < elems.length; i++) {
489
                                var val = parseInt(elems[i].textContent.trim());
490
                                if (!isNaN(val)) {
491
                                    elems[i].textContent = (val / 100000).toFixed(1) + 'L';
492
                                }
493
                            }
494
                        })
495
                        .catch(function () {
496
                            container.innerHTML = '<p class="text-danger">Error loading data. Please try again.</p>';
497
                        });
498
            } else {
499
                // Standalone page — full reload
500
                window.location.href = '/indent/rbm_call_target?date=' + date;
501
            }
502
        }
503
    }
504
 
35984 ranu 505
    // Store current authId and agentName for break time loading
35953 ranu 506
    var currentModalAuthId = null;
507
    var currentModalDate = null;
35984 ranu 508
    var currentModalAgentName = null;
35953 ranu 509
 
35638 ranu 510
    document.addEventListener('DOMContentLoaded', function () {
511
        var elems = document.querySelectorAll('.lakh');
512
        for (var i = 0; i < elems.length; i++) {
513
            var val = parseInt(elems[i].textContent.trim());
35636 ranu 514
            if (!isNaN(val)) {
35638 ranu 515
                elems[i].textContent = (val / 100000).toFixed(1) + 'L';
35636 ranu 516
            }
35638 ranu 517
        }
35636 ranu 518
    });
519
 
35631 ranu 520
    function showOutOfSequenceDetails(authId, rbmName) {
521
        document.getElementById('oosModalLabel').textContent = 'Out of Sequence Calls - ' + rbmName;
522
        document.getElementById('oosDetailsContent').innerHTML = '<p>Loading...</p>';
523
        $('#oosModal').modal('show');
524
 
525
        fetch('/indent/rbm_call_target/oos_details?authId=' + authId)
526
                .then(function (response) {
527
                    return response.json();
528
                })
529
                .then(function (data) {
530
                    if (data && data.length > 0) {
531
                        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>';
532
                        for (var i = 0; i < data.length; i++) {
533
                            html += '<tr><td>' + (i + 1) + '</td><td>' + data[i].partyName + '</td><td>' + data[i].code + '</td><td>' + data[i].time + '</td></tr>';
534
                        }
535
                        html += '</tbody></table>';
536
                        document.getElementById('oosDetailsContent').innerHTML = html;
537
                    } else {
538
                        document.getElementById('oosDetailsContent').innerHTML = '<p>No out of sequence calls found.</p>';
539
                    }
540
                })
541
                .catch(function () {
542
                    document.getElementById('oosDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
543
                });
544
    }
35670 ranu 545
 
546
    function showCalledPartnerDetails(authId, rbmName) {
36234 ranu 547
        // Always use current global date (updated after AJAX reload)
548
        var currentDate = window.pageQueryDate;
35984 ranu 549
        // Store authId and agentName for break time tab
35953 ranu 550
        currentModalAuthId = authId;
36234 ranu 551
        currentModalDate = currentDate;
35984 ranu 552
        currentModalAgentName = rbmName;
35953 ranu 553
 
36234 ranu 554
        document.getElementById('calledModalLabel').textContent = 'Called Partners - ' + rbmName + ' (' + currentDate + ')';
35670 ranu 555
        document.getElementById('calledDetailsContent').innerHTML = '<p>Loading...</p>';
35953 ranu 556
 
35670 ranu 557
        $('#calledModal').modal('show');
558
 
36234 ranu 559
        var dateParam = currentDate ? '&date=' + currentDate : '';
560
        fetch('/indent/rbm_call_target/called_details?authId=' + authId + '&agentName=' + encodeURIComponent(rbmName) + dateParam)
35670 ranu 561
                .then(function (response) {
562
                    return response.json();
563
                })
564
                .then(function (data) {
36234 ranu 565
                    // Filter out break log entries — only show actual calls
566
                    var calls = (data || []).filter(function (d) {
567
                        return !d.breakLog;
568
                    });
569
                    if (calls.length > 0) {
35763 ranu 570
                        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>';
36234 ranu 571
                        for (var i = 0; i < calls.length; i++) {
35703 ranu 572
                            var recordingHtml = '-';
36234 ranu 573
                            if (calls[i].recordingUrl) {
574
                                recordingHtml = '<audio controls style="width: 150px; height: 30px;"><source src="' + calls[i].recordingUrl + '" type="audio/mpeg">Your browser does not support audio.</audio>';
35703 ranu 575
                            }
36234 ranu 576
                            html += '<tr><td>' + (i + 1) + '</td><td>' + calls[i].partyName + '</td><td>' + calls[i].code + '</td><td>' + calls[i].remark + '- &nbsp;' + (calls[i].message || '-') + '</td><td>' + (calls[i].callStatus || '-') + '</td><td>' + (calls[i].callDuration || '-') + '</td><td>' + (calls[i].callDateTime || '-') + '</td><td>' + recordingHtml + '</td></tr>';
35670 ranu 577
                        }
578
                        html += '</tbody></table>';
579
                        document.getElementById('calledDetailsContent').innerHTML = html;
580
                    } else {
581
                        document.getElementById('calledDetailsContent').innerHTML = '<p>No called partners found.</p>';
582
                    }
583
                })
584
                .catch(function () {
585
                    document.getElementById('calledDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
586
                });
587
    }
35730 ranu 588
 
35953 ranu 589
 
35730 ranu 590
    // Date-wise Called Partner History
591
    function showHistoryCalledPartners() {
592
        var selectedDate = document.getElementById('historyDate').value;
593
        var selectedRbm = document.getElementById('historyRbm');
594
        var authId = selectedRbm.value;
595
        var rbmName = selectedRbm.options[selectedRbm.selectedIndex].text;
596
 
597
        if (!selectedDate) {
598
            alert('Please select a date');
599
            return;
600
        }
601
        if (!authId) {
602
            alert('Please select an RBM');
603
            return;
604
        }
605
 
35984 ranu 606
        // Store authId, date and agentName for break time tab
35953 ranu 607
        currentModalAuthId = authId;
608
        currentModalDate = selectedDate;
35984 ranu 609
        currentModalAgentName = rbmName;
35953 ranu 610
 
611
        document.getElementById('calledModalLabel').textContent = 'Activity - ' + rbmName + ' (' + selectedDate + ')';
35730 ranu 612
        document.getElementById('calledDetailsContent').innerHTML = '<p>Loading...</p>';
35953 ranu 613
        document.getElementById('breakTimeDetailsContent').innerHTML = '<p>Click to load break time data.</p>';
614
 
615
        // Reset to Called tab
616
        $('#called-tab').tab('show');
617
 
35730 ranu 618
        $('#calledModal').modal('show');
619
 
35984 ranu 620
        fetch('/indent/rbm_call_target/called_details?authId=' + authId + '&date=' + selectedDate + '&agentName=' + encodeURIComponent(rbmName))
35730 ranu 621
                .then(function (response) {
622
                    return response.json();
623
                })
624
                .then(function (data) {
625
                    if (data && data.length > 0) {
35763 ranu 626
                        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 627
                        for (var i = 0; i < data.length; i++) {
35984 ranu 628
                            var rowStyle = '';
35730 ranu 629
                            var recordingHtml = '-';
35984 ranu 630
 
631
                            // Check if this is a break log entry
632
                            if (data[i].breakLog) {
36097 ranu 633
                                var status = (data[i].breakStatus || '').toLowerCase();
634
                                if (status.indexOf('available') >= 0) {
36099 ranu 635
                                    rowStyle = 'style="background-color: #f8d7da; color: #721c24;"'; // Light red
36097 ranu 636
                                } else if (status.indexOf('trying') >= 0) {
637
                                    rowStyle = 'style="background-color: #fff3cd; color: #856404;"'; // Light yellow
638
                                } else if (status.indexOf('logged out') >= 0 || status.indexOf('logout') >= 0) {
639
                                    rowStyle = 'style="background-color: #e2e3e5; color: #383d41;"'; // Light grey
640
                                } else if (status.indexOf('break') >= 0) {
641
                                    rowStyle = 'style="background-color: #ffe5cc; color: #c45200;"'; // Light orange
642
                                } else {
643
                                    rowStyle = 'style="background-color: #f8f9fa; color: #333;"'; // Default light
644
                                }
36098 ranu 645
                                var timeRange = data[i].callDateTime || '-';
646
                                if (data[i].breakEndTime) {
647
                                    // Extract just the time part from callDateTime and show range
648
                                    var startTime = timeRange.split(' ').slice(-2).join(' '); // Get "hh:mm AM/PM"
649
                                    timeRange = startTime + ' to ' + data[i].breakEndTime;
650
                                }
651
                                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 652
                            } else {
653
                                if (data[i].recordingUrl) {
654
                                    recordingHtml = '<audio controls style="width: 150px; height: 30px;"><source src="' + data[i].recordingUrl + '" type="audio/mpeg">Your browser does not support audio.</audio>';
655
                                }
656
                                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 657
                            }
658
                        }
659
                        html += '</tbody></table>';
660
                        document.getElementById('calledDetailsContent').innerHTML = html;
661
                    } else {
662
                        document.getElementById('calledDetailsContent').innerHTML = '<p>No called partners found for selected date.</p>';
663
                    }
664
                })
665
                .catch(function () {
666
                    document.getElementById('calledDetailsContent').innerHTML = '<p>Error loading details. Please try again.</p>';
667
                });
668
    }
35852 ranu 669
 
670
    // Auto-refresh agent status every 30 seconds
671
    function refreshAgentStatus() {
672
        fetch('/indent/rbm_call_target/get_agent_statuses')
35879 ranu 673
                .then(function (response) {
674
                    return response.json();
675
                })
676
                .then(function (data) {
677
                    if (data && data.length > 0) {
678
                        for (var i = 0; i < data.length; i++) {
679
                            var agent = data[i];
680
                            var statusCell = document.querySelector('.agent-status-cell[data-authid="' + agent.authId + '"]');
681
                            var timeCell = document.querySelector('.time-in-status-cell[data-authid="' + agent.authId + '"]');
35852 ranu 682
 
35879 ranu 683
                            if (statusCell) {
684
                                var statusHtml = getStatusBadge(agent.agentStatus);
685
                                statusCell.innerHTML = statusHtml;
686
                            }
687
                            if (timeCell) {
688
                                timeCell.textContent = agent.timeInStatus || '-';
689
                            }
35852 ranu 690
                        }
691
                    }
35879 ranu 692
                })
693
                .catch(function (err) {
694
                    console.error('Error refreshing agent status:', err);
695
                });
35852 ranu 696
    }
697
 
698
    function getStatusBadge(status) {
699
        if (!status) return '<span class="badge" style="background-color: #6c757d; color: white;">-</span>';
700
 
701
        var bgColor = '#6c757d';
702
        var textColor = 'white';
35994 ranu 703
        var lowerStatus = status.toLowerCase();
35852 ranu 704
 
705
        if (status === 'On Call') {
706
            bgColor = '#28a745';
707
        } else if (status === 'Available') {
35994 ranu 708
            bgColor = '#dc3545';
709
        } else if (lowerStatus.indexOf('break') !== -1) {
36057 ranu 710
            bgColor = '#fd7e14';  // Orange for break
35852 ranu 711
        } else if (status === 'Logged Out') {
36057 ranu 712
            bgColor = '#6c757d';  // Grey for logged out
35852 ranu 713
        } else if (status === 'Trying') {
36057 ranu 714
            bgColor = '#ffc107';  // Yellow for trying
715
            textColor = 'black';
35852 ranu 716
        }
717
 
718
        return '<span class="badge" style="background-color: ' + bgColor + '; color: ' + textColor + ';">' + status + '</span>';
719
    }
720
 
36234 ranu 721
    // Refresh every 10 seconds (only for today's view)
722
        #if($isToday)
36057 ranu 723
    setInterval(refreshAgentStatus, 10000);
35852 ranu 724
 
725
    // Initial refresh after page load
726
    setTimeout(refreshAgentStatus, 2000);
36234 ranu 727
        #end
35852 ranu 728
 
729
    // Download All Call Data by Date
730
    function downloadCallData() {
731
        var selectedDate = document.getElementById('downloadDate').value;
732
        if (!selectedDate) {
733
            alert('Please select a date');
734
            return;
735
        }
736
        window.location.href = '/indent/rbm_call_target/download_call_data?date=' + selectedDate;
737
    }
35631 ranu 738
</script>