Skip to content

Commit 7843ac6

Browse files
feat: add default include tax field to companies
1 parent 43d2a94 commit 7843ac6

File tree

10 files changed

+57
-13
lines changed

10 files changed

+57
-13
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Kysely } from 'kysely'
2+
3+
export async function up(db: Kysely<unknown>): Promise<void> {
4+
await db.schema
5+
.alterTable('companies')
6+
.addColumn('default_include_tax', 'boolean', (col) => col.defaultTo(true))
7+
.execute()
8+
}
9+
10+
export async function down(db: Kysely<unknown>): Promise<void> {
11+
await db.schema
12+
.alterTable('companies')
13+
.dropColumn('default_include_tax')
14+
.execute()
15+
}

packages/api/src/kysely/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface Companies {
5353
defaultNumberPrefixTemplate: string | null
5454
defaultLocale: string | null
5555
defaultCurrency: 'EUR' | 'USD' | null
56+
defaultIncludeTax: Generated<boolean>
5657
createdAt: Generated<string>
5758
}
5859

packages/api/src/repositories/company.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const defaultSelect = [
2626
'website',
2727
'defaultNumberPrefixTemplate',
2828
'defaultLocale',
29-
'defaultCurrency'
29+
'defaultCurrency',
30+
'defaultIncludeTax'
3031
] as (keyof Company)[]
3132

3233
function find({

packages/api/src/trpc/admin/companies.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export const adminCompanyRoutes = ({
4040
prefix,
4141
defaultNumberPrefixTemplate,
4242
defaultLocale,
43-
defaultCurrency
43+
defaultCurrency,
44+
defaultIncludeTax
4445
} = input
4546

4647
let logoSvg = input.logoSvg
@@ -71,7 +72,8 @@ export const adminCompanyRoutes = ({
7172
logoSvg,
7273
defaultNumberPrefixTemplate,
7374
defaultLocale,
74-
defaultCurrency
75+
defaultCurrency,
76+
defaultIncludeTax
7577
})
7678
if (result) return result
7779

@@ -120,7 +122,8 @@ export const adminCompanyRoutes = ({
120122
prefix,
121123
defaultNumberPrefixTemplate,
122124
defaultLocale,
123-
defaultCurrency
125+
defaultCurrency,
126+
defaultIncludeTax
124127
} = input
125128

126129
let logoSvg = input.logoSvg
@@ -155,7 +158,8 @@ export const adminCompanyRoutes = ({
155158
logoSvg,
156159
defaultNumberPrefixTemplate,
157160
defaultLocale,
158-
defaultCurrency
161+
defaultCurrency,
162+
defaultIncludeTax
159163
}
160164
)
161165
if (result) return result

packages/api/src/zod/company.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export const companyValidation = {
3838
defaultCurrency: z
3939
.union([z.literal('EUR'), z.literal('USD')])
4040
.nullable()
41-
.optional()
41+
.optional(),
42+
defaultIncludeTax: z.boolean().optional()
4243
}
4344

4445
export const company = z.object(companyValidation)

packages/app/src/components/company/CompanyForm.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@
190190
lazy-rules
191191
name="defaultCurrency"
192192
/>
193+
<boolean-select
194+
v-model="modelValue.defaultIncludeTax"
195+
:label="lang.company.fields.defaultIncludeTax"
196+
class="md:col-span-3 col-span-12"
197+
bottom-slots
198+
lazy-rules
199+
name="defaultIncludeTax"
200+
/>
193201
</div>
194202
</q-form>
195203
</template>
@@ -204,7 +212,8 @@ import SvgAvatar from '../SvgAvatar.vue'
204212
import NumberPrefixSelect from '../numberPrefix/NumberPrefixSelect.vue'
205213
import {
206214
LocaleSelect,
207-
CurrencySelect
215+
CurrencySelect,
216+
BooleanSelect
208217
} from '@simsustech/quasar-components/form'
209218
import { Company, NumberPrefix } from '@slimfact/api/zod'
210219
export interface Props {
@@ -255,7 +264,8 @@ const initialValue: Company = {
255264
website: null,
256265
defaultNumberPrefixTemplate: '',
257266
defaultLocale: 'en-US',
258-
defaultCurrency: 'EUR'
267+
defaultCurrency: 'EUR',
268+
defaultIncludeTax: true
259269
}
260270
261271
const modelValue = ref<Company>(initialValue)

packages/app/src/components/invoice/InvoiceForm.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ const filterClients: InstanceType<
333333
const addLine = () => {
334334
modelValue.value.lines.push({
335335
listPrice: 0,
336-
listPriceIncludesTax: true,
336+
listPriceIncludesTax: includeTax.value,
337337
taxRate: 21,
338338
description: '',
339339
quantity: 1000,
@@ -408,6 +408,8 @@ const setValue = (newValue: RawNewInvoice) => {
408408
}
409409
}
410410
411+
const includeTax = ref(true)
412+
411413
watch(
412414
() => modelValue.value.companyId,
413415
(newVal) => {
@@ -421,12 +423,19 @@ watch(
421423
const defaultLocale = filteredCompanies.value.find(
422424
(company) => company.id === newVal
423425
)?.defaultLocale
424-
if (defaultLocale) modelValue.value.locale = defaultLocale
426+
if (defaultLocale !== void 0 && defaultLocale !== null)
427+
modelValue.value.locale = defaultLocale
425428
426429
const defaultCurrency = filteredCompanies.value.find(
427430
(company) => company.id === newVal
428431
)?.defaultCurrency
429-
if (defaultCurrency) modelValue.value.currency = defaultCurrency
432+
if (defaultCurrency !== void 0 && defaultCurrency !== null)
433+
modelValue.value.currency = defaultCurrency
434+
435+
const defaultIncludeTax = filteredCompanies.value.find(
436+
(company) => company.id === newVal
437+
)?.defaultIncludeTax
438+
if (defaultIncludeTax !== void 0) includeTax.value = defaultIncludeTax
430439
}
431440
)
432441

packages/app/src/lang/en-US.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ const lang: Language = {
7070
bic: 'BIC',
7171
defaultNumberPrefixTemplate: 'Default number prefix',
7272
defaultLocale: 'Default locale',
73-
defaultCurrency: 'Default currency'
73+
defaultCurrency: 'Default currency',
74+
defaultIncludeTax: 'Default incl. VAT'
7475
},
7576
validations: {
7677
fieldRequired: 'Field is required'

packages/app/src/lang/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface Language {
7070
defaultNumberPrefixTemplate: string
7171
defaultLocale: string
7272
defaultCurrency: string
73+
defaultIncludeTax: string
7374
}
7475
validations: {
7576
fieldRequired: string

packages/app/src/lang/nl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ const lang: Language = {
7070
bic: 'BIC',
7171
defaultNumberPrefixTemplate: 'Standaard nummer voorvoegsel',
7272
defaultLocale: 'Standaard regio',
73-
defaultCurrency: 'Standaard valuta'
73+
defaultCurrency: 'Standaard valuta',
74+
defaultIncludeTax: 'Standaard incl. btw'
7475
},
7576
validations: {
7677
fieldRequired: 'Veld is vereist'

0 commit comments

Comments
 (0)