mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
fix: auto-increment setting parsing. (#453)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { difference } from 'lodash';
|
import { difference, isEmpty } from 'lodash';
|
||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import {
|
import {
|
||||||
@@ -244,16 +244,12 @@ export class CommandManualJournalValidators {
|
|||||||
/**
|
/**
|
||||||
* Validates the manual journal number require.
|
* Validates the manual journal number require.
|
||||||
* @param {string} journalNumber
|
* @param {string} journalNumber
|
||||||
|
* @throws {ServiceError(ERRORS.MANUAL_JOURNAL_NO_REQUIRED)}
|
||||||
*/
|
*/
|
||||||
public validateJournalNoRequireWhenAutoNotEnabled = (
|
public validateJournalNoRequireWhenAutoNotEnabled = (
|
||||||
tenantId: number,
|
|
||||||
journalNumber: string
|
journalNumber: string
|
||||||
) => {
|
) => {
|
||||||
// Retrieve the next manual journal number.
|
if (isEmpty(journalNumber)) {
|
||||||
const autoIncrmenetEnabled =
|
|
||||||
this.autoIncrement.autoIncrementEnabled(tenantId);
|
|
||||||
|
|
||||||
if (!journalNumber || !autoIncrmenetEnabled) {
|
|
||||||
throw new ServiceError(ERRORS.MANUAL_JOURNAL_NO_REQUIRED);
|
throw new ServiceError(ERRORS.MANUAL_JOURNAL_NO_REQUIRED);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ export class CreateManualJournalService {
|
|||||||
|
|
||||||
// Validate manual journal number require when auto-increment not enabled.
|
// Validate manual journal number require when auto-increment not enabled.
|
||||||
this.validator.validateJournalNoRequireWhenAutoNotEnabled(
|
this.validator.validateJournalNoRequireWhenAutoNotEnabled(
|
||||||
tenantId,
|
|
||||||
manualJournalDTO.journalNumber
|
manualJournalDTO.journalNumber
|
||||||
);
|
);
|
||||||
// Validate manual journal uniquiness on the storage.
|
// Validate manual journal uniquiness on the storage.
|
||||||
|
|||||||
@@ -15,10 +15,8 @@ export default class AutoIncrementOrdersService {
|
|||||||
const group = settingsGroup;
|
const group = settingsGroup;
|
||||||
|
|
||||||
// Settings service transaction number and prefix.
|
// Settings service transaction number and prefix.
|
||||||
const autoIncrement = settings.get({ group, key: 'auto_increment' }, false);
|
return settings.get({ group, key: 'auto_increment' }, false);
|
||||||
|
};
|
||||||
return parseBoolean(autoIncrement, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the next service transaction number.
|
* Retrieve the next service transaction number.
|
||||||
@@ -27,17 +25,16 @@ export default class AutoIncrementOrdersService {
|
|||||||
* @param {Function} getMaxTransactionNo
|
* @param {Function} getMaxTransactionNo
|
||||||
* @return {Promise<string>}
|
* @return {Promise<string>}
|
||||||
*/
|
*/
|
||||||
getNextTransactionNumber(tenantId: number, settingsGroup: string): string {
|
getNextTransactionNumber(tenantId: number, group: string): string {
|
||||||
const settings = this.tenancy.settings(tenantId);
|
const settings = this.tenancy.settings(tenantId);
|
||||||
const group = settingsGroup;
|
|
||||||
|
|
||||||
// Settings service transaction number and prefix.
|
// Settings service transaction number and prefix.
|
||||||
const autoIncrement = settings.get({ group, key: 'auto_increment' }, false);
|
const autoIncrement = this.autoIncrementEnabled(tenantId, group);
|
||||||
|
|
||||||
const settingNo = settings.get({ group, key: 'next_number' }, '');
|
const settingNo = settings.get({ group, key: 'next_number' }, '');
|
||||||
const settingPrefix = settings.get({ group, key: 'number_prefix' }, '');
|
const settingPrefix = settings.get({ group, key: 'number_prefix' }, '');
|
||||||
|
|
||||||
return parseBoolean(autoIncrement, false) ? `${settingPrefix}${settingNo}` : '';
|
return autoIncrement ? `${settingPrefix}${settingNo}` : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +50,9 @@ export default class AutoIncrementOrdersService {
|
|||||||
const autoIncrement = settings.get({ group, key: 'auto_increment' });
|
const autoIncrement = settings.get({ group, key: 'auto_increment' });
|
||||||
|
|
||||||
// Can't continue if the auto-increment of the service was disabled.
|
// Can't continue if the auto-increment of the service was disabled.
|
||||||
if (!autoIncrement) { return; }
|
if (!autoIncrement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
settings.set(
|
settings.set(
|
||||||
{ group, key: 'next_number' },
|
{ group, key: 'next_number' },
|
||||||
|
|||||||
@@ -337,6 +337,9 @@ const booleanValues: string[] = [
|
|||||||
].map((value) => normalizeValue(value));
|
].map((value) => normalizeValue(value));
|
||||||
|
|
||||||
export const parseBoolean = <T>(value: any, defaultValue: T): T | boolean => {
|
export const parseBoolean = <T>(value: any, defaultValue: T): T | boolean => {
|
||||||
|
if (typeof value === 'boolean') {
|
||||||
|
return value; // Retrun early we have nothing to parse.
|
||||||
|
}
|
||||||
const normalizedValue = normalizeValue(value);
|
const normalizedValue = normalizeValue(value);
|
||||||
if (isEmpty(value) || booleanValues.indexOf(normalizedValue) === -1) {
|
if (isEmpty(value) || booleanValues.indexOf(normalizedValue) === -1) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user