diff --git a/packages/api/src/kysely/migrations/03_create_companies_table.ts b/packages/api/src/kysely/migrations/03_create_companies_table.ts index 4e1c3b4..013ae85 100644 --- a/packages/api/src/kysely/migrations/03_create_companies_table.ts +++ b/packages/api/src/kysely/migrations/03_create_companies_table.ts @@ -23,6 +23,7 @@ export async function up(db: Kysely): Promise { .addColumn('bic', 'varchar', (col) => col.notNull()) .addColumn('default_number_prefix_template', 'varchar') .addColumn('default_locale', 'varchar') + .addColumn('default_currency', 'varchar') .addColumn('created_at', 'text', (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull() diff --git a/packages/api/src/kysely/types.d.ts b/packages/api/src/kysely/types.d.ts index 806ff8a..e0e3659 100644 --- a/packages/api/src/kysely/types.d.ts +++ b/packages/api/src/kysely/types.d.ts @@ -46,6 +46,7 @@ export interface Companies { website?: string | null defaultNumberPrefixTemplate?: string | null defaultLocale?: string | null + defaultCurrency?: 'EUR' | 'USD' | null createdAt: Generated } diff --git a/packages/api/src/repositories/company.ts b/packages/api/src/repositories/company.ts index e336290..b947d3b 100644 --- a/packages/api/src/repositories/company.ts +++ b/packages/api/src/repositories/company.ts @@ -25,7 +25,8 @@ const defaultSelect = [ 'prefix', 'website', 'defaultNumberPrefixTemplate', - 'defaultLocale' + 'defaultLocale', + 'defaultCurrency' ] as (keyof Company)[] function find({ diff --git a/packages/api/src/trpc/admin/companies.ts b/packages/api/src/trpc/admin/companies.ts index bc41658..7678137 100644 --- a/packages/api/src/trpc/admin/companies.ts +++ b/packages/api/src/trpc/admin/companies.ts @@ -39,7 +39,8 @@ export const adminCompanyRoutes = ({ website, prefix, defaultNumberPrefixTemplate, - defaultLocale + defaultLocale, + defaultCurrency } = input let logoSvg = input.logoSvg @@ -69,7 +70,8 @@ export const adminCompanyRoutes = ({ prefix, logoSvg, defaultNumberPrefixTemplate, - defaultLocale + defaultLocale, + defaultCurrency }) if (result) return result @@ -117,7 +119,8 @@ export const adminCompanyRoutes = ({ website, prefix, defaultNumberPrefixTemplate, - defaultLocale + defaultLocale, + defaultCurrency } = input let logoSvg = input.logoSvg @@ -151,7 +154,8 @@ export const adminCompanyRoutes = ({ prefix, logoSvg, defaultNumberPrefixTemplate, - defaultLocale + defaultLocale, + defaultCurrency } ) if (result) return result diff --git a/packages/api/src/zod/company.ts b/packages/api/src/zod/company.ts index df8cd99..d58c415 100644 --- a/packages/api/src/zod/company.ts +++ b/packages/api/src/zod/company.ts @@ -19,7 +19,11 @@ export const companyValidation = { prefix: z.string(), logoSvg: z.string().nullable().optional(), defaultNumberPrefixTemplate: z.string().nullable().optional(), - defaultLocale: z.string().nullable().optional() + defaultLocale: z.string().nullable().optional(), + defaultCurrency: z + .union([z.literal('EUR'), z.literal('USD')]) + .nullable() + .optional() } export const company = z.object(companyValidation) diff --git a/packages/app/src/components/company/CompanyForm.vue b/packages/app/src/components/company/CompanyForm.vue index f2d8e00..63a876b 100644 --- a/packages/app/src/components/company/CompanyForm.vue +++ b/packages/app/src/components/company/CompanyForm.vue @@ -161,15 +161,23 @@ :filtered-options="filteredNumberPrefixes" bottom-slots lazy-rules + name="defaultNumberPrefixTemplate" /> + @@ -183,7 +191,10 @@ import { type ResponsiveDialog } from '@simsustech/quasar-components' import { FormInput } from '@simsustech/quasar-components/form' import SvgAvatar from '../SvgAvatar.vue' import NumberPrefixSelect from '../numberPrefix/NumberPrefixSelect.vue' -import { LocaleSelect } from '@simsustech/quasar-components/form' +import { + LocaleSelect, + CurrencySelect +} from '@simsustech/quasar-components/form' import { Company, NumberPrefix } from '@slimfact/api/zod' export interface Props { form?: QFormProps & Partial & Partial @@ -232,7 +243,8 @@ const initialValue: Company = { prefix: '', website: null, defaultNumberPrefixTemplate: '', - defaultLocale: 'en-US' + defaultLocale: 'en-US', + defaultCurrency: 'EUR' } const modelValue = ref(initialValue) diff --git a/packages/app/src/components/invoice/InvoiceForm.vue b/packages/app/src/components/invoice/InvoiceForm.vue index 769b4f3..276ad45 100644 --- a/packages/app/src/components/invoice/InvoiceForm.vue +++ b/packages/app/src/components/invoice/InvoiceForm.vue @@ -335,6 +335,11 @@ watch( (company) => company.id === newVal )?.defaultLocale if (defaultLocale) modelValue.value.locale = defaultLocale + + const defaultCurrency = filteredCompanies.value.find( + (company) => company.id === newVal + )?.defaultCurrency + if (defaultCurrency) modelValue.value.currency = defaultCurrency } ) @@ -366,7 +371,6 @@ const submitClient: InstanceType< const updateClient: InstanceType< typeof ClientForm >['$props']['onSubmit'] = async ({ data, done }) => { - console.log(data) modelValue.value.clientDetails = data done() diff --git a/packages/app/src/components/subscription/SubscriptionForm.vue b/packages/app/src/components/subscription/SubscriptionForm.vue index bbb7790..1e1cfbb 100644 --- a/packages/app/src/components/subscription/SubscriptionForm.vue +++ b/packages/app/src/components/subscription/SubscriptionForm.vue @@ -330,6 +330,11 @@ watch( (company) => company.id === newVal )?.defaultLocale if (defaultLocale) modelValue.value.locale = defaultLocale + + const defaultCurrency = filteredCompanies.value.find( + (company) => company.id === newVal + )?.defaultCurrency + if (defaultCurrency) modelValue.value.currency = defaultCurrency } ) diff --git a/packages/app/src/lang/en-US.ts b/packages/app/src/lang/en-US.ts index f1b6a8b..9fb4e33 100644 --- a/packages/app/src/lang/en-US.ts +++ b/packages/app/src/lang/en-US.ts @@ -67,7 +67,8 @@ const lang: Language = { prefix: 'Prefix', bic: 'BIC', defaultNumberPrefixTemplate: 'Default number prefix', - defaultLocale: 'Default locale' + defaultLocale: 'Default locale', + defaultCurrency: 'Default currency' }, validations: { fieldRequired: 'Field is required' diff --git a/packages/app/src/lang/index.ts b/packages/app/src/lang/index.ts index d2ddb10..1e3b66f 100644 --- a/packages/app/src/lang/index.ts +++ b/packages/app/src/lang/index.ts @@ -67,6 +67,7 @@ export interface Language { bic: string defaultNumberPrefixTemplate: string defaultLocale: string + defaultCurrency: string } validations: { fieldRequired: string diff --git a/packages/app/src/lang/nl.ts b/packages/app/src/lang/nl.ts index 0d59888..4d9e083 100644 --- a/packages/app/src/lang/nl.ts +++ b/packages/app/src/lang/nl.ts @@ -67,7 +67,8 @@ const lang: Language = { website: 'Website', bic: 'BIC', defaultNumberPrefixTemplate: 'Standaard nummer voorvoegsel', - defaultLocale: 'Standaard regio' + defaultLocale: 'Standaard regio', + defaultCurrency: 'Standaard valuta' }, validations: { fieldRequired: 'Veld is vereist'