klydekushy commited on
Commit
ededd7b
·
verified ·
1 Parent(s): cfd6d98

Update src/modules/Check_Up_Loans.py

Browse files
Files changed (1) hide show
  1. src/modules/Check_Up_Loans.py +45 -38
src/modules/Check_Up_Loans.py CHANGED
@@ -269,7 +269,7 @@ def show_check_up_loans(client, sheet_name):
269
  apply_checkup_loans_styles()
270
  st.markdown('<div id="checkup-loans-module">', unsafe_allow_html=True)
271
 
272
- st.header("🔄 MISE À JOUR DE PRÊT")
273
  st.markdown("*Modification des conditions d'un prêt avant tout remboursement*")
274
 
275
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
@@ -301,7 +301,7 @@ def show_check_up_loans(client, sheet_name):
301
  # Vérification données clients
302
  if df_clients.empty:
303
  st.error("🛑 Aucun client trouvé dans la base KYC.")
304
- st.info("💡 Veuillez d'abord enregistrer des clients avant de pouvoir modifier des prêts.")
305
  st.markdown('</div>', unsafe_allow_html=True)
306
  return
307
 
@@ -316,7 +316,7 @@ def show_check_up_loans(client, sheet_name):
316
  # ÉTAPE 2 : SÉLECTION DU CLIENT
317
  # ============================================================================
318
 
319
- st.subheader("📋 Étape 1 : Sélectionner le client")
320
 
321
  # Préparation de la liste de sélection
322
  df_clients['search_label'] = df_clients['ID_Client'].astype(str) + " - " + df_clients['Nom_Complet'].astype(str)
@@ -328,7 +328,7 @@ def show_check_up_loans(client, sheet_name):
328
  )
329
 
330
  if not selected_client_label:
331
- st.info("👆 Sélectionnez un client pour commencer")
332
  st.markdown('</div>', unsafe_allow_html=True)
333
  return
334
 
@@ -336,7 +336,7 @@ def show_check_up_loans(client, sheet_name):
336
  client_info = df_clients[df_clients['search_label'] == selected_client_label].iloc[0]
337
  client_id = client_info['ID_Client']
338
 
339
- st.success(f" Client sélectionné : **{client_info['Nom_Complet']}** (ID: {client_id})")
340
 
341
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
342
 
@@ -344,7 +344,7 @@ def show_check_up_loans(client, sheet_name):
344
  # ÉTAPE 3 : IDENTIFICATION DES PRÊTS ACTIFS DU CLIENT
345
  # ============================================================================
346
 
347
- st.subheader("🔍 Étape 2 : Identifier le prêt à modifier")
348
 
349
  # Filtrage des prêts ACTIF du client sélectionné
