Subversion Repositories SmartDukaan

Rev

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

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