mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
fix: Generation d'une fiche d'élève avec le nouveau modèle PayementMode
et PayementPlans
This commit is contained in:
@ -8,28 +8,28 @@ register = template.Library()
|
|||||||
def getRegistrationPaymentPlan(pk):
|
def getRegistrationPaymentPlan(pk):
|
||||||
registerForm = RegistrationForm.objects.get(student=pk)
|
registerForm = RegistrationForm.objects.get(student=pk)
|
||||||
if registerForm.registration_payment_plan:
|
if registerForm.registration_payment_plan:
|
||||||
return registerForm.registration_payment_plan.label
|
return registerForm.registration_payment_plan.plan_type.label
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def getTuitionPaymentPlan(pk):
|
def getTuitionPaymentPlan(pk):
|
||||||
registerForm = RegistrationForm.objects.get(student=pk)
|
registerForm = RegistrationForm.objects.get(student=pk)
|
||||||
if registerForm.tuition_payment_plan:
|
if registerForm.tuition_payment_plan:
|
||||||
return registerForm.tuition_payment_plan.label
|
return registerForm.tuition_payment_plan.plan_type.label
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def getRegistrationPaymentMethod(pk):
|
def getRegistrationPaymentMethod(pk):
|
||||||
registerForm = RegistrationForm.objects.get(student=pk)
|
registerForm = RegistrationForm.objects.get(student=pk)
|
||||||
if registerForm.registration_payment:
|
if registerForm.registration_payment:
|
||||||
return registerForm.registration_payment.label
|
return registerForm.registration_payment.mode.label
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def getTuitionPaymentMethod(pk):
|
def getTuitionPaymentMethod(pk):
|
||||||
registerForm = RegistrationForm.objects.get(student=pk)
|
registerForm = RegistrationForm.objects.get(student=pk)
|
||||||
if registerForm.tuition_payment:
|
if registerForm.tuition_payment:
|
||||||
return registerForm.tuition_payment.label
|
return registerForm.tuition_payment.mode.label
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
|
|||||||
@ -306,13 +306,13 @@ class RegisterFormWithIdView(APIView):
|
|||||||
# L'école doit désormais valider le dossier d'inscription
|
# L'école doit désormais valider le dossier d'inscription
|
||||||
try:
|
try:
|
||||||
# Génération de la fiche d'inscription au format PDF
|
# Génération de la fiche d'inscription au format PDF
|
||||||
# base_dir = os.path.join(settings.MEDIA_ROOT, f"registration_files/dossier_rf_{registerForm.pk}")
|
base_dir = os.path.join(settings.MEDIA_ROOT, f"registration_files/dossier_rf_{registerForm.pk}")
|
||||||
# os.makedirs(base_dir, exist_ok=True)
|
os.makedirs(base_dir, exist_ok=True)
|
||||||
|
|
||||||
# # Fichier PDF initial
|
# Fichier PDF initial
|
||||||
# initial_pdf = f"{base_dir}/Inscription_{registerForm.student.last_name}_{registerForm.student.first_name}.pdf"
|
initial_pdf = f"{base_dir}/Inscription_{registerForm.student.last_name}_{registerForm.student.first_name}.pdf"
|
||||||
# registerForm.registration_file = util.rfToPDF(registerForm, initial_pdf)
|
registerForm.registration_file = util.rfToPDF(registerForm, initial_pdf)
|
||||||
# registerForm.save()
|
registerForm.save()
|
||||||
|
|
||||||
# Mise à jour de l'automate
|
# Mise à jour de l'automate
|
||||||
# Vérification de la présence du fichier SEPA
|
# Vérification de la présence du fichier SEPA
|
||||||
|
|||||||
@ -375,8 +375,7 @@ export default function InscriptionFormShared({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Vérifier si le mode de paiement sélectionné est un prélèvement SEPA
|
// Vérifier si le mode de paiement sélectionné est un prélèvement SEPA
|
||||||
const isSepaPayment =
|
const isSepaPayment = formData.isSepa === 1;
|
||||||
formData.registration_payment === 1 || formData.tuition_payment === 1;
|
|
||||||
|
|
||||||
// Préparer les données JSON
|
// Préparer les données JSON
|
||||||
const jsonData = {
|
const jsonData = {
|
||||||
|
|||||||
@ -64,6 +64,14 @@ export default function PaymentMethodSelector({
|
|||||||
setFormData((prev) => ({ ...prev, [field]: value }));
|
setFormData((prev) => ({ ...prev, [field]: value }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fonction utilitaire pour trier selon paymentPlansOptions
|
||||||
|
const sortPlansByOptions = (plans, options) => {
|
||||||
|
const order = options.map((opt) => opt.id);
|
||||||
|
return [...plans].sort(
|
||||||
|
(a, b) => order.indexOf(a.plan_type) - order.indexOf(b.plan_type)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Frais d'inscription */}
|
{/* Frais d'inscription */}
|
||||||
@ -84,11 +92,21 @@ export default function PaymentMethodSelector({
|
|||||||
label="Mode de Paiement"
|
label="Mode de Paiement"
|
||||||
placeHolder="Sélectionner un mode de paiement"
|
placeHolder="Sélectionner un mode de paiement"
|
||||||
selected={formData.registration_payment}
|
selected={formData.registration_payment}
|
||||||
callback={(e) =>
|
callback={(e) => {
|
||||||
onChange('registration_payment', parseInt(e.target.value, 10))
|
const selectedId = parseInt(e.target.value, 10);
|
||||||
|
const selectedMode = registrationPaymentModes.find(
|
||||||
|
(mode) => mode.id === selectedId
|
||||||
|
);
|
||||||
|
onChange('registration_payment', selectedId);
|
||||||
|
// Ajoute ou retire isSepa selon le mode choisi
|
||||||
|
if (selectedMode && selectedMode.mode === 1) {
|
||||||
|
onChange('isSepa', 1);
|
||||||
|
} else {
|
||||||
|
onChange('isSepa', 0);
|
||||||
}
|
}
|
||||||
|
}}
|
||||||
choices={registrationPaymentModes.map((mode) => ({
|
choices={registrationPaymentModes.map((mode) => ({
|
||||||
value: mode.mode,
|
value: mode.id, // <-- utiliser l'id du mode de paiement
|
||||||
label:
|
label:
|
||||||
paymentModesOptions.find((option) => option.id === mode.mode)
|
paymentModesOptions.find((option) => option.id === mode.mode)
|
||||||
?.name || 'Mode inconnu',
|
?.name || 'Mode inconnu',
|
||||||
@ -102,26 +120,25 @@ export default function PaymentMethodSelector({
|
|||||||
<RadioList
|
<RadioList
|
||||||
sectionLabel="Choisissez une option"
|
sectionLabel="Choisissez une option"
|
||||||
required
|
required
|
||||||
items={paymentPlansOptions
|
items={sortPlansByOptions(
|
||||||
.filter((option) =>
|
registrationPaymentPlans,
|
||||||
registrationPaymentPlans.some(
|
paymentPlansOptions
|
||||||
(plan) => plan.plan_type === option.id
|
).map((plan) => ({
|
||||||
)
|
id: plan.id,
|
||||||
)
|
label:
|
||||||
.map((option) => ({
|
paymentPlansOptions.find((opt) => opt.id === plan.plan_type)
|
||||||
id: option.id,
|
?.name || `Option ${plan.plan_type}`,
|
||||||
label: option.name,
|
|
||||||
}))}
|
}))}
|
||||||
formData={{
|
formData={{
|
||||||
...formData,
|
...formData,
|
||||||
registration_payment_plan: parseInt(
|
registration_payment_plan: parseInt(
|
||||||
formData.registration_payment_plan,
|
formData.registration_payment_plan,
|
||||||
10
|
10
|
||||||
), // S'assurer que la valeur est un entier
|
),
|
||||||
}}
|
}}
|
||||||
handleChange={(e) => {
|
handleChange={(e) => {
|
||||||
const value = parseInt(e.target.value, 10);
|
const value = parseInt(e.target.value, 10);
|
||||||
onChange('registration_payment_plan', value); // Convertir la valeur en entier
|
onChange('registration_payment_plan', value);
|
||||||
}}
|
}}
|
||||||
fieldName="registration_payment_plan"
|
fieldName="registration_payment_plan"
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
@ -147,11 +164,21 @@ export default function PaymentMethodSelector({
|
|||||||
label="Mode de Paiement"
|
label="Mode de Paiement"
|
||||||
placeHolder="Sélectionner un mode de paiement"
|
placeHolder="Sélectionner un mode de paiement"
|
||||||
selected={formData.tuition_payment}
|
selected={formData.tuition_payment}
|
||||||
callback={(e) =>
|
callback={(e) => {
|
||||||
onChange('tuition_payment', parseInt(e.target.value, 10))
|
const selectedId = parseInt(e.target.value, 10);
|
||||||
|
const selectedMode = tuitionPaymentModes.find(
|
||||||
|
(mode) => mode.id === selectedId
|
||||||
|
);
|
||||||
|
onChange('tuition_payment', selectedId);
|
||||||
|
// Ajoute ou retire isSepa selon le mode choisi
|
||||||
|
if (selectedMode && selectedMode.mode === 1) {
|
||||||
|
onChange('isSepa', 1);
|
||||||
|
} else {
|
||||||
|
onChange('isSepa', 0);
|
||||||
}
|
}
|
||||||
|
}}
|
||||||
choices={tuitionPaymentModes.map((mode) => ({
|
choices={tuitionPaymentModes.map((mode) => ({
|
||||||
value: mode.mode,
|
value: mode.id,
|
||||||
label:
|
label:
|
||||||
paymentModesOptions.find((option) => option.id === mode.mode)
|
paymentModesOptions.find((option) => option.id === mode.mode)
|
||||||
?.name || 'Mode inconnu',
|
?.name || 'Mode inconnu',
|
||||||
@ -165,18 +192,22 @@ export default function PaymentMethodSelector({
|
|||||||
<RadioList
|
<RadioList
|
||||||
sectionLabel="Choisissez une option"
|
sectionLabel="Choisissez une option"
|
||||||
required
|
required
|
||||||
items={paymentPlansOptions
|
items={sortPlansByOptions(
|
||||||
.filter((option) =>
|
tuitionPaymentPlans,
|
||||||
tuitionPaymentPlans.some((plan) => plan.plan_type === option.id)
|
paymentPlansOptions
|
||||||
)
|
).map((plan) => ({
|
||||||
.map((option) => ({
|
id: plan.id,
|
||||||
id: option.id,
|
label:
|
||||||
label: option.name,
|
paymentPlansOptions.find((opt) => opt.id === plan.plan_type)
|
||||||
|
?.name || `Option ${plan.plan_type}`,
|
||||||
}))}
|
}))}
|
||||||
formData={formData}
|
formData={{
|
||||||
|
...formData,
|
||||||
|
tuition_payment_plan: parseInt(formData.tuition_payment_plan, 10),
|
||||||
|
}}
|
||||||
handleChange={(e) => {
|
handleChange={(e) => {
|
||||||
const value = parseInt(e.target.value, 10);
|
const value = parseInt(e.target.value, 10); // valeur = id du plan
|
||||||
onChange('tuition_payment_plan', value); // Convertir la valeur en entier
|
onChange('tuition_payment_plan', value);
|
||||||
}}
|
}}
|
||||||
fieldName="tuition_payment_plan"
|
fieldName="tuition_payment_plan"
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
|
|||||||
Reference in New Issue
Block a user