Skip to content

Commit

Permalink
feat: add defaultNumberPrefixTemplate to company
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvanherwijnen committed Jul 9, 2024
1 parent 77f00ad commit b7815b6
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export async function up(db: Kysely<unknown>): Promise<void> {
.addColumn('vat_id_number', 'varchar', (col) => col.notNull())
.addColumn('iban', 'varchar', (col) => col.notNull())
.addColumn('bic', 'varchar', (col) => col.notNull())
.addColumn('default_number_prefix_template', 'varchar')

.addColumn('created_at', 'text', (col) =>
col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/kysely/seeds/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ const numberPrefixes: Insertable<NumberPrefixes>[] = [
{
name: 'YYYY.',
template: '{{YYYY}}.'
},
{
name: 'companyDetails.prefix-YYYY-',
template: '{{companyDetails.prefix}}-{{YYYY}}-'
}
]

Expand Down
1 change: 1 addition & 0 deletions packages/api/src/kysely/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface Companies {
telephoneNumber?: string | null
vatIdNumber: string
website?: string | null
defaultNumberPrefixTemplate?: string | null
createdAt: Generated<string>
}

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/repositories/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const defaultSelect = [
'bic',
'logoSvg',
'prefix',
'website'
'website',
'defaultNumberPrefixTemplate'
] as (keyof Company)[]

function find({
Expand Down
6 changes: 4 additions & 2 deletions packages/api/src/trpc/admin/companies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const adminCompanyRoutes = ({
telephoneNumber,
website,
prefix,
logoSvg
logoSvg,
defaultNumberPrefixTemplate
} = input
const result = await createCompany({
name,
Expand All @@ -54,7 +55,8 @@ export const adminCompanyRoutes = ({
telephoneNumber,
website,
prefix,
logoSvg
logoSvg,
defaultNumberPrefixTemplate
})
if (result) return result

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/zod/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const companyValidation = {
website: z.union([z.string().url().nullish(), z.literal('')]),
emailBcc: z.union([z.string().email().nullish(), z.literal('')]),
prefix: z.string(),
logoSvg: z.string().nullable().optional()
logoSvg: z.string().nullable().optional(),
defaultNumberPrefixTemplate: z.string().nullable().optional()
}

export const company = z.object(companyValidation)
Expand Down
24 changes: 17 additions & 7 deletions packages/app/src/components/company/CompanyForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,27 @@
name="emailBcc"
:hint="lang.company.helpers.emailBcc"
/>
<number-prefix-select
v-model="modelValue.defaultNumberPrefixTemplate"
class="col-md-3 col-12"
:label="lang.company.fields.defaultNumberPrefixTemplate"
:filtered-options="filteredNumberPrefixes"
bottom-slots
lazy-rules
/>
</div>
</q-form>
</template>

<script setup lang="ts">
import type { CompanyDetails } from '@modular-api/fastify-checkout'
import { type QFormProps, type QInputProps, type QForm, extend } from 'quasar'
import { useLang } from '../../lang/index.js'
import { ref } from 'vue'
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 { Company, NumberPrefix } from '@slimfact/api/zod'
export interface Props {
form?: QFormProps & Partial<HTMLFormElement> & Partial<HTMLDivElement>
input?: Omit<
Expand All @@ -180,6 +188,7 @@ export interface Props {
| 'autofocus'
| ('label' & { style?: Partial<CSSStyleDeclaration> })
>
filteredNumberPrefixes: NumberPrefix[]
}
defineProps<Props>()
const emit = defineEmits<{
Expand All @@ -189,13 +198,13 @@ const emit = defineEmits<{
data,
done
}: {
data: CompanyDetails
data: Company
done: (success?: boolean) => void
}
): void
}>()
const initialValue: CompanyDetails = {
const initialValue: Company = {
name: '',
address: '',
postalCode: '',
Expand All @@ -210,17 +219,18 @@ const initialValue: CompanyDetails = {
contactPersonName: '',
logoSvg: null,
prefix: '',
website: null
website: null,
defaultNumberPrefixTemplate: ''
}
const modelValue = ref<CompanyDetails>(initialValue)
const modelValue = ref<Company>(initialValue)
// const $q = useQuasar()
const lang = useLang()
const formRef = ref<QForm>()
const setValue = (newValue: CompanyDetails) => {
const setValue = (newValue: Company) => {
modelValue.value = extend({}, initialValue, newValue)
}
Expand Down
25 changes: 18 additions & 7 deletions packages/app/src/components/invoice/InvoiceForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,27 @@ import {
} from '@simsustech/quasar-components/form'
import {
type RawNewInvoice,
type CompanyDetails,
type ClientDetails
} from '@modular-api/fastify-checkout'
import { useLang } from '../../lang/index.js'
import { ref } from 'vue'
import { ref, toRefs, watch } from 'vue'
import CompanySelect from '../company/CompanySelect.vue'
import ClientSelect from '../client/ClientSelect.vue'
import {
InvoiceLineRow,
InvoiceDiscountSurchargeRow
} from '@modular-api/quasar-components/checkout'
import { QForm, extend } from 'quasar'
import { ResponsiveDialog } from '@simsustech/quasar-components'
import NumberPrefixSelect from '../numberPrefix/NumberPrefixSelect.vue'
import { NumberPrefix, Invoice, Company } from '@slimfact/api/zod'
export interface Props {
filteredCompanies: CompanyDetails[]
filteredCompanies: Company[]
filteredClients: ClientDetails[]
filteredNumberPrefixes: NumberPrefix[]
}
import { ResponsiveDialog } from '@simsustech/quasar-components'
import NumberPrefixSelect from '../numberPrefix/NumberPrefixSelect.vue'
import { NumberPrefix, Invoice } from '@slimfact/api/zod'
defineProps<Props>()
const props = defineProps<Props>()
const emit = defineEmits<{
(
Expand Down Expand Up @@ -217,6 +217,8 @@ const initialValue: Invoice = {
projectId: null
}
const { filteredCompanies } = toRefs(props)
const modelValue = ref<Invoice>(initialValue)
const lang = useLang()
Expand Down Expand Up @@ -282,6 +284,15 @@ const setValue = (newValue: RawNewInvoice) => {
modelValue.value.companyId = newValue.companyId || newValue.companyDetails.id
modelValue.value.clientId = newValue.clientId || newValue.clientDetails.id
}
watch(
() => modelValue.value.companyId,
(newVal) => {
modelValue.value.numberPrefixTemplate =
filteredCompanies.value.find((company) => company.id === newVal)
?.defaultNumberPrefixTemplate || ''
}
)
const functions = ref({
submit,
setValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { loadLang, useLang } from '../../lang/index.js'
import { NumberPrefix } from '@slimfact/api/zod'
export interface Props {
modelValue?: string
modelValue?: string | null
filteredOptions: NumberPrefix[]
required?: boolean
onFilter?: unknown
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const lang: Language = {
website: 'Website',
emailBcc: 'Email BCC',
prefix: 'Prefix',
bic: 'BIC'
bic: 'BIC',
defaultNumberPrefixTemplate: 'Default number prefix'
},
validations: {
fieldRequired: 'Field is required'
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/lang/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface Language {
emailBcc: string
prefix: string
bic: string
defaultNumberPrefixTemplate: string
}
validations: {
fieldRequired: string
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/lang/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ const lang: Language = {
vatIdNumber: 'BTW ID nummer',
contactPersonName: 'Naam contact persoon',
prefix: 'Voorvoegsel',
bic: 'BIC',
emailBcc: 'Email BCC',
website: 'Website'
website: 'Website',
bic: 'BIC',
defaultNumberPrefixTemplate: 'Standaard nummer voorvoegsel'
},
validations: {
fieldRequired: 'Veld is vereist'
Expand Down
6 changes: 6 additions & 0 deletions packages/app/src/pages/admin/CompaniesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
<responsive-dialog ref="updateDialogRef" persistent @submit="update">
<company-form
ref="updateCompanyFormRef"
:filtered-number-prefixes="numberPrefixes"
@submit="updateCompany"
></company-form>
</responsive-dialog>
<responsive-dialog ref="createDialogRef" persistent @submit="create">
<company-form
ref="createCompanyFormRef"
:filtered-number-prefixes="numberPrefixes"
@submit="createCompany"
></company-form>
</responsive-dialog>
Expand Down Expand Up @@ -52,6 +54,10 @@ const { data, execute } = useQuery('admin.getCompanies', {
// immediate: true
})
const { data: numberPrefixes } = useQuery('admin.getNumberPrefixes', {
immediate: true
})
const updateCompanyFormRef = ref<typeof CompanyForm>()
const createCompanyFormRef = ref<typeof CompanyForm>()
const updateDialogRef = ref<typeof ResponsiveDialog>()
Expand Down

0 comments on commit b7815b6

Please sign in to comment.