Subversion Repositories SmartDukaan

Rev

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