@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.
Files changed (216) 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/Commercial.d.ts +4 -1
  6. package/dist/cjs/api/resources/Commercial.d.ts.map +1 -1
  7. package/dist/cjs/api/resources/Commercial.js +3 -0
  8. package/dist/cjs/api/resources/Commercial.js.map +1 -1
  9. package/dist/cjs/api/resources/Exercice.d.ts +2 -2
  10. package/dist/cjs/api/resources/Exercice.d.ts.map +1 -1
  11. package/dist/cjs/api/resources/Exercice.js +2 -2
  12. package/dist/cjs/api/resources/Exercice.js.map +1 -1
  13. package/dist/cjs/api/resources/IntermediateManagementRebate.d.ts.map +1 -1
  14. package/dist/cjs/api/resources/IntermediateManagementRebate.js +6 -1
  15. package/dist/cjs/api/resources/IntermediateManagementRebate.js.map +1 -1
  16. package/dist/cjs/api/resources/Payment.d.ts +2 -1
  17. package/dist/cjs/api/resources/Payment.d.ts.map +1 -1
  18. package/dist/cjs/api/resources/Payment.js +3 -0
  19. package/dist/cjs/api/resources/Payment.js.map +1 -1
  20. package/dist/cjs/types/Enum/PriceGridClementine.d.ts +22 -0
  21. package/dist/cjs/types/Enum/PriceGridClementine.d.ts.map +1 -1
  22. package/dist/cjs/types/Enum/PriceGridClementine.js +27 -1
  23. package/dist/cjs/types/Enum/PriceGridClementine.js.map +1 -1
  24. package/dist/cjs/types/Enum/PriceGridLegalstart.d.ts +8 -0
  25. package/dist/cjs/types/Enum/PriceGridLegalstart.d.ts.map +1 -1
  26. package/dist/cjs/types/Enum/PriceGridLegalstart.js +8 -0
  27. package/dist/cjs/types/Enum/PriceGridLegalstart.js.map +1 -1
  28. package/dist/cjs/types/Enum/PriceGridPourcentage.d.ts +10 -0
  29. package/dist/cjs/types/Enum/PriceGridPourcentage.d.ts.map +1 -1
  30. package/dist/cjs/types/Enum/PriceGridPourcentage.js +84 -0
  31. package/dist/cjs/types/Enum/PriceGridPourcentage.js.map +1 -1
  32. package/dist/cjs/types/Enum/StatisticType.d.ts +2 -1
  33. package/dist/cjs/types/Enum/StatisticType.d.ts.map +1 -1
  34. package/dist/cjs/types/Enum/StatisticType.js +1 -0
  35. package/dist/cjs/types/Enum/StatisticType.js.map +1 -1
  36. package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.d.ts +4 -0
  37. package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.d.ts.map +1 -0
  38. package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.js +23 -0
  39. package/dist/cjs/types/Interface/api/authentification/ConnectFromSSO.js.map +1 -0
  40. package/dist/cjs/types/Interface/api/commercial/QueryGetStatsHistory.d.ts +7 -0
  41. package/dist/cjs/types/Interface/api/commercial/QueryGetStatsHistory.d.ts.map +1 -0
  42. package/dist/cjs/types/Interface/api/commercial/QueryGetStatsHistory.js +42 -0
  43. package/dist/cjs/types/Interface/api/commercial/QueryGetStatsHistory.js.map +1 -0
  44. package/dist/cjs/types/Interface/api/exercice/QueryExercice.d.ts +3 -0
  45. package/dist/cjs/types/Interface/api/exercice/QueryExercice.d.ts.map +1 -1
  46. package/dist/cjs/types/Interface/api/exercice/QueryExercice.js +11 -1
  47. package/dist/cjs/types/Interface/api/exercice/QueryExercice.js.map +1 -1
  48. package/dist/cjs/types/Interface/api/exercice/UpdateExercice.d.ts +1 -0
  49. package/dist/cjs/types/Interface/api/exercice/UpdateExercice.d.ts.map +1 -1
  50. package/dist/cjs/types/Interface/api/exercice/UpdateExercice.js +7 -0
  51. package/dist/cjs/types/Interface/api/exercice/UpdateExercice.js.map +1 -1
  52. package/dist/cjs/types/Interface/api/payment/Params.d.ts +4 -0
  53. package/dist/cjs/types/Interface/api/payment/Params.d.ts.map +1 -0
  54. package/dist/cjs/types/Interface/api/payment/Params.js +24 -0
  55. package/dist/cjs/types/Interface/api/payment/Params.js.map +1 -0
  56. package/dist/cjs/types/Interface/api/payment/Util.d.ts +27 -0
  57. package/dist/cjs/types/Interface/api/payment/Util.d.ts.map +1 -0
  58. package/dist/cjs/types/Interface/api/payment/Util.js +3 -0
  59. package/dist/cjs/types/Interface/api/payment/Util.js.map +1 -0
  60. package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.d.ts +1 -0
  61. package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.d.ts.map +1 -1
  62. package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.js +8 -0
  63. package/dist/cjs/types/Interface/api/society/QueryPaginatedSociety.js.map +1 -1
  64. package/dist/cjs/types/Interface/api/statistic/QueryInternal.d.ts +1 -1
  65. package/dist/cjs/types/Interface/api/statistic/QueryInternal.d.ts.map +1 -1
  66. package/dist/cjs/types/Interface/api/statistic/QueryInternal.js +5 -5
  67. package/dist/cjs/types/Interface/api/statistic/QueryInternal.js.map +1 -1
  68. package/dist/cjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js +1 -1
  69. package/dist/cjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js.map +1 -1
  70. package/dist/cjs/types/Interface/models/IExercicePrestation.d.ts +1 -0
  71. package/dist/cjs/types/Interface/models/IExercicePrestation.d.ts.map +1 -1
  72. package/dist/cjs/types/Interface/models/IExercicePrestation.js.map +1 -1
  73. package/dist/cjs/types/Interface/models/ISociety.d.ts +2 -1
  74. package/dist/cjs/types/Interface/models/ISociety.d.ts.map +1 -1
  75. package/dist/cjs/types/Interface/models/ISociety.js.map +1 -1
  76. package/dist/cjs/types/index.d.ts +4 -0
  77. package/dist/cjs/types/index.d.ts.map +1 -1
  78. package/dist/cjs/types/index.js +4 -0
  79. package/dist/cjs/types/index.js.map +1 -1
  80. package/dist/cjs/utils/payment.d.ts +15 -2
  81. package/dist/cjs/utils/payment.d.ts.map +1 -1
  82. package/dist/cjs/utils/payment.js +180 -2
  83. package/dist/cjs/utils/payment.js.map +1 -1
  84. package/dist/cjs/utils/prestation.d.ts +60 -0
  85. package/dist/cjs/utils/prestation.d.ts.map +1 -1
  86. package/dist/cjs/utils/prestation.js +4 -3
  87. package/dist/cjs/utils/prestation.js.map +1 -1
  88. package/dist/cjs/utils/tests/payment.spec.d.ts +2 -0
  89. package/dist/cjs/utils/tests/payment.spec.d.ts.map +1 -0
  90. package/dist/cjs/utils/tests/payment.spec.js +494 -0
  91. package/dist/cjs/utils/tests/payment.spec.js.map +1 -0
  92. package/dist/cjs/utils/vat/utils.d.ts +2 -0
  93. package/dist/cjs/utils/vat/utils.d.ts.map +1 -1
  94. package/dist/cjs/utils/vat/utils.js +19 -1
  95. package/dist/cjs/utils/vat/utils.js.map +1 -1
  96. package/dist/mjs/api/resources/Closing.d.ts +2 -1
  97. package/dist/mjs/api/resources/Closing.d.ts.map +1 -1
  98. package/dist/mjs/api/resources/Closing.js +3 -0
  99. package/dist/mjs/api/resources/Closing.js.map +1 -1
  100. package/dist/mjs/api/resources/Commercial.d.ts +4 -1
  101. package/dist/mjs/api/resources/Commercial.d.ts.map +1 -1
  102. package/dist/mjs/api/resources/Commercial.js +7 -0
  103. package/dist/mjs/api/resources/Commercial.js.map +1 -1
  104. package/dist/mjs/api/resources/Exercice.d.ts +2 -2
  105. package/dist/mjs/api/resources/Exercice.d.ts.map +1 -1
  106. package/dist/mjs/api/resources/Exercice.js +2 -2
  107. package/dist/mjs/api/resources/Exercice.js.map +1 -1
  108. package/dist/mjs/api/resources/IntermediateManagementRebate.d.ts.map +1 -1
  109. package/dist/mjs/api/resources/IntermediateManagementRebate.js +6 -1
  110. package/dist/mjs/api/resources/IntermediateManagementRebate.js.map +1 -1
  111. package/dist/mjs/api/resources/Payment.d.ts +2 -1
  112. package/dist/mjs/api/resources/Payment.d.ts.map +1 -1
  113. package/dist/mjs/api/resources/Payment.js +3 -0
  114. package/dist/mjs/api/resources/Payment.js.map +1 -1
  115. package/dist/mjs/types/Enum/PriceGridClementine.d.ts +22 -0
  116. package/dist/mjs/types/Enum/PriceGridClementine.d.ts.map +1 -1
  117. package/dist/mjs/types/Enum/PriceGridClementine.js +27 -1
  118. package/dist/mjs/types/Enum/PriceGridClementine.js.map +1 -1
  119. package/dist/mjs/types/Enum/PriceGridLegalstart.d.ts +8 -0
  120. package/dist/mjs/types/Enum/PriceGridLegalstart.d.ts.map +1 -1
  121. package/dist/mjs/types/Enum/PriceGridLegalstart.js +8 -0
  122. package/dist/mjs/types/Enum/PriceGridLegalstart.js.map +1 -1
  123. package/dist/mjs/types/Enum/PriceGridPourcentage.d.ts +10 -0
  124. package/dist/mjs/types/Enum/PriceGridPourcentage.d.ts.map +1 -1
  125. package/dist/mjs/types/Enum/PriceGridPourcentage.js +84 -0
  126. package/dist/mjs/types/Enum/PriceGridPourcentage.js.map +1 -1
  127. package/dist/mjs/types/Enum/StatisticType.d.ts +2 -1
  128. package/dist/mjs/types/Enum/StatisticType.d.ts.map +1 -1
  129. package/dist/mjs/types/Enum/StatisticType.js +1 -0
  130. package/dist/mjs/types/Enum/StatisticType.js.map +1 -1
  131. package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.d.ts +4 -0
  132. package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.d.ts.map +1 -0
  133. package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.js +20 -0
  134. package/dist/mjs/types/Interface/api/authentification/ConnectFromSSO.js.map +1 -0
  135. package/dist/mjs/types/Interface/api/commercial/QueryGetStatsHistory.d.ts +7 -0
  136. package/dist/mjs/types/Interface/api/commercial/QueryGetStatsHistory.d.ts.map +1 -0
  137. package/dist/mjs/types/Interface/api/commercial/QueryGetStatsHistory.js +42 -0
  138. package/dist/mjs/types/Interface/api/commercial/QueryGetStatsHistory.js.map +1 -0
  139. package/dist/mjs/types/Interface/api/exercice/QueryExercice.d.ts +3 -0
  140. package/dist/mjs/types/Interface/api/exercice/QueryExercice.d.ts.map +1 -1
  141. package/dist/mjs/types/Interface/api/exercice/QueryExercice.js +10 -0
  142. package/dist/mjs/types/Interface/api/exercice/QueryExercice.js.map +1 -1
  143. package/dist/mjs/types/Interface/api/exercice/UpdateExercice.d.ts +1 -0
  144. package/dist/mjs/types/Interface/api/exercice/UpdateExercice.d.ts.map +1 -1
  145. package/dist/mjs/types/Interface/api/exercice/UpdateExercice.js +8 -0
  146. package/dist/mjs/types/Interface/api/exercice/UpdateExercice.js.map +1 -1
  147. package/dist/mjs/types/Interface/api/payment/Params.d.ts +4 -0
  148. package/dist/mjs/types/Interface/api/payment/Params.d.ts.map +1 -0
  149. package/dist/mjs/types/Interface/api/payment/Params.js +21 -0
  150. package/dist/mjs/types/Interface/api/payment/Params.js.map +1 -0
  151. package/dist/mjs/types/Interface/api/payment/Util.d.ts +27 -0
  152. package/dist/mjs/types/Interface/api/payment/Util.d.ts.map +1 -0
  153. package/dist/mjs/types/Interface/api/payment/Util.js +2 -0
  154. package/dist/mjs/types/Interface/api/payment/Util.js.map +1 -0
  155. package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.d.ts +1 -0
  156. package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.d.ts.map +1 -1
  157. package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.js +8 -0
  158. package/dist/mjs/types/Interface/api/society/QueryPaginatedSociety.js.map +1 -1
  159. package/dist/mjs/types/Interface/api/statistic/QueryInternal.d.ts +1 -1
  160. package/dist/mjs/types/Interface/api/statistic/QueryInternal.d.ts.map +1 -1
  161. package/dist/mjs/types/Interface/api/statistic/QueryInternal.js +3 -3
  162. package/dist/mjs/types/Interface/api/statistic/QueryInternal.js.map +1 -1
  163. package/dist/mjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js +1 -1
  164. package/dist/mjs/types/Interface/api/user/ParamsGetAllUserWithRoles.js.map +1 -1
  165. package/dist/mjs/types/Interface/models/IExercicePrestation.d.ts +1 -0
  166. package/dist/mjs/types/Interface/models/IExercicePrestation.d.ts.map +1 -1
  167. package/dist/mjs/types/Interface/models/IExercicePrestation.js.map +1 -1
  168. package/dist/mjs/types/Interface/models/ISociety.d.ts +2 -1
  169. package/dist/mjs/types/Interface/models/ISociety.d.ts.map +1 -1
  170. package/dist/mjs/types/Interface/models/ISociety.js.map +1 -1
  171. package/dist/mjs/types/index.d.ts +4 -0
  172. package/dist/mjs/types/index.d.ts.map +1 -1
  173. package/dist/mjs/types/index.js +4 -0
  174. package/dist/mjs/types/index.js.map +1 -1
  175. package/dist/mjs/utils/payment.d.ts +15 -2
  176. package/dist/mjs/utils/payment.d.ts.map +1 -1
  177. package/dist/mjs/utils/payment.js +178 -1
  178. package/dist/mjs/utils/payment.js.map +1 -1
  179. package/dist/mjs/utils/prestation.d.ts +60 -0
  180. package/dist/mjs/utils/prestation.d.ts.map +1 -1
  181. package/dist/mjs/utils/prestation.js +1 -1
  182. package/dist/mjs/utils/prestation.js.map +1 -1
  183. package/dist/mjs/utils/tests/payment.spec.d.ts +2 -0
  184. package/dist/mjs/utils/tests/payment.spec.d.ts.map +1 -0
  185. package/dist/mjs/utils/tests/payment.spec.js +485 -0
  186. package/dist/mjs/utils/tests/payment.spec.js.map +1 -0
  187. package/dist/mjs/utils/vat/utils.d.ts +2 -0
  188. package/dist/mjs/utils/vat/utils.d.ts.map +1 -1
  189. package/dist/mjs/utils/vat/utils.js +14 -0
  190. package/dist/mjs/utils/vat/utils.js.map +1 -1
  191. package/package.json +1 -1
  192. package/ts/api/resources/Closing.ts +6 -1
  193. package/ts/api/resources/Commercial.ts +8 -0
  194. package/ts/api/resources/Exercice.ts +3 -3
  195. package/ts/api/resources/IntermediateManagementRebate.ts +6 -1
  196. package/ts/api/resources/Payment.ts +5 -1
  197. package/ts/types/Enum/PriceGridClementine.ts +27 -1
  198. package/ts/types/Enum/PriceGridLegalstart.ts +8 -0
  199. package/ts/types/Enum/PriceGridPourcentage.ts +84 -0
  200. package/ts/types/Enum/StatisticType.ts +1 -0
  201. package/ts/types/Interface/api/authentification/ConnectFromSSO.ts +8 -0
  202. package/ts/types/Interface/api/commercial/QueryGetStatsHistory.ts +26 -0
  203. package/ts/types/Interface/api/exercice/QueryExercice.ts +8 -0
  204. package/ts/types/Interface/api/exercice/UpdateExercice.ts +6 -0
  205. package/ts/types/Interface/api/payment/Params.ts +9 -0
  206. package/ts/types/Interface/api/payment/Util.ts +28 -0
  207. package/ts/types/Interface/api/society/QueryPaginatedSociety.ts +6 -0
  208. package/ts/types/Interface/api/statistic/QueryInternal.ts +1 -1
  209. package/ts/types/Interface/api/user/ParamsGetAllUserWithRoles.ts +1 -1
  210. package/ts/types/Interface/models/IExercicePrestation.ts +1 -0
  211. package/ts/types/Interface/models/ISociety.ts +2 -0
  212. package/ts/types/index.ts +4 -0
  213. package/ts/utils/payment.ts +200 -2
  214. package/ts/utils/prestation.ts +3 -1
  215. package/ts/utils/tests/payment.spec.ts +502 -0
  216. 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
