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 machine rate to work center/costing

Brad Barbina5c57c8d0232
diff --git a/apps/carbon/app/components/Form/WorkCenter.tsx b/apps/carbon/app/components/Form/WorkCenter.tsx
index 5cbc2fd275..c52348f9d0 100644
--- a/apps/carbon/app/components/Form/WorkCenter.tsx
+++ b/apps/carbon/app/components/Form/WorkCenter.tsx
@@ -50,6 +50,7 @@ const WorkCenter = (props: WorkCenterSelectProps) => {
overheadRate: 0,
laborRate: 0,
locationId: props?.locationId ?? defaults?.locationId ?? "",
+ machineRate: 0,
processes: props?.processId ? [props.processId] : [],
defaultStandardFactor: "Minutes/Piece" as "Total Hours",
}}
diff --git a/apps/carbon/app/components/Form/WorkCenters.tsx b/apps/carbon/app/components/Form/WorkCenters.tsx
index a93c943786..a84b2856b9 100644
--- a/apps/carbon/app/components/Form/WorkCenters.tsx
+++ b/apps/carbon/app/components/Form/WorkCenters.tsx
@@ -47,6 +47,7 @@ const WorkCenters = (props: WorkCenterSelectProps) => {
overheadRate: 0,
laborRate: 0,
locationId: defaults?.locationId ?? "",
+ machineRate: 0,
processes: props?.processId ? [props.processId] : [],
defaultStandardFactor: "Minutes/Piece" as "Total Hours",
}}
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
index 52e08c28ef..5c7160b0b2 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
@@ -64,7 +64,7 @@ const SupplierForm = ({
<div>
<ModalCardProvider type={type}>
<ModalCard onClose={onClose}>
- <ModalCardContent>
+ <ModalCardContent size="medium">
<ValidatedForm
method="post"
action={isEditing ? undefined : path.to.newSupplier}
diff --git a/apps/carbon/app/modules/resources/resources.models.ts b/apps/carbon/app/modules/resources/resources.models.ts
index 76f26244d9..039aabf2f0 100644
--- a/apps/carbon/app/modules/resources/resources.models.ts
+++ b/apps/carbon/app/modules/resources/resources.models.ts
@@ -124,6 +124,7 @@ export const workCenterValidator = z.object({
}),
laborRate: zfd.numeric(z.number().min(0)),
locationId: z.string().min(20, { message: "Location is required" }),
+ machineRate: zfd.numeric(z.number().min(0)),
overheadRate: zfd.numeric(z.number().min(0)),
processes: z
.array(z.string().min(20, { message: "Invalid process" }))
diff --git a/apps/carbon/app/modules/resources/ui/WorkCenters/WorkCenterForm.tsx b/apps/carbon/app/modules/resources/ui/WorkCenters/WorkCenterForm.tsx
index 5653804b0e..cff7ee0af1 100644
--- a/apps/carbon/app/modules/resources/ui/WorkCenters/WorkCenterForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/WorkCenters/WorkCenterForm.tsx
@@ -104,17 +104,26 @@ const WorkCenterForm = ({
)}
<TextArea name="description" label="Description" />
<Location name="locationId" label="Location" />
+
<Number
- name="overheadRate"
- label="Overhead Rate"
+ name="laborRate"
+ label="Labor Rate"
formatOptions={{
style: "currency",
currency: "USD",
}}
/>
<Number
- name="laborRate"
- label="Labor Rate"
+ name="machineRate"
+ label="Machine Rate"
+ formatOptions={{
+ style: "currency",
+ currency: "USD",
+ }}
+ />
+ <Number
+ name="overheadRate"
+ label="Overhead Rate"
formatOptions={{
style: "currency",
currency: "USD",
diff --git a/apps/carbon/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx b/apps/carbon/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
index 3e803ae12f..48a9f8c08d 100644
--- a/apps/carbon/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
@@ -5,6 +5,7 @@ import {
MenuItem,
useDisclosure,
} from "@carbon/react";
+import { useLocale } from "@react-aria/i18n";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo, useState } from "react";
@@ -26,6 +27,10 @@ type WorkCentersTableProps = {
};
const defaultColumnVisibility = {
+ description: false,
+ laborRate: false,
+ machineRate: false,
+ overheadRate: false,
createdAt: false,
createdBy: false,
updatedAt: false,
@@ -43,6 +48,14 @@ const WorkCentersTable = memo(
const [selectedWorkCenter, setSelectedWorkCenter] =
useState<WorkCenter | null>(null);
+ const { locale } = useLocale();
+ // TODO: factor in default currency, po currency and exchange rate
+ const formatter = useMemo(
+ () =>
+ new Intl.NumberFormat(locale, { style: "currency", currency: "USD" }),
+ [locale]
+ );
+
const onDelete = (data: WorkCenter) => {
setSelectedWorkCenter(data);
deleteModal.onOpen();
@@ -112,6 +125,27 @@ const WorkCentersTable = memo(
</span>
),
},
+ {
+ accessorKey: "laborRate",
+ header: "Labor Rate",
+ cell: ({ row }) => (
+ <span>{formatter.format(row.original.laborRate ?? 0)}</span>
+ ),
+ },
+ {
+ accessorKey: "machineRate",
+ header: "Machine Rate",
+ cell: ({ row }) => (
+ <span>{formatter.format(row.original.machineRate ?? 0)}</span>
+ ),
+ },
+ {
+ accessorKey: "overheadRate",
+ header: "Overhead Rate",
+ cell: ({ row }) => (
+ <span>{formatter.format(row.original.overheadRate ?? 0)}</span>
+ ),
+ },
{
id: "createdBy",
header: "Created By",
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index edf09d031e..af5812ccbe 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -285,6 +285,7 @@ export const quoteOperationValidator = z
})
.optional(),
machineTime: zfd.numeric(z.number().min(0).optional()),
+ machineRate: zfd.numeric(z.number().min(0).optional()),
overheadRate: zfd.numeric(z.number().min(0).optional()),
laborRate: zfd.numeric(z.number().min(0).optional()),
operationSupplierProcessId: zfd.text(z.string().optional()),
@@ -400,6 +401,18 @@ export const quoteOperationValidator = z
path: ["machineTime"],
}
)
+ .refine(
+ (data) => {
+ if (data.operationType === "Inside") {
+ return Number.isFinite(data.machineTime);
+ }
+ return true;
+ },
+ {
+ message: "Machine rate is required",
+ path: ["machineRate"],
+ }
+ )
.refine(
(data) => {
if (data.operationType === "Inside") {
diff --git a/apps/carbon/app/modules/sales/types.ts b/apps/carbon/app/modules/sales/types.ts
index 47941b8827..5d526b6739 100644
--- a/apps/carbon/app/modules/sales/types.ts
+++ b/apps/carbon/app/modules/sales/types.ts
@@ -28,6 +28,7 @@ export type Costs = {
laborCost: number;
laborHours: number;
machineHours: number;
+ machineCost: number;
materialCost: number;
overheadCost: number;
outsideCost: number;
@@ -43,6 +44,7 @@ export type CostEffects = {
laborCost: QuantityEffect[];
laborHours: QuantityEffect[];
machineHours: QuantityEffect[];
+ machineCost: QuantityEffect[];
materialCost: QuantityEffect[];
outsideCost: QuantityEffect[];
overheadCost: QuantityEffect[];
diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx
index 508a74aada..66623f30e5 100644
--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx
@@ -64,7 +64,7 @@ const CustomerForm = ({
<div>
<ModalCardProvider type={type}>
<ModalCard onClose={onClose}>
- <ModalCardContent>
+ <ModalCardContent size="medium">
<ValidatedForm
method="post"
action={isEditing ? undefined : path.to.newCustomer}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
index c36d09d6f6..b7db5e42ae 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
@@ -112,6 +112,7 @@ const initialOperation: Omit<Operation, "quoteMakeMethodId" | "order"> = {
laborRate: 0,
laborTime: 0,
laborUnit: "Minutes/Piece",
+ machineRate: 0,
machineTime: 0,
machineUnit: "Minutes/Piece",
operationUnitCost: 0,
@@ -196,7 +197,7 @@ const QuoteBillOfProcess = ({
setItems((prevItems) => prevItems.filter((item) => item.id !== id));
const response = await supabase
- ?.from("methodOperation")
+ ?.from("quoteOperation")
.delete()
.eq("id", id);
if (response?.error) {
@@ -570,6 +571,7 @@ function OperationForm({
laborRate: number;
laborUnit: string;
laborUnitHint: string;
+ machineRate: number;
machineUnit: string;
machineUnitHint: string;
operationMinimumCost: number;
@@ -585,6 +587,7 @@ function OperationForm({
laborRate: item.data.laborRate ?? 0,
laborUnit: item.data.laborUnit ?? "Hours/Piece",
laborUnitHint: getUnitHint(item.data.laborUnit),
+ machineRate: item.data.machineRate ?? 0,
machineUnit: item.data.machineUnit ?? "Hours/Piece",
machineUnitHint: getUnitHint(item.data.machineUnit),
operationMinimumCost: item.data.operationMinimumCost ?? 0,
@@ -620,8 +623,6 @@ function OperationForm({
description: process.data?.name ?? "",
laborUnit: process.data?.defaultStandardFactor ?? "Hours/Piece",
laborUnitHint: getUnitHint(process.data?.defaultStandardFactor),
- machineUnit: process.data?.defaultStandardFactor ?? "Hours/Piece",
- machineUnitHint: getUnitHint(process.data?.defaultStandardFactor),
laborRate:
// get the average labor rate from the work centers
activeWorkCenters.length
@@ -629,12 +630,21 @@ function OperationForm({
return (acc += workCenter.workCenter?.laborRate ?? 0);
}, 0) / activeWorkCenters.length
: p.laborRate,
+ machineUnit: process.data?.defaultStandardFactor ?? "Hours/Piece",
+ machineUnitHint: getUnitHint(process.data?.defaultStandardFactor),
+ machineRate:
+ // get the average labor rate from the work centers
+ activeWorkCenters.length
+ ? activeWorkCenters.reduce((acc, workCenter) => {
+ return (acc += workCenter.workCenter?.machineRate ?? 0);
+ }, 0) / activeWorkCenters.length
+ : p.machineRate,
// get the average quoting rate from the work centers
overheadRate: activeWorkCenters.length
? activeWorkCenters?.reduce((acc, workCenter) => {
return (acc += workCenter.workCenter?.overheadRate ?? 0);
}, 0) / activeWorkCenters.length
- : p.laborRate,
+ : p.overheadRate,
operationMinimumCost:
supplierProcesses.data && supplierProcesses.data.length > 0
? supplierProcesses.data.reduce((acc, sp) => {
@@ -676,12 +686,13 @@ function OperationForm({
setProcessData((d) => ({
...d,
+ laborRate: data?.laborRate ?? 0,
laborUnit: data?.defaultStandardFactor ?? "Hours/Piece",
laborUnitHint: getUnitHint(data?.defaultStandardFactor),
+ machineRate: data?.machineRate ?? 0,
machineUnit: data?.defaultStandardFactor ?? "Hours/Piece",
machineUnitHint: getUnitHint(data?.defaultStandardFactor),
overheadRate: data?.overheadRate ?? 0,
- laborRate: data?.laborRate ?? 0,
}));
};
@@ -934,10 +945,10 @@ function OperationForm({
/>
<NumberControlled
- name="overheadRate"
- label="Overhead Rate"
+ name="laborRate"
+ label="Labor Rate"
minValue={0}
- value={processData.overheadRate}
+ value={processData.laborRate}
formatOptions={{
style: "currency",
currency: "USD",
@@ -945,15 +956,15 @@ function OperationForm({
onChange={(newValue) =>
setProcessData((d) => ({
...d,
- overheadRate: newValue,
+ laborRate: newValue,
}))
}
/>
<NumberControlled
- name="laborRate"
- label="Labor Rate"
+ name="machineRate"
+ label="Machine Rate"
minValue={0}
- value={processData.laborRate}
+ value={processData.machineRate}
formatOptions={{
style: "currency",
currency: "USD",
@@ -961,7 +972,23 @@ function OperationForm({
onChange={(newValue) =>
setProcessData((d) => ({
...d,
- laborRate: newValue,
+ machineRate: newValue,
+ }))
+ }
+ />
+ <NumberControlled
+ name="overheadRate"
+ label="Overhead Rate"
+ minValue={0}
+ value={processData.overheadRate}
+ formatOptions={{
+ style: "currency",
+ currency: "USD",
+ }}
+ onChange={(newValue) =>
+ setProcessData((d) => ({
+ ...d,
+ overheadRate: newValue,
}))
}
/>
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
index 9221915ee9..992fa93883 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
@@ -21,10 +21,11 @@ import {
useDisclosure,
VStack,
} from "@carbon/react";
+import { formatDurationHours } from "@carbon/utils";
import { useLocale } from "@react-aria/i18n";
import { useParams } from "@remix-run/react";
import { useMemo } from "react";
-import { LuInfo } from "react-icons/lu";
+import { LuClock, LuInfo } from "react-icons/lu";
import { MethodItemTypeIcon, TimeTypeIcon } from "~/modules/shared";
import type { Costs } from "../../types";
@@ -306,48 +307,20 @@ const QuoteLineCosting = ({
<Tr>
<Td className="border-r border-border ">
<HStack className="w-full justify-between ">
- <span>Total Labor Cost</span>
- <Enumerable value="Labor" />
+ <span>Total Direct Cost</span>
+ <Enumerable value="Direct" />
</HStack>
</Td>
{quantityCosts.map(({ quantity, costs }, index) => {
+ const totalDirectCost =
+ (costs.laborCost ?? 0) + (costs.machineCost ?? 0);
return (
<Td key={quantity.toString()}>
<VStack spacing={0}>
- <span>
- {costs.laborCost
- ? formatter.format(costs.laborCost)
- : formatter.format(0)}
- </span>
- <span className="text-muted-foreground text-xs">
- {costs.laborCost && quantity > 0
- ? formatter.format(costs.laborCost / quantity)
- : formatter.format(0)}
- </span>
- </VStack>
- </Td>
- );
- })}
- </Tr>
- <Tr>
- <Td className="border-r border-border ">
- <HStack className="w-full justify-between ">
- <span>Total Overhead Cost</span>
- <Enumerable value="Overhead" />
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }, index) => {
- return (
- <Td key={quantity.toString()}>
- <VStack spacing={0}>
- <span>
- {costs.overheadCost
- ? formatter.format(costs.overheadCost)
- : formatter.format(0)}
- </span>
+ <span>{formatter.format(totalDirectCost)}</span>
<span className="text-muted-foreground text-xs">
- {costs.overheadCost && quantity > 0
- ? formatter.format(costs.overheadCost / quantity)
+ {totalDirectCost && quantity > 0
+ ? formatter.format(totalDirectCost / quantity)
: formatter.format(0)}
</span>
</VStack>
@@ -355,16 +328,17 @@ const QuoteLineCosting = ({
);
})}
</Tr>
+
{detailsDisclosure.isOpen && (
<>
<Tr>
<Td className="border-r border-border pl-10 ">
<HStack className="w-full justify-between ">
<span className="whitespace-nowrap flex items-center justify-start gap-2">
- Setup Hours
+ Labor Costs
</span>
<Badge variant="secondary">
- <TimeTypeIcon type="Setup" />
+ <TimeTypeIcon type="Labor" />
</Badge>
</HStack>
</Td>
@@ -372,11 +346,15 @@ const QuoteLineCosting = ({
return (
<Td key={quantity.toString()}>
<VStack spacing={0}>
- <span>{(costs.setupHours ?? 0).toFixed(2)}</span>
+ <span>
+ {costs.laborCost
+ ? formatter.format(costs.laborCost)
+ : formatter.format(0)}
+ </span>
<span className="text-muted-foreground text-xs">
- {costs.setupHours && quantity > 0
- ? (costs.setupHours / quantity).toFixed(2)
- : (0).toFixed(2)}
+ {costs.laborCost && quantity > 0
+ ? formatter.format(costs.laborCost / quantity)
+ : formatter.format(0)}
</span>
</VStack>
</Td>
@@ -384,25 +362,27 @@ const QuoteLineCosting = ({
})}
</Tr>
<Tr>
- <Td className="border-r border-border pl-10 ">
+ <Td className="border-r border-border pl-14 ">
<HStack className="w-full justify-between ">
<span className="whitespace-nowrap flex items-center justify-start gap-2">
Labor Hours
</span>
<Badge variant="secondary">
- <TimeTypeIcon type="Labor" />
+ <LuClock />
</Badge>
</HStack>
</Td>
{quantityCosts.map(({ quantity, costs }) => {
+ const laborHours =
+ (costs.laborHours ?? 0) + (costs.setupHours ?? 0);
return (
<Td key={quantity.toString()}>
<VStack spacing={0}>
- <span>{(costs.laborHours ?? 0).toFixed(2)}</span>
+ <span>{formatDurationHours(laborHours)}</span>
<span className="text-muted-foreground text-xs">
- {costs.laborHours && quantity > 0
- ? (costs.laborHours / quantity).toFixed(2)
- : (0).toFixed(2)}
+ {laborHours && quantity > 0
+ ? formatDurationHours(laborHours / quantity)
+ : formatDurationHours(0)}
</span>
</VStack>
</Td>
@@ -413,7 +393,7 @@ const QuoteLineCosting = ({
<Td className="border-r border-border pl-10 ">
<HStack className="w-full justify-between ">
<span className="whitespace-nowrap flex items-center justify-start gap-2">
- Machine Hours
+ Machine Costs
</span>
<Badge variant="secondary">
<TimeTypeIcon type="Machine" />
@@ -424,11 +404,42 @@ const QuoteLineCosting = ({
return (
<Td key={quantity.toString()}>
<VStack spacing={0}>
- <span>{(costs.machineHours ?? 0).toFixed(2)}</span>
+ <span>
+ {costs.machineCost
+ ? formatter.format(costs.machineCost)
+ : formatter.format(0)}
+ </span>
<span className="text-muted-foreground text-xs">
- {costs.machineHours && quantity > 0
- ? (costs.machineHours / quantity).toFixed(2)
- : (0).toFixed(2)}
+ {costs.machineCost && quantity > 0
+ ? formatter.format(costs.machineCost / quantity)
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ <Tr>
+ <Td className="border-r border-border pl-14 ">
+ <HStack className="w-full justify-between ">
+ <span className="whitespace-nowrap flex items-center justify-start gap-2">
+ Machine Hours
+ </span>
+ <Badge variant="secondary">
+ <LuClock />
+ </Badge>
+ </HStack>
+ </Td>
+ {quantityCosts.map(({ quantity, costs }) => {
+ const machineHours = costs.machineHours ?? 0;
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>{formatDurationHours(machineHours)}</span>
+ <span className="text-muted-foreground text-xs">
+ {machineHours && quantity > 0
+ ? formatDurationHours(machineHours / quantity)
+ : formatDurationHours(0)}
</span>
</VStack>
</Td>
@@ -437,6 +448,32 @@ const QuoteLineCosting = ({
</Tr>
</>
)}
+ <Tr>
+ <Td className="border-r border-border ">
+ <HStack className="w-full justify-between ">
+ <span>Total Indirect Cost</span>
+ <Enumerable value="Overhead" />
+ </HStack>
+ </Td>
+ {quantityCosts.map(({ quantity, costs }, index) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>
+ {costs.overheadCost
+ ? formatter.format(costs.overheadCost)
+ : formatter.format(0)}
+ </span>
+ <span className="text-muted-foreground text-xs">
+ {costs.overheadCost && quantity > 0
+ ? formatter.format(costs.overheadCost / quantity)
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
<Tr>
<Td className="border-r border-border ">
<HStack className="w-full justify-between ">
@@ -468,15 +505,16 @@ const QuoteLineCosting = ({
<Td className="border-r border-border ">Total Estimated Cost</Td>
{quantityCosts.map(({ quantity, costs }) => {
const totalCost =
- costs.materialCost +
- costs.partCost +
- costs.toolCost +
- costs.fixtureCost +
costs.consumableCost +
- costs.serviceCost +
+ costs.fixtureCost +
costs.laborCost +
+ costs.machineCost +
+ costs.materialCost +
+ costs.outsideCost +
costs.overheadCost +
- costs.outsideCost;
+ costs.partCost +
+ costs.serviceCost +
+ costs.toolCost;
return (
<Td key={quantity.toString()}>
<VStack spacing={0}>
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
index bcf8b228fd..c4ac7c3015 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
@@ -174,14 +174,15 @@ const QuoteLinePricing = ({
const unitCostsByQuantity = quantities.map((quantity, index) => {
const costs = getLineCosts(quantity);
const totalCost =
- (costs.materialCost +
- costs.partCost +
- costs.toolCost +
+ (costs.consumableCost +
costs.fixtureCost +
- costs.consumableCost +
- costs.serviceCost +
costs.laborCost +
+ costs.machineCost +
+ costs.materialCost +
costs.overheadCost +
+ costs.partCost +
+ costs.serviceCost +
+ costs.toolCost +
costs.outsideCost) /
quantity;
return totalCost;
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/useLineCosts.tsx b/apps/carbon/app/modules/sales/ui/Quotes/useLineCosts.tsx
index 8c3c7e5286..72a29b6e42 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/useLineCosts.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/useLineCosts.tsx
@@ -13,6 +13,7 @@ const defaultEffects: CostEffects = {
fixtureCost: [],
laborCost: [],
laborHours: [],
+ machineCost: [],
machineHours: [],
materialCost: [],
outsideCost: [],
@@ -180,11 +181,10 @@ export function useLineCosts({
});
}
- let laborHoursPerUnit = 0;
- let machineHoursPerUnit = 0;
-
let laborFixedHours = 0;
+ let laborHoursPerUnit = 0;
let machineFixedHours = 0;
+ let machineHoursPerUnit = 0;
if (operation.laborTime) {
// normalize production standard to hours
@@ -233,6 +233,16 @@ export function useLineCosts({
laborHoursPerUnit * quantity * data.quantity + laborFixedHours
);
});
+
+ effects.laborCost.push((quantity) => {
+ return (
+ laborHoursPerUnit *
+ quantity *
+ data.quantity *
+ (operation.laborRate ?? 0) +
+ laborFixedHours * (operation.laborRate ?? 0)
+ );
+ });
}
if (operation.machineTime) {
@@ -283,29 +293,32 @@ export function useLineCosts({
machineFixedHours
);
});
- }
- effects.laborCost.push((quantity) => {
- return (
- laborHoursPerUnit *
- quantity *
- data.quantity *
- (operation.laborRate ?? 0) +
- laborFixedHours * (operation.laborRate ?? 0)
- );
- });
+ effects.machineCost.push((quantity) => {
+ return (
+ machineHoursPerUnit *
+ quantity *
+ data.quantity *
+ (operation.machineRate ?? 0) +
+ machineFixedHours * (operation.machineRate ?? 0)
+ );
+ });
+ }
const hoursPerUnit = Math.max(laborHoursPerUnit, machineHoursPerUnit);
const fixedHours = Math.max(laborFixedHours, machineFixedHours);
effects.overheadCost.push((quantity) => {
- return (
- hoursPerUnit *
+ if (hoursPerUnit * quantity * data.quantity > fixedHours) {
+ return (
+ hoursPerUnit *
quantity *
data.quantity *
- (operation.overheadRate ?? 0) +
- fixedHours * (operation.overheadRate ?? 0)
- );
+ (operation.overheadRate ?? 0)
+ );
+ } else {
+ return fixedHours * (operation.overheadRate ?? 0);
+ }
});
} else if (operation.operationType === "Outside") {
effects.outsideCost.push((quantity) => {
@@ -389,24 +402,30 @@ export function useLineCosts({
0
);
+ const machineCost = costEffects.machineCost.reduce(
+ (acc, effect) => acc + effect(quantity),
+ 0
+ );
+
const machineHours = costEffects.machineHours.reduce(
(acc, effect) => acc + effect(quantity),
0
);
return {
- materialCost,
- partCost,
- toolCost,
- fixtureCost,
consumableCost,
- serviceCost,
+ fixtureCost,
laborCost,
- overheadCost,
- outsideCost,
- setupHours,
laborHours,
+ machineCost,
machineHours,
+ materialCost,
+ outsideCost,
+ overheadCost,
+ partCost,
+ serviceCost,
+ setupHours,
+ toolCost,
};
},
[costEffects]
diff --git a/apps/carbon/app/routes/x+/resources+/work-centers.$id.tsx b/apps/carbon/app/routes/x+/resources+/work-centers.$id.tsx
index e2adffe7cf..4f077ad5f7 100644
--- a/apps/carbon/app/routes/x+/resources+/work-centers.$id.tsx
+++ b/apps/carbon/app/routes/x+/resources+/work-centers.$id.tsx
@@ -84,15 +84,16 @@ export default function WorkCenterRoute() {
const initialValues = {
id: workCenter?.id ?? undefined,
- name: workCenter?.name ?? "",
+ defaultStandardFactor: workCenter?.defaultStandardFactor ?? "Minutes/Piece",
description: workCenter?.description ?? "",
- requiredAbilityId: workCenter?.requiredAbilityId ?? undefined,
laborRate: workCenter?.laborRate ?? 0,
- overheadRate: workCenter?.overheadRate ?? 0,
- defaultStandardFactor: workCenter?.defaultStandardFactor ?? "Minutes/Piece",
locationId: workCenter?.locationId ?? "",
+ machineRate: workCenter?.machineRate ?? 0,
+ name: workCenter?.name ?? "",
+ overheadRate: workCenter?.overheadRate ?? 0,
// @ts-ignore
processes: (workCenter?.processes ?? []).map((p) => p.id) ?? [],
+ requiredAbilityId: workCenter?.requiredAbilityId ?? undefined,
...getCustomFields(workCenter?.customFields),
};
diff --git a/apps/carbon/app/routes/x+/resources+/work-centers.new.tsx b/apps/carbon/app/routes/x+/resources+/work-centers.new.tsx
index 3e857a2088..cbd8f90aaf 100644
--- a/apps/carbon/app/routes/x+/resources+/work-centers.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/work-centers.new.tsx
@@ -59,12 +59,13 @@ export default function NewWorkCenterRoute() {
const { defaults } = useUser();
const initialValues = {
- name: "",
+ defaultStandardFactor: "Minutes/Piece" as "Minutes/Piece",
description: "",
laborRate: 0,
- overheadRate: 0,
- defaultStandardFactor: "Minutes/Piece" as "Minutes/Piece",
locationId: defaults?.locationId ?? "",
+ machineRate: 0,
+ name: "",
+ overheadRate: 0,
processes: [],
};
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 0da9fa2eac..aa45cfef80 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -7912,7 +7912,6 @@ export type Database = {
operationSupplierProcessId: string | null
operationType: Database["public"]["Enums"]["operationType"]
order: number
- overheadRate: number
processId: string
setupTime: number
setupUnit: Database["public"]["Enums"]["factor"]
@@ -7936,7 +7935,6 @@ export type Database = {
operationSupplierProcessId?: string | null
operationType?: Database["public"]["Enums"]["operationType"]
order?: number
- overheadRate?: number
processId: string
setupTime?: number
setupUnit?: Database["public"]["Enums"]["factor"]
@@ -7960,7 +7958,6 @@ export type Database = {
operationSupplierProcessId?: string | null
operationType?: Database["public"]["Enums"]["operationType"]
order?: number
- overheadRate?: number
processId?: string
setupTime?: number
setupUnit?: Database["public"]["Enums"]["factor"]
@@ -13476,6 +13473,7 @@ export type Database = {
laborRate: number
laborTime: number
laborUnit: Database["public"]["Enums"]["factor"]
+ machineRate: number | null
machineTime: number
machineUnit: Database["public"]["Enums"]["factor"]
operationLeadTime: number
@@ -13507,6 +13505,7 @@ export type Database = {
laborRate?: number
laborTime?: number
laborUnit?: Database["public"]["Enums"]["factor"]
+ machineRate?: number | null
machineTime?: number
machineUnit?: Database["public"]["Enums"]["factor"]
operationLeadTime?: number
@@ -13538,6 +13537,7 @@ export type Database = {
laborRate?: number
laborTime?: number
laborUnit?: Database["public"]["Enums"]["factor"]
+ machineRate?: number | null
machineTime?: number
machineUnit?: Database["public"]["Enums"]["factor"]
operationLeadTime?: number
@@ -19669,6 +19669,7 @@ export type Database = {
id: string
laborRate: number
locationId: string | null
+ machineRate: number
name: string
overheadRate: number
requiredAbilityId: string | null
@@ -19686,6 +19687,7 @@ export type Database = {
id?: string
laborRate?: number
locationId?: string | null
+ machineRate?: number
name: string
overheadRate?: number
requiredAbilityId?: string | null
@@ -19703,6 +19705,7 @@ export type Database = {
id?: string
laborRate?: number
locationId?: string | null
+ machineRate?: number
name?: string
overheadRate?: number
requiredAbilityId?: string | null
@@ -23607,6 +23610,7 @@ export type Database = {
laborRate: number | null
laborTime: number | null
laborUnit: Database["public"]["Enums"]["factor"] | null
+ machineRate: number | null
machineTime: number | null
machineUnit: Database["public"]["Enums"]["factor"] | null
makeMethodId: string | null
@@ -26335,6 +26339,7 @@ export type Database = {
laborRate: number | null
locationId: string | null
locationName: string | null
+ machineRate: number | null
name: string | null
overheadRate: number | null
processes: Json | null
diff --git a/packages/database/supabase/functions/get-method/index.ts b/packages/database/supabase/functions/get-method/index.ts
index 6f0752edee..f7d5ef587a 100644
--- a/packages/database/supabase/functions/get-method/index.ts
+++ b/packages/database/supabase/functions/get-method/index.ts
@@ -689,8 +689,6 @@ serve(async (req: Request) => {
let quoteMethodTree: QuoteMethodTreeItem | null = null;
- console.log({ quoteMakeMethodId, fullQuoteMethodTree });
-
traverseQuoteMethod(
fullQuoteMethodTree,
(node: QuoteMethodTreeItem) => {
@@ -1017,11 +1015,12 @@ const getRatesFromWorkCenters =
(
processId: string,
workCenterId: string | null
- ): { overheadRate: number; laborRate: number } => {
+ ): { overheadRate: number; laborRate: number; machineRate: number } => {
if (!workCenters) {
return {
- overheadRate: 0,
laborRate: 0,
+ machineRate: 0,
+ overheadRate: 0,
};
}
@@ -1032,8 +1031,9 @@ const getRatesFromWorkCenters =
if (workCenter) {
return {
- overheadRate: workCenter.overheadRate ?? 0,
laborRate: workCenter.laborRate ?? 0,
+ machineRate: workCenter.machineRate ?? 0,
+ overheadRate: workCenter.overheadRate ?? 0,
};
}
}
@@ -1044,24 +1044,32 @@ const getRatesFromWorkCenters =
});
if (relatedWorkCenters.length > 0) {
- const overheadRate =
- relatedWorkCenters.reduce((acc, workCenter) => {
- return (acc += workCenter.overheadRate ?? 0);
- }, 0) / relatedWorkCenters.length;
const laborRate =
relatedWorkCenters.reduce((acc, workCenter) => {
return (acc += workCenter.laborRate ?? 0);
}, 0) / relatedWorkCenters.length;
+ const machineRate =
+ relatedWorkCenters.reduce((acc, workCenter) => {
+ return (acc += workCenter.machineRate ?? 0);
+ }, 0) / relatedWorkCenters.length;
+
+ const overheadRate =
+ relatedWorkCenters.reduce((acc, workCenter) => {
+ return (acc += workCenter.overheadRate ?? 0);
+ }, 0) / relatedWorkCenters.length;
+
return {
- overheadRate,
laborRate,
+ machineRate,
+ overheadRate,
};
}
return {
- overheadRate: 0,
laborRate: 0,
+ machineRate: 0,
+ overheadRate: 0,
};
};
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 0da9fa2eac..aa45cfef80 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -7912,7 +7912,6 @@ export type Database = {
operationSupplierProcessId: string | null
operationType: Database["public"]["Enums"]["operationType"]
order: number
- overheadRate: number
processId: string
setupTime: number
setupUnit: Database["public"]["Enums"]["factor"]
@@ -7936,7 +7935,6 @@ export type Database = {
operationSupplierProcessId?: string | null
operationType?: Database["public"]["Enums"]["operationType"]
order?: number
- overheadRate?: number
processId: string
setupTime?: number
setupUnit?: Database["public"]["Enums"]["factor"]
@@ -7960,7 +7958,6 @@ export type Database = {
operationSupplierProcessId?: string | null
operationType?: Database["public"]["Enums"]["operationType"]
order?: number
- overheadRate?: number
processId?: string
setupTime?: number
setupUnit?: Database["public"]["Enums"]["factor"]
@@ -13476,6 +13473,7 @@ export type Database = {
laborRate: number
laborTime: number
laborUnit: Database["public"]["Enums"]["factor"]
+ machineRate: number | null
machineTime: number
machineUnit: Database["public"]["Enums"]["factor"]
operationLeadTime: number
@@ -13507,6 +13505,7 @@ export type Database = {
laborRate?: number
laborTime?: number
laborUnit?: Database["public"]["Enums"]["factor"]
+ machineRate?: number | null
machineTime?: number
machineUnit?: Database["public"]["Enums"]["factor"]
operationLeadTime?: number
@@ -13538,6 +13537,7 @@ export type Database = {
laborRate?: number
laborTime?: number
laborUnit?: Database["public"]["Enums"]["factor"]
+ machineRate?: number | null
machineTime?: number
machineUnit?: Database["public"]["Enums"]["factor"]
operationLeadTime?: number
@@ -19669,6 +19669,7 @@ export type Database = {
id: string
laborRate: number
locationId: string | null
+ machineRate: number
name: string
overheadRate: number
requiredAbilityId: string | null
@@ -19686,6 +19687,7 @@ export type Database = {
id?: string
laborRate?: number
locationId?: string | null
+ machineRate?: number
name: string
overheadRate?: number
requiredAbilityId?: string | null
@@ -19703,6 +19705,7 @@ export type Database = {
id?: string
laborRate?: number
locationId?: string | null
+ machineRate?: number
name?: string
overheadRate?: number
requiredAbilityId?: string | null
@@ -23607,6 +23610,7 @@ export type Database = {
laborRate: number | null
laborTime: number | null
laborUnit: Database["public"]["Enums"]["factor"] | null
+ machineRate: number | null
machineTime: number | null
machineUnit: Database["public"]["Enums"]["factor"] | null
makeMethodId: string | null
@@ -26335,6 +26339,7 @@ export type Database = {
laborRate: number | null
locationId: string | null
locationName: string | null
+ machineRate: number | null
name: string | null
overheadRate: number | null
processes: Json | null
diff --git a/packages/database/supabase/migrations/20240823024502_outside-operations.sql b/packages/database/supabase/migrations/20240823024502_outside-operations.sql
index 22d91f1394..01977280d5 100644
--- a/packages/database/supabase/migrations/20240823024502_outside-operations.sql
+++ b/packages/database/supabase/migrations/20240823024502_outside-operations.sql
@@ -12,10 +12,10 @@ COMMIT;
ALTER TABLE "workCenter"
DROP COLUMN "quotingRate" CASCADE,
+ ADD COLUMN "machineRate" NUMERIC(10,4) NOT NULL DEFAULT 0,
ADD COLUMN "overheadRate" NUMERIC(10,4) NOT NULL DEFAULT 0;
-
CREATE TABLE "supplierProcess" (
"id" TEXT NOT NULL DEFAULT xid(),
"supplierId" TEXT NOT NULL,
@@ -92,13 +92,13 @@ CREATE VIEW "supplierProcesses" WITH(SECURITY_INVOKER=true) AS
ALTER TABLE "methodOperation"
- ADD COLUMN "overheadRate" NUMERIC(10,4) NOT NULL DEFAULT 0,
ADD COLUMN "operationType" "operationType" NOT NULL DEFAULT 'Inside',
ADD COLUMN "operationSupplierProcessId" TEXT,
ADD CONSTRAINT "quoteOperation_operationSupplierProcessId_fkey" FOREIGN KEY ("operationSupplierProcessId") REFERENCES "supplierProcess" ("id") ON DELETE SET NULL;;
ALTER TABLE "quoteOperation"
+ ADD COLUMN "machineRate" NUMERIC(10,4),
ADD COLUMN "operationType" "operationType" NOT NULL DEFAULT 'Inside',
ADD COLUMN "operationMinimumCost" NUMERIC(10,4) NOT NULL DEFAULT 0,
ADD COLUMN "operationLeadTime" NUMERIC(10,4) NOT NULL DEFAULT 0,
diff --git a/packages/react/src/ModalCard.tsx b/packages/react/src/ModalCard.tsx
index 21309e4f02..1641f33a44 100644
--- a/packages/react/src/ModalCard.tsx
+++ b/packages/react/src/ModalCard.tsx
@@ -90,13 +90,15 @@ const ModalCardContent = forwardRef<
| ComponentPropsWithoutRef<typeof ModalContent>
| ComponentPropsWithoutRef<"div">
>((props, ref) => {
+ // @ts-expect-error
+ const { size, ...rest } = props;
const type = useModalCardType();
if (type === "card") {
return <div {...props} ref={ref} />;
}
- return <ModalContent {...props} size="xlarge" ref={ref} />;
+ return <ModalContent {...rest} size={size ?? "xlarge"} ref={ref} />;
});
ModalCardContent.displayName = "ModalCardContent";
diff --git a/packages/utils/src/duration.ts b/packages/utils/src/duration.ts
index 93653901aa..7bd45d7116 100644
--- a/packages/utils/src/duration.ts
+++ b/packages/utils/src/duration.ts
@@ -26,6 +26,13 @@ export function formatDuration(
const aboveOneSecondUnits = ["d", "h", "m", "s"] as Unit[];
const belowOneSecondUnits = ["ms"] as Unit[];
+export function formatDurationHours(
+ hours: number,
+ options?: DurationOptions
+): string {
+ return formatDurationMilliseconds(hours * 1000 * 60 * 60, options);
+}
+
export function formatDurationMilliseconds(
milliseconds: number,
options?: DurationOptions