11import React from 'react' ;
22import { api } from 'trpc/server' ;
3+ import { lang } from 'utils/language' ;
34
45interface TransactionsSummaryProps {
56 start ?: Date ;
@@ -18,33 +19,38 @@ const TransactionsSummary = async ({
1819 take,
1920 } ) ;
2021
22+ let sum = 0 ;
23+
24+ const summary = transactions . items . map ( ( item ) => {
25+ const summary = transactions . summary [ item ] ;
26+ if ( ! summary ) {
27+ return null ;
28+ }
29+ sum += summary . totalPrice ;
30+ return (
31+ < tr key = { item } className = 'divide-x divide-solid dark:divide-neutral-800' >
32+ < td className = 'px-2' > { item } </ td >
33+ < td className = 'px-2 text-right' > { summary . amount } </ td >
34+ < td className = 'px-2 text-right' > { summary . totalPrice } </ td >
35+ </ tr >
36+ ) ;
37+ } ) ;
38+
2139 return (
22- < div >
40+ < div className = 'flex max-w-min flex-col gap-2' >
41+ < h5 >
42+ { lang ( 'Summa:' , 'Sum:' ) } { sum }
43+ </ h5 >
2344 < table className = 'table text-sm' >
2445 < thead >
2546 < tr className = 'text-left' >
26- < th className = 'px-1' > Artikel</ th >
27- < th className = 'px-1' > Antal</ th >
28- < th className = 'px-1' > Totalpris</ th >
47+ < th className = 'px-1' > { lang ( ' Artikel' , 'Item' ) } </ th >
48+ < th className = 'px-1' > { lang ( ' Antal' , 'Amount' ) } </ th >
49+ < th className = 'px-1' > { lang ( ' Totalpris' , 'Total price' ) } </ th >
2950 </ tr >
3051 </ thead >
3152 < tbody className = 'gap-1 divide-y divide-solid dark:divide-neutral-800' >
32- { transactions . items . map ( ( item ) => {
33- const summary = transactions . summary [ item ] ;
34- if ( ! summary ) {
35- return null ;
36- }
37- return (
38- < tr
39- key = { item }
40- className = 'divide-x divide-solid dark:divide-neutral-800'
41- >
42- < td className = 'px-2' > { item } </ td >
43- < td className = 'px-2 text-right' > { summary . amount } </ td >
44- < td className = 'px-2 text-right' > { summary . totalPrice } </ td >
45- </ tr >
46- ) ;
47- } ) }
53+ { summary }
4854 </ tbody >
4955 </ table >
5056 </ div >
0 commit comments