|
28 | 28 | link: string; |
29 | 29 | } |
30 | 30 | let orders: Order[] = $state([]); |
| 31 | + let expenditures: Record<string, number> = $state({}); |
| 32 | + let maxExpenditure = $state(0); |
31 | 33 |
|
32 | 34 | interface OrderStatus { |
33 | 35 | order_id: number; |
|
58 | 60 | setTimeout(() => { |
59 | 61 | fetching = false; |
60 | 62 | }, 500); |
| 63 | +
|
| 64 | + expenditures = orders.reduce<Record<string, number>>((acc, order) => { |
| 65 | + const team = order.team; |
| 66 | + const subtotal = order.count * (order.unit_cost as number); |
| 67 | + if (acc[team] === undefined) { |
| 68 | + acc[team] = 0; |
| 69 | + } |
| 70 | + acc[team] += subtotal; |
| 71 | + return acc; |
| 72 | + }, {}); |
| 73 | +
|
| 74 | + maxExpenditure = Math.max(...Object.values(expenditures)); |
61 | 75 | } |
62 | 76 |
|
63 | 77 | if (browser) { |
|
502 | 516 | {/if} |
503 | 517 | {:else if tabIndex === 4} |
504 | 518 | {#snippet cost(team: string)} |
505 | | - <p>{team} Total: {orders |
506 | | - .filter(o => o.team === team) |
507 | | - .reduce((acc, cur) => acc + cur.count * (cur.unit_cost as number), 0).toLocaleString('en-US', { style: 'currency', currency: 'USD' })}</p> |
| 519 | + <p>{team} Total: {(expenditures[team] ?? 0).toLocaleString( |
| 520 | + 'en-US', |
| 521 | + { style: 'currency', currency: 'USD' } |
| 522 | + )}</p> |
508 | 523 | {/snippet} |
509 | 524 | {@render cost("Software")} |
510 | 525 | {@render cost("Mechanical")} |
511 | 526 | {@render cost("Electrical")} |
| 527 | + |
| 528 | + <section class="flex flex-row gap-4 w-min p-4" style:min-height="20rem" style:background-color="darkgray"> |
| 529 | + {#snippet bar(team: string)} |
| 530 | + <div class="flex flex-col"> |
| 531 | + <div class="flex flex-col justify-end flex-grow"> |
| 532 | + <div style:background-color="darkred" style:height={`calc(100% * ${expenditures[team] / maxExpenditure})`}> |
| 533 | + </div> |
| 534 | + </div> |
| 535 | + <p>{team}</p> |
| 536 | + </div> |
| 537 | + {/snippet} |
| 538 | + {@render bar("Software")} |
| 539 | + {@render bar("Mechanical")} |
| 540 | + {@render bar("Electrical")} |
| 541 | + </section> |
512 | 542 | {/if} |
513 | 543 | </section> |
514 | 544 | </section> |
|
0 commit comments