Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: add db methods for quote materials
Brad Barbin73b729910d2d
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.tsindex 964682d006..a4769f5423 100644--- a/apps/carbon/app/modules/sales/sales.models.ts+++ b/apps/carbon/app/modules/sales/sales.models.ts@@ -106,6 +106,20 @@ export const quotationAssemblyValidator = withZod(}));+export const quotationMaterialValidator = withZod(+ z.object({+ id: zfd.text(z.string().optional()),+ quoteId: z.string(),+ partId: z.string().min(1, { message: "Part is required" }),+ quantity: zfd.numeric(+ z.number().min(1, { message: "Quantity is required" })+ ),+ description: z.string().min(1, { message: "Description is required" }),+ unitCost: zfd.numeric(z.number().min(0)),+ unitOfMeasureCode: zfd.text(z.string().optional()),+ })+);+export const quotationOperationValidator = withZod(z.object({id: zfd.text(z.string().optional()),diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex 32236e17f9..8717dddc16 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -12,6 +12,7 @@ import type {customerValidator,quotationAssemblyValidator,quotationLineValidator,+ quotationMaterialValidator,quotationOperationValidator,quotationValidator,} from "./sales.models";@@ -68,6 +69,13 @@ export async function deleteQuoteLine(return client.from("quoteLine").delete().eq("id", quoteLineId);}+export async function deleteQuoteMaterial(+ client: SupabaseClient<Database>,+ quoteMaterialId: string+) {+ return client.from("quoteMaterial").delete().eq("id", quoteMaterialId);+}+export async function deleteQuoteOperation(client: SupabaseClient<Database>,quoteOperationId: string@@ -345,6 +353,33 @@ export async function getQuoteLineQuantities(.eq("quoteLineId", quoteLineId);}+export async function getQuoteMaterials(+ client: SupabaseClient<Database>,+ quoteId: string+) {+ return client.from("quoteMaterial").select("*").eq("quoteId", quoteId);+}++export async function getQuoteMaterialsByLine(+ client: SupabaseClient<Database>,+ quoteLineId: string+) {+ return client+ .from("quoteMaterial")+ .select("*")+ .eq("quoteLineId", quoteLineId);+}++export async function getQuoteMaterialsByOperation(+ client: SupabaseClient<Database>,+ quoteOperationId: string+) {+ return client+ .from("quoteMaterial")+ .select("*")+ .eq("quoteOperationId", quoteOperationId);+}+export async function getQuoteOperation(client: SupabaseClient<Database>,quoteOperationId: string@@ -698,6 +733,38 @@ export async function upsertQuoteLine(return client.from("quoteLine").insert([quotationLine]).select("id").single();}+export async function upsertQuoteMaterial(+ client: SupabaseClient<Database>,+ quotationMaterial:+ | (Omit<TypeOfValidator<typeof quotationMaterialValidator>, "id"> & {+ quoteId: string;+ quoteLineId: string;+ quoteOperationId: string;+ createdBy: string;+ })+ | (Omit<TypeOfValidator<typeof quotationMaterialValidator>, "id"> & {+ id: string;+ quoteId: string;+ quoteLineId: string;+ quoteOperationId: string;+ updatedBy: string;+ })+) {+ if ("id" in quotationMaterial) {+ return client+ .from("quoteMaterial")+ .update(sanitize(quotationMaterial))+ .eq("id", quotationMaterial.id)+ .select("id")+ .single();+ }+ return client+ .from("quoteMaterial")+ .insert([quotationMaterial])+ .select("id")+ .single();+}+export async function upsertQuoteOperation(client: SupabaseClient<Database>,quotationOperation:diff --git a/apps/carbon/app/modules/sales/types.ts b/apps/carbon/app/modules/sales/types.tsindex 1707c2d2c9..93f671ba5b 100644--- a/apps/carbon/app/modules/sales/types.ts+++ b/apps/carbon/app/modules/sales/types.ts@@ -10,6 +10,8 @@ import type {getQuoteExternalDocuments,getQuoteLineQuantities,getQuoteLines,+ getQuoteMaterials,+ getQuoteOperation,getQuotes,} from "./sales.service";@@ -57,4 +59,12 @@ export type QuotationLineQuantity = NonNullable<Awaited<ReturnType<typeof getQuoteLineQuantities>>["data"]>[number];+export type QuotationMaterial = NonNullable<+ Awaited<ReturnType<typeof getQuoteMaterials>>["data"]+>[number];++export type QuotationOperation = NonNullable<+ Awaited<ReturnType<typeof getQuoteOperation>>["data"]+>;+export type QuotationStatusType = Database["public"]["Enums"]["quoteStatus"];diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLines/QuotationLineQuantities.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLines/QuotationLineQuantities.tsxindex 9f30d28c6d..a879d86269 100644--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLines/QuotationLineQuantities.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLines/QuotationLineQuantities.tsx@@ -228,6 +228,7 @@ const QuotationLineQuantities = ({data={quotationLineQuantities}columns={columns}canEdit={canEdit && isEditable}+ // @ts-ignoreeditableComponents={editableComponents}onNewRow={canEdit && isEditablediff --git a/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx b/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsxnew file mode 100644index 0000000000..ff1a7d7060--- /dev/null+++ b/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx@@ -0,0 +1,24 @@+import { atom } from "nanostores";+import { useNanoStore } from "~/hooks";+import type {+ QuotationAssembly,+ QuotationLine,+ QuotationMaterial,+ QuotationOperation,+} from "~/modules/sales";++type Quote = {+ lines: QuotationLine[];+ assemblies: QuotationAssembly[];+ operations: QuotationOperation[];+ materials: QuotationMaterial[];+};++const $quotationStore = atom<Quote>({+ lines: [],+ assemblies: [],+ operations: [],+ materials: [],+});++export const useParts = () => useNanoStore<Quote>($quotationStore);