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"> + + + 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)

+ +
+ +
+ + +
+