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 invoices

Brad Barbin9f3cd48b2bce
diff --git a/apps/carbon/app/components/SupplierAvatar.tsx b/apps/carbon/app/components/SupplierAvatar.tsx
index d64a0cbef0..96b8ec98c0 100644
--- a/apps/carbon/app/components/SupplierAvatar.tsx
+++ b/apps/carbon/app/components/SupplierAvatar.tsx
@@ -4,6 +4,7 @@ import Avatar from "./Avatar";
const SupplierAvatar = ({ supplierId }: { supplierId: string | null }) => {
const [suppliers] = useSuppliers();
+ console.log({ supplierId });
if (!supplierId) return null;
const supplier = suppliers.find((s) => s.id === supplierId) ?? {
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsx
index b4e4aab62d..4b4ec9fee3 100644
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsx
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader.tsx
@@ -13,8 +13,10 @@ import {
VStack,
useDisclosure,
} from "@carbon/react";
+import { formatDate } from "@carbon/utils";
import { useParams } from "@remix-run/react";
import { useMemo, useState } from "react";
+import { Assign, EmployeeAvatar, useOptimisticAssignment } from "~/components";
import { usePermissions, useRouteData } from "~/hooks";
import { useSupabase } from "~/lib/supabase";
import type { PurchaseInvoice } from "~/modules/invoicing";
@@ -22,6 +24,7 @@ import {
PurchaseInvoicingStatus,
usePurchaseInvoiceTotals,
} from "~/modules/invoicing";
+import { useSuppliers } from "~/stores";
import { path } from "~/utils/path";
import PurchaseInvoicePostModal from "./PurchaseInvoicePostModal";
@@ -73,11 +76,30 @@ const PurchaseInvoiceHeader = () => {
postingModal.onOpen();
};
+ const optimisticAssignment = useOptimisticAssignment({
+ id: invoiceId,
+ table: "purchaseInvoice",
+ });
+ const assignee =
+ optimisticAssignment !== undefined
+ ? optimisticAssignment
+ : routeData?.purchaseInvoice?.assignee;
+
+ const [suppliers] = useSuppliers();
+ const supplier = suppliers.find(
+ (s) => s.id === routeData.purchaseInvoice?.supplierId
+ );
+
return (
<>
<VStack>
{permissions.is("employee") && (
<Menubar>
+ <Assign
+ id={invoiceId}
+ table="purchaseInvoice"
+ value={assignee ?? undefined}
+ />
<MenubarItem
isDisabled={!permissions.can("update", "invoicing") || isPosted}
onClick={showPostModal}
@@ -90,21 +112,40 @@ const PurchaseInvoiceHeader = () => {
<Card>
<CardHeader>
<CardTitle>{purchaseInvoice.invoiceId}</CardTitle>
- <CardDescription>{purchaseInvoice.supplierName}</CardDescription>
+ <CardDescription>{supplier ? supplier.name : "-"}</CardDescription>
</CardHeader>
<CardContent>
<CardAttributes>
<CardAttribute>
- <CardAttributeLabel>Total</CardAttributeLabel>
+ <CardAttributeLabel>Assignee</CardAttributeLabel>
<CardAttributeValue>
- {formatter.format(purchaseInvoiceTotals?.total ?? 0)}
+ {assignee ? (
+ <EmployeeAvatar employeeId={assignee ?? null} />
+ ) : (
+ "-"
+ )}
</CardAttributeValue>
</CardAttribute>
+
+ <CardAttribute>
+ <CardAttributeLabel>Date Due</CardAttributeLabel>
+ <CardAttributeValue>
+ {formatDate(purchaseInvoice.dateDue)}
+ </CardAttributeValue>
+ </CardAttribute>
+
<CardAttribute>
<CardAttributeLabel>Date Issued</CardAttributeLabel>
<CardAttributeValue>
- {purchaseInvoice.dateIssued}
+ {formatDate(purchaseInvoice.dateIssued)}
+ </CardAttributeValue>
+ </CardAttribute>
+
+ <CardAttribute>
+ <CardAttributeLabel>Date Paid</CardAttributeLabel>
+ <CardAttributeValue>
+ {formatDate(purchaseInvoice.datePaid)}
</CardAttributeValue>
</CardAttribute>
@@ -112,6 +153,12 @@ const PurchaseInvoiceHeader = () => {
<CardAttributeLabel>Status</CardAttributeLabel>
<PurchaseInvoicingStatus status={purchaseInvoice.status} />
</CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Total</CardAttributeLabel>
+ <CardAttributeValue>
+ {formatter.format(purchaseInvoiceTotals?.total ?? 0)}
+ </CardAttributeValue>
+ </CardAttribute>
</CardAttributes>
</CardContent>
</Card>
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTable.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTable.tsx
index eb3ba729ad..86803342ee 100644
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTable.tsx
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTable.tsx
@@ -1,11 +1,17 @@
-import { HStack, MenuIcon, MenuItem, useDisclosure } from "@carbon/react";
+import { Enumerable, MenuIcon, MenuItem, useDisclosure } from "@carbon/react";
import { formatDate } from "@carbon/utils";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo, useState } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
-import { Avatar, Hyperlink, New, Table } from "~/components";
+import {
+ EmployeeAvatar,
+ Hyperlink,
+ New,
+ SupplierAvatar,
+ Table,
+} from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions, useRealtime } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
@@ -14,7 +20,7 @@ import {
PurchaseInvoicingStatus,
purchaseInvoiceStatusType,
} from "~/modules/invoicing";
-import { useSuppliers } from "~/stores";
+import { usePeople, useSuppliers } from "~/stores";
import { path } from "~/utils/path";
type PurchaseInvoicesTableProps = {
@@ -29,6 +35,8 @@ const PurchaseInvoicesTable = memo(
`id=in.(${data.map((d) => d.id).join(",")})`
);
+ console.log({ data });
+
const permissions = usePermissions();
const navigate = useNavigate();
@@ -36,6 +44,7 @@ const PurchaseInvoicesTable = memo(
useState<PurchaseInvoice | null>(null);
const closePurchaseInvoiceModal = useDisclosure();
+ const [people] = usePeople();
const [suppliers] = useSuppliers();
const customColumns = useCustomColumns<PurchaseInvoice>("purchaseInvoice");
@@ -51,22 +60,40 @@ const PurchaseInvoicesTable = memo(
),
},
{
- accessorKey: "supplierName",
+ id: "supplierId",
header: "Supplier",
- cell: (item) => item.getValue(),
+ cell: ({ row }) => (
+ <SupplierAvatar supplierId={row.original.supplierId} />
+ ),
meta: {
filter: {
type: "static",
options: suppliers?.map((supplier) => ({
- value: supplier.name,
+ value: supplier.id,
label: supplier.name,
})),
},
},
},
{
- accessorKey: "dateDue",
- header: "Due Date",
+ id: "invoiceSupplierId",
+ header: "Invoice Supplier",
+ cell: ({ row }) => (
+ <SupplierAvatar supplierId={row.original.invoiceSupplierId} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: suppliers?.map((supplier) => ({
+ value: supplier.id,
+ label: supplier.name,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "supplierReference",
+ header: "Supplier Ref.",
cell: (item) => item.getValue(),
},
{
@@ -88,21 +115,56 @@ const PurchaseInvoicesTable = 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: "dateIssued",
header: "Issued Date",
- cell: (item) => item.getValue(),
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
+ {
+ accessorKey: "dateDue",
+ header: "Due Date",
+ cell: (item) => formatDate(item.getValue<string>()),
},
{
- accessorKey: "createdByFullName",
+ accessorKey: "datePaid",
+ header: "Paid Date",
+ cell: (item) => formatDate(item.getValue<string>()),
+ },
+ {
+ accessorKey: "paymentTermName",
+ header: "Payment Method",
+ cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ },
+ {
+ id: "createdBy",
header: "Created By",
- cell: ({ row }) => {
- return (
- <HStack>
- <Avatar size="sm" path={row.original.createdByAvatar} />
- <span>{row.original.createdByFullName}</span>
- </HStack>
- );
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.createdBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
},
},
{
@@ -111,27 +173,30 @@ const PurchaseInvoicesTable = memo(
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} />
- <span>{row.original.updatedByFullName}</span>
- </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",
+ header: "Created At",
cell: (item) => formatDate(item.getValue<string>()),
},
];
return [...defaultColumns, ...customColumns];
- }, [customColumns, suppliers]);
-
+ }, [customColumns, people, suppliers]);
const renderContextMenu = useMemo(() => {
// eslint-disable-next-line react/display-name
@@ -169,6 +234,16 @@ const PurchaseInvoicesTable = memo(
defaultColumnPinning={{
left: ["invoiceId"],
}}
+ defaultColumnVisibility={{
+ invoiceSupplierId: false,
+ paymentTermName: false,
+ dateIssued: false,
+ datePaid: false,
+ createdAt: false,
+ createdBy: false,
+ updatedAt: false,
+ updatedBy: false,
+ }}
primaryAction={
permissions.can("create", "invoicing") && (
<New label="Purchase Invoice" to={path.to.newPurchaseInvoice} />
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
index 2fab09d9b0..d343f817f8 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
@@ -118,10 +118,10 @@ const PurchaseOrdersTable = memo(
),
},
{
- accessorKey: "supplierId",
+ id: "supplierId",
header: "Supplier",
- cell: (item) => {
- return <SupplierAvatar supplierId={item.getValue<string>()} />;
+ cell: ({ row }) => {
+ return <SupplierAvatar supplierId={row.original.supplierId} />;
},
meta: {
filter: {
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index ef5965ae30..20cff17a66 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -6585,6 +6585,7 @@ export type Database = {
}
purchaseInvoice: {
Row: {
+ assignee: string | null
balance: number
createdAt: string
createdBy: string
@@ -6612,6 +6613,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ assignee?: string | null
balance?: number
createdAt?: string
createdBy: string
@@ -6639,6 +6641,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ assignee?: string | null
balance?: number
createdAt?: string
createdBy?: string
@@ -6666,6 +6669,34 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "purchaseInvoice_createdBy_fkey"
columns: ["createdBy"]
@@ -14050,12 +14081,10 @@ export type Database = {
}
purchaseInvoices: {
Row: {
+ assignee: string | null
balance: number | null
- contactName: string | null
createdAt: string | null
createdBy: string | null
- createdByAvatar: string | null
- createdByFullName: string | null
currencyCode: string | null
customFields: Json | null
dateDue: string | null
@@ -14064,25 +14093,49 @@ export type Database = {
exchangeRate: number | null
id: string | null
invoiceId: string | null
- invoiceSupplierContactId: string | null
invoiceSupplierId: string | null
- invoiceSupplierLocationId: string | null
paymentTermId: string | null
+ paymentTermName: string | null
postingDate: string | null
status: Database["public"]["Enums"]["purchaseInvoiceStatus"] | null
subtotal: number | null
supplierId: string | null
- supplierName: string | null
supplierReference: string | null
totalAmount: number | null
totalDiscount: number | null
totalTax: number | null
updatedAt: string | null
updatedBy: string | null
- updatedByAvatar: string | null
- updatedByFullName: string | null
}
Relationships: [
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "purchaseInvoice_createdBy_fkey"
columns: ["createdBy"]
@@ -14118,13 +14171,6 @@ export type Database = {
referencedRelation: "currency"
referencedColumns: ["code"]
},
- {
- foreignKeyName: "purchaseInvoice_invoiceSupplierContactId_fkey"
- columns: ["invoiceSupplierContactId"]
- isOneToOne: false
- referencedRelation: "supplierContact"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "purchaseInvoice_invoiceSupplierId_fkey"
columns: ["invoiceSupplierId"]
@@ -14160,13 +14206,6 @@ export type Database = {
referencedRelation: "suppliers"
referencedColumns: ["id"]
},
- {
- foreignKeyName: "purchaseInvoice_invoiceSupplierLocationId_fkey"
- columns: ["invoiceSupplierLocationId"]
- isOneToOne: false
- referencedRelation: "supplierLocation"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "purchaseInvoice_paymentTermId_fkey"
columns: ["paymentTermId"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index ef5965ae30..20cff17a66 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -6585,6 +6585,7 @@ export type Database = {
}
purchaseInvoice: {
Row: {
+ assignee: string | null
balance: number
createdAt: string
createdBy: string
@@ -6612,6 +6613,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ assignee?: string | null
balance?: number
createdAt?: string
createdBy: string
@@ -6639,6 +6641,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ assignee?: string | null
balance?: number
createdAt?: string
createdBy?: string
@@ -6666,6 +6669,34 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "purchaseInvoice_createdBy_fkey"
columns: ["createdBy"]
@@ -14050,12 +14081,10 @@ export type Database = {
}
purchaseInvoices: {
Row: {
+ assignee: string | null
balance: number | null
- contactName: string | null
createdAt: string | null
createdBy: string | null
- createdByAvatar: string | null
- createdByFullName: string | null
currencyCode: string | null
customFields: Json | null
dateDue: string | null
@@ -14064,25 +14093,49 @@ export type Database = {
exchangeRate: number | null
id: string | null
invoiceId: string | null
- invoiceSupplierContactId: string | null
invoiceSupplierId: string | null
- invoiceSupplierLocationId: string | null
paymentTermId: string | null
+ paymentTermName: string | null
postingDate: string | null
status: Database["public"]["Enums"]["purchaseInvoiceStatus"] | null
subtotal: number | null
supplierId: string | null
- supplierName: string | null
supplierReference: string | null
totalAmount: number | null
totalDiscount: number | null
totalTax: number | null
updatedAt: string | null
updatedBy: string | null
- updatedByAvatar: string | null
- updatedByFullName: string | null
}
Relationships: [
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "purchaseInvoice_assignee_fkey"
+ columns: ["assignee"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "purchaseInvoice_createdBy_fkey"
columns: ["createdBy"]
@@ -14118,13 +14171,6 @@ export type Database = {
referencedRelation: "currency"
referencedColumns: ["code"]
},
- {
- foreignKeyName: "purchaseInvoice_invoiceSupplierContactId_fkey"
- columns: ["invoiceSupplierContactId"]
- isOneToOne: false
- referencedRelation: "supplierContact"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "purchaseInvoice_invoiceSupplierId_fkey"
columns: ["invoiceSupplierId"]
@@ -14160,13 +14206,6 @@ export type Database = {
referencedRelation: "suppliers"
referencedColumns: ["id"]
},
- {
- foreignKeyName: "purchaseInvoice_invoiceSupplierLocationId_fkey"
- columns: ["invoiceSupplierLocationId"]
- isOneToOne: false
- referencedRelation: "supplierLocation"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "purchaseInvoice_paymentTermId_fkey"
columns: ["paymentTermId"]
diff --git a/packages/database/supabase/migrations/20240324175747_assignee.sql b/packages/database/supabase/migrations/20240324175747_assignee.sql
index 02f3274a44..09369d3077 100644
--- a/packages/database/supabase/migrations/20240324175747_assignee.sql
+++ b/packages/database/supabase/migrations/20240324175747_assignee.sql
@@ -1,7 +1,7 @@
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 "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 "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;
@@ -55,49 +55,39 @@ CREATE OR REPLACE VIEW "purchaseOrders" WITH(SECURITY_INVOKER=true) AS
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
--- SELECT
--- pi."id",
--- pi."invoiceId",
--- pi."supplierId",
--- pi."supplierReference",
--- pi."invoiceSupplierId",
--- pi."invoiceSupplierLocationId",
--- pi."invoiceSupplierContactId",
--- pi."postingDate",
--- pi."dateIssued",
--- pi."dateDue",
--- pi."datePaid",
--- pi."paymentTermId",
--- pi."currencyCode",
--- pi."exchangeRate",
--- pi."subtotal",
--- pi."totalDiscount",
--- pi."totalAmount",
--- pi."totalTax",
--- pi."balance",
--- pi."createdBy",
--- pi."createdAt",
--- pi."updatedBy",
--- pi."updatedAt",
--- pi."customFields",
--- CASE
--- WHEN pi."dateDue" < CURRENT_DATE AND pi."status" = 'Submitted' THEN 'Overdue'
--- ELSE pi."status"
--- END AS status,
--- s."name" AS "supplierName",
--- c."fullName" AS "contactName",
--- u."avatarUrl" AS "createdByAvatar",
--- u."fullName" AS "createdByFullName",
--- u2."avatarUrl" AS "updatedByAvatar",
--- u2."fullName" AS "updatedByFullName"
--- FROM "purchaseInvoice" pi
--- LEFT JOIN "supplier" s ON s.id = pi."supplierId"
--- LEFT JOIN "supplierContact" sc ON sc.id = pi."invoiceSupplierContactId"
--- LEFT JOIN "contact" c ON c.id = sc."contactId"
--- LEFT JOIN "user" u ON u."id" = pi."createdBy"
--- LEFT JOIN "user" u2 ON u2."id" = pi."updatedBy";
+DROP VIEW "purchaseInvoices";
+CREATE OR REPLACE VIEW "purchaseInvoices" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ pi."id",
+ pi."invoiceId",
+ pi."supplierId",
+ pi."supplierReference",
+ pi."invoiceSupplierId",
+ pi."postingDate",
+ pi."dateIssued",
+ pi."dateDue",
+ pi."datePaid",
+ pi."paymentTermId",
+ pi."currencyCode",
+ pi."exchangeRate",
+ pi."subtotal",
+ pi."totalDiscount",
+ pi."totalAmount",
+ pi."totalTax",
+ pi."balance",
+ pi."assignee",
+ pi."createdBy",
+ pi."createdAt",
+ pi."updatedBy",
+ pi."updatedAt",
+ pi."customFields",
+ CASE
+ WHEN pi."dateDue" < CURRENT_DATE AND pi."status" = 'Submitted' THEN 'Overdue'
+ ELSE pi."status"
+ END AS status,
+ pt."name" AS "paymentTermName"
+ FROM "purchaseInvoice" pi
+ LEFT JOIN "paymentTerm" pt ON pt."id" = pi."paymentTermId";
-- DROP VIEW "quotes";
-- CREATE OR REPLACE VIEW "quotes" WITH(SECURITY_INVOKER=true) AS