Subversion Repositories SmartDukaan

Rev

Rev 37582 | Rev 37584 | 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 {
37523 ranu 54
      max-width: none;
37444 ranu 55
      margin: 0 auto;
37523 ranu 56
      padding: 22px 20px 100px
37444 ranu 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
 
37522 ranu 1893
    /* purchase-milestones (brand × person) — compact heatmap grid, custom-rendered client-side */
37468 ranu 1894
    #rdrrPmWrap {
37522 ranu 1895
      overflow: hidden
37468 ranu 1896
    }
1897
 
37522 ranu 1898
    #rdrrPmWrap .pm-grid-wrap {
37561 ranu 1899
      overflow: auto;
1900
      max-height: 720px;
37522 ranu 1901
      border: 1px solid var(--line);
1902
      border-radius: 10px;
1903
      background: #fff
1904
    }
1905
 
1906
    #rdrrPmWrap .pm-grid {
37468 ranu 1907
      border-collapse: separate;
1908
      border-spacing: 0;
37561 ranu 1909
      font-size: 13px;
37468 ranu 1910
      background: #fff
1911
    }
1912
 
37522 ranu 1913
    /* --- header (brand strip) --- */
1914
    #rdrrPmWrap .pm-grid thead th {
37561 ranu 1915
      position: sticky;
1916
      top: 0;
1917
      z-index: 3;
1918
      padding: 10px 14px;
1919
      min-width: 140px;
37522 ranu 1920
      color: #fff;
1921
      font-weight: 700;
37523 ranu 1922
      letter-spacing: .05em;
37561 ranu 1923
      font-size: 11px;
37522 ranu 1924
      text-transform: uppercase;
1925
      text-align: center;
1926
      white-space: nowrap;
1927
      background: linear-gradient(180deg, var(--brand2), var(--brand));
37523 ranu 1928
      border-bottom: 2px solid rgba(0, 0, 0, .08)
37522 ranu 1929
    }
1930
 
1931
    #rdrrPmWrap .pm-grid thead th.pm-corner {
37561 ranu 1932
      position: sticky;
1933
      left: 0;
1934
      z-index: 5;
1935
      min-width: 170px;
37522 ranu 1936
      background: #fff;
37468 ranu 1937
      color: var(--ink);
37522 ranu 1938
      text-align: left;
1939
      border-right: 1px solid var(--line);
37561 ranu 1940
      padding: 10px 14px
37468 ranu 1941
    }
1942
 
37522 ranu 1943
    #rdrrPmWrap .pm-corner-lbl {
37523 ranu 1944
      font-size: 11.5px;
37522 ranu 1945
      font-weight: 700;
1946
      letter-spacing: .05em;
1947
      color: var(--ink)
1948
    }
1949
 
1950
    #rdrrPmWrap .pm-corner-hint {
37523 ranu 1951
      font-size: 10px;
37522 ranu 1952
      color: var(--soft);
1953
      font-weight: 500;
1954
      letter-spacing: .02em;
1955
      text-transform: none;
37523 ranu 1956
      margin-top: 1px
37522 ranu 1957
    }
1958
 
37523 ranu 1959
    /* --- name column --- */
37522 ranu 1960
    #rdrrPmWrap .pm-name {
37561 ranu 1961
      position: sticky;
1962
      left: 0;
1963
      z-index: 2;
37468 ranu 1964
      background: #fff;
37576 ranu 1965
      padding: 7px 5px;
37522 ranu 1966
      border-right: 1px solid var(--line);
1967
      vertical-align: middle
37468 ranu 1968
    }
1969
 
37522 ranu 1970
    #rdrrPmWrap .pm-name-txt {
1971
      font-weight: 650;
37576 ranu 1972
      font-size: 16px;
37522 ranu 1973
      color: var(--ink);
1974
      line-height: 1.2;
1975
      white-space: nowrap;
1976
      overflow: hidden;
1977
      text-overflow: ellipsis
1978
    }
1979
 
1980
    #rdrrPmWrap .pm-name-sub {
37523 ranu 1981
      font-size: 9.5px;
37468 ranu 1982
      color: var(--soft);
37523 ranu 1983
      margin-top: 1px;
37522 ranu 1984
      letter-spacing: .04em;
1985
      text-transform: uppercase;
1986
      font-weight: 600
1987
    }
1988
 
1989
    /* --- data cells --- */
1990
    #rdrrPmWrap .pm-cell {
37576 ranu 1991
      padding: 5px 7px;
37522 ranu 1992
      text-align: right;
1993
      vertical-align: middle;
1994
      font-variant-numeric: tabular-nums;
37561 ranu 1995
      color: var(--ink)
37522 ranu 1996
    }
1997
 
1998
    #rdrrPmWrap .pm-cell-zero {
1999
      color: #cbd0d9;
37570 ranu 2000
      font-size: 17px;
37523 ranu 2001
      font-weight: 500;
2002
      text-align: center
37522 ranu 2003
    }
2004
 
37570 ranu 2005
    /* Stacked cell content: partner count on top, PO in middle, Billed at bottom (primary) */
2006
    #rdrrPmWrap .pm-partners {
2007
      font-size: 12px;
37573 ranu 2008
      font-weight: 700;
37582 ranu 2009
      color: #000;
37573 ranu 2010
      line-height: 1.2;
37570 ranu 2011
      margin-bottom: 4px;
37523 ranu 2012
      white-space: nowrap
37468 ranu 2013
    }
2014
 
37570 ranu 2015
    #rdrrPmWrap .pm-po {
37573 ranu 2016
      font-size: 14px;
2017
      font-weight: 600;
37582 ranu 2018
      color: #000;
37573 ranu 2019
      line-height: 1.2;
37570 ranu 2020
      margin-bottom: 4px;
37561 ranu 2021
      white-space: nowrap
37468 ranu 2022
    }
2023
 
37570 ranu 2024
    #rdrrPmWrap .pm-billed {
2025
      font-weight: 800;
37576 ranu 2026
      font-size: 16px;
37570 ranu 2027
      line-height: 1.2;
2028
      color: var(--ink);
2029
      white-space: nowrap
37468 ranu 2030
    }
2031
 
37570 ranu 2032
    #rdrrPmWrap .pm-tag {
37576 ranu 2033
      font-size: 12px;
37570 ranu 2034
      font-weight: 500;
37573 ranu 2035
      opacity: .6;
37570 ranu 2036
      margin-left: 2px;
37573 ranu 2037
      letter-spacing: .02em;
37582 ranu 2038
      color: #000;
37523 ranu 2039
    }
2040
 
2041
    /* --- row hover --- */
2042
    #rdrrPmWrap .pm-grid tbody tr.pm-row + tr.pm-row td {
2043
      border-top: 1px solid var(--line2)
37468 ranu 2044
    }
2045
 
37523 ranu 2046
    #rdrrPmWrap .pm-grid tbody tr.pm-row:hover .pm-name {
2047
      background: #eef2fb
2048
    }
2049
 
37522 ranu 2050
    /* --- totals row (pinned at top, distinct) --- */
2051
    #rdrrPmWrap .pm-total-row .pm-name {
2052
      background: linear-gradient(180deg, #f2f5fb, #eaeff9);
2053
      border-right: 1px solid var(--line);
2054
      border-bottom: 2px solid var(--brand)
37468 ranu 2055
    }
2056
 
37522 ranu 2057
    #rdrrPmWrap .pm-total-row .pm-name-txt {
2058
      color: var(--brand);
2059
      font-weight: 800
37468 ranu 2060
    }
2061
 
37522 ranu 2062
    #rdrrPmWrap .pm-total-row .pm-name-sub {
2063
      color: var(--brand);
2064
      opacity: .8
37468 ranu 2065
    }
2066
 
37522 ranu 2067
    #rdrrPmWrap .pm-cell-total {
2068
      background: linear-gradient(180deg, #f2f5fb, #eaeff9) !important;
2069
      border-bottom: 2px solid var(--brand)
2070
    }
2071
 
2072
    #rdrrPmWrap .pm-cell-total .pm-billed {
2073
      color: var(--brand);
2074
      font-weight: 800;
37523 ranu 2075
      font-size: 13px
37522 ranu 2076
    }
2077
 
2078
    /* --- brand accent header gradients (slug matches JS output) --- */
2079
    #rdrrPmWrap .pm-grid thead th.total {
2080
      background: linear-gradient(180deg, #3b5bdb, #28449e)
2081
    }
2082
 
2083
    #rdrrPmWrap .pm-grid thead th.vivo {
37468 ranu 2084
      background: linear-gradient(180deg, #00baf2, #0a8fb5)
2085
    }
2086
 
37522 ranu 2087
    #rdrrPmWrap .pm-grid thead th.oppo {
37468 ranu 2088
      background: linear-gradient(180deg, #20a558, #177a3a)
2089
    }
2090
 
37522 ranu 2091
    #rdrrPmWrap .pm-grid thead th.samsung {
37468 ranu 2092
      background: linear-gradient(180deg, #0b3d91, #071e51)
2093
    }
2094
 
37522 ranu 2095
    #rdrrPmWrap .pm-grid thead th.alcatel {
37468 ranu 2096
      background: linear-gradient(180deg, #5c7cfa, #3b5bdb)
2097
    }
2098
 
37522 ranu 2099
    #rdrrPmWrap .pm-grid thead th.motorola {
37468 ranu 2100
      background: linear-gradient(180deg, #495057, #212529)
2101
    }
2102
 
37522 ranu 2103
    #rdrrPmWrap .pm-grid thead th.hmd {
37468 ranu 2104
      background: linear-gradient(180deg, #7048e8, #5b34c9)
2105
    }
2106
 
37522 ranu 2107
    #rdrrPmWrap .pm-grid thead th.xiaomi {
37468 ranu 2108
      background: linear-gradient(180deg, #ffa726, #e8590c)
2109
    }
2110
 
37522 ranu 2111
    #rdrrPmWrap .pm-grid thead th.lava {
37468 ranu 2112
      background: linear-gradient(180deg, #e03131, #a11515)
2113
    }
2114
 
37522 ranu 2115
    #rdrrPmWrap .pm-grid thead th.poco {
37468 ranu 2116
      background: linear-gradient(180deg, #ffd43b, #e8ac00);
2117
      color: #3a2500
2118
    }
2119
 
37522 ranu 2120
    #rdrrPmWrap .pm-grid thead th.realme {
37468 ranu 2121
      background: linear-gradient(180deg, #f59f00, #e8590c)
2122
    }
2123
 
37522 ranu 2124
    #rdrrPmWrap .pm-grid thead th.apple {
37468 ranu 2125
      background: linear-gradient(180deg, #495057, #141a2b)
2126
    }
2127
 
37522 ranu 2128
    #rdrrPmWrap .pm-grid thead th.oneplus {
37468 ranu 2129
      background: linear-gradient(180deg, #e03131, #a11515)
2130
    }
2131
 
37522 ranu 2132
    #rdrrPmWrap .pm-grid thead th.tecno {
37468 ranu 2133
      background: linear-gradient(180deg, #0ca678, #087a56)
2134
    }
2135
 
37444 ranu 2136
    @media (max-width: 960px) {
2137
      .kpis {
2138
        grid-template-columns:repeat(2, 1fr)
2139
      }
2140
 
2141
      .brand h1 {
2142
        font-size: 22px
2143
      }
2144
 
2145
      .status-grid {
2146
        grid-template-columns:1fr
2147
      }
2148
    }
2149
  </style>
