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.

refactor: quote pdf

Brad Barbin18f93121d15a
diff --git a/apps/carbon/app/components/MultiSelect.tsx b/apps/carbon/app/components/MultiSelect.tsx
index 3b5803578a..44f02c0ea0 100644
--- a/apps/carbon/app/components/MultiSelect.tsx
+++ b/apps/carbon/app/components/MultiSelect.tsx
@@ -62,6 +62,7 @@ const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(
aria-controls={id}
aria-expanded={open}
role="combobox"
+ tabIndex={0}
variant="secondary"
className={cn(
multiSelectTriggerVariants({ size, hasSelections }),
@@ -69,6 +70,7 @@ const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(
className
)}
onClick={() => setOpen(!open)}
+ onKeyDown={() => setOpen(!open)}
asChild
>
<div>
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index 5eddb9390e..2b39795623 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -77,6 +77,7 @@ export const quotationValidator = z.object({
customerContactId: zfd.text(z.string().optional()),
customerReference: zfd.text(z.string().optional()),
locationId: zfd.text(z.string().optional()),
+ status: z.enum(quoteStatusType).optional(),
notes: zfd.text(z.string().optional()),
expirationDate: zfd.text(z.string().optional()),
});
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index 321dd92a31..89a8ff1731 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -349,7 +349,7 @@ export async function getQuoteLines(
client: SupabaseClient<Database>,
quoteId: string
) {
- return client.from("quoteLine").select("*").eq("quoteId", quoteId);
+ return client.from("quoteLines").select("*").eq("quoteId", quoteId);
}
export async function getQuoteCustomerDetails(
@@ -565,14 +565,28 @@ export async function releaseQuote(
quoteId: string,
usedId: string
) {
- return client
+ const quoteUpdate = await client
.from("quote")
.update({
status: "Open",
+ quoteDate: today(getLocalTimeZone()).toString(),
updatedAt: today(getLocalTimeZone()).toString(),
updatedBy: usedId,
})
.eq("id", quoteId);
+
+ if (quoteUpdate.error) {
+ return quoteUpdate;
+ }
+
+ return client
+ .from("quoteLine")
+ .update({
+ status: "Complete",
+ updatedAt: today(getLocalTimeZone()).toString(),
+ updatedBy: usedId,
+ })
+ .eq("quoteId", quoteId);
}
export async function upsertCustomer(
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
index 3a249f7e72..88aa86916b 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
@@ -20,11 +20,12 @@ import {
Hidden,
Input,
Location,
+ Select,
Submit,
TextArea,
} from "~/components/Form";
import { usePermissions } from "~/hooks";
-import { quotationValidator } from "~/modules/sales";
+import { quotationValidator, quoteStatusType } from "~/modules/sales";
type QuotationFormValues = z.infer<typeof quotationValidator>;
@@ -40,6 +41,11 @@ const QuotationForm = ({ initialValues }: QuotationFormProps) => {
const isEditing = initialValues.id !== undefined;
+ const statusOptions = quoteStatusType.map((status) => ({
+ label: status,
+ value: status,
+ }));
+
return (
<ValidatedForm
method="post"
@@ -96,6 +102,15 @@ const QuotationForm = ({ initialValues }: QuotationFormProps) => {
<>
<DatePicker name="expirationDate" label="Expiration Date" />
<TextArea name="notes" label="Notes" />
+ {permissions.can("delete", "purchasing") && (
+ <Select
+ name="status"
+ label="Status"
+ value={initialValues.status}
+ options={statusOptions}
+ isReadOnly={permissions.is("customer")}
+ />
+ )}
</>
)}
<CustomFormFields table="quote" />
diff --git a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
index 93ecd4aca9..cabe6d45e0 100644
--- a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
@@ -137,7 +137,7 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
{
id: "partIds",
header: "Parts",
- cell: (item) => item.getValue<string[]>()?.length ?? 0,
+ cell: ({ row }) => row.original.partIds?.length ?? 0,
meta: {
filter: {
type: "static",
diff --git a/apps/carbon/app/routes/_public+/login.tsx b/apps/carbon/app/routes/_public+/login.tsx
index cbd9ee6a83..96b4e4013a 100644
--- a/apps/carbon/app/routes/_public+/login.tsx
+++ b/apps/carbon/app/routes/_public+/login.tsx
@@ -20,9 +20,9 @@ import {
signInWithEmail,
verifyAuthSession,
} from "~/services/auth";
-import { createAuthSession, getAuthSession } from "~/services/session.server";
+import { commitAuthSession, getAuthSession } from "~/services/session.server";
import type { Result } from "~/types";
-import { assertIsPost } from "~/utils/http";
+import { assertIsPost, safeRedirect } from "~/utils/http";
import { path } from "~/utils/path";
import { error } from "~/utils/result";
@@ -61,10 +61,13 @@ export async function action({ request }: ActionFunctionArgs) {
});
}
- createAuthSession({
- request,
- authSession,
- redirectTo: redirectTo || path.to.authenticatedRoot,
+ throw redirect(safeRedirect(redirectTo), {
+ headers: {
+ "Set-Cookie": await commitAuthSession(request, {
+ authSession,
+ flashErrorMessage: null,
+ }),
+ },
});
}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.release.tsx b/apps/carbon/app/routes/x+/quote+/$id.release.tsx
index 37d6e185dc..cfd57c48e1 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.release.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.release.tsx
@@ -4,12 +4,12 @@ import { renderAsync } from "@react-email/components";
import { redirect, type ActionFunctionArgs } from "@remix-run/node";
import { triggerClient } from "~/lib/trigger.server";
import {
- getQuote,
- releaseQuote,
- quotationReleaseValidator,
getCustomer,
- getQuoteLines,
getCustomerContact,
+ getQuote,
+ getQuoteLines,
+ quotationReleaseValidator,
+ releaseQuote,
} from "~/modules/sales";
import { getCompany } from "~/modules/settings";
import { getUser } from "~/modules/users/users.server";
@@ -100,7 +100,7 @@ export async function action(args: ActionFunctionArgs) {
const [company, customer, customerContact, quoteLines, user] =
await Promise.all([
getCompany(client),
- getCustomer(client, quote.data.customerId),
+ getCustomer(client, quote.data.customerId!),
getCustomerContact(client, customerContactId),
getQuoteLines(client, id),
getUser(client, userId),
@@ -115,10 +115,12 @@ export async function action(args: ActionFunctionArgs) {
// TODO: Update sender email
const emailTemplate = QuoteEmail({
company: company.data,
+ // @ts-ignore
quote: quote.data,
+ // @ts-ignore
quoteLines: quoteLines.data ?? [],
recipient: {
- email: customerContact.data.contact.email,
+ email: customerContact.data?.contact!.email!,
firstName: "Customer",
lastName: "",
},
@@ -132,7 +134,7 @@ export async function action(args: ActionFunctionArgs) {
await triggerClient.sendEvent({
name: "resend.email",
payload: {
- to: customerContact.data.contact.email,
+ to: customerContact.data.contact!.email!,
from: user.data.email,
subject: `${quote.data.quoteId} from ${company.data.name}`,
html: await renderAsync(emailTemplate),
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index 1436391ab8..3915f772ad 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -133,6 +133,8 @@ export default function QuotationRoute() {
const { id } = useParams();
if (!id) throw new Error("id not found");
+ const isReleased = !["Draft"].includes(quote.quote?.status ?? "");
+
const buttonRef = useRef<HTMLButtonElement>(null);
useKeyboardShortcuts({
l: (event: KeyboardEvent) => {
@@ -204,7 +206,7 @@ export default function QuotationRoute() {
</MenubarItem>
<MenubarItem
onClick={releaseDisclosure.onOpen}
- // isDisabled={isReleased}
+ isDisabled={isReleased}
>
Release
</MenubarItem>
diff --git a/apps/carbon/app/services/session.server.ts b/apps/carbon/app/services/session.server.ts
index f0d328cbae..139615f484 100644
--- a/apps/carbon/app/services/session.server.ts
+++ b/apps/carbon/app/services/session.server.ts
@@ -1,11 +1,6 @@
import { createCookieSessionStorage, redirect } from "@remix-run/node";
-import {
- getCurrentPath,
- isGet,
- makeRedirectToFromHere,
- safeRedirect,
-} from "~/utils/http";
+import { getCurrentPath, isGet, makeRedirectToFromHere } from "~/utils/http";
import {
NODE_ENV,
@@ -47,25 +42,6 @@ const sessionStorage = createCookieSessionStorage({
},
});
-export async function createAuthSession({
- request,
- authSession,
- redirectTo,
-}: {
- request: Request;
- authSession: AuthSession;
- redirectTo: string;
-}) {
- throw redirect(safeRedirect(redirectTo), {
- headers: {
- "Set-Cookie": await commitAuthSession(request, {
- authSession,
- flashErrorMessage: null,
- }),
- },
- });
-}
-
export async function commitAuthSession(
request: Request,
{
diff --git a/package-lock.json b/package-lock.json
index aef501168f..2bb6003773 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -32110,6 +32110,7 @@
"@carbon/database": "*",
"@carbon/jest": "*",
"@carbon/tsconfig": "*",
+ "@internationalized/date": "^3.5.2",
"@testing-library/dom": "^8.11.1",
"@types/dompurify": "^2.4.0",
"@types/jest": "^26.0.22",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index affad4d0f6..d324a12b15 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -8694,6 +8694,13 @@ export type Database = {
referencedRelation: "quoteLine"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteAssembly_quoteLineId_fkey"
+ columns: ["quoteLineId"]
+ isOneToOne: false
+ referencedRelation: "quoteLines"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteAssembly_updatedBy_fkey"
columns: ["updatedBy"]
@@ -9042,6 +9049,13 @@ export type Database = {
referencedRelation: "quoteLine"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteLinePrice_quoteLineId_fkey"
+ columns: ["quoteLineId"]
+ isOneToOne: false
+ referencedRelation: "quoteLines"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteLinePrice_updatedBy_fkey"
columns: ["updatedBy"]
@@ -9199,6 +9213,13 @@ export type Database = {
referencedRelation: "quoteLine"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteMaterial_quoteLineId_fkey"
+ columns: ["quoteLineId"]
+ isOneToOne: false
+ referencedRelation: "quoteLines"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteMaterial_quoteOperationId_fkey"
columns: ["quoteOperationId"]
@@ -9368,6 +9389,13 @@ export type Database = {
referencedRelation: "quoteLine"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteOperation_quoteLineId_fkey"
+ columns: ["quoteLineId"]
+ isOneToOne: false
+ referencedRelation: "quoteLines"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteOperation_updatedBy_fkey"
columns: ["updatedBy"]
@@ -14850,6 +14878,130 @@ export type Database = {
},
]
}
+ quoteLines: {
+ Row: {
+ createdBy: string | null
+ customerPartId: string | null
+ customerPartRevision: string | null
+ customFields: Json | null
+ description: string | null
+ id: string | null
+ partId: string | null
+ pricingDiscountPercent: number | null
+ pricingExtendedPrice: number | null
+ pricingLeadTime: number | null
+ pricingMarkupPercent: number | null
+ pricingQuantity: number | null
+ pricingUnitCost: number | null
+ quoteId: string | null
+ quoteRevisionId: number | null
+ replenishmentSystem: string | null
+ status: Database["public"]["Enums"]["quoteLineStatus"] | null
+ unitOfMeasureCode: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "quoteLine_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "quoteLine_partId_fkey"
+ columns: ["partId"]
+ isOneToOne: false
+ referencedRelation: "part"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_partId_fkey"
+ columns: ["partId"]
+ isOneToOne: false
+ referencedRelation: "partQuantities"
+ referencedColumns: ["partId"]
+ },
+ {
+ foreignKeyName: "quoteLine_partId_fkey"
+ columns: ["partId"]
+ isOneToOne: false
+ referencedRelation: "parts"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_quoteId_fkey"
+ columns: ["quoteId"]
+ isOneToOne: false
+ referencedRelation: "quote"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_quoteId_fkey"
+ columns: ["quoteId"]
+ isOneToOne: false
+ referencedRelation: "quoteCustomerDetails"
+ referencedColumns: ["quoteId"]
+ },
+ {
+ foreignKeyName: "quoteLine_quoteId_fkey"
+ columns: ["quoteId"]
+ isOneToOne: false
+ referencedRelation: "quotes"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
quotes: {
Row: {
assignee: string | null
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index affad4d0f6..d324a12b15 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -8694,6 +8694,13 @@ export type Database = {
referencedRelation: "quoteLine"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteAssembly_quoteLineId_fkey"
+ columns: ["quoteLineId"]
+ isOneToOne: false
+ referencedRelation: "quoteLines"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteAssembly_updatedBy_fkey"
columns: ["updatedBy"]
@@ -9042,6 +9049,13 @@ export type Database = {
referencedRelation: "quoteLine"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteLinePrice_quoteLineId_fkey"
+ columns: ["quoteLineId"]
+ isOneToOne: false
+ referencedRelation: "quoteLines"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteLinePrice_updatedBy_fkey"
columns: ["updatedBy"]
@@ -9199,6 +9213,13 @@ export type Database = {
referencedRelation: "quoteLine"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteMaterial_quoteLineId_fkey"
+ columns: ["quoteLineId"]
+ isOneToOne: false
+ referencedRelation: "quoteLines"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteMaterial_quoteOperationId_fkey"
columns: ["quoteOperationId"]
@@ -9368,6 +9389,13 @@ export type Database = {
referencedRelation: "quoteLine"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteOperation_quoteLineId_fkey"
+ columns: ["quoteLineId"]
+ isOneToOne: false
+ referencedRelation: "quoteLines"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "quoteOperation_updatedBy_fkey"
columns: ["updatedBy"]
@@ -14850,6 +14878,130 @@ export type Database = {
},
]
}
+ quoteLines: {
+ Row: {
+ createdBy: string | null
+ customerPartId: string | null
+ customerPartRevision: string | null
+ customFields: Json | null
+ description: string | null
+ id: string | null
+ partId: string | null
+ pricingDiscountPercent: number | null
+ pricingExtendedPrice: number | null
+ pricingLeadTime: number | null
+ pricingMarkupPercent: number | null
+ pricingQuantity: number | null
+ pricingUnitCost: number | null
+ quoteId: string | null
+ quoteRevisionId: number | null
+ replenishmentSystem: string | null
+ status: Database["public"]["Enums"]["quoteLineStatus"] | null
+ unitOfMeasureCode: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "quoteLine_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "quoteLine_partId_fkey"
+ columns: ["partId"]
+ isOneToOne: false
+ referencedRelation: "part"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_partId_fkey"
+ columns: ["partId"]
+ isOneToOne: false
+ referencedRelation: "partQuantities"
+ referencedColumns: ["partId"]
+ },
+ {
+ foreignKeyName: "quoteLine_partId_fkey"
+ columns: ["partId"]
+ isOneToOne: false
+ referencedRelation: "parts"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_quoteId_fkey"
+ columns: ["quoteId"]
+ isOneToOne: false
+ referencedRelation: "quote"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_quoteId_fkey"
+ columns: ["quoteId"]
+ isOneToOne: false
+ referencedRelation: "quoteCustomerDetails"
+ referencedColumns: ["quoteId"]
+ },
+ {
+ foreignKeyName: "quoteLine_quoteId_fkey"
+ columns: ["quoteId"]
+ isOneToOne: false
+ referencedRelation: "quotes"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
quotes: {
Row: {
assignee: string | null
diff --git a/packages/database/supabase/migrations/20240329034816_quote-pricing.sql b/packages/database/supabase/migrations/20240329034816_quote-pricing.sql
index 2cafcd6886..db047b0ead 100644
--- a/packages/database/supabase/migrations/20240329034816_quote-pricing.sql
+++ b/packages/database/supabase/migrations/20240329034816_quote-pricing.sql
@@ -21,4 +21,17 @@ CREATE TABLE "quoteLinePrice" (
CONSTRAINT "quoteLinePrice_quoteLineId_fkey" FOREIGN KEY ("quoteLineId") REFERENCES "quoteLine" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "quoteLinePrice_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "quoteLinePrice_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
+);
+
+CREATE OR REPLACE VIEW "quoteLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ ql.*,
+ qlp."quantity" AS "pricingQuantity",
+ qlp."unitCost" AS "pricingUnitCost",
+ qlp."leadTime" AS "pricingLeadTime",
+ qlp."discountPercent" AS "pricingDiscountPercent",
+ qlp."markupPercent" AS "pricingMarkupPercent",
+ qlp."extendedPrice" AS "pricingExtendedPrice"
+ FROM "quoteLine" ql
+ LEFT JOIN "quoteLinePrice" qlp ON ql."id" = qlp."quoteLineId"
);
\ No newline at end of file
diff --git a/packages/documents/package.json b/packages/documents/package.json
index 623330378c..e6c835a75a 100644
--- a/packages/documents/package.json
+++ b/packages/documents/package.json
@@ -9,6 +9,7 @@
"@carbon/database": "*",
"@carbon/jest": "*",
"@carbon/tsconfig": "*",
+ "@internationalized/date": "^3.5.2",
"@testing-library/dom": "^8.11.1",
"@types/dompurify": "^2.4.0",
"@types/jest": "^26.0.22",
diff --git a/packages/documents/src/pdf/PurchaseOrderPDF.tsx b/packages/documents/src/pdf/PurchaseOrderPDF.tsx
index 238c05d189..2b4bdccef6 100644
--- a/packages/documents/src/pdf/PurchaseOrderPDF.tsx
+++ b/packages/documents/src/pdf/PurchaseOrderPDF.tsx
@@ -18,6 +18,10 @@ interface PurchaseOrderPDFProps extends PDF {
}
// TODO: format currency based on settings
+const formatter = new Intl.NumberFormat("en-US", {
+ style: "currency",
+ currency: "USD",
+});
const PurchaseOrderPDF = ({
company,
@@ -162,30 +166,21 @@ const PurchaseOrderPDF = ({
: line.purchaseQuantity}
</Text>
<Text style={styles.tableCol3}>
- {line.purchaseOrderLineType === "Comment" ? null : (
- <>
- <Text>$</Text>
- <Text>
- {line.unitPrice ? line.unitPrice.toFixed(2) : ""}
- </Text>
- </>
- )}
+ {line.purchaseOrderLineType === "Comment"
+ ? null
+ : formatter.format(line.unitPrice ?? 0)}
</Text>
<Text style={styles.tableCol4}>
- {line.purchaseOrderLineType === "Comment" ? null : (
- <>
- <Text>$</Text>
- <Text>{getLineTotal(line)}</Text>
- </>
- )}
+ {line.purchaseOrderLineType === "Comment"
+ ? null
+ : formatter.format(getLineTotal(line))}
</Text>
</View>
))}
<View style={styles.tfoot}>
<Text>Total</Text>
<Text style={styles.bold}>
- <Text>$</Text>
- <Text>{getTotal(purchaseOrderLines)}</Text>
+ {formatter.format(getTotal(purchaseOrderLines))}
</Text>
</View>
</View>
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index 3c433ffacf..550465717e 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -1,15 +1,28 @@
import type { Database } from "@carbon/database";
+import { getLocalTimeZone, today } from "@internationalized/date";
import { StyleSheet, Text, View } from "@react-pdf/renderer";
import type { PDF } from "../types";
-import { QuoteHeader, QuoteSummary, Template } from "./components";
+import {
+ getLineDescription,
+ getLineDescriptionDetails,
+ getTotal,
+} from "../utils/quote";
+import { formatAddress } from "../utils/shared";
+import { Header, Summary, Template } from "./components";
interface QuotePDFProps extends PDF {
quote: Database["public"]["Views"]["quotes"]["Row"];
- quoteLines: Database["public"]["Tables"]["quoteLine"]["Row"][];
+ quoteLines: Database["public"]["Views"]["quoteLines"]["Row"][];
quoteCustomerDetails: Database["public"]["Views"]["quoteCustomerDetails"]["Row"];
}
+// TODO: format currency based on settings
+const formatter = new Intl.NumberFormat("en-US", {
+ style: "currency",
+ currency: "USD",
+});
+
const QuotePDF = ({
company,
meta,
@@ -18,74 +31,105 @@ const QuotePDF = ({
quoteCustomerDetails,
title = "Quote",
}: QuotePDFProps) => {
+ const {
+ customerName,
+ customerAddressLine1,
+ customerAddressLine2,
+ customerCity,
+ customerState,
+ customerPostalCode,
+ customerCountryCode,
+ } = quoteCustomerDetails;
+
return (
<Template
title={title}
meta={{
author: meta?.author ?? "Carbon ERP",
- keywords: meta?.keywords ?? "Quote",
+ keywords: meta?.keywords ?? "quote",
subject: meta?.subject ?? "Quote",
}}
>
<View>
- <QuoteHeader
- title={title}
- quoteNumber={quote.quoteId ? quote.quoteId : null}
- company={company}
- />
- <QuoteSummary
+ <Header title={title} company={company} />
+ <Summary
company={company}
- quoteCustomerDetails={quoteCustomerDetails}
items={[
{
label: "Date",
- value: quote?.quoteDate ? quote.quoteDate : null,
+ value: quote?.quoteDate ?? today(getLocalTimeZone()).toString(),
+ },
+ {
+ label: "Expires",
+ value: quote?.expirationDate ?? "",
+ },
+ {
+ label: "Quote #",
+ value: quote?.quoteId,
},
]}
/>
+ <View style={styles.row}>
+ <View style={styles.colThird}>
+ <Text style={styles.label}>Supplier</Text>
+ <Text>{customerName}</Text>
+ {customerAddressLine1 && <Text>{customerAddressLine1}</Text>}
+ {customerAddressLine2 && <Text>{customerAddressLine2}</Text>}
+ <Text>
+ {formatAddress(customerCity, customerState, customerPostalCode)}
+ </Text>
+ <Text>{customerCountryCode}</Text>
+ </View>
+ </View>
+
<View style={styles.table}>
<View style={styles.thead}>
<Text style={styles.tableCol1}>Description</Text>
<Text style={styles.tableCol2}>Qty</Text>
- <Text style={styles.tableCol3}>Time</Text>
- <Text style={styles.tableCol4}>Cost</Text>
- <Text style={styles.tableCol5}>Total</Text>
+ <Text style={styles.tableCol3}>Price</Text>
+ <Text style={styles.tableCol3}>Lead Time</Text>
+ <Text style={styles.tableCol4}>Total</Text>
</View>
{quoteLines.map((line) => (
- <View key={line.id} style={styles.tr}>
+ <View style={styles.tr} key={line.id}>
<View style={styles.tableCol1}>
- <Text style={styles.bold}>{line.description}</Text>
- <Text style={{ fontSize: 9, opacity: 0.8 }}>{line.partId}</Text>
- </View>
- <View style={styles.quantityTable}>
- {/* {quoteLineQuantities &&
- quoteLineQuantities.map((quantity) =>
- quantity.quoteLineId === line.id ? (
- <View style={styles.quantityRow} key={quantity.id}>
- <View style={styles.quantityCol1}>
- <Text>{quantity.quantity}</Text>
- </View>
- <View style={styles.quantityCol2}>
- <Text>{quantity.leadTime} d</Text>
- </View>
- <View style={styles.quantityCol3}>
- <Text>{getUnitCost(quantity).toFixed(2)}</Text>
- </View>
- <View style={styles.quantityCol4}>
- <Text>${getExtendedPrice(quantity).toFixed(2)}</Text>
- </View>
- </View>
- ) : null
- )} */}
+ <Text style={{ ...styles.bold, marginBottom: 4 }}>
+ {getLineDescription(line)}
+ </Text>
+ <Text style={{ fontSize: 9, opacity: 0.8 }}>
+ {getLineDescriptionDetails(line)}
+ </Text>
</View>
+ <Text style={styles.tableCol2}>{line.pricingQuantity}</Text>
+ <Text style={styles.tableCol3}>
+ <Text>
+ {line.pricingQuantity
+ ? formatter.format(
+ (line.pricingExtendedPrice ?? 0) / line.pricingQuantity
+ )
+ : formatter.format(0)}
+ </Text>
+ </Text>
+ <Text style={styles.tableCol3}>
+ <Text>{line.pricingLeadTime ?? 0}</Text>
+ </Text>
+ <Text style={styles.tableCol4}>
+ <Text>{formatter.format(line.pricingExtendedPrice ?? 0)}</Text>
+ </Text>
</View>
))}
+ <View style={styles.tfoot}>
+ <Text>Total</Text>
+ <Text style={styles.bold}>
+ <Text>{formatter.format(getTotal(quoteLines))}</Text>
+ </Text>
+ </View>
</View>
- {quote.notes && (
+ {quote?.notes && (
<View style={styles.row}>
- <View style={styles.colFull}>
+ <View style={styles.colHalf}>
<Text style={styles.label}>Notes</Text>
- <Text>{quote.notes}</Text>
+ <Text>{quote?.notes}</Text>
</View>
</View>
)}
@@ -180,47 +224,18 @@ const styles = StyleSheet.create({
textTransform: "uppercase",
},
tableCol1: {
- width: "40%",
+ width: "50%",
textAlign: "left",
},
tableCol2: {
width: "15%",
- textAlign: "left",
+ textAlign: "right",
},
tableCol3: {
- width: "12.5%",
- textAlign: "left",
- },
- tableCol4: {
- width: "12.5%",
- textAlign: "left",
- },
- tableCol5: {
width: "15%",
textAlign: "right",
},
- quantityTable: {
- width: "60%",
- },
- quantityRow: {
- display: "flex",
- flexDirection: "row",
- justifyContent: "space-between",
- padding: "6px 3px 6px 3px",
- },
- quantityCol1: {
- width: "15%",
- textAlign: "left",
- },
- quantityCol2: {
- width: "12.5%",
- textAlign: "left",
- },
- quantityCol3: {
- width: "12.5%",
- textAlign: "left",
- },
- quantityCol4: {
+ tableCol4: {
width: "20%",
textAlign: "right",
},
diff --git a/packages/documents/src/utils/purchase-order.ts b/packages/documents/src/utils/purchase-order.ts
index e35441e1f4..f8b158c7a7 100644
--- a/packages/documents/src/utils/purchase-order.ts
+++ b/packages/documents/src/utils/purchase-order.ts
@@ -52,10 +52,10 @@ export function getLineTotal(
line: Database["public"]["Views"]["purchaseOrderLines"]["Row"]
) {
if (line?.purchaseQuantity && line?.unitPrice) {
- return (line.purchaseQuantity * line.unitPrice).toFixed(2);
+ return line.purchaseQuantity * line.unitPrice;
}
- return "";
+ return 0;
}
export function getTotal(
@@ -69,5 +69,5 @@ export function getTotal(
}
});
- return total.toFixed(2);
+ return total;
}
diff --git a/packages/documents/src/utils/quote.ts b/packages/documents/src/utils/quote.ts
index ee4a36b32c..08bd425a6f 100644
--- a/packages/documents/src/utils/quote.ts
+++ b/packages/documents/src/utils/quote.ts
@@ -1,30 +1,32 @@
import type { Database } from "@carbon/database";
export function getLineDescription(
- line: Database["public"]["Tables"]["quoteLineQuantity"]["Row"]
+ line: Database["public"]["Views"]["quoteLines"]["Row"]
) {
- return line?.quantity;
+ const customerPartNumber = line.customerPartId
+ ? ` (${line.customerPartId} ${
+ line.customerPartRevision ? `Rev ${line.customerPartRevision}` : ""
+ })`
+ : "";
+ return line?.partId + customerPartNumber;
}
-export function getExtendedPrice(
- line: Database["public"]["Tables"]["quoteLineQuantity"]["Row"]
+export function getLineDescriptionDetails(
+ line: Database["public"]["Views"]["quoteLines"]["Row"]
) {
- return (
- line?.quantity *
- (getUnitCost(line) + line.unitTaxAmount) *
- (1 - line.discountPercentage / 100) *
- (1 + line.markupPercentage / 100)
- );
+ return line?.description ? `${line.description}` : "";
}
-export function getUnitCost(
- line: Database["public"]["Tables"]["quoteLineQuantity"]["Row"]
+export function getTotal(
+ lines: Database["public"]["Views"]["quoteLines"]["Row"][]
) {
- return line.quantity
- ? (line.materialCost +
- line.laborCost +
- line.overheadCost +
- line.additionalCost) /
- line.quantity
- : 0;
+ let total = 0;
+
+ lines.forEach((line) => {
+ if (line?.pricingExtendedPrice) {
+ total += line.pricingExtendedPrice;
+ }
+ });
+
+ return total;
}