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.

feat: add assignee to purchase orders

Brad Barbin512230368952
diff --git a/apps/carbon/app/modules/parts/parts.service.ts b/apps/carbon/app/modules/parts/parts.service.ts
index 6cd4c3bd55..494762667f 100644
--- a/apps/carbon/app/modules/parts/parts.service.ts
+++ b/apps/carbon/app/modules/parts/parts.service.ts
@@ -1,4 +1,5 @@
import type { Database, Json } from "@carbon/database";
+import { getLocalTimeZone, today } from "@internationalized/date";
import type { SupabaseClient } from "@supabase/supabase-js";
import type { z } from "zod";
import type { GenericQueryFilters } from "~/utils/query";
@@ -362,7 +363,13 @@ export async function upsertPart(
if ("createdBy" in part) {
return client.from("part").insert(part).select("*").single();
}
- return client.from("part").update(sanitize(part)).eq("id", part.id);
+ return client
+ .from("part")
+ .update({
+ ...sanitize(part),
+ updatedAt: today(getLocalTimeZone()).toString(),
+ })
+ .eq("id", part.id);
}
export async function upsertPartCost(
diff --git a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
index 6c0b44e8a3..874c1b4d0e 100644
--- a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
+++ b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
@@ -149,8 +149,9 @@ const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {
<Input name="name" label="Name" />
<PartGroup name="partGroupId" label="Part Group" />
-
- <TextArea name="description" label="Description" />
+ {isEditing && (
+ <TextArea name="description" label="Description" />
+ )}
<Select
name="replenishmentSystem"
label="Replenishment System"
diff --git a/apps/carbon/app/modules/purchasing/purchasing.service.ts b/apps/carbon/app/modules/purchasing/purchasing.service.ts
index 454639ebfe..e39671d7d7 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.service.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.service.ts
@@ -614,7 +614,10 @@ export async function upsertSupplier(
}
return client
.from("supplier")
- .update(sanitize(supplier))
+ .update({
+ ...sanitize(supplier),
+ updatedAt: today(getLocalTimeZone()).toString(),
+ })
.eq("id", supplier.id)
.select("id")
.single();
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderHeader.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderHeader.tsx
index 59b246ee73..5b5f8951a4 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderHeader.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderHeader.tsx
@@ -9,17 +9,21 @@ import {
CardDescription,
CardHeader,
CardTitle,
+ Enumerable,
HStack,
Menubar,
MenubarItem,
VStack,
useDisclosure,
} from "@carbon/react";
+import { formatDate } from "@carbon/utils";
import { useParams } from "@remix-run/react";
import { useMemo } from "react";
+import { Assign, EmployeeAvatar, useOptimisticAssignment } from "~/components";
import { usePermissions, useRouteData } from "~/hooks";
import type { PurchaseOrder } from "~/modules/purchasing";
import { PurchasingStatus, usePurchaseOrderTotals } from "~/modules/purchasing";
+import { useSuppliers } from "~/stores";
import { path } from "~/utils/path";
import { usePurchaseOrder } from "../PurchaseOrders/usePurchaseOrder";
import PurchaseOrderReleaseModal from "./PurchaseOrderReleaseModal";
@@ -50,11 +54,30 @@ const PurchaseOrderHeader = () => {
const { receive, invoice } = usePurchaseOrder();
const releaseDisclosure = useDisclosure();
+ const optimisticAssignment = useOptimisticAssignment({
+ id: orderId,
+ table: "purchaseOrder",
+ });
+ const assignee =
+ optimisticAssignment !== undefined
+ ? optimisticAssignment
+ : routeData?.purchaseOrder?.assignee;
+
+ const [suppliers] = useSuppliers();
+ const supplier = suppliers.find(
+ (s) => s.id === routeData.purchaseOrder?.supplierId
+ );
+
return (
<>
<VStack>
{permissions.is("employee") && (
<Menubar>
+ <Assign
+ id={orderId}
+ table="purchaseOrder"
+ value={assignee ?? undefined}
+ />
<MenubarItem asChild>
<a
target="_blank"
@@ -101,7 +124,7 @@ const PurchaseOrderHeader = () => {
<CardHeader>
<CardTitle>{routeData?.purchaseOrder?.purchaseOrderId}</CardTitle>
<CardDescription>
- {routeData?.purchaseOrder?.supplierName}
+ {supplier ? supplier.name : "-"}
</CardDescription>
</CardHeader>
<CardAction>
@@ -117,35 +140,45 @@ const PurchaseOrderHeader = () => {
<CardContent>
<CardAttributes>
<CardAttribute>
- <CardAttributeLabel>Total</CardAttributeLabel>
+ <CardAttributeLabel>Assignee</CardAttributeLabel>
<CardAttributeValue>
- {formatter.format(purchaseOrderTotals?.total ?? 0)}
+ {assignee ? (
+ <EmployeeAvatar employeeId={assignee ?? null} />
+ ) : (
+ "-"
+ )}
</CardAttributeValue>
</CardAttribute>
+
<CardAttribute>
<CardAttributeLabel>Order Date</CardAttributeLabel>
<CardAttributeValue>
- {routeData?.purchaseOrder?.orderDate}
+ {formatDate(routeData?.purchaseOrder?.orderDate)}
</CardAttributeValue>
</CardAttribute>
<CardAttribute>
<CardAttributeLabel>Promised Date</CardAttributeLabel>
<CardAttributeValue>
- {routeData?.purchaseOrder?.receiptPromisedDate}
+ {formatDate(routeData?.purchaseOrder?.receiptPromisedDate)}
</CardAttributeValue>
</CardAttribute>
<CardAttribute>
<CardAttributeLabel>Type</CardAttributeLabel>
<CardAttributeValue>
- {routeData?.purchaseOrder?.type}
+ <Enumerable value={routeData?.purchaseOrder?.type} />
</CardAttributeValue>
</CardAttribute>
-
<CardAttribute>
<CardAttributeLabel>Status</CardAttributeLabel>
<PurchasingStatus status={routeData?.purchaseOrder?.status} />
</CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Total</CardAttributeLabel>
+ <CardAttributeValue>
+ {formatter.format(purchaseOrderTotals?.total ?? 0)}
+ </CardAttributeValue>
+ </CardAttribute>
</CardAttributes>
</CardContent>
</Card>
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
index d1e4e6eed5..2fab09d9b0 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
@@ -6,13 +6,20 @@ import {
MenuItem,
useDisclosure,
} from "@carbon/react";
+import { formatDate } from "@carbon/utils";
import { useFetcher, useFetchers } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo, useState } from "react";
import { BsFillPenFill, BsPin, BsPinFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
import { MdCallReceived } from "react-icons/md";
-import { Avatar, Hyperlink, New, Table } from "~/components";
+import {
+ EmployeeAvatar,
+ Hyperlink,
+ New,
+ SupplierAvatar,
+ Table,
+} from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
@@ -21,7 +28,7 @@ import {
PurchasingStatus,
purchaseOrderStatusType,
} from "~/modules/purchasing";
-import { useSuppliers } from "~/stores";
+import { usePeople, useSuppliers } from "~/stores";
import { favoriteSchema } from "~/types/validators";
import { path } from "~/utils/path";
import { usePurchaseOrder } from "./usePurchaseOrder";
@@ -39,6 +46,8 @@ const PurchaseOrdersTable = memo(
useState<PurchaseOrder | null>(null);
const deletePurchaseOrderModal = useDisclosure();
+
+ const [people] = usePeople();
const [suppliers] = useSuppliers();
const fetcher = useFetcher();
@@ -109,14 +118,16 @@ const PurchaseOrdersTable = memo(
),
},
{
- accessorKey: "supplierName",
+ accessorKey: "supplierId",
header: "Supplier",
- cell: (item) => item.getValue(),
+ cell: (item) => {
+ return <SupplierAvatar supplierId={item.getValue<string>()} />;
+ },
meta: {
filter: {
type: "static",
options: suppliers?.map((supplier) => ({
- value: supplier.name,
+ value: supplier.id,
label: supplier.name,
})),
},
@@ -151,6 +162,22 @@ const PurchaseOrdersTable = memo(
pluralHeader: "Statuses",
},
},
+ {
+ id: "assignee",
+ header: "Assignee",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.assignee} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
{
accessorKey: "receiptPromisedDate",
header: "Promised Date",
@@ -187,43 +214,51 @@ const PurchaseOrdersTable = memo(
},
},
{
- accessorKey: "createdByFullName",
+ id: "createdBy",
header: "Created By",
- cell: ({ row }) => {
- return (
- <HStack>
- <Avatar size="sm" path={row.original.createdByAvatar} />
- <p>{row.original.createdByFullName}</p>
- </HStack>
- );
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.createdBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
},
},
{
accessorKey: "createdAt",
header: "Created At",
- cell: (item) => item.getValue(),
+ cell: (item) => formatDate(item.getValue<string>()),
},
{
- accessorKey: "updatedByFullName",
+ id: "updatedBy",
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;
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.updatedBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
},
},
{
accessorKey: "updatedAt",
- header: "Updated At",
- cell: (item) => item.getValue(),
+ header: "Created At",
+ cell: (item) => formatDate(item.getValue<string>()),
},
];
return [...defaultColumns, ...customColumns];
- }, [fetcher, suppliers, customColumns]);
+ }, [suppliers, people, customColumns, fetcher]);
const renderContextMenu = useMemo(() => {
// eslint-disable-next-line react/display-name
@@ -273,6 +308,17 @@ const PurchaseOrdersTable = memo(
defaultColumnPinning={{
left: ["purchaseOrderId"],
}}
+ defaultColumnVisibility={{
+ receiptPromisedDate: false,
+ shippingMethodName: false,
+ shippingTermName: false,
+ paymentTermName: false,
+ dropShipment: false,
+ createdBy: false,
+ createdAt: false,
+ updatedBy: false,
+ updatedAt: false,
+ }}
primaryAction={
permissions.can("create", "purchasing") && (
<New label="Purchase Order" to={path.to.newPurchaseOrder} />
diff --git a/apps/carbon/app/modules/resources/ui/Contractors/ContractorForm.tsx b/apps/carbon/app/modules/resources/ui/Contractors/ContractorForm.tsx
index 18299f6534..3715ee5777 100644
--- a/apps/carbon/app/modules/resources/ui/Contractors/ContractorForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Contractors/ContractorForm.tsx
@@ -18,7 +18,6 @@ import type { z } from "zod";
import {
Abilities,
CustomFormFields,
- Employee,
Number,
Submit,
Supplier,
@@ -94,7 +93,6 @@ const ContractorForm = ({ initialValues }: ContractorFormProps) => {
minValue={0}
maxValue={10000}
/>
- <Employee name="assignee" label="Assignee" type="assignee" />
<CustomFormFields table="contractor" />
</VStack>
</DrawerBody>
diff --git a/apps/carbon/app/modules/resources/ui/Contractors/ContractorsTable.tsx b/apps/carbon/app/modules/resources/ui/Contractors/ContractorsTable.tsx
index 906bb0dee8..d4d10e1ef1 100644
--- a/apps/carbon/app/modules/resources/ui/Contractors/ContractorsTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/Contractors/ContractorsTable.tsx
@@ -4,17 +4,11 @@ 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 {
- EmployeeAvatar,
- Hyperlink,
- New,
- SupplierAvatar,
- Table,
-} from "~/components";
+import { Hyperlink, New, SupplierAvatar, Table } from "~/components";
import { usePermissions, useUrlParams } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
import type { Ability, Contractor } from "~/modules/resources";
-import { usePeople, useSuppliers } from "~/stores";
+import { useSuppliers } from "~/stores";
import { path } from "~/utils/path";
type ContractorsTableProps = {
@@ -29,7 +23,6 @@ const ContractorsTable = memo(
const permissions = usePermissions();
const [params] = useUrlParams();
- const [people] = usePeople();
const [suppliers] = useSuppliers();
const customColumns = useCustomColumns<Contractor>("contractor");
@@ -110,26 +103,10 @@ const ContractorsTable = memo(
header: "Hours per Week",
cell: (item) => item.getValue(),
},
- {
- id: "assignee",
- header: "Assignee",
- cell: ({ row }) => (
- <EmployeeAvatar employeeId={row.original.assignee} />
- ),
- meta: {
- filter: {
- type: "static",
- options: people.map((employee) => ({
- value: employee.id,
- label: employee.name,
- })),
- },
- },
- },
];
return [...defaultColumns, ...customColumns];
- }, [suppliers, abilities, people, customColumns, params]);
+ }, [suppliers, abilities, customColumns, params]);
const renderContextMenu = useCallback(
(row: Contractor) => {
diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerHeader.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerHeader.tsx
index 1c37751712..a414b5be81 100644
--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerHeader.tsx
+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerHeader.tsx
@@ -64,7 +64,7 @@ const CustomerHeader = () => {
<Assign
id={customerId}
table="customer"
- value={routeData?.customer?.assignee ?? ""}
+ value={assignee ?? undefined}
/>
</Menubar>
)}
diff --git a/apps/carbon/app/routes/x+/resources+/contractors.$supplierContactId.tsx b/apps/carbon/app/routes/x+/resources+/contractors.$supplierContactId.tsx
index 86fc071f88..bd7cff55f3 100644
--- a/apps/carbon/app/routes/x+/resources+/contractors.$supplierContactId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/contractors.$supplierContactId.tsx
@@ -85,7 +85,6 @@ export default function ContractorRoute() {
supplierId: contractor.supplierId ?? "",
hoursPerWeek: contractor.hoursPerWeek ?? 0,
abilities: contractor.abilityIds ?? ([] as string[]),
- assignee: contractor.assignee ?? "",
...getCustomFields(contractor.customFields),
};
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 37b7daba9a..ef5965ae30 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -1512,7 +1512,6 @@ export type Database = {
contractor: {
Row: {
active: boolean
- assignee: string | null
createdAt: string
createdBy: string
customFields: Json | null
@@ -1523,7 +1522,6 @@ export type Database = {
}
Insert: {
active?: boolean
- assignee?: string | null
createdAt?: string
createdBy: string
customFields?: Json | null
@@ -1534,7 +1532,6 @@ export type Database = {
}
Update: {
active?: boolean
- assignee?: string | null
createdAt?: string
createdBy?: string
customFields?: Json | null
@@ -1544,34 +1541,6 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "employees"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "employeeSummary"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "user"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "userDefaults"
- referencedColumns: ["userId"]
- },
{
foreignKeyName: "contractor_createdBy_fkey"
columns: ["createdBy"]
@@ -7289,6 +7258,7 @@ export type Database = {
}
purchaseOrder: {
Row: {
+ assignee: string | null
closedAt: string | null
closedBy: string | null
createdAt: string
@@ -7309,6 +7279,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ assignee?: string | null
closedAt?: string | null
closedBy?: string | null
createdAt?: string
@@ -7329,6 +7300,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ assignee?: string | null
closedAt?: string | null
closedBy?: string | null
createdAt?: string
@@ -7349,6 +7321,34 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "purchaseOrder_closedBy_fkey"
columns: ["closedBy"]
@@ -13365,7 +13365,6 @@ export type Database = {
Row: {
abilityIds: string[] | null
active: boolean | null
- assignee: string | null
customFields: Json | null
email: string | null
firstName: string | null
@@ -13373,36 +13372,9 @@ export type Database = {
lastName: string | null
supplierContactId: string | null
supplierId: string | null
+ supplierName: string | null
}
Relationships: [
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "user"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "employeeSummary"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "employees"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "userDefaults"
- referencedColumns: ["userId"]
- },
{
foreignKeyName: "contractor_id_fkey"
columns: ["supplierContactId"]
@@ -13866,14 +13838,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -14528,14 +14500,11 @@ export type Database = {
}
purchaseOrders: {
Row: {
+ assignee: string | null
closedAt: string | null
closedBy: string | null
- closedByAvatar: string | null
- closedByFullName: string | null
createdAt: string | null
createdBy: string | null
- createdByAvatar: string | null
- createdByFullName: string | null
customFields: Json | null
dropShipment: boolean | null
favorite: boolean | null
@@ -14555,15 +14524,40 @@ export type Database = {
supplierContactId: string | null
supplierId: string | null
supplierLocationId: string | null
- supplierName: string | null
supplierReference: string | null
type: Database["public"]["Enums"]["purchaseOrderType"] | null
updatedAt: string | null
updatedBy: string | null
- updatedByAvatar: string | null
- updatedByFullName: string | null
}
Relationships: [
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "purchaseOrder_closedBy_fkey"
columns: ["closedBy"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 37b7daba9a..ef5965ae30 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -1512,7 +1512,6 @@ export type Database = {
contractor: {
Row: {
active: boolean
- assignee: string | null
createdAt: string
createdBy: string
customFields: Json | null
@@ -1523,7 +1522,6 @@ export type Database = {
}
Insert: {
active?: boolean
- assignee?: string | null
createdAt?: string
createdBy: string
customFields?: Json | null
@@ -1534,7 +1532,6 @@ export type Database = {
}
Update: {
active?: boolean
- assignee?: string | null
createdAt?: string
createdBy?: string
customFields?: Json | null
@@ -1544,34 +1541,6 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "employees"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "employeeSummary"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "user"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "userDefaults"
- referencedColumns: ["userId"]
- },
{
foreignKeyName: "contractor_createdBy_fkey"
columns: ["createdBy"]
@@ -7289,6 +7258,7 @@ export type Database = {
}
purchaseOrder: {
Row: {
+ assignee: string | null
closedAt: string | null
closedBy: string | null
createdAt: string
@@ -7309,6 +7279,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ assignee?: string | null
closedAt?: string | null
closedBy?: string | null
createdAt?: string
@@ -7329,6 +7300,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ assignee?: string | null
closedAt?: string | null
closedBy?: string | null
createdAt?: string
@@ -7349,6 +7321,34 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "purchaseOrder_closedBy_fkey"
columns: ["closedBy"]
@@ -13365,7 +13365,6 @@ export type Database = {
Row: {
abilityIds: string[] | null
active: boolean | null
- assignee: string | null
customFields: Json | null
email: string | null
firstName: string | null
@@ -13373,36 +13372,9 @@ export type Database = {
lastName: string | null
supplierContactId: string | null
supplierId: string | null
+ supplierName: string | null
}
Relationships: [
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "user"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "employeeSummary"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "employees"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "contractor_assignee_fkey"
- columns: ["assignee"]
- isOneToOne: false
- referencedRelation: "userDefaults"
- referencedColumns: ["userId"]
- },
{
foreignKeyName: "contractor_id_fkey"
columns: ["supplierContactId"]
@@ -13866,14 +13838,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -14528,14 +14500,11 @@ export type Database = {
}
purchaseOrders: {
Row: {
+ assignee: string | null
closedAt: string | null
closedBy: string | null
- closedByAvatar: string | null
- closedByFullName: string | null
createdAt: string | null
createdBy: string | null
- createdByAvatar: string | null
- createdByFullName: string | null
customFields: Json | null
dropShipment: boolean | null
favorite: boolean | null
@@ -14555,15 +14524,40 @@ export type Database = {
supplierContactId: string | null
supplierId: string | null
supplierLocationId: string | null
- supplierName: string | null
supplierReference: string | null
type: Database["public"]["Enums"]["purchaseOrderType"] | null
updatedAt: string | null
updatedBy: string | null
- updatedByAvatar: string | null
- updatedByFullName: string | null
}
Relationships: [
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseOrder_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "purchaseOrder_closedBy_fkey"
columns: ["closedBy"]
diff --git a/packages/database/supabase/migrations/20240324175747_assignee.sql b/packages/database/supabase/migrations/20240324175747_assignee.sql
index 9ea50c32c3..02f3274a44 100644
--- a/packages/database/supabase/migrations/20240324175747_assignee.sql
+++ b/packages/database/supabase/migrations/20240324175747_assignee.sql
@@ -1,9 +1,6 @@
--- ALTER TABLE "account" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
-ALTER TABLE "contractor" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
ALTER TABLE "customer" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
ALTER TABLE "part" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
--- ALTER TABLE "partner" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
--- ALTER TABLE "purchaseOrder" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
+ALTER TABLE "purchaseOrder" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
-- ALTER TABLE "purchaseInvoice" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
-- ALTER TABLE "quote" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
-- ALTER TABLE "receipt" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
@@ -11,42 +8,8 @@ ALTER TABLE "part" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE
-- ALTER TABLE "service" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
ALTER TABLE "supplier" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
--- DROP VIEW "accounts";
--- CREATE OR REPLACE VIEW "accounts" WITH(SECURITY_INVOKER=true) AS
--- SELECT
--- "account".*,
--- (SELECT "category" FROM "accountCategory" WHERE "accountCategory"."id" = "account"."accountCategoryId") AS "accountCategory",
--- (SELECT "name" FROM "accountSubcategory" WHERE "accountSubcategory"."id" = "account"."accountSubcategoryId") AS "accountSubCategory"
--- FROM "account"
--- ;
-
-DROP VIEW "contractors";
-CREATE OR REPLACE VIEW "contractors" WITH(SECURITY_INVOKER=true) AS
- SELECT
- p.id AS "supplierContactId",
- p."active",
- p."hoursPerWeek",
- p."customFields",
- p."assignee",
- s.id AS "supplierId",
- c."firstName",
- c."lastName",
- c."email",
- array_agg(pa."abilityId") AS "abilityIds"
- FROM "contractor" p
- INNER JOIN "supplierContact" sc
- ON sc.id = p.id
- INNER JOIN "supplier" s
- ON s.id = sc."supplierId"
- INNER JOIN "contact" c
- ON c.id = sc."contactId"
- LEFT JOIN "contractorAbility" pa
- ON pa."contractorId" = p.id
- WHERE p."active" = true
- GROUP BY p.id, p.active, p."hoursPerWeek", p."customFields", s.id, c.id, s.name, c."firstName", c."lastName", c."email";
-
DROP VIEW "customers";
-CREATE OR REPLACE VIEW "customers" AS
+CREATE OR REPLACE VIEW "customers" WITH(SECURITY_INVOKER=true) AS
SELECT
c.*,
ct.name AS "type",
@@ -55,42 +18,6 @@ CREATE OR REPLACE VIEW "customers" AS
LEFT JOIN "customerType" ct ON ct.id = c."customerTypeId"
LEFT JOIN "customerStatus" cs ON cs.id = c."customerStatusId";
--- DROP VIEW "documents";
--- CREATE OR REPLACE VIEW "documents" WITH(SECURITY_INVOKER=true) AS
--- SELECT
--- d.*,
--- u."avatarUrl" AS "createdByAvatar",
--- u."fullName" AS "createdByFullName",
--- u2."avatarUrl" AS "updatedByAvatar",
--- u2."fullName" AS "updatedByFullName",
--- ARRAY(SELECT dl.label FROM "documentLabel" dl WHERE dl."documentId" = d.id AND dl."userId" = auth.uid()::text) AS labels,
--- EXISTS(SELECT 1 FROM "documentFavorite" df WHERE df."documentId" = d.id AND df."userId" = auth.uid()::text) AS favorite,
--- (SELECT MAX("createdAt") FROM "documentTransaction" dt WHERE dt."documentId" = d.id) AS "lastActivityAt"
--- FROM "document" d
--- LEFT JOIN "user" u ON u.id = d."createdBy"
--- LEFT JOIN "user" u2 ON u2.id = d."updatedBy";
-
--- DROP VIEW "partners";
--- CREATE OR REPLACE VIEW "partners" WITH(SECURITY_INVOKER=true) AS
--- SELECT
--- p.*,
--- p.id AS "supplierLocationId",
--- a2.name AS "abilityName",
--- s.id AS "supplierId",
--- s.name AS "supplierName",
--- a.city,
--- a.state
--- FROM "partner" p
--- INNER JOIN "supplierLocation" sl
--- ON sl.id = p.id
--- INNER JOIN "supplier" s
--- ON s.id = sl."supplierId"
--- INNER JOIN "address" a
--- ON a.id = sl."addressId"
--- INNER JOIN "ability" a2
--- ON a2.id = p."abilityId"
--- WHERE p."active" = true;
-
DROP VIEW "parts";
CREATE OR REPLACE VIEW "parts" WITH(SECURITY_INVOKER=true) AS
SELECT
@@ -107,37 +34,26 @@ CREATE OR REPLACE VIEW "parts" WITH(SECURITY_INVOKER=true) AS
GROUP BY "partId"
) ps ON ps."partId" = p.id;
--- DROP VIEW "purchaseOrders";
--- CREATE OR REPLACE VIEW "purchaseOrders" WITH(SECURITY_INVOKER=true) AS
--- SELECT
--- p.*,
--- sm."name" AS "shippingMethodName",
--- st."name" AS "shippingTermName",
--- pt."name" AS "paymentTermName",
--- pd."receiptRequestedDate",
--- pd."receiptPromisedDate",
--- pd."dropShipment",
--- l."id" AS "locationId",
--- l."name" AS "locationName",
--- s."name" AS "supplierName",
--- u."avatarUrl" AS "createdByAvatar",
--- u."fullName" AS "createdByFullName",
--- u2."avatarUrl" AS "updatedByAvatar",
--- u2."fullName" AS "updatedByFullName",
--- u3."avatarUrl" AS "closedByAvatar",
--- u3."fullName" AS "closedByFullName",
--- EXISTS(SELECT 1 FROM "purchaseOrderFavorite" pf WHERE pf."purchaseOrderId" = p.id AND pf."userId" = auth.uid()::text) AS favorite
--- FROM "purchaseOrder" p
--- LEFT JOIN "purchaseOrderDelivery" pd ON pd."id" = p."id"
--- LEFT JOIN "shippingMethod" sm ON sm."id" = pd."shippingMethodId"
--- LEFT JOIN "shippingTerm" st ON st."id" = pd."shippingTermId"
--- LEFT JOIN "purchaseOrderPayment" pp ON pp."id" = p."id"
--- LEFT JOIN "paymentTerm" pt ON pt."id" = pp."paymentTermId"
--- LEFT JOIN "location" l ON l."id" = pd."locationId"
--- LEFT JOIN "supplier" s ON s."id" = p."supplierId"
--- LEFT JOIN "user" u ON u."id" = p."createdBy"
--- LEFT JOIN "user" u2 ON u2."id" = p."updatedBy"
--- LEFT JOIN "user" u3 ON u3."id" = p."closedBy";
+DROP VIEW "purchaseOrders";
+CREATE OR REPLACE VIEW "purchaseOrders" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ p.*,
+ sm."name" AS "shippingMethodName",
+ st."name" AS "shippingTermName",
+ pt."name" AS "paymentTermName",
+ pd."receiptRequestedDate",
+ pd."receiptPromisedDate",
+ pd."dropShipment",
+ l."id" AS "locationId",
+ l."name" AS "locationName",
+ EXISTS(SELECT 1 FROM "purchaseOrderFavorite" pf WHERE pf."purchaseOrderId" = p.id AND pf."userId" = auth.uid()::text) AS favorite
+ FROM "purchaseOrder" p
+ LEFT JOIN "purchaseOrderDelivery" pd ON pd."id" = p."id"
+ LEFT JOIN "shippingMethod" sm ON sm."id" = pd."shippingMethodId"
+ LEFT JOIN "shippingTerm" st ON st."id" = pd."shippingTermId"
+ LEFT JOIN "purchaseOrderPayment" pp ON pp."id" = p."id"
+ LEFT JOIN "paymentTerm" pt ON pt."id" = pp."paymentTermId"
+ LEFT JOIN "location" l ON l."id" = pd."locationId";
-- DROP VIEW "purchaseInvoices";
-- CREATE OR REPLACE VIEW "purchaseInvoices" WITH(SECURITY_INVOKER=true) AS
@@ -357,7 +273,7 @@ CREATE OR REPLACE VIEW "parts" WITH(SECURITY_INVOKER=true) AS
-- pg.name;
DROP VIEW "suppliers";
-CREATE OR REPLACE VIEW "suppliers" AS
+CREATE OR REPLACE VIEW "suppliers" WITH(SECURITY_INVOKER=true) AS
SELECT
s.*,
st.name AS "type",