Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
37444 ranu 1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
  <title>RBM DRR Dashboard</title>
7
  <style>
8
    :root {
9
      --bg: #f4f6fb;
10
      --card: #ffffff;
11
      --ink: #141a2b;
12
      --muted: #5d6a83;
13
      --soft: #97a1b5;
14
      --line: #e6e9f1;
15
      --line2: #eef1f6;
16
      --brand: #3b5bdb;
17
      --brand2: #5c7cfa;
18
      --teal: #0ca678;
19
      --cyan: #1098ad;
20
      --amber: #f59f00;
21
      --orange: #e8590c;
22
      --red: #e03131;
23
      --violet: #7048e8;
24
      --pink: #d6336c;
25
      --good: #2f9e44;
26
      --warn: #e8590c;
27
      --bad: #e03131;
28
      --hid: #7048e8;
29
      --fast: #3b5bdb;
30
      --run: #0ca678;
31
      --slow: #e8590c;
32
      --other: #868e96;
33
      --hid-bg: #f2edff;
34
      --fast-bg: #eaf0ff;
35
      --run-bg: #e5f7ee;
36
      --slow-bg: #ffefe0;
37
      --other-bg: #eef0f4;
38
    }
39
 
40
    * {
41
      box-sizing: border-box
42
    }
43
 
44
    html, body {
45
      margin: 0;
46
      background: var(--bg);
47
      color: var(--ink);
48
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
49
      -webkit-font-smoothing: antialiased;
50
      font-size: 14px
51
    }
52
 
53
    .wrap {
54
      max-width: 1440px;
55
      margin: 0 auto;
56
      padding: 22px 26px 100px
57
    }
58
 
59
    a {
60
      color: var(--brand);
61
      text-decoration: none
62
    }
63
 
64
    a:hover {
65
      text-decoration: underline
66
    }
67
 
68
    /* header */
69
    header.top {
70
      display: flex;
71
      align-items: flex-end;
72
      justify-content: space-between;
73
      gap: 18px;
74
      flex-wrap: wrap;
75
      margin-bottom: 20px
76
    }
77
 
78
    .brand .crumb {
79
      font-size: 12px;
80
      color: var(--soft);
81
      font-weight: 600
82
    }
83
 
84
    .brand h1 {
85
      margin: 4px 0 0;
86
      font-size: 26px;
87
      font-weight: 770;
88
      letter-spacing: -.015em;
89
      display: flex;
90
      align-items: center;
91
      gap: 12px
92
    }
93
 
94
    .brand h1 .live {
95
      font-size: 11px;
96
      font-weight: 700;
97
      color: var(--teal);
98
      background: #e6fcf5;
99
      border: 1px solid #c3fae8;
100
      border-radius: 999px;
101
      padding: 3px 10px
102
    }
103
 
104
    .brand h1 .live i {
105
      display: inline-block;
106
      width: 7px;
107
      height: 7px;
108
      border-radius: 50%;
109
      background: var(--teal);
110
      margin-right: 5px;
111
      animation: pulse 1.6s infinite;
112
      vertical-align: middle
113
    }
114
 
115
    @keyframes pulse {
116
      0%, 100% {
117
        opacity: 1
118
      }
119
      50% {
120
        opacity: .25
121
      }
122
    }
123
 
124
    .hd-right {
125
      display: flex;
126
      align-items: center;
127
      gap: 10px;
128
      flex-wrap: wrap
129
    }
130
 
131
    .ctl {
132
      background: var(--card);
133
      border: 1px solid var(--line);
134
      border-radius: 10px;
135
      padding: 9px 13px;
136
      font-size: 13px;
137
      color: var(--ink);
138
      font-weight: 600;
139
      box-shadow: 0 1px 2px rgba(20, 30, 60, .04)
140
    }
141
 
142
    input.ctl {
143
      appearance: none;
144
      cursor: pointer;
145
      height: 38px;
146
      min-width: 240px
147
    }
148
 
149
    .btn-r {
150
      background: var(--brand);
151
      border: 0;
152
      color: #fff;
153
      font-weight: 670;
154
      padding: 9px 18px;
155
      border-radius: 10px;
156
      cursor: pointer;
157
      font-size: 13px;
158
      height: 38px;
159
      box-shadow: 0 1px 2px rgba(59, 91, 219, .35);
160
      transition: transform .1s, box-shadow .1s
161
    }
162
 
163
    .btn-r:hover {
164
      background: var(--brand2);
165
      box-shadow: 0 3px 10px rgba(59, 91, 219, .35)
166
    }
167
 
168
    .btn-r:active {
169
      transform: translateY(1px)
170
    }
171
 
172
    /* KPI cards */
173
    .kpis {
174
      display: grid;
175
      grid-template-columns:repeat(4, 1fr);
176
      gap: 14px;
177
      margin-bottom: 22px
178
    }
179
 
180
    .kpi {
181
      position: relative;
182
      background: var(--card);
183
      border: 1px solid var(--line);
184
      border-radius: 14px;
185
      padding: 16px 18px;
186
      box-shadow: 0 1px 2px rgba(20, 30, 60, .05);
187
      display: flex;
188
      flex-direction: column;
189
      min-height: 118px;
190
      overflow: hidden
191
    }
192
 
193
    .kpi::before {
194
      content: "";
195
      position: absolute;
196
      top: 0;
197
      left: 0;
198
      height: 3px;
199
      width: 100%;
200
      border-top-left-radius: 14px;
201
      border-top-right-radius: 14px
202
    }
203
 
204
    .kpi.a::before {
205
      background: linear-gradient(90deg, var(--brand), var(--brand2))
206
    }
207
 
