Subversion Repositories SmartDukaan

Rev

Rev 37469 | Rev 37497 | 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
 
37487 ranu 962
    /* warehouse flow (buying vs selling) in drill-down */
963
    .flow-tbl {
964
      width: 100%;
965
      border-collapse: separate;
966
      border-spacing: 0;
967
      font-size: 12.5px;
968
      margin-bottom: 20px;
969
      background: #fff;
970
      border: 1px solid var(--line);
971
      border-radius: 11px;
972
      overflow: hidden
973
    }
974
 
975
    .flow-tbl th, .flow-tbl td {
976
      padding: 10px 12px;
977
      border-bottom: 1px solid var(--line2);
978
      text-align: right;
979
      font-variant-numeric: tabular-nums
980
    }
981
 
982
    .flow-tbl th {
983
      font-size: 10.5px;
984
      text-transform: uppercase;
985
      letter-spacing: .05em;
986
      color: var(--soft);
987
      font-weight: 700;
988
      background: #fafbfe;
989
      text-align: left;
990
      padding-left: 14px
991
    }
992
 
993
    .flow-tbl th.num, .flow-tbl td.num {
994
      text-align: right
995
    }
996
 
997
    .flow-tbl thead th:first-child {
998
      text-align: left
999
    }
1000
 
1001
    .flow-tbl tbody tr td:first-child {
1002
      text-align: left;
1003
      padding-left: 14px;
1004
      font-weight: 700;
1005
      letter-spacing: .03em;
1006
      text-transform: uppercase;
1007
      font-size: 11px
1008
    }
1009
 
1010
    .flow-tbl tbody tr td:first-child i {
1011
      display: inline-block;
1012
      width: 7px;
1013
      height: 7px;
1014
      border-radius: 50%;
1015
      margin-right: 6px;
1016
      vertical-align: middle
1017
    }
1018
 
1019
    .flow-tbl tbody tr:last-child td {
1020
      border-bottom: 0
1021
    }
1022
 
1023
    .flow-tbl tbody tr.hid td:first-child {
1024
      color: var(--hid)
1025
    }
1026
 
1027
    .flow-tbl tbody tr.hid td:first-child i {
1028
      background: var(--hid)
1029
    }
1030
 
1031
    .flow-tbl tbody tr.fastmoving td:first-child {
1032
      color: var(--fast)
1033
    }
1034
 
1035
    .flow-tbl tbody tr.fastmoving td:first-child i {
1036
      background: var(--fast)
1037
    }
1038
 
1039
    .flow-tbl tbody tr.running td:first-child {
1040
      color: var(--run)
1041
    }
1042
 
1043
    .flow-tbl tbody tr.running td:first-child i {
1044
      background: var(--run)
1045
    }
1046
 
1047
    .flow-tbl tbody tr.slowmoving td:first-child {
1048
      color: var(--slow)
1049
    }
1050
 
1051
    .flow-tbl tbody tr.slowmoving td:first-child i {
1052
      background: var(--slow)
1053
    }
1054
 
1055
    .flow-tbl tbody tr.other td:first-child {
1056
      color: var(--other)
1057
    }
1058
 
1059
    .flow-tbl tbody tr.other td:first-child i {
1060
      background: var(--other)
1061
    }
1062
 
1063
    .flow-tbl .cov-cell {
1064
      display: inline-flex;
1065
      align-items: center;
1066
      gap: 6px;
1067
      justify-content: flex-end
1068
    }
1069
 
1070
    .flow-tbl .cov-cell .cov-bar {
1071
      width: 60px;
1072
      height: 6px;
1073
      border-radius: 3px;
1074
      background: #eef1f6;
1075
      overflow: hidden;
1076
      flex: none
1077
    }
1078
 
1079
    .flow-tbl .cov-cell .cov-bar > i {
1080
      display: block;
1081
      height: 100%;
1082
      border-radius: 3px
1083
    }
1084
 
1085
    .flow-tbl .cov-cell.good .cov-bar > i {
1086
      background: var(--good)
1087
    }
1088
 
1089
    .flow-tbl .cov-cell.warn .cov-bar > i {
1090
      background: var(--warn)
1091
    }
1092
 
1093
    .flow-tbl .cov-cell.bad .cov-bar > i {
1094
      background: var(--bad)
1095
    }
1096
 
1097
    .flow-tbl .cov-cell.good .cov-pct {
1098
      color: var(--good);
1099
      font-weight: 700
1100
    }
1101
 
1102
    .flow-tbl .cov-cell.warn .cov-pct {
1103
      color: var(--warn);
1104
      font-weight: 700
1105
    }
1106
 
1107
    .flow-tbl .cov-cell.bad .cov-pct {
1108
      color: var(--bad);
1109
      font-weight: 700
1110
    }
1111
 
1112
    .flow-tbl .cov-cell.na {
1113
      color: var(--soft);
1114
      font-weight: 500
1115
    }
1116
 
1117
    .flow-tbl tr.tot td {
1118
      font-weight: 770;
1119
      background: #fafbfe;
1120
      color: var(--ink);
1121
      border-top: 2px solid var(--line)
1122
    }
1123
 
37444 ranu 1124
    /* brand mix bars in drill-down */
1125
    .brands {
1126
      display: flex;
1127
      flex-direction: column;
1128
      gap: 8px;
1129
      margin-bottom: 20px
1130
    }
1131
 
1132
    .brand-card {
1133
      background: #fff;
1134
      border: 1px solid var(--line);
1135
      border-radius: 11px;
1136
      overflow: hidden;
1137
      transition: box-shadow .12s
1138
    }
1139
 
1140
    .brand-card:hover {
1141
      box-shadow: 0 3px 10px rgba(20, 30, 60, .06)
1142
    }
1143
 
1144
    .brand-card.open {
1145
      box-shadow: 0 4px 14px rgba(59, 91, 219, .14);
1146
      border-color: #c8d2f4
1147
    }
1148
 
1149
    .brand-head {
1150
      display: grid;
37460 ranu 1151
      grid-template-columns:24px 130px 1fr 96px 100px 60px;
37444 ranu 1152
      gap: 12px;
1153
      align-items: center;
1154
      padding: 10px 14px;
1155
      cursor: pointer;
1156
      user-select: none
1157
    }
1158
 
37460 ranu 1159
    .brand-head .bpc {
1160
      display: inline-flex;
1161
      align-items: center;
1162
      justify-content: center;
1163
      gap: 4px;
1164
      font-size: 11.5px;
1165
      font-weight: 700;
1166
      color: var(--brand);
1167
      background: #eef2ff;
1168
      border: 1px solid #d7defb;
1169
      border-radius: 999px;
1170
      padding: 3px 9px;
1171
      font-variant-numeric: tabular-nums;
1172
      white-space: nowrap;
1173
      justify-self: center
1174
    }
1175
 
1176
    .brand-head .bpc.zero {
1177
      color: var(--soft);
1178
      background: #f1f3f9;
1179
      border-color: var(--line)
1180
    }
1181
 
1182
    .brand-head .bpc svg {
1183
      width: 11px;
1184
      height: 11px
1185
    }
1186
 
37444 ranu 1187
    .brand-head .cx {
1188
      color: #c5cce0;
1189
      font-size: 14px;
1190
      transition: transform .18s ease, color .12s
1191
    }
1192
 
1193
    .brand-card.open .brand-head .cx {
1194
      transform: rotate(90deg);
1195
      color: var(--brand)
1196
    }
1197
 
1198
    .brand-head .bn {
1199
      font-size: 13px;
1200
      font-weight: 700;
1201
      color: var(--ink);
1202
      white-space: nowrap;
1203
      overflow: hidden;
1204
      text-overflow: ellipsis
1205
    }
1206
 
1207
    .brand-head .btrack {
1208
      height: 10px;
1209
      background: #eef1f6;
1210
      border-radius: 6px;
1211
      overflow: hidden
1212
    }
1213
 
1214
    .brand-head .btrack > i {
1215
      display: block;
1216
      height: 100%;
1217
      border-radius: 6px;
1218
      background: linear-gradient(90deg, var(--brand2), var(--brand));
1219
      transition: width .3s ease
1220
    }
1221
 
1222
    .brand-head .bval {
1223
      font-size: 13px;
1224
      font-weight: 700;
1225
      color: var(--ink);
1226
      font-variant-numeric: tabular-nums;
1227
      text-align: right
1228
    }
1229
 
1230
    .brand-head .bshare {
1231
      font-size: 12px;
1232
      font-weight: 700;
1233
      color: var(--muted);
1234
      font-variant-numeric: tabular-nums;
1235
      text-align: right
1236
    }
1237
 
