Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/core/helpers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
icon-color="secondary" class="bg-orange-100 text-orange-500">
<template #message>Aucun stagiaire des structures sélectionnées n'est inscrit à la formation</template>
</ni-banner>
<ni-banner v-if="info.isCoursePriceExceeded" icon="info_outline" icon-color="secondary"
class="bg-orange-100 text-orange-500">
<template #message>
Le montant des factures validées au réel de cette formation dépasserait le prix de la formation
</template>
</ni-banner>
</div>
<ni-date-input caption="Date de facture" :model-value="billToValidate.billedAt" :error="validations.billedAt.$error"
@blur="validations.billedAt.$touch" in-modal required-field @update:model-value="update($event, 'billedAt')" />
Expand Down
36 changes: 27 additions & 9 deletions src/modules/vendor/components/billing/CourseBillingCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(' - ');
};
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
{{ price.step.name }} : {{ formatPrice(price.hourlyAmount) }} / h
</div>
<div v-if="opt.elearningPrice" class="text-caption q-py-xs">
E-learning : {{ formatPrice(opt.elearningPrice) }}
E-learning : {{ formatPrice(opt.elearningPrice) }} / h
<span v-if="opt.elearningLimit">(limite : {{ formatLimit(opt.elearningLimit) }})</span>
</div>
</q-card>
</q-expansion-item>
Expand All @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -176,6 +181,7 @@ export default {
selectPlan,
selectHourlyPlan,
formatPrice,
formatLimit,
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
<div v-for="price in plan.prices" :key="price.step" class="q-py-xs">
{{ getStepName(price.step) }} : {{ price.hourlyAmount }} € / h
</div>
<div v-if="plan.elearningPrice" class="q-py-xs">E-learning : {{ plan.elearningPrice }} €</div>
<div v-if="plan.elearningPrice" class="q-py-xs">
E-learning : {{ plan.elearningPrice }} € / h
<span v-if="plan.elearningLimit">(limite : {{ formatLimit(plan.elearningLimit) }})</span>
</div>
</div>
</q-expansion-item>
</ni-modal>
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -73,6 +80,7 @@ export default {
hide,
input,
getStepName,
formatLimit,
validateDeletion,
};
},
Expand Down
74 changes: 72 additions & 2 deletions src/modules/vendor/components/programs/HourlyPaymentPlanModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
<ni-input in-modal type="number" :model-value="plan.elearningPrice" suffix="€ / h" required-field
caption="Tarif e-learning" :error-message="getElearningPriceError()" :error="!!getElearningPriceError()"
@update:model-value="updateElearningPrice" />
<div class="row justify-between">
<p class="q-mb-none input-caption">Limite d'heures e-learning facturables (optionnelle)</p>
<q-icon v-if="getElearningLimitError()" name="error_outline" color="secondary" />
</div>
<q-field class="duration-field" dense :error="!!getElearningLimitError()"
:error-message="getElearningLimitError()" borderless>
<div class="duration-container row items-end">
<ni-input in-modal :model-value="limitHours" suffix="h" class="flex-1 q-pr-sm"
@update:model-value="updateTmp($event, 'hours')" @blur="updateElearningLimit()" />
<ni-input in-modal :model-value="limitMinutes" suffix="min" class="flex-1 q-pl-sm"
@update:model-value="updateTmp($event, 'minutes')" @blur="updateElearningLimit()" />
</div>
</q-field>
</div>
<template #footer>
<q-btn no-caps class="full-width modal-btn" color="primary" icon-right="add" :loading="loading"
Expand All @@ -28,8 +41,9 @@
</template>

<script>
import { toRefs, ref, computed } from 'vue';
import { REQUIRED_LABEL } from '@data/constants';
import { toRefs, ref, computed, watch } from 'vue';
import { REQUIRED_LABEL, PT0S } from '@data/constants';
import CompaniDuration from '@helpers/dates/companiDurations';
import Modal from '@components/modal/Modal';
import Input from '@components/form/Input';
import Banner from '@components/Banner';
Expand Down Expand Up @@ -76,6 +90,37 @@ export default {

const updateElearningPrice = (value) => { emit('update:plan', { ...plan.value, elearningPrice: value }); };

const limitHours = ref(0);
const limitMinutes = ref(0);
const currentEditedField = ref({});

watch(
() => plan.value.elearningLimit,
() => {
const durationObject = CompaniDuration(plan.value.elearningLimit || PT0S).toHoursAndMinutesObject();
limitHours.value = durationObject.hours;
limitMinutes.value = durationObject.minutes;
},
{ immediate: true }
);

const updateTmp = (event, path) => { currentEditedField.value = { path, event: event || '0' }; };

const updateElearningLimit = () => {
const { path, event } = currentEditedField.value;

if (event) {
const parsedEvent = parseFloat(event);
const value = path === 'hours'
? `PT${parsedEvent || 0}H${limitMinutes.value}M`
: `PT${limitHours.value}H${parsedEvent || 0}M`;

const { hours, minutes } = CompaniDuration(value).toHoursAndMinutesObject();
emit('update:plan', { ...plan.value, elearningLimit: `PT${hours}H${minutes}M` });
currentEditedField.value = {};
}
};

const getAmountError = (index) => {
if (!showErrors.value) return '';
const validation = validations.value.prices.$each.$response.$data[index].hourlyAmount;
Expand All @@ -85,13 +130,22 @@ export default {
return '';
};

const getElearningLimitError = () => {
if (!showErrors.value || !validations.value.elearningLimit.$error) return '';

return 'Durée non valide';
};

const getElearningPriceError = () => {
if (!showErrors.value || !validations.value.elearningPrice.$error) return '';
if (validations.value.elearningPrice.required.$invalid) return REQUIRED_LABEL;
return 'Nombre non valide, doit être strictement positif';
};

return {
// Data
limitHours,
limitMinutes,
// Computed
hourlyPaymentPlansCount,
// Methods
Expand All @@ -102,9 +156,25 @@ export default {
getStepName,
updateHourlyAmount,
updateElearningPrice,
updateTmp,
updateElearningLimit,
getAmountError,
getElearningPriceError,
getElearningLimitError,
};
},
};
</script>

<style lang="sass" scoped>
.duration-field
:deep(.q-field__control)
border: none !important

.duration-container
:deep(.q-field__control)
border: 1px solid $copper-grey-300 !important
border-radius: 3px !important
:deep(.q-field__bottom)
display: none
</style>
13 changes: 10 additions & 3 deletions src/modules/vendor/composables/HourlyPaymentPlan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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,
Expand All @@ -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 },
};
};

Expand All @@ -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;
};
Expand All @@ -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;
Expand Down
30 changes: 21 additions & 9 deletions src/modules/vendor/pages/ni/billing/CourseBillsDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading