Subversion Repositories SmartDukaan

Rev

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