2150
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css"/>
2151
</head>
2152
<body>
2153
<div class="wrap">
2154
  <header class="top">
2155
    <div class="brand">
2156
      <div class="crumb"><a href="/indent/today_po_rbm">&larr; Today PO / RBM</a> &middot; Sales &middot; Indent</div>
2157
      <h1>RBM DRR Dashboard <span class="live"><i></i>Live</span></h1>
2158
    </div>
2159
    <div class="hd-right">
37497 ranu 2160
      <select id="rdrrTypeSelect" class="ctl" style="min-width:120px;height:38px;padding:8px 12px" title="Filter type">
2161
        <option value="RBM" selected>RBM</option>
2162
        <option value="SALES">Sales</option>
2163
      </select>
2164
      <select id="rdrrLevelSelect" class="ctl" style="min-width:140px;height:38px;padding:8px 12px;display:none"
2165
              title="Sales level">
2166
        <option value="">Select level</option>
2167
        <option value="ASM">ASM (L1)</option>
2168
        <option value="CM">CM (L2)</option>
2169
        <option value="DM">DM (L3)</option>
2170
        <option value="BM">BM (L4)</option>
2171
        <option value="RSM">RSM (L5)</option>
2172
        <option value="NSM">NSM (L6)</option>
2173
      </select>
2174
      <select id="rdrrPersonSelect" class="ctl" style="min-width:230px;height:38px;padding:8px 12px" title="Person">
37487 ranu 2175
        <option value="">All RBMs</option>
2176
      </select>
37444 ranu 2177
      <input class="ctl" id="rdrrPeriod" type="text" placeholder="Select date range"/>
2178
      <button class="btn-r" id="rdrrApply">Apply</button>
2179
    </div>
2180
  </header>
2181
 
2182
  <div class="kpis">
2183
    <div class="kpi a">
2184
      <div class="top">
2185
        <div class="ic">
2186
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
2187
               stroke-linejoin="round">
2188
            <path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>
2189
          </svg>
2190
        </div>
2191
        <div class="label">Total Achieved</div>
2192
      </div>
2193
      <div class="val" id="rdrrKpiAch">&mdash;</div>
2194
      <div class="foot" id="rdrrKpiAchSub">Actual billed across all RBMs</div>
2195
    </div>
2196
    <div class="kpi b">
2197
      <div class="top">
2198
        <div class="ic">
2199
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
2200
               stroke-linejoin="round">
2201
            <circle cx="12" cy="12" r="9"/>
2202
            <circle cx="12" cy="12" r="5"/>
2203
            <circle cx="12" cy="12" r="1.5" fill="currentColor"/>
2204
          </svg>
2205
        </div>
2206
        <div class="label">Total Target</div>
2207
      </div>
2208
      <div class="val" id="rdrrKpiTgt">&mdash;</div>
2209
      <div class="foot" id="rdrrKpiTgtSub">Sum of daily target snapshots</div>
2210
    </div>
2211
    <div class="kpi c">
2212
      <div class="top">
2213
        <div class="ic">
2214
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"
2215
               stroke-linejoin="round">
2216
            <path d="M3 17l6-6 4 4 8-8"/>
2217
            <path d="M17 7h4v4"/>
2218
          </svg>
2219
        </div>
2220
        <div class="label">Achievement %</div>
2221
      </div>
2222
      <div class="val" id="rdrrKpiPct">&mdash;</div>
2223
      <div class="foot" id="rdrrKpiPctSub">Total ACH / Total TGT</div>
2224
    </div>
2225
    <div class="kpi d clickable" id="rdrrKpiTopCard" title="Click to see achieved vs pending RBMs">
2226
      <div class="top">
2227
        <div class="ic">
2228
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"
2229
               stroke-linejoin="round">
2230
            <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"/>
2231
          </svg>
2232
        </div>
2233
        <div class="label">RBMs ≥ 100% Target</div>
2234
      </div>
2235
      <div class="val" id="rdrrKpiTop">&mdash;</div>
2236
      <div class="foot" id="rdrrKpiTopSub">Rows meeting or beating target</div>
2237
      <span class="hint">Click for list &rsaquo;</span>
2238
    </div>
2239
  </div>
2240
 
2241
  <div class="sectionlabel">RBM &times; Warehouse &times; Movement Bucket</div>
2242
  <div class="legend">
2243
    <span class="lg hid"><i></i><span class="lgt">HID</span></span>
2244
    <span class="lg fast"><i></i><span class="lgt">FAST</span></span>
2245
    <span class="lg run"><i></i><span class="lgt">RUN</span></span>
2246
    <span class="lg slow"><i></i><span class="lgt">SLOW</span></span>
2247
    <span class="lg other"><i></i><span class="lgt">OTHER</span></span>
2248
  </div>
2249
  <div class="card">
2250
    <div class="card-hd">
2251
      <div>
2252
        <h2>Achievement vs Target</h2>
2253
        <p class="desc">Click any row for a per-bucket breakdown and the catalogs sold.</p>
2254
      </div>
2255
      <span class="badge-period" id="rdrrPeriodLabel">&mdash;</span>
2256
    </div>
2257
    <div id="rdrrTableWrap">
2258
      <div class="loading">
2259
        <div class="spinner"></div>
2260
        Loading&hellip;
2261
      </div>
2262
    </div>
2263
    <div class="foot-note">
2264
      <b>TGT</b> is summed from persisted per-day snapshots (<code>inventory.rbm_targets</code>) — days with no
2265
      scheduler-written snapshot contribute 0.
2266
      <b>ACH</b> is computed from source orders (<code>transaction.order</code>) for the range.
2267
    </div>
2268
  </div>
37460 ranu 2269
 
2270
  <!-- >15 Days Aging Sold -->
2271
  <div class="sectionlabel">&gt; 15 Days Aging Sold</div>
2272
  <div class="card">
2273
    <div class="card-hd">
2274
      <div>
2275
        <h2>Aging Inventory Cleared</h2>
2276
        <p class="desc">Billed value of items that were &gt; 15 days old at sale, per RBM, for the picked range.</p>
2277
      </div>
2278
      <span class="badge-period" id="rdrrAgingPeriod">&mdash;</span>
2279
    </div>
2280
    <div id="rdrrAgingWrap">
2281
      <div class="loading">
2282
        <div class="spinner"></div>
2283
        Loading&hellip;
2284
      </div>
2285
    </div>
2286
  </div>
2287
 
2288
  <!-- Partner Billing Count -->
2289
  <div class="sectionlabel">Partner Billing Count <span
2290
          style="color:var(--soft);font-weight:600;text-transform:none;letter-spacing:0;margin-left:6px">(Target: &gt;1L, Non-Target: &gt;20K)</span>
2291
  </div>
2292
  <div class="card">
2293
    <div class="card-hd">
2294
      <div>
2295
        <h2>Partners Who Billed This Month</h2>
2296
        <p class="desc">Counts partners meeting the billing threshold in each week bucket. Always month-to-date (weekly
2297
          buckets are inherently monthly).</p>
2298
      </div>
2299
      <span class="badge-period" id="rdrrBillingPeriod">&mdash;</span>
2300
    </div>
2301
    <div id="rdrrBillingWrap">
2302
      <div class="loading">
2303
        <div class="spinner"></div>
2304
        Loading&hellip;
2305
      </div>
2306
    </div>
2307
  </div>
37468 ranu 2308
 
2309
  <!-- RBM Performance Dashboard (MTD) — extracted from /indent/today_po_rbm without any backend change -->
2310
  <div class="sectionlabel">RBM Performance Dashboard (MTD)</div>
2311
  <div class="card">
2312
    <div class="card-hd">
2313
      <div>
2314
        <h2>Composite MTD Ranking</h2>
2315
        <p class="desc">Rank of RBMs by weighted score across Talk Time (10%) + MTD Achievement (55%) + Aging (2%) +
2316
          &gt;1L Partners (29%) + Rating (2%) + Partners Rated (2%).</p>
2317
      </div>
2318
      <span class="badge-period" id="rdrrPerfMonth">MTD</span>
2319
    </div>
2320
    <div id="rdrrPerfWrap">
2321
      <div class="loading">
2322
        <div class="spinner"></div>
2323
        Loading&hellip;
2324
      </div>
2325
    </div>
2326
  </div>
2327
 
2328
  <!-- Today PO & Billed — Brand × RBM matrix (reuses /indent/today_po_table_fragment) -->
2329
  <div class="sectionlabel">Today PO &amp; Billed — Brand &times; RBM</div>
2330
  <div class="card">
2331
    <div class="card-hd">
2332
      <div>
2333
        <h2>Purchase Milestones by Brand</h2>
2334
        <p class="desc">Today's PO value / partner count / total billed, per RBM &times; brand. Always today
2335
          (independent of the range picker above).</p>
2336
      </div>
2337
      <select id="rdrrPmCategory" class="ctl" style="min-width:170px;height:34px;padding:6px 12px">
2338
        <option value="RBM">All RBMs</option>
2339
        <option value="NSM">All NSMs</option>
2340
        <option value="RSM">All RSMs</option>
2341
        <option value="BM">All BMs</option>
2342
        <option value="DM">All DMs</option>
2343
        <option value="CM">All CMs</option>
2344
        <option value="ASM">All ASMs</option>
2345
      </select>
2346
    </div>
2347
    <div id="rdrrPmWrap">
2348
      <div class="loading">
2349
        <div class="spinner"></div>
2350
        Loading&hellip;
2351
      </div>
2352
    </div>
2353
  </div>
37469 ranu 2354
 
2355
  <!-- RBM Call Target Summary — full interactive page injected via iframe srcdoc (no backend change) -->
2356
  <div class="sectionlabel">RBM Call Target Summary</div>
2357
  <div class="card">
2358
    <div class="card-hd">
2359
      <div>
2360
        <h2>Today's Call Coverage per RBM</h2>
2361
        <p class="desc">Full interactive view — all popups, drill-downs and downloads work exactly like the standalone
2362
          page.</p>
2363
      </div>
2364
      <a class="badge-period" href="/indent/rbm_call_target" target="_blank" style="text-decoration:none">Open in new
2365
        tab &rsaquo;</a>
2366
    </div>
2367
    <iframe id="rdrrCallFrame" title="RBM Call Target Summary"
2368
            style="width:100%;min-height:800px;border:0;border-radius:10px;background:#fff;display:block"></iframe>
2369
  </div>
37444 ranu 2370
</div>
2371
 
2372
<!-- achieved-vs-pending modal (opens from the RBMs ≥ 100% Target KPI card) -->
2373
<div class="status-back" id="rdrrStatusBack">
2374
  <div class="status-modal">
2375
    <button class="x" id="rdrrStatusClose" aria-label="Close">&times;</button>
2376
    <h3>Target Status by RBM</h3>
2377
    <p class="desc" id="rdrrStatusDesc">&mdash;</p>
2378
    <div class="status-grid">
2379
      <div class="status-col good">
2380
        <h4>✅ Achieved <span class="cnt" id="rdrrStatusAchCnt">0</span></h4>
2381
        <div class="status-list" id="rdrrStatusAchList"></div>
2382
      </div>
2383
      <div class="status-col bad">
2384
        <h4>⚠ Pending <span class="cnt" id="rdrrStatusPndCnt">0</span></h4>
2385
        <div class="status-list" id="rdrrStatusPndList"></div>
2386
      </div>
2387
    </div>
2388
  </div>
2389
</div>
2390
 
