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.

fix: total hours nested calculations

Brad Barbin259329ae4198
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx b/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
index e3612b6910..b2a9d3c186 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
@@ -112,6 +112,8 @@ const $quotationLinePriceEffects = computed($quotationStore, (store) => {
return acc;
}, {});
+ console.log("extendedQuantitiesPerAssembly", extendedQuantitiesPerAssembly);
+
operationsByLineId[line.id]?.forEach((operation: QuotationOperation) => {
let materials = materialsByOperationId[operation.id] ?? [];
let extendedQuantityPerAssembly = operation.quoteAssemblyId
@@ -150,6 +152,7 @@ const $quotationLinePriceEffects = computed($quotationStore, (store) => {
if (operation.productionStandard) {
let hoursPerProductionStandard = 0;
switch (operation.standardFactor) {
+ case "Total Hours":
case "Hours/Piece":
hoursPerProductionStandard = operation.productionStandard;
break;
@@ -159,6 +162,7 @@ const $quotationLinePriceEffects = computed($quotationStore, (store) => {
case "Hours/1000 Pieces":
hoursPerProductionStandard = operation.productionStandard / 1000;
break;
+ case "Total Minutes":
case "Minutes/Piece":
hoursPerProductionStandard = operation.productionStandard / 60;
break;
@@ -180,81 +184,42 @@ const $quotationLinePriceEffects = computed($quotationStore, (store) => {
case "Seconds/Piece":
hoursPerProductionStandard = operation.productionStandard / 3600;
break;
- case "Total Hours":
- hoursPerProductionStandard = operation.productionStandard;
- break;
- case "Total Minutes":
- hoursPerProductionStandard = operation.productionStandard / 60;
- break;
+
default:
break;
}
- if (
- ["Total Hours", "Total Minutes"].includes(operation.standardFactor)
- ) {
- effects[line.id].productionHours.push((quantity) => {
- return quantity * hoursPerProductionStandard;
+ effects[line.id].productionHours.push((quantity) => {
+ return (
+ hoursPerProductionStandard * quantity * extendedQuantityPerAssembly
+ );
+ });
+ if (operation.quotingRate) {
+ effects[line.id].overheadCost.push((quantity) => {
+ return (
+ hoursPerProductionStandard *
+ quantity *
+ extendedQuantityPerAssembly *
+ (operation.quotingRate ?? 0)
+ );
});
- if (operation.quotingRate) {
- effects[line.id].overheadCost.push((quantity) => {
- return (
- quantity *
- hoursPerProductionStandard *
- (operation.quotingRate ?? 0)
- );
- });
- } else {
- effects[line.id].laborCost.push((quantity) => {
- return (
- quantity *
- hoursPerProductionStandard *
- (operation.laborRate ?? 0)
- );
- });
- effects[line.id].overheadCost.push((quantity) => {
- return (
- quantity *
- hoursPerProductionStandard *
- (operation.overheadRate ?? 0)
- );
- });
- }
} else {
- effects[line.id].productionHours.push((quantity) => {
+ effects[line.id].laborCost.push((quantity) => {
+ return (
+ hoursPerProductionStandard *
+ quantity *
+ extendedQuantityPerAssembly *
+ (operation.laborRate ?? 0)
+ );
+ });
+ effects[line.id].overheadCost.push((quantity) => {
return (
hoursPerProductionStandard *
quantity *
- extendedQuantityPerAssembly
+ extendedQuantityPerAssembly *
+ (operation.overheadRate ?? 0)
);
});
- if (operation.quotingRate) {
- effects[line.id].overheadCost.push((quantity) => {
- return (
- hoursPerProductionStandard *
- quantity *
- extendedQuantityPerAssembly *
- (operation.quotingRate ?? 0)
- );
- });
- } else {
- effects[line.id].laborCost.push((quantity) => {
- return (
- hoursPerProductionStandard *
- quantity *
- extendedQuantityPerAssembly *
- (operation.laborRate ?? 0)
- );
- });
- effects[line.id].overheadCost.push((quantity) => {
- return (
- hoursPerProductionStandard *
- quantity *
- extendedQuantityPerAssembly *
- (operation.overheadRate ?? 0)
- );
- });
- }
}
}
});
diff --git a/apps/carbon/app/modules/settings/ui/Company/CompanyForm.tsx b/apps/carbon/app/modules/settings/ui/Company/CompanyForm.tsx
index b180a83c8c..cd25fb28c4 100644
--- a/apps/carbon/app/modules/settings/ui/Company/CompanyForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/Company/CompanyForm.tsx
@@ -1,4 +1,12 @@
-import { VStack } from "@carbon/react";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ VStack,
+} from "@carbon/react";
import { ValidatedForm } from "remix-validated-form";
import { Hidden, Input, Submit } from "~/components/Form";
import { companyValidator } from "~/modules/settings";
@@ -11,34 +19,43 @@ type CompanyFormProps = {
const CompanyForm = ({ company }: CompanyFormProps) => {
return (
- <div className="w-full">
+ <Card>
<ValidatedForm
method="post"
action={path.to.company}
validator={companyValidator}
defaultValues={company}
>
- <VStack spacing={4} className="my-4">
- <div className="grid grid-cols-1 md:grid-cols-2 gap-4 w-full">
- <Input name="name" label="Company Name" />
- <Input name="taxId" label="Tax ID" />
- <Input name="addressLine1" label="Address Line 1" />
- <Input name="addressLine2" label="Address Line 2" />
- <Input name="city" label="City" />
- <Input name="state" label="State" />
- <Input name="postalCode" label="Postal Code" />
- <Input name="countryCode" label="Country" />
- <Input name="phone" label="Phone Number" />
- <Input name="fax" label="Fax Number" />
- <Input name="email" label="Email" />
- <Input name="website" label="Website" />
- </div>
-
- <Hidden name="intent" value="about" />
+ <CardHeader>
+ <CardTitle>Company</CardTitle>
+ <CardDescription>
+ This information will be displayed on document headers.
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ <VStack spacing={4} className="my-4">
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4 w-full">
+ <Input name="name" label="Company Name" />
+ <Input name="taxId" label="Tax ID" />
+ <Input name="addressLine1" label="Address Line 1" />
+ <Input name="addressLine2" label="Address Line 2" />
+ <Input name="city" label="City" />
+ <Input name="state" label="State" />
+ <Input name="postalCode" label="Postal Code" />
+ <Input name="countryCode" label="Country" />
+ <Input name="phone" label="Phone Number" />
+ <Input name="fax" label="Fax Number" />
+ <Input name="email" label="Email" />
+ <Input name="website" label="Website" />
+ </div>
+ <Hidden name="intent" value="about" />
+ </VStack>
+ </CardContent>
+ <CardFooter>
<Submit>Save</Submit>
- </VStack>
+ </CardFooter>
</ValidatedForm>
- </div>
+ </Card>
);
};
diff --git a/apps/carbon/app/modules/settings/ui/Company/CompanyLogoForm.tsx b/apps/carbon/app/modules/settings/ui/Company/CompanyLogoForm.tsx
index 5ff5878718..d50b16ebf7 100644
--- a/apps/carbon/app/modules/settings/ui/Company/CompanyLogoForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/Company/CompanyLogoForm.tsx
@@ -64,7 +64,7 @@ const CompanyLogoForm = ({ company }: CompanyLogoFormProps) => {
};
return (
- <VStack className="items-center px-8">
+ <VStack className="items-center p-4">
{company?.logo ? (
<img
alt={`${company.name} Logo`}
diff --git a/apps/carbon/app/modules/settings/ui/Theme/ThemeForm.tsx b/apps/carbon/app/modules/settings/ui/Theme/ThemeForm.tsx
index 223688e6f5..20b070f37f 100644
--- a/apps/carbon/app/modules/settings/ui/Theme/ThemeForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/Theme/ThemeForm.tsx
@@ -1,4 +1,14 @@
-import { Button, VStack, cn } from "@carbon/react";
+import {
+ Button,
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ VStack,
+ cn,
+} from "@carbon/react";
import type { Theme } from "@carbon/utils";
import { themes } from "@carbon/utils";
import { useEffect, useState } from "react";
@@ -38,51 +48,61 @@ const ThemeForm = ({ theme: defaultValues }: ThemeFormProps) => {
}, [mode]);
return (
- <div className="w-full">
+ <Card>
<ValidatedForm
method="post"
action={path.to.theme}
validator={themeValidator}
defaultValues={defaultValues}
>
- <VStack spacing={4} className="max-w-[520px]">
- <Hidden name="theme" value={theme} />
- <div className="grid grid-cols-3 gap-4">
- {themes.map((t) => {
- const isActive = theme === t.name;
- return (
- <Button
- key={t.name}
- variant="secondary"
- onClick={() => onThemeChange(t)}
- className={cn(
- "justify-start",
- isActive && "border-2 border-primary"
- )}
- style={
- {
- "--theme-primary": `hsl(${
- t?.activeColor[mode === "dark" ? "dark" : "light"]
- })`,
- } as React.CSSProperties
- }
- >
- <span
+ <CardHeader>
+ <CardTitle>Theme</CardTitle>
+ <CardDescription>
+ This updates the theme for all users of the application
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ <VStack spacing={4} className="max-w-[520px]">
+ <Hidden name="theme" value={theme} />
+ <div className="grid grid-cols-3 gap-4">
+ {themes.map((t) => {
+ const isActive = theme === t.name;
+ return (
+ <Button
+ key={t.name}
+ variant="secondary"
+ onClick={() => onThemeChange(t)}
className={cn(
- "mr-1 flex h-5 w-5 shrink-0 -translate-x-1 items-center justify-center rounded-full bg-[--theme-primary]"
+ "justify-start",
+ isActive && "border-2 border-primary"
)}
+ style={
+ {
+ "--theme-primary": `hsl(${
+ t?.activeColor[mode === "dark" ? "dark" : "light"]
+ })`,
+ } as React.CSSProperties
+ }
>
- {isActive && <RxCheck className="h-4 w-4 text-white" />}
- </span>
- {t.label}
- </Button>
- );
- })}
- </div>
+ <span
+ className={cn(
+ "mr-1 flex h-5 w-5 shrink-0 -translate-x-1 items-center justify-center rounded-full bg-[--theme-primary]"
+ )}
+ >
+ {isActive && <RxCheck className="h-4 w-4 text-white" />}
+ </span>
+ {t.label}
+ </Button>
+ );
+ })}
+ </div>
+ </VStack>
+ </CardContent>
+ <CardFooter>
<Submit>Save</Submit>
- </VStack>
+ </CardFooter>
</ValidatedForm>
- </div>
+ </Card>
);
};
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index cd5019ee63..f3990e7b50 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -3,12 +3,14 @@ import {
Heading,
IconButton,
Input,
+ Kbd,
Menubar,
MenubarItem,
Tooltip,
TooltipContent,
TooltipTrigger,
VStack,
+ useKeyboardShortcuts,
} from "@carbon/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
@@ -18,7 +20,7 @@ import {
useNavigate,
useParams,
} from "@remix-run/react";
-import { useEffect } from "react";
+import { useEffect, useRef } from "react";
import { IoMdAdd } from "react-icons/io";
import { CollapsibleSidebar } from "~/components/Layout";
import { useSupabase } from "~/lib/supabase";
@@ -138,6 +140,14 @@ export default function QuotationRoute() {
const { id } = useParams();
if (!id) throw new Error("id not found");
+ const buttonRef = useRef<HTMLButtonElement>(null);
+ useKeyboardShortcuts({
+ l: (event: KeyboardEvent) => {
+ event.stopPropagation();
+ buttonRef.current?.click();
+ },
+ });
+
return (
<div className="grid grid-cols-1 md:grid-cols-[auto_1fr] w-full">
<CollapsibleSidebar width={260}>
@@ -156,10 +166,13 @@ export default function QuotationRoute() {
aria-label="Add Quote Line"
variant="secondary"
icon={<IoMdAdd />}
+ ref={buttonRef}
onClick={() => navigate(path.to.newQuoteLine(id))}
/>
</TooltipTrigger>
- <TooltipContent>Add Quote Line</TooltipContent>
+ <TooltipContent>
+ Add Quote Line <Kbd>l</Kbd>
+ </TooltipContent>
</Tooltip>
</HStack>
</VStack>
diff --git a/apps/carbon/app/routes/x+/settings+/company.tsx b/apps/carbon/app/routes/x+/settings+/company.tsx
index de8eeda541..1858d7a09c 100644
--- a/apps/carbon/app/routes/x+/settings+/company.tsx
+++ b/apps/carbon/app/routes/x+/settings+/company.tsx
@@ -2,7 +2,6 @@ import { VStack } from "@carbon/react";
import type { ActionFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { validationError } from "remix-validated-form";
-import { PageTitle } from "~/components/Layout";
import { useRouteData } from "~/hooks";
import type { Company as CompanyType } from "~/modules/settings";
import {
@@ -107,12 +106,8 @@ export default function Company() {
};
return (
- <VStack spacing={0} className="bg-background p-8 h-full">
- <PageTitle
- title="Company"
- subtitle="This information will be displayed on document headers."
- />
- <div className="grid grid-cols-1 md:grid-cols-[1fr_auto] gap-8 w-full">
+ <VStack spacing={0} className="p-4 h-full">
+ <div className="grid grid-cols-1 md:grid-cols-[1fr_auto] gap-4 w-full">
<CompanyForm company={initialValues} />
<CompanyLogoForm company={company} />
</div>
diff --git a/apps/carbon/app/routes/x+/settings+/theme.tsx b/apps/carbon/app/routes/x+/settings+/theme.tsx
index 4bd837dbb6..52a48b760b 100644
--- a/apps/carbon/app/routes/x+/settings+/theme.tsx
+++ b/apps/carbon/app/routes/x+/settings+/theme.tsx
@@ -3,7 +3,6 @@ import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { validationError } from "remix-validated-form";
-import { PageTitle } from "~/components/Layout";
import type { Theme as ThemeValue } from "~/modules/settings";
import {
ThemeForm,
@@ -75,12 +74,7 @@ export default function Theme() {
};
return (
- <VStack spacing={0} className="bg-background p-8 h-full">
- <PageTitle
- title="Theme"
- subtitle="Pick a style and color scheme that suits you best."
- />
-
+ <VStack spacing={0} className="p-4 h-full">
<ThemeForm theme={initialValues} />
</VStack>
);
diff --git a/packages/react/src/Form/FormLabel.tsx b/packages/react/src/Form/FormLabel.tsx
index c15719ebe8..1e0b87668b 100644
--- a/packages/react/src/Form/FormLabel.tsx
+++ b/packages/react/src/Form/FormLabel.tsx
@@ -1,35 +1,12 @@
import type { ComponentPropsWithoutRef, ElementRef } from "react";
import { forwardRef } from "react";
-import { cn } from "~/utils/cn";
-import type { FormControlOptions } from "./FormControl";
import { useFormControlContext } from "./FormControl";
-import type { VariantProps } from "class-variance-authority";
-import { cva } from "class-variance-authority";
import * as ReactAria from "react-aria-components";
-const labelVariants = cva(
- "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 text-foreground",
- {
- variants: {
- isInvalid: {
- true: "text-destructive",
- },
- },
- defaultVariants: {
- isInvalid: false,
- },
- }
-);
-
-export interface FormLabelProps
- extends ComponentPropsWithoutRef<typeof ReactAria.Label>,
- Omit<VariantProps<typeof labelVariants>, "isInvalid">,
- FormControlOptions {}
-
export const FormLabel = forwardRef<
ElementRef<typeof ReactAria.Label>,
- FormLabelProps
+ ComponentPropsWithoutRef<typeof ReactAria.Label>
>((props, ref) => {
const { className, children, ...rest } = props;
@@ -37,12 +14,7 @@ export const FormLabel = forwardRef<
const labelProps = field?.getLabelProps(rest, ref) ?? { ref, ...rest };
return (
- <ReactAria.Label
- {...labelProps}
- ref={ref}
- className={cn(labelVariants({ isInvalid: field?.isInvalid }), className)}
- {...props}
- >
+ <ReactAria.Label {...labelProps} ref={ref} className={className} {...props}>
{children}
{field?.isRequired && <span className="text-destructive"> *</span>}
</ReactAria.Label>
diff --git a/packages/utils/src/themes.ts b/packages/utils/src/themes.ts
index 463d75c39a..7907d6b4d6 100644
--- a/packages/utils/src/themes.ts
+++ b/packages/utils/src/themes.ts
@@ -89,7 +89,7 @@ export const themes = [
"card-foreground": "0 0% 98%",
popover: "0 0% 8.9%",
"popover-foreground": "0 0% 98%",
- primary: "0 0% 98%",
+ primary: "30 24% 81%",
"primary-foreground": "0 0% 9%",
secondary: "0 0% 14.9%",
"secondary-foreground": "0 0% 98%",