Subversion Repositories SmartDukaan

Rev

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