Skip to content

Commit

Permalink
feat: Add tax numbers to the organization details (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
kochie authored Oct 25, 2023
1 parent 2c5537e commit e4a7f09
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
29 changes: 26 additions & 3 deletions packages/server/src/api/controllers/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export default class OrganizationController extends BaseController {

router.post(
'/build',
this.organizationValidationSchema,
this.buildOrganizationValidationSchema,
this.validationResult,
asyncMiddleware(this.build.bind(this)),
this.handleServiceErrors.bind(this)
);
router.put(
'/',
this.organizationValidationSchema,
this.updateOrganizationValidationSchema,
this.validationResult,
this.asyncMiddleware(this.updateOrganization.bind(this)),
this.handleServiceErrors.bind(this)
Expand All @@ -55,7 +55,7 @@ export default class OrganizationController extends BaseController {
* Organization setup schema.
* @return {ValidationChain[]}
*/
private get organizationValidationSchema(): ValidationChain[] {
private get commonOrganizationValidationSchema(): ValidationChain[] {
return [
check('name').exists().trim(),
check('industry').optional({ nullable: true }).isString().trim().escape(),
Expand All @@ -68,6 +68,29 @@ export default class OrganizationController extends BaseController {
];
}

/**
* Build organization validation schema.
* @returns {ValidationChain[]}
*/
private get buildOrganizationValidationSchema(): ValidationChain[] {
return [...this.commonOrganizationValidationSchema];
}

/**
* Update organization validation schema.
* @returns {ValidationChain[]}
*/
private get updateOrganizationValidationSchema(): ValidationChain[] {
return [
...this.commonOrganizationValidationSchema,
check('tax_number')
.optional({ nullable: true })
.isString()
.trim()
.escape(),
];
}

/**
* Builds tenant database and migrate database schema.
* @param {Request} req - Express request.
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/interfaces/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface IOrganizationUpdateDTO {
timezone: string;
fiscalYear: string;
industry: string;
taxNumber: string;
}

export interface IOrganizationBuildEventPayload {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.up = function (knex) {
return knex.schema.table('tenants_metadata', (table) => {
table.string('tax_number')
});
};

exports.down = function (knex) {
return knex.schema.table('tenants_metadata', (table) => {
table.dropColumn('tax_number');
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const Schema = Yup.object().shape({
name: Yup.string()
.required()
.label(intl.get('organization_name_')),
tax_number: Yup.string()
.nullable()
.label(intl.get('organization_tax_number_')),
industry: Yup.string()
.nullable()
.label(intl.get('organization_industry_')),
Expand Down
11 changes: 11 additions & 0 deletions packages/webapp/src/containers/Preferences/General/GeneralForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ export default function PreferencesGeneralForm({ isSubmitting }) {
<FInputGroup medium={'true'} name={'name'} fastField={true} />
</FFormGroup>

{/* ---------- Organization Tax Number ---------- */}
<FFormGroup
name={'tax_number'}
label={<T id={'organization_tax_number'} />}
inline={true}
helperText={<T id={'shown_on_sales_forms_and_purchase_orders'} />}
fastField={true}
>
<FInputGroup medium={'true'} name={'tax_number'} fastField={true} />
</FFormGroup>

{/* ---------- Industry ---------- */}
<FFormGroup
name={'industry'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const defaultValues = {
fiscal_year: '',
date_format: '',
timezone: '',
tax_number: '',
};

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/webapp/src/lang/en/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"success": "Success",
"register_a_new_organization": "Register a New Organization.",
"organization_name": "Organization Name",
"organization_tax_number": "Organization Tax Number",
"email": "Email",
"email_address": "Email Address",
"register": "Register",
Expand Down Expand Up @@ -339,6 +340,7 @@
"item_type_": "Item type",
"item_name_": "Item name",
"organization_industry_": "Organization industry",
"organization_tax_number_": "Organization tax number",
"base_currency_": "Base currency",
"date_format_": "Date format",
"category_name_": "Category name",
Expand Down

0 comments on commit e4a7f09

Please sign in to comment.