@silexpert/core 1.1.308 → 1.1.310
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/CommercialDocument.d.ts +3 -1
- package/dist/cjs/api/resources/CommercialDocument.d.ts.map +1 -1
- package/dist/cjs/api/resources/CommercialDocument.js +9 -0
- package/dist/cjs/api/resources/CommercialDocument.js.map +1 -1
- package/dist/cjs/api/resources/KilometricAllowance.d.ts +2 -0
- package/dist/cjs/api/resources/KilometricAllowance.d.ts.map +1 -1
- package/dist/cjs/api/resources/KilometricAllowance.js +9 -0
- package/dist/cjs/api/resources/KilometricAllowance.js.map +1 -1
- package/dist/cjs/types/Enum/EstimateInvoice.d.ts +4 -0
- package/dist/cjs/types/Enum/EstimateInvoice.d.ts.map +1 -1
- package/dist/cjs/types/Enum/EstimateInvoice.js +27 -1
- package/dist/cjs/types/Enum/EstimateInvoice.js.map +1 -1
- package/dist/cjs/types/Enum/PriceGridClementine.js +1 -1
- package/dist/cjs/types/Enum/PriceGridClementine.js.map +1 -1
- package/dist/cjs/types/Interface/api/bankAccount/Read.d.ts +1 -0
- package/dist/cjs/types/Interface/api/bankAccount/Read.d.ts.map +1 -1
- package/dist/cjs/types/Interface/api/bankAccount/Read.js.map +1 -1
- package/dist/cjs/types/Interface/api/commercialManagement/Query.d.ts +6 -0
- package/dist/cjs/types/Interface/api/commercialManagement/Query.d.ts.map +1 -1
- package/dist/cjs/types/Interface/api/commercialManagement/Query.js +26 -1
- package/dist/cjs/types/Interface/api/commercialManagement/Query.js.map +1 -1
- package/dist/cjs/types/Interface/api/payment/Util.d.ts +2 -0
- package/dist/cjs/types/Interface/api/payment/Util.d.ts.map +1 -1
- package/dist/cjs/types/Interface/api/payment/Util.js.map +1 -1
- package/dist/cjs/types/Interface/models/IPrestation.d.ts +1 -0
- package/dist/cjs/types/Interface/models/IPrestation.d.ts.map +1 -1
- package/dist/cjs/types/Interface/models/IPrestation.js.map +1 -1
- package/dist/cjs/utils/payment.d.ts +2 -0
- package/dist/cjs/utils/payment.d.ts.map +1 -1
- package/dist/cjs/utils/payment.js +83 -33
- package/dist/cjs/utils/payment.js.map +1 -1
- package/dist/cjs/utils/tests/payment.spec.js +36 -0
- package/dist/cjs/utils/tests/payment.spec.js.map +1 -1
- package/dist/mjs/api/resources/CommercialDocument.d.ts +3 -1
- package/dist/mjs/api/resources/CommercialDocument.d.ts.map +1 -1
- package/dist/mjs/api/resources/CommercialDocument.js +9 -0
- package/dist/mjs/api/resources/CommercialDocument.js.map +1 -1
- package/dist/mjs/api/resources/KilometricAllowance.d.ts +2 -0
- package/dist/mjs/api/resources/KilometricAllowance.d.ts.map +1 -1
- package/dist/mjs/api/resources/KilometricAllowance.js +9 -0
- package/dist/mjs/api/resources/KilometricAllowance.js.map +1 -1
- package/dist/mjs/types/Enum/EstimateInvoice.d.ts +4 -0
- package/dist/mjs/types/Enum/EstimateInvoice.d.ts.map +1 -1
- package/dist/mjs/types/Enum/EstimateInvoice.js +26 -0
- package/dist/mjs/types/Enum/EstimateInvoice.js.map +1 -1
- package/dist/mjs/types/Enum/PriceGridClementine.js +1 -1
- package/dist/mjs/types/Enum/PriceGridClementine.js.map +1 -1
- package/dist/mjs/types/Interface/api/bankAccount/Read.d.ts +1 -0
- package/dist/mjs/types/Interface/api/bankAccount/Read.d.ts.map +1 -1
- package/dist/mjs/types/Interface/api/bankAccount/Read.js.map +1 -1
- package/dist/mjs/types/Interface/api/commercialManagement/Query.d.ts +6 -0
- package/dist/mjs/types/Interface/api/commercialManagement/Query.d.ts.map +1 -1
- package/dist/mjs/types/Interface/api/commercialManagement/Query.js +29 -1
- package/dist/mjs/types/Interface/api/commercialManagement/Query.js.map +1 -1
- package/dist/mjs/types/Interface/api/payment/Util.d.ts +2 -0
- package/dist/mjs/types/Interface/api/payment/Util.d.ts.map +1 -1
- package/dist/mjs/types/Interface/api/payment/Util.js.map +1 -1
- package/dist/mjs/types/Interface/models/IPrestation.d.ts +1 -0
- package/dist/mjs/types/Interface/models/IPrestation.d.ts.map +1 -1
- package/dist/mjs/types/Interface/models/IPrestation.js.map +1 -1
- package/dist/mjs/utils/payment.d.ts +2 -0
- package/dist/mjs/utils/payment.d.ts.map +1 -1
- package/dist/mjs/utils/payment.js +83 -34
- package/dist/mjs/utils/payment.js.map +1 -1
- package/dist/mjs/utils/tests/payment.spec.js +37 -1
- package/dist/mjs/utils/tests/payment.spec.js.map +1 -1
- package/package.json +1 -1
- package/ts/api/resources/CommercialDocument.ts +11 -0
- package/ts/api/resources/KilometricAllowance.ts +10 -0
- package/ts/types/Enum/EstimateInvoice.ts +28 -1
- package/ts/types/Enum/PriceGridClementine.ts +1 -1
- package/ts/types/Interface/api/bankAccount/Read.ts +1 -0
- package/ts/types/Interface/api/commercialManagement/Query.ts +21 -1
- package/ts/types/Interface/api/payment/Util.ts +2 -0
- package/ts/types/Interface/models/IPrestation.ts +1 -0
- package/ts/utils/payment.ts +86 -34
- package/ts/utils/tests/payment.spec.ts +37 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Query.js","sourceRoot":"","sources":["../../../../../../ts/types/Interface/api/commercialManagement/Query.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"Query.js","sourceRoot":"","sources":["../../../../../../ts/types/Interface/api/commercialManagement/Query.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,GAC9D,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gDAAgD,CAAC;AAC3E,OAAO,EAAgB,cAAc,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAA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AAE;IACd,UAAU,EAAE;;yEACQ;AAErB;IAAC,mBAAmB,EAAE;IACrB,UAAU,EAAE;IACZ,YAAY,EAAE;;uEACI;AAEnB;IAAC,WAAW,EAAE;IACb,KAAK,EAAE;;yEACY;AAEpB;IAAC,WAAW,EAAE;IACb,OAAO,EAAE;;qEACqB","sourcesContent":["import {\n IsArray, IsBoolean, IsDateString, IsInt, IsOptional, IsString,\n} from 'class-validator';\nimport { Order } from '../../..';\nimport { ApiProperty, ApiPropertyOptional } from '../../../../utils';\nimport { ToBoolean } from '../../../../utils/transforms/boolean.transform';\nimport { DiscountType, EstimateStatus, InvoiceStatus } from '../../../Enum/CommercialManagement';\nimport { EstimateInvoiceType } from '../../../Enum/EstimateInvoice';\nimport { QueryPaginate } from '../BasePaginate';\n\nexport class QueryInvoice {\n @ApiPropertyOptional()\n @IsOptional()\n @IsDateString()\n minDate?: string;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsDateString()\n maxDate?: string;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsString()\n search?: string;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsString()\n status?: InvoiceStatus;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsString()\n orderBy?: string;\n\n @ApiPropertyOptional()\n @IsBoolean()\n @ToBoolean()\n @IsOptional()\n toAnnotate?: boolean;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsBoolean()\n @ToBoolean()\n isDescending?: boolean;\n}\n\nexport interface ParamPaginatedInvoices {\n idSociety: number;\n date?: {\n gte?: string;\n lte?: string;\n };\n status?: InvoiceStatus;\n search?: string;\n pagination: QueryPaginate;\n toAnnotate?: boolean;\n order?: Order;\n}\n\nexport class QueryGetDefaultPayload {\n @ApiProperty()\n idEstimateInvoiceType: EstimateInvoiceType;\n}\n\nexport class QueryNextReference {\n @ApiProperty()\n idEstimateInvoiceType: EstimateInvoiceType;\n\n @ApiPropertyOptional()\n @IsBoolean()\n @ToBoolean()\n @IsOptional()\n isDraft?: boolean;\n}\n\nexport interface Discount {\n type: DiscountType,\n amount: number\n}\n\nexport class QueryPreviewDocument {\n @ApiProperty()\n idEstimateInvoiceType: EstimateInvoiceType;\n}\n\nexport class QueryDocumentPaginated {\n @ApiProperty()\n @IsArray()\n types: EstimateInvoiceType[];\n\n @ApiPropertyOptional()\n @IsDateString()\n @IsOptional()\n minDate?: string;\n\n @ApiPropertyOptional()\n @IsDateString()\n @IsOptional()\n maxDate?: string;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsString()\n status?: EstimateStatus;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsString()\n orderBy?: string;\n\n @ApiPropertyOptional()\n @IsBoolean()\n @ToBoolean()\n @IsOptional()\n isDescending?: boolean;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsString()\n search?: string;\n\n @ApiPropertyOptional()\n @IsBoolean()\n @ToBoolean()\n @IsOptional()\n isDraft?: boolean;\n}\n\nexport class QueryCountByStatus {\n @ApiPropertyOptional()\n @IsDateString()\n @IsOptional()\n minDate?: string;\n\n @ApiPropertyOptional()\n @IsDateString()\n @IsOptional()\n maxDate?: string;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsString()\n search?: string;\n\n @ApiPropertyOptional()\n @IsBoolean()\n @ToBoolean()\n @IsOptional()\n isDraft?: boolean;\n}\n\nexport class QueryExportCommercialManagementIntoCSV {\n @ApiPropertyOptional()\n @IsDateString()\n @IsOptional()\n startDate?: string;\n\n @ApiPropertyOptional()\n @IsOptional()\n @IsDateString()\n endDate?: string;\n\n @ApiProperty()\n @IsInt()\n idSociety: number;\n\n @ApiProperty()\n @IsArray()\n types: EstimateInvoiceType[];\n}"]}
|
|
@@ -10,6 +10,8 @@ export interface ParamsForPaymentsAuto {
|
|
|
10
10
|
firstExerciceNonExpresssEndDate: Date;
|
|
11
11
|
goToClient: Date;
|
|
12
12
|
idPrestation: number;
|
|
13
|
+
idLegalForm: number;
|
|
14
|
+
isWithApplicationFees: boolean;
|
|
13
15
|
idVat: number;
|
|
14
16
|
prestationList: IPrestationList;
|
|
15
17
|
yearlyAmountNonExpress: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../../../../ts/types/Interface/api/payment/Util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,gCAAgC;IAC/C,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,0BAA0B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,WAAW,EAAE,MAAM,CAAA;CACpB;AACD,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B,EAAE,IAAI,CAAC;IACtC,UAAU,EAAE,IAAI,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,eAAe,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,0BAA0B,EAAE,MAAM,CAAC;IACnC,oCAAoC,EAAE,gCAAgC,EAAE,CAAC;IACzE,eAAe,EAAE,WAAW,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,IAAI,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,IAAI,CAAC;CACnB"}
|
|
1
|
+
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../../../../ts/types/Interface/api/payment/Util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,gCAAgC;IAC/C,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,0BAA0B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,WAAW,EAAE,MAAM,CAAA;CACpB;AACD,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B,EAAE,IAAI,CAAC;IACtC,UAAU,EAAE,IAAI,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,eAAe,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,0BAA0B,EAAE,MAAM,CAAC;IACnC,oCAAoC,EAAE,gCAAgC,EAAE,CAAC;IACzE,eAAe,EAAE,WAAW,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,IAAI,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,IAAI,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Util.js","sourceRoot":"","sources":["../../../../../../ts/types/Interface/api/payment/Util.ts"],"names":[],"mappings":"","sourcesContent":["import { IPrestationList, IRegulation } from '../../..';\n\nexport interface PartialExercicePrestationExpress {\n startDate: Date;\n endDate: Date;\n countExpressMonthlyPayment: number | null; // if null, non express | if not null, express\n totalAmount: number\n}\nexport interface ParamsForPaymentsAuto {\n idTypeBrand: number;\n firstExerciceNonExpresssEndDate: Date;\n goToClient: Date;\n idPrestation: number;\n idVat: number;\n prestationList: IPrestationList;\n yearlyAmountNonExpress: number;\n nextYearlyAmountNonExpress: number;\n listPartialExercicePrestationExpress: PartialExercicePrestationExpress[];\n listRegulations: IRegulation[];\n}\n\nexport interface PaymentAuto {\n amount: number;\n isPaid?: boolean;\n datePayment: Date;\n idPrestation: number;\n idPaymentMethod: number;\n closingDate: Date;\n}"]}
|
|
1
|
+
{"version":3,"file":"Util.js","sourceRoot":"","sources":["../../../../../../ts/types/Interface/api/payment/Util.ts"],"names":[],"mappings":"","sourcesContent":["import { IPrestationList, IRegulation } from '../../..';\n\nexport interface PartialExercicePrestationExpress {\n startDate: Date;\n endDate: Date;\n countExpressMonthlyPayment: number | null; // if null, non express | if not null, express\n totalAmount: number\n}\nexport interface ParamsForPaymentsAuto {\n idTypeBrand: number;\n firstExerciceNonExpresssEndDate: Date;\n goToClient: Date;\n idPrestation: number;\n idLegalForm: number;\n isWithApplicationFees: boolean;\n idVat: number;\n prestationList: IPrestationList;\n yearlyAmountNonExpress: number;\n nextYearlyAmountNonExpress: number;\n listPartialExercicePrestationExpress: PartialExercicePrestationExpress[];\n listRegulations: IRegulation[];\n}\n\nexport interface PaymentAuto {\n amount: number;\n isPaid?: boolean;\n datePayment: Date;\n idPrestation: number;\n idPaymentMethod: number;\n closingDate: Date;\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IPrestation.d.ts","sourceRoot":"","sources":["../../../../../ts/types/Interface/models/IPrestation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAG9B,MAAM,WAAW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,CAAC;IAClC,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IACpD,mBAAmB,CAAC,EAAE,WAAW,CAAC;IAClC,gBAAgB,CAAC,EAAE,WAAW,CAAC;IAC/B,kBAAkB,CAAC,EAAE,WAAW,CAAC;IACjC,oBAAoB,CAAC,EAAE,QAAQ,CAAC;IAChC,gCAAgC,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACzD,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC3C,eAAe,CAAC,EAAE,gBAAgB,CAAC;IACnC,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IPrestation.js","sourceRoot":"","sources":["../../../../../ts/types/Interface/models/IPrestation.ts"],"names":[],"mappings":"","sourcesContent":["import { IExercice } from './IExercice';\nimport { IPayment } from './IPayment';\nimport { IPrestationList } from './IPrestationList';\nimport { IPrestationComplementary } from './IPrestationComplementary';\nimport { ISociety } from './ISociety';\nimport { IExercicePrestation } from './IExercicePrestation';\nimport { ICustomerSignature } from './ICustomerSignature';\nimport { ITerminationList } from './ITerminationList';\nimport { IUser } from '../..';\n\n// prestations\nexport interface IPrestation {\n id?: number;\n numPrestation: string | null;\n statePrevi: number | null;\n archive: boolean;\n withStatuteDrafted: boolean | null;\n withCaptainContrat: boolean | null;\n withStatutesApportNature: boolean | null;\n withStatutesAutorisationTutelle: boolean | null;\n withStatutesFileAccre: boolean | null;\n paid: boolean | null;\n signed: boolean | null;\n toAdministratif: number | null;\n goToAdministratif: Date | null;\n administratifStatus: number;\n toConstitution: number;\n dateValidPrestation: Date | null;\n goToOnboarding: Date | null;\n dateLeavingOnboarding?: Date | null;\n goToClient: Date | null;\n goToFacturation?: Date | null;\n dateLeavingFacturation?: Date | null;\n scoring: number | null;\n state: boolean;\n commentPdf: string | null;\n token: string | null;\n size: number | null;\n inProgress: number | null;\n idSociety: number;\n idPrestationList: number;\n idPrestationComplementary: number | null;\n gestionJuridique: boolean;\n idPrestationSocial: number | null;\n idPrestationJuridique: number | null;\n idPrestationCreation: number | null;\n idPrestationDeclarationIR: number | null;\n idPrestationControleFiscal: number | null;\n idOnBoarder: number | null;\n idStateAppointment: number | null;\n totalAmount?: number;\n discountAmount?: number;\n debitType?: string;\n createdAt?: Date | null;\n updatedAt?: Date | null;\n deletedAt?: Date | null;\n\n // Associations\n exercices?: IExercice[];\n prestationsPayments?: IPayment[];\n prestationsList?: IPrestationList;\n prestationsComplementary?: IPrestationComplementary;\n prestationJuridique?: IPrestation;\n prestationSocial?: IPrestation;\n prestationCreation?: IPrestation;\n societiesPrestations?: ISociety;\n prestationsDetailsBeforeExercice?: IExercicePrestation[];\n customersSignatures?: ICustomerSignature[];\n terminationList?: ITerminationList;\n onBoarder?: IUser;\n}"]}
|
|
1
|
+
{"version":3,"file":"IPrestation.js","sourceRoot":"","sources":["../../../../../ts/types/Interface/models/IPrestation.ts"],"names":[],"mappings":"","sourcesContent":["import { IExercice } from './IExercice';\nimport { IPayment } from './IPayment';\nimport { IPrestationList } from './IPrestationList';\nimport { IPrestationComplementary } from './IPrestationComplementary';\nimport { ISociety } from './ISociety';\nimport { IExercicePrestation } from './IExercicePrestation';\nimport { ICustomerSignature } from './ICustomerSignature';\nimport { ITerminationList } from './ITerminationList';\nimport { IUser } from '../..';\n\n// prestations\nexport interface IPrestation {\n id?: number;\n numPrestation: string | null;\n statePrevi: number | null;\n archive: boolean;\n withStatuteDrafted: boolean | null;\n withCaptainContrat: boolean | null;\n withStatutesApportNature: boolean | null;\n withStatutesAutorisationTutelle: boolean | null;\n withStatutesFileAccre: boolean | null;\n paid: boolean | null;\n signed: boolean | null;\n toAdministratif: number | null;\n goToAdministratif: Date | null;\n administratifStatus: number;\n toConstitution: number;\n dateValidPrestation: Date | null;\n goToOnboarding: Date | null;\n dateLeavingOnboarding?: Date | null;\n goToClient: Date | null;\n goToFacturation?: Date | null;\n dateLeavingFacturation?: Date | null;\n scoring: number | null;\n isWithApplicationFees?: boolean;\n state: boolean;\n commentPdf: string | null;\n token: string | null;\n size: number | null;\n inProgress: number | null;\n idSociety: number;\n idPrestationList: number;\n idPrestationComplementary: number | null;\n gestionJuridique: boolean;\n idPrestationSocial: number | null;\n idPrestationJuridique: number | null;\n idPrestationCreation: number | null;\n idPrestationDeclarationIR: number | null;\n idPrestationControleFiscal: number | null;\n idOnBoarder: number | null;\n idStateAppointment: number | null;\n totalAmount?: number;\n discountAmount?: number;\n debitType?: string;\n createdAt?: Date | null;\n updatedAt?: Date | null;\n deletedAt?: Date | null;\n\n // Associations\n exercices?: IExercice[];\n prestationsPayments?: IPayment[];\n prestationsList?: IPrestationList;\n prestationsComplementary?: IPrestationComplementary;\n prestationJuridique?: IPrestation;\n prestationSocial?: IPrestation;\n prestationCreation?: IPrestation;\n societiesPrestations?: ISociety;\n prestationsDetailsBeforeExercice?: IExercicePrestation[];\n customersSignatures?: ICustomerSignature[];\n terminationList?: ITerminationList;\n onBoarder?: IUser;\n}"]}
|
|
@@ -18,6 +18,8 @@ declare const groupPaymentsByServiceType: (payments: IPayment[], types?: ('isCom
|
|
|
18
18
|
// * @param {number} firstPaymentAmount - amount of the first payment (first regulation of the customer)
|
|
19
19
|
* @param {Date} firstExerciceNonExpresssEndDate - end date of the first exercice non express
|
|
20
20
|
* @param {number} idPrestation - prestation id
|
|
21
|
+
* @param {number} idLegalForm - legal form id of the society
|
|
22
|
+
* @param {boolean} isWithApplicationFees - if the prestation has application fees to paid
|
|
21
23
|
* @param {IPrestationList} prestationList - type of prestation (hidden: 0, isCatalog: 1, isComptable: 1)
|
|
22
24
|
* @param {number} idVat - vat id of society linked
|
|
23
25
|
* @param {number} yearlyAmountNonExpress - yearly amount of non express prestation (HT)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../ts/utils/payment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAe,qBAAqB,EAAiB,WAAW,
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../ts/utils/payment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAe,qBAAqB,EAAiB,WAAW,EAA6C,MAAM,UAAU,CAAC;AAK/I,UAAU,gBAAiB,SAAQ,QAAQ;IACzC,IAAI,EAAE,aAAa,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,CAAC;IAC7D,YAAY,EAAE,QAAQ,EAAE,CAAA;CACzB;AAED;;;;;;;;;GASG;AACH,QAAA,MAAM,0BAA0B,aAAc,QAAQ,EAAE,UAAS,CAAC,aAAa,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,CAAC,EAAE,KAA2D,gBAAgB,EAoCrM,CAAC;AAkBF;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,qBAAqB,WAAY,qBAAqB,KAAE,WAAW,EAsNxE,CAAC;AAEF,OAAO,EACL,0BAA0B,EAAE,qBAAqB,GAClD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
import { PaymentMethod, getTaxesIncludedAmount } from '../types';
|
|
2
|
+
import { PaymentMethod, getTaxesIncludedAmount, LegalFormTypeEnum } from '../types';
|
|
3
3
|
import * as dayjs from 'dayjs';
|
|
4
4
|
import { getPriceGrid } from './prestation';
|
|
5
5
|
/**
|
|
@@ -65,6 +65,8 @@ const calculateFees = (amount, goToClient, paymentDate) => {
|
|
|
65
65
|
// * @param {number} firstPaymentAmount - amount of the first payment (first regulation of the customer)
|
|
66
66
|
* @param {Date} firstExerciceNonExpresssEndDate - end date of the first exercice non express
|
|
67
67
|
* @param {number} idPrestation - prestation id
|
|
68
|
+
* @param {number} idLegalForm - legal form id of the society
|
|
69
|
+
* @param {boolean} isWithApplicationFees - if the prestation has application fees to paid
|
|
68
70
|
* @param {IPrestationList} prestationList - type of prestation (hidden: 0, isCatalog: 1, isComptable: 1)
|
|
69
71
|
* @param {number} idVat - vat id of society linked
|
|
70
72
|
* @param {number} yearlyAmountNonExpress - yearly amount of non express prestation (HT)
|
|
@@ -74,11 +76,10 @@ const calculateFees = (amount, goToClient, paymentDate) => {
|
|
|
74
76
|
* @returns { IPayment[] } list of payment to create for billing auto, after each presta go to onBoarding
|
|
75
77
|
*/
|
|
76
78
|
const calculatePaymentsAuto = (params) => {
|
|
77
|
-
const { idTypeBrand, goToClient, firstExerciceNonExpresssEndDate, idPrestation, prestationList, idVat, yearlyAmountNonExpress, nextYearlyAmountNonExpress, listPartialExercicePrestationExpress, listRegulations } = params;
|
|
79
|
+
const { idTypeBrand, goToClient, isWithApplicationFees, firstExerciceNonExpresssEndDate, idPrestation, idLegalForm, prestationList, idVat, yearlyAmountNonExpress, nextYearlyAmountNonExpress, listPartialExercicePrestationExpress, listRegulations } = params;
|
|
78
80
|
const initializedPaymentDate = dayjs().endOf('month').diff(dayjs(), 'day') < 3 /* || dayjs().date() >= 15 */
|
|
79
81
|
? dayjs().add(2, 'month').startOf('month').toDate()
|
|
80
82
|
: dayjs().add(1, 'month').startOf('month').toDate();
|
|
81
|
-
let isApplicationAlreadyPaid = false;
|
|
82
83
|
// On récupère la grille tarifaire pour savoir si les tarifs sont HT ou TTC
|
|
83
84
|
// et pour connaitre le montant du coût de l'app
|
|
84
85
|
if (!prestationList.id)
|
|
@@ -88,6 +89,7 @@ const calculatePaymentsAuto = (params) => {
|
|
|
88
89
|
throw new Error('Impossible de trouver la grille tarifaire correspondante');
|
|
89
90
|
const { applicationCost, priceWithTaxesIncluded } = priceGrid;
|
|
90
91
|
const applicationCostTotalTTC = (priceWithTaxesIncluded ? applicationCost : getTaxesIncludedAmount(applicationCost, idVat)) * 12;
|
|
92
|
+
const applicationFeesAmount = (idLegalForm === LegalFormTypeEnum.SCI) ? 150 : 50;
|
|
91
93
|
if (prestationList?.isCatalog || !prestationList?.isComptable)
|
|
92
94
|
throw new Error('Ce type de prestation ne correspond pas aux conditions attendues.');
|
|
93
95
|
// if (!listRegulations?.length) throw new Error('List of regulations can not be empty');
|
|
@@ -98,7 +100,23 @@ const calculatePaymentsAuto = (params) => {
|
|
|
98
100
|
const nbExoExpress = listPartialExercicePrestationExpress.length;
|
|
99
101
|
const listPayments = [];
|
|
100
102
|
// on récupère le/les premiers réglements effectués, non alloués
|
|
101
|
-
|
|
103
|
+
let isApplicationFeesAlreadyPaid = false;
|
|
104
|
+
const sumRegulations = listRegulations.reduce((acc, r) => {
|
|
105
|
+
//Si la regulation est rattachée à un paymentExpectation, on récupère le détail
|
|
106
|
+
// et on ne prend que les frais de dossier (applicationFee) + le montant de la compta (accountingFee)
|
|
107
|
+
if (r.paymentsExpectation?.payload) {
|
|
108
|
+
const payload = JSON.parse(r.paymentsExpectation?.payload);
|
|
109
|
+
if (+payload?.applicationFee > 0) {
|
|
110
|
+
isApplicationFeesAlreadyPaid = true;
|
|
111
|
+
}
|
|
112
|
+
if (+payload?.accountingFee > 0)
|
|
113
|
+
acc += +payload?.accountingFee;
|
|
114
|
+
return acc;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return acc + r.amount - r.amountUsed;
|
|
118
|
+
}
|
|
119
|
+
}, 0);
|
|
102
120
|
let remainingAmount = -sumRegulations; //TTC
|
|
103
121
|
let paymentDate = initializedPaymentDate;
|
|
104
122
|
//On order les exercicePrestation par startDate ASC et id ASC
|
|
@@ -118,6 +136,18 @@ const calculatePaymentsAuto = (params) => {
|
|
|
118
136
|
closingDate: listPartialExercicePrestationExpress?.length ? listPartialExercicePrestationExpress[0].endDate : firstExerciceNonExpresssEndDate,
|
|
119
137
|
});
|
|
120
138
|
}
|
|
139
|
+
// Si les frais de dossiers sont facturés et qu'ils n'ont pas déjà été payés,
|
|
140
|
+
// on ajoute un paiement sur la première mensualité non express
|
|
141
|
+
if (isWithApplicationFees && !isApplicationFeesAlreadyPaid) {
|
|
142
|
+
listPayments.push({
|
|
143
|
+
amount: getTaxesIncludedAmount(applicationFeesAmount, idVat),
|
|
144
|
+
isPaid: false,
|
|
145
|
+
datePayment: dayjs().startOf('month').add(1, 'month').toDate(),
|
|
146
|
+
idPrestation,
|
|
147
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
148
|
+
closingDate: listPartialExercicePrestationExpress?.length ? listPartialExercicePrestationExpress[0].endDate : firstExerciceNonExpresssEndDate,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
121
151
|
// =========================
|
|
122
152
|
// EXPRESS
|
|
123
153
|
// =========================
|
|
@@ -160,32 +190,52 @@ const calculatePaymentsAuto = (params) => {
|
|
|
160
190
|
if (nbExoExpress <= 1)
|
|
161
191
|
paymentDate = initializedPaymentDate;
|
|
162
192
|
let exerciceEndDate = dayjs(firstExerciceNonExpresssEndDate).toDate();
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
remainingAmountByExercicePrestation
|
|
186
|
-
|
|
193
|
+
let hasGeneratedWholeYear = false;
|
|
194
|
+
let isFirstNonExpress = true;
|
|
195
|
+
//On génère des paiements jusqu'à ce qu'un exercice soit entier (12 mois), non express
|
|
196
|
+
while (!hasGeneratedWholeYear) {
|
|
197
|
+
//On compte le nb de mois restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
|
|
198
|
+
let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));
|
|
199
|
+
if (countMonthsBeforeExerciceEnd < 3)
|
|
200
|
+
countMonthsBeforeExerciceEnd = 3;
|
|
201
|
+
const exoAmount = isFirstNonExpress ? yearlyAmountNonExpress : nextYearlyAmountNonExpress;
|
|
202
|
+
remainingAmount += priceWithTaxesIncluded ? exoAmount : getTaxesIncludedAmount(exoAmount, idVat);
|
|
203
|
+
//TODO: CAS A TESTER : si sumRegulations couvre le premier exercice par exemple (cas rar mais à envisager)
|
|
204
|
+
//Si le premier règlement couvre le coût de cet exercicePrestation, on passe au suivant
|
|
205
|
+
// if (remainingAmount <= 0) {
|
|
206
|
+
// continue;
|
|
207
|
+
// }
|
|
208
|
+
// Si on a ajouté une ligne pour les applications fees, alors on les déduit du montant total
|
|
209
|
+
if (isFirstNonExpress && isWithApplicationFees && !isApplicationFeesAlreadyPaid) {
|
|
210
|
+
remainingAmount -= getTaxesIncludedAmount(applicationFeesAmount, idVat);
|
|
211
|
+
}
|
|
212
|
+
let remainingAmountByExercicePrestation = remainingAmount;
|
|
213
|
+
// - frais d'application dès les second exo non express
|
|
214
|
+
if (!isFirstNonExpress)
|
|
215
|
+
remainingAmountByExercicePrestation += applicationCostTotalTTC;
|
|
216
|
+
const monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd; //TTC
|
|
217
|
+
if (monthlyAmount > 0) {
|
|
218
|
+
for (let index = 1; index <= countMonthsBeforeExerciceEnd; index++) {
|
|
219
|
+
let amount = index < countMonthsBeforeExerciceEnd ? monthlyAmount : remainingAmountByExercicePrestation;
|
|
220
|
+
// Si besoin, on applique les frais nécessaires :
|
|
221
|
+
// - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
|
|
222
|
+
amount = calculateFees(amount, goToClient, paymentDate);
|
|
223
|
+
listPayments.push({
|
|
224
|
+
amount: Math.round(100 * amount) / 100,
|
|
225
|
+
datePayment: paymentDate,
|
|
226
|
+
idPrestation,
|
|
227
|
+
idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,
|
|
228
|
+
closingDate: exerciceEndDate,
|
|
229
|
+
});
|
|
230
|
+
remainingAmountByExercicePrestation -= monthlyAmount;
|
|
231
|
+
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
232
|
+
}
|
|
233
|
+
exerciceEndDate = dayjs(exerciceEndDate).startOf('month').add(1, 'year').endOf('month').toDate();
|
|
187
234
|
}
|
|
188
|
-
|
|
235
|
+
remainingAmount = 0;
|
|
236
|
+
if (countMonthsBeforeExerciceEnd === 12)
|
|
237
|
+
hasGeneratedWholeYear = true;
|
|
238
|
+
isFirstNonExpress = false;
|
|
189
239
|
}
|
|
190
240
|
remainingAmount = 0;
|
|
191
241
|
// =========================
|
|
@@ -193,18 +243,18 @@ const calculatePaymentsAuto = (params) => {
|
|
|
193
243
|
// =========================
|
|
194
244
|
// On applique le taux de tva de la société, si besoin, selon la grille tarifaire
|
|
195
245
|
remainingAmount += priceWithTaxesIncluded ? nextYearlyAmountNonExpress : getTaxesIncludedAmount(nextYearlyAmountNonExpress, idVat);
|
|
196
|
-
remainingAmountByExercicePrestation = remainingAmount;
|
|
246
|
+
let remainingAmountByExercicePrestation = remainingAmount;
|
|
197
247
|
//On compte le nb de mois restants entre la date à laquelle le paiement va être créé et la date de fin d'exercice
|
|
198
|
-
countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));
|
|
248
|
+
let countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));
|
|
199
249
|
if (countMonthsBeforeExerciceEnd < 3)
|
|
200
250
|
countMonthsBeforeExerciceEnd = 3;
|
|
201
251
|
// - frais d'application dès les second exo non express
|
|
202
252
|
remainingAmountByExercicePrestation += applicationCostTotalTTC;
|
|
203
|
-
monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd;
|
|
253
|
+
const monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd;
|
|
204
254
|
// Si aucun paiement généré, on stoppe là
|
|
205
255
|
if (!listPayments.length)
|
|
206
256
|
return [];
|
|
207
|
-
while (dayjs(listPayments.slice(-1)[0].datePayment).month() < 11
|
|
257
|
+
while (dayjs(listPayments.slice(-1)[0].datePayment).month() < 11) {
|
|
208
258
|
let amount = monthlyAmount;
|
|
209
259
|
// Si besoin, on applique les frais nécessaires :
|
|
210
260
|
// - 2,75% d'augmentation chaque année, sauf si souscriptiuon dans les 3 derniers mois de l'année civile)
|
|
@@ -218,7 +268,6 @@ const calculatePaymentsAuto = (params) => {
|
|
|
218
268
|
closingDate: exerciceEndDate,
|
|
219
269
|
});
|
|
220
270
|
paymentDate = dayjs(paymentDate).add(1, 'month').startOf('month').toDate();
|
|
221
|
-
isApplicationAlreadyPaid = true;
|
|
222
271
|
}
|
|
223
272
|
return listPayments;
|
|
224
273
|
};
|
|
@@ -1 +1 @@
|
|
|
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;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAO5C;;;;;;;;;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,EAA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ExD,YAAY,CAAC,IAAI,CAAC;YAChB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,GAAG;YACtC,WAAW,EAAE,WAAW;YACxB,YAAY;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;QAC3E,wBAAwB,GAAG,IAAI,CAAC;KACjC;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';\nimport { getPriceGrid } from './prestation';\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):number => {\n const yearlyPriceIncreasing = 1.0275;\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 return amount;\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 {number} nextYearlyAmountNonExpress - yearly amount of non express prestation for next years (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 { idTypeBrand, goToClient, firstExerciceNonExpresssEndDate, idPrestation, prestationList, idVat, yearlyAmountNonExpress, nextYearlyAmountNonExpress, 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 let isApplicationAlreadyPaid = false;\n\n // On récupère la grille tarifaire pour savoir si les tarifs sont HT ou TTC \n // et pour connaitre le montant du coût de l'app\n if (!prestationList.id) throw new Error('idPrestationList manquant');\n const priceGrid = getPriceGrid(idTypeBrand, prestationList.id);\n if (!priceGrid) throw new Error('Impossible de trouver la grille tarifaire correspondante');\n const { applicationCost, priceWithTaxesIncluded } = priceGrid;\n const applicationCostTotalTTC = (priceWithTaxesIncluded ? applicationCost : getTaxesIncludedAmount(applicationCost, idVat)) * 12;\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 isPaid: true,\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, indexEP: number) => {\n remainingAmount += !priceWithTaxesIncluded \n ? getTaxesIncludedAmount(exercicePrestation.totalAmount, idVat) \n : exercicePrestation.totalAmount; //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 //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é)\n if (indexEP === 0 && sumRegulations > 0) countExpressMonthlyPayment -= 1;\n\n const monthlyAmount = remainingAmountByExercicePrestation / countExpressMonthlyPayment; //TTC\n for (let index = 1; index <= countExpressMonthlyPayment; index++) {\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 ? monthlyAmount : remainingAmountByExercicePrestation; //TTC\n \n listPayments.push({\n amount: Math.round(100 * amount) / 100,\n datePayment: paymentDate,\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: exercicePrestation.endDate,\n });\n remainingAmountByExercicePrestation -= monthlyAmount; \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 exerciceEndDate = dayjs(firstExerciceNonExpresssEndDate).toDate();\n \n //On génère un seul exercices plein, non express\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 const exoAmount = yearlyAmountNonExpress;\n remainingAmount += priceWithTaxesIncluded ? exoAmount : getTaxesIncludedAmount(exoAmount, idVat);\n\n let remainingAmountByExercicePrestation = remainingAmount;\n let monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd; //TTC\n\n if (monthlyAmount > 0) {\n for (let index = 1; index <= countMonthsBeforeExerciceEnd; index++) {\n let amount = index < countMonthsBeforeExerciceEnd ? monthlyAmount : remainingAmountByExercicePrestation;\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 amount = calculateFees(amount, goToClient, paymentDate);\n \n listPayments.push({\n amount: Math.round(100 * amount) / 100,\n datePayment: paymentDate,\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: exerciceEndDate,\n });\n remainingAmountByExercicePrestation -= monthlyAmount; \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\n remainingAmount = 0;\n\n // =========================\n // JUSQU'EN DECEMBRE\n // =========================\n // On applique le taux de tva de la société, si besoin, selon la grille tarifaire\n remainingAmount += priceWithTaxesIncluded ? nextYearlyAmountNonExpress : getTaxesIncludedAmount(nextYearlyAmountNonExpress, idVat);\n\n remainingAmountByExercicePrestation = remainingAmount;\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 countMonthsBeforeExerciceEnd = Math.ceil(dayjs(exerciceEndDate).diff(paymentDate, 'months', true));\n if (countMonthsBeforeExerciceEnd < 3) countMonthsBeforeExerciceEnd = 3;\n\n // - frais d'application dès les second exo non express\n remainingAmountByExercicePrestation += applicationCostTotalTTC;\n \n monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd;\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 || !isApplicationAlreadyPaid) {\n let amount = monthlyAmount;\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);\n\n listPayments.push({\n amount: Math.round(100 * amount) / 100,\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 isApplicationAlreadyPaid = true;\n }\n\n return listPayments;\n};\n\nexport {\n groupPaymentsByServiceType, calculatePaymentsAuto,\n};"]}
|
|
1
|
+
{"version":3,"file":"payment.js","source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AC,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QAExD,YAAY,CAAC,IAAI,CAAC;YAChB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,GAAG;YACtC,WAAW,EAAE,WAAW;YACxB,YAAY;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, LegalFormTypeEnum } from '../types';\nimport * as dayjs from 'dayjs';\nimport { PartialExercicePrestationExpress } from '../types/Interface/api/payment/Util';\nimport { getPriceGrid } from './prestation';\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):number => {\n const yearlyPriceIncreasing = 1.0275;\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 return amount;\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 {number} idLegalForm - legal form id of the society\n * @param {boolean} isWithApplicationFees - if the prestation has application fees to paid\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 {number} nextYearlyAmountNonExpress - yearly amount of non express prestation for next years (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 { idTypeBrand, goToClient, isWithApplicationFees, firstExerciceNonExpresssEndDate, idPrestation, idLegalForm, prestationList, idVat, yearlyAmountNonExpress, nextYearlyAmountNonExpress, 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 // On récupère la grille tarifaire pour savoir si les tarifs sont HT ou TTC \n // et pour connaitre le montant du coût de l'app\n if (!prestationList.id) throw new Error('idPrestationList manquant');\n const priceGrid = getPriceGrid(idTypeBrand, prestationList.id);\n if (!priceGrid) throw new Error('Impossible de trouver la grille tarifaire correspondante');\n const { applicationCost, priceWithTaxesIncluded } = priceGrid;\n const applicationCostTotalTTC = (priceWithTaxesIncluded ? applicationCost : getTaxesIncludedAmount(applicationCost, idVat)) * 12;\n const applicationFeesAmount = (idLegalForm === LegalFormTypeEnum.SCI) ? 150 : 50;\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 let isApplicationFeesAlreadyPaid = false;\n const sumRegulations = listRegulations.reduce((acc: number, r:IRegulation) => {\n //Si la regulation est rattachée à un paymentExpectation, on récupère le détail\n // et on ne prend que les frais de dossier (applicationFee) + le montant de la compta (accountingFee)\n if (r.paymentsExpectation?.payload) {\n const payload = JSON.parse(r.paymentsExpectation?.payload);\n if (+payload?.applicationFee > 0) {\n isApplicationFeesAlreadyPaid = true;\n }\n if (+payload?.accountingFee > 0) acc += +payload?.accountingFee;\n return acc;\n } else {\n return acc + r.amount - r.amountUsed;\n }\n }, 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 isPaid: true,\n datePayment: dayjs().toDate(),\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: listPartialExercicePrestationExpress?.length ? listPartialExercicePrestationExpress[0].endDate : firstExerciceNonExpresssEndDate,\n });\n }\n\n // Si les frais de dossiers sont facturés et qu'ils n'ont pas déjà été payés,\n // on ajoute un paiement sur la première mensualité non express\n if (isWithApplicationFees && !isApplicationFeesAlreadyPaid) {\n listPayments.push({\n amount: getTaxesIncludedAmount(applicationFeesAmount, idVat), //TTC\n isPaid: false,\n datePayment: dayjs().startOf('month').add(1, 'month').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, indexEP: number) => {\n remainingAmount += !priceWithTaxesIncluded \n ? getTaxesIncludedAmount(exercicePrestation.totalAmount, idVat) \n : exercicePrestation.totalAmount; //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 //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é)\n if (indexEP === 0 && sumRegulations > 0) countExpressMonthlyPayment -= 1;\n\n const monthlyAmount = remainingAmountByExercicePrestation / countExpressMonthlyPayment; //TTC\n for (let index = 1; index <= countExpressMonthlyPayment; index++) {\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 ? monthlyAmount : remainingAmountByExercicePrestation; //TTC\n \n listPayments.push({\n amount: Math.round(100 * amount) / 100,\n datePayment: paymentDate,\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: exercicePrestation.endDate,\n });\n remainingAmountByExercicePrestation -= monthlyAmount; \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 exerciceEndDate = dayjs(firstExerciceNonExpresssEndDate).toDate();\n\n let hasGeneratedWholeYear = false;\n let isFirstNonExpress = true;\n \n //On génère des paiements jusqu'à ce qu'un exercice soit entier (12 mois), non express\n while (!hasGeneratedWholeYear) {\n \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 const exoAmount = isFirstNonExpress ? yearlyAmountNonExpress : nextYearlyAmountNonExpress;\n remainingAmount += priceWithTaxesIncluded ? exoAmount : getTaxesIncludedAmount(exoAmount, idVat);\n\n //TODO: CAS A TESTER : si sumRegulations couvre le premier exercice par exemple (cas rar mais à envisager)\n //Si le premier règlement couvre le coût de cet exercicePrestation, on passe au suivant\n // if (remainingAmount <= 0) {\n // continue;\n // }\n\n // Si on a ajouté une ligne pour les applications fees, alors on les déduit du montant total\n if (isFirstNonExpress && isWithApplicationFees && !isApplicationFeesAlreadyPaid) {\n remainingAmount -= getTaxesIncludedAmount(applicationFeesAmount, idVat);\n }\n\n let remainingAmountByExercicePrestation = remainingAmount;\n\n // - frais d'application dès les second exo non express\n if (!isFirstNonExpress) remainingAmountByExercicePrestation += applicationCostTotalTTC;\n\n const monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd; //TTC\n\n if (monthlyAmount > 0) {\n for (let index = 1; index <= countMonthsBeforeExerciceEnd; index++) {\n let amount = index < countMonthsBeforeExerciceEnd ? monthlyAmount : remainingAmountByExercicePrestation;\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 amount = calculateFees(amount, goToClient, paymentDate);\n \n listPayments.push({\n amount: Math.round(100 * amount) / 100,\n datePayment: paymentDate,\n idPrestation,\n idPaymentMethod: PaymentMethod.DIRECT_DEBIT.id,\n closingDate: exerciceEndDate,\n });\n remainingAmountByExercicePrestation -= monthlyAmount; \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 remainingAmount = 0;\n if (countMonthsBeforeExerciceEnd === 12) hasGeneratedWholeYear = true;\n isFirstNonExpress = false;\n }\n\n remainingAmount = 0;\n\n // =========================\n // JUSQU'EN DECEMBRE\n // =========================\n // On applique le taux de tva de la société, si besoin, selon la grille tarifaire\n remainingAmount += priceWithTaxesIncluded ? nextYearlyAmountNonExpress : getTaxesIncludedAmount(nextYearlyAmountNonExpress, idVat);\n\n let remainingAmountByExercicePrestation = remainingAmount;\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 // - frais d'application dès les second exo non express\n remainingAmountByExercicePrestation += applicationCostTotalTTC;\n \n const monthlyAmount = remainingAmountByExercicePrestation / countMonthsBeforeExerciceEnd;\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 = monthlyAmount;\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);\n\n listPayments.push({\n amount: Math.round(100 * amount) / 100,\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};"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as dayjs from 'dayjs';
|
|
2
|
-
import { Vat, PaymentMethod } from '../../types';
|
|
2
|
+
import { Vat, PaymentMethod, LegalFormTypeEnum } from '../../types';
|
|
3
3
|
import MockDate from 'mockdate';
|
|
4
4
|
import { calculatePaymentsAuto } from '../payment';
|
|
5
5
|
describe('Payment', () => {
|
|
@@ -78,6 +78,8 @@ describe('Payment', () => {
|
|
|
78
78
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
79
79
|
firstExerciceNonExpresssEndDate,
|
|
80
80
|
idPrestation,
|
|
81
|
+
isWithApplicationFees: true,
|
|
82
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
81
83
|
prestationList: {
|
|
82
84
|
...prestationList,
|
|
83
85
|
isCatalog: true,
|
|
@@ -103,6 +105,8 @@ describe('Payment', () => {
|
|
|
103
105
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
104
106
|
firstExerciceNonExpresssEndDate,
|
|
105
107
|
idPrestation,
|
|
108
|
+
isWithApplicationFees: true,
|
|
109
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
106
110
|
prestationList,
|
|
107
111
|
idVat,
|
|
108
112
|
listPartialExercicePrestationExpress,
|
|
@@ -125,6 +129,8 @@ describe('Payment', () => {
|
|
|
125
129
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
126
130
|
firstExerciceNonExpresssEndDate,
|
|
127
131
|
idPrestation,
|
|
132
|
+
isWithApplicationFees: true,
|
|
133
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
128
134
|
prestationList,
|
|
129
135
|
idVat,
|
|
130
136
|
listPartialExercicePrestationExpress,
|
|
@@ -149,6 +155,8 @@ describe('Payment', () => {
|
|
|
149
155
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
150
156
|
firstExerciceNonExpresssEndDate,
|
|
151
157
|
idPrestation,
|
|
158
|
+
isWithApplicationFees: true,
|
|
159
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
152
160
|
prestationList,
|
|
153
161
|
idVat,
|
|
154
162
|
listPartialExercicePrestationExpress: [listPartialExercicePrestationExpress[0]],
|
|
@@ -166,6 +174,8 @@ describe('Payment', () => {
|
|
|
166
174
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
167
175
|
firstExerciceNonExpresssEndDate,
|
|
168
176
|
idPrestation,
|
|
177
|
+
isWithApplicationFees: true,
|
|
178
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
169
179
|
prestationList,
|
|
170
180
|
idVat,
|
|
171
181
|
listPartialExercicePrestationExpress,
|
|
@@ -188,6 +198,8 @@ describe('Payment', () => {
|
|
|
188
198
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
189
199
|
firstExerciceNonExpresssEndDate: newFirstExerciceNonExpresssEndDate,
|
|
190
200
|
idPrestation,
|
|
201
|
+
isWithApplicationFees: true,
|
|
202
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
191
203
|
prestationList,
|
|
192
204
|
idVat,
|
|
193
205
|
listPartialExercicePrestationExpress: [],
|
|
@@ -211,6 +223,8 @@ describe('Payment', () => {
|
|
|
211
223
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
212
224
|
firstExerciceNonExpresssEndDate: newFirstExerciceNonExpresssEndDate,
|
|
213
225
|
idPrestation,
|
|
226
|
+
isWithApplicationFees: true,
|
|
227
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
214
228
|
prestationList,
|
|
215
229
|
idVat,
|
|
216
230
|
listPartialExercicePrestationExpress: [],
|
|
@@ -238,6 +252,8 @@ describe('Payment', () => {
|
|
|
238
252
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
239
253
|
firstExerciceNonExpresssEndDate: newFirstExerciceNonExpresssEndDate,
|
|
240
254
|
idPrestation,
|
|
255
|
+
isWithApplicationFees: true,
|
|
256
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
241
257
|
prestationList,
|
|
242
258
|
idVat,
|
|
243
259
|
listPartialExercicePrestationExpress: [],
|
|
@@ -262,6 +278,8 @@ describe('Payment', () => {
|
|
|
262
278
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
263
279
|
firstExerciceNonExpresssEndDate: newFirstExerciceNonExpresssEndDate,
|
|
264
280
|
idPrestation,
|
|
281
|
+
isWithApplicationFees: true,
|
|
282
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
265
283
|
prestationList,
|
|
266
284
|
idVat,
|
|
267
285
|
listPartialExercicePrestationExpress: [],
|
|
@@ -283,6 +301,8 @@ describe('Payment', () => {
|
|
|
283
301
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
284
302
|
firstExerciceNonExpresssEndDate: newFirstExerciceNonExpresssEndDate,
|
|
285
303
|
idPrestation,
|
|
304
|
+
isWithApplicationFees: true,
|
|
305
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
286
306
|
prestationList,
|
|
287
307
|
idVat,
|
|
288
308
|
listPartialExercicePrestationExpress: [],
|
|
@@ -306,6 +326,8 @@ describe('Payment', () => {
|
|
|
306
326
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
307
327
|
firstExerciceNonExpresssEndDate: newFirstExerciceNonExpresssEndDate,
|
|
308
328
|
idPrestation,
|
|
329
|
+
isWithApplicationFees: true,
|
|
330
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
309
331
|
prestationList,
|
|
310
332
|
idVat,
|
|
311
333
|
listPartialExercicePrestationExpress: [],
|
|
@@ -329,6 +351,8 @@ describe('Payment', () => {
|
|
|
329
351
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
330
352
|
firstExerciceNonExpresssEndDate: newFirstExerciceNonExpresssEndDate,
|
|
331
353
|
idPrestation,
|
|
354
|
+
isWithApplicationFees: true,
|
|
355
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
332
356
|
prestationList,
|
|
333
357
|
idVat,
|
|
334
358
|
listPartialExercicePrestationExpress: [],
|
|
@@ -360,6 +384,8 @@ describe('Payment', () => {
|
|
|
360
384
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
361
385
|
firstExerciceNonExpresssEndDate,
|
|
362
386
|
idPrestation,
|
|
387
|
+
isWithApplicationFees: true,
|
|
388
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
363
389
|
prestationList,
|
|
364
390
|
idVat,
|
|
365
391
|
listPartialExercicePrestationExpress: listPartialExercicePrestationExpressCloned,
|
|
@@ -378,6 +404,8 @@ describe('Payment', () => {
|
|
|
378
404
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
379
405
|
firstExerciceNonExpresssEndDate,
|
|
380
406
|
idPrestation,
|
|
407
|
+
isWithApplicationFees: true,
|
|
408
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
381
409
|
prestationList,
|
|
382
410
|
idVat,
|
|
383
411
|
listPartialExercicePrestationExpress,
|
|
@@ -415,6 +443,8 @@ describe('Payment', () => {
|
|
|
415
443
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
416
444
|
firstExerciceNonExpresssEndDate,
|
|
417
445
|
idPrestation,
|
|
446
|
+
isWithApplicationFees: true,
|
|
447
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
418
448
|
prestationList,
|
|
419
449
|
idVat,
|
|
420
450
|
listPartialExercicePrestationExpress,
|
|
@@ -434,6 +464,8 @@ describe('Payment', () => {
|
|
|
434
464
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
435
465
|
firstExerciceNonExpresssEndDate,
|
|
436
466
|
idPrestation,
|
|
467
|
+
isWithApplicationFees: true,
|
|
468
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
437
469
|
prestationList,
|
|
438
470
|
idVat,
|
|
439
471
|
listPartialExercicePrestationExpress,
|
|
@@ -450,6 +482,8 @@ describe('Payment', () => {
|
|
|
450
482
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
451
483
|
firstExerciceNonExpresssEndDate,
|
|
452
484
|
idPrestation,
|
|
485
|
+
isWithApplicationFees: true,
|
|
486
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
453
487
|
prestationList,
|
|
454
488
|
idVat,
|
|
455
489
|
listPartialExercicePrestationExpress: [],
|
|
@@ -465,6 +499,8 @@ describe('Payment', () => {
|
|
|
465
499
|
goToClient: dayjs('2024-06-06').toDate(),
|
|
466
500
|
firstExerciceNonExpresssEndDate: dayjs('2024-12-31').toDate(),
|
|
467
501
|
idPrestation,
|
|
502
|
+
isWithApplicationFees: true,
|
|
503
|
+
idLegalForm: LegalFormTypeEnum.SARL,
|
|
468
504
|
prestationList,
|
|
469
505
|
idVat: Vat.TX_20.id,
|
|
470
506
|
listPartialExercicePrestationExpress: [],
|