Subversion Repositories SmartDukaan

Rev

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