350
  df_prets_client = df_prets[
@@ -439,7 +439,7 @@ def show_check_up_loans(client, sheet_name):
439
  return
440
 
441
  # Aucun remboursement → Autorisation de modifier
442
- st.success(f"Aucun remboursement détecté - **Modification autorisée** pour le prêt {loan_id}")
443
 
444
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
445
 
@@ -447,7 +447,7 @@ def show_check_up_loans(client, sheet_name):
447
  # ÉTAPE 5 : AFFICHAGE DES INFORMATIONS ACTUELLES
448
  # ============================================================================
449
 
450
- st.subheader("📊 Étape 3 : Informations actuelles du prêt")
451
 
452
  st.markdown('<div class="checkup-loan-card">', unsafe_allow_html=True)
453
  st.markdown(f"### Prêt {loan_id}")
@@ -501,9 +501,9 @@ def show_check_up_loans(client, sheet_name):
501
  # ÉTAPE 6 : FORMULAIRE DE MODIFICATION
502
  # ============================================================================
503
 
504
- st.subheader("✏️ Étape 4 : Nouvelles conditions du prêt")
505
 
506
- st.info("💡 Modifiez les paramètres ci-dessous. Les montants seront recalculés automatiquement.")
507
 
508
  # Initialisation des variables de session pour éviter les pertes de données
509
  if 'dates_perso_update' not in st.session_state:
@@ -620,7 +620,14 @@ def show_check_up_loans(client, sheet_name):
620
  nouveau_nb_versements = 0
621
  nouvelle_duree_semaines = 0
622
  nouvelles_dates_versements = []
623
- nouvelle_date_debut = date.today()
 
 
 
 
 
 
 
624
  nouvelle_date_fin = nouvelle_date_debut
625
 
626
  # -----------------------------------------------------------
@@ -642,7 +649,7 @@ def show_check_up_loans(client, sheet_name):
642
  nouveau_nb_versements = 1
643
 
644
  # Affichage résultat simulation
645
- st.markdown("### 💰 Simulation des nouveaux montants")
646
  res1, res2, res3 = st.columns(3)
647
  res1.metric("Versement unique", f"{int(nouveau_montant_versement):,} XOF".replace(",", " "))
648
  res2.metric("Coût du crédit", f"{int(nouveau_cout_credit):,} XOF".replace(",", " "))
@@ -673,7 +680,7 @@ def show_check_up_loans(client, sheet_name):
673
  nouveau_nb_versements = int(nouvelle_duree_mois)
674
 
675
  # Affichage résultat simulation
676
- st.markdown("### 💰 Simulation des nouveaux montants")
677
  res1, res2 = st.columns(2)
678
  res1.metric("Intérêts mensuels", f"{int(interet_mensuel):,} XOF".replace(",", " "))
679
  res2.metric("Dernier versement", f"{int(montant_final_mois):,} XOF".replace(",", " "))
@@ -710,7 +717,7 @@ def show_check_up_loans(client, sheet_name):
710
  nouveau_nb_versements = int(nouvelle_duree_mois)
711
 
712
  # Affichage résultat simulation
713
- st.markdown("### 💰 Simulation des nouveaux montants")
714
  res1, res2, res3 = st.columns(3)
715
  res1.metric("Mensualité constante", f"{int(mensualite):,} XOF".replace(",", " "))
716
  res2.metric("Coût du crédit", f"{int(nouveau_cout_credit):,} XOF".replace(",", " "))
@@ -742,7 +749,7 @@ def show_check_up_loans(client, sheet_name):
742
  nouveau_nb_versements = int(nouvelle_duree_semaines)
743
 
744
  # Affichage résultat simulation
745
- st.markdown("### 💰 Simulation des nouveaux montants")
746
  res1, res2, res3 = st.columns(3)
747
  res1.metric("Versement Hebdo", f"{int(hebdomadalite):,} XOF".replace(",", " "))
748
  res2.metric("Coût du crédit", f"{int(nouveau_cout_credit):,} XOF".replace(",", " "))
@@ -753,12 +760,12 @@ def show_check_up_loans(client, sheet_name):
753
  # 5. LOGIQUE PERSONNALISÉE (Dates manuelles)
754
  # -----------------------------------------------------------
755
  else: # PERSONNALISE
756
- st.info("📅 Configurez les dates de versement ci-dessous")
757
 
758
  # Interface d'ajout de dates
759
  st.markdown("**Dates de versement :**")
760
  col_add, col_reset = st.columns([1, 4])
761
- if col_add.button("Ajouter", key="add_date_update"):
762
  last_date = st.session_state.dates_perso_update[-1]
763
  st.session_state.dates_perso_update.append(last_date + timedelta(weeks=1))
764
  st.rerun()
@@ -774,7 +781,7 @@ def show_check_up_loans(client, sheet_name):
774
  min_value=date.today()
775
  )
776
  nouvelles_dates_versements.append(new_date)
777
- if col_x.button("🗑️", key=f"del_update_{idx}") and len(st.session_state.dates_perso_update) > 1:
778
  st.session_state.dates_perso_update.pop(idx)
779
  st.rerun()
780
 
@@ -785,7 +792,7 @@ def show_check_up_loans(client, sheet_name):
785
  nouvelles_dates_versements.sort()
786
  nouvelle_date_fin = nouvelles_dates_versements[-1]
787
  delta_days = (nouvelle_date_fin - nouvelle_date_debut).days
