Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

refactor: new table/filter components for receipts table

Brad Barbin2f363e037063
diff --git a/apps/carbon/app/components/Table/Table.tsx b/apps/carbon/app/components/Table/Table.tsx
index a6d6fba067..55aca46c21 100644
--- a/apps/carbon/app/components/Table/Table.tsx
+++ b/apps/carbon/app/components/Table/Table.tsx
@@ -514,12 +514,18 @@ const Table = <T extends object>({
header.column.columnDef.header,
header.getContext()
)}
- <span className="pl-4">
+ <span className="pl-2">
{sorted ? (
sorted === -1 ? (
- <FaSortDown aria-label="sorted descending" />
+ <FaSortDown
+ aria-label="sorted descending"
+ className="text-primary"
+ />
) : (
- <FaSortUp aria-label="sorted ascending" />
+ <FaSortUp
+ aria-label="sorted ascending"
+ className="text-primary"
+ />
)
) : sortable ? (
<FaSort aria-label="sort" />
@@ -624,12 +630,18 @@ const Table = <T extends object>({
header.column.columnDef.header,
header.getContext()
)}
- <span className="pl-4">
+ <span className="pl-2">
{sorted ? (
sorted === -1 ? (
- <FaSortDown aria-label="sorted descending" />
+ <FaSortDown
+ aria-label="sorted descending"
+ className="text-primary"
+ />
) : (
- <FaSortUp aria-label="sorted ascending" />
+ <FaSortUp
+ aria-label="sorted ascending"
+ className="text-primary"
+ />
)
) : sortable ? (
<FaSort
diff --git a/apps/carbon/app/components/Table/components/Columns.tsx b/apps/carbon/app/components/Table/components/Columns.tsx
index 4ec8728807..5bcf23d5a7 100644
--- a/apps/carbon/app/components/Table/components/Columns.tsx
+++ b/apps/carbon/app/components/Table/components/Columns.tsx
@@ -1,5 +1,4 @@
import {
- Button,
HStack,
IconButton,
Popover,
@@ -34,9 +33,12 @@ const Columns = <T extends object>({
return (
<Popover>
<PopoverTrigger asChild>
- <Button variant="ghost" leftIcon={<BsLayoutThreeColumns />}>
- Columns
- </Button>
+ <IconButton
+ aria-label="Columns"
+ title="Columns"
+ variant="ghost"
+ icon={<BsLayoutThreeColumns />}
+ />
</PopoverTrigger>
<PopoverContent className="w-96">
<PopoverHeader>
diff --git a/apps/carbon/app/components/Table/components/Sort/Sort.tsx b/apps/carbon/app/components/Table/components/Sort/Sort.tsx
index 97c80c4926..b13334c117 100644
--- a/apps/carbon/app/components/Table/components/Sort/Sort.tsx
+++ b/apps/carbon/app/components/Table/components/Sort/Sort.tsx
@@ -39,6 +39,7 @@ const Sort = ({ columnAccessors }: SortProps) => {
<PopoverTrigger asChild>
<IconButton
aria-label="Sort"
+ title="Sort"
variant={hasNoSorts ? "ghost" : "primary"}
icon={<BsSortUp />}
/>
diff --git a/apps/carbon/app/components/Table/components/TableHeader.tsx b/apps/carbon/app/components/Table/components/TableHeader.tsx
index 674be5561f..4427acfa4e 100644
--- a/apps/carbon/app/components/Table/components/TableHeader.tsx
+++ b/apps/carbon/app/components/Table/components/TableHeader.tsx
@@ -58,7 +58,7 @@ const TableHeader = <T extends object>({
return (
<>
- <HStack className="px-4 py-2 justify-between bg-background border-b border-border w-full">
+ <HStack className="px-4 py-2 justify-between bg-card border-b border-border w-full">
<HStack>
<DebouncedInput param="search" size="sm" placeholder="Search" />
{!!filters?.length && <Filter filters={filters} />}
@@ -104,7 +104,7 @@ const TableHeader = <T extends object>({
</HStack>
</HStack>
{currentFilters.length > 0 && (
- <HStack className="px-4 py-1.5 justify-between bg-background border-b border-border w-full">
+ <HStack className="px-4 py-1.5 justify-between bg-card border-b border-border w-full">
<HStack>
<ActiveFilters filters={filters} />
</HStack>
diff --git a/apps/carbon/app/modules/inventory/inventory.service.ts b/apps/carbon/app/modules/inventory/inventory.service.ts
index c37b25baed..0f629d8b5e 100644
--- a/apps/carbon/app/modules/inventory/inventory.service.ts
+++ b/apps/carbon/app/modules/inventory/inventory.service.ts
@@ -30,13 +30,11 @@ export async function getReceipts(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
search: string | null;
- document: string | null;
- location: string | null;
}
) {
let query = client
- .from("receipt")
- .select("*, location(name), supplier(name)", {
+ .from("receipts")
+ .select("*", {
count: "exact",
})
.neq("sourceDocumentId", "");
@@ -47,14 +45,6 @@ export async function getReceipts(
);
}
- if (args.document) {
- query = query.eq("sourceDocument", args.document);
- }
-
- if (args.location) {
- query = query.eq("locationId", args.location);
- }
-
query = setGenericQueryFilters(query, args, [
{ column: "receiptId", ascending: false },
]);
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTable.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTable.tsx
index 444a7e9ccb..ebf1101ee7 100644
--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTable.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTable.tsx
@@ -1,22 +1,36 @@
-import { Enumerable, Hyperlink, MenuIcon, MenuItem } from "@carbon/react";
+import {
+ Checkbox,
+ Enumerable,
+ HStack,
+ Hyperlink,
+ MenuIcon,
+ MenuItem,
+} from "@carbon/react";
import { formatDate } from "@carbon/utils";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
-import { Table } from "~/components";
+import { Avatar, TableNew } from "~/components";
import { usePermissions, useRealtime, useUrlParams } from "~/hooks";
-import type { Receipt, receiptStatusType } from "~/modules/inventory";
-import { ReceiptStatus } from "~/modules/inventory";
+import type { Receipt } from "~/modules/inventory";
+import {
+ ReceiptStatus,
+ receiptSourceDocumentType,
+ receiptStatusType,
+} from "~/modules/inventory";
+import { useSuppliers } from "~/stores";
+import type { ListItem } from "~/types";
import { path } from "~/utils/path";
type ReceiptsTableProps = {
data: Receipt[];
count: number;
+ locations: ListItem[];
};
-const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
+const ReceiptsTable = memo(({ data, count, locations }: ReceiptsTableProps) => {
useRealtime("receipt", `id=in.(${data.map((d) => d.id).join(",")})`);
const [params] = useUrlParams();
@@ -24,6 +38,7 @@ const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
const permissions = usePermissions();
const rows = useMemo(() => data, [data]);
+ const [suppliers] = useSuppliers();
const columns = useMemo<ColumnDef<Receipt>[]>(() => {
const result: ColumnDef<(typeof rows)[number]>[] = [
@@ -31,7 +46,7 @@ const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
accessorKey: "receiptId",
header: "Receipt ID",
cell: ({ row }) => (
- <Hyperlink onClick={() => navigate(row.original.id)}>
+ <Hyperlink onClick={() => navigate(row.original.id!)}>
{row.original.receiptId}
</Hyperlink>
),
@@ -40,6 +55,15 @@ const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
accessorKey: "sourceDocument",
header: "Source Document",
cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: receiptSourceDocumentType.map((type) => ({
+ value: type,
+ label: <Enumerable value={type} />,
+ })),
+ },
+ },
},
{
accessorKey: "sourceDocumentReadableId",
@@ -77,9 +101,32 @@ const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
},
},
{
- accessorKey: "location.name",
+ accessorKey: "locationName",
header: "Location",
+ cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: locations.map(({ name }) => ({
+ value: name,
+ label: <Enumerable value={name} />,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "supplierName",
+ header: "Supplier",
cell: (item) => item.getValue() ?? null,
+ meta: {
+ filter: {
+ type: "static",
+ options: suppliers.map(({ name }) => ({
+ value: name,
+ label: name,
+ })),
+ },
+ },
},
{
accessorKey: "status",
@@ -88,16 +135,75 @@ const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
const status = item.getValue<(typeof receiptStatusType)[number]>();
return <ReceiptStatus status={status} />;
},
+ meta: {
+ filter: {
+ type: "static",
+ options: receiptStatusType.map((type) => ({
+ value: type,
+ label: <ReceiptStatus status={type} />,
+ })),
+ },
+ pluralHeader: "Statuses",
+ },
},
{
accessorKey: "postingDate",
header: "Posting Date",
cell: (item) => formatDate(item.getValue<string>()),
},
+ {
+ accessorKey: "invoiced",
+ header: "Invoiced",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Yes" },
+ { value: "false", label: "No" },
+ ],
+ },
+ pluralHeader: "Invoiced Statuses",
+ },
+ },
+ {
+ accessorKey: "createdByFullName",
+ header: "Created By",
+ cell: ({ row }) => {
+ return (
+ <HStack>
+ <Avatar size="sm" path={row.original.createdByAvatar} />
+ <p>{row.original.createdByFullName}</p>
+ </HStack>
+ );
+ },
+ },
+ {
+ accessorKey: "createdAt",
+ header: "Created At",
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
+ {
+ accessorKey: "updatedByFullName",
+ header: "Updated By",
+ cell: ({ row }) => {
+ return row.original.updatedByFullName ? (
+ <HStack>
+ <Avatar size="sm" path={row.original.updatedByAvatar ?? null} />
+ <p>{row.original.updatedByFullName}</p>
+ </HStack>
+ ) : null;
+ },
+ },
+ {
+ accessorKey: "updatedAt",
+ header: "Updated At",
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
];
return result;
- }, [navigate]);
+ }, [locations, navigate, suppliers]);
const renderContextMenu = useCallback(
(row: Receipt) => {
@@ -106,7 +212,7 @@ const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
<MenuItem
disabled={!permissions.can("update", "inventory")}
onClick={() => {
- navigate(`${path.to.receipt(row.id)}?${params.toString()}`);
+ navigate(`${path.to.receipt(row.id!)}?${params.toString()}`);
}}
>
<MenuIcon icon={<BsFillPenFill />} />
@@ -119,7 +225,9 @@ const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
row.status === "Pending"
}
onClick={() => {
- navigate(`${path.to.deleteReceipt(row.id)}?${params.toString()}`);
+ navigate(
+ `${path.to.deleteReceipt(row.id!)}?${params.toString()}`
+ );
}}
>
<MenuIcon icon={<IoMdTrash />} />
@@ -131,22 +239,19 @@ const ReceiptsTable = memo(({ data, count }: ReceiptsTableProps) => {
[navigate, params, permissions]
);
- const defaultColumnVisibility = {
- location_name: false,
- postingDate: false,
- };
-
return (
- <Table<(typeof data)[number]>
+ <TableNew<(typeof data)[number]>
data={data}
columns={columns}
count={count}
- defaultColumnVisibility={defaultColumnVisibility}
- withColumnOrdering
- withFilters
- withPagination
- withSimpleSorting
+ defaultColumnPinning={{
+ left: ["receiptId"],
+ }}
+ label="Receipt"
+ newPath={path.to.newReceipt}
+ newPermission={permissions.can("create", "inventory")}
renderContextMenu={renderContextMenu}
+ withColumnOrdering
/>
);
});
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters.tsx
deleted file mode 100644
index a10f848043..0000000000
--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-import { HStack } from "@carbon/react";
-import { Combobox, New } from "~/components";
-import { TableFilters } from "~/components/Layout";
-import { DebouncedInput } from "~/components/Search";
-import { usePermissions, useUrlParams } from "~/hooks";
-import { receiptSourceDocumentType } from "~/modules/inventory";
-import type { ListItem } from "~/types";
-
-type ReceiptsTableFiltersProps = {
- locations: ListItem[];
-};
-
-const ReceiptsTableFilters = ({ locations }: ReceiptsTableFiltersProps) => {
- const [params, setParams] = useUrlParams();
- const permissions = usePermissions();
-
- const sourceDocumentOptions = receiptSourceDocumentType.map((type) => ({
- label: type,
- value: type,
- }));
-
- const locationOptions = locations.map(({ id, name }) => ({
- label: name,
- value: id,
- }));
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="search" size="sm" placeholder="Search" />
- <Combobox
- size="sm"
- value={params.get("document") ?? ""}
- isClearable
- options={sourceDocumentOptions}
- onChange={(selected) => {
- setParams({ document: selected });
- }}
- aria-label="Source Document"
- placeholder="Source Document"
- />
- <Combobox
- size="sm"
- value={params.get("location") ?? ""}
- isClearable
- options={locationOptions}
- onChange={(selected) => {
- setParams({ location: selected });
- }}
- placeholder="Location"
- />
- </HStack>
- <HStack>
- {permissions.can("create", "inventory") && (
- <New label="Receipt" to={`new?${params.toString()}`} />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default ReceiptsTableFilters;
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/index.ts b/apps/carbon/app/modules/inventory/ui/Receipts/index.ts
index 6a04fd9ee7..72ecf4e6db 100644
--- a/apps/carbon/app/modules/inventory/ui/Receipts/index.ts
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/index.ts
@@ -1,13 +1,6 @@
import ReceiptForm from "./ReceiptForm";
import ReceiptPostModal from "./ReceiptPostModal";
import ReceiptsTable from "./ReceiptsTable";
-import ReceiptsTableFilters from "./ReceiptsTableFilters";
import ReceiptStatus from "./ReceiptStatus";
-export {
- ReceiptForm,
- ReceiptPostModal,
- ReceiptStatus,
- ReceiptsTable,
- ReceiptsTableFilters,
-};
+export { ReceiptForm, ReceiptPostModal, ReceiptsTable, ReceiptStatus };
diff --git a/apps/carbon/app/routes/x+/inventory+/receipts.tsx b/apps/carbon/app/routes/x+/inventory+/receipts.tsx
index 5842f9c06f..edf58b8e30 100644
--- a/apps/carbon/app/routes/x+/inventory+/receipts.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/receipts.tsx
@@ -2,11 +2,7 @@ import { VStack } from "@carbon/react";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
-import {
- ReceiptsTable,
- ReceiptsTableFilters,
- getReceipts,
-} from "~/modules/inventory";
+import { ReceiptsTable, getReceipts } from "~/modules/inventory";
import { getLocationsList } from "~/modules/resources";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
@@ -29,18 +25,16 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
const search = searchParams.get("search");
- const document = searchParams.get("document");
- const location = searchParams.get("location");
- const { limit, offset, sorts } = getGenericQueryFilters(searchParams);
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
const [receipts, locations] = await Promise.all([
getReceipts(client, {
search,
- document,
- location,
limit,
offset,
sorts,
+ filters,
}),
getLocationsList(client),
]);
@@ -64,8 +58,7 @@ export default function ReceiptsRoute() {
return (
<VStack spacing={0} className="h-full">
- <ReceiptsTableFilters locations={locations ?? []} />
- <ReceiptsTable data={receipts} count={count ?? 0} />
+ <ReceiptsTable data={receipts} count={count ?? 0} locations={locations} />
<Outlet />
</VStack>
);
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 7e36de3986..0f4a3a414c 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -8775,6 +8775,13 @@ export type Database = {
referencedRelation: "receipt"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "receiptLine_receiptId_fkey"
+ columns: ["receiptId"]
+ isOneToOne: false
+ referencedRelation: "receipts"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "receiptLine_receiptId_fkey"
columns: ["receiptId"]
@@ -12337,14 +12344,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -12815,14 +12822,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["id"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["id"]
@@ -13111,6 +13118,133 @@ export type Database = {
},
]
}
+ receipts: {
+ Row: {
+ createdAt: string | null
+ createdBy: string | null
+ createdByAvatar: string | null
+ createdByFullName: string | null
+ externalDocumentId: string | null
+ id: string | null
+ invoiced: boolean | null
+ locationId: string | null
+ locationName: string | null
+ postingDate: string | null
+ receiptId: string | null
+ sourceDocument:
+ | Database["public"]["Enums"]["receiptSourceDocument"]
+ | null
+ sourceDocumentId: string | null
+ sourceDocumentReadableId: string | null
+ status: Database["public"]["Enums"]["receiptStatus"] | null
+ supplierId: string | null
+ supplierName: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ updatedByAvatar: string | null
+ updatedByFullName: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "receipt_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "receipt_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "location"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "partQuantities"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "receipt_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "supplier"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "contractors"
+ referencedColumns: ["supplierId"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "partners"
+ referencedColumns: ["supplierId"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrderSuppliers"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "suppliers"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
receiptsPostedNotInvoiced: {
Row: {
estimatedCost: number | null
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 7e36de3986..0f4a3a414c 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -8775,6 +8775,13 @@ export type Database = {
referencedRelation: "receipt"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "receiptLine_receiptId_fkey"
+ columns: ["receiptId"]
+ isOneToOne: false
+ referencedRelation: "receipts"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "receiptLine_receiptId_fkey"
columns: ["receiptId"]
@@ -12337,14 +12344,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -12815,14 +12822,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["id"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["id"]
@@ -13111,6 +13118,133 @@ export type Database = {
},
]
}
+ receipts: {
+ Row: {
+ createdAt: string | null
+ createdBy: string | null
+ createdByAvatar: string | null
+ createdByFullName: string | null
+ externalDocumentId: string | null
+ id: string | null
+ invoiced: boolean | null
+ locationId: string | null
+ locationName: string | null
+ postingDate: string | null
+ receiptId: string | null
+ sourceDocument:
+ | Database["public"]["Enums"]["receiptSourceDocument"]
+ | null
+ sourceDocumentId: string | null
+ sourceDocumentReadableId: string | null
+ status: Database["public"]["Enums"]["receiptStatus"] | null
+ supplierId: string | null
+ supplierName: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ updatedByAvatar: string | null
+ updatedByFullName: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "receipt_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "receipt_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "location"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "partQuantities"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "receipt_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "supplier"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "contractors"
+ referencedColumns: ["supplierId"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "partners"
+ referencedColumns: ["supplierId"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrderSuppliers"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_supplierId_fkey"
+ columns: ["supplierId"]
+ isOneToOne: false
+ referencedRelation: "suppliers"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "receipt_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
receiptsPostedNotInvoiced: {
Row: {
estimatedCost: number | null
diff --git a/packages/database/supabase/migrations/20230224035103_shifts.sql b/packages/database/supabase/migrations/20230224035103_shifts.sql
index e1cb4c20fa..924a540d83 100644
--- a/packages/database/supabase/migrations/20230224035103_shifts.sql
+++ b/packages/database/supabase/migrations/20230224035103_shifts.sql
@@ -18,6 +18,8 @@ CREATE TABLE "location" (
CONSTRAINT "location_pkey" PRIMARY KEY ("id")
);
+CREATE INDEX "location_name_idx" ON "location" ("name");
+
ALTER TABLE "location" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Employees can view locations" ON "location"
diff --git a/packages/database/supabase/migrations/20230728025201_receipts.sql b/packages/database/supabase/migrations/20230728025201_receipts.sql
index ae1fa5c5d3..483eb12da0 100644
--- a/packages/database/supabase/migrations/20230728025201_receipts.sql
+++ b/packages/database/supabase/migrations/20230728025201_receipts.sql
@@ -140,6 +140,22 @@ CREATE POLICY "Employees with inventory_delete can delete receipt lines" ON "rec
AND (get_my_claim('role'::text)) = '"employee"'::jsonb
);
-
-
-
+CREATE OR REPLACE VIEW "receipts" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ r.*,
+ cb."fullName" as "createdByFullName",
+ cb."avatarUrl" as "createdByAvatar",
+ ub."fullName" as "updatedByFullName",
+ ub."avatarUrl" as "updatedByAvatar",
+ l."name" as "locationName",
+ s."name" as "supplierName"
+ FROM "receipt" r
+ LEFT JOIN "user" cb
+ ON cb.id = r."createdBy"
+ LEFT JOIN "user" ub
+ ON ub.id = r."updatedBy"
+ LEFT JOIN "location" l
+ ON l.id = r."locationId"
+ LEFT JOIN "supplier" s
+ ON s.id = r."supplierId";
+
\ No newline at end of file
diff --git a/packages/react/src/utils/react.ts b/packages/react/src/utils/react.ts
index 4163c6086e..1e5ff9be69 100644
--- a/packages/react/src/utils/react.ts
+++ b/packages/react/src/utils/react.ts
@@ -33,6 +33,9 @@ export const reactNodeToString = function (reactNode: ReactNode): string {
if (reactNode.props.value) {
// for Enumerable component
string += reactNode.props.value;
+ } else if (reactNode.props.status) {
+ // for Status components
+ string += reactNode.props.status;
} else {
string += reactNodeToString(reactNode.props.children);
}