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 routes of quote payment and shipment
Brad Barbin10f734709cb1
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex 1cf3bcf590..2b1fdda784 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -19,6 +19,8 @@ import type {quoteLineValidator,quoteMaterialValidator,quoteOperationValidator,+ quotePaymentValidator,+ quoteShipmentValidator,quoteStatusType,quoteValidator,salesOrderLineValidator,@@ -785,28 +787,6 @@ export async function getSalesOrderShipment(.single();}-/*export async function getSalesOrderLocations(- client: SupabaseClient<Database>,- salesOrderId: string-) {- return client- .from("salesOrderLocations")- .select("*")- .eq("id", salesOrderId)- .single();-}*/--/*export async function getSalesOrderPayment(- client: SupabaseClient<Database>,- salesOrderId: string-) {- return client- .from("salesOrderPayment")- .select("*")- .eq("id", salesOrderId)- .single();-}*/-export async function getSalesOrderCustomers(client: SupabaseClient<Database>) {return client.from("salesOrderCustomers").select("id, name");}@@ -1729,6 +1709,60 @@ export async function upsertQuoteOperation(.single();}+export async function upsertQuotePayment(+ client: SupabaseClient<Database>,+ quotePayment:+ | (z.infer<typeof quotePaymentValidator> & {+ createdBy: string;+ customFields?: Json;+ })+ | (z.infer<typeof quotePaymentValidator> & {+ id: string;+ updatedBy: string;+ customFields?: Json;+ })+) {+ if ("id" in quotePayment) {+ return client+ .from("quotePayment")+ .update(sanitize(quotePayment))+ .eq("id", quotePayment.id)+ .select("id")+ .single();+ }+ return client+ .from("quotePayment")+ .insert([quotePayment])+ .select("id")+ .single();+}++export async function upsertQuoteShipment(+ client: SupabaseClient<Database>,+ quoteShipment:+ | (z.infer<typeof quoteShipmentValidator> & {+ createdBy: string;+ })+ | (z.infer<typeof quoteShipmentValidator> & {+ id: string;+ updatedBy: string;+ })+) {+ if ("id" in quoteShipment) {+ return client+ .from("quoteShipment")+ .update(sanitize(quoteShipment))+ .eq("id", quoteShipment.id)+ .select("id")+ .single();+ }+ return client+ .from("quoteShipment")+ .insert([quoteShipment])+ .select("id")+ .single();+}+export async function updateSalesOrderFavorite(client: SupabaseClient<Database>,args: {diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsxindex 2a998dda34..f27bcf8b0d 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx@@ -461,7 +461,7 @@ const LinePricingOptions = ({};function PaymentDetailsForm() {- const [isExpanded, setIsExpanded] = useState(false);+ const [isExpanded, setIsExpanded] = useState(true);const { quoteId } = useParams();if (!quoteId) throw new Error("Could not find quoteId");@@ -492,7 +492,7 @@ function PaymentDetailsForm() {<Table className="py-4"><Tbody><Tr>- <Td>Bill To</Td>+ <Td className="w-1/2">Bill To</Td><Td><CustomerAvatarcustomerId={quoteData?.payment.invoiceCustomerId ?? null}@@ -500,9 +500,9 @@ function PaymentDetailsForm() {</Td></Tr><Tr>- <Td>Payment Term</Td>+ <Td className="w-1/2">Payment Term</Td><Td>- <Enumerable value={paymentTerm?.value ?? null} />+ <Enumerable value={paymentTerm?.label ?? null} /></Td></Tr></Tbody>@@ -513,7 +513,7 @@ function PaymentDetailsForm() {}function CustomerDetailsForm() {- const [isExpanded, setIsExpanded] = useState(false);+ const [isExpanded, setIsExpanded] = useState(true);const { quoteId } = useParams();if (!quoteId) throw new Error("Could not find quoteId");@@ -539,7 +539,7 @@ function CustomerDetailsForm() {<Table className="py-4"><Tbody><Tr>- <Td>Customer</Td>+ <Td className="w-1/2">Customer</Td><Td><CustomerAvatarcustomerId={quoteData?.quote.customerId ?? null}@@ -547,7 +547,7 @@ function CustomerDetailsForm() {</Td></Tr><Tr>- <Td>Customer Ref:</Td>+ <Td className="w-1/2">Customer Ref:</Td><Td>{quoteData?.quote.customerReference}</Td></Tr></Tbody>@@ -558,7 +558,7 @@ function CustomerDetailsForm() {}function ShippingDetailsForm() {- const [isExpanded, setIsExpanded] = useState(false);+ const [isExpanded, setIsExpanded] = useState(true);const { quoteId } = useParams();if (!quoteId) throw new Error("Could not find quoteId");@@ -589,8 +589,8 @@ function ShippingDetailsForm() {<Table className="py-4"><Tbody><Tr>- <Td>Shipping Method</Td>- <Td>+ <Td className="w-1/2">Shipping Method</Td>+ <Td className="w-1/2"><Enumerable value={shippingMethod?.label ?? null} /></Td></Tr>diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.payment.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.payment.tsxnew file mode 100644index 0000000000..d4bebb5bc4--- /dev/null+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.payment.tsx@@ -0,0 +1,48 @@+import { validationError, validator } from "@carbon/form";+import type { ActionFunctionArgs } from "@remix-run/node";+import { redirect } from "@remix-run/node";+import { quotePaymentValidator, upsertQuotePayment } from "~/modules/sales";+import { requirePermissions } from "~/services/auth/auth.server";+import { flash } from "~/services/session.server";+import { setCustomFields } from "~/utils/form";+import { assertIsPost } from "~/utils/http";+import { path } from "~/utils/path";+import { error, success } from "~/utils/result";++export async function action({ request, params }: ActionFunctionArgs) {+ assertIsPost(request);+ const { client, userId } = await requirePermissions(request, {+ update: "sales",+ });++ const { quoteId } = params;+ if (!quoteId) throw new Error("Could not find quoteId");++ const formData = await request.formData();+ const validation = await validator(quotePaymentValidator).validate(formData);++ if (validation.error) {+ return validationError(validation.error);+ }++ const updateQuotePayment = await upsertQuotePayment(client, {+ ...validation.data,+ id: quoteId,+ updatedBy: userId,+ customFields: setCustomFields(formData),+ });+ if (updateQuotePayment.error) {+ throw redirect(+ path.to.quoteDetails(quoteId),+ await flash(+ request,+ error(updateQuotePayment.error, "Failed to update quote payment")+ )+ );+ }++ throw redirect(+ path.to.quoteDetails(quoteId),+ await flash(request, success("Updated quote payment"))+ );+}diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.shipment.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.shipment.tsxnew file mode 100644index 0000000000..7661aea59d--- /dev/null+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.shipment.tsx@@ -0,0 +1,46 @@+import { validationError, validator } from "@carbon/form";+import type { ActionFunctionArgs } from "@remix-run/node";+import { redirect } from "@remix-run/node";+import { quoteShipmentValidator, upsertQuoteShipment } from "~/modules/sales";+import { requirePermissions } from "~/services/auth/auth.server";+import { flash } from "~/services/session.server";+import { assertIsPost } from "~/utils/http";+import { path } from "~/utils/path";+import { error, success } from "~/utils/result";++export async function action({ request, params }: ActionFunctionArgs) {+ assertIsPost(request);+ const { client, userId } = await requirePermissions(request, {+ update: "sales",+ });++ const { quoteId } = params;+ if (!quoteId) throw new Error("Could not find quoteId");++ const formData = await request.formData();+ const validation = await validator(quoteShipmentValidator).validate(formData);++ if (validation.error) {+ return validationError(validation.error);+ }++ const updateQuoteShipment = await upsertQuoteShipment(client, {+ ...validation.data,+ id: quoteId,+ updatedBy: userId,+ });+ if (updateQuoteShipment.error) {+ throw redirect(+ path.to.quoteDetails(quoteId),+ await flash(+ request,+ error(updateQuoteShipment.error, "Failed to update quote shipment")+ )+ );+ }++ throw redirect(+ path.to.quoteDetails(quoteId),+ await flash(request, success("Updated quote shipment"))+ );+}diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsxindex 42b76d9c15..4007633daa 100644--- a/packages/documents/src/pdf/QuotePDF.tsx+++ b/packages/documents/src/pdf/QuotePDF.tsx@@ -104,7 +104,7 @@ const QuotePDF = ({/><View style={styles.row}><View style={{ ...styles.colThird, ...styles.header }}>- <Text style={styles.label}>Supplier</Text>+ <Text style={styles.label}>Customer</Text><Text>{customerName}</Text>{customerAddressLine1 && <Text>{customerAddressLine1}</Text>}{customerAddressLine2 && <Text>{customerAddressLine2}</Text>}