788
- nouvelle_duree_semaines = max(1, delta_days // 7)
789
 
790
  nouveau_montant_total = nouveau_montant * (1 + (nouveau_taux / 100) * nouvelle_duree_semaines)
791
  nouveau_cout_credit = nouveau_montant_total - nouveau_montant
@@ -793,7 +800,7 @@ def show_check_up_loans(client, sheet_name):
793
  nouveau_montant_versement = nouveau_montant_total / nouveau_nb_versements
794
 
795
  # Affichage résultat simulation
796
- st.markdown("### 💰 Simulation des nouveaux montants")
797
  res1, res2 = st.columns(2)
798
  res1.metric("Moyenne/Versement", f"{int(nouveau_montant_versement):,} XOF".replace(",", " "))
799
  res2.metric("Durée estimée", f"{int(nouvelle_duree_semaines)} sem")
@@ -822,7 +829,7 @@ def show_check_up_loans(client, sheet_name):
822
 
823
  # Affichage pour information
824
  if nouveau_taux_endettement > 0:
825
- st.info(f"📊 **Nouveau taux d'endettement calculé** : {nouveau_taux_endettement:.2f}%")
826
 
827
  # Warning si le taux dépasse 33%
828
  if nouveau_taux_endettement > 33:
@@ -835,7 +842,7 @@ def show_check_up_loans(client, sheet_name):
835
  # ============================================================================
836
 
837
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
838
- st.subheader("📊 Comparaison Avant / Après")
839
 
840
  st.markdown('<div class="checkup-comparison-table">', unsafe_allow_html=True)
841
 
@@ -913,7 +920,7 @@ def show_check_up_loans(client, sheet_name):
913
 
914
  # Warning 4 : Augmentation du montant capital
915
  if nouveau_montant > montant_capital_actuel:
916
- warnings.append(f"💰 Le montant capital augmente de **{int(nouveau_montant - montant_capital_actuel):,} XOF**".replace(",", " "))
917
 
918
  if warnings:
919
  st.markdown('<div class="checkup-warning-box">', unsafe_allow_html=True)
@@ -927,7 +934,7 @@ def show_check_up_loans(client, sheet_name):
927
  # ============================================================================
928
 
929
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
930
- st.subheader("🎯 Nouvelle analyse de solvabilité")
931
 
932
  # Appel du cerveau analytique
933
  analyse = analyser_capacite(
@@ -941,7 +948,7 @@ def show_check_up_loans(client, sheet_name):
941
  unsafe_allow_html=True)
942
  st.info(analyse['message'])
943
 
944
- with st.expander("📋 Détails financiers"):
945
  st.markdown(analyse['details'])
946
 
947
  # ============================================================================
@@ -949,7 +956,7 @@ def show_check_up_loans(client, sheet_name):
949
  # ============================================================================
950
 
951
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
952
- st.subheader("📅 Nouveau tableau d'échéances")
953
 
954
  # Génération du tableau
955
  if nouveau_type_code == "PERSONNALISE":
@@ -975,7 +982,7 @@ def show_check_up_loans(client, sheet_name):
975
  # ============================================================================
976
 
977
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
978
- st.subheader(" Validation de la mise à jour")
979
 
980
  st.info("🔒 **Attention** : Cette action va créer un nouveau prêt et archiver l'ancien avec le statut UPDATED.")
981
 
@@ -1002,7 +1009,7 @@ def show_check_up_loans(client, sheet_name):
1002
  help="Ce commentaire sera enregistré dans la feuille Prets_Update pour traçabilité"
1003
  )
1004
 
1005
- submit_update = st.form_submit_button(" VALIDER LA MISE À JOUR", use_container_width=True)
1006
 
1007
 
1008
  if submit_update:
@@ -1011,7 +1018,7 @@ def show_check_up_loans(client, sheet_name):
1011
  # ÉTAPE A : MISE À JOUR DU STATUT DANS Prets_Master
1012
  # ========================================================================
1013
 
1014
- with st.spinner(" Mise à jour du prêt en cours..."):
1015
  ws_prets_master = sh.worksheet("Prets_Master")
1016
 
