@silexpert/core 1.1.305 → 1.1.307
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/Commercial.d.ts +4 -1
- package/dist/cjs/api/resources/Commercial.d.ts.map +1 -1
- package/dist/cjs/api/resources/Commercial.js +3 -0
- package/dist/cjs/api/resources/Commercial.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/PriceGridClementine.d.ts +22 -0
- package/dist/cjs/types/Enum/PriceGridClementine.d.ts.map +1 -1
- package/dist/cjs/types/Enum/PriceGridClementine.js +27 -1
- package/dist/cjs/types/Enum/PriceGridClementine.js.map +1 -1
- package/dist/cjs/types/Enum/PriceGridLegalstart.d.ts +8 -0
- package/dist/cjs/types/Enum/PriceGridLegalstart.d.ts.map +1 -1
- package/dist/cjs/types/Enum/PriceGridLegalstart.js +8 -0
- package/dist/cjs/types/Enum/PriceGridLegalstart.js.map +1 -1
- package/dist/cjs/types/Enum/PriceGridPourcentage.d.ts +10 -0
- package/dist/cjs/types/Enum/PriceGridPourcentage.d.ts.map +1 -1
- package/dist/cjs/types/Enum/PriceGridPourcentage.js +84 -0
- package/dist/cjs/types/Enum/PriceGridPourcentage.js.map +1 -1
- package/dist/cjs/types/Enum/StatisticType.d.ts +2 -1
- package/dist/cjs/types/Enum/StatisticType.d.ts.map +1 -1
- package/dist/cjs/types/Enum/StatisticType.js +1 -0
- package/dist/cjs/types/Enum/StatisticType.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/commercial/QueryGetStatsHistory.d.ts +7 -0
- package/dist/cjs/types/Interface/api/commercial/QueryGetStatsHistory.d.ts.map +1 -0
- package/dist/cjs/types/Interface/api/commercial/QueryGetStatsHistory.js +42 -0
- package/dist/cjs/types/Interface/api/commercial/QueryGetStatsHistory.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 +27 -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/statistic/QueryInternal.d.ts +1 -1
- package/dist/cjs/types/Interface/api/statistic/QueryInternal.d.ts.map +1 -1
- package/dist/cjs/types/Interface/api/statistic/QueryInternal.js +5 -5
- package/dist/cjs/types/Interface/api/statistic/QueryInternal.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 +4 -0
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +4 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/payment.d.ts +15 -2
- package/dist/cjs/utils/payment.d.ts.map +1 -1
- package/dist/cjs/utils/payment.js +180 -2
- package/dist/cjs/utils/payment.js.map +1 -1
- package/dist/cjs/utils/prestation.d.ts +60 -0
- package/dist/cjs/utils/prestation.d.ts.map +1 -1
- package/dist/cjs/utils/prestation.js +4 -3
- package/dist/cjs/utils/prestation.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 +494 -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/Commercial.d.ts +4 -1
- package/dist/mjs/api/resources/Commercial.d.ts.map +1 -1
- package/dist/mjs/api/resources/Commercial.js +7 -0
- package/dist/mjs/api/resources/Commercial.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/PriceGridClementine.d.ts +22 -0
- package/dist/mjs/types/Enum/PriceGridClementine.d.ts.map +1 -1
- package/dist/mjs/types/Enum/PriceGridClementine.js +27 -1
- package/dist/mjs/types/Enum/PriceGridClementine.js.map +1 -1
- package/dist/mjs/types/Enum/PriceGridLegalstart.d.ts +8 -0
- package/dist/mjs/types/Enum/PriceGridLegalstart.d.ts.map +1 -1
- package/dist/mjs/types/Enum/PriceGridLegalstart.js +8 -0
- package/dist/mjs/types/Enum/PriceGridLegalstart.js.map +1 -1
- package/dist/mjs/types/Enum/PriceGridPourcentage.d.ts +10 -0
- package/dist/mjs/types/Enum/PriceGridPourcentage.d.ts.map +1 -1
- package/dist/mjs/types/Enum/PriceGridPourcentage.js +84 -0
- package/dist/mjs/types/Enum/PriceGridPourcentage.js.map +1 -1
- package/dist/mjs/types/Enum/StatisticType.d.ts +2 -1
- package/dist/mjs/types/Enum/StatisticType.d.ts.map +1 -1
- package/dist/mjs/types/Enum/StatisticType.js +1 -0
- package/dist/mjs/types/Enum/StatisticType.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/commercial/QueryGetStatsHistory.d.ts +7 -0
- package/dist/mjs/types/Interface/api/commercial/QueryGetStatsHistory.d.ts.map +1 -0
- package/dist/mjs/types/Interface/api/commercial/QueryGetStatsHistory.js +42 -0
- package/dist/mjs/types/Interface/api/commercial/QueryGetStatsHistory.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 +27 -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/statistic/QueryInternal.d.ts +1 -1
- package/dist/mjs/types/Interface/api/statistic/QueryInternal.d.ts.map +1 -1
- package/dist/mjs/types/Interface/api/statistic/QueryInternal.js +3 -3
- package/dist/mjs/types/Interface/api/statistic/QueryInternal.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 +4 -0
- package/dist/mjs/types/index.d.ts.map +1 -1
- package/dist/mjs/types/index.js +4 -0
- package/dist/mjs/types/index.js.map +1 -1
- package/dist/mjs/utils/payment.d.ts +15 -2
- package/dist/mjs/utils/payment.d.ts.map +1 -1
- package/dist/mjs/utils/payment.js +178 -1
- package/dist/mjs/utils/payment.js.map +1 -1
- package/dist/mjs/utils/prestation.d.ts +60 -0
- package/dist/mjs/utils/prestation.d.ts.map +1 -1
- package/dist/mjs/utils/prestation.js +1 -1
- package/dist/mjs/utils/prestation.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 +485 -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/Commercial.ts +8 -0
- 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/PriceGridClementine.ts +27 -1
- package/ts/types/Enum/PriceGridLegalstart.ts +8 -0
- package/ts/types/Enum/PriceGridPourcentage.ts +84 -0
- package/ts/types/Enum/StatisticType.ts +1 -0
- package/ts/types/Interface/api/authentification/ConnectFromSSO.ts +8 -0
- package/ts/types/Interface/api/commercial/QueryGetStatsHistory.ts +26 -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 +28 -0
- package/ts/types/Interface/api/society/QueryPaginatedSociety.ts +6 -0
- package/ts/types/Interface/api/statistic/QueryInternal.ts +1 -1
- 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 +4 -0
- package/ts/utils/payment.ts +200 -2
- package/ts/utils/prestation.ts +3 -1
- package/ts/utils/tests/payment.spec.ts +502 -0
- package/ts/utils/vat/utils.ts +16 -0
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
idTypeBrand: number;
|
|
11
|
+
firstExerciceNonExpresssEndDate: Date;
|
|
12
|
+
goToClient: Date;
|
|
13
|
+
idPrestation: number;
|
|
14
|
+
idVat: number;
|
|
15
|
+
prestationList: IPrestationList;
|
|
16
|
+
yearlyAmountNonExpress: number;
|
|
17
|
+
nextYearlyAmountNonExpress: number;
|
|
18
|
+
listPartialExercicePrestationExpress: PartialExercicePrestationExpress[];
|
|
19
|
+
listRegulations: IRegulation[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PaymentAuto {
|
|
23
|
+
amount: number;
|
|
24
|
+
datePayment: Date;
|
|
25
|
+
idPrestation: number;
|
|
26
|
+
idPaymentMethod: number;
|
|
27
|
+
closingDate: Date;
|
|
28
|
+
}
|
|
@@ -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';
|
|
@@ -627,6 +630,7 @@ export * from './Interface/api/facturation/CreateRebilling';
|
|
|
627
630
|
export * from './Interface/api/facturation/GoToFacturation';
|
|
628
631
|
export * from './Interface/api/OnBoarding';
|
|
629
632
|
export * from './Interface/api/commercial/QueryGetStats';
|
|
633
|
+
export * from './Interface/api/commercial/QueryGetStatsHistory';
|
|
630
634
|
export * from './Interface/api/commercial/RequiredDocsTypeParams';
|
|
631
635
|
export * from './Interface/api/commercial/QueryFetchDialogDatasInfosOk';
|
|
632
636
|
export * from './Interface/api/commercial/QueryMovePrestationsToNextMonth';
|
package/ts/utils/payment.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
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';
|
|
6
|
+
import { getPriceGrid } from './prestation';
|
|
2
7
|
|
|
3
8
|
interface PaymentsWithList extends IPayment {
|
|
4
9
|
type: 'isComptable' | 'isJuridique' | 'isSocial' | 'isOther',
|
|
@@ -53,6 +58,199 @@ const groupPaymentsByServiceType = (payments: IPayment[], types: ('isComptable'
|
|
|
53
58
|
return societyPayment;
|
|
54
59
|
};
|
|
55
60
|
|
|
61
|
+
const calculateFees = (amount: number, goToClient: Date, paymentDate: Date):number => {
|
|
62
|
+
const yearlyPriceIncreasing = 1.0275;
|
|
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
|
+
return amount;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
// * @param {number} firstPaymentAmount - amount of the first payment (first regulation of the customer)
|
|
79
|
+
* @param {Date} firstExerciceNonExpresssEndDate - end date of the first exercice non express
|
|
80
|
+
* @param {number} idPrestation - prestation id
|
|
81
|
+
* @param {IPrestationList} prestationList - type of prestation (hidden: 0, isCatalog: 1, isComptable: 1)
|
|
82
|
+
* @param {number} idVat - vat id of society linked
|
|
83
|
+
* @param {number} yearlyAmountNonExpress - yearly amount of non express prestation (HT)
|
|
84
|
+
* @param {number} nextYearlyAmountNonExpress - yearly amount of non express prestation for next years (HT)
|
|
85
|
+
* @param {PartialExercicePrestationExpress[]} listPartialExercicePrestationExpress - list of exercicePrestation linked to idPrestation -> used to get express
|
|
86
|
+
* @param {IRegulation[]} listRegulations - list of regulations linked to idPrestation (TTC)
|
|
87
|
+
* @returns { IPayment[] } list of payment to create for billing auto, after each presta go to onBoarding
|
|
88
|
+
*/
|
|
89
|
+
const calculatePaymentsAuto = (params: ParamsForPaymentsAuto):PaymentAuto[] => {
|
|
90
|
+
const { idTypeBrand, goToClient, firstExerciceNonExpresssEndDate, idPrestation, prestationList, idVat, yearlyAmountNonExpress, nextYearlyAmountNonExpress, listPartialExercicePrestationExpress, listRegulations } = params;
|
|
91
|
+
const initializedPaymentDate = dayjs().endOf('month').diff(dayjs(), 'day') < 3/* || dayjs().date() >= 15 */
|
|
92
|
+
? dayjs().add(2, 'month').startOf('month').toDate()
|
|
93
|
+
: dayjs().add(1, 'month').startOf('month').toDate();
|
|
94
|
+
let isApplicationAlreadyPaid = false;
|
|
95
|
+
|
|
96
|
+
// On récupère la grille tarifaire pour savoir si les tarifs sont HT ou TTC
|
|
97
|
+
// et pour connaitre le montant du coût de l'app
|
|
98
|
+
if (!prestationList.id) throw new Error('idPrestationList manquant');
|
|
99
|
+
const priceGrid = getPriceGrid(idTypeBrand, prestationList.id);
|
|
100
|
+
if (!priceGrid) throw new Error('Impossible de trouver la grille tarifaire correspondante');
|
|
101
|
+
const { applicationCost, priceWithTaxesIncluded } = priceGrid;
|
|
102
|
+
const applicationCostTotalTTC = (priceWithTaxesIncluded ? applicationCost : getTaxesIncludedAmount(applicationCost, idVat)) * 12;
|
|
103
|
+
|
|
104
|
+
if (prestationList?.isCatalog || !prestationList?.isComptable) throw new Error('Ce type de prestation ne correspond pas aux conditions attendues.');
|
|
105
|
+
// if (!listRegulations?.length) throw new Error('List of regulations can not be empty');
|
|
106
|
+
if (listPartialExercicePrestationExpress.length && listPartialExercicePrestationExpress?.some((ep: PartialExercicePrestationExpress) => !ep?.startDate)) throw new Error('Start date of some exercice are missing');
|
|
107
|
+
if (!listRegulations?.every((r: IRegulation) => !!r?.amount || !!r?.amountUsed)) throw new Error('Amount and amountUsed are missing for regulations');
|
|
108
|
+
|
|
109
|
+
const nbExoExpress = listPartialExercicePrestationExpress.length;
|
|
110
|
+
const listPayments:PaymentAuto[] = [];
|
|
111
|
+
|
|
112
|
+
// on récupère le/les premiers réglements effectués, non alloués
|
|
113
|
+
const sumRegulations = listRegulations.reduce((acc: number, r:IRegulation) => acc + r.amount - r.amountUsed, 0);
|
|
114
|
+
let remainingAmount = -sumRegulations; //TTC
|
|
115
|
+
let paymentDate = initializedPaymentDate;
|
|
116
|
+
|
|
117
|
+
//On order les exercicePrestation par startDate ASC et id ASC
|
|
118
|
+
listPartialExercicePrestationExpress.sort((a, b) => {
|
|
119
|
+
const aStartDate = a?.startDate as Date;
|
|
120
|
+
const bStartDate = b?.startDate as Date;
|
|
121
|
+
return dayjs(aStartDate).diff(bStartDate);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
//On ajoute un paiement initial correspondant à la somme des régulations
|
|
125
|
+
if (sumRegulations) {
|
|
126
|
+
listPayments.push({
|
|
127
|
+
amount:sumRegulations, //TTC
|
|
128
|
+
datePayment: dayjs().toDate(),
|
|
129
|
+
idPrestation,
|
|
130
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
131
|
+
closingDate: listPartialExercicePrestationExpress?.length ? listPartialExercicePrestationExpress[0].endDate : firstExerciceNonExpresssEndDate,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// =========================
|
|
136
|
+
// EXPRESS
|
|
137
|
+
// =========================
|
|
138
|
+
listPartialExercicePrestationExpress.forEach((exercicePrestation:PartialExercicePrestationExpress, indexEP: number) => {
|
|
139
|
+
remainingAmount += !priceWithTaxesIncluded
|
|
140
|
+
? getTaxesIncludedAmount(exercicePrestation.totalAmount, idVat)
|
|
141
|
+
: exercicePrestation.totalAmount; //TTC
|
|
142
|
+
//Si le premier règlement couvre le coût de cet exercicePrestation, on passe au suivant
|
|
143
|
+
if (remainingAmount <= 0) return;
|
|
144
|
+
|
|
145
|
+
//express : on étale en countExpressMonthlyPayment (nb de mensualités)
|
|
146
|
+
let remainingAmountByExercicePrestation = remainingAmount; //TTC
|
|
147
|
+
let countExpressMonthlyPayment = exercicePrestation?.countExpressMonthlyPayment ?? 3; //TTC
|
|
148
|
+
//Si un premier règlement est généré avec le montant des regulations, on le considère comme une mensualité (unioquement pour le premier express et la première mensualité)
|
|
149
|
+
if (indexEP === 0 && sumRegulations > 0) countExpressMonthlyPayment -= 1;
|
|
150
|
+
|
|
151
|
+
const monthlyAmount = remainingAmountByExercicePrestation / countExpressMonthlyPayment; //TTC
|
|
152
|
+
for (let index = 1; index <= countExpressMonthlyPayment; index++) {
|
|
153
|
+
// 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
|
|
154
|
+
// et on applique le taux de tva de la société
|
|
155
|
+
const amount = index < countExpressMonthlyPayment ? monthlyAmount : remainingAmountByExercicePrestation; //TTC
|
|
156
|
+
|
|
157
|
+
listPayments.push({
|
|
158
|
+
amount: Math.round(100 * amount) / 100,
|
|
159
|
+
datePayment: paymentDate,
|
|
160
|
+
idPrestation,
|
|
161
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
162
|
+
closingDate: exercicePrestation.endDate,
|
|
163
|
+
});
|
|
164
|
+
remainingAmountByExercicePrestation -= monthlyAmount;
|
|
165
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
166
|
+
}
|
|
167
|
+
remainingAmount = 0;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// =========================
|
|
171
|
+
// NON EXPRESS
|
|
172
|
+
// =========================
|
|
173
|
+
// on lisse sur le nb de mois restants (avec au minimum 3 mensualités)
|
|
174
|
+
// Si un seul exo express, alors on met les paiements de l'exo actuel en parallèle
|
|
175
|
+
// sinon, ils sont à la suite des express
|
|
176
|
+
if (nbExoExpress <= 1) paymentDate = initializedPaymentDate;
|
|
177
|
+
let exerciceEndDate = dayjs(firstExerciceNonExpresssEndDate).toDate();
|
|
178
|
+
|
|
179
|
+
//On génère un seul exercices plein, non express
|
|
180
|
+
//On compte le nb de mois restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
|
|
181
|
+
let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));
|
|
182
|
+
if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;
|
|
183
|
+
|
|
184
|
+
const exoAmount = yearlyAmountNonExpress;
|
|
185
|
+
remainingAmount += priceWithTaxesIncluded ? exoAmount : getTaxesIncludedAmount(exoAmount, idVat);
|
|
186
|
+
|
|
187
|
+
let remainingAmountByExercicePrestation = remainingAmount;
|
|
188
|
+
let monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd; //TTC
|
|
189
|
+
|
|
190
|
+
if (monthlyAmount > 0) {
|
|
191
|
+
for (let index = 1; index <= countMonthsBeforeExerciceEnd; index++) {
|
|
192
|
+
let amount = index < countMonthsBeforeExerciceEnd ? monthlyAmount : remainingAmountByExercicePrestation;
|
|
193
|
+
|
|
194
|
+
// Si besoin, on applique les frais nécessaires :
|
|
195
|
+
// - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
|
|
196
|
+
amount = calculateFees(amount, goToClient, paymentDate);
|
|
197
|
+
|
|
198
|
+
listPayments.push({
|
|
199
|
+
amount: Math.round(100 * amount) / 100,
|
|
200
|
+
datePayment: paymentDate,
|
|
201
|
+
idPrestation,
|
|
202
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
203
|
+
closingDate: exerciceEndDate,
|
|
204
|
+
});
|
|
205
|
+
remainingAmountByExercicePrestation -= monthlyAmount;
|
|
206
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
207
|
+
}
|
|
208
|
+
exerciceEndDate = dayjs(exerciceEndDate).startOf('month').add(1, 'year').endOf('month').toDate();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
remainingAmount = 0;
|
|
212
|
+
|
|
213
|
+
// =========================
|
|
214
|
+
// JUSQU'EN DECEMBRE
|
|
215
|
+
// =========================
|
|
216
|
+
// On applique le taux de tva de la société, si besoin, selon la grille tarifaire
|
|
217
|
+
remainingAmount += priceWithTaxesIncluded ? nextYearlyAmountNonExpress : getTaxesIncludedAmount(nextYearlyAmountNonExpress, idVat);
|
|
218
|
+
|
|
219
|
+
remainingAmountByExercicePrestation = remainingAmount;
|
|
220
|
+
//On compte le nb de mois restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
|
|
221
|
+
countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));
|
|
222
|
+
if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;
|
|
223
|
+
|
|
224
|
+
// - frais d'application dès les second exo non express
|
|
225
|
+
remainingAmountByExercicePrestation += applicationCostTotalTTC;
|
|
226
|
+
|
|
227
|
+
monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd;
|
|
228
|
+
|
|
229
|
+
// Si aucun paiement généré, on stoppe là
|
|
230
|
+
if (!listPayments.length) return [];
|
|
231
|
+
|
|
232
|
+
while (dayjs(listPayments.slice(-1)[0].datePayment).month() < 11 || !isApplicationAlreadyPaid) {
|
|
233
|
+
let amount = monthlyAmount;
|
|
234
|
+
|
|
235
|
+
// Si besoin, on applique les frais nécessaires :
|
|
236
|
+
// - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
|
|
237
|
+
// - frais d'application dès les second exo non express
|
|
238
|
+
amount = calculateFees(amount, goToClient, paymentDate);
|
|
239
|
+
|
|
240
|
+
listPayments.push({
|
|
241
|
+
amount: Math.round(100 * amount) / 100,
|
|
242
|
+
datePayment: paymentDate,
|
|
243
|
+
idPrestation,
|
|
244
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
245
|
+
closingDate: exerciceEndDate,
|
|
246
|
+
});
|
|
247
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
248
|
+
isApplicationAlreadyPaid = true;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return listPayments;
|
|
252
|
+
};
|
|
253
|
+
|
|
56
254
|
export {
|
|
57
|
-
groupPaymentsByServiceType,
|
|
255
|
+
groupPaymentsByServiceType, calculatePaymentsAuto,
|
|
58
256
|
};
|
package/ts/utils/prestation.ts
CHANGED
|
@@ -19,6 +19,8 @@ type priceGridBrand = {
|
|
|
19
19
|
|
|
20
20
|
type priceGrid = {
|
|
21
21
|
idPrestationList: number[],
|
|
22
|
+
priceWithTaxesIncluded: boolean,
|
|
23
|
+
applicationCost: number,
|
|
22
24
|
monthlyNbr?: monthlyNbr[],
|
|
23
25
|
exerciceNbr?: exerciceNbr[],
|
|
24
26
|
turnoverCreatedYear?: turnover[],
|
|
@@ -136,7 +138,7 @@ const calculateScoringOfPrestation = (idPrestationType: PrestationType, prestati
|
|
|
136
138
|
return numberPoint;
|
|
137
139
|
};
|
|
138
140
|
|
|
139
|
-
const getPriceGrid = (idTypeBrand: number, idPrestationList: number): priceGrid | undefined => {
|
|
141
|
+
export const getPriceGrid = (idTypeBrand: number, idPrestationList: number): priceGrid | undefined => {
|
|
140
142
|
let currentBrandPriceGrid: priceGridBrand | undefined;
|
|
141
143
|
let currentPriceGrid: priceGrid | undefined;
|
|
142
144
|
|