@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.
Files changed (153) hide show
  1. package/dist/cjs/api/resources/Closing.d.ts +2 -1
  2. package/dist/cjs/api/resources/Closing.d.ts.map +1 -1
  3. package/dist/cjs/api/resources/Closing.js +3 -0
  4. package/dist/cjs/api/resources/Closing.js.map +1 -1
  5. package/dist/cjs/api/resources/Exercice.d.ts +2 -2
  6. package/dist/cjs/api/resources/Exercice.d.ts.map +1 -1
  7. package/dist/cjs/api/resources/Exercice.js +2 -2
  8. package/dist/cjs/api/resources/Exercice.js.map +1 -1
  9. package/dist/cjs/api/resources/IntermediateManagementRebate.d.ts.map +1 -1
  10. package/dist/cjs/api/resources/IntermediateManagementRebate.js +6 -1
  11. package/dist/cjs/api/resources/IntermediateManagementRebate.js.map +1 -1
  12. package/dist/cjs/api/resources/Payment.d.ts +2 -1
  13. package/dist/cjs/api/resources/Payment.d.ts.map +1 -1
  14. package/dist/cjs/api/resources/Payment.js +3 -0
  15. package/dist/cjs/api/resources/Payment.js.map +1 -1
  16. package/dist/cjs/types/Enum/JobTitle.d.ts +2 -1
  17. package/dist/cjs/types/Enum/JobTitle.d.ts.map +1 -1
  18. package/dist/cjs/types/Enum/JobTitle.js +6 -0
  19. package/dist/cjs/types/Enum/JobTitle.js.map +1 -1
  20. package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.d.ts +4 -0
  21. package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.d.ts.map +1 -0
  22. package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.js +23 -0
  23. package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.js.map +1 -0
  24. package/dist/cjs/types/Interface/api/exercice/QueryExercice.d.ts +3 -0
  25. package/dist/cjs/types/Interface/api/exercice/QueryExercice.d.ts.map +1 -1
  26. package/dist/cjs/types/Interface/api/exercice/QueryExercice.js +11 -1
  27. package/dist/cjs/types/Interface/api/exercice/QueryExercice.js.map +1 -1
  28. package/dist/cjs/types/Interface/api/exercice/UpdateExercice.d.ts +1 -0
  29. package/dist/cjs/types/Interface/api/exercice/UpdateExercice.d.ts.map +1 -1
  30. package/dist/cjs/types/Interface/api/exercice/UpdateExercice.js +7 -0
  31. package/dist/cjs/types/Interface/api/exercice/UpdateExercice.js.map +1 -1
  32. package/dist/cjs/types/Interface/api/payment/Params.d.ts +4 -0
  33. package/dist/cjs/types/Interface/api/payment/Params.d.ts.map +1 -0
  34. package/dist/cjs/types/Interface/api/payment/Params.js +24 -0
  35. package/dist/cjs/types/Interface/api/payment/Params.js.map +1 -0
  36. package/dist/cjs/types/Interface/api/payment/Util.d.ts +25 -0
  37. package/dist/cjs/types/Interface/api/payment/Util.d.ts.map +1 -0
  38. package/dist/cjs/types/Interface/api/payment/Util.js +3 -0
  39. package/dist/cjs/types/Interface/api/payment/Util.js.map +1 -0
  40. package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.d.ts +1 -0
  41. package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.d.ts.map +1 -1
  42. package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.js +8 -0
  43. package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.js.map +1 -1
  44. package/dist/cjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js +1 -1
  45. package/dist/cjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js.map +1 -1
  46. package/dist/cjs/types/Interface/models/IExercicePrestation.d.ts +1 -0
  47. package/dist/cjs/types/Interface/models/IExercicePrestation.d.ts.map +1 -1
  48. package/dist/cjs/types/Interface/models/IExercicePrestation.js.map +1 -1
  49. package/dist/cjs/types/Interface/models/ISociety.d.ts +2 -1
  50. package/dist/cjs/types/Interface/models/ISociety.d.ts.map +1 -1
  51. package/dist/cjs/types/Interface/models/ISociety.js.map +1 -1
  52. package/dist/cjs/types/index.d.ts +3 -0
  53. package/dist/cjs/types/index.d.ts.map +1 -1
  54. package/dist/cjs/types/index.js +3 -0
  55. package/dist/cjs/types/index.js.map +1 -1
  56. package/dist/cjs/utils/payment.d.ts +14 -2
  57. package/dist/cjs/utils/payment.d.ts.map +1 -1
  58. package/dist/cjs/utils/payment.js +172 -2
  59. package/dist/cjs/utils/payment.js.map +1 -1
  60. package/dist/cjs/utils/tests/payment.spec.d.ts +2 -0
  61. package/dist/cjs/utils/tests/payment.spec.d.ts.map +1 -0
  62. package/dist/cjs/utils/tests/payment.spec.js +458 -0
  63. package/dist/cjs/utils/tests/payment.spec.js.map +1 -0
  64. package/dist/cjs/utils/vat/utils.d.ts +2 -0
  65. package/dist/cjs/utils/vat/utils.d.ts.map +1 -1
  66. package/dist/cjs/utils/vat/utils.js +19 -1
  67. package/dist/cjs/utils/vat/utils.js.map +1 -1
  68. package/dist/mjs/api/resources/Closing.d.ts +2 -1
  69. package/dist/mjs/api/resources/Closing.d.ts.map +1 -1
  70. package/dist/mjs/api/resources/Closing.js +3 -0
  71. package/dist/mjs/api/resources/Closing.js.map +1 -1
  72. package/dist/mjs/api/resources/Exercice.d.ts +2 -2
  73. package/dist/mjs/api/resources/Exercice.d.ts.map +1 -1
  74. package/dist/mjs/api/resources/Exercice.js +2 -2
  75. package/dist/mjs/api/resources/Exercice.js.map +1 -1
  76. package/dist/mjs/api/resources/IntermediateManagementRebate.d.ts.map +1 -1
  77. package/dist/mjs/api/resources/IntermediateManagementRebate.js +6 -1
  78. package/dist/mjs/api/resources/IntermediateManagementRebate.js.map +1 -1
  79. package/dist/mjs/api/resources/Payment.d.ts +2 -1
  80. package/dist/mjs/api/resources/Payment.d.ts.map +1 -1
  81. package/dist/mjs/api/resources/Payment.js +3 -0
  82. package/dist/mjs/api/resources/Payment.js.map +1 -1
  83. package/dist/mjs/types/Enum/JobTitle.d.ts +2 -1
  84. package/dist/mjs/types/Enum/JobTitle.d.ts.map +1 -1
  85. package/dist/mjs/types/Enum/JobTitle.js +6 -0
  86. package/dist/mjs/types/Enum/JobTitle.js.map +1 -1
  87. package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.d.ts +4 -0
  88. package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.d.ts.map +1 -0
  89. package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.js +20 -0
  90. package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.js.map +1 -0
  91. package/dist/mjs/types/Interface/api/exercice/QueryExercice.d.ts +3 -0
  92. package/dist/mjs/types/Interface/api/exercice/QueryExercice.d.ts.map +1 -1
  93. package/dist/mjs/types/Interface/api/exercice/QueryExercice.js +10 -0
  94. package/dist/mjs/types/Interface/api/exercice/QueryExercice.js.map +1 -1
  95. package/dist/mjs/types/Interface/api/exercice/UpdateExercice.d.ts +1 -0
  96. package/dist/mjs/types/Interface/api/exercice/UpdateExercice.d.ts.map +1 -1
  97. package/dist/mjs/types/Interface/api/exercice/UpdateExercice.js +8 -0
  98. package/dist/mjs/types/Interface/api/exercice/UpdateExercice.js.map +1 -1
  99. package/dist/mjs/types/Interface/api/payment/Params.d.ts +4 -0
  100. package/dist/mjs/types/Interface/api/payment/Params.d.ts.map +1 -0
  101. package/dist/mjs/types/Interface/api/payment/Params.js +21 -0
  102. package/dist/mjs/types/Interface/api/payment/Params.js.map +1 -0
  103. package/dist/mjs/types/Interface/api/payment/Util.d.ts +25 -0
  104. package/dist/mjs/types/Interface/api/payment/Util.d.ts.map +1 -0
  105. package/dist/mjs/types/Interface/api/payment/Util.js +2 -0
  106. package/dist/mjs/types/Interface/api/payment/Util.js.map +1 -0
  107. package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.d.ts +1 -0
  108. package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.d.ts.map +1 -1
  109. package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.js +8 -0
  110. package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.js.map +1 -1
  111. package/dist/mjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js +1 -1
  112. package/dist/mjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js.map +1 -1
  113. package/dist/mjs/types/Interface/models/IExercicePrestation.d.ts +1 -0
  114. package/dist/mjs/types/Interface/models/IExercicePrestation.d.ts.map +1 -1
  115. package/dist/mjs/types/Interface/models/IExercicePrestation.js.map +1 -1
  116. package/dist/mjs/types/Interface/models/ISociety.d.ts +2 -1
  117. package/dist/mjs/types/Interface/models/ISociety.d.ts.map +1 -1
  118. package/dist/mjs/types/Interface/models/ISociety.js.map +1 -1
  119. package/dist/mjs/types/index.d.ts +3 -0
  120. package/dist/mjs/types/index.d.ts.map +1 -1
  121. package/dist/mjs/types/index.js +3 -0
  122. package/dist/mjs/types/index.js.map +1 -1
  123. package/dist/mjs/utils/payment.d.ts +14 -2
  124. package/dist/mjs/utils/payment.d.ts.map +1 -1
  125. package/dist/mjs/utils/payment.js +170 -1
  126. package/dist/mjs/utils/payment.js.map +1 -1
  127. package/dist/mjs/utils/tests/payment.spec.d.ts +2 -0
  128. package/dist/mjs/utils/tests/payment.spec.d.ts.map +1 -0
  129. package/dist/mjs/utils/tests/payment.spec.js +449 -0
  130. package/dist/mjs/utils/tests/payment.spec.js.map +1 -0
  131. package/dist/mjs/utils/vat/utils.d.ts +2 -0
  132. package/dist/mjs/utils/vat/utils.d.ts.map +1 -1
  133. package/dist/mjs/utils/vat/utils.js +14 -0
  134. package/dist/mjs/utils/vat/utils.js.map +1 -1
  135. package/package.json +1 -1
  136. package/ts/api/resources/Closing.ts +6 -1
  137. package/ts/api/resources/Exercice.ts +3 -3
  138. package/ts/api/resources/IntermediateManagementRebate.ts +6 -1
  139. package/ts/api/resources/Payment.ts +5 -1
  140. package/ts/types/Enum/JobTitle.ts +6 -0
  141. package/ts/types/Interface/api/authentification/ConnectFromSSO.ts +8 -0
  142. package/ts/types/Interface/api/exercice/QueryExercice.ts +8 -0
  143. package/ts/types/Interface/api/exercice/UpdateExercice.ts +6 -0
  144. package/ts/types/Interface/api/payment/Params.ts +9 -0
  145. package/ts/types/Interface/api/payment/Util.ts +26 -0
  146. package/ts/types/Interface/api/society/QueryPaginatedSociety.ts +6 -0
  147. package/ts/types/Interface/api/user/ParamsGetAllUserWithRoles.ts +1 -1
  148. package/ts/types/Interface/models/IExercicePrestation.ts +1 -0
  149. package/ts/types/Interface/models/ISociety.ts +2 -0
  150. package/ts/types/index.ts +3 -0
  151. package/ts/utils/payment.ts +194 -2
  152. package/ts/utils/tests/payment.spec.ts +466 -0
  153. package/ts/utils/vat/utils.ts +16 -0
