Skip to content

Commit f167c7d

Browse files
Add toggleable sort by name and show created by options in PrintChargeItems (#15306)
1 parent f5f68b9 commit f167c7d

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

public/locale/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5251,6 +5251,7 @@
52515251
"show_all_notifications": "Show All",
52525252
"show_all_slots": "Show all slots",
52535253
"show_available_beds_only": "Show Available Beds Only",
5254+
"show_created_by": "Show Created By",
52545255
"show_default_presets": "Show Default Presets",
52555256
"show_less": "Show less",
52565257
"show_notes": "Show notes",
@@ -5299,7 +5300,7 @@
52995300
"sort_by_latest_created": "Newest Entry First",
53005301
"sort_by_latest_payment": "Newest Payment First",
53015302
"sort_by_locations": "Number of Locations",
5302-
"sort_by_name": "Name",
5303+
"sort_by_name": "Sort by name",
53035304
"sort_by_net_content": "Sort by net content",
53045305
"sort_by_oldest_created": "Oldest Entry First",
53055306
"sort_by_oldest_payment": "Oldest Payment First",

src/pages/Facility/billing/account/components/PrintChargeItems.tsx

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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")}

src/types/billing/chargeItem/chargeItem.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export interface ChargeItemRead extends ChargeItemBase {
9797
performer_actor?: UserReadMinimal;
9898
created_date: string;
9999
modified_date: string;
100+
created_by: UserReadMinimal;
101+
updated_by: UserReadMinimal;
100102
}
101103

102104
export interface ChargeItemBatchResponse {

0 commit comments

Comments
 (0)