37469 ranu 2391
<!-- call-target drill-down drawer (Called Partners / OOS Calls) -->
2392
<div class="rdrr-back" id="rdrrCallDrawerBack">
2393
  <div class="rdrr-panel">
2394
    <button class="x" id="rdrrCallDrawerClose" aria-label="Close">&times;</button>
2395
    <h3 id="rdrrCallDrawerTitle">&mdash;</h3>
2396
    <p class="desc" id="rdrrCallDrawerDesc">&mdash;</p>
2397
    <div id="rdrrCallDrawerBody">
2398
      <div class="loading">
2399
        <div class="spinner"></div>
2400
        Loading&hellip;
2401
      </div>
2402
    </div>
2403
  </div>
2404
</div>
2405
 
37444 ranu 2406
<!-- drill-down panel -->
2407
<div class="rdrr-back" id="rdrrBack">
2408
  <div class="rdrr-panel">
2409
    <button class="x" id="rdrrClose" aria-label="Close">&times;</button>
2410
    <h3 id="rdrrDdTitle">&mdash;</h3>
2411
    <p class="desc" id="rdrrDdDesc">&mdash;</p>
2412
 
2413
    <div class="rdrr-total">
2414
      <div>
2415
        <div class="k">Achieved</div>
2416
        <div class="v" id="rdrrDdAch">&mdash;</div>
2417
      </div>
2418
      <div>
2419
        <div class="k">Target</div>
2420
        <div class="v" id="rdrrDdTgt">&mdash;</div>
2421
      </div>
2422
      <div>
2423
        <div class="k">Achievement</div>
2424
        <div class="v" id="rdrrDdPct">&mdash;</div>
2425
      </div>
2426
    </div>
2427
 
2428
    <div class="sectionlabel" style="margin-top:2px">Movement Split — Achievement vs Target</div>
2429
    <div class="bbars" id="rdrrDdBars"></div>
2430
 
37487 ranu 2431
    <div class="sectionlabel">Warehouse Flow — Buying vs Selling <span
2432
            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>
2433
    </div>
2434
    <div id="rdrrDdFlow">
2435
      <div class="loading">
2436
        <div class="spinner"></div>
2437
        Loading&hellip;
2438
      </div>
2439
    </div>
2440
 
37444 ranu 2441
    <div class="sectionlabel">Brand Mix — Share of Achievement <span
2442
            style="color:var(--soft);font-weight:600;text-transform:none;letter-spacing:0;margin-left:6px">(click a brand for movement split)</span>
2443
    </div>
2444
    <div id="rdrrDdBrands">
2445
      <div class="loading">
2446
        <div class="spinner"></div>
2447
        Loading brand mix&hellip;
2448
      </div>
2449
    </div>
2450
  </div>
2451
</div>
2452
 
