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 currencyCode, phone, fax, website fields to customer and supplier
Rob Carrington480f9c44e5b8
diff --git a/apps/carbon/app/modules/purchasing/purchasing.models.ts b/apps/carbon/app/modules/purchasing/purchasing.models.tsindex 6625af28a5..bf854aed1d 100644--- a/apps/carbon/app/modules/purchasing/purchasing.models.ts+++ b/apps/carbon/app/modules/purchasing/purchasing.models.ts@@ -173,6 +173,10 @@ export const supplierValidator = z.object({name: z.string().min(1, { message: "Name is required" }),supplierStatusId: zfd.text(z.string().optional()),accountManagerId: zfd.text(z.string().optional()),+ currencyCode: zfd.text(z.string().optional()),+ phone: zfd.text(z.string().optional()),+ fax: zfd.text(z.string().optional()),+ website: zfd.text(z.string().optional()),});export const supplierContactValidator = z.object({diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsxindex 1b123ec897..55dedce76b 100644--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx@@ -1,4 +1,4 @@-import { ValidatedForm } from "@carbon/form";+import { PhoneInput, ValidatedForm } from "@carbon/form";import {HStack,ModalCard,@@ -17,6 +17,7 @@ import type { PostgrestResponse } from "@supabase/supabase-js";import { useEffect } from "react";import type { z } from "zod";import {+ Currency,CustomFormFields,Employee,Hidden,@@ -106,6 +107,12 @@ const SupplierForm = ({<Employee name="accountManagerId" label="Account Manager" />+ <Currency name="currencyCode" label="Currency" />++ <PhoneInput name="phone" label="Phone" />+ <PhoneInput name="fax" label="Fax" />+ <Input name="website" label="Website" />+<CustomFormFields table="supplier" /></div></ModalCardBody>diff --git a/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx b/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsxindex c5bf25722a..ddb04cbbaf 100644--- a/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx+++ b/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx@@ -112,6 +112,26 @@ const SuppliersTable = memo(</Button>),},+ {+ accessorKey: "currencyCode",+ header: "Currency",+ cell: (item) => item.getValue(),+ },+ {+ accessorKey: "phone",+ header: "Phone",+ cell: (item) => item.getValue(),+ },+ {+ accessorKey: "fax",+ header: "Fax",+ cell: (item) => item.getValue(),+ },+ {+ accessorKey: "website",+ header: "Website",+ cell: (item) => item.getValue(),+ },{id: "createdBy",header: "Created By",@@ -151,7 +171,7 @@ const SuppliersTable = memo(},{accessorKey: "updatedAt",- header: "Created At",+ header: "Updated At",cell: (item) => formatDate(item.getValue<string>()),},];@@ -181,6 +201,10 @@ const SuppliersTable = memo(left: ["name"],}}defaultColumnVisibility={{+ currencyCode: false,+ phone: false,+ fax: false,+ website: false,createdBy: false,createdAt: false,updatedBy: false,diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.tsindex 714ef0256f..6a1ebc31aa 100644--- a/apps/carbon/app/modules/sales/sales.models.ts+++ b/apps/carbon/app/modules/sales/sales.models.ts@@ -40,6 +40,10 @@ export const customerValidator = z.object({name: z.string().min(1, { message: "Name is required" }),customerStatusId: zfd.text(z.string().optional()),accountManagerId: zfd.text(z.string().optional()),+ currencyCode: zfd.text(z.string().optional()),+ phone: zfd.text(z.string().optional()),+ fax: zfd.text(z.string().optional()),+ website: zfd.text(z.string().optional()),});export const customerPaymentValidator = z.object({diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsxindex 0688826259..53b7333009 100644--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx@@ -1,4 +1,4 @@-import { ValidatedForm } from "@carbon/form";+import { PhoneInput, ValidatedForm } from "@carbon/form";import {HStack,ModalCard,@@ -17,6 +17,7 @@ import type { PostgrestResponse } from "@supabase/supabase-js";import { useEffect } from "react";import type { z } from "zod";import {+ Currency,CustomFormFields,CustomerStatus,Employee,@@ -106,6 +107,12 @@ const CustomerForm = ({<Employee name="accountManagerId" label="Account Manager" />+ <Currency name="currencyCode" label="Currency" />++ <PhoneInput name="phone" label="Phone" />+ <PhoneInput name="fax" label="Fax" />+ <Input name="website" label="Website" />+<CustomFormFields table="customer" /></div></ModalCardBody>diff --git a/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx b/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsxindex 0ea74a8df0..7159a96dfa 100644--- a/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx+++ b/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx@@ -88,6 +88,26 @@ const CustomersTable = memo(},},},+ {+ accessorKey: "currencyCode",+ header: "Currency",+ cell: (item) => item.getValue(),+ },+ {+ accessorKey: "phone",+ header: "Phone",+ cell: (item) => item.getValue(),+ },+ {+ accessorKey: "fax",+ header: "Fax",+ cell: (item) => item.getValue(),+ },+ {+ accessorKey: "website",+ header: "Website",+ cell: (item) => item.getValue(),+ },{id: "createdBy",header: "Created By",@@ -127,7 +147,7 @@ const CustomersTable = memo(},{accessorKey: "updatedAt",- header: "Created At",+ header: "Updated At",cell: (item) => formatDate(item.getValue<string>()),},];@@ -157,6 +177,10 @@ const CustomersTable = memo(left: ["name"],}}defaultColumnVisibility={{+ currencyCode: false,+ phone: false,+ fax: false,+ website: false,createdBy: false,createdAt: false,updatedBy: false,diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.details.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.details.tsxindex 5052cc392f..0b485af949 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.details.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.details.tsx@@ -12,6 +12,7 @@ import {customerValidator,upsertCustomer,} from "~/modules/sales";+import type { Company } from "~/modules/settings";import { getCustomFields, setCustomFields } from "~/utils/form";import { path } from "~/utils/path";@@ -60,8 +61,15 @@ export default function CustomerEditRoute() {path.to.customer(customerId));+ const rootRouteData = useRouteData<{ company: Company }>(+ path.to.authenticatedRoot+ );+if (!routeData?.customer) return null;+ const company = rootRouteData?.company;+ if (!company) throw new Error("Company not found");+const initialValues = {...routeData.customer,name: routeData?.customer?.name ?? "",@@ -69,6 +77,10 @@ export default function CustomerEditRoute() {customerStatusId: routeData?.customer?.customerStatusId ?? undefined,accountManagerId: routeData?.customer?.accountManagerId ?? undefined,taxId: routeData?.customer?.taxId ?? "",+ currencyCode: routeData?.customer?.currencyCode ?? undefined,+ phone: routeData?.customer?.phone ?? "",+ fax: routeData?.customer?.fax ?? "",+ website: routeData?.customer?.website ?? "",...getCustomFields(routeData?.customer?.customFields),};diff --git a/apps/carbon/app/routes/x+/customer+/new.tsx b/apps/carbon/app/routes/x+/customer+/new.tsxindex ccc737af0c..2535315920 100644--- a/apps/carbon/app/routes/x+/customer+/new.tsx+++ b/apps/carbon/app/routes/x+/customer+/new.tsx@@ -4,11 +4,13 @@ import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import type { ActionFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";+import { useRouteData } from "~/hooks";import {CustomerForm,customerValidator,upsertCustomer,} from "~/modules/sales";+import type { Company } from "~/modules/settings";import { setCustomFields } from "~/utils/form";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -66,9 +68,21 @@ export async function action({ request }: ActionFunctionArgs) {}export default function CustomersNewRoute() {+ const routeData = useRouteData<{ company: Company }>(+ path.to.authenticatedRoot+ );++ const company = routeData?.company;+ if (!company) throw new Error("Company not found");+const initialValues = {name: "",+ currencyCode: company.baseCurrencyCode ?? undefined,+ phone: "",+ fax: "",+ website: "",};+return (<div className="max-w-[50rem] w-full p-2 sm:p-0 mx-auto mt-0 md:mt-8"><CustomerForm initialValues={initialValues} />diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.details.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.details.tsxindex 577807a5c9..95653dc025 100644--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.details.tsx+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.details.tsx@@ -12,6 +12,7 @@ import {supplierValidator,upsertSupplier,} from "~/modules/purchasing";+import type { Company } from "~/modules/settings";import { getCustomFields, setCustomFields } from "~/utils/form";import { path } from "~/utils/path";@@ -60,8 +61,15 @@ export default function SupplierEditRoute() {path.to.supplier(supplierId));+ const rootRouteData = useRouteData<{ company: Company }>(+ path.to.authenticatedRoot+ );+if (!routeData?.supplier) return null;+ const company = rootRouteData?.company;+ if (!company) throw new Error("Company not found");+const initialValues = {id: routeData?.supplier?.id ?? undefined,name: routeData?.supplier?.name ?? "",@@ -69,6 +77,10 @@ export default function SupplierEditRoute() {supplierStatusId: routeData?.supplier?.supplierStatusId ?? undefined,accountManagerId: routeData?.supplier?.accountManagerId ?? undefined,taxId: routeData?.supplier?.taxId ?? "",+ currencyCode: routeData?.supplier?.currencyCode ?? undefined,+ phone: routeData?.supplier?.phone ?? "",+ fax: routeData?.supplier?.fax ?? "",+ website: routeData?.supplier?.website ?? "",...getCustomFields(routeData?.supplier?.customFields),};diff --git a/apps/carbon/app/routes/x+/supplier+/new.tsx b/apps/carbon/app/routes/x+/supplier+/new.tsxindex 03dae5d489..a54aff0b5e 100644--- a/apps/carbon/app/routes/x+/supplier+/new.tsx+++ b/apps/carbon/app/routes/x+/supplier+/new.tsx@@ -4,11 +4,13 @@ import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import type { ActionFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";+import { useRouteData } from "~/hooks";import {SupplierForm,supplierValidator,upsertSupplier,} from "~/modules/purchasing";+import type { Company } from "~/modules/settings";import { setCustomFields } from "~/utils/form";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -66,8 +68,19 @@ export async function action({ request }: ActionFunctionArgs) {}export default function SuppliersNewRoute() {+ const routeData = useRouteData<{ company: Company }>(+ path.to.authenticatedRoot+ );++ const company = routeData?.company;+ if (!company) throw new Error("Company not found");+const initialValues = {name: "",+ currencyCode: company.baseCurrencyCode ?? undefined,+ phone: "",+ fax: "",+ website: "",};return (<div className="max-w-[50rem] w-full p-2 sm:p-0 mx-auto mt-0 md:mt-8">diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.tsindex a0b09073e2..627e7d8657 100644--- a/packages/database/src/swagger-docs-schema.ts+++ b/packages/database/src/swagger-docs-schema.ts@@ -13341,6 +13341,18 @@ export default {{$ref: "#/parameters/rowFilter.customer.customFields",},+ {+ $ref: "#/parameters/rowFilter.customer.currencyCode",+ },+ {+ $ref: "#/parameters/rowFilter.customer.phone",+ },+ {+ $ref: "#/parameters/rowFilter.customer.fax",+ },+ {+ $ref: "#/parameters/rowFilter.customer.website",+ },{$ref: "#/parameters/select",},@@ -13442,6 +13454,18 @@ export default {{$ref: "#/parameters/rowFilter.customer.customFields",},+ {+ $ref: "#/parameters/rowFilter.customer.currencyCode",+ },+ {+ $ref: "#/parameters/rowFilter.customer.phone",+ },+ {+ $ref: "#/parameters/rowFilter.customer.fax",+ },+ {+ $ref: "#/parameters/rowFilter.customer.website",+ },{$ref: "#/parameters/preferReturn",},@@ -13497,6 +13521,18 @@ export default {{$ref: "#/parameters/rowFilter.customer.customFields",},+ {+ $ref: "#/parameters/rowFilter.customer.currencyCode",+ },+ {+ $ref: "#/parameters/rowFilter.customer.phone",+ },+ {+ $ref: "#/parameters/rowFilter.customer.fax",+ },+ {+ $ref: "#/parameters/rowFilter.customer.website",+ },{$ref: "#/parameters/body.customer",},@@ -14841,6 +14877,18 @@ export default {{$ref: "#/parameters/rowFilter.supplier.customFields",},+ {+ $ref: "#/parameters/rowFilter.supplier.currencyCode",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.phone",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.fax",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.website",+ },{$ref: "#/parameters/select",},@@ -14942,6 +14990,18 @@ export default {{$ref: "#/parameters/rowFilter.supplier.customFields",},+ {+ $ref: "#/parameters/rowFilter.supplier.currencyCode",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.phone",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.fax",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.website",+ },{$ref: "#/parameters/preferReturn",},@@ -14997,6 +15057,18 @@ export default {{$ref: "#/parameters/rowFilter.supplier.customFields",},+ {+ $ref: "#/parameters/rowFilter.supplier.currencyCode",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.phone",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.fax",+ },+ {+ $ref: "#/parameters/rowFilter.supplier.website",+ },{$ref: "#/parameters/body.supplier",},@@ -29565,6 +29637,18 @@ export default {{$ref: "#/parameters/rowFilter.suppliers.customFields",},+ {+ $ref: "#/parameters/rowFilter.suppliers.currencyCode",+ },+ {+ $ref: "#/parameters/rowFilter.suppliers.phone",+ },+ {+ $ref: "#/parameters/rowFilter.suppliers.fax",+ },+ {+ $ref: "#/parameters/rowFilter.suppliers.website",+ },{$ref: "#/parameters/rowFilter.suppliers.type",},@@ -29997,6 +30081,18 @@ export default {{$ref: "#/parameters/rowFilter.customers.customFields",},+ {+ $ref: "#/parameters/rowFilter.customers.currencyCode",+ },+ {+ $ref: "#/parameters/rowFilter.customers.phone",+ },+ {+ $ref: "#/parameters/rowFilter.customers.fax",+ },+ {+ $ref: "#/parameters/rowFilter.customers.website",+ },{$ref: "#/parameters/rowFilter.customers.type",},@@ -42280,6 +42376,24 @@ export default {customFields: {format: "jsonb",},+ currencyCode: {+ description:+ "Note:\nThis is a Foreign Key to `currencyCode.code`.<fk table='currencyCode' column='code'/>",+ format: "text",+ type: "string",+ },+ phone: {+ format: "text",+ type: "string",+ },+ fax: {+ format: "text",+ type: "string",+ },+ website: {+ format: "text",+ type: "string",+ },},type: "object",},@@ -42939,6 +43053,24 @@ export default {customFields: {format: "jsonb",},+ currencyCode: {+ description:+ "Note:\nThis is a Foreign Key to `currencyCode.code`.<fk table='currencyCode' column='code'/>",+ format: "text",+ type: "string",+ },+ phone: {+ format: "text",+ type: "string",+ },+ fax: {+ format: "text",+ type: "string",+ },+ website: {+ format: "text",+ type: "string",+ },},type: "object",},@@ -46990,7 +47122,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",},@@ -47039,7 +47171,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",},@@ -49412,6 +49544,24 @@ export default {customFields: {format: "jsonb",},+ currencyCode: {+ description:+ "Note:\nThis is a Foreign Key to `currencyCode.code`.<fk table='currencyCode' column='code'/>",+ format: "text",+ type: "string",+ },+ phone: {+ format: "text",+ type: "string",+ },+ fax: {+ format: "text",+ type: "string",+ },+ website: {+ format: "text",+ type: "string",+ },type: {format: "text",type: "string",@@ -49732,6 +49882,24 @@ export default {customFields: {format: "jsonb",},+ currencyCode: {+ description:+ "Note:\nThis is a Foreign Key to `currencyCode.code`.<fk table='currencyCode' column='code'/>",+ format: "text",+ type: "string",+ },+ phone: {+ format: "text",+ type: "string",+ },+ fax: {+ format: "text",+ type: "string",+ },+ website: {+ format: "text",+ type: "string",+ },type: {format: "text",type: "string",@@ -59731,6 +59899,34 @@ export default {in: "query",type: "string",},+ "rowFilter.customer.currencyCode": {+ name: "currencyCode",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.customer.phone": {+ name: "phone",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.customer.fax": {+ name: "fax",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.customer.website": {+ name: "website",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },"body.note": {name: "note",description: "note",@@ -60615,6 +60811,34 @@ export default {in: "query",type: "string",},+ "rowFilter.supplier.currencyCode": {+ name: "currencyCode",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.supplier.phone": {+ name: "phone",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.supplier.fax": {+ name: "fax",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.supplier.website": {+ name: "website",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },"body.customFieldTable": {name: "customFieldTable",description: "customFieldTable",@@ -69018,6 +69242,34 @@ export default {in: "query",type: "string",},+ "rowFilter.suppliers.currencyCode": {+ name: "currencyCode",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.suppliers.phone": {+ name: "phone",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.suppliers.fax": {+ name: "fax",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.suppliers.website": {+ name: "website",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },"rowFilter.suppliers.type": {name: "type",required: false,@@ -69465,6 +69717,34 @@ export default {in: "query",type: "string",},+ "rowFilter.customers.currencyCode": {+ name: "currencyCode",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.customers.phone": {+ name: "phone",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.customers.fax": {+ name: "fax",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },+ "rowFilter.customers.website": {+ name: "website",+ required: false,+ format: "text",+ in: "query",+ type: "string",+ },"rowFilter.customers.type": {name: "type",required: false,diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 61a276208e..9df854173d 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -2797,15 +2797,19 @@ export type Database = {companyId: stringcreatedAt: stringcreatedBy: string | null+ currencyCode: string | nullcustomerStatusId: string | nullcustomerTypeId: string | nullcustomFields: Json | null+ fax: string | nullid: stringlogo: string | nullname: string+ phone: string | nulltaxId: string | nullupdatedAt: string | nullupdatedBy: string | null+ website: string | null}Insert: {accountManagerId?: string | null@@ -2813,15 +2817,19 @@ export type Database = {companyId: stringcreatedAt?: stringcreatedBy?: string | null+ currencyCode?: string | nullcustomerStatusId?: string | nullcustomerTypeId?: string | nullcustomFields?: Json | null+ fax?: string | nullid?: stringlogo?: string | nullname: string+ phone?: string | nulltaxId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null+ website?: string | null}Update: {accountManagerId?: string | null@@ -2829,15 +2837,19 @@ export type Database = {companyId?: stringcreatedAt?: stringcreatedBy?: string | null+ currencyCode?: string | nullcustomerStatusId?: string | nullcustomerTypeId?: string | nullcustomFields?: Json | null+ fax?: string | nullid?: stringlogo?: string | nullname?: string+ phone?: string | nulltaxId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null+ website?: string | null}Relationships: [{@@ -2973,6 +2985,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "customer_currencyCode_fkey"+ columns: ["currencyCode"]+ isOneToOne: false+ referencedRelation: "currencyCode"+ referencedColumns: ["code"]+ },{foreignKeyName: "customer_customerStatusId_fkey"columns: ["customerStatusId"]@@ -18943,15 +18962,19 @@ export type Database = {companyId: stringcreatedAt: stringcreatedBy: string | null+ currencyCode: string | nullcustomFields: Json | null+ fax: string | nullid: stringlogo: string | nullname: string+ phone: string | nullsupplierStatusId: string | nullsupplierTypeId: string | nulltaxId: string | nullupdatedAt: string | nullupdatedBy: string | null+ website: string | null}Insert: {accountManagerId?: string | null@@ -18959,15 +18982,19 @@ export type Database = {companyId: stringcreatedAt?: stringcreatedBy?: string | null+ currencyCode?: string | nullcustomFields?: Json | null+ fax?: string | nullid?: stringlogo?: string | nullname: string+ phone?: string | nullsupplierStatusId?: string | nullsupplierTypeId?: string | nulltaxId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null+ website?: string | null}Update: {accountManagerId?: string | null@@ -18975,15 +19002,19 @@ export type Database = {companyId?: stringcreatedAt?: stringcreatedBy?: string | null+ currencyCode?: string | nullcustomFields?: Json | null+ fax?: string | nullid?: stringlogo?: string | nullname?: string+ phone?: string | nullsupplierStatusId?: string | nullsupplierTypeId?: string | nulltaxId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null+ website?: string | null}Relationships: [{@@ -19119,6 +19150,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "supplier_currencyCode_fkey"+ columns: ["currencyCode"]+ isOneToOne: false+ referencedRelation: "currencyCode"+ referencedColumns: ["code"]+ },{foreignKeyName: "supplier_supplierStatusId_fkey"columns: ["supplierStatusId"]@@ -22812,18 +22850,22 @@ export type Database = {companyId: string | nullcreatedAt: string | nullcreatedBy: string | null+ currencyCode: string | nullcustomerStatusId: string | nullcustomerTypeId: string | nullcustomFields: Json | null+ fax: string | nullid: string | nulllogo: string | nullname: string | nullorderCount: number | null+ phone: string | nullstatus: string | nulltaxId: string | nulltype: string | nullupdatedAt: string | nullupdatedBy: string | null+ website: string | null}Relationships: [{@@ -22959,6 +23001,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "customer_currencyCode_fkey"+ columns: ["currencyCode"]+ isOneToOne: false+ referencedRelation: "currencyCode"+ referencedColumns: ["code"]+ },{foreignKeyName: "customer_customerStatusId_fkey"columns: ["customerStatusId"]@@ -28580,12 +28629,15 @@ export type Database = {companyId: string | nullcreatedAt: string | nullcreatedBy: string | null+ currencyCode: string | nullcustomFields: Json | null+ fax: string | nullid: string | nulllogo: string | nullname: string | nullorderCount: number | nullpartCount: number | null+ phone: string | nullstatus: string | nullsupplierStatusId: string | nullsupplierTypeId: string | null@@ -28593,6 +28645,7 @@ export type Database = {type: string | nullupdatedAt: string | nullupdatedBy: string | null+ website: string | null}Relationships: [{@@ -28728,6 +28781,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "supplier_currencyCode_fkey"+ columns: ["currencyCode"]+ isOneToOne: false+ referencedRelation: "currencyCode"+ referencedColumns: ["code"]+ },{foreignKeyName: "supplier_supplierStatusId_fkey"columns: ["supplierStatusId"]diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 61a276208e..9df854173d 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -2797,15 +2797,19 @@ export type Database = {companyId: stringcreatedAt: stringcreatedBy: string | null+ currencyCode: string | nullcustomerStatusId: string | nullcustomerTypeId: string | nullcustomFields: Json | null+ fax: string | nullid: stringlogo: string | nullname: string+ phone: string | nulltaxId: string | nullupdatedAt: string | nullupdatedBy: string | null+ website: string | null}Insert: {accountManagerId?: string | null@@ -2813,15 +2817,19 @@ export type Database = {companyId: stringcreatedAt?: stringcreatedBy?: string | null+ currencyCode?: string | nullcustomerStatusId?: string | nullcustomerTypeId?: string | nullcustomFields?: Json | null+ fax?: string | nullid?: stringlogo?: string | nullname: string+ phone?: string | nulltaxId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null+ website?: string | null}Update: {accountManagerId?: string | null@@ -2829,15 +2837,19 @@ export type Database = {companyId?: stringcreatedAt?: stringcreatedBy?: string | null+ currencyCode?: string | nullcustomerStatusId?: string | nullcustomerTypeId?: string | nullcustomFields?: Json | null+ fax?: string | nullid?: stringlogo?: string | nullname?: string+ phone?: string | nulltaxId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null+ website?: string | null}Relationships: [{@@ -2973,6 +2985,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "customer_currencyCode_fkey"+ columns: ["currencyCode"]+ isOneToOne: false+ referencedRelation: "currencyCode"+ referencedColumns: ["code"]+ },{foreignKeyName: "customer_customerStatusId_fkey"columns: ["customerStatusId"]@@ -18943,15 +18962,19 @@ export type Database = {companyId: stringcreatedAt: stringcreatedBy: string | null+ currencyCode: string | nullcustomFields: Json | null+ fax: string | nullid: stringlogo: string | nullname: string+ phone: string | nullsupplierStatusId: string | nullsupplierTypeId: string | nulltaxId: string | nullupdatedAt: string | nullupdatedBy: string | null+ website: string | null}Insert: {accountManagerId?: string | null@@ -18959,15 +18982,19 @@ export type Database = {companyId: stringcreatedAt?: stringcreatedBy?: string | null+ currencyCode?: string | nullcustomFields?: Json | null+ fax?: string | nullid?: stringlogo?: string | nullname: string+ phone?: string | nullsupplierStatusId?: string | nullsupplierTypeId?: string | nulltaxId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null+ website?: string | null}Update: {accountManagerId?: string | null@@ -18975,15 +19002,19 @@ export type Database = {companyId?: stringcreatedAt?: stringcreatedBy?: string | null+ currencyCode?: string | nullcustomFields?: Json | null+ fax?: string | nullid?: stringlogo?: string | nullname?: string+ phone?: string | nullsupplierStatusId?: string | nullsupplierTypeId?: string | nulltaxId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null+ website?: string | null}Relationships: [{@@ -19119,6 +19150,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "supplier_currencyCode_fkey"+ columns: ["currencyCode"]+ isOneToOne: false+ referencedRelation: "currencyCode"+ referencedColumns: ["code"]+ },{foreignKeyName: "supplier_supplierStatusId_fkey"columns: ["supplierStatusId"]@@ -22812,18 +22850,22 @@ export type Database = {companyId: string | nullcreatedAt: string | nullcreatedBy: string | null+ currencyCode: string | nullcustomerStatusId: string | nullcustomerTypeId: string | nullcustomFields: Json | null+ fax: string | nullid: string | nulllogo: string | nullname: string | nullorderCount: number | null+ phone: string | nullstatus: string | nulltaxId: string | nulltype: string | nullupdatedAt: string | nullupdatedBy: string | null+ website: string | null}Relationships: [{@@ -22959,6 +23001,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "customer_currencyCode_fkey"+ columns: ["currencyCode"]+ isOneToOne: false+ referencedRelation: "currencyCode"+ referencedColumns: ["code"]+ },{foreignKeyName: "customer_customerStatusId_fkey"columns: ["customerStatusId"]@@ -28580,12 +28629,15 @@ export type Database = {companyId: string | nullcreatedAt: string | nullcreatedBy: string | null+ currencyCode: string | nullcustomFields: Json | null+ fax: string | nullid: string | nulllogo: string | nullname: string | nullorderCount: number | nullpartCount: number | null+ phone: string | nullstatus: string | nullsupplierStatusId: string | nullsupplierTypeId: string | null@@ -28593,6 +28645,7 @@ export type Database = {type: string | nullupdatedAt: string | nullupdatedBy: string | null+ website: string | null}Relationships: [{@@ -28728,6 +28781,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "supplier_currencyCode_fkey"+ columns: ["currencyCode"]+ isOneToOne: false+ referencedRelation: "currencyCode"+ referencedColumns: ["code"]+ },{foreignKeyName: "supplier_supplierStatusId_fkey"columns: ["supplierStatusId"]diff --git a/packages/database/supabase/migrations/20241009181230_customer-supplier-additional-fields.sql b/packages/database/supabase/migrations/20241009181230_customer-supplier-additional-fields.sqlnew file mode 100644index 0000000000..65ff1be0c2--- /dev/null+++ b/packages/database/supabase/migrations/20241009181230_customer-supplier-additional-fields.sql@@ -0,0 +1,63 @@+-- Customer additional fields+ALTER TABLE "customer" ADD COLUMN "currencyCode" TEXT;+ALTER TABLE "customer" ADD CONSTRAINT "customer_currencyCode_fkey"+ FOREIGN KEY ("currencyCode") REFERENCES "currencyCode"("code")+ ON DELETE SET NULL ON UPDATE CASCADE;++ALTER TABLE "customer" ADD COLUMN "phone" TEXT;+ALTER TABLE "customer" ADD COLUMN "fax" TEXT;+ALTER TABLE "customer" ADD COLUMN "website" TEXT;++DROP VIEW "customers";+CREATE OR REPLACE VIEW "customers" WITH(SECURITY_INVOKER=true) AS+ SELECT+ c.*,+ ct.name AS "type",+ cs.name AS "status",+ so.count AS "orderCount"+ FROM "customer" c+ LEFT JOIN "customerType" ct ON ct.id = c."customerTypeId"+ LEFT JOIN "customerStatus" cs ON cs.id = c."customerStatusId"+ LEFT JOIN (+ SELECT+ "customerId",+ COUNT(*) AS "count"+ FROM "salesOrder"+ GROUP BY "customerId"+ ) so ON so."customerId" = c.id;++-- Supplier additional fields+ALTER TABLE "supplier" ADD COLUMN "currencyCode" TEXT;+ALTER TABLE "supplier" ADD CONSTRAINT "supplier_currencyCode_fkey"+ FOREIGN KEY ("currencyCode") REFERENCES "currencyCode"("code")+ ON DELETE SET NULL ON UPDATE CASCADE;++ALTER TABLE "supplier" ADD COLUMN "phone" TEXT;+ALTER TABLE "supplier" ADD COLUMN "fax" TEXT;+ALTER TABLE "supplier" ADD COLUMN "website" TEXT;++DROP VIEW "suppliers";+CREATE OR REPLACE VIEW "suppliers" WITH(SECURITY_INVOKER=true) AS+ SELECT+ s.*,+ st.name AS "type",+ ss.name AS "status",+ po.count AS "orderCount",+ p.count AS "partCount"+ FROM "supplier" s+ LEFT JOIN "supplierType" st ON st.id = s."supplierTypeId"+ LEFT JOIN "supplierStatus" ss ON ss.id = s."supplierStatusId"+ LEFT JOIN (+ SELECT+ "supplierId",+ COUNT(*) AS "count"+ FROM "purchaseOrder"+ GROUP BY "supplierId"+ ) po ON po."supplierId" = s.id+ LEFT JOIN (+ SELECT+ "supplierId",+ COUNT(*) AS "count"+ FROM "buyMethod"+ GROUP BY "supplierId"+ ) p ON p."supplierId" = s.id;\ No newline at end of file