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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: add ui for quote operation form
Brad Barbine5938d60497d
diff --git a/apps/carbon/app/components/Form/EquipmentType.tsx b/apps/carbon/app/components/Form/EquipmentType.tsxnew file mode 100644index 0000000000..4061ee7629--- /dev/null+++ b/apps/carbon/app/components/Form/EquipmentType.tsx@@ -0,0 +1,41 @@+import { useMount } from "@carbon/react";+import { useFetcher } from "@remix-run/react";+import { useMemo } from "react";+import type { getEquipmentTypesList } from "~/modules/resources";+import { path } from "~/utils/path";+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";++type EquipmentTypeSelectProps = Omit<ComboboxProps, "options">;++const EquipmentType = (props: EquipmentTypeSelectProps) => {+ const equipmentTypesFetcher =+ useFetcher<Awaited<ReturnType<typeof getEquipmentTypesList>>>();++ useMount(() => {+ equipmentTypesFetcher.load(path.to.api.equipmentTypes);+ });++ const options = useMemo(+ () =>+ equipmentTypesFetcher.data?.data+ ? equipmentTypesFetcher.data?.data.map((c) => ({+ value: c.id,+ label: c.name,+ }))+ : [],+ [equipmentTypesFetcher.data]+ );++ return (+ <Combobox+ options={options}+ {...props}+ label={props?.label ?? "Equipment Type"}+ />+ );+};++EquipmentType.displayName = "EquipmentType";++export default EquipmentType;diff --git a/apps/carbon/app/components/Form/Part.tsx b/apps/carbon/app/components/Form/Part.tsxindex 4a675815ee..1fca1ad360 100644--- a/apps/carbon/app/components/Form/Part.tsx+++ b/apps/carbon/app/components/Form/Part.tsx@@ -1,9 +1,8 @@-import { useDisclosure } from "@carbon/react";-import { useMemo, useState } from "react";-import { PartForm, type PartReplenishmentSystem } from "~/modules/parts";+import { useMemo } from "react";+import { type PartReplenishmentSystem } from "~/modules/parts";import { useParts } from "~/stores";import type { ComboboxProps } from "./Combobox";-import CreatableCombobox from "./CreatableCombobox";+import Combobox from "./Combobox";type PartSelectProps = Omit<ComboboxProps, "options"> & {partReplenishmentSystem?: PartReplenishmentSystem;@@ -11,8 +10,6 @@ type PartSelectProps = Omit<ComboboxProps, "options"> & {const Part = ({ partReplenishmentSystem, ...props }: PartSelectProps) => {const [parts] = useParts();- const newPartsModal = useDisclosure();- const [createdPart, setCreatedPart] = useState<string>("");const options = useMemo(() =>@@ -34,36 +31,7 @@ const Part = ({ partReplenishmentSystem, ...props }: PartSelectProps) => {);return (- <>- <CreatableCombobox- options={options}- {...props}- label={props?.label ?? "Part"}- onCreateOption={(option) => {- newPartsModal.onOpen();- setCreatedPart(option);- }}- />- {newPartsModal.isOpen && (- <PartForm- type="modal"- onClose={() => {- setCreatedPart("");- newPartsModal.onClose();- }}- initialValues={{- id: "",- name: createdPart,- description: "",- partType: "Inventory" as "Inventory",- replenishmentSystem: "Buy" as "Buy",- unitOfMeasureCode: "EA",- blocked: false,- active: false,- }}- />- )}- </>+ <Combobox options={options} {...props} label={props?.label ?? "Part"} />);};diff --git a/apps/carbon/app/components/Form/StandardFactor.tsx b/apps/carbon/app/components/Form/StandardFactor.tsxnew file mode 100644index 0000000000..0427bc08a9--- /dev/null+++ b/apps/carbon/app/components/Form/StandardFactor.tsx@@ -0,0 +1,16 @@+import { standardFactorType } from "~/modules/shared";+import type { SelectProps } from "./Select";+import Select from "./Select";++export type StandardFactorSelectProps = Omit<SelectProps, "options">;++const StandardFactor = (props: StandardFactorSelectProps) => {+ return (+ <Select+ {...props}+ options={standardFactorType.map((t) => ({ value: t, label: t }))}+ />+ );+};++export default StandardFactor;diff --git a/apps/carbon/app/components/Form/WorkCellType.tsx b/apps/carbon/app/components/Form/WorkCellType.tsxnew file mode 100644index 0000000000..10d164aba5--- /dev/null+++ b/apps/carbon/app/components/Form/WorkCellType.tsx@@ -0,0 +1,41 @@+import { useMount } from "@carbon/react";+import { useFetcher } from "@remix-run/react";+import { useMemo } from "react";+import type { getWorkCellTypesList } from "~/modules/resources";+import { path } from "~/utils/path";+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";++type WorkCellTypeSelectProps = Omit<ComboboxProps, "options">;++const WorkCellType = (props: WorkCellTypeSelectProps) => {+ const workCellTypesFetcher =+ useFetcher<Awaited<ReturnType<typeof getWorkCellTypesList>>>();++ useMount(() => {+ workCellTypesFetcher.load(path.to.api.workCellTypes);+ });++ const options = useMemo(+ () =>+ workCellTypesFetcher.data?.data+ ? workCellTypesFetcher.data?.data.map((c) => ({+ value: c.id,+ label: c.name,+ }))+ : [],+ [workCellTypesFetcher.data]+ );++ return (+ <Combobox+ options={options}+ {...props}+ label={props?.label ?? "Work Cell Type"}+ />+ );+};++WorkCellType.displayName = "WorkCellType";++export default WorkCellType;diff --git a/apps/carbon/app/components/Form/index.ts b/apps/carbon/app/components/Form/index.tsindex 579f4ae41f..4609032148 100644--- a/apps/carbon/app/components/Form/index.ts+++ b/apps/carbon/app/components/Form/index.ts@@ -17,6 +17,7 @@ import DatePicker from "./DatePicker";import Department from "./Department";import Employee from "./Employee";import Employees from "./Employees";+import EquipmentType from "./EquipmentType";import Hidden from "./Hidden";import Input from "./Input";import InputControlled from "./InputControlled";@@ -33,6 +34,7 @@ import SelectControlled from "./SelectControlled";import Sequence from "./Sequence";import Service from "./Service";import Shift from "./Shift";+import StandardFactor from "./StandardFactor";import Submit from "./Submit";import Supplier from "./Supplier";import SupplierContact from "./SupplierContact";@@ -42,6 +44,7 @@ import TimePicker from "./TimePicker";import Timezone from "./Timezone";import User from "./User";import Users from "./Users";+import WorkCellType from "./WorkCellType";export {Abilities,@@ -63,6 +66,7 @@ export {Department,Employee,Employees,+ EquipmentType,Hidden,Input,InputControlled,@@ -79,6 +83,7 @@ export {Sequence,Service,Shift,+ StandardFactor,Submit,Supplier,SupplierContact,@@ -88,4 +93,5 @@ export {Timezone,User,Users,+ WorkCellType,};diff --git a/apps/carbon/app/components/Layout/Navigation/IconSidebar.tsx b/apps/carbon/app/components/Layout/Navigation/IconSidebar.tsxindex 0f8d474cda..bf726e6115 100644--- a/apps/carbon/app/components/Layout/Navigation/IconSidebar.tsx+++ b/apps/carbon/app/components/Layout/Navigation/IconSidebar.tsx@@ -38,10 +38,10 @@ const IconSidebar = () => {}, new Set<string>());return (- <div className="h-full bg-background z-10 border-r border-border">+ <div className="h-full bg-background z-10 border-r border-border p-2"><div><TooltipProvider>- <VStack spacing={0} className="self-start sticky">+ <VStack spacing={1} className="self-start sticky">{company?.logo ? (<Linkto="/"@@ -54,13 +54,7 @@ const IconSidebar = () => {/></Link>) : (- <Button- isIcon- asChild- variant="ghost"- size="lg"- className="rounded-none"- >+ <Button isIcon asChild variant="ghost" size="lg"><Link to="/"><BsFillHexagonFill /></Link>@@ -80,7 +74,6 @@ const IconSidebar = () => {aria-label={link.name}variant={isActive ? "primary" : "ghost"}size="lg"- className="rounded-none"><Link to={link.to} prefetch="intent"><link.icon />diff --git a/apps/carbon/app/components/Table/components/Row.tsx b/apps/carbon/app/components/Table/components/Row.tsxindex 1309134bea..a2e8953ea8 100644--- a/apps/carbon/app/components/Table/components/Row.tsx+++ b/apps/carbon/app/components/Table/components/Row.tsx@@ -47,7 +47,7 @@ const Row = <T extends object>({key={row.id}className={cn("border-b border-border transition-colors",- isFrozenColumn && "bg-background"+ isFrozenColumn && "bg-card")}{...props}>diff --git a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsxindex 1cfaa0cfde..1d1642fa9c 100644--- a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx+++ b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx@@ -1,12 +1,10 @@import {- ModalCard,- ModalCardBody,- ModalCardContent,- ModalCardDescription,- ModalCardFooter,- ModalCardHeader,- ModalCardProvider,- ModalCardTitle,+ Card,+ CardContent,+ CardDescription,+ CardFooter,+ CardHeader,+ CardTitle,VStack,cn,} from "@carbon/react";@@ -34,8 +32,6 @@ import { path } from "~/utils/path";type PartFormProps = {initialValues: TypeOfValidator<typeof partValidator>;- type?: "card" | "modal";- onClose?: () => void;};const useNextPartIdShortcut = () => {@@ -83,7 +79,7 @@ const useNextPartIdShortcut = () => {return { partId, onPartIdChange, loading };};-const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {+const PartForm = ({ initialValues }: PartFormProps) => {const sharedPartsData = useRouteData<{partGroups: PartGroupListItem[];unitOfMeasures: UnitOfMeasureListItem[];@@ -118,94 +114,86 @@ const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {})) ?? [];return (- <ModalCardProvider type={type}>- <ModalCard onClose={onClose}>- <ModalCardContent>- <ValidatedForm- action={isEditing ? undefined : path.to.newPart}- method="post"- validator={partValidator}- defaultValues={initialValues}- onSubmit={onClose}+ <ValidatedForm+ method="post"+ validator={partValidator}+ defaultValues={initialValues}+ >+ <Card>+ <CardHeader>+ <CardTitle>{isEditing ? "Part Details" : "New Part"}</CardTitle>+ {!isEditing && (+ <CardDescription>+ A part contains the information about a specific item that can be+ purchased or manufactured.+ </CardDescription>+ )}+ </CardHeader>+ <CardContent>+ <div+ className={cn(+ "grid w-full gap-x-8 gap-y-2",+ isEditing ? "grid-cols-1 md:grid-cols-3" : "grid-cols-1"+ )}>- <ModalCardHeader>- <ModalCardTitle>- {isEditing ? "Part Details" : "New Part"}- </ModalCardTitle>- {!isEditing && (- <ModalCardDescription>- A part contains the information about a specific item that can- be purchased or manufactured.- </ModalCardDescription>+ <VStack>+ {isEditing ? (+ <Input autoFocus name="id" label="Part ID" isReadOnly />+ ) : (+ <InputControlled+ name="id"+ label="Part ID"+ helperText="Use ... to get the next part ID"+ value={partId}+ onChange={onPartIdChange}+ isDisabled={loading}+ />)}- </ModalCardHeader>- <ModalCardBody>- <div- className={cn(- "grid w-full gap-x-8 gap-y-2",- isEditing ? "grid-cols-1 md:grid-cols-3" : "grid-cols-1"- )}- >- <VStack>- {isEditing ? (- <Input name="id" label="Part ID" isReadOnly />- ) : (- <InputControlled- name="id"- label="Part ID"- helperText="Use ... to get the next part ID"- value={partId}- onChange={onPartIdChange}- isDisabled={loading}- />- )}- <Input name="name" label="Name" />- <TextArea name="description" label="Description" />- </VStack>- <VStack>- <Select- name="replenishmentSystem"- label="Replenishment System"- options={partReplenishmentSystemOptions}- />- <Select- name="partType"- label="Part Type"- options={partTypeOptions}- />- <Combobox- name="unitOfMeasureCode"- label="Unit of Measure"- options={unitOfMeasureOptions}- />- </VStack>- <VStack>- <Combobox- name="partGroupId"- label="Part Group"- options={partGroupOptions}- />- <Boolean name="blocked" label="Blocked" />- {isEditing && <Boolean name="active" label="Active" />}- </VStack>- </div>- </ModalCardBody>- <ModalCardFooter>- <Submit- isDisabled={- isEditing- ? !permissions.can("update", "parts")- : !permissions.can("create", "parts")- }- >- Save- </Submit>- </ModalCardFooter>- </ValidatedForm>- </ModalCardContent>- </ModalCard>- </ModalCardProvider>+ <Input name="name" label="Name" />+ <TextArea name="description" label="Description" />+ </VStack>+ <VStack>+ <Select+ name="replenishmentSystem"+ label="Replenishment System"+ options={partReplenishmentSystemOptions}+ />+ <Select+ name="partType"+ label="Part Type"+ options={partTypeOptions}+ />+ <Combobox+ name="unitOfMeasureCode"+ label="Unit of Measure"+ options={unitOfMeasureOptions}+ />+ </VStack>+ <VStack>+ <Combobox+ name="partGroupId"+ label="Part Group"+ options={partGroupOptions}+ />+ <Boolean name="blocked" label="Blocked" />+ {isEditing && <Boolean name="active" label="Active" />}+ </VStack>+ </div>+ </CardContent>+ <CardFooter>+ <Submit+ isDisabled={+ isEditing+ ? !permissions.can("update", "parts")+ : !permissions.can("create", "parts")+ }+ >+ Save+ </Submit>+ </CardFooter>+ </Card>+ </ValidatedForm>);};diff --git a/apps/carbon/app/modules/resources/resources.models.ts b/apps/carbon/app/modules/resources/resources.models.tsindex 7435c44efd..c127df9bbe 100644--- a/apps/carbon/app/modules/resources/resources.models.ts+++ b/apps/carbon/app/modules/resources/resources.models.ts@@ -3,6 +3,20 @@ import { z } from "zod";import { zfd } from "zod-form-data";import { DataType } from "~/modules/users";+export const standardFactorType = [+ "Hours/Piece",+ "Hours/100 Pieces",+ "Hours/1000 Pieces",+ "Minutes/Piece",+ "Minutes/100 Pieces",+ "Minutes/1000 Pieces",+ "Pieces/Hour",+ "Pieces/Minute",+ "Seconds/Piece",+ "Total Hours",+ "Total Minutes",+] as const;+export const abilityValidator = withZod(z.object({@@ -135,6 +149,9 @@ export const equipmentTypeValidator = withZod(description: z.string(),color: z.string(),requiredAbility: zfd.text(z.string().optional()),+ setupHours: zfd.numeric(+ z.number().min(0, { message: "Setup hours is required" })+ ),}));@@ -218,5 +235,11 @@ export const workCellTypeValidator = withZod(description: z.string(),color: z.string(),requiredAbility: zfd.text(z.string().optional()),+ quotingRate: zfd.numeric(z.number().min(0)),+ laborRate: zfd.numeric(z.number().min(0)),+ overheadRate: zfd.numeric(z.number().min(0)),+ defaultStandardFactor: z.enum(standardFactorType, {+ errorMap: (issue, ctx) => ({ message: "Standard factor is required" }),+ }),}));diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.tsindex 2eec45ecfd..cc857ca99b 100644--- a/apps/carbon/app/modules/resources/resources.service.ts+++ b/apps/carbon/app/modules/resources/resources.service.ts@@ -8,9 +8,11 @@ import { setGenericQueryFilters } from "~/utils/query";import { sanitize } from "~/utils/supabase";import type {employeeJobValidator,+ equipmentTypeValidator,equipmentValidator,locationValidator,partnerValidator,+ workCellTypeValidator,} from "./resources.models";export async function deleteAbility(@@ -405,9 +407,7 @@ export async function getEquipmentType() {return client.from("equipmentType")- .select(- "id, name, color, description, requiredAbility, equipment(id, name, location(id, name))"- )+ .select("*, equipment(id, name, location(id, name))").eq("active", true).eq("id", equipmentTypeId).single();@@ -439,6 +439,10 @@ export async function getEquipmentTypes(return query;}+export async function getEquipmentTypesList(client: SupabaseClient<Database>) {+ return client.from("equipmentType").select("id, name").order("name");+}+export async function getHoliday(client: SupabaseClient<Database>,holidayId: string@@ -539,64 +543,6 @@ export async function getPartners(return query;}-export async function getShift(- client: SupabaseClient<Database>,- shiftId: string-) {- return client- .from("shift")- .select(- `id, name, startTime, endTime, locationId,- monday, tuesday, wednesday, thursday, friday, saturday, sunday,- employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`- )- .eq("id", shiftId)- .eq("active", true)- .single();-}--export async function getShifts(- client: SupabaseClient<Database>,- args: GenericQueryFilters & { name: string | null; location: string | null }-) {- let query = client- .from("shift")- .select(- `id, name, startTime, endTime, locationId,- monday, tuesday, wednesday, thursday, friday, saturday, sunday,- employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`,- {- count: "exact",- }- )- .eq("active", true)- .eq("employeeShift.user.active", true);-- if (args?.name) {- query = query.ilike("name", `%${args.name}%`);- }-- if (args.location) {- query = query.eq("locationId", args.location);- }-- query = setGenericQueryFilters(query, args, "locationId");- return query;-}--export async function getShiftsList(- client: SupabaseClient<Database>,- locationId: string | null-) {- let query = client.from("shift").select(`id, name`).eq("active", true);-- if (locationId) {- query = query.eq("locationId", locationId);- }-- return query.order("name");-}-type UserAttributeId = string;export type PersonAttributeValue = {@@ -696,6 +642,64 @@ export async function getPeople(};}+export async function getShift(+ client: SupabaseClient<Database>,+ shiftId: string+) {+ return client+ .from("shift")+ .select(+ `id, name, startTime, endTime, locationId,+ monday, tuesday, wednesday, thursday, friday, saturday, sunday,+ employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`+ )+ .eq("id", shiftId)+ .eq("active", true)+ .single();+}++export async function getShifts(+ client: SupabaseClient<Database>,+ args: GenericQueryFilters & { name: string | null; location: string | null }+) {+ let query = client+ .from("shift")+ .select(+ `id, name, startTime, endTime, locationId,+ monday, tuesday, wednesday, thursday, friday, saturday, sunday,+ employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`,+ {+ count: "exact",+ }+ )+ .eq("active", true)+ .eq("employeeShift.user.active", true);++ if (args?.name) {+ query = query.ilike("name", `%${args.name}%`);+ }++ if (args.location) {+ query = query.eq("locationId", args.location);+ }++ query = setGenericQueryFilters(query, args, "locationId");+ return query;+}++export async function getShiftsList(+ client: SupabaseClient<Database>,+ locationId: string | null+) {+ let query = client.from("shift").select(`id, name`).eq("active", true);++ if (locationId) {+ query = query.eq("locationId", locationId);+ }++ return query.order("name");+}+export async function getWorkCell(client: SupabaseClient<Database>,workCellId: string@@ -734,9 +738,7 @@ export async function getWorkCellType() {return client.from("workCellType")- .select(- "id, name, color, description, requiredAbility, workCell(id, name, location(id, name), department(id, name))"- )+ .select("*, workCell(id, name, location(id, name), department(id, name))").eq("active", true).eq("id", workCellTypeId).single();@@ -768,6 +770,10 @@ export async function getWorkCellTypes(return query;}+export async function getWorkCellTypesList(client: SupabaseClient<Database>) {+ return client.from("workCellType").select("id, name").order("name");+}+export async function insertAbility(client: SupabaseClient<Database>,ability: {@@ -1076,21 +1082,13 @@ export async function upsertEquipment(export async function upsertEquipmentType(client: SupabaseClient<Database>,equipmentType:- | {- name: string;- description: string;- requiredAbility?: string;- color: string;+ | (Omit<TypeOfValidator<typeof equipmentTypeValidator>, "id"> & {createdBy: string;- }- | {+ })+ | (Omit<TypeOfValidator<typeof equipmentTypeValidator>, "id"> & {id: string;- name: string;- description: string;- requiredAbility?: string;- color: string;updatedBy: string;- }+ })) {if ("id" in equipmentType) {const { id, ...update } = equipmentType;@@ -1226,21 +1224,13 @@ export async function upsertWorkCell(export async function upsertWorkCellType(client: SupabaseClient<Database>,workCellType:- | {- name: string;- description: string;- color: string;- requiredAbility?: string;+ | (Omit<TypeOfValidator<typeof workCellTypeValidator>, "id"> & {createdBy: string;- }- | {+ })+ | (Omit<TypeOfValidator<typeof workCellTypeValidator>, "id"> & {id: string;- name: string;- description: string;- color: string;- requiredAbility?: string;updatedBy: string;- }+ })) {if ("id" in workCellType) {const { id, ...update } = workCellType;diff --git a/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypeForm.tsx b/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypeForm.tsxindex 7aedfffc75..d5781e9b15 100644--- a/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypeForm.tsx+++ b/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypeForm.tsx@@ -15,6 +15,7 @@ import {Color,Hidden,Input,+ Number,Submit,TextArea,} from "~/components/Form";@@ -73,6 +74,7 @@ const EquipmentTypeForm = ({label="Required Ability"isClearable/>+ <Number name="setupHours" label="Setup Hours" /></VStack></DrawerBody><DrawerFooter>diff --git a/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx b/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsxindex b4d8037e67..ba16ec1111 100644--- a/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx+++ b/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx@@ -15,6 +15,8 @@ import {Color,Hidden,Input,+ Number,+ StandardFactor,Submit,TextArea,} from "~/components/Form";@@ -73,6 +75,13 @@ const WorkCellTypeForm = ({label="Required Ability"isClearable/>+ <Number name="quotingRate" label="Quoting Rate" />+ <Number name="laborRate" label="Labor Rate" />+ <Number name="overheadRate" label="Overhead Rate" />+ <StandardFactor+ name="defaultStandardFactor"+ label="Default Standard Factor"+ /></VStack></DrawerBody><DrawerFooter>diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsxnew file mode 100644index 0000000000..53d705d87f--- /dev/null+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx@@ -0,0 +1,257 @@+import {+ Card,+ CardAction,+ CardContent,+ CardDescription,+ CardFooter,+ CardHeader,+ CardTitle,+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuIcon,+ DropdownMenuItem,+ DropdownMenuTrigger,+ HStack,+ IconButton,+ VStack,+ cn,+} from "@carbon/react";+import { useNavigate, useParams } from "@remix-run/react";+import { useState } from "react";+import { BsThreeDotsVertical } from "react-icons/bs";+import { IoMdTrash } from "react-icons/io";+import { ValidatedForm } from "remix-validated-form";+import {+ EquipmentType,+ Hidden,+ InputControlled,+ Number,+ NumberControlled,+ StandardFactor,+ Submit,+ WorkCellType,+} from "~/components/Form";+import { usePermissions } from "~/hooks";+import { useSupabase } from "~/lib/supabase";+import { quotationOperationValidator } from "~/modules/sales";+import type { TypeOfValidator } from "~/types/validators";+import { path } from "~/utils/path";++type QuotationOperationFormValues = TypeOfValidator<+ typeof quotationOperationValidator+>;++type QuotationOperationFormProps = {+ initialValues: QuotationOperationFormValues;+};++const QuotationOperationForm = ({+ initialValues,+}: QuotationOperationFormProps) => {+ const navigate = useNavigate();+ const permissions = usePermissions();+ const { supabase } = useSupabase();++ const { id: quoteId, lineId } = useParams();+ if (!quoteId) throw new Error("quoteId not found");+ if (!lineId) throw new Error("lineId not found");++ const isEditing = initialValues.id !== undefined;++ const [workCellData, setWorkCellData] = useState<{+ workCellTypeId: string;+ description: string;+ quotingRate: number;+ laborRate: number;+ overheadRate: number;+ }>({+ workCellTypeId: initialValues.workCellTypeId ?? "",+ description: initialValues.description ?? "",+ quotingRate: initialValues.quotingRate ?? 0,+ laborRate: initialValues.laborRate ?? 0,+ overheadRate: initialValues.overheadRate ?? 0,+ });++ const onWorkCellChange = async (workCellTypeId: string) => {+ if (!supabase || !workCellTypeId) return;+ const { data, error } = await supabase+ .from("workCellType")+ .select("*")+ .eq("id", workCellTypeId)+ .single();++ if (error) throw new Error(error.message);++ setWorkCellData({+ workCellTypeId,+ description: data?.description ?? "",+ quotingRate: data?.quotingRate ?? 0,+ laborRate: data?.laborRate ?? 0,+ overheadRate: data?.overheadRate ?? 0,+ });+ };++ const [equipmentData, setEquipmentData] = useState<{+ equipmentTypeId: string;+ setupHours: number;+ }>({+ equipmentTypeId: initialValues.equipmentTypeId ?? "",+ setupHours: initialValues.setupHours ?? 0,+ });++ const onEquipmentChange = async (equipmentTypeId: string) => {+ if (!supabase || !equipmentTypeId) return;+ const { data, error } = await supabase+ .from("equipmentType")+ .select("*")+ .eq("id", equipmentTypeId)+ .single();++ if (error) throw new Error(error.message);++ setEquipmentData({+ equipmentTypeId,+ setupHours: data?.setupHours ?? 0,+ });+ };++ return (+ <ValidatedForm+ method="post"+ validator={quotationOperationValidator}+ defaultValues={initialValues}+ className="w-full"+ action={+ isEditing+ ? path.to.quoteOperation(quoteId, lineId, initialValues.id!)+ : path.to.newQuoteOperation(quoteId, lineId)+ }+ >+ <Card className={cn(!isEditing && "mt-4")}>+ <HStack className="w-full justify-between items-start">+ <CardHeader>+ <CardTitle>+ {isEditing ? "Quote Operation" : "New Operation"}+ </CardTitle>+ <CardDescription>+ {!isEditing &&+ "A quote operation is a distinct step in the production of a part. It can consume material"}+ </CardDescription>+ </CardHeader>+ <CardAction>+ {isEditing && (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <IconButton+ icon={<BsThreeDotsVertical />}+ aria-label="More"+ variant="secondary"+ />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem onClick={() => navigate("delete")}>+ <DropdownMenuIcon icon={<IoMdTrash />} />+ Delete Operation+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ )}+ </CardAction>+ </HStack>+ <CardContent>+ <Hidden name="id" />+ <Hidden name="quoteAssemblyId" />++ <VStack>+ <div className="grid w-full gap-x-8 gap-y-2 grid-cols-1 md:grid-cols-3">+ <VStack>+ <WorkCellType+ name="workCellTypeId"+ label="Work Cell"+ onChange={(value) => {+ onWorkCellChange(value?.value as string);+ }}+ />+ <InputControlled+ name="description"+ label="Description"+ value={workCellData.description}+ onChange={(newValue) => {+ setWorkCellData((d) => ({ ...d, description: newValue }));+ }}+ />+ <EquipmentType+ name="equipmentTypeId"+ label="Equipment"+ onChange={(value) =>+ onEquipmentChange(value?.value as string)+ }+ />+ </VStack>+ <VStack>+ <NumberControlled+ name="setupTime"+ label="Setup Time (hours)"+ minValue={0}+ value={equipmentData.setupHours}+ onChange={(newValue) => {+ setEquipmentData((d) => ({ ...d, setupHours: newValue }));+ }}+ />+ <StandardFactor name="standardFactor" label="Standard Factor" />++ <Number+ name="productionStandard"+ label="Production Standard"+ minValue={0}+ />+ </VStack>+ <VStack>+ <NumberControlled+ name="quotingRate"+ label="Quoting Rate"+ minValue={0}+ value={workCellData.quotingRate}+ onChange={(newValue) => {+ setWorkCellData((d) => ({ ...d, quotingRate: newValue }));+ }}+ />+ <NumberControlled+ name="laborRate"+ label="Labor Rate"+ minValue={0}+ value={workCellData.laborRate}+ onChange={(newValue) => {+ setWorkCellData((d) => ({ ...d, laborRate: newValue }));+ }}+ />+ <NumberControlled+ name="overheadRate"+ label="Overhead Rate"+ minValue={0}+ value={workCellData.overheadRate}+ onChange={(newValue) => {+ setWorkCellData((d) => ({ ...d, overheadRate: newValue }));+ }}+ />+ </VStack>+ </div>+ </VStack>+ </CardContent>+ <CardFooter>+ <Submit+ isDisabled={+ isEditing+ ? !permissions.can("update", "sales")+ : !permissions.can("create", "sales")+ }+ >+ Save+ </Submit>+ </CardFooter>+ </Card>+ </ValidatedForm>+ );+};++export default QuotationOperationForm;diff --git a/apps/carbon/app/routes/api+/resources.equipment-types.tsx b/apps/carbon/app/routes/api+/resources.equipment-types.tsxnew file mode 100644index 0000000000..93ccb680f9--- /dev/null+++ b/apps/carbon/app/routes/api+/resources.equipment-types.tsx@@ -0,0 +1,10 @@+import type { LoaderFunctionArgs } from "@remix-run/node";+import { json } from "@remix-run/node";+import { getEquipmentTypesList } from "~/modules/resources";+import { requirePermissions } from "~/services/auth";++export async function loader({ request }: LoaderFunctionArgs) {+ const authorized = await requirePermissions(request, {});++ return json(await getEquipmentTypesList(authorized.client));+}diff --git a/apps/carbon/app/routes/api+/resources.work-cell-types.tsx b/apps/carbon/app/routes/api+/resources.work-cell-types.tsxnew file mode 100644index 0000000000..35f5977c63--- /dev/null+++ b/apps/carbon/app/routes/api+/resources.work-cell-types.tsx@@ -0,0 +1,10 @@+import type { LoaderFunctionArgs } from "@remix-run/node";+import { json } from "@remix-run/node";+import { getWorkCellTypesList } from "~/modules/resources";+import { requirePermissions } from "~/services/auth";++export async function loader({ request }: LoaderFunctionArgs) {+ const authorized = await requirePermissions(request, {});++ return json(await getWorkCellTypesList(authorized.client));+}diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsxindex 120fb3c481..c6516452df 100644--- a/apps/carbon/app/routes/x+/quote+/$id.tsx+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx@@ -122,7 +122,7 @@ export default function QuotationRoute() {<BillOfMaterialExplorer /></VStack></CollapsibleSidebar>- <VStack className="p-4">+ <VStack className="p-2"><Menubar><MenubarItem asChild><a@@ -133,6 +133,7 @@ export default function QuotationRoute() {Preview</a></MenubarItem>+ <MenubarItem>Release</MenubarItem></Menubar><Outlet />@@ -171,18 +172,18 @@ const data: BillOfMaterialNode[] = [type: "parent",children: [{- id: "cnad6opvo0l053gabtp0",+ id: "cnc03dgmu0l0h0gm0330",label: "P000000001",type: "line",children: [{- id: "cnad6opvo0l053gabtp0",+ id: "cnc03dgmu0l0h0gm0330",// parentId: "cn9v3tldq0l1lvlkrqmg",label: "Assemblies",type: "assemblies",},{- id: "cnad6opvo0l053gabtp0",+ id: "cnc03dgmu0l0h0gm0330",label: "Operations",type: "operations",},@@ -299,7 +300,6 @@ const BillOfMaterialItem = ({switch (type) {case "assemblies":- console.log({ type, id, parentId, label });return (<Buttonvariant="ghost"@@ -334,14 +334,13 @@ const BillOfMaterialItem = ({);case "line":return (- <Button- variant="ghost"- className="flex-1 justify-start"- leftIcon={<AiOutlinePartition />}- asChild- >+ <Button variant="ghost" className="flex-1 justify-between" asChild><Link to={path.to.quoteLine(quoteId, id)} prefetch="intent">- {label}+ <span className="flex justify-start">+ <AiOutlinePartition className="w-4 h-4 mr-2" />+ {label}+ </span>+ <span className="bg-orange-500 rounded-full h-2 w-2 inline-block ml-2" /></Link></Button>);diff --git a/apps/carbon/app/routes/x+/resources+/equipment.$typeId.tsx b/apps/carbon/app/routes/x+/resources+/equipment.$typeId.tsxindex ca78026023..d9a012564b 100644--- a/apps/carbon/app/routes/x+/resources+/equipment.$typeId.tsx+++ b/apps/carbon/app/routes/x+/resources+/equipment.$typeId.tsx@@ -51,15 +51,12 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { id, name, color, description, requiredAbility } = validation.data;+ const { id, ...data } = validation.data;if (!id) throw new Error("ID is was not found");const updateCategory = await upsertEquipmentType(client, {id,- name,- color,- description,- requiredAbility,+ ...data,updatedBy: userId,});if (updateCategory.error) {@@ -89,6 +86,7 @@ export default function EditAttributeCategoryRoute() {description: equipmentType?.description ?? "",color: equipmentType?.color ?? "#000000",requiredAbility: equipmentType?.requiredAbility ?? undefined,+ setupHours: equipmentType?.setupHours ?? 0,};return <EquipmentTypeForm onClose={onClose} initialValues={initialValues} />;diff --git a/apps/carbon/app/routes/x+/resources+/equipment.new.tsx b/apps/carbon/app/routes/x+/resources+/equipment.new.tsxindex 2d27934710..f605a541d3 100644--- a/apps/carbon/app/routes/x+/resources+/equipment.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/equipment.new.tsx@@ -27,13 +27,10 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { name, description, color, requiredAbility } = validation.data;+ const { id, ...data } = validation.data;const createEquipmentType = await upsertEquipmentType(client, {- name,- description,- color,- requiredAbility,+ ...data,createdBy: userId,});if (createEquipmentType.error) {@@ -57,6 +54,7 @@ export default function NewEquipmentTypeRoute() {name: "",description: "",color: "#000000",+ setupHours: 0,};return <EquipmentTypeForm onClose={onClose} initialValues={initialValues} />;diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsxindex ed14913436..0f414953bd 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx@@ -51,15 +51,12 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { id, name, color, description, requiredAbility } = validation.data;+ const { id, ...data } = validation.data;if (!id) throw new Error("ID is was not found");const updateCategory = await upsertWorkCellType(client, {id,- name,- color,- description,- requiredAbility,+ ...data,updatedBy: userId,});if (updateCategory.error) {@@ -89,6 +86,10 @@ export default function EditAttributeCategoryRoute() {description: workCellType?.description ?? "",color: workCellType?.color ?? "#000000",requiredAbility: workCellType?.requiredAbility ?? undefined,+ quotingRate: workCellType?.quotingRate ?? 0,+ laborRate: workCellType?.laborRate ?? 0,+ overheadRate: workCellType?.overheadRate ?? 0,+ defaultStandardFactor: workCellType?.defaultStandardFactor ?? "Total Hours",};return <WorkCellTypeForm onClose={onClose} initialValues={initialValues} />;diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsxindex 712ae32b02..afcfe9ffc8 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx@@ -27,13 +27,10 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { name, description, color, requiredAbility } = validation.data;+ const { id, ...data } = validation.data;const createWorkCellType = await upsertWorkCellType(client, {- name,- description,- color,- requiredAbility,+ ...data,createdBy: userId,});if (createWorkCellType.error) {@@ -57,6 +54,10 @@ export default function NewWorkCellTypeRoute() {name: "",description: "",color: "#000000",+ quotingRate: 0,+ laborRate: 0,+ overheadRate: 0,+ defaultStandardFactor: "Total Hours" as "Total Hours",};return <WorkCellTypeForm onClose={onClose} initialValues={initialValues} />;diff --git a/apps/carbon/app/routes/x+/settings+/theme.tsx b/apps/carbon/app/routes/x+/settings+/theme.tsxindex 9e615ecb7b..4bd837dbb6 100644--- a/apps/carbon/app/routes/x+/settings+/theme.tsx+++ b/apps/carbon/app/routes/x+/settings+/theme.tsx@@ -64,7 +64,7 @@ export async function action({ request }: ActionFunctionArgs) {await flash(request, error(update.error, "Failed to update theme")));- return json({}, await flash(request, success("Updated theme.")));+ return json({}, await flash(request, success("Updated theme")));}export default function Theme() {diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 1b23ca9588..ee0f880612 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -22,6 +22,7 @@ export const path = {departments: `${api}/resources/departments`,employeeTypes: `${api}/users/employee-types`,emptyPermissions: `${api}/users/empty-permissions`,+ equipmentTypes: `${api}/resources/equipment-types`,groupsByType: (type?: string) =>generatePath(`${api}/users/groups?type=${type}`),locations: `${api}/resources/locations`,@@ -41,6 +42,7 @@ export const path = {generatePath(`${api}/purchasing/supplier-locations?supplierId=${id}`),workCells: (id: string) =>generatePath(`${api}/resources/work-cells?location=${id}`),+ workCellTypes: `${api}/resources/work-cell-types`,},file: {previewImage: (bucket: string, path: string) =>@@ -293,6 +295,12 @@ export const path = {newQuoteLine: (id: string) => generatePath(`${x}/quote/${id}/new`),newQuoteLineQuantity: (id: string, lineId: string) =>generatePath(`${x}/quote/${id}/lines/${lineId}/new`),+ newQuoteOperation: (quoteId: string, lineId: string, parentId?: string) =>+ generatePath(+ `${x}/quote/${quoteId}/lines/${lineId}/operation/new${+ parentId ? `?quoteAssemblyId=${parentId}` : ""+ }`+ ),newReceipt: `${x}/inventory/receipts/new`,newRequestForQuote: `${x}/rfq/new`,newShift: `${x}/resources/shifts/new`,@@ -388,6 +396,10 @@ export const path = {generatePath(`${x}/quote/${id}/internal`),quoteLine: (quoteId: string, id: string) =>generatePath(`${x}/quote/${quoteId}/lines/${id}/details`),+ quoteOperation: (quoteId: string, lineId: string, operationId: string) =>+ generatePath(+ `${x}/quote/${quoteId}/lines/${lineId}/operation/${operationId}`+ ),quoteRelease: (id: string) => generatePath(`${x}/quote/${id}/release`),quotes: `${x}/sales/quotes`,receipt: (id: string) => generatePath(`${x}/inventory/receipts/${id}`),diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 7cf0f2c337..9828ec6796 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -2926,6 +2926,7 @@ export interface Database {id: string;name: string;requiredAbility: string | null;+ setupHours: number;updatedAt: string | null;updatedBy: string | null;};@@ -2938,6 +2939,7 @@ export interface Database {id?: string;name: string;requiredAbility?: string | null;+ setupHours?: number;updatedAt?: string | null;updatedBy?: string | null;};@@ -2950,6 +2952,7 @@ export interface Database {id?: string;name?: string;requiredAbility?: string | null;+ setupHours?: number;updatedAt?: string | null;updatedBy?: string | null;};@@ -10343,9 +10346,13 @@ export interface Database {color: string;createdAt: string;createdBy: string;+ defaultStandardFactor: Database["public"]["Enums"]["factor"];description: string | null;id: string;+ laborRate: number;name: string;+ overheadRate: number;+ quotingRate: number;requiredAbility: string | null;updatedAt: string | null;updatedBy: string | null;@@ -10355,9 +10362,13 @@ export interface Database {color?: string;createdAt?: string;createdBy: string;+ defaultStandardFactor?: Database["public"]["Enums"]["factor"];description?: string | null;id?: string;+ laborRate?: number;name: string;+ overheadRate?: number;+ quotingRate?: number;requiredAbility?: string | null;updatedAt?: string | null;updatedBy?: string | null;@@ -10367,9 +10378,13 @@ export interface Database {color?: string;createdAt?: string;createdBy?: string;+ defaultStandardFactor?: Database["public"]["Enums"]["factor"];description?: string | null;id?: string;+ laborRate?: number;name?: string;+ overheadRate?: number;+ quotingRate?: number;requiredAbility?: string | null;updatedAt?: string | null;updatedBy?: string | null;diff --git a/packages/database/supabase/migrations/20230302030217_equipment.sql b/packages/database/supabase/migrations/20230302030217_equipment.sqlindex d47bcbd400..5f692c3938 100644--- a/packages/database/supabase/migrations/20230302030217_equipment.sql+++ b/packages/database/supabase/migrations/20230302030217_equipment.sql@@ -64,6 +64,10 @@ CREATE TABLE "workCellType" ("color" TEXT NOT NULL DEFAULT '#000000',"description" TEXT,"requiredAbility" TEXT,+ "quotingRate" NUMERIC NOT NULL DEFAULT 0,+ "laborRate" NUMERIC NOT NULL DEFAULT 0,+ "overheadRate" NUMERIC NOT NULL DEFAULT 0,+ "defaultStandardFactor" factor NOT NULL DEFAULT 'Total Hours',"active" BOOLEAN NOT NULL DEFAULT true,"createdBy" TEXT NOT NULL,"createdAt" TIMESTAMP NOT NULL DEFAULT now(),@@ -255,6 +259,7 @@ CREATE TABLE "equipmentType" ("color" TEXT NOT NULL DEFAULT '#000000',"description" TEXT,"requiredAbility" TEXT,+ "setupHours" NUMERIC NOT NULL DEFAULT 0,"active" BOOLEAN NOT NULL DEFAULT true,"createdBy" TEXT NOT NULL,"createdAt" TIMESTAMP NOT NULL DEFAULT now(),diff --git a/packages/utils/src/themes.ts b/packages/utils/src/themes.tsindex 619ddc51d1..463d75c39a 100644--- a/packages/utils/src/themes.ts+++ b/packages/utils/src/themes.ts@@ -293,17 +293,17 @@ export const themes = [dark: {background: "20 14.3% 6.1%",foreground: "0 0% 95%",- popover: "0 0% 9%",- "popover-foreground": "0 0% 95%",- card: "0 0% 9%",- "card-foreground": "0 0% 95%",+ popover: "240 0% 9%",+ "popover-foreground": "240 0% 95%",+ card: "240 0% 9%",+ "card-foreground": "2400 0% 95%",primary: "142.1 87.6% 63.3%","primary-foreground": "144.9 80.4% 10%",secondary: "240 3.7% 15.9%","secondary-foreground": "0 0% 98%",- muted: "0 0% 15%",+ muted: "240 0% 15%","muted-foreground": "240 5% 64.9%",- accent: "12 6.5% 15.1%",+ accent: "240 6.5% 15.1%","accent-foreground": "0 0% 98%",destructive: "0 62.8% 30.6%","destructive-foreground": "0 85.7% 97.3%",diff --git a/www/pages/develop/index.mdx b/www/pages/develop/index.mdxindex a11cd9e6c4..35fbfb4cb9 100644--- a/www/pages/develop/index.mdx+++ b/www/pages/develop/index.mdx@@ -9,7 +9,7 @@ import { Features } from "../../components";<Features />-Carbon ERP is a high permformance, [open-source](https://github.com/barbinbrad/carbon), single-tenant (incomplete) ERP written in Typescript with web standards. It allows customers, suppliers, and employees to share a common platform.+Carbon ERP is a high performance, [open-source](https://github.com/barbinbrad/carbon), single-tenant (incomplete) ERP written in Typescript with web standards. It allows customers, suppliers, and employees to share a common platform.### High Performance