@@ -1,3 +1,6 @@
1
+ 'use strict';
2
+ import { PaymentMethod, getTaxesIncludedAmount } from '../types';
3
+ import * as dayjs from 'dayjs';
1
4
  /**
2
5
  * A partir d'une liste de payment (avec include jusqu'à prestationList,
3
6
  * avec en attributs 'isComptable' | 'isJuridique' | 'isSocial' | 'isOther')
@@ -44,5 +47,171 @@ const groupPaymentsByServiceType = (payments, types = ['isComptable', 'isJuridiq
44
47
  }
45
48
  return societyPayment;
46
49
  };
47
- export { groupPaymentsByServiceType, };
50
+ const calculateFees = (amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat) => {
51
+ const yearlyPriceIncreasing = 1.0275;
52
+ const appCost = getTaxesIncludedAmount(14.9, idVat);
53
+ const oneYearLessIfIn3LastMonthsOfYear = dayjs(goToClient).month() >= 9 ? 1 : 0;
54
+ if (dayjs(paymentDate).year() - dayjs().year() > 0) {
55
+ const nbYearsMore = dayjs(paymentDate).year() - dayjs().year() - oneYearLessIfIn3LastMonthsOfYear;
56
+ // on applique X fois l'augmentation
57
+ // ex. : si on lance l'appel en 2024, et qu'on génére un paiement pour 2026, on applique 2 fois l'augmentation
58
+ // soit amount * yearlyPriceIncreasing * yearlyPriceIncreasing
59
+ // soit amount * yearlyPriceIncreasing ^ nbYearsMore
60
+ amount = amount * Math.pow(yearlyPriceIncreasing, nbYearsMore);
61
+ }
62
+ // À partir du second exercice non express, on applique le coût de l'application (14,9€ HT)
63
+ if (nbExoNonExpressGenerated >= 2) {
64
+ amount += appCost;
65
+ }
66
+ return Math.round(100 * amount) / 100;
67
+ };
68
+ /**
69
+ // * @param {number} firstPaymentAmount - amount of the first payment (first regulation of the customer)
70
+ * @param {Date} firstExerciceNonExpresssEndDate - end date of the first exercice non express
71
+ * @param {number} idPrestation - prestation id
72
+ * @param {IPrestationList} prestationList - type of prestation (hidden: 0, isCatalog: 1, isComptable: 1)
73
+ * @param {number} idVat - vat id of society linked
74
+ * @param {number} yearlyAmountNonExpress - yearly amount of non express prestation (HT)
75
+ * @param {PartialExercicePrestationExpress[]} listPartialExercicePrestationExpress - list of exercicePrestation linked to idPrestation -> used to get express
76
+ * @param {IRegulation[]} listRegulations - list of regulations linked to idPrestation (TTC)
77
+ * @returns { IPayment[] } list of payment to create for billing auto, after each presta go to onBoarding
78
+ */
79
+ const calculatePaymentsAuto = (params) => {
80
+ const { goToClient, firstExerciceNonExpresssEndDate, idPrestation, prestationList, idVat, yearlyAmountNonExpress, listPartialExercicePrestationExpress, listRegulations } = params;
81
+ const initializedPaymentDate = dayjs().endOf('month').diff(dayjs(), 'day') < 3 /* || dayjs().date() >= 15 */
82
+ ? dayjs().add(2, 'month').startOf('month').toDate()
83
+ : dayjs().add(1, 'month').startOf('month').toDate();
84
+ if (prestationList?.isCatalog || !prestationList?.isComptable)
85
+ throw new Error('Ce type de prestation ne correspond pas aux conditions attendues.');
86
+ // if (!listRegulations?.length) throw new Error('List of regulations can not be empty');
87
+ if (listPartialExercicePrestationExpress.length && listPartialExercicePrestationExpress?.some((ep) => !ep?.startDate))
88
+ throw new Error('Start date of some exercice are missing');
89
+ if (!listRegulations?.every((r) => !!r?.amount || !!r?.amountUsed))
90
+ throw new Error('Amount and amountUsed are missing for regulations');
91
+ const nbExoExpress = listPartialExercicePrestationExpress.length;
92
+ const listPayments = [];
93
+ // on récupère le/les premiers réglements effectués, non alloués
94
+ const sumRegulations = listRegulations.reduce((acc, r) => acc + r.amount - r.amountUsed, 0);
95
+ let remainingAmount = -sumRegulations; //TTC
96
+ let paymentDate = initializedPaymentDate;
97
+ //On order les exercicePrestation par startDate ASC et id ASC
98
+ listPartialExercicePrestationExpress.sort((a, b) => {
99
+ const aStartDate = a?.startDate;
100
+ const bStartDate = b?.startDate;
101
+ return dayjs(aStartDate).diff(bStartDate);
102
+ });
103
+ //On ajoute un paiement initial correspondant à la somme des régulations
104
+ if (sumRegulations) {
105
+ listPayments.push({
106
+ amount: sumRegulations,
107
+ datePayment: dayjs().toDate(),
108
+ idPrestation,
109
+ idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
110
+ closingDate: listPartialExercicePrestationExpress?.length ? listPartialExercicePrestationExpress[0].endDate : firstExerciceNonExpresssEndDate,
111
+ });
112
+ }
113
+ // =========================
114
+ // EXPRESS
115
+ // =========================
116
+ listPartialExercicePrestationExpress.forEach((exercicePrestation) => {
117
+ remainingAmount += getTaxesIncludedAmount(exercicePrestation.totalAmount, idVat); //TTC
118
+ //Si le premier règlement couvre le coût de cet exercicePrestation, on passe au suivant
119
+ if (remainingAmount <= 0)
120
+ return;
121
+ //express : on étale en countExpressMonthlyPayment (nb de mensualités)
122
+ let remainingAmountByExercicePrestation = remainingAmount; //TTC
123
+ let countExpressMonthlyPayment = exercicePrestation?.countExpressMonthlyPayment ?? 3; //TTC
124
+ const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / countExpressMonthlyPayment) / 100; //TTC
125
+ for (let index = 1; index <= countExpressMonthlyPayment; index++) {
126
+ //Si un premier règlement est généré avec le montant des regulations, on le considère comme une mensualité
127
+ if (index === 1 && sumRegulations)
128
+ countExpressMonthlyPayment -= 1;
129
+ // 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
130
+ // et on applique le taux de tva de la société
131
+ const amount = index < countExpressMonthlyPayment ? monthlyAmountRounded : remainingAmountByExercicePrestation; //TTC
132
+ listPayments.push({
133
+ amount,
134
+ datePayment: paymentDate,
135
+ idPrestation,
136
+ idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
137
+ closingDate: exercicePrestation.endDate,
138
+ });
139
+ remainingAmountByExercicePrestation -= monthlyAmountRounded;
140
+ paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
141
+ }
142
+ remainingAmount = 0;
143
+ });
144
+ // =========================
145
+ // NON EXPRESS
146
+ // =========================
147
+ // on lisse sur le nb de mois restants (avec au minimum 3 mensualités)
148
+ // Si un seul exo express, alors on met les paiements de l'exo actuel en parallèle
149
+ // sinon, ils sont à la suite des express
150
+ if (nbExoExpress <= 1)
151
+ paymentDate = initializedPaymentDate;
152
+ let nbExoNonExpressGenerated = 1;
153
+ let exerciceEndDate = dayjs(firstExerciceNonExpresssEndDate).toDate();
154
+ //On génère au minimum 2 exercices plein
155
+ while (nbExoNonExpressGenerated <= 2) {
156
+ //On compte le nb de mois restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
157
+ let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));
158
+ if (countMonthsBeforeExerciceEnd < 3)
159
+ countMonthsBeforeExerciceEnd = 3;
160
+ remainingAmount += getTaxesIncludedAmount(yearlyAmountNonExpress, idVat);
161
+ let remainingAmountByExercicePrestation = remainingAmount;
162
+ const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd) / 100; //TTC
163
+ if (monthlyAmountRounded > 0) {
164
+ for (let index = 1; index <= countMonthsBeforeExerciceEnd; index++) {
165
+ let amount = index < countMonthsBeforeExerciceEnd ? monthlyAmountRounded : Math.round(100 * remainingAmountByExercicePrestation) / 100;
166
+ // Si besoin, on applique les frais nécessaires :
167
+ // - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
168
+ // - frais d'application dès les second exo non express
169
+ amount = calculateFees(amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat);
170
+ listPayments.push({
171
+ amount,
172
+ datePayment: paymentDate,
173
+ idPrestation,
174
+ idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
175
+ closingDate: exerciceEndDate,
176
+ });
177
+ remainingAmountByExercicePrestation -= monthlyAmountRounded;
178
+ paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
179
+ }
180
+ exerciceEndDate = dayjs(exerciceEndDate).startOf('month').add(1, 'year').endOf('month').toDate();
181
+ }
182
+ nbExoNonExpressGenerated += 1;
183
+ remainingAmount = 0;
184
+ }
185
+ // =========================
186
+ // JUSQU'EN DECEMBRE
187
+ // =========================
188
+ //On compte le nb d'exercices restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
189
+ // let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true)); //Logiquement, 12
190
+ // if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;
191
+ remainingAmount += yearlyAmountNonExpress;
192
+ const remainingAmountByExercicePrestation = remainingAmount;
193
+ const monthlyAmountRounded = Math.round(100 * remainingAmountByExercicePrestation / 12) / 100;
194
+ // Si aucun paiement généré, on stoppe là
195
+ if (!listPayments.length)
196
+ return [];
197
+ while (dayjs(listPayments.slice(-1)[0].datePayment).month() < 11) {
198
+ let amount = monthlyAmountRounded;
199
+ // Si besoin, on applique les frais nécessaires :
200
+ // - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
201
+ // - frais d'application dès les second exo non express
202
+ amount = calculateFees(amount, goToClient, paymentDate, nbExoNonExpressGenerated, idVat);
203
+ // On applique le taux de tva de la société
204
+ amount = getTaxesIncludedAmount(amount, idVat);
205
+ listPayments.push({
206
+ amount,
207
+ datePayment: paymentDate,
208
+ idPrestation,
209
+ idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
210
+ closingDate: exerciceEndDate,
211
+ });
212
+ paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
213
+ }
214
+ return listPayments;
215
+ };
216
+ export { groupPaymentsByServiceType, calculatePaymentsAuto, };
48
217
  //# sourceMappingURL=payment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../ts/utils/payment.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,MAAM,0BAA0B,GAAG,CAAC,QAAoB,EAAE,QAAoE,CAAC,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,CAAC,EAAsB,EAAE;IACzM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,IAAI,KAAK,CAAC,CAAC;IAChH,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,IAAI,EAAE,EAAE,mBAAmB,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;IAC3J,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,IAAI,EAAE,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC;IACjK,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,IAAI,CAAC,EAAE,EAAE,mBAAmB,EAAE,eAAe,EAAE,WAAW,IAAI,CAAC,EAAE,EAAE,mBAAmB,EAAE,eAAe,EAAE,QAAQ,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,CAAC;YAClB,GAAG,eAAe,CAAC,CAAC,CAAC;YACrB,IAAI,EAAE,aAAa;YACnB,YAAY,EAAE,eAAe;SAC9B,CAAC,CAAC;KACJ;IACD,IAAI,YAAY,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACrD,cAAc,CAAC,IAAI,CAAC;YAClB,GAAG,YAAY,CAAC,CAAC,CAAC;YAClB,IAAI,EAAE,UAAU;YAChB,YAAY,EAAE,YAAY;SAC3B,CAAC,CAAC;KACJ;IACD,IAAI,eAAe,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;QAC3D,cAAc,CAAC,IAAI,CAAC;YAClB,GAAG,eAAe,CAAC,CAAC,CAAC;YACrB,IAAI,EAAE,aAAa;YACnB,YAAY,EAAE,eAAe;SAC9B,CAAC,CAAC;KACJ;IACD,IAAI,WAAW,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;QACnD,cAAc,CAAC,IAAI,CAAC;YAClB,GAAG,WAAW,CAAC,CAAC,CAAC;YACjB,IAAI,EAAE,SAAS;YACf,YAAY,EAAE,WAAW;SAC1B,CAAC,CAAC;KACJ;IACD,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF,OAAO,EACL,0BAA0B,GAC3B,CAAC","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,YAAY,CAAC;AAEb,OAAO,EAAgD,aAAa,EAAe,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAC5H,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B;;;;;;;;;GASG;AACH,MAAM,0BAA0B,GAAG,CAAC,QAAoB,EAAE,QAAoE,CAAC,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,CAAC,EAAsB,EAAE;IACzM,MAAM,eAAe,GAAG,QAAQ,CAAC,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AY;YACZ,eAAe,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE;YAC9C,WAAW,EAAE,eAAe;SAC7B,CAAC,CAAC;QACH,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;KAC5E;IAED,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,OAAO,EACL,0BAA0B,EAAE,qBAAqB,GAClD,CAAC","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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=payment.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.spec.d.ts","sourceRoot":"","sources":["../../../../ts/utils/tests/payment.spec.ts"],"names":[],"mappings":""}