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 supplier table

Brad Barbinf7b88649c144
diff --git a/apps/carbon/app/modules/purchasing/purchasing.models.ts b/apps/carbon/app/modules/purchasing/purchasing.models.ts
index 4adcfca910..9fbb91f4c5 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.models.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.models.ts
@@ -212,6 +212,7 @@ export const supplierValidator = z.object({
supplierStatusId: zfd.text(z.string().optional()),
taxId: zfd.text(z.string().optional()),
accountManagerId: zfd.text(z.string().optional()),
+ assignee: zfd.text(z.string().optional()),
});
export const supplierContactValidator = z.object({
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
index 65d63bf722..3f979453e2 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
@@ -92,7 +92,7 @@ const SupplierForm = ({
/>
<Employee name="accountManagerId" label="Account Manager" />
-
+ <Employee name="assignee" label="Assignee" type="assignee" />
<CustomFormFields table="supplier" />
</div>
</ModalCardBody>
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierHeader.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierHeader.tsx
index ddc1e184cd..8777c8b15a 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierHeader.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierHeader.tsx
@@ -8,10 +8,13 @@ import {
CardContent,
CardHeader,
CardTitle,
+ Enumerable,
HStack,
VStack,
} from "@carbon/react";
+
import { useParams } from "@remix-run/react";
+import { EmployeeAvatar } from "~/components";
import { useRouteData } from "~/hooks";
import type {
SupplierDetail,
@@ -27,13 +30,20 @@ const SupplierHeader = () => {
const routeData = useRouteData<{ supplier: SupplierDetail }>(
path.to.supplier(supplierId)
);
-
const sharedSupplierData = useRouteData<{
supplierTypes: SupplierType[];
supplierStatuses: SupplierStatus[];
paymentTerms: ListItem[];
}>(path.to.supplierRoot);
+ const supplierStatus = sharedSupplierData?.supplierStatuses?.find(
+ (status) => status.id === routeData?.supplier?.supplierStatusId
+ )?.name;
+
+ const supplierType = sharedSupplierData?.supplierTypes?.find(
+ (type) => type.id === routeData?.supplier?.supplierTypeId
+ )?.name;
+
return (
<VStack>
<Card>
@@ -42,11 +52,7 @@ const SupplierHeader = () => {
<CardTitle>{routeData?.supplier?.name}</CardTitle>
</CardHeader>
<CardAction>
- {/* <Button
- variant="secondary"
- onClick={() => alert("TODO")}
- leftIcon={<FaHistory />}
- >
+ {/* <Button onClick={() => alert("TODO")} leftIcon={<FaHistory />}>
Supplier Details
</Button> */}
</CardAction>
@@ -54,25 +60,40 @@ const SupplierHeader = () => {
<CardContent>
<CardAttributes>
<CardAttribute>
- <CardAttributeLabel>Type</CardAttributeLabel>
+ <CardAttributeLabel>Account Manager</CardAttributeLabel>
<CardAttributeValue>
- {sharedSupplierData?.supplierTypes?.find(
- (type) => type.id === routeData?.supplier?.supplierTypeId
- )?.name ?? "-"}
+ {routeData?.supplier?.accountManagerId ? (
+ <EmployeeAvatar
+ employeeId={routeData?.supplier?.accountManagerId ?? null}
+ />
+ ) : (
+ "-"
+ )}
</CardAttributeValue>
</CardAttribute>
<CardAttribute>
- <CardAttributeLabel>Status</CardAttributeLabel>
+ <CardAttributeLabel>Assignee</CardAttributeLabel>
+ <CardAttributeValue>
+ {routeData?.supplier?.assignee ? (
+ <EmployeeAvatar
+ employeeId={routeData?.supplier?.assignee ?? null}
+ />
+ ) : (
+ "-"
+ )}
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Type</CardAttributeLabel>
<CardAttributeValue>
- {sharedSupplierData?.supplierStatuses?.find(
- (status) =>
- status.id === routeData?.supplier?.supplierStatusId
- )?.name ?? "-"}
+ {supplierType ? <Enumerable value={supplierType!} /> : "-"}
</CardAttributeValue>
</CardAttribute>
<CardAttribute>
- <CardAttributeLabel>Payment Terms</CardAttributeLabel>
- <CardAttributeValue>-</CardAttributeValue>
+ <CardAttributeLabel>Status</CardAttributeLabel>
+ <CardAttributeValue>
+ {supplierStatus ? <Enumerable value={supplierStatus!} /> : "-"}
+ </CardAttributeValue>
</CardAttribute>
</CardAttributes>
</CardContent>
diff --git a/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx b/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx
index 996d39e77d..d1fbb5b0ba 100644
--- a/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx
@@ -1,9 +1,10 @@
import { Button, Enumerable, 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, useMemo } from "react";
import { BsFillPenFill } from "react-icons/bs";
-import { Hyperlink, New, Table } from "~/components";
+import { EmployeeAvatar, Hyperlink, New, Table } from "~/components";
import { usePermissions } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
import type {
@@ -11,6 +12,7 @@ import type {
SupplierStatus,
SupplierType,
} from "~/modules/purchasing";
+import { usePeople } from "~/stores";
import { path } from "~/utils/path";
type SuppliersTableProps = {
@@ -24,6 +26,7 @@ const SuppliersTable = memo(
({ data, count, supplierStatuses, supplierTypes }: SuppliersTableProps) => {
const navigate = useNavigate();
const permissions = usePermissions();
+ const [people] = usePeople();
const customColumns = useCustomColumns<Supplier>("supplier");
const columns = useMemo<ColumnDef<Supplier>[]>(() => {
@@ -37,6 +40,38 @@ const SuppliersTable = memo(
</Hyperlink>
),
},
+ {
+ id: "accountManagerId",
+ header: "Updated By",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.accountManagerId} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
+ {
+ 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: "type",
header: "Supplier Type",
@@ -95,9 +130,52 @@ const SuppliersTable = memo(
</Button>
),
},
+ {
+ id: "createdBy",
+ header: "Created By",
+ 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) => formatDate(item.getValue<string>()),
+ },
+ {
+ id: "updatedBy",
+ header: "Updated By",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.updatedBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "updatedAt",
+ header: "Created At",
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
];
+
return [...defaultColumns, ...customColumns];
- }, [navigate, supplierStatuses, supplierTypes, customColumns]);
+ }, [supplierTypes, supplierStatuses, people, customColumns]);
const renderContextMenu = useMemo(
// eslint-disable-next-line react/display-name
@@ -117,12 +195,22 @@ const SuppliersTable = memo(
count={count}
columns={columns}
data={data}
+ defaultColumnPinning={{
+ left: ["name"],
+ }}
+ defaultColumnVisibility={{
+ createdBy: false,
+ createdAt: false,
+ updatedBy: false,
+ updatedAt: false,
+ }}
primaryAction={
permissions.can("create", "purchasing") && (
<New label="Supplier" to={path.to.newSupplier} />
)
}
renderContextMenu={renderContextMenu}
+ withColumnOrdering
/>
</>
);
diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerHeader.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerHeader.tsx
index 6e5164b66e..28ec4e3c01 100644
--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerHeader.tsx
+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerHeader.tsx
@@ -62,17 +62,25 @@ const CustomerHeader = () => {
<CardAttribute>
<CardAttributeLabel>Account Manager</CardAttributeLabel>
<CardAttributeValue>
- <EmployeeAvatar
- employeeId={routeData?.customer?.accountManagerId ?? null}
- />
+ {routeData?.customer?.accountManagerId ? (
+ <EmployeeAvatar
+ employeeId={routeData?.customer?.accountManagerId ?? null}
+ />
+ ) : (
+ "-"
+ )}
</CardAttributeValue>
</CardAttribute>
<CardAttribute>
<CardAttributeLabel>Assignee</CardAttributeLabel>
<CardAttributeValue>
- <EmployeeAvatar
- employeeId={routeData?.customer?.assignee ?? null}
- />
+ {routeData?.customer?.assignee ? (
+ <EmployeeAvatar
+ employeeId={routeData?.customer?.assignee ?? null}
+ />
+ ) : (
+ "-"
+ )}
</CardAttributeValue>
</CardAttribute>
<CardAttribute>
diff --git a/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx b/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx
index 06aab62cfe..58cd4fe076 100644
--- a/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx
+++ b/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx
@@ -100,7 +100,7 @@ const CustomersTable = memo(
id: "createdBy",
header: "Created By",
cell: ({ row }) => (
- <EmployeeAvatar employeeId={row.original.accountManagerId} />
+ <EmployeeAvatar employeeId={row.original.createdBy} />
),
meta: {
filter: {
@@ -121,7 +121,7 @@ const CustomersTable = memo(
id: "updatedBy",
header: "Updated By",
cell: ({ row }) => (
- <EmployeeAvatar employeeId={row.original.accountManagerId} />
+ <EmployeeAvatar employeeId={row.original.updatedBy} />
),
meta: {
filter: {
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.details.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.details.tsx
index b3bf6d86c4..6e4c4b2a76 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.details.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.details.tsx
@@ -70,6 +70,7 @@ export default function SupplierEditRoute() {
supplierStatusId: routeData?.supplier?.supplierStatusId ?? undefined,
accountManagerId: routeData?.supplier?.accountManagerId ?? undefined,
taxId: routeData?.supplier?.taxId ?? "",
+ assignee: routeData?.supplier?.assignee ?? undefined,
...getCustomFields(routeData?.supplier?.customFields),
};
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index f2065b4124..1ca117b3b3 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -15439,17 +15439,109 @@ export type Database = {
}
suppliers: {
Row: {
+ accountManagerId: string | null
+ assignee: string | null
+ createdAt: string | null
+ createdBy: string | null
customFields: Json | null
id: string | null
+ logo: string | null
name: string | null
orderCount: number | null
partCount: number | null
status: string | null
supplierStatusId: string | null
supplierTypeId: string | null
+ taxId: string | null
type: string | null
+ updatedAt: string | null
+ updatedBy: string | null
}
Relationships: [
+ {
+ foreignKeyName: "supplier_accountManagerId_fkey"
+ columns: ["accountManagerId"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_accountManagerId_fkey"
+ columns: ["accountManagerId"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_accountManagerId_fkey"
+ columns: ["accountManagerId"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_accountManagerId_fkey"
+ columns: ["accountManagerId"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "supplier_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "supplier_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "supplier_supplierStatusId_fkey"
columns: ["supplierStatusId"]
@@ -15464,6 +15556,34 @@ export type Database = {
referencedRelation: "supplierType"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "supplier_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
]
}
totalReceiptsPostedNotInvoiced: {
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index f2065b4124..1ca117b3b3 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -15439,17 +15439,109 @@ export type Database = {
}
suppliers: {
Row: {
+ accountManagerId: string | null
+ assignee: string | null
+ createdAt: string | null
+ createdBy: string | null
customFields: Json | null
id: string | null
+ logo: string | null
name: string | null
orderCount: number | null
partCount: number | null
status: string | null
supplierStatusId: string | null
supplierTypeId: string | null
+ taxId: string | null
type: string | null
+ updatedAt: string | null
+ updatedBy: string | null
}
Relationships: [
+ {
+ foreignKeyName: "supplier_accountManagerId_fkey"
+ columns: ["accountManagerId"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_accountManagerId_fkey"
+ columns: ["accountManagerId"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_accountManagerId_fkey"
+ columns: ["accountManagerId"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_accountManagerId_fkey"
+ columns: ["accountManagerId"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "supplier_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "supplier_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "supplier_supplierStatusId_fkey"
columns: ["supplierStatusId"]
@@ -15464,6 +15556,34 @@ export type Database = {
referencedRelation: "supplierType"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "supplier_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "supplier_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
]
}
totalReceiptsPostedNotInvoiced: {
diff --git a/packages/database/supabase/migrations/20240324175747_assignee.sql b/packages/database/supabase/migrations/20240324175747_assignee.sql
index fe451ea383..6ec341dfbe 100644
--- a/packages/database/supabase/migrations/20240324175747_assignee.sql
+++ b/packages/database/supabase/migrations/20240324175747_assignee.sql
@@ -1,24 +1,24 @@
-ALTER TABLE "account" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
+-- 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 "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;
-ALTER TABLE "requestForQuote" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
-ALTER TABLE "service" 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 "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;
+-- ALTER TABLE "requestForQuote" ADD COLUMN "assignee" TEXT REFERENCES "user" ("id") ON DELETE SET NULL;
+-- 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 "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
@@ -366,31 +366,28 @@ CREATE OR REPLACE VIEW "customers" AS
-- s."customFields",
-- pg.name;
--- CREATE OR REPLACE VIEW "suppliers" AS
--- SELECT
--- s.id,
--- s.name,
--- s."supplierTypeId",
--- st.name AS "type",
--- s."supplierStatusId",
--- ss.name AS "status",
--- po.count AS "orderCount",
--- p.count AS "partCount",
--- s."customFields"
--- FROM "supplier" s
--- LEFT JOIN "supplierType" st ON st.id = s."supplierTypeId"
--- LEFT JOIN "supplierStatus" ss ON ss.id = s."supplierStatusId"
--- LEFT JOIN (
--- SELECT
--- "supplierId",
--- COUNT(*) AS "count"
--- FROM "purchaseOrder"
--- GROUP BY "supplierId"
--- ) po ON po."supplierId" = s.id
--- LEFT JOIN (
--- SELECT
--- "supplierId",
--- COUNT(*) AS "count"
--- FROM "partSupplier"
--- GROUP BY "supplierId"
--- ) p ON p."supplierId" = s.id;
\ No newline at end of file
+DROP VIEW "suppliers";
+CREATE OR REPLACE VIEW "suppliers" AS
+ SELECT
+ s.*,
+ st.name AS "type",
+ ss.name AS "status",
+ po.count AS "orderCount",
+ p.count AS "partCount"
+ FROM "supplier" s
+ LEFT JOIN "supplierType" st ON st.id = s."supplierTypeId"
+ LEFT JOIN "supplierStatus" ss ON ss.id = s."supplierStatusId"
+ LEFT JOIN (
+ SELECT
+ "supplierId",
+ COUNT(*) AS "count"
+ FROM "purchaseOrder"
+ GROUP BY "supplierId"
+ ) po ON po."supplierId" = s.id
+ LEFT JOIN (
+ SELECT
+ "supplierId",
+ COUNT(*) AS "count"
+ FROM "partSupplier"
+ GROUP BY "supplierId"
+ ) p ON p."supplierId" = s.id;
\ No newline at end of file