@silexpert/core 1.1.304 → 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/Enum/JobTitle.d.ts +2 -1
- package/dist/cjs/types/Enum/JobTitle.d.ts.map +1 -1
- package/dist/cjs/types/Enum/JobTitle.js +6 -0
- package/dist/cjs/types/Enum/JobTitle.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/Enum/JobTitle.d.ts +2 -1
- package/dist/mjs/types/Enum/JobTitle.d.ts.map +1 -1
- package/dist/mjs/types/Enum/JobTitle.js +6 -0
- package/dist/mjs/types/Enum/JobTitle.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/Enum/JobTitle.ts +6 -0
- 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
|
@@ -12,7 +12,12 @@ export class IntermediateManagementRebate extends Resource {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
getFile(idExercice: number): Promise<Buffer> {
|
|
15
|
-
return this.axios.$get(`/exercices/${idExercice}/intermediate-management-rebates/file
|
|
15
|
+
return this.axios.$get(`/exercices/${idExercice}/intermediate-management-rebates/file`, {
|
|
16
|
+
responseType: 'arraybuffer',
|
|
17
|
+
headers: {
|
|
18
|
+
Accept: 'application/pdf',
|
|
19
|
+
},
|
|
20
|
+
});
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Resource } from '../Resource';
|
|
2
|
-
import { CreateNotifyCustomer, IPayment, QueryMonthlyPayment, QueryPayment, QueryPaymentCsv, QuerySocietyUnpaid, ReadPaid, ReadStatPrestation, ReadStatsSocietyUnpaid } from '../../types';
|
|
2
|
+
import { CreateNotifyCustomer, CreatePaymentsAutoBilling, IPayment, QueryMonthlyPayment, QueryPayment, QueryPaymentCsv, QuerySocietyUnpaid, ReadPaid, ReadStatPrestation, ReadStatsSocietyUnpaid } from '../../types';
|
|
3
3
|
|
|
4
4
|
export class Payment extends Resource {
|
|
5
5
|
getMonthlyCsv(query: QueryMonthlyPayment): Promise<void> {
|
|
@@ -53,4 +53,8 @@ export class Payment extends Resource {
|
|
|
53
53
|
params: payload,
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
generateForAutoBilling(payload: CreatePaymentsAutoBilling): Promise<ReadStatsSocietyUnpaid[]> {
|
|
58
|
+
return this.axios.$post('payment/auto-billing', payload);
|
|
59
|
+
}
|
|
56
60
|
}
|
|
@@ -31,6 +31,7 @@ export enum JobTitle {
|
|
|
31
31
|
TERMINATION = 30,
|
|
32
32
|
LITIGE = 31,
|
|
33
33
|
DATA_OFFICER = 32,
|
|
34
|
+
PROJECT_MANAGER = 33,
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export const JobTitleList: Array<{ id: JobTitle; menText: string, womenText: string }> = [
|
|
@@ -194,4 +195,9 @@ export const JobTitleList: Array<{ id: JobTitle; menText: string, womenText: str
|
|
|
194
195
|
menText: 'Aide Comptable',
|
|
195
196
|
womenText: 'Aide Comptable',
|
|
196
197
|
},
|
|
198
|
+
{
|
|
199
|
+
id: JobTitle.PROJECT_MANAGER,
|
|
200
|
+
menText: 'Chef de projet',
|
|
201
|
+
womenText: 'Cheffe de projet',
|
|
202
|
+
},
|
|
197
203
|
];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IPrestationList, IRegulation } from '../../..';
|
|
2
|
+
|
|
3
|
+
export interface PartialExercicePrestationExpress {
|
|
4
|
+
startDate: Date;
|
|
5
|
+
endDate: Date;
|
|
6
|
+
countExpressMonthlyPayment: number | null; // if null, non express | if not null, express
|
|
7
|
+
totalAmount: number
|
|
8
|
+
}
|
|
9
|
+
export interface ParamsForPaymentsAuto {
|
|
10
|
+
firstExerciceNonExpresssEndDate: Date;
|
|
11
|
+
goToClient: Date;
|
|
12
|
+
idPrestation: number;
|
|
13
|
+
idVat: number;
|
|
14
|
+
prestationList: IPrestationList;
|
|
15
|
+
yearlyAmountNonExpress: number;
|
|
16
|
+
listPartialExercicePrestationExpress: PartialExercicePrestationExpress[];
|
|
17
|
+
listRegulations: IRegulation[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PaymentAuto {
|
|
21
|
+
amount: number;
|
|
22
|
+
datePayment: Date;
|
|
23
|
+
idPrestation: number;
|
|
24
|
+
idPaymentMethod: number;
|
|
25
|
+
closingDate: Date;
|
|
26
|
+
}
|
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
IAccountingFile,
|
|
54
54
|
IThirdPartySociety,
|
|
55
55
|
ICalendarEvent,
|
|
56
|
+
IRegulation,
|
|
56
57
|
} from '../..';
|
|
57
58
|
import { IBrandType } from './IBrandType';
|
|
58
59
|
import { IFile } from './IFile';
|
|
@@ -222,6 +223,7 @@ export interface ISociety {
|
|
|
222
223
|
userPermission?: IUserSocietyPermission;
|
|
223
224
|
usersPermissions?: IUserSocietyPermission[];
|
|
224
225
|
regulates?: IRegulate[];
|
|
226
|
+
regulations?: IRegulation[];
|
|
225
227
|
brandType?: IBrandType;
|
|
226
228
|
partneredAccountantCompaniesServices?: IPartneredAccountantCompanyService[];
|
|
227
229
|
partneredAccountantRelated?: IPartneredAccountantToSociety;
|
package/ts/types/index.ts
CHANGED
|
@@ -548,6 +548,7 @@ export * from './Interface/api/adjustment/Query';
|
|
|
548
548
|
export * from './Interface/api/adjustment/Read';
|
|
549
549
|
export * from './Interface/api/vatDeclaration/ReadVatDeclaration';
|
|
550
550
|
export * from './Interface/api/adjustment/Create';
|
|
551
|
+
export * from './Interface/api/authentification/ConnectFromSSO';
|
|
551
552
|
export * from './Interface/api/partnerTransactionType/ReadPartnerTransactionType';
|
|
552
553
|
export * from './Interface/api/jeDeclare/ReadJeDeclare';
|
|
553
554
|
export * from './Interface/api/aspone/ReadInterchange';
|
|
@@ -564,6 +565,8 @@ export * from './Interface/api/immobilization/ReadFormattedImmobilization';
|
|
|
564
565
|
export * from './Interface/api/immobilization/CreateImmobilization';
|
|
565
566
|
export * from './Interface/api/payment/QueryMonthlyPayment';
|
|
566
567
|
export * from './Interface/api/payment/QueryPayment';
|
|
568
|
+
export * from './Interface/api/payment/Params';
|
|
569
|
+
export * from './Interface/api/payment/Util';
|
|
567
570
|
export * from './Interface/api/payment/ReadPayment';
|
|
568
571
|
export * from './Interface/api/payment/CreateNotifyCustomer';
|
|
569
572
|
export * from './Interface/api/payment/CreateNotifyCustomerInvoice';
|
package/ts/utils/payment.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { IPayment, IRegulation, ParamsForPaymentsAuto, PaymentMethod, PaymentAuto, getTaxesIncludedAmount } from '../types';
|
|
4
|
+
import * as dayjs from 'dayjs';
|
|
5
|
+
import { PartialExercicePrestationExpress } from '../types/Interface/api/payment/Util';
|
|
2
6
|
|
|
3
7
|
interface PaymentsWithList extends IPayment {
|
|
4
8
|
type: 'isComptable' | 'isJuridique' | 'isSocial' | 'isOther',
|
|
@@ -53,6 +57,194 @@ const groupPaymentsByServiceType = (payments: IPayment[], types: ('isComptable'
|
|
|
53
57
|
return societyPayment;
|
|
54
58
|
};
|
|
55
59
|
|
|
60
|
+
const calculateFees = (amount: number, goToClient: Date, paymentDate: Date, nbExoNonExpressGenerated: number, idVat: number):number => {
|
|
61
|
+
const yearlyPriceIncreasing = 1.0275;
|
|
62
|
+
const appCost = getTaxesIncludedAmount(14.9, idVat);
|
|
63
|
+
|
|
64
|
+
const oneYearLessIfIn3LastMonthsOfYear = dayjs(goToClient).month() >= 9 ? 1 : 0;
|
|
65
|
+
|
|
66
|
+
if (dayjs(paymentDate).year() - dayjs().year() > 0) {
|
|
67
|
+
const nbYearsMore = dayjs(paymentDate).year() - dayjs().year() - oneYearLessIfIn3LastMonthsOfYear;
|
|
68
|
+
// on applique X fois l'augmentation
|
|
69
|
+
// ex. : si on lance l'appel en 2024, et qu'on génére un paiement pour 2026, on applique 2 fois l'augmentation
|
|
70
|
+
// soit amount * yearlyPriceIncreasing * yearlyPriceIncreasing
|
|
71
|
+
// soit amount * yearlyPriceIncreasing ^ nbYearsMore
|
|
72
|
+
amount = amount * Math.pow(yearlyPriceIncreasing, nbYearsMore);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// À partir du second exercice non express, on applique le coût de l'application (14,9€ HT)
|
|
76
|
+
if (nbExoNonExpressGenerated >= 2) {
|
|
77
|
+
amount += appCost;
|
|
78
|
+
}
|
|
79
|
+
return Math.round(100 * amount) / 100;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
// * @param {number} firstPaymentAmount - amount of the first payment (first regulation of the customer)
|
|
84
|
+
* @param {Date} firstExerciceNonExpresssEndDate - end date of the first exercice non express
|
|
85
|
+
* @param {number} idPrestation - prestation id
|
|
86
|
+
* @param {IPrestationList} prestationList - type of prestation (hidden: 0, isCatalog: 1, isComptable: 1)
|
|
87
|
+
* @param {number} idVat - vat id of society linked
|
|
88
|
+
* @param {number} yearlyAmountNonExpress - yearly amount of non express prestation (HT)
|
|
89
|
+
* @param {PartialExercicePrestationExpress[]} listPartialExercicePrestationExpress - list of exercicePrestation linked to idPrestation -> used to get express
|
|
90
|
+
* @param {IRegulation[]} listRegulations - list of regulations linked to idPrestation (TTC)
|
|
91
|
+
* @returns { IPayment[] } list of payment to create for billing auto, after each presta go to onBoarding
|
|
92
|
+
*/
|
|
93
|
+
const calculatePaymentsAuto = (params: ParamsForPaymentsAuto):PaymentAuto[] => {
|
|
94
|
+
const { goToClient, firstExerciceNonExpresssEndDate, idPrestation, prestationList, idVat, yearlyAmountNonExpress, listPartialExercicePrestationExpress, listRegulations } = params;
|
|
95
|
+
const initializedPaymentDate = dayjs().endOf('month').diff(dayjs(), 'day') < 3/* || dayjs().date() >= 15 */
|
|
96
|
+
? dayjs().add(2, 'month').startOf('month').toDate()
|
|
97
|
+
: dayjs().add(1, 'month').startOf('month').toDate();
|
|
98
|
+
|
|
99
|
+
if (prestationList?.isCatalog || !prestationList?.isComptable) throw new Error('Ce type de prestation ne correspond pas aux conditions attendues.');
|
|
100
|
+
// if (!listRegulations?.length) throw new Error('List of regulations can not be empty');
|
|
101
|
+
if (listPartialExercicePrestationExpress.length && listPartialExercicePrestationExpress?.some((ep: PartialExercicePrestationExpress) => !ep?.startDate)) throw new Error('Start date of some exercice are missing');
|
|
102
|
+
if (!listRegulations?.every((r: IRegulation) => !!r?.amount || !!r?.amountUsed)) throw new Error('Amount and amountUsed are missing for regulations');
|
|
103
|
+
|
|
104
|
+
const nbExoExpress = listPartialExercicePrestationExpress.length;
|
|
105
|
+
const listPayments:PaymentAuto[] = [];
|
|
106
|
+
|
|
107
|
+
// on récupère le/les premiers réglements effectués, non alloués
|
|
108
|
+
const sumRegulations = listRegulations.reduce((acc: number, r:IRegulation) => acc + r.amount - r.amountUsed, 0);
|
|
109
|
+
let remainingAmount = -sumRegulations; //TTC
|
|
110
|
+
let paymentDate = initializedPaymentDate;
|
|
111
|
+
|
|
112
|
+
//On order les exercicePrestation par startDate ASC et id ASC
|
|
113
|
+
listPartialExercicePrestationExpress.sort((a, b) => {
|
|
114
|
+
const aStartDate = a?.startDate as Date;
|
|
115
|
+
const bStartDate = b?.startDate as Date;
|
|
116
|
+
return dayjs(aStartDate).diff(bStartDate);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
//On ajoute un paiement initial correspondant à la somme des régulations
|
|
120
|
+
if (sumRegulations) {
|
|
121
|
+
listPayments.push({
|
|
122
|
+
amount:sumRegulations, //TTC
|
|
123
|
+
datePayment: dayjs().toDate(),
|
|
124
|
+
idPrestation,
|
|
125
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
126
|
+
closingDate: listPartialExercicePrestationExpress?.length ? listPartialExercicePrestationExpress[0].endDate : firstExerciceNonExpresssEndDate,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// =========================
|
|
131
|
+
// EXPRESS
|
|
132
|
+
// =========================
|
|
133
|
+
listPartialExercicePrestationExpress.forEach((exercicePrestation:PartialExercicePrestationExpress) => {
|
|
134
|
+
remainingAmount += getTaxesIncludedAmount(exercicePrestation.totalAmount, idVat); //TTC
|
|
135
|
+
//Si le premier règlement couvre le coût de cet exercicePrestation, on passe au suivant
|
|
136
|
+
if (remainingAmount <= 0) return;
|
|
137
|
+
|
|
138
|
+
//express : on étale en countExpressMonthlyPayment (nb de mensualités)
|
|
139
|
+
let remainingAmountByExercicePrestation = remainingAmount; //TTC
|
|
140
|
+
let countExpressMonthlyPayment = exercicePrestation?.countExpressMonthlyPayment ?? 3; //TTC
|
|
141
|
+
const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / countExpressMonthlyPayment) / 100; //TTC
|
|
142
|
+
for (let index = 1; index <= countExpressMonthlyPayment; index++) {
|
|
143
|
+
//Si un premier règlement est généré avec le montant des regulations, on le considère comme une mensualité
|
|
144
|
+
if (index === 1 && sumRegulations) countExpressMonthlyPayment -= 1;
|
|
145
|
+
|
|
146
|
+
// 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
|
|
147
|
+
// et on applique le taux de tva de la société
|
|
148
|
+
const amount = index < countExpressMonthlyPayment ? monthlyAmountRounded : remainingAmountByExercicePrestation; //TTC
|
|
149
|
+
|
|
150
|
+
listPayments.push({
|
|
151
|
+
amount,
|
|
152
|
+
datePayment: paymentDate,
|
|
153
|
+
idPrestation,
|
|
154
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
155
|
+
closingDate: exercicePrestation.endDate,
|
|
156
|
+
});
|
|
157
|
+
remainingAmountByExercicePrestation -= monthlyAmountRounded;
|
|
158
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
159
|
+
}
|
|
160
|
+
remainingAmount = 0;
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// =========================
|
|
164
|
+
// NON EXPRESS
|
|
165
|
+
// =========================
|
|
166
|
+
// on lisse sur le nb de mois restants (avec au minimum 3 mensualités)
|
|
167
|
+
// Si un seul exo express, alors on met les paiements de l'exo actuel en parallèle
|
|
168
|
+
// sinon, ils sont à la suite des express
|
|
169
|
+
if (nbExoExpress <= 1) paymentDate = initializedPaymentDate;
|
|
170
|
+
let nbExoNonExpressGenerated = 1;
|
|
171
|
+
let exerciceEndDate = dayjs(firstExerciceNonExpresssEndDate).toDate();
|
|
172
|
+
|
|
173
|
+
//On génère au minimum 2 exercices plein
|
|
174
|
+
while (nbExoNonExpressGenerated <= 2) {
|
|
175
|
+
//On compte le nb de mois restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
|
|
176
|
+
let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));
|
|
177
|
+
if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;
|
|
178
|
+
|
|
179
|
+
remainingAmount += getTaxesIncludedAmount(yearlyAmountNonExpress, idVat);
|
|
180
|
+
|
|
181
|
+
let remainingAmountByExercicePrestation = remainingAmount;
|
|
182
|
+
const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd) / 100; //TTC
|
|
183
|
+
|
|
184
|
+
if (monthlyAmountRounded > 0) {
|
|
185
|
+
for (let index = 1; index <= countMonthsBeforeExerciceEnd; index++) {
|
|
186
|
+
let amount = index < countMonthsBeforeExerciceEnd ? monthlyAmountRounded : Math.round(100 * remainingAmountByExercicePrestation) / 100;
|
|
187
|
+
|
|
188
|
+
// Si besoin, on applique les frais nécessaires :
|
|
189
|
+
// - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
|
|
190
|
+
// - frais d'application dès les second exo non express
|
|
191
|
+
amount = calculateFees(amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat);
|
|
192
|
+
|
|
193
|
+
listPayments.push({
|
|
194
|
+
amount,
|
|
195
|
+
datePayment: paymentDate,
|
|
196
|
+
idPrestation,
|
|
197
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
198
|
+
closingDate: exerciceEndDate,
|
|
199
|
+
});
|
|
200
|
+
remainingAmountByExercicePrestation -= monthlyAmountRounded;
|
|
201
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
202
|
+
}
|
|
203
|
+
exerciceEndDate = dayjs(exerciceEndDate).startOf('month').add(1, 'year').endOf('month').toDate();
|
|
204
|
+
}
|
|
205
|
+
nbExoNonExpressGenerated += 1;
|
|
206
|
+
|
|
207
|
+
remainingAmount = 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// =========================
|
|
211
|
+
// JUSQU'EN DECEMBRE
|
|
212
|
+
// =========================
|
|
213
|
+
//On compte le nb d'exercices restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
|
|
214
|
+
// let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true)); //Logiquement, 12
|
|
215
|
+
// if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;
|
|
216
|
+
|
|
217
|
+
remainingAmount += yearlyAmountNonExpress;
|
|
218
|
+
const remainingAmountByExercicePrestation = remainingAmount;
|
|
219
|
+
const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / 12) / 100;
|
|
220
|
+
|
|
221
|
+
// Si aucun paiement généré, on stoppe là
|
|
222
|
+
if (!listPayments.length) return [];
|
|
223
|
+
|
|
224
|
+
while (dayjs(listPayments.slice(-1)[0].datePayment).month() < 11) {
|
|
225
|
+
let amount = monthlyAmountRounded;
|
|
226
|
+
|
|
227
|
+
// Si besoin, on applique les frais nécessaires :
|
|
228
|
+
// - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
|
|
229
|
+
// - frais d'application dès les second exo non express
|
|
230
|
+
amount = calculateFees(amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat);
|
|
231
|
+
|
|
232
|
+
// On applique le taux de tva de la société
|
|
233
|
+
amount = getTaxesIncludedAmount(amount, idVat);
|
|
234
|
+
|
|
235
|
+
listPayments.push({
|
|
236
|
+
amount,
|
|
237
|
+
datePayment: paymentDate,
|
|
238
|
+
idPrestation,
|
|
239
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
240
|
+
closingDate: exerciceEndDate,
|
|
241
|
+
});
|
|
242
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return listPayments;
|
|
246
|
+
};
|
|
247
|
+
|
|
56
248
|
export {
|
|
57
|
-
groupPaymentsByServiceType,
|
|
249
|
+
groupPaymentsByServiceType, calculatePaymentsAuto,
|
|
58
250
|
};
|