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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: add country selector to addresses
Rob Carringtonb2ea281e7c8f
diff --git a/apps/carbon/app/components/Form/Country.tsx b/apps/carbon/app/components/Form/Country.tsxnew file mode 100644index 0000000000..053a78d011--- /dev/null+++ b/apps/carbon/app/components/Form/Country.tsx@@ -0,0 +1,36 @@+import { useMount } from "@carbon/react";+import { useFetcher } from "@remix-run/react";+import { Select } from "~/components/Form";+import type { getCountries } from "~/modules/shared";+import { path } from "~/utils/path";++const Country = () => {+ const options = useCountry();++ return (+ <>+ <Select name="countryCode" options={options} label="Country" />+ </>+ );+};++Country.displayName = "Country";++export default Country;++export const useCountry = () => {+ const countryFetcher = useFetcher<Awaited<ReturnType<typeof getCountries>>>();++ useMount(() => {+ countryFetcher.load(path.to.api.countries);+ });++ const countries = countryFetcher.data?.data ?? [];++ const options = countries.map((c) => ({+ value: c.alpha2,+ label: c.name,+ }));++ return options;+};diff --git a/apps/carbon/app/components/Location.tsx b/apps/carbon/app/components/Location.tsxindex 418a660a0d..7d8bbe86a6 100644--- a/apps/carbon/app/components/Location.tsx+++ b/apps/carbon/app/components/Location.tsx@@ -4,7 +4,7 @@ import {DropdownMenuItem,VStack,} from "@carbon/react";-import { formatAddressLines, formatCityStateZipCountry } from "@carbon/utils";+import { formatAddressLines, formatCityStatePostalCode } from "@carbon/utils";import { LuMapPin } from "react-icons/lu";import type { Action } from "~/types";@@ -17,6 +17,10 @@ type LocationProps = {city: string | null;state: string | null;postalCode: string | null;+ country: {+ alpha2: string;+ name: string;+ } | null;} | null;};actions: Action[];@@ -32,7 +36,7 @@ const Location = ({ location, actions }: LocationProps) => {location.address.addressLine1,location.address.addressLine2);- const cityStateZipCountry = formatCityStateZipCountry(+ const cityStatePostalCode = formatCityStatePostalCode(location.address.city,location.address.state,location.address.postalCode@@ -46,8 +50,13 @@ const Location = ({ location, actions }: LocationProps) => {{addressLines}</p><p className="text-sm text-muted-foreground line-clamp-1">- {cityStateZipCountry}+ {cityStatePostalCode}</p>+ {location.address.country && (+ <p className="text-sm text-muted-foreground line-clamp-1">+ {location.address.country.name}+ </p>+ )}</VStack>{actions.length > 0 && (<ActionMenu>diff --git a/apps/carbon/app/modules/purchasing/purchasing.service.ts b/apps/carbon/app/modules/purchasing/purchasing.service.tsindex e034035362..afa017304e 100644--- a/apps/carbon/app/modules/purchasing/purchasing.service.ts+++ b/apps/carbon/app/modules/purchasing/purchasing.service.ts@@ -283,7 +283,7 @@ export async function getSupplierLocations(return client.from("supplierLocation").select(- "*, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"+ "*, address(id, addressLine1, addressLine2, city, state, country(alpha2, name), postalCode)").eq("supplierId", supplierId);}@@ -295,7 +295,7 @@ export async function getSupplierLocation(return client.from("supplierLocation").select(- "*, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"+ "*, address(id, addressLine1, addressLine2, city, state, country(alpha2, name), postalCode)").eq("id", supplierContactId).single();diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocationForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocationForm.tsxindex 7f61a113ce..339ef7edb8 100644--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocationForm.tsx+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocationForm.tsx@@ -18,6 +18,7 @@ import type { PostgrestResponse } from "@supabase/supabase-js";import { useEffect } from "react";import type { z } from "zod";import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";+import Country from "~/components/Form/Country";import { usePermissions } from "~/hooks";import { supplierLocationValidator } from "~/modules/purchasing";import { path } from "~/utils/path";@@ -95,7 +96,7 @@ const SupplierLocationForm = ({<Input name="city" label="City" /><Input name="state" label="State" /><Input name="postalCode" label="Zip Code" />- {/* Country dropdown */}+ <Country /><CustomFormFields table="supplierLocation" /></VStack></ModalDrawerBody>diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex 05dee449f0..285ce04af4 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -224,7 +224,7 @@ export async function getCustomerLocation(return client.from("customerLocation").select(- "*, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"+ "*, address(id, addressLine1, addressLine2, city, state, country(alpha2, name), postalCode)").eq("id", customerContactId).single();@@ -237,7 +237,7 @@ export async function getCustomerLocations(return client.from("customerLocation").select(- "*, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"+ "*, address(id, addressLine1, addressLine2, city, state, country(alpha2, name), postalCode)").eq("customerId", customerId);}diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerLocationForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerLocationForm.tsxindex e166cdb1fe..03f83c6445 100644--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerLocationForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerLocationForm.tsx@@ -15,6 +15,7 @@ import { ValidatedForm } from "@carbon/form";import { useFetcher } from "@remix-run/react";import type { z } from "zod";import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";+import Country from "~/components/Form/Country";import { usePermissions } from "~/hooks";import { customerLocationValidator } from "~/modules/sales";import { path } from "~/utils/path";@@ -83,8 +84,8 @@ const CustomerLocationForm = ({<Input name="addressLine2" label="Address Line 2" /><Input name="city" label="City" /><Input name="state" label="State" />- <Input name="postalCode" label="Zip Code" />- {/* Country dropdown */}+ <Input name="postalCode" label="Postal Code" />+ <Country /><CustomFormFields table="customerLocation" /></VStack></ModalDrawerBody>diff --git a/apps/carbon/app/modules/shared/shared.service.ts b/apps/carbon/app/modules/shared/shared.service.tsindex 6eb402ae80..eed6fbf0a5 100644--- a/apps/carbon/app/modules/shared/shared.service.ts+++ b/apps/carbon/app/modules/shared/shared.service.ts@@ -27,6 +27,10 @@ export async function getBase64ImageFromSupabase(return `data:image/png;base64,${base64String}`;}+export async function getCountries(client: SupabaseClient<Database>) {+ return client.from("country").select("*").order("name");+}+export async function getNotes(client: SupabaseClient<Database>,documentId: stringdiff --git a/apps/carbon/app/routes/api+/countries.ts b/apps/carbon/app/routes/api+/countries.tsnew file mode 100644index 0000000000..63384fccd9--- /dev/null+++ b/apps/carbon/app/routes/api+/countries.ts@@ -0,0 +1,10 @@+import { requirePermissions } from "@carbon/auth/auth.server";+import type { LoaderFunctionArgs } from "@vercel/remix";+import { json } from "@vercel/remix";+import { getCountries } from "~/modules/shared";++export async function loader({ request }: LoaderFunctionArgs) {+ const { client } = await requirePermissions(request, {});++ return json(await getCountries(client));+}diff --git a/apps/carbon/app/routes/onboarding+/company.tsx b/apps/carbon/app/routes/onboarding+/company.tsxindex 8a353eacac..cb4a34f27d 100644--- a/apps/carbon/app/routes/onboarding+/company.tsx+++ b/apps/carbon/app/routes/onboarding+/company.tsx@@ -17,6 +17,7 @@ import { getLocalTimeZone } from "@internationalized/date";import { Link, useLoaderData } from "@remix-run/react";import { json, redirect, type ActionFunctionArgs } from "@vercel/remix";import { Hidden, Input, Submit } from "~/components/Form";+import Country from "~/components/Form/Country";import { useOnboarding } from "~/hooks";import { insertEmployeeJob } from "~/modules/people";import { getLocationsList, upsertLocation } from "~/modules/resources";@@ -164,6 +165,7 @@ export default function OnboardingCompany() {city: company?.city ?? "",state: company?.state ?? "",postalCode: company?.postalCode ?? "",+ countryCode: company?.countryCode ?? "",};return (@@ -174,7 +176,7 @@ export default function OnboardingCompany() {method="post"><CardHeader>- <CardTitle>Now let's setup your company</CardTitle>+ <CardTitle>Now let's set up your company</CardTitle><CardDescription>You can always change this later</CardDescription></CardHeader><CardContent>@@ -185,6 +187,7 @@ export default function OnboardingCompany() {<Input name="city" label="City" /><Input name="state" label="State" /><Input name="postalCode" label="Zip Code" />+ <Country /></VStack></CardContent>diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsxindex e7440dc3b3..8aa7683f75 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx@@ -108,6 +108,7 @@ export default function EditCustomerLocationRoute() {city: location?.address?.city ?? "",state: location?.address?.state ?? "",postalCode: location?.address?.postalCode ?? "",+ countryCode: location?.address?.country?.alpha2 ?? "",...getCustomFields(location?.customFields),};diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsxindex 8256ae57f4..e3479f1c37 100644--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx@@ -108,6 +108,7 @@ export default function EditSupplierLocationRoute() {city: location?.address?.city ?? "",state: location?.address?.state ?? "",postalCode: location?.address?.postalCode ?? "",+ countryCode: location?.address?.country?.alpha2 ?? "",...getCustomFields(location?.customFields),};diff --git a/apps/carbon/app/types/validators.ts b/apps/carbon/app/types/validators.tsindex 38e8bd1bee..9f8e25bf3d 100644--- a/apps/carbon/app/types/validators.ts+++ b/apps/carbon/app/types/validators.ts@@ -17,7 +17,7 @@ export const address = {city: zfd.text(z.string().optional()),state: zfd.text(z.string().optional()),postalCode: zfd.text(z.string().optional()),- countryId: zfd.numeric(z.number().optional()),+ countryCode: zfd.text(z.string().optional()),phone: zfd.text(z.string().optional()),fax: zfd.text(z.string().optional()),};diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 339c687ba1..11fbfaabfc 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -17,6 +17,7 @@ export const path = {assign: `${api}/assign`,autodeskToken: `${api}/autodesk/token`,autodeskUpload: `${api}/autodesk/upload`,+ countries: `${api}/countries`,currencies: `${api}/accounting/currencies`,customerContacts: (id: string) =>generatePath(`${api}/sales/customer-contacts?customerId=${id}`),diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.tsindex f9a3f6204c..c76552bffb 100644--- a/packages/database/src/swagger-docs-schema.ts+++ b/packages/database/src/swagger-docs-schema.ts@@ -3,7 +3,7 @@ export default {info: {description: "",title: "standard public schema",- version: "12.0.2 (a4e00ff)",+ version: "12.0.1 (cd38da5)",},host: "0.0.0.0:3000",basePath: "/",@@ -4677,6 +4677,9 @@ export default {{$ref: "#/parameters/rowFilter.jobOperation.quantityScrapped",},+ {+ $ref: "#/parameters/rowFilter.jobOperation.quantityReworked",+ },{$ref: "#/parameters/rowFilter.jobOperation.status",},@@ -4835,6 +4838,9 @@ export default {{$ref: "#/parameters/rowFilter.jobOperation.quantityScrapped",},+ {+ $ref: "#/parameters/rowFilter.jobOperation.quantityReworked",+ },{$ref: "#/parameters/rowFilter.jobOperation.status",},@@ -4947,6 +4953,9 @@ export default {{$ref: "#/parameters/rowFilter.jobOperation.quantityScrapped",},+ {+ $ref: "#/parameters/rowFilter.jobOperation.quantityReworked",+ },{$ref: "#/parameters/rowFilter.jobOperation.status",},@@ -6531,6 +6540,9 @@ export default {{$ref: "#/parameters/rowFilter.jobOperationsWithMakeMethods.quantityScrapped",},+ {+ $ref: "#/parameters/rowFilter.jobOperationsWithMakeMethods.quantityReworked",+ },{$ref: "#/parameters/rowFilter.jobOperationsWithMakeMethods.status",},@@ -9589,13 +9601,13 @@ export default {get: {parameters: [{- $ref: "#/parameters/rowFilter.country.id",+ $ref: "#/parameters/rowFilter.country.name",},{- $ref: "#/parameters/rowFilter.country.name",+ $ref: "#/parameters/rowFilter.country.alpha2",},{- $ref: "#/parameters/rowFilter.country.code",+ $ref: "#/parameters/rowFilter.country.alpha3",},{$ref: "#/parameters/select",@@ -9657,13 +9669,13 @@ export default {delete: {parameters: [{- $ref: "#/parameters/rowFilter.country.id",+ $ref: "#/parameters/rowFilter.country.name",},{- $ref: "#/parameters/rowFilter.country.name",+ $ref: "#/parameters/rowFilter.country.alpha2",},{- $ref: "#/parameters/rowFilter.country.code",+ $ref: "#/parameters/rowFilter.country.alpha3",},{$ref: "#/parameters/preferReturn",@@ -9679,13 +9691,13 @@ export default {patch: {parameters: [{- $ref: "#/parameters/rowFilter.country.id",+ $ref: "#/parameters/rowFilter.country.name",},{- $ref: "#/parameters/rowFilter.country.name",+ $ref: "#/parameters/rowFilter.country.alpha2",},{- $ref: "#/parameters/rowFilter.country.code",+ $ref: "#/parameters/rowFilter.country.alpha3",},{$ref: "#/parameters/body.country",@@ -31074,6 +31086,213 @@ export default {tags: ["currency"],},},+ "/productionEvent": {+ get: {+ parameters: [+ {+ $ref: "#/parameters/rowFilter.productionEvent.id",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.jobOperationId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.type",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.startTime",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.endTime",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.duration",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.employeeId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.workCenterId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.companyId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.createdAt",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.createdBy",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.updatedAt",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.updatedBy",+ },+ {+ $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/productionEvent",+ },+ type: "array",+ },+ },+ "206": {+ description: "Partial Content",+ },+ },+ tags: ["productionEvent"],+ },+ post: {+ parameters: [+ {+ $ref: "#/parameters/body.productionEvent",+ },+ {+ $ref: "#/parameters/select",+ },+ {+ $ref: "#/parameters/preferPost",+ },+ ],+ responses: {+ "201": {+ description: "Created",+ },+ },+ tags: ["productionEvent"],+ },+ delete: {+ parameters: [+ {+ $ref: "#/parameters/rowFilter.productionEvent.id",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.jobOperationId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.type",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.startTime",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.endTime",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.duration",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.employeeId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.workCenterId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.companyId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.createdAt",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.createdBy",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.updatedAt",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.updatedBy",+ },+ {+ $ref: "#/parameters/preferReturn",+ },+ ],+ responses: {+ "204": {+ description: "No Content",+ },+ },+ tags: ["productionEvent"],+ },+ patch: {+ parameters: [+ {+ $ref: "#/parameters/rowFilter.productionEvent.id",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.jobOperationId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.type",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.startTime",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.endTime",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.duration",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.employeeId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.workCenterId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.companyId",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.createdAt",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.createdBy",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.updatedAt",+ },+ {+ $ref: "#/parameters/rowFilter.productionEvent.updatedBy",+ },+ {+ $ref: "#/parameters/body.productionEvent",+ },+ {+ $ref: "#/parameters/preferReturn",+ },+ ],+ responses: {+ "204": {+ description: "No Content",+ },+ },+ tags: ["productionEvent"],+ },+ },"/accounts": {get: {parameters: [@@ -33819,6 +34038,63 @@ export default {tags: ["(rpc) has_any_company_permission"],},},+ "/rpc/get_job_operation_by_id": {+ get: {+ parameters: [+ {+ format: "text",+ in: "query",+ name: "operation_id",+ required: true,+ type: "string",+ },+ ],+ produces: [+ "application/json",+ "application/vnd.pgrst.object+json;nulls=stripped",+ "application/vnd.pgrst.object+json",+ ],+ responses: {+ "200": {+ description: "OK",+ },+ },+ tags: ["(rpc) get_job_operation_by_id"],+ },+ post: {+ parameters: [+ {+ in: "body",+ name: "args",+ required: true,+ schema: {+ properties: {+ operation_id: {+ format: "text",+ type: "string",+ },+ },+ required: ["operation_id"],+ type: "object",+ },+ },+ {+ $ref: "#/parameters/preferParams",+ },+ ],+ produces: [+ "application/json",+ "application/vnd.pgrst.object+json;nulls=stripped",+ "application/vnd.pgrst.object+json",+ ],+ responses: {+ "200": {+ description: "OK",+ },+ },+ tags: ["(rpc) get_job_operation_by_id"],+ },+ },"/rpc/_xid_machine_id": {get: {produces: [@@ -33977,6 +34253,74 @@ export default {tags: ["(rpc) xid_encode"],},},+ "/rpc/get_active_job_operations_by_employee": {+ get: {+ parameters: [+ {+ format: "text",+ in: "query",+ name: "employee_id",+ required: true,+ type: "string",+ },+ {+ format: "text",+ in: "query",+ name: "company_id",+ required: true,+ type: "string",+ },+ ],+ produces: [+ "application/json",+ "application/vnd.pgrst.object+json;nulls=stripped",+ "application/vnd.pgrst.object+json",+ ],+ responses: {+ "200": {+ description: "OK",+ },+ },+ tags: ["(rpc) get_active_job_operations_by_employee"],+ },+ post: {+ parameters: [+ {+ in: "body",+ name: "args",+ required: true,+ schema: {+ properties: {+ company_id: {+ format: "text",+ type: "string",+ },+ employee_id: {+ format: "text",+ type: "string",+ },+ },+ required: ["employee_id", "company_id"],+ type: "object",+ },+ },+ {+ $ref: "#/parameters/preferParams",+ },+ ],+ produces: [+ "application/json",+ "application/vnd.pgrst.object+json;nulls=stripped",+ "application/vnd.pgrst.object+json",+ ],+ responses: {+ "200": {+ description: "OK",+ },+ },+ tags: ["(rpc) get_active_job_operations_by_employee"],+ },+ },"/rpc/groups_query": {get: {parameters: [@@ -35071,6 +35415,74 @@ export default {tags: ["(rpc) get_method_tree"],},},+ "/rpc/get_active_job_count": {+ get: {+ parameters: [+ {+ format: "text",+ in: "query",+ name: "employee_id",+ required: true,+ type: "string",+ },+ {+ format: "text",+ in: "query",+ name: "company_id",+ required: true,+ type: "string",+ },+ ],+ produces: [+ "application/json",+ "application/vnd.pgrst.object+json;nulls=stripped",+ "application/vnd.pgrst.object+json",+ ],+ responses: {+ "200": {+ description: "OK",+ },+ },+ tags: ["(rpc) get_active_job_count"],+ },+ post: {+ parameters: [+ {+ in: "body",+ name: "args",+ required: true,+ schema: {+ properties: {+ company_id: {+ format: "text",+ type: "string",+ },+ employee_id: {+ format: "text",+ type: "string",+ },+ },+ required: ["employee_id", "company_id"],+ type: "object",+ },+ },+ {+ $ref: "#/parameters/preferParams",+ },+ ],+ produces: [+ "application/json",+ "application/vnd.pgrst.object+json;nulls=stripped",+ "application/vnd.pgrst.object+json",+ ],+ responses: {+ "200": {+ description: "OK",+ },+ },+ tags: ["(rpc) get_active_job_count"],+ },+ },"/rpc/users_for_groups": {get: {parameters: [@@ -35131,6 +35543,74 @@ export default {tags: ["(rpc) users_for_groups"],},},+ "/rpc/get_recent_job_operations_by_employee": {+ get: {+ parameters: [+ {+ format: "text",+ in: "query",+ name: "employee_id",+ required: true,+ type: "string",+ },+ {+ format: "text",+ in: "query",+ name: "company_id",+ required: true,+ type: "string",+ },+ ],+ produces: [+ "application/json",+ "application/vnd.pgrst.object+json;nulls=stripped",+ "application/vnd.pgrst.object+json",+ ],+ responses: {+ "200": {+ description: "OK",+ },+ },+ tags: ["(rpc) get_recent_job_operations_by_employee"],+ },+ post: {+ parameters: [+ {+ in: "body",+ name: "args",+ required: true,+ schema: {+ properties: {+ company_id: {+ format: "text",+ type: "string",+ },+ employee_id: {+ format: "text",+ type: "string",+ },+ },+ required: ["employee_id", "company_id"],+ type: "object",+ },+ },+ {+ $ref: "#/parameters/preferParams",+ },+ ],+ produces: [+ "application/json",+ "application/vnd.pgrst.object+json;nulls=stripped",+ "application/vnd.pgrst.object+json",+ ],+ responses: {+ "200": {+ description: "OK",+ },+ },+ tags: ["(rpc) get_recent_job_operations_by_employee"],+ },+ },},definitions: {purchaseInvoiceStatusHistory: {@@ -37281,6 +37761,11 @@ export default {format: "numeric",type: "number",},+ quantityReworked: {+ default: 0,+ format: "numeric",+ type: "number",+ },status: {default: "Todo",enum: [@@ -38135,6 +38620,10 @@ export default {format: "numeric",type: "number",},+ quantityReworked: {+ format: "numeric",+ type: "number",+ },status: {enum: ["Canceled",@@ -39527,19 +40016,21 @@ export default {type: "object",},country: {- required: ["id", "name", "code"],+ required: ["name", "alpha2", "alpha3"],properties: {- id: {- description: "Note:\nThis is a Primary Key.<pk/>",- format: "integer",- type: "integer",- },name: {format: "text",type: "string",},- code: {- format: "text",+ alpha2: {+ description: "Note:\nThis is a Primary Key.<pk/>",+ format: "character",+ maxLength: 2,+ type: "string",+ },+ alpha3: {+ format: "character",+ maxLength: 3,type: "string",},},@@ -41055,9 +41546,9 @@ export default {},supplierCountryCode: {description:- "Note:\nThis is a Foreign Key to `country.id`.<fk table='country' column='id'/>",- format: "integer",- type: "integer",+ "Note:\nThis is a Foreign Key to `country.alpha2`.<fk table='country' column='alpha2'/>",+ format: "text",+ type: "string",},deliveryName: {format: "text",@@ -41117,9 +41608,9 @@ export default {},customerCountryCode: {description:- "Note:\nThis is a Foreign Key to `country.id`.<fk table='country' column='id'/>",- format: "integer",- type: "integer",+ "Note:\nThis is a Foreign Key to `country.alpha2`.<fk table='country' column='alpha2'/>",+ format: "text",+ type: "string",},},type: "object",@@ -44074,9 +44565,9 @@ export default {},customerCountryCode: {description:- "Note:\nThis is a Foreign Key to `country.id`.<fk table='country' column='id'/>",- format: "integer",- type: "integer",+ "Note:\nThis is a Foreign Key to `country.alpha2`.<fk table='country' column='alpha2'/>",+ format: "text",+ type: "string",},},type: "object",@@ -46057,7 +46548,7 @@ export default {properties: {id: {description:- "Note:\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",+ "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",format: "text",type: "string",},@@ -46106,7 +46597,7 @@ export default {},supplierLocationId: {description:- "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",+ "Note:\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",format: "text",type: "string",},@@ -47310,9 +47801,9 @@ export default {},countryCode: {description:- "Note:\nThis is a Foreign Key to `country.id`.<fk table='country' column='id'/>",- format: "integer",- type: "integer",+ "Note:\nThis is a Foreign Key to `country.alpha2`.<fk table='country' column='alpha2'/>",+ format: "text",+ type: "string",},phone: {format: "text",@@ -48016,9 +48507,9 @@ export default {},customerCountryCode: {description:- "Note:\nThis is a Foreign Key to `country.id`.<fk table='country' column='id'/>",- format: "integer",- type: "integer",+ "Note:\nThis is a Foreign Key to `country.alpha2`.<fk table='country' column='alpha2'/>",+ format: "text",+ type: "string",},paymentCustomerName: {format: "text",@@ -48046,9 +48537,9 @@ export default {},paymentCountryCode: {description:- "Note:\nThis is a Foreign Key to `country.id`.<fk table='country' column='id'/>",- format: "integer",- type: "integer",+ "Note:\nThis is a Foreign Key to `country.alpha2`.<fk table='country' column='alpha2'/>",+ format: "text",+ type: "string",},},type: "object",@@ -49420,6 +49911,88 @@ export default {},type: "object",},+ productionEvent: {+ required: [+ "id",+ "jobOperationId",+ "startTime",+ "companyId",+ "createdAt",+ "createdBy",+ ],+ properties: {+ id: {+ default: "public.xid()",+ description: "Note:\nThis is a Primary Key.<pk/>",+ format: "text",+ type: "string",+ },+ jobOperationId: {+ description:+ "Note:\nThis is a Foreign Key to `jobOperation.id`.<fk table='jobOperation' column='id'/>",+ format: "text",+ type: "string",+ },+ type: {+ enum: ["Setup", "Labor", "Machine"],+ format: 'public."productionEventType"',+ type: "string",+ },+ startTime: {+ default: "now()",+ format: "timestamp with time zone",+ type: "string",+ },+ endTime: {+ format: "timestamp with time zone",+ type: "string",+ },+ duration: {+ format: "integer",+ type: "integer",+ },+ employeeId: {+ description:+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",+ format: "text",+ type: "string",+ },+ workCenterId: {+ description:+ "Note:\nThis is a Foreign Key to `workCenter.id`.<fk table='workCenter' column='id'/>",+ format: "text",+ type: "string",+ },+ companyId: {+ description:+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",+ format: "text",+ type: "string",+ },+ createdAt: {+ default: "now()",+ format: "timestamp with time zone",+ type: "string",+ },+ createdBy: {+ description:+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",+ format: "text",+ type: "string",+ },+ updatedAt: {+ format: "timestamp with time zone",+ type: "string",+ },+ updatedBy: {+ description:+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",+ format: "text",+ type: "string",+ },+ },+ type: "object",+ },accounts: {properties: {id: {@@ -53175,6 +53748,13 @@ export default {in: "query",type: "string",},+ "rowFilter.jobOperation.quantityReworked": {+ name: "quantityReworked",+ required: false,+ format: "numeric",+ in: "query",+ type: "string",+ },"rowFilter.jobOperation.status": {name: "status",required: false,@@ -54264,6 +54844,13 @@ export default {in: "query",type: "string",},+ "rowFilter.jobOperationsWithMakeMethods.quantityReworked": {+ name: "quantityReworked",+ required: false,+ format: "numeric",+ in: "query",+ type: "string",+ },"rowFilter.jobOperationsWithMakeMethods.status": {name: "status",required: false,@@ -56061,24 +56648,24 @@ export default {$ref: "#/definitions/country",},},- "rowFilter.country.id": {- name: "id",+ "rowFilter.country.name": {+ name: "name",required: false,- format: "integer",+ format: "text",in: "query",type: "string",},- "rowFilter.country.name": {- name: "name",+ "rowFilter.country.alpha2": {+ name: "alpha2",required: false,- format: "text",+ format: "character",in: "query",type: "string",},- "rowFilter.country.code": {- name: "code",+ "rowFilter.country.alpha3": {+ name: "alpha3",required: false,- format: "text",+ format: "character",in: "query",type: "string",},@@ -58057,7 +58644,7 @@ export default {"rowFilter.purchaseOrderLocations.supplierCountryCode": {name: "supplierCountryCode",required: false,- format: "integer",+ format: "text",in: "query",type: "string",},@@ -58162,7 +58749,7 @@ export default {"rowFilter.purchaseOrderLocations.customerCountryCode": {name: "customerCountryCode",required: false,- format: "integer",+ format: "text",in: "query",type: "string",},@@ -62009,7 +62596,7 @@ export default {"rowFilter.quoteCustomerDetails.customerCountryCode": {name: "customerCountryCode",required: false,- format: "integer",+ format: "text",in: "query",type: "string",},@@ -66238,7 +66825,7 @@ export default {"rowFilter.address.countryCode": {name: "countryCode",required: false,- format: "integer",+ format: "text",in: "query",type: "string",},@@ -67149,7 +67736,7 @@ export default {"rowFilter.salesOrderLocations.customerCountryCode": {name: "customerCountryCode",required: false,- format: "integer",+ format: "text",in: "query",type: "string",},@@ -67198,7 +67785,7 @@ export default {"rowFilter.salesOrderLocations.paymentCountryCode": {name: "paymentCountryCode",required: false,- format: "integer",+ format: "text",in: "query",type: "string",},@@ -69031,6 +69618,106 @@ export default {in: "query",type: "string",},+ "body.productionEvent": {+ name: "productionEvent",+ description: "productionEvent",+ required: false,+ in: "body",+ schema: {+ $ref: "#/definitions/productionEvent",+ },+ },+ "rowFilter.productionEvent.id": {+ name: "id",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.jobOperationId": {+ name: "jobOperationId",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.type": {+ name: "type",+ required: false,+ format: 'public."productionEventType"',+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.startTime": {+ name: "startTime",+ required: false,+ format: "timestamp with time zone",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.endTime": {+ name: "endTime",+ required: false,+ format: "timestamp with time zone",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.duration": {+ name: "duration",+ required: false,+ format: "integer",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.employeeId": {+ name: "employeeId",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.workCenterId": {+ name: "workCenterId",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.companyId": {+ name: "companyId",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.createdAt": {+ name: "createdAt",+ required: false,+ format: "timestamp with time zone",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.createdBy": {+ name: "createdBy",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.updatedAt": {+ name: "updatedAt",+ required: false,+ format: "timestamp with time zone",+ in: "query",+ type: "string",+ },+ "rowFilter.productionEvent.updatedBy": {+ name: "updatedBy",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },"body.accounts": {name: "accounts",description: "accounts",diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex b7cb88e759..557713d467 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -1520,7 +1520,7 @@ export type Database = {addressLine2: string | nullcity: string | nullcompanyId: string- countryCode: number | null+ countryCode: string | nullfax: string | nullid: stringphone: string | null@@ -1532,7 +1532,7 @@ export type Database = {addressLine2?: string | nullcity?: string | nullcompanyId: string- countryCode?: number | null+ countryCode?: string | nullfax?: string | nullid?: stringphone?: string | null@@ -1544,7 +1544,7 @@ export type Database = {addressLine2?: string | nullcity?: string | nullcompanyId?: string- countryCode?: number | null+ countryCode?: string | nullfax?: string | nullid?: stringphone?: string | null@@ -1585,7 +1585,7 @@ export type Database = {columns: ["countryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},]}@@ -2636,18 +2636,18 @@ export type Database = {}country: {Row: {- code: string- id: number+ alpha2: string+ alpha3: stringname: string}Insert: {- code: string- id?: number+ alpha2: string+ alpha3: stringname: string}Update: {- code?: string- id?: number+ alpha2?: string+ alpha3?: stringname?: string}Relationships: []@@ -11503,7 +11503,8 @@ export type Database = {startTime: stringtype: Database["public"]["Enums"]["productionEventType"] | nullupdatedAt: string | null- updatedBy: string+ updatedBy: string | null+ workCenterId: string | null}Insert: {companyId: string@@ -11514,10 +11515,11 @@ export type Database = {endTime?: string | nullid?: stringjobOperationId: string- startTime: string+ startTime?: stringtype?: Database["public"]["Enums"]["productionEventType"] | nullupdatedAt?: string | null- updatedBy: string+ updatedBy?: string | null+ workCenterId?: string | null}Update: {companyId?: string@@ -11531,7 +11533,8 @@ export type Database = {startTime?: stringtype?: Database["public"]["Enums"]["productionEventType"] | nullupdatedAt?: string | null- updatedBy?: string+ updatedBy?: string | null+ workCenterId?: string | null}Relationships: [{@@ -11681,6 +11684,20 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "productionEvent_workCenterId_fkey"+ columns: ["workCenterId"]+ isOneToOne: false+ referencedRelation: "workCenter"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "productionEvent_workCenterId_fkey"+ columns: ["workCenterId"]+ isOneToOne: false+ referencedRelation: "workCenters"+ referencedColumns: ["id"]+ },]}purchaseInvoice: {@@ -23586,6 +23603,7 @@ export type Database = {overheadRate: number | nullprocessId: string | nullquantityComplete: number | null+ quantityReworked: number | nullquantityScrapped: number | nullsetupTime: number | nullsetupUnit: Database["public"]["Enums"]["factor"] | null@@ -25229,7 +25247,7 @@ export type Database = {customerAddressLine1: string | nullcustomerAddressLine2: string | nullcustomerCity: string | null- customerCountryCode: number | null+ customerCountryCode: string | nullcustomerName: string | nullcustomerPostalCode: string | nullcustomerState: string | null@@ -25245,7 +25263,7 @@ export type Database = {supplierAddressLine1: string | nullsupplierAddressLine2: string | nullsupplierCity: string | null- supplierCountryCode: number | null+ supplierCountryCode: string | nullsupplierName: string | nullsupplierPostalCode: string | nullsupplierState: string | null@@ -25253,17 +25271,17 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["supplierCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["supplierCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},]}@@ -25561,7 +25579,7 @@ export type Database = {customerAddressLine1: string | nullcustomerAddressLine2: string | nullcustomerCity: string | null- customerCountryCode: number | null+ customerCountryCode: string | nullcustomerName: string | nullcustomerPostalCode: string | nullcustomerState: string | null@@ -25573,7 +25591,7 @@ export type Database = {columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},]}@@ -26971,7 +26989,7 @@ export type Database = {customerAddressLine1: string | nullcustomerAddressLine2: string | nullcustomerCity: string | null- customerCountryCode: number | null+ customerCountryCode: string | nullcustomerName: string | nullcustomerPostalCode: string | nullcustomerState: string | null@@ -26979,7 +26997,7 @@ export type Database = {paymentAddressLine1: string | nullpaymentAddressLine2: string | nullpaymentCity: string | null- paymentCountryCode: number | null+ paymentCountryCode: string | nullpaymentCustomerName: string | nullpaymentPostalCode: string | nullpaymentState: string | null@@ -26990,14 +27008,14 @@ export type Database = {columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},]}diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex b7cb88e759..557713d467 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -1520,7 +1520,7 @@ export type Database = {addressLine2: string | nullcity: string | nullcompanyId: string- countryCode: number | null+ countryCode: string | nullfax: string | nullid: stringphone: string | null@@ -1532,7 +1532,7 @@ export type Database = {addressLine2?: string | nullcity?: string | nullcompanyId: string- countryCode?: number | null+ countryCode?: string | nullfax?: string | nullid?: stringphone?: string | null@@ -1544,7 +1544,7 @@ export type Database = {addressLine2?: string | nullcity?: string | nullcompanyId?: string- countryCode?: number | null+ countryCode?: string | nullfax?: string | nullid?: stringphone?: string | null@@ -1585,7 +1585,7 @@ export type Database = {columns: ["countryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},]}@@ -2636,18 +2636,18 @@ export type Database = {}country: {Row: {- code: string- id: number+ alpha2: string+ alpha3: stringname: string}Insert: {- code: string- id?: number+ alpha2: string+ alpha3: stringname: string}Update: {- code?: string- id?: number+ alpha2?: string+ alpha3?: stringname?: string}Relationships: []@@ -11503,7 +11503,8 @@ export type Database = {startTime: stringtype: Database["public"]["Enums"]["productionEventType"] | nullupdatedAt: string | null- updatedBy: string+ updatedBy: string | null+ workCenterId: string | null}Insert: {companyId: string@@ -11514,10 +11515,11 @@ export type Database = {endTime?: string | nullid?: stringjobOperationId: string- startTime: string+ startTime?: stringtype?: Database["public"]["Enums"]["productionEventType"] | nullupdatedAt?: string | null- updatedBy: string+ updatedBy?: string | null+ workCenterId?: string | null}Update: {companyId?: string@@ -11531,7 +11533,8 @@ export type Database = {startTime?: stringtype?: Database["public"]["Enums"]["productionEventType"] | nullupdatedAt?: string | null- updatedBy?: string+ updatedBy?: string | null+ workCenterId?: string | null}Relationships: [{@@ -11681,6 +11684,20 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "productionEvent_workCenterId_fkey"+ columns: ["workCenterId"]+ isOneToOne: false+ referencedRelation: "workCenter"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "productionEvent_workCenterId_fkey"+ columns: ["workCenterId"]+ isOneToOne: false+ referencedRelation: "workCenters"+ referencedColumns: ["id"]+ },]}purchaseInvoice: {@@ -23586,6 +23603,7 @@ export type Database = {overheadRate: number | nullprocessId: string | nullquantityComplete: number | null+ quantityReworked: number | nullquantityScrapped: number | nullsetupTime: number | nullsetupUnit: Database["public"]["Enums"]["factor"] | null@@ -25229,7 +25247,7 @@ export type Database = {customerAddressLine1: string | nullcustomerAddressLine2: string | nullcustomerCity: string | null- customerCountryCode: number | null+ customerCountryCode: string | nullcustomerName: string | nullcustomerPostalCode: string | nullcustomerState: string | null@@ -25245,7 +25263,7 @@ export type Database = {supplierAddressLine1: string | nullsupplierAddressLine2: string | nullsupplierCity: string | null- supplierCountryCode: number | null+ supplierCountryCode: string | nullsupplierName: string | nullsupplierPostalCode: string | nullsupplierState: string | null@@ -25253,17 +25271,17 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["supplierCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["supplierCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},]}@@ -25561,7 +25579,7 @@ export type Database = {customerAddressLine1: string | nullcustomerAddressLine2: string | nullcustomerCity: string | null- customerCountryCode: number | null+ customerCountryCode: string | nullcustomerName: string | nullcustomerPostalCode: string | nullcustomerState: string | null@@ -25573,7 +25591,7 @@ export type Database = {columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},]}@@ -26971,7 +26989,7 @@ export type Database = {customerAddressLine1: string | nullcustomerAddressLine2: string | nullcustomerCity: string | null- customerCountryCode: number | null+ customerCountryCode: string | nullcustomerName: string | nullcustomerPostalCode: string | nullcustomerState: string | null@@ -26979,7 +26997,7 @@ export type Database = {paymentAddressLine1: string | nullpaymentAddressLine2: string | nullpaymentCity: string | null- paymentCountryCode: number | null+ paymentCountryCode: string | nullpaymentCustomerName: string | nullpaymentPostalCode: string | nullpaymentState: string | null@@ -26990,14 +27008,14 @@ export type Database = {columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"- referencedColumns: ["id"]+ referencedColumns: ["alpha2"]},]}diff --git a/packages/database/supabase/migrations/20240928155702_country-codes.sql b/packages/database/supabase/migrations/20240928155702_country-codes.sqlnew file mode 100644index 0000000000..d6368fe302--- /dev/null+++ b/packages/database/supabase/migrations/20240928155702_country-codes.sql@@ -0,0 +1,321 @@+-- Change the primary key of the 'country' table to 'alpha2'++-- Drop the views that reference the address table's countryCode column+DROP VIEW IF EXISTS "purchaseOrderLocations";+DROP VIEW IF EXISTS "quoteCustomerDetails";+DROP VIEW IF EXISTS "salesOrderLocations";++-- Remove the 'code' column+ALTER TABLE "country" DROP COLUMN IF EXISTS "code";++-- Add 'alpha2' and 'alpha3' columns+ALTER TABLE "country" ADD COLUMN "alpha2" CHAR(2);+ALTER TABLE "country" ADD COLUMN "alpha3" CHAR(3);++-- Add the new primary key constraint on the 'alpha2' column and update the address table accordingly+ALTER TABLE "address" DROP CONSTRAINT IF EXISTS "address_countryCode_fkey";+ALTER TABLE "country" DROP CONSTRAINT IF EXISTS "country_pkey";+ALTER TABLE "country" ADD PRIMARY KEY ("alpha2");+ALTER TABLE "country" DROP COLUMN IF EXISTS "id";+UPDATE "address" SET "countryCode" = NULL;+ALTER TABLE "address" ALTER COLUMN "countryCode" TYPE TEXT;+ALTER TABLE "address" ADD CONSTRAINT "address_countryCode_fkey" FOREIGN KEY ("countryCode") REFERENCES "country"("alpha2") ON DELETE SET NULL ON UPDATE CASCADE;++-- Make 'alpha3' NOT NULL and add a unique constraint+ALTER TABLE "country" ALTER COLUMN "alpha3" SET NOT NULL;+ALTER TABLE "country" ADD CONSTRAINT "country_alpha3_unique" UNIQUE ("alpha3");++-- Recreate the purchaseOrderLocations view+CREATE OR REPLACE VIEW "purchaseOrderLocations" WITH(SECURITY_INVOKER=true) AS+ SELECT+ po.id,+ s.name AS "supplierName",+ sa."addressLine1" AS "supplierAddressLine1",+ sa."addressLine2" AS "supplierAddressLine2",+ sa."city" AS "supplierCity",+ sa."state" AS "supplierState",+ sa."postalCode" AS "supplierPostalCode",+ sa."countryCode" AS "supplierCountryCode",+ dl.name AS "deliveryName",+ dl."addressLine1" AS "deliveryAddressLine1",+ dl."addressLine2" AS "deliveryAddressLine2",+ dl."city" AS "deliveryCity",+ dl."state" AS "deliveryState",+ dl."postalCode" AS "deliveryPostalCode",+ dl."countryCode" AS "deliveryCountryCode",+ pod."dropShipment",+ c.name AS "customerName",+ ca."addressLine1" AS "customerAddressLine1",+ ca."addressLine2" AS "customerAddressLine2",+ ca."city" AS "customerCity",+ ca."state" AS "customerState",+ ca."postalCode" AS "customerPostalCode",+ ca."countryCode" AS "customerCountryCode"+ FROM "purchaseOrder" po+ LEFT OUTER JOIN "supplier" s+ ON s.id = po."supplierId"+ LEFT OUTER JOIN "supplierLocation" sl+ ON sl.id = po."supplierLocationId"+ LEFT OUTER JOIN "address" sa+ ON sa.id = sl."addressId"+ INNER JOIN "purchaseOrderDelivery" pod+ ON pod.id = po.id+ LEFT OUTER JOIN "location" dl+ ON dl.id = pod."locationId"+ LEFT OUTER JOIN "customer" c+ ON c.id = pod."customerId"+ LEFT OUTER JOIN "customerLocation" cl+ ON cl.id = pod."customerLocationId"+ LEFT OUTER JOIN "address" ca+ ON ca.id = cl."addressId";++-- Recreate the quoteCustomerDetails view+CREATE OR REPLACE VIEW "quoteCustomerDetails" WITH(SECURITY_INVOKER=true) AS+SELECT+ q.id as "quoteId",+ c.name as "customerName",+ ca."addressLine1" AS "customerAddressLine1",+ ca."addressLine2" AS "customerAddressLine2",+ ca."city" AS "customerCity",+ ca."state" AS "customerState",+ ca."postalCode" AS "customerPostalCode",+ ca."countryCode" AS "customerCountryCode"+FROM+ "quote" q+ LEFT OUTER JOIN "customer" c ON c.id = q."customerId"+ LEFT OUTER JOIN "customerLocation" cl on cl.id = q."customerLocationId"+ LEFT OUTER JOIN "address" ca ON ca.id = cl."addressId";++ -- Recreate the salesOrderLocations view+ CREATE OR REPLACE VIEW "salesOrderLocations" WITH(SECURITY_INVOKER=true) AS+ SELECT+ so.id,+ c.name AS "customerName",+ ca."addressLine1" AS "customerAddressLine1",+ ca."addressLine2" AS "customerAddressLine2",+ ca."city" AS "customerCity",+ ca."state" AS "customerState",+ ca."postalCode" AS "customerPostalCode",+ ca."countryCode" AS "customerCountryCode",+ pc.name AS "paymentCustomerName",+ pa."addressLine1" AS "paymentAddressLine1",+ pa."addressLine2" AS "paymentAddressLine2",+ pa."city" AS "paymentCity",+ pa."state" AS "paymentState",+ pa."postalCode" AS "paymentPostalCode",+ pa."countryCode" AS "paymentCountryCode"+ FROM "salesOrder" so+ INNER JOIN "customer" c+ ON c.id = so."customerId"+ LEFT OUTER JOIN "customerLocation" cl+ ON cl.id = so."customerLocationId"+ LEFT OUTER JOIN "address" ca+ ON ca.id = cl."addressId"+ LEFT OUTER JOIN "salesOrderPayment" sop+ ON sop.id = so.id+ LEFT OUTER JOIN "customer" pc+ ON pc.id = sop."invoiceCustomerId"+ LEFT OUTER JOIN "customerLocation" pl+ ON pl.id = sop."invoiceCustomerLocationId"+ LEFT OUTER JOIN "address" pa+ ON pa.id = pl."addressId";++-- Insert the country code data+INSERT INTO "country" ("name", "alpha2", "alpha3") VALUES+('Afghanistan', 'AF', 'AFG'),+('Albania', 'AL', 'ALB'),+('Algeria', 'DZ', 'DZA'),+('Andorra', 'AD', 'AND'),+('Angola', 'AO', 'AGO'),+('Antigua and Barbuda', 'AG', 'ATG'),+('Argentina', 'AR', 'ARG'),+('Armenia', 'AM', 'ARM'),+('Australia', 'AU', 'AUS'),+('Austria', 'AT', 'AUT'),+('Azerbaijan', 'AZ', 'AZE'),+('Bahamas', 'BS', 'BHS'),+('Bahrain', 'BH', 'BHR'),+('Bangladesh', 'BD', 'BGD'),+('Barbados', 'BB', 'BRB'),+('Belarus', 'BY', 'BLR'),+('Belgium', 'BE', 'BEL'),+('Belize', 'BZ', 'BLZ'),+('Benin', 'BJ', 'BEN'),+('Bhutan', 'BT', 'BTN'),+('Bolivia', 'BO', 'BOL'),+('Bosnia and Herzegovina', 'BA', 'BIH'),+('Botswana', 'BW', 'BWA'),+('Brazil', 'BR', 'BRA'),+('Brunei', 'BN', 'BRN'),+('Bulgaria', 'BG', 'BGR'),+('Burkina Faso', 'BF', 'BFA'),+('Burundi', 'BI', 'BDI'),+('Cambodia', 'KH', 'KHM'),+('Cameroon', 'CM', 'CMR'),+('Canada', 'CA', 'CAN'),+('Cape Verde', 'CV', 'CPV'),+('Central African Republic', 'CF', 'CAF'),+('Chad', 'TD', 'TCD'),+('Chile', 'CL', 'CHL'),+('China', 'CN', 'CHN'),+('Colombia', 'CO', 'COL'),+('Comoros', 'KM', 'COM'),+('Congo', 'CG', 'COG'),+('Costa Rica', 'CR', 'CRI'),+('Croatia', 'HR', 'HRV'),+('Cuba', 'CU', 'CUB'),+('Cyprus', 'CY', 'CYP'),+('Czech Republic', 'CZ', 'CZE'),+('Democratic Republic of the Congo', 'CD', 'COD'),+('Denmark', 'DK', 'DNK'),+('Djibouti', 'DJ', 'DJI'),+('Dominica', 'DM', 'DMA'),+('Dominican Republic', 'DO', 'DOM'),+('East Timor', 'TL', 'TLS'),+('Ecuador', 'EC', 'ECU'),+('Egypt', 'EG', 'EGY'),+('El Salvador', 'SV', 'SLV'),+('Equatorial Guinea', 'GQ', 'GNQ'),+('Eritrea', 'ER', 'ERI'),+('Estonia', 'EE', 'EST'),+('Ethiopia', 'ET', 'ETH'),+('Fiji', 'FJ', 'FJI'),+('Finland', 'FI', 'FIN'),+('France', 'FR', 'FRA'),+('Gabon', 'GA', 'GAB'),+('Gambia', 'GM', 'GMB'),+('Georgia', 'GE', 'GEO'),+('Germany', 'DE', 'DEU'),+('Ghana', 'GH', 'GHA'),+('Greece', 'GR', 'GRC'),+('Grenada', 'GD', 'GRD'),+('Guatemala', 'GT', 'GTM'),+('Guinea', 'GN', 'GIN'),+('Guinea-Bissau', 'GW', 'GNB'),+('Guyana', 'GY', 'GUY'),+('Haiti', 'HT', 'HTI'),+('Honduras', 'HN', 'HND'),+('Hungary', 'HU', 'HUN'),+('Iceland', 'IS', 'ISL'),+('India', 'IN', 'IND'),+('Indonesia', 'ID', 'IDN'),+('Iran', 'IR', 'IRN'),+('Iraq', 'IQ', 'IRQ'),+('Ireland', 'IE', 'IRL'),+('Israel', 'IL', 'ISR'),+('Italy', 'IT', 'ITA'),+('Ivory Coast', 'CI', 'CIV'),+('Jamaica', 'JM', 'JAM'),+('Japan', 'JP', 'JPN'),+('Jordan', 'JO', 'JOR'),+('Kazakhstan', 'KZ', 'KAZ'),+('Kenya', 'KE', 'KEN'),+('Kiribati', 'KI', 'KIR'),+('Kuwait', 'KW', 'KWT'),+('Kyrgyzstan', 'KG', 'KGZ'),+('Laos', 'LA', 'LAO'),+('Latvia', 'LV', 'LVA'),+('Lebanon', 'LB', 'LBN'),+('Lesotho', 'LS', 'LSO'),+('Liberia', 'LR', 'LBR'),+('Libya', 'LY', 'LBY'),+('Liechtenstein', 'LI', 'LIE'),+('Lithuania', 'LT', 'LTU'),+('Luxembourg', 'LU', 'LUX'),+('Madagascar', 'MG', 'MDG'),+('Malawi', 'MW', 'MWI'),+('Malaysia', 'MY', 'MYS'),+('Maldives', 'MV', 'MDV'),+('Mali', 'ML', 'MLI'),+('Malta', 'MT', 'MLT'),+('Marshall Islands', 'MH', 'MHL'),+('Mauritania', 'MR', 'MRT'),+('Mauritius', 'MU', 'MUS'),+('Mexico', 'MX', 'MEX'),+('Micronesia', 'FM', 'FSM'),+('Moldova', 'MD', 'MDA'),+('Monaco', 'MC', 'MCO'),+('Mongolia', 'MN', 'MNG'),+('Montenegro', 'ME', 'MNE'),+('Morocco', 'MA', 'MAR'),+('Mozambique', 'MZ', 'MOZ'),+('Myanmar', 'MM', 'MMR'),+('Namibia', 'NA', 'NAM'),+('Nauru', 'NR', 'NRU'),+('Nepal', 'NP', 'NPL'),+('Netherlands', 'NL', 'NLD'),+('New Zealand', 'NZ', 'NZL'),+('Nicaragua', 'NI', 'NIC'),+('Niger', 'NE', 'NER'),+('Nigeria', 'NG', 'NGA'),+('North Korea', 'KP', 'PRK'),+('North Macedonia', 'MK', 'MKD'),+('Norway', 'NO', 'NOR'),+('Oman', 'OM', 'OMN'),+('Pakistan', 'PK', 'PAK'),+('Palau', 'PW', 'PLW'),+('Palestine', 'PS', 'PSE'),+('Panama', 'PA', 'PAN'),+('Papua New Guinea', 'PG', 'PNG'),+('Paraguay', 'PY', 'PRY'),+('Peru', 'PE', 'PER'),+('Philippines', 'PH', 'PHL'),+('Poland', 'PL', 'POL'),+('Portugal', 'PT', 'PRT'),+('Qatar', 'QA', 'QAT'),+('Romania', 'RO', 'ROU'),+('Russia', 'RU', 'RUS'),+('Rwanda', 'RW', 'RWA'),+('Saint Kitts and Nevis', 'KN', 'KNA'),+('Saint Lucia', 'LC', 'LCA'),+('Saint Vincent and the Grenadines', 'VC', 'VCT'),+('Samoa', 'WS', 'WSM'),+('San Marino', 'SM', 'SMR'),+('Sao Tome and Principe', 'ST', 'STP'),+('Saudi Arabia', 'SA', 'SAU'),+('Senegal', 'SN', 'SEN'),+('Serbia', 'RS', 'SRB'),+('Seychelles', 'SC', 'SYC'),+('Sierra Leone', 'SL', 'SLE'),+('Singapore', 'SG', 'SGP'),+('Slovakia', 'SK', 'SVK'),+('Slovenia', 'SI', 'SVN'),+('Solomon Islands', 'SB', 'SLB'),+('Somalia', 'SO', 'SOM'),+('South Africa', 'ZA', 'ZAF'),+('South Korea', 'KR', 'KOR'),+('South Sudan', 'SS', 'SSD'),+('Spain', 'ES', 'ESP'),+('Sri Lanka', 'LK', 'LKA'),+('Sudan', 'SD', 'SDN'),+('Suriname', 'SR', 'SUR'),+('Sweden', 'SE', 'SWE'),+('Switzerland', 'CH', 'CHE'),+('Syria', 'SY', 'SYR'),+('Tajikistan', 'TJ', 'TJK'),+('Tanzania', 'TZ', 'TZA'),+('Thailand', 'TH', 'THA'),+('Togo', 'TG', 'TGO'),+('Tonga', 'TO', 'TON'),+('Trinidad and Tobago', 'TT', 'TTO'),+('Tunisia', 'TN', 'TUN'),+('Turkey', 'TR', 'TUR'),+('Turkmenistan', 'TM', 'TKM'),+('Tuvalu', 'TV', 'TUV'),+('Uganda', 'UG', 'UGA'),+('Ukraine', 'UA', 'UKR'),+('United Arab Emirates', 'AE', 'ARE'),+('United Kingdom', 'GB', 'GBR'),+('United States', 'US', 'USA'),+('Uruguay', 'UY', 'URY'),+('Uzbekistan', 'UZ', 'UZB'),+('Vanuatu', 'VU', 'VUT'),+('Vatican City', 'VA', 'VAT'),+('Venezuela', 'VE', 'VEN'),+('Vietnam', 'VN', 'VNM'),+('Yemen', 'YE', 'YEM'),+('Zambia', 'ZM', 'ZMB'),+('Zimbabwe', 'ZW', 'ZWE');+++diff --git a/packages/documents/src/email/PurchaseOrderEmail.tsx b/packages/documents/src/email/PurchaseOrderEmail.tsxindex 9c57e8e31a..9d077c0cf1 100644--- a/packages/documents/src/email/PurchaseOrderEmail.tsx+++ b/packages/documents/src/email/PurchaseOrderEmail.tsx@@ -1,4 +1,5 @@import type { Database } from "@carbon/database";+import { formatCityStatePostalCode } from "@carbon/utils";import {Body,Column,@@ -20,7 +21,6 @@ import {getLineDescriptionDetails,getTotal,} from "../utils/purchase-order";-import { formatAddress } from "../utils/shared";interface PurchaseOrderEmailProps extends Email {purchaseOrder: Database["public"]["Views"]["purchaseOrders"]["Row"];@@ -147,7 +147,7 @@ const PurchaseOrderEmail = ({<Text>{customerAddressLine2}</Text>)}<Text>- {formatAddress(+ {formatCityStatePostalCode(customerCity,customerState,customerPostalCode@@ -166,7 +166,7 @@ const PurchaseOrderEmail = ({<Text>{deliveryAddressLine2}</Text>)}<Text>- {formatAddress(+ {formatCityStatePostalCode(deliveryCity,deliveryState,deliveryPostalCodediff --git a/packages/documents/src/email/SalesOrderEmail.tsx b/packages/documents/src/email/SalesOrderEmail.tsxindex 74db0fd779..94ff4a7588 100644--- a/packages/documents/src/email/SalesOrderEmail.tsx+++ b/packages/documents/src/email/SalesOrderEmail.tsx@@ -1,4 +1,5 @@import type { Database } from "@carbon/database";+import { formatCityStatePostalCode } from "@carbon/utils";import {Body,Column,@@ -21,7 +22,6 @@ import {getLineTotal,getTotal,} from "../utils/sales-order";-import { formatAddress } from "../utils/shared";interface SalesOrderEmailProps extends Email {salesOrder: Database["public"]["Views"]["salesOrders"]["Row"];@@ -146,7 +146,7 @@ const SalesOrderEmail = ({{customerAddressLine1 && <Text>{customerAddressLine1}</Text>}{customerAddressLine2 && <Text>{customerAddressLine2}</Text>}<Text>- {formatAddress(+ {formatCityStatePostalCode(customerCity,customerState,customerPostalCodediff --git a/packages/documents/src/pdf/PurchaseOrderPDF.tsx b/packages/documents/src/pdf/PurchaseOrderPDF.tsxindex 53540c2e6a..c08523e114 100644--- a/packages/documents/src/pdf/PurchaseOrderPDF.tsx+++ b/packages/documents/src/pdf/PurchaseOrderPDF.tsx@@ -3,6 +3,7 @@ import { Text, View } from "@react-pdf/renderer";import { createTw } from "react-pdf-tailwind";import type { JSONContent } from "@carbon/react";+import { formatCityStatePostalCode } from "@carbon/utils";import type { PDF } from "../types";import {getLineDescription,@@ -10,7 +11,6 @@ import {getLineTotal,getTotal,} from "../utils/purchase-order";-import { formatAddress } from "../utils/shared";import { Header, Note, Summary, Template } from "./components";interface PurchaseOrderPDFProps extends PDF {@@ -107,7 +107,11 @@ const PurchaseOrderPDF = ({{supplierAddressLine1 && <Text>{supplierAddressLine1}</Text>}{supplierAddressLine2 && <Text>{supplierAddressLine2}</Text>}<Text>- {formatAddress(supplierCity, supplierState, supplierPostalCode)}+ {formatCityStatePostalCode(+ supplierCity,+ supplierState,+ supplierPostalCode+ )}</Text><Text>{supplierCountryCode}</Text></View>@@ -118,7 +122,11 @@ const PurchaseOrderPDF = ({{customerAddressLine1 && <Text>{customerAddressLine1}</Text>}{customerAddressLine2 && <Text>{customerAddressLine2}</Text>}<Text>- {formatAddress(customerCity, customerState, customerPostalCode)}+ {formatCityStatePostalCode(+ customerCity,+ customerState,+ customerPostalCode+ )}</Text><Text>{customerCountryCode}</Text></View>@@ -129,7 +137,11 @@ const PurchaseOrderPDF = ({{deliveryAddressLine1 && <Text>{deliveryAddressLine1}</Text>}{deliveryAddressLine2 && <Text>{deliveryAddressLine2}</Text>}<Text>- {formatAddress(deliveryCity, deliveryState, deliveryPostalCode)}+ {formatCityStatePostalCode(+ deliveryCity,+ deliveryState,+ deliveryPostalCode+ )}</Text><Text>{deliveryCountryCode}</Text></View>diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsxindex ac3736e310..524403ad31 100644--- a/packages/documents/src/pdf/QuotePDF.tsx+++ b/packages/documents/src/pdf/QuotePDF.tsx@@ -4,9 +4,9 @@ import { Image, Text, View } from "@react-pdf/renderer";import { createTw } from "react-pdf-tailwind";import type { JSONContent } from "@carbon/react";+import { formatCityStatePostalCode } from "@carbon/utils";import type { PDF } from "../types";import { getLineDescription, getLineDescriptionDetails } from "../utils/quote";-import { formatAddress } from "../utils/shared";import { Header, Note, Summary, Template } from "./components";interface QuotePDFProps extends PDF {@@ -146,7 +146,11 @@ const QuotePDF = ({{customerAddressLine1 && <Text>{customerAddressLine1}</Text>}{customerAddressLine2 && <Text>{customerAddressLine2}</Text>}<Text>- {formatAddress(customerCity, customerState, customerPostalCode)}+ {formatCityStatePostalCode(+ customerCity,+ customerState,+ customerPostalCode+ )}</Text><Text>{customerCountryCode}</Text></View>diff --git a/packages/documents/src/pdf/SalesOrderPDF.tsx b/packages/documents/src/pdf/SalesOrderPDF.tsxindex a60301de1f..efda763989 100644--- a/packages/documents/src/pdf/SalesOrderPDF.tsx+++ b/packages/documents/src/pdf/SalesOrderPDF.tsx@@ -3,6 +3,7 @@ import { Text, View } from "@react-pdf/renderer";import { createTw } from "react-pdf-tailwind";import type { JSONContent } from "@carbon/react";+import { formatCityStatePostalCode } from "@carbon/utils";import type { PDF } from "../types";import {getLineDescription,@@ -10,7 +11,6 @@ import {getLineTotal,getTotal,} from "../utils/sales-order";-import { formatAddress } from "../utils/shared";import { Header, Note, Summary, Template } from "./components";interface SalesOrderPDFProps extends PDF {@@ -103,7 +103,11 @@ const SalesOrderPDF = ({<Text style={tw("text-sm")}>{customerAddressLine2}</Text>)}<Text style={tw("text-sm")}>- {formatAddress(customerCity, customerState, customerPostalCode)}+ {formatCityStatePostalCode(+ customerCity,+ customerState,+ customerPostalCode+ )}</Text><Text style={tw("text-sm")}>{customerCountryCode}</Text></View>@@ -117,7 +121,11 @@ const SalesOrderPDF = ({<Text style={tw("text-sm")}>{paymentAddressLine2}</Text>)}<Text style={tw("text-sm")}>- {formatAddress(paymentCity, paymentState, paymentPostalCode)}+ {formatCityStatePostalCode(+ paymentCity,+ paymentState,+ paymentPostalCode+ )}</Text><Text style={tw("text-sm")}>{paymentCountryCode}</Text></View>diff --git a/packages/documents/src/utils/shared.ts b/packages/documents/src/utils/shared.tsindex 9842c55b78..e69de29bb2 100644--- a/packages/documents/src/utils/shared.ts+++ b/packages/documents/src/utils/shared.ts@@ -1,11 +0,0 @@-export function formatAddress(- city: string | null,- state: string | null,- postalCode: string | null-) {- if (city && state && postalCode) {- return `${city}, ${state}, ${postalCode}`;- }-- return "";-}diff --git a/packages/utils/src/address.ts b/packages/utils/src/address.tsindex 59fa69ab2b..03613934ad 100644--- a/packages/utils/src/address.ts+++ b/packages/utils/src/address.ts@@ -13,11 +13,10 @@ export function formatAddressLines(}}-export function formatCityStateZipCountry(+export function formatCityStatePostalCode(city?: string | null,state?: string | null,- zip?: string | null,- country?: string | null+ postalCode?: string | null): string {// Create an array to hold the different parts of the addressconst parts: string[] = [];@@ -25,17 +24,14 @@ export function formatCityStateZipCountry(// Add city in the correct formatif (city) parts.push(city);- // Combine state and zip without a comma if both are provided+ // Combine state and postalCode without a comma if both are providedif (state) {- const stateZip = zip ? `${state} ${zip}` : state;- parts.push(stateZip);- } else if (zip) {- parts.push(zip);+ const statepostalCode = postalCode ? `${state} ${postalCode}` : state;+ parts.push(statepostalCode);+ } else if (postalCode) {+ parts.push(postalCode);}- // Add country in the correct format- if (country) parts.push(country);-// Join all parts with a comma separatorreturn parts.join(", ");}@@ -45,7 +41,7 @@ export function formatAddress(addressLine2?: string | null,city?: string | null,state?: string | null,- zip?: string | null,+ postalCode?: string | null,country?: string | null): string {// Create an array to hold the different parts of the address@@ -54,13 +50,14 @@ export function formatAddress(const formattedAddressLines = formatAddressLines(addressLine1, addressLine2);if (formattedAddressLines) parts.push(formattedAddressLines);- const formattedCityStateZipCountry = formatCityStateZipCountry(+ const formattedCityStatePostalCode = formatCityStatePostalCode(city,state,- zip,- country+ postalCode);- if (formattedCityStateZipCountry) parts.push(formattedCityStateZipCountry);+ if (formattedCityStatePostalCode) parts.push(formattedCityStatePostalCode);++ if (country) parts.push(country);// Join all parts with a comma separatorreturn parts.join(", ");