+ }
@@ -30,4 +30,10 @@ export class QueryPaginatedSociety {
30
30
  @IsOptional()
31
31
  @IsNumber()
32
32
  page?: number;
33
+
34
+ @ApiPropertyOptional()
35
+ @IsOptional()
36
+ @IsBoolean()
37
+ @ToBoolean()
38
+ onlyOwners? = true;
33
39
  }
@@ -3,7 +3,7 @@ import {
3
3
  } from 'class-validator';
4
4
  import { ApiPropertyOptional } from '../../../../utils';
5
5
 
6
- export class QueryInternal {
6
+ export class QueryInternalAccountant {
7
7
  @ApiPropertyOptional()
8
8
  @IsOptional()
9
9
  @IsBoolean()
@@ -25,7 +25,7 @@ export class ParamsGetAllUserWithRoles {
25
25
  @IsString({
26
26
  each: true,
27
27
  })
28
- @IsIn(['permissions'], { each: true })
28
+ @IsIn(['permissions', 'businessPartners'], { each: true })
29
29
  includes?: string[];
30
30
 
31
31
  @ApiPropertyOptional()
@@ -12,6 +12,7 @@ export interface IExercicePrestation {
12
12
  amountSocial: number | null;
13
13
  monthOffers: number | null;
14
14
  isInCA: boolean;
15
+ countExpressMonthlyPayment: number | null;
15
16
  idBalanceSheet: number | null;
16
17
  createdAt?: Date | null;
17
18
  updatedAt?: Date | null;
@@ -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';
@@ -1,4 +1,9 @@
1
- import { IPayment } from '../types';
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
  };
@@ -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