@@ -79,12 +79,16 @@ export const PrintChargeItems = (props: {
7979 const [ summaryMode , setSummaryMode ] = useState ( false ) ;
8080 const [ hideHeader , setHideHeader ] = useState ( false ) ;
8181 const [ preserveHeaderSpace , setPreserveHeaderSpace ] = useState ( true ) ;
82+ const [ sortByName , setSortByName ] = useState ( false ) ;
83+ const [ showCreatedBy , setShowCreatedBy ] = useState ( false ) ;
8284
8385 const hideCategoryLabel = `${ t ( "hide_category_grouping" ) } ` ;
8486 const hidePaymentTypeLabel = `${ t ( "hide_payment_type_grouping" ) } ` ;
8587 const summaryLabel = `${ t ( "summary" ) } ` ;
8688 const hideHeaderLabel = `${ t ( "hide_header" ) } ` ;
8789 const preserveHeaderSpaceLabel = `${ t ( "preserve_header_space" ) } ` ;
90+ const sortByNameLabel = `${ t ( "sort_by_name" ) } ` ;
91+ const showCreatedByLabel = `${ t ( "show_created_by" ) } ` ;
8892
8993 const { data : account } = useQuery ( {
9094 queryKey : [ "account" , accountId ] ,
@@ -205,6 +209,31 @@ export const PrintChargeItems = (props: {
205209 </ label >
206210 </ div >
207211 ) }
212+
213+ < div className = "gap-2 flex items-center" >
214+ < Switch
215+ id = "sort-by-name"
216+ checked = { sortByName }
217+ onCheckedChange = { setSortByName }
218+ />
219+ < label htmlFor = "sort-by-name" className = "cursor-pointer text-sm" >
220+ { sortByNameLabel }
221+ </ label >
222+ </ div >
223+
224+ < div className = "gap-2 flex items-center" >
225+ < Switch
226+ id = "show-created-by"
227+ checked = { showCreatedBy }
228+ onCheckedChange = { setShowCreatedBy }
229+ />
230+ < label
231+ htmlFor = "show-created-by"
232+ className = "cursor-pointer text-sm"
233+ >
234+ { showCreatedByLabel }
235+ </ label >
236+ </ div >
208237 </ >
209238 ) }
210239 </ div >
@@ -331,6 +360,11 @@ export const PrintChargeItems = (props: {
331360 < TableHead className = "font-bold text-center w-8" >
332361 { t ( "status" ) }
333362 </ TableHead >
363+ { showCreatedBy && (
364+ < TableHead className = "font-bold w-16" >
365+ { t ( "created_by" ) }
366+ </ TableHead >
367+ ) }
334368 < TableHead className = "font-bold w-10" >
335369 { t ( "rate" ) }
336370 </ TableHead >
@@ -376,8 +410,13 @@ export const PrintChargeItems = (props: {
376410 const rows : React . ReactNode [ ] = [ ] ;
377411
378412 sortedCategories . forEach ( ( categoryTitle ) => {
379- const items : ChargeItemRead [ ] =
413+ const baseItems : ChargeItemRead [ ] =
380414 groups [ categoryTitle ] ?? [ ] ;
415+ const items = sortByName
416+ ? baseItems . sort ( ( a , b ) =>
417+ a . title . localeCompare ( b . title ) ,
418+ )
419+ : baseItems ;
381420
382421 const categoryTotal = add (
383422 ...items . map ( ( i ) => i . total_price || 0 ) ,
@@ -413,7 +452,7 @@ export const PrintChargeItems = (props: {
413452 className = "font-bold hover:bg-transparent"
414453 >
415454 < TableCell
416- colSpan = { 5 }
455+ colSpan = { showCreatedBy ? 6 : 5 }
417456 className = "capitalize"
418457 >
419458 { categoryTitle }
@@ -462,6 +501,14 @@ export const PrintChargeItems = (props: {
462501 { t ( chargeItem . status ) }
463502 </ span >
464503 </ TableCell >
504+ { showCreatedBy && (
505+ < TableCell className = "w-16" >
506+ {
507+ chargeItem . created_by
508+ ?. first_name
509+ }
510+ </ TableCell >
511+ ) }
465512 < TableCell className = "text-right w-10" >
466513 < MonetaryDisplay
467514 amount = { unitPrice }
@@ -489,7 +536,7 @@ export const PrintChargeItems = (props: {
489536 className = "bg-muted/30 font-semibold"
490537 >
491538 < TableCell
492- colSpan = { 5 }
539+ colSpan = { showCreatedBy ? 6 : 5 }
493540 className = "text-right pr-2"
494541 >
495542 { t ( "net_total" ) }
0 commit comments