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: create global currencyCode table

Rob Carrington2081670cdffa
diff --git a/apps/carbon/app/components/Form/Currency.tsx b/apps/carbon/app/components/Form/Currency.tsx
index 85d4fe09ac..9e1a246d8d 100644
--- a/apps/carbon/app/components/Form/Currency.tsx
+++ b/apps/carbon/app/components/Form/Currency.tsx
@@ -9,7 +9,7 @@ import { path } from "~/utils/path";
type CurrencySelectProps = Omit<ComboboxProps, "options">;
const Currency = ({ ...props }: CurrencySelectProps) => {
- const options = useCurrencies();
+ const options = useCurrencyCodes();
return (
<Combobox {...props} options={options} label={props?.label ?? "Currency"} />
@@ -20,7 +20,7 @@ Currency.displayName = "Currency";
export default Currency;
-const useCurrencies = () => {
+const useCurrencyCodes = () => {
const currencyFetcher =
useFetcher<Awaited<ReturnType<typeof getCurrenciesList>>>();
diff --git a/apps/carbon/app/modules/accounting/accounting.service.ts b/apps/carbon/app/modules/accounting/accounting.service.ts
index 2729064d4a..53f33c6b16 100644
--- a/apps/carbon/app/modules/accounting/accounting.service.ts
+++ b/apps/carbon/app/modules/accounting/accounting.service.ts
@@ -426,9 +426,8 @@ export async function getCurrenciesList(
companyId: string
) {
return client
- .from("currency")
+ .from("currencyCode")
.select("code, name")
- .eq("companyId", companyId)
.order("name", { ascending: true });
}
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 0188440038..b5864bf862 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -3480,6 +3480,123 @@ export default {
tags: ["supplierPayment"],
},
},
+ "/currencyCode": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.code",
+ },
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.symbol",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/currencyCode",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["currencyCode"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.currencyCode",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["currencyCode"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.code",
+ },
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.symbol",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["currencyCode"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.code",
+ },
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.currencyCode.symbol",
+ },
+ {
+ $ref: "#/parameters/body.currencyCode",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["currencyCode"],
+ },
+ },
"/methodMaterial": {
get: {
parameters: [
@@ -31116,15 +31233,9 @@ export default {
{
$ref: "#/parameters/rowFilter.currency.id",
},
- {
- $ref: "#/parameters/rowFilter.currency.name",
- },
{
$ref: "#/parameters/rowFilter.currency.code",
},
- {
- $ref: "#/parameters/rowFilter.currency.symbol",
- },
{
$ref: "#/parameters/rowFilter.currency.exchangeRate",
},
@@ -31217,15 +31328,9 @@ export default {
{
$ref: "#/parameters/rowFilter.currency.id",
},
- {
- $ref: "#/parameters/rowFilter.currency.name",
- },
{
$ref: "#/parameters/rowFilter.currency.code",
},
- {
- $ref: "#/parameters/rowFilter.currency.symbol",
- },
{
$ref: "#/parameters/rowFilter.currency.exchangeRate",
},
@@ -31272,15 +31377,9 @@ export default {
{
$ref: "#/parameters/rowFilter.currency.id",
},
- {
- $ref: "#/parameters/rowFilter.currency.name",
- },
{
$ref: "#/parameters/rowFilter.currency.code",
},
- {
- $ref: "#/parameters/rowFilter.currency.symbol",
- },
{
$ref: "#/parameters/rowFilter.currency.exchangeRate",
},
@@ -37152,6 +37251,25 @@ export default {
},
type: "object",
},
+ currencyCode: {
+ required: ["code", "name", "symbol"],
+ properties: {
+ code: {
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ name: {
+ format: "text",
+ type: "string",
+ },
+ symbol: {
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
methodMaterial: {
required: [
"id",
@@ -50189,7 +50307,6 @@ export default {
currency: {
required: [
"id",
- "name",
"code",
"exchangeRate",
"decimalPlaces",
@@ -50206,15 +50323,9 @@ export default {
format: "text",
type: "string",
},
- name: {
- format: "text",
- type: "string",
- },
code: {
- format: "text",
- type: "string",
- },
- symbol: {
+ description:
+ "Note:\nThis is a Foreign Key to `currencyCode.code`.<fk table='currencyCode' column='code'/>",
format: "text",
type: "string",
},
@@ -53063,6 +53174,36 @@ export default {
in: "query",
type: "string",
},
+ "body.currencyCode": {
+ name: "currencyCode",
+ description: "currencyCode",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/currencyCode",
+ },
+ },
+ "rowFilter.currencyCode.code": {
+ name: "code",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.currencyCode.name": {
+ name: "name",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.currencyCode.symbol": {
+ name: "symbol",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.methodMaterial": {
name: "methodMaterial",
description: "methodMaterial",
@@ -70048,13 +70189,6 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.currency.name": {
- name: "name",
- required: false,
- format: "text",
- in: "query",
- type: "string",
- },
"rowFilter.currency.code": {
name: "code",
required: false,
@@ -70062,13 +70196,6 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.currency.symbol": {
- name: "symbol",
- required: false,
- format: "text",
- in: "query",
- type: "string",
- },
"rowFilter.currency.exchangeRate": {
name: "exchangeRate",
required: false,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 6402ab4052..c80145de88 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -2664,8 +2664,6 @@ export type Database = {
exchangeRate: number
id: string
isBaseCurrency: boolean
- name: string
- symbol: string | null
updatedAt: string | null
updatedBy: string | null
}
@@ -2680,8 +2678,6 @@ export type Database = {
exchangeRate?: number
id?: string
isBaseCurrency?: boolean
- name: string
- symbol?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -2696,8 +2692,6 @@ export type Database = {
exchangeRate?: number
id?: string
isBaseCurrency?: boolean
- name?: string
- symbol?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -2730,6 +2724,13 @@ export type Database = {
referencedRelation: "integrations"
referencedColumns: ["companyId"]
},
+ {
+ foreignKeyName: "currency_currencyCode_fkey"
+ columns: ["code"]
+ isOneToOne: false
+ referencedRelation: "currencyCode"
+ referencedColumns: ["code"]
+ },
{
foreignKeyName: "currency_updatedBy_fkey"
columns: ["updatedBy"]
@@ -2767,6 +2768,24 @@ export type Database = {
},
]
}
+ currencyCode: {
+ Row: {
+ code: string
+ name: string
+ symbol: string
+ }
+ Insert: {
+ code: string
+ name: string
+ symbol: string
+ }
+ Update: {
+ code?: string
+ name?: string
+ symbol?: string
+ }
+ Relationships: []
+ }
customer: {
Row: {
accountManagerId: string | null
diff --git a/packages/database/supabase/functions/lib/seed.ts b/packages/database/supabase/functions/lib/seed.ts
index 0ddbadecb2..31b460da45 100644
--- a/packages/database/supabase/functions/lib/seed.ts
+++ b/packages/database/supabase/functions/lib/seed.ts
@@ -803,1062 +803,826 @@ export const accountDefaults = {
export const currencies = [
{
- name: "US Dollar",
code: "USD",
- symbol: "$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Canadian Dollar",
code: "CAD",
- symbol: "CA$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Euro",
code: "EUR",
- symbol: "€",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "United Arab Emirates Dirham",
code: "AED",
- symbol: "AED",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Afghan Afghani",
code: "AFN",
- symbol: "Af",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Albanian Lek",
code: "ALL",
- symbol: "ALL",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Armenian Dram",
code: "AMD",
- symbol: "AMD",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Argentine Peso",
code: "ARS",
- symbol: "AR$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Australian Dollar",
code: "AUD",
- symbol: "AU$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Azerbaijani Manat",
code: "AZN",
- symbol: "man.",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Bosnia-Herzegovina Convertible Mark",
code: "BAM",
- symbol: "KM",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Bangladeshi Taka",
code: "BDT",
- symbol: "Tk",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Bulgarian Lev",
code: "BGN",
- symbol: "BGN",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Bahraini Dinar",
code: "BHD",
- symbol: "BD",
exchangeRate: 1,
decimalPlaces: 3,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Burundian Franc",
code: "BIF",
- symbol: "FBu",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Brunei Dollar",
code: "BND",
- symbol: "BN$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Bolivian Boliviano",
code: "BOB",
- symbol: "Bs",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Brazilian Real",
code: "BRL",
- symbol: "R$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Botswanan Pula",
code: "BWP",
- symbol: "BWP",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Belarusian Ruble",
code: "BYN",
- symbol: "Br",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Belize Dollar",
code: "BZD",
- symbol: "BZ$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Congolese Franc",
code: "CDF",
- symbol: "CDF",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Swiss Franc",
code: "CHF",
- symbol: "CHF",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Chilean Peso",
code: "CLP",
- symbol: "CL$",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Chinese Yuan",
code: "CNY",
- symbol: "CN¥",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Colombian Peso",
code: "COP",
- symbol: "CO$",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Costa Rican Colón",
code: "CRC",
- symbol: "₡",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Cape Verdean Escudo",
code: "CVE",
- symbol: "CV$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Czech Republic Koruna",
code: "CZK",
- symbol: "Kč",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Djiboutian Franc",
code: "DJF",
- symbol: "Fdj",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Danish Krone",
code: "DKK",
- symbol: "Dkr",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Dominican Peso",
code: "DOP",
- symbol: "RD$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Algerian Dinar",
code: "DZD",
- symbol: "DA",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Egyptian Pound",
code: "EGP",
- symbol: "EGP",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Eritrean Nakfa",
code: "ERN",
- symbol: "Nfk",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Ethiopian Birr",
code: "ETB",
- symbol: "Br",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "British Pound Sterling",
code: "GBP",
- symbol: "£",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Georgian Lari",
code: "GEL",
- symbol: "GEL",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Ghanaian Cedi",
code: "GHS",
- symbol: "GH₵",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Guinean Franc",
code: "GNF",
- symbol: "FG",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Guatemalan Quetzal",
code: "GTQ",
- symbol: "GTQ",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Hong Kong Dollar",
code: "HKD",
- symbol: "HK$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Honduran Lempira",
code: "HNL",
- symbol: "HNL",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Croatian Kuna",
code: "HRK",
- symbol: "kn",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Hungarian Forint",
code: "HUF",
- symbol: "Ft",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Indonesian Rupiah",
code: "IDR",
- symbol: "Rp",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Israeli New Sheqel",
code: "ILS",
- symbol: "₪",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Indian Rupee",
code: "INR",
- symbol: "Rs",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Iraqi Dinar",
code: "IQD",
- symbol: "IQD",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Iranian Rial",
code: "IRR",
- symbol: "IRR",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Icelandic Króna",
code: "ISK",
- symbol: "Ikr",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Jamaican Dollar",
code: "JMD",
- symbol: "J$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Jordanian Dinar",
code: "JOD",
- symbol: "JD",
exchangeRate: 1,
decimalPlaces: 3,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Japanese Yen",
code: "JPY",
- symbol: "¥",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Kenyan Shilling",
code: "KES",
- symbol: "Ksh",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Cambodian Riel",
code: "KHR",
- symbol: "KHR",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Comorian Franc",
code: "KMF",
- symbol: "CF",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "South Korean Won",
code: "KRW",
- symbol: "₩",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Kuwaiti Dinar",
code: "KWD",
- symbol: "KD",
exchangeRate: 1,
decimalPlaces: 3,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Kazakhstani Tenge",
code: "KZT",
- symbol: "KZT",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Lebanese Pound",
code: "LBP",
- symbol: "L.L",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Sri Lankan Rupee",
code: "LKR",
- symbol: "SLRs",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Lithuanian Litas",
code: "LTL",
- symbol: "Lt",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Latvian Lats",
code: "LVL",
- symbol: "Ls",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Libyan Dinar",
code: "LYD",
- symbol: "LD",
exchangeRate: 1,
decimalPlaces: 3,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Moroccan Dirham",
code: "MAD",
- symbol: "MAD",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Moldovan Leu",
code: "MDL",
- symbol: "MDL",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Malagasy Ariary",
code: "MGA",
- symbol: "MGA",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Macedonian Denar",
code: "MKD",
- symbol: "MKD",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Myanma Kyat",
code: "MMK",
- symbol: "MMK",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Macanese Pataca",
code: "MOP",
- symbol: "MOP$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Mauritian Rupee",
code: "MUR",
- symbol: "MURs",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Mexican Peso",
code: "MXN",
- symbol: "MX$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Malaysian Ringgit",
code: "MYR",
- symbol: "RM",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Mozambican Metical",
code: "MZN",
- symbol: "MTn",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Namibian Dollar",
code: "NAD",
- symbol: "N$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Nigerian Naira",
code: "NGN",
- symbol: "₦",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Nicaraguan Córdoba",
code: "NIO",
- symbol: "C$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Norwegian Krone",
code: "NOK",
- symbol: "Nkr",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Nepalese Rupee",
code: "NPR",
- symbol: "NPRs",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "New Zealand Dollar",
code: "NZD",
- symbol: "NZ$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Omani Rial",
code: "OMR",
- symbol: "OMR",
exchangeRate: 1,
decimalPlaces: 3,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Panamanian Balboa",
code: "PAB",
- symbol: "B/.",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Peruvian Nuevo Sol",
code: "PEN",
- symbol: "S/.",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Philippine Peso",
code: "PHP",
- symbol: "₱",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Pakistani Rupee",
code: "PKR",
- symbol: "PKRs",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Polish Zloty",
code: "PLN",
- symbol: "zł",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Paraguayan Guarani",
code: "PYG",
- symbol: "₲",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Qatari Rial",
code: "QAR",
- symbol: "QR",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Romanian Leu",
code: "RON",
- symbol: "RON",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Serbian Dinar",
code: "RSD",
- symbol: "din.",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Russian Ruble",
code: "RUB",
- symbol: "RUB",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Rwandan Franc",
code: "RWF",
- symbol: "RWF",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Saudi Riyal",
code: "SAR",
- symbol: "SR",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Sudanese Pound",
code: "SDG",
- symbol: "SDG",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Swedish Krona",
code: "SEK",
- symbol: "Skr",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Singapore Dollar",
code: "SGD",
- symbol: "S$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Somali Shilling",
code: "SOS",
- symbol: "Ssh",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Syrian Pound",
code: "SYP",
- symbol: "SY£",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Thai Baht",
code: "THB",
- symbol: "฿",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Tunisian Dinar",
code: "TND",
- symbol: "DT",
exchangeRate: 1,
decimalPlaces: 3,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Tongan Paʻanga",
code: "TOP",
- symbol: "T$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Turkish Lira",
code: "TRY",
- symbol: "TL",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Trinidad and Tobago Dollar",
code: "TTD",
- symbol: "TT$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "New Taiwan Dollar",
code: "TWD",
- symbol: "NT$",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Tanzanian Shilling",
code: "TZS",
- symbol: "TSh",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Ukrainian Hryvnia",
code: "UAH",
- symbol: "₴",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Ugandan Shilling",
code: "UGX",
- symbol: "USh",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Uruguayan Peso",
code: "UYU",
- symbol: "$U",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Uzbekistan Som",
code: "UZS",
- symbol: "UZS",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Venezuelan Bolívar",
code: "VEF",
- symbol: "Bs.F",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Vietnamese Dong",
code: "VND",
- symbol: "₫",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "CFA Franc BEAC",
code: "XAF",
- symbol: "FCFA",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "CFA Franc BCEAO",
code: "XOF",
- symbol: "CFA",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Yemeni Rial",
code: "YER",
- symbol: "YR",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "South African Rand",
code: "ZAR",
- symbol: "R",
exchangeRate: 1,
decimalPlaces: 2,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Zambian Kwacha",
code: "ZMK",
- symbol: "ZK",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
createdBy: "system",
},
{
- name: "Zimbabwean Dollar",
code: "ZWL",
- symbol: "ZWL$",
exchangeRate: 1,
decimalPlaces: 0,
isBaseCurrency: false,
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 6402ab4052..c80145de88 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -2664,8 +2664,6 @@ export type Database = {
exchangeRate: number
id: string
isBaseCurrency: boolean
- name: string
- symbol: string | null
updatedAt: string | null
updatedBy: string | null
}
@@ -2680,8 +2678,6 @@ export type Database = {
exchangeRate?: number
id?: string
isBaseCurrency?: boolean
- name: string
- symbol?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -2696,8 +2692,6 @@ export type Database = {
exchangeRate?: number
id?: string
isBaseCurrency?: boolean
- name?: string
- symbol?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -2730,6 +2724,13 @@ export type Database = {
referencedRelation: "integrations"
referencedColumns: ["companyId"]
},
+ {
+ foreignKeyName: "currency_currencyCode_fkey"
+ columns: ["code"]
+ isOneToOne: false
+ referencedRelation: "currencyCode"
+ referencedColumns: ["code"]
+ },
{
foreignKeyName: "currency_updatedBy_fkey"
columns: ["updatedBy"]
@@ -2767,6 +2768,24 @@ export type Database = {
},
]
}
+ currencyCode: {
+ Row: {
+ code: string
+ name: string
+ symbol: string
+ }
+ Insert: {
+ code: string
+ name: string
+ symbol: string
+ }
+ Update: {
+ code?: string
+ name?: string
+ symbol?: string
+ }
+ Relationships: []
+ }
customer: {
Row: {
accountManagerId: string | null
diff --git a/packages/database/supabase/migrations/20240930183906_currency-codes.sql b/packages/database/supabase/migrations/20240930183906_currency-codes.sql
new file mode 100644
index 0000000000..6367c87876
--- /dev/null
+++ b/packages/database/supabase/migrations/20240930183906_currency-codes.sql
@@ -0,0 +1,138 @@
+CREATE TABLE "currencyCode" (
+ "code" TEXT PRIMARY KEY,
+ "name" TEXT NOT NULL,
+ "symbol" TEXT NOT NULL
+);
+
+ALTER TABLE "currencyCode" ENABLE ROW LEVEL SECURITY;
+CREATE POLICY "Authenticated users can view currency codes" ON "currencyCode" FOR SELECT USING (auth.role() = 'authenticated');
+
+INSERT INTO "currencyCode" ("code", "name", "symbol")
+VALUES
+ ('USD', 'US Dollar', '$'),
+ ('CAD', 'Canadian Dollar', 'CA$'),
+ ('EUR', 'Euro', '€'),
+ ('AED', 'United Arab Emirates Dirham', 'AED'),
+ ('AFN', 'Afghan Afghani', 'Af'),
+ ('ALL', 'Albanian Lek', 'ALL'),
+ ('AMD', 'Armenian Dram', 'AMD'),
+ ('ARS', 'Argentine Peso', 'AR$'),
+ ('AUD', 'Australian Dollar', 'AU$'),
+ ('AZN', 'Azerbaijani Manat', 'man.'),
+ ('BAM', 'Bosnia-Herzegovina Convertible Mark', 'KM'),
+ ('BDT', 'Bangladeshi Taka', 'Tk'),
+ ('BGN', 'Bulgarian Lev', 'BGN'),
+ ('BHD', 'Bahraini Dinar', 'BD'),
+ ('BIF', 'Burundian Franc', 'FBu'),
+ ('BND', 'Brunei Dollar', 'BN$'),
+ ('BOB', 'Bolivian Boliviano', 'Bs'),
+ ('BRL', 'Brazilian Real', 'R$'),
+ ('BWP', 'Botswanan Pula', 'BWP'),
+ ('BYN', 'Belarusian Ruble', 'Br'),
+ ('BZD', 'Belize Dollar', 'BZ$'),
+ ('CDF', 'Congolese Franc', 'CDF'),
+ ('CHF', 'Swiss Franc', 'CHF'),
+ ('CLP', 'Chilean Peso', 'CL$'),
+ ('CNY', 'Chinese Yuan', 'CN¥'),
+ ('COP', 'Colombian Peso', 'CO$'),
+ ('CRC', 'Costa Rican Colón', '₡'),
+ ('CVE', 'Cape Verdean Escudo', 'CV$'),
+ ('CZK', 'Czech Republic Koruna', 'Kč'),
+ ('DJF', 'Djiboutian Franc', 'Fdj'),
+ ('DKK', 'Danish Krone', 'Dkr'),
+ ('DOP', 'Dominican Peso', 'RD$'),
+ ('DZD', 'Algerian Dinar', 'DA'),
+ ('EGP', 'Egyptian Pound', 'EGP'),
+ ('ERN', 'Eritrean Nakfa', 'Nfk'),
+ ('ETB', 'Ethiopian Birr', 'Br'),
+ ('GBP', 'British Pound Sterling', '£'),
+ ('GEL', 'Georgian Lari', 'GEL'),
+ ('GHS', 'Ghanaian Cedi', 'GH₵'),
+ ('GNF', 'Guinean Franc', 'FG'),
+ ('GTQ', 'Guatemalan Quetzal', 'GTQ'),
+ ('HKD', 'Hong Kong Dollar', 'HK$'),
+ ('HNL', 'Honduran Lempira', 'HNL'),
+ ('HRK', 'Croatian Kuna', 'kn'),
+ ('HUF', 'Hungarian Forint', 'Ft'),
+ ('IDR', 'Indonesian Rupiah', 'Rp'),
+ ('ILS', 'Israeli New Sheqel', '₪'),
+ ('INR', 'Indian Rupee', 'Rs'),
+ ('IQD', 'Iraqi Dinar', 'IQD'),
+ ('IRR', 'Iranian Rial', 'IRR'),
+ ('ISK', 'Icelandic Króna', 'Ikr'),
+ ('JMD', 'Jamaican Dollar', 'J$'),
+ ('JOD', 'Jordanian Dinar', 'JD'),
+ ('JPY', 'Japanese Yen', '¥'),
+ ('KES', 'Kenyan Shilling', 'Ksh'),
+ ('KHR', 'Cambodian Riel', 'KHR'),
+ ('KMF', 'Comorian Franc', 'CF'),
+ ('KRW', 'South Korean Won', '₩'),
+ ('KWD', 'Kuwaiti Dinar', 'KD'),
+ ('KZT', 'Kazakhstani Tenge', 'KZT'),
+ ('LBP', 'Lebanese Pound', 'L.L'),
+ ('LKR', 'Sri Lankan Rupee', 'SLRs'),
+ ('LTL', 'Lithuanian Litas', 'Lt'),
+ ('LVL', 'Latvian Lats', 'Ls'),
+ ('LYD', 'Libyan Dinar', 'LD'),
+ ('MAD', 'Moroccan Dirham', 'MAD'),
+ ('MDL', 'Moldovan Leu', 'MDL'),
+ ('MGA', 'Malagasy Ariary', 'MGA'),
+ ('MKD', 'Macedonian Denar', 'MKD'),
+ ('MMK', 'Myanma Kyat', 'MMK'),
+ ('MOP', 'Macanese Pataca', 'MOP$'),
+ ('MUR', 'Mauritian Rupee', 'MURs'),
+ ('MXN', 'Mexican Peso', 'MX$'),
+ ('MYR', 'Malaysian Ringgit', 'RM'),
+ ('MZN', 'Mozambican Metical', 'MTn'),
+ ('NAD', 'Namibian Dollar', 'N$'),
+ ('NGN', 'Nigerian Naira', '₦'),
+ ('NIO', 'Nicaraguan Córdoba', 'C$'),
+ ('NOK', 'Norwegian Krone', 'Nkr'),
+ ('NPR', 'Nepalese Rupee', 'NPRs'),
+ ('NZD', 'New Zealand Dollar', 'NZ$'),
+ ('OMR', 'Omani Rial', 'OMR'),
+ ('PAB', 'Panamanian Balboa', 'B/.'),
+ ('PEN', 'Peruvian Nuevo Sol', 'S/.'),
+ ('PHP', 'Philippine Peso', '₱'),
+ ('PKR', 'Pakistani Rupee', 'PKRs'),
+ ('PLN', 'Polish Zloty', 'zł'),
+ ('PYG', 'Paraguayan Guarani', '₲'),
+ ('QAR', 'Qatari Rial', 'QR'),
+ ('RON', 'Romanian Leu', 'RON'),
+ ('RSD', 'Serbian Dinar', 'din.'),
+ ('RUB', 'Russian Ruble', 'RUB'),
+ ('RWF', 'Rwandan Franc', 'RWF'),
+ ('SAR', 'Saudi Riyal', 'SR'),
+ ('SDG', 'Sudanese Pound', 'SDG'),
+ ('SEK', 'Swedish Krona', 'Skr'),
+ ('SGD', 'Singapore Dollar', 'S$'),
+ ('SOS', 'Somali Shilling', 'Ssh'),
+ ('SYP', 'Syrian Pound', 'SY£'),
+ ('THB', 'Thai Baht', '฿'),
+ ('TND', 'Tunisian Dinar', 'DT'),
+ ('TOP', 'Tongan Paʻanga', 'T$'),
+ ('TRY', 'Turkish Lira', 'TL'),
+ ('TTD', 'Trinidad and Tobago Dollar', 'TT$'),
+ ('TWD', 'New Taiwan Dollar', 'NT$'),
+ ('TZS', 'Tanzanian Shilling', 'TSh'),
+ ('UAH', 'Ukrainian Hryvnia', '₴'),
+ ('UGX', 'Ugandan Shilling', 'USh'),
+ ('UYU', 'Uruguayan Peso', '$U'),
+ ('UZS', 'Uzbekistan Som', 'UZS'),
+ ('VEF', 'Venezuelan Bolívar', 'Bs.F'),
+ ('VND', 'Vietnamese Dong', '₫'),
+ ('XAF', 'CFA Franc BEAC', 'FCFA'),
+ ('XOF', 'CFA Franc BCEAO', 'CFA'),
+ ('YER', 'Yemeni Rial', 'YR'),
+ ('ZAR', 'South African Rand', 'R'),
+ ('ZMK', 'Zambian Kwacha', 'ZK'),
+ ('ZWL', 'Zimbabwean Dollar', 'ZWL$');
+
+-- Add foreign key constraint
+ALTER TABLE "currency" ADD CONSTRAINT "currency_currencyCode_fkey"
+ FOREIGN KEY ("code") REFERENCES "currencyCode"("code")
+ ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- Drop the name and symbol columns from the currency table
+ALTER TABLE "currency" DROP COLUMN "name";
+ALTER TABLE "currency" DROP COLUMN "symbol";