208
    .kpi.b::before {
209
      background: linear-gradient(90deg, var(--teal), #20c997)
210
    }
211
 
212
    .kpi.c::before {
213
      background: linear-gradient(90deg, var(--amber), #ffc078)
214
    }
215
 
216
    .kpi.d::before {
217
      background: linear-gradient(90deg, var(--violet), #9775fa)
218
    }
219
 
220
    .kpi .top {
221
      display: flex;
222
      align-items: center;
223
      gap: 10px
224
    }
225
 
226
    .kpi .ic {
227
      width: 34px;
228
      height: 34px;
229
      border-radius: 10px;
230
      display: flex;
231
      align-items: center;
232
      justify-content: center;
233
      flex: none;
234
      color: #fff;
235
      box-shadow: 0 2px 6px rgba(0, 0, 0, .08)
236
    }
237
 
238
    .kpi.a .ic {
239
      background: linear-gradient(135deg, var(--brand), var(--brand2))
240
    }
241
 
242
    .kpi.b .ic {
243
      background: linear-gradient(135deg, var(--teal), #20c997)
244
    }
245
 
246
    .kpi.c .ic {
247
      background: linear-gradient(135deg, var(--amber), #ffc078);
248
      color: #3a2500
249
    }
250
 
251
    .kpi.d .ic {
252
      background: linear-gradient(135deg, var(--violet), #9775fa)
253
    }
254
 
255
    .kpi .ic svg {
256
      width: 18px;
257
      height: 18px
258
    }
259
 
260
    .kpi .label {
261
      font-size: 12px;
262
      color: var(--muted);
263
      font-weight: 650;
264
      line-height: 1.2;
265
      letter-spacing: .005em
266
    }
267
 
268
    .kpi .val {
269
      font-size: 28px;
270
      font-weight: 780;
271
      margin-top: auto;
272
      padding-top: 10px;
273
      letter-spacing: -.02em;
274
      line-height: 1;
275
      font-variant-numeric: tabular-nums
276
    }
277
 
278
    .kpi .val .u {
279
      font-size: 13px;
280
      color: var(--soft);
281
      font-weight: 600;
282
      margin-left: 3px
283
    }
284
 
285
    .kpi .foot {
286
      font-size: 11.5px;
287
      color: var(--soft);
288
      margin-top: 8px;
289
      font-weight: 500
290
    }
291
 
292
    .kpi .val .pct {
293
      margin-left: 0;
294
      font-size: 20px;
295
      padding: 4px 12px
296
    }
297
 
298
    .kpi.clickable {
299
      cursor: pointer;
300
      transition: transform .1s, box-shadow .12s, border-color .12s
301
    }
302
 
303
    .kpi.clickable:hover {
304
      transform: translateY(-2px);
305
      box-shadow: 0 6px 18px rgba(20, 30, 60, .08);
306
      border-color: #c8d2f4
307
    }
308
 
309
    .kpi.clickable .hint {
310
      position: absolute;
311
      bottom: 8px;
312
      right: 12px;
313
      color: var(--soft);
314
      font-size: 11px;
315
      font-weight: 600;
316
      opacity: .7
317
    }
318
 
319
    .kpi.clickable:hover .hint {
320
      opacity: 1;
321
      color: var(--brand)
322
    }
323
 
324
    /* Cards & section labels */
325
    .card {
326
      background: var(--card);
327
      border: 1px solid var(--line);
328
      border-radius: 15px;
329
      padding: 18px 20px;
330
      margin-bottom: 16px;
331
      box-shadow: 0 1px 2px rgba(20, 30, 60, .04)
332
    }
333
 
334
    .card .card-hd {
335
      display: flex;
336
      align-items: baseline;
337
      justify-content: space-between;
338
      gap: 14px;
339
      margin-bottom: 14px
340
    }
341
 
342
    .card h2 {
343
      margin: 0;
344
      font-size: 16px;
345
      font-weight: 730;
346
      letter-spacing: -.01em
347
    }
348
 
349
    .card .desc {
350
      color: var(--muted);
351
      font-size: 12.5px;
352
      margin: 2px 0 0
353
    }
354
 
355
    .card .badge-period {
356
      background: #eef2ff;
357
      border: 1px solid #d7defb;
358
      color: var(--brand);
359
      border-radius: 999px;
360
      padding: 3px 12px;
361
      font-size: 12px;
362
      font-weight: 650;
363
      letter-spacing: .01em
364
    }
365
 
366
    .sectionlabel {
367
      font-size: 11px;
368
      letter-spacing: .14em;
369
      text-transform: uppercase;
370
      color: var(--soft);
371
      font-weight: 700;
372
      margin: 20px 2px 10px
373
    }
374
 
375
    /* Legend under section label */
376
    .legend {
377
      display: flex;
378
      gap: 14px;
379
      flex-wrap: wrap;
380
      margin: 0 2px 10px;
381
      align-items: center;
382
      color: var(--soft);
383
      font-size: 11.5px;
384
      font-weight: 600
385
    }
386
 
387
    .legend .lg {
388
      display: inline-flex;
389
      align-items: center;
390
      gap: 5px
391
    }
392
 
393
    .legend .lg i {
394
      width: 8px;
395
      height: 8px;
396
      border-radius: 50%;
397
      display: inline-block
398
    }
399
 
400
    .legend .lg.hid i {
401
      background: var(--hid)
402
    }
403
 
404
    .legend .lg.fast i {
405
      background: var(--fast)
406
    }
407
 
408
    .legend .lg.run i {
409
      background: var(--run)
410
    }
411
 
412
    .legend .lg.slow i {
413
      background: var(--slow)
414
    }
415
 
416
    .legend .lg.other i {
417
      background: var(--other)
418
    }
419
 
420
    .legend .lg .lgt {
421
      color: var(--muted)
422
    }
423
 
424
    /* Table */
425
    table {
426
      width: 100%;
427
      border-collapse: separate;
428
      border-spacing: 0;
429
      font-size: 13px
430
    }
431
 
432
    th, td {
433
      text-align: left;
434
      padding: 11px 10px;
435
      border-bottom: 1px solid var(--line2)
436
    }
437
 
438
    thead th {
439
      font-size: 10.5px;
440
      text-transform: uppercase;
441
      letter-spacing: .06em;
442
      color: var(--soft);
443
      font-weight: 700;
444
      white-space: nowrap;
445
      user-select: none;
446
      position: sticky;
447
      top: 0;
448
      background: #fff;
449
      z-index: 1;
450
      border-bottom: 1px solid var(--line)
451
    }
452
 
453
    th.num, td.num {
454
      text-align: right
455
    }
456
 
457
    th.g-hid {
458
      color: var(--hid);
459
      border-top: 3px solid var(--hid)
460
    }
461
 
462
    th.g-fast {
463
      color: var(--fast);
464
      border-top: 3px solid var(--fast)
465
    }
466
 
467
    th.g-run {
468
      color: var(--run);
469
      border-top: 3px solid var(--run)
470
    }
471
 
472
    th.g-slow {
473
      color: var(--slow);
474
      border-top: 3px solid var(--slow)
475
    }
476
 
477
    th.g-other {
478
      color: var(--other);
479
      border-top: 3px solid var(--other)
480
    }
481
 
482
    th.g-total {
483
      color: var(--brand);
484
      border-top: 3px solid var(--brand)
485
    }
486
 
487
    tbody tr:hover {
488
      background: #f6f8fd
489
    }
490
 
491
    tbody tr.clickable {
492
      cursor: pointer;
493
      transition: background .1s
494
    }
495
 
496
    tbody tr.clickable:hover {
497
      background: #eef2ff
498
    }
499
 
500
    tr.totalrow {
501
      background: #fafbfe;
502
      border-top: 2px solid var(--line)
503
    }
504
 
505
    tr.totalrow td {
506
      font-weight: 770;
507
      color: var(--ink)
508
    }
509
 
510
    tr.totalrow .cell-val {
511
      font-size: 14px
512
    }
513
 
514
    .rbm-cell {
515
      display: flex;
516
      flex-direction: column;
517
      gap: 2px
518
    }
519
 
520
    .rbm-cell .rn {
521
      font-weight: 700;
522
      color: var(--ink);
523
      font-size: 13.5px
524
    }
525
 
526
    .rbm-cell .wh {
527
      font-size: 11.5px;
528
      color: var(--muted);
529
      font-weight: 600
530
    }
531
 
532
    .cell-val {
533
      font-variant-numeric: tabular-nums;
534
      font-weight: 650;
535
      color: var(--ink);
536
      white-space: nowrap
537
    }
538
 
539
    .cell-val small {
540
      color: var(--soft);
541
      font-weight: 500;
542
      margin-left: 3px
543
    }
544
 
545
    .pct {
546
      display: inline-flex;
547
      align-items: center;
548
      justify-content: center;
549
      min-width: 56px;
550
      padding: 3px 9px;
551
      border-radius: 7px;
552
      font-size: 11.5px;
553
      font-weight: 700;
554
      text-align: center;
555
      font-variant-numeric: tabular-nums;
556
      line-height: 1.35
557
    }
558
 
559
    .pct.good {
560
      background: #e5f7ee;
561
      color: #177a3a
562
    }
563
 
564
    .pct.warn {
565
      background: #fff0e0;
566
      color: #a04600
567
    }
568
 
569
    .pct.bad {
570
      background: #ffeaea;
571
      color: #b8272b
572
    }
573
 
574
    .pct.na {
575
      background: transparent;
576
      color: var(--soft);
577
      font-weight: 600;
578
      min-width: auto;
579
      padding: 0
580
    }
581
 
582
    .bar {
583
      height: 5px;
584
      border-radius: 3px;
585
      background: #eef1f6;
586
      overflow: hidden;
587
      margin-top: 6px
588
    }
589
 
590
    .bar > i {
591
      display: block;
592
      height: 100%;
593
      border-radius: 3px;
594
      transition: width .3s ease
595
    }
596
 
597
    .bar > i.good {
598
      background: linear-gradient(90deg, #51cf66, #2f9e44)
599
    }
600
 
601
    .bar > i.warn {
602
      background: linear-gradient(90deg, #ffa94d, #e8590c)
603
    }
604
 
605
    .bar > i.bad {
606
      background: linear-gradient(90deg, #ff8787, #e03131)
607
    }
608
 
609
    .chev {
610
      color: #c5cce0;
611
      font-size: 16px;
612
      padding-left: 6px;
613
      transition: transform .12s, color .12s
614
    }
615
 
616
    tr.clickable:hover .chev {
617
      color: var(--brand);
618
      transform: translateX(2px)
619
    }
620
 
621
    .loading {
622
      padding: 70px;
623
      text-align: center;
624
      color: var(--muted)
625
    }
626
 
627
    .spinner {
628
      width: 32px;
629
      height: 32px;
630
      border: 3px solid #e3e8f5;
631
      border-top-color: var(--brand);
632
      border-radius: 50%;
633
      animation: spin 1s linear infinite;
634
      margin: 0 auto 12px
635
    }
636
 
637
    @keyframes spin {
638
      to {
639
        transform: rotate(360deg)
640
      }
641
    }
642
 
643
    .empty {
644
      padding: 56px 20px;
645
      text-align: center;
646
      color: var(--soft);
647
      font-size: 13.5px
648
    }
649
 
650
    .empty .ei {
651
      font-size: 36px;
652
      margin-bottom: 8px;
653
      opacity: .5
654
    }
655
 
656
    .foot-note {
657
      color: var(--soft);
658
      font-size: 11.5px;
659
      margin-top: 14px;
660
      padding: 10px 12px;
661
      background: #fafbfe;
662
      border: 1px dashed var(--line);
663
      border-radius: 10px;
664
      line-height: 1.5
665
    }
666
 
667
    .foot-note code {
668
      background: #eef1f6;
669
      color: var(--muted);
670
      padding: 1px 5px;
671
      border-radius: 4px;
672
      font-size: 11px
673
    }
674
 
675
    /* drill-down panel */
676
    .rdrr-back {
677
      position: fixed;
678
      inset: 0;
679
      background: rgba(15, 22, 40, .5);
680
      backdrop-filter: blur(2px);
681
      z-index: 1200;
682
      display: none
683
    }
684
 
685
    .rdrr-back.show {
686
      display: block
687
    }
688
 
689
    .rdrr-panel {
690
      position: absolute;
691
      top: 0;
692
      right: 0;
693
      height: 100%;
694
      width: min(760px, 96vw);
695
      background: #fff;
696
      box-shadow: -12px 0 40px rgba(20, 30, 60, .22);
697
      display: flex;
698
      flex-direction: column;
699
      padding: 24px 26px 20px;
700
      transform: translateX(100%);
701
      transition: transform .22s ease;
702
      overflow-y: auto
703
    }
704
 
705
    .rdrr-back.show .rdrr-panel {
706
      transform: translateX(0)
707
    }
708
 
709
    .rdrr-panel .x {
710
      position: absolute;
711
      top: 16px;
712
      right: 18px;
713
      cursor: pointer;
714
      color: var(--soft);
715
      font-size: 24px;
716
      line-height: 1;
717
      border: 0;
718
      background: none;
719
      width: 32px;
720
      height: 32px;
721
      border-radius: 8px;
722
      transition: background .1s, color .1s
723
    }
724
 
725
    .rdrr-panel .x:hover {
726
      background: #f1f3f9;
727
      color: var(--ink)
728
    }
729
 
730
    .rdrr-panel h3 {
731
      margin: 0 0 3px;
732
      font-size: 19px;
733
      font-weight: 750;
734
      letter-spacing: -.01em;
735
      padding-right: 40px
736
    }
737
 
738
    .rdrr-panel > .desc {
739
      margin: 0 0 18px;
740
      font-size: 12.5px;
741
      color: var(--muted);
742
      font-weight: 600
743
    }
744
 
745
    .rdrr-total {
746
      display: flex;
747
      gap: 14px;
748
      padding: 14px 16px;
749
      background: linear-gradient(135deg, #f8f9fc, #eef2ff);
750
      border: 1px solid #dbe2f6;
751
      border-radius: 12px;
752
      margin-bottom: 18px
753
    }
754
 
755
    .rdrr-total > div {
756
      flex: 1;
757
      text-align: center;
758
      border-right: 1px solid #dbe2f6;
759
      padding: 0 4px
760
    }
761
 
762
    .rdrr-total > div:last-child {
763
      border-right: 0
764
    }
765
 
766
    .rdrr-total .k {
767
      font-size: 10.5px;
768
      color: var(--muted);
769
      text-transform: uppercase;
770
      letter-spacing: .06em;
771
      font-weight: 700
772
    }
773
 
774
    .rdrr-total .v {
775
      font-size: 20px;
776
      font-weight: 770;
777
      color: var(--ink);
778
      font-variant-numeric: tabular-nums;
779
      margin-top: 5px;
780
      letter-spacing: -.01em
781
    }
782
 
783
    .rdrr-total .v .pct {
784
      font-size: 16px;
785
      padding: 3px 10px;
786
      margin-top: 0
787
    }
788
 
789
    .bbars {
790
      display: flex;
791
      flex-direction: column;
792
      gap: 10px;
793
      margin-bottom: 20px
794
    }
795
 
796
    .bbar {
797
      display: grid;
798
      grid-template-columns:82px 1fr 145px 60px;
799
      gap: 14px;
800
      align-items: center;
801
      padding: 12px 14px;
802
      background: #fff;
803
      border: 1px solid var(--line);
804
      border-radius: 11px;
805
      transition: box-shadow .12s
806
    }
807
 
808
    .bbar:hover {
809
      box-shadow: 0 3px 10px rgba(20, 30, 60, .06)
810
    }
811
 
812
    .bbar .bname {
813
      font-size: 11.5px;
814
      font-weight: 750;
815
      color: var(--ink);
816
      letter-spacing: .04em;
817
      text-transform: uppercase;
818
      display: flex;
819
      align-items: center;
820
      gap: 6px
821
    }
822
 
823
    .bbar .bname i {
824
      display: inline-block;
825
      width: 8px;
826
      height: 8px;
827
      border-radius: 50%
828
    }
829
 
830
    .bbar.hid .bname {
831
      color: var(--hid)
832
    }
833
 
834
    .bbar.fast .bname {
835
      color: var(--fast)
836
    }
837
 
838
    .bbar.run .bname {
839
      color: var(--run)
840
    }
841
 
842
    .bbar.slow .bname {
843
      color: var(--slow)
844
    }
845
 
846
    .bbar.other .bname {
847
      color: var(--other)
848
    }
849
 
850
    .bbar.hid .bname i {
851
      background: var(--hid)
852
    }
853
 
854
    .bbar.fast .bname i {
855
      background: var(--fast)
856
    }
857
 
858
    .bbar.run .bname i {
859
      background: var(--run)
860
    }
861
 
862
    .bbar.slow .bname i {
863
      background: var(--slow)
864
    }
865
 
866
    .bbar.other .bname i {
867
      background: var(--other)
868
    }
869
 
870
    .bbar .btrack {
871
      height: 14px;
872
      border-radius: 8px;
873
      overflow: hidden;
874
      position: relative
875
    }
876
 
877
    .bbar.hid .btrack {
878
      background: var(--hid-bg)
879
    }
880
 
881
    .bbar.fast .btrack {
882
      background: var(--fast-bg)
883
    }
884
 
885
    .bbar.run .btrack {
886
      background: var(--run-bg)
887
    }
888
 
889
    .bbar.slow .btrack {
890
      background: var(--slow-bg)
891
    }
892
 
893
    .bbar.other .btrack {
894
      background: var(--other-bg)
895
    }
896
 
897
    .bbar .btrack > i {
898
      display: block;
899
      height: 100%;
900
      border-radius: 8px;
901
      transition: width .3s ease;
902
      position: relative
903
    }
904
 
905
    .bbar.hid .btrack > i {
906
      background: linear-gradient(90deg, #9775fa, var(--hid))
907
    }
908
 
909
    .bbar.fast .btrack > i {
910
      background: linear-gradient(90deg, var(--brand2), var(--fast))
911
    }
912
 
913
    .bbar.run .btrack > i {
914
      background: linear-gradient(90deg, #20c997, var(--run))
915
    }
916
 
917
    .bbar.slow .btrack > i {
918
      background: linear-gradient(90deg, #ffa94d, var(--slow))
919
    }
920
 
921
    .bbar.other .btrack > i {
922
      background: linear-gradient(90deg, #adb5bd, var(--other))
923
    }
924
 
925
    .bbar .btgt {
926
      font-size: 12px;
927
      color: var(--muted);
928
      font-variant-numeric: tabular-nums;
929
      font-weight: 600;
930
      text-align: right
931
    }
932
 
933
    .bbar .btgt b {
934
      color: var(--ink);
935
      font-weight: 700
936
    }
937
 
938
    .bbar .bpct {
939
      font-size: 13px;
940
      font-weight: 750;
941
      text-align: right;
942
      font-variant-numeric: tabular-nums
943
    }
944
 
945
    .bbar .bpct.good {
946
      color: var(--good)
947
    }
948
 
949
    .bbar .bpct.warn {
950
      color: var(--warn)
951
    }
952
 
953
    .bbar .bpct.bad {
954
      color: var(--bad)
955
    }
956
 
957
    .bbar .bpct.na {
958
      color: var(--soft);
959
      font-weight: 600
960
    }
961
 
962
    /* brand mix bars in drill-down */
963
    .brands {
964
      display: flex;
965
      flex-direction: column;
966
      gap: 8px;
967
      margin-bottom: 20px
968
    }
969
 
970
    .brand-card {
971
      background: #fff;
972
      border: 1px solid var(--line);
973
      border-radius: 11px;
974
      overflow: hidden;
975
      transition: box-shadow .12s
976
    }
977
 
978
    .brand-card:hover {
979
      box-shadow: 0 3px 10px rgba(20, 30, 60, .06)
980
    }
981
 
982
    .brand-card.open {
983
      box-shadow: 0 4px 14px rgba(59, 91, 219, .14);
984
      border-color: #c8d2f4
985
    }
986
 
987
    .brand-head {
988
      display: grid;
37460 ranu 989
      grid-template-columns:24px 130px 1fr 96px 100px 60px;
37444 ranu 990
      gap: 12px;
991
      align-items: center;
992
      padding: 10px 14px;
993
      cursor: pointer;
994
      user-select: none
995
    }
996
 
37460 ranu 997
    .brand-head .bpc {
998
      display: inline-flex;
999
      align-items: center;
1000
      justify-content: center;
1001
      gap: 4px;
1002
      font-size: 11.5px;
1003
      font-weight: 700;
1004
      color: var(--brand);
1005
      background: #eef2ff;
1006
      border: 1px solid #d7defb;
1007
      border-radius: 999px;
1008
      padding: 3px 9px;
1009
      font-variant-numeric: tabular-nums;
1010
      white-space: nowrap;
1011
      justify-self: center
1012
    }
1013
 
1014
    .brand-head .bpc.zero {
1015
      color: var(--soft);
1016
      background: #f1f3f9;
1017
      border-color: var(--line)
1018
    }
1019
 
1020
    .brand-head .bpc svg {
1021
      width: 11px;
1022
      height: 11px
1023
    }
1024
 
37444 ranu 1025
    .brand-head .cx {
1026
      color: #c5cce0;
1027
      font-size: 14px;
1028
      transition: transform .18s ease, color .12s
1029
    }
1030
 
1031
    .brand-card.open .brand-head .cx {
1032
      transform: rotate(90deg);
1033
      color: var(--brand)
1034
    }
1035
 
1036
    .brand-head .bn {
1037
      font-size: 13px;
1038
      font-weight: 700;
1039
      color: var(--ink);
1040
      white-space: nowrap;
1041
      overflow: hidden;
1042
      text-overflow: ellipsis
1043
    }
1044
 
1045
    .brand-head .btrack {
1046
      height: 10px;
1047
      background: #eef1f6;
1048
      border-radius: 6px;
1049
      overflow: hidden
1050
    }
1051
 
1052
    .brand-head .btrack > i {
1053
      display: block;
1054
      height: 100%;
1055
      border-radius: 6px;
1056
      background: linear-gradient(90deg, var(--brand2), var(--brand));
1057
      transition: width .3s ease
1058
    }
1059
 
1060
    .brand-head .bval {
1061
      font-size: 13px;
1062
      font-weight: 700;
1063
      color: var(--ink);
1064
      font-variant-numeric: tabular-nums;
1065
      text-align: right
1066
    }
1067
 
1068
    .brand-head .bshare {
1069
      font-size: 12px;
1070
      font-weight: 700;
1071
      color: var(--muted);
1072
      font-variant-numeric: tabular-nums;
1073
      text-align: right
1074
    }
1075
 
1076
    .brand-card.top .brand-head .btrack > i {
1077
      background: linear-gradient(90deg, #38b2ac, var(--teal))
1078
    }
1079
 
1080
    .brand-card.top .brand-head .bshare {
1081
      color: var(--teal)
1082
    }
1083
 
1084
    .brand-body {
1085
      display: none;
1086
      padding: 6px 14px 14px;
1087
      border-top: 1px dashed var(--line);
1088
      background: #fafbfe
1089
    }
1090
 
1091
    .brand-card.open .brand-body {
1092
      display: block
1093
    }
1094
 
1095
    .brand-body .bhdr {
1096
      font-size: 10.5px;
1097
      letter-spacing: .06em;
1098
      text-transform: uppercase;
1099
      color: var(--soft);
1100
      font-weight: 700;
1101
      margin: 8px 0 8px
1102
    }
1103
 
1104
    .mbars {
1105
      display: flex;
1106
      flex-direction: column;
1107
      gap: 6px
1108
    }
1109
 
1110
    .mbar {
1111
      display: grid;
1112
      grid-template-columns:90px 1fr 100px 60px;
1113
      gap: 10px;
1114
      align-items: center;
1115
      padding: 6px 10px;
1116
      background: #fff;
1117
      border: 1px solid var(--line2);
1118
      border-radius: 8px
1119
    }
1120
 
1121
    .mbar .mname {
1122
      font-size: 11px;
1123
      font-weight: 700;
1124
      letter-spacing: .04em;
1125
      text-transform: uppercase;
1126
      display: flex;
1127
      align-items: center;
1128
      gap: 5px
1129
    }
1130
 
1131
    .mbar .mname i {
1132
      display: inline-block;
1133
      width: 7px;
1134
      height: 7px;
1135
      border-radius: 50%
1136
    }
1137
 
1138
    .mbar.hid .mname {
1139
      color: var(--hid)
1140
    }
1141
 
1142
    .mbar.hid .mname i {
1143
      background: var(--hid)
1144
    }
1145
 
1146
    .mbar.fastmoving .mname {
1147
      color: var(--fast)
1148
    }
1149
 
1150
    .mbar.fastmoving .mname i {
1151
      background: var(--fast)
1152
    }
1153
 
1154
    .mbar.running .mname {
1155
      color: var(--run)
1156
    }
1157
 
1158
    .mbar.running .mname i {
1159
      background: var(--run)
1160
    }
1161
 
1162
    .mbar.slowmoving .mname {
1163
      color: var(--slow)
1164
    }
1165
 
1166
    .mbar.slowmoving .mname i {
1167
      background: var(--slow)
1168
    }
1169
 
1170
    .mbar.other .mname {
1171
      color: var(--other)
1172
    }
1173
 
1174
    .mbar.other .mname i {
1175
      background: var(--other)
1176
    }
1177
 
1178
    .mbar .mtrack {
1179
      height: 10px;
1180
      border-radius: 5px;
1181
      overflow: hidden
1182
    }
1183
 
1184
    .mbar.hid .mtrack {
1185
      background: var(--hid-bg)
1186
    }
1187
 
1188
    .mbar.fastmoving .mtrack {
1189
      background: var(--fast-bg)
1190
    }
1191
 
1192
    .mbar.running .mtrack {
1193
      background: var(--run-bg)
1194
    }
1195
 
1196
    .mbar.slowmoving .mtrack {
1197
      background: var(--slow-bg)
1198
    }
1199
 
1200
    .mbar.other .mtrack {
1201
      background: var(--other-bg)
1202
    }
1203
 
1204
    .mbar .mtrack > i {
1205
      display: block;
1206
      height: 100%;
1207
      border-radius: 5px;
1208
      transition: width .3s ease
1209
    }
1210
 
1211
    .mbar.hid .mtrack > i {
1212
      background: linear-gradient(90deg, #9775fa, var(--hid))
1213
    }
1214
 
1215
    .mbar.fastmoving .mtrack > i {
1216
      background: linear-gradient(90deg, var(--brand2), var(--fast))
1217
    }
1218
 
1219
    .mbar.running .mtrack > i {
1220
      background: linear-gradient(90deg, #20c997, var(--run))
1221
    }
1222
 
1223
    .mbar.slowmoving .mtrack > i {
1224
      background: linear-gradient(90deg, #ffa94d, var(--slow))
1225
    }
1226
 
1227
    .mbar.other .mtrack > i {
1228
      background: linear-gradient(90deg, #adb5bd, var(--other))
1229
    }
1230
 
1231
    .mbar .mval {
1232
      font-size: 12px;
1233
      font-weight: 650;
1234
      color: var(--ink);
1235
      font-variant-numeric: tabular-nums;
1236
      text-align: right
1237
    }
1238
 
1239
    .mbar .mshare {
1240
      font-size: 12px;
1241
      font-weight: 700;
1242
      font-variant-numeric: tabular-nums;
1243
      text-align: right;
1244
      color: var(--muted)
1245
    }
1246
 
1247
    /* status list modal (achieved vs pending) */
1248
    .status-back {
1249
      position: fixed;
1250
      inset: 0;
1251
      background: rgba(15, 22, 40, .5);
1252
      backdrop-filter: blur(2px);
1253
      z-index: 1300;
1254
      display: none;
1255
      align-items: flex-start;
1256
      justify-content: center;
1257
      padding: 60px 20px;
1258
      overflow-y: auto
1259
    }
1260
 
1261
    .status-back.show {
1262
      display: flex
1263
    }
1264
 
1265
    .status-modal {
1266
      background: #fff;
1267
      border-radius: 16px;
1268
      max-width: 1000px;
1269
      width: 100%;
1270
      box-shadow: 0 20px 60px rgba(20, 30, 60, .28);
1271
      padding: 22px 24px 20px;
1272
      position: relative
1273
    }
1274
 
1275
    .status-modal .x {
1276
      position: absolute;
1277
      top: 14px;
1278
      right: 16px;
1279
      cursor: pointer;
1280
      color: var(--soft);
1281
      font-size: 24px;
1282
      line-height: 1;
1283
      border: 0;
1284
      background: none;
1285
      width: 32px;
1286
      height: 32px;
1287
      border-radius: 8px;
1288
      transition: background .1s
1289
    }
1290
 
1291
    .status-modal .x:hover {
1292
      background: #f1f3f9;
1293
      color: var(--ink)
1294
    }
1295
 
1296
    .status-modal h3 {
1297
      margin: 0 0 3px;
1298
      font-size: 19px;
1299
      font-weight: 760;
1300
      letter-spacing: -.01em;
1301
      padding-right: 40px
1302
    }
1303
 
1304
    .status-modal > .desc {
1305
      margin: 0 0 18px;
1306
      font-size: 12.5px;
1307
      color: var(--muted);
1308
      font-weight: 600
1309
    }
1310
 
1311
    .status-grid {
1312
      display: grid;
1313
      grid-template-columns:1fr 1fr;
1314
      gap: 18px
1315
    }
1316
 
1317
    .status-col {
1318
      border: 1px solid var(--line);
1319
      border-radius: 12px;
1320
      padding: 14px 16px;
1321
      background: #fbfcfe
1322
    }
1323
 
1324
    .status-col.good {
1325
      border-color: #c3e8d0;
1326
      background: #f4fbf6
1327
    }
1328
 
1329
    .status-col.bad {
1330
      border-color: #f2c4c4;
1331
      background: #fdf5f5
1332
    }
1333
 
1334
    .status-col h4 {
1335
      margin: 0 0 10px;
1336
      font-size: 13px;
1337
      font-weight: 730;
1338
      display: flex;
1339
      align-items: center;
1340
      gap: 8px;
1341
      letter-spacing: -.005em
1342
    }
1343
 
1344
    .status-col h4 .cnt {
1345
      background: #fff;
1346
      border: 1px solid var(--line);
1347
      color: var(--ink);
1348
      font-size: 11px;
1349
      font-weight: 700;
1350
      padding: 2px 9px;
1351
      border-radius: 999px
1352
    }
1353
 
1354
    .status-col.good h4 {
1355
      color: #177a3a
1356
    }
1357
 
1358
    .status-col.good h4 .cnt {
1359
      background: #e5f7ee;
1360
      border-color: #c3e8d0;
1361
      color: #177a3a
1362
    }
1363
 
1364
    .status-col.bad h4 {
1365
      color: #b8272b
1366
    }
1367
 
1368
    .status-col.bad h4 .cnt {
1369
      background: #ffeaea;
1370
      border-color: #f2c4c4;
1371
      color: #b8272b
1372
    }
1373
 
1374
    .status-list {
1375
      display: flex;
1376
      flex-direction: column;
1377
      gap: 6px;
1378
      max-height: 60vh;
1379
      overflow-y: auto;
1380
      padding-right: 4px
1381
    }
1382
 
1383
    .status-item {
1384
      display: grid;
1385
      grid-template-columns:1fr 100px 68px;
1386
      gap: 10px;
1387
      align-items: center;
1388
      padding: 9px 12px;
1389
      background: #fff;
1390
      border: 1px solid var(--line2);
1391
      border-radius: 9px;
1392
      transition: box-shadow .12s
1393
    }
1394
 
1395
    .status-item:hover {
1396
      box-shadow: 0 2px 8px rgba(20, 30, 60, .06)
1397
    }
1398
 
1399
    .status-item .rn {
1400
      font-weight: 700;
1401
      color: var(--ink);
1402
      font-size: 12.5px;
1403
      line-height: 1.3
1404
    }
1405
 
1406
    .status-item .wh {
1407
      font-size: 11px;
1408
      color: var(--muted);
1409
      font-weight: 600;
1410
      display: block;
1411
      margin-top: 2px
1412
    }
1413
 
1414
    .status-item .vv {
1415
      font-size: 12px;
1416
      color: var(--muted);
1417
      font-variant-numeric: tabular-nums;
1418
      font-weight: 600;
1419
      text-align: right;
1420
      white-space: nowrap
1421
    }
1422
 
1423
    .status-item .vv b {
1424
      color: var(--ink);
1425
      font-weight: 700
1426
    }
1427
 
1428
    .status-item .pp {
1429
      font-size: 12px;
1430
      font-weight: 700;
1431
      font-variant-numeric: tabular-nums;
1432
      text-align: right
1433
    }
1434
 
1435
    .status-item .pp.good {
1436
      color: var(--good)
1437
    }
1438
 
1439
    .status-item .pp.warn {
1440
      color: var(--warn)
1441
    }
1442
 
1443
    .status-item .pp.bad {
1444
      color: var(--bad)
1445
    }
1446
 
1447
    .status-empty {
1448
      padding: 24px;
1449
      text-align: center;
1450
      color: var(--soft);
1451
      font-size: 12.5px
1452
    }
1453
 
37460 ranu 1454
    /* extras: aging + partner-billing tables */
1455
    .xtable {
1456
      width: 100%;
1457
      border-collapse: separate;
1458
      border-spacing: 0;
1459
      font-size: 13px
1460
    }
1461
 
1462
    .xtable th {
1463
      font-size: 10.5px;
1464
      text-transform: uppercase;
1465
      letter-spacing: .06em;
1466
      color: var(--soft);
1467
      font-weight: 700;
1468
      white-space: nowrap;
1469
      padding: 10px 10px;
1470
      border-bottom: 1px solid var(--line);
1471
      text-align: left;
1472
      background: #fff
1473
    }
1474
 
1475
    .xtable th.num {
1476
      text-align: right
1477
    }
1478
 
1479
    .xtable td {
1480
      padding: 10px;
1481
      border-bottom: 1px solid var(--line2);
1482
      color: var(--ink);
1483
      font-weight: 500
1484
    }
1485
 
1486
    .xtable td.num {
1487
      text-align: right;
1488
      font-variant-numeric: tabular-nums;
1489
      font-weight: 650
1490
    }
1491
 
1492
    .xtable tbody tr:hover {
1493
      background: #f6f8fd
1494
    }
1495
 
1496
    .xtable .rbm-nm {
1497
      font-weight: 700;
1498
      color: var(--ink)
1499
    }
1500
 
1501
    .xtable tr.tot td {
1502
      font-weight: 770;
1503
      background: #fafbfe;
1504
      border-top: 2px solid var(--line);
1505
      color: var(--ink)
1506
    }
1507
 
1508
    .xtable tr.bal td {
1509
      font-weight: 700;
1510
      background: #fffbf2;
1511
      border-top: 1px dashed #f0d68a;
1512
      color: #7a5a00
1513
    }
1514
 
1515
    .xtable tr.bal td.hdr {
1516
      font-weight: 770
1517
    }
1518
 
1519
    .xtable td.g-hid {
1520
      border-left: 2px solid transparent
1521
    }
1522
 
1523
    /* placeholder for future column tint */
1524
    .xtable th.g-hid, .xtable td.g-hid {
1525
      color: var(--hid)
1526
    }
1527
 
1528
    .xtable th.g-fast, .xtable td.g-fast {
1529
      color: var(--fast)
1530
    }
1531
 
1532
    .xtable th.g-run, .xtable td.g-run {
1533
      color: var(--run)
1534
    }
1535
 
1536
    .xtable th.g-slow, .xtable td.g-slow {
1537
      color: var(--slow)
1538
    }
1539
 
1540
    .xtable th.g-other, .xtable td.g-other {
1541
      color: var(--other)
1542
    }
1543
 
1544
    .xtable th.g-total, .xtable td.g-total {
1545
      color: var(--brand);
1546
      font-weight: 700
1547
    }
1548
 
1549
    .xtable td.g-hid, .xtable td.g-fast, .xtable td.g-run, .xtable td.g-slow, .xtable td.g-other {
1550
      opacity: .95
1551
    }
1552
 
1553
    .xtable td.zero {
1554
      color: var(--soft);
1555
      font-weight: 500
1556
    }
1557
 
1558
    .xtable .cnt-pill {
1559
      display: inline-block;
1560
      min-width: 32px;
1561
      padding: 2px 8px;
1562
      border-radius: 6px;
1563
      font-size: 11.5px;
1564
      font-weight: 700;
1565
      font-variant-numeric: tabular-nums;
1566
      background: #eef2ff;
1567
      color: var(--brand)
1568
    }
1569
 
1570
    .xtable .cnt-pill.zero {
1571
      background: #f1f3f9;
1572
      color: var(--soft)
1573
    }
1574
 
1575
    .xtable .cnt-pill.warn {
1576
      background: #fff0e0;
1577
      color: #a04600
1578
    }
1579
 
1580
    .xtable .cnt-pill.good {
1581
      background: #e5f7ee;
1582
      color: #177a3a
1583
    }
1584
 
37469 ranu 1585
    /* call-target drawer content (Called Partners / OOS Calls) */
1586
    #rdrrCallDrawerBody {
1587
      overflow-x: auto
1588
    }
1589
 
1590
    #rdrrCallDrawerBody table {
1591
      width: 100%;
1592
      border-collapse: separate;
1593
      border-spacing: 0;
1594
      font-size: 12.5px;
1595
      background: #fff;
1596
      margin: 0
1597
    }
1598
 
1599
    #rdrrCallDrawerBody table th {
1600
      font-size: 10.5px;
1601
      text-transform: uppercase;
1602
      letter-spacing: .04em;
1603
      color: var(--soft);
1604
      font-weight: 700;
1605
      padding: 9px 10px;
1606
      background: #fafbfe;
1607
      border-bottom: 1px solid var(--line);
1608
      text-align: left;
1609
      white-space: nowrap
1610
    }
1611
 
1612
    #rdrrCallDrawerBody table td {
1613
      padding: 9px 10px;
1614
      border-bottom: 1px solid var(--line2);
1615
      color: var(--ink);
1616
      font-weight: 500;
1617
      vertical-align: middle
1618
    }
1619
 
1620
    #rdrrCallDrawerBody table tr:hover {
1621
      background: #f6f8fd
1622
    }
1623
 
1624
    #rdrrCallDrawerBody audio {
1625
      max-width: 170px;
1626
      height: 26px
1627
    }
1628
 
37468 ranu 1629
    /* rbm performance dashboard (extracted from today_po_rbm) */
1630
    #rdrrPerfWrap {
1631
      overflow-x: auto
1632
    }
1633
 
1634
    #rdrrPerfWrap table {
1635
      width: 100%;
1636
      border-collapse: separate;
1637
      border-spacing: 0;
1638
      font-size: 12.5px;
1639
      background: #fff
1640
    }
1641
 
1642
    #rdrrPerfWrap table th, #rdrrPerfWrap table td {
1643
      padding: 9px 10px;
1644
      text-align: center;
1645
      vertical-align: middle;
1646
      border-bottom: 1px solid var(--line2);
1647
      color: var(--ink);
1648
      font-weight: 500
1649
    }
1650
 
1651
    #rdrrPerfWrap table thead th {
1652
      font-size: 10.5px;
1653
      text-transform: uppercase;
1654
      letter-spacing: .05em;
1655
      font-weight: 700;
1656
      background: #1d2433;
1657
      color: #fff;
1658
      border-bottom: 0;
1659
      padding: 10px 8px;
1660
      line-height: 1.2
1661
    }
1662
 
1663
    #rdrrPerfWrap table thead th small {
1664
      font-size: 9.5px;
1665
      color: rgba(255, 255, 255, .7);
1666
      font-weight: 600;
1667
      display: block;
1668
      margin-top: 2px
1669
    }
1670
 
1671
    /* per-column accent badges (keep original palette from today_po_rbm) */
1672
    #rdrrPerfWrap table thead th:nth-child(4) {
1673
      background: linear-gradient(180deg, #40c057, #2f9e44)
1674
    }
1675
 
1676
    #rdrrPerfWrap table thead th:nth-child(5) {
1677
      background: linear-gradient(180deg, #22b8cf, #0e959f)
1678
    }
1679
 
1680
    #rdrrPerfWrap table thead th:nth-child(6) {
1681
      background: linear-gradient(180deg, #ffa94d, #e8590c)
1682
    }
1683
 
1684
    #rdrrPerfWrap table thead th:nth-child(7) {
1685
      background: linear-gradient(180deg, #9775fa, #7048e8)
1686
    }
1687
 
1688
    #rdrrPerfWrap table thead th:nth-child(8) {
1689
      background: linear-gradient(180deg, #ffd43b, #e8ac00);
1690
      color: #3a2500
1691
    }
1692
 
1693
    #rdrrPerfWrap table thead th:nth-child(8) small {
1694
      color: rgba(58, 37, 0, .75)
1695
    }
1696
 
1697
    #rdrrPerfWrap table thead th:nth-child(9) {
1698
      background: linear-gradient(180deg, #ff922b, #e8590c)
1699
    }
1700
 
1701
    #rdrrPerfWrap table thead th:last-child {
1702
      background: linear-gradient(180deg, #ff6b6b, #e03131)
1703
    }
1704
 
1705
    #rdrrPerfWrap table tbody tr:hover {
1706
      background: #f6f8fd
1707
    }
1708
 
1709
    /* rank rows keep their original background tint from today_po_rbm inline style */
1710
    #rdrrPerfWrap table tbody tr td:nth-child(2) {
1711
      text-align: left;
1712
      font-weight: 700;
1713
      color: var(--ink)
1714
    }
1715
 
1716
    #rdrrPerfWrap table tbody tr td:first-child img {
1717
      width: 24px;
1718
      height: 24px
1719
    }
1720
 
1721
    #rdrrPerfWrap table tbody tr:first-child td {
1722
      font-weight: 700
1723
    }
1724
 
1725
    #rdrrPerfWrap table tbody tr td:last-child {
1726
      font-weight: 770;
1727
      font-size: 13.5px;
1728
      font-variant-numeric: tabular-nums
1729
    }
1730
 
1731
    /* purchase-milestones (brand Γ— RBM) container β€” restyles the injected Bootstrap fragment */
1732
    #rdrrPmWrap {
1733
      overflow-x: auto
1734
    }
1735
 
1736
    #rdrrPmWrap table {
1737
      width: 100%;
1738
      border-collapse: separate;
1739
      border-spacing: 0;
1740
      font-size: 12.5px;
1741
      margin-bottom: 12px;
1742
      background: #fff
1743
    }