1238
    .brand-card.top .brand-head .btrack > i {
1239
      background: linear-gradient(90deg, #38b2ac, var(--teal))
1240
    }
1241
 
1242
    .brand-card.top .brand-head .bshare {
1243
      color: var(--teal)
1244
    }
1245
 
1246
    .brand-body {
1247
      display: none;
1248
      padding: 6px 14px 14px;
1249
      border-top: 1px dashed var(--line);
1250
      background: #fafbfe
1251
    }
1252
 
1253
    .brand-card.open .brand-body {
1254
      display: block
1255
    }
1256
 
1257
    .brand-body .bhdr {
1258
      font-size: 10.5px;
1259
      letter-spacing: .06em;
1260
      text-transform: uppercase;
1261
      color: var(--soft);
1262
      font-weight: 700;
1263
      margin: 8px 0 8px
1264
    }
1265
 
1266
    .mbars {
1267
      display: flex;
1268
      flex-direction: column;
1269
      gap: 6px
1270
    }
1271
 
1272
    .mbar {
1273
      display: grid;
1274
      grid-template-columns:90px 1fr 100px 60px;
1275
      gap: 10px;
1276
      align-items: center;
1277
      padding: 6px 10px;
1278
      background: #fff;
1279
      border: 1px solid var(--line2);
1280
      border-radius: 8px
1281
    }
1282
 
1283
    .mbar .mname {
1284
      font-size: 11px;
1285
      font-weight: 700;
1286
      letter-spacing: .04em;
1287
      text-transform: uppercase;
1288
      display: flex;
1289
      align-items: center;
1290
      gap: 5px
1291
    }
1292
 
1293
    .mbar .mname i {
1294
      display: inline-block;
1295
      width: 7px;
1296
      height: 7px;
1297
      border-radius: 50%
1298
    }
1299
 
1300
    .mbar.hid .mname {
1301
      color: var(--hid)
1302
    }
1303
 
1304
    .mbar.hid .mname i {
1305
      background: var(--hid)
1306
    }
1307
 
1308
    .mbar.fastmoving .mname {
1309
      color: var(--fast)
1310
    }
1311
 
1312
    .mbar.fastmoving .mname i {
1313
      background: var(--fast)
1314
    }
1315
 
1316
    .mbar.running .mname {
1317
      color: var(--run)
1318
    }
1319
 
1320
    .mbar.running .mname i {
1321
      background: var(--run)
1322
    }
1323
 
1324
    .mbar.slowmoving .mname {
1325
      color: var(--slow)
1326
    }
1327
 
1328
    .mbar.slowmoving .mname i {
1329
      background: var(--slow)
1330
    }
1331
 
1332
    .mbar.other .mname {
1333
      color: var(--other)
1334
    }
1335
 
1336
    .mbar.other .mname i {
1337
      background: var(--other)
1338
    }
1339
 
1340
    .mbar .mtrack {
1341
      height: 10px;
1342
      border-radius: 5px;
1343
      overflow: hidden
1344
    }
1345
 
1346
    .mbar.hid .mtrack {
1347
      background: var(--hid-bg)
1348
    }
1349
 
1350
    .mbar.fastmoving .mtrack {
1351
      background: var(--fast-bg)
1352
    }
1353
 
1354
    .mbar.running .mtrack {
1355
      background: var(--run-bg)
1356
    }
1357
 
1358
    .mbar.slowmoving .mtrack {
1359
      background: var(--slow-bg)
1360
    }
1361
 
1362
    .mbar.other .mtrack {
1363
      background: var(--other-bg)
1364
    }
1365
 
1366
    .mbar .mtrack > i {
1367
      display: block;
1368
      height: 100%;
1369
      border-radius: 5px;
1370
      transition: width .3s ease
1371
    }
1372
 
1373
    .mbar.hid .mtrack > i {
1374
      background: linear-gradient(90deg, #9775fa, var(--hid))
1375
    }
1376
 
1377
    .mbar.fastmoving .mtrack > i {
1378
      background: linear-gradient(90deg, var(--brand2), var(--fast))
1379
    }
1380
 
1381
    .mbar.running .mtrack > i {
1382
      background: linear-gradient(90deg, #20c997, var(--run))
1383
    }
1384
 
1385
    .mbar.slowmoving .mtrack > i {
1386
      background: linear-gradient(90deg, #ffa94d, var(--slow))
1387
    }
1388
 
1389
    .mbar.other .mtrack > i {
1390
      background: linear-gradient(90deg, #adb5bd, var(--other))
1391
    }
1392
 
1393
    .mbar .mval {
1394
      font-size: 12px;
1395
      font-weight: 650;
1396
      color: var(--ink);
1397
      font-variant-numeric: tabular-nums;
1398
      text-align: right
1399
    }
1400
 
1401
    .mbar .mshare {
1402
      font-size: 12px;
1403
      font-weight: 700;
1404
      font-variant-numeric: tabular-nums;
1405
      text-align: right;
1406
      color: var(--muted)
1407
    }
1408
 
1409
    /* status list modal (achieved vs pending) */
1410
    .status-back {
1411
      position: fixed;
1412
      inset: 0;
1413
      background: rgba(15, 22, 40, .5);
1414
      backdrop-filter: blur(2px);
1415
      z-index: 1300;
1416
      display: none;
1417
      align-items: flex-start;
1418
      justify-content: center;
1419
      padding: 60px 20px;
1420
      overflow-y: auto
1421
    }
1422
 
1423
    .status-back.show {
1424
      display: flex
1425
    }
1426
 
1427
    .status-modal {
1428
      background: #fff;
1429
      border-radius: 16px;
1430
      max-width: 1000px;
1431
      width: 100%;
1432
      box-shadow: 0 20px 60px rgba(20, 30, 60, .28);
1433
      padding: 22px 24px 20px;
1434
      position: relative
1435
    }
1436
 
1437
    .status-modal .x {
1438
      position: absolute;
1439
      top: 14px;
1440
      right: 16px;
1441
      cursor: pointer;
1442
      color: var(--soft);
1443
      font-size: 24px;
1444
      line-height: 1;
1445
      border: 0;
1446
      background: none;
1447
      width: 32px;
1448
      height: 32px;
1449
      border-radius: 8px;
1450
      transition: background .1s
1451
    }
1452
 
1453
    .status-modal .x:hover {
1454
      background: #f1f3f9;
1455
      color: var(--ink)
1456
    }
1457
 
1458
    .status-modal h3 {
1459
      margin: 0 0 3px;
1460
      font-size: 19px;
1461
      font-weight: 760;
1462
      letter-spacing: -.01em;
1463
      padding-right: 40px
1464
    }
1465
 
1466
    .status-modal > .desc {
1467
      margin: 0 0 18px;
1468
      font-size: 12.5px;
1469
      color: var(--muted);
1470
      font-weight: 600
1471
    }
1472
 
1473
    .status-grid {
1474
      display: grid;
1475
      grid-template-columns:1fr 1fr;
1476
      gap: 18px
1477
    }
1478
 
1479
    .status-col {
1480
      border: 1px solid var(--line);
1481
      border-radius: 12px;
1482
      padding: 14px 16px;
1483
      background: #fbfcfe
1484
    }
1485
 
1486
    .status-col.good {
1487
      border-color: #c3e8d0;
1488
      background: #f4fbf6
1489
    }
1490
 
1491
    .status-col.bad {
1492
      border-color: #f2c4c4;
1493
      background: #fdf5f5
1494
    }
1495
 
1496
    .status-col h4 {
1497
      margin: 0 0 10px;
1498
      font-size: 13px;
1499
      font-weight: 730;
1500
      display: flex;
1501
      align-items: center;
1502
      gap: 8px;
1503
      letter-spacing: -.005em
1504
    }
1505
 
1506
    .status-col h4 .cnt {
1507
      background: #fff;
1508
      border: 1px solid var(--line);
1509
      color: var(--ink);
1510
      font-size: 11px;
1511
      font-weight: 700;
1512
      padding: 2px 9px;
1513
      border-radius: 999px
1514
    }
1515
 
1516
    .status-col.good h4 {
1517
      color: #177a3a
1518
    }
1519
 
1520
    .status-col.good h4 .cnt {
1521
      background: #e5f7ee;
1522
      border-color: #c3e8d0;
1523
      color: #177a3a
1524
    }
1525
 
1526
    .status-col.bad h4 {
1527
      color: #b8272b
1528
    }
1529
 
1530
    .status-col.bad h4 .cnt {
1531
      background: #ffeaea;
1532
      border-color: #f2c4c4;
1533
      color: #b8272b
1534
    }
1535
 
1536
    .status-list {
1537
      display: flex;
1538
      flex-direction: column;
1539
      gap: 6px;
1540
      max-height: 60vh;
1541
      overflow-y: auto;
1542
      padding-right: 4px
1543
    }
1544
 
1545
    .status-item {
1546
      display: grid;
1547
      grid-template-columns:1fr 100px 68px;
1548
      gap: 10px;
1549
      align-items: center;
1550
      padding: 9px 12px;
1551
      background: #fff;
1552
      border: 1px solid var(--line2);
1553
      border-radius: 9px;
1554
      transition: box-shadow .12s
1555
    }
1556
 
1557
    .status-item:hover {
1558
      box-shadow: 0 2px 8px rgba(20, 30, 60, .06)
1559
    }
1560
 
1561
    .status-item .rn {
1562
      font-weight: 700;
1563
      color: var(--ink);
1564
      font-size: 12.5px;
1565
      line-height: 1.3
1566
    }
1567
 
1568
    .status-item .wh {
1569
      font-size: 11px;
1570
      color: var(--muted);
1571
      font-weight: 600;
1572
      display: block;
1573
      margin-top: 2px
1574
    }
1575
 
1576
    .status-item .vv {
1577
      font-size: 12px;
1578
      color: var(--muted);
1579
      font-variant-numeric: tabular-nums;
1580
      font-weight: 600;
1581
      text-align: right;
1582
      white-space: nowrap
1583
    }
1584
 
1585
    .status-item .vv b {
1586
      color: var(--ink);
1587
      font-weight: 700
1588
    }
1589
 
1590
    .status-item .pp {
1591
      font-size: 12px;
1592
      font-weight: 700;
1593
      font-variant-numeric: tabular-nums;
1594
      text-align: right
1595
    }
1596
 
1597
    .status-item .pp.good {
1598
      color: var(--good)
1599
    }
1600
 
1601
    .status-item .pp.warn {
1602
      color: var(--warn)
1603
    }
1604
 
1605
    .status-item .pp.bad {
1606
      color: var(--bad)
1607
    }
1608
 
1609
    .status-empty {
1610
      padding: 24px;
1611
      text-align: center;
1612
      color: var(--soft);
1613
      font-size: 12.5px
1614
    }
1615
 
37460 ranu 1616
    /* extras: aging + partner-billing tables */
1617
    .xtable {
1618
      width: 100%;
1619
      border-collapse: separate;
1620
      border-spacing: 0;
1621
      font-size: 13px
1622
    }
1623
 
1624
    .xtable th {
1625
      font-size: 10.5px;
1626
      text-transform: uppercase;
1627
      letter-spacing: .06em;
1628
      color: var(--soft);
1629
      font-weight: 700;
1630
      white-space: nowrap;
1631
      padding: 10px 10px;
1632
      border-bottom: 1px solid var(--line);
1633
      text-align: left;
1634
      background: #fff
1635
    }
1636
 
1637
    .xtable th.num {
1638
      text-align: right
1639
    }
1640
 
1641
    .xtable td {
1642
      padding: 10px;
1643
      border-bottom: 1px solid var(--line2);
1644
      color: var(--ink);
1645
      font-weight: 500
1646
    }
1647
 
1648
    .xtable td.num {
1649
      text-align: right;
1650
      font-variant-numeric: tabular-nums;
1651
      font-weight: 650
1652
    }
1653
 
1654
    .xtable tbody tr:hover {
1655
      background: #f6f8fd
1656
    }
1657
 
1658
    .xtable .rbm-nm {
1659
      font-weight: 700;
1660
      color: var(--ink)
1661
    }
1662
 
1663
    .xtable tr.tot td {
1664
      font-weight: 770;
1665
      background: #fafbfe;
1666
      border-top: 2px solid var(--line);
1667
      color: var(--ink)
1668
    }
1669
 
1670
    .xtable tr.bal td {
1671
      font-weight: 700;
1672
      background: #fffbf2;
1673
      border-top: 1px dashed #f0d68a;
1674
      color: #7a5a00
1675
    }
1676
 
1677
    .xtable tr.bal td.hdr {
1678
      font-weight: 770
1679
    }
1680
 
1681
    .xtable td.g-hid {
1682
      border-left: 2px solid transparent
1683
    }
1684
 
1685
    /* placeholder for future column tint */
1686
    .xtable th.g-hid, .xtable td.g-hid {
1687
      color: var(--hid)
1688
    }
1689
 
1690
    .xtable th.g-fast, .xtable td.g-fast {
1691
      color: var(--fast)
1692
    }
1693
 
1694
    .xtable th.g-run, .xtable td.g-run {
1695
      color: var(--run)
1696
    }
1697
 
1698
    .xtable th.g-slow, .xtable td.g-slow {
1699
      color: var(--slow)
1700
    }
1701
 
1702
    .xtable th.g-other, .xtable td.g-other {
1703
      color: var(--other)
1704
    }
1705
 
1706
    .xtable th.g-total, .xtable td.g-total {
1707
      color: var(--brand);
1708
      font-weight: 700
1709
    }
1710
 
1711
    .xtable td.g-hid, .xtable td.g-fast, .xtable td.g-run, .xtable td.g-slow, .xtable td.g-other {
1712
      opacity: .95
1713
    }
1714
 
1715
    .xtable td.zero {
1716
      color: var(--soft);
1717
      font-weight: 500
1718
    }
1719
 
1720
    .xtable .cnt-pill {
1721
      display: inline-block;
1722
      min-width: 32px;
1723
      padding: 2px 8px;
1724
      border-radius: 6px;
1725
      font-size: 11.5px;
1726
      font-weight: 700;
1727
      font-variant-numeric: tabular-nums;
1728
      background: #eef2ff;
1729
      color: var(--brand)
1730
    }
1731
 
1732
    .xtable .cnt-pill.zero {
1733
      background: #f1f3f9;
1734
      color: var(--soft)
1735
    }
1736
 
1737
    .xtable .cnt-pill.warn {
1738
      background: #fff0e0;
1739
      color: #a04600
1740
    }
1741
 
1742
    .xtable .cnt-pill.good {
1743
      background: #e5f7ee;
1744
      color: #177a3a
1745
    }
1746
 
37469 ranu 1747
    /* call-target drawer content (Called Partners / OOS Calls) */
1748
    #rdrrCallDrawerBody {
1749
      overflow-x: auto
1750
    }
1751
 
1752
    #rdrrCallDrawerBody table {
1753
      width: 100%;
1754
      border-collapse: separate;
1755
      border-spacing: 0;
1756
      font-size: 12.5px;
1757
      background: #fff;
1758
      margin: 0
1759
    }
1760
 
1761
    #rdrrCallDrawerBody table th {
1762
      font-size: 10.5px;
1763
      text-transform: uppercase;
1764
      letter-spacing: .04em;
1765
      color: var(--soft);
1766
      font-weight: 700;
1767
      padding: 9px 10px;
1768
      background: #fafbfe;
1769
      border-bottom: 1px solid var(--line);
1770
      text-align: left;
1771
      white-space: nowrap
1772
    }
1773
 
1774
    #rdrrCallDrawerBody table td {
1775
      padding: 9px 10px;
1776
      border-bottom: 1px solid var(--line2);
1777
      color: var(--ink);
1778
      font-weight: 500;
1779
      vertical-align: middle
1780
    }
1781
 
1782
    #rdrrCallDrawerBody table tr:hover {
1783
      background: #f6f8fd
1784
    }
