@silexpert/core 1.1.33 → 1.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/types/Interface/api/registration/ReadRegistration.d.ts +4 -2
- package/es/types/Interface/api/registration/ReadRegistration.d.ts.map +1 -1
- package/es/types/Interface/api/registration/ReadRegistration.js +2 -1
- package/es/types/Interface/api/registration/ReadRegistration.js.map +1 -1
- package/es/utils/vat/3310/century23.d.ts.map +1 -1
- package/es/utils/vat/3310/century23.js +33 -33
- package/es/utils/vat/3310/century23.js.map +1 -1
- package/es/utils/vat/3517/century23.d.ts.map +1 -1
- package/es/utils/vat/3517/century23.js +17 -16
- package/es/utils/vat/3517/century23.js.map +1 -1
- package/es/utils/vat/utils.d.ts +1 -0
- package/es/utils/vat/utils.d.ts.map +1 -1
- package/es/utils/vat/utils.js +3 -0
- package/es/utils/vat/utils.js.map +1 -1
- package/js/types/Interface/api/registration/ReadRegistration.js +2 -0
- package/js/types/Interface/api/registration/ReadRegistration.js.map +1 -1
- package/js/utils/vat/3310/century23.js +26 -26
- package/js/utils/vat/3310/century23.js.map +1 -1
- package/js/utils/vat/3517/century23.js +15 -14
- package/js/utils/vat/3517/century23.js.map +1 -1
- package/js/utils/vat/utils.js +4 -0
- package/js/utils/vat/utils.js.map +1 -1
- package/package.json +1 -1
- package/ts/types/Interface/api/registration/ReadRegistration.ts +7 -1
- package/ts/utils/vat/3310/century23.ts +34 -33
- package/ts/utils/vat/3517/century23.ts +17 -16
- package/ts/utils/vat/utils.ts +4 -0
package/js/utils/vat/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getAmountByAccountNumber = getAmountByAccountNumber;
|
|
7
|
+
exports.setZeroIfIsNegative = setZeroIfIsNegative;
|
|
7
8
|
exports.getTaxAmountByAccountNumber = getTaxAmountByAccountNumber;
|
|
8
9
|
exports.textFormatting = textFormatting;
|
|
9
10
|
var _lodash = require("lodash");
|
|
@@ -23,6 +24,9 @@ function getAmountByAccountNumber(accountingEntries, accountsNumber, precision =
|
|
|
23
24
|
}, 0), precision);
|
|
24
25
|
return isAbs ? Math.abs(result) : result;
|
|
25
26
|
}
|
|
27
|
+
function setZeroIfIsNegative(value) {
|
|
28
|
+
return value < 0 ? 0 : value;
|
|
29
|
+
}
|
|
26
30
|
function getTaxAmountByAccountNumber(accountingEntries, accountsNumber, precision = 0) {
|
|
27
31
|
const accountingEntriesUniq = (0, _lodash.uniqBy)(accountingEntries, 'id');
|
|
28
32
|
return (0, _lodash.round)(accountingEntriesUniq.reduce((acc, accountingEntry) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["getAmountByAccountNumber","exports","getTaxAmountByAccountNumber","textFormatting","_lodash","require","_Vat","accountingEntries","accountsNumber","precision","isAbs","accountingEntriesUniq","_uniqBy","result","_round","reduce","acc","accountingEntry","accTmp","some","number","account","toString","startsWith","debit","credit","Math","abs","_b","_a","Object","values","Vat","find","v","id","idVat","
|
|
1
|
+
{"version":3,"file":"utils.js","names":["getAmountByAccountNumber","exports","setZeroIfIsNegative","getTaxAmountByAccountNumber","textFormatting","_lodash","require","_Vat","accountingEntries","accountsNumber","precision","isAbs","accountingEntriesUniq","_uniqBy","result","_round","reduce","acc","accountingEntry","accTmp","some","number","account","toString","startsWith","debit","credit","Math","abs","value","_b","_a","Object","values","Vat","find","v","id","idVat","length","formattedValue","replace","slice"],"sources":["../../../ts/utils/vat/utils.ts"],"sourcesContent":["import { round as _round, uniqBy as _uniqBy } from 'lodash';\nimport { IAccountingEntry } from '../../types/Interface/models/IAccountingEntry';\nimport { Vat } from '../../types/Enum/Vat';\n\nexport function getAmountByAccountNumber(accountingEntries: IAccountingEntry[], accountsNumber: string[], precision = 0, isAbs = false): number {\n const accountingEntriesUniq = _uniqBy(accountingEntries, 'id');\n const result = _round(accountingEntriesUniq.reduce((acc, accountingEntry) => {\n let accTmp = acc;\n accountsNumber.some((number) => {\n if (accountingEntry.account && accountingEntry.account.number && accountingEntry.account.number.toString().startsWith(number)) {\n accTmp += accountingEntry.debit - accountingEntry.credit;\n return true;\n }\n return false;\n });\n return accTmp;\n }, 0), precision);\n return isAbs ? Math.abs(result) : result;\n}\n\nexport function setZeroIfIsNegative(value: number): number {\n return value < 0 ? 0 : value;\n}\n\nexport function getTaxAmountByAccountNumber(accountingEntries: IAccountingEntry[], accountsNumber: string[], precision = 0): number {\n const accountingEntriesUniq = _uniqBy(accountingEntries, 'id');\n return _round(accountingEntriesUniq.reduce((acc, accountingEntry) => {\n let accTmp = acc;\n accountsNumber.some((number) => {\n if (accountingEntry.account && accountingEntry.account.number && accountingEntry.account.number.toString().startsWith(number)) {\n accTmp += ((accountingEntry.debit - accountingEntry.credit) * (((Object.values(Vat).find((v) => v.id === accountingEntry.idVat)?.value ?? 0) / 100)));\n return true;\n }\n return false;\n });\n return accTmp;\n }, precision));\n}\n\nexport function textFormatting(value: any, length: number | null = null): string | null {\n if (value && typeof value === 'string') {\n let formattedValue = value.replace(/[\\u2018\\u2019]/g, '\\''); // Suppression des \"Curly Quotes\"\n formattedValue = formattedValue.replace(/&/g, ''); // Suppression des &\n formattedValue = formattedValue.replace(/!/g, ''); // Suppression des !\n formattedValue = formattedValue.replace(/[\\t]/g, ''); // Suppression des tabulations\n formattedValue = formattedValue.replace(/`/g, '\\''); // Suppression des `\n formattedValue = formattedValue.replace(/\"/g, ''); // Suppression des \"\n formattedValue = formattedValue.replace(/^ */, ''); // Suppression des espaces de début\n formattedValue = formattedValue.replace(/ *$/, ''); // Suppression des espaces de fin\n if (length) formattedValue = formattedValue.slice(0, length);\n return formattedValue;\n }\n return null;\n}"],"mappings":";;;;;QAIgBA,wBAAwB,GAAxBA,wBAAwB;AAAAC,OAAA,CAgBxBC,mBAAmB,GAAnBA,mBAAmB;AAAAD,OAAA,CAInBE,2BAA2B,GAA3BA,2BAA2B;A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ACrDD,cAAc,GAAGA,cAAc,CAACC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IACnDD,cAAc,GAAGA,cAAc,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IACpDD,cAAc,GAAGA,cAAc,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IACpD,IAAIF,MAAM,EAAEC,cAAc,GAAGA,cAAc,CAACE,KAAK,CAAC,CAAC,EAAEH,MAAM,CAAC;IAC5D,OAAOC,cAAc;;EAEvB,OAAO,IAAI;AACb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silexpert/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.35",
|
|
4
4
|
"description": "Silex Core perform HTTP Request and object binding. Silex core helps developers to retrieve and return formatted object",
|
|
5
5
|
"homepage": "https://gitlab.compta-clementine.fr/dev/silex-api",
|
|
6
6
|
"main": "js/index.js",
|
|
@@ -26,6 +26,7 @@ export interface ReadRegistrationTick {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface ReadVatEntry {
|
|
29
|
+
isAsset: boolean;
|
|
29
30
|
idVat: number | null;
|
|
30
31
|
account: IAccount | null;
|
|
31
32
|
totalTaxIncluded: number;
|
|
@@ -38,4 +39,9 @@ export interface ReadVatEntry {
|
|
|
38
39
|
entry?: IAccountingEntry
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
export
|
|
42
|
+
export class UpdatedAnnotationObject {
|
|
43
|
+
old: IAccountingEntry[];
|
|
44
|
+
new: IAccountingEntry[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type UpdatedAnnotation = UpdatedAnnotationObject[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as dayjs from 'dayjs';
|
|
2
2
|
import { isDefined } from 'class-validator';
|
|
3
|
-
import { round as _round, flatten } from 'lodash';
|
|
3
|
+
import { round as _round, flatten, uniqBy } from 'lodash';
|
|
4
4
|
import { IAccountingEntry } from '../../../types/Interface/models/IAccountingEntry';
|
|
5
5
|
import { Cerfa3310_2023, PayloadCerfa3310_2023 } from '../../../types/Interface/api/cerfa/3310';
|
|
6
6
|
import { Vat } from '../../../types/Enum/Vat';
|
|
7
|
-
import { getAmountByAccountNumber, getTaxAmountByAccountNumber, textFormatting } from '../utils';
|
|
7
|
+
import { getAmountByAccountNumber, getTaxAmountByAccountNumber, setZeroIfIsNegative, textFormatting } from '../utils';
|
|
8
8
|
import { AsponeFormFields, CerfaPayloadForm } from '../../../types/Interface/api/cerfa/ReadCerfa';
|
|
9
9
|
import { UpdatedAnnotation } from '../../../types/Interface/api/registration/ReadRegistration';
|
|
10
10
|
|
|
@@ -18,7 +18,7 @@ export function getCerfa3310Century23Payload(accountingEntries: IAccountingEntry
|
|
|
18
18
|
const withoutTaxVat = vats.filter((v) => v.value === 0).map((v) => v.id);
|
|
19
19
|
const importationVat = vats.filter((v) => v.isVatImportation && !v.isVatIntracom).map((v) => v.id);
|
|
20
20
|
|
|
21
|
-
const vatEntries = accountingEntries.filter((ae) => typeof ae.idVat === 'number') as Array<IAccountingEntry & { idVat: number }>;
|
|
21
|
+
const vatEntries = uniqBy(accountingEntries.filter((ae) => typeof ae.idVat === 'number'), 'id') as Array<IAccountingEntry & { idVat: number }>;
|
|
22
22
|
|
|
23
23
|
const oldEntries = flatten(updatedEntries?.map((u) => u.old));
|
|
24
24
|
const newEntries = flatten(updatedEntries?.map((u) => u.new));
|
|
@@ -44,60 +44,61 @@ export function getCerfa3310Century23Payload(accountingEntries: IAccountingEntry
|
|
|
44
44
|
// Opérations taxées
|
|
45
45
|
const taxedServicesEntries = vatEntries.filter((ae) => frenchVat.includes(ae.idVat) && withTaxVat.includes(ae.idVat));
|
|
46
46
|
const servicesAccounts = ['701', '702', '703', '704', '705', '706', '707', '708', '472'];
|
|
47
|
-
const taxedServicesFromFrance = getAmountByAccountNumber(taxedServicesEntries, servicesAccounts, 0, true);
|
|
48
|
-
const taxedOther = getAmountByAccountNumber(vatEntries.filter((ae) => withTaxVat.includes(ae.idVat)), ['775'], 0, true);
|
|
47
|
+
const taxedServicesFromFrance = setZeroIfIsNegative(getAmountByAccountNumber(taxedServicesEntries, servicesAccounts, 0, true));
|
|
48
|
+
const taxedOther = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => withTaxVat.includes(ae.idVat)), ['775'], 0, true));
|
|
49
49
|
const intracommunityServiceAccounts = ['604', '611', '612', '613', '614', '615', '616', '617', '618', '619', '62'];
|
|
50
50
|
const intracommunityServiceEntries = vatEntries.filter((ae) => withTaxVat.includes(ae.idVat) && intracomVat.includes(ae.idVat));
|
|
51
|
-
const taxedPurchaseOfIntracommunityService = getAmountByAccountNumber(intracommunityServiceEntries, intracommunityServiceAccounts, 0, true);
|
|
51
|
+
const taxedPurchaseOfIntracommunityService = setZeroIfIsNegative(getAmountByAccountNumber(intracommunityServiceEntries, intracommunityServiceAccounts, 0, true));
|
|
52
52
|
const taxedImportEntries = vatEntries.filter((ae) => importationVat.includes(ae.idVat) && withTaxVat.includes(ae.idVat));
|
|
53
53
|
const taxedImportAccounts = ['6'];
|
|
54
|
-
const taxedImport = getAmountByAccountNumber(taxedImportEntries, taxedImportAccounts, 0, true);
|
|
55
|
-
const taxedIntracommunityAcquisitions = getAmountByAccountNumber(vatEntries.filter((ae) => intracomVat.includes(ae.idVat) && withTaxVat.includes(ae.idVat)), ['601', '602', '603', '605', '606', '607'], 0, true);
|
|
54
|
+
const taxedImport = setZeroIfIsNegative(getAmountByAccountNumber(taxedImportEntries, taxedImportAccounts, 0, true));
|
|
55
|
+
const taxedIntracommunityAcquisitions = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => intracomVat.includes(ae.idVat) && withTaxVat.includes(ae.idVat)), ['601', '602', '603', '605', '606', '607'], 0, true));
|
|
56
56
|
// Opérations non taxées
|
|
57
|
-
const untaxedExportationNotInEurope = getAmountByAccountNumber(vatEntries.filter((ae) => importationVat.includes(ae.idVat) && withoutTaxVat.includes(ae.idVat)), servicesAccounts, 0, true);
|
|
58
|
-
const untaxedOther = getAmountByAccountNumber(vatEntries.filter((ae) => frenchVat.includes(ae.idVat) && withoutTaxVat.includes(ae.idVat)), ['7'], 0, true);
|
|
59
|
-
const untaxedImport = getAmountByAccountNumber(vatEntries.filter((ae) => importationVat.includes(ae.idVat) && withoutTaxVat.includes(ae.idVat)), ['6'], 0, true);
|
|
60
|
-
const untaxedIntracomunity = getAmountByAccountNumber(vatEntries.filter((ae) => intracomVat.includes(ae.idVat) && withoutTaxVat.includes(ae.idVat)), ['601', '602', '603', '605', '606', '607'], 0, true);
|
|
61
|
-
const untaxedIntracommunityDelivery = getAmountByAccountNumber(vatEntries.filter((ae) => withoutTaxVat.includes(ae.idVat) && intracomVat.includes(ae.idVat)), ['701', '707'], 0, true);
|
|
57
|
+
const untaxedExportationNotInEurope = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => importationVat.includes(ae.idVat) && withoutTaxVat.includes(ae.idVat)), servicesAccounts, 0, true));
|
|
58
|
+
const untaxedOther = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => frenchVat.includes(ae.idVat) && withoutTaxVat.includes(ae.idVat)), ['7'], 0, true));
|
|
59
|
+
const untaxedImport = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => importationVat.includes(ae.idVat) && withoutTaxVat.includes(ae.idVat)), ['6'], 0, true));
|
|
60
|
+
const untaxedIntracomunity = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => intracomVat.includes(ae.idVat) && withoutTaxVat.includes(ae.idVat)), ['601', '602', '603', '605', '606', '607'], 0, true));
|
|
61
|
+
const untaxedIntracommunityDelivery = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => withoutTaxVat.includes(ae.idVat) && intracomVat.includes(ae.idVat)), ['701', '707'], 0, true));
|
|
62
62
|
// TVA brute
|
|
63
|
-
const normalRate = getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 20).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
64
|
-
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 20).map((v) => v.id).includes(e.idVat)), ['6'], 0, true);
|
|
63
|
+
const normalRate = setZeroIfIsNegative(getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 20).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
64
|
+
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 20).map((v) => v.id).includes(e.idVat)), ['6'], 0, true));
|
|
65
|
+
|
|
65
66
|
const normalRateTax = _round(normalRate * 0.2);
|
|
66
67
|
|
|
67
|
-
const reducedRate5Dot5 = getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 5.5).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
68
|
-
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 5.5).map((v) => v.id).includes(e.idVat)), ['6'], 0, true);
|
|
68
|
+
const reducedRate5Dot5 = setZeroIfIsNegative(getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 5.5).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
69
|
+
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 5.5).map((v) => v.id).includes(e.idVat)), ['6'], 0, true));
|
|
69
70
|
const reducedRate5Dot5Tax = _round(reducedRate5Dot5 * 0.055);
|
|
70
71
|
|
|
71
|
-
const reducedRate10 = getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 10).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
72
|
-
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 10).map((v) => v.id).includes(e.idVat)), ['6'], 0, true);
|
|
72
|
+
const reducedRate10 = setZeroIfIsNegative(getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 10).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
73
|
+
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 10).map((v) => v.id).includes(e.idVat)), ['6'], 0, true));
|
|
73
74
|
const reducedRate10Tax = _round(reducedRate10 * 0.1);
|
|
74
75
|
|
|
75
|
-
const reducedRate8Dot5 = getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 8.5).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
76
|
-
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 8.5).map((v) => v.id).includes(e.idVat)), ['6'], 0, true);
|
|
76
|
+
const reducedRate8Dot5 = setZeroIfIsNegative(getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 8.5).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
77
|
+
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 8.5).map((v) => v.id).includes(e.idVat)), ['6'], 0, true));
|
|
77
78
|
const reducedRate8Dot5Tax = _round(reducedRate8Dot5 * 0.085);
|
|
78
79
|
|
|
79
|
-
const reducedRate2Dot1 = getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 2.1).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
80
|
-
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 2.1).map((v) => v.id).includes(e.idVat)), ['6'], 0, true);
|
|
80
|
+
const reducedRate2Dot1 = setZeroIfIsNegative(getAmountByAccountNumber(taxedServicesEntries.filter((e) => vats.filter((v) => v.value === 2.1).map((v) => v.id).includes(e.idVat)), servicesAccounts, 0, true)
|
|
81
|
+
+ getAmountByAccountNumber(intracommunityServiceEntries.filter((e) => vats.filter((v) => v.value === 2.1).map((v) => v.id).includes(e.idVat)), ['6'], 0, true));
|
|
81
82
|
const reducedRate2Dot1Tax = _round(reducedRate2Dot1 * 0.021);
|
|
82
83
|
|
|
83
|
-
const importNormalRate = getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 20).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true);
|
|
84
|
+
const importNormalRate = setZeroIfIsNegative(getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 20).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true));
|
|
84
85
|
const importNormalRateTax = _round(importNormalRate * 0.2);
|
|
85
|
-
const importReducedRate10 = getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 10).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true);
|
|
86
|
+
const importReducedRate10 = setZeroIfIsNegative(getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 10).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true));
|
|
86
87
|
const importReducedRate10Tax = _round(importReducedRate10 * 0.1);
|
|
87
|
-
const importReducedRate8Dot5 = getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 8.5).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true);
|
|
88
|
+
const importReducedRate8Dot5 = setZeroIfIsNegative(getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 8.5).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true));
|
|
88
89
|
const importReducedRate8Dot5Tax = _round(importReducedRate8Dot5 * 0.085);
|
|
89
|
-
const importReducedRate5Dot5 = getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 5.5).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true);
|
|
90
|
+
const importReducedRate5Dot5 = setZeroIfIsNegative(getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 5.5).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true));
|
|
90
91
|
const importReducedRate5Dot5Tax = _round(importReducedRate8Dot5 * 0.055);
|
|
91
|
-
const importReducedRate2Dot1 = getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 2.1).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true);
|
|
92
|
+
const importReducedRate2Dot1 = setZeroIfIsNegative(getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 2.1).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true));
|
|
92
93
|
const importReducedRate2Dot1Tax = _round(importReducedRate2Dot1 * 0.021);
|
|
93
|
-
const importReducedRate1Dot05 = getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 1.05).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true);
|
|
94
|
+
const importReducedRate1Dot05 = setZeroIfIsNegative(getAmountByAccountNumber(taxedImportEntries.filter((e) => vats.filter((v) => v.value === 1.05).map((v) => v.id).includes(e.idVat)), taxedImportAccounts, 0, true));
|
|
94
95
|
const importReducedRate1Dot05Tax = _round(importReducedRate1Dot05 * 0.0105);
|
|
95
|
-
const intracommunityTax = getTaxAmountByAccountNumber(intracommunityServiceEntries, intracommunityServiceAccounts);
|
|
96
|
+
const intracommunityTax = setZeroIfIsNegative(getTaxAmountByAccountNumber(intracommunityServiceEntries, intracommunityServiceAccounts));
|
|
96
97
|
|
|
97
98
|
// TVA Déductible
|
|
98
|
-
const immobilizationTax = getTaxAmountByAccountNumber(vatEntries, ['2']);
|
|
99
|
-
const otherGoodsAndServices = getTaxAmountByAccountNumber(vatEntries.filter((e) => vats.filter((v) => !v.isVatImportation).map((v) => v.id).includes(e.idVat)), ['6']);
|
|
100
|
-
const otherDeductibles = getTaxAmountByAccountNumber(vatEntries.filter((e) => vats.filter((v) => v.isVatImportation).map((v) => v.id).includes(e.idVat)), ['6']);
|
|
99
|
+
const immobilizationTax = setZeroIfIsNegative(getTaxAmountByAccountNumber(vatEntries, ['2']));
|
|
100
|
+
const otherGoodsAndServices = setZeroIfIsNegative(getTaxAmountByAccountNumber(vatEntries.filter((e) => vats.filter((v) => !v.isVatImportation).map((v) => v.id).includes(e.idVat)), ['6']));
|
|
101
|
+
const otherDeductibles = setZeroIfIsNegative(getTaxAmountByAccountNumber(vatEntries.filter((e) => vats.filter((v) => v.isVatImportation).map((v) => v.id).includes(e.idVat)), ['6']));
|
|
101
102
|
const report = payload.previousVatDeclaration?.credit?.toReport ?? 0;
|
|
102
103
|
|
|
103
104
|
const coefficient = _round(payload.vat?.deductible?.coefficient ?? 100, 2);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as dayjs from 'dayjs';
|
|
2
2
|
import { isDefined } from 'class-validator';
|
|
3
|
-
import { round as _round } from 'lodash';
|
|
3
|
+
import { round as _round, uniqBy } from 'lodash';
|
|
4
4
|
import { Cerfa3517_2023, PayloadCerfa3517_2023 } from '../../../types/Interface/api/cerfa/3517';
|
|
5
5
|
import { IAccountingEntry } from '../../../types/Interface/models/IAccountingEntry';
|
|
6
6
|
import { Vat } from '../../../types/Enum/Vat';
|
|
7
|
-
import { getAmountByAccountNumber, getTaxAmountByAccountNumber, textFormatting } from '../utils';
|
|
7
|
+
import { getAmountByAccountNumber, getTaxAmountByAccountNumber, setZeroIfIsNegative, textFormatting } from '../utils';
|
|
8
8
|
import { Cerfa3514_2022, CerfaPayloadForm, IRegistration } from '../../../types';
|
|
9
9
|
|
|
10
10
|
export function getCerfa3517Century23Payload(accountingEntries: IAccountingEntry[], payload: PayloadCerfa3517_2023): Cerfa3517_2023 {
|
|
@@ -13,33 +13,34 @@ export function getCerfa3517Century23Payload(accountingEntries: IAccountingEntry
|
|
|
13
13
|
const isNil = payload.isNil === true;
|
|
14
14
|
const vats = Object.values(Vat);
|
|
15
15
|
|
|
16
|
-
const vatEntries = accountingEntries.filter((ae) => typeof ae.idVat === 'number') as Array<IAccountingEntry & { idVat: number }>;
|
|
16
|
+
const vatEntries = uniqBy(accountingEntries.filter((ae) => typeof ae.idVat === 'number'), 'id') as Array<IAccountingEntry & { idVat: number }>;
|
|
17
17
|
|
|
18
18
|
const withoutTaxVat = vats.filter((v) => v.value === 0).map((v) => v.id);
|
|
19
19
|
const intracomVat = vats.filter((v) => v.isVatIntracom && !v.isVatImportation).map((v) => v.id);
|
|
20
20
|
const frenchVat = vats.filter((v) => !v.isVatImportation && !v.isVatIntracom).map((v) => v.id);
|
|
21
|
+
const importationVat = vats.filter((v) => v.isVatImportation && !v.isVatIntracom).map((v) => v.id);
|
|
21
22
|
|
|
22
|
-
const taxedOperationsAccounts = ['701', '702', '703', '704', '705', '706', '707', '708'];
|
|
23
|
+
const taxedOperationsAccounts = ['701', '702', '703', '704', '705', '706', '707', '708', '472'];
|
|
23
24
|
|
|
24
|
-
const vatNormalRate20 = getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_20.id), taxedOperationsAccounts, 0, true);
|
|
25
|
-
const vatReducedRate5Dot5 = getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_5_5.id), taxedOperationsAccounts, 0, true);
|
|
26
|
-
const vatReducedRate10 = getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_10.id), taxedOperationsAccounts, 0, true);
|
|
27
|
-
const vatReducedRate8Dot5 = getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_8_5.id), taxedOperationsAccounts, 0, true);
|
|
28
|
-
const vatReducedRate2Dot1 = getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_2_1.id), taxedOperationsAccounts, 0, true);
|
|
25
|
+
const vatNormalRate20 = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_20.id), taxedOperationsAccounts, 0, true));
|
|
26
|
+
const vatReducedRate5Dot5 = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_5_5.id), taxedOperationsAccounts, 0, true));
|
|
27
|
+
const vatReducedRate10 = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_10.id), taxedOperationsAccounts, 0, true));
|
|
28
|
+
const vatReducedRate8Dot5 = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_8_5.id), taxedOperationsAccounts, 0, true));
|
|
29
|
+
const vatReducedRate2Dot1 = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => ae.idVat === Vat.TX_2_1.id), taxedOperationsAccounts, 0, true));
|
|
29
30
|
|
|
30
31
|
const prestation2Entries = vatEntries.filter((ae) => intracomVat.includes(ae.idVat));
|
|
31
32
|
const presta2Accounts = ['604', '61', '62'];
|
|
32
|
-
const prestation2Base = getAmountByAccountNumber(prestation2Entries, presta2Accounts, 0, true);
|
|
33
|
-
const prestation2AmountOfVat = getTaxAmountByAccountNumber(prestation2Entries, presta2Accounts);
|
|
33
|
+
const prestation2Base = setZeroIfIsNegative(getAmountByAccountNumber(prestation2Entries, presta2Accounts, 0, true));
|
|
34
|
+
const prestation2AmountOfVat = setZeroIfIsNegative(getTaxAmountByAccountNumber(prestation2Entries, presta2Accounts));
|
|
34
35
|
|
|
35
|
-
const saleOfImmobilization = getAmountByAccountNumber(vatEntries.filter((ae) => !withoutTaxVat.includes(ae.idVat) && frenchVat.includes(ae.idVat)), ['775'], 0, true);
|
|
36
|
+
const saleOfImmobilization = setZeroIfIsNegative(getAmountByAccountNumber(vatEntries.filter((ae) => !withoutTaxVat.includes(ae.idVat) && frenchVat.includes(ae.idVat)), ['775'], 0, true));
|
|
36
37
|
|
|
37
|
-
const onInvoiceDeductible =
|
|
38
|
-
const onImmobilizationDeductible =
|
|
38
|
+
const onInvoiceDeductible = setZeroIfIsNegative(getTaxAmountByAccountNumber(vatEntries.filter(ae => !importationVat.includes(ae.idVat)), ['6']));
|
|
39
|
+
const onImmobilizationDeductible = setZeroIfIsNegative(getTaxAmountByAccountNumber(vatEntries, ['2']));
|
|
39
40
|
|
|
40
|
-
const julyAdvance: IRegistration | null = payload?.exerciceAdvanceRegistrations?.find((a) => dayjs(a.endDate).month()
|
|
41
|
+
const julyAdvance: IRegistration | null = payload?.exerciceAdvanceRegistrations?.find((a) => [5, 6].includes(dayjs(a.endDate).month())) ?? null;
|
|
41
42
|
const julyAdvancePayload: Cerfa3514_2022 | null = julyAdvance?.payload?.cerfa3514 ?? null;
|
|
42
|
-
const decemberAdvance: IRegistration | null = payload?.exerciceAdvanceRegistrations?.find((a) => dayjs(a.endDate).month()
|
|
43
|
+
const decemberAdvance: IRegistration | null = payload?.exerciceAdvanceRegistrations?.find((a) => [10, 11].includes(dayjs(a.endDate).month())) ?? null;
|
|
43
44
|
const decemberAdvancePayload: Cerfa3514_2022 | null = decemberAdvance?.payload?.cerfa3514 ?? null;
|
|
44
45
|
|
|
45
46
|
const data:Cerfa3517_2023 = {
|
package/ts/utils/vat/utils.ts
CHANGED
|
@@ -18,6 +18,10 @@ export function getAmountByAccountNumber(accountingEntries: IAccountingEntry[],
|
|
|
18
18
|
return isAbs ? Math.abs(result) : result;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export function setZeroIfIsNegative(value: number): number {
|
|
22
|
+
return value < 0 ? 0 : value;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
export function getTaxAmountByAccountNumber(accountingEntries: IAccountingEntry[], accountsNumber: string[], precision = 0): number {
|
|
22
26
|
const accountingEntriesUniq = _uniqBy(accountingEntries, 'id');
|
|
23
27
|
return _round(accountingEntriesUniq.reduce((acc, accountingEntry) => {
|