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: calibration dates on gauge record

Brad Barbinda931a4b97e5
diff --git a/apps/erp/app/modules/quality/quality.models.ts b/apps/erp/app/modules/quality/quality.models.ts
index 308858cbb5..763832abaa 100644
--- a/apps/erp/app/modules/quality/quality.models.ts
+++ b/apps/erp/app/modules/quality/quality.models.ts
@@ -78,6 +78,11 @@ export const gaugeValidator = z.object({
nextCalibrationDate: zfd.text(z.string().optional()),
locationId: zfd.text(z.string().optional()),
shelfId: zfd.text(z.string().optional()),
+ calibrationIntervalInMonths: zfd.numeric(
+ z.number().min(1, {
+ message: "Calibration interval is required",
+ })
+ ),
});
export const gaugeTypeValidator = z.object({
diff --git a/apps/erp/app/modules/quality/ui/Gauge/GaugeForm.tsx b/apps/erp/app/modules/quality/ui/Gauge/GaugeForm.tsx
index 2eaed79600..02e8d41c39 100644
--- a/apps/erp/app/modules/quality/ui/Gauge/GaugeForm.tsx
+++ b/apps/erp/app/modules/quality/ui/Gauge/GaugeForm.tsx
@@ -11,7 +11,10 @@ import {
ModalDrawerTitle,
VStack,
} from "@carbon/react";
+import { parseDate } from "@internationalized/date";
import { useFetcher } from "@remix-run/react";
+import { useState } from "react";
+import { LuCalendar } from "react-icons/lu";
import type { z } from "zod";
import { Enumerable } from "~/components/Enumerable";
import {
@@ -19,6 +22,7 @@ import {
Hidden,
Input,
Location,
+ NumberControlled,
SequenceOrCustomId,
Shelf,
Submit,
@@ -54,6 +58,12 @@ const GaugeForm = ({
? !permissions.can("update", "quality")
: !permissions.can("create", "quality");
+ const [calibrationInterval, setCalibrationInterval] = useState({
+ lastCalibrationDate: initialValues.lastCalibrationDate,
+ nextCalibrationDate: initialValues.nextCalibrationDate,
+ calibrationIntervalInMonths: initialValues.calibrationIntervalInMonths ?? 6,
+ });
+
return (
<ModalDrawerProvider type={type}>
<ModalDrawer
@@ -133,10 +143,32 @@ const GaugeForm = ({
<DatePicker
name="lastCalibrationDate"
label="Last Calibration Date"
+ value={calibrationInterval.lastCalibrationDate}
+ onChange={(value) => {
+ setCalibrationInterval({
+ ...calibrationInterval,
+ lastCalibrationDate: value?.toString(),
+ nextCalibrationDate: value
+ ? parseDate(value?.toString())
+ .add({
+ months:
+ calibrationInterval.calibrationIntervalInMonths,
+ })
+ .toString()
+ : undefined,
+ });
+ }}
/>
<DatePicker
name="nextCalibrationDate"
label="Next Calibration Date"
+ value={calibrationInterval.nextCalibrationDate}
+ onChange={(value) => {
+ setCalibrationInterval({
+ ...calibrationInterval,
+ nextCalibrationDate: value?.toString(),
+ });
+ }}
/>
<Location name="locationId" label="Location" />
<Shelf
@@ -146,6 +178,28 @@ const GaugeForm = ({
/>
<CustomFormFields table="gauge" />
</div>
+ <div className="border bg-muted/30 rounded-lg p-4 relative w-full">
+ <LuCalendar className="absolute top-2 right-4 text-muted-foreground" />
+ <NumberControlled
+ name="calibrationIntervalInMonths"
+ label="Calibration Interval (Months)"
+ value={calibrationInterval.calibrationIntervalInMonths}
+ onChange={(value) => {
+ setCalibrationInterval({
+ ...calibrationInterval,
+ calibrationIntervalInMonths: value,
+ nextCalibrationDate:
+ calibrationInterval.lastCalibrationDate
+ ? parseDate(calibrationInterval.lastCalibrationDate)
+ .add({
+ months: value,
+ })
+ .toString()
+ : undefined,
+ });
+ }}
+ />
+ </div>
</VStack>
</ModalDrawerBody>
<ModalDrawerFooter>
diff --git a/apps/erp/app/routes/x+/quality+/gauges.$id.tsx b/apps/erp/app/routes/x+/quality+/gauges.$id.tsx
index 80c6584a36..4243a614c4 100644
--- a/apps/erp/app/routes/x+/quality+/gauges.$id.tsx
+++ b/apps/erp/app/routes/x+/quality+/gauges.$id.tsx
@@ -124,6 +124,7 @@ export default function GaugeRoute() {
nextCalibrationDate: gauge.nextCalibrationDate ?? "",
locationId: gauge.locationId ?? "",
shelfId: gauge.shelfId ?? "",
+ calibrationIntervalInMonths: gauge.calibrationIntervalInMonths ?? 6,
...getCustomFields(gauge.customFields),
};
diff --git a/apps/erp/app/routes/x+/quality+/gauges.new.tsx b/apps/erp/app/routes/x+/quality+/gauges.new.tsx
index 4d49c04732..cf1080aab7 100644
--- a/apps/erp/app/routes/x+/quality+/gauges.new.tsx
+++ b/apps/erp/app/routes/x+/quality+/gauges.new.tsx
@@ -123,6 +123,7 @@ export default function GaugeNewRoute() {
nextCalibrationDate: "",
locationId: defaults.locationId ?? "",
shelfId: "",
+ calibrationIntervalInMonths: 6,
};
return (
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 117e0891fd..4f930b94cb 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -7485,6 +7485,9 @@ export default {
{
$ref: "#/parameters/rowFilter.gauges.gaugeRole",
},
+ {
+ $ref: "#/parameters/rowFilter.gauges.calibrationIntervalInMonths",
+ },
{
$ref: "#/parameters/rowFilter.gauges.lastCalibrationDate",
},
@@ -7610,6 +7613,9 @@ export default {
{
$ref: "#/parameters/rowFilter.gauges.gaugeRole",
},
+ {
+ $ref: "#/parameters/rowFilter.gauges.calibrationIntervalInMonths",
+ },
{
$ref: "#/parameters/rowFilter.gauges.lastCalibrationDate",
},
@@ -7689,6 +7695,9 @@ export default {
{
$ref: "#/parameters/rowFilter.gauges.gaugeRole",
},
+ {
+ $ref: "#/parameters/rowFilter.gauges.calibrationIntervalInMonths",
+ },
{
$ref: "#/parameters/rowFilter.gauges.lastCalibrationDate",
},
@@ -46017,6 +46026,9 @@ export default {
{
$ref: "#/parameters/rowFilter.gauge.gaugeRole",
},
+ {
+ $ref: "#/parameters/rowFilter.gauge.calibrationIntervalInMonths",
+ },
{
$ref: "#/parameters/rowFilter.gauge.lastCalibrationDate",
},
@@ -46139,6 +46151,9 @@ export default {
{
$ref: "#/parameters/rowFilter.gauge.gaugeRole",
},
+ {
+ $ref: "#/parameters/rowFilter.gauge.calibrationIntervalInMonths",
+ },
{
$ref: "#/parameters/rowFilter.gauge.lastCalibrationDate",
},
@@ -46215,6 +46230,9 @@ export default {
{
$ref: "#/parameters/rowFilter.gauge.gaugeRole",
},
+ {
+ $ref: "#/parameters/rowFilter.gauge.calibrationIntervalInMonths",
+ },
{
$ref: "#/parameters/rowFilter.gauge.lastCalibrationDate",
},
@@ -56222,7 +56240,7 @@ export default {
properties: {
id: {
description:
- "Note:\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
+ "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
format: "text",
type: "string",
},
@@ -56271,7 +56289,7 @@ export default {
},
supplierLocationId: {
description:
- "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
+ "Note:\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
format: "text",
type: "string",
},
@@ -56492,6 +56510,10 @@ export default {
format: 'public."gaugeRole"',
type: "string",
},
+ calibrationIntervalInMonths: {
+ format: "integer",
+ type: "integer",
+ },
lastCalibrationDate: {
format: "date",
type: "string",
@@ -74530,6 +74552,7 @@ export default {
"gaugeCalibrationStatus",
"gaugeStatus",
"gaugeRole",
+ "calibrationIntervalInMonths",
"customFields",
"createdAt",
"createdBy",
@@ -74591,6 +74614,11 @@ export default {
format: 'public."gaugeRole"',
type: "string",
},
+ calibrationIntervalInMonths: {
+ default: 6,
+ format: "integer",
+ type: "integer",
+ },
lastCalibrationDate: {
format: "date",
type: "string",
@@ -79521,6 +79549,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.gauges.calibrationIntervalInMonths": {
+ name: "calibrationIntervalInMonths",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"rowFilter.gauges.lastCalibrationDate": {
name: "lastCalibrationDate",
required: false,
@@ -99918,6 +99952,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.gauge.calibrationIntervalInMonths": {
+ name: "calibrationIntervalInMonths",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"rowFilter.gauge.lastCalibrationDate": {
name: "lastCalibrationDate",
required: false,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 5bd3536d2d..9f04e1f07d 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -6175,6 +6175,7 @@ export type Database = {
}
gauge: {
Row: {
+ calibrationIntervalInMonths: number
companyId: string | null
createdAt: string
createdBy: string
@@ -6198,6 +6199,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ calibrationIntervalInMonths?: number
companyId?: string | null
createdAt?: string
createdBy: string
@@ -6221,6 +6223,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ calibrationIntervalInMonths?: number
companyId?: string | null
createdAt?: string
createdBy?: string
@@ -32762,6 +32765,7 @@ export type Database = {
}
gauges: {
Row: {
+ calibrationIntervalInMonths: number | null
companyId: string | null
createdAt: string | null
createdBy: string | null
@@ -32790,6 +32794,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ calibrationIntervalInMonths?: number | null
companyId?: string | null
createdAt?: string | null
createdBy?: string | null
@@ -32816,6 +32821,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ calibrationIntervalInMonths?: number | null
companyId?: string | null
createdAt?: string | null
createdBy?: string | null
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 5bd3536d2d..9f04e1f07d 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -6175,6 +6175,7 @@ export type Database = {
}
gauge: {
Row: {
+ calibrationIntervalInMonths: number
companyId: string | null
createdAt: string
createdBy: string
@@ -6198,6 +6199,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ calibrationIntervalInMonths?: number
companyId?: string | null
createdAt?: string
createdBy: string
@@ -6221,6 +6223,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ calibrationIntervalInMonths?: number
companyId?: string | null
createdAt?: string
createdBy?: string
@@ -32762,6 +32765,7 @@ export type Database = {
}
gauges: {
Row: {
+ calibrationIntervalInMonths: number | null
companyId: string | null
createdAt: string | null
createdBy: string | null
@@ -32790,6 +32794,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ calibrationIntervalInMonths?: number | null
companyId?: string | null
createdAt?: string | null
createdBy?: string | null
@@ -32816,6 +32821,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ calibrationIntervalInMonths?: number | null
companyId?: string | null
createdAt?: string | null
createdBy?: string | null
diff --git a/packages/database/supabase/migrations/20250502132738_gauge-calibration.sql b/packages/database/supabase/migrations/20250502132738_gauge-calibration.sql
index 09f5b4347b..7aa4b7b803 100644
--- a/packages/database/supabase/migrations/20250502132738_gauge-calibration.sql
+++ b/packages/database/supabase/migrations/20250502132738_gauge-calibration.sql
@@ -130,6 +130,7 @@ CREATE TABLE "gauge" (
"gaugeCalibrationStatus" "gaugeCalibrationStatus" NOT NULL DEFAULT 'Pending',
"gaugeStatus" "gaugeStatus" NOT NULL DEFAULT 'Active',
"gaugeRole" "gaugeRole" NOT NULL DEFAULT 'Standard',
+ "calibrationIntervalInMonths" INTEGER NOT NULL DEFAULT 6,
"lastCalibrationDate" DATE,
"nextCalibrationDate" DATE,
"locationId" TEXT,
diff --git a/packages/form/src/components/DatePicker.tsx b/packages/form/src/components/DatePicker.tsx
index e68ff771e1..044f9becaf 100644
--- a/packages/form/src/components/DatePicker.tsx
+++ b/packages/form/src/components/DatePicker.tsx
@@ -8,7 +8,7 @@ import {
import { formatDate } from "@carbon/utils";
import type { CalendarDate } from "@internationalized/date";
import { parseDate } from "@internationalized/date";
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { flushSync } from "react-dom";
import { useField } from "../hooks";
@@ -19,6 +19,7 @@ type DatePickerProps = {
minValue?: CalendarDate;
maxValue?: CalendarDate;
inline?: boolean;
+ value?: string;
onChange?: (date: string | null) => void;
};
@@ -29,14 +30,25 @@ const DatePicker = ({
minValue,
maxValue,
inline = false,
+ value,
onChange,
}: DatePickerProps) => {
const { validate } = useFormContext();
const { error, defaultValue, validate: validateField } = useField(name);
const [date, setDate] = useState<CalendarDate | undefined>(
- defaultValue ? parseDate(defaultValue) : undefined
+ value
+ ? parseDate(value)
+ : defaultValue
+ ? parseDate(defaultValue)
+ : undefined
);
+ useEffect(() => {
+ if (value) {
+ setDate(parseDate(value));
+ }
+ }, [value]);
+
const handleChange = async (newDate: CalendarDate) => {
const formattedDate = newDate ? newDate.toString() : null;
flushSync(() => {