2453
<script src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
2454
<script src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
2455
<script src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
2456
<script>
2457
  (function () {
2458
    var DEFAULT_START = "$defaultStartDate";
2459
    var DEFAULT_END = "$defaultEndDate";
2460
 
2461
    // Prefer query-string range if the caller provided one (e.g. from today_po_rbm's date picker).
2462
    var url = new URL(window.location.href);
2463
    var qsStart = url.searchParams.get("startDate");
2464
    var qsEnd = url.searchParams.get("endDate");
2465
    var startDate = qsStart || DEFAULT_START;
2466
    var endDate = qsEnd || DEFAULT_END;
2467
 
2468
    function fmtDate(s) {
2469
      return moment(s).format("DD MMM");
2470
    }
2471
 
2472
    function fmtLakh(v) {
2473
      v = Number(v) || 0;
2474
      return (v / 100000).toFixed(1) + "L";
2475
    }
2476
 
2477
    function pctClass(p) {
2478
      if (p >= 95) return "good";
2479
      if (p >= 41) return "warn";
2480
      return "bad";
2481
    }
2482
 
2483
    function pctLabel(ach, tgt) {
2484
      if (!tgt || tgt <= 0) return {text: "-", cls: "na", num: null};
2485
      var p = (ach / tgt) * 100;
2486
      return {text: p.toFixed(1) + "%", cls: pctClass(p), num: p};
2487
    }
2488
 
2489
    function pctBarWidth(ach, tgt) {
2490
      if (!tgt || tgt <= 0) return 0;
2491
      return Math.min(100, (ach / tgt) * 100);
2492
    }
2493
 
2494
    // Initialise the range picker.
2495
    $("#rdrrPeriod").daterangepicker({
2496
      startDate: moment(startDate),
2497
      endDate: moment(endDate),
2498
      locale: {format: "YYYY-MM-DD", cancelLabel: "Clear"}
2499
    });
2500
    $("#rdrrPeriod").on("apply.daterangepicker", function (ev, picker) {
2501
      startDate = picker.startDate.format("YYYY-MM-DD");
2502
      endDate = picker.endDate.format("YYYY-MM-DD");
2503
    });
2504
 
2505
    // Defensive: read the picker's current state at click time in case
2506
    // the apply.daterangepicker event was swallowed for any reason.
2507
    $("#rdrrApply").on("click", function () {
2508
      var p = $("#rdrrPeriod").data("daterangepicker");
2509
      if (p) {
2510
        startDate = p.startDate.format("YYYY-MM-DD");
2511
        endDate = p.endDate.format("YYYY-MM-DD");
2512
      }
2513
      load();
37517 ranu 2514
      // If a Sales role is currently active, re-fetch sales-data for the new range.
2515
      if (CURRENT_SALES_ROLE) {
37497 ranu 2516
        $.ajax({
2517
          url: "/rbm-drr/sales-data",
2518
          type: "GET",
2519
          data: {startDate: startDate, endDate: endDate},
2520
          dataType: "json",
2521
          success: function (payload) {
2522
            SALES_PAYLOAD = payload;
2523
            renderFiltered();
2524
          },
2525
          error: function () {
2526
            SALES_PAYLOAD = {rows: []};
2527
            renderFiltered();
2528
          }
2529
        });
2530
      }
37444 ranu 2531
    });
2532
 
2533
    function load() {
2534
      $("#rdrrTableWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
37460 ranu 2535
      $("#rdrrAgingWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
2536
      $("#rdrrBillingWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
37444 ranu 2537
      $("#rdrrPeriodLabel").text(fmtDate(startDate) + " – " + fmtDate(endDate));
37460 ranu 2538
      $("#rdrrAgingPeriod").text(fmtDate(startDate) + " – " + fmtDate(endDate));
37444 ranu 2539
      fetch("/rbm-drr/data?startDate=" + startDate + "&endDate=" + endDate, {credentials: "same-origin"})
2540
              .then(function (r) {
2541
                return r.json().then(function (b) {
2542
                  return {ok: r.ok, body: b};
2543
                });
2544
              })
2545
              .then(function (res) {
2546
                if (!res.ok) {
2547
                  $("#rdrrTableWrap").html('<div class="empty">' + escapeHtml(res.body && res.body.error ? res.body.error : "Failed to load.") + '</div>');
2548
                  return;
2549
                }
2550
                render(res.body);
2551
              })
2552
              .catch(function (e) {
2553
                $("#rdrrTableWrap").html('<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>');
2554
              });
37460 ranu 2555
 
2556
      fetch("/rbm-drr/extras?startDate=" + startDate + "&endDate=" + endDate, {credentials: "same-origin"})
2557
              .then(function (r) {
2558
                return r.json().then(function (b) {
2559
                  return {ok: r.ok, body: b};
2560
                });
2561
              })
2562
              .then(function (res) {
2563
                if (!res.ok) {
2564
                  var msg = '<div class="empty">' + escapeHtml(res.body && res.body.error ? res.body.error : "Failed to load.") + '</div>';
2565
                  $("#rdrrAgingWrap").html(msg);
2566
                  $("#rdrrBillingWrap").html(msg);
2567
                  return;
2568
                }
2569
                renderAging(res.body);
2570
                renderPartnerBilling(res.body);
2571
              })
2572
              .catch(function (e) {
2573
                var msg = '<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>';
2574
                $("#rdrrAgingWrap").html(msg);
2575
                $("#rdrrBillingWrap").html(msg);
2576
              });
37444 ranu 2577
    }
2578
 
37460 ranu 2579
    function renderAging(data) {
2580
      var rows = data.aging || [];
2581
      var totals = data.agingTotals || {};
2582
      var balance = data.balance || {};
2583
      if (rows.length === 0) {
2584
        $("#rdrrAgingWrap").html('<div class="empty"><div class="ei">📦</div>No aging inventory sold in this range.</div>');
2585
        return;
2586
      }
2587
      var html = ['<table class="xtable"><thead><tr>',
2588
        '<th>RBM</th>',
2589
        '<th class="num g-hid">HID</th>',
2590
        '<th class="num g-fast">FAST</th>',
2591
        '<th class="num g-run">RUN</th>',
2592
        '<th class="num g-slow">SLOW</th>',
2593
        '<th class="num g-other">OTHER</th>',
2594
        '<th class="num g-total">TOTAL</th>',
2595
        '</tr></thead><tbody>'];
2596
      rows.forEach(function (r) {
2597
        html.push('<tr>' +
2598
                '<td class="rbm-nm">' + escapeHtml(r.rbmName || '-') + '</td>' +
2599
                cell(r.hid, 'g-hid') + cell(r.fast, 'g-fast') + cell(r.run, 'g-run') +
2600
                cell(r.slow, 'g-slow') + cell(r.other, 'g-other') + cell(r.total, 'g-total') +
2601
                '</tr>');
2602
      });
2603
      html.push('<tr class="tot">' +
2604
              '<td>Total</td>' +
2605
              cell(totals.hid, 'g-hid') + cell(totals.fast, 'g-fast') + cell(totals.run, 'g-run') +
2606
              cell(totals.slow, 'g-slow') + cell(totals.other, 'g-other') + cell(totals.total, 'g-total') +
2607
              '</tr>');
2608
      html.push('<tr class="bal">' +
2609
              '<td class="hdr">15-Day Balance Value</td>' +
2610
              cell(balance.hid) + cell(balance.fast) + cell(balance.run) +
2611
              cell(balance.slow) + cell(balance.other) + cell(balance.total) +
2612
              '</tr>');
2613
      html.push('</tbody></table>');
2614
      $("#rdrrAgingWrap").html(html.join(""));
2615
    }
2616
 
2617
    function cell(v, cls) {
2618
      v = Number(v) || 0;
2619
      var zero = v === 0 ? ' zero' : '';
2620
      var extra = cls ? ' ' + cls : '';
2621
      return '<td class="num' + extra + zero + '">' + formatIndian(v) + '</td>';
2622
    }
2623
 
2624
    function formatIndian(n) {
2625
      n = Math.round(Number(n) || 0);
2626
      if (n === 0) return '0';
2627
      var s = n.toString();
2628
      var lastThree = s.substring(s.length - 3);
2629
      var otherNums = s.substring(0, s.length - 3);
2630
      if (otherNums !== '') lastThree = ',' + lastThree;
2631
      return otherNums.replace(/\B(?=(\d{2})+(?!\d))/g, ',') + lastThree;
2632
    }
2633
 
2634
    function renderPartnerBilling(data) {
2635
      var rows = data.partnerBilling || [];
2636
      var totals = data.partnerBillingTotals || {};
2637
      $("#rdrrBillingPeriod").text(data.partnerBillingMonth || '');
2638
      if (rows.length === 0) {
2639
        $("#rdrrBillingWrap").html('<div class="empty"><div class="ei">👥</div>No targeted partners this month.</div>');
2640
        return;
2641
      }
2642
      var html = ['<table class="xtable"><thead><tr>',
2643
        '<th>RBM</th>',
2644
        '<th class="num">Targeted</th>',
2645
        '<th class="num">Week 1<br><small style="color:var(--soft);font-weight:600">(1–7)</small></th>',
2646
        '<th class="num">Week 2<br><small style="color:var(--soft);font-weight:600">(8–15)</small></th>',
2647
        '<th class="num">Week 3<br><small style="color:var(--soft);font-weight:600">(16–22)</small></th>',
2648
        '<th class="num">Week 4<br><small style="color:var(--soft);font-weight:600">(23–end)</small></th>',
2649
        '<th class="num g-total">MTD</th>',
2650
        '<th class="num">Zero Billed<br><small style="color:var(--soft);font-weight:600">(&lt;1L / &lt;20K)</small></th>',
2651
        '</tr></thead><tbody>'];
2652
      rows.forEach(function (r) {
2653
        html.push('<tr>' +
2654
                '<td class="rbm-nm">' + escapeHtml(r.rbmName || '-') + '</td>' +
2655
                '<td class="num">' + pill(r.targeted, '') + '</td>' +
2656
                '<td class="num">' + pill(r.w1, ratio(r.w1, r.targeted)) + '</td>' +
2657
                '<td class="num">' + pill(r.w2, ratio(r.w2, r.targeted)) + '</td>' +
2658
                '<td class="num">' + pill(r.w3, ratio(r.w3, r.targeted)) + '</td>' +
2659
                '<td class="num">' + pill(r.w4, ratio(r.w4, r.targeted)) + '</td>' +
2660
                '<td class="num g-total">' + pill(r.mtd, ratio(r.mtd, r.targeted)) + '</td>' +
2661
                '<td class="num">' + pill(r.zero, r.zero > 0 ? 'warn' : 'zero') + '</td>' +
2662
                '</tr>');
2663
      });
2664
      html.push('<tr class="tot">' +
2665
              '<td>Total</td>' +
2666
              '<td class="num">' + formatIndian(totals.targeted) + '</td>' +
2667
              '<td class="num">' + formatIndian(totals.w1) + '</td>' +
2668
              '<td class="num">' + formatIndian(totals.w2) + '</td>' +
2669
              '<td class="num">' + formatIndian(totals.w3) + '</td>' +
2670
              '<td class="num">' + formatIndian(totals.w4) + '</td>' +
2671
              '<td class="num g-total">' + formatIndian(totals.mtd) + '</td>' +
2672
              '<td class="num">' + formatIndian(totals.zero) + '</td>' +
2673
              '</tr>');
2674
      html.push('</tbody></table>');
2675
      $("#rdrrBillingWrap").html(html.join(""));
2676
    }
2677
 
2678
    function pill(v, cls) {
2679
      v = Number(v) || 0;
2680
      var c = cls || (v === 0 ? 'zero' : '');
2681
      return '<span class="cnt-pill ' + c + '">' + formatIndian(v) + '</span>';
2682
    }
2683
 
2684
    function ratio(part, total) {
2685
      part = Number(part) || 0;
2686
      total = Number(total) || 0;
2687
      if (total === 0) return 'zero';
2688
      var p = (part / total) * 100;
2689
      if (p >= 60) return 'good';
2690
      if (p >= 30) return '';
2691
      if (p > 0) return 'warn';
2692
      return 'zero';
2693
    }
2694
 
37444 ranu 2695
    // Cached latest payload so the "Target Status by RBM" modal can render
2696
    // without a re-fetch when the KPI card is clicked.
2697
    var LAST_PAYLOAD = null;
37517 ranu 2698
    var SALES_PAYLOAD = null;              // fetched from /rbm-drr/sales-data when a Sales role is selected
2699
    var CURRENT_SALES_ROLE = null;         // "ASM" / "CM" / … — when set with SALES_PAYLOAD, we render Sales view
2700
    var CURRENT_SALES_AUTH_ID = null;      // when set, further narrows Sales view to this person
37497 ranu 2701
    // Set of RBM authIds allowed by the current filter. null = no filter (show all).
2702
    var CURRENT_FILTER_AUTH_IDS = null;
37444 ranu 2703
 
2704
    function render(data) {
2705
      LAST_PAYLOAD = data;
37487 ranu 2706
      renderFiltered();
2707
    }
37444 ranu 2708
 
37517 ranu 2709
    // Maps a sales-data row into the same shape the RBM grid renderer expects.
2710
    function normaliseSalesRow(r) {
2711
      return {
2712
        authId: r.salesAuthId, warehouseId: r.warehouseId,
2713
        rbmName: r.salesName + (r.role ? " (" + r.role + ")" : ""),
2714
        warehouseName: r.warehouseName,
2715
        totalAch: r.totalAch, totalTgt: r.totalTgt,
2716
        hidAch: r.hidAch, hidTgt: r.hidTgt,
2717
        fastAch: r.fastAch, fastTgt: r.fastTgt,
2718
        runAch: r.runAch, runTgt: r.runTgt,
2719
        slowAch: r.slowAch, slowTgt: r.slowTgt,
2720
        otherAch: r.otherAch, otherTgt: r.otherTgt
2721
      };
2722
    }
2723
 
37497 ranu 2724
    // Renders KPIs + grid from the appropriate payload:
37517 ranu 2725
    //  - Sales role active + payload loaded → filter SALES_PAYLOAD to that role (and optionally one person)
2726
    //  - RBM filter or no filter → LAST_PAYLOAD filtered by CURRENT_FILTER_AUTH_IDS
37487 ranu 2727
    function renderFiltered() {
37517 ranu 2728
      if (CURRENT_SALES_ROLE && SALES_PAYLOAD) {
37497 ranu 2729
        var salesRows = (SALES_PAYLOAD.rows || []).filter(function (r) {
37517 ranu 2730
          if (r.role !== CURRENT_SALES_ROLE) return false;
2731
          if (CURRENT_SALES_AUTH_ID && String(r.salesAuthId) !== String(CURRENT_SALES_AUTH_ID)) return false;
2732
          return true;
2733
        }).map(normaliseSalesRow);
37497 ranu 2734
        renderRowsAsGrid(salesRows, true);
2735
        return;
2736
      }
37487 ranu 2737
      if (!LAST_PAYLOAD) return;
2738
      var allRows = LAST_PAYLOAD.rows || [];
37497 ranu 2739
      var rows = CURRENT_FILTER_AUTH_IDS
37487 ranu 2740
              ? allRows.filter(function (r) {
37497 ranu 2741
                return CURRENT_FILTER_AUTH_IDS[String(r.authId)];
37487 ranu 2742
              })
2743
              : allRows;
37497 ranu 2744
      renderRowsAsGrid(rows, false);
2745
    }
37487 ranu 2746
 
37497 ranu 2747
    // Extracted from renderFiltered() so both RBM-source and Sales-source paths share it.
2748
    function renderRowsAsGrid(rows, isSalesView) {
2749
 
37487 ranu 2750
      // Recompute totals from the filtered subset. Cheaper + correct vs using server totals.
2751
      var t = {
2752
        totalAch: 0, totalTgt: 0, hidAch: 0, hidTgt: 0, fastAch: 0, fastTgt: 0,
2753
        runAch: 0, runTgt: 0, slowAch: 0, slowTgt: 0, otherAch: 0, otherTgt: 0,
2754
        rbmsAtOrAbove100: 0, rbmRowCount: rows.length
2755
      };
2756
      rows.forEach(function (r) {
2757
        t.totalAch += Number(r.totalAch) || 0;
2758
        t.totalTgt += Number(r.totalTgt) || 0;
2759
        t.hidAch += Number(r.hidAch) || 0;
2760
        t.hidTgt += Number(r.hidTgt) || 0;
2761
        t.fastAch += Number(r.fastAch) || 0;
2762
        t.fastTgt += Number(r.fastTgt) || 0;
2763
        t.runAch += Number(r.runAch) || 0;
2764
        t.runTgt += Number(r.runTgt) || 0;
2765
        t.slowAch += Number(r.slowAch) || 0;
2766
        t.slowTgt += Number(r.slowTgt) || 0;
2767
        t.otherAch += Number(r.otherAch) || 0;
2768
        t.otherTgt += Number(r.otherTgt) || 0;
2769
        if (r.totalTgt > 0 && r.totalAch >= r.totalTgt) t.rbmsAtOrAbove100++;
2770
      });
2771
 
37444 ranu 2772
      $("#rdrrKpiAch").html('&#8377;&nbsp;' + fmtLakh(t.totalAch));
2773
      $("#rdrrKpiTgt").html('&#8377;&nbsp;' + fmtLakh(t.totalTgt));
2774
      var pk = pctLabel(t.totalAch, t.totalTgt);
2775
      $("#rdrrKpiPct").html(pk.cls === "na" ? '<span class="u">n/a</span>' :
2776
              '<span class="pct ' + pk.cls + '">' + pk.text + '</span>');
2777
      $("#rdrrKpiTop").html((t.rbmsAtOrAbove100 || 0) + ' <span class="u">/ ' + (t.rbmRowCount || 0) + '</span>');
2778
 
2779
      if (rows.length === 0) {
37497 ranu 2780
        var emptyMsg;
2781
        if (isSalesView) {
2782
          emptyMsg = 'No Sales target/achievement rows for this person in the range. Has the pushSalesTargets cron run today?';
2783
        } else if (CURRENT_FILTER_AUTH_IDS) {
2784
          emptyMsg = 'No RBM rows in this range for the selected filter.';
2785
        } else {
2786
          emptyMsg = 'No RBM rows in this range.';
2787
        }
2788
        $("#rdrrTableWrap").html('<div class="empty"><div class="ei">📭</div>' + emptyMsg + '</div>');
37444 ranu 2789
        return;
2790
      }
2791
 
2792
      var buckets = [
2793
        {key: "hid", label: "HID"},
2794
        {key: "fast", label: "FAST"},
2795
        {key: "run", label: "RUN"},
2796
        {key: "slow", label: "SLOW"},
2797
        {key: "other", label: "OTHER"}
2798
      ];
2799
 
2800
      var html = ['<table id="rdrrGrid"><thead><tr>',
2801
        '<th>RBM &middot; Warehouse</th>',
2802
        '<th class="num g-total">Total<br><small style="color:var(--soft);font-weight:600">ACH / TGT</small></th>',
2803
        '<th class="num g-total">%</th>'];
2804
      buckets.forEach(function (b) {
2805
        html.push('<th class="num g-' + b.key + '">' + b.label + '<br><small style="color:var(--soft);font-weight:600">ACH / TGT</small></th>');
2806
        html.push('<th class="num g-' + b.key + '">%</th>');
2807
      });
2808
      html.push('<th></th></tr></thead><tbody>');
2809
 
2810
      rows.forEach(function (r) {
2811
        var tr = ['<tr class="clickable" data-authid="' + r.authId + '" data-warehouseid="' + r.warehouseId + '" data-rbmname="' + escapeHtml(r.rbmName) + '" data-warehousename="' + escapeHtml(r.warehouseName) + '">'];
2812
        tr.push('<td><div class="rbm-cell"><span class="rn">' + escapeHtml(r.rbmName) + '</span><span class="wh">' + escapeHtml(r.warehouseName) + '</span></div></td>');
2813
        tr.push(cellPair(r.totalAch, r.totalTgt));
2814
        buckets.forEach(function (b) {
2815
          tr.push(cellPair(r[b.key + "Ach"], r[b.key + "Tgt"]));
2816
        });
2817
        tr.push('<td class="chev">&rsaquo;</td>');
2818
        tr.push('</tr>');
2819
        html.push(tr.join(""));
2820
      });
2821
 
2822
      // totals row
2823
      var totTr = ['<tr class="totalrow"><td><strong>Total</strong></td>'];
2824
      totTr.push(cellPair(t.totalAch, t.totalTgt, true));
2825
      buckets.forEach(function (b) {
2826
        totTr.push(cellPair(t[b.key + "Ach"], t[b.key + "Tgt"], true));
2827
      });
2828
      totTr.push('<td></td></tr>');
2829
      html.push(totTr.join(""));
2830
 
2831
      html.push('</tbody></table>');
2832
      $("#rdrrTableWrap").html(html.join(""));
2833
 
2834
      // Cache the parsed row on each <tr> so drill-down can render bars immediately.
2835
      rows.forEach(function (r) {
2836
        $("#rdrrGrid tbody tr").filter(function () {
2837
          return +this.dataset.authid === r.authId && +this.dataset.warehouseid === r.warehouseId;
2838
        }).each(function () {
2839
          $(this).data("cached", r);
2840
        });
2841
      });
2842
 
2843
      $("#rdrrGrid tbody tr.clickable").on("click", function () {
2844
        var d = this.dataset;
2845
        var cached = $(this).data("cached");
2846
        openDrilldown(+d.authid, +d.warehouseid, d.rbmname, d.warehousename, cached);
2847
      });
2848
    }
2849
 
2850
    function cellPair(ach, tgt, isTotal) {
2851
      var p = pctLabel(ach, tgt);
2852
      var vhtml = '<td class="num"><div class="cell-val">' + fmtLakh(ach) + ' <small>/ ' + fmtLakh(tgt) + '</small></div></td>';
2853
      var barCls = p.cls === "na" ? "" : p.cls;
2854
      var barW = pctBarWidth(ach, tgt);
2855
      var pctHtml = '<td class="num"><span class="pct ' + p.cls + '">' + p.text + '</span>' +
2856
              (barCls ? '<div class="bar"><i class="' + barCls + '" style="width:' + barW.toFixed(1) + '%"></i></div>' : '') +
2857
              '</td>';
2858
      return vhtml + pctHtml;
2859
    }
2860
 
2861
    // --------------------------- drill-down ---------------------------
2862
 
2863
    function openDrilldown(authId, warehouseId, rbmName, warehouseName, cachedRow) {
2864
      var back = $("#rdrrBack");
2865
      $("#rdrrDdTitle").text(rbmName + " — " + warehouseName);
2866
      $("#rdrrDdDesc").text(fmtDate(startDate) + " – " + fmtDate(endDate));
2867
      $("#rdrrDdBars").empty();
2868
      back.addClass("show");
2869
 
2870
      if (cachedRow) {
2871
        renderBars(cachedRow);
2872
      } else {
2873
        $("#rdrrDdAch").text("—");
2874
        $("#rdrrDdTgt").text("—");
2875
        $("#rdrrDdPct").text("—");
2876
      }
2877
      $("#rdrrDdBrands").html('<div class="loading"><div class="spinner"></div>Loading brand mix&hellip;</div>');
37487 ranu 2878
      $("#rdrrDdFlow").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
37444 ranu 2879
 
37533 ranu 2880
      var salesQs = CURRENT_SALES_ROLE ? ("&hierarchy=SALES&role=" + encodeURIComponent(CURRENT_SALES_ROLE)) : "";
37444 ranu 2881
      fetch("/rbm-drr/rbm-detail?authId=" + authId + "&warehouseId=" + warehouseId +
37533 ranu 2882
              "&startDate=" + startDate + "&endDate=" + endDate + salesQs, {credentials: "same-origin"})
37444 ranu 2883
              .then(function (r) {
2884
                return r.json();
2885
              })
2886
              .then(function (data) {
2887
                renderBrands(data);
37487 ranu 2888
                renderWarehouseFlow(data, cachedRow);
37444 ranu 2889
              })
2890
              .catch(function (e) {
37487 ranu 2891
                var msg = '<div class="empty">Failed to load: ' + (e && e.message ? e.message : "network error") + '</div>';
2892
                $("#rdrrDdBrands").html(msg);
2893
                $("#rdrrDdFlow").html(msg);
37444 ranu 2894
              });
2895
    }
2896
 
37487 ranu 2897
    function renderWarehouseFlow(data, row) {
2898
      var buying = (data && data.buying) || [];
2899
      // Map buying values by status for O(1) lookup.
2900
      var buyMap = {};
2901
      buying.forEach(function (b) {
2902
        buyMap[b.status] = Number(b.value) || 0;
2903
      });
2904
      var labels = {HID: "HID", FASTMOVING: "FAST", RUNNING: "RUN", SLOWMOVING: "SLOW", OTHER: "OTHER"};
2905
      var order = ["HID", "FASTMOVING", "RUNNING", "SLOWMOVING", "OTHER"];
2906
      // Selling per bucket from the cached grid row (already has ACH per bucket).
2907
      var sellMap = {
2908
        HID: row ? Number(row.hidAch) || 0 : 0,
2909
        FASTMOVING: row ? Number(row.fastAch) || 0 : 0,
2910
        RUNNING: row ? Number(row.runAch) || 0 : 0,
2911
        SLOWMOVING: row ? Number(row.slowAch) || 0 : 0,
2912
        OTHER: row ? Number(row.otherAch) || 0 : 0
2913
      };
2914
      var totBuy = 0, totSell = 0;
2915
      order.forEach(function (s) {
2916
        totBuy += buyMap[s] || 0;
2917
        totSell += sellMap[s] || 0;
2918
      });
2919
 
2920
      // "Coverage" = selling / buying. High coverage = we sold most of what came in.
2921
      // Low coverage = supply piling up (aging risk).
2922
      function covCell(sell, buy) {
2923
        if (!buy || buy <= 0) {
2924
          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>';
2925
          return '<span class="cov-cell na">—</span>';
2926
        }
2927
        var pct = (sell / buy) * 100;
2928
        var cls = pct >= 60 ? 'good' : pct >= 25 ? 'warn' : 'bad';
2929
        var w = Math.min(100, pct);
2930
        return '<span class="cov-cell ' + cls + '">' +
2931
                '<span class="cov-bar"><i style="width:' + w.toFixed(1) + '%"></i></span>' +
2932
                '<span class="cov-pct">' + pct.toFixed(1) + '%</span></span>';
2933
      }
2934
 
2935
      var html = '<table class="flow-tbl"><thead><tr>' +
2936
              '<th>Movement</th><th class="num">Buying</th><th class="num">Selling</th><th class="num">Coverage (sold / bought)</th>' +
2937
              '</tr></thead><tbody>';
2938
      order.forEach(function (s) {
2939
        var buy = buyMap[s] || 0, sell = sellMap[s] || 0;
2940
        html += '<tr class="' + s.toLowerCase() + '">' +
2941
                '<td><i></i>' + labels[s] + '</td>' +
2942
                '<td class="num">' + fmtLakh(buy) + '</td>' +
2943
                '<td class="num">' + fmtLakh(sell) + '</td>' +
2944
                '<td class="num">' + covCell(sell, buy) + '</td>' +
2945
                '</tr>';
2946
      });
2947
      html += '<tr class="tot">' +
2948
              '<td>Total</td>' +
2949
              '<td class="num">' + fmtLakh(totBuy) + '</td>' +
2950
              '<td class="num">' + fmtLakh(totSell) + '</td>' +
2951
              '<td class="num">' + covCell(totSell, totBuy) + '</td>' +
2952
              '</tr>';
2953
      html += '</tbody></table>';
2954
      $("#rdrrDdFlow").html(html);
2955
    }
2956
 
37444 ranu 2957
    function renderBrands(data) {
2958
      var brands = (data && data.brands) || [];
2959
      if (brands.length === 0) {
2960
        $("#rdrrDdBrands").html('<div class="empty"><div class="ei">🏷️</div>No brand sales in this range.</div>');
2961
        return;
2962
      }
2963
      var maxShare = brands[0].sharePct || 0.001;
2964
      var html = '<div class="brands">';
2965
      brands.forEach(function (b, idx) {
2966
        var barW = maxShare > 0 ? Math.min(100, (b.sharePct / maxShare) * 100) : 0;
2967
        var topCls = idx === 0 ? ' top' : '';
37460 ranu 2968
        var pc = Number(b.partnerCount) || 0;
2969
        var pcCls = pc === 0 ? ' zero' : '';
37583 ranu 2970
        var pcLabel = pc + (pc === 1 ? ' partner' : ' p');
37444 ranu 2971
        html += '<div class="brand-card' + topCls + '" data-idx="' + idx + '">' +
2972
                '<div class="brand-head">' +
2973
                '<div class="cx">&rsaquo;</div>' +
2974
                '<div class="bn" title="' + escapeHtml(b.brand) + '">' + escapeHtml(b.brand) + '</div>' +
2975
                '<div class="btrack"><i style="width:' + barW.toFixed(1) + '%"></i></div>' +
37460 ranu 2976
                '<div class="bpc' + pcCls + '" title="Distinct partners of this RBM who billed ' + escapeHtml(b.brand) + ' in the range">' +
2977
                '<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>' +
2978
                pcLabel +
2979
                '</div>' +
37444 ranu 2980
                '<div class="bval">' + fmtLakh(b.valueSold) + '</div>' +
2981
                '<div class="bshare">' + (b.sharePct || 0).toFixed(1) + '%</div>' +
2982
                '</div>' +
2983
                '<div class="brand-body">' +
2984
                '<div class="bhdr">Movement Split within ' + escapeHtml(b.brand) + '</div>' +
2985
                renderBrandBuckets(b.buckets || []) +
2986
                '</div>' +
2987
                '</div>';
2988
      });
2989
      html += '</div>';
2990
      $("#rdrrDdBrands").html(html);
2991
 
2992
      $("#rdrrDdBrands .brand-head").on("click", function () {
2993
        $(this).closest(".brand-card").toggleClass("open");
2994
      });
2995
    }
2996
 
2997
    function renderBrandBuckets(buckets) {
2998
      if (!buckets || buckets.length === 0) {
2999
        return '<div style="color:var(--soft);font-size:12px;padding:8px 4px">No movement split available.</div>';
3000
      }
3001
      var labels = {HID: "HID", FASTMOVING: "FAST", RUNNING: "RUN", SLOWMOVING: "SLOW", OTHER: "OTHER"};
3002
      var html = '<div class="mbars">';
3003
      buckets.forEach(function (bk) {
3004
        var cls = (bk.status || "OTHER").toLowerCase();
3005
        var label = labels[bk.status] || bk.status || "OTHER";
3006
        var sp = bk.sharePctOfBrand || 0;
3007
        var barW = Math.min(100, sp);
3008
        html += '<div class="mbar ' + cls + '">' +
3009
                '<div class="mname"><i></i>' + label + '</div>' +
3010
                '<div class="mtrack"><i style="width:' + barW.toFixed(1) + '%"></i></div>' +
3011
                '<div class="mval">' + fmtLakh(bk.valueSold) + '</div>' +
3012
                '<div class="mshare">' + sp.toFixed(1) + '%</div>' +
3013
                '</div>';
3014
      });
3015
      html += '</div>';
3016
      return html;
3017
    }
3018
 
3019
    function renderBars(row) {
3020
      var totalAch = row.totalAch, totalTgt = row.totalTgt;
3021
      $("#rdrrDdAch").html('&#8377;&nbsp;' + fmtLakh(totalAch));
3022
      $("#rdrrDdTgt").html('&#8377;&nbsp;' + fmtLakh(totalTgt));
3023
      var pt = pctLabel(totalAch, totalTgt);
3024
      $("#rdrrDdPct").html(pt.cls === "na" ? '<span style="color:var(--soft);font-size:14px">n/a</span>' :
3025
              '<span class="pct ' + pt.cls + '">' + pt.text + '</span>');
3026
 
3027
      var buckets = [
3028
        {key: "hid", label: "HID"},
3029
        {key: "fast", label: "FAST"},
3030
        {key: "run", label: "RUN"},
3031
        {key: "slow", label: "SLOW"},
3032
        {key: "other", label: "OTHER"}
3033
      ];
3034
      var html = "";
3035
      buckets.forEach(function (b) {
3036
        var ach = row[b.key + "Ach"], tgt = row[b.key + "Tgt"];
3037
        var p = pctLabel(ach, tgt);
3038
        var w = pctBarWidth(ach, tgt);
3039
        html += '<div class="bbar ' + b.key + '">' +
3040
                '<div class="bname"><i></i>' + b.label + '</div>' +
3041
                '<div class="btrack"><i style="width:' + w.toFixed(1) + '%"></i></div>' +
3042
                '<div class="btgt"><b>' + fmtLakh(ach) + '</b> / ' + fmtLakh(tgt) + '</div>' +
3043
                '<div class="bpct ' + p.cls + '">' + p.text + '</div>' +
3044
                '</div>';
3045
      });
3046
      $("#rdrrDdBars").html(html);
3047
    }
3048
 
3049
    function escapeHtml(s) {
3050
      if (s == null) return "";
3051
      return String(s).replace(/[&<>"']/g, function (c) {
3052
        return {"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;"}[c];
3053
      });
3054
    }
3055
 
3056
    $("#rdrrClose").on("click", function () {
3057
      $("#rdrrBack").removeClass("show");
3058
    });
3059
    $("#rdrrBack").on("click", function (e) {
3060
      if (e.target === this) $(this).removeClass("show");
3061
    });
3062
 
3063
    // Target-status modal (achieved vs pending) — opens from the KPI card.
3064
    $("#rdrrKpiTopCard").on("click", function () {
3065
      openStatusModal();
3066
    });
3067
    $("#rdrrStatusClose").on("click", function () {
3068
      $("#rdrrStatusBack").removeClass("show");
3069
    });
3070
    $("#rdrrStatusBack").on("click", function (e) {
3071
      if (e.target === this) $(this).removeClass("show");
3072
    });
3073
 
3074
    function openStatusModal() {
3075
      if (!LAST_PAYLOAD) return;
37487 ranu 3076
      // Respect the RBM filter so the modal matches what's on screen.
3077
      var rows = (LAST_PAYLOAD.rows || []).filter(function (r) {
37497 ranu 3078
        return !CURRENT_FILTER_AUTH_IDS || CURRENT_FILTER_AUTH_IDS[String(r.authId)];
37487 ranu 3079
      });
37444 ranu 3080
      var achieved = [], pending = [];
3081
      rows.forEach(function (r) {
3082
        if (!r.totalTgt || r.totalTgt <= 0) return;
3083
        var pct = (r.totalAch / r.totalTgt) * 100;
3084
        var enriched = {row: r, pct: pct};
3085
        if (r.totalAch >= r.totalTgt) achieved.push(enriched);
3086
        else pending.push(enriched);
3087
      });
3088
      achieved.sort(function (a, b) {
3089
        return b.pct - a.pct;
3090
      });
3091
      pending.sort(function (a, b) {
3092
        return a.pct - b.pct;
3093
      });
3094
 
3095
      $("#rdrrStatusDesc").text(fmtDate(startDate) + " – " + fmtDate(endDate));
3096
      $("#rdrrStatusAchCnt").text(achieved.length);
3097
      $("#rdrrStatusPndCnt").text(pending.length);
3098
      $("#rdrrStatusAchList").html(renderStatusList(achieved, "achieved"));
3099
      $("#rdrrStatusPndList").html(renderStatusList(pending, "pending"));
3100
      $("#rdrrStatusBack").addClass("show");
3101
 
3102
      // Bind click on each item to open the same drill-down slide-in.
3103
      $("#rdrrStatusBack .status-item").on("click", function () {
3104
        var d = this.dataset;
3105
        var cachedRow = null;
3106
        (LAST_PAYLOAD.rows || []).some(function (r) {
3107
          if (r.authId == d.authid && r.warehouseId == d.warehouseid) {
3108
            cachedRow = r;
3109
            return true;
3110
          }
3111
          return false;
3112
        });
3113
        $("#rdrrStatusBack").removeClass("show");
3114
        openDrilldown(+d.authid, +d.warehouseid, d.rbmname, d.warehousename, cachedRow);
3115
      });
3116
    }
3117
 
3118
    function renderStatusList(items, kind) {
3119
      if (items.length === 0) {
3120
        return '<div class="status-empty">' +
3121
                (kind === "achieved" ? "No RBM has met target in this range." : "All RBMs met target — nice!") +
3122
                '</div>';
3123
      }
3124
      var html = "";
3125
      items.forEach(function (it) {
3126
        var r = it.row;
3127
        var p = pctClass(it.pct);
3128
        html += '<div class="status-item" title="Click to view drill-down"' +
3129
                ' data-authid="' + r.authId + '" data-warehouseid="' + r.warehouseId + '"' +
3130
                ' data-rbmname="' + escapeHtml(r.rbmName) + '" data-warehousename="' + escapeHtml(r.warehouseName) + '"' +
3131
                ' style="cursor:pointer">' +
3132
                '<div><span class="rn">' + escapeHtml(r.rbmName) + '</span>' +
3133
                '<span class="wh">' + escapeHtml(r.warehouseName) + '</span></div>' +
3134
                '<div class="vv"><b>' + fmtLakh(r.totalAch) + '</b> / ' + fmtLakh(r.totalTgt) + '</div>' +
3135
                '<div class="pp ' + p + '">' + it.pct.toFixed(1) + '%</div>' +
3136
                '</div>';
3137
      });
3138
      return html;
3139
    }
3140
 
37468 ranu 3141
    // ------------------------- Today PO & Billed matrix -------------------------
3142
    // Reuses the existing /indent/today_po_table_fragment endpoint (unchanged).
37522 ranu 3143
    // Parses the returned HTML into a data model and re-renders a compact
3144
    // heatmap grid — one row per person, one column per brand, cell showing
3145
    // Billed (primary) + Partners/PO (secondary), with per-brand heat shading.
37468 ranu 3146
    function loadPurchaseMilestones() {
3147
      var cat = $("#rdrrPmCategory").val() || "RBM";
3148
      $("#rdrrPmWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
3149
      $.ajax({
3150
        url: "/indent/today_po_table_fragment",
3151
        type: "GET",
3152
        data: {categoryType: cat},
3153
        success: function (html) {
37522 ranu 3154
          try {
3155
            var model = parsePurchaseMilestonesFragment(html);
3156
            $("#rdrrPmWrap").html(renderPurchaseMilestonesGrid(model));
3157
          } catch (e) {
3158
            $("#rdrrPmWrap").html('<div class="empty">Failed to render purchase-milestones data.</div>');
3159
          }
37468 ranu 3160
        },
3161
        error: function () {
3162
          $("#rdrrPmWrap").html('<div class="empty">Failed to load purchase-milestones data.</div>');
3163
        }
3164
      });
3165
    }
3166
 
3167
    function numberToIndianCurrency(n) {
3168
      if (n === 0) return "0";
3169
      var s = n.toString();
3170
      var lastThree = s.substring(s.length - 3);
3171
      var other = s.substring(0, s.length - 3);
3172
      if (other !== "") lastThree = "," + lastThree;
3173
      return other.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
3174
    }
3175
 
37570 ranu 3176
    // Compact Lakh format for the Purchase Milestones grid: 623478 → "6.2L", 500 → "0.0L", 15737358 → "157.4L".
3177
    // Always one decimal, always suffixed "L" — matches how other DRR sections display money.
3178
    function pmLakh(n) {
3179
      n = Number(n) || 0;
3180
      return (n / 100000).toFixed(1) + "L";
3181
    }
3182
 
37523 ranu 3183
    // Compact currency: >= 1Cr => "1.19Cr", >= 1L => "18.68L", >= 1K => "28.4K", else raw.
3184
    // `tight=true` drops the space before the unit for narrow cells.
3185
    function pmCompactCurrency(n, tight) {
37522 ranu 3186
      n = Number(n) || 0;
37523 ranu 3187
      var sp = tight ? "" : " ";
3188
      if (n >= 10000000) return "₹" + (n / 10000000).toFixed(2) + sp + "Cr";
3189
      if (n >= 100000) return "₹" + (n / 100000).toFixed(2) + sp + "L";
3190
      if (n >= 1000) return "₹" + (n / 1000).toFixed(1) + sp + "K";
37522 ranu 3191
      return "₹" + numberToIndianCurrency(Math.round(n));
3192
    }
3193
 
3194
    // Parse the injected multi-table fragment into:
3195
    //   { brands: [{name, slug}], rows: [{name, cells: {brand: {po, count, billed}}, totals: {po, count, billed}}] }
3196
    function parsePurchaseMilestonesFragment(html) {
3197
      var doc = new DOMParser().parseFromString(html, "text/html");
3198
      var tables = doc.querySelectorAll("table");
3199
      var brandOrder = [];
3200
      var brandSet = {};
3201
      var rowsMap = {};   // name -> {name, order, cells}
3202
      var rowOrder = [];
3203
 
3204
      tables.forEach(function (tbl) {
3205
        var theadRows = tbl.querySelectorAll("thead tr");
3206
        if (theadRows.length < 1) return;
3207
        // First thead row: [AuthUser th] + brand ths (colspan=3)
3208
        var brandThs = theadRows[0].querySelectorAll("th[colspan]");
3209
        var brands = [];
3210
        brandThs.forEach(function (th) {
3211
          var label = (th.textContent || "").trim().toUpperCase();
3212
          if (!label) return;
3213
          brands.push(label);
3214
          if (!brandSet[label]) {
3215
            brandSet[label] = true;
3216
            brandOrder.push({name: label, slug: label.toLowerCase().replace(/[^a-z0-9]+/g, "")});
3217
          }
3218
        });
3219
 
3220
        tbl.querySelectorAll("tbody tr").forEach(function (tr) {
3221
          var tds = tr.querySelectorAll("td");
3222
          if (tds.length < 1 + brands.length * 3) return;
3223
          var name = (tds[0].textContent || "").trim();
3224
          if (!name) return;
3225
          var row = rowsMap[name];
3226
          if (!row) {
3227
            row = {name: name, cells: {}, isTotal: /^all\b/i.test(name)};
3228
            rowsMap[name] = row;
3229
            rowOrder.push(name);
3230
          }
3231
          for (var i = 0; i < brands.length; i++) {
3232
            var b = brands[i];
3233
            var po = parseFloat((tds[1 + i * 3].textContent || "0").replace(/[^\d.-]/g, "")) || 0;
3234
            var count = parseInt((tds[1 + i * 3 + 1].textContent || "0").replace(/[^\d.-]/g, ""), 10) || 0;
3235
            var billed = parseFloat((tds[1 + i * 3 + 2].textContent || "0").replace(/[^\d.-]/g, "")) || 0;
3236
            row.cells[b] = {po: po, count: count, billed: billed};
3237
          }
3238
        });
3239
      });
3240
 
3241
      // Pull the TOTAL brand out of brandOrder and keep it first (fixed column).
3242
      var totalIdx = brandOrder.findIndex(function (b) {
3243
        return b.name === "TOTAL";
3244
      });
3245
      var totalBrand = totalIdx >= 0 ? brandOrder.splice(totalIdx, 1)[0] : null;
3246
 
3247
      // Sort remaining brands by grand total Billed (biggest first) using the "All …" row if present.
3248
      var totalRowName = rowOrder.find(function (n) {
3249
        return /^all\b/i.test(n);
3250
      });
3251
      var totalRow = totalRowName ? rowsMap[totalRowName] : null;
3252
      if (totalRow) {
3253
        brandOrder.sort(function (a, b) {
3254
          var av = (totalRow.cells[a.name] || {}).billed || 0;
3255
          var bv = (totalRow.cells[b.name] || {}).billed || 0;
3256
          return bv - av;
3257
        });
3258
      }
3259
      if (totalBrand) brandOrder.unshift(totalBrand);
3260
 
3261
      // Order rows: total first, others by grand total Billed (from TOTAL brand or sum).
3262
      var totalRowIdx = totalRowName ? rowOrder.indexOf(totalRowName) : -1;
3263
      if (totalRowIdx > 0) {
3264
        rowOrder.splice(totalRowIdx, 1);
3265
        rowOrder.unshift(totalRowName);
3266
      }
3267
      var head = totalRowIdx >= 0 ? [rowOrder.shift()] : [];
3268
      rowOrder.sort(function (a, b) {
3269
        var av = (rowsMap[a].cells["TOTAL"] || {}).billed || 0;
3270
        var bv = (rowsMap[b].cells["TOTAL"] || {}).billed || 0;
3271
        return bv - av;
3272
      });
3273
      rowOrder = head.concat(rowOrder);
3274
 
3275
      // Per-brand max Billed for heatmap intensity (excludes the totals row).
3276
      var brandMax = {};
3277
      brandOrder.forEach(function (b) {
3278
        var max = 0;
3279
        rowOrder.forEach(function (name) {
3280
          var row = rowsMap[name];
3281
          if (row.isTotal) return;
3282
          var v = (row.cells[b.name] || {}).billed || 0;
3283
          if (v > max) max = v;
3284
        });
3285
        brandMax[b.name] = max;
3286
      });
3287
 
3288
      var rows = rowOrder.map(function (n) {
3289
        return rowsMap[n];
3290
      });
3291
      return {brands: brandOrder, rows: rows, brandMax: brandMax};
3292
    }
3293
 
3294
    function renderPurchaseMilestonesGrid(model) {
3295
      if (!model.rows.length || !model.brands.length) {
3296
        return '<div class="empty">No data.</div>';
3297
      }
3298
      var html = ['<div class="pm-grid-wrap"><table class="pm-grid"><thead><tr>'];
3299
      html.push('<th class="pm-corner">' +
3300
              '<div class="pm-corner-lbl">Person</div>' +
3301
              '<div class="pm-corner-hint">' + model.rows.length + ' · ' + model.brands.length + ' brands</div>' +
3302
              '</th>');
3303
      model.brands.forEach(function (b) {
3304
        html.push('<th class="pm-brand ' + b.slug + '">' + b.name + '</th>');
3305
      });
3306
      html.push('</tr></thead><tbody>');
3307
 
3308
      model.rows.forEach(function (row) {
3309
        html.push('<tr class="pm-row' + (row.isTotal ? ' pm-total-row' : '') + '">');
3310
        html.push('<td class="pm-name">' +
3311
                '<div class="pm-name-txt">' + escapeHtml(row.name) + '</div>' +
3312
                (row.isTotal ? '<div class="pm-name-sub">Grand total</div>' : '') +
3313
                '</td>');
3314
        model.brands.forEach(function (b) {
3315
          var c = row.cells[b.name] || {po: 0, count: 0, billed: 0};
3316
          var max = model.brandMax[b.name] || 0;
3317
          var intensity = (!row.isTotal && max > 0) ? Math.min(1, c.billed / max) : 0;
3318
          var isZero = c.billed === 0 && c.po === 0 && c.count === 0;
37575 ranu 3319
          // Softer blue heatmap: capped alpha keeps dark text readable at max intensity.
3320
          var bgAlpha = intensity > 0 ? (0.05 + intensity * 0.22).toFixed(2) : 0;
37522 ranu 3321
          var style = (!row.isTotal && intensity > 0)
37575 ranu 3322
                  ? ' style="background: rgba(59,130,246,' + bgAlpha + ')"' : '';
37522 ranu 3323
          if (isZero) {
3324
            html.push('<td class="pm-cell pm-cell-zero">&mdash;</td>');
3325
          } else {
37570 ranu 3326
            // Values formatted in Lakh (X.XL) — matches how the drill-down and other DRR sections display money.
3327
            var billedTxt = pmLakh(c.billed);
3328
            var poTxt = pmLakh(c.po);
3329
            var partnerLine = c.count > 0
37583 ranu 3330
                    ? ('<div class="pm-partners">' + c.count + '<span class="pm-tag"> p' + (c.count === 1 ? '' : 's') + '</span></div>')
37570 ranu 3331
                    : '';
3332
            var poLine = (c.po > 0 || c.billed > 0)
3333
                    ? ('<div class="pm-po">' + poTxt + '<span class="pm-tag"> PO</span></div>')
3334
                    : '';
3335
            var billedLine = '<div class="pm-billed">' + billedTxt + '</div>';
3336
            // Order: partner (top) → PO (middle) → billed (bottom, primary)
37522 ranu 3337
            html.push('<td class="pm-cell' + (row.isTotal ? ' pm-cell-total' : '') + '"' + style + '>' +
37570 ranu 3338
                    partnerLine + poLine + billedLine +
37522 ranu 3339
                    '</td>');
3340
          }
3341
        });
3342
        html.push('</tr>');
3343
      });
3344
      html.push('</tbody></table></div>');
3345
      return html.join("");
3346
    }
3347
 
3348
    function escapeHtml(s) {
3349
      return String(s == null ? "" : s)
3350
              .replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
3351
              .replace(/"/g, "&quot;").replace(/'/g, "&#39;");
3352
    }
3353
 
37468 ranu 3354
    $("#rdrrPmCategory").on("change", loadPurchaseMilestones);
3355
 
3356
    // ------------------------- RBM Performance Dashboard (MTD) -------------------------
3357
    // No dedicated backend endpoint exists — the perf-dashboard table is only rendered
3358
    // inline in /indent/today_po_rbm. We fetch that page and extract just the table.
3359
    // Trade-off: heavier request (server re-runs full page prep). Consider adding a
3360
    // /rbm-drr/performance fragment endpoint later if this becomes a hot path.
3361
    function loadPerformanceDashboard() {
3362
      $("#rdrrPerfWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
3363
      $.ajax({
3364
        url: "/indent/today_po_rbm",
3365
        type: "GET",
3366
        dataType: "html",
3367
        success: function (fullHtml) {
3368
          var doc = new DOMParser().parseFromString(fullHtml, "text/html");
3369
          var tbl = doc.querySelector("#performance-dashboard-table");
3370
          if (!tbl) {
3371
            $("#rdrrPerfWrap").html('<div class="empty"><div class="ei">📊</div>No performance dashboard data available yet.</div>');
3372
            return;
3373
          }
3374
          // Fix any relative image paths (e.g. king.png / trophy-cup.png) to be root-relative.
3375
          tbl.querySelectorAll("img").forEach(function (im) {
3376
            var src = im.getAttribute("src") || "";
3377
            if (src.indexOf("resources/") !== -1 && src.charAt(0) !== "/") {
3378
              im.setAttribute("src", "/" + src.replace(/^\.\.\/+/, ""));
3379
            }
3380
          });
3381
          $("#rdrrPerfWrap").empty().append(tbl);
3382
        },
3383
        error: function () {
3384
          $("#rdrrPerfWrap").html('<div class="empty">Failed to load performance dashboard.</div>');
3385
        }
3386
      });
3387
    }
3388
 
37469 ranu 3389
    // ------------------------- RBM Call Target iframe -------------------------
3390
    // The /indent/rbm_call_target endpoint returns a Velocity FRAGMENT (no <html>,
3391
    // no Bootstrap/jQuery). When loaded directly in an iframe, Bootstrap modals
3392
    // collapse and their inner Loading… contents render inline. Fix: fetch the
3393
    // fragment, wrap it in a self-contained document that loads jQuery + Popper +
3394
    // Bootstrap, then hand it to the iframe via srcdoc. Zero backend change.
3395
    function loadCallTargetIframe() {
3396
      $.ajax({
3397
        url: "/indent/rbm_call_target",
3398
        type: "GET",
3399
        dataType: "html",
3400
        success: function (fragment) {
3401
          var doc = [
3402
            '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">',
3403
            '<meta name="viewport" content="width=device-width,initial-scale=1">',
3404
            '<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">',
3405
            '<style>body{margin:0;padding:16px;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:#fff}</style>',
3406
            '</head><body>',
3407
            fragment,
3408
            '<script src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></' + 'script>',
3409
            '<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></' + 'script>',
3410
            '<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></' + 'script>',
3411
            '</body></html>'
3412
          ].join("");
3413
          var frame = document.getElementById("rdrrCallFrame");
3414
          frame.onload = function () {
3415
            hookCallTargetDrawer(frame);
3416
          };
3417
          frame.srcdoc = doc;
3418
        },
3419
        error: function () {
3420
          document.getElementById("rdrrCallFrame").srcdoc =
3421
                  '<div style="padding:24px;font-family:system-ui;color:#97a1b5">Failed to load call-target view.</div>';
3422
        }
3423
      });
3424
    }
3425
 
3426
    // Redirect the iframe's Bootstrap-modal drill-downs into a slide-in parent drawer
3427
    // that matches the dashboard style. srcdoc iframes inherit the parent origin so
3428
    // we can freely reach into the iframe's window and override its functions.
3429
    function hookCallTargetDrawer(frame) {
3430
      var iw = frame.contentWindow;
3431
      if (!iw) return;
3432
      // Give the source's own <script> a moment to run and define the functions.
3433
      setTimeout(function () {
3434
        try {
3435
          iw.showCalledPartnerDetails = function (authId, rbmName) {
3436
            openCallTargetDrawer("called", authId, rbmName, iw.pageQueryDate);
3437
          };
3438
          iw.showOutOfSequenceDetails = function (authId, rbmName) {
3439
            openCallTargetDrawer("oos", authId, rbmName, iw.pageQueryDate);
3440
          };
3441
        } catch (e) {
3442
          // If cross-origin ever kicks in (shouldn't with srcdoc same-origin),
3443
          // fall back to the iframe's native Bootstrap modal — no crash.
3444
        }
3445
      }, 50);
3446
    }
3447
 
3448
    function openCallTargetDrawer(kind, authId, rbmName, dateStr) {
3449
      var titleWho = rbmName + (dateStr ? " (" + dateStr + ")" : "");
3450
      var title = (kind === "oos" ? "Out of Sequence Calls — " : "Called Partners — ") + titleWho;
3451
      $("#rdrrCallDrawerTitle").text(title);
3452
      $("#rdrrCallDrawerDesc").text(kind === "oos"
3453
              ? "Calls placed outside the recommended sequence."
3454
              : "All calls made by this RBM today, with recordings.");
3455
      $("#rdrrCallDrawerBody").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
3456
      $("#rdrrCallDrawerBack").addClass("show");
3457
 
3458
      var url;
3459
      if (kind === "oos") {
3460
        url = "/indent/rbm_call_target/oos_details?authId=" + encodeURIComponent(authId);
3461
      } else {
3462
        var dp = dateStr ? "&date=" + encodeURIComponent(dateStr) : "";
3463
        url = "/indent/rbm_call_target/called_details?authId=" + encodeURIComponent(authId)
3464
                + "&agentName=" + encodeURIComponent(rbmName) + dp;
3465
      }
3466
      $.ajax({
3467
        url: url, type: "GET", dataType: "json",
3468
        success: function (data) {
3469
          if (!data || data.length === 0) {
3470
            $("#rdrrCallDrawerBody").html('<div class="empty"><div class="ei">📭</div>No entries.</div>');
3471
            return;
3472
          }
3473
          $("#rdrrCallDrawerBody").html(kind === "oos" ? renderOosTable(data) : renderCalledTable(data));
3474
        },
3475
        error: function () {
3476
          $("#rdrrCallDrawerBody").html('<div class="empty">Failed to load details.</div>');
3477
        }
3478
      });
3479
    }
3480
 
3481
    function renderOosTable(data) {
3482
      var html = '<table><thead><tr><th>S.No</th><th>Party Name</th><th>Code</th><th>Time</th></tr></thead><tbody>';
3483
      data.forEach(function (r, i) {
3484
        html += '<tr><td>' + (i + 1) + '</td><td>' + escapeHtml(r.partyName || "-") +
3485
                '</td><td>' + escapeHtml(r.code || "-") + '</td><td>' + escapeHtml(r.time || "-") + '</td></tr>';
3486
      });
3487
      return html + '</tbody></table>';
3488
    }
3489
 
3490
    function renderCalledTable(data) {
3491
      var html = '<table><thead><tr>' +
3492
              '<th>S.No</th><th>Party Name</th><th>Code</th><th>Remark</th>' +
3493
              '<th>Call Status</th><th>Duration</th><th>Date/Time</th><th>Recording</th>' +
3494
              '</tr></thead><tbody>';
3495
      data.forEach(function (r, i) {
3496
        var rowStyle = "";
3497
        var recording = "-";
3498
        if (r.breakLog) {
3499
          var status = (r.breakStatus || "").toLowerCase();
3500
          if (status.indexOf("available") >= 0) rowStyle = 'style="background:#fdecec;color:#721c24"';
3501
          else if (status.indexOf("trying") >= 0) rowStyle = 'style="background:#fff5d6;color:#856404"';
3502
          else if (status.indexOf("logged out") >= 0 || status.indexOf("logout") >= 0) rowStyle = 'style="background:#eef0f4;color:#383d41"';
3503
          else if (status.indexOf("break") >= 0) rowStyle = 'style="background:#ffe5cc;color:#c45200"';
3504
        }
3505
        if (r.recordingUrl) {
3506
          recording = '<audio controls preload="none" src="' + escapeHtml(r.recordingUrl) + '"></audio>';
3507
        }
3508
        html += '<tr ' + rowStyle + '>' +
3509
                '<td>' + (i + 1) + '</td>' +
3510
                '<td>' + escapeHtml(r.partyName || (r.breakLog ? (r.breakStatus || "-") : "-")) + '</td>' +
3511
                '<td>' + escapeHtml(r.code || "-") + '</td>' +
3512
                '<td>' + escapeHtml(r.remark || "-") + '</td>' +
3513
                '<td>' + escapeHtml(r.callStatus || "-") + '</td>' +
3514
                '<td>' + escapeHtml(r.callDuration || "-") + '</td>' +
3515
                '<td>' + escapeHtml(r.callDateTime || "-") + '</td>' +
3516
                '<td>' + recording + '</td>' +
3517
                '</tr>';
3518
      });
3519
      return html + '</tbody></table>';
3520
    }
3521
 
3522
    $("#rdrrCallDrawerClose").on("click", function () {
3523
      $("#rdrrCallDrawerBack").removeClass("show");
3524
    });
3525
    $("#rdrrCallDrawerBack").on("click", function (e) {
3526
      if (e.target === this) $(this).removeClass("show");
3527
    });
3528
 
37497 ranu 3529
    // ------------------------- cascading filter (Type → [Level] → Person) -------------------------
3530
    // Flow:
3531
    //   Type = RBM   → Person dropdown = all RBMs. Pick one to filter to that RBM.
3532
    //   Type = SALES → Level dropdown appears (ASM/CM/DM/BM/RSM/NSM). Pick a level
3533
    //                  → Person dropdown = active people at that level. Pick a person
3534
    //                  → fetches /rbm-drr/sales-data and shows that person's aggregated rows.
3535
    // One backend call caches both the RBM list and the Sales list.
3536
    var ALL_RBMS = [];         // [{authId, name}, ...]
3537
    var ALL_SALES_BY_ROLE = {}; // {ASM: [...], CM: [...], ...}
3538
 
3539
    function loadFilterOptions() {
3540
      $.ajax({
3541
        url: "/rbm-drr/all-sales", type: "GET", dataType: "json",
3542
        success: function (payload) {
3543
          ALL_RBMS = (payload && payload.rbms) || [];
3544
          ALL_SALES_BY_ROLE = {};
3545
          ((payload && payload.sales) || []).forEach(function (s) {
3546
            (ALL_SALES_BY_ROLE[s.role] = ALL_SALES_BY_ROLE[s.role] || []).push(s);
3547
          });
3548
          repopulatePersonForCurrentType();
3549
        }
3550
      });
3551
    }
3552
 
3553
    // Refill the Person dropdown based on current Type (+ Level if Sales).
3554
    function repopulatePersonForCurrentType() {
3555
      var type = $("#rdrrTypeSelect").val();
3556
      var personSel = $("#rdrrPersonSelect");
3557
      if (type === "RBM") {
3558
        var html = '<option value="">All RBMs (' + ALL_RBMS.length + ')</option>';
3559
        ALL_RBMS.forEach(function (r) {
3560
          html += '<option value="' + r.authId + '">' + escapeHtml(r.name || "Unknown") + '</option>';
3561
        });
3562
        personSel.html(html).prop("disabled", false);
3563
        return;
3564
      }
3565
      // SALES
3566
      var level = $("#rdrrLevelSelect").val();
3567
      if (!level) {
3568
        personSel.html('<option value="">Pick a level first</option>').prop("disabled", true);
3569
        return;
3570
      }
3571
      var list = ALL_SALES_BY_ROLE[level] || [];
3572
      var salesHtml = '<option value="">All ' + escapeHtml(level) + 's (' + list.length + ')</option>';
3573
      list.forEach(function (s) {
3574
        salesHtml += '<option value="' + s.authId + '">' + escapeHtml(s.name || "Unknown") + '</option>';
3575
      });
3576
      personSel.html(salesHtml).prop("disabled", false);
3577
    }
3578
 
37517 ranu 3579
    // Fetches (or refetches) /rbm-drr/sales-data for the current date range,
3580
    // then renders. Called on Level change and on Apply while Sales view active.
3581
    function fetchAndRenderSales() {
3582
      $("#rdrrTableWrap").html('<div class="loading"><div class="spinner"></div>Loading&hellip;</div>');
3583
      $.ajax({
3584
        url: "/rbm-drr/sales-data", type: "GET",
3585
        data: {startDate: startDate, endDate: endDate}, dataType: "json",
3586
        success: function (payload) {
3587
          SALES_PAYLOAD = payload;
3588
          renderFiltered();
3589
        },
3590
        error: function () {
3591
          SALES_PAYLOAD = {rows: []};
3592
          renderFiltered();
3593
        }
3594
      });
3595
    }
3596
 
37497 ranu 3597
    // Type toggles: show/hide Level; reset filter state; refresh Person options.
3598
    $("#rdrrTypeSelect").on("change", function () {
3599
      var type = $(this).val();
3600
      if (type === "SALES") {
3601
        $("#rdrrLevelSelect").css("display", "").val("");
3602
      } else {
3603
        $("#rdrrLevelSelect").css("display", "none").val("");
3604
      }
3605
      // Clear all filter state whenever the type changes.
3606
      CURRENT_FILTER_AUTH_IDS = null;
37517 ranu 3607
      CURRENT_SALES_ROLE = null;
37497 ranu 3608
      CURRENT_SALES_AUTH_ID = null;
3609
      SALES_PAYLOAD = null;
3610
      repopulatePersonForCurrentType();
37487 ranu 3611
      renderFiltered();
3612
    });
3613
 
37497 ranu 3614
    $("#rdrrLevelSelect").on("change", function () {
37517 ranu 3615
      var level = $(this).val();
3616
      // Reset the person-specific filter; role determines the view.
37497 ranu 3617
      CURRENT_FILTER_AUTH_IDS = null;
3618
      CURRENT_SALES_AUTH_ID = null;
37517 ranu 3619
      CURRENT_SALES_ROLE = level || null;
37497 ranu 3620
      repopulatePersonForCurrentType();
37517 ranu 3621
      if (level) {
3622
        // Fetch Sales-data once, then all subsequent role/person filtering is client-side.
3623
        fetchAndRenderSales();
3624
      } else {
3625
        SALES_PAYLOAD = null;
3626
        renderFiltered();
3627
      }
37497 ranu 3628
    });
3629
 
3630
    $("#rdrrPersonSelect").on("change", function () {
3631
      var authId = $(this).val();
3632
      var type = $("#rdrrTypeSelect").val();
3633
 
3634
      if (type === "RBM") {
3635
        // RBM filter (single authId) — no server round trip needed.
37517 ranu 3636
        CURRENT_SALES_ROLE = null;
37497 ranu 3637
        CURRENT_SALES_AUTH_ID = null;
3638
        SALES_PAYLOAD = null;
3639
        if (!authId) {
3640
          CURRENT_FILTER_AUTH_IDS = null;
3641
        } else {
3642
          var single = {};
3643
          single[String(authId)] = true;
3644
          CURRENT_FILTER_AUTH_IDS = single;
3645
        }
3646
        renderFiltered();
3647
        return;
3648
      }
3649
 
37517 ranu 3650
      // SALES type — role already active from Level dropdown; SALES_PAYLOAD already fetched.
3651
      // Person selection just further filters client-side (no re-fetch).
37497 ranu 3652
      CURRENT_FILTER_AUTH_IDS = null;
37517 ranu 3653
      CURRENT_SALES_AUTH_ID = authId || null;
3654
      if (SALES_PAYLOAD) {
37497 ranu 3655
        renderFiltered();
37517 ranu 3656
      } else if (CURRENT_SALES_ROLE) {
3657
        // Edge case: person changed before Level's fetch completed — trigger the fetch.
3658
        fetchAndRenderSales();
37497 ranu 3659
      }
3660
    });
3661
 
37444 ranu 3662
    // initial load
37497 ranu 3663
    loadFilterOptions();
37444 ranu 3664
    load();
37468 ranu 3665
    loadPurchaseMilestones();
3666
    loadPerformanceDashboard();
37469 ranu 3667
    loadCallTargetIframe();
37444 ranu 3668
  })();
3669
</script>
3670
</body>
3671
</html>