1785
 
1786
    #rdrrCallDrawerBody audio {
1787
      max-width: 170px;
1788
      height: 26px
1789
    }
1790
 
37468 ranu 1791
    /* rbm performance dashboard (extracted from today_po_rbm) */
1792
    #rdrrPerfWrap {
1793
      overflow-x: auto
1794
    }
1795
 
1796
    #rdrrPerfWrap table {
1797
      width: 100%;
1798
      border-collapse: separate;
1799
      border-spacing: 0;
1800
      font-size: 12.5px;
1801
      background: #fff
1802
    }
1803
 
1804
    #rdrrPerfWrap table th, #rdrrPerfWrap table td {
1805
      padding: 9px 10px;
1806
      text-align: center;
1807
      vertical-align: middle;
1808
      border-bottom: 1px solid var(--line2);
1809
      color: var(--ink);
1810
      font-weight: 500
1811
    }
1812
 
1813
    #rdrrPerfWrap table thead th {
1814
      font-size: 10.5px;
1815
      text-transform: uppercase;
1816
      letter-spacing: .05em;
1817
      font-weight: 700;
1818
      background: #1d2433;
1819
      color: #fff;
1820
      border-bottom: 0;
1821
      padding: 10px 8px;
1822
      line-height: 1.2
1823
    }
1824
 
1825
    #rdrrPerfWrap table thead th small {
1826
      font-size: 9.5px;
1827
      color: rgba(255, 255, 255, .7);
1828
      font-weight: 600;
1829
      display: block;
1830
      margin-top: 2px
1831
    }
1832
 
1833
    /* per-column accent badges (keep original palette from today_po_rbm) */
1834
    #rdrrPerfWrap table thead th:nth-child(4) {
1835
      background: linear-gradient(180deg, #40c057, #2f9e44)
1836
    }
1837
 
1838
    #rdrrPerfWrap table thead th:nth-child(5) {
1839
      background: linear-gradient(180deg, #22b8cf, #0e959f)
1840
    }
1841
 
1842
    #rdrrPerfWrap table thead th:nth-child(6) {
1843
      background: linear-gradient(180deg, #ffa94d, #e8590c)
1844
    }
1845
 
1846
    #rdrrPerfWrap table thead th:nth-child(7) {
1847
      background: linear-gradient(180deg, #9775fa, #7048e8)
1848
    }
1849
 
1850
    #rdrrPerfWrap table thead th:nth-child(8) {
1851
      background: linear-gradient(180deg, #ffd43b, #e8ac00);
1852
      color: #3a2500
1853
    }
1854
 
1855
    #rdrrPerfWrap table thead th:nth-child(8) small {
1856
      color: rgba(58, 37, 0, .75)
1857
    }
1858
 
1859
    #rdrrPerfWrap table thead th:nth-child(9) {
1860
      background: linear-gradient(180deg, #ff922b, #e8590c)
1861
    }
1862
 
1863
    #rdrrPerfWrap table thead th:last-child {
1864
      background: linear-gradient(180deg, #ff6b6b, #e03131)
1865
    }
1866
 
1867
    #rdrrPerfWrap table tbody tr:hover {
1868
      background: #f6f8fd
1869
    }
1870
 
1871
    /* rank rows keep their original background tint from today_po_rbm inline style */
1872
    #rdrrPerfWrap table tbody tr td:nth-child(2) {
1873
      text-align: left;
1874
      font-weight: 700;
1875
      color: var(--ink)
1876
    }
1877
 
1878
    #rdrrPerfWrap table tbody tr td:first-child img {
1879
      width: 24px;
1880
      height: 24px
1881
    }
1882
 
1883
    #rdrrPerfWrap table tbody tr:first-child td {
1884
      font-weight: 700
1885
    }
1886
 
1887
    #rdrrPerfWrap table tbody tr td:last-child {
1888
      font-weight: 770;
1889
      font-size: 13.5px;
1890
      font-variant-numeric: tabular-nums
1891
    }
1892
 
1893
    /* purchase-milestones (brand Γ— RBM) container β€” restyles the injected Bootstrap fragment */
1894
    #rdrrPmWrap {
1895
      overflow-x: auto
1896
    }
1897
 
1898
    #rdrrPmWrap table {
1899
      width: 100%;
1900
      border-collapse: separate;
1901
      border-spacing: 0;
1902
      font-size: 12.5px;
1903
      margin-bottom: 12px;
1904
      background: #fff
1905
    }
1906
 
1907
    #rdrrPmWrap table th, #rdrrPmWrap table td {
1908
      padding: 8px 8px;
1909
      border-bottom: 1px solid var(--line2);
1910
      border-right: 1px solid var(--line2);
1911
      text-align: right;
1912
      font-variant-numeric: tabular-nums;
1913
      color: var(--ink);
1914
      vertical-align: middle
1915
    }
1916
 
1917
    #rdrrPmWrap table th:first-child, #rdrrPmWrap table td:first-child {
1918
      text-align: left;
1919
      border-left: 1px solid var(--line2);
1920
      font-weight: 650;
1921
      position: sticky;
1922
      left: 0;
1923
      background: #fff;
1924
      z-index: 1;
1925
      min-width: 130px
1926
    }
1927
 
1928
    #rdrrPmWrap table thead th {
1929
      text-transform: uppercase;
1930
      letter-spacing: .04em;
1931
      font-size: 10.5px;
1932
      color: var(--soft);
1933
      font-weight: 700;
1934
      background: #fafbfe;
1935
      border-top: 1px solid var(--line);
1936
      border-bottom: 1px solid var(--line);
1937
      text-align: center
1938
    }
1939
 
1940
    #rdrrPmWrap table thead th[colspan] {
1941
      font-size: 12px;
1942
      padding: 8px 6px;
1943
      color: #fff
1944
    }
1945
 
1946
    #rdrrPmWrap table thead th p {
1947
      margin: 0;
1948
      font-size: 13px;
1949
      font-weight: 770;
1950
      letter-spacing: .01em;
1951
      line-height: 1.1
1952
    }
1953
 
1954
    #rdrrPmWrap table thead tr:first-child th:first-child {
1955
      background: #fafbfe;
1956
      color: var(--soft)
1957
    }
1958
 
1959
    #rdrrPmWrap table tbody tr:hover {
1960
      background: #f6f8fd
1961
    }
1962
 
1963
    #rdrrPmWrap table tbody tr:hover td:first-child {
1964
      background: #f6f8fd
1965
    }
1966
 
1967
    #rdrrPmWrap table tr.green td {
1968
      background: #eaf7ef !important;
1969
      font-weight: 770;
1970
      color: #177a3a
1971
    }
1972
 
1973
    #rdrrPmWrap table tr.green td:first-child {
1974
      background: #eaf7ef !important;
1975
      color: #177a3a
1976
    }
1977
 
1978
    /* known brand accents (extend as more brands appear) */
1979
    #rdrrPmWrap table thead th.vivo {
1980
      background: linear-gradient(180deg, #00baf2, #0a8fb5)
1981
    }
1982
 
1983
    #rdrrPmWrap table thead th.oppo {
1984
      background: linear-gradient(180deg, #20a558, #177a3a)
1985
    }
1986
 
1987
    #rdrrPmWrap table thead th.samsung {
1988
      background: linear-gradient(180deg, #0b3d91, #071e51)
1989
    }
1990
 
1991
    #rdrrPmWrap table thead th.alcatel {
1992
      background: linear-gradient(180deg, #5c7cfa, #3b5bdb)
1993
    }
1994
 
1995
    #rdrrPmWrap table thead th.motorola {
1996
      background: linear-gradient(180deg, #495057, #212529)
1997
    }
1998
 
1999
    #rdrrPmWrap table thead th.hmd {
2000
      background: linear-gradient(180deg, #7048e8, #5b34c9)
2001
    }
2002
 
2003
    #rdrrPmWrap table thead th.xiaomi {
2004
      background: linear-gradient(180deg, #ffa726, #e8590c)
2005
    }
2006
 
2007
    #rdrrPmWrap table thead th.lava {
2008
      background: linear-gradient(180deg, #e03131, #a11515)
2009
    }
2010
 
2011
    #rdrrPmWrap table thead th.poco {
2012
      background: linear-gradient(180deg, #ffd43b, #e8ac00);
2013
      color: #3a2500
2014
    }
2015
 
2016
    #rdrrPmWrap table thead th.realme {
2017
      background: linear-gradient(180deg, #f59f00, #e8590c)
2018
    }
2019
 
2020
    #rdrrPmWrap table thead th.apple {
2021
      background: linear-gradient(180deg, #495057, #141a2b)
2022
    }
2023
 
2024
    #rdrrPmWrap table thead th.oneplus {
2025
      background: linear-gradient(180deg, #e03131, #a11515)
2026
    }
2027
 
2028
    #rdrrPmWrap table thead th.tecno {
2029
      background: linear-gradient(180deg, #0ca678, #087a56)
2030
    }
2031
 
2032
    #rdrrPmWrap table thead th.ai + {
2033
      background: linear-gradient(180deg, #7048e8, #5b34c9)
2034
    }
2035
 
2036
    #rdrrPmWrap table thead th.total {
2037
      background: linear-gradient(180deg, #3b5bdb, #28449e)
2038
    }
2039
 
2040
    /* default gradient for any unmapped brand */
2041
    #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) {
2042
      background: linear-gradient(180deg, var(--brand2), var(--brand))
2043
    }
2044
 
2045
    #rdrrPmWrap table td.currency {
2046
      font-weight: 600
2047
    }
2048
 
37444 ranu 2049
    @media (max-width: 960px) {
2050
      .kpis {
2051
        grid-template-columns:repeat(2, 1fr)
2052
      }
2053
 
2054
      .brand h1 {
2055
        font-size: 22px
2056
      }
2057
 
2058
      .status-grid {
2059
        grid-template-columns:1fr
2060
      }
2061
    }
2062
  </style>
2063
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css"/>
2064
</head>
2065
<body>
2066
<div class="wrap">
2067
  <header class="top">
2068
    <div class="brand">
2069
      <div class="crumb"><a href="/indent/today_po_rbm">&larr; Today PO / RBM</a> &middot; Sales &middot; Indent</div>
2070
      <h1>RBM DRR Dashboard <span class="live"><i></i>Live</span></h1>
2071
    </div>
2072
    <div class="hd-right">
37487 ranu 2073
      <select id="rdrrRbmFilter" class="ctl" style="min-width:220px;height:38px;padding:8px 12px">
2074
        <option value="">All RBMs</option>
2075
      </select>
37444 ranu 2076
      <input class="ctl" id="rdrrPeriod" type="text" placeholder="Select date range"/>
2077
      <button class="btn-r" id="rdrrApply">Apply</button>
2078
    </div>
2079
  </header>
2080
 
2081
  <div class="kpis">
2082
    <div class="kpi a">
2083
      <div class="top">
2084
        <div class="ic">
2085
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
2086
               stroke-linejoin="round">
2087
            <path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>
2088
          </svg>
2089
        </div>
2090
        <div class="label">Total Achieved</div>
2091
      </div>
2092
      <div class="val" id="rdrrKpiAch">&mdash;</div>