1744
 
1745
    #rdrrPmWrap table th, #rdrrPmWrap table td {
1746
      padding: 8px 8px;
1747
      border-bottom: 1px solid var(--line2);
1748
      border-right: 1px solid var(--line2);
1749
      text-align: right;
1750
      font-variant-numeric: tabular-nums;
1751
      color: var(--ink);
1752
      vertical-align: middle
1753
    }
1754
 
1755
    #rdrrPmWrap table th:first-child, #rdrrPmWrap table td:first-child {
1756
      text-align: left;
1757
      border-left: 1px solid var(--line2);
1758
      font-weight: 650;
1759
      position: sticky;
1760
      left: 0;
1761
      background: #fff;
1762
      z-index: 1;
1763
      min-width: 130px
1764
    }
1765
 
1766
    #rdrrPmWrap table thead th {
1767
      text-transform: uppercase;
1768
      letter-spacing: .04em;
1769
      font-size: 10.5px;
1770
      color: var(--soft);
1771
      font-weight: 700;
1772
      background: #fafbfe;
1773
      border-top: 1px solid var(--line);
1774
      border-bottom: 1px solid var(--line);
1775
      text-align: center
1776
    }
1777
 
1778
    #rdrrPmWrap table thead th[colspan] {
1779
      font-size: 12px;
