diff --git a/src/core/helpers/courses.js b/src/core/helpers/courses.js
index a7c52a3d1..c3837bc0f 100644
--- a/src/core/helpers/courses.js
+++ b/src/core/helpers/courses.js
@@ -10,8 +10,10 @@ import {
SELF_POSITIONNING,
TRAINER_ROLE_OPTIONS,
} from '@data/constants';
+import get from 'lodash/get';
import CompaniDate from '@helpers/dates/companiDates';
import CompaniDuration from '@helpers/dates/companiDurations';
+import { add, isGreaterThan } from '@helpers/numbers';
import { formatIntervalHourly, getISODuration, getSlotDurationMultiplier } from './dates/utils';
export const happened = sameDaySlots => CompaniDate().isSameOrAfter(sameDaySlots[sameDaySlots.length - 1].endDate);
@@ -73,3 +75,12 @@ export const getQuestionnaireTypeTitle = (types) => {
};
export const isInterrupted = (interruptionDates = []) => interruptionDates.some(d => !d.endDate);
+
+export const isCoursePriceExceeded = (prices, validatedBillsAmount, billsToValidateAmount) => {
+ const globalPrice = get(prices, '[0].global');
+ if (!globalPrice) return false;
+
+ const coursePrice = add(globalPrice, get(prices, '[0].trainerFees', 0));
+
+ return isGreaterThan(add(validatedBillsAmount, billsToValidateAmount), coursePrice);
+};
diff --git a/src/modules/vendor/components/billing/CourseBillValidationModal.vue b/src/modules/vendor/components/billing/CourseBillValidationModal.vue
index 215737e58..701a71220 100644
--- a/src/modules/vendor/components/billing/CourseBillValidationModal.vue
+++ b/src/modules/vendor/components/billing/CourseBillValidationModal.vue
@@ -14,6 +14,12 @@
icon-color="secondary" class="bg-orange-100 text-orange-500">
Aucun stagiaire des structures sélectionnées n'est inscrit à la formation
+
+
+ Le montant des factures validées au réel de cette formation dépasserait le prix de la formation
+
+
diff --git a/src/modules/vendor/components/billing/CourseBillingCard.vue b/src/modules/vendor/components/billing/CourseBillingCard.vue
index 2e93948bc..c5098db05 100644
--- a/src/modules/vendor/components/billing/CourseBillingCard.vue
+++ b/src/modules/vendor/components/billing/CourseBillingCard.vue
@@ -206,11 +206,12 @@ import CourseCreditNotes from '@api/CourseCreditNotes';
import { NotifyNegative, NotifyPositive, NotifyWarning } from '@components/popup/notify';
import Button from '@components/Button';
import { useCourseBilling } from '@composables/courseBills';
-import { COMPANY, INTRA, SINGLE, DD_MM_YYYY, GROUP, COUNT_UNIT, LIST } from '@data/constants';
+import { COMPANY, INTRA, SINGLE, DD_MM_YYYY, GROUP, COUNT_UNIT, LIST, SHORT_DURATION_H_MM } from '@data/constants';
+import CompaniDuration from '@helpers/dates/companiDurations';
import { strictPositiveNumber, integerNumber, minDate } from '@helpers/vuelidateCustomVal';
import { add, toFixedToFloat } from '@helpers/numbers';
import { formatPrice, formatName, formatIdentity } from '@helpers/utils';
-import { composeCourseName, isInterrupted } from '@helpers/courses';
+import { composeCourseName, isInterrupted, isCoursePriceExceeded } from '@helpers/courses';
import CompaniDate from '@helpers/dates/companiDates';
import CourseBillEditionModal from 'src/modules/vendor/components/billing/CourseBillEditionModal';
import CourseFeeEditionModal from 'src/modules/vendor/components/billing/CourseFeeEditionModal';
@@ -264,7 +265,11 @@ export default {
if (!plan) return '';
const stepPrices = plan.prices.map(p => `${get(p, 'step.name', '')} : ${formatPrice(p.hourlyAmount)}/h`);
- const eLearningPrice = plan.elearningPrice ? [`E-learning : ${formatPrice(plan.elearningPrice)}/h`] : [];
+ const limit = plan.elearningLimit && CompaniDuration(plan.elearningLimit).format(SHORT_DURATION_H_MM);
+ const eLearningLimit = limit ? ` (limite : ${limit})` : '';
+ const eLearningPrice = plan.elearningPrice
+ ? [`E-learning : ${formatPrice(plan.elearningPrice)}/h${eLearningLimit}`]
+ : [];
return [...stepPrices, ...eLearningPrice].join(' - ');
};
@@ -393,12 +398,25 @@ export default {
return `${value} %`;
});
- const courseInfos = computed(() => ([{
- courseType: course.value.type,
- companiesName,
- courseName,
- traineesQuantity: Number(traineesQuantity.value),
- }]));
+ const courseInfos = computed(() => {
+ const billToValidateWithPlan = courseBills.value
+ .find(bill => bill._id === billToValidate.value._id && bill.hourlyPaymentPlan);
+ const validatedHourlyBillsAmount = courseBills.value
+ .filter(bill => bill.billedAt && bill.hourlyPaymentPlan && !bill.courseCreditNote)
+ .reduce((acc, bill) => add(acc, bill.netExclTaxes), 0);
+
+ return [{
+ courseType: course.value.type,
+ companiesName,
+ courseName,
+ traineesQuantity: Number(traineesQuantity.value),
+ isCoursePriceExceeded: !!billToValidateWithPlan && isCoursePriceExceeded(
+ course.value.prices,
+ validatedHourlyBillsAmount,
+ billToValidateWithPlan.netExclTaxes
+ ),
+ }];
+ });
const isCourseInterrupted = computed(() => isInterrupted(course.value.interruptionDates));
diff --git a/src/modules/vendor/components/billing/MultipleCourseBillCreationModal.vue b/src/modules/vendor/components/billing/MultipleCourseBillCreationModal.vue
index 23124ae44..30d88ea9e 100644
--- a/src/modules/vendor/components/billing/MultipleCourseBillCreationModal.vue
+++ b/src/modules/vendor/components/billing/MultipleCourseBillCreationModal.vue
@@ -39,7 +39,8 @@
{{ price.step.name }} : {{ formatPrice(price.hourlyAmount) }} / h
- E-learning : {{ formatPrice(opt.elearningPrice) }}
+ E-learning : {{ formatPrice(opt.elearningPrice) }} / h
+ (limite : {{ formatLimit(opt.elearningLimit) }})
@@ -65,7 +66,8 @@ import Button from '@components/Button';
import ButtonToggle from '@components/ButtonToggle';
import OptionGroup from '@components/form/OptionGroup';
import { formatPrice } from '@helpers/utils';
-import { MANUAL, PAYMENT_PLAN, HOURLY_PAYMENT_PLAN } from '@data/constants';
+import CompaniDuration from '@helpers/dates/companiDurations';
+import { MANUAL, PAYMENT_PLAN, HOURLY_PAYMENT_PLAN, SHORT_DURATION_H_MM } from '@data/constants';
export default {
name: 'MultipleCourseBillCreationModal',
@@ -124,8 +126,11 @@ export default {
value: plan._id,
prices: plan.prices,
elearningPrice: plan.elearningPrice,
+ elearningLimit: plan.elearningLimit,
})));
+ const formatLimit = limit => CompaniDuration(limit).format(SHORT_DURATION_H_MM);
+
const quantityErrorMessage = computed(() => {
if (validations.value.newBillsQuantity.strictPositiveNumber.$response === false ||
validations.value.newBillsQuantity.integerNumber.$response === false) {
@@ -176,6 +181,7 @@ export default {
selectPlan,
selectHourlyPlan,
formatPrice,
+ formatLimit,
};
},
};
diff --git a/src/modules/vendor/components/programs/HourlyPaymentPlanListModal.vue b/src/modules/vendor/components/programs/HourlyPaymentPlanListModal.vue
index 8d0c3b41c..9c83c4bb3 100644
--- a/src/modules/vendor/components/programs/HourlyPaymentPlanListModal.vue
+++ b/src/modules/vendor/components/programs/HourlyPaymentPlanListModal.vue
@@ -20,7 +20,10 @@
{{ getStepName(price.step) }} : {{ price.hourlyAmount }} € / h
- E-learning : {{ plan.elearningPrice }} €
+
+ E-learning : {{ plan.elearningPrice }} € / h
+ (limite : {{ formatLimit(plan.elearningLimit) }})
+
@@ -32,6 +35,8 @@ import { useQuasar } from 'quasar';
import { NotifyPositive } from '@components/popup/notify';
import Modal from '@components/modal/Modal';
import Button from '@components/Button';
+import CompaniDuration from '@helpers/dates/companiDurations';
+import { SHORT_DURATION_H_MM } from '@data/constants';
export default {
name: 'HourlyPaymentPlanListModal',
@@ -55,6 +60,8 @@ export default {
const getStepName = stepId => (subProgram.value.steps || []).find(s => s._id === stepId)?.name || '';
+ const formatLimit = limit => CompaniDuration(limit).format(SHORT_DURATION_H_MM);
+
const validateDeletion = (hourlyPaymentPlanId) => {
$q.dialog({
title: 'Confirmation',
@@ -73,6 +80,7 @@ export default {
hide,
input,
getStepName,
+ formatLimit,
validateDeletion,
};
},
diff --git a/src/modules/vendor/components/programs/HourlyPaymentPlanModal.vue b/src/modules/vendor/components/programs/HourlyPaymentPlanModal.vue
index 0131c51e8..3b303a038 100644
--- a/src/modules/vendor/components/programs/HourlyPaymentPlanModal.vue
+++ b/src/modules/vendor/components/programs/HourlyPaymentPlanModal.vue
@@ -19,6 +19,19 @@
+
+
Limite d'heures e-learning facturables (optionnelle)
+
+
+
+
+
+
+
+
+
+
diff --git a/src/modules/vendor/composables/HourlyPaymentPlan.js b/src/modules/vendor/composables/HourlyPaymentPlan.js
index b832aa910..fca2c1ffd 100644
--- a/src/modules/vendor/composables/HourlyPaymentPlan.js
+++ b/src/modules/vendor/composables/HourlyPaymentPlan.js
@@ -3,7 +3,8 @@ import useVuelidate from '@vuelidate/core';
import { required, helpers } from '@vuelidate/validators';
import { strictPositiveNumber } from '@helpers/vuelidateCustomVal';
import SubPrograms from '@api/SubPrograms';
-import { E_LEARNING } from '@data/constants';
+import { E_LEARNING, PT0S } from '@data/constants';
+import CompaniDuration from '@helpers/dates/companiDurations';
import { NotifyNegative, NotifyWarning, NotifyPositive } from '@components/popup/notify';
export const useHourlyPaymentPlan = (modalLoading, refreshProgram, program) => {
@@ -12,16 +13,19 @@ export const useHourlyPaymentPlan = (modalLoading, refreshProgram, program) => {
const hourlyPaymentPlanListModal = ref(false);
const selectedSubProgramForHourlyPlan = ref({});
- const emptyPlan = () => ({ subProgram: {}, prices: [], elearningPrice: '' });
+ const emptyPlan = () => ({ subProgram: {}, prices: [], elearningPrice: '', elearningLimit: PT0S });
const newHourlyPaymentPlan = ref(emptyPlan());
const editedHourlyPaymentPlan = ref({ planId: '', ...emptyPlan() });
+ const positiveIntDuration = value => !value || /^(PT\d+H\d+M|PT\d+S)$/.test(value);
+
const planRules = {
prices: { $each: helpers.forEach({ step: { required }, hourlyAmount: { required, strictPositiveNumber } }) },
elearningPrice: {
required: (value, plan) => !plan.hasELearning || required.$validator(value),
strictPositiveNumber: (value, plan) => !plan.hasELearning || strictPositiveNumber(value),
},
+ elearningLimit: { positiveIntDuration: (value, plan) => !plan.hasELearning || positiveIntDuration(value) },
};
const rules = computed(() => ({
newHourlyPaymentPlan: planRules,
@@ -42,6 +46,8 @@ export const useHourlyPaymentPlan = (modalLoading, refreshProgram, program) => {
...plan.planId && { hourlyPaymentPlanId: plan.planId },
prices,
...plan.hasELearning && { elearningPrice: Number(plan.elearningPrice) },
+ ...plan.hasELearning && !CompaniDuration(plan.elearningLimit).isEquivalentTo(PT0S) &&
+ { elearningLimit: plan.elearningLimit },
};
};
@@ -54,7 +60,7 @@ export const useHourlyPaymentPlan = (modalLoading, refreshProgram, program) => {
subProgram: { _id: subProgram._id, steps, hourlyPaymentPlansCount: subProgram.hourlyPaymentPlans?.length },
prices: steps.map(s => ({ step: s._id, hourlyAmount: 0 })),
hasELearning,
- ...hasELearning && { elearningPrice: 0 },
+ ...hasELearning && { elearningPrice: 0, elearningLimit: PT0S },
};
hourlyPaymentPlanAdditionModal.value = true;
};
@@ -79,6 +85,7 @@ export const useHourlyPaymentPlan = (modalLoading, refreshProgram, program) => {
prices: plan.prices.map(p => ({ step: p.step, hourlyAmount: p.hourlyAmount })),
hasELearning: subProgram.steps.some(s => s.type === E_LEARNING),
elearningPrice: plan.elearningPrice,
+ elearningLimit: plan.elearningLimit || PT0S,
};
hourlyPaymentPlanListModal.value = false;
hourlyPaymentPlanEditionModal.value = true;
diff --git a/src/modules/vendor/pages/ni/billing/CourseBillsDashboard.vue b/src/modules/vendor/pages/ni/billing/CourseBillsDashboard.vue
index ae8fdd1c7..4410b9a75 100644
--- a/src/modules/vendor/pages/ni/billing/CourseBillsDashboard.vue
+++ b/src/modules/vendor/pages/ni/billing/CourseBillsDashboard.vue
@@ -104,7 +104,8 @@ import CompanySelect from '@components/form/CompanySelect';
import { NotifyNegative, NotifyPositive, NotifyWarning } from '@components/popup/notify';
import { useCourseBilling } from '@composables/courseBills';
import { DASHBOARD, COURSE_TYPES, MONTH, INTERRUPTED_COURSES, NO_HOLDING } from '@data/constants';
-import { composeCourseName, isInterrupted } from '@helpers/courses';
+import { composeCourseName, isInterrupted, isCoursePriceExceeded } from '@helpers/courses';
+import { add } from '@helpers/numbers';
import CompaniDate from '@helpers/dates/companiDates';
import { minDate, maxDate, minArrayLength } from '@helpers/vuelidateCustomVal';
import { formatAndSortOptions, formatAndSortCompanyOptions, formatQuantity, formatName } from '@helpers/utils';
@@ -290,14 +291,25 @@ export default {
...courseBillsFromInterruptedCourses.value,
].filter(bill => billsToValidate.value._ids.includes(bill._id));
- return bills.map(bill => ({
- courseType: bill.course.type,
- companiesName: formatName(bill.companies),
- courseName: composeCourseName(bill.course),
- traineesQuantity: bill.course.trainees
- .filter(trainee => bill.companies.map(c => c._id).includes(trainee.registrationCompany))
- .length,
- }));
+ return bills.map((bill) => {
+ const hourlyBillsToValidateAmount = bills
+ .filter(b => b.hourlyPaymentPlan && b.course._id === bill.course._id)
+ .reduce((acc, b) => add(acc, b.netExclTaxes), 0);
+
+ return {
+ courseType: bill.course.type,
+ companiesName: formatName(bill.companies),
+ courseName: composeCourseName(bill.course),
+ traineesQuantity: bill.course.trainees
+ .filter(trainee => bill.companies.map(c => c._id).includes(trainee.registrationCompany))
+ .length,
+ isCoursePriceExceeded: !!bill.hourlyPaymentPlan && isCoursePriceExceeded(
+ bill.course.prices,
+ bill.validatedHourlyBillsAmount || 0,
+ hourlyBillsToValidateAmount
+ ),
+ };
+ });
});
const refreshValidatedCourseBills = async () => {