Subversion Repositories SmartDukaan

Rev

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