1780
      padding: 8px 6px;
1781
      color: #fff
1782
    }
1783
 
1784
    #rdrrPmWrap table thead th p {
1785
      margin: 0;
1786
      font-size: 13px;
1787
      font-weight: 770;
1788
      letter-spacing: .01em;
1789
      line-height: 1.1
1790
    }
1791
 
1792
    #rdrrPmWrap table thead tr:first-child th:first-child {
1793
      background: #fafbfe;
1794
      color: var(--soft)
1795
    }
1796
 
1797
    #rdrrPmWrap table tbody tr:hover {
1798
      background: #f6f8fd
1799
    }
1800
 
1801
    #rdrrPmWrap table tbody tr:hover td:first-child {
1802
      background: #f6f8fd
1803
    }
1804
 
1805
    #rdrrPmWrap table tr.green td {
1806
      background: #eaf7ef !important;
1807
      font-weight: 770;
1808
      color: #177a3a
1809
    }
1810
 
1811
    #rdrrPmWrap table tr.green td:first-child {
1812
      background: #eaf7ef !important;
1813
      color: #177a3a
1814
    }
1815
 
1816
    /* known brand accents (extend as more brands appear) */
1817
    #rdrrPmWrap table thead th.vivo {
1818
      background: linear-gradient(180deg, #00baf2, #0a8fb5)
1819
    }
1820
 
1821
    #rdrrPmWrap table thead th.oppo {
1822
      background: linear-gradient(180deg, #20a558, #177a3a)
1823
    }
1824
 
1825
    #rdrrPmWrap table thead th.samsung {
1826
      background: linear-gradient(180deg, #0b3d91, #071e51)
1827
    }
1828
 
1829
    #rdrrPmWrap table thead th.alcatel {
1830
      background: linear-gradient(180deg, #5c7cfa, #3b5bdb)
1831
    }
1832
 
1833
    #rdrrPmWrap table thead th.motorola {
1834
      background: linear-gradient(180deg, #495057, #212529)
1835
    }
1836
 
1837
    #rdrrPmWrap table thead th.hmd {
1838
      background: linear-gradient(180deg, #7048e8, #5b34c9)
1839
    }
1840
 
1841
    #rdrrPmWrap table thead th.xiaomi {
1842
      background: linear-gradient(180deg, #ffa726, #e8590c)
1843
    }
1844
 
1845
    #rdrrPmWrap table thead th.lava {
1846
      background: linear-gradient(180deg, #e03131, #a11515)
1847
    }
1848
 
1849
    #rdrrPmWrap table thead th.poco {
1850
      background: linear-gradient(180deg, #ffd43b, #e8ac00);
1851
      color: #3a2500
1852
    }
1853
 
1854
    #rdrrPmWrap table thead th.realme {
1855
      background: linear-gradient(180deg, #f59f00, #e8590c)
1856
    }
1857
 
1858
    #rdrrPmWrap table thead th.apple {
1859
      background: linear-gradient(180deg, #495057, #141a2b)
1860
    }
1861
 
1862
    #rdrrPmWrap table thead th.oneplus {
1863
      background: linear-gradient(180deg, #e03131, #a11515)
1864
    }
1865
 
1866
    #rdrrPmWrap table thead th.tecno {
1867
      background: linear-gradient(180deg, #0ca678, #087a56)
1868
    }
1869
 
1870
    #rdrrPmWrap table thead th.ai + {
