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: update quote pricing for overhead/outside processing

Brad Barbin9742f0f18729
diff --git a/apps/carbon/app/modules/sales/types.ts b/apps/carbon/app/modules/sales/types.ts
index 0483d7654c..47941b8827 100644
--- a/apps/carbon/app/modules/sales/types.ts
+++ b/apps/carbon/app/modules/sales/types.ts
@@ -27,13 +27,12 @@ export type Costs = {
fixtureCost: number;
laborCost: number;
laborHours: number;
- machineCost: number;
machineHours: number;
materialCost: number;
+ overheadCost: number;
outsideCost: number;
partCost: number;
serviceCost: number;
- setupCost: number;
setupHours: number;
toolCost: number;
};
@@ -43,13 +42,12 @@ export type CostEffects = {
fixtureCost: QuantityEffect[];
laborCost: QuantityEffect[];
laborHours: QuantityEffect[];
- machineCost: QuantityEffect[];
machineHours: QuantityEffect[];
materialCost: QuantityEffect[];
outsideCost: QuantityEffect[];
+ overheadCost: QuantityEffect[];
partCost: QuantityEffect[];
serviceCost: QuantityEffect[];
- setupCost: QuantityEffect[];
setupHours: QuantityEffect[];
toolCost: QuantityEffect[];
};
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
index b5d0cea113..9221915ee9 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
@@ -1,11 +1,13 @@
import {
Badge,
Card,
+ CardAction,
CardContent,
CardHeader,
CardTitle,
Enumerable,
HStack,
+ Switch,
Table,
Tbody,
Td,
@@ -16,6 +18,7 @@ import {
TooltipContent,
TooltipTrigger,
Tr,
+ useDisclosure,
VStack,
} from "@carbon/react";
import { useLocale } from "@react-aria/i18n";
@@ -49,11 +52,28 @@ const QuoteLineCosting = ({
[locale]
);
+ const detailsDisclosure = useDisclosure();
+
return (
<Card>
- <CardHeader>
- <CardTitle>Costing</CardTitle>
- </CardHeader>
+ <HStack className="justify-between items-start">
+ <CardHeader>
+ <CardTitle>Costing</CardTitle>
+ </CardHeader>
+ <CardAction>
+ <div className="flex items-center space-x-2 py-2">
+ <Switch
+ variant="small"
+ checked={detailsDisclosure.isOpen}
+ onCheckedChange={detailsDisclosure.onToggle}
+ id="cost-details"
+ />
+ <label className="text-sm" htmlFor="cost-details">
+ Show Details
+ </label>
+ </div>
+ </CardAction>
+ </HStack>
<CardContent>
<Table>
<Thead>
@@ -99,206 +119,209 @@ const QuoteLineCosting = ({
);
})}
</Tr>
- <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">
- Part Cost{" "}
- <Tooltip>
- <TooltipTrigger>
- <LuInfo className="w-4 h-4" />
- </TooltipTrigger>
- <TooltipContent>
- Includes bought and picked parts
- </TooltipContent>
- </Tooltip>
- </span>
- <Badge variant="secondary">
- <MethodItemTypeIcon type="Part" />
- </Badge>
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }) => {
- return (
- <Td key={quantity.toString()}>
- <VStack spacing={0}>
- <span>
- {costs.partCost
- ? formatter.format(costs.partCost)
- : formatter.format(0)}
+ {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">
+ Part Cost{" "}
+ <Tooltip>
+ <TooltipTrigger>
+ <LuInfo className="w-4 h-4" />
+ </TooltipTrigger>
+ <TooltipContent>
+ Includes bought and picked parts
+ </TooltipContent>
+ </Tooltip>
</span>
- <span className="text-muted-foreground text-xs">
- {costs.partCost && quantity > 0
- ? formatter.format(costs.partCost / quantity)
- : formatter.format(0)}
- </span>
- </VStack>
+ <Badge variant="secondary">
+ <MethodItemTypeIcon type="Part" />
+ </Badge>
+ </HStack>
</Td>
- );
- })}
- </Tr>
- <Tr>
- <Td className="border-r border-border pl-10 ">
- <HStack className="w-full justify-between ">
- <span className="whitespace-nowrap">Material Cost</span>
- <Badge variant="secondary">
- <MethodItemTypeIcon type="Material" />
- </Badge>
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }) => {
- return (
- <Td key={quantity.toString()}>
- <VStack spacing={0}>
- <span>
- {costs.materialCost
- ? formatter.format(costs.materialCost)
- : formatter.format(0)}
- </span>
- <span className="text-muted-foreground text-xs">
- {costs.materialCost && quantity > 0
- ? formatter.format(costs.materialCost / quantity)
- : formatter.format(0)}
- </span>
- </VStack>
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>
+ {costs.partCost
+ ? formatter.format(costs.partCost)
+ : formatter.format(0)}
+ </span>
+ <span className="text-muted-foreground text-xs">
+ {costs.partCost && quantity > 0
+ ? formatter.format(costs.partCost / quantity)
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ <Tr>
+ <Td className="border-r border-border pl-10 ">
+ <HStack className="w-full justify-between ">
+ <span className="whitespace-nowrap">Material Cost</span>
+ <Badge variant="secondary">
+ <MethodItemTypeIcon type="Material" />
+ </Badge>
+ </HStack>
</Td>
- );
- })}
- </Tr>
- <Tr>
- <Td className="border-r border-border pl-10 ">
- <HStack className="w-full justify-between ">
- <span className="whitespace-nowrap">Tooling Cost</span>
- <Badge variant="secondary">
- <MethodItemTypeIcon type="Tool" />
- </Badge>
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }) => {
- return (
- <Td key={quantity.toString()}>
- <VStack spacing={0}>
- <span>
- {costs.toolCost
- ? formatter.format(costs.toolCost)
- : formatter.format(0)}
- </span>
- <span className="text-muted-foreground text-xs">
- {costs.toolCost && quantity > 0
- ? formatter.format(costs.toolCost / quantity)
- : formatter.format(0)}
- </span>
- </VStack>
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>
+ {costs.materialCost
+ ? formatter.format(costs.materialCost)
+ : formatter.format(0)}
+ </span>
+ <span className="text-muted-foreground text-xs">
+ {costs.materialCost && quantity > 0
+ ? formatter.format(costs.materialCost / quantity)
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ <Tr>
+ <Td className="border-r border-border pl-10 ">
+ <HStack className="w-full justify-between ">
+ <span className="whitespace-nowrap">Tooling Cost</span>
+ <Badge variant="secondary">
+ <MethodItemTypeIcon type="Tool" />
+ </Badge>
+ </HStack>
</Td>
- );
- })}
- </Tr>
- <Tr>
- <Td className="border-r border-border pl-10 ">
- <HStack className="w-full justify-between ">
- <span className="whitespace-nowrap">Fixture Cost</span>
- <Badge variant="secondary">
- <MethodItemTypeIcon type="Fixture" />
- </Badge>
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }) => {
- return (
- <Td key={quantity.toString()}>
- <VStack spacing={0}>
- <span>
- {costs.fixtureCost
- ? formatter.format(costs.fixtureCost)
- : formatter.format(0)}
- </span>
- <span className="text-muted-foreground text-xs">
- {costs.fixtureCost && quantity > 0
- ? formatter.format(costs.fixtureCost / quantity)
- : formatter.format(0)}
- </span>
- </VStack>
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>
+ {costs.toolCost
+ ? formatter.format(costs.toolCost)
+ : formatter.format(0)}
+ </span>
+ <span className="text-muted-foreground text-xs">
+ {costs.toolCost && quantity > 0
+ ? formatter.format(costs.toolCost / quantity)
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ <Tr>
+ <Td className="border-r border-border pl-10 ">
+ <HStack className="w-full justify-between ">
+ <span className="whitespace-nowrap">Fixture Cost</span>
+ <Badge variant="secondary">
+ <MethodItemTypeIcon type="Fixture" />
+ </Badge>
+ </HStack>
</Td>
- );
- })}
- </Tr>
- <Tr>
- <Td className="border-r border-border pl-10 ">
- <HStack className="w-full justify-between ">
- <span className="whitespace-nowrap">Consumable Cost</span>
- <Badge variant="secondary">
- <MethodItemTypeIcon type="Consumable" />
- </Badge>
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }) => {
- return (
- <Td key={quantity.toString()}>
- <VStack spacing={0}>
- <span>
- {costs.consumableCost
- ? formatter.format(costs.consumableCost)
- : formatter.format(0)}
- </span>
- <span className="text-muted-foreground text-xs">
- {costs.consumableCost && quantity > 0
- ? formatter.format(costs.consumableCost / quantity)
- : formatter.format(0)}
- </span>
- </VStack>
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>
+ {costs.fixtureCost
+ ? formatter.format(costs.fixtureCost)
+ : formatter.format(0)}
+ </span>
+ <span className="text-muted-foreground text-xs">
+ {costs.fixtureCost && quantity > 0
+ ? formatter.format(costs.fixtureCost / quantity)
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ <Tr>
+ <Td className="border-r border-border pl-10 ">
+ <HStack className="w-full justify-between ">
+ <span className="whitespace-nowrap">Consumable Cost</span>
+ <Badge variant="secondary">
+ <MethodItemTypeIcon type="Consumable" />
+ </Badge>
+ </HStack>
</Td>
- );
- })}
- </Tr>
- <Tr>
- <Td className="border-r border-border pl-10 ">
- <HStack className="w-full justify-between ">
- <span className="whitespace-nowrap">Service Cost</span>
- <Badge variant="secondary">
- <MethodItemTypeIcon type="Service" />
- </Badge>
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }) => {
- return (
- <Td key={quantity.toString()}>
- <VStack spacing={0}>
- <span>
- {costs.serviceCost
- ? formatter.format(costs.serviceCost)
- : formatter.format(0)}
- </span>
- <span className="text-muted-foreground text-xs">
- {costs.serviceCost && quantity > 0
- ? formatter.format(costs.serviceCost / quantity)
- : formatter.format(0)}
- </span>
- </VStack>
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>
+ {costs.consumableCost
+ ? formatter.format(costs.consumableCost)
+ : formatter.format(0)}
+ </span>
+ <span className="text-muted-foreground text-xs">
+ {costs.consumableCost && quantity > 0
+ ? formatter.format(
+ costs.consumableCost / quantity
+ )
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ <Tr>
+ <Td className="border-r border-border pl-10 ">
+ <HStack className="w-full justify-between ">
+ <span className="whitespace-nowrap">Service Cost</span>
+ <Badge variant="secondary">
+ <MethodItemTypeIcon type="Service" />
+ </Badge>
+ </HStack>
</Td>
- );
- })}
- </Tr>
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>
+ {costs.serviceCost
+ ? formatter.format(costs.serviceCost)
+ : formatter.format(0)}
+ </span>
+ <span className="text-muted-foreground text-xs">
+ {costs.serviceCost && quantity > 0
+ ? formatter.format(costs.serviceCost / quantity)
+ : formatter.format(0)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ </>
+ )}
<Tr>
<Td className="border-r border-border ">
<HStack className="w-full justify-between ">
- <span>Total Time Cost</span>
- <Enumerable value="Time" />
+ <span>Total Labor Cost</span>
+ <Enumerable value="Labor" />
</HStack>
</Td>
{quantityCosts.map(({ quantity, costs }, index) => {
- const totalLaborCost =
- costs.setupCost + costs.laborCost + costs.machineCost;
-
return (
<Td key={quantity.toString()}>
<VStack spacing={0}>
<span>
- {totalLaborCost
- ? formatter.format(totalLaborCost)
+ {costs.laborCost
+ ? formatter.format(costs.laborCost)
: formatter.format(0)}
</span>
<span className="text-muted-foreground text-xs">
- {totalLaborCost && quantity > 0
- ? formatter.format(totalLaborCost / quantity)
+ {costs.laborCost && quantity > 0
+ ? formatter.format(costs.laborCost / quantity)
: formatter.format(0)}
</span>
</VStack>
@@ -307,28 +330,24 @@ const QuoteLineCosting = ({
})}
</Tr>
<Tr>
- <Td className="border-r border-border pl-10 ">
+ <Td className="border-r border-border ">
<HStack className="w-full justify-between ">
- <span className="whitespace-nowrap flex items-center justify-start gap-2">
- Setup Cost
- </span>
- <Badge variant="secondary">
- <TimeTypeIcon type="Setup" />
- </Badge>
+ <span>Total Overhead Cost</span>
+ <Enumerable value="Overhead" />
</HStack>
</Td>
- {quantityCosts.map(({ quantity, costs }) => {
+ {quantityCosts.map(({ quantity, costs }, index) => {
return (
<Td key={quantity.toString()}>
<VStack spacing={0}>
<span>
- {costs.setupCost
- ? formatter.format(costs.setupCost)
+ {costs.overheadCost
+ ? formatter.format(costs.overheadCost)
: formatter.format(0)}
</span>
<span className="text-muted-foreground text-xs">
- {costs.setupCost && quantity > 0
- ? formatter.format(costs.setupCost / quantity)
+ {costs.overheadCost && quantity > 0
+ ? formatter.format(costs.overheadCost / quantity)
: formatter.format(0)}
</span>
</VStack>
@@ -336,76 +355,98 @@ const QuoteLineCosting = ({
);
})}
</Tr>
- <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">
- Labor Cost
- </span>
- <Badge variant="secondary">
- <TimeTypeIcon type="Labor" />
- </Badge>
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }) => {
- 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)}
+ {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
</span>
- </VStack>
+ <Badge variant="secondary">
+ <TimeTypeIcon type="Setup" />
+ </Badge>
+ </HStack>
</Td>
- );
- })}
- </Tr>
- <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">
- Machine Cost
- </span>
- <Badge variant="secondary">
- <TimeTypeIcon type="Machine" />
- </Badge>
- </HStack>
- </Td>
- {quantityCosts.map(({ quantity, costs }) => {
- return (
- <Td key={quantity.toString()}>
- <VStack spacing={0}>
- <span>
- {costs.machineCost
- ? formatter.format(costs.machineCost)
- : formatter.format(0)}
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>{(costs.setupHours ?? 0).toFixed(2)}</span>
+ <span className="text-muted-foreground text-xs">
+ {costs.setupHours && quantity > 0
+ ? (costs.setupHours / quantity).toFixed(2)
+ : (0).toFixed(2)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ <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">
+ Labor Hours
</span>
- <span className="text-muted-foreground text-xs">
- {costs.machineCost && quantity > 0
- ? formatter.format(costs.machineCost / quantity)
- : formatter.format(0)}
+ <Badge variant="secondary">
+ <TimeTypeIcon type="Labor" />
+ </Badge>
+ </HStack>
+ </Td>
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>{(costs.laborHours ?? 0).toFixed(2)}</span>
+ <span className="text-muted-foreground text-xs">
+ {costs.laborHours && quantity > 0
+ ? (costs.laborHours / quantity).toFixed(2)
+ : (0).toFixed(2)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ <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">
+ Machine Hours
</span>
- </VStack>
+ <Badge variant="secondary">
+ <TimeTypeIcon type="Machine" />
+ </Badge>
+ </HStack>
</Td>
- );
- })}
- </Tr>
- {/* <Tr>
+ {quantityCosts.map(({ quantity, costs }) => {
+ return (
+ <Td key={quantity.toString()}>
+ <VStack spacing={0}>
+ <span>{(costs.machineHours ?? 0).toFixed(2)}</span>
+ <span className="text-muted-foreground text-xs">
+ {costs.machineHours && quantity > 0
+ ? (costs.machineHours / quantity).toFixed(2)
+ : (0).toFixed(2)}
+ </span>
+ </VStack>
+ </Td>
+ );
+ })}
+ </Tr>
+ </>
+ )}
+ <Tr>
<Td className="border-r border-border ">
<HStack className="w-full justify-between ">
- <span>Total Outside Processing</span>
- <Enumerable value="Subcontract" />
+ <span>Total Outside Cost</span>
+ <Enumerable value="Outside" />
</HStack>
</Td>
{quantityCosts.map(({ quantity, costs }) => {
return (
- <Td key={quantity.toString()} >
+ <Td key={quantity.toString()}>
<VStack spacing={0}>
<span>
{costs.outsideCost
@@ -421,15 +462,10 @@ const QuoteLineCosting = ({
</Td>
);
})}
- </Tr> */}
+ </Tr>
<Tr className="font-bold ">
- <Td className="border-r border-border ">
- <HStack className="w-full justify-between ">
- <span>Total Estimated Cost</span>
- <Enumerable value="Total" />
- </HStack>
- </Td>
+ <Td className="border-r border-border ">Total Estimated Cost</Td>
{quantityCosts.map(({ quantity, costs }) => {
const totalCost =
costs.materialCost +
@@ -438,9 +474,8 @@ const QuoteLineCosting = ({
costs.fixtureCost +
costs.consumableCost +
costs.serviceCost +
- costs.setupCost +
costs.laborCost +
- costs.machineCost +
+ costs.overheadCost +
costs.outsideCost;
return (
<Td key={quantity.toString()}>
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
index af004f211b..bcf8b228fd 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
@@ -181,8 +181,7 @@ const QuoteLinePricing = ({
costs.consumableCost +
costs.serviceCost +
costs.laborCost +
- costs.setupCost +
- costs.machineCost +
+ costs.overheadCost +
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 14e87e9496..cda78a54be 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/useLineCosts.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/useLineCosts.tsx
@@ -13,13 +13,12 @@ const defaultEffects: CostEffects = {
fixtureCost: [],
laborCost: [],
laborHours: [],
- machineCost: [],
machineHours: [],
materialCost: [],
outsideCost: [],
+ overheadCost: [],
partCost: [],
serviceCost: [],
- setupCost: [],
setupHours: [],
toolCost: [],
};
@@ -112,178 +111,209 @@ export function useLineCosts({
}
data.operations?.forEach((operation: QuotationOperation) => {
- if (operation.setupTime) {
- // normalize production standard to hours
- let hoursPerUnit = 0;
- let fixedHours = 0;
- switch (operation.setupUnit) {
- case "Total Hours":
- fixedHours = operation.setupTime;
- break;
- case "Total Minutes":
- fixedHours = operation.setupTime / 60;
- break;
- case "Hours/Piece":
- hoursPerUnit = operation.setupTime;
- break;
- case "Hours/100 Pieces":
- hoursPerUnit = operation.setupTime / 100;
- break;
- case "Hours/1000 Pieces":
- hoursPerUnit = operation.setupTime / 1000;
- break;
-
- case "Minutes/Piece":
- hoursPerUnit = operation.setupTime / 60;
- break;
- case "Minutes/100 Pieces":
- hoursPerUnit = operation.setupTime / 100 / 60;
- break;
- case "Minutes/1000 Pieces":
- hoursPerUnit = operation.setupTime / 1000 / 60;
- break;
- case "Pieces/Hour":
- hoursPerUnit = 1 / operation.setupTime;
- break;
- case "Pieces/Minute":
- hoursPerUnit = 1 / (operation.setupTime / 60);
- break;
- case "Seconds/Piece":
- hoursPerUnit = operation.setupTime / 3600;
- break;
- default:
- break;
+ if (operation.operationType === "Inside") {
+ if (operation.setupTime) {
+ // normalize production standard to hours
+ let hoursPerUnit = 0;
+ let fixedHours = 0;
+ switch (operation.setupUnit) {
+ case "Total Hours":
+ fixedHours = operation.setupTime;
+ break;
+ case "Total Minutes":
+ fixedHours = operation.setupTime / 60;
+ break;
+ case "Hours/Piece":
+ hoursPerUnit = operation.setupTime;
+ break;
+ case "Hours/100 Pieces":
+ hoursPerUnit = operation.setupTime / 100;
+ break;
+ case "Hours/1000 Pieces":
+ hoursPerUnit = operation.setupTime / 1000;
+ break;
+
+ case "Minutes/Piece":
+ hoursPerUnit = operation.setupTime / 60;
+ break;
+ case "Minutes/100 Pieces":
+ hoursPerUnit = operation.setupTime / 100 / 60;
+ break;
+ case "Minutes/1000 Pieces":
+ hoursPerUnit = operation.setupTime / 1000 / 60;
+ break;
+ case "Pieces/Hour":
+ hoursPerUnit = 1 / operation.setupTime;
+ break;
+ case "Pieces/Minute":
+ hoursPerUnit = 1 / (operation.setupTime / 60);
+ break;
+ case "Seconds/Piece":
+ hoursPerUnit = operation.setupTime / 3600;
+ break;
+ default:
+ break;
+ }
+
+ effects.setupHours.push((quantity) => {
+ return hoursPerUnit * quantity * data.quantity + fixedHours;
+ });
+
+ effects.laborCost.push((quantity) => {
+ return (
+ hoursPerUnit *
+ quantity *
+ data.quantity *
+ (operation.laborRate ?? 0) +
+ fixedHours * (operation.laborRate ?? 0)
+ );
+ });
+
+ effects.overheadCost.push((quantity) => {
+ return (
+ hoursPerUnit *
+ quantity *
+ data.quantity *
+ (operation.overheadRate ?? 0) +
+ fixedHours * (operation.overheadRate ?? 0)
+ );
+ });
}
- effects.setupHours.push((quantity) => {
- return hoursPerUnit * quantity * data.quantity + fixedHours;
- });
-
- effects.setupCost.push((quantity) => {
- return (
- hoursPerUnit *
- quantity *
- data.quantity *
- (operation.quotingRate ?? 0) +
- fixedHours * (operation.quotingRate ?? 0)
- );
- });
- }
-
- if (operation.laborTime) {
- // normalize production standard to hours
- let hoursPerUnit = 0;
- let fixedHours = 0;
- switch (operation.laborUnit) {
- case "Total Hours":
- fixedHours = operation.laborTime;
- break;
- case "Total Minutes":
- fixedHours = operation.laborTime / 60;
- break;
- case "Hours/Piece":
- hoursPerUnit = operation.laborTime;
- break;
- case "Hours/100 Pieces":
- hoursPerUnit = operation.laborTime / 100;
- break;
- case "Hours/1000 Pieces":
- hoursPerUnit = operation.laborTime / 1000;
- break;
-
- case "Minutes/Piece":
- hoursPerUnit = operation.laborTime / 60;
- break;
- case "Minutes/100 Pieces":
- hoursPerUnit = operation.laborTime / 100 / 60;
- break;
- case "Minutes/1000 Pieces":
- hoursPerUnit = operation.laborTime / 1000 / 60;
- break;
- case "Pieces/Hour":
- hoursPerUnit = 1 / operation.laborTime;
- break;
- case "Pieces/Minute":
- hoursPerUnit = 1 / (operation.laborTime / 60);
- break;
- case "Seconds/Piece":
- hoursPerUnit = operation.laborTime / 3600;
- break;
- default:
- break;
+ let laborHoursPerUnit = 0;
+ let machineHoursPerUnit = 0;
+
+ let laborFixedHours = 0;
+ let machineFixedHours = 0;
+
+ if (operation.laborTime) {
+ // normalize production standard to hours
+
+ switch (operation.laborUnit) {
+ case "Total Hours":
+ laborFixedHours = operation.laborTime;
+ break;
+ case "Total Minutes":
+ laborFixedHours = operation.laborTime / 60;
+ break;
+ case "Hours/Piece":
+ laborHoursPerUnit = operation.laborTime;
+ break;
+ case "Hours/100 Pieces":
+ laborHoursPerUnit = operation.laborTime / 100;
+ break;
+ case "Hours/1000 Pieces":
+ laborHoursPerUnit = operation.laborTime / 1000;
+ break;
+
+ case "Minutes/Piece":
+ laborHoursPerUnit = operation.laborTime / 60;
+ break;
+ case "Minutes/100 Pieces":
+ laborHoursPerUnit = operation.laborTime / 100 / 60;
+ break;
+ case "Minutes/1000 Pieces":
+ laborHoursPerUnit = operation.laborTime / 1000 / 60;
+ break;
+ case "Pieces/Hour":
+ laborHoursPerUnit = 1 / operation.laborTime;
+ break;
+ case "Pieces/Minute":
+ laborHoursPerUnit = 1 / (operation.laborTime / 60);
+ break;
+ case "Seconds/Piece":
+ laborHoursPerUnit = operation.laborTime / 3600;
+ break;
+ default:
+ break;
+ }
+
+ effects.laborHours.push((quantity) => {
+ return (
+ laborHoursPerUnit * quantity * data.quantity + laborFixedHours
+ );
+ });
}
- effects.laborHours.push((quantity) => {
- return hoursPerUnit * quantity * data.quantity + fixedHours;
- });
+ if (operation.machineTime) {
+ // normalize production standard to hours
+
+ switch (operation.machineUnit) {
+ case "Total Hours":
+ machineFixedHours = operation.machineTime;
+ break;
+ case "Total Minutes":
+ machineFixedHours = operation.machineTime / 60;
+ break;
+ case "Hours/Piece":
+ machineHoursPerUnit = operation.machineTime;
+ break;
+ case "Hours/100 Pieces":
+ machineHoursPerUnit = operation.machineTime / 100;
+ break;
+ case "Hours/1000 Pieces":
+ machineHoursPerUnit = operation.machineTime / 1000;
+ break;
+
+ case "Minutes/Piece":
+ machineHoursPerUnit = operation.machineTime / 60;
+ break;
+ case "Minutes/100 Pieces":
+ machineHoursPerUnit = operation.machineTime / 100 / 60;
+ break;
+ case "Minutes/1000 Pieces":
+ machineHoursPerUnit = operation.machineTime / 1000 / 60;
+ break;
+ case "Pieces/Hour":
+ machineHoursPerUnit = 1 / operation.machineTime;
+ break;
+ case "Pieces/Minute":
+ machineHoursPerUnit = 1 / (operation.machineTime / 60);
+ break;
+ case "Seconds/Piece":
+ machineHoursPerUnit = operation.machineTime / 3600;
+ break;
+ default:
+ break;
+ }
+
+ effects.machineHours.push((quantity) => {
+ return (
+ machineHoursPerUnit * quantity * data.quantity +
+ machineFixedHours
+ );
+ });
+ }
effects.laborCost.push((quantity) => {
return (
- hoursPerUnit *
+ laborHoursPerUnit *
quantity *
data.quantity *
- (operation.quotingRate ?? 0) +
- fixedHours * (operation.quotingRate ?? 0)
+ (operation.laborRate ?? 0) +
+ laborFixedHours * (operation.laborRate ?? 0)
);
});
- }
- if (operation.machineTime) {
- // normalize production standard to hours
- let hoursPerUnit = 0;
- let fixedHours = 0;
- switch (operation.machineUnit) {
- case "Total Hours":
- fixedHours = operation.machineTime;
- break;
- case "Total Minutes":
- fixedHours = operation.machineTime / 60;
- break;
- case "Hours/Piece":
- hoursPerUnit = operation.machineTime;
- break;
- case "Hours/100 Pieces":
- hoursPerUnit = operation.machineTime / 100;
- break;
- case "Hours/1000 Pieces":
- hoursPerUnit = operation.machineTime / 1000;
- break;
-
- case "Minutes/Piece":
- hoursPerUnit = operation.machineTime / 60;
- break;
- case "Minutes/100 Pieces":
- hoursPerUnit = operation.machineTime / 100 / 60;
- break;
- case "Minutes/1000 Pieces":
- hoursPerUnit = operation.machineTime / 1000 / 60;
- break;
- case "Pieces/Hour":
- hoursPerUnit = 1 / operation.machineTime;
- break;
- case "Pieces/Minute":
- hoursPerUnit = 1 / (operation.machineTime / 60);
- break;
- case "Seconds/Piece":
- hoursPerUnit = operation.machineTime / 3600;
- break;
- default:
- break;
- }
-
- effects.machineHours.push((quantity) => {
- return hoursPerUnit * quantity * data.quantity + fixedHours;
- });
+ const hoursPerUnit = Math.max(laborHoursPerUnit, machineHoursPerUnit);
+ const fixedHours = Math.max(laborFixedHours, machineFixedHours);
- effects.machineCost.push((quantity) => {
+ effects.overheadCost.push((quantity) => {
return (
hoursPerUnit *
quantity *
data.quantity *
- (operation.quotingRate ?? 0) +
- fixedHours * (operation.quotingRate ?? 0)
+ (operation.overheadRate ?? 0) +
+ fixedHours * (operation.overheadRate ?? 0)
);
});
+ } else if (operation.operationType === "Outside") {
+ console.log({ operation });
+ effects.outsideCost.push((quantity) => {
+ const unitCost =
+ operation.operationUnitCost * data.quantity * quantity;
+ return Math.max(operation.operationMinimumCost, unitCost);
+ });
}
});
@@ -340,12 +370,12 @@ export function useLineCosts({
0
);
- const setupCost = costEffects.setupCost.reduce(
+ const overheadCost = costEffects.overheadCost.reduce(
(acc, effect) => acc + effect(quantity),
0
);
- const machineCost = costEffects.machineCost.reduce(
+ const outsideCost = costEffects.outsideCost.reduce(
(acc, effect) => acc + effect(quantity),
0
);
@@ -373,9 +403,8 @@ export function useLineCosts({
consumableCost,
serviceCost,
laborCost,
- setupCost,
- machineCost,
- outsideCost: 0,
+ overheadCost,
+ outsideCost,
setupHours,
laborHours,
machineHours,