Subversion Repositories SmartDukaan

Rev

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