1871
      background: linear-gradient(180deg, #7048e8, #5b34c9)
1872
    }
1873
 
1874
    #rdrrPmWrap table thead th.total {
1875
      background: linear-gradient(180deg, #3b5bdb, #28449e)
1876
    }
1877
 
1878
    /* default gradient for any unmapped brand */
1879
    #rdrrPmWrap table thead th[colspan]:not(.vivo):not(.oppo):not(.samsung):not(.alcatel):not(.motorola):not(.hmd):not(.xiaomi):not(.lava):not(.poco):not(.realme):not(.apple):not(.oneplus):not(.tecno):not(.total) {
1880
      background: linear-gradient(180deg, var(--brand2), var(--brand))
1881
    }
1882
 
1883
    #rdrrPmWrap table td.currency {
1884
      font-weight: 600
1885
    }
1886
 
37444 ranu 1887
    @media (max-width: 960px) {
1888
      .kpis {
1889
        grid-template-columns:repeat(2, 1fr)
1890
      }
1891
 
1892
      .brand h1 {
1893
        font-size: 22px
1894
      }
1895
 
1896
      .status-grid {
1897
        grid-template-columns:1fr
1898
      }
1899
    }
1900
  </style>
1901
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css"/>
1902
</head>
1903
<body>
1904
<div class="wrap">
1905
  <header class="top">
1906
    <div class="brand">
1907
      <div class="crumb"><a href="/indent/today_po_rbm">&larr; Today PO / RBM</a> &middot; Sales &middot; Indent</div>
1908
      <h1>RBM DRR Dashboard <span class="live"><i></i>Live</span></h1>
1909
    </div>
1910
    <div class="hd-right">
1911
      <input class="ctl" id="rdrrPeriod" type="text" placeholder="Select date range"/>
1912
      <button class="btn-r" id="rdrrApply">Apply</button>
1913
    </div>
1914
  </header>
1915
 
1916
  <div class="kpis">
1917
    <div class="kpi a">
1918
      <div class="top">
1919
        <div class="ic">
1920
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
1921
               stroke-linejoin="round">
1922
            <path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>
1923
          </svg>
1924
        </div>
1925
        <div class="label">Total Achieved</div>
1926
      </div>
1927
      <div class="val" id="rdrrKpiAch">&mdash;</div>
1928
      <div class="foot" id="rdrrKpiAchSub">Actual billed across all RBMs</div>
1929
    </div>
1930
    <div class="kpi b">
1931
      <div class="top">
1932
        <div class="ic">
1933
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
1934
               stroke-linejoin="round">
1935
            <circle cx="12" cy="12" r="9"/>
1936
            <circle cx="12" cy="12" r="5"/>
1937
            <circle cx="12" cy="12" r="1.5" fill="currentColor"/>
1938
          </svg>
1939
        </div>
1940
        <div class="label">Total Target</div>
1941
      </div>
1942
      <div class="val" id="rdrrKpiTgt">&mdash;</div>
1943
      <div class="foot" id="rdrrKpiTgtSub">Sum of daily target snapshots</div>
1944
    </div>
1945
    <div class="kpi c">
1946
      <div class="top">
1947
        <div class="ic">
1948
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
1949
               stroke-linejoin="round">
1950
            <path d="M3 17l6-6 4 4 8-8"/>
1951
            <path d="M17 7h4v4"/>
1952
          </svg>
1953
        </div>
1954
        <div class="label">Achievement %</div>
1955
      </div>
1956
      <div class="val" id="rdrrKpiPct">&mdash;</div>
1957
      <div class="foot" id="rdrrKpiPctSub">Total ACH / Total TGT</div>
1958
    </div>
1959
    <div class="kpi d clickable" id="rdrrKpiTopCard" title="Click to see achieved vs pending RBMs">
1960
      <div class="top">
1961
        <div class="ic">
1962
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"
1963
               stroke-linejoin="round">
1964
            <path d="M12 2l3 6.5 7 1-5 5 1.5 7L12 18l-6.5 3.5L7 14.5 2 9.5l7-1L12 2z"/>
1965
          </svg>
1966
        </div>
1967
        <div class="label">RBMs β‰₯ 100% Target</div>
1968
      </div>
1969
      <div class="val" id="rdrrKpiTop">&mdash;</div>
1970
      <div class="foot" id="rdrrKpiTopSub">Rows meeting or beating target</div>
1971
      <span class="hint">Click for list &rsaquo;</span>
1972
    </div>
1973
  </div>
1974
 
1975
  <div class="sectionlabel">RBM &times; Warehouse &times; Movement Bucket</div>
1976
  <div class="legend">
1977
    <span class="lg hid"><i></i><span class="lgt">HID</span></span>
1978
    <span class="lg fast"><i></i><span class="lgt">FAST</span></span>
1979
    <span class="lg run"><i></i><span class="lgt">RUN</span></span>
1980
    <span class="lg slow"><i></i><span class="lgt">SLOW</span></span>
1981
    <span class="lg other"><i></i><span class="lgt">OTHER</span></span>
1982
  </div>
1983
  <div class="card">
1984
    <div class="card-hd">
1985
      <div>
1986
        <h2>Achievement vs Target</h2>
1987
        <p class="desc">Click any row for a per-bucket breakdown and the catalogs sold.</p>
1988
      </div>
1989
      <span class="badge-period" id="rdrrPeriodLabel">&mdash;</span>
1990
    </div>
1991
    <div id="rdrrTableWrap">
1992
      <div class="loading">
1993
        <div class="spinner"></div>
1994
        Loading&hellip;
1995
      </div>
1996
    </div>
1997
    <div class="foot-note">
1998
      <b>TGT</b> is summed from persisted per-day snapshots (<code>inventory.rbm_targets</code>) β€” days with no
1999
      scheduler-written snapshot contribute 0.
2000
      <b>ACH</b> is computed from source orders (<code>transaction.order</code>) for the range.
2001
    </div>
2002
  </div>
37460 ranu 2003
 
2004
  <!-- >15 Days Aging Sold -->
2005
  <div class="sectionlabel">&gt; 15 Days Aging Sold</div>
2006
  <div class="card">
2007
    <div class="card-hd">
2008
      <div>
2009
        <h2>Aging Inventory Cleared</h2>
2010
        <p class="desc">Billed value of items that were &gt; 15 days old at sale, per RBM, for the picked range.</p>
2011
      </div>
2012
      <span class="badge-period" id="rdrrAgingPeriod">&mdash;</span>
2013
    </div>
2014
    <div id="rdrrAgingWrap">
2015
      <div class="loading">
2016
        <div class="spinner"></div>
2017
        Loading&hellip;
2018
      </div>
2019
    </div>
2020
  </div>
2021
 
2022
  <!-- Partner Billing Count -->
2023
  <div class="sectionlabel">Partner Billing Count <span
2024
          style="color:var(--soft);font-weight:600;text-transform:none;letter-spacing:0;margin-left:6px">(Target: &gt;1L, Non-Target: &gt;20K)</span>
2025
  </div>
2026
  <div class="card">
2027
    <div class="card-hd">
2028
      <div>
2029
        <h2>Partners Who Billed This Month</h2>
2030
        <p class="desc">Counts partners meeting the billing threshold in each week bucket. Always month-to-date (weekly
2031
          buckets are inherently monthly).</p>
2032
      </div>
2033
      <span class="badge-period" id="rdrrBillingPeriod">&mdash;</span>
2034
    </div>
2035
    <div id="rdrrBillingWrap">
2036
      <div class="loading">
2037
        <div class="spinner"></div>
2038
        Loading&hellip;
2039
      </div>
2040
    </div>
2041
  </div>
37468 ranu 2042
 
2043
  <!-- RBM Performance Dashboard (MTD) β€” extracted from /indent/today_po_rbm without any backend change -->
2044
  <div class="sectionlabel">RBM Performance Dashboard (MTD)</div>
2045
  <div class="card">
2046
    <div class="card-hd">
2047
      <div>
2048
        <h2>Composite MTD Ranking</h2>
2049
        <p class="desc">Rank of RBMs by weighted score across Talk Time (10%) + MTD Achievement (55%) + Aging (2%) +
2050
          &gt;1L Partners (29%) + Rating (2%) + Partners Rated (2%).</p>
2051
      </div>
2052
      <span class="badge-period" id="rdrrPerfMonth">MTD</span>
2053
    </div>
2054
    <div id="rdrrPerfWrap">
2055
      <div class="loading">
2056
        <div class="spinner"></div>
2057
        Loading&hellip;
2058
      </div>
2059
    </div>
2060
  </div>
2061
 
2062
  <!-- Today PO & Billed β€” Brand Γ— RBM matrix (reuses /indent/today_po_table_fragment) -->
2063
  <div class="sectionlabel">Today PO &amp; Billed β€” Brand &times; RBM</div>
2064
  <div class="card">
2065
    <div class="card-hd">
2066
      <div>
2067
        <h2>Purchase Milestones by Brand</h2>
2068
        <p class="desc">Today's PO value / partner count / total billed, per RBM &times; brand. Always today
2069
          (independent of the range picker above).</p>
2070
      </div>
2071
      <select id="rdrrPmCategory" class="ctl" style="min-width:170px;height:34px;padding:6px 12px">
2072
        <option value="RBM">All RBMs</option>
2073
        <option value="NSM">All NSMs</option>
2074
        <option value="RSM">All RSMs</option>
2075
        <option value="BM">All BMs</option>
2076
        <option value="DM">All DMs</option>
2077
        <option value="CM">All CMs</option>
2078
        <option value="ASM">All ASMs</option>
2079
      </select>
2080
    </div>
2081
    <div id="rdrrPmWrap">
2082
      <div class="loading">
2083
        <div class="spinner"></div>
2084
        Loading&hellip;
2085
      </div>
2086
    </div>
2087
  </div>
37469 ranu 2088
 
2089
  <!-- RBM Call Target Summary β€” full interactive page injected via iframe srcdoc (no backend change) -->
2090
  <div class="sectionlabel">RBM Call Target Summary</div>
2091
  <div class="card">
2092
    <div class="card-hd">
2093
      <div>
2094
        <h2>Today's Call Coverage per RBM</h2>
2095
        <p class="desc">Full interactive view β€” all popups, drill-downs and downloads work exactly like the standalone
2096
          page.</p>
2097
      </div>
2098
      <a class="badge-period" href="/indent/rbm_call_target" target="_blank" style="text-decoration:none">Open in new
2099
        tab &rsaquo;</a>
2100
    </div>
2101
    <iframe id="rdrrCallFrame" title="RBM Call Target Summary"
2102
            style="width:100%;min-height:800px;border:0;border-radius:10px;background:#fff;display:block"></iframe>
2103
  </div>
37444 ranu 2104
</div>
2105
 
2106
<!-- achieved-vs-pending modal (opens from the RBMs β‰₯ 100% Target KPI card) -->
2107
<div class="status-back" id="rdrrStatusBack">
2108
  <div class="status-modal">
2109
    <button class="x" id="rdrrStatusClose" aria-label="Close">&times;</button>
2110
    <h3>Target Status by RBM</h3>
2111
    <p class="desc" id="rdrrStatusDesc">&mdash;</p>
2112
    <div class="status-grid">
2113
      <div class="status-col good">
2114
        <h4>βœ… Achieved <span class="cnt" id="rdrrStatusAchCnt">0</span></h4>
2115
        <div class="status-list" id="rdrrStatusAchList"></div>
2116
      </div>
2117
      <div class="status-col bad">
2118
        <h4>⚠ Pending <span class="cnt" id="rdrrStatusPndCnt">0</span></h4>
2119
        <div class="status-list" id="rdrrStatusPndList"></div>
2120
      </div>
2121
    </div>
2122
  </div>
2123
</div>
2124
 
37469 ranu 2125
<!-- call-target drill-down drawer (Called Partners / OOS Calls) -->
2126
<div class="rdrr-back" id="rdrrCallDrawerBack">
2127
  <div class="rdrr-panel">
2128
    <button class="x" id="rdrrCallDrawerClose" aria-label="Close">&times;</button>
2129
    <h3 id="rdrrCallDrawerTitle">&mdash;</h3>
2130
    <p class="desc" id="rdrrCallDrawerDesc">&mdash;</p>
2131
    <div id="rdrrCallDrawerBody">
2132
      <div class="loading">
2133
        <div class="spinner"></div>
2134
        Loading&hellip;
2135
      </div>
2136
    </div>
2137
  </div>
2138
</div>
2139
 
37444 ranu 2140
<!-- drill-down panel -->
2141
<div class="rdrr-back" id="rdrrBack">
2142
  <div class="rdrr-panel">
2143
    <button class="x" id="rdrrClose" aria-label="Close">&times;</button>
2144
    <h3 id="rdrrDdTitle">&mdash;</h3>
2145
    <p class="desc" id="rdrrDdDesc">&mdash;</p>
2146
 
2147
    <div class="rdrr-total">
2148
      <div>
2149
        <div class="k">Achieved</div>
2150
        <div class="v" id="rdrrDdAch">&mdash;</div>
2151
      </div>
2152
      <div>
2153
        <div class="k">Target</div>
2154
        <div class="v" id="rdrrDdTgt">&mdash;</div>
2155
      </div>
2156
      <div>
2157
        <div class="k">Achievement</div>