1017
  # Recherche de la ligne du prêt à modifier
@@ -1051,13 +1058,13 @@ def show_check_up_loans(client, sheet_name):
1051
 
1052
  time.sleep(1) # Anti rate-limit
1053
 
1054
- st.success(f" Prêt {loan_id} → Statut changé en **UPDATED**")
1055
 
1056
  # ========================================================================
1057
  # ÉTAPE B : CRÉATION DU NOUVEAU PRÊT DANS Prets_Update
1058
  # ========================================================================
1059
 
1060
- with st.spinner("📝 Création du nouveau prêt dans Prets_Update..."):
1061
  # Vérification/Création de la feuille Prets_Update
1062
  try:
1063
  ws_prets_update = sh.worksheet("Prets_Update")
@@ -1180,9 +1187,9 @@ def show_check_up_loans(client, sheet_name):
1180
 
1181
  if st.session_state.get('loan_updated', False):
1182
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
1183
- st.markdown(f"### 📄 Documents du prêt **{st.session_state.new_loan_id}**")
1184
 
1185
- st.success(f" Prêt mis à jour : **{st.session_state.get('new_loan_data', {}).get('ID_Pret_Source')}** → **{st.session_state.new_loan_id}**")
1186
 
1187
  # Préparation des données pour les PDFs
1188
  loan_data_pdf = st.session_state.new_loan_data
@@ -1200,7 +1207,7 @@ def show_check_up_loans(client, sheet_name):
1200
  with col_pdf1:
1201
  pdf_contrat = generer_contrat_pret(loan_data_pdf, client_data_pdf, df_amort_pdf)
