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: add popup to confirm receipt creation for lines with no PO

Brad Barbin40dea9a5f706
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptPostModal/ReceiptPostModal.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptPostModal/ReceiptPostModal.tsx
index c25e3949af..6d8c98958e 100644
--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptPostModal/ReceiptPostModal.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptPostModal/ReceiptPostModal.tsx
@@ -24,9 +24,7 @@ const ReceiptPostModal = (props: ReceiptPostModalProps) => {
<ModalContent>
<ModalHeader>Post Receipt</ModalHeader>
<ModalCloseButton />
- <ModalBody>
- Are you sure you want to post this receipt? This cannot be undone.
- </ModalBody>
+ <ModalBody>Are you sure you want to post this receipt?</ModalBody>
<ModalFooter>
<HStack spacing={2}>
diff --git a/apps/carbon/app/modules/invoicing/invoicing.models.ts b/apps/carbon/app/modules/invoicing/invoicing.models.ts
index 7dcdc70b9a..6d76e38edb 100644
--- a/apps/carbon/app/modules/invoicing/invoicing.models.ts
+++ b/apps/carbon/app/modules/invoicing/invoicing.models.ts
@@ -54,7 +54,7 @@ export const purchaseInvoiceLineValidator = withZod(
accountNumber: zfd.text(z.string().optional()),
assetId: zfd.text(z.string().optional()),
description: zfd.text(z.string().optional()),
- quantity: zfd.numeric(z.number().optional()),
+ quantity: zfd.numeric(z.number()),
unitPrice: zfd.numeric(z.number().optional()),
locationId: zfd.text(z.string().optional()),
shelfId: zfd.text(z.string().optional()),
@@ -66,6 +66,13 @@ export const purchaseInvoiceLineValidator = withZod(
message: "Part is required",
path: ["partId"], // path of error
})
+ .refine(
+ (data) => (data.invoiceLineType === "Part" ? data.locationId : true),
+ {
+ message: "Location is required",
+ path: ["locationId"], // path of error
+ }
+ )
.refine(
(data) =>
data.invoiceLineType === "G/L Account" ? data.accountNumber : true,
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader/PurchaseInvoiceHeader.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader/PurchaseInvoiceHeader.tsx
index 4041b50e4b..e83c579ecc 100644
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader/PurchaseInvoiceHeader.tsx
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceHeader/PurchaseInvoiceHeader.tsx
@@ -6,19 +6,12 @@ import {
CardHeader,
HStack,
Heading,
- Modal,
- ModalBody,
- ModalCloseButton,
- ModalContent,
- ModalFooter,
- ModalHeader,
- ModalOverlay,
Stack,
Text,
VStack,
useDisclosure,
} from "@chakra-ui/react";
-import { Form, useParams } from "@remix-run/react";
+import { useParams } from "@remix-run/react";
import { useMemo, useState } from "react";
import { FaHistory } from "react-icons/fa";
import { usePermissions, useRouteData } from "~/hooks";
@@ -29,6 +22,7 @@ import {
usePurchaseInvoiceTotals,
} from "~/modules/invoicing";
import { path } from "~/utils/path";
+import PurchaseInvoicePostModal from "../PurchaseInvoicePostModal";
const PurchaseInvoiceHeader = () => {
const permissions = usePermissions();
@@ -36,7 +30,9 @@ const PurchaseInvoiceHeader = () => {
const postingModal = useDisclosure();
const { supabase } = useSupabase();
- const [lines, setLines] = useState<PurchaseInvoiceLine[]>([]);
+ const [linesNotAssociatedWithPO, setLinesNotAssociatedWithPO] = useState<
+ PurchaseInvoiceLine[]
+ >([]);
if (!invoiceId) throw new Error("invoiceId not found");
@@ -59,16 +55,20 @@ const PurchaseInvoiceHeader = () => {
);
const showPostModal = async () => {
+ // check if there are any lines that are not associated with a PO
if (!supabase) throw new Error("supabase not found");
const { data, error } = await supabase
.from("purchaseInvoiceLine")
- .select("*")
- .eq("invoiceId", invoiceId);
+ .select("partId, quantity")
+ .eq("invoiceId", invoiceId)
+ .eq("invoiceLineType", "Part")
+ .is("purchaseOrderLineId", null);
if (error) throw new Error(error.message);
if (!data) return;
- setLines(data);
+ // so that we can ask the user if they want to receive those lines
+ setLinesNotAssociatedWithPO(data);
postingModal.onOpen();
};
@@ -133,33 +133,12 @@ const PurchaseInvoiceHeader = () => {
</CardBody>
</Card>
</VStack>
- <Modal isOpen={postingModal.isOpen} onClose={postingModal.onClose}>
- <ModalOverlay />
- <ModalContent>
- <ModalHeader>Post Invoice</ModalHeader>
- <ModalCloseButton />
- <ModalBody>
- Are you sure you want to post this invoice? This cannot be undone.
- {JSON.stringify(lines)}
- </ModalBody>
-
- <ModalFooter>
- <HStack spacing={2}>
- <Button colorScheme="gray" onClick={postingModal.onClose}>
- Cancel
- </Button>
- <Form
- method="post"
- action={path.to.purchaseInvoicePost(invoiceId)}
- >
- <Button colorScheme="brand" type="submit">
- Post Invoice
- </Button>
- </Form>
- </HStack>
- </ModalFooter>
- </ModalContent>
- </Modal>
+ <PurchaseInvoicePostModal
+ invoiceId={invoiceId}
+ isOpen={postingModal.isOpen}
+ onClose={postingModal.onClose}
+ linesToReceive={linesNotAssociatedWithPO}
+ />
</>
);
};
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal/PurchaseInvoicePostModal.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal/PurchaseInvoicePostModal.tsx
new file mode 100644
index 0000000000..0a9e3e4b15
--- /dev/null
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal/PurchaseInvoicePostModal.tsx
@@ -0,0 +1,77 @@
+import {
+ Button,
+ HStack,
+ ListItem,
+ Modal,
+ ModalBody,
+ ModalCloseButton,
+ ModalContent,
+ ModalFooter,
+ ModalHeader,
+ ModalOverlay,
+ UnorderedList,
+} from "@chakra-ui/react";
+import { Form } from "@remix-run/react";
+import { path } from "~/utils/path";
+
+type PurchaseInvoicePostModalProps = {
+ isOpen: boolean;
+ onClose: () => void;
+ invoiceId: string;
+ linesToReceive: { partId: string; quantity: number }[];
+};
+
+const PurchaseInvoicePostModal = ({
+ isOpen,
+ onClose,
+ invoiceId,
+ linesToReceive,
+}: PurchaseInvoicePostModalProps) => {
+ const hasLinesToReceive = linesToReceive.length > 0;
+
+ return (
+ <Modal isOpen={isOpen} onClose={onClose}>
+ <ModalOverlay />
+ <ModalContent>
+ <ModalHeader>Post Invoice</ModalHeader>
+ <ModalCloseButton />
+ <ModalBody>
+ {hasLinesToReceive ? (
+ <>
+ <p>
+ Are you sure you want to post this invoice? A receipt will be
+ automatically created and posted for:
+ </p>
+ <UnorderedList mt={2}>
+ {linesToReceive.map((line) => (
+ <ListItem key={line.partId}>
+ {`${line.partId} (${line.quantity})`}
+ </ListItem>
+ ))}
+ </UnorderedList>
+ </>
+ ) : (
+ <p>Are you sure you want to post this invoice?</p>
+ )}
+ </ModalBody>
+
+ <ModalFooter>
+ <HStack spacing={2}>
+ <Button colorScheme="gray" onClick={onClose}>
+ Cancel
+ </Button>
+ <Form method="post" action={path.to.purchaseInvoicePost(invoiceId)}>
+ <Button colorScheme="brand" type="submit">
+ {hasLinesToReceive
+ ? "Post and Receive Invoice"
+ : "Post Invoice"}
+ </Button>
+ </Form>
+ </HStack>
+ </ModalFooter>
+ </ModalContent>
+ </Modal>
+ );
+};
+
+export default PurchaseInvoicePostModal;
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal/index.ts b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal/index.ts
new file mode 100644
index 0000000000..a96471ebf0
--- /dev/null
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoicePostModal/index.ts
@@ -0,0 +1,3 @@
+import PurchaseInvoicePostModal from "./PurchaseInvoicePostModal";
+
+export default PurchaseInvoicePostModal;
diff --git a/apps/carbon/app/modules/purchasing/purchasing.models.ts b/apps/carbon/app/modules/purchasing/purchasing.models.ts
index 9fb45e0c3d..5f573ee451 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.models.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.models.ts
@@ -97,9 +97,9 @@ export const purchaseOrderLineValidator = withZod(
accountNumber: zfd.text(z.string().optional()),
assetId: zfd.text(z.string().optional()),
description: zfd.text(z.string().optional()),
- purchaseQuantity: zfd.numeric(z.number().optional()),
+ purchaseQuantity: z.number(),
unitOfMeasureCode: zfd.text(z.string().optional()),
- unitPrice: zfd.numeric(z.number().optional()),
+ unitPrice: zfd.numeric(z.number()),
setupPrice: zfd.numeric(z.number().optional()),
locationId: zfd.text(z.string().optional()),
shelfId: zfd.text(z.string().optional()),
diff --git a/apps/carbon/app/routes/x+/purchase-invoice+/$invoiceId.post.tsx b/apps/carbon/app/routes/x+/purchase-invoice+/$invoiceId.post.tsx
index 890e461590..ce6304b125 100644
--- a/apps/carbon/app/routes/x+/purchase-invoice+/$invoiceId.post.tsx
+++ b/apps/carbon/app/routes/x+/purchase-invoice+/$invoiceId.post.tsx
@@ -1,31 +1,11 @@
import type { ActionFunctionArgs } from "@remix-run/node";
-import { json, redirect } from "@remix-run/node";
-import { getPurchaseInvoiceLines } from "~/modules/invoicing";
+import { redirect } from "@remix-run/node";
import { PostingQueueType, postingQueue } from "~/queues";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session";
import { path } from "~/utils/path";
import { error } from "~/utils/result";
-export async function loader({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- update: "inventory",
- });
-
- const { invoiceId } = params;
- if (!invoiceId) throw new Error("invoiceId not found");
-
- const purchaseInvoiceLines = await getPurchaseInvoiceLines(client, invoiceId);
- if (purchaseInvoiceLines.error) {
- return redirect(
- path.to.purchaseInvoiceDetails(invoiceId),
- await flash(request, error(purchaseInvoiceLines.error))
- );
- }
-
- return json({ purchaseInvoiceLines: purchaseInvoiceLines.data ?? [] });
-}
-
export async function action({ request, params }: ActionFunctionArgs) {
const { client } = await requirePermissions(request, {
update: "invoicing",
diff --git a/www/components/pages/Home.tsx b/www/components/pages/Home.tsx
index 73948f7d98..052d71ceeb 100644
--- a/www/components/pages/Home.tsx
+++ b/www/components/pages/Home.tsx
@@ -7,17 +7,6 @@ import { useWindowSize } from "../../hooks/useWindowSize";
import Features from "../features";
import Sticky from "../sticky";
-const fadeIn = {
- initial: {
- opacity: 0,
- scale: 0.9,
- },
- animate: {
- opacity: 1,
- scale: 1,
- },
-};
-
function Gradient() {
const { scrollYProgress } = useScroll();
@@ -38,14 +27,17 @@ function Gradient() {
}
function Hero() {
- const { height } = useWindowSize();
+ const { height, width } = useWindowSize();
if (!height) return null;
+ if (!width) return null;
+
return (
<section>
<Sticky
cover
height={height}
+ width={width}
render={({ progress }) => {
const blur = {
filter: `blur(${progress * 3}px)`,
@@ -53,7 +45,7 @@ function Hero() {
};
const scale = {
- transform: `scale(${clamp(0.9, 1.1, 1.1 - progress * 0.3)})`,
+ transform: `scale(${clamp(0.8, 1, 1 - progress * 0.3)})`,
};
return (
@@ -90,7 +82,7 @@ function Hero() {
}}
className="mt-6 nx-text-xl font-medium leading-tight text-black/60 dark:text-white/60 sm:nx-text-2xl md:nx-text-3xl lg:nx-text-4xl"
>
- Carbon is an open-source starting point for business
+ Carbon is an open-source starting point for business planning
</motion.p>
</div>
<div
@@ -171,3 +163,14 @@ export default function Home() {
</>
);
}
+
+const fadeIn = {
+ initial: {
+ opacity: 0,
+ scale: 0.9,
+ },
+ animate: {
+ opacity: 1,
+ scale: 1,
+ },
+};
diff --git a/www/components/sticky.tsx b/www/components/sticky.tsx
index b13dae615a..f589aef17b 100644
--- a/www/components/sticky.tsx
+++ b/www/components/sticky.tsx
@@ -8,9 +8,10 @@ type StickyProps = {
render: (props: { progress: number }) => React.ReactNode;
cover?: boolean;
height: number;
+ width: number;
};
-const Sticky = ({ render, cover, height }: StickyProps) => {
+const Sticky = ({ render, cover, height, width }: StickyProps) => {
const ref = useRef<HTMLDivElement>(null);
const { scrollYProgress } = useScroll({
@@ -20,6 +21,8 @@ const Sticky = ({ render, cover, height }: StickyProps) => {
const [progress, setProgress] = useState(0);
useMotionValueEvent(scrollYProgress, "change", (latest) => {
+ console.log(width);
+ if (width < 768) return;
setProgress(latest);
});