2093
      <div class="foot" id="rdrrKpiAchSub">Actual billed across all RBMs</div>
2094
    </div>
2095
    <div class="kpi b">
2096
      <div class="top">
2097
        <div class="ic">
2098
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
2099
               stroke-linejoin="round">
2100
            <circle cx="12" cy="12" r="9"/>
2101
            <circle cx="12" cy="12" r="5"/>
2102
            <circle cx="12" cy="12" r="1.5" fill="currentColor"/>
2103
          </svg>
2104
        </div>
2105
        <div class="label">Total Target</div>
2106
      </div>
2107
      <div class="val" id="rdrrKpiTgt">&mdash;</div>
2108
      <div class="foot" id="rdrrKpiTgtSub">Sum of daily target snapshots</div>
2109
    </div>
2110
    <div class="kpi c">
2111
      <div class="top">
2112
        <div class="ic">
2113
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
2114
               stroke-linejoin="round">
2115
            <path d="M3 17l6-6 4 4 8-8"/>
2116
            <path d="M17 7h4v4"/>
2117
          </svg>
2118
        </div>
2119
        <div class="label">Achievement %</div>
2120
      </div>
2121
      <div class="val" id="rdrrKpiPct">&mdash;</div>
2122
      <div class="foot" id="rdrrKpiPctSub">Total ACH / Total TGT</div>
2123
    </div>
2124
    <div class="kpi d clickable" id="rdrrKpiTopCard" title="Click to see achieved vs pending RBMs">
2125
      <div class="top">
2126
        <div class="ic">
2127
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"
2128
               stroke-linejoin="round">
2129
            <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"/>
2130
          </svg>
2131
        </div>
2132
        <div class="label">RBMs β‰₯ 100% Target</div>
2133
      </div>
2134
      <div class="val" id="rdrrKpiTop">&mdash;</div>
2135
      <div class="foot" id="rdrrKpiTopSub">Rows meeting or beating target</div>
2136
      <span class="hint">Click for list &rsaquo;</span>
2137
    </div>
2138
  </div>
2139
 
2140
  <div class="sectionlabel">RBM &times; Warehouse &times; Movement Bucket</div>
2141
  <div class="legend">
2142
    <span class="lg hid"><i></i><span class="lgt">HID</span></span>
2143
    <span class="lg fast"><i></i><span class="lgt">FAST</span></span>
2144
    <span class="lg run"><i></i><span class="lgt">RUN</span></span>
2145
    <span class="lg slow"><i></i><span class="lgt">SLOW</span></span>
2146
    <span class="lg other"><i></i><span class="lgt">OTHER</span></span>
2147
  </div>
2148
  <div class="card">
2149
    <div class="card-hd">
2150
      <div>
2151
        <h2>Achievement vs Target</h2>
2152
        <p class="desc">Click any row for a per-bucket breakdown and the catalogs sold.</p>
2153
      </div>
2154
      <span class="badge-period" id="rdrrPeriodLabel">&mdash;</span>
2155
    </div>
2156
    <div id="rdrrTableWrap">
2157
      <div class="loading">
2158
        <div class="spinner"></div>
2159
        Loading&hellip;
2160
      </div>
2161
    </div>
2162
    <div class="foot-note">
2163
      <b>TGT</b> is summed from persisted per-day snapshots (<code>inventory.rbm_targets</code>) β€” days with no
2164
      scheduler-written snapshot contribute 0.
2165
      <b>ACH</b> is computed from source orders (<code>transaction.order</code>) for the range.
2166
    </div>
2167
  </div>
37460 ranu 2168
 
2169
  <!-- >15 Days Aging Sold -->
2170
  <div class="sectionlabel">&gt; 15 Days Aging Sold</div>
2171
  <div class="card">
2172
    <div class="card-hd">
2173
      <div>
2174
        <h2>Aging Inventory Cleared</h2>
2175
        <p class="desc">Billed value of items that were &gt; 15 days old at sale, per RBM, for the picked range.</p>
2176
      </div>
2177
      <span class="badge-period" id="rdrrAgingPeriod">&mdash;</span>
2178
    </div>
2179
    <div id="rdrrAgingWrap">
2180
      <div class="loading">
2181
        <div class="spinner"></div>
2182
        Loading&hellip;
2183
      </div>
2184
    </div>
2185
  </div>
2186
 
2187
  <!-- Partner Billing Count -->
2188
  <div class="sectionlabel">Partner Billing Count <span
2189
          style="color:var(--soft);font-weight:600;text-transform:none;letter-spacing:0;margin-left:6px">(Target: &gt;1L, Non-Target: &gt;20K)</span>
2190
  </div>
2191
  <div class="card">
2192
    <div class="card-hd">
2193
      <div>
2194
        <h2>Partners Who Billed This Month</h2>
2195
        <p class="desc">Counts partners meeting the billing threshold in each week bucket. Always month-to-date (weekly
2196
          buckets are inherently monthly).</p>
2197
      </div>
2198
      <span class="badge-period" id="rdrrBillingPeriod">&mdash;</span>
2199
    </div>
2200
    <div id="rdrrBillingWrap">
2201
      <div class="loading">
2202
        <div class="spinner"></div>
2203
        Loading&hellip;
2204
      </div>
2205
    </div>
2206
  </div>
37468 ranu 2207
 
2208
  <!-- RBM Performance Dashboard (MTD) β€” extracted from /indent/today_po_rbm without any backend change -->
2209
  <div class="sectionlabel">RBM Performance Dashboard (MTD)</div>
2210
  <div class="card">
2211
    <div class="card-hd">
2212
      <div>
2213
        <h2>Composite MTD Ranking</h2>
2214
        <p class="desc">Rank of RBMs by weighted score across Talk Time (10%) + MTD Achievement (55%) + Aging (2%) +
2215
          &gt;1L Partners (29%) + Rating (2%) + Partners Rated (2%).</p>
2216
      </div>
2217
      <span class="badge-period" id="rdrrPerfMonth">MTD</span>
2218
    </div>
2219
    <div id="rdrrPerfWrap">
2220
      <div class="loading">
2221
        <div class="spinner"></div>
2222
        Loading&hellip;
2223
      </div>
2224
    </div>
2225
  </div>
2226
 
2227
  <!-- Today PO & Billed β€” Brand Γ— RBM matrix (reuses /indent/today_po_table_fragment) -->
2228
  <div class="sectionlabel">Today PO &amp; Billed β€” Brand &times; RBM</div>
2229
  <div class="card">
2230
    <div class="card-hd">
2231
      <div>
2232
        <h2>Purchase Milestones by Brand</h2>
2233
        <p class="desc">Today's PO value / partner count / total billed, per RBM &times; brand. Always today
2234
          (independent of the range picker above).</p>
2235
      </div>
2236
      <select id="rdrrPmCategory" class="ctl" style="min-width:170px;height:34px;padding:6px 12px">
2237
        <option value="RBM">All RBMs</option>
2238
        <option value="NSM">All NSMs</option>
2239
        <option value="RSM">All RSMs</option>
2240
        <option value="BM">All BMs</option>
2241
        <option value="DM">All DMs</option>
2242
        <option value="CM">All CMs</option>
2243
        <option value="ASM">All ASMs</option>
2244
      </select>
2245
    </div>
2246
    <div id="rdrrPmWrap">
2247
      <div class="loading">
2248
        <div class="spinner"></div>
2249
        Loading&hellip;
2250
      </div>
2251
    </div>
2252
  </div>
37469 ranu 2253
 
2254
  <!-- RBM Call Target Summary β€” full interactive page injected via iframe srcdoc (no backend change) -->
2255
  <div class="sectionlabel">RBM Call Target Summary</div>
2256
  <div class="card">
2257
    <div class="card-hd">
2258
      <div>
2259
        <h2>Today's Call Coverage per RBM</h2>
2260
        <p class="desc">Full interactive view β€” all popups, drill-downs and downloads work exactly like the standalone
2261
          page.</p>
2262
      </div>
2263
      <a class="badge-period" href="/indent/rbm_call_target" target="_blank" style="text-decoration:none">Open in new
2264
        tab &rsaquo;</a>
2265
    </div>
2266
    <iframe id="rdrrCallFrame" title="RBM Call Target Summary"
2267
            style="width:100%;min-height:800px;border:0;border-radius:10px;background:#fff;display:block"></iframe>
2268
  </div>
37444 ranu 2269
</div>
2270
 
2271
<!-- achieved-vs-pending modal (opens from the RBMs β‰₯ 100% Target KPI card) -->
2272
<div class="status-back" id="rdrrStatusBack">
2273
  <div class="status-modal">
2274
    <button class="x" id="rdrrStatusClose" aria-label="Close">&times;</button>
2275
    <h3>Target Status by RBM</h3>
2276
    <p class="desc" id="rdrrStatusDesc">&mdash;</p>
2277
    <div class="status-grid">
2278
      <div class="status-col good">
2279
        <h4>βœ… Achieved <span class="cnt" id="rdrrStatusAchCnt">0</span></h4>
2280
        <div class="status-list" id="rdrrStatusAchList"></div>
2281
      </div>
2282
      <div class="status-col bad">
2283
        <h4>⚠ Pending <span class="cnt" id="rdrrStatusPndCnt">0</span></h4>
2284
        <div class="status-list" id="rdrrStatusPndList"></div>
2285
      </div>
2286
    </div>
2287
  </div>
2288
</div>
2289
 
37469 ranu 2290
<!-- call-target drill-down drawer (Called Partners / OOS Calls) -->
2291
<div class="rdrr-back" id="rdrrCallDrawerBack">
2292
  <div class="rdrr-panel">
2293
    <button class="x" id="rdrrCallDrawerClose" aria-label="Close">&times;</button>
2294
    <h3 id="rdrrCallDrawerTitle">&mdash;</h3>
2295
    <p class="desc" id="rdrrCallDrawerDesc">&mdash;</p>
2296
    <div id="rdrrCallDrawerBody">
2297
      <div class="loading">
2298
        <div class="spinner"></div>
2299
        Loading&hellip;
2300
      </div>
2301
    </div>
2302
  </div>
2303
</div>
2304
 
37444 ranu 2305
<!-- drill-down panel -->
2306
<div class="rdrr-back" id="rdrrBack">
2307
  <div class="rdrr-panel">
2308
    <button class="x" id="rdrrClose" aria-label="Close">&times;</button>
2309
    <h3 id="rdrrDdTitle">&mdash;</h3>
2310
    <p class="desc" id="rdrrDdDesc">&mdash;</p>
2311
 
2312
    <div class="rdrr-total">
2313
      <div>
2314
        <div class="k">Achieved</div>
2315
        <div class="v" id="rdrrDdAch">&mdash;</div>
2316
      </div>
2317
      <div>
2318
        <div class="k">Target</div>
2319
        <div class="v" id="rdrrDdTgt">&mdash;</div>
2320
      </div>
2321
      <div>
2322
        <div class="k">Achievement</div>
2323
        <div class="v" id="rdrrDdPct">&mdash;</div>
2324
      </div>
2325
    </div>
2326
 
2327
    <div class="sectionlabel" style="margin-top:2px">Movement Split β€” Achievement vs Target</div>
2328
    <div class="bbars" id="rdrrDdBars"></div>
2329
 
37487 ranu 2330
    <div class="sectionlabel">Warehouse Flow β€” Buying vs Selling <span
2331
            style="color:var(--soft);font-weight:600;text-transform:none;letter-spacing:0;margin-left:6px">(GRN into this warehouse + cross-warehouse direct billings)</span>
2332
    </div>
2333
    <div id="rdrrDdFlow">
2334
      <div class="loading">
2335
        <div class="spinner"></div>
2336
        Loading&hellip;
2337
      </div>
2338
    </div>
2339
 
37444 ranu 2340
    <div class="sectionlabel">Brand Mix β€” Share of Achievement <span