1202
  st.download_button(
1203
- "📄 Contrat de Prêt",
1204
  pdf_contrat,
1205
  f"Contrat_{st.session_state.new_loan_id}.pdf",
1206
  "application/pdf",
@@ -1211,7 +1218,7 @@ def show_check_up_loans(client, sheet_name):
1211
  with col_pdf2:
1212
  pdf_dette = generer_reconnaissance_dette(loan_data_pdf, client_data_pdf)
1213
  st.download_button(
1214
- "📄 Reconnaissance Dette",
1215
  pdf_dette,
1216
  f"Dette_{st.session_state.new_loan_id}.pdf",
1217
  "application/pdf",
@@ -1223,7 +1230,7 @@ def show_check_up_loans(client, sheet_name):
1223
  if garant_data_pdf is not None:
1224
  pdf_caution = generer_contrat_caution(loan_data_pdf, garant_data_pdf)
1225
  st.download_button(
1226
- "📄 Contrat Caution",
1227
  pdf_caution,
1228
  f"Caution_{st.session_state.new_loan_id}.pdf",
1229
  "application/pdf",
@@ -1234,7 +1241,7 @@ def show_check_up_loans(client, sheet_name):
1234
 
1235
  # BOUTON RESET : Nouvelle mise à jour
1236
  with col_reset:
1237
- if st.button("🔄 Nouvelle Mise à Jour", use_container_width=True, type="primary"):
1238
  # Nettoyage du session state
1239
  st.session_state.loan_updated = False
1240
  st.session_state.pop('new_loan_id', None)
@@ -1248,7 +1255,7 @@ def show_check_up_loans(client, sheet_name):
1248
 
1249
  # Affichage d'un récapitulatif
1250
  st.markdown("---")
1251
- with st.expander("📋 Récapitulatif de la mise à jour"):
1252
  col_recap1, col_recap2 = st.columns(2)
1253
 
1254
  with col_recap1:
 
269
  apply_checkup_loans_styles()
270
  st.markdown('<div id="checkup-loans-module">', unsafe_allow_html=True)
271
 
272
+ st.header("MISE À JOUR DE PRÊT")
273
  st.markdown("*Modification des conditions d'un prêt avant tout remboursement*")
274
 
275
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
 
301
  # Vérification données clients
302
  if df_clients.empty:
303
  st.error("🛑 Aucun client trouvé dans la base KYC.")
304
+ st.info(" Veuillez d'abord enregistrer des clients avant de pouvoir modifier des prêts.")
305
  st.markdown('</div>', unsafe_allow_html=True)
306
  return
307
 
 
316
  # ÉTAPE 2 : SÉLECTION DU CLIENT
317
  # ============================================================================
318
 
319
+ st.subheader(" Étape 1 : Sélectionner le client")
320
 
321
  # Préparation de la liste de sélection
322
  df_clients['search_label'] = df_clients['ID_Client'].astype(str) + " - " + df_clients['Nom_Complet'].astype(str)
 
328
  )
329
 
330
  if not selected_client_label:
331
+ st.info("Sélectionnez un client pour commencer")
332
  st.markdown('</div>', unsafe_allow_html=True)
333
  return
334
 
 
336
  client_info = df_clients[df_clients['search_label'] == selected_client_label].iloc[0]
337
  client_id = client_info['ID_Client']
338
 
339
+ st.success(f" Client sélectionné : **{client_info['Nom_Complet']}** (ID: {client_id})")
340
 
341
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
342
 
 
344
  # ÉTAPE 3 : IDENTIFICATION DES PRÊTS ACTIFS DU CLIENT
345
  # ============================================================================
346
 
347
+ st.subheader("Étape 2 : Identifier le prêt à modifier")
348
 
349
  # Filtrage des prêts ACTIF du client sélectionné
350
  df_prets_client = df_prets[
 
439
  return
440
 
441
  # Aucun remboursement → Autorisation de modifier
442
+ st.success(f"Aucun remboursement détecté - **Modification autorisée** pour le prêt {loan_id}")
443
 
444
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
445
 
 
447
  # ÉTAPE 5 : AFFICHAGE DES INFORMATIONS ACTUELLES
448
  # ============================================================================
449
 
450
+ st.subheader("Étape 3 : Informations actuelles du prêt")
451
 
452
  st.markdown('<div class="checkup-loan-card">', unsafe_allow_html=True)
453
  st.markdown(f"### Prêt {loan_id}")
 
501
  # ÉTAPE 6 : FORMULAIRE DE MODIFICATION
502
  # ============================================================================
503
 
504
+ st.subheader(" Étape 4 : Nouvelles conditions du prêt")
505
 
506
+ st.info(" Modifiez les paramètres ci-dessous. Les montants seront recalculés automatiquement.")
507
 
508
  # Initialisation des variables de session pour éviter les pertes de données
509
  if 'dates_perso_update' not in st.session_state:
 
620
  nouveau_nb_versements = 0
621
  nouvelle_duree_semaines = 0
622
  nouvelles_dates_versements = []
623
+
624
+ # ✅ CORRECTION : Utiliser Date_Deblocage au lieu de date.today()
625
+ try:
626
+ nouvelle_date_debut = datetime.strptime(selected_loan['Date_Deblocage'], "%d/%m/%Y").date()
627
+ except:
628
+ # Fallback si le format est différent
629
+ nouvelle_date_debut = date.today()
630
+
631
  nouvelle_date_fin = nouvelle_date_debut
632
 
633
  # -----------------------------------------------------------
 
649
  nouveau_nb_versements = 1
650
 
651
  # Affichage résultat simulation
652
+ st.markdown("### Simulation des nouveaux montants")
653
  res1, res2, res3 = st.columns(3)
654
  res1.metric("Versement unique", f"{int(nouveau_montant_versement):,} XOF".replace(",", " "))
655
  res2.metric("Coût du crédit", f"{int(nouveau_cout_credit):,} XOF".replace(",", " "))
 
680
  nouveau_nb_versements = int(nouvelle_duree_mois)
681
 
682
  # Affichage résultat simulation
683
+ st.markdown("### Simulation des nouveaux montants")
684
  res1, res2 = st.columns(2)
685
  res1.metric("Intérêts mensuels", f"{int(interet_mensuel):,} XOF".replace(",", " "))
686
  res2.metric("Dernier versement", f"{int(montant_final_mois):,} XOF".replace(",", " "))
 
717
  nouveau_nb_versements = int(nouvelle_duree_mois)
718
 
719
  # Affichage résultat simulation
720
+ st.markdown("### Simulation des nouveaux montants")
721
  res1, res2, res3 = st.columns(3)
722
  res1.metric("Mensualité constante", f"{int(mensualite):,} XOF".replace(",", " "))
723
  res2.metric("Coût du crédit", f"{int(nouveau_cout_credit):,} XOF".replace(",", " "))
 
749
  nouveau_nb_versements = int(nouvelle_duree_semaines)
750
 
751
  # Affichage résultat simulation
752
+ st.markdown("### Simulation des nouveaux montants")
753
  res1, res2, res3 = st.columns(3)
754
  res1.metric("Versement Hebdo", f"{int(hebdomadalite):,} XOF".replace(",", " "))
755
  res2.metric("Coût du crédit", f"{int(nouveau_cout_credit):,} XOF".replace(",", " "))
 
760
  # 5. LOGIQUE PERSONNALISÉE (Dates manuelles)
761
  # -----------------------------------------------------------
762
  else: # PERSONNALISE
763
+ st.info(" Configurez les dates de versement ci-dessous")
764
 
765
  # Interface d'ajout de dates
766
  st.markdown("**Dates de versement :**")
767
  col_add, col_reset = st.columns([1, 4])
768
+ if col_add.button("Ajouter", key="add_date_update"):
769
  last_date = st.session_state.dates_perso_update[-1]
770
  st.session_state.dates_perso_update.append(last_date + timedelta(weeks=1))
771
  st.rerun()
 
781
  min_value=date.today()
782
  )
783
  nouvelles_dates_versements.append(new_date)
784
+ if col_x.button("️", key=f"del_update_{idx}") and len(st.session_state.dates_perso_update) > 1:
785
  st.session_state.dates_perso_update.pop(idx)
786
  st.rerun()
787
 
 
792
  nouvelles_dates_versements.sort()
793
  nouvelle_date_fin = nouvelles_dates_versements[-1]
794
  delta_days = (nouvelle_date_fin - nouvelle_date_debut).days
795
+ nouvelle_duree_semaines = max(1, delta_days / 7)
796
 
797
  nouveau_montant_total = nouveau_montant * (1 + (nouveau_taux / 100) * nouvelle_duree_semaines)
798
  nouveau_cout_credit = nouveau_montant_total - nouveau_montant
 
800
  nouveau_montant_versement = nouveau_montant_total / nouveau_nb_versements
801
 
802
  # Affichage résultat simulation
803
+ st.markdown("### Simulation des nouveaux montants")
804
  res1, res2 = st.columns(2)
805
  res1.metric("Moyenne/Versement", f"{int(nouveau_montant_versement):,} XOF".replace(",", " "))
806
  res2.metric("Durée estimée", f"{int(nouvelle_duree_semaines)} sem")
 
829
 
830
  # Affichage pour information
831
  if nouveau_taux_endettement > 0:
832
+ st.info(f" **Nouveau taux d'endettement calculé** : {nouveau_taux_endettement:.2f}%")
833
 
834
  # Warning si le taux dépasse 33%
835
  if nouveau_taux_endettement > 33:
 
842
  # ============================================================================
843
 
844
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
845
+ st.subheader(" Comparaison Avant / Après")
846
 
847
  st.markdown('<div class="checkup-comparison-table">', unsafe_allow_html=True)
848
 
 
920
 
921
  # Warning 4 : Augmentation du montant capital
922
  if nouveau_montant > montant_capital_actuel:
923
+ warnings.append(f" Le montant capital augmente de **{int(nouveau_montant - montant_capital_actuel):,} XOF**".replace(",", " "))
924
 
925
  if warnings:
926
  st.markdown('<div class="checkup-warning-box">', unsafe_allow_html=True)
 
934
  # ============================================================================
935
 
936
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
937
+ st.subheader(" Nouvelle analyse de solvabilité")
938
 
939
  # Appel du cerveau analytique
940
  analyse = analyser_capacite(
 
948
  unsafe_allow_html=True)
949
  st.info(analyse['message'])
950
 
951
+ with st.expander(" Détails financiers"):
952
  st.markdown(analyse['details'])
953
 
954
  # ============================================================================
 
956
  # ============================================================================
957
 
958
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
959
+ st.subheader(" Nouveau tableau d'échéances")
960
 
961
  # Génération du tableau
962
  if nouveau_type_code == "PERSONNALISE":
 
982
  # ============================================================================
983
 
984
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
985
+ st.subheader(" Validation de la mise à jour")
986
 
987
  st.info("🔒 **Attention** : Cette action va créer un nouveau prêt et archiver l'ancien avec le statut UPDATED.")
988
 
 
1009
  help="Ce commentaire sera enregistré dans la feuille Prets_Update pour traçabilité"
1010
  )
1011
 
1012
+ submit_update = st.form_submit_button(" VALIDER LA MISE À JOUR", use_container_width=True)
1013
 
1014
 
1015
  if submit_update:
 
1018
  # ÉTAPE A : MISE À JOUR DU STATUT DANS Prets_Master
1019
  # ========================================================================
1020
 
1021
+ with st.spinner(" Mise à jour du prêt en cours..."):
1022
  ws_prets_master = sh.worksheet("Prets_Master")
1023
 
1024
  # Recherche de la ligne du prêt à modifier
 
1058
 
1059
  time.sleep(1) # Anti rate-limit
1060
 
1061
+ st.success(f" Prêt {loan_id} → Statut changé en **UPDATED**")
1062
 
1063
  # ========================================================================
1064
  # ÉTAPE B : CRÉATION DU NOUVEAU PRÊT DANS Prets_Update
1065
  # ========================================================================
1066
 
1067
+ with st.spinner(" Création du nouveau prêt dans Prets_Update..."):
1068
  # Vérification/Création de la feuille Prets_Update
1069
  try:
1070
  ws_prets_update = sh.worksheet("Prets_Update")
 
1187
 
1188
  if st.session_state.get('loan_updated', False):
1189
  st.markdown('<div class="checkup-section-divider"></div>', unsafe_allow_html=True)
1190
+ st.markdown(f"### Documents du prêt **{st.session_state.new_loan_id}**")
1191
 
1192
+ st.success(f" Prêt mis à jour : **{st.session_state.get('new_loan_data', {}).get('ID_Pret_Source')}** → **{st.session_state.new_loan_id}**")
1193
 
1194
  # Préparation des données pour les PDFs
1195
  loan_data_pdf = st.session_state.new_loan_data
 
1207
  with col_pdf1:
1208
  pdf_contrat = generer_contrat_pret(loan_data_pdf, client_data_pdf, df_amort_pdf)
1209
  st.download_button(
1210
+ " Contrat de Prêt",
1211
  pdf_contrat,
1212
  f"Contrat_{st.session_state.new_loan_id}.pdf",
1213
  "application/pdf",
 
1218
  with col_pdf2:
1219
  pdf_dette = generer_reconnaissance_dette(loan_data_pdf, client_data_pdf)
1220
  st.download_button(
1221
+ " Reconnaissance Dette",
1222
  pdf_dette,
1223
  f"Dette_{st.session_state.new_loan_id}.pdf",
1224
  "application/pdf",
 
1230
  if garant_data_pdf is not None:
1231
  pdf_caution = generer_contrat_caution(loan_data_pdf, garant_data_pdf)
1232
  st.download_button(
1233
+ " Contrat Caution",
1234
  pdf_caution,
1235
  f"Caution_{st.session_state.new_loan_id}.pdf",
1236
  "application/pdf",
 
1241
 
1242
  # BOUTON RESET : Nouvelle mise à jour
1243
  with col_reset:
1244
+ if st.button(" Nouvelle Mise à Jour", use_container_width=True, type="primary"):
1245
  # Nettoyage du session state
1246
  st.session_state.loan_updated = False
1247
  st.session_state.pop('new_loan_id', None)
 
1255
 
1256
  # Affichage d'un récapitulatif
1257
  st.markdown("---")
1258
+ with st.expander(" Récapitulatif de la mise à jour"):
1259
  col_recap1, col_recap2 = st.columns(2)
1260
 
1261
  with col_recap1: