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: notify sales person when quote expires

Brad Barbin2e3a41f577da
diff --git a/apps/carbon/app/components/CadModel.tsx b/apps/carbon/app/components/CadModel.tsx
index 0546fc5649..0c0d80f38d 100644
--- a/apps/carbon/app/components/CadModel.tsx
+++ b/apps/carbon/app/components/CadModel.tsx
@@ -186,6 +186,7 @@ const CadModel = ({
{() => {
return file || modelPath ? (
<ModelViewer
+ key={modelPath}
file={file}
url={modelPath ? getPrivateUrl(modelPath) : null}
mode={mode}
diff --git a/apps/carbon/app/components/Layout/Topbar/Notifications.tsx b/apps/carbon/app/components/Layout/Topbar/Notifications.tsx
index 96d9d2f5c5..e120ddc6f5 100644
--- a/apps/carbon/app/components/Layout/Topbar/Notifications.tsx
+++ b/apps/carbon/app/components/Layout/Topbar/Notifications.tsx
@@ -18,6 +18,7 @@ import { Link } from "@remix-run/react";
import { useEffect, useState } from "react";
import {
LuBell,
+ LuCalendarX,
LuDollarSign,
LuHammer,
LuInbox,
@@ -160,6 +161,14 @@ function GenericNotification({
{...props}
/>
);
+ case NotificationEvent.QuoteExpired:
+ return (
+ <Notification
+ icon={<LuCalendarX />}
+ to={path.to.quoteDetails(id)}
+ {...props}
+ />
+ );
default:
return null;
}
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index c99525df98..18a29ff657 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -521,6 +521,7 @@ export const salesOrderValidator = z.object({
currencyCode: zfd.text(z.string()),
exchangeRate: zfd.numeric(z.number().optional()),
exchangeRateUpdatedAt: zfd.text(z.string().optional()),
+ salesPersonId: zfd.text(z.string().optional()),
});
export const salesOrderShipmentValidator = z
@@ -660,6 +661,7 @@ export const salesRfqValidator = z.object({
locationId: zfd.text(z.string().optional()),
rfqDate: z.string().min(1, { message: "Order Date is required" }),
status: z.enum(salesRFQStatusType).optional(),
+ salesPersonId: zfd.text(z.string().optional()),
});
export const salesRfqDragValidator = z.object({
diff --git a/apps/carbon/app/modules/sales/ui/Opportunity/OpportunityState.tsx b/apps/carbon/app/modules/sales/ui/Opportunity/OpportunityState.tsx
index 9d88fa0243..16e41e91b2 100644
--- a/apps/carbon/app/modules/sales/ui/Opportunity/OpportunityState.tsx
+++ b/apps/carbon/app/modules/sales/ui/Opportunity/OpportunityState.tsx
@@ -95,13 +95,9 @@ const OpportunityState = ({ opportunity }: { opportunity: Opportunity }) => {
{getStateIcon(isCompleted)({
className: cn(
"w-8 h-8 muted-foreground",
- isStarted &&
- isCurrent &&
- "text-emerald-100 dark:text-emerald-400",
- isStarted &&
- !isCurrent &&
- "text-emerald-600 dark:text-emerald-400",
- !isStarted && "text-muted-foreground"
+ isStarted && isCurrent
+ ? "text-emerald-100 dark:text-emerald-400"
+ : "text-muted-foreground"
),
})}
</div>
diff --git a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderForm.tsx b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderForm.tsx
index 004f4108a2..dbb47f4738 100644
--- a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderForm.tsx
@@ -22,6 +22,7 @@ import {
CustomerContact,
CustomerLocation,
DatePicker,
+ Employee,
Hidden,
Input,
Location,
@@ -150,6 +151,8 @@ const SalesOrderForm = ({ initialValues }: SalesOrderFormProps) => {
<Location name="locationId" label="Sales Location" />
+ <Employee name="salesPersonId" label="Sales Person" />
+
<Currency
name="currencyCode"
label="Currency"
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx
index dcc201a35c..2b93335ab0 100644
--- a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx
@@ -17,6 +17,7 @@ import {
CustomerContact,
CustomerLocation,
DatePicker,
+ Employee,
Hidden,
Input,
Location,
@@ -100,6 +101,7 @@ const SalesRFQForm = ({ initialValues }: SalesRFQFormProps) => {
isDisabled={isCustomer}
/>
<Location name="locationId" label="RFQ Location" />
+ <Employee name="salesPersonId" label="Sales Person" isOptional />
<CustomFormFields table="salesRfq" />
</div>
</VStack>
diff --git a/apps/carbon/app/novu/workflows.ts b/apps/carbon/app/novu/workflows.ts
index 9e0ce2062a..ca889a1fb4 100644
--- a/apps/carbon/app/novu/workflows.ts
+++ b/apps/carbon/app/novu/workflows.ts
@@ -44,3 +44,14 @@ export const digitalQuoteResponseWorkflow = workflow(
payloadSchema,
}
);
+
+export const expirationWorkflow = workflow(
+ NotificationWorkflow.Expiration,
+ async ({ payload, step }) => {
+ await step.inApp(NotificationType.ExpirationInApp, () => ({
+ body: "Expired",
+ payload,
+ }));
+ },
+ { payloadSchema }
+);
diff --git a/apps/carbon/app/routes/api+/novu.ts b/apps/carbon/app/routes/api+/novu.ts
index 327026e98f..cd110f5e0d 100644
--- a/apps/carbon/app/routes/api+/novu.ts
+++ b/apps/carbon/app/routes/api+/novu.ts
@@ -2,10 +2,15 @@ import { serve } from "@novu/framework/remix";
import {
assignmentWorkflow,
digitalQuoteResponseWorkflow,
+ expirationWorkflow,
} from "~/novu/workflows";
const handler = serve({
- workflows: [assignmentWorkflow, digitalQuoteResponseWorkflow],
+ workflows: [
+ assignmentWorkflow,
+ digitalQuoteResponseWorkflow,
+ expirationWorkflow,
+ ],
});
export const config = {
diff --git a/apps/carbon/app/routes/file+/model+/$id.tsx b/apps/carbon/app/routes/file+/model+/$id.tsx
index 73fdf6f95c..0f455426f2 100644
--- a/apps/carbon/app/routes/file+/model+/$id.tsx
+++ b/apps/carbon/app/routes/file+/model+/$id.tsx
@@ -27,6 +27,7 @@ export default function ModelRoute() {
<div className="w-screen h-screen bg-white p-0 m-0">
<ModelViewer
mode="light"
+ key={model.modelPath}
file={null}
url={getPublicModelUrl(model.modelPath)}
/>
diff --git a/apps/carbon/app/routes/x+/quote+/new.tsx b/apps/carbon/app/routes/x+/quote+/new.tsx
index 817b2b8129..9cad2592a3 100644
--- a/apps/carbon/app/routes/x+/quote+/new.tsx
+++ b/apps/carbon/app/routes/x+/quote+/new.tsx
@@ -66,7 +66,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function QuoteNewRoute() {
- const { defaults } = useUser();
+ const { id: userId, defaults } = useUser();
const [params] = useUrlParams();
const customerId = params.get("customerId");
const initialValues = {
@@ -80,6 +80,7 @@ export default function QuoteNewRoute() {
locationId: defaults?.locationId ?? "",
quoteId: undefined,
status: "Draft" as QuotationStatusType,
+ salesPersonId: userId,
currencyCode: undefined,
exchangeRate: undefined,
exchangeRateUpdatedAt: "",
diff --git a/apps/carbon/app/routes/x+/sales-order+/$orderId.details.tsx b/apps/carbon/app/routes/x+/sales-order+/$orderId.details.tsx
index a2f09ff2a5..fdab54fc69 100644
--- a/apps/carbon/app/routes/x+/sales-order+/$orderId.details.tsx
+++ b/apps/carbon/app/routes/x+/sales-order+/$orderId.details.tsx
@@ -166,6 +166,7 @@ export default function SalesOrderRoute() {
exchangeRate: orderData?.salesOrder?.exchangeRate ?? undefined,
exchangeRateUpdatedAt: orderData?.salesOrder?.exchangeRateUpdatedAt ?? "",
originatedFromQuote: originatedFromQuote,
+ salesPersonId: orderData?.salesOrder?.salesPersonId ?? "",
...getCustomFields(orderData?.salesOrder?.customFields),
};
diff --git a/apps/carbon/app/routes/x+/sales-order+/new.tsx b/apps/carbon/app/routes/x+/sales-order+/new.tsx
index 3172d9fdf0..1a29bbbb28 100644
--- a/apps/carbon/app/routes/x+/sales-order+/new.tsx
+++ b/apps/carbon/app/routes/x+/sales-order+/new.tsx
@@ -76,7 +76,7 @@ export async function action({ request }: ActionFunctionArgs) {
export default function SalesOrderNewRoute() {
const [params] = useUrlParams();
const customerId = params.get("customerId");
- const { company } = useUser();
+ const { id: userId, company } = useUser();
const initialValues = {
id: undefined,
salesOrderId: undefined,
@@ -84,6 +84,7 @@ export default function SalesOrderNewRoute() {
orderDate: today(getLocalTimeZone()).toString(),
status: "Draft" as SalesOrderStatus,
currencyCode: company?.baseCurrencyCode ?? "USD",
+ salesPersonId: userId,
exchangeRate: undefined,
exchangeRateUpdatedAt: "",
originatedFromQuote: false,
diff --git a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx
index 0bc9a7811c..7b592214b3 100644
--- a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx
+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx
@@ -94,6 +94,8 @@ export default function SalesRFQDetailsRoute() {
: "",
rfqId: rfqData?.rfqSummary?.rfqId ?? "",
status: rfqData?.rfqSummary?.status ?? ("Draft" as SalesRFQStatusType),
+ salesPersonId: rfqData?.rfqSummary?.salesPersonId ?? "",
+
...getCustomFields(rfqData.rfqSummary?.customFields ?? {}),
};
diff --git a/apps/carbon/app/routes/x+/sales-rfq+/new.tsx b/apps/carbon/app/routes/x+/sales-rfq+/new.tsx
index 6ef419f54b..fd2d6284dd 100644
--- a/apps/carbon/app/routes/x+/sales-rfq+/new.tsx
+++ b/apps/carbon/app/routes/x+/sales-rfq+/new.tsx
@@ -69,7 +69,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function SalesRFQNewRoute() {
- const { defaults } = useUser();
+ const { id: userId, defaults } = useUser();
const [params] = useUrlParams();
const customerId = params.get("customerId");
const initialValues = {
@@ -82,6 +82,7 @@ export default function SalesRFQNewRoute() {
rfqDate: today(getLocalTimeZone()).toString(),
rfqId: undefined,
status: "Draft" as SalesRFQStatusType,
+ salesPersonId: userId,
};
return (
diff --git a/apps/carbon/app/routes/x+/settings+/sales.tsx b/apps/carbon/app/routes/x+/settings+/sales.tsx
index 79ed642fc0..5cb42280c3 100644
--- a/apps/carbon/app/routes/x+/settings+/sales.tsx
+++ b/apps/carbon/app/routes/x+/settings+/sales.tsx
@@ -5,6 +5,7 @@ import {
CardFooter,
CardHeader,
CardTitle,
+ Label,
ScrollArea,
toast,
VStack,
@@ -95,9 +96,7 @@ export default function SalesSettingsRoute() {
>
<input type="hidden" name="intent" value="digitalQuote" />
<CardHeader>
- <CardTitle className="flex items-center gap-2">
- Digital Quote
- </CardTitle>
+ <CardTitle className="flex items-center gap-2">Quotes</CardTitle>
<CardDescription>
Enable digital quotes for your company. This will allow you to
send digital quotes to your customers, and allow them to accept
@@ -105,12 +104,21 @@ export default function SalesSettingsRoute() {
</CardDescription>
</CardHeader>
<CardContent>
- <div className="flex flex-col gap-4 max-w-[400px]">
- <Boolean name="digitalQuoteEnabled" description="Enabled" />
- <Users
- name="digitalQuoteNotificationGroup"
- label="Who should receive notifications when a digital quote is accepted?"
- />
+ <div className="flex flex-col gap-8 max-w-[400px]">
+ <div className="flex flex-col gap-2">
+ <Label>Digital Quotes</Label>
+ <Boolean
+ name="digitalQuoteEnabled"
+ description="Digital Quotes Enabled"
+ />
+ </div>
+ <div className="flex flex-col gap-2">
+ <Label>Notifications</Label>
+ <Users
+ name="digitalQuoteNotificationGroup"
+ label="Who should receive notifications when a digital quote is accepted or expired?"
+ />
+ </div>
</div>
</CardContent>
<CardFooter>
diff --git a/apps/carbon/app/trigger/expire-quotes.ts b/apps/carbon/app/trigger/expire-quotes.ts
new file mode 100644
index 0000000000..eb78c23fc6
--- /dev/null
+++ b/apps/carbon/app/trigger/expire-quotes.ts
@@ -0,0 +1,103 @@
+import { getCarbonServiceRole, NOVU_SECRET_KEY } from "@carbon/auth";
+import type { TriggerPayload } from "@carbon/notifications";
+import {
+ getSubscriberId,
+ NotificationEvent,
+ NotificationWorkflow,
+ triggerBulk,
+} from "@carbon/notifications";
+import { Novu } from "@novu/node";
+import { schedules } from "@trigger.dev/sdk/v3";
+
+const serviceRole = getCarbonServiceRole();
+const novu = new Novu(NOVU_SECRET_KEY!);
+
+export const expireQuotes = schedules.task({
+ id: "expire-quotes",
+ // Run at 9am, 2pm, and 7pm every day
+ cron: "0 9,14,19 * * *",
+ run: async () => {
+ console.log(
+ `🕒 Quote Expiration Check Started: ${new Date().toISOString()}`
+ );
+
+ try {
+ // Fetch expired quotes that are in sent status and have a sales person assigned
+ const { data: expiredQuotes, error } = await serviceRole
+ .from("quote")
+ .select("*")
+ .eq("status", "Sent")
+ .not("expirationDate", "is", null)
+ .lt("expirationDate", new Date().toISOString());
+
+ if (error) {
+ console.error(
+ `Error fetching expired quotes: ${JSON.stringify(error)}`
+ );
+ return;
+ }
+
+ if (!expiredQuotes?.length) {
+ console.log("No expired quotes found requiring notification");
+ return;
+ } else {
+ console.log(`Found ${expiredQuotes.length} expired quotes`);
+ const { error } = await serviceRole
+ .from("quote")
+ .update({ status: "Expired" })
+ .in(
+ "id",
+ expiredQuotes.map((quote) => quote.id)
+ );
+
+ if (error) {
+ console.error(
+ `Error updating expired quotes: ${JSON.stringify(error)}`
+ );
+ return;
+ }
+ }
+
+ const notificationPayloads: TriggerPayload[] = expiredQuotes
+ .filter((quote) => Boolean(quote.salesPersonId))
+ .map((quote) => {
+ return {
+ workflow: NotificationWorkflow.Expiration,
+ payload: {
+ documentId: quote.id,
+ event: NotificationEvent.QuoteExpired,
+ recordId: quote.id,
+ description: `Quote ${quote.quoteId} has expired`,
+ },
+ user: {
+ subscriberId: getSubscriberId({
+ companyId: quote.companyId,
+ userId: quote.salesPersonId!,
+ }),
+ },
+ };
+ });
+
+ if (notificationPayloads.length > 0) {
+ console.log(`Triggering ${notificationPayloads.length} notifications`);
+ try {
+ await triggerBulk(novu, notificationPayloads.flat());
+ } catch (error) {
+ console.error("Error triggering notifications");
+ console.error(error);
+ }
+ } else {
+ console.log("No notifications to trigger");
+ }
+ console.log(
+ `🕒 Quote Expiration Check Completed: ${new Date().toISOString()}`
+ );
+ } catch (error) {
+ console.error(
+ `Unexpected error in quote expiration task: ${
+ error instanceof Error ? error.message : String(error)
+ }`
+ );
+ }
+ },
+});
diff --git a/apps/carbon/app/trigger/notify.ts b/apps/carbon/app/trigger/notify.ts
index 1be986f33c..621260115a 100644
--- a/apps/carbon/app/trigger/notify.ts
+++ b/apps/carbon/app/trigger/notify.ts
@@ -154,17 +154,6 @@ export const notifyTask = task({
}
if (payload.recipient.type === "user") {
- const user = await client
- .from("user")
- .select("*")
- .eq("id", payload.recipient.userId)
- .single();
-
- if (user.error) {
- console.error("Failed to get user", user.error);
- throw user.error;
- }
-
try {
await trigger(novu, {
workflow,
@@ -177,12 +166,8 @@ export const notifyTask = task({
user: {
subscriberId: getSubscriberId({
companyId: payload.companyId,
- userId: user.data.id,
+ userId: payload.recipient.userId,
}),
- email: user.data.email,
- fullName: user.data.fullName ?? "",
- avatarUrl: user.data.avatarUrl ?? undefined,
- companyId: payload.companyId,
},
});
} catch (error) {
@@ -213,30 +198,20 @@ export const notifyTask = task({
return;
}
- const users = await client
- .from("user")
- .select("*")
- .in("id", [...new Set(userIds.data as string[])]);
-
const notificationPayloads: TriggerPayload[] =
- users.data?.map((user) => ({
+ [...new Set(userIds.data as string[])].map((userId) => ({
workflow,
payload: {
recordId: payload.documentId,
description,
event: payload.event,
- link: "#",
from: payload.from,
},
user: {
subscriberId: getSubscriberId({
companyId: payload.companyId,
- userId: user.id,
+ userId: userId,
}),
- email: user.email,
- fullName: user.fullName ?? "",
- avatarUrl: user.avatarUrl ?? undefined,
- companyId: payload.companyId,
},
})) ?? [];
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index d00c020c11..cf41f9986b 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -550,6 +550,7 @@ export const JobOperation = ({
<div className="h-[calc(100vh-156px)] md:h-[calc(100vh-104px)] p-4">
<ModelViewer
file={null}
+ key={operation.itemModelPath ?? job.modelPath}
url={`/file/preview/private/${
operation.itemModelPath ?? job.modelPath
}`}
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 45f72c16f0..167dc579d6 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -16475,6 +16475,7 @@ export type Database = {
orderDate: string
revisionId: number
salesOrderId: string
+ salesPersonId: string | null
status: Database["public"]["Enums"]["salesOrderStatus"]
updatedAt: string | null
updatedBy: string | null
@@ -16501,6 +16502,7 @@ export type Database = {
orderDate?: string
revisionId?: number
salesOrderId: string
+ salesPersonId?: string | null
status?: Database["public"]["Enums"]["salesOrderStatus"]
updatedAt?: string | null
updatedBy?: string | null
@@ -16527,6 +16529,7 @@ export type Database = {
orderDate?: string
revisionId?: number
salesOrderId?: string
+ salesPersonId?: string | null
status?: Database["public"]["Enums"]["salesOrderStatus"]
updatedAt?: string | null
updatedBy?: string | null
@@ -17635,6 +17638,7 @@ export type Database = {
revisionId: number
rfqDate: string
rfqId: string
+ salesPersonId: string | null
status: Database["public"]["Enums"]["salesRfqStatus"]
updatedAt: string | null
updatedBy: string | null
@@ -17658,6 +17662,7 @@ export type Database = {
revisionId?: number
rfqDate: string
rfqId: string
+ salesPersonId?: string | null
status?: Database["public"]["Enums"]["salesRfqStatus"]
updatedAt?: string | null
updatedBy?: string | null
@@ -17681,6 +17686,7 @@ export type Database = {
revisionId?: number
rfqDate?: string
rfqId?: string
+ salesPersonId?: string | null
status?: Database["public"]["Enums"]["salesRfqStatus"]
updatedAt?: string | null
updatedBy?: string | null
@@ -25049,14 +25055,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"]
@@ -27749,6 +27755,7 @@ export type Database = {
receiptRequestedDate: string | null
revisionId: number | null
salesOrderId: string | null
+ salesPersonId: string | null
shippingMethodName: string | null
shippingTermName: string | null
status: Database["public"]["Enums"]["salesOrderStatus"] | null
@@ -28168,6 +28175,7 @@ export type Database = {
rfqDate: string | null
rfqId: string | null
salesOrderId: string | null
+ salesPersonId: string | null
status: Database["public"]["Enums"]["salesRfqStatus"] | null
updatedAt: string | null
updatedBy: string | null
diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.ts
index bb20ac9d39..16161a589d 100644
--- a/packages/database/supabase/functions/convert/index.ts
+++ b/packages/database/supabase/functions/convert/index.ts
@@ -124,6 +124,7 @@ serve(async (req: Request) => {
customerLocationId: quote.data.customerLocationId,
customerReference: quote.data.customerReference,
locationId: quote.data.locationId,
+ salesPersonId: quote.data.salesPersonId ?? userId,
status: "Confirmed",
createdBy: userId,
companyId: companyId,
@@ -479,7 +480,7 @@ serve(async (req: Request) => {
expirationDate: toCalendarDate(
now(getLocalTimeZone()).add({ days: 30 })
).toString(),
- salesPersonId: salesRfq.data?.createdBy,
+ salesPersonId: salesRfq.data?.salesPersonId ?? userId,
status: "Draft",
externalNotes: salesRfq.data?.externalNotes,
internalNotes: salesRfq.data?.internalNotes,
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 45f72c16f0..167dc579d6 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -16475,6 +16475,7 @@ export type Database = {
orderDate: string
revisionId: number
salesOrderId: string
+ salesPersonId: string | null
status: Database["public"]["Enums"]["salesOrderStatus"]
updatedAt: string | null
updatedBy: string | null
@@ -16501,6 +16502,7 @@ export type Database = {
orderDate?: string
revisionId?: number
salesOrderId: string
+ salesPersonId?: string | null
status?: Database["public"]["Enums"]["salesOrderStatus"]
updatedAt?: string | null
updatedBy?: string | null
@@ -16527,6 +16529,7 @@ export type Database = {
orderDate?: string
revisionId?: number
salesOrderId?: string
+ salesPersonId?: string | null
status?: Database["public"]["Enums"]["salesOrderStatus"]
updatedAt?: string | null
updatedBy?: string | null
@@ -17635,6 +17638,7 @@ export type Database = {
revisionId: number
rfqDate: string
rfqId: string
+ salesPersonId: string | null
status: Database["public"]["Enums"]["salesRfqStatus"]
updatedAt: string | null
updatedBy: string | null
@@ -17658,6 +17662,7 @@ export type Database = {
revisionId?: number
rfqDate: string
rfqId: string
+ salesPersonId?: string | null
status?: Database["public"]["Enums"]["salesRfqStatus"]
updatedAt?: string | null
updatedBy?: string | null
@@ -17681,6 +17686,7 @@ export type Database = {
revisionId?: number
rfqDate?: string
rfqId?: string
+ salesPersonId?: string | null
status?: Database["public"]["Enums"]["salesRfqStatus"]
updatedAt?: string | null
updatedBy?: string | null
@@ -25049,14 +25055,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"]
@@ -27749,6 +27755,7 @@ export type Database = {
receiptRequestedDate: string | null
revisionId: number | null
salesOrderId: string | null
+ salesPersonId: string | null
shippingMethodName: string | null
shippingTermName: string | null
status: Database["public"]["Enums"]["salesOrderStatus"] | null
@@ -28168,6 +28175,7 @@ export type Database = {
rfqDate: string | null
rfqId: string | null
salesOrderId: string | null
+ salesPersonId: string | null
status: Database["public"]["Enums"]["salesRfqStatus"] | null
updatedAt: string | null
updatedBy: string | null
diff --git a/packages/database/supabase/migrations/20241111222137_sales-person-id.sql b/packages/database/supabase/migrations/20241111222137_sales-person-id.sql
new file mode 100644
index 0000000000..eabd206827
--- /dev/null
+++ b/packages/database/supabase/migrations/20241111222137_sales-person-id.sql
@@ -0,0 +1,47 @@
+ALTER TABLE "salesRfq" ADD COLUMN "salesPersonId" TEXT;
+ALTER TABLE "salesOrder" ADD COLUMN "salesPersonId" TEXT;
+
+DROP VIEW "salesRfqs";
+CREATE OR REPLACE VIEW "salesRfqs" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ rfq.*,
+ l."name" AS "locationName",
+ opp."quoteId",
+ opp."salesOrderId",
+ EXISTS(SELECT 1 FROM "salesRfqFavorite" rf WHERE rf."rfqId" = rfq.id AND rf."userId" = auth.uid()::text) AS favorite
+ FROM "salesRfq" rfq
+ LEFT JOIN "location" l
+ ON l.id = rfq."locationId"
+ LEFT JOIN "opportunity" opp
+ ON opp."salesRfqId" = rfq.id;
+
+DROP VIEW "salesOrders";
+CREATE OR REPLACE VIEW "salesOrders" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ s.*,
+ sm."name" AS "shippingMethodName",
+ st."name" AS "shippingTermName",
+ pt."name" AS "paymentTermName",
+ ss."receiptRequestedDate",
+ ss."receiptPromisedDate",
+ ss."dropShipment",
+ l."name" AS "locationName",
+ c."name" AS "customerName",
+ 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 "salesOrderFavorite" sf WHERE sf."salesOrderId" = s.id AND sf."userId" = auth.uid()::text) AS favorite
+ FROM "salesOrder" s
+ LEFT JOIN "salesOrderShipment" ss ON ss."id" = s."id"
+ LEFT JOIN "shippingMethod" sm ON sm."id" = ss."shippingMethodId"
+ LEFT JOIN "shippingTerm" st ON st."id" = ss."shippingTermId"
+ LEFT JOIN "salesOrderPayment" sp ON sp."id" = s."id"
+ LEFT JOIN "paymentTerm" pt ON pt."id" = sp."paymentTermId"
+ LEFT JOIN "location" l ON l."id" = ss."locationId"
+ LEFT JOIN "customer" c ON c."id" = s."customerId"
+ LEFT JOIN "user" u ON u."id" = s."createdBy"
+ LEFT JOIN "user" u2 ON u2."id" = s."updatedBy"
+ LEFT JOIN "user" u3 ON u3."id" = s."closedBy";
\ No newline at end of file
diff --git a/packages/notifications/src/index.ts b/packages/notifications/src/index.ts
index 9f00f63a08..657ebc6f6e 100644
--- a/packages/notifications/src/index.ts
+++ b/packages/notifications/src/index.ts
@@ -5,6 +5,7 @@ const API_ENDPOINT = "https://api.novu.co/v1";
export enum NotificationWorkflow {
Assignment = "assignment",
DigitalQuoteResponse = "digital-quote-response",
+ Expiration = "expiration",
}
export enum NotificationEvent {
@@ -13,19 +14,17 @@ export enum NotificationEvent {
SalesOrderAssignment = "sales-order-assignment",
JobAssignment = "job-assignment",
DigitalQuoteResponse = "digital-quote-response",
+ QuoteExpired = "quote-expired",
}
export enum NotificationType {
AssignmentInApp = "assignment-in-app",
DigitalQuoteResponseInApp = "digital-quote-response-in-app",
+ ExpirationInApp = "expiration-in-app",
}
export type TriggerUser = {
subscriberId: string;
- email: string;
- fullName: string;
- avatarUrl?: string;
- companyId: string;
};
export type NotificationPayload = {