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.

wip

Brad Barbind9790fb385d5
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index a997ebfd26..829ee06ddd 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -2,6 +2,7 @@ import {
Alert,
AlertDescription,
AlertTitle,
+ Avatar,
Badge,
Button,
cn,
@@ -13,6 +14,7 @@ import {
Heading,
HStack,
IconButton,
+ Input,
Modal,
ModalBody,
ModalContent,
@@ -131,15 +133,52 @@ import {
LuGitBranchPlus,
LuHammer,
LuHardHat,
+ LuSend,
LuTimer,
LuTriangleAlert,
} from "react-icons/lu";
import { MethodIcon, MethodItemTypeIcon } from "~/components/Icons";
import { getFileType } from "~/services/operations.service";
-import { useItems } from "~/stores";
+import { useItems, usePeople } from "~/stores";
import ItemThumbnail from "./ItemThumbnail";
import ScrapReason from "./ScrapReason";
+const MOCK_NOTES = [
+ {
+ id: "c8j2m4k9n1",
+ jobOperationId: "op123",
+ note: "Setup completed successfully. All tooling verified.",
+ companyId: "comp789",
+ createdAt: "2024-01-15T14:30:00Z",
+ createdBy: "user456",
+ updatedBy: null,
+ updatedAt: null,
+ productionQuantityId: "pq123",
+ },
+ {
+ id: "d9k3n5m2p4",
+ jobOperationId: "op123",
+ note: "Quality check performed - dimensions within spec",
+ companyId: "comp789",
+ createdAt: "2024-01-15T16:45:00Z",
+ createdBy: "16c54d5a-fc00-4c54-ac34-25e43f85e366",
+ updatedBy: "user456",
+ updatedAt: "2024-01-15T17:00:00Z",
+ productionQuantityId: "pq124",
+ },
+ {
+ id: "e1m4n7p3q5",
+ jobOperationId: "op123",
+ note: "Machine maintenance required - coolant levels low",
+ companyId: "comp789",
+ createdAt: "2024-01-16T09:15:00Z",
+ createdBy: "user123",
+ updatedBy: null,
+ updatedAt: null,
+ productionQuantityId: null,
+ },
+];
+
type JobOperationProps = {
events: ProductionEvent[];
files: Promise<StorageItem[]>;
@@ -160,6 +199,8 @@ export const JobOperation = ({
workCenter,
}: JobOperationProps) => {
const navigate = useNavigate();
+ const user = useUser();
+ const [employees] = usePeople();
const { downloadFile, downloadModel, getFilePath } = useFiles(job);
@@ -257,6 +298,9 @@ export const JobOperation = ({
>
Instructions
</TabsTrigger>
+ <TabsTrigger variant="primary" value="notes">
+ Notes
+ </TabsTrigger>
</TabsList>
</div>
</HStack>
@@ -688,7 +732,66 @@ export const JobOperation = ({
/>
</ScrollArea>
</TabsContent>
- {activeTab !== "instructions" && (
+ <TabsContent value="notes">
+ <div className="flex flex-col h-[calc(100dvh-var(--header-height)*2-var(--controls-height)-2rem)]">
+ <ScrollArea className="flex-1 p-4">
+ <div className="flex flex-col-reverse gap-3">
+ {MOCK_NOTES.map((note) => {
+ const createdBy = employees.find(
+ (employee) => employee.id === note.createdBy
+ );
+ return (
+ <div
+ key={note.id}
+ className={cn(
+ "flex gap-2",
+ note.createdBy === user.id && "flex-row-reverse"
+ )}
+ >
+ <Avatar name={createdBy?.name} />
+
+ <div
+ className={cn(
+ "max-w-[80%] rounded-2xl p-3",
+ note.createdBy === user.id
+ ? "bg-blue-500 text-blue-white"
+ : "bg-muted"
+ )}
+ >
+ <p className="text-sm">{note.note}</p>
+ <span className="text-xs opacity-70">
+ {new Date(note.createdAt).toLocaleTimeString([], {
+ hour: "2-digit",
+ minute: "2-digit",
+ })}
+ </span>
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ </ScrollArea>
+
+ <div className="border-t p-4">
+ <form className="flex gap-2">
+ <Input
+ className="flex-1"
+ placeholder="Type a message..."
+ name="message"
+ />
+ <Button
+ className="h-10"
+ aria-label="Send"
+ type="submit"
+ leftIcon={<LuSend />}
+ >
+ Send
+ </Button>
+ </form>
+ </div>
+ </div>
+ </TabsContent>
+ {!["instructions", "notes"].includes(activeTab) && (
<Controls>
<div className="flex flex-col items-center gap-2 p-4">
<VStack spacing={2}>
@@ -823,100 +926,105 @@ export const JobOperation = ({
</div>
</Controls>
)}
- <Times>
- <div className="flex items-start p-4">
- <div className="flex flex-col w-full gap-2">
- {operation.setupDuration > 0 && (
- <HStack>
- <Tooltip>
- <TooltipTrigger>
- <LuTimer className="h-4 w-4 mr-1" />
- </TooltipTrigger>
- <TooltipContent side="right">Setup</TooltipContent>
- </Tooltip>
- <Progress
- numerator={formatDurationMilliseconds(progress.setup)}
- denominator={formatDurationMilliseconds(
- operation.setupDuration
- )}
- value={(progress.setup / operation.setupDuration) * 100}
- indicatorClassName={
- progress.setup > operation.setupDuration
- ? "bg-red-500"
- : ""
- }
- />
- </HStack>
- )}
- {operation.laborDuration > 0 && (
+ {!["notes"].includes(activeTab) && (
+ <Times>
+ <div className="flex items-start p-4">
+ <div className="flex flex-col w-full gap-2">
+ {operation.setupDuration > 0 && (
+ <HStack>
+ <Tooltip>
+ <TooltipTrigger>
+ <LuTimer className="h-4 w-4 mr-1" />
+ </TooltipTrigger>
+ <TooltipContent side="right">Setup</TooltipContent>
+ </Tooltip>
+ <Progress
+ numerator={formatDurationMilliseconds(progress.setup)}
+ denominator={formatDurationMilliseconds(
+ operation.setupDuration
+ )}
+ value={(progress.setup / operation.setupDuration) * 100}
+ indicatorClassName={
+ progress.setup > operation.setupDuration
+ ? "bg-red-500"
+ : ""
+ }
+ />
+ </HStack>
+ )}
+ {operation.laborDuration > 0 && (
+ <HStack>
+ <Tooltip>
+ <TooltipTrigger>
+ <LuHardHat className="h-4 w-4 mr-1" />
+ </TooltipTrigger>
+ <TooltipContent side="right">Labor</TooltipContent>
+ </Tooltip>
+ <Progress
+ numerator={formatDurationMilliseconds(progress.labor)}
+ denominator={formatDurationMilliseconds(
+ operation.laborDuration
+ )}
+ value={(progress.labor / operation.laborDuration) * 100}
+ indicatorClassName={
+ progress.labor > operation.laborDuration
+ ? "bg-red-500"
+ : ""
+ }
+ />
+ </HStack>
+ )}
+ {operation.machineDuration > 0 && (
+ <HStack>
+ <Tooltip>
+ <TooltipTrigger>
+ <LuHammer className="h-4 w-4 mr-1" />
+ </TooltipTrigger>
+ <TooltipContent side="right">Machine</TooltipContent>
+ </Tooltip>
+ <Progress
+ numerator={formatDurationMilliseconds(progress.machine)}
+ denominator={formatDurationMilliseconds(
+ operation.machineDuration
+ )}
+ value={
+ (progress.machine / operation.machineDuration) * 100
+ }
+ indicatorClassName={
+ progress.machine > operation.machineDuration
+ ? "bg-red-500"
+ : ""
+ }
+ />
+ </HStack>
+ )}
<HStack>
<Tooltip>
<TooltipTrigger>
- <LuHardHat className="h-4 w-4 mr-1" />
+ <FaTasks className="h-4 w-4 mr-1" />
</TooltipTrigger>
- <TooltipContent side="right">Labor</TooltipContent>
+ <TooltipContent side="right">Quantity</TooltipContent>
</Tooltip>
<Progress
- numerator={formatDurationMilliseconds(progress.labor)}
- denominator={formatDurationMilliseconds(
- operation.laborDuration
- )}
- value={(progress.labor / operation.laborDuration) * 100}
indicatorClassName={
- progress.labor > operation.laborDuration
- ? "bg-red-500"
+ operation.operationStatus === "Paused" &&
+ operation.quantityComplete < operation.operationQuantity
+ ? "bg-yellow-500"
: ""
}
- />
- </HStack>
- )}
- {operation.machineDuration > 0 && (
- <HStack>
- <Tooltip>
- <TooltipTrigger>
- <LuHammer className="h-4 w-4 mr-1" />
- </TooltipTrigger>
- <TooltipContent side="right">Machine</TooltipContent>
- </Tooltip>
- <Progress
- numerator={formatDurationMilliseconds(progress.machine)}
- denominator={formatDurationMilliseconds(
- operation.machineDuration
- )}
- value={(progress.machine / operation.machineDuration) * 100}
- indicatorClassName={
- progress.machine > operation.machineDuration
- ? "bg-red-500"
- : ""
+ numerator={operation.quantityComplete.toString()}
+ denominator={operation.operationQuantity.toString()}
+ value={
+ (operation.quantityComplete /
+ operation.operationQuantity) *
+ 100
}
/>
</HStack>
- )}
- <HStack>
- <Tooltip>
- <TooltipTrigger>
- <FaTasks className="h-4 w-4 mr-1" />
- </TooltipTrigger>
- <TooltipContent side="right">Quantity</TooltipContent>
- </Tooltip>
- <Progress
- indicatorClassName={
- operation.operationStatus === "Paused" &&
- operation.quantityComplete < operation.operationQuantity
- ? "bg-yellow-500"
- : ""
- }
- numerator={operation.quantityComplete.toString()}
- denominator={operation.operationQuantity.toString()}
- value={
- (operation.quantityComplete / operation.operationQuantity) *
- 100
- }
- />
- </HStack>
+ </div>
</div>
- </div>
- </Times>
+ </Times>
+ )}
</Tabs>
{reworkModal.isOpen && (
<QuantityModal
@@ -1174,9 +1282,12 @@ function useOperation(
};
}, [activeEvents]);
- useInterval(() => {
- setProgress(getProgress());
- }, 1000);
+ useInterval(
+ () => {
+ setProgress(getProgress());
+ },
+ active.setup || active.labor || active.machine ? 1000 : null
+ );
return {
active,
@@ -1204,6 +1315,7 @@ function useOperation(
function useFiles(job: Job) {
const user = useUser();
+
const { carbon } = useCarbon();
const getFilePath = useCallback(
diff --git a/apps/mes/app/components/RealtimeDataProvider.tsx b/apps/mes/app/components/RealtimeDataProvider.tsx
index 579cc77e9c..0a061beb08 100644
--- a/apps/mes/app/components/RealtimeDataProvider.tsx
+++ b/apps/mes/app/components/RealtimeDataProvider.tsx
@@ -138,32 +138,6 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
}
}
)
-
- .on(
- "postgres_changes",
- {
- event: "*",
- schema: "public",
- table: "employee",
- filter: `companyId=eq.${companyId}`,
- },
- async (payload) => {
- if ("companyId" in payload.new && payload.new.companyId !== companyId)
- return;
- // TODO: there's a cleaner way of doing this, but since customers and suppliers
- // are also in the users table, we can't automatically add/update/delete them
- // from our list of employees. So for now we just refetch.
- const { data } = await carbon
- .from("employees")
- .select("id, name, avatarUrl")
- .eq("companyId", companyId)
- .order("name");
- if (data) {
- // @ts-ignore
- setPeople(data);
- }
- }
- )
.subscribe();
return () => {
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index c589549f26..a894a7d37a 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -7601,6 +7601,7 @@ export type Database = {
}
job: {
Row: {
+ actualTime: number | null
assignee: string | null
companyId: string
completedDate: string | null
@@ -7611,6 +7612,7 @@ export type Database = {
customFields: Json | null
deadlineType: Database["public"]["Enums"]["deadlineType"]
dueDate: string | null
+ estimatedTime: number | null
id: string
itemId: string
jobId: string
@@ -7635,6 +7637,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ actualTime?: number | null
assignee?: string | null
companyId: string
completedDate?: string | null
@@ -7645,6 +7648,7 @@ export type Database = {
customFields?: Json | null
deadlineType?: Database["public"]["Enums"]["deadlineType"]
dueDate?: string | null
+ estimatedTime?: number | null
id?: string
itemId: string
jobId: string
@@ -7669,6 +7673,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ actualTime?: number | null
assignee?: string | null
companyId?: string
completedDate?: string | null
@@ -7679,6 +7684,7 @@ export type Database = {
customFields?: Json | null
deadlineType?: Database["public"]["Enums"]["deadlineType"]
dueDate?: string | null
+ estimatedTime?: number | null
id?: string
itemId?: string
jobId?: string
@@ -8713,6 +8719,138 @@ export type Database = {
},
]
}
+ jobOperationNote: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ jobOperationId: string
+ note: string
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ id?: string
+ jobOperationId: string
+ note: string
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ id?: string
+ jobOperationId?: string
+ note?: string
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "jobOperationNote_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
jobOperationTool: {
Row: {
companyId: string
@@ -18975,6 +19113,7 @@ export type Database = {
id: string
internalNotes: Json | null
locationId: string | null
+ noQuoteReasonId: string | null
revisionId: number
rfqDate: string
rfqId: string
@@ -19000,6 +19139,7 @@ export type Database = {
id?: string
internalNotes?: Json | null
locationId?: string | null
+ noQuoteReasonId?: string | null
revisionId?: number
rfqDate?: string
rfqId: string
@@ -19025,6 +19165,7 @@ export type Database = {
id?: string
internalNotes?: Json | null
locationId?: string | null
+ noQuoteReasonId?: string | null
revisionId?: number
rfqDate?: string
rfqId?: string
@@ -19217,6 +19358,13 @@ export type Database = {
referencedRelation: "purchaseOrders"
referencedColumns: ["locationId"]
},
+ {
+ foreignKeyName: "salesRfq_noQuoteReasonId_fkey"
+ columns: ["noQuoteReasonId"]
+ isOneToOne: false
+ referencedRelation: "noQuoteReason"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "salesRfq_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index c589549f26..a894a7d37a 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -7601,6 +7601,7 @@ export type Database = {
}
job: {
Row: {
+ actualTime: number | null
assignee: string | null
companyId: string
completedDate: string | null
@@ -7611,6 +7612,7 @@ export type Database = {
customFields: Json | null
deadlineType: Database["public"]["Enums"]["deadlineType"]
dueDate: string | null
+ estimatedTime: number | null
id: string
itemId: string
jobId: string
@@ -7635,6 +7637,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ actualTime?: number | null
assignee?: string | null
companyId: string
completedDate?: string | null
@@ -7645,6 +7648,7 @@ export type Database = {
customFields?: Json | null
deadlineType?: Database["public"]["Enums"]["deadlineType"]
dueDate?: string | null
+ estimatedTime?: number | null
id?: string
itemId: string
jobId: string
@@ -7669,6 +7673,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ actualTime?: number | null
assignee?: string | null
companyId?: string
completedDate?: string | null
@@ -7679,6 +7684,7 @@ export type Database = {
customFields?: Json | null
deadlineType?: Database["public"]["Enums"]["deadlineType"]
dueDate?: string | null
+ estimatedTime?: number | null
id?: string
itemId?: string
jobId?: string
@@ -8713,6 +8719,138 @@ export type Database = {
},
]
}
+ jobOperationNote: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ jobOperationId: string
+ note: string
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ id?: string
+ jobOperationId: string
+ note: string
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ id?: string
+ jobOperationId?: string
+ note?: string
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "jobOperationNote_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationNote_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
jobOperationTool: {
Row: {
companyId: string
@@ -18975,6 +19113,7 @@ export type Database = {
id: string
internalNotes: Json | null
locationId: string | null
+ noQuoteReasonId: string | null
revisionId: number
rfqDate: string
rfqId: string
@@ -19000,6 +19139,7 @@ export type Database = {
id?: string
internalNotes?: Json | null
locationId?: string | null
+ noQuoteReasonId?: string | null
revisionId?: number
rfqDate?: string
rfqId: string
@@ -19025,6 +19165,7 @@ export type Database = {
id?: string
internalNotes?: Json | null
locationId?: string | null
+ noQuoteReasonId?: string | null
revisionId?: number
rfqDate?: string
rfqId?: string
@@ -19217,6 +19358,13 @@ export type Database = {
referencedRelation: "purchaseOrders"
referencedColumns: ["locationId"]
},
+ {
+ foreignKeyName: "salesRfq_noQuoteReasonId_fkey"
+ columns: ["noQuoteReasonId"]
+ isOneToOne: false
+ referencedRelation: "noQuoteReason"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "salesRfq_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/migrations/20250113145319_operation-notes.sql b/packages/database/supabase/migrations/20250113145319_operation-notes.sql
new file mode 100644
index 0000000000..3d2647abfd
--- /dev/null
+++ b/packages/database/supabase/migrations/20250113145319_operation-notes.sql
@@ -0,0 +1,51 @@
+CREATE TABLE "jobOperationNote" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "jobOperationId" TEXT NOT NULL,
+ "note" TEXT NOT NULL,
+ "companyId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+ "createdBy" TEXT NOT NULL,
+ "updatedBy" TEXT,
+ "updatedAt" TIMESTAMP WITH TIME ZONE,
+
+ CONSTRAINT "jobOperationNote_pkey" PRIMARY KEY ("id"),
+ CONSTRAINT "jobOperationNote_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON UPDATE CASCADE ON DELETE CASCADE,
+ CONSTRAINT "jobOperationNote_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON UPDATE CASCADE ON DELETE RESTRICT,
+ CONSTRAINT "jobOperationNote_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE ON DELETE SET NULL
+);
+
+CREATE INDEX "jobOperationNote_companyId_fkey" ON "jobOperationNote"("companyId", "jobOperationId");
+
+ALTER TABLE "jobOperationNote" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "Employees can view job operation notes" ON "jobOperationNote"
+ FOR SELECT
+ USING (
+ has_role('employee', "companyId")
+ );
+
+CREATE POLICY "Employees can insert job operation notes" ON "jobOperationNote"
+ FOR INSERT
+ WITH CHECK (
+ has_role('employee', "companyId")
+ );
+
+CREATE POLICY "Employees with production_update can update job operation notes" ON "jobOperationNote"
+ FOR UPDATE
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('production_update', "companyId")
+ );
+
+CREATE POLICY "Employees with production_delete can delete job operation notes" ON "jobOperationNote"
+ FOR DELETE
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('production_delete', "companyId")
+ );
+
+ALTER TABLE "jobOperationNote" ADD COLUMN "productionQuantityId" TEXT;
+
+ALTER TABLE "jobOperationNote" ADD CONSTRAINT "jobOperationNote_productionQuantityId_fkey" FOREIGN KEY ("productionQuantityId") REFERENCES "productionQuantity"("id") ON UPDATE CASCADE ON DELETE CASCADE;
+
+CREATE INDEX "jobOperationNote_productionQuantityId_fkey" ON "jobOperationNote"("productionQuantityId");