2022-04-19 05:59:36 +00:00
|
|
|
import { t } from 'fyo';
|
2022-04-24 06:48:44 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
2022-04-29 13:00:24 +00:00
|
|
|
import { FormulaMap, ListsMap, ValidationMap } from 'fyo/model/types';
|
2022-04-22 11:02:03 +00:00
|
|
|
import { validateEmail } from 'fyo/model/validationFunction';
|
2022-04-24 06:48:44 +00:00
|
|
|
import { getCountryInfo, getFiscalYear } from 'utils/misc';
|
2022-04-11 09:41:49 +00:00
|
|
|
|
|
|
|
export function getCOAList() {
|
|
|
|
return [
|
2022-04-18 11:29:20 +00:00
|
|
|
{ name: t`Standard Chart of Accounts`, countryCode: '' },
|
2022-04-11 09:41:49 +00:00
|
|
|
|
|
|
|
{ countryCode: 'ae', name: 'U.A.E - Chart of Accounts' },
|
|
|
|
{
|
|
|
|
countryCode: 'ca',
|
|
|
|
name: 'Canada - Plan comptable pour les provinces francophones',
|
|
|
|
},
|
|
|
|
{ countryCode: 'gt', name: 'Guatemala - Cuentas' },
|
|
|
|
{ countryCode: 'hu', name: 'Hungary - Chart of Accounts' },
|
|
|
|
{ countryCode: 'id', name: 'Indonesia - Chart of Accounts' },
|
|
|
|
{ countryCode: 'in', name: 'India - Chart of Accounts' },
|
|
|
|
{ countryCode: 'mx', name: 'Mexico - Plan de Cuentas' },
|
|
|
|
{ countryCode: 'ni', name: 'Nicaragua - Catalogo de Cuentas' },
|
|
|
|
{ countryCode: 'nl', name: 'Netherlands - Grootboekschema' },
|
|
|
|
{ countryCode: 'sg', name: 'Singapore - Chart of Accounts' },
|
2022-08-28 15:15:51 +00:00
|
|
|
{ countryCode: 'fr', name: 'France - Plan comptable' },
|
|
|
|
/* { countryCode: 'th', name: 'Thailand - Chart of Accounts' },
|
2022-08-24 15:35:13 +00:00
|
|
|
{ countryCode: 'us', name: 'United States - Chart of Accounts' },
|
|
|
|
{ countryCode: 've', name: 'Venezuela - Plan de Cuentas' },
|
|
|
|
{ countryCode: 'za', name: 'South Africa - Chart of Accounts' },
|
|
|
|
{ countryCode: 'de', name: 'Germany - Kontenplan' },
|
|
|
|
{ countryCode: 'it', name: 'Italy - Piano dei Conti' },
|
|
|
|
{ countryCode: 'es', name: 'Spain - Plan de Cuentas' },
|
|
|
|
{ countryCode: 'pt', name: 'Portugal - Plan de Contas' },
|
|
|
|
{ countryCode: 'pl', name: 'Poland - Rejestr Kont' },
|
|
|
|
{ countryCode: 'ro', name: 'Romania - Contabilitate' },
|
|
|
|
{ countryCode: 'ru', name: 'Russia - Chart of Accounts' },
|
|
|
|
{ countryCode: 'se', name: 'Sweden - Kontoplan' },
|
|
|
|
{ countryCode: 'ch', name: 'Switzerland - Kontenplan' },
|
2022-08-28 15:15:51 +00:00
|
|
|
{ countryCode: 'tr', name: 'Turkey - Chart of Accounts' },*/
|
2022-04-11 09:41:49 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SetupWizard extends Doc {
|
|
|
|
formulas: FormulaMap = {
|
2022-04-29 13:00:24 +00:00
|
|
|
fiscalYearStart: {
|
|
|
|
formula: async () => {
|
|
|
|
if (!this.country) return;
|
2022-04-11 09:41:49 +00:00
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
const countryInfo = getCountryInfo();
|
|
|
|
const fyStart =
|
|
|
|
countryInfo[this.country as string]?.fiscal_year_start ?? '';
|
|
|
|
return getFiscalYear(fyStart, true);
|
|
|
|
},
|
|
|
|
dependsOn: ['country'],
|
2022-04-11 09:41:49 +00:00
|
|
|
},
|
2022-04-29 13:00:24 +00:00
|
|
|
fiscalYearEnd: {
|
|
|
|
formula: async () => {
|
|
|
|
if (!this.country) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-11 09:41:49 +00:00
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
const countryInfo = getCountryInfo();
|
|
|
|
const fyEnd =
|
|
|
|
countryInfo[this.country as string]?.fiscal_year_end ?? '';
|
|
|
|
return getFiscalYear(fyEnd, false);
|
|
|
|
},
|
|
|
|
dependsOn: ['country'],
|
2022-04-11 09:41:49 +00:00
|
|
|
},
|
2022-04-29 13:00:24 +00:00
|
|
|
currency: {
|
|
|
|
formula: async () => {
|
|
|
|
if (!this.country) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const countryInfo = getCountryInfo();
|
|
|
|
return countryInfo[this.country as string]?.currency;
|
|
|
|
},
|
|
|
|
dependsOn: ['country'],
|
2022-04-11 09:41:49 +00:00
|
|
|
},
|
2022-04-29 13:00:24 +00:00
|
|
|
chartOfAccounts: {
|
|
|
|
formula: async () => {
|
|
|
|
const country = this.get('country') as string | undefined;
|
|
|
|
if (country === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-11 09:41:49 +00:00
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
const countryInfo = getCountryInfo();
|
|
|
|
const code = (countryInfo[country] as undefined | { code: string })
|
|
|
|
?.code;
|
|
|
|
if (code === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-11 09:41:49 +00:00
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
const coaList = getCOAList();
|
|
|
|
const coa = coaList.find(({ countryCode }) => countryCode === code);
|
2022-04-11 09:41:49 +00:00
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
if (coa === undefined) {
|
|
|
|
return coaList[0].name;
|
|
|
|
}
|
|
|
|
return coa.name;
|
|
|
|
},
|
|
|
|
dependsOn: ['country'],
|
2022-04-11 09:41:49 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-04-22 11:02:03 +00:00
|
|
|
validations: ValidationMap = {
|
|
|
|
email: validateEmail,
|
|
|
|
};
|
|
|
|
|
2022-04-11 09:41:49 +00:00
|
|
|
static lists: ListsMap = {
|
2022-04-23 09:23:44 +00:00
|
|
|
country: () => Object.keys(getCountryInfo()),
|
2022-04-11 09:41:49 +00:00
|
|
|
chartOfAccounts: () => getCOAList().map(({ name }) => name),
|
|
|
|
};
|
|
|
|
}
|