2341
            style="color:var(--soft);font-weight:600;text-transform:none;letter-spacing:0;margin-left:6px">(click a brand for movement split)</span>
2342
    </div>
2343
    <div id="rdrrDdBrands">
2344
      <div class="loading">
2345
        <div class="spinner"></div>
2346
        Loading brand mix&hellip;
2347
      </div>
2348
    </div>
2349
  </div>
2350
</div>
2351
 
2352
<script src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
2353
<script src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
2354
<script src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
2355
<script>
2356
  (function () {
2357
    var DEFAULT_START = "$defaultStartDate";
2358
    var DEFAULT_END = "$defaultEndDate";
2359
 
2360
    // Prefer query-string range if the caller provided one (e.g. from today_po_rbm's date picker).
2361
    var url = new URL(window.location.href);
2362
    var qsStart = url.searchParams.get("startDate");
2363
    var qsEnd = url.searchParams.get("endDate");
2364
    var startDate = qsStart || DEFAULT_START;
2365
    var endDate = qsEnd || DEFAULT_END;
2366
 
2367
    function fmtDate(s) {
2368
      return moment(s).format("DD MMM");
2369
    }
2370
 
2371
    function fmtLakh(v) {
2372
      v = Number(v) || 0;
2373
      return (v / 100000).toFixed(1) + "L";
2374
    }
2375
 
2376
    function pctClass(p) {
2377
      if (p >= 95) return "good";
2378
      if (p >= 41) return "warn";
2379
      return "bad";
2380
    }
2381
 
2382
    function pctLabel(ach, tgt) {
2383
      if (!tgt || tgt <= 0) return {text: "-", cls: "na", num: null};
2384
      var p = (ach / tgt) * 100;
2385
      return {text: p.toFixed(1) + "%", cls: pctClass(p), num: p};
2386
    }
2387
 
2388
    function pctBarWidth(ach, tgt) {
2389
      if (!tgt || tgt <= 0) return 0;
2390
      return Math.min(100, (ach / tgt) * 100);
2391
    }
2392
 
2393
    // Initialise the range picker.
2394
    $("#rdrrPeriod").daterangepicker({
2395
      startDate: moment(startDate),
2396
      endDate: moment(endDate),
2397
      locale: {format: "YYYY-MM-DD", cancelLabel: "Clear"}
2398
    });
2399
    $("#rdrrPeriod").on("apply.daterangepicker", function (ev, picker) {
2400
      startDate = picker.startDate.format("YYYY-MM-DD");
2401
      endDate = picker.endDate.format("YYYY-MM-DD");
2402
    });
2403
 
2404
    // Defensive: read the picker's current state at click time in case
2405
    // the apply.daterangepicker event was swallowed for any reason.
2406
    $("#rdrrApply").on("click", function () {
2407
      var p = $("#rdrrPeriod").data("daterangepicker");
2408
      if (p) {
2409
        startDate = p.startDate.format("YYYY-MM-DD");
2410
        endDate = p.endDate.format("YYYY-MM-DD");
2411
      }
2412
      load();
2413
    });
2414
 
2415
    function load() {
2416
      $("#rdrrTableWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
37460 ranu 2417
      $("#rdrrAgingWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
2418
      $("#rdrrBillingWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
37444 ranu 2419
      $("#rdrrPeriodLabel").text(fmtDate(startDate) + " – " + fmtDate(endDate));
37460 ranu 2420
      $("#rdrrAgingPeriod").text(fmtDate(startDate) + " – " + fmtDate(endDate));
37444 ranu 2421
      fetch("/rbm-drr/data?startDate=" + startDate + "&endDate=" + endDate, {credentials: "same-origin"})
2422
              .then(function (r) {
2423
                return r.json().then(function (b) {
2424
                  return {ok: r.ok, body: b};
2425
                });
2426
              })
2427
              .then(function (res) {
2428
                if (!res.ok) {
2429
                  $("#rdrrTableWrap").html('<div class="empty">' + escapeHtml(res.body && res.body.error ? res.body.error : "Failed to load.") + '</div>');
2430
                  return;
2431
                }
2432
                render(res.body);
2433
              })
2434
              .catch(function (e) {
2435
                $("#rdrrTableWrap").html('<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>');
2436
              });
37460 ranu 2437
 
2438
      fetch("/rbm-drr/extras?startDate=" + startDate + "&endDate=" + endDate, {credentials: "same-origin"})
2439
              .then(function (r) {
2440
                return r.json().then(function (b) {
2441
                  return {ok: r.ok, body: b};
2442
                });
2443
              })
2444
              .then(function (res) {
2445
                if (!res.ok) {
2446
                  var msg = '<div class="empty">' + escapeHtml(res.body && res.body.error ? res.body.error : "Failed to load.") + '</div>';
2447
                  $("#rdrrAgingWrap").html(msg);
2448
                  $("#rdrrBillingWrap").html(msg);
2449
                  return;
2450
                }
2451
                renderAging(res.body);
2452
                renderPartnerBilling(res.body);
2453
              })
2454
              .catch(function (e) {
2455
                var msg = '<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>';
2456
                $("#rdrrAgingWrap").html(msg);
2457
                $("#rdrrBillingWrap").html(msg);
2458
              });
37444 ranu 2459
    }
2460
 
37460 ranu 2461
    function renderAging(data) {
2462
      var rows = data.aging || [];
2463
      var totals = data.agingTotals || {};
2464
      var balance = data.balance || {};
2465
      if (rows.length === 0) {
2466
        $("#rdrrAgingWrap").html('<div class="empty"><div class="ei">πŸ“¦</div>No aging inventory sold in this range.</div>');
2467
        return;
2468
      }
2469
      var html = ['<table class="xtable"><thead><tr>',
2470
        '<th>RBM</th>',
2471
        '<th class="num g-hid">HID</th>',
2472
        '<th class="num g-fast">FAST</th>',
2473
        '<th class="num g-run">RUN</th>',
2474
        '<th class="num g-slow">SLOW</th>',
2475
        '<th class="num g-other">OTHER</th>',
2476
        '<th class="num g-total">TOTAL</th>',
2477
        '</tr></thead><tbody>'];
2478
      rows.forEach(function (r) {
2479
        html.push('<tr>' +
2480
                '<td class="rbm-nm">' + escapeHtml(r.rbmName || '-') + '</td>' +
2481
                cell(r.hid, 'g-hid') + cell(r.fast, 'g-fast') + cell(r.run, 'g-run') +
2482
                cell(r.slow, 'g-slow') + cell(r.other, 'g-other') + cell(r.total, 'g-total') +
2483
                '</tr>');
2484
      });
2485
      html.push('<tr class="tot">' +
2486
              '<td>Total</td>' +
2487
              cell(totals.hid, 'g-hid') + cell(totals.fast, 'g-fast') + cell(totals.run, 'g-run') +
2488
              cell(totals.slow, 'g-slow') + cell(totals.other, 'g-other') + cell(totals.total, 'g-total') +
2489
              '</tr>');
2490
      html.push('<tr class="bal">' +
2491
              '<td class="hdr">15-Day Balance Value</td>' +
2492
              cell(balance.hid) + cell(balance.fast) + cell(balance.run) +
2493
              cell(balance.slow) + cell(balance.other) + cell(balance.total) +
2494
              '</tr>');
2495
      html.push('</tbody></table>');
2496
      $("#rdrrAgingWrap").html(html.join(""));
2497
    }
2498
 
2499
    function cell(v, cls) {
2500
      v = Number(v) || 0;
2501
      var zero = v === 0 ? ' zero' : '';
2502
      var extra = cls ? ' ' + cls : '';
2503
      return '<td class="num' + extra + zero + '">' + formatIndian(v) + '</td>';
2504
    }
2505
 
2506
    function formatIndian(n) {
2507
      n = Math.round(Number(n) || 0);
2508
      if (n === 0) return '0';
2509
      var s = n.toString();
2510
      var lastThree = s.substring(s.length - 3);
2511
      var otherNums = s.substring(0, s.length - 3);
2512
      if (otherNums !== '') lastThree = ',' + lastThree;
2513
      return otherNums.replace(/\B(?=(\d{2})+(?!\d))/g, ',') + lastThree;
2514
    }
2515
 
2516
    function renderPartnerBilling(data) {
2517
      var rows = data.partnerBilling || [];
2518
      var totals = data.partnerBillingTotals || {};
2519
      $("#rdrrBillingPeriod").text(data.partnerBillingMonth || '');
2520
      if (rows.length === 0) {
2521
        $("#rdrrBillingWrap").html('<div class="empty"><div class="ei">πŸ‘₯</div>No targeted partners this month.</div>');
2522
        return;
2523
      }
2524
      var html = ['<table class="xtable"><thead><tr>',
2525
        '<th>RBM</th>',
2526
        '<th class="num">Targeted</th>',
2527
        '<th class="num">Week 1<br><small style="color:var(--soft);font-weight:600">(1–7)</small></th>',
2528
        '<th class="num">Week 2<br><small style="color:var(--soft);font-weight:600">(8–15)</small></th>',
2529
        '<th class="num">Week 3<br><small style="color:var(--soft);font-weight:600">(16–22)</small></th>',
2530
        '<th class="num">Week 4<br><small style="color:var(--soft);font-weight:600">(23–end)</small></th>',
2531
        '<th class="num g-total">MTD</th>',
2532
        '<th class="num">Zero Billed<br><small style="color:var(--soft);font-weight:600">(&lt;1L / &lt;20K)</small></th>',
2533
        '</tr></thead><tbody>'];
2534
      rows.forEach(function (r) {
2535
        html.push('<tr>' +
2536
                '<td class="rbm-nm">' + escapeHtml(r.rbmName || '-') + '</td>' +
2537
                '<td class="num">' + pill(r.targeted, '') + '</td>' +
2538
                '<td class="num">' + pill(r.w1, ratio(r.w1, r.targeted)) + '</td>' +
2539
                '<td class="num">' + pill(r.w2, ratio(r.w2, r.targeted)) + '</td>' +
2540
                '<td class="num">' + pill(r.w3, ratio(r.w3, r.targeted)) + '</td>' +
2541
                '<td class="num">' + pill(r.w4, ratio(r.w4, r.targeted)) + '</td>' +
2542
                '<td class="num g-total">' + pill(r.mtd, ratio(r.mtd, r.targeted)) + '</td>' +
2543
                '<td class="num">' + pill(r.zero, r.zero > 0 ? 'warn' : 'zero') + '</td>' +
2544
                '</tr>');
2545
      });
2546
      html.push('<tr class="tot">' +
2547
              '<td>Total</td>' +
2548
              '<td class="num">' + formatIndian(totals.targeted) + '</td>' +
2549
              '<td class="num">' + formatIndian(totals.w1) + '</td>' +
2550
              '<td class="num">' + formatIndian(totals.w2) + '</td>' +
2551
              '<td class="num">' + formatIndian(totals.w3) + '</td>' +
2552
              '<td class="num">' + formatIndian(totals.w4) + '</td>' +
2553
              '<td class="num g-total">' + formatIndian(totals.mtd) + '</td>' +
2554
              '<td class="num">' + formatIndian(totals.zero) + '</td>' +
2555
              '</tr>');
2556
      html.push('</tbody></table>');
2557
      $("#rdrrBillingWrap").html(html.join(""));
2558
    }
2559
 
2560
    function pill(v, cls) {
2561
      v = Number(v) || 0;
2562
      var c = cls || (v === 0 ? 'zero' : '');
2563
      return '<span class="cnt-pill ' + c + '">' + formatIndian(v) + '</span>';
2564
    }
2565
 
2566
    function ratio(part, total) {
2567
      part = Number(part) || 0;
2568
      total = Number(total) || 0;
2569
      if (total === 0) return 'zero';
2570
      var p = (part / total) * 100;
2571
      if (p >= 60) return 'good';
2572
      if (p >= 30) return '';
2573
      if (p > 0) return 'warn';
2574
      return 'zero';
2575
    }
2576
 
37444 ranu 2577
    // Cached latest payload so the "Target Status by RBM" modal can render
2578
    // without a re-fetch when the KPI card is clicked.
2579
    var LAST_PAYLOAD = null;
37487 ranu 2580
    var CURRENT_FILTER_AUTH_ID = "";  // "" = all RBMs
37444 ranu 2581
 
2582
    function render(data) {
2583
      LAST_PAYLOAD = data;
37487 ranu 2584
      populateRbmFilter(data.rows || []);
2585
      renderFiltered();
2586
    }
37444 ranu 2587
 
37487 ranu 2588
    // Build the dropdown options from the fetched rows (unique RBM names).
2589
    // Preserves current selection if the RBM still exists in the new dataset.
2590
    function populateRbmFilter(rows) {
2591
      var seen = {};
2592
      var options = [];
2593
      rows.forEach(function (r) {
2594
        if (!seen[r.authId]) {
2595
          seen[r.authId] = true;
2596
          options.push({id: r.authId, name: r.rbmName});
2597
        }
2598
      });
2599
      options.sort(function (a, b) {
2600
        return (a.name || "").localeCompare(b.name || "");
2601
      });
2602
      var sel = $("#rdrrRbmFilter");
2603
      var prev = sel.val() || "";
2604
      var html = '<option value="">All RBMs (' + options.length + ')</option>';
2605
      options.forEach(function (o) {
2606
        html += '<option value="' + o.id + '">' + escapeHtml(o.name || "Unknown") + '</option>';
2607
      });
2608
      sel.html(html);
2609
      // Restore prior selection if still valid; otherwise reset.
2610
      if (prev && seen[prev]) sel.val(prev); else CURRENT_FILTER_AUTH_ID = "";
2611
    }
2612
 
2613
    // Renders KPIs + grid from LAST_PAYLOAD filtered by CURRENT_FILTER_AUTH_ID.
2614
    function renderFiltered() {
2615
      if (!LAST_PAYLOAD) return;
2616
      var allRows = LAST_PAYLOAD.rows || [];
2617
      var rows = CURRENT_FILTER_AUTH_ID
2618
              ? allRows.filter(function (r) {
2619
                return String(r.authId) === String(CURRENT_FILTER_AUTH_ID);
2620
              })
2621
              : allRows;
2622
 
2623
      // Recompute totals from the filtered subset. Cheaper + correct vs using server totals.
2624
      var t = {
2625
        totalAch: 0, totalTgt: 0, hidAch: 0, hidTgt: 0, fastAch: 0, fastTgt: 0,
2626
        runAch: 0, runTgt: 0, slowAch: 0, slowTgt: 0, otherAch: 0, otherTgt: 0,
2627
        rbmsAtOrAbove100: 0, rbmRowCount: rows.length
2628
      };
2629
      rows.forEach(function (r) {
2630
        t.totalAch += Number(r.totalAch) || 0;
2631
        t.totalTgt += Number(r.totalTgt) || 0;
2632
        t.hidAch += Number(r.hidAch) || 0;
2633
        t.hidTgt += Number(r.hidTgt) || 0;
2634
        t.fastAch += Number(r.fastAch) || 0;
2635
        t.fastTgt += Number(r.fastTgt) || 0;
2636
        t.runAch += Number(r.runAch) || 0;
2637
        t.runTgt += Number(r.runTgt) || 0;
2638
        t.slowAch += Number(r.slowAch) || 0;
2639
        t.slowTgt += Number(r.slowTgt) || 0;
2640
        t.otherAch += Number(r.otherAch) || 0;
2641
        t.otherTgt += Number(r.otherTgt) || 0;
2642
        if (r.totalTgt > 0 && r.totalAch >= r.totalTgt) t.rbmsAtOrAbove100++;
2643
      });
2644
 
37444 ranu 2645
      $("#rdrrKpiAch").html('&#8377;&nbsp;' + fmtLakh(t.totalAch));
2646
      $("#rdrrKpiTgt").html('&#8377;&nbsp;' + fmtLakh(t.totalTgt));
2647
      var pk = pctLabel(t.totalAch, t.totalTgt);
2648
      $("#rdrrKpiPct").html(pk.cls === "na" ? '<span class="u">n/a</span>' :
2649
              '<span class="pct ' + pk.cls + '">' + pk.text + '</span>');
2650
      $("#rdrrKpiTop").html((t.rbmsAtOrAbove100 || 0) + ' <span class="u">/ ' + (t.rbmRowCount || 0) + '</span>');
2651
 
2652
      if (rows.length === 0) {
37487 ranu 2653
        $("#rdrrTableWrap").html('<div class="empty"><div class="ei">πŸ“­</div>' +
2654
                (CURRENT_FILTER_AUTH_ID ? 'This RBM has no rows in the current range.' : 'No RBM rows in this range.') +
2655
                '</div>');
37444 ranu 2656
        return;
2657
      }
2658
 
2659
      var buckets = [
2660
        {key: "hid", label: "HID"},
2661
        {key: "fast", label: "FAST"},
2662
        {key: "run", label: "RUN"},
2663
        {key: "slow", label: "SLOW"},
2664
        {key: "other", label: "OTHER"}
2665
      ];
2666
 
2667
      var html = ['<table id="rdrrGrid"><thead><tr>',
2668
        '<th>RBM &middot; Warehouse</th>',
2669
        '<th class="num g-total">Total<br><small style="color:var(--soft);font-weight:600">ACH / TGT</small></th>',
2670
        '<th class="num g-total">%</th>'];
2671
      buckets.forEach(function (b) {
2672
        html.push('<th class="num g-' + b.key + '">' + b.label + '<br><small style="color:var(--soft);font-weight:600">ACH / TGT</small></th>');
2673
        html.push('<th class="num g-' + b.key + '">%</th>');
2674
      });
2675
      html.push('<th></th></tr></thead><tbody>');
2676
 
2677
      rows.forEach(function (r) {
2678
        var tr = ['<tr class="clickable" data-authid="' + r.authId + '" data-warehouseid="' + r.warehouseId + '" data-rbmname="' + escapeHtml(r.rbmName) + '" data-warehousename="' + escapeHtml(r.warehouseName) + '">'];
2679
        tr.push('<td><div class="rbm-cell"><span class="rn">' + escapeHtml(r.rbmName) + '</span><span class="wh">' + escapeHtml(r.warehouseName) + '</span></div></td>');
2680
        tr.push(cellPair(r.totalAch, r.totalTgt));
2681
        buckets.forEach(function (b) {
2682
          tr.push(cellPair(r[b.key + "Ach"], r[b.key + "Tgt"]));
2683
        });
2684
        tr.push('<td class="chev">&rsaquo;</td>');
2685
        tr.push('</tr>');
2686
        html.push(tr.join(""));
2687
      });
2688
 
2689
      // totals row
2690
      var totTr = ['<tr class="totalrow"><td><strong>Total</strong></td>'];
2691
      totTr.push(cellPair(t.totalAch, t.totalTgt, true));
2692
      buckets.forEach(function (b) {
2693
        totTr.push(cellPair(t[b.key + "Ach"], t[b.key + "Tgt"], true));
2694
      });
2695
      totTr.push('<td></td></tr>');
2696
      html.push(totTr.join(""));
2697
 
2698
      html.push('</tbody></table>');
2699
      $("#rdrrTableWrap").html(html.join(""));
2700
 
2701
      // Cache the parsed row on each <tr> so drill-down can render bars immediately.
2702
      rows.forEach(function (r) {
2703
        $("#rdrrGrid tbody tr").filter(function () {
2704
          return +this.dataset.authid === r.authId && +this.dataset.warehouseid === r.warehouseId;
2705
        }).each(function () {
2706
          $(this).data("cached", r);
2707
        });
2708
      });
2709
 
2710
      $("#rdrrGrid tbody tr.clickable").on("click", function () {
2711
        var d = this.dataset;
2712
        var cached = $(this).data("cached");
2713
        openDrilldown(+d.authid, +d.warehouseid, d.rbmname, d.warehousename, cached);
2714
      });
2715
    }
2716
 
2717
    function cellPair(ach, tgt, isTotal) {
2718
      var p = pctLabel(ach, tgt);
2719
      var vhtml = '<td class="num"><div class="cell-val">' + fmtLakh(ach) + ' <small>/ ' + fmtLakh(tgt) + '</small></div></td>';
2720
      var barCls = p.cls === "na" ? "" : p.cls;
2721
      var barW = pctBarWidth(ach, tgt);
2722
      var pctHtml = '<td class="num"><span class="pct ' + p.cls + '">' + p.text + '</span>' +
2723
              (barCls ? '<div class="bar"><i class="' + barCls + '" style="width:' + barW.toFixed(1) + '%"></i></div>' : '') +
2724
              '</td>';
2725
      return vhtml + pctHtml;
2726
    }
2727
 
2728
    // --------------------------- drill-down ---------------------------
2729
 
2730
    function openDrilldown(authId, warehouseId, rbmName, warehouseName, cachedRow) {
2731
      var back = $("#rdrrBack");
2732
      $("#rdrrDdTitle").text(rbmName + " β€” " + warehouseName);
2733
      $("#rdrrDdDesc").text(fmtDate(startDate) + " – " + fmtDate(endDate));
2734
      $("#rdrrDdBars").empty();
2735
      back.addClass("show");
2736
 
2737
      if (cachedRow) {
2738
        renderBars(cachedRow);
2739
      } else {
2740
        $("#rdrrDdAch").text("β€”");
2741
        $("#rdrrDdTgt").text("β€”");
2742
        $("#rdrrDdPct").text("β€”");
2743
      }
2744
      $("#rdrrDdBrands").html('<div class="loading"><div class="spinner"></div>Loading brand mix&hellip;</div>');
37487 ranu 2745
      $("#rdrrDdFlow").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
37444 ranu 2746
 
2747
      fetch("/rbm-drr/rbm-detail?authId=" + authId + "&warehouseId=" + warehouseId +
2748
              "&startDate=" + startDate + "&endDate=" + endDate, {credentials: "same-origin"})
2749
              .then(function (r) {
2750
                return r.json();
2751
              })
2752
              .then(function (data) {
2753
                renderBrands(data);
37487 ranu 2754
                renderWarehouseFlow(data, cachedRow);
37444 ranu 2755
              })
2756
              .catch(function (e) {
37487 ranu 2757
                var msg = '<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>';
2758
                $("#rdrrDdBrands").html(msg);
2759
                $("#rdrrDdFlow").html(msg);
37444 ranu 2760
              });
2761
    }
2762
 
37487 ranu 2763
    function renderWarehouseFlow(data, row) {
2764
      var buying = (data && data.buying) || [];
2765
      // Map buying values by status for O(1) lookup.
2766
      var buyMap = {};
2767
      buying.forEach(function (b) {
2768
        buyMap[b.status] = Number(b.value) || 0;
2769
      });
2770
      var labels = {HID: "HID", FASTMOVING: "FAST", RUNNING: "RUN", SLOWMOVING: "SLOW", OTHER: "OTHER"};
2771
      var order = ["HID", "FASTMOVING", "RUNNING", "SLOWMOVING", "OTHER"];
2772
      // Selling per bucket from the cached grid row (already has ACH per bucket).
2773
      var sellMap = {
2774
        HID: row ? Number(row.hidAch) || 0 : 0,
2775
        FASTMOVING: row ? Number(row.fastAch) || 0 : 0,
2776
        RUNNING: row ? Number(row.runAch) || 0 : 0,
2777
        SLOWMOVING: row ? Number(row.slowAch) || 0 : 0,
2778
        OTHER: row ? Number(row.otherAch) || 0 : 0
2779
      };
2780
      var totBuy = 0, totSell = 0;
2781
      order.forEach(function (s) {
2782
        totBuy += buyMap[s] || 0;
2783
        totSell += sellMap[s] || 0;
2784
      });
2785
 
2786
      // "Coverage" = selling / buying. High coverage = we sold most of what came in.
2787
      // Low coverage = supply piling up (aging risk).
2788
      function covCell(sell, buy) {
2789
        if (!buy || buy <= 0) {
2790
          if (sell > 0) return '<span class="cov-cell na" title="No buying recorded in this range">β€” <span class="cov-pct" style="color:var(--good)">sold ' + fmtLakh(sell) + '</span></span>';
2791
          return '<span class="cov-cell na">β€”</span>';
2792
        }
2793
        var pct = (sell / buy) * 100;
2794
        var cls = pct >= 60 ? 'good' : pct >= 25 ? 'warn' : 'bad';
2795
        var w = Math.min(100, pct);
2796
        return '<span class="cov-cell ' + cls + '">' +
2797
                '<span class="cov-bar"><i style="width:' + w.toFixed(1) + '%"></i></span>' +
2798
                '<span class="cov-pct">' + pct.toFixed(1) + '%</span></span>';
2799
      }
2800
 
2801
      var html = '<table class="flow-tbl"><thead><tr>' +
2802
              '<th>Movement</th><th class="num">Buying</th><th class="num">Selling</th><th class="num">Coverage (sold / bought)</th>' +
2803
              '</tr></thead><tbody>';
2804
      order.forEach(function (s) {
2805
        var buy = buyMap[s] || 0, sell = sellMap[s] || 0;
2806
        html += '<tr class="' + s.toLowerCase() + '">' +
2807
                '<td><i></i>' + labels[s] + '</td>' +
2808
                '<td class="num">' + fmtLakh(buy) + '</td>' +
2809
                '<td class="num">' + fmtLakh(sell) + '</td>' +
2810
                '<td class="num">' + covCell(sell, buy) + '</td>' +
2811
                '</tr>';
2812
      });
2813
      html += '<tr class="tot">' +
2814
              '<td>Total</td>' +
2815
              '<td class="num">' + fmtLakh(totBuy) + '</td>' +
2816
              '<td class="num">' + fmtLakh(totSell) + '</td>' +
2817
              '<td class="num">' + covCell(totSell, totBuy) + '</td>' +
2818
              '</tr>';
2819
      html += '</tbody></table>';
2820
      $("#rdrrDdFlow").html(html);
2821
    }
2822
 
37444 ranu 2823
    function renderBrands(data) {
2824
      var brands = (data && data.brands) || [];
2825
      if (brands.length === 0) {
2826
        $("#rdrrDdBrands").html('<div class="empty"><div class="ei">🏷️</div>No brand sales in this range.</div>');
2827
        return;
2828
      }
2829
      var maxShare = brands[0].sharePct || 0.001;
2830
      var html = '<div class="brands">';
2831
      brands.forEach(function (b, idx) {
2832
        var barW = maxShare > 0 ? Math.min(100, (b.sharePct / maxShare) * 100) : 0;
2833
        var topCls = idx === 0 ? ' top' : '';
37460 ranu 2834
        var pc = Number(b.partnerCount) || 0;
2835
        var pcCls = pc === 0 ? ' zero' : '';
2836
        var pcLabel = pc + (pc === 1 ? ' partner' : ' partners');
37444 ranu 2837
        html += '<div class="brand-card' + topCls + '" data-idx="' + idx + '">' +
2838
                '<div class="brand-head">' +
2839
                '<div class="cx">&rsaquo;</div>' +
2840
                '<div class="bn" title="' + escapeHtml(b.brand) + '">' + escapeHtml(b.brand) + '</div>' +
2841
                '<div class="btrack"><i style="width:' + barW.toFixed(1) + '%"></i></div>' +
37460 ranu 2842
                '<div class="bpc' + pcCls + '" title="Distinct partners of this RBM who billed ' + escapeHtml(b.brand) + ' in the range">' +
2843
                '<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>' +
2844
                pcLabel +
2845
                '</div>' +
37444 ranu 2846
                '<div class="bval">' + fmtLakh(b.valueSold) + '</div>' +
2847
                '<div class="bshare">' + (b.sharePct || 0).toFixed(1) + '%</div>' +
2848
                '</div>' +
2849
                '<div class="brand-body">' +
2850
                '<div class="bhdr">Movement Split within ' + escapeHtml(b.brand) + '</div>' +
2851
                renderBrandBuckets(b.buckets || []) +
2852
                '</div>' +
2853
                '</div>';
2854
      });
2855
      html += '</div>';
2856
      $("#rdrrDdBrands").html(html);
2857
 
2858
      $("#rdrrDdBrands .brand-head").on("click", function () {
2859
        $(this).closest(".brand-card").toggleClass("open");
2860
      });
2861
    }
2862
 
2863
    function renderBrandBuckets(buckets) {
2864
      if (!buckets || buckets.length === 0) {
2865
        return '<div style="color:var(--soft);font-size:12px;padding:8px 4px">No movement split available.</div>';
2866
      }
2867
      var labels = {HID: "HID", FASTMOVING: "FAST", RUNNING: "RUN", SLOWMOVING: "SLOW", OTHER: "OTHER"};
2868
      var html = '<div class="mbars">';
2869
      buckets.forEach(function (bk) {
2870
        var cls = (bk.status || "OTHER").toLowerCase();
2871
        var label = labels[bk.status] || bk.status || "OTHER";
2872
        var sp = bk.sharePctOfBrand || 0;
2873
        var barW = Math.min(100, sp);
2874
        html += '<div class="mbar ' + cls + '">' +
2875
                '<div class="mname"><i></i>' + label + '</div>' +
2876
                '<div class="mtrack"><i style="width:' + barW.toFixed(1) + '%"></i></div>' +
2877
                '<div class="mval">' + fmtLakh(bk.valueSold) + '</div>' +
2878
                '<div class="mshare">' + sp.toFixed(1) + '%</div>' +
2879
                '</div>';
2880
      });
2881
      html += '</div>';
2882
      return html;
2883
    }
2884
 
2885
    function renderBars(row) {
2886
      var totalAch = row.totalAch, totalTgt = row.totalTgt;
2887
      $("#rdrrDdAch").html('&#8377;&nbsp;' + fmtLakh(totalAch));
2888
      $("#rdrrDdTgt").html('&#8377;&nbsp;' + fmtLakh(totalTgt));
2889
      var pt = pctLabel(totalAch, totalTgt);
2890
      $("#rdrrDdPct").html(pt.cls === "na" ? '<span style="color:var(--soft);font-size:14px">n/a</span>' :
2891
              '<span class="pct ' + pt.cls + '">' + pt.text + '</span>');
2892
 
2893
      var buckets = [
2894
        {key: "hid", label: "HID"},
2895
        {key: "fast", label: "FAST"},
2896
        {key: "run", label: "RUN"},
2897
        {key: "slow", label: "SLOW"},
2898
        {key: "other", label: "OTHER"}
2899
      ];
2900
      var html = "";
2901
      buckets.forEach(function (b) {
2902
        var ach = row[b.key + "Ach"], tgt = row[b.key + "Tgt"];
2903
        var p = pctLabel(ach, tgt);
2904
        var w = pctBarWidth(ach, tgt);
2905
        html += '<div class="bbar ' + b.key + '">' +
2906
                '<div class="bname"><i></i>' + b.label + '</div>' +
2907
                '<div class="btrack"><i style="width:' + w.toFixed(1) + '%"></i></div>' +
2908
                '<div class="btgt"><b>' + fmtLakh(ach) + '</b> / ' + fmtLakh(tgt) + '</div>' +
2909
                '<div class="bpct ' + p.cls + '">' + p.text + '</div>' +
2910
                '</div>';
2911
      });
2912
      $("#rdrrDdBars").html(html);
2913
    }
2914
 
2915
    function escapeHtml(s) {
2916
      if (s == null) return "";
2917
      return String(s).replace(/[&<>"']/g, function (c) {
2918
        return {"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;"}[c];
2919
      });
2920
    }
2921
 
2922
    $("#rdrrClose").on("click", function () {
2923
      $("#rdrrBack").removeClass("show");
2924
    });
2925
    $("#rdrrBack").on("click", function (e) {
2926
      if (e.target === this) $(this).removeClass("show");
2927
    });
2928
 
2929
    // Target-status modal (achieved vs pending) β€” opens from the KPI card.
2930
    $("#rdrrKpiTopCard").on("click", function () {
2931
      openStatusModal();
2932
    });
2933
    $("#rdrrStatusClose").on("click", function () {
2934
      $("#rdrrStatusBack").removeClass("show");
2935
    });
2936
    $("#rdrrStatusBack").on("click", function (e) {
2937
      if (e.target === this) $(this).removeClass("show");
2938
    });
2939
 
2940
    function openStatusModal() {
2941
      if (!LAST_PAYLOAD) return;
37487 ranu 2942
      // Respect the RBM filter so the modal matches what's on screen.
2943
      var rows = (LAST_PAYLOAD.rows || []).filter(function (r) {
2944
        return !CURRENT_FILTER_AUTH_ID || String(r.authId) === String(CURRENT_FILTER_AUTH_ID);
2945
      });
37444 ranu 2946
      var achieved = [], pending = [];
2947
      rows.forEach(function (r) {
2948
        if (!r.totalTgt || r.totalTgt <= 0) return;
2949
        var pct = (r.totalAch / r.totalTgt) * 100;
2950
        var enriched = {row: r, pct: pct};
2951
        if (r.totalAch >= r.totalTgt) achieved.push(enriched);
2952
        else pending.push(enriched);
2953
      });
2954
      achieved.sort(function (a, b) {
2955
        return b.pct - a.pct;
2956
      });
2957
      pending.sort(function (a, b) {
2958
        return a.pct - b.pct;
2959
      });
2960
 
2961
      $("#rdrrStatusDesc").text(fmtDate(startDate) + " – " + fmtDate(endDate));
2962
      $("#rdrrStatusAchCnt").text(achieved.length);
2963
      $("#rdrrStatusPndCnt").text(pending.length);
2964
      $("#rdrrStatusAchList").html(renderStatusList(achieved, "achieved"));
2965
      $("#rdrrStatusPndList").html(renderStatusList(pending, "pending"));
2966
      $("#rdrrStatusBack").addClass("show");
2967
 
2968
      // Bind click on each item to open the same drill-down slide-in.
2969
      $("#rdrrStatusBack .status-item").on("click", function () {
2970
        var d = this.dataset;
2971
        var cachedRow = null;
2972
        (LAST_PAYLOAD.rows || []).some(function (r) {
2973
          if (r.authId == d.authid && r.warehouseId == d.warehouseid) {
2974
            cachedRow = r;
2975
            return true;
2976
          }
2977
          return false;
2978
        });
2979
        $("#rdrrStatusBack").removeClass("show");
2980
        openDrilldown(+d.authid, +d.warehouseid, d.rbmname, d.warehousename, cachedRow);
2981
      });
2982
    }
2983
 
2984
    function renderStatusList(items, kind) {
2985
      if (items.length === 0) {
2986
        return '<div class="status-empty">' +
2987
                (kind === "achieved" ? "No RBM has met target in this range." : "All RBMs met target β€” nice!") +
2988
                '</div>';
2989
      }
2990
      var html = "";
2991
      items.forEach(function (it) {
2992
        var r = it.row;
2993
        var p = pctClass(it.pct);
2994
        html += '<div class="status-item" title="Click to view drill-down"' +
2995
                ' data-authid="' + r.authId + '" data-warehouseid="' + r.warehouseId + '"' +
2996
                ' data-rbmname="' + escapeHtml(r.rbmName) + '" data-warehousename="' + escapeHtml(r.warehouseName) + '"' +
2997
                ' style="cursor:pointer">' +
2998
                '<div><span class="rn">' + escapeHtml(r.rbmName) + '</span>' +
2999
                '<span class="wh">' + escapeHtml(r.warehouseName) + '</span></div>' +
3000
                '<div class="vv"><b>' + fmtLakh(r.totalAch) + '</b> / ' + fmtLakh(r.totalTgt) + '</div>' +
3001
                '<div class="pp ' + p + '">' + it.pct.toFixed(1) + '%</div>' +
3002
                '</div>';
3003
      });
3004
      return html;
3005
    }
3006
 
37468 ranu 3007
    // ------------------------- Today PO & Billed matrix -------------------------
3008
    // Reuses the existing /indent/today_po_table_fragment endpoint (unchanged).
3009
    // Injects the returned HTML and restyles it via #rdrrPmWrap CSS.
3010
    function loadPurchaseMilestones() {
3011
      var cat = $("#rdrrPmCategory").val() || "RBM";
3012
      $("#rdrrPmWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
3013
      $.ajax({
3014
        url: "/indent/today_po_table_fragment",
3015
        type: "GET",
3016
        data: {categoryType: cat},
3017
        success: function (html) {
3018
          $("#rdrrPmWrap").html(html);
3019
          $("#rdrrPmWrap .currency").each(function () {
3020
            var elem = $(this);
3021
            var n = parseInt(elem.text().replace(/[^\d.-]/g, ""), 10);
3022
            if (!isNaN(n)) elem.text(numberToIndianCurrency(n));
3023
          });
3024
        },
3025
        error: function () {
3026
          $("#rdrrPmWrap").html('<div class="empty">Failed to load purchase-milestones data.</div>');
3027
        }
3028
      });
3029
    }
3030
 
3031
    function numberToIndianCurrency(n) {
3032
      if (n === 0) return "0";
3033
      var s = n.toString();
3034
      var lastThree = s.substring(s.length - 3);
3035
      var other = s.substring(0, s.length - 3);
3036
      if (other !== "") lastThree = "," + lastThree;
3037
      return other.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
3038
    }
3039
 
3040
    $("#rdrrPmCategory").on("change", loadPurchaseMilestones);
3041
 
3042
    // ------------------------- RBM Performance Dashboard (MTD) -------------------------
3043
    // No dedicated backend endpoint exists β€” the perf-dashboard table is only rendered
3044
    // inline in /indent/today_po_rbm. We fetch that page and extract just the table.
3045
    // Trade-off: heavier request (server re-runs full page prep). Consider adding a
3046
    // /rbm-drr/performance fragment endpoint later if this becomes a hot path.
3047
    function loadPerformanceDashboard() {
3048
      $("#rdrrPerfWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
3049
      $.ajax({
3050
        url: "/indent/today_po_rbm",
3051
        type: "GET",
3052
        dataType: "html",
3053
        success: function (fullHtml) {
3054
          var doc = new DOMParser().parseFromString(fullHtml, "text/html");
3055
          var tbl = doc.querySelector("#performance-dashboard-table");
3056
          if (!tbl) {
3057
            $("#rdrrPerfWrap").html('<div class="empty"><div class="ei">πŸ“Š</div>No performance dashboard data available yet.</div>');
3058
            return;
3059
          }
3060
          // Fix any relative image paths (e.g. king.png / trophy-cup.png) to be root-relative.
3061
          tbl.querySelectorAll("img").forEach(function (im) {
3062
            var src = im.getAttribute("src") || "";
3063
            if (src.indexOf("resources/") !== -1 && src.charAt(0) !== "/") {
3064
              im.setAttribute("src", "/" + src.replace(/^\.\.\/+/, ""));
3065
            }
3066
          });
3067
          $("#rdrrPerfWrap").empty().append(tbl);
3068
        },
3069
        error: function () {
3070
          $("#rdrrPerfWrap").html('<div class="empty">Failed to load performance dashboard.</div>');
3071
        }
3072
      });
3073
    }
3074
 
37469 ranu 3075
    // ------------------------- RBM Call Target iframe -------------------------
3076
    // The /indent/rbm_call_target endpoint returns a Velocity FRAGMENT (no <html>,
3077
    // no Bootstrap/jQuery). When loaded directly in an iframe, Bootstrap modals
3078
    // collapse and their inner Loading… contents render inline. Fix: fetch the
3079
    // fragment, wrap it in a self-contained document that loads jQuery + Popper +
3080
    // Bootstrap, then hand it to the iframe via srcdoc. Zero backend change.
3081
    function loadCallTargetIframe() {
3082
      $.ajax({
3083
        url: "/indent/rbm_call_target",
3084
        type: "GET",
3085
        dataType: "html",
3086
        success: function (fragment) {
3087
          var doc = [
3088
            '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">',
3089
            '<meta name="viewport" content="width=device-width,initial-scale=1">',
3090
            '<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">',
3091
            '<style>body{margin:0;padding:16px;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:#fff}</style>',
3092
            '</head><body>',
3093
            fragment,
3094
            '<script src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></' + 'script>',
3095
            '<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></' + 'script>',
3096
            '<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></' + 'script>',
3097
            '</body></html>'
3098
          ].join("");
3099
          var frame = document.getElementById("rdrrCallFrame");
3100
          frame.onload = function () {
3101
            hookCallTargetDrawer(frame);
3102
          };
3103
          frame.srcdoc = doc;
3104
        },
3105
        error: function () {
3106
          document.getElementById("rdrrCallFrame").srcdoc =
3107
                  '<div style="padding:24px;font-family:system-ui;color:#97a1b5">Failed to load call-target view.</div>';
3108
        }
3109
      });
3110
    }
3111
 
3112
    // Redirect the iframe's Bootstrap-modal drill-downs into a slide-in parent drawer
3113
    // that matches the dashboard style. srcdoc iframes inherit the parent origin so
3114
    // we can freely reach into the iframe's window and override its functions.
3115
    function hookCallTargetDrawer(frame) {
3116
      var iw = frame.contentWindow;
3117
      if (!iw) return;
3118
      // Give the source's own <script> a moment to run and define the functions.
3119
      setTimeout(function () {
3120
        try {
3121
          iw.showCalledPartnerDetails = function (authId, rbmName) {
3122
            openCallTargetDrawer("called", authId, rbmName, iw.pageQueryDate);
3123
          };
3124
          iw.showOutOfSequenceDetails = function (authId, rbmName) {
3125
            openCallTargetDrawer("oos", authId, rbmName, iw.pageQueryDate);
3126
          };
3127
        } catch (e) {
3128
          // If cross-origin ever kicks in (shouldn't with srcdoc same-origin),
3129
          // fall back to the iframe's native Bootstrap modal β€” no crash.
3130
        }
3131
      }, 50);
3132
    }
3133
 
3134
    function openCallTargetDrawer(kind, authId, rbmName, dateStr) {
3135
      var titleWho = rbmName + (dateStr ? " (" + dateStr + ")" : "");
3136
      var title = (kind === "oos" ? "Out of Sequence Calls β€” " : "Called Partners β€” ") + titleWho;
3137
      $("#rdrrCallDrawerTitle").text(title);
3138
      $("#rdrrCallDrawerDesc").text(kind === "oos"
3139
              ? "Calls placed outside the recommended sequence."
3140
              : "All calls made by this RBM today, with recordings.");
3141
      $("#rdrrCallDrawerBody").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
3142
      $("#rdrrCallDrawerBack").addClass("show");
3143
 
3144
      var url;
3145
      if (kind === "oos") {
3146
        url = "/indent/rbm_call_target/oos_details?authId=" + encodeURIComponent(authId);
3147
      } else {
3148
        var dp = dateStr ? "&date=" + encodeURIComponent(dateStr) : "";
3149
        url = "/indent/rbm_call_target/called_details?authId=" + encodeURIComponent(authId)
3150
                + "&agentName=" + encodeURIComponent(rbmName) + dp;
3151
      }
3152
      $.ajax({
3153
        url: url, type: "GET", dataType: "json",
3154
        success: function (data) {
3155
          if (!data || data.length === 0) {
3156
            $("#rdrrCallDrawerBody").html('<div class="empty"><div class="ei">πŸ“­</div>No entries.</div>');
3157
            return;
3158
          }
3159
          $("#rdrrCallDrawerBody").html(kind === "oos" ? renderOosTable(data) : renderCalledTable(data));
3160
        },
3161
        error: function () {
3162
          $("#rdrrCallDrawerBody").html('<div class="empty">Failed to load details.</div>');
3163
        }
3164
      });
3165
    }
3166
 
3167
    function renderOosTable(data) {
3168
      var html = '<table><thead><tr><th>S.No</th><th>Party Name</th><th>Code</th><th>Time</th></tr></thead><tbody>';
3169
      data.forEach(function (r, i) {
3170
        html += '<tr><td>' + (i + 1) + '</td><td>' + escapeHtml(r.partyName || "-") +
3171
                '</td><td>' + escapeHtml(r.code || "-") + '</td><td>' + escapeHtml(r.time || "-") + '</td></tr>';
3172
      });
3173
      return html + '</tbody></table>';
3174
    }
3175
 
3176
    function renderCalledTable(data) {
3177
      var html = '<table><thead><tr>' +
3178
              '<th>S.No</th><th>Party Name</th><th>Code</th><th>Remark</th>' +
3179
              '<th>Call Status</th><th>Duration</th><th>Date/Time</th><th>Recording</th>' +
3180
              '</tr></thead><tbody>';
3181
      data.forEach(function (r, i) {
3182
        var rowStyle = "";
3183
        var recording = "-";
3184
        if (r.breakLog) {
3185
          var status = (r.breakStatus || "").toLowerCase();
3186
          if (status.indexOf("available") >= 0) rowStyle = 'style="background:#fdecec;color:#721c24"';
3187
          else if (status.indexOf("trying") >= 0) rowStyle = 'style="background:#fff5d6;color:#856404"';
3188
          else if (status.indexOf("logged out") >= 0 || status.indexOf("logout") >= 0) rowStyle = 'style="background:#eef0f4;color:#383d41"';
3189
          else if (status.indexOf("break") >= 0) rowStyle = 'style="background:#ffe5cc;color:#c45200"';
3190
        }
3191
        if (r.recordingUrl) {
3192
          recording = '<audio controls preload="none" src="' + escapeHtml(r.recordingUrl) + '"></audio>';
3193
        }
3194
        html += '<tr ' + rowStyle + '>' +
3195
                '<td>' + (i + 1) + '</td>' +
3196
                '<td>' + escapeHtml(r.partyName || (r.breakLog ? (r.breakStatus || "-") : "-")) + '</td>' +
3197
                '<td>' + escapeHtml(r.code || "-") + '</td>' +
3198
                '<td>' + escapeHtml(r.remark || "-") + '</td>' +
3199
                '<td>' + escapeHtml(r.callStatus || "-") + '</td>' +
3200
                '<td>' + escapeHtml(r.callDuration || "-") + '</td>' +
3201
                '<td>' + escapeHtml(r.callDateTime || "-") + '</td>' +
3202
                '<td>' + recording + '</td>' +
3203
                '</tr>';
3204
      });
3205
      return html + '</tbody></table>';
3206
    }
3207
 
3208
    $("#rdrrCallDrawerClose").on("click", function () {
3209
      $("#rdrrCallDrawerBack").removeClass("show");
3210
    });
3211
    $("#rdrrCallDrawerBack").on("click", function (e) {
3212
      if (e.target === this) $(this).removeClass("show");
3213
    });
3214
 
37487 ranu 3215
    // RBM filter β€” re-render KPIs + grid from the cached payload (no re-fetch).
3216
    $("#rdrrRbmFilter").on("change", function () {
3217
      CURRENT_FILTER_AUTH_ID = $(this).val() || "";
3218
      renderFiltered();
3219
    });
3220
 
37444 ranu 3221
    // initial load
3222
    load();
37468 ranu 3223
    loadPurchaseMilestones();
3224
    loadPerformanceDashboard();
37469 ranu 3225
    loadCallTargetIframe();
37444 ranu 3226
  })();
3227
</script>
3228
</body>
3229
</html>