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: conversion between supplier currency and base currency

Brad Barbinfefc5aac4cec
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx b/apps/carbon/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx
index b0c262fef6..dce216dc65 100644
--- a/apps/carbon/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx
@@ -77,15 +77,8 @@ const SupplierQuoteLinePricing = ({
routeData?.quote?.currencyCode ?? baseCurrency
);
- const netPricesByQuantity = quantities.map((quantity, index) => {
- const price = prices[quantity]?.unitPrice ?? 0;
- const discount = prices[quantity]?.discountPercent ?? 0;
- const netPrice = price * (1 - discount);
- return netPrice;
- });
-
const onUpdatePrice = async (
- key: "leadTime" | "unitPrice" | "shippingCost",
+ key: "leadTime" | "supplierUnitPrice" | "supplierShippingCost",
quantity: number,
value: number
) => {
@@ -105,10 +98,9 @@ const SupplierQuoteLinePricing = ({
supplierQuoteLineId: lineId,
quantity,
leadTime: 0,
- unitPrice: 0,
- discountPercent: 0,
exchangeRate: supplierQuoteExchangeRate.data?.exchangeRate ?? 1,
- shippingCost: 0,
+ supplierUnitPrice: 0,
+ supplierShippingCost: 0,
createdBy: userId,
} as unknown as SupplierQuoteLinePrice;
}
@@ -198,7 +190,8 @@ const SupplierQuoteLinePricing = ({
<Tr>
<Td className="border-r border-border">
<HStack className="w-full justify-between ">
- <span>Unit Price</span>
+ <span>Supplier Unit Price</span>
+
<Enumerable
value={
unitOfMeasures.find(
@@ -209,19 +202,20 @@ const SupplierQuoteLinePricing = ({
</HStack>
</Td>
{quantities.map((quantity) => {
- const price = prices[quantity]?.unitPrice;
+ const price = prices[quantity]?.supplierUnitPrice ?? 0;
return (
<Td key={quantity.toString()}>
<NumberField
value={price}
formatOptions={{
style: "currency",
- currency: baseCurrency,
+ currency:
+ routeData?.quote?.currencyCode ?? baseCurrency,
}}
minValue={0}
onChange={(value) => {
if (Number.isFinite(value) && value !== price) {
- onUpdatePrice("unitPrice", quantity, value);
+ onUpdatePrice("supplierUnitPrice", quantity, value);
}
}}
>
@@ -240,7 +234,7 @@ const SupplierQuoteLinePricing = ({
<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 Unit Price</span>
+ <span>Unit Price</span>
<Enumerable
value={
unitOfMeasures.find(
@@ -250,7 +244,10 @@ const SupplierQuoteLinePricing = ({
/>
</HStack>
</Td>
- {netPricesByQuantity.map((price, index) => {
+ {quantities.map((quantity, index) => {
+ const price =
+ (prices[quantity]?.supplierUnitPrice ?? 0) *
+ (prices[quantity]?.exchangeRate ?? 1);
return (
<Td key={index} className="group-hover:bg-muted/50">
<VStack spacing={0}>
@@ -270,19 +267,25 @@ const SupplierQuoteLinePricing = ({
</HStack>
</Td>
{quantities.map((quantity) => {
- const shippingCost = prices[quantity]?.shippingCost;
+ const shippingCost =
+ prices[quantity]?.supplierShippingCost ?? 0;
return (
<Td key={quantity.toString()}>
<NumberField
value={shippingCost}
formatOptions={{
style: "currency",
- currency: baseCurrency,
+ currency:
+ routeData?.quote?.currencyCode ?? baseCurrency,
}}
minValue={0}
onChange={(value) => {
if (Number.isFinite(value) && value !== shippingCost) {
- onUpdatePrice("shippingCost", quantity, value);
+ onUpdatePrice(
+ "supplierShippingCost",
+ quantity,
+ value
+ );
}
}}
>
@@ -318,6 +321,7 @@ const SupplierQuoteLinePricing = ({
<NumberInput
className="border-0 -ml-3 shadow-none disabled:bg-transparent disabled:opacity-100"
size="sm"
+ isDisabled
/>
</NumberField>
</Td>
@@ -327,19 +331,20 @@ const SupplierQuoteLinePricing = ({
<Tr className="font-bold [&>td]:bg-muted/60">
<Td className="border-r border-border group-hover:bg-muted/50">
<HStack className="w-full justify-between ">
- <span>Total Price</span>
+ <span>Supplier Total Price</span>
</HStack>
</Td>
{quantities.map((quantity, index) => {
const subtotal =
- (netPricesByQuantity[index] ?? 0) * quantity +
- (prices[quantity]?.shippingCost ?? 0);
+ (prices[quantity]?.supplierUnitPrice ?? 0) * quantity +
+ (prices[quantity]?.supplierShippingCost ?? 0);
const tax = subtotal * (line.taxPercent ?? 0);
const price = subtotal + tax;
+
return (
<Td key={index} className="group-hover:bg-muted/50">
<VStack spacing={0}>
- <span>{formatter.format(price)}</span>
+ <span>{presentationCurrencyFormatter.format(price)}</span>
</VStack>
</Td>
);
@@ -367,25 +372,21 @@ const SupplierQuoteLinePricing = ({
<Tr className="font-bold [&>td]:bg-muted/60">
<Td className="border-r border-border group-hover:bg-muted/50">
<HStack className="w-full justify-between ">
- <span>Converted Total Price</span>
+ <span>Total Price</span>
</HStack>
</Td>
{quantities.map((quantity, index) => {
const subtotal =
- (netPricesByQuantity[index] ?? 0) * quantity +
- (prices[quantity]?.shippingCost ?? 0);
+ ((prices[quantity]?.supplierUnitPrice ?? 0) * quantity +
+ (prices[quantity]?.supplierShippingCost ?? 0)) *
+ (prices[quantity]?.exchangeRate ?? 1);
const tax = subtotal * (line.taxPercent ?? 0);
const price = subtotal + tax;
- const exchangeRate = prices[quantity]?.exchangeRate;
- const convertedPrice = price * (exchangeRate ?? 1);
+
return (
<Td key={index} className="group-hover:bg-muted/50">
<VStack spacing={0}>
- <span>
- {presentationCurrencyFormatter.format(
- convertedPrice
- )}
- </span>
+ <span>{formatter.format(price)}</span>
</VStack>
</Td>
);
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSummary.tsx b/apps/carbon/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSummary.tsx
index 5bcb3b2df0..84dbae3e50 100644
--- a/apps/carbon/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSummary.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteSummary.tsx
@@ -22,7 +22,8 @@ import { motion } from "framer-motion";
import { useMemo, useState } from "react";
import { LuChevronDown, LuExternalLink, LuImage } from "react-icons/lu";
import { SupplierAvatar } from "~/components";
-import { useRouteData, useUser } from "~/hooks";
+import { useUnitOfMeasure } from "~/components/Form/UnitOfMeasure";
+import { useCurrencyFormatter, useRouteData, useUser } from "~/hooks";
import { getPrivateUrl, path } from "~/utils/path";
import type {
PurchaseOrderLine,
@@ -43,13 +44,16 @@ const LineItems = ({
const { company } = useUser();
const { id } = useParams();
if (!id) throw new Error("Could not find quote id");
+
const routeData = useRouteData<{
quote: SupplierQuote;
lines: SupplierQuoteLine[];
prices: SupplierQuoteLinePrice[];
}>(path.to.supplierQuote(id));
- const [openItems, setOpenItems] = useState<string[]>([]);
+ const [openItems, setOpenItems] = useState<string[]>(
+ routeData?.lines.map((line) => line.id!) ?? []
+ );
const pricingByLine = useMemo(
() =>
@@ -187,14 +191,12 @@ type LinePricingOptionsProps = {
const LinePricingOptions = ({
line,
options,
- quoteCurrency,
- shouldConvertCurrency,
- quoteExchangeRate,
locale,
formatter,
}: LinePricingOptionsProps) => {
const { id } = useParams();
if (!id) throw new Error("Could not find quote id");
+ const unitOfMeasures = useUnitOfMeasure();
return (
<VStack spacing={4} className="w-full">
@@ -204,7 +206,8 @@ const LinePricingOptions = ({
<Th>Quantity</Th>
<Th>Unit Price</Th>
<Th>Lead Time</Th>
- <Th>Subtotal</Th>
+
+ <Th className="text-right">Total</Th>
</Tr>
</Thead>
<Tbody>
@@ -220,9 +223,45 @@ const LinePricingOptions = ({
(line?.quantity?.includes(option.quantity) ||
option.quantity === 0) && (
<Tr key={index}>
- <Td>{option.quantity}</Td>
<Td>
- {formatter.format(option.convertedNetUnitPrice ?? 0)}
+ <div className="flex items-center gap-x-2 justify-between">
+ <VStack spacing={0}>
+ <span>
+ {option.quantity}{" "}
+ {
+ unitOfMeasures.find(
+ (uom) =>
+ uom.value === line.purchaseUnitOfMeasureCode
+ )?.label
+ }
+ </span>
+ {line.conversionFactor !== 1 && (
+ <span className="text-muted-foreground text-xs">
+ {option.quantity * (line.conversionFactor ?? 1)}{" "}
+ {
+ unitOfMeasures.find(
+ (uom) =>
+ uom.value ===
+ line.inventoryUnitOfMeasureCode
+ )?.label
+ }
+ </span>
+ )}
+ </VStack>
+ </div>
+ </Td>
+ <Td>
+ <VStack spacing={0}>
+ <span>{formatter.format(option.unitPrice ?? 0)}</span>
+ {line.conversionFactor !== 1 && (
+ <span className="text-muted-foreground text-xs">
+ {formatter.format(
+ (option.unitPrice ?? 0) /
+ (line.conversionFactor ?? 1)
+ )}
+ </span>
+ )}
+ </VStack>
</Td>
<Td>
@@ -231,10 +270,12 @@ const LinePricingOptions = ({
unit: "day",
}).format(option.leadTime)}
</Td>
- <Td>
+
+ <Td className="text-right">
{formatter.format(
- (option.convertedNetUnitPrice ?? 0) * option.quantity +
- (option.convertedShippingCost ?? 0)
+ ((option.unitPrice ?? 0) * option.quantity +
+ (option.shippingCost ?? 0)) *
+ (1 + (line.taxPercent ?? 0))
)}
</Td>
</Tr>
@@ -258,14 +299,7 @@ const SupplierQuoteSummary = () => {
}>(path.to.supplierQuote(id));
const { locale } = useLocale();
- const formatter = useMemo(
- () =>
- new Intl.NumberFormat(locale, {
- style: "currency",
- currency: routeData?.quote.currencyCode ?? "USD",
- }),
- [locale, routeData?.quote.currencyCode]
- );
+ const formatter = useCurrencyFormatter();
return (
<Card>
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.exchange-rate.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.exchange-rate.tsx
index 3c42464ced..b91aca3944 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.exchange-rate.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.exchange-rate.tsx
@@ -4,7 +4,7 @@ import { flash } from "@carbon/auth/session.server";
import { redirect, type ActionFunctionArgs } from "@vercel/remix";
import { getCurrencyByCode } from "~/modules/accounting";
import { updateQuoteExchangeRate } from "~/modules/sales";
-import { path } from "~/utils/path";
+import { path, requestReferrer } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
@@ -33,7 +33,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
return redirect(
- path.to.quoteDetails(quoteId),
+ requestReferrer(request) ?? path.to.quoteDetails(quoteId),
await flash(request, success("Successfully updated exchange rate"))
);
}
diff --git a/apps/carbon/app/routes/x+/supplier-quote+/$id.exchange-rate.tsx b/apps/carbon/app/routes/x+/supplier-quote+/$id.exchange-rate.tsx
index 2f346512d4..24e84c888e 100644
--- a/apps/carbon/app/routes/x+/supplier-quote+/$id.exchange-rate.tsx
+++ b/apps/carbon/app/routes/x+/supplier-quote+/$id.exchange-rate.tsx
@@ -4,7 +4,7 @@ import { flash } from "@carbon/auth/session.server";
import { redirect, type ActionFunctionArgs } from "@vercel/remix";
import { getCurrencyByCode } from "~/modules/accounting";
import { updateSupplierQuoteExchangeRate } from "~/modules/purchasing";
-import { path } from "~/utils/path";
+import { path, requestReferrer } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
@@ -33,7 +33,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
return redirect(
- path.to.supplierQuoteDetails(id),
+ requestReferrer(request) ?? path.to.supplierQuoteDetails(id),
await flash(request, success("Successfully updated exchange rate"))
);
}
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 21f55e2651..3dc85fb036 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -26368,35 +26368,26 @@ export default {
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.leadTime",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.discountPercent",
- },
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.unitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierUnitPrice",
},
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.exchangeRate",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedUnitPrice",
- },
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.netUnitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.unitPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedNetUnitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierExtendedPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.netExtendedPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.extendedPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedNetExtendedPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierShippingCost",
},
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.shippingCost",
},
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedShippingCost",
- },
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.createdAt",
},
@@ -26481,35 +26472,26 @@ export default {
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.leadTime",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.discountPercent",
- },
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.unitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierUnitPrice",
},
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.exchangeRate",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedUnitPrice",
- },
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.netUnitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.unitPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedNetUnitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierExtendedPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.netExtendedPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.extendedPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedNetExtendedPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierShippingCost",
},
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.shippingCost",
},
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedShippingCost",
- },
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.createdAt",
},
@@ -26548,35 +26530,26 @@ export default {
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.leadTime",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.discountPercent",
- },
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.unitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierUnitPrice",
},
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.exchangeRate",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedUnitPrice",
- },
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.netUnitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.unitPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedNetUnitPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierExtendedPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.netExtendedPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.extendedPrice",
},
{
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedNetExtendedPrice",
+ $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.supplierShippingCost",
},
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.shippingCost",
},
- {
- $ref: "#/parameters/rowFilter.supplierQuoteLinePrice.convertedShippingCost",
- },
{
$ref: "#/parameters/rowFilter.supplierQuoteLinePrice.createdAt",
},
@@ -52340,9 +52313,8 @@ export default {
"supplierQuoteLineId",
"quantity",
"leadTime",
- "discountPercent",
- "unitPrice",
- "shippingCost",
+ "supplierUnitPrice",
+ "supplierShippingCost",
"createdAt",
"createdBy",
],
@@ -52370,12 +52342,7 @@ export default {
format: "numeric",
type: "number",
},
- discountPercent: {
- default: 0,
- format: "numeric",
- type: "number",
- },
- unitPrice: {
+ supplierUnitPrice: {
default: 0,
format: "numeric",
type: "number",
@@ -52385,32 +52352,24 @@ export default {
format: "numeric",
type: "number",
},
- convertedUnitPrice: {
- format: "numeric",
- type: "number",
- },
- netUnitPrice: {
- format: "numeric",
- type: "number",
- },
- convertedNetUnitPrice: {
+ unitPrice: {
format: "numeric",
type: "number",
},
- netExtendedPrice: {
+ supplierExtendedPrice: {
format: "numeric",
type: "number",
},
- convertedNetExtendedPrice: {
+ extendedPrice: {
format: "numeric",
type: "number",
},
- shippingCost: {
+ supplierShippingCost: {
default: 0,
format: "numeric",
type: "number",
},
- convertedShippingCost: {
+ shippingCost: {
format: "numeric",
type: "number",
},
@@ -73398,15 +73357,8 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.supplierQuoteLinePrice.discountPercent": {
- name: "discountPercent",
- required: false,
- format: "numeric",
- in: "query",
- type: "string",
- },
- "rowFilter.supplierQuoteLinePrice.unitPrice": {
- name: "unitPrice",
+ "rowFilter.supplierQuoteLinePrice.supplierUnitPrice": {
+ name: "supplierUnitPrice",
required: false,
format: "numeric",
in: "query",
@@ -73419,36 +73371,29 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.supplierQuoteLinePrice.convertedUnitPrice": {
- name: "convertedUnitPrice",
- required: false,
- format: "numeric",
- in: "query",
- type: "string",
- },
- "rowFilter.supplierQuoteLinePrice.netUnitPrice": {
- name: "netUnitPrice",
+ "rowFilter.supplierQuoteLinePrice.unitPrice": {
+ name: "unitPrice",
required: false,
format: "numeric",
in: "query",
type: "string",
},
- "rowFilter.supplierQuoteLinePrice.convertedNetUnitPrice": {
- name: "convertedNetUnitPrice",
+ "rowFilter.supplierQuoteLinePrice.supplierExtendedPrice": {
+ name: "supplierExtendedPrice",
required: false,
format: "numeric",
in: "query",
type: "string",
},
- "rowFilter.supplierQuoteLinePrice.netExtendedPrice": {
- name: "netExtendedPrice",
+ "rowFilter.supplierQuoteLinePrice.extendedPrice": {
+ name: "extendedPrice",
required: false,
format: "numeric",
in: "query",
type: "string",
},
- "rowFilter.supplierQuoteLinePrice.convertedNetExtendedPrice": {
- name: "convertedNetExtendedPrice",
+ "rowFilter.supplierQuoteLinePrice.supplierShippingCost": {
+ name: "supplierShippingCost",
required: false,
format: "numeric",
in: "query",
@@ -73461,13 +73406,6 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.supplierQuoteLinePrice.convertedShippingCost": {
- name: "convertedShippingCost",
- required: false,
- format: "numeric",
- in: "query",
- type: "string",
- },
"rowFilter.supplierQuoteLinePrice.createdAt": {
name: "createdAt",
required: false,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 1e3d2f0365..b4372a54c6 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -21790,62 +21790,53 @@ export type Database = {
}
supplierQuoteLinePrice: {
Row: {
- convertedNetExtendedPrice: number | null
- convertedNetUnitPrice: number | null
- convertedShippingCost: number | null
- convertedUnitPrice: number | null
createdAt: string
createdBy: string
- discountPercent: number
exchangeRate: number | null
+ extendedPrice: number | null
leadTime: number
- netExtendedPrice: number | null
- netUnitPrice: number | null
quantity: number
- shippingCost: number
+ shippingCost: number | null
+ supplierExtendedPrice: number | null
supplierQuoteId: string
supplierQuoteLineId: string
- unitPrice: number
+ supplierShippingCost: number
+ supplierUnitPrice: number
+ unitPrice: number | null
updatedAt: string | null
updatedBy: string | null
}
Insert: {
- convertedNetExtendedPrice?: number | null
- convertedNetUnitPrice?: number | null
- convertedShippingCost?: number | null
- convertedUnitPrice?: number | null
createdAt?: string
createdBy: string
- discountPercent?: number
exchangeRate?: number | null
+ extendedPrice?: number | null
leadTime?: number
- netExtendedPrice?: number | null
- netUnitPrice?: number | null
quantity?: number
- shippingCost?: number
+ shippingCost?: number | null
+ supplierExtendedPrice?: number | null
supplierQuoteId: string
supplierQuoteLineId: string
- unitPrice?: number
+ supplierShippingCost?: number
+ supplierUnitPrice?: number
+ unitPrice?: number | null
updatedAt?: string | null
updatedBy?: string | null
}
Update: {
- convertedNetExtendedPrice?: number | null
- convertedNetUnitPrice?: number | null
- convertedShippingCost?: number | null
- convertedUnitPrice?: number | null
createdAt?: string
createdBy?: string
- discountPercent?: number
exchangeRate?: number | null
+ extendedPrice?: number | null
leadTime?: number
- netExtendedPrice?: number | null
- netUnitPrice?: number | null
quantity?: number
- shippingCost?: number
+ shippingCost?: number | null
+ supplierExtendedPrice?: number | null
supplierQuoteId?: string
supplierQuoteLineId?: string
- unitPrice?: number
+ supplierShippingCost?: number
+ supplierUnitPrice?: number
+ unitPrice?: number | null
updatedAt?: string | null
updatedBy?: string | null
}
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 1e3d2f0365..b4372a54c6 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -21790,62 +21790,53 @@ export type Database = {
}
supplierQuoteLinePrice: {
Row: {
- convertedNetExtendedPrice: number | null
- convertedNetUnitPrice: number | null
- convertedShippingCost: number | null
- convertedUnitPrice: number | null
createdAt: string
createdBy: string
- discountPercent: number
exchangeRate: number | null
+ extendedPrice: number | null
leadTime: number
- netExtendedPrice: number | null
- netUnitPrice: number | null
quantity: number
- shippingCost: number
+ shippingCost: number | null
+ supplierExtendedPrice: number | null
supplierQuoteId: string
supplierQuoteLineId: string
- unitPrice: number
+ supplierShippingCost: number
+ supplierUnitPrice: number
+ unitPrice: number | null
updatedAt: string | null
updatedBy: string | null
}
Insert: {
- convertedNetExtendedPrice?: number | null
- convertedNetUnitPrice?: number | null
- convertedShippingCost?: number | null
- convertedUnitPrice?: number | null
createdAt?: string
createdBy: string
- discountPercent?: number
exchangeRate?: number | null
+ extendedPrice?: number | null
leadTime?: number
- netExtendedPrice?: number | null
- netUnitPrice?: number | null
quantity?: number
- shippingCost?: number
+ shippingCost?: number | null
+ supplierExtendedPrice?: number | null
supplierQuoteId: string
supplierQuoteLineId: string
- unitPrice?: number
+ supplierShippingCost?: number
+ supplierUnitPrice?: number
+ unitPrice?: number | null
updatedAt?: string | null
updatedBy?: string | null
}
Update: {
- convertedNetExtendedPrice?: number | null
- convertedNetUnitPrice?: number | null
- convertedShippingCost?: number | null
- convertedUnitPrice?: number | null
createdAt?: string
createdBy?: string
- discountPercent?: number
exchangeRate?: number | null
+ extendedPrice?: number | null
leadTime?: number
- netExtendedPrice?: number | null
- netUnitPrice?: number | null
quantity?: number
- shippingCost?: number
+ shippingCost?: number | null
+ supplierExtendedPrice?: number | null
supplierQuoteId?: string
supplierQuoteLineId?: string
- unitPrice?: number
+ supplierShippingCost?: number
+ supplierUnitPrice?: number
+ unitPrice?: number | null
updatedAt?: string | null
updatedBy?: string | null
}
diff --git a/packages/database/supabase/migrations/20241202192419_supplier-quotes.sql b/packages/database/supabase/migrations/20241202192419_supplier-quotes.sql
index d2e8bce4a2..53d9cb7a33 100644
--- a/packages/database/supabase/migrations/20241202192419_supplier-quotes.sql
+++ b/packages/database/supabase/migrations/20241202192419_supplier-quotes.sql
@@ -54,8 +54,8 @@ CREATE TABLE "supplierQuote" (
CONSTRAINT "supplierQuote_pkey" PRIMARY KEY ("id"),
CONSTRAINT "supplierQuote_quoteId_key" UNIQUE ("supplierQuoteId", "companyId"),
CONSTRAINT "supplierQuote_supplierId_fkey" FOREIGN KEY ("supplierId") REFERENCES "supplier" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT "supplierQuote_supplierLocationId_fkey" FOREIGN KEY ("supplierLocationId") REFERENCES "supplierLocation" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
- CONSTRAINT "supplierQuote_supplierContactId_fkey" FOREIGN KEY ("supplierContactId") REFERENCES "supplierContact" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "supplierQuote_supplierLocationId_fkey" FOREIGN KEY ("supplierLocationId") REFERENCES "supplierLocation" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT "supplierQuote_supplierContactId_fkey" FOREIGN KEY ("supplierContactId") REFERENCES "supplierContact" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "supplierQuote_assignee_fkey" FOREIGN KEY ("assignee") REFERENCES "user" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "supplierQuote_currencyCode_fkey" FOREIGN KEY ("currencyCode") REFERENCES "currencyCode"("code") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "supplierQuote_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
@@ -106,16 +106,13 @@ CREATE TABLE "supplierQuoteLinePrice" (
"supplierQuoteLineId" TEXT NOT NULL,
"quantity" NUMERIC(10,5) NOT NULL DEFAULT 1,
"leadTime" NUMERIC(10,5) NOT NULL DEFAULT 0,
- "discountPercent" NUMERIC(10,5) NOT NULL DEFAULT 0,
- "unitPrice" NUMERIC(10,5) NOT NULL DEFAULT 0,
+ "supplierUnitPrice" NUMERIC(10,5) NOT NULL DEFAULT 0,
"exchangeRate" NUMERIC(10,4) DEFAULT 1,
- "convertedUnitPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * "exchangeRate") STORED,
- "netUnitPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * (1 - "discountPercent")) STORED,
- "convertedNetUnitPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * "exchangeRate" * (1 - "discountPercent")) STORED,
- "netExtendedPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * (1 - "discountPercent") * "quantity") STORED,
- "convertedNetExtendedPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("unitPrice" * "exchangeRate" * (1 - "discountPercent") * "quantity") STORED,
- "shippingCost" NUMERIC(10,5) NOT NULL DEFAULT 0,
- "convertedShippingCost" NUMERIC(10,5) GENERATED ALWAYS AS ("shippingCost" * "exchangeRate") STORED,
+ "unitPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("supplierUnitPrice" * "exchangeRate") STORED,
+ "supplierExtendedPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("supplierUnitPrice" * "quantity") STORED,
+ "extendedPrice" NUMERIC(10,5) GENERATED ALWAYS AS ("supplierUnitPrice" * "exchangeRate" * "quantity") STORED,
+ "supplierShippingCost" NUMERIC(10,5) NOT NULL DEFAULT 0,
+ "shippingCost" NUMERIC(10,5) GENERATED ALWAYS AS ("supplierShippingCost" * "exchangeRate") STORED,
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
"createdBy" TEXT NOT NULL,
"updatedAt" TIMESTAMP WITH TIME ZONE,
@@ -214,3 +211,21 @@ CREATE OR REPLACE VIEW "supplierQuoteLines" WITH(SECURITY_INVOKER=true) AS (
INNER JOIN "item" i ON i.id = ql."itemId"
LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
);
+
+CREATE OR REPLACE FUNCTION update_supplier_quote_line_price_exchange_rate()
+RETURNS TRIGGER AS $$
+BEGIN
+ UPDATE "supplierQuoteLinePrice"
+ SET "exchangeRate" = NEW."exchangeRate"
+ WHERE "supplierQuoteId" = NEW."id";
+
+ RETURN NEW;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE OR REPLACE TRIGGER update_supplier_quote_line_price_exchange_rate_trigger
+AFTER UPDATE OF "exchangeRate" ON "supplierQuote"
+FOR EACH ROW
+WHEN (OLD."exchangeRate" IS DISTINCT FROM NEW."exchangeRate")
+EXECUTE FUNCTION update_supplier_quote_line_price_exchange_rate();
+