2158
        <div class="v" id="rdrrDdPct">&mdash;</div>
2159
      </div>
2160
    </div>
2161
 
2162
    <div class="sectionlabel" style="margin-top:2px">Movement Split β€” Achievement vs Target</div>
2163
    <div class="bbars" id="rdrrDdBars"></div>
2164
 
2165
    <div class="sectionlabel">Brand Mix β€” Share of Achievement <span
2166
            style="color:var(--soft);font-weight:600;text-transform:none;letter-spacing:0;margin-left:6px">(click a brand for movement split)</span>
2167
    </div>
2168
    <div id="rdrrDdBrands">
2169
      <div class="loading">
2170
        <div class="spinner"></div>
2171
        Loading brand mix&hellip;
2172
      </div>
2173
    </div>
2174
  </div>
2175
</div>
2176
 
2177
<script src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
2178
<script src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
2179
<script src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
2180
<script>
2181
  (function () {
2182
    var DEFAULT_START = "$defaultStartDate";
2183
    var DEFAULT_END = "$defaultEndDate";
2184
 
2185
    // Prefer query-string range if the caller provided one (e.g. from today_po_rbm's date picker).
2186
    var url = new URL(window.location.href);
2187
    var qsStart = url.searchParams.get("startDate");
2188
    var qsEnd = url.searchParams.get("endDate");
2189
    var startDate = qsStart || DEFAULT_START;
2190
    var endDate = qsEnd || DEFAULT_END;
2191
 
2192
    function fmtDate(s) {
2193
      return moment(s).format("DD MMM");
2194
    }
2195
 
2196
    function fmtLakh(v) {
2197
      v = Number(v) || 0;
2198
      return (v / 100000).toFixed(1) + "L";
2199
    }
2200
 
2201
    function pctClass(p) {
2202
      if (p >= 95) return "good";
2203
      if (p >= 41) return "warn";
2204
      return "bad";
2205
    }
2206
 
2207
    function pctLabel(ach, tgt) {
2208
      if (!tgt || tgt <= 0) return {text: "-", cls: "na", num: null};
2209
      var p = (ach / tgt) * 100;
2210
      return {text: p.toFixed(1) + "%", cls: pctClass(p), num: p};
2211
    }
2212
 
2213
    function pctBarWidth(ach, tgt) {
2214
      if (!tgt || tgt <= 0) return 0;
2215
      return Math.min(100, (ach / tgt) * 100);
2216
    }
2217
 
2218
    // Initialise the range picker.
2219
    $("#rdrrPeriod").daterangepicker({
2220
      startDate: moment(startDate),
2221
      endDate: moment(endDate),
2222
      locale: {format: "YYYY-MM-DD", cancelLabel: "Clear"}
2223
    });
2224
    $("#rdrrPeriod").on("apply.daterangepicker", function (ev, picker) {
2225
      startDate = picker.startDate.format("YYYY-MM-DD");
2226
      endDate = picker.endDate.format("YYYY-MM-DD");
2227
    });
2228
 
2229
    // Defensive: read the picker's current state at click time in case
2230
    // the apply.daterangepicker event was swallowed for any reason.
2231
    $("#rdrrApply").on("click", function () {
2232
      var p = $("#rdrrPeriod").data("daterangepicker");
2233
      if (p) {
2234
        startDate = p.startDate.format("YYYY-MM-DD");
2235
        endDate = p.endDate.format("YYYY-MM-DD");
2236
      }
2237
      load();
2238
    });
2239
 
2240
    function load() {
2241
      $("#rdrrTableWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
37460 ranu 2242
      $("#rdrrAgingWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
2243
      $("#rdrrBillingWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
37444 ranu 2244
      $("#rdrrPeriodLabel").text(fmtDate(startDate) + " – " + fmtDate(endDate));
37460 ranu 2245
      $("#rdrrAgingPeriod").text(fmtDate(startDate) + " – " + fmtDate(endDate));
37444 ranu 2246
      fetch("/rbm-drr/data?startDate=" + startDate + "&endDate=" + endDate, {credentials: "same-origin"})
2247
              .then(function (r) {
2248
                return r.json().then(function (b) {
2249
                  return {ok: r.ok, body: b};
2250
                });
2251
              })
2252
              .then(function (res) {
2253
                if (!res.ok) {
2254
                  $("#rdrrTableWrap").html('<div class="empty">' + escapeHtml(res.body && res.body.error ? res.body.error : "Failed to load.") + '</div>');
2255
                  return;
2256
                }
2257
                render(res.body);
2258
              })
2259
              .catch(function (e) {
2260
                $("#rdrrTableWrap").html('<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>');
2261
              });
37460 ranu 2262
 
2263
      fetch("/rbm-drr/extras?startDate=" + startDate + "&endDate=" + endDate, {credentials: "same-origin"})
2264
              .then(function (r) {
2265
                return r.json().then(function (b) {
2266
                  return {ok: r.ok, body: b};
2267
                });
2268
              })
2269
              .then(function (res) {
2270
                if (!res.ok) {
2271
                  var msg = '<div class="empty">' + escapeHtml(res.body && res.body.error ? res.body.error : "Failed to load.") + '</div>';
2272
                  $("#rdrrAgingWrap").html(msg);
2273
                  $("#rdrrBillingWrap").html(msg);
2274
                  return;
2275
                }
2276
                renderAging(res.body);
2277
                renderPartnerBilling(res.body);
2278
              })
2279
              .catch(function (e) {
2280
                var msg = '<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>';
2281
                $("#rdrrAgingWrap").html(msg);
2282
                $("#rdrrBillingWrap").html(msg);
2283
              });
37444 ranu 2284
    }
2285
 
37460 ranu 2286
    function renderAging(data) {
2287
      var rows = data.aging || [];
2288
      var totals = data.agingTotals || {};
2289
      var balance = data.balance || {};
2290
      if (rows.length === 0) {
2291
        $("#rdrrAgingWrap").html('<div class="empty"><div class="ei">πŸ“¦</div>No aging inventory sold in this range.</div>');
2292
        return;
2293
      }
2294
      var html = ['<table class="xtable"><thead><tr>',
2295
        '<th>RBM</th>',
2296
        '<th class="num g-hid">HID</th>',
2297
        '<th class="num g-fast">FAST</th>',
2298
        '<th class="num g-run">RUN</th>',
2299
        '<th class="num g-slow">SLOW</th>',
2300
        '<th class="num g-other">OTHER</th>',
2301
        '<th class="num g-total">TOTAL</th>',
2302
        '</tr></thead><tbody>'];
2303
      rows.forEach(function (r) {
2304
        html.push('<tr>' +
2305
                '<td class="rbm-nm">' + escapeHtml(r.rbmName || '-') + '</td>' +
2306
                cell(r.hid, 'g-hid') + cell(r.fast, 'g-fast') + cell(r.run, 'g-run') +
2307
                cell(r.slow, 'g-slow') + cell(r.other, 'g-other') + cell(r.total, 'g-total') +
2308
                '</tr>');
2309
      });
2310
      html.push('<tr class="tot">' +
2311
              '<td>Total</td>' +
2312
              cell(totals.hid, 'g-hid') + cell(totals.fast, 'g-fast') + cell(totals.run, 'g-run') +
2313
              cell(totals.slow, 'g-slow') + cell(totals.other, 'g-other') + cell(totals.total, 'g-total') +
2314
              '</tr>');
2315
      html.push('<tr class="bal">' +
2316
              '<td class="hdr">15-Day Balance Value</td>' +
2317
              cell(balance.hid) + cell(balance.fast) + cell(balance.run) +
2318
              cell(balance.slow) + cell(balance.other) + cell(balance.total) +
2319
              '</tr>');
2320
      html.push('</tbody></table>');
2321
      $("#rdrrAgingWrap").html(html.join(""));
2322
    }
2323
 
2324
    function cell(v, cls) {
2325
      v = Number(v) || 0;
2326
      var zero = v === 0 ? ' zero' : '';
2327
      var extra = cls ? ' ' + cls : '';
2328
      return '<td class="num' + extra + zero + '">' + formatIndian(v) + '</td>';
2329
    }
2330
 
2331
    function formatIndian(n) {
2332
      n = Math.round(Number(n) || 0);
2333
      if (n === 0) return '0';
2334
      var s = n.toString();
2335
      var lastThree = s.substring(s.length - 3);
2336
      var otherNums = s.substring(0, s.length - 3);
2337
      if (otherNums !== '') lastThree = ',' + lastThree;
2338
      return otherNums.replace(/\B(?=(\d{2})+(?!\d))/g, ',') + lastThree;
2339
    }
2340
 
2341
    function renderPartnerBilling(data) {
2342
      var rows = data.partnerBilling || [];
2343
      var totals = data.partnerBillingTotals || {};
2344
      $("#rdrrBillingPeriod").text(data.partnerBillingMonth || '');
2345
      if (rows.length === 0) {
2346
        $("#rdrrBillingWrap").html('<div class="empty"><div class="ei">πŸ‘₯</div>No targeted partners this month.</div>');
2347
        return;
2348
      }
2349
      var html = ['<table class="xtable"><thead><tr>',
2350
        '<th>RBM</th>',
2351
        '<th class="num">Targeted</th>',
2352
        '<th class="num">Week 1<br><small style="color:var(--soft);font-weight:600">(1–7)</small></th>',
2353
        '<th class="num">Week 2<br><small style="color:var(--soft);font-weight:600">(8–15)</small></th>',
2354
        '<th class="num">Week 3<br><small style="color:var(--soft);font-weight:600">(16–22)</small></th>',
2355
        '<th class="num">Week 4<br><small style="color:var(--soft);font-weight:600">(23–end)</small></th>',
2356
        '<th class="num g-total">MTD</th>',
2357
        '<th class="num">Zero Billed<br><small style="color:var(--soft);font-weight:600">(&lt;1L / &lt;20K)</small></th>',
2358
        '</tr></thead><tbody>'];
2359
      rows.forEach(function (r) {
2360
        html.push('<tr>' +
2361
                '<td class="rbm-nm">' + escapeHtml(r.rbmName || '-') + '</td>' +
2362
                '<td class="num">' + pill(r.targeted, '') + '</td>' +
2363
                '<td class="num">' + pill(r.w1, ratio(r.w1, r.targeted)) + '</td>' +
2364
                '<td class="num">' + pill(r.w2, ratio(r.w2, r.targeted)) + '</td>' +
2365
                '<td class="num">' + pill(r.w3, ratio(r.w3, r.targeted)) + '</td>' +
2366
                '<td class="num">' + pill(r.w4, ratio(r.w4, r.targeted)) + '</td>' +
2367
                '<td class="num g-total">' + pill(r.mtd, ratio(r.mtd, r.targeted)) + '</td>' +
2368
                '<td class="num">' + pill(r.zero, r.zero > 0 ? 'warn' : 'zero') + '</td>' +
2369
                '</tr>');
2370
      });
2371
      html.push('<tr class="tot">' +
2372
              '<td>Total</td>' +
2373
              '<td class="num">' + formatIndian(totals.targeted) + '</td>' +
2374
              '<td class="num">' + formatIndian(totals.w1) + '</td>' +
2375
              '<td class="num">' + formatIndian(totals.w2) + '</td>' +
2376
              '<td class="num">' + formatIndian(totals.w3) + '</td>' +
2377
              '<td class="num">' + formatIndian(totals.w4) + '</td>' +
2378
              '<td class="num g-total">' + formatIndian(totals.mtd) + '</td>' +
2379
              '<td class="num">' + formatIndian(totals.zero) + '</td>' +
2380
              '</tr>');
2381
      html.push('</tbody></table>');
2382
      $("#rdrrBillingWrap").html(html.join(""));
2383
    }
2384
 
2385
    function pill(v, cls) {
2386
      v = Number(v) || 0;
2387
      var c = cls || (v === 0 ? 'zero' : '');
2388
      return '<span class="cnt-pill ' + c + '">' + formatIndian(v) + '</span>';
2389
    }
2390
 
2391
    function ratio(part, total) {
2392
      part = Number(part) || 0;
2393
      total = Number(total) || 0;
2394
      if (total === 0) return 'zero';
2395
      var p = (part / total) * 100;
2396
      if (p >= 60) return 'good';
2397
      if (p >= 30) return '';
2398
      if (p > 0) return 'warn';
2399
      return 'zero';
2400
    }
2401
 
37444 ranu 2402
    // Cached latest payload so the "Target Status by RBM" modal can render
2403
    // without a re-fetch when the KPI card is clicked.
2404
    var LAST_PAYLOAD = null;
2405
 
2406
    function render(data) {
2407
      LAST_PAYLOAD = data;
2408
      var rows = data.rows || [];
2409
      var t = data.totals || {};
2410
 
2411
      $("#rdrrKpiAch").html('&#8377;&nbsp;' + fmtLakh(t.totalAch));
2412
      $("#rdrrKpiTgt").html('&#8377;&nbsp;' + fmtLakh(t.totalTgt));
2413
      var pk = pctLabel(t.totalAch, t.totalTgt);
2414
      $("#rdrrKpiPct").html(pk.cls === "na" ? '<span class="u">n/a</span>' :
2415
              '<span class="pct ' + pk.cls + '">' + pk.text + '</span>');
2416
      $("#rdrrKpiTop").html((t.rbmsAtOrAbove100 || 0) + ' <span class="u">/ ' + (t.rbmRowCount || 0) + '</span>');
2417
 
2418
      if (rows.length === 0) {
2419
        $("#rdrrTableWrap").html('<div class="empty"><div class="ei">πŸ“­</div>No RBM rows in this range.</div>');
2420
        return;
2421
      }
2422
 
2423
      var buckets = [
2424
        {key: "hid", label: "HID"},
2425
        {key: "fast", label: "FAST"},
2426
        {key: "run", label: "RUN"},
2427
        {key: "slow", label: "SLOW"},
2428
        {key: "other", label: "OTHER"}
2429
      ];
2430
 
2431
      var html = ['<table id="rdrrGrid"><thead><tr>',
2432
        '<th>RBM &middot; Warehouse</th>',
2433
        '<th class="num g-total">Total<br><small style="color:var(--soft);font-weight:600">ACH / TGT</small></th>',
2434
        '<th class="num g-total">%</th>'];
2435
      buckets.forEach(function (b) {
2436
        html.push('<th class="num g-' + b.key + '">' + b.label + '<br><small style="color:var(--soft);font-weight:600">ACH / TGT</small></th>');
2437
        html.push('<th class="num g-' + b.key + '">%</th>');
2438
      });
2439
      html.push('<th></th></tr></thead><tbody>');
2440
 
2441
      rows.forEach(function (r) {
2442
        var tr = ['<tr class="clickable" data-authid="' + r.authId + '" data-warehouseid="' + r.warehouseId + '" data-rbmname="' + escapeHtml(r.rbmName) + '" data-warehousename="' + escapeHtml(r.warehouseName) + '">'];
2443
        tr.push('<td><div class="rbm-cell"><span class="rn">' + escapeHtml(r.rbmName) + '</span><span class="wh">' + escapeHtml(r.warehouseName) + '</span></div></td>');
2444
        tr.push(cellPair(r.totalAch, r.totalTgt));
2445
        buckets.forEach(function (b) {
2446
          tr.push(cellPair(r[b.key + "Ach"], r[b.key + "Tgt"]));
2447
        });
2448
        tr.push('<td class="chev">&rsaquo;</td>');
2449
        tr.push('</tr>');
2450
        html.push(tr.join(""));
2451
      });
2452
 
2453
      // totals row
2454
      var totTr = ['<tr class="totalrow"><td><strong>Total</strong></td>'];
2455
      totTr.push(cellPair(t.totalAch, t.totalTgt, true));
2456
      buckets.forEach(function (b) {
2457
        totTr.push(cellPair(t[b.key + "Ach"], t[b.key + "Tgt"], true));
2458
      });
2459
      totTr.push('<td></td></tr>');
2460
      html.push(totTr.join(""));
2461
 
2462
      html.push('</tbody></table>');
2463
      $("#rdrrTableWrap").html(html.join(""));
2464
 
2465
      // Cache the parsed row on each <tr> so drill-down can render bars immediately.
2466
      rows.forEach(function (r) {
2467
        $("#rdrrGrid tbody tr").filter(function () {
2468
          return +this.dataset.authid === r.authId && +this.dataset.warehouseid === r.warehouseId;
2469
        }).each(function () {
2470
          $(this).data("cached", r);
2471
        });
2472
      });
2473
 
2474
      $("#rdrrGrid tbody tr.clickable").on("click", function () {
2475
        var d = this.dataset;
2476
        var cached = $(this).data("cached");
2477
        openDrilldown(+d.authid, +d.warehouseid, d.rbmname, d.warehousename, cached);
2478
      });
2479
    }
2480
 
2481
    function cellPair(ach, tgt, isTotal) {
2482
      var p = pctLabel(ach, tgt);
2483
      var vhtml = '<td class="num"><div class="cell-val">' + fmtLakh(ach) + ' <small>/ ' + fmtLakh(tgt) + '</small></div></td>';
2484
      var barCls = p.cls === "na" ? "" : p.cls;
2485
      var barW = pctBarWidth(ach, tgt);
2486
      var pctHtml = '<td class="num"><span class="pct ' + p.cls + '">' + p.text + '</span>' +
2487
              (barCls ? '<div class="bar"><i class="' + barCls + '" style="width:' + barW.toFixed(1) + '%"></i></div>' : '') +
2488
              '</td>';
2489
      return vhtml + pctHtml;
2490
    }
2491
 
2492
    // --------------------------- drill-down ---------------------------
2493
 
2494
    function openDrilldown(authId, warehouseId, rbmName, warehouseName, cachedRow) {
2495
      var back = $("#rdrrBack");
2496
      $("#rdrrDdTitle").text(rbmName + " β€” " + warehouseName);
2497
      $("#rdrrDdDesc").text(fmtDate(startDate) + " – " + fmtDate(endDate));
2498
      $("#rdrrDdBars").empty();
2499
      back.addClass("show");
2500
 
2501
      if (cachedRow) {
2502
        renderBars(cachedRow);
2503
      } else {
2504
        $("#rdrrDdAch").text("β€”");
2505
        $("#rdrrDdTgt").text("β€”");
2506
        $("#rdrrDdPct").text("β€”");
2507
      }
2508
      $("#rdrrDdBrands").html('<div class="loading"><div class="spinner"></div>Loading brand mix&hellip;</div>');
2509
 
2510
      fetch("/rbm-drr/rbm-detail?authId=" + authId + "&warehouseId=" + warehouseId +
2511
              "&startDate=" + startDate + "&endDate=" + endDate, {credentials: "same-origin"})
2512
              .then(function (r) {
2513
                return r.json();
2514
              })
2515
              .then(function (data) {
2516
                renderBrands(data);
2517
              })
2518
              .catch(function (e) {
2519
                $("#rdrrDdBrands").html('<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>');
2520
              });
2521
    }
2522
 
2523
    function renderBrands(data) {
2524
      var brands = (data && data.brands) || [];
2525
      if (brands.length === 0) {
2526
        $("#rdrrDdBrands").html('<div class="empty"><div class="ei">🏷️</div>No brand sales in this range.</div>');
2527
        return;
2528
      }
2529
      var maxShare = brands[0].sharePct || 0.001;
2530
      var html = '<div class="brands">';
2531
      brands.forEach(function (b, idx) {
2532
        var barW = maxShare > 0 ? Math.min(100, (b.sharePct / maxShare) * 100) : 0;
2533
        var topCls = idx === 0 ? ' top' : '';
37460 ranu 2534
        var pc = Number(b.partnerCount) || 0;
2535
        var pcCls = pc === 0 ? ' zero' : '';
2536
        var pcLabel = pc + (pc === 1 ? ' partner' : ' partners');
37444 ranu 2537
        html += '<div class="brand-card' + topCls + '" data-idx="' + idx + '">' +
2538
                '<div class="brand-head">' +
2539
                '<div class="cx">&rsaquo;</div>' +
2540
                '<div class="bn" title="' + escapeHtml(b.brand) + '">' + escapeHtml(b.brand) + '</div>' +
2541
                '<div class="btrack"><i style="width:' + barW.toFixed(1) + '%"></i></div>' +
37460 ranu 2542
                '<div class="bpc' + pcCls + '" title="Distinct partners of this RBM who billed ' + escapeHtml(b.brand) + ' in the range">' +
2543
                '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>' +
2544
                pcLabel +
2545
                '</div>' +
37444 ranu 2546
                '<div class="bval">' + fmtLakh(b.valueSold) + '</div>' +
2547
                '<div class="bshare">' + (b.sharePct || 0).toFixed(1) + '%</div>' +
2548
                '</div>' +
2549
                '<div class="brand-body">' +
2550
                '<div class="bhdr">Movement Split within ' + escapeHtml(b.brand) + '</div>' +
2551
                renderBrandBuckets(b.buckets || []) +
2552
                '</div>' +
2553
                '</div>';
2554
      });
2555
      html += '</div>';
2556
      $("#rdrrDdBrands").html(html);
2557
 
2558
      $("#rdrrDdBrands .brand-head").on("click", function () {
2559
        $(this).closest(".brand-card").toggleClass("open");
2560
      });
2561
    }
2562
 
2563
    function renderBrandBuckets(buckets) {
2564
      if (!buckets || buckets.length === 0) {
2565
        return '<div style="color:var(--soft);font-size:12px;padding:8px 4px">No movement split available.</div>';
2566
      }
2567
      var labels = {HID: "HID", FASTMOVING: "FAST", RUNNING: "RUN", SLOWMOVING: "SLOW", OTHER: "OTHER"};
2568
      var html = '<div class="mbars">';
2569
      buckets.forEach(function (bk) {
2570
        var cls = (bk.status || "OTHER").toLowerCase();
2571
        var label = labels[bk.status] || bk.status || "OTHER";
2572
        var sp = bk.sharePctOfBrand || 0;
2573
        var barW = Math.min(100, sp);
2574
        html += '<div class="mbar ' + cls + '">' +
2575
                '<div class="mname"><i></i>' + label + '</div>' +
2576
                '<div class="mtrack"><i style="width:' + barW.toFixed(1) + '%"></i></div>' +
2577
                '<div class="mval">' + fmtLakh(bk.valueSold) + '</div>' +
2578
                '<div class="mshare">' + sp.toFixed(1) + '%</div>' +
2579
                '</div>';
2580
      });
2581
      html += '</div>';
2582
      return html;
2583
    }
2584
 
2585
    function renderBars(row) {
2586
      var totalAch = row.totalAch, totalTgt = row.totalTgt;
2587
      $("#rdrrDdAch").html('&#8377;&nbsp;' + fmtLakh(totalAch));
2588
      $("#rdrrDdTgt").html('&#8377;&nbsp;' + fmtLakh(totalTgt));
2589
      var pt = pctLabel(totalAch, totalTgt);
2590
      $("#rdrrDdPct").html(pt.cls === "na" ? '<span style="color:var(--soft);font-size:14px">n/a</span>' :
2591
              '<span class="pct ' + pt.cls + '">' + pt.text + '</span>');
2592
 
2593
      var buckets = [
2594
        {key: "hid", label: "HID"},
2595
        {key: "fast", label: "FAST"},
2596
        {key: "run", label: "RUN"},
2597
        {key: "slow", label: "SLOW"},
2598
        {key: "other", label: "OTHER"}
2599
      ];
2600
      var html = "";
2601
      buckets.forEach(function (b) {
2602
        var ach = row[b.key + "Ach"], tgt = row[b.key + "Tgt"];
2603
        var p = pctLabel(ach, tgt);
2604
        var w = pctBarWidth(ach, tgt);
2605
        html += '<div class="bbar ' + b.key + '">' +
2606
                '<div class="bname"><i></i>' + b.label + '</div>' +
2607
                '<div class="btrack"><i style="width:' + w.toFixed(1) + '%"></i></div>' +
2608
                '<div class="btgt"><b>' + fmtLakh(ach) + '</b> / ' + fmtLakh(tgt) + '</div>' +
2609
                '<div class="bpct ' + p.cls + '">' + p.text + '</div>' +
2610
                '</div>';
2611
      });
2612
      $("#rdrrDdBars").html(html);
2613
    }
2614
 
2615
    function escapeHtml(s) {
2616
      if (s == null) return "";
2617
      return String(s).replace(/[&<>"']/g, function (c) {
2618
        return {"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;"}[c];
2619
      });
2620
    }
2621
 
2622
    $("#rdrrClose").on("click", function () {
2623
      $("#rdrrBack").removeClass("show");
2624
    });
2625
    $("#rdrrBack").on("click", function (e) {
2626
      if (e.target === this) $(this).removeClass("show");
2627
    });
2628
 
2629
    // Target-status modal (achieved vs pending) β€” opens from the KPI card.
2630
    $("#rdrrKpiTopCard").on("click", function () {
2631
      openStatusModal();
2632
    });
2633
    $("#rdrrStatusClose").on("click", function () {
2634
      $("#rdrrStatusBack").removeClass("show");
2635
    });
2636
    $("#rdrrStatusBack").on("click", function (e) {
2637
      if (e.target === this) $(this).removeClass("show");
2638
    });
2639
 
2640
    function openStatusModal() {
2641
      if (!LAST_PAYLOAD) return;
2642
      var rows = (LAST_PAYLOAD.rows || []).slice();
2643
      var achieved = [], pending = [];
2644
      rows.forEach(function (r) {
2645
        if (!r.totalTgt || r.totalTgt <= 0) return;
2646
        var pct = (r.totalAch / r.totalTgt) * 100;
2647
        var enriched = {row: r, pct: pct};
2648
        if (r.totalAch >= r.totalTgt) achieved.push(enriched);
2649
        else pending.push(enriched);
2650
      });
2651
      achieved.sort(function (a, b) {
2652
        return b.pct - a.pct;
2653
      });
2654
      pending.sort(function (a, b) {
2655
        return a.pct - b.pct;
2656
      });
2657
 
2658
      $("#rdrrStatusDesc").text(fmtDate(startDate) + " – " + fmtDate(endDate));
2659
      $("#rdrrStatusAchCnt").text(achieved.length);
2660
      $("#rdrrStatusPndCnt").text(pending.length);
2661
      $("#rdrrStatusAchList").html(renderStatusList(achieved, "achieved"));
2662
      $("#rdrrStatusPndList").html(renderStatusList(pending, "pending"));
2663
      $("#rdrrStatusBack").addClass("show");
2664
 
2665
      // Bind click on each item to open the same drill-down slide-in.
2666
      $("#rdrrStatusBack .status-item").on("click", function () {
2667
        var d = this.dataset;
2668
        var cachedRow = null;
2669
        (LAST_PAYLOAD.rows || []).some(function (r) {
2670
          if (r.authId == d.authid && r.warehouseId == d.warehouseid) {
2671
            cachedRow = r;
2672
            return true;
2673
          }
2674
          return false;
2675
        });
2676
        $("#rdrrStatusBack").removeClass("show");
2677
        openDrilldown(+d.authid, +d.warehouseid, d.rbmname, d.warehousename, cachedRow);
2678
      });
2679
    }
2680
 
2681
    function renderStatusList(items, kind) {
2682
      if (items.length === 0) {
2683
        return '<div class="status-empty">' +
2684
                (kind === "achieved" ? "No RBM has met target in this range." : "All RBMs met target β€” nice!") +
2685
                '</div>';
2686
      }
2687
      var html = "";
2688
      items.forEach(function (it) {
2689
        var r = it.row;
2690
        var p = pctClass(it.pct);
2691
        html += '<div class="status-item" title="Click to view drill-down"' +
2692
                ' data-authid="' + r.authId + '" data-warehouseid="' + r.warehouseId + '"' +
2693
                ' data-rbmname="' + escapeHtml(r.rbmName) + '" data-warehousename="' + escapeHtml(r.warehouseName) + '"' +
2694
                ' style="cursor:pointer">' +
2695
                '<div><span class="rn">' + escapeHtml(r.rbmName) + '</span>' +
2696
                '<span class="wh">' + escapeHtml(r.warehouseName) + '</span></div>' +
2697
                '<div class="vv"><b>' + fmtLakh(r.totalAch) + '</b> / ' + fmtLakh(r.totalTgt) + '</div>' +
2698
                '<div class="pp ' + p + '">' + it.pct.toFixed(1) + '%</div>' +
2699
                '</div>';
2700
      });
2701
      return html;
2702
    }
2703
 
37468 ranu 2704
    // ------------------------- Today PO & Billed matrix -------------------------
2705
    // Reuses the existing /indent/today_po_table_fragment endpoint (unchanged).
2706
    // Injects the returned HTML and restyles it via #rdrrPmWrap CSS.
2707
    function loadPurchaseMilestones() {
2708
      var cat = $("#rdrrPmCategory").val() || "RBM";
2709
      $("#rdrrPmWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
2710
      $.ajax({
2711
        url: "/indent/today_po_table_fragment",
2712
        type: "GET",
2713
        data: {categoryType: cat},
2714
        success: function (html) {
2715
          $("#rdrrPmWrap").html(html);
2716
          $("#rdrrPmWrap .currency").each(function () {
2717
            var elem = $(this);
2718
            var n = parseInt(elem.text().replace(/[^\d.-]/g, ""), 10);
2719
            if (!isNaN(n)) elem.text(numberToIndianCurrency(n));
2720
          });
2721
        },
2722
        error: function () {
2723
          $("#rdrrPmWrap").html('<div class="empty">Failed to load purchase-milestones data.</div>');
2724
        }
2725
      });
2726
    }
2727
 
2728
    function numberToIndianCurrency(n) {
2729
      if (n === 0) return "0";
2730
      var s = n.toString();
2731
      var lastThree = s.substring(s.length - 3);
2732
      var other = s.substring(0, s.length - 3);
2733
      if (other !== "") lastThree = "," + lastThree;
2734
      return other.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
2735
    }
2736
 
2737
    $("#rdrrPmCategory").on("change", loadPurchaseMilestones);
2738
 
2739
    // ------------------------- RBM Performance Dashboard (MTD) -------------------------
2740
    // No dedicated backend endpoint exists β€” the perf-dashboard table is only rendered
2741
    // inline in /indent/today_po_rbm. We fetch that page and extract just the table.
2742
    // Trade-off: heavier request (server re-runs full page prep). Consider adding a
2743
    // /rbm-drr/performance fragment endpoint later if this becomes a hot path.
2744
    function loadPerformanceDashboard() {
2745
      $("#rdrrPerfWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
2746
      $.ajax({
2747
        url: "/indent/today_po_rbm",
2748
        type: "GET",
2749
        dataType: "html",
2750
        success: function (fullHtml) {
2751
          var doc = new DOMParser().parseFromString(fullHtml, "text/html");
2752
          var tbl = doc.querySelector("#performance-dashboard-table");
2753
          if (!tbl) {
2754
            $("#rdrrPerfWrap").html('<div class="empty"><div class="ei">πŸ“Š</div>No performance dashboard data available yet.</div>');
2755
            return;
2756
          }
2757
          // Fix any relative image paths (e.g. king.png / trophy-cup.png) to be root-relative.
2758
          tbl.querySelectorAll("img").forEach(function (im) {
2759
            var src = im.getAttribute("src") || "";
2760
            if (src.indexOf("resources/") !== -1 && src.charAt(0) !== "/") {
2761
              im.setAttribute("src", "/" + src.replace(/^\.\.\/+/, ""));
2762
            }
2763
          });
2764
          $("#rdrrPerfWrap").empty().append(tbl);
2765
        },
2766
        error: function () {
2767
          $("#rdrrPerfWrap").html('<div class="empty">Failed to load performance dashboard.</div>');
2768
        }
2769
      });
2770
    }
2771
 
37469 ranu 2772
    // ------------------------- RBM Call Target iframe -------------------------
2773
    // The /indent/rbm_call_target endpoint returns a Velocity FRAGMENT (no <html>,
2774
    // no Bootstrap/jQuery). When loaded directly in an iframe, Bootstrap modals
2775
    // collapse and their inner Loading… contents render inline. Fix: fetch the
2776
    // fragment, wrap it in a self-contained document that loads jQuery + Popper +
2777
    // Bootstrap, then hand it to the iframe via srcdoc. Zero backend change.
2778
    function loadCallTargetIframe() {
2779
      $.ajax({
2780
        url: "/indent/rbm_call_target",
2781
        type: "GET",
2782
        dataType: "html",
2783
        success: function (fragment) {
2784
          var doc = [
2785
            '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">',
2786
            '<meta name="viewport" content="width=device-width,initial-scale=1">',
2787
            '<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">',
2788
            '<style>body{margin:0;padding:16px;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:#fff}</style>',
2789
            '</head><body>',
2790
            fragment,
2791
            '<script src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></' + 'script>',
2792
            '<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></' + 'script>',
2793
            '<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></' + 'script>',
2794
            '</body></html>'
2795
          ].join("");
2796
          var frame = document.getElementById("rdrrCallFrame");
2797
          frame.onload = function () {
2798
            hookCallTargetDrawer(frame);
2799
          };
2800
          frame.srcdoc = doc;
2801
        },
2802
        error: function () {
2803
          document.getElementById("rdrrCallFrame").srcdoc =
2804
                  '<div style="padding:24px;font-family:system-ui;color:#97a1b5">Failed to load call-target view.</div>';
2805
        }
2806
      });
2807
    }
2808
 
2809
    // Redirect the iframe's Bootstrap-modal drill-downs into a slide-in parent drawer
2810
    // that matches the dashboard style. srcdoc iframes inherit the parent origin so
2811
    // we can freely reach into the iframe's window and override its functions.
2812
    function hookCallTargetDrawer(frame) {
2813
      var iw = frame.contentWindow;
2814
      if (!iw) return;
2815
      // Give the source's own <script> a moment to run and define the functions.
2816
      setTimeout(function () {
2817
        try {
2818
          iw.showCalledPartnerDetails = function (authId, rbmName) {
2819
            openCallTargetDrawer("called", authId, rbmName, iw.pageQueryDate);
2820
          };
2821
          iw.showOutOfSequenceDetails = function (authId, rbmName) {
2822
            openCallTargetDrawer("oos", authId, rbmName, iw.pageQueryDate);
2823
          };
2824
        } catch (e) {
2825
          // If cross-origin ever kicks in (shouldn't with srcdoc same-origin),
2826
          // fall back to the iframe's native Bootstrap modal β€” no crash.
2827
        }
2828
      }, 50);
2829
    }
2830
 
2831
    function openCallTargetDrawer(kind, authId, rbmName, dateStr) {
2832
      var titleWho = rbmName + (dateStr ? " (" + dateStr + ")" : "");
2833
      var title = (kind === "oos" ? "Out of Sequence Calls β€” " : "Called Partners β€” ") + titleWho;
2834
      $("#rdrrCallDrawerTitle").text(title);
2835
      $("#rdrrCallDrawerDesc").text(kind === "oos"
2836
              ? "Calls placed outside the recommended sequence."
2837
              : "All calls made by this RBM today, with recordings.");
2838
      $("#rdrrCallDrawerBody").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
2839
      $("#rdrrCallDrawerBack").addClass("show");
2840
 
2841
      var url;
2842
      if (kind === "oos") {
2843
        url = "/indent/rbm_call_target/oos_details?authId=" + encodeURIComponent(authId);
2844
      } else {
2845
        var dp = dateStr ? "&date=" + encodeURIComponent(dateStr) : "";
2846
        url = "/indent/rbm_call_target/called_details?authId=" + encodeURIComponent(authId)
2847
                + "&agentName=" + encodeURIComponent(rbmName) + dp;
2848
      }
2849
      $.ajax({
2850
        url: url, type: "GET", dataType: "json",
2851
        success: function (data) {
2852
          if (!data || data.length === 0) {
2853
            $("#rdrrCallDrawerBody").html('<div class="empty"><div class="ei">πŸ“­</div>No entries.</div>');
2854
            return;
2855
          }
2856
          $("#rdrrCallDrawerBody").html(kind === "oos" ? renderOosTable(data) : renderCalledTable(data));
2857
        },
2858
        error: function () {
2859
          $("#rdrrCallDrawerBody").html('<div class="empty">Failed to load details.</div>');
2860
        }
2861
      });
2862
    }
2863
 
2864
    function renderOosTable(data) {
2865
      var html = '<table><thead><tr><th>S.No</th><th>Party Name</th><th>Code</th><th>Time</th></tr></thead><tbody>';
2866
      data.forEach(function (r, i) {
2867
        html += '<tr><td>' + (i + 1) + '</td><td>' + escapeHtml(r.partyName || "-") +
2868
                '</td><td>' + escapeHtml(r.code || "-") + '</td><td>' + escapeHtml(r.time || "-") + '</td></tr>';
2869
      });
2870
      return html + '</tbody></table>';
2871
    }
2872
 
2873
    function renderCalledTable(data) {
2874
      var html = '<table><thead><tr>' +
2875
              '<th>S.No</th><th>Party Name</th><th>Code</th><th>Remark</th>' +
2876
              '<th>Call Status</th><th>Duration</th><th>Date/Time</th><th>Recording</th>' +
2877
              '</tr></thead><tbody>';
2878
      data.forEach(function (r, i) {
2879
        var rowStyle = "";
2880
        var recording = "-";
2881
        if (r.breakLog) {
2882
          var status = (r.breakStatus || "").toLowerCase();
2883
          if (status.indexOf("available") >= 0) rowStyle = 'style="background:#fdecec;color:#721c24"';
2884
          else if (status.indexOf("trying") >= 0) rowStyle = 'style="background:#fff5d6;color:#856404"';
2885
          else if (status.indexOf("logged out") >= 0 || status.indexOf("logout") >= 0) rowStyle = 'style="background:#eef0f4;color:#383d41"';
2886
          else if (status.indexOf("break") >= 0) rowStyle = 'style="background:#ffe5cc;color:#c45200"';
2887
        }
2888
        if (r.recordingUrl) {
2889
          recording = '<audio controls preload="none" src="' + escapeHtml(r.recordingUrl) + '"></audio>';
2890
        }
2891
        html += '<tr ' + rowStyle + '>' +
2892
                '<td>' + (i + 1) + '</td>' +
2893
                '<td>' + escapeHtml(r.partyName || (r.breakLog ? (r.breakStatus || "-") : "-")) + '</td>' +
2894
                '<td>' + escapeHtml(r.code || "-") + '</td>' +
2895
                '<td>' + escapeHtml(r.remark || "-") + '</td>' +
2896
                '<td>' + escapeHtml(r.callStatus || "-") + '</td>' +
2897
                '<td>' + escapeHtml(r.callDuration || "-") + '</td>' +
2898
                '<td>' + escapeHtml(r.callDateTime || "-") + '</td>' +
2899
                '<td>' + recording + '</td>' +
2900
                '</tr>';
2901
      });
2902
      return html + '</tbody></table>';
2903
    }
2904
 
2905
    $("#rdrrCallDrawerClose").on("click", function () {
2906
      $("#rdrrCallDrawerBack").removeClass("show");
2907
    });
2908
    $("#rdrrCallDrawerBack").on("click", function (e) {
2909
      if (e.target === this) $(this).removeClass("show");
2910
    });
2911
 
37444 ranu 2912
    // initial load
2913
    load();
37468 ranu 2914
    loadPurchaseMilestones();
2915
    loadPerformanceDashboard();
37469 ranu 2916
    loadCallTargetIframe();
37444 ranu 2917
  })();
2918
</script>
2919
</body>
2920
</html>