@silexpert/core 1.1.305 → 1.1.306
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/dist/cjs/api/resources/Closing.d.ts +2 -1
- package/dist/cjs/api/resources/Closing.d.ts.map +1 -1
- package/dist/cjs/api/resources/Closing.js +3 -0
- package/dist/cjs/api/resources/Closing.js.map +1 -1
- package/dist/cjs/api/resources/Exercice.d.ts +2 -2
- package/dist/cjs/api/resources/Exercice.d.ts.map +1 -1
- package/dist/cjs/api/resources/Exercice.js +2 -2
- package/dist/cjs/api/resources/Exercice.js.map +1 -1
- package/dist/cjs/api/resources/IntermediateManagementRebate.d.ts.map +1 -1
- package/dist/cjs/api/resources/IntermediateManagementRebate.js +6 -1
- package/dist/cjs/api/resources/IntermediateManagementRebate.js.map +1 -1
- package/dist/cjs/api/resources/Payment.d.ts +2 -1
- package/dist/cjs/api/resources/Payment.d.ts.map +1 -1
- package/dist/cjs/api/resources/Payment.js +3 -0
- package/dist/cjs/api/resources/Payment.js.map +1 -1
- package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.d.ts +4 -0
- package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.d.ts.map +1 -0
- package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.js +23 -0
- package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.js.map +1 -0
- package/dist/cjs/types/Interface/api/exercice/QueryExercice.d.ts +3 -0
- package/dist/cjs/types/Interface/api/exercice/QueryExercice.d.ts.map +1 -1
- package/dist/cjs/types/Interface/api/exercice/QueryExercice.js +11 -1
- package/dist/cjs/types/Interface/api/exercice/QueryExercice.js.map +1 -1
- package/dist/cjs/types/Interface/api/exercice/UpdateExercice.d.ts +1 -0
- package/dist/cjs/types/Interface/api/exercice/UpdateExercice.d.ts.map +1 -1
- package/dist/cjs/types/Interface/api/exercice/UpdateExercice.js +7 -0
- package/dist/cjs/types/Interface/api/exercice/UpdateExercice.js.map +1 -1
- package/dist/cjs/types/Interface/api/payment/Params.d.ts +4 -0
- package/dist/cjs/types/Interface/api/payment/Params.d.ts.map +1 -0
- package/dist/cjs/types/Interface/api/payment/Params.js +24 -0
- package/dist/cjs/types/Interface/api/payment/Params.js.map +1 -0
- package/dist/cjs/types/Interface/api/payment/Util.d.ts +25 -0
- package/dist/cjs/types/Interface/api/payment/Util.d.ts.map +1 -0
- package/dist/cjs/types/Interface/api/payment/Util.js +3 -0
- package/dist/cjs/types/Interface/api/payment/Util.js.map +1 -0
- package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.d.ts +1 -0
- package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.d.ts.map +1 -1
- package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.js +8 -0
- package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.js.map +1 -1
- package/dist/cjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js +1 -1
- package/dist/cjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js.map +1 -1
- package/dist/cjs/types/Interface/models/IExercicePrestation.d.ts +1 -0
- package/dist/cjs/types/Interface/models/IExercicePrestation.d.ts.map +1 -1
- package/dist/cjs/types/Interface/models/IExercicePrestation.js.map +1 -1
- package/dist/cjs/types/Interface/models/ISociety.d.ts +2 -1
- package/dist/cjs/types/Interface/models/ISociety.d.ts.map +1 -1
- package/dist/cjs/types/Interface/models/ISociety.js.map +1 -1
- package/dist/cjs/types/index.d.ts +3 -0
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +3 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/payment.d.ts +14 -2
- package/dist/cjs/utils/payment.d.ts.map +1 -1
- package/dist/cjs/utils/payment.js +172 -2
- package/dist/cjs/utils/payment.js.map +1 -1
- package/dist/cjs/utils/tests/payment.spec.d.ts +2 -0
- package/dist/cjs/utils/tests/payment.spec.d.ts.map +1 -0
- package/dist/cjs/utils/tests/payment.spec.js +458 -0
- package/dist/cjs/utils/tests/payment.spec.js.map +1 -0
- package/dist/cjs/utils/vat/utils.d.ts +2 -0
- package/dist/cjs/utils/vat/utils.d.ts.map +1 -1
- package/dist/cjs/utils/vat/utils.js +19 -1
- package/dist/cjs/utils/vat/utils.js.map +1 -1
- package/dist/mjs/api/resources/Closing.d.ts +2 -1
- package/dist/mjs/api/resources/Closing.d.ts.map +1 -1
- package/dist/mjs/api/resources/Closing.js +3 -0
- package/dist/mjs/api/resources/Closing.js.map +1 -1
- package/dist/mjs/api/resources/Exercice.d.ts +2 -2
- package/dist/mjs/api/resources/Exercice.d.ts.map +1 -1
- package/dist/mjs/api/resources/Exercice.js +2 -2
- package/dist/mjs/api/resources/Exercice.js.map +1 -1
- package/dist/mjs/api/resources/IntermediateManagementRebate.d.ts.map +1 -1
- package/dist/mjs/api/resources/IntermediateManagementRebate.js +6 -1
- package/dist/mjs/api/resources/IntermediateManagementRebate.js.map +1 -1
- package/dist/mjs/api/resources/Payment.d.ts +2 -1
- package/dist/mjs/api/resources/Payment.d.ts.map +1 -1
- package/dist/mjs/api/resources/Payment.js +3 -0
- package/dist/mjs/api/resources/Payment.js.map +1 -1
- package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.d.ts +4 -0
- package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.d.ts.map +1 -0
- package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.js +20 -0
- package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.js.map +1 -0
- package/dist/mjs/types/Interface/api/exercice/QueryExercice.d.ts +3 -0
- package/dist/mjs/types/Interface/api/exercice/QueryExercice.d.ts.map +1 -1
- package/dist/mjs/types/Interface/api/exercice/QueryExercice.js +10 -0
- package/dist/mjs/types/Interface/api/exercice/QueryExercice.js.map +1 -1
- package/dist/mjs/types/Interface/api/exercice/UpdateExercice.d.ts +1 -0
- package/dist/mjs/types/Interface/api/exercice/UpdateExercice.d.ts.map +1 -1
- package/dist/mjs/types/Interface/api/exercice/UpdateExercice.js +8 -0
- package/dist/mjs/types/Interface/api/exercice/UpdateExercice.js.map +1 -1
- package/dist/mjs/types/Interface/api/payment/Params.d.ts +4 -0
- package/dist/mjs/types/Interface/api/payment/Params.d.ts.map +1 -0
- package/dist/mjs/types/Interface/api/payment/Params.js +21 -0
- package/dist/mjs/types/Interface/api/payment/Params.js.map +1 -0
- package/dist/mjs/types/Interface/api/payment/Util.d.ts +25 -0
- package/dist/mjs/types/Interface/api/payment/Util.d.ts.map +1 -0
- package/dist/mjs/types/Interface/api/payment/Util.js +2 -0
- package/dist/mjs/types/Interface/api/payment/Util.js.map +1 -0
- package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.d.ts +1 -0
- package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.d.ts.map +1 -1
- package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.js +8 -0
- package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.js.map +1 -1
- package/dist/mjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js +1 -1
- package/dist/mjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js.map +1 -1
- package/dist/mjs/types/Interface/models/IExercicePrestation.d.ts +1 -0
- package/dist/mjs/types/Interface/models/IExercicePrestation.d.ts.map +1 -1
- package/dist/mjs/types/Interface/models/IExercicePrestation.js.map +1 -1
- package/dist/mjs/types/Interface/models/ISociety.d.ts +2 -1
- package/dist/mjs/types/Interface/models/ISociety.d.ts.map +1 -1
- package/dist/mjs/types/Interface/models/ISociety.js.map +1 -1
- package/dist/mjs/types/index.d.ts +3 -0
- package/dist/mjs/types/index.d.ts.map +1 -1
- package/dist/mjs/types/index.js +3 -0
- package/dist/mjs/types/index.js.map +1 -1
- package/dist/mjs/utils/payment.d.ts +14 -2
- package/dist/mjs/utils/payment.d.ts.map +1 -1
- package/dist/mjs/utils/payment.js +170 -1
- package/dist/mjs/utils/payment.js.map +1 -1
- package/dist/mjs/utils/tests/payment.spec.d.ts +2 -0
- package/dist/mjs/utils/tests/payment.spec.d.ts.map +1 -0
- package/dist/mjs/utils/tests/payment.spec.js +449 -0
- package/dist/mjs/utils/tests/payment.spec.js.map +1 -0
- package/dist/mjs/utils/vat/utils.d.ts +2 -0
- package/dist/mjs/utils/vat/utils.d.ts.map +1 -1
- package/dist/mjs/utils/vat/utils.js +14 -0
- package/dist/mjs/utils/vat/utils.js.map +1 -1
- package/package.json +1 -1
- package/ts/api/resources/Closing.ts +6 -1
- package/ts/api/resources/Exercice.ts +3 -3
- package/ts/api/resources/IntermediateManagementRebate.ts +6 -1
- package/ts/api/resources/Payment.ts +5 -1
- package/ts/types/Interface/api/authentification/ConnectFromSSO.ts +8 -0
- package/ts/types/Interface/api/exercice/QueryExercice.ts +8 -0
- package/ts/types/Interface/api/exercice/UpdateExercice.ts +6 -0
- package/ts/types/Interface/api/payment/Params.ts +9 -0
- package/ts/types/Interface/api/payment/Util.ts +26 -0
- package/ts/types/Interface/api/society/QueryPaginatedSociety.ts +6 -0
- package/ts/types/Interface/api/user/ParamsGetAllUserWithRoles.ts +1 -1
- package/ts/types/Interface/models/IExercicePrestation.ts +1 -0
- package/ts/types/Interface/models/ISociety.ts +2 -0
- package/ts/types/index.ts +3 -0
- package/ts/utils/payment.ts +194 -2
- package/ts/utils/tests/payment.spec.ts +466 -0
- package/ts/utils/vat/utils.ts +16 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.groupPaymentsByServiceType = void 0;
|
|
3
|
+
exports.calculatePaymentsAuto = exports.groupPaymentsByServiceType = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const dayjs = require("dayjs");
|
|
4
6
|
/**
|
|
5
7
|
* A partir d'une liste de payment (avec include jusqu'à prestationList,
|
|
6
8
|
* avec en attributs 'isComptable' | 'isJuridique' | 'isSocial' | 'isOther')
|
|
@@ -32,4 +34,172 @@ const groupPaymentsByServiceType = (payments, types = ['isComptable', 'isJuridiq
|
|
|
32
34
|
return societyPayment;
|
|
33
35
|
};
|
|
34
36
|
exports.groupPaymentsByServiceType = groupPaymentsByServiceType;
|
|
37
|
+
const calculateFees = (amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat) => {
|
|
38
|
+
const yearlyPriceIncreasing = 1.0275;
|
|
39
|
+
const appCost = (0, types_1.getTaxesIncludedAmount)(14.9, idVat);
|
|
40
|
+
const oneYearLessIfIn3LastMonthsOfYear = dayjs(goToClient).month() >= 9 ? 1 : 0;
|
|
41
|
+
if (dayjs(paymentDate).year() - dayjs().year() > 0) {
|
|
42
|
+
const nbYearsMore = dayjs(paymentDate).year() - dayjs().year() - oneYearLessIfIn3LastMonthsOfYear;
|
|
43
|
+
// on applique X fois l'augmentation
|
|
44
|
+
// ex. : si on lance l'appel en 2024, et qu'on génére un paiement pour 2026, on applique 2 fois l'augmentation
|
|
45
|
+
// soit amount * yearlyPriceIncreasing * yearlyPriceIncreasing
|
|
46
|
+
// soit amount * yearlyPriceIncreasing ^ nbYearsMore
|
|
47
|
+
amount = amount * Math.pow(yearlyPriceIncreasing, nbYearsMore);
|
|
48
|
+
}
|
|
49
|
+
// À partir du second exercice non express, on applique le coût de l'application (14,9€ HT)
|
|
50
|
+
if (nbExoNonExpressGenerated >= 2) {
|
|
51
|
+
amount += appCost;
|
|
52
|
+
}
|
|
53
|
+
return Math.round(100 * amount) / 100;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
// * @param {number} firstPaymentAmount - amount of the first payment (first regulation of the customer)
|
|
57
|
+
* @param {Date} firstExerciceNonExpresssEndDate - end date of the first exercice non express
|
|
58
|
+
* @param {number} idPrestation - prestation id
|
|
59
|
+
* @param {IPrestationList} prestationList - type of prestation (hidden: 0, isCatalog: 1, isComptable: 1)
|
|
60
|
+
* @param {number} idVat - vat id of society linked
|
|
61
|
+
* @param {number} yearlyAmountNonExpress - yearly amount of non express prestation (HT)
|
|
62
|
+
* @param {PartialExercicePrestationExpress[]} listPartialExercicePrestationExpress - list of exercicePrestation linked to idPrestation -> used to get express
|
|
63
|
+
* @param {IRegulation[]} listRegulations - list of regulations linked to idPrestation (TTC)
|
|
64
|
+
* @returns { IPayment[] } list of payment to create for billing auto, after each presta go to onBoarding
|
|
65
|
+
*/
|
|
66
|
+
const calculatePaymentsAuto = (params) => {
|
|
67
|
+
const { goToClient, firstExerciceNonExpresssEndDate, idPrestation, prestationList, idVat, yearlyAmountNonExpress, listPartialExercicePrestationExpress, listRegulations } = params;
|
|
68
|
+
const initializedPaymentDate = dayjs().endOf('month').diff(dayjs(), 'day') < 3 /* || dayjs().date() >= 15 */
|
|
69
|
+
? dayjs().add(2, 'month').startOf('month').toDate()
|
|
70
|
+
: dayjs().add(1, 'month').startOf('month').toDate();
|
|
71
|
+
if ((prestationList === null || prestationList === void 0 ? void 0 : prestationList.isCatalog) || !(prestationList === null || prestationList === void 0 ? void 0 : prestationList.isComptable))
|
|
72
|
+
throw new Error('Ce type de prestation ne correspond pas aux conditions attendues.');
|
|
73
|
+
// if (!listRegulations?.length) throw new Error('List of regulations can not be empty');
|
|
74
|
+
if (listPartialExercicePrestationExpress.length && (listPartialExercicePrestationExpress === null || listPartialExercicePrestationExpress === void 0 ? void 0 : listPartialExercicePrestationExpress.some((ep) => !(ep === null || ep === void 0 ? void 0 : ep.startDate))))
|
|
75
|
+
throw new Error('Start date of some exercice are missing');
|
|
76
|
+
if (!(listRegulations === null || listRegulations === void 0 ? void 0 : listRegulations.every((r) => !!(r === null || r === void 0 ? void 0 : r.amount) || !!(r === null || r === void 0 ? void 0 : r.amountUsed))))
|
|
77
|
+
throw new Error('Amount and amountUsed are missing for regulations');
|
|
78
|
+
const nbExoExpress = listPartialExercicePrestationExpress.length;
|
|
79
|
+
const listPayments = [];
|
|
80
|
+
// on récupère le/les premiers réglements effectués, non alloués
|
|
81
|
+
const sumRegulations = listRegulations.reduce((acc, r) => acc + r.amount - r.amountUsed, 0);
|
|
82
|
+
let remainingAmount = -sumRegulations; //TTC
|
|
83
|
+
let paymentDate = initializedPaymentDate;
|
|
84
|
+
//On order les exercicePrestation par startDate ASC et id ASC
|
|
85
|
+
listPartialExercicePrestationExpress.sort((a, b) => {
|
|
86
|
+
const aStartDate = a === null || a === void 0 ? void 0 : a.startDate;
|
|
87
|
+
const bStartDate = b === null || b === void 0 ? void 0 : b.startDate;
|
|
88
|
+
return dayjs(aStartDate).diff(bStartDate);
|
|
89
|
+
});
|
|
90
|
+
//On ajoute un paiement initial correspondant à la somme des régulations
|
|
91
|
+
if (sumRegulations) {
|
|
92
|
+
listPayments.push({
|
|
93
|
+
amount: sumRegulations,
|
|
94
|
+
datePayment: dayjs().toDate(),
|
|
95
|
+
idPrestation,
|
|
96
|
+
idPaymentMethod: types_1.PaymentMethod.DIRECT_DEBIT.id,
|
|
97
|
+
closingDate: (listPartialExercicePrestationExpress === null || listPartialExercicePrestationExpress === void 0 ? void 0 : listPartialExercicePrestationExpress.length) ? listPartialExercicePrestationExpress[0].endDate : firstExerciceNonExpresssEndDate,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// =========================
|
|
101
|
+
// EXPRESS
|
|
102
|
+
// =========================
|
|
103
|
+
listPartialExercicePrestationExpress.forEach((exercicePrestation) => {
|
|
104
|
+
var _a;
|
|
105
|
+
remainingAmount += (0, types_1.getTaxesIncludedAmount)(exercicePrestation.totalAmount, idVat); //TTC
|
|
106
|
+
//Si le premier règlement couvre le coût de cet exercicePrestation, on passe au suivant
|
|
107
|
+
if (remainingAmount <= 0)
|
|
108
|
+
return;
|
|
109
|
+
//express : on étale en countExpressMonthlyPayment (nb de mensualités)
|
|
110
|
+
let remainingAmountByExercicePrestation = remainingAmount; //TTC
|
|
111
|
+
let countExpressMonthlyPayment = (_a = exercicePrestation === null || exercicePrestation === void 0 ? void 0 : exercicePrestation.countExpressMonthlyPayment) !== null && _a !== void 0 ? _a : 3; //TTC
|
|
112
|
+
const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / countExpressMonthlyPayment) / 100; //TTC
|
|
113
|
+
for (let index = 1; index <= countExpressMonthlyPayment; index++) {
|
|
114
|
+
//Si un premier règlement est généré avec le montant des regulations, on le considère comme une mensualité
|
|
115
|
+
if (index === 1 && sumRegulations)
|
|
116
|
+
countExpressMonthlyPayment -= 1;
|
|
117
|
+
// On arrondis les 11 premières mensualités, mais on récupère le reste pour la dernière mensualité, pour éviter les centimes perdus en arrondis
|
|
118
|
+
// et on applique le taux de tva de la société
|
|
119
|
+
const amount = index < countExpressMonthlyPayment ? monthlyAmountRounded : remainingAmountByExercicePrestation; //TTC
|
|
120
|
+
listPayments.push({
|
|
121
|
+
amount,
|
|
122
|
+
datePayment: paymentDate,
|
|
123
|
+
idPrestation,
|
|
124
|
+
idPaymentMethod: types_1.PaymentMethod.DIRECT_DEBIT.id,
|
|
125
|
+
closingDate: exercicePrestation.endDate,
|
|
126
|
+
});
|
|
127
|
+
remainingAmountByExercicePrestation -= monthlyAmountRounded;
|
|
128
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
129
|
+
}
|
|
130
|
+
remainingAmount = 0;
|
|
131
|
+
});
|
|
132
|
+
// =========================
|
|
133
|
+
// NON EXPRESS
|
|
134
|
+
// =========================
|
|
135
|
+
// on lisse sur le nb de mois restants (avec au minimum 3 mensualités)
|
|
136
|
+
// Si un seul exo express, alors on met les paiements de l'exo actuel en parallèle
|
|
137
|
+
// sinon, ils sont à la suite des express
|
|
138
|
+
if (nbExoExpress <= 1)
|
|
139
|
+
paymentDate = initializedPaymentDate;
|
|
140
|
+
let nbExoNonExpressGenerated = 1;
|
|
141
|
+
let exerciceEndDate = dayjs(firstExerciceNonExpresssEndDate).toDate();
|
|
142
|
+
//On génère au minimum 2 exercices plein
|
|
143
|
+
while (nbExoNonExpressGenerated <= 2) {
|
|
144
|
+
//On compte le nb de mois restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
|
|
145
|
+
let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));
|
|
146
|
+
if (countMonthsBeforeExerciceEnd < 3)
|
|
147
|
+
countMonthsBeforeExerciceEnd = 3;
|
|
148
|
+
remainingAmount += (0, types_1.getTaxesIncludedAmount)(yearlyAmountNonExpress, idVat);
|
|
149
|
+
let remainingAmountByExercicePrestation = remainingAmount;
|
|
150
|
+
const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd) / 100; //TTC
|
|
151
|
+
if (monthlyAmountRounded > 0) {
|
|
152
|
+
for (let index = 1; index <= countMonthsBeforeExerciceEnd; index++) {
|
|
153
|
+
let amount = index < countMonthsBeforeExerciceEnd ? monthlyAmountRounded : Math.round(100 * remainingAmountByExercicePrestation) / 100;
|
|
154
|
+
// Si besoin, on applique les frais nécessaires :
|
|
155
|
+
// - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
|
|
156
|
+
// - frais d'application dès les second exo non express
|
|
157
|
+
amount = calculateFees(amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat);
|
|
158
|
+
listPayments.push({
|
|
159
|
+
amount,
|
|
160
|
+
datePayment: paymentDate,
|
|
161
|
+
idPrestation,
|
|
162
|
+
idPaymentMethod: types_1.PaymentMethod.DIRECT_DEBIT.id,
|
|
163
|
+
closingDate: exerciceEndDate,
|
|
164
|
+
});
|
|
165
|
+
remainingAmountByExercicePrestation -= monthlyAmountRounded;
|
|
166
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
167
|
+
}
|
|
168
|
+
exerciceEndDate = dayjs(exerciceEndDate).startOf('month').add(1, 'year').endOf('month').toDate();
|
|
169
|
+
}
|
|
170
|
+
nbExoNonExpressGenerated += 1;
|
|
171
|
+
remainingAmount = 0;
|
|
172
|
+
}
|
|
173
|
+
// =========================
|
|
174
|
+
// JUSQU'EN DECEMBRE
|
|
175
|
+
// =========================
|
|
176
|
+
//On compte le nb d'exercices restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
|
|
177
|
+
// let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true)); //Logiquement, 12
|
|
178
|
+
// if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;
|
|
179
|
+
remainingAmount += yearlyAmountNonExpress;
|
|
180
|
+
const remainingAmountByExercicePrestation = remainingAmount;
|
|
181
|
+
const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / 12) / 100;
|
|
182
|
+
// Si aucun paiement généré, on stoppe là
|
|
183
|
+
if (!listPayments.length)
|
|
184
|
+
return [];
|
|
185
|
+
while (dayjs(listPayments.slice(-1)[0].datePayment).month() < 11) {
|
|
186
|
+
let amount = monthlyAmountRounded;
|
|
187
|
+
// Si besoin, on applique les frais nécessaires :
|
|
188
|
+
// - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
|
|
189
|
+
// - frais d'application dès les second exo non express
|
|
190
|
+
amount = calculateFees(amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat);
|
|
191
|
+
// On applique le taux de tva de la société
|
|
192
|
+
amount = (0, types_1.getTaxesIncludedAmount)(amount, idVat);
|
|
193
|
+
listPayments.push({
|
|
194
|
+
amount,
|
|
195
|
+
datePayment: paymentDate,
|
|
196
|
+
idPrestation,
|
|
197
|
+
idPaymentMethod: types_1.PaymentMethod.DIRECT_DEBIT.id,
|
|
198
|
+
closingDate: exerciceEndDate,
|
|
199
|
+
});
|
|
200
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
201
|
+
}
|
|
202
|
+
return listPayments;
|
|
203
|
+
};
|
|
204
|
+
exports.calculatePaymentsAuto = calculatePaymentsAuto;
|
|
35
205
|
//# sourceMappingURL=payment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.js","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MAAA,MAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,mBAAmB,0CAAE,eAAe,0CAAE,WAAW,CAAA,IAAI,CAAC,CAAA,MAAA,MAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,mBAAmB,0CAAE,eAAe,0CAAE,QAAQ,CAAA,CAAA,EAAA,CAAC,CAAC;IAErN,MAAM,cAAc,GAAuB,EAAE,CAAC;IAC9C,IAAI,eAAe,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;QAC3D,cAAc,CAAC,IAAI,iCACd,eAAe,CAAC,CAAC,CAAC,KACrB,IAAI,EAAE,aAAa,EACnB,YAAY,EAAE,eAAe,IAC7B,CAAC;KACJ;IACD,IAAI,YAAY,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACrD,cAAc,CAAC,IAAI,iCACd,YAAY,CAAC,CAAC,CAAC,KAClB,IAAI,EAAE,UAAU,EAChB,YAAY,EAAE,YAAY,IAC1B,CAAC;KACJ;IACD,IAAI,eAAe,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;QAC3D,cAAc,CAAC,IAAI,iCACd,eAAe,CAAC,CAAC,CAAC,KACrB,IAAI,EAAE,aAAa,EACnB,YAAY,EAAE,eAAe,IAC7B,CAAC;KACJ;IACD,IAAI,WAAW,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;QACnD,cAAc,CAAC,IAAI,iCACd,WAAW,CAAC,CAAC,CAAC,KACjB,IAAI,EAAE,SAAS,EACf,YAAY,EAAE,WAAW,IACzB,CAAC;KACJ;IACD,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAGA,gEAA0B","sourcesContent":["import { IPayment } from '../types';\n\ninterface PaymentsWithList extends IPayment {\n type: 'isComptable' | 'isJuridique' | 'isSocial' | 'isOther',\n listPayments: IPayment[]\n}\n\n/**\n * A partir d'une liste de payment (avec include jusqu'à prestationList, \n * avec en attributs 'isComptable' | 'isJuridique' | 'isSocial' | 'isOther')\n * permet de récupérer uniquement le premier paiement de chaque type \n * et les autres payments dans listPayments\n * avec possibilité de filtrer avec le tableau de filtres\n * @param payments \n * @param types \n * @returns \n */\nconst groupPaymentsByServiceType = (payments: IPayment[], types: ('isComptable' | 'isJuridique' | 'isSocial' | 'isOther')[] = ['isComptable', 'isJuridique', 'isSocial', 'isOther']): PaymentsWithList[] => {\n const prestaComptable = payments.filter((el) => el?.paymentsPrestations?.prestationsList?.isComptable ?? false);\n const prestaSocial = payments.filter((el) => !el?.paymentsPrestations?.prestationsList?.isComptable && el?.paymentsPrestations?.prestationsList?.isSocial);\n const prestaJuridique = payments.filter((el) => !el?.paymentsPrestations?.prestationsList?.isComptable && el?.paymentsPrestations?.prestationsList?.isJuridique);\n const prestaOther = payments.filter((el) => !el?.paymentsPrestations?.prestationsList?.isComptable && !el?.paymentsPrestations?.prestationsList?.isJuridique && !el?.paymentsPrestations?.prestationsList?.isSocial);\n \n const societyPayment: PaymentsWithList[] = [];\n if (prestaComptable.length && types.includes('isComptable')) {\n societyPayment.push({\n ...prestaComptable[0], // Données de base\n type: 'isComptable',\n listPayments: prestaComptable,\n });\n }\n if (prestaSocial.length && types.includes('isSocial')) {\n societyPayment.push({\n ...prestaSocial[0], // Données de base\n type: 'isSocial',\n listPayments: prestaSocial,\n });\n }\n if (prestaJuridique.length && types.includes('isJuridique')) {\n societyPayment.push({\n ...prestaJuridique[0], // Données de base\n type: 'isJuridique',\n listPayments: prestaJuridique,\n });\n }\n if (prestaOther.length && types.includes('isOther')) {\n societyPayment.push({\n ...prestaOther[0], // Données de base\n type: 'isOther',\n listPayments: prestaOther,\n });\n }\n return societyPayment;\n};\n\nexport {\n groupPaymentsByServiceType,\n};"]}
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../ts/utils/payment.ts"],"names":[],"mappings":"AAAA,YAA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C,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;KAC5E;IAED,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAG4B,sDAAqB","sourcesContent":["'use strict';\n\nimport { IPayment, IRegulation, ParamsForPaymentsAuto, PaymentMethod, PaymentAuto, getTaxesIncludedAmount } from '../types';\nimport * as dayjs from 'dayjs';\nimport { PartialExercicePrestationExpress } from '../types/Interface/api/payment/Util';\n\ninterface PaymentsWithList extends IPayment {\n type: 'isComptable' | 'isJuridique' | 'isSocial' | 'isOther',\n listPayments: IPayment[]\n}\n\n/**\n * A partir d'une liste de payment (avec include jusqu'à prestationList, \n * avec en attributs 'isComptable' | 'isJuridique' | 'isSocial' | 'isOther')\n * permet de récupérer uniquement le premier paiement de chaque type \n * et les autres payments dans listPayments\n * avec possibilité de filtrer avec le tableau de filtres\n * @param payments \n * @param types \n * @returns \n */\nconst groupPaymentsByServiceType = (payments: IPayment[], types: ('isComptable' | 'isJuridique' | 'isSocial' | 'isOther')[] = ['isComptable', 'isJuridique', 'isSocial', 'isOther']): PaymentsWithList[] => {\n const prestaComptable = payments.filter((el) => el?.paymentsPrestations?.prestationsList?.isComptable ?? false);\n const prestaSocial = payments.filter((el) => !el?.paymentsPrestations?.prestationsList?.isComptable && el?.paymentsPrestations?.prestationsList?.isSocial);\n const prestaJuridique = payments.filter((el) => !el?.paymentsPrestations?.prestationsList?.isComptable && el?.paymentsPrestations?.prestationsList?.isJuridique);\n const prestaOther = payments.filter((el) => !el?.paymentsPrestations?.prestationsList?.isComptable && !el?.paymentsPrestations?.prestationsList?.isJuridique && !el?.paymentsPrestations?.prestationsList?.isSocial);\n \n const societyPayment: PaymentsWithList[] = [];\n if (prestaComptable.length && types.includes('isComptable')) {\n societyPayment.push({\n ...prestaComptable[0], // Données de base\n type: 'isComptable',\n listPayments: prestaComptable,\n });\n }\n if (prestaSocial.length && types.includes('isSocial')) {\n societyPayment.push({\n ...prestaSocial[0], // Données de base\n type: 'isSocial',\n listPayments: prestaSocial,\n });\n }\n if (prestaJuridique.length && types.includes('isJuridique')) {\n societyPayment.push({\n ...prestaJuridique[0], // Données de base\n type: 'isJuridique',\n listPayments: prestaJuridique,\n });\n }\n if (prestaOther.length && types.includes('isOther')) {\n societyPayment.push({\n ...prestaOther[0], // Données de base\n type: 'isOther',\n listPayments: prestaOther,\n });\n }\n return societyPayment;\n};\n\nconst calculateFees = (amount: number, goToClient: Date, paymentDate: Date, nbExoNonExpressGenerated: number, idVat: number):number => {\n const yearlyPriceIncreasing = 1.0275;\n const appCost = getTaxesIncludedAmount(14.9, idVat);\n\n const oneYearLessIfIn3LastMonthsOfYear = dayjs(goToClient).month() >= 9 ? 1 : 0;\n\n if (dayjs(paymentDate).year() - dayjs().year() > 0) {\n const nbYearsMore = dayjs(paymentDate).year() - dayjs().year() - oneYearLessIfIn3LastMonthsOfYear;\n // on applique X fois l'augmentation\n // ex. : si on lance l'appel en 2024, et qu'on génére un paiement pour 2026, on applique 2 fois l'augmentation\n // soit amount * yearlyPriceIncreasing * yearlyPriceIncreasing\n // soit amount * yearlyPriceIncreasing ^ nbYearsMore\n amount = amount * Math.pow(yearlyPriceIncreasing, nbYearsMore);\n }\n\n // À partir du second exercice non express, on applique le coût de l'application (14,9€ HT)\n if (nbExoNonExpressGenerated >= 2) {\n amount += appCost;\n }\n return Math.round(100 * amount) / 100;\n};\n\n/**\n// * @param {number} firstPaymentAmount - amount of the first payment (first regulation of the customer)\n * @param {Date} firstExerciceNonExpresssEndDate - end date of the first exercice non express\n * @param {number} idPrestation - prestation id\n * @param {IPrestationList} prestationList - type of prestation (hidden: 0, isCatalog: 1, isComptable: 1)\n * @param {number} idVat - vat id of society linked\n * @param {number} yearlyAmountNonExpress - yearly amount of non express prestation (HT)\n * @param {PartialExercicePrestationExpress[]} listPartialExercicePrestationExpress - list of exercicePrestation linked to idPrestation -> used to get express\n * @param {IRegulation[]} listRegulations - list of regulations linked to idPrestation (TTC)\n * @returns { IPayment[] } list of payment to create for billing auto, after each presta go to onBoarding\n */\nconst calculatePaymentsAuto = (params: ParamsForPaymentsAuto):PaymentAuto[] => {\n const { goToClient, firstExerciceNonExpresssEndDate, idPrestation, prestationList, idVat, yearlyAmountNonExpress, listPartialExercicePrestationExpress, listRegulations } = params;\n const initializedPaymentDate = dayjs().endOf('month').diff(dayjs(), 'day') < 3/* || dayjs().date() >= 15 */\n ? dayjs().add(2, 'month').startOf('month').toDate()\n : dayjs().add(1, 'month').startOf('month').toDate();\n\n if (prestationList?.isCatalog || !prestationList?.isComptable) throw new Error('Ce type de prestation ne correspond pas aux conditions attendues.');\n // if (!listRegulations?.length) throw new Error('List of regulations can not be empty');\n if (listPartialExercicePrestationExpress.length && listPartialExercicePrestationExpress?.some((ep: PartialExercicePrestationExpress) => !ep?.startDate)) throw new Error('Start date of some exercice are missing');\n if (!listRegulations?.every((r: IRegulation) => !!r?.amount || !!r?.amountUsed)) throw new Error('Amount and amountUsed are missing for regulations');\n\n const nbExoExpress = listPartialExercicePrestationExpress.length;\n const listPayments:PaymentAuto[] = [];\n\n // on récupère le/les premiers réglements effectués, non alloués\n const sumRegulations = listRegulations.reduce((acc: number, r:IRegulation) => acc + r.amount - r.amountUsed, 0);\n let remainingAmount = -sumRegulations; //TTC\n let paymentDate = initializedPaymentDate;\n\n //On order les exercicePrestation par startDate ASC et id ASC\n listPartialExercicePrestationExpress.sort((a, b) => {\n const aStartDate = a?.startDate as Date;\n const bStartDate = b?.startDate as Date;\n return dayjs(aStartDate).diff(bStartDate);\n });\n\n //On ajoute un paiement initial correspondant à la somme des régulations\n if (sumRegulations) {\n listPayments.push({\n amount:sumRegulations, //TTC\n datePayment: dayjs().toDate(),\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: listPartialExercicePrestationExpress?.length ? listPartialExercicePrestationExpress[0].endDate : firstExerciceNonExpresssEndDate,\n });\n }\n \n // =========================\n // EXPRESS\n // =========================\n listPartialExercicePrestationExpress.forEach((exercicePrestation:PartialExercicePrestationExpress) => {\n remainingAmount += getTaxesIncludedAmount(exercicePrestation.totalAmount, idVat); //TTC\n //Si le premier règlement couvre le coût de cet exercicePrestation, on passe au suivant\n if (remainingAmount <= 0) return;\n \n //express : on étale en countExpressMonthlyPayment (nb de mensualités)\n let remainingAmountByExercicePrestation = remainingAmount; //TTC\n let countExpressMonthlyPayment = exercicePrestation?.countExpressMonthlyPayment ?? 3; //TTC\n const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / countExpressMonthlyPayment) / 100; //TTC\n for (let index = 1; index <= countExpressMonthlyPayment; index++) {\n //Si un premier règlement est généré avec le montant des regulations, on le considère comme une mensualité\n if (index === 1 && sumRegulations) countExpressMonthlyPayment -= 1;\n \n // On arrondis les 11 premières mensualités, mais on récupère le reste pour la dernière mensualité, pour éviter les centimes perdus en arrondis\n // et on applique le taux de tva de la société\n const amount = index < countExpressMonthlyPayment ? monthlyAmountRounded : remainingAmountByExercicePrestation; //TTC\n \n listPayments.push({\n amount,\n datePayment: paymentDate,\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: exercicePrestation.endDate,\n });\n remainingAmountByExercicePrestation -= monthlyAmountRounded; \n paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();\n }\n remainingAmount = 0;\n });\n\n // =========================\n // NON EXPRESS\n // =========================\n // on lisse sur le nb de mois restants (avec au minimum 3 mensualités)\n // Si un seul exo express, alors on met les paiements de l'exo actuel en parallèle\n // sinon, ils sont à la suite des express\n if (nbExoExpress <= 1) paymentDate = initializedPaymentDate;\n let nbExoNonExpressGenerated = 1;\n let exerciceEndDate = dayjs(firstExerciceNonExpresssEndDate).toDate();\n \n //On génère au minimum 2 exercices plein\n while (nbExoNonExpressGenerated <= 2) {\n //On compte le nb de mois restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice\n let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));\n if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;\n\n remainingAmount += getTaxesIncludedAmount(yearlyAmountNonExpress, idVat);\n\n let remainingAmountByExercicePrestation = remainingAmount;\n const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd) / 100; //TTC\n\n if (monthlyAmountRounded > 0) {\n for (let index = 1; index <= countMonthsBeforeExerciceEnd; index++) {\n let amount = index < countMonthsBeforeExerciceEnd ? monthlyAmountRounded : Math.round(100 * remainingAmountByExercicePrestation) / 100;\n \n // Si besoin, on applique les frais nécessaires :\n // - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)\n // - frais d'application dès les second exo non express\n amount = calculateFees(amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat);\n \n listPayments.push({\n amount,\n datePayment: paymentDate,\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: exerciceEndDate,\n });\n remainingAmountByExercicePrestation -= monthlyAmountRounded; \n paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();\n }\n exerciceEndDate = dayjs(exerciceEndDate).startOf('month').add(1, 'year').endOf('month').toDate();\n }\n nbExoNonExpressGenerated += 1;\n\n remainingAmount = 0;\n }\n\n // =========================\n // JUSQU'EN DECEMBRE\n // =========================\n //On compte le nb d'exercices restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice\n // let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true)); //Logiquement, 12\n // if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;\n\n remainingAmount += yearlyAmountNonExpress;\n const remainingAmountByExercicePrestation = remainingAmount;\n const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / 12) / 100;\n \n // Si aucun paiement généré, on stoppe là\n if (!listPayments.length) return [];\n\n while (dayjs(listPayments.slice(-1)[0].datePayment).month() < 11) {\n let amount = monthlyAmountRounded;\n \n // Si besoin, on applique les frais nécessaires :\n // - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)\n // - frais d'application dès les second exo non express\n amount = calculateFees(amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat);\n \n // On applique le taux de tva de la société\n amount = getTaxesIncludedAmount(amount, idVat);\n\n listPayments.push({\n amount,\n datePayment: paymentDate,\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: exerciceEndDate,\n });\n paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();\n }\n\n return listPayments;\n};\n\nexport {\n groupPaymentsByServiceType, calculatePaymentsAuto,\n};"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.spec.d.ts","sourceRoot":"","sources":["../../../../ts/utils/tests/payment.spec.ts"],"names":[],"mappings":""}
|