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: update quote line UI and quote PDF to pull exchange rate from quoteLinePrice

Rob Carringtone120a7ab6a47
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
index 83c28f8765..83464dad20 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
@@ -78,7 +78,6 @@ const QuoteLinePricing = ({
const routeData = useRouteData<{
quote: Quotation;
- exchangeRate: number;
}>(path.to.quote(quoteId));
const isEditable =
permissions.can("update", "sales") &&
@@ -193,13 +192,6 @@ const QuoteLinePricing = ({
return totalCost;
});
- const netPricesByQuantity = quantities.map((quantity, index) => {
- const price = prices[quantity]?.unitPrice ?? 0;
- const discount = prices[quantity]?.discountPercent ?? 0;
- const netPrice = price * (1 - discount / 100);
- return netPrice;
- });
-
const onRecalculate = (markup: number) => {
const formData = new FormData();
formData.append("markup", markup.toString());
@@ -534,10 +526,11 @@ const QuoteLinePricing = ({
<Tr className="[&>td]:bg-muted/60">
<Td className="border-r border-border group-hover:bg-muted/50">
<HStack className="w-full justify-between ">
- <span>Net Price</span>
+ <span>Net Unit Price</span>
</HStack>
</Td>
- {netPricesByQuantity.map((price, index) => {
+ {quantities.map((quantity, index) => {
+ const price = prices[quantity]?.netUnitPrice ?? 0;
return (
<Td key={index} className="group-hover:bg-muted/50">
<VStack spacing={0}>
@@ -562,7 +555,8 @@ const QuoteLinePricing = ({
</span>
</HStack>
</Td>
- {netPricesByQuantity.map((price, index) => {
+ {quantities.map((quantity, index) => {
+ const price = prices[quantity]?.netUnitPrice ?? 0;
const cost = unitCostsByQuantity[index];
const profit = ((price - cost) / price) * 100;
return (
@@ -588,13 +582,14 @@ const QuoteLinePricing = ({
</HStack>
</Td>
{quantities.map((quantity, index) => {
- const price = netPricesByQuantity[index];
- const cost = unitCostsByQuantity[index];
- const profit = (price - cost) * quantity;
+ const netExtendedPrice =
+ prices[quantity]?.netExtendedPrice ?? 0;
+ const extendedCost = unitCostsByQuantity[index] * quantity;
+ const profit = netExtendedPrice - extendedCost;
return (
<Td key={index} className="group-hover:bg-muted/50">
<VStack spacing={0}>
- {price ? (
+ {netExtendedPrice ? (
<span className={cn(profit < -0.01 && "text-red-500")}>
{formatter.format(profit)}
</span>
@@ -751,7 +746,7 @@ const QuoteLinePricing = ({
</Td>
{quantities.map((quantity, index) => {
const price =
- netPricesByQuantity[index] * quantity +
+ (prices[quantity]?.netExtendedPrice ?? 0) +
additionalChargesByQuantity[index];
return (
<Td key={index} className="group-hover:bg-muted/50">
@@ -770,13 +765,16 @@ const QuoteLinePricing = ({
<span>Exchange Rate</span>
</HStack>
</Td>
- {quantities.map((quantity, index) => (
- <Td key={index} className="group-hover:bg-muted/50">
- <VStack spacing={0}>
- <span>{routeData?.exchangeRate ?? 1}</span>
- </VStack>
- </Td>
- ))}
+ {quantities.map((quantity, index) => {
+ const exchangeRate = prices[quantity]?.exchangeRate;
+ return (
+ <Td key={index} className="group-hover:bg-muted/50">
+ <VStack spacing={0}>
+ <span>{exchangeRate ?? 1}</span>
+ </VStack>
+ </Td>
+ );
+ })}
</Tr>
<Tr className="font-bold [&>td]:bg-muted/60">
<Td className="border-r border-border group-hover:bg-muted/50">
@@ -786,17 +784,14 @@ const QuoteLinePricing = ({
</Td>
{quantities.map((quantity, index) => {
const price =
- netPricesByQuantity[index] * quantity +
- additionalChargesByQuantity[index];
- const convertedPrice =
- price * (routeData?.exchangeRate ?? 1);
+ (prices[quantity]?.convertedNetExtendedPrice ?? 0) +
+ additionalChargesByQuantity[index] *
+ (prices[quantity]?.exchangeRate ?? 1);
return (
<Td key={index} className="group-hover:bg-muted/50">
<VStack spacing={0}>
<span>
- {presentationCurrencyFormatter.format(
- convertedPrice
- )}
+ {presentationCurrencyFormatter.format(price)}
</span>
</VStack>
</Td>
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 285ac71914..bacab69354 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -20610,6 +20610,18 @@ export default {
{
$ref: "#/parameters/rowFilter.quoteLinePrice.convertedUnitPrice",
},
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.netUnitPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.convertedNetUnitPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.netExtendedPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.convertedNetExtendedPrice",
+ },
{
$ref: "#/parameters/select",
},
@@ -20705,6 +20717,18 @@ export default {
{
$ref: "#/parameters/rowFilter.quoteLinePrice.convertedUnitPrice",
},
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.netUnitPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.convertedNetUnitPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.netExtendedPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.convertedNetExtendedPrice",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -20754,6 +20778,18 @@ export default {
{
$ref: "#/parameters/rowFilter.quoteLinePrice.convertedUnitPrice",
},
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.netUnitPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.convertedNetUnitPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.netExtendedPrice",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteLinePrice.convertedNetExtendedPrice",
+ },
{
$ref: "#/parameters/body.quoteLinePrice",
},
@@ -45816,6 +45852,22 @@ export default {
format: "numeric",
type: "number",
},
+ netUnitPrice: {
+ format: "numeric",
+ type: "number",
+ },
+ convertedNetUnitPrice: {
+ format: "numeric",
+ type: "number",
+ },
+ netExtendedPrice: {
+ format: "numeric",
+ type: "number",
+ },
+ convertedNetExtendedPrice: {
+ format: "numeric",
+ type: "number",
+ },
},
type: "object",
},
@@ -64423,6 +64475,34 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.quoteLinePrice.netUnitPrice": {
+ name: "netUnitPrice",
+ required: false,
+ format: "numeric",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.quoteLinePrice.convertedNetUnitPrice": {
+ name: "convertedNetUnitPrice",
+ required: false,
+ format: "numeric",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.quoteLinePrice.netExtendedPrice": {
+ name: "netExtendedPrice",
+ required: false,
+ format: "numeric",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.quoteLinePrice.convertedNetExtendedPrice": {
+ name: "convertedNetExtendedPrice",
+ required: false,
+ format: "numeric",
+ in: "query",
+ type: "string",
+ },
"body.makeMethod": {
name: "makeMethod",
description: "makeMethod",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index b507bb9212..565d631998 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -14609,12 +14609,16 @@ export type Database = {
}
quoteLinePrice: {
Row: {
+ convertedNetExtendedPrice: number | null
+ convertedNetUnitPrice: number | null
convertedUnitPrice: number | null
createdAt: string
createdBy: string
discountPercent: number
exchangeRate: number | null
leadTime: number
+ netExtendedPrice: number | null
+ netUnitPrice: number | null
quantity: number
quoteId: string
quoteLineId: string
@@ -14623,12 +14627,16 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ convertedNetExtendedPrice?: number | null
+ convertedNetUnitPrice?: number | null
convertedUnitPrice?: number | null
createdAt?: string
createdBy: string
discountPercent?: number
exchangeRate?: number | null
leadTime?: number
+ netExtendedPrice?: number | null
+ netUnitPrice?: number | null
quantity?: number
quoteId: string
quoteLineId: string
@@ -14637,12 +14645,16 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ convertedNetExtendedPrice?: number | null
+ convertedNetUnitPrice?: number | null
convertedUnitPrice?: number | null
createdAt?: string
createdBy?: string
discountPercent?: number
exchangeRate?: number | null
leadTime?: number
+ netExtendedPrice?: number | null
+ netUnitPrice?: number | null
quantity?: number
quoteId?: string
quoteLineId?: string
@@ -24632,14 +24644,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -25507,14 +25519,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -27266,14 +27278,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index b507bb9212..565d631998 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -14609,12 +14609,16 @@ export type Database = {
}
quoteLinePrice: {
Row: {
+ convertedNetExtendedPrice: number | null
+ convertedNetUnitPrice: number | null
convertedUnitPrice: number | null
createdAt: string
createdBy: string
discountPercent: number
exchangeRate: number | null
leadTime: number
+ netExtendedPrice: number | null
+ netUnitPrice: number | null
quantity: number
quoteId: string
quoteLineId: string
@@ -14623,12 +14627,16 @@ export type Database = {
updatedBy: string | null
}
Insert: {
+ convertedNetExtendedPrice?: number | null
+ convertedNetUnitPrice?: number | null
convertedUnitPrice?: number | null
createdAt?: string
createdBy: string
discountPercent?: number
exchangeRate?: number | null
leadTime?: number
+ netExtendedPrice?: number | null
+ netUnitPrice?: number | null
quantity?: number
quoteId: string
quoteLineId: string
@@ -14637,12 +14645,16 @@ export type Database = {
updatedBy?: string | null
}
Update: {
+ convertedNetExtendedPrice?: number | null
+ convertedNetUnitPrice?: number | null
convertedUnitPrice?: number | null
createdAt?: string
createdBy?: string
discountPercent?: number
exchangeRate?: number | null
leadTime?: number
+ netExtendedPrice?: number | null
+ netUnitPrice?: number | null
quantity?: number
quoteId?: string
quoteLineId?: string
@@ -24632,14 +24644,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -25507,14 +25519,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -27266,14 +27278,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/migrations/20241010193506_quote-order-presentation-currency.sql b/packages/database/supabase/migrations/20241010193506_quote-order-presentation-currency.sql
index ef9a672161..f12564f055 100644
--- a/packages/database/supabase/migrations/20241010193506_quote-order-presentation-currency.sql
+++ b/packages/database/supabase/migrations/20241010193506_quote-order-presentation-currency.sql
@@ -121,6 +121,10 @@ DROP POLICY IF EXISTS "Employees with accounting_delete can delete currencies" O
-- Add exchangeRate and convertedUnitPrice to quoteLinePrice
ALTER TABLE "quoteLinePrice" ADD COLUMN "exchangeRate" NUMERIC(10,4) DEFAULT 1;
ALTER TABLE "quoteLinePrice" ADD COLUMN "convertedUnitPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * "exchangeRate") STORED;
+ALTER TABLE "quoteLinePrice" ADD COLUMN "netUnitPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * (1 - "discountPercent")) STORED;
+ALTER TABLE "quoteLinePrice" ADD COLUMN "convertedNetUnitPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * "exchangeRate" * (1 - "discountPercent")) STORED;
+ALTER TABLE "quoteLinePrice" ADD COLUMN "netExtendedPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * (1 - "discountPercent") * "quantity") STORED;
+ALTER TABLE "quoteLinePrice" ADD COLUMN "convertedNetExtendedPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * "exchangeRate" * (1 - "discountPercent") * "quantity") STORED;
-- Add a trigger to update the exchangeRate on quoteLinePrice when the exchangeRate is updated
CREATE OR REPLACE FUNCTION update_quote_line_price_exchange_rate()
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index 532f9eff26..51de1e4d17 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -76,11 +76,7 @@ const QuotePDF = ({
if (!acc[price.quoteLineId]) {
acc[price.quoteLineId] = [];
}
- const convertedPrice = { ...price };
- if (shouldConvertCurrency) {
- convertedPrice.unitPrice = price.unitPrice * exchangeRate;
- }
- acc[price.quoteLineId].push(convertedPrice);
+ acc[price.quoteLineId].push(price);
return acc;
}, {});
@@ -176,7 +172,7 @@ const QuotePDF = ({
<Text style={tw("w-1/5 text-right")}>Unit Price</Text>
<Text style={tw("w-1/5 text-right")}>Add-Ons</Text>
<Text style={tw("w-1/5 text-right")}>Lead Time</Text>
- <Text style={tw("w-1/5 text-right")}>Extended Price</Text>
+ <Text style={tw("w-1/5 text-right")}>Total Price</Text>
</View>
</View>
@@ -254,9 +250,9 @@ const QuotePDF = ({
const price = prices.find(
(price) => price.quantity === quantity
);
- const netPrice =
- price?.unitPrice *
- (1 - (price?.discountPercent ?? 0) / 100);
+ const netUnitPrice = price?.convertedNetUnitPrice ?? 0;
+ const netExtendedPrice =
+ price?.convertedNetExtendedPrice ?? 0;
const additionalCharge =
additionalChargesByQuantity[index] ?? 0;
@@ -265,7 +261,9 @@ const QuotePDF = ({
<View key={quantity} style={tw("flex flex-row")}>
<Text style={tw("w-1/5 text-right")}>{quantity}</Text>
<Text style={tw("w-1/5 text-right")}>
- {netPrice ? formatter.format(netPrice) : "-"}
+ {netUnitPrice
+ ? formatter.format(netUnitPrice)
+ : "-"}
</Text>
<Text style={tw("w-1/5 text-right")}>
{additionalCharge
@@ -276,9 +274,9 @@ const QuotePDF = ({
{price ? `${price.leadTime} days` : "-"}
</Text>
<Text style={tw("w-1/5 text-right")}>
- {netPrice
+ {netUnitPrice
? formatter.format(
- netPrice * quantity + additionalCharge
+ netExtendedPrice + additionalCharge
)
: "-"}
</Text>