Subversion Repositories SmartDukaan

Rev

Rev